1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
4 * of PCI-SCSI IO processors.
6 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
8 * This driver is derived from the Linux sym53c8xx driver.
9 * Copyright (C) 1998-2000 Gerard Roudier
11 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
12 * a port of the FreeBSD ncr driver to Linux-1.2.13.
14 * The original ncr driver has been written for 386bsd and FreeBSD by
15 * Wolfgang Stanglmeier <wolf@cologne.de>
16 * Stefan Esser <se@mi.Uni-Koeln.de>
17 * Copyright (C) 1994 Wolfgang Stanglmeier
19 * Other major contributions:
21 * NVRAM detection and reading.
22 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
24 *-----------------------------------------------------------------------------
28 #include "sym_nvram.h"
30 #ifdef SYM_CONF_DEBUG_NVRAM
31 static u_char Tekram_boot_delay[7] = {3, 5, 10, 20, 30, 60, 120};
35 * Get host setup from NVRAM.
37 void sym_nvram_setup_host(struct Scsi_Host *shost, struct sym_hcb *np, struct sym_nvram *nvram)
40 * Get parity checking, host ID, verbose mode
41 * and miscellaneous host flags from NVRAM.
43 switch (nvram->type) {
44 case SYM_SYMBIOS_NVRAM:
45 if (!(nvram->data.Symbios.flags & SYMBIOS_PARITY_ENABLE))
46 np->rv_scntl0 &= ~0x0a;
47 np->myaddr = nvram->data.Symbios.host_id & 0x0f;
48 if (nvram->data.Symbios.flags & SYMBIOS_VERBOSE_MSGS)
50 if (nvram->data.Symbios.flags1 & SYMBIOS_SCAN_HI_LO)
51 shost->reverse_ordering = 1;
52 if (nvram->data.Symbios.flags2 & SYMBIOS_AVOID_BUS_RESET)
53 np->usrflags |= SYM_AVOID_BUS_RESET;
55 case SYM_TEKRAM_NVRAM:
56 np->myaddr = nvram->data.Tekram.host_id & 0x0f;
60 if (nvram->data.parisc.host_id != -1)
61 np->myaddr = nvram->data.parisc.host_id;
62 if (nvram->data.parisc.factor != -1)
63 np->minsync = nvram->data.parisc.factor;
64 if (nvram->data.parisc.width != -1)
65 np->maxwide = nvram->data.parisc.width;
66 switch (nvram->data.parisc.mode) {
67 case 0: np->scsi_mode = SMODE_SE; break;
68 case 1: np->scsi_mode = SMODE_HVD; break;
69 case 2: np->scsi_mode = SMODE_LVD; break;
79 * Get target set-up from Symbios format NVRAM.
82 sym_Symbios_setup_target(struct sym_tcb *tp, int target, Symbios_nvram *nvram)
84 Symbios_target *tn = &nvram->target[target];
86 if (!(tn->flags & SYMBIOS_QUEUE_TAGS_ENABLED))
88 if (!(tn->flags & SYMBIOS_DISCONNECT_ENABLE))
89 tp->usrflags &= ~SYM_DISC_ENABLED;
90 if (!(tn->flags & SYMBIOS_SCAN_AT_BOOT_TIME))
91 tp->usrflags |= SYM_SCAN_BOOT_DISABLED;
92 if (!(tn->flags & SYMBIOS_SCAN_LUNS))
93 tp->usrflags |= SYM_SCAN_LUNS_DISABLED;
94 tp->usr_period = (tn->sync_period + 3) / 4;
95 tp->usr_width = (tn->bus_width == 0x8) ? 0 : 1;
98 static const unsigned char Tekram_sync[16] = {
99 25, 31, 37, 43, 50, 62, 75, 125, 12, 15, 18, 21, 6, 7, 9, 10
103 * Get target set-up from Tekram format NVRAM.
106 sym_Tekram_setup_target(struct sym_tcb *tp, int target, Tekram_nvram *nvram)
108 struct Tekram_target *tn = &nvram->target[target];
110 if (tn->flags & TEKRAM_TAGGED_COMMANDS) {
111 tp->usrtags = 2 << nvram->max_tags_index;
114 if (tn->flags & TEKRAM_DISCONNECT_ENABLE)
115 tp->usrflags |= SYM_DISC_ENABLED;
117 if (tn->flags & TEKRAM_SYNC_NEGO)
118 tp->usr_period = Tekram_sync[tn->sync_index & 0xf];
119 tp->usr_width = (tn->flags & TEKRAM_WIDE_NEGO) ? 1 : 0;
123 * Get target setup from NVRAM.
125 void sym_nvram_setup_target(struct sym_tcb *tp, int target, struct sym_nvram *nvp)
128 case SYM_SYMBIOS_NVRAM:
129 sym_Symbios_setup_target(tp, target, &nvp->data.Symbios);
131 case SYM_TEKRAM_NVRAM:
132 sym_Tekram_setup_target(tp, target, &nvp->data.Tekram);
139 #ifdef SYM_CONF_DEBUG_NVRAM
141 * Dump Symbios format NVRAM for debugging purpose.
143 static void sym_display_Symbios_nvram(struct sym_device *np, Symbios_nvram *nvram)
147 /* display Symbios nvram host data */
148 printf("%s: HOST ID=%d%s%s%s%s%s%s\n",
149 sym_name(np), nvram->host_id & 0x0f,
150 (nvram->flags & SYMBIOS_SCAM_ENABLE) ? " SCAM" :"",
151 (nvram->flags & SYMBIOS_PARITY_ENABLE) ? " PARITY" :"",
152 (nvram->flags & SYMBIOS_VERBOSE_MSGS) ? " VERBOSE" :"",
153 (nvram->flags & SYMBIOS_CHS_MAPPING) ? " CHS_ALT" :"",
154 (nvram->flags2 & SYMBIOS_AVOID_BUS_RESET)?" NO_RESET" :"",
155 (nvram->flags1 & SYMBIOS_SCAN_HI_LO) ? " HI_LO" :"");
157 /* display Symbios nvram drive data */
158 for (i = 0 ; i < 15 ; i++) {
159 struct Symbios_target *tn = &nvram->target[i];
160 printf("%s-%d:%s%s%s%s WIDTH=%d SYNC=%d TMO=%d\n",
162 (tn->flags & SYMBIOS_DISCONNECT_ENABLE) ? " DISC" : "",
163 (tn->flags & SYMBIOS_SCAN_AT_BOOT_TIME) ? " SCAN_BOOT" : "",
164 (tn->flags & SYMBIOS_SCAN_LUNS) ? " SCAN_LUNS" : "",
165 (tn->flags & SYMBIOS_QUEUE_TAGS_ENABLED)? " TCQ" : "",
173 * Dump TEKRAM format NVRAM for debugging purpose.
175 static void sym_display_Tekram_nvram(struct sym_device *np, Tekram_nvram *nvram)
177 int i, tags, boot_delay;
180 /* display Tekram nvram host data */
181 tags = 2 << nvram->max_tags_index;
183 if (nvram->boot_delay_index < 6)
184 boot_delay = Tekram_boot_delay[nvram->boot_delay_index];
185 switch ((nvram->flags & TEKRAM_REMOVABLE_FLAGS) >> 6) {
187 case 0: rem = ""; break;
188 case 1: rem = " REMOVABLE=boot device"; break;
189 case 2: rem = " REMOVABLE=all"; break;
192 printf("%s: HOST ID=%d%s%s%s%s%s%s%s%s%s BOOT DELAY=%d tags=%d\n",
193 sym_name(np), nvram->host_id & 0x0f,
194 (nvram->flags1 & SYMBIOS_SCAM_ENABLE) ? " SCAM" :"",
195 (nvram->flags & TEKRAM_MORE_THAN_2_DRIVES) ? " >2DRIVES":"",
196 (nvram->flags & TEKRAM_DRIVES_SUP_1GB) ? " >1GB" :"",
197 (nvram->flags & TEKRAM_RESET_ON_POWER_ON) ? " RESET" :"",
198 (nvram->flags & TEKRAM_ACTIVE_NEGATION) ? " ACT_NEG" :"",
199 (nvram->flags & TEKRAM_IMMEDIATE_SEEK) ? " IMM_SEEK" :"",
200 (nvram->flags & TEKRAM_SCAN_LUNS) ? " SCAN_LUNS" :"",
201 (nvram->flags1 & TEKRAM_F2_F6_ENABLED) ? " F2_F6" :"",
202 rem, boot_delay, tags);
204 /* display Tekram nvram drive data */
205 for (i = 0; i <= 15; i++) {
207 struct Tekram_target *tn = &nvram->target[i];
208 j = tn->sync_index & 0xf;
209 sync = Tekram_sync[j];
210 printf("%s-%d:%s%s%s%s%s%s PERIOD=%d\n",
212 (tn->flags & TEKRAM_PARITY_CHECK) ? " PARITY" : "",
213 (tn->flags & TEKRAM_SYNC_NEGO) ? " SYNC" : "",
214 (tn->flags & TEKRAM_DISCONNECT_ENABLE) ? " DISC" : "",
215 (tn->flags & TEKRAM_START_CMD) ? " START" : "",
216 (tn->flags & TEKRAM_TAGGED_COMMANDS) ? " TCQ" : "",
217 (tn->flags & TEKRAM_WIDE_NEGO) ? " WIDE" : "",
222 static void sym_display_Symbios_nvram(struct sym_device *np, Symbios_nvram *nvram) { (void)np; (void)nvram; }
223 static void sym_display_Tekram_nvram(struct sym_device *np, Tekram_nvram *nvram) { (void)np; (void)nvram; }
224 #endif /* SYM_CONF_DEBUG_NVRAM */
228 * 24C16 EEPROM reading.
230 * GPIO0 - data in/data out
232 * Symbios NVRAM wiring now also used by Tekram.
241 * Set/clear data/clock bit in GPIO0
243 static void S24C16_set_bit(struct sym_device *np, u_char write_bit, u_char *gpreg,
262 OUTB(np, nc_gpreg, *gpreg);
268 * Send START condition to NVRAM to wake it up.
270 static void S24C16_start(struct sym_device *np, u_char *gpreg)
272 S24C16_set_bit(np, 1, gpreg, SET_BIT);
273 S24C16_set_bit(np, 0, gpreg, SET_CLK);
274 S24C16_set_bit(np, 0, gpreg, CLR_BIT);
275 S24C16_set_bit(np, 0, gpreg, CLR_CLK);
279 * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZzzzz!!
281 static void S24C16_stop(struct sym_device *np, u_char *gpreg)
283 S24C16_set_bit(np, 0, gpreg, SET_CLK);
284 S24C16_set_bit(np, 1, gpreg, SET_BIT);
288 * Read or write a bit to the NVRAM,
289 * read if GPIO0 input else write if GPIO0 output
291 static void S24C16_do_bit(struct sym_device *np, u_char *read_bit, u_char write_bit,
294 S24C16_set_bit(np, write_bit, gpreg, SET_BIT);
295 S24C16_set_bit(np, 0, gpreg, SET_CLK);
297 *read_bit = INB(np, nc_gpreg);
298 S24C16_set_bit(np, 0, gpreg, CLR_CLK);
299 S24C16_set_bit(np, 0, gpreg, CLR_BIT);
303 * Output an ACK to the NVRAM after reading,
304 * change GPIO0 to output and when done back to an input
306 static void S24C16_write_ack(struct sym_device *np, u_char write_bit, u_char *gpreg,
309 OUTB(np, nc_gpcntl, *gpcntl & 0xfe);
310 S24C16_do_bit(np, NULL, write_bit, gpreg);
311 OUTB(np, nc_gpcntl, *gpcntl);
315 * Input an ACK from NVRAM after writing,
316 * change GPIO0 to input and when done back to an output
318 static void S24C16_read_ack(struct sym_device *np, u_char *read_bit, u_char *gpreg,
321 OUTB(np, nc_gpcntl, *gpcntl | 0x01);
322 S24C16_do_bit(np, read_bit, 1, gpreg);
323 OUTB(np, nc_gpcntl, *gpcntl);
327 * WRITE a byte to the NVRAM and then get an ACK to see it was accepted OK,
328 * GPIO0 must already be set as an output
330 static void S24C16_write_byte(struct sym_device *np, u_char *ack_data, u_char write_data,
331 u_char *gpreg, u_char *gpcntl)
335 for (x = 0; x < 8; x++)
336 S24C16_do_bit(np, NULL, (write_data >> (7 - x)) & 0x01, gpreg);
338 S24C16_read_ack(np, ack_data, gpreg, gpcntl);
342 * READ a byte from the NVRAM and then send an ACK to say we have got it,
343 * GPIO0 must already be set as an input
345 static void S24C16_read_byte(struct sym_device *np, u_char *read_data, u_char ack_data,
346 u_char *gpreg, u_char *gpcntl)
352 for (x = 0; x < 8; x++) {
353 S24C16_do_bit(np, &read_bit, 1, gpreg);
354 *read_data |= ((read_bit & 0x01) << (7 - x));
357 S24C16_write_ack(np, ack_data, gpreg, gpcntl);
360 #ifdef SYM_CONF_NVRAM_WRITE_SUPPORT
362 * Write 'len' bytes starting at 'offset'.
364 static int sym_write_S24C16_nvram(struct sym_device *np, int offset,
365 u_char *data, int len)
367 u_char gpcntl, gpreg;
368 u_char old_gpcntl, old_gpreg;
372 /* save current state of GPCNTL and GPREG */
373 old_gpreg = INB(np, nc_gpreg);
374 old_gpcntl = INB(np, nc_gpcntl);
375 gpcntl = old_gpcntl & 0x1c;
377 /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
378 OUTB(np, nc_gpreg, old_gpreg);
379 OUTB(np, nc_gpcntl, gpcntl);
381 /* this is to set NVRAM into a known state with GPIO0/1 both low */
383 S24C16_set_bit(np, 0, &gpreg, CLR_CLK);
384 S24C16_set_bit(np, 0, &gpreg, CLR_BIT);
386 /* now set NVRAM inactive with GPIO0/1 both high */
387 S24C16_stop(np, &gpreg);
389 /* NVRAM has to be written in segments of 16 bytes */
390 for (x = 0; x < len ; x += 16) {
392 S24C16_start(np, &gpreg);
393 S24C16_write_byte(np, &ack_data,
394 0xa0 | (((offset+x) >> 7) & 0x0e),
396 } while (ack_data & 0x01);
398 S24C16_write_byte(np, &ack_data, (offset+x) & 0xff,
401 for (y = 0; y < 16; y++)
402 S24C16_write_byte(np, &ack_data, data[x+y],
404 S24C16_stop(np, &gpreg);
407 /* return GPIO0/1 to original states after having accessed NVRAM */
408 OUTB(np, nc_gpcntl, old_gpcntl);
409 OUTB(np, nc_gpreg, old_gpreg);
413 #endif /* SYM_CONF_NVRAM_WRITE_SUPPORT */
416 * Read 'len' bytes starting at 'offset'.
418 static int sym_read_S24C16_nvram(struct sym_device *np, int offset, u_char *data, int len)
420 u_char gpcntl, gpreg;
421 u_char old_gpcntl, old_gpreg;
426 /* save current state of GPCNTL and GPREG */
427 old_gpreg = INB(np, nc_gpreg);
428 old_gpcntl = INB(np, nc_gpcntl);
429 gpcntl = old_gpcntl & 0x1c;
431 /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
432 OUTB(np, nc_gpreg, old_gpreg);
433 OUTB(np, nc_gpcntl, gpcntl);
435 /* this is to set NVRAM into a known state with GPIO0/1 both low */
437 S24C16_set_bit(np, 0, &gpreg, CLR_CLK);
438 S24C16_set_bit(np, 0, &gpreg, CLR_BIT);
440 /* now set NVRAM inactive with GPIO0/1 both high */
441 S24C16_stop(np, &gpreg);
444 S24C16_start(np, &gpreg);
446 /* write device code and random address MSB */
447 S24C16_write_byte(np, &ack_data,
448 0xa0 | ((offset >> 7) & 0x0e), &gpreg, &gpcntl);
452 /* write random address LSB */
453 S24C16_write_byte(np, &ack_data,
454 offset & 0xff, &gpreg, &gpcntl);
458 /* regenerate START state to set up for reading */
459 S24C16_start(np, &gpreg);
461 /* rewrite device code and address MSB with read bit set (lsb = 0x01) */
462 S24C16_write_byte(np, &ack_data,
463 0xa1 | ((offset >> 7) & 0x0e), &gpreg, &gpcntl);
467 /* now set up GPIO0 for inputting data */
469 OUTB(np, nc_gpcntl, gpcntl);
471 /* input all requested data - only part of total NVRAM */
472 for (x = 0; x < len; x++)
473 S24C16_read_byte(np, &data[x], (x == (len-1)), &gpreg, &gpcntl);
475 /* finally put NVRAM back in inactive mode */
477 OUTB(np, nc_gpcntl, gpcntl);
478 S24C16_stop(np, &gpreg);
481 /* return GPIO0/1 to original states after having accessed NVRAM */
482 OUTB(np, nc_gpcntl, old_gpcntl);
483 OUTB(np, nc_gpreg, old_gpreg);
494 * Try reading Symbios NVRAM.
497 static int sym_read_Symbios_nvram(struct sym_device *np, Symbios_nvram *nvram)
499 static u_char Symbios_trailer[6] = {0xfe, 0xfe, 0, 0, 0, 0};
500 u_char *data = (u_char *) nvram;
501 int len = sizeof(*nvram);
505 /* probe the 24c16 and read the SYMBIOS 24c16 area */
506 if (sym_read_S24C16_nvram (np, SYMBIOS_NVRAM_ADDRESS, data, len))
509 /* check valid NVRAM signature, verify byte count and checksum */
510 if (nvram->type != 0 ||
511 memcmp(nvram->trailer, Symbios_trailer, 6) ||
512 nvram->byte_count != len - 12)
515 /* verify checksum */
516 for (x = 6, csum = 0; x < len - 6; x++)
518 if (csum != nvram->checksum)
525 * 93C46 EEPROM reading.
530 * GPIO4 - chip select
536 * Pulse clock bit in GPIO0
538 static void T93C46_Clk(struct sym_device *np, u_char *gpreg)
540 OUTB(np, nc_gpreg, *gpreg | 0x04);
543 OUTB(np, nc_gpreg, *gpreg);
547 * Read bit from NVRAM
549 static void T93C46_Read_Bit(struct sym_device *np, u_char *read_bit, u_char *gpreg)
552 T93C46_Clk(np, gpreg);
553 *read_bit = INB(np, nc_gpreg);
559 static void T93C46_Write_Bit(struct sym_device *np, u_char write_bit, u_char *gpreg)
561 if (write_bit & 0x01)
568 OUTB(np, nc_gpreg, *gpreg);
572 T93C46_Clk(np, gpreg);
576 * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZZzzz!!
578 static void T93C46_Stop(struct sym_device *np, u_char *gpreg)
581 OUTB(np, nc_gpreg, *gpreg);
585 T93C46_Clk(np, gpreg);
589 * Send read command and address to NVRAM
591 static void T93C46_Send_Command(struct sym_device *np, u_short write_data,
592 u_char *read_bit, u_char *gpreg)
596 /* send 9 bits, start bit (1), command (2), address (6) */
597 for (x = 0; x < 9; x++)
598 T93C46_Write_Bit(np, (u_char) (write_data >> (8 - x)), gpreg);
600 *read_bit = INB(np, nc_gpreg);
604 * READ 2 bytes from the NVRAM
606 static void T93C46_Read_Word(struct sym_device *np,
607 unsigned short *nvram_data, unsigned char *gpreg)
613 for (x = 0; x < 16; x++) {
614 T93C46_Read_Bit(np, &read_bit, gpreg);
617 *nvram_data |= (0x01 << (15 - x));
619 *nvram_data &= ~(0x01 << (15 - x));
624 * Read Tekram NvRAM data.
626 static int T93C46_Read_Data(struct sym_device *np, unsigned short *data,
627 int len, unsigned char *gpreg)
631 for (x = 0; x < len; x++) {
632 unsigned char read_bit;
633 /* output read command and address */
634 T93C46_Send_Command(np, 0x180 | x, &read_bit, gpreg);
637 T93C46_Read_Word(np, &data[x], gpreg);
638 T93C46_Stop(np, gpreg);
645 * Try reading 93C46 Tekram NVRAM.
647 static int sym_read_T93C46_nvram(struct sym_device *np, Tekram_nvram *nvram)
649 u_char gpcntl, gpreg;
650 u_char old_gpcntl, old_gpreg;
653 /* save current state of GPCNTL and GPREG */
654 old_gpreg = INB(np, nc_gpreg);
655 old_gpcntl = INB(np, nc_gpcntl);
657 /* set up GPREG & GPCNTL to set GPIO0/1/2/4 in to known state, 0 in,
659 gpreg = old_gpreg & 0xe9;
660 OUTB(np, nc_gpreg, gpreg);
661 gpcntl = (old_gpcntl & 0xe9) | 0x09;
662 OUTB(np, nc_gpcntl, gpcntl);
664 /* input all of NVRAM, 64 words */
665 retv = T93C46_Read_Data(np, (u_short *) nvram,
666 sizeof(*nvram) / sizeof(short), &gpreg);
668 /* return GPIO0/1/2/4 to original states after having accessed NVRAM */
669 OUTB(np, nc_gpcntl, old_gpcntl);
670 OUTB(np, nc_gpreg, old_gpreg);
676 * Try reading Tekram NVRAM.
679 static int sym_read_Tekram_nvram (struct sym_device *np, Tekram_nvram *nvram)
681 u_char *data = (u_char *) nvram;
682 int len = sizeof(*nvram);
686 switch (np->pdev->device) {
687 case PCI_DEVICE_ID_NCR_53C885:
688 case PCI_DEVICE_ID_NCR_53C895:
689 case PCI_DEVICE_ID_NCR_53C896:
690 x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
693 case PCI_DEVICE_ID_NCR_53C875:
694 x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
700 x = sym_read_T93C46_nvram(np, nvram);
706 /* verify checksum */
707 for (x = 0, csum = 0; x < len - 1; x += 2)
708 csum += data[x] + (data[x+1] << 8);
717 * Host firmware (PDC) keeps a table for altering SCSI capabilities.
718 * Many newer machines export one channel of 53c896 chip as SE, 50-pin HD.
719 * Also used for Multi-initiator SCSI clusters to set the SCSI Initiator ID.
721 static int sym_read_parisc_pdc(struct sym_device *np, struct pdc_initiator *pdc)
723 struct hardware_path hwpath;
724 get_pci_node_path(np->pdev, &hwpath);
725 if (!pdc_get_initiator(&hwpath, pdc))
728 return SYM_PARISC_PDC;
731 static inline int sym_read_parisc_pdc(struct sym_device *np,
732 struct pdc_initiator *x)
739 * Try reading Symbios or Tekram NVRAM
741 int sym_read_nvram(struct sym_device *np, struct sym_nvram *nvp)
743 if (!sym_read_Symbios_nvram(np, &nvp->data.Symbios)) {
744 nvp->type = SYM_SYMBIOS_NVRAM;
745 sym_display_Symbios_nvram(np, &nvp->data.Symbios);
746 } else if (!sym_read_Tekram_nvram(np, &nvp->data.Tekram)) {
747 nvp->type = SYM_TEKRAM_NVRAM;
748 sym_display_Tekram_nvram(np, &nvp->data.Tekram);
750 nvp->type = sym_read_parisc_pdc(np, &nvp->data.parisc);
755 char *sym_nvram_type(struct sym_nvram *nvp)
758 case SYM_SYMBIOS_NVRAM:
759 return "Symbios NVRAM";
760 case SYM_TEKRAM_NVRAM:
761 return "Tekram NVRAM";
763 return "PA-RISC Firmware";