Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / scsi / sym53c8xx_2 / sym_nvram.c
index cfaa02c..15d6929 100644 (file)
  *
  *-----------------------------------------------------------------------------
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
+ * 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.
  *
- * Where this Software is combined with software released under the terms of 
- * the GNU Public License ("GPL") and the terms of the GPL would require the 
- * combined work to also be released under the terms of the GPL, the terms
- * and conditions of this License will apply in addition to those of the
- * GPL with the exception of any terms or conditions of this License that
- * conflict with, or are expressly prohibited by, the GPL.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "sym_glue.h"
 #include "sym_nvram.h"
 
-/*
- *  Some poor and bogus sync table that refers to Tekram NVRAM layout.
- */
-static u_char Tekram_sync[16] =
-       {25,31,37,43, 50,62,75,125, 12,15,18,21, 6,7,9,10};
 #ifdef SYM_CONF_DEBUG_NVRAM
 static u_char Tekram_boot_delay[7] = {3, 5, 10, 20, 30, 60, 120};
 #endif
@@ -65,7 +47,7 @@ static u_char Tekram_boot_delay[7] = {3, 5, 10, 20, 30, 60, 120};
 /*
  *  Get host setup from NVRAM.
  */
-void sym_nvram_setup_host(struct sym_hcb *np, struct sym_nvram *nvram)
+void sym_nvram_setup_host(struct Scsi_Host *shost, struct sym_hcb *np, struct sym_nvram *nvram)
 {
        /*
         *  Get parity checking, host ID, verbose mode 
@@ -79,13 +61,28 @@ void sym_nvram_setup_host(struct sym_hcb *np, struct sym_nvram *nvram)
                if (nvram->data.Symbios.flags & SYMBIOS_VERBOSE_MSGS)
                        np->verbose += 1;
                if (nvram->data.Symbios.flags1 & SYMBIOS_SCAN_HI_LO)
-                       np->usrflags |= SYM_SCAN_TARGETS_HILO;
+                       shost->reverse_ordering = 1;
                if (nvram->data.Symbios.flags2 & SYMBIOS_AVOID_BUS_RESET)
                        np->usrflags |= SYM_AVOID_BUS_RESET;
                break;
        case SYM_TEKRAM_NVRAM:
                np->myaddr = nvram->data.Tekram.host_id & 0x0f;
                break;
+#ifdef CONFIG_PARISC
+       case SYM_PARISC_PDC:
+               if (nvram->data.parisc.host_id != -1)
+                       np->myaddr = nvram->data.parisc.host_id;
+               if (nvram->data.parisc.factor != -1)
+                       np->minsync = nvram->data.parisc.factor;
+               if (nvram->data.parisc.width != -1)
+                       np->maxwide = nvram->data.parisc.width;
+               switch (nvram->data.parisc.mode) {
+                       case 0: np->scsi_mode = SMODE_SE; break;
+                       case 1: np->scsi_mode = SMODE_HVD; break;
+                       case 2: np->scsi_mode = SMODE_LVD; break;
+                       default: break;
+               }
+#endif
        default:
                break;
        }
@@ -95,41 +92,33 @@ void sym_nvram_setup_host(struct sym_hcb *np, struct sym_nvram *nvram)
  *  Get target set-up from Symbios format NVRAM.
  */
 static void
-sym_Symbios_setup_target(struct sym_hcb *np, int target, Symbios_nvram *nvram)
+sym_Symbios_setup_target(struct sym_tcb *tp, int target, Symbios_nvram *nvram)
 {
-       struct sym_tcb *tp = &np->target[target];
        Symbios_target *tn = &nvram->target[target];
 
-       tp->tinfo.user.period = tn->sync_period ? (tn->sync_period + 3) / 4 : 0;
-       tp->tinfo.user.width  = tn->bus_width == 0x10 ? BUS_16_BIT : BUS_8_BIT;
-       tp->usrtags =
-               (tn->flags & SYMBIOS_QUEUE_TAGS_ENABLED)? SYM_SETUP_MAX_TAG : 0;
-
+       if (!(tn->flags & SYMBIOS_QUEUE_TAGS_ENABLED))
+               tp->usrtags = 0;
        if (!(tn->flags & SYMBIOS_DISCONNECT_ENABLE))
                tp->usrflags &= ~SYM_DISC_ENABLED;
        if (!(tn->flags & SYMBIOS_SCAN_AT_BOOT_TIME))
                tp->usrflags |= SYM_SCAN_BOOT_DISABLED;
        if (!(tn->flags & SYMBIOS_SCAN_LUNS))
                tp->usrflags |= SYM_SCAN_LUNS_DISABLED;
+       tp->usr_period = (tn->sync_period + 3) / 4;
+       tp->usr_width = (tn->bus_width == 0x8) ? 0 : 1;
 }
 
+static const unsigned char Tekram_sync[16] = {
+       25, 31, 37, 43, 50, 62, 75, 125, 12, 15, 18, 21, 6, 7, 9, 10
+};
+
 /*
  *  Get target set-up from Tekram format NVRAM.
  */
 static void
-sym_Tekram_setup_target(struct sym_hcb *np, int target, Tekram_nvram *nvram)
+sym_Tekram_setup_target(struct sym_tcb *tp, int target, Tekram_nvram *nvram)
 {
-       struct sym_tcb *tp = &np->target[target];
        struct Tekram_target *tn = &nvram->target[target];
-       int i;
-
-       if (tn->flags & TEKRAM_SYNC_NEGO) {
-               i = tn->sync_index & 0xf;
-               tp->tinfo.user.period = Tekram_sync[i];
-       }
-
-       tp->tinfo.user.width = (tn->flags & TEKRAM_WIDE_NEGO) ?
-               BUS_16_BIT : BUS_8_BIT;
 
        if (tn->flags & TEKRAM_TAGGED_COMMANDS) {
                tp->usrtags = 2 << nvram->max_tags_index;
@@ -138,22 +127,22 @@ sym_Tekram_setup_target(struct sym_hcb *np, int target, Tekram_nvram *nvram)
        if (tn->flags & TEKRAM_DISCONNECT_ENABLE)
                tp->usrflags |= SYM_DISC_ENABLED;
  
-       /* If any device does not support parity, we will not use this option */
-       if (!(tn->flags & TEKRAM_PARITY_CHECK))
-               np->rv_scntl0  &= ~0x0a; /* SCSI parity checking disabled */
+       if (tn->flags & TEKRAM_SYNC_NEGO)
+               tp->usr_period = Tekram_sync[tn->sync_index & 0xf];
+       tp->usr_width = (tn->flags & TEKRAM_WIDE_NEGO) ? 1 : 0;
 }
 
 /*
  *  Get target setup from NVRAM.
  */
-void sym_nvram_setup_target(struct sym_hcb *np, int target, struct sym_nvram *nvp)
+void sym_nvram_setup_target(struct sym_tcb *tp, int target, struct sym_nvram *nvp)
 {
        switch (nvp->type) {
        case SYM_SYMBIOS_NVRAM:
-               sym_Symbios_setup_target(np, target, &nvp->data.Symbios);
+               sym_Symbios_setup_target(tp, target, &nvp->data.Symbios);
                break;
        case SYM_TEKRAM_NVRAM:
-               sym_Tekram_setup_target(np, target, &nvp->data.Tekram);
+               sym_Tekram_setup_target(tp, target, &nvp->data.Tekram);
                break;
        default:
                break;
@@ -267,7 +256,7 @@ static void sym_display_Tekram_nvram(struct sym_device *np, Tekram_nvram *nvram)
 static void S24C16_set_bit(struct sym_device *np, u_char write_bit, u_char *gpreg, 
                          int bit_mode)
 {
-       UDELAY (5);
+       udelay(5);
        switch (bit_mode) {
        case SET_BIT:
                *gpreg |= write_bit;
@@ -283,8 +272,9 @@ static void S24C16_set_bit(struct sym_device *np, u_char write_bit, u_char *gpre
                break;
 
        }
-       OUTB (nc_gpreg, *gpreg);
-       UDELAY (5);
+       OUTB(np, nc_gpreg, *gpreg);
+       INB(np, nc_mbox1);
+       udelay(5);
 }
 
 /*
@@ -317,7 +307,7 @@ static void S24C16_do_bit(struct sym_device *np, u_char *read_bit, u_char write_
        S24C16_set_bit(np, write_bit, gpreg, SET_BIT);
        S24C16_set_bit(np, 0, gpreg, SET_CLK);
        if (read_bit)
-               *read_bit = INB (nc_gpreg);
+               *read_bit = INB(np, nc_gpreg);
        S24C16_set_bit(np, 0, gpreg, CLR_CLK);
        S24C16_set_bit(np, 0, gpreg, CLR_BIT);
 }
@@ -329,9 +319,9 @@ static void S24C16_do_bit(struct sym_device *np, u_char *read_bit, u_char write_
 static void S24C16_write_ack(struct sym_device *np, u_char write_bit, u_char *gpreg, 
                            u_char *gpcntl)
 {
-       OUTB (nc_gpcntl, *gpcntl & 0xfe);
-       S24C16_do_bit(np, 0, write_bit, gpreg);
-       OUTB (nc_gpcntl, *gpcntl);
+       OUTB(np, nc_gpcntl, *gpcntl & 0xfe);
+       S24C16_do_bit(np, NULL, write_bit, gpreg);
+       OUTB(np, nc_gpcntl, *gpcntl);
 }
 
 /*
@@ -341,9 +331,9 @@ static void S24C16_write_ack(struct sym_device *np, u_char write_bit, u_char *gp
 static void S24C16_read_ack(struct sym_device *np, u_char *read_bit, u_char *gpreg, 
                           u_char *gpcntl)
 {
-       OUTB (nc_gpcntl, *gpcntl | 0x01);
+       OUTB(np, nc_gpcntl, *gpcntl | 0x01);
        S24C16_do_bit(np, read_bit, 1, gpreg);
-       OUTB (nc_gpcntl, *gpcntl);
+       OUTB(np, nc_gpcntl, *gpcntl);
 }
 
 /*
@@ -356,7 +346,7 @@ static void S24C16_write_byte(struct sym_device *np, u_char *ack_data, u_char wr
        int x;
        
        for (x = 0; x < 8; x++)
-               S24C16_do_bit(np, 0, (write_data >> (7 - x)) & 0x01, gpreg);
+               S24C16_do_bit(np, NULL, (write_data >> (7 - x)) & 0x01, gpreg);
                
        S24C16_read_ack(np, ack_data, gpreg, gpcntl);
 }
@@ -380,7 +370,7 @@ static void S24C16_read_byte(struct sym_device *np, u_char *read_data, u_char ac
        S24C16_write_ack(np, ack_data, gpreg, gpcntl);
 }
 
-#if SYM_CONF_NVRAM_WRITE_SUPPORT
+#ifdef SYM_CONF_NVRAM_WRITE_SUPPORT
 /*
  *  Write 'len' bytes starting at 'offset'.
  */
@@ -393,13 +383,13 @@ static int sym_write_S24C16_nvram(struct sym_device *np, int offset,
        int     x;
 
        /* save current state of GPCNTL and GPREG */
-       old_gpreg       = INB (nc_gpreg);
-       old_gpcntl      = INB (nc_gpcntl);
+       old_gpreg       = INB(np, nc_gpreg);
+       old_gpcntl      = INB(np, nc_gpcntl);
        gpcntl          = old_gpcntl & 0x1c;
 
        /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
-       OUTB (nc_gpreg,  old_gpreg);
-       OUTB (nc_gpcntl, gpcntl);
+       OUTB(np, nc_gpreg,  old_gpreg);
+       OUTB(np, nc_gpcntl, gpcntl);
 
        /* this is to set NVRAM into a known state with GPIO0/1 both low */
        gpreg = old_gpreg;
@@ -428,8 +418,8 @@ static int sym_write_S24C16_nvram(struct sym_device *np, int offset,
        }
 
        /* return GPIO0/1 to original states after having accessed NVRAM */
-       OUTB (nc_gpcntl, old_gpcntl);
-       OUTB (nc_gpreg,  old_gpreg);
+       OUTB(np, nc_gpcntl, old_gpcntl);
+       OUTB(np, nc_gpreg,  old_gpreg);
 
        return 0;
 }
@@ -447,13 +437,13 @@ static int sym_read_S24C16_nvram(struct sym_device *np, int offset, u_char *data
        int     x;
 
        /* save current state of GPCNTL and GPREG */
-       old_gpreg       = INB (nc_gpreg);
-       old_gpcntl      = INB (nc_gpcntl);
+       old_gpreg       = INB(np, nc_gpreg);
+       old_gpcntl      = INB(np, nc_gpcntl);
        gpcntl          = old_gpcntl & 0x1c;
 
        /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
-       OUTB (nc_gpreg,  old_gpreg);
-       OUTB (nc_gpcntl, gpcntl);
+       OUTB(np, nc_gpreg,  old_gpreg);
+       OUTB(np, nc_gpcntl, gpcntl);
 
        /* this is to set NVRAM into a known state with GPIO0/1 both low */
        gpreg = old_gpreg;
@@ -489,7 +479,7 @@ static int sym_read_S24C16_nvram(struct sym_device *np, int offset, u_char *data
 
        /* now set up GPIO0 for inputting data */
        gpcntl |= 0x01;
-       OUTB (nc_gpcntl, gpcntl);
+       OUTB(np, nc_gpcntl, gpcntl);
                
        /* input all requested data - only part of total NVRAM */
        for (x = 0; x < len; x++) 
@@ -497,13 +487,13 @@ static int sym_read_S24C16_nvram(struct sym_device *np, int offset, u_char *data
 
        /* finally put NVRAM back in inactive mode */
        gpcntl &= 0xfe;
-       OUTB (nc_gpcntl, gpcntl);
+       OUTB(np, nc_gpcntl, gpcntl);
        S24C16_stop(np, &gpreg);
        retv = 0;
 out:
        /* return GPIO0/1 to original states after having accessed NVRAM */
-       OUTB (nc_gpcntl, old_gpcntl);
-       OUTB (nc_gpreg,  old_gpreg);
+       OUTB(np, nc_gpcntl, old_gpcntl);
+       OUTB(np, nc_gpreg,  old_gpreg);
 
        return retv;
 }
@@ -560,9 +550,10 @@ static int sym_read_Symbios_nvram(struct sym_device *np, Symbios_nvram *nvram)
  */
 static void T93C46_Clk(struct sym_device *np, u_char *gpreg)
 {
-       OUTB (nc_gpreg, *gpreg | 0x04);
-       UDELAY (2);
-       OUTB (nc_gpreg, *gpreg);
+       OUTB(np, nc_gpreg, *gpreg | 0x04);
+       INB(np, nc_mbox1);
+       udelay(2);
+       OUTB(np, nc_gpreg, *gpreg);
 }
 
 /* 
@@ -570,9 +561,9 @@ static void T93C46_Clk(struct sym_device *np, u_char *gpreg)
  */
 static void T93C46_Read_Bit(struct sym_device *np, u_char *read_bit, u_char *gpreg)
 {
-       UDELAY (2);
+       udelay(2);
        T93C46_Clk(np, gpreg);
-       *read_bit = INB (nc_gpreg);
+       *read_bit = INB(np, nc_gpreg);
 }
 
 /*
@@ -587,8 +578,9 @@ static void T93C46_Write_Bit(struct sym_device *np, u_char write_bit, u_char *gp
                
        *gpreg |= 0x10;
                
-       OUTB (nc_gpreg, *gpreg);
-       UDELAY (2);
+       OUTB(np, nc_gpreg, *gpreg);
+       INB(np, nc_mbox1);
+       udelay(2);
 
        T93C46_Clk(np, gpreg);
 }
@@ -599,8 +591,9 @@ static void T93C46_Write_Bit(struct sym_device *np, u_char write_bit, u_char *gp
 static void T93C46_Stop(struct sym_device *np, u_char *gpreg)
 {
        *gpreg &= 0xef;
-       OUTB (nc_gpreg, *gpreg);
-       UDELAY (2);
+       OUTB(np, nc_gpreg, *gpreg);
+       INB(np, nc_mbox1);
+       udelay(2);
 
        T93C46_Clk(np, gpreg);
 }
@@ -617,7 +610,7 @@ static void T93C46_Send_Command(struct sym_device *np, u_short write_data,
        for (x = 0; x < 9; x++)
                T93C46_Write_Bit(np, (u_char) (write_data >> (8 - x)), gpreg);
 
-       *read_bit = INB (nc_gpreg);
+       *read_bit = INB(np, nc_gpreg);
 }
 
 /*
@@ -671,23 +664,23 @@ static int sym_read_T93C46_nvram(struct sym_device *np, Tekram_nvram *nvram)
        int retv = 1;
 
        /* save current state of GPCNTL and GPREG */
-       old_gpreg       = INB (nc_gpreg);
-       old_gpcntl      = INB (nc_gpcntl);
+       old_gpreg       = INB(np, nc_gpreg);
+       old_gpcntl      = INB(np, nc_gpcntl);
 
        /* set up GPREG & GPCNTL to set GPIO0/1/2/4 in to known state, 0 in,
           1/2/4 out */
        gpreg = old_gpreg & 0xe9;
-       OUTB (nc_gpreg, gpreg);
+       OUTB(np, nc_gpreg, gpreg);
        gpcntl = (old_gpcntl & 0xe9) | 0x09;
-       OUTB (nc_gpcntl, gpcntl);
+       OUTB(np, nc_gpcntl, gpcntl);
 
        /* input all of NVRAM, 64 words */
        retv = T93C46_Read_Data(np, (u_short *) nvram,
                                sizeof(*nvram) / sizeof(short), &gpreg);
        
        /* return GPIO0/1/2/4 to original states after having accessed NVRAM */
-       OUTB (nc_gpcntl, old_gpcntl);
-       OUTB (nc_gpreg,  old_gpreg);
+       OUTB(np, nc_gpcntl, old_gpcntl);
+       OUTB(np, nc_gpreg,  old_gpreg);
 
        return retv;
 }
@@ -731,6 +724,29 @@ static int sym_read_Tekram_nvram (struct sym_device *np, Tekram_nvram *nvram)
        return 0;
 }
 
+#ifdef CONFIG_PARISC
+/*
+ * Host firmware (PDC) keeps a table for altering SCSI capabilities.
+ * Many newer machines export one channel of 53c896 chip as SE, 50-pin HD.
+ * Also used for Multi-initiator SCSI clusters to set the SCSI Initiator ID.
+ */
+static int sym_read_parisc_pdc(struct sym_device *np, struct pdc_initiator *pdc)
+{
+       struct hardware_path hwpath;
+       get_pci_node_path(np->pdev, &hwpath);
+       if (!pdc_get_initiator(&hwpath, pdc))
+               return 0;
+
+       return SYM_PARISC_PDC;
+}
+#else
+static inline int sym_read_parisc_pdc(struct sym_device *np,
+                                       struct pdc_initiator *x)
+{
+       return 0;
+}
+#endif
+
 /*
  *  Try reading Symbios or Tekram NVRAM
  */
@@ -743,7 +759,21 @@ int sym_read_nvram(struct sym_device *np, struct sym_nvram *nvp)
                nvp->type = SYM_TEKRAM_NVRAM;
                sym_display_Tekram_nvram(np, &nvp->data.Tekram);
        } else {
-               nvp->type = 0;
+               nvp->type = sym_read_parisc_pdc(np, &nvp->data.parisc);
        }
        return nvp->type;
 }
+
+char *sym_nvram_type(struct sym_nvram *nvp)
+{
+       switch (nvp->type) {
+       case SYM_SYMBIOS_NVRAM:
+               return "Symbios NVRAM";
+       case SYM_TEKRAM_NVRAM:
+               return "Tekram NVRAM";
+       case SYM_PARISC_PDC:
+               return "PA-RISC Firmware";
+       default:
+               return "No NVRAM";
+       }
+}