sym_nvram.c 20 KB

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