tree-wide: fix assorted typos all over the place
[safe/jmp/linux-2.6] / drivers / scsi / sym53c8xx_2 / sym_hipd.c
index 39f84bb..a7bc8b7 100644 (file)
@@ -52,7 +52,7 @@
  *  Needed function prototypes.
  */
 static void sym_int_ma (struct sym_hcb *np);
-static void sym_int_sir (struct sym_hcb *np);
+static void sym_int_sir(struct sym_hcb *);
 static struct sym_ccb *sym_alloc_ccb(struct sym_hcb *np);
 static struct sym_ccb *sym_ccb_from_dsa(struct sym_hcb *np, u32 dsa);
 static void sym_alloc_lcb_tags (struct sym_hcb *np, u_char tn, u_char ln);
@@ -602,7 +602,7 @@ sym_getsync(struct sym_hcb *np, u_char dt, u_char sfac, u_char *divp, u_char *fa
 /*
  *  Set initial io register bits from burst code.
  */
-static __inline void sym_init_burst(struct sym_hcb *np, u_char bc)
+static inline void sym_init_burst(struct sym_hcb *np, u_char bc)
 {
        np->rv_ctest4   &= ~0x80;
        np->rv_dmode    &= ~(0x3 << 6);
@@ -684,6 +684,8 @@ static void sym_set_bus_mode(struct sym_hcb *np, struct sym_nvram *nvram)
  */
 static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, struct sym_nvram *nvram)
 {
+       struct sym_data *sym_data = shost_priv(shost);
+       struct pci_dev *pdev = sym_data->pdev;
        u_char  burst_max;
        u32     period;
        int i;
@@ -778,19 +780,12 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
         *  64 bit addressing  (895A/896/1010) ?
         */
        if (np->features & FE_DAC) {
-#if   SYM_CONF_DMA_ADDRESSING_MODE == 0
-               np->rv_ccntl1   |= (DDAC);
-#elif SYM_CONF_DMA_ADDRESSING_MODE == 1
-               if (!np->use_dac)
-                       np->rv_ccntl1   |= (DDAC);
-               else
-                       np->rv_ccntl1   |= (XTIMOD | EXTIBMV);
-#elif SYM_CONF_DMA_ADDRESSING_MODE == 2
-               if (!np->use_dac)
-                       np->rv_ccntl1   |= (DDAC);
-               else
-                       np->rv_ccntl1   |= (0 | EXTIBMV);
-#endif
+               if (!use_dac(np))
+                       np->rv_ccntl1 |= (DDAC);
+               else if (SYM_CONF_DMA_ADDRESSING_MODE == 1)
+                       np->rv_ccntl1 |= (XTIMOD | EXTIBMV);
+               else if (SYM_CONF_DMA_ADDRESSING_MODE == 2)
+                       np->rv_ccntl1 |= (0 | EXTIBMV);
        }
 
        /*
@@ -804,8 +799,8 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
         *  In dual channel mode, contention occurs if internal cycles
         *  are used. Disable internal cycles.
         */
-       if (np->s.device->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
-           np->s.device->revision < 0x1)
+       if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
+           pdev->revision < 0x1)
                np->rv_ccntl0   |=  DILS;
 
        /*
@@ -828,10 +823,10 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
         *  this driver. The generic ncr driver that does not use 
         *  LOAD/STORE instructions does not need this work-around.
         */
-       if ((np->s.device->device == PCI_DEVICE_ID_NCR_53C810 &&
-            np->s.device->revision >= 0x10 && np->s.device->revision <= 0x11) ||
-           (np->s.device->device == PCI_DEVICE_ID_NCR_53C860 &&
-            np->s.device->revision <= 0x1))
+       if ((pdev->device == PCI_DEVICE_ID_NCR_53C810 &&
+            pdev->revision >= 0x10 && pdev->revision <= 0x11) ||
+           (pdev->device == PCI_DEVICE_ID_NCR_53C860 &&
+            pdev->revision <= 0x1))
                np->features &= ~(FE_WRIE|FE_ERL|FE_ERMP);
 
        /*
@@ -897,7 +892,7 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
        if ((SYM_SETUP_SCSI_LED || 
             (nvram->type == SYM_SYMBIOS_NVRAM ||
              (nvram->type == SYM_TEKRAM_NVRAM &&
-              np->s.device->device == PCI_DEVICE_ID_NCR_53C895))) &&
+              pdev->device == PCI_DEVICE_ID_NCR_53C895))) &&
            !(np->features & FE_LEDC) && !(np->sv_gpcntl & 0x01))
                np->features |= FE_LED0;
 
@@ -1135,8 +1130,9 @@ restart_test:
  *  First 24 register of the chip:
  *     r0..rf
  */
-static void sym_log_hard_error(struct sym_hcb *np, u_short sist, u_char dstat)
+static void sym_log_hard_error(struct Scsi_Host *shost, u_short sist, u_char dstat)
 {
+       struct sym_hcb *np = sym_get_hcb(shost);
        u32     dsp;
        int     script_ofs;
        int     script_size;
@@ -1189,17 +1185,18 @@ static void sym_log_hard_error(struct sym_hcb *np, u_short sist, u_char dstat)
         *  PCI BUS error.
         */
        if (dstat & (MDPE|BF))
-               sym_log_bus_error(np);
+               sym_log_bus_error(shost);
 }
 
-void sym_dump_registers(struct sym_hcb *np)
+void sym_dump_registers(struct Scsi_Host *shost)
 {
+       struct sym_hcb *np = sym_get_hcb(shost);
        u_short sist;
        u_char dstat;
 
        sist = INW(np, nc_sist);
        dstat = INB(np, nc_dstat);
-       sym_log_hard_error(np, sist, dstat);
+       sym_log_hard_error(shost, sist, dstat);
 }
 
 static struct sym_chip sym_dev_table[] = {
@@ -1322,7 +1319,7 @@ int sym_lookup_dmap(struct sym_hcb *np, u32 h, int s)
 {
        int i;
 
-       if (!np->use_dac)
+       if (!use_dac(np))
                goto weird;
 
        /* Look up existing mappings */
@@ -1436,13 +1433,12 @@ static int sym_prepare_nego(struct sym_hcb *np, struct sym_ccb *cp, u_char *msgp
         * Many devices implement PPR in a buggy way, so only use it if we
         * really want to.
         */
-       if (goal->offset &&
-           (goal->iu || goal->dt || goal->qas || (goal->period < 0xa))) {
+       if (goal->renego == NS_PPR || (goal->offset &&
+           (goal->iu || goal->dt || goal->qas || (goal->period < 0xa)))) {
                nego = NS_PPR;
-       } else if (spi_width(starget) != goal->width) {
+       } else if (goal->renego == NS_WIDE || goal->width) {
                nego = NS_WIDE;
-       } else if (spi_period(starget) != goal->period ||
-                  spi_offset(starget) != goal->offset) {
+       } else if (goal->renego == NS_SYNC || goal->offset) {
                nego = NS_SYNC;
        } else {
                goal->check_nego = 0;
@@ -1529,7 +1525,8 @@ void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp)
        np->squeueput = qidx;
 
        if (DEBUG_FLAGS & DEBUG_QUEUE)
-               printf ("%s: queuepos=%d.\n", sym_name (np), np->squeueput);
+               scmd_printk(KERN_DEBUG, cp->cmd, "queuepos=%d\n",
+                                                       np->squeueput);
 
        /*
         *  Script processor may be waiting for reselect.
@@ -1649,7 +1646,7 @@ static void sym_flush_comp_queue(struct sym_hcb *np, int cam_status)
        SYM_QUEHEAD *qp;
        struct sym_ccb *cp;
 
-       while ((qp = sym_remque_head(&np->comp_ccbq)) != 0) {
+       while ((qp = sym_remque_head(&np->comp_ccbq)) != NULL) {
                struct scsi_cmnd *cmd;
                cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
                sym_insque_tail(&cp->link_ccbq, &np->busy_ccbq);
@@ -1706,8 +1703,11 @@ static void sym_flush_busy_queue (struct sym_hcb *np, int cam_status)
  *     1: SCSI BUS RESET delivered or received.
  *     2: SCSI BUS MODE changed.
  */
-void sym_start_up (struct sym_hcb *np, int reason)
+void sym_start_up(struct Scsi_Host *shost, int reason)
 {
+       struct sym_data *sym_data = shost_priv(shost);
+       struct pci_dev *pdev = sym_data->pdev;
+       struct sym_hcb *np = sym_data->ncb;
        int     i;
        u32     phys;
 
@@ -1756,7 +1756,7 @@ void sym_start_up (struct sym_hcb *np, int reason)
         *  This also let point to first position the start 
         *  and done queue pointers used from SCRIPTS.
         */
-       np->fw_patch(np);
+       np->fw_patch(shost);
 
        /*
         *  Wakeup all pending jobs.
@@ -1798,7 +1798,7 @@ void sym_start_up (struct sym_hcb *np, int reason)
        /*
         *  For now, disable AIP generation on C1010-66.
         */
-       if (np->s.device->device == PCI_DEVICE_ID_LSI_53C1010_66)
+       if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_66)
                OUTB(np, nc_aipcntl1, DISAIP);
 
        /*
@@ -1808,8 +1808,8 @@ void sym_start_up (struct sym_hcb *np, int reason)
         *  that from SCRIPTS for each selection/reselection, but 
         *  I just don't want. :)
         */
-       if (np->s.device->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
-           np->s.device->revision < 1)
+       if (pdev->device == PCI_DEVICE_ID_LSI_53C1010_33 &&
+           pdev->revision < 1)
                OUTB(np, nc_stest1, INB(np, nc_stest1) | 0x30);
 
        /*
@@ -1817,9 +1817,9 @@ void sym_start_up (struct sym_hcb *np, int reason)
         *  Disable overlapped arbitration for some dual function devices, 
         *  regardless revision id (kind of post-chip-design feature. ;-))
         */
-       if (np->s.device->device == PCI_DEVICE_ID_NCR_53C875)
+       if (pdev->device == PCI_DEVICE_ID_NCR_53C875)
                OUTB(np, nc_ctest0, (1<<5));
-       else if (np->s.device->device == PCI_DEVICE_ID_NCR_53C896)
+       else if (pdev->device == PCI_DEVICE_ID_NCR_53C896)
                np->rv_ccntl0 |= DPR;
 
        /*
@@ -1837,7 +1837,7 @@ void sym_start_up (struct sym_hcb *np, int reason)
         *  Set up scratch C and DRS IO registers to map the 32 bit 
         *  DMA address range our data structures are located in.
         */
-       if (np->use_dac) {
+       if (use_dac(np)) {
                np->dmap_bah[0] = 0;    /* ??? */
                OUTL(np, nc_scrx[0], np->dmap_bah[0]);
                OUTL(np, nc_drs, np->dmap_bah[0]);
@@ -1896,6 +1896,15 @@ void sym_start_up (struct sym_hcb *np, int reason)
                tp->head.sval = 0;
                tp->head.wval = np->rv_scntl3;
                tp->head.uval = 0;
+               if (tp->lun0p)
+                       tp->lun0p->to_clear = 0;
+               if (tp->lunmp) {
+                       int ln;
+
+                       for (ln = 1; ln < SYM_CONF_MAX_LUN; ln++)
+                               if (tp->lunmp[ln])
+                                       tp->lunmp[ln]->to_clear = 0;
+               }
        }
 
        /*
@@ -2039,6 +2048,29 @@ static void sym_settrans(struct sym_hcb *np, int target, u_char opts, u_char ofs
        }
 }
 
+static void sym_announce_transfer_rate(struct sym_tcb *tp)
+{
+       struct scsi_target *starget = tp->starget;
+
+       if (tp->tprint.period != spi_period(starget) ||
+           tp->tprint.offset != spi_offset(starget) ||
+           tp->tprint.width != spi_width(starget) ||
+           tp->tprint.iu != spi_iu(starget) ||
+           tp->tprint.dt != spi_dt(starget) ||
+           tp->tprint.qas != spi_qas(starget) ||
+           !tp->tprint.check_nego) {
+               tp->tprint.period = spi_period(starget);
+               tp->tprint.offset = spi_offset(starget);
+               tp->tprint.width = spi_width(starget);
+               tp->tprint.iu = spi_iu(starget);
+               tp->tprint.dt = spi_dt(starget);
+               tp->tprint.qas = spi_qas(starget);
+               tp->tprint.check_nego = 1;
+
+               spi_display_xfer_agreement(starget);
+       }
+}
+
 /*
  *  We received a WDTR.
  *  Let everything be aware of the changes.
@@ -2048,11 +2080,13 @@ static void sym_setwide(struct sym_hcb *np, int target, u_char wide)
        struct sym_tcb *tp = &np->target[target];
        struct scsi_target *starget = tp->starget;
 
-       if (spi_width(starget) == wide)
-               return;
-
        sym_settrans(np, target, 0, 0, 0, wide, 0, 0);
 
+       if (wide)
+               tp->tgoal.renego = NS_WIDE;
+       else
+               tp->tgoal.renego = 0;
+       tp->tgoal.check_nego = 0;
        tp->tgoal.width = wide;
        spi_offset(starget) = 0;
        spi_period(starget) = 0;
@@ -2062,7 +2096,7 @@ static void sym_setwide(struct sym_hcb *np, int target, u_char wide)
        spi_qas(starget) = 0;
 
        if (sym_verbose >= 3)
-               spi_display_xfer_agreement(starget);
+               sym_announce_transfer_rate(tp);
 }
 
 /*
@@ -2079,6 +2113,12 @@ sym_setsync(struct sym_hcb *np, int target,
 
        sym_settrans(np, target, 0, ofs, per, wide, div, fak);
 
+       if (wide)
+               tp->tgoal.renego = NS_WIDE;
+       else if (ofs)
+               tp->tgoal.renego = NS_SYNC;
+       else
+               tp->tgoal.renego = 0;
        spi_period(starget) = per;
        spi_offset(starget) = ofs;
        spi_iu(starget) = spi_dt(starget) = spi_qas(starget) = 0;
@@ -2089,7 +2129,7 @@ sym_setsync(struct sym_hcb *np, int target,
                tp->tgoal.check_nego = 0;
        }
 
-       spi_display_xfer_agreement(starget);
+       sym_announce_transfer_rate(tp);
 }
 
 /*
@@ -2105,6 +2145,10 @@ sym_setpprot(struct sym_hcb *np, int target, u_char opts, u_char ofs,
 
        sym_settrans(np, target, opts, ofs, per, wide, div, fak);
 
+       if (wide || ofs)
+               tp->tgoal.renego = NS_PPR;
+       else
+               tp->tgoal.renego = 0;
        spi_width(starget) = tp->tgoal.width = wide;
        spi_period(starget) = tp->tgoal.period = per;
        spi_offset(starget) = tp->tgoal.offset = ofs;
@@ -2113,7 +2157,7 @@ sym_setpprot(struct sym_hcb *np, int target, u_char opts, u_char ofs,
        spi_qas(starget) = tp->tgoal.qas = !!(opts & PPR_OPT_QAS);
        tp->tgoal.check_nego = 0;
 
-       spi_display_xfer_agreement(starget);
+       sym_announce_transfer_rate(tp);
 }
 
 /*
@@ -2224,8 +2268,9 @@ static void sym_int_udc (struct sym_hcb *np)
  *  mode to eight bit asynchronous, etc...
  *  So, just reinitializing all except chip should be enough.
  */
-static void sym_int_sbmc (struct sym_hcb *np)
+static void sym_int_sbmc(struct Scsi_Host *shost)
 {
+       struct sym_hcb *np = sym_get_hcb(shost);
        u_char scsi_mode = INB(np, nc_stest4) & SMODE;
 
        /*
@@ -2238,7 +2283,7 @@ static void sym_int_sbmc (struct sym_hcb *np)
         *  Should suspend command processing for a few seconds and 
         *  reinitialize all except the chip.
         */
-       sym_start_up (np, 2);
+       sym_start_up(shost, 2);
 }
 
 /*
@@ -2276,8 +2321,9 @@ static void sym_int_par (struct sym_hcb *np, u_short sist)
        int phase       = cmd & 7;
        struct sym_ccb *cp      = sym_ccb_from_dsa(np, dsa);
 
-       printf("%s: SCSI parity error detected: SCR1=%d DBC=%x SBCL=%x\n",
-               sym_name(np), hsts, dbc, sbcl);
+       if (printk_ratelimit())
+               printf("%s: SCSI parity error detected: SCR1=%d DBC=%x SBCL=%x\n",
+                       sym_name(np), hsts, dbc, sbcl);
 
        /*
         *  Check that the chip is connected to the SCSI BUS.
@@ -2646,7 +2692,7 @@ static void sym_int_ma (struct sym_hcb *np)
         *  we force a SIR_NEGO_PROTO interrupt (it is a hack that avoids 
         *  bloat for such a should_not_happen situation).
         *  In all other situation, we reset the BUS.
-        *  Are these assumptions reasonnable ? (Wait and see ...)
+        *  Are these assumptions reasonable ? (Wait and see ...)
         */
 unexpected_phase:
        dsp -= 8;
@@ -2766,8 +2812,11 @@ reset_all:
  *  Use at your own decision and risk.
  */
 
-void sym_interrupt (struct sym_hcb *np)
+irqreturn_t sym_interrupt(struct Scsi_Host *shost)
 {
+       struct sym_data *sym_data = shost_priv(shost);
+       struct sym_hcb *np = sym_data->ncb;
+       struct pci_dev *pdev = sym_data->pdev;
        u_char  istat, istatc;
        u_char  dstat;
        u_short sist;
@@ -2786,13 +2835,13 @@ void sym_interrupt (struct sym_hcb *np)
        istat = INB(np, nc_istat);
        if (istat & INTF) {
                OUTB(np, nc_istat, (istat & SIGP) | INTF | np->istat_sem);
-               istat = INB(np, nc_istat);              /* DUMMY READ */
+               istat |= INB(np, nc_istat);             /* DUMMY READ */
                if (DEBUG_FLAGS & DEBUG_TINY) printf ("F ");
                sym_wakeup_done(np);
        }
 
        if (!(istat & (SIP|DIP)))
-               return;
+               return (istat & INTF) ? IRQ_HANDLED : IRQ_NONE;
 
 #if 0  /* We should never get this one */
        if (istat & CABRT)
@@ -2823,8 +2872,8 @@ void sym_interrupt (struct sym_hcb *np)
                /* Prevent deadlock waiting on a condition that may
                 * never clear. */
                if (unlikely(sist == 0xffff && dstat == 0xff)) {
-                       if (pci_channel_offline(np->s.device))
-                               return;
+                       if (pci_channel_offline(pdev))
+                               return IRQ_NONE;
                }
        } while (istatc & (SIP|DIP));
 
@@ -2859,10 +2908,10 @@ void sym_interrupt (struct sym_hcb *np)
            !(dstat & (MDPE|BF|ABRT|IID))) {
                if      (sist & PAR)    sym_int_par (np, sist);
                else if (sist & MA)     sym_int_ma (np);
-               else if (dstat & SIR)   sym_int_sir (np);
+               else if (dstat & SIR)   sym_int_sir(np);
                else if (dstat & SSI)   OUTONB_STD();
                else                    goto unknown_int;
-               return;
+               return IRQ_HANDLED;
        }
 
        /*
@@ -2878,8 +2927,8 @@ void sym_interrupt (struct sym_hcb *np)
         */
        if (sist & RST) {
                printf("%s: SCSI BUS reset detected.\n", sym_name(np));
-               sym_start_up (np, 1);
-               return;
+               sym_start_up(shost, 1);
+               return IRQ_HANDLED;
        }
 
        OUTB(np, nc_ctest3, np->rv_ctest3 | CLF);       /* clear dma fifo  */
@@ -2887,11 +2936,11 @@ void sym_interrupt (struct sym_hcb *np)
 
        if (!(sist  & (GEN|HTH|SGE)) &&
            !(dstat & (MDPE|BF|ABRT|IID))) {
-               if      (sist & SBMC)   sym_int_sbmc (np);
+               if      (sist & SBMC)   sym_int_sbmc(shost);
                else if (sist & STO)    sym_int_sto (np);
                else if (sist & UDC)    sym_int_udc (np);
                else                    goto unknown_int;
-               return;
+               return IRQ_HANDLED;
        }
 
        /*
@@ -2901,12 +2950,12 @@ void sym_interrupt (struct sym_hcb *np)
         *  Reset everything.
         */
 
-       sym_log_hard_error(np, sist, dstat);
+       sym_log_hard_error(shost, sist, dstat);
 
        if ((sist & (GEN|HTH|SGE)) ||
                (dstat & (MDPE|BF|ABRT|IID))) {
                sym_start_reset(np);
-               return;
+               return IRQ_HANDLED;
        }
 
 unknown_int:
@@ -2917,6 +2966,7 @@ unknown_int:
        printf( "%s: unknown interrupt(s) ignored, "
                "ISTAT=0x%x DSTAT=0x%x SIST=0x%x\n",
                sym_name(np), istat, dstat, sist);
+       return IRQ_NONE;
 }
 
 /*
@@ -3162,7 +3212,7 @@ int sym_clear_tasks(struct sym_hcb *np, int cam_status, int target, int lun, int
         *  the COMP queue and put back other ones into 
         *  the BUSY queue.
         */
-       while ((qp = sym_remque_head(&qtmp)) != 0) {
+       while ((qp = sym_remque_head(&qtmp)) != NULL) {
                struct scsi_cmnd *cmd;
                cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
                cmd = cp->cmd;
@@ -3510,6 +3560,7 @@ static void sym_sir_task_recovery(struct sym_hcb *np, int num)
                        spi_dt(starget) = 0;
                        spi_qas(starget) = 0;
                        tp->tgoal.check_nego = 1;
+                       tp->tgoal.renego = 0;
                }
 
                /*
@@ -3537,7 +3588,8 @@ static void sym_sir_task_recovery(struct sym_hcb *np, int num)
                 *  If we sent a BDR, make upper layer aware of that.
                 */
                if (np->abrt_msg[0] == M_RESET)
-                       sym_xpt_async_sent_bdr(np, target);
+                       starget_printk(KERN_NOTICE, starget,
+                                                       "has been reset\n");
                break;
        }
 
@@ -3835,7 +3887,7 @@ int sym_compute_residual(struct sym_hcb *np, struct sym_ccb *cp)
        if (cp->startp == cp->phys.head.lastp ||
            sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp),
                            &dp_ofs) < 0) {
-               return cp->data_len;
+               return cp->data_len - cp->odd_byte_adjustment;
        }
 
        /*
@@ -4321,7 +4373,7 @@ static void sym_nego_rejected(struct sym_hcb *np, struct sym_tcb *tp, struct sym
 /*
  *  chip exception handler for programmed interrupts.
  */
-static void sym_int_sir (struct sym_hcb *np)
+static void sym_int_sir(struct sym_hcb *np)
 {
        u_char  num     = INB(np, nc_dsps);
        u32     dsa     = INL(np, nc_dsa);
@@ -4360,31 +4412,30 @@ static void sym_int_sir (struct sym_hcb *np)
                return;
        /*
         *  The device didn't go to MSG OUT phase after having 
-        *  been selected with ATN. We donnot want to handle 
-        *  that.
+        *  been selected with ATN.  We do not want to handle that.
         */
        case SIR_SEL_ATN_NO_MSG_OUT:
-               printf ("%s:%d: No MSG OUT phase after selection with ATN.\n",
-                       sym_name (np), target);
+               scmd_printk(KERN_WARNING, cp->cmd,
+                               "No MSG OUT phase after selection with ATN\n");
                goto out_stuck;
        /*
         *  The device didn't switch to MSG IN phase after 
-        *  having reseleted the initiator.
+        *  having reselected the initiator.
         */
        case SIR_RESEL_NO_MSG_IN:
-               printf ("%s:%d: No MSG IN phase after reselection.\n",
-                       sym_name (np), target);
+               scmd_printk(KERN_WARNING, cp->cmd,
+                               "No MSG IN phase after reselection\n");
                goto out_stuck;
        /*
         *  After reselection, the device sent a message that wasn't 
         *  an IDENTIFY.
         */
        case SIR_RESEL_NO_IDENTIFY:
-               printf ("%s:%d: No IDENTIFY after reselection.\n",
-                       sym_name (np), target);
+               scmd_printk(KERN_WARNING, cp->cmd,
+                               "No IDENTIFY after reselection\n");
                goto out_stuck;
        /*
-        *  The device reselected a LUN we donnot know about.
+        *  The device reselected a LUN we do not know about.
         */
        case SIR_RESEL_BAD_LUN:
                np->msgout[0] = M_RESET;
@@ -4397,8 +4448,7 @@ static void sym_int_sir (struct sym_hcb *np)
                np->msgout[0] = M_ABORT;
                goto out;
        /*
-        *  The device reselected for a tagged nexus that we donnot 
-        *  have.
+        * The device reselected for a tagged nexus that we do not have.
         */
        case SIR_RESEL_BAD_I_T_L_Q:
                np->msgout[0] = M_ABORT_TAG;
@@ -4410,8 +4460,8 @@ static void sym_int_sir (struct sym_hcb *np)
        case SIR_RESEL_ABORTED:
                np->lastmsg = np->msgout[0];
                np->msgout[0] = M_NOOP;
-               printf ("%s:%d: message %x sent on bad reselection.\n",
-                       sym_name (np), target, np->lastmsg);
+               scmd_printk(KERN_WARNING, cp->cmd,
+                       "message %x sent on bad reselection\n", np->lastmsg);
                goto out;
        /*
         *  The SCRIPTS let us know that a message has been 
@@ -4948,7 +4998,7 @@ struct sym_lcb *sym_alloc_lcb (struct sym_hcb *np, u_char tn, u_char ln)
         */
        if (ln && !tp->lunmp) {
                tp->lunmp = kcalloc(SYM_CONF_MAX_LUN, sizeof(struct sym_lcb *),
-                               GFP_KERNEL);
+                               GFP_ATOMIC);
                if (!tp->lunmp)
                        goto fail;
        }
@@ -4968,6 +5018,7 @@ struct sym_lcb *sym_alloc_lcb (struct sym_hcb *np, u_char tn, u_char ln)
                tp->lun0p = lp;
                tp->head.lun0_sa = cpu_to_scr(vtobus(lp));
        }
+       tp->nlcb++;
 
        /*
         *  Let the itl task point to error handling.
@@ -5045,6 +5096,43 @@ fail:
 }
 
 /*
+ *  Lun control block deallocation. Returns the number of valid remaing LCBs
+ *  for the target.
+ */
+int sym_free_lcb(struct sym_hcb *np, u_char tn, u_char ln)
+{
+       struct sym_tcb *tp = &np->target[tn];
+       struct sym_lcb *lp = sym_lp(tp, ln);
+
+       tp->nlcb--;
+
+       if (ln) {
+               if (!tp->nlcb) {
+                       kfree(tp->lunmp);
+                       sym_mfree_dma(tp->luntbl, 256, "LUNTBL");
+                       tp->lunmp = NULL;
+                       tp->luntbl = NULL;
+                       tp->head.luntbl_sa = cpu_to_scr(vtobus(np->badluntbl));
+               } else {
+                       tp->luntbl[ln] = cpu_to_scr(vtobus(&np->badlun_sa));
+                       tp->lunmp[ln] = NULL;
+               }
+       } else {
+               tp->lun0p = NULL;
+               tp->head.lun0_sa = cpu_to_scr(vtobus(&np->badlun_sa));
+       }
+
+       if (lp->itlq_tbl) {
+               sym_mfree_dma(lp->itlq_tbl, SYM_CONF_MAX_TASK*4, "ITLQ_TBL");
+               kfree(lp->cb_tags);
+       }
+
+       sym_mfree_dma(lp, sizeof(*lp), "LCB");
+
+       return tp->nlcb;
+}
+
+/*
  *  Queue a SCSI IO to the controller.
  */
 int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
@@ -5130,9 +5218,14 @@ int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *
        /*
         *  Build a negotiation message if needed.
         *  (nego_status is filled by sym_prepare_nego())
+        *
+        *  Always negotiate on INQUIRY and REQUEST SENSE.
+        *
         */
        cp->nego_status = 0;
-       if (tp->tgoal.check_nego && !tp->nego_cp && lp) {
+       if ((tp->tgoal.check_nego ||
+            cmd->cmnd[0] == INQUIRY || cmd->cmnd[0] == REQUEST_SENSE) &&
+           !tp->nego_cp && lp) {
                msglen += sym_prepare_nego(np, cp, msgptr + msglen);
        }
 
@@ -5724,7 +5817,7 @@ void sym_hcb_free(struct sym_hcb *np)
                sym_mfree_dma(np->dqueue, sizeof(u32)*(MAX_QUEUE*2), "DQUEUE");
 
        if (np->actccbs) {
-               while ((qp = sym_remque_head(&np->free_ccbq)) != 0) {
+               while ((qp = sym_remque_head(&np->free_ccbq)) != NULL) {
                        cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
                        sym_mfree_dma(cp, sizeof(*cp), "CCB");
                }
@@ -5736,6 +5829,8 @@ void sym_hcb_free(struct sym_hcb *np)
 
        for (target = 0; target < SYM_CONF_MAX_TARGET ; target++) {
                tp = &np->target[target];
+               if (tp->luntbl)
+                       sym_mfree_dma(tp->luntbl, 256, "LUNTBL");
 #if SYM_CONF_MAX_LUN > 1
                kfree(tp->lunmp);
 #endif