--- linux/drivers/scsi/megaraid.h.save  Tue Jan  4 14:51:08 2000
+++ linux/drivers/scsi/megaraid.h       Tue Jan  4 00:57:23 2000
@@ -12,7 +12,6 @@
#define BOARD_QUARTZ            0x08000000L
#define BOARD_40LD              0x04000000L

-#ifndef HOSTS_C
#define SCB_FREE     0x0
#define SCB_ACTIVE   0x1
#define SCB_WAITQ    0x2
@@ -20,7 +19,6 @@
#define SCB_COMPLETE 0x4
#define SCB_ABORTED  0x5
#define SCB_RESET    0x6
-#endif

#define MEGA_CMD_TIMEOUT        10

@@ -109,6 +107,7 @@
#define PCI_CONF_IRQ_OFFSET        0x3c
#define PCI_CONF_AMISIG            0xa0
#define AMI_SIGNATURE              0x3344
+#define AMI_SIGNATURE_471          0xCCCC

#if LINUX_VERSION_CODE < 0x20100
#define MEGARAID \
--- linux/drivers/scsi/megaraid.c.save  Tue Jan  4 14:44:41 2000
+++ linux/drivers/scsi/megaraid.c       Tue Jan  4 00:57:17 2000
@@ -2,14 +2,14 @@
 *
 *                    Linux MegaRAID device driver
 *
- * Copyright 1998 American Megatrends Inc.
+ * Copyright 1999 American Megatrends Inc.
 *
 *              This program is free software; you can redistribute it and/or
 *              modify it under the terms of the GNU General Public License
 *              as published by the Free Software Foundation; either version
 *              2 of the License, or (at your option) any later version.
 *
- * Version : 1.05
+ * Version : 1.07
 *
 * Description: Linux device driver for AMI MegaRAID controller
 *
@@ -120,6 +120,9 @@
 *      also enables the driver to handle large amount of I/O requests for
 *      long duration of time.
 *
+ * Version 1.07
+ *    Removed the usage of uaccess.h file for kernel versions less than
+ *    2.0.36, as this file is not present in those versions.
 *
 * BUGS:
 *     Some older 2.1 kernels (eg. 2.1.90) have a bug in pci.c that
@@ -135,7 +138,7 @@
#define CRLFSTR "\n"
#define IOCTL_CMD_NEW  0x81

-#define MEGARAID_VERSION "v1.05 (October 27, 1999)"
+#define MEGARAID_VERSION "v107 (December 22, 1999)"


#include <linux/config.h>
@@ -178,7 +181,9 @@

#include <asm/io.h>
#include <asm/irq.h>
+#if LINUX_VERSION_CODE > 0x020024
#include <asm/uaccess.h>
+#endif

#include "sd.h"
#include "scsi.h"
@@ -265,7 +270,6 @@



-
#if LINUX_VERSION_CODE > 0x020100
#  include <asm/spinlock.h>
#  include <linux/smp.h>
@@ -304,6 +308,7 @@
       cli();
#  define DRIVER_UNLOCK(p) \
       restore_flags(cpu_flags);
+#  define IO_LOCK_T unsigned long io_flags = 0;
#  define IO_LOCK(p)   DRIVER_LOCK(p)
#  define IO_UNLOCK(p) DRIVER_UNLOCK(p)
#  define le32_to_cpu(x) (x)
@@ -329,6 +334,7 @@
/*  Use "megaraid=skipXX" as LILO option to prohibit driver from scanning
    XX scsi id on each channel.  Used for Madrona motherboard, where SAF_TE
    processor id cannot be scanned */
+
static char *megaraid;
#if LINUX_VERSION_CODE > 0x20100
#ifdef MODULE
@@ -350,7 +356,6 @@
#if SERDEBUG
volatile static spinlock_t serial_lock;
#endif
-//volatile static spinlock_t mega_lock;

struct proc_dir_entry proc_scsi_megaraid =
{
@@ -593,7 +598,6 @@
  }

  SCpnt = pScb->SCpnt;
-  /*freeSCB(megaCfg, pScb);*/ /*delay this to the end of this func.*/
  pthru = &pScb->pthru;
  mbox = (mega_mailbox *) &pScb->mboxData;

@@ -708,13 +712,11 @@

  if ( islogical ) {
       lun = (SCpnt->target * 8) + lun;
-#if 1
        if ( lun > FC_MAX_LOGICAL_DRIVES ){
            SCpnt->result = (DID_BAD_TARGET << 16);
            callDone (SCpnt);
            return NULL;
        }
-#endif
  }
  /*-----------------------------------------------------
   *
@@ -878,7 +880,6 @@
    return NULL;
  }

-
  mboxdata = (u8 *) & pScb->mboxData;
  mbox = (mega_ioctl_mbox *) & pScb->mboxData;
  mailbox = (mega_mailbox *) & pScb->mboxData;
@@ -913,6 +914,14 @@
  }
  /* else normal (nonpassthru) command */

+#if LINUX_VERSION_CODE > 0x020024
+/*
+ * usage of the function copy from user is used in case of data more than
+ * 4KB.  This is used only with adapters which supports more than 8 logical
+ * drives.  This feature is disabled on kernels earlier or same as 2.0.36
+ * as the uaccess.h file is not available with those kernels.
+ */
+
  if (SCpnt->cmnd[0] == IOCTL_CMD_NEW) {
            /* use external data area for large xfers  */
     /* If cmnd[0] is set to IOCTL_CMD_NEW then *
@@ -938,6 +947,7 @@
      copy_from_user(kern_area,user_area,xfer_size);
      pScb->kern_area = kern_area;
  }
+#endif

  mbox->cmd = data[0];
  mbox->channel = data[1];
@@ -998,7 +1008,9 @@
 *--------------------------------------------------------------------*/
static void megaraid_isr (int irq, void *devp, struct pt_regs *regs)
{
+#if LINUX_VERSION_CODE >= 0x20100
  IO_LOCK_T
+#endif
  mega_host_config    *megaCfg;
  u_char byte, idx, sIdx, tmpBox[MAILBOX_SIZE];
  u32 dword=0;
@@ -1011,7 +1023,6 @@
  megaCfg = (mega_host_config *) devp;
  mbox = (mega_mailbox *)tmpBox;

-
  if (megaCfg->host->irq == irq) {

    if (megaCfg->flag & IN_ISR) {
@@ -1031,10 +1042,6 @@
      if (dword != 0x10001234) {
       /* Spurious interrupt */
       megaCfg->flag &= ~IN_ISR;
-//#if LINUX_VERSION_CODE >= 0x20100
-//        IO_UNLOCK;
-//#endif
-//     break;
       return;
      }
    }
@@ -1043,10 +1050,6 @@
      if ((byte & VALID_INTR_BYTE) == 0) {
       /* Spurious interrupt */
       megaCfg->flag &= ~IN_ISR;
-//#if LINUX_VERSION_CODE >= 0x20100
-//     IO_UNLOCK;
-//#endif
-//     break;
       return;
      }
      WRITE_PORT (megaCfg->host->io_port, INTR_PORT, byte);
@@ -1110,9 +1113,6 @@
 */
       if (pScb->state == SCB_ABORTED) {
          SCpnt = pScb->SCpnt;
-#if DEBUG
-printk("megaraid_isr:fcnt=%d, pcnt=%d, qcnt=%d\n",megaCfg->qFcnt, megaCfg->qPcnt, megaCfg->qCcnt);
-#endif
       }
       if (pScb->state == SCB_RESET) {
          SCpnt = pScb->SCpnt;
@@ -1211,9 +1211,6 @@
#endif

  /* Wait until mailbox is free */
-#if 0
-  while (mega_busyWaitMbox (megaCfg))
-#endif
  if (mega_busyWaitMbox (megaCfg)) {
    printk("Blocked mailbox......!!\n");
    udelay(1000);
@@ -1266,7 +1263,6 @@

      if (pScb) {
       mega_cmd_done (megaCfg, pScb, mbox->status);
-//     mega_rundoneq (megaCfg);
      }

      WRINDOOR (megaCfg, phys_mbox | 0x2);
@@ -1285,7 +1281,6 @@

      if (pScb) {
       mega_cmd_done (megaCfg, pScb, mbox->status);
-//     mega_rundoneq (megaCfg);
      }
      else {
       TRACE (("Error: NULL pScb!\n"));
@@ -1424,7 +1419,6 @@
  u32 paddr;
  u8 retval;

-
  /* Initialize adapter inquiry mailbox*/
  paddr = virt_to_bus (megaCfg->mega_buffer);
  mbox = (mega_mailbox *) mboxData;
@@ -1496,25 +1490,6 @@
    megaCfg->host->can_queue = MAX_COMMANDS-1;
  }

-#if 0
-  int i;
-  printk (KERN_DEBUG "---- Logical drive info from enquiry3 struct----\n");
-  for (i = 0; i < megaCfg->numldrv; i++) {
-    printk ("%d: size: %d prop: %x state: %x\n", i,
-           enquiry3Pnt->lDrvSize[i],
-           enquiry3Pnt->lDrvProp[i],
-           enquiry3Pnt->lDrvState[i]);
-  }
-
-  printk (KERN_DEBUG "---- Physical drive info ----\n");
-  for (i = 0; i < FC_MAX_PHYSICAL_DEVICES; i++) {
-    if (i && !(i % 8))
-      printk ("\n");
-    printk ("%d: %x   ", i, enquiry3Pnt->pDrvState[i]);
-  }
-  printk ("\n");
-#endif
-
#ifdef HP                      /* use HP firmware and bios version encoding */
  sprintf (megaCfg->fwVer, "%c%d%d.%d%d",
          megaCfg->productInfo.FwVer[2],
@@ -1573,10 +1548,6 @@

#if LINUX_VERSION_CODE < 0x20100
  while (!pcibios_find_device (pciVendor, pciDev, pciIdx, &pciBus, &pciDevFun)) {
-
-#if 0
-  } /* keep auto-indenters happy */
-#endif
#else

  struct pci_dev *pdev = pci_devices;
@@ -1590,7 +1561,7 @@
      pcibios_read_config_word (pciBus, pciDevFun,
                               PCI_CONF_AMISIG,
                               &magic);
-      if (magic != AMI_SIGNATURE) {
+      if ((magic != AMI_SIGNATURE) && (magic != AMI_SIGNATURE_471) ){
        pciIdx++;
       continue;               /* not an AMI board */
      }
@@ -1824,9 +1795,6 @@

  /* If driver in abort or reset.. cancel this command */
  if (megaCfg->flag & IN_ABORT) {
-#if DEBUG
-printk("mq: got a request while in abort\n");
-#endif
    SCpnt->result = (DID_ABORT << 16);
    /* Add Scsi_Command to end of completed queue */
    if( megaCfg->qCompletedH == NULL ) {
@@ -1843,9 +1811,6 @@
    return 0;
  }
  else if (megaCfg->flag & IN_RESET) {
-#if DEBUG
-printk("mq: got a request while in reset\n");
-#endif
    SCpnt->result = (DID_RESET << 16);
    /* Add Scsi_Command to end of completed queue */
    if( megaCfg->qCompletedH == NULL ) {
@@ -1878,16 +1843,9 @@
    megaCfg->qPendingT->next = NULL;
    megaCfg->qPcnt++;

-
-    /* Issue any pending command to the card if not in ISR */
-//    if (!(megaCfg->flag & IN_ISR)) {
      mega_runpendq(megaCfg);
-//    }
-/*
- * try running the pend queue, irrespective of the driver's context.
- * -cn
- */

+#if LINUX_VERSION_CODE > 0x020024
    if ( SCpnt->cmnd[0]==IOCTL_CMD_NEW )
    {  /* user data from external user buffer */
          char *user_area;
@@ -1905,6 +1863,7 @@

          mega_freeSCB(megaCfg, pScb);
    }
+#endif
  }

  megaCfg->flag &= ~IN_QUEUE;
@@ -1959,9 +1918,6 @@

  megaCfg->flag |= IN_ABORT;

-#if DEBUG
-printk("ma:fcnt=%d, pcnt=%d, qcnt=%d\n",megaCfg->qFcnt, megaCfg->qPcnt, megaCfg->qCcnt);
-#endif
  for(pScb=megaCfg->qPendingH; pScb; pScb=pScb->next) {
    if (pScb->SCpnt == SCpnt) {
      /* Found an aborting command */
@@ -2013,20 +1969,6 @@
    }
  }

-#if 0
-  TRACE (("ABORT!!! %.08lx %.02x <%d.%d.%d>\n",
-         SCpnt->serial_number, SCpnt->cmnd[0], SCpnt->channel, SCpnt->target,
-         SCpnt->lun));
-  for(pScb=megaCfg->qPending; pScb; pScb=pScb->next) {
-    if (pScb->SCpnt == SCpnt) {
-      ser_printk("** %d<%x>  %c\n", pScb->SCpnt->pid, pScb->idx+1,
-                pScb->state == SCB_ACTIVE ? 'A' : 'I');
-#if DEBUG
-      showMbox(pScb);
-#endif
-    }
-  }
-#endif
  megaCfg->flag &= ~IN_ABORT;

#if DEBUG
@@ -2044,12 +1986,11 @@
  megaCfg->qCompletedH = (Scsi_Cmnd *)SCpnt->host_scribble;
  megaCfg->qCcnt--;

-  SCpnt->host_scribble = (unsigned char *) NULL ; // XC : sep 14
+  SCpnt->host_scribble = (unsigned char *) NULL ;
  /* Callback */
  callDone (SCpnt);
}
  mega_rundoneq(megaCfg);
-

  return rc;
}