sym_nvram.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /*
  2. * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
  3. * of PCI-SCSI IO processors.
  4. *
  5. * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
  6. *
  7. * This driver is derived from the Linux sym53c8xx driver.
  8. * Copyright (C) 1998-2000 Gerard Roudier
  9. *
  10. * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
  11. * a port of the FreeBSD ncr driver to Linux-1.2.13.
  12. *
  13. * The original ncr driver has been written for 386bsd and FreeBSD by
  14. * Wolfgang Stanglmeier <wolf@cologne.de>
  15. * Stefan Esser <se@mi.Uni-Koeln.de>
  16. * Copyright (C) 1994 Wolfgang Stanglmeier
  17. *
  18. * Other major contributions:
  19. *
  20. * NVRAM detection and reading.
  21. * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
  22. *
  23. *-----------------------------------------------------------------------------
  24. *
  25. * This program is free software; you can redistribute it and/or modify
  26. * it under the terms of the GNU General Public License as published by
  27. * the Free Software Foundation; either version 2 of the License, or
  28. * (at your option) any later version.
  29. *
  30. * This program is distributed in the hope that it will be useful,
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. * GNU General Public License for more details.
  34. *
  35. * You should have received a copy of the GNU General Public License
  36. * along with this program; if not, write to the Free Software
  37. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  38. */
  39. #include "sym_glue.h"
  40. #include "sym_nvram.h"
  41. #ifdef SYM_CONF_DEBUG_NVRAM
  42. static u_char Tekram_boot_delay[7] = {3, 5, 10, 20, 30, 60, 120};
  43. #endif
  44. /*
  45. * Get host setup from NVRAM.
  46. */
  47. void sym_nvram_setup_host(struct Scsi_Host *shost, struct sym_hcb *np, struct sym_nvram *nvram)
  48. {
  49. /*
  50. * Get parity checking, host ID, verbose mode
  51. * and miscellaneous host flags from NVRAM.
  52. */
  53. switch (nvram->type) {
  54. case SYM_SYMBIOS_NVRAM:
  55. if (!(nvram->data.Symbios.flags & SYMBIOS_PARITY_ENABLE))
  56. np->rv_scntl0 &= ~0x0a;
  57. np->myaddr = nvram->data.Symbios.host_id & 0x0f;
  58. if (nvram->data.Symbios.flags & SYMBIOS_VERBOSE_MSGS)
  59. np->verbose += 1;
  60. if (nvram->data.Symbios.flags1 & SYMBIOS_SCAN_HI_LO)
  61. shost->reverse_ordering = 1;
  62. if (nvram->data.Symbios.flags2 & SYMBIOS_AVOID_BUS_RESET)
  63. np->usrflags |= SYM_AVOID_BUS_RESET;
  64. break;
  65. case SYM_TEKRAM_NVRAM:
  66. np->myaddr = nvram->data.Tekram.host_id & 0x0f;
  67. break;
  68. #ifdef CONFIG_PARISC
  69. case SYM_PARISC_PDC:
  70. if (nvram->data.parisc.host_id != -1)
  71. np->myaddr = nvram->data.parisc.host_id;
  72. if (nvram->data.parisc.factor != -1)
  73. np->minsync = nvram->data.parisc.factor;
  74. if (nvram->data.parisc.width != -1)
  75. np->maxwide = nvram->data.parisc.width;
  76. switch (nvram->data.parisc.mode) {
  77. case 0: np->scsi_mode = SMODE_SE; break;
  78. case 1: np->scsi_mode = SMODE_HVD; break;
  79. case 2: np->scsi_mode = SMODE_LVD; break;
  80. default: break;
  81. }
  82. #endif
  83. default:
  84. break;
  85. }
  86. }
  87. /*
  88. * Get target set-up from Symbios format NVRAM.
  89. */
  90. static void
  91. sym_Symbios_setup_target(struct sym_hcb *np, int target, Symbios_nvram *nvram)
  92. {
  93. struct sym_tcb *tp = &np->target[target];
  94. Symbios_target *tn = &nvram->target[target];
  95. tp->usrtags =
  96. (tn->flags & SYMBIOS_QUEUE_TAGS_ENABLED)? SYM_SETUP_MAX_TAG : 0;
  97. if (!(tn->flags & SYMBIOS_DISCONNECT_ENABLE))
  98. tp->usrflags &= ~SYM_DISC_ENABLED;
  99. if (!(tn->flags & SYMBIOS_SCAN_AT_BOOT_TIME))
  100. tp->usrflags |= SYM_SCAN_BOOT_DISABLED;
  101. if (!(tn->flags & SYMBIOS_SCAN_LUNS))
  102. tp->usrflags |= SYM_SCAN_LUNS_DISABLED;
  103. }
  104. /*
  105. * Get target set-up from Tekram format NVRAM.
  106. */
  107. static void
  108. sym_Tekram_setup_target(struct sym_hcb *np, int target, Tekram_nvram *nvram)
  109. {
  110. struct sym_tcb *tp = &np->target[target];
  111. struct Tekram_target *tn = &nvram->target[target];
  112. if (tn->flags & TEKRAM_TAGGED_COMMANDS) {
  113. tp->usrtags = 2 << nvram->max_tags_index;
  114. }
  115. if (tn->flags & TEKRAM_DISCONNECT_ENABLE)
  116. tp->usrflags |= SYM_DISC_ENABLED;
  117. /* If any device does not support parity, we will not use this option */
  118. if (!(tn->flags & TEKRAM_PARITY_CHECK))
  119. np->rv_scntl0 &= ~0x0a; /* SCSI parity checking disabled */
  120. }
  121. /*
  122. * Get target setup from NVRAM.
  123. */
  124. void sym_nvram_setup_target(struct sym_hcb *np, int target, struct sym_nvram *nvp)
  125. {
  126. switch (nvp->type) {
  127. case SYM_SYMBIOS_NVRAM:
  128. sym_Symbios_setup_target(np, target, &nvp->data.Symbios);
  129. break;
  130. case SYM_TEKRAM_NVRAM:
  131. sym_Tekram_setup_target(np, target, &nvp->data.Tekram);
  132. break;
  133. default:
  134. break;
  135. }
  136. }
  137. #ifdef SYM_CONF_DEBUG_NVRAM
  138. /*
  139. * Dump Symbios format NVRAM for debugging purpose.
  140. */
  141. static void sym_display_Symbios_nvram(struct sym_device *np, Symbios_nvram *nvram)
  142. {
  143. int i;
  144. /* display Symbios nvram host data */
  145. printf("%s: HOST ID=%d%s%s%s%s%s%s\n",
  146. sym_name(np), nvram->host_id & 0x0f,
  147. (nvram->flags & SYMBIOS_SCAM_ENABLE) ? " SCAM" :"",
  148. (nvram->flags & SYMBIOS_PARITY_ENABLE) ? " PARITY" :"",
  149. (nvram->flags & SYMBIOS_VERBOSE_MSGS) ? " VERBOSE" :"",
  150. (nvram->flags & SYMBIOS_CHS_MAPPING) ? " CHS_ALT" :"",
  151. (nvram->flags2 & SYMBIOS_AVOID_BUS_RESET)?" NO_RESET" :"",
  152. (nvram->flags1 & SYMBIOS_SCAN_HI_LO) ? " HI_LO" :"");
  153. /* display Symbios nvram drive data */
  154. for (i = 0 ; i < 15 ; i++) {
  155. struct Symbios_target *tn = &nvram->target[i];
  156. printf("%s-%d:%s%s%s%s WIDTH=%d SYNC=%d TMO=%d\n",
  157. sym_name(np), i,
  158. (tn->flags & SYMBIOS_DISCONNECT_ENABLE) ? " DISC" : "",
  159. (tn->flags & SYMBIOS_SCAN_AT_BOOT_TIME) ? " SCAN_BOOT" : "",
  160. (tn->flags & SYMBIOS_SCAN_LUNS) ? " SCAN_LUNS" : "",
  161. (tn->flags & SYMBIOS_QUEUE_TAGS_ENABLED)? " TCQ" : "",
  162. tn->bus_width,
  163. tn->sync_period / 4,
  164. tn->timeout);
  165. }
  166. }
  167. /*
  168. * Dump TEKRAM format NVRAM for debugging purpose.
  169. */
  170. static void sym_display_Tekram_nvram(struct sym_device *np, Tekram_nvram *nvram)
  171. {
  172. int i, tags, boot_delay;
  173. char *rem;
  174. /* display Tekram nvram host data */
  175. tags = 2 << nvram->max_tags_index;
  176. boot_delay = 0;
  177. if (nvram->boot_delay_index < 6)
  178. boot_delay = Tekram_boot_delay[nvram->boot_delay_index];
  179. switch ((nvram->flags & TEKRAM_REMOVABLE_FLAGS) >> 6) {
  180. default:
  181. case 0: rem = ""; break;
  182. case 1: rem = " REMOVABLE=boot device"; break;
  183. case 2: rem = " REMOVABLE=all"; break;
  184. }
  185. printf("%s: HOST ID=%d%s%s%s%s%s%s%s%s%s BOOT DELAY=%d tags=%d\n",
  186. sym_name(np), nvram->host_id & 0x0f,
  187. (nvram->flags1 & SYMBIOS_SCAM_ENABLE) ? " SCAM" :"",
  188. (nvram->flags & TEKRAM_MORE_THAN_2_DRIVES) ? " >2DRIVES":"",
  189. (nvram->flags & TEKRAM_DRIVES_SUP_1GB) ? " >1GB" :"",
  190. (nvram->flags & TEKRAM_RESET_ON_POWER_ON) ? " RESET" :"",
  191. (nvram->flags & TEKRAM_ACTIVE_NEGATION) ? " ACT_NEG" :"",
  192. (nvram->flags & TEKRAM_IMMEDIATE_SEEK) ? " IMM_SEEK" :"",
  193. (nvram->flags & TEKRAM_SCAN_LUNS) ? " SCAN_LUNS" :"",
  194. (nvram->flags1 & TEKRAM_F2_F6_ENABLED) ? " F2_F6" :"",
  195. rem, boot_delay, tags);
  196. /* display Tekram nvram drive data */
  197. for (i = 0; i <= 15; i++) {
  198. int sync, j;
  199. struct Tekram_target *tn = &nvram->target[i];
  200. j = tn->sync_index & 0xf;
  201. sync = Tekram_sync[j];
  202. printf("%s-%d:%s%s%s%s%s%s PERIOD=%d\n",
  203. sym_name(np), i,
  204. (tn->flags & TEKRAM_PARITY_CHECK) ? " PARITY" : "",
  205. (tn->flags & TEKRAM_SYNC_NEGO) ? " SYNC" : "",
  206. (tn->flags & TEKRAM_DISCONNECT_ENABLE) ? " DISC" : "",
  207. (tn->flags & TEKRAM_START_CMD) ? " START" : "",
  208. (tn->flags & TEKRAM_TAGGED_COMMANDS) ? " TCQ" : "",
  209. (tn->flags & TEKRAM_WIDE_NEGO) ? " WIDE" : "",
  210. sync);
  211. }
  212. }
  213. #else
  214. static void sym_display_Symbios_nvram(struct sym_device *np, Symbios_nvram *nvram) { (void)np; (void)nvram; }
  215. static void sym_display_Tekram_nvram(struct sym_device *np, Tekram_nvram *nvram) { (void)np; (void)nvram; }
  216. #endif /* SYM_CONF_DEBUG_NVRAM */
  217. /*
  218. * 24C16 EEPROM reading.
  219. *
  220. * GPOI0 - data in/data out
  221. * GPIO1 - clock
  222. * Symbios NVRAM wiring now also used by Tekram.
  223. */
  224. #define SET_BIT 0
  225. #define CLR_BIT 1
  226. #define SET_CLK 2
  227. #define CLR_CLK 3
  228. /*
  229. * Set/clear data/clock bit in GPIO0
  230. */
  231. static void S24C16_set_bit(struct sym_device *np, u_char write_bit, u_char *gpreg,
  232. int bit_mode)
  233. {
  234. udelay(5);
  235. switch (bit_mode) {
  236. case SET_BIT:
  237. *gpreg |= write_bit;
  238. break;
  239. case CLR_BIT:
  240. *gpreg &= 0xfe;
  241. break;
  242. case SET_CLK:
  243. *gpreg |= 0x02;
  244. break;
  245. case CLR_CLK:
  246. *gpreg &= 0xfd;
  247. break;
  248. }
  249. OUTB(np, nc_gpreg, *gpreg);
  250. INB(np, nc_mbox1);
  251. udelay(5);
  252. }
  253. /*
  254. * Send START condition to NVRAM to wake it up.
  255. */
  256. static void S24C16_start(struct sym_device *np, u_char *gpreg)
  257. {
  258. S24C16_set_bit(np, 1, gpreg, SET_BIT);
  259. S24C16_set_bit(np, 0, gpreg, SET_CLK);
  260. S24C16_set_bit(np, 0, gpreg, CLR_BIT);
  261. S24C16_set_bit(np, 0, gpreg, CLR_CLK);
  262. }
  263. /*
  264. * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZzzzz!!
  265. */
  266. static void S24C16_stop(struct sym_device *np, u_char *gpreg)
  267. {
  268. S24C16_set_bit(np, 0, gpreg, SET_CLK);
  269. S24C16_set_bit(np, 1, gpreg, SET_BIT);
  270. }
  271. /*
  272. * Read or write a bit to the NVRAM,
  273. * read if GPIO0 input else write if GPIO0 output
  274. */
  275. static void S24C16_do_bit(struct sym_device *np, u_char *read_bit, u_char write_bit,
  276. u_char *gpreg)
  277. {
  278. S24C16_set_bit(np, write_bit, gpreg, SET_BIT);
  279. S24C16_set_bit(np, 0, gpreg, SET_CLK);
  280. if (read_bit)
  281. *read_bit = INB(np, nc_gpreg);
  282. S24C16_set_bit(np, 0, gpreg, CLR_CLK);
  283. S24C16_set_bit(np, 0, gpreg, CLR_BIT);
  284. }
  285. /*
  286. * Output an ACK to the NVRAM after reading,
  287. * change GPIO0 to output and when done back to an input
  288. */
  289. static void S24C16_write_ack(struct sym_device *np, u_char write_bit, u_char *gpreg,
  290. u_char *gpcntl)
  291. {
  292. OUTB(np, nc_gpcntl, *gpcntl & 0xfe);
  293. S24C16_do_bit(np, NULL, write_bit, gpreg);
  294. OUTB(np, nc_gpcntl, *gpcntl);
  295. }
  296. /*
  297. * Input an ACK from NVRAM after writing,
  298. * change GPIO0 to input and when done back to an output
  299. */
  300. static void S24C16_read_ack(struct sym_device *np, u_char *read_bit, u_char *gpreg,
  301. u_char *gpcntl)
  302. {
  303. OUTB(np, nc_gpcntl, *gpcntl | 0x01);
  304. S24C16_do_bit(np, read_bit, 1, gpreg);
  305. OUTB(np, nc_gpcntl, *gpcntl);
  306. }
  307. /*
  308. * WRITE a byte to the NVRAM and then get an ACK to see it was accepted OK,
  309. * GPIO0 must already be set as an output
  310. */
  311. static void S24C16_write_byte(struct sym_device *np, u_char *ack_data, u_char write_data,
  312. u_char *gpreg, u_char *gpcntl)
  313. {
  314. int x;
  315. for (x = 0; x < 8; x++)
  316. S24C16_do_bit(np, NULL, (write_data >> (7 - x)) & 0x01, gpreg);
  317. S24C16_read_ack(np, ack_data, gpreg, gpcntl);
  318. }
  319. /*
  320. * READ a byte from the NVRAM and then send an ACK to say we have got it,
  321. * GPIO0 must already be set as an input
  322. */
  323. static void S24C16_read_byte(struct sym_device *np, u_char *read_data, u_char ack_data,
  324. u_char *gpreg, u_char *gpcntl)
  325. {
  326. int x;
  327. u_char read_bit;
  328. *read_data = 0;
  329. for (x = 0; x < 8; x++) {
  330. S24C16_do_bit(np, &read_bit, 1, gpreg);
  331. *read_data |= ((read_bit & 0x01) << (7 - x));
  332. }
  333. S24C16_write_ack(np, ack_data, gpreg, gpcntl);
  334. }
  335. #ifdef SYM_CONF_NVRAM_WRITE_SUPPORT
  336. /*
  337. * Write 'len' bytes starting at 'offset'.
  338. */
  339. static int sym_write_S24C16_nvram(struct sym_device *np, int offset,
  340. u_char *data, int len)
  341. {
  342. u_char gpcntl, gpreg;
  343. u_char old_gpcntl, old_gpreg;
  344. u_char ack_data;
  345. int x;
  346. /* save current state of GPCNTL and GPREG */
  347. old_gpreg = INB(np, nc_gpreg);
  348. old_gpcntl = INB(np, nc_gpcntl);
  349. gpcntl = old_gpcntl & 0x1c;
  350. /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
  351. OUTB(np, nc_gpreg, old_gpreg);
  352. OUTB(np, nc_gpcntl, gpcntl);
  353. /* this is to set NVRAM into a known state with GPIO0/1 both low */
  354. gpreg = old_gpreg;
  355. S24C16_set_bit(np, 0, &gpreg, CLR_CLK);
  356. S24C16_set_bit(np, 0, &gpreg, CLR_BIT);
  357. /* now set NVRAM inactive with GPIO0/1 both high */
  358. S24C16_stop(np, &gpreg);
  359. /* NVRAM has to be written in segments of 16 bytes */
  360. for (x = 0; x < len ; x += 16) {
  361. do {
  362. S24C16_start(np, &gpreg);
  363. S24C16_write_byte(np, &ack_data,
  364. 0xa0 | (((offset+x) >> 7) & 0x0e),
  365. &gpreg, &gpcntl);
  366. } while (ack_data & 0x01);
  367. S24C16_write_byte(np, &ack_data, (offset+x) & 0xff,
  368. &gpreg, &gpcntl);
  369. for (y = 0; y < 16; y++)
  370. S24C16_write_byte(np, &ack_data, data[x+y],
  371. &gpreg, &gpcntl);
  372. S24C16_stop(np, &gpreg);
  373. }
  374. /* return GPIO0/1 to original states after having accessed NVRAM */
  375. OUTB(np, nc_gpcntl, old_gpcntl);
  376. OUTB(np, nc_gpreg, old_gpreg);
  377. return 0;
  378. }
  379. #endif /* SYM_CONF_NVRAM_WRITE_SUPPORT */
  380. /*
  381. * Read 'len' bytes starting at 'offset'.
  382. */
  383. static int sym_read_S24C16_nvram(struct sym_device *np, int offset, u_char *data, int len)
  384. {
  385. u_char gpcntl, gpreg;
  386. u_char old_gpcntl, old_gpreg;
  387. u_char ack_data;
  388. int retv = 1;
  389. int x;
  390. /* save current state of GPCNTL and GPREG */
  391. old_gpreg = INB(np, nc_gpreg);
  392. old_gpcntl = INB(np, nc_gpcntl);
  393. gpcntl = old_gpcntl & 0x1c;
  394. /* set up GPREG & GPCNTL to set GPIO0 and GPIO1 in to known state */
  395. OUTB(np, nc_gpreg, old_gpreg);
  396. OUTB(np, nc_gpcntl, gpcntl);
  397. /* this is to set NVRAM into a known state with GPIO0/1 both low */
  398. gpreg = old_gpreg;
  399. S24C16_set_bit(np, 0, &gpreg, CLR_CLK);
  400. S24C16_set_bit(np, 0, &gpreg, CLR_BIT);
  401. /* now set NVRAM inactive with GPIO0/1 both high */
  402. S24C16_stop(np, &gpreg);
  403. /* activate NVRAM */
  404. S24C16_start(np, &gpreg);
  405. /* write device code and random address MSB */
  406. S24C16_write_byte(np, &ack_data,
  407. 0xa0 | ((offset >> 7) & 0x0e), &gpreg, &gpcntl);
  408. if (ack_data & 0x01)
  409. goto out;
  410. /* write random address LSB */
  411. S24C16_write_byte(np, &ack_data,
  412. offset & 0xff, &gpreg, &gpcntl);
  413. if (ack_data & 0x01)
  414. goto out;
  415. /* regenerate START state to set up for reading */
  416. S24C16_start(np, &gpreg);
  417. /* rewrite device code and address MSB with read bit set (lsb = 0x01) */
  418. S24C16_write_byte(np, &ack_data,
  419. 0xa1 | ((offset >> 7) & 0x0e), &gpreg, &gpcntl);
  420. if (ack_data & 0x01)
  421. goto out;
  422. /* now set up GPIO0 for inputting data */
  423. gpcntl |= 0x01;
  424. OUTB(np, nc_gpcntl, gpcntl);
  425. /* input all requested data - only part of total NVRAM */
  426. for (x = 0; x < len; x++)
  427. S24C16_read_byte(np, &data[x], (x == (len-1)), &gpreg, &gpcntl);
  428. /* finally put NVRAM back in inactive mode */
  429. gpcntl &= 0xfe;
  430. OUTB(np, nc_gpcntl, gpcntl);
  431. S24C16_stop(np, &gpreg);
  432. retv = 0;
  433. out:
  434. /* return GPIO0/1 to original states after having accessed NVRAM */
  435. OUTB(np, nc_gpcntl, old_gpcntl);
  436. OUTB(np, nc_gpreg, old_gpreg);
  437. return retv;
  438. }
  439. #undef SET_BIT
  440. #undef CLR_BIT
  441. #undef SET_CLK
  442. #undef CLR_CLK
  443. /*
  444. * Try reading Symbios NVRAM.
  445. * Return 0 if OK.
  446. */
  447. static int sym_read_Symbios_nvram(struct sym_device *np, Symbios_nvram *nvram)
  448. {
  449. static u_char Symbios_trailer[6] = {0xfe, 0xfe, 0, 0, 0, 0};
  450. u_char *data = (u_char *) nvram;
  451. int len = sizeof(*nvram);
  452. u_short csum;
  453. int x;
  454. /* probe the 24c16 and read the SYMBIOS 24c16 area */
  455. if (sym_read_S24C16_nvram (np, SYMBIOS_NVRAM_ADDRESS, data, len))
  456. return 1;
  457. /* check valid NVRAM signature, verify byte count and checksum */
  458. if (nvram->type != 0 ||
  459. memcmp(nvram->trailer, Symbios_trailer, 6) ||
  460. nvram->byte_count != len - 12)
  461. return 1;
  462. /* verify checksum */
  463. for (x = 6, csum = 0; x < len - 6; x++)
  464. csum += data[x];
  465. if (csum != nvram->checksum)
  466. return 1;
  467. return 0;
  468. }
  469. /*
  470. * 93C46 EEPROM reading.
  471. *
  472. * GPOI0 - data in
  473. * GPIO1 - data out
  474. * GPIO2 - clock
  475. * GPIO4 - chip select
  476. *
  477. * Used by Tekram.
  478. */
  479. /*
  480. * Pulse clock bit in GPIO0
  481. */
  482. static void T93C46_Clk(struct sym_device *np, u_char *gpreg)
  483. {
  484. OUTB(np, nc_gpreg, *gpreg | 0x04);
  485. INB(np, nc_mbox1);
  486. udelay(2);
  487. OUTB(np, nc_gpreg, *gpreg);
  488. }
  489. /*
  490. * Read bit from NVRAM
  491. */
  492. static void T93C46_Read_Bit(struct sym_device *np, u_char *read_bit, u_char *gpreg)
  493. {
  494. udelay(2);
  495. T93C46_Clk(np, gpreg);
  496. *read_bit = INB(np, nc_gpreg);
  497. }
  498. /*
  499. * Write bit to GPIO0
  500. */
  501. static void T93C46_Write_Bit(struct sym_device *np, u_char write_bit, u_char *gpreg)
  502. {
  503. if (write_bit & 0x01)
  504. *gpreg |= 0x02;
  505. else
  506. *gpreg &= 0xfd;
  507. *gpreg |= 0x10;
  508. OUTB(np, nc_gpreg, *gpreg);
  509. INB(np, nc_mbox1);
  510. udelay(2);
  511. T93C46_Clk(np, gpreg);
  512. }
  513. /*
  514. * Send STOP condition to NVRAM - puts NVRAM to sleep... ZZZzzz!!
  515. */
  516. static void T93C46_Stop(struct sym_device *np, u_char *gpreg)
  517. {
  518. *gpreg &= 0xef;
  519. OUTB(np, nc_gpreg, *gpreg);
  520. INB(np, nc_mbox1);
  521. udelay(2);
  522. T93C46_Clk(np, gpreg);
  523. }
  524. /*
  525. * Send read command and address to NVRAM
  526. */
  527. static void T93C46_Send_Command(struct sym_device *np, u_short write_data,
  528. u_char *read_bit, u_char *gpreg)
  529. {
  530. int x;
  531. /* send 9 bits, start bit (1), command (2), address (6) */
  532. for (x = 0; x < 9; x++)
  533. T93C46_Write_Bit(np, (u_char) (write_data >> (8 - x)), gpreg);
  534. *read_bit = INB(np, nc_gpreg);
  535. }
  536. /*
  537. * READ 2 bytes from the NVRAM
  538. */
  539. static void T93C46_Read_Word(struct sym_device *np,
  540. unsigned short *nvram_data, unsigned char *gpreg)
  541. {
  542. int x;
  543. u_char read_bit;
  544. *nvram_data = 0;
  545. for (x = 0; x < 16; x++) {
  546. T93C46_Read_Bit(np, &read_bit, gpreg);
  547. if (read_bit & 0x01)
  548. *nvram_data |= (0x01 << (15 - x));
  549. else
  550. *nvram_data &= ~(0x01 << (15 - x));
  551. }
  552. }
  553. /*
  554. * Read Tekram NvRAM data.
  555. */
  556. static int T93C46_Read_Data(struct sym_device *np, unsigned short *data,
  557. int len, unsigned char *gpreg)
  558. {
  559. int x;
  560. for (x = 0; x < len; x++) {
  561. unsigned char read_bit;
  562. /* output read command and address */
  563. T93C46_Send_Command(np, 0x180 | x, &read_bit, gpreg);
  564. if (read_bit & 0x01)
  565. return 1; /* Bad */
  566. T93C46_Read_Word(np, &data[x], gpreg);
  567. T93C46_Stop(np, gpreg);
  568. }
  569. return 0;
  570. }
  571. /*
  572. * Try reading 93C46 Tekram NVRAM.
  573. */
  574. static int sym_read_T93C46_nvram(struct sym_device *np, Tekram_nvram *nvram)
  575. {
  576. u_char gpcntl, gpreg;
  577. u_char old_gpcntl, old_gpreg;
  578. int retv = 1;
  579. /* save current state of GPCNTL and GPREG */
  580. old_gpreg = INB(np, nc_gpreg);
  581. old_gpcntl = INB(np, nc_gpcntl);
  582. /* set up GPREG & GPCNTL to set GPIO0/1/2/4 in to known state, 0 in,
  583. 1/2/4 out */
  584. gpreg = old_gpreg & 0xe9;
  585. OUTB(np, nc_gpreg, gpreg);
  586. gpcntl = (old_gpcntl & 0xe9) | 0x09;
  587. OUTB(np, nc_gpcntl, gpcntl);
  588. /* input all of NVRAM, 64 words */
  589. retv = T93C46_Read_Data(np, (u_short *) nvram,
  590. sizeof(*nvram) / sizeof(short), &gpreg);
  591. /* return GPIO0/1/2/4 to original states after having accessed NVRAM */
  592. OUTB(np, nc_gpcntl, old_gpcntl);
  593. OUTB(np, nc_gpreg, old_gpreg);
  594. return retv;
  595. }
  596. /*
  597. * Try reading Tekram NVRAM.
  598. * Return 0 if OK.
  599. */
  600. static int sym_read_Tekram_nvram (struct sym_device *np, Tekram_nvram *nvram)
  601. {
  602. u_char *data = (u_char *) nvram;
  603. int len = sizeof(*nvram);
  604. u_short csum;
  605. int x;
  606. switch (np->device_id) {
  607. case PCI_DEVICE_ID_NCR_53C885:
  608. case PCI_DEVICE_ID_NCR_53C895:
  609. case PCI_DEVICE_ID_NCR_53C896:
  610. x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
  611. data, len);
  612. break;
  613. case PCI_DEVICE_ID_NCR_53C875:
  614. x = sym_read_S24C16_nvram(np, TEKRAM_24C16_NVRAM_ADDRESS,
  615. data, len);
  616. if (!x)
  617. break;
  618. default:
  619. x = sym_read_T93C46_nvram(np, nvram);
  620. break;
  621. }
  622. if (x)
  623. return 1;
  624. /* verify checksum */
  625. for (x = 0, csum = 0; x < len - 1; x += 2)
  626. csum += data[x] + (data[x+1] << 8);
  627. if (csum != 0x1234)
  628. return 1;
  629. return 0;
  630. }
  631. #ifdef CONFIG_PARISC
  632. /*
  633. * Host firmware (PDC) keeps a table for altering SCSI capabilities.
  634. * Many newer machines export one channel of 53c896 chip as SE, 50-pin HD.
  635. * Also used for Multi-initiator SCSI clusters to set the SCSI Initiator ID.
  636. */
  637. static int sym_read_parisc_pdc(struct sym_device *np, struct pdc_initiator *pdc)
  638. {
  639. struct hardware_path hwpath;
  640. get_pci_node_path(np->pdev, &hwpath);
  641. if (!pdc_get_initiator(&hwpath, pdc))
  642. return 0;
  643. return SYM_PARISC_PDC;
  644. }
  645. #else
  646. static inline int sym_read_parisc_pdc(struct sym_device *np,
  647. struct pdc_initiator *x)
  648. {
  649. return 0;
  650. }
  651. #endif
  652. /*
  653. * Try reading Symbios or Tekram NVRAM
  654. */
  655. int sym_read_nvram(struct sym_device *np, struct sym_nvram *nvp)
  656. {
  657. if (!sym_read_Symbios_nvram(np, &nvp->data.Symbios)) {
  658. nvp->type = SYM_SYMBIOS_NVRAM;
  659. sym_display_Symbios_nvram(np, &nvp->data.Symbios);
  660. } else if (!sym_read_Tekram_nvram(np, &nvp->data.Tekram)) {
  661. nvp->type = SYM_TEKRAM_NVRAM;
  662. sym_display_Tekram_nvram(np, &nvp->data.Tekram);
  663. } else {
  664. nvp->type = sym_read_parisc_pdc(np, &nvp->data.parisc);
  665. }
  666. return nvp->type;
  667. }
  668. char *sym_nvram_type(struct sym_nvram *nvp)
  669. {
  670. switch (nvp->type) {
  671. case SYM_SYMBIOS_NVRAM:
  672. return "Symbios NVRAM";
  673. case SYM_TEKRAM_NVRAM:
  674. return "Tekram NVRAM";
  675. case SYM_PARISC_PDC:
  676. return "PA-RISC Firmware";
  677. default:
  678. return "No NVRAM";
  679. }
  680. }