sym_glue.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
  4. * of PCI-SCSI IO processors.
  5. *
  6. * Copyright (C) 1999-2001 Gerard Roudier <[email protected]>
  7. * Copyright (c) 2003-2005 Matthew Wilcox <[email protected]>
  8. *
  9. * This driver is derived from the Linux sym53c8xx driver.
  10. * Copyright (C) 1998-2000 Gerard Roudier
  11. *
  12. * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
  13. * a port of the FreeBSD ncr driver to Linux-1.2.13.
  14. *
  15. * The original ncr driver has been written for 386bsd and FreeBSD by
  16. * Wolfgang Stanglmeier <[email protected]>
  17. * Stefan Esser <[email protected]>
  18. * Copyright (C) 1994 Wolfgang Stanglmeier
  19. *
  20. * Other major contributions:
  21. *
  22. * NVRAM detection and reading.
  23. * Copyright (C) 1997 Richard Waltham <[email protected]>
  24. *
  25. *-----------------------------------------------------------------------------
  26. */
  27. #include <linux/ctype.h>
  28. #include <linux/init.h>
  29. #include <linux/module.h>
  30. #include <linux/moduleparam.h>
  31. #include <linux/spinlock.h>
  32. #include <scsi/scsi.h>
  33. #include <scsi/scsi_tcq.h>
  34. #include <scsi/scsi_device.h>
  35. #include <scsi/scsi_transport.h>
  36. #include "sym_glue.h"
  37. #include "sym_nvram.h"
  38. #define NAME53C "sym53c"
  39. #define NAME53C8XX "sym53c8xx"
  40. struct sym_driver_setup sym_driver_setup = SYM_LINUX_DRIVER_SETUP;
  41. unsigned int sym_debug_flags = 0;
  42. static char *excl_string;
  43. static char *safe_string;
  44. module_param_named(cmd_per_lun, sym_driver_setup.max_tag, ushort, 0);
  45. module_param_named(burst, sym_driver_setup.burst_order, byte, 0);
  46. module_param_named(led, sym_driver_setup.scsi_led, byte, 0);
  47. module_param_named(diff, sym_driver_setup.scsi_diff, byte, 0);
  48. module_param_named(irqm, sym_driver_setup.irq_mode, byte, 0);
  49. module_param_named(buschk, sym_driver_setup.scsi_bus_check, byte, 0);
  50. module_param_named(hostid, sym_driver_setup.host_id, byte, 0);
  51. module_param_named(verb, sym_driver_setup.verbose, byte, 0);
  52. module_param_named(debug, sym_debug_flags, uint, 0);
  53. module_param_named(settle, sym_driver_setup.settle_delay, byte, 0);
  54. module_param_named(nvram, sym_driver_setup.use_nvram, byte, 0);
  55. module_param_named(excl, excl_string, charp, 0);
  56. module_param_named(safe, safe_string, charp, 0);
  57. MODULE_PARM_DESC(cmd_per_lun, "The maximum number of tags to use by default");
  58. MODULE_PARM_DESC(burst, "Maximum burst. 0 to disable, 255 to read from registers");
  59. MODULE_PARM_DESC(led, "Set to 1 to enable LED support");
  60. MODULE_PARM_DESC(diff, "0 for no differential mode, 1 for BIOS, 2 for always, 3 for not GPIO3");
  61. MODULE_PARM_DESC(irqm, "0 for open drain, 1 to leave alone, 2 for totem pole");
  62. MODULE_PARM_DESC(buschk, "0 to not check, 1 for detach on error, 2 for warn on error");
  63. MODULE_PARM_DESC(hostid, "The SCSI ID to use for the host adapters");
  64. MODULE_PARM_DESC(verb, "0 for minimal verbosity, 1 for normal, 2 for excessive");
  65. MODULE_PARM_DESC(debug, "Set bits to enable debugging");
  66. MODULE_PARM_DESC(settle, "Settle delay in seconds. Default 3");
  67. MODULE_PARM_DESC(nvram, "Option currently not used");
  68. MODULE_PARM_DESC(excl, "List ioport addresses here to prevent controllers from being attached");
  69. MODULE_PARM_DESC(safe, "Set other settings to a \"safe mode\"");
  70. MODULE_LICENSE("GPL");
  71. MODULE_VERSION(SYM_VERSION);
  72. MODULE_AUTHOR("Matthew Wilcox <[email protected]>");
  73. MODULE_DESCRIPTION("NCR, Symbios and LSI 8xx and 1010 PCI SCSI adapters");
  74. static void sym2_setup_params(void)
  75. {
  76. char *p = excl_string;
  77. int xi = 0;
  78. while (p && (xi < 8)) {
  79. char *next_p;
  80. int val = (int) simple_strtoul(p, &next_p, 0);
  81. sym_driver_setup.excludes[xi++] = val;
  82. p = next_p;
  83. }
  84. if (safe_string) {
  85. if (*safe_string == 'y') {
  86. sym_driver_setup.max_tag = 0;
  87. sym_driver_setup.burst_order = 0;
  88. sym_driver_setup.scsi_led = 0;
  89. sym_driver_setup.scsi_diff = 1;
  90. sym_driver_setup.irq_mode = 0;
  91. sym_driver_setup.scsi_bus_check = 2;
  92. sym_driver_setup.host_id = 7;
  93. sym_driver_setup.verbose = 2;
  94. sym_driver_setup.settle_delay = 10;
  95. sym_driver_setup.use_nvram = 1;
  96. } else if (*safe_string != 'n') {
  97. printk(KERN_WARNING NAME53C8XX "Ignoring parameter %s"
  98. " passed to safe option", safe_string);
  99. }
  100. }
  101. }
  102. static struct scsi_transport_template *sym2_transport_template = NULL;
  103. /*
  104. * Driver private area in the SCSI command structure.
  105. */
  106. struct sym_ucmd { /* Override the SCSI pointer structure */
  107. struct completion *eh_done; /* SCSI error handling */
  108. };
  109. #define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)scsi_cmd_priv(cmd))
  110. #define SYM_SOFTC_PTR(cmd) sym_get_hcb(cmd->device->host)
  111. /*
  112. * Complete a pending CAM CCB.
  113. */
  114. void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *cmd)
  115. {
  116. struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
  117. if (ucmd->eh_done)
  118. complete(ucmd->eh_done);
  119. scsi_dma_unmap(cmd);
  120. scsi_done(cmd);
  121. }
  122. /*
  123. * Tell the SCSI layer about a BUS RESET.
  124. */
  125. void sym_xpt_async_bus_reset(struct sym_hcb *np)
  126. {
  127. printf_notice("%s: SCSI BUS has been reset.\n", sym_name(np));
  128. np->s.settle_time = jiffies + sym_driver_setup.settle_delay * HZ;
  129. np->s.settle_time_valid = 1;
  130. if (sym_verbose >= 2)
  131. printf_info("%s: command processing suspended for %d seconds\n",
  132. sym_name(np), sym_driver_setup.settle_delay);
  133. }
  134. /*
  135. * Choose the more appropriate CAM status if
  136. * the IO encountered an extended error.
  137. */
  138. static int sym_xerr_cam_status(int cam_status, int x_status)
  139. {
  140. if (x_status) {
  141. if (x_status & XE_PARITY_ERR)
  142. cam_status = DID_PARITY;
  143. else
  144. cam_status = DID_ERROR;
  145. }
  146. return cam_status;
  147. }
  148. /*
  149. * Build CAM result for a failed or auto-sensed IO.
  150. */
  151. void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
  152. {
  153. struct scsi_cmnd *cmd = cp->cmd;
  154. u_int cam_status, scsi_status;
  155. cam_status = DID_OK;
  156. scsi_status = cp->ssss_status;
  157. if (cp->host_flags & HF_SENSE) {
  158. scsi_status = cp->sv_scsi_status;
  159. resid = cp->sv_resid;
  160. if (sym_verbose && cp->sv_xerr_status)
  161. sym_print_xerr(cmd, cp->sv_xerr_status);
  162. if (cp->host_status == HS_COMPLETE &&
  163. cp->ssss_status == S_GOOD &&
  164. cp->xerr_status == 0) {
  165. cam_status = sym_xerr_cam_status(DID_OK,
  166. cp->sv_xerr_status);
  167. /*
  168. * Bounce back the sense data to user.
  169. */
  170. memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  171. memcpy(cmd->sense_buffer, cp->sns_bbuf,
  172. min(SCSI_SENSE_BUFFERSIZE, SYM_SNS_BBUF_LEN));
  173. #if 0
  174. /*
  175. * If the device reports a UNIT ATTENTION condition
  176. * due to a RESET condition, we should consider all
  177. * disconnect CCBs for this unit as aborted.
  178. */
  179. if (1) {
  180. u_char *p;
  181. p = (u_char *) cmd->sense_data;
  182. if (p[0]==0x70 && p[2]==0x6 && p[12]==0x29)
  183. sym_clear_tasks(np, DID_ABORT,
  184. cp->target,cp->lun, -1);
  185. }
  186. #endif
  187. } else {
  188. /*
  189. * Error return from our internal request sense. This
  190. * is bad: we must clear the contingent allegiance
  191. * condition otherwise the device will always return
  192. * BUSY. Use a big stick.
  193. */
  194. sym_reset_scsi_target(np, cmd->device->id);
  195. cam_status = DID_ERROR;
  196. }
  197. } else if (cp->host_status == HS_COMPLETE) /* Bad SCSI status */
  198. cam_status = DID_OK;
  199. else if (cp->host_status == HS_SEL_TIMEOUT) /* Selection timeout */
  200. cam_status = DID_NO_CONNECT;
  201. else if (cp->host_status == HS_UNEXPECTED) /* Unexpected BUS FREE*/
  202. cam_status = DID_ERROR;
  203. else { /* Extended error */
  204. if (sym_verbose) {
  205. sym_print_addr(cmd, "COMMAND FAILED (%x %x %x).\n",
  206. cp->host_status, cp->ssss_status,
  207. cp->xerr_status);
  208. }
  209. /*
  210. * Set the most appropriate value for CAM status.
  211. */
  212. cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
  213. }
  214. scsi_set_resid(cmd, resid);
  215. cmd->result = (cam_status << 16) | scsi_status;
  216. }
  217. static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
  218. {
  219. int segment;
  220. int use_sg;
  221. cp->data_len = 0;
  222. use_sg = scsi_dma_map(cmd);
  223. if (use_sg > 0) {
  224. struct scatterlist *sg;
  225. struct sym_tcb *tp = &np->target[cp->target];
  226. struct sym_tblmove *data;
  227. if (use_sg > SYM_CONF_MAX_SG) {
  228. scsi_dma_unmap(cmd);
  229. return -1;
  230. }
  231. data = &cp->phys.data[SYM_CONF_MAX_SG - use_sg];
  232. scsi_for_each_sg(cmd, sg, use_sg, segment) {
  233. dma_addr_t baddr = sg_dma_address(sg);
  234. unsigned int len = sg_dma_len(sg);
  235. if ((len & 1) && (tp->head.wval & EWS)) {
  236. len++;
  237. cp->odd_byte_adjustment++;
  238. }
  239. sym_build_sge(np, &data[segment], baddr, len);
  240. cp->data_len += len;
  241. }
  242. } else {
  243. segment = -2;
  244. }
  245. return segment;
  246. }
  247. /*
  248. * Queue a SCSI command.
  249. */
  250. static int sym_queue_command(struct sym_hcb *np, struct scsi_cmnd *cmd)
  251. {
  252. struct scsi_device *sdev = cmd->device;
  253. struct sym_tcb *tp;
  254. struct sym_lcb *lp;
  255. struct sym_ccb *cp;
  256. int order;
  257. /*
  258. * Retrieve the target descriptor.
  259. */
  260. tp = &np->target[sdev->id];
  261. /*
  262. * Select tagged/untagged.
  263. */
  264. lp = sym_lp(tp, sdev->lun);
  265. order = (lp && lp->s.reqtags) ? M_SIMPLE_TAG : 0;
  266. /*
  267. * Queue the SCSI IO.
  268. */
  269. cp = sym_get_ccb(np, cmd, order);
  270. if (!cp)
  271. return 1; /* Means resource shortage */
  272. sym_queue_scsiio(np, cmd, cp);
  273. return 0;
  274. }
  275. /*
  276. * Setup buffers and pointers that address the CDB.
  277. */
  278. static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
  279. {
  280. memcpy(cp->cdb_buf, cmd->cmnd, cmd->cmd_len);
  281. cp->phys.cmd.addr = CCB_BA(cp, cdb_buf[0]);
  282. cp->phys.cmd.size = cpu_to_scr(cmd->cmd_len);
  283. return 0;
  284. }
  285. /*
  286. * Setup pointers that address the data and start the I/O.
  287. */
  288. int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
  289. {
  290. u32 lastp, goalp;
  291. int dir;
  292. /*
  293. * Build the CDB.
  294. */
  295. if (sym_setup_cdb(np, cmd, cp))
  296. goto out_abort;
  297. /*
  298. * No direction means no data.
  299. */
  300. dir = cmd->sc_data_direction;
  301. if (dir != DMA_NONE) {
  302. cp->segments = sym_scatter(np, cp, cmd);
  303. if (cp->segments < 0) {
  304. sym_set_cam_status(cmd, DID_ERROR);
  305. goto out_abort;
  306. }
  307. /*
  308. * No segments means no data.
  309. */
  310. if (!cp->segments)
  311. dir = DMA_NONE;
  312. } else {
  313. cp->data_len = 0;
  314. cp->segments = 0;
  315. }
  316. /*
  317. * Set the data pointer.
  318. */
  319. switch (dir) {
  320. case DMA_BIDIRECTIONAL:
  321. scmd_printk(KERN_INFO, cmd, "got DMA_BIDIRECTIONAL command");
  322. sym_set_cam_status(cmd, DID_ERROR);
  323. goto out_abort;
  324. case DMA_TO_DEVICE:
  325. goalp = SCRIPTA_BA(np, data_out2) + 8;
  326. lastp = goalp - 8 - (cp->segments * (2*4));
  327. break;
  328. case DMA_FROM_DEVICE:
  329. cp->host_flags |= HF_DATA_IN;
  330. goalp = SCRIPTA_BA(np, data_in2) + 8;
  331. lastp = goalp - 8 - (cp->segments * (2*4));
  332. break;
  333. case DMA_NONE:
  334. default:
  335. lastp = goalp = SCRIPTB_BA(np, no_data);
  336. break;
  337. }
  338. /*
  339. * Set all pointers values needed by SCRIPTS.
  340. */
  341. cp->phys.head.lastp = cpu_to_scr(lastp);
  342. cp->phys.head.savep = cpu_to_scr(lastp);
  343. cp->startp = cp->phys.head.savep;
  344. cp->goalp = cpu_to_scr(goalp);
  345. /*
  346. * When `#ifed 1', the code below makes the driver
  347. * panic on the first attempt to write to a SCSI device.
  348. * It is the first test we want to do after a driver
  349. * change that does not seem obviously safe. :)
  350. */
  351. #if 0
  352. switch (cp->cdb_buf[0]) {
  353. case 0x0A: case 0x2A: case 0xAA:
  354. panic("XXXXXXXXXXXXX WRITE NOT YET ALLOWED XXXXXXXXXXXXXX\n");
  355. break;
  356. default:
  357. break;
  358. }
  359. #endif
  360. /*
  361. * activate this job.
  362. */
  363. sym_put_start_queue(np, cp);
  364. return 0;
  365. out_abort:
  366. sym_free_ccb(np, cp);
  367. sym_xpt_done(np, cmd);
  368. return 0;
  369. }
  370. /*
  371. * timer daemon.
  372. *
  373. * Misused to keep the driver running when
  374. * interrupts are not configured correctly.
  375. */
  376. static void sym_timer(struct sym_hcb *np)
  377. {
  378. unsigned long thistime = jiffies;
  379. /*
  380. * Restart the timer.
  381. */
  382. np->s.timer.expires = thistime + SYM_CONF_TIMER_INTERVAL;
  383. add_timer(&np->s.timer);
  384. /*
  385. * If we are resetting the ncr, wait for settle_time before
  386. * clearing it. Then command processing will be resumed.
  387. */
  388. if (np->s.settle_time_valid) {
  389. if (time_before_eq(np->s.settle_time, thistime)) {
  390. if (sym_verbose >= 2 )
  391. printk("%s: command processing resumed\n",
  392. sym_name(np));
  393. np->s.settle_time_valid = 0;
  394. }
  395. return;
  396. }
  397. /*
  398. * Nothing to do for now, but that may come.
  399. */
  400. if (np->s.lasttime + 4*HZ < thistime) {
  401. np->s.lasttime = thistime;
  402. }
  403. #ifdef SYM_CONF_PCIQ_MAY_MISS_COMPLETIONS
  404. /*
  405. * Some way-broken PCI bridges may lead to
  406. * completions being lost when the clearing
  407. * of the INTFLY flag by the CPU occurs
  408. * concurrently with the chip raising this flag.
  409. * If this ever happen, lost completions will
  410. * be reaped here.
  411. */
  412. sym_wakeup_done(np);
  413. #endif
  414. }
  415. /*
  416. * PCI BUS error handler.
  417. */
  418. void sym_log_bus_error(struct Scsi_Host *shost)
  419. {
  420. struct sym_data *sym_data = shost_priv(shost);
  421. struct pci_dev *pdev = sym_data->pdev;
  422. unsigned short pci_sts;
  423. pci_read_config_word(pdev, PCI_STATUS, &pci_sts);
  424. if (pci_sts & 0xf900) {
  425. pci_write_config_word(pdev, PCI_STATUS, pci_sts);
  426. shost_printk(KERN_WARNING, shost,
  427. "PCI bus error: status = 0x%04x\n", pci_sts & 0xf900);
  428. }
  429. }
  430. /*
  431. * queuecommand method. Entered with the host adapter lock held and
  432. * interrupts disabled.
  433. */
  434. static int sym53c8xx_queue_command_lck(struct scsi_cmnd *cmd)
  435. {
  436. struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
  437. struct sym_ucmd *ucp = SYM_UCMD_PTR(cmd);
  438. int sts = 0;
  439. memset(ucp, 0, sizeof(*ucp));
  440. /*
  441. * Shorten our settle_time if needed for
  442. * this command not to time out.
  443. */
  444. if (np->s.settle_time_valid && scsi_cmd_to_rq(cmd)->timeout) {
  445. unsigned long tlimit = jiffies + scsi_cmd_to_rq(cmd)->timeout;
  446. tlimit -= SYM_CONF_TIMER_INTERVAL*2;
  447. if (time_after(np->s.settle_time, tlimit)) {
  448. np->s.settle_time = tlimit;
  449. }
  450. }
  451. if (np->s.settle_time_valid)
  452. return SCSI_MLQUEUE_HOST_BUSY;
  453. sts = sym_queue_command(np, cmd);
  454. if (sts)
  455. return SCSI_MLQUEUE_HOST_BUSY;
  456. return 0;
  457. }
  458. static DEF_SCSI_QCMD(sym53c8xx_queue_command)
  459. /*
  460. * Linux entry point of the interrupt handler.
  461. */
  462. static irqreturn_t sym53c8xx_intr(int irq, void *dev_id)
  463. {
  464. struct Scsi_Host *shost = dev_id;
  465. struct sym_data *sym_data = shost_priv(shost);
  466. irqreturn_t result;
  467. /* Avoid spinloop trying to handle interrupts on frozen device */
  468. if (pci_channel_offline(sym_data->pdev))
  469. return IRQ_NONE;
  470. if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("[");
  471. spin_lock(shost->host_lock);
  472. result = sym_interrupt(shost);
  473. spin_unlock(shost->host_lock);
  474. if (DEBUG_FLAGS & DEBUG_TINY) printf_debug ("]\n");
  475. return result;
  476. }
  477. /*
  478. * Linux entry point of the timer handler
  479. */
  480. static void sym53c8xx_timer(struct timer_list *t)
  481. {
  482. struct sym_hcb *np = from_timer(np, t, s.timer);
  483. unsigned long flags;
  484. spin_lock_irqsave(np->s.host->host_lock, flags);
  485. sym_timer(np);
  486. spin_unlock_irqrestore(np->s.host->host_lock, flags);
  487. }
  488. /*
  489. * What the eh thread wants us to perform.
  490. */
  491. #define SYM_EH_ABORT 0
  492. #define SYM_EH_DEVICE_RESET 1
  493. #define SYM_EH_BUS_RESET 2
  494. #define SYM_EH_HOST_RESET 3
  495. /*
  496. * Generic method for our eh processing.
  497. * The 'op' argument tells what we have to do.
  498. */
  499. static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
  500. {
  501. struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
  502. struct Scsi_Host *shost = cmd->device->host;
  503. struct sym_data *sym_data = shost_priv(shost);
  504. struct pci_dev *pdev = sym_data->pdev;
  505. struct sym_hcb *np = sym_data->ncb;
  506. SYM_QUEHEAD *qp;
  507. int cmd_queued = 0;
  508. int sts = -1;
  509. struct completion eh_done;
  510. scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname);
  511. /* We may be in an error condition because the PCI bus
  512. * went down. In this case, we need to wait until the
  513. * PCI bus is reset, the card is reset, and only then
  514. * proceed with the scsi error recovery. There's no
  515. * point in hurrying; take a leisurely wait.
  516. */
  517. #define WAIT_FOR_PCI_RECOVERY 35
  518. if (pci_channel_offline(pdev)) {
  519. int finished_reset = 0;
  520. init_completion(&eh_done);
  521. spin_lock_irq(shost->host_lock);
  522. /* Make sure we didn't race */
  523. if (pci_channel_offline(pdev)) {
  524. BUG_ON(sym_data->io_reset);
  525. sym_data->io_reset = &eh_done;
  526. } else {
  527. finished_reset = 1;
  528. }
  529. spin_unlock_irq(shost->host_lock);
  530. if (!finished_reset)
  531. finished_reset = wait_for_completion_timeout
  532. (sym_data->io_reset,
  533. WAIT_FOR_PCI_RECOVERY*HZ);
  534. spin_lock_irq(shost->host_lock);
  535. sym_data->io_reset = NULL;
  536. spin_unlock_irq(shost->host_lock);
  537. if (!finished_reset)
  538. return SCSI_FAILED;
  539. }
  540. spin_lock_irq(shost->host_lock);
  541. /* This one is queued in some place -> to wait for completion */
  542. FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
  543. struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
  544. if (cp->cmd == cmd) {
  545. cmd_queued = 1;
  546. break;
  547. }
  548. }
  549. /* Try to proceed the operation we have been asked for */
  550. sts = -1;
  551. switch(op) {
  552. case SYM_EH_ABORT:
  553. sts = sym_abort_scsiio(np, cmd, 1);
  554. break;
  555. case SYM_EH_DEVICE_RESET:
  556. sts = sym_reset_scsi_target(np, cmd->device->id);
  557. break;
  558. case SYM_EH_BUS_RESET:
  559. sym_reset_scsi_bus(np, 1);
  560. sts = 0;
  561. break;
  562. case SYM_EH_HOST_RESET:
  563. sym_reset_scsi_bus(np, 0);
  564. sym_start_up(shost, 1);
  565. sts = 0;
  566. break;
  567. default:
  568. break;
  569. }
  570. /* On error, restore everything and cross fingers :) */
  571. if (sts)
  572. cmd_queued = 0;
  573. if (cmd_queued) {
  574. init_completion(&eh_done);
  575. ucmd->eh_done = &eh_done;
  576. spin_unlock_irq(shost->host_lock);
  577. if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
  578. ucmd->eh_done = NULL;
  579. sts = -2;
  580. }
  581. } else {
  582. spin_unlock_irq(shost->host_lock);
  583. }
  584. dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
  585. sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
  586. return sts ? SCSI_FAILED : SCSI_SUCCESS;
  587. }
  588. /*
  589. * Error handlers called from the eh thread (one thread per HBA).
  590. */
  591. static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
  592. {
  593. return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
  594. }
  595. static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
  596. {
  597. return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
  598. }
  599. static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
  600. {
  601. return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
  602. }
  603. static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
  604. {
  605. return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
  606. }
  607. /*
  608. * Tune device queuing depth, according to various limits.
  609. */
  610. static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
  611. {
  612. struct sym_lcb *lp = sym_lp(tp, lun);
  613. u_short oldtags;
  614. if (!lp)
  615. return;
  616. oldtags = lp->s.reqtags;
  617. if (reqtags > lp->s.scdev_depth)
  618. reqtags = lp->s.scdev_depth;
  619. lp->s.reqtags = reqtags;
  620. if (reqtags != oldtags) {
  621. dev_info(&tp->starget->dev,
  622. "tagged command queuing %s, command queue depth %d.\n",
  623. lp->s.reqtags ? "enabled" : "disabled", reqtags);
  624. }
  625. }
  626. static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
  627. {
  628. struct sym_hcb *np = sym_get_hcb(sdev->host);
  629. struct sym_tcb *tp = &np->target[sdev->id];
  630. struct sym_lcb *lp;
  631. unsigned long flags;
  632. int error;
  633. if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
  634. return -ENXIO;
  635. spin_lock_irqsave(np->s.host->host_lock, flags);
  636. /*
  637. * Fail the device init if the device is flagged NOSCAN at BOOT in
  638. * the NVRAM. This may speed up boot and maintain coherency with
  639. * BIOS device numbering. Clearing the flag allows the user to
  640. * rescan skipped devices later. We also return an error for
  641. * devices not flagged for SCAN LUNS in the NVRAM since some single
  642. * lun devices behave badly when asked for a non zero LUN.
  643. */
  644. if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
  645. tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
  646. starget_printk(KERN_INFO, sdev->sdev_target,
  647. "Scan at boot disabled in NVRAM\n");
  648. error = -ENXIO;
  649. goto out;
  650. }
  651. if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
  652. if (sdev->lun != 0) {
  653. error = -ENXIO;
  654. goto out;
  655. }
  656. starget_printk(KERN_INFO, sdev->sdev_target,
  657. "Multiple LUNs disabled in NVRAM\n");
  658. }
  659. lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
  660. if (!lp) {
  661. error = -ENOMEM;
  662. goto out;
  663. }
  664. if (tp->nlcb == 1)
  665. tp->starget = sdev->sdev_target;
  666. spi_min_period(tp->starget) = tp->usr_period;
  667. spi_max_width(tp->starget) = tp->usr_width;
  668. error = 0;
  669. out:
  670. spin_unlock_irqrestore(np->s.host->host_lock, flags);
  671. return error;
  672. }
  673. /*
  674. * Linux entry point for device queue sizing.
  675. */
  676. static int sym53c8xx_slave_configure(struct scsi_device *sdev)
  677. {
  678. struct sym_hcb *np = sym_get_hcb(sdev->host);
  679. struct sym_tcb *tp = &np->target[sdev->id];
  680. struct sym_lcb *lp = sym_lp(tp, sdev->lun);
  681. int reqtags, depth_to_use;
  682. /*
  683. * Get user flags.
  684. */
  685. lp->curr_flags = lp->user_flags;
  686. /*
  687. * Select queue depth from driver setup.
  688. * Do not use more than configured by user.
  689. * Use at least 1.
  690. * Do not use more than our maximum.
  691. */
  692. reqtags = sym_driver_setup.max_tag;
  693. if (reqtags > tp->usrtags)
  694. reqtags = tp->usrtags;
  695. if (!sdev->tagged_supported)
  696. reqtags = 0;
  697. if (reqtags > SYM_CONF_MAX_TAG)
  698. reqtags = SYM_CONF_MAX_TAG;
  699. depth_to_use = reqtags ? reqtags : 1;
  700. scsi_change_queue_depth(sdev, depth_to_use);
  701. lp->s.scdev_depth = depth_to_use;
  702. sym_tune_dev_queuing(tp, sdev->lun, reqtags);
  703. if (!spi_initial_dv(sdev->sdev_target))
  704. spi_dv_device(sdev);
  705. return 0;
  706. }
  707. static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
  708. {
  709. struct sym_hcb *np = sym_get_hcb(sdev->host);
  710. struct sym_tcb *tp = &np->target[sdev->id];
  711. struct sym_lcb *lp = sym_lp(tp, sdev->lun);
  712. unsigned long flags;
  713. /* if slave_alloc returned before allocating a sym_lcb, return */
  714. if (!lp)
  715. return;
  716. spin_lock_irqsave(np->s.host->host_lock, flags);
  717. if (lp->busy_itlq || lp->busy_itl) {
  718. /*
  719. * This really shouldn't happen, but we can't return an error
  720. * so let's try to stop all on-going I/O.
  721. */
  722. starget_printk(KERN_WARNING, tp->starget,
  723. "Removing busy LCB (%d)\n", (u8)sdev->lun);
  724. sym_reset_scsi_bus(np, 1);
  725. }
  726. if (sym_free_lcb(np, sdev->id, sdev->lun) == 0) {
  727. /*
  728. * It was the last unit for this target.
  729. */
  730. tp->head.sval = 0;
  731. tp->head.wval = np->rv_scntl3;
  732. tp->head.uval = 0;
  733. tp->tgoal.check_nego = 1;
  734. tp->starget = NULL;
  735. }
  736. spin_unlock_irqrestore(np->s.host->host_lock, flags);
  737. }
  738. /*
  739. * Linux entry point for info() function
  740. */
  741. static const char *sym53c8xx_info (struct Scsi_Host *host)
  742. {
  743. return SYM_DRIVER_NAME;
  744. }
  745. #ifdef SYM_LINUX_PROC_INFO_SUPPORT
  746. /*
  747. * Proc file system stuff
  748. *
  749. * A read operation returns adapter information.
  750. * A write operation is a control command.
  751. * The string is parsed in the driver code and the command is passed
  752. * to the sym_usercmd() function.
  753. */
  754. #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
  755. struct sym_usrcmd {
  756. u_long target;
  757. u_long lun;
  758. u_long data;
  759. u_long cmd;
  760. };
  761. #define UC_SETSYNC 10
  762. #define UC_SETTAGS 11
  763. #define UC_SETDEBUG 12
  764. #define UC_SETWIDE 14
  765. #define UC_SETFLAG 15
  766. #define UC_SETVERBOSE 17
  767. #define UC_RESETDEV 18
  768. #define UC_CLEARDEV 19
  769. static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
  770. {
  771. struct sym_tcb *tp;
  772. int t, l;
  773. switch (uc->cmd) {
  774. case 0: return;
  775. #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
  776. case UC_SETDEBUG:
  777. sym_debug_flags = uc->data;
  778. break;
  779. #endif
  780. case UC_SETVERBOSE:
  781. np->verbose = uc->data;
  782. break;
  783. default:
  784. /*
  785. * We assume that other commands apply to targets.
  786. * This should always be the case and avoid the below
  787. * 4 lines to be repeated 6 times.
  788. */
  789. for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
  790. if (!((uc->target >> t) & 1))
  791. continue;
  792. tp = &np->target[t];
  793. if (!tp->nlcb)
  794. continue;
  795. switch (uc->cmd) {
  796. case UC_SETSYNC:
  797. if (!uc->data || uc->data >= 255) {
  798. tp->tgoal.iu = tp->tgoal.dt =
  799. tp->tgoal.qas = 0;
  800. tp->tgoal.offset = 0;
  801. } else if (uc->data <= 9 && np->minsync_dt) {
  802. if (uc->data < np->minsync_dt)
  803. uc->data = np->minsync_dt;
  804. tp->tgoal.iu = tp->tgoal.dt =
  805. tp->tgoal.qas = 1;
  806. tp->tgoal.width = 1;
  807. tp->tgoal.period = uc->data;
  808. tp->tgoal.offset = np->maxoffs_dt;
  809. } else {
  810. if (uc->data < np->minsync)
  811. uc->data = np->minsync;
  812. tp->tgoal.iu = tp->tgoal.dt =
  813. tp->tgoal.qas = 0;
  814. tp->tgoal.period = uc->data;
  815. tp->tgoal.offset = np->maxoffs;
  816. }
  817. tp->tgoal.check_nego = 1;
  818. break;
  819. case UC_SETWIDE:
  820. tp->tgoal.width = uc->data ? 1 : 0;
  821. tp->tgoal.check_nego = 1;
  822. break;
  823. case UC_SETTAGS:
  824. for (l = 0; l < SYM_CONF_MAX_LUN; l++)
  825. sym_tune_dev_queuing(tp, l, uc->data);
  826. break;
  827. case UC_RESETDEV:
  828. tp->to_reset = 1;
  829. np->istat_sem = SEM;
  830. OUTB(np, nc_istat, SIGP|SEM);
  831. break;
  832. case UC_CLEARDEV:
  833. for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
  834. struct sym_lcb *lp = sym_lp(tp, l);
  835. if (lp) lp->to_clear = 1;
  836. }
  837. np->istat_sem = SEM;
  838. OUTB(np, nc_istat, SIGP|SEM);
  839. break;
  840. case UC_SETFLAG:
  841. tp->usrflags = uc->data;
  842. break;
  843. }
  844. }
  845. break;
  846. }
  847. }
  848. static int sym_skip_spaces(char *ptr, int len)
  849. {
  850. int cnt, c;
  851. for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
  852. return (len - cnt);
  853. }
  854. static int get_int_arg(char *ptr, int len, u_long *pv)
  855. {
  856. char *end;
  857. *pv = simple_strtoul(ptr, &end, 10);
  858. return (end - ptr);
  859. }
  860. static int is_keyword(char *ptr, int len, char *verb)
  861. {
  862. int verb_len = strlen(verb);
  863. if (len >= verb_len && !memcmp(verb, ptr, verb_len))
  864. return verb_len;
  865. else
  866. return 0;
  867. }
  868. #define SKIP_SPACES(ptr, len) \
  869. if ((arg_len = sym_skip_spaces(ptr, len)) < 1) \
  870. return -EINVAL; \
  871. ptr += arg_len; len -= arg_len;
  872. #define GET_INT_ARG(ptr, len, v) \
  873. if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
  874. return -EINVAL; \
  875. ptr += arg_len; len -= arg_len;
  876. /*
  877. * Parse a control command
  878. */
  879. static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
  880. {
  881. struct sym_hcb *np = sym_get_hcb(shost);
  882. char *ptr = buffer;
  883. int len = length;
  884. struct sym_usrcmd cmd, *uc = &cmd;
  885. int arg_len;
  886. u_long target;
  887. memset(uc, 0, sizeof(*uc));
  888. if (len > 0 && ptr[len-1] == '\n')
  889. --len;
  890. if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
  891. uc->cmd = UC_SETSYNC;
  892. else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
  893. uc->cmd = UC_SETTAGS;
  894. else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
  895. uc->cmd = UC_SETVERBOSE;
  896. else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
  897. uc->cmd = UC_SETWIDE;
  898. #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
  899. else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
  900. uc->cmd = UC_SETDEBUG;
  901. #endif
  902. else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
  903. uc->cmd = UC_SETFLAG;
  904. else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
  905. uc->cmd = UC_RESETDEV;
  906. else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
  907. uc->cmd = UC_CLEARDEV;
  908. else
  909. arg_len = 0;
  910. #ifdef DEBUG_PROC_INFO
  911. printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
  912. #endif
  913. if (!arg_len)
  914. return -EINVAL;
  915. ptr += arg_len; len -= arg_len;
  916. switch(uc->cmd) {
  917. case UC_SETSYNC:
  918. case UC_SETTAGS:
  919. case UC_SETWIDE:
  920. case UC_SETFLAG:
  921. case UC_RESETDEV:
  922. case UC_CLEARDEV:
  923. SKIP_SPACES(ptr, len);
  924. if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
  925. ptr += arg_len; len -= arg_len;
  926. uc->target = ~0;
  927. } else {
  928. GET_INT_ARG(ptr, len, target);
  929. uc->target = (1<<target);
  930. #ifdef DEBUG_PROC_INFO
  931. printk("sym_user_command: target=%ld\n", target);
  932. #endif
  933. }
  934. break;
  935. }
  936. switch(uc->cmd) {
  937. case UC_SETVERBOSE:
  938. case UC_SETSYNC:
  939. case UC_SETTAGS:
  940. case UC_SETWIDE:
  941. SKIP_SPACES(ptr, len);
  942. GET_INT_ARG(ptr, len, uc->data);
  943. #ifdef DEBUG_PROC_INFO
  944. printk("sym_user_command: data=%ld\n", uc->data);
  945. #endif
  946. break;
  947. #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
  948. case UC_SETDEBUG:
  949. while (len > 0) {
  950. SKIP_SPACES(ptr, len);
  951. if ((arg_len = is_keyword(ptr, len, "alloc")))
  952. uc->data |= DEBUG_ALLOC;
  953. else if ((arg_len = is_keyword(ptr, len, "phase")))
  954. uc->data |= DEBUG_PHASE;
  955. else if ((arg_len = is_keyword(ptr, len, "queue")))
  956. uc->data |= DEBUG_QUEUE;
  957. else if ((arg_len = is_keyword(ptr, len, "result")))
  958. uc->data |= DEBUG_RESULT;
  959. else if ((arg_len = is_keyword(ptr, len, "scatter")))
  960. uc->data |= DEBUG_SCATTER;
  961. else if ((arg_len = is_keyword(ptr, len, "script")))
  962. uc->data |= DEBUG_SCRIPT;
  963. else if ((arg_len = is_keyword(ptr, len, "tiny")))
  964. uc->data |= DEBUG_TINY;
  965. else if ((arg_len = is_keyword(ptr, len, "timing")))
  966. uc->data |= DEBUG_TIMING;
  967. else if ((arg_len = is_keyword(ptr, len, "nego")))
  968. uc->data |= DEBUG_NEGO;
  969. else if ((arg_len = is_keyword(ptr, len, "tags")))
  970. uc->data |= DEBUG_TAGS;
  971. else if ((arg_len = is_keyword(ptr, len, "pointer")))
  972. uc->data |= DEBUG_POINTER;
  973. else
  974. return -EINVAL;
  975. ptr += arg_len; len -= arg_len;
  976. }
  977. #ifdef DEBUG_PROC_INFO
  978. printk("sym_user_command: data=%ld\n", uc->data);
  979. #endif
  980. break;
  981. #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
  982. case UC_SETFLAG:
  983. while (len > 0) {
  984. SKIP_SPACES(ptr, len);
  985. if ((arg_len = is_keyword(ptr, len, "no_disc")))
  986. uc->data &= ~SYM_DISC_ENABLED;
  987. else
  988. return -EINVAL;
  989. ptr += arg_len; len -= arg_len;
  990. }
  991. break;
  992. default:
  993. break;
  994. }
  995. if (len)
  996. return -EINVAL;
  997. else {
  998. unsigned long flags;
  999. spin_lock_irqsave(shost->host_lock, flags);
  1000. sym_exec_user_command(np, uc);
  1001. spin_unlock_irqrestore(shost->host_lock, flags);
  1002. }
  1003. return length;
  1004. }
  1005. #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
  1006. /*
  1007. * Copy formatted information into the input buffer.
  1008. */
  1009. static int sym_show_info(struct seq_file *m, struct Scsi_Host *shost)
  1010. {
  1011. #ifdef SYM_LINUX_USER_INFO_SUPPORT
  1012. struct sym_data *sym_data = shost_priv(shost);
  1013. struct pci_dev *pdev = sym_data->pdev;
  1014. struct sym_hcb *np = sym_data->ncb;
  1015. seq_printf(m, "Chip " NAME53C "%s, device id 0x%x, "
  1016. "revision id 0x%x\n", np->s.chip_name,
  1017. pdev->device, pdev->revision);
  1018. seq_printf(m, "At PCI address %s, IRQ %u\n",
  1019. pci_name(pdev), pdev->irq);
  1020. seq_printf(m, "Min. period factor %d, %s SCSI BUS%s\n",
  1021. (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
  1022. np->maxwide ? "Wide" : "Narrow",
  1023. np->minsync_dt ? ", DT capable" : "");
  1024. seq_printf(m, "Max. started commands %d, "
  1025. "max. commands per LUN %d\n",
  1026. SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
  1027. return 0;
  1028. #else
  1029. return -EINVAL;
  1030. #endif /* SYM_LINUX_USER_INFO_SUPPORT */
  1031. }
  1032. #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
  1033. /*
  1034. * Free resources claimed by sym_iomap_device(). Note that
  1035. * sym_free_resources() should be used instead of this function after calling
  1036. * sym_attach().
  1037. */
  1038. static void sym_iounmap_device(struct sym_device *device)
  1039. {
  1040. if (device->s.ioaddr)
  1041. pci_iounmap(device->pdev, device->s.ioaddr);
  1042. if (device->s.ramaddr)
  1043. pci_iounmap(device->pdev, device->s.ramaddr);
  1044. }
  1045. /*
  1046. * Free controller resources.
  1047. */
  1048. static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev,
  1049. int do_free_irq)
  1050. {
  1051. /*
  1052. * Free O/S specific resources.
  1053. */
  1054. if (do_free_irq)
  1055. free_irq(pdev->irq, np->s.host);
  1056. if (np->s.ioaddr)
  1057. pci_iounmap(pdev, np->s.ioaddr);
  1058. if (np->s.ramaddr)
  1059. pci_iounmap(pdev, np->s.ramaddr);
  1060. /*
  1061. * Free O/S independent resources.
  1062. */
  1063. sym_hcb_free(np);
  1064. sym_mfree_dma(np, sizeof(*np), "HCB");
  1065. }
  1066. /*
  1067. * Host attach and initialisations.
  1068. *
  1069. * Allocate host data and ncb structure.
  1070. * Remap MMIO region.
  1071. * Do chip initialization.
  1072. * If all is OK, install interrupt handling and
  1073. * start the timer daemon.
  1074. */
  1075. static struct Scsi_Host *sym_attach(struct scsi_host_template *tpnt, int unit,
  1076. struct sym_device *dev)
  1077. {
  1078. struct sym_data *sym_data;
  1079. struct sym_hcb *np = NULL;
  1080. struct Scsi_Host *shost = NULL;
  1081. struct pci_dev *pdev = dev->pdev;
  1082. unsigned long flags;
  1083. struct sym_fw *fw;
  1084. int do_free_irq = 0;
  1085. printk(KERN_INFO "sym%d: <%s> rev 0x%x at pci %s irq %u\n",
  1086. unit, dev->chip.name, pdev->revision, pci_name(pdev),
  1087. pdev->irq);
  1088. /*
  1089. * Get the firmware for this chip.
  1090. */
  1091. fw = sym_find_firmware(&dev->chip);
  1092. if (!fw)
  1093. goto attach_failed;
  1094. shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
  1095. if (!shost)
  1096. goto attach_failed;
  1097. sym_data = shost_priv(shost);
  1098. /*
  1099. * Allocate immediately the host control block,
  1100. * since we are only expecting to succeed. :)
  1101. * We keep track in the HCB of all the resources that
  1102. * are to be released on error.
  1103. */
  1104. np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
  1105. if (!np)
  1106. goto attach_failed;
  1107. np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
  1108. sym_data->ncb = np;
  1109. sym_data->pdev = pdev;
  1110. np->s.host = shost;
  1111. pci_set_drvdata(pdev, shost);
  1112. /*
  1113. * Copy some useful infos to the HCB.
  1114. */
  1115. np->hcb_ba = vtobus(np);
  1116. np->verbose = sym_driver_setup.verbose;
  1117. np->s.unit = unit;
  1118. np->features = dev->chip.features;
  1119. np->clock_divn = dev->chip.nr_divisor;
  1120. np->maxoffs = dev->chip.offset_max;
  1121. np->maxburst = dev->chip.burst_max;
  1122. np->myaddr = dev->host_id;
  1123. np->mmio_ba = (u32)dev->mmio_base;
  1124. np->ram_ba = (u32)dev->ram_base;
  1125. np->s.ioaddr = dev->s.ioaddr;
  1126. np->s.ramaddr = dev->s.ramaddr;
  1127. /*
  1128. * Edit its name.
  1129. */
  1130. strlcpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
  1131. sprintf(np->s.inst_name, "sym%d", np->s.unit);
  1132. if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
  1133. !dma_set_mask(&pdev->dev, DMA_DAC_MASK)) {
  1134. set_dac(np);
  1135. } else if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
  1136. printf_warning("%s: No suitable DMA available\n", sym_name(np));
  1137. goto attach_failed;
  1138. }
  1139. if (sym_hcb_attach(shost, fw, dev->nvram))
  1140. goto attach_failed;
  1141. /*
  1142. * Install the interrupt handler.
  1143. * If we synchonize the C code with SCRIPTS on interrupt,
  1144. * we do not want to share the INTR line at all.
  1145. */
  1146. if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
  1147. shost)) {
  1148. printf_err("%s: request irq %u failure\n",
  1149. sym_name(np), pdev->irq);
  1150. goto attach_failed;
  1151. }
  1152. do_free_irq = 1;
  1153. /*
  1154. * After SCSI devices have been opened, we cannot
  1155. * reset the bus safely, so we do it here.
  1156. */
  1157. spin_lock_irqsave(shost->host_lock, flags);
  1158. if (sym_reset_scsi_bus(np, 0))
  1159. goto reset_failed;
  1160. /*
  1161. * Start the SCRIPTS.
  1162. */
  1163. sym_start_up(shost, 1);
  1164. /*
  1165. * Start the timer daemon
  1166. */
  1167. timer_setup(&np->s.timer, sym53c8xx_timer, 0);
  1168. np->s.lasttime=0;
  1169. sym_timer (np);
  1170. /*
  1171. * Fill Linux host instance structure
  1172. * and return success.
  1173. */
  1174. shost->max_channel = 0;
  1175. shost->this_id = np->myaddr;
  1176. shost->max_id = np->maxwide ? 16 : 8;
  1177. shost->max_lun = SYM_CONF_MAX_LUN;
  1178. shost->unique_id = pci_resource_start(pdev, 0);
  1179. shost->cmd_per_lun = SYM_CONF_MAX_TAG;
  1180. shost->can_queue = (SYM_CONF_MAX_START-2);
  1181. shost->sg_tablesize = SYM_CONF_MAX_SG;
  1182. shost->max_cmd_len = 16;
  1183. BUG_ON(sym2_transport_template == NULL);
  1184. shost->transportt = sym2_transport_template;
  1185. /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
  1186. if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
  1187. shost->dma_boundary = 0xFFFFFF;
  1188. spin_unlock_irqrestore(shost->host_lock, flags);
  1189. return shost;
  1190. reset_failed:
  1191. printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
  1192. "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
  1193. spin_unlock_irqrestore(shost->host_lock, flags);
  1194. attach_failed:
  1195. printf_info("sym%d: giving up ...\n", unit);
  1196. if (np)
  1197. sym_free_resources(np, pdev, do_free_irq);
  1198. else
  1199. sym_iounmap_device(dev);
  1200. if (shost)
  1201. scsi_host_put(shost);
  1202. return NULL;
  1203. }
  1204. /*
  1205. * Detect and try to read SYMBIOS and TEKRAM NVRAM.
  1206. */
  1207. #if SYM_CONF_NVRAM_SUPPORT
  1208. static void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
  1209. {
  1210. devp->nvram = nvp;
  1211. nvp->type = 0;
  1212. sym_read_nvram(devp, nvp);
  1213. }
  1214. #else
  1215. static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
  1216. {
  1217. }
  1218. #endif /* SYM_CONF_NVRAM_SUPPORT */
  1219. static int sym_check_supported(struct sym_device *device)
  1220. {
  1221. struct sym_chip *chip;
  1222. struct pci_dev *pdev = device->pdev;
  1223. unsigned long io_port = pci_resource_start(pdev, 0);
  1224. int i;
  1225. /*
  1226. * If user excluded this chip, do not initialize it.
  1227. * I hate this code so much. Must kill it.
  1228. */
  1229. if (io_port) {
  1230. for (i = 0 ; i < 8 ; i++) {
  1231. if (sym_driver_setup.excludes[i] == io_port)
  1232. return -ENODEV;
  1233. }
  1234. }
  1235. /*
  1236. * Check if the chip is supported. Then copy the chip description
  1237. * to our device structure so we can make it match the actual device
  1238. * and options.
  1239. */
  1240. chip = sym_lookup_chip_table(pdev->device, pdev->revision);
  1241. if (!chip) {
  1242. dev_info(&pdev->dev, "device not supported\n");
  1243. return -ENODEV;
  1244. }
  1245. memcpy(&device->chip, chip, sizeof(device->chip));
  1246. return 0;
  1247. }
  1248. /*
  1249. * Ignore Symbios chips controlled by various RAID controllers.
  1250. * These controllers set value 0x52414944 at RAM end - 16.
  1251. */
  1252. static int sym_check_raid(struct sym_device *device)
  1253. {
  1254. unsigned int ram_size, ram_val;
  1255. if (!device->s.ramaddr)
  1256. return 0;
  1257. if (device->chip.features & FE_RAM8K)
  1258. ram_size = 8192;
  1259. else
  1260. ram_size = 4096;
  1261. ram_val = readl(device->s.ramaddr + ram_size - 16);
  1262. if (ram_val != 0x52414944)
  1263. return 0;
  1264. dev_info(&device->pdev->dev,
  1265. "not initializing, driven by RAID controller.\n");
  1266. return -ENODEV;
  1267. }
  1268. static int sym_set_workarounds(struct sym_device *device)
  1269. {
  1270. struct sym_chip *chip = &device->chip;
  1271. struct pci_dev *pdev = device->pdev;
  1272. u_short status_reg;
  1273. /*
  1274. * (ITEM 12 of a DEL about the 896 I haven't yet).
  1275. * We must ensure the chip will use WRITE AND INVALIDATE.
  1276. * The revision number limit is for now arbitrary.
  1277. */
  1278. if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 0x4) {
  1279. chip->features |= (FE_WRIE | FE_CLSE);
  1280. }
  1281. /* If the chip can do Memory Write Invalidate, enable it */
  1282. if (chip->features & FE_WRIE) {
  1283. if (pci_set_mwi(pdev))
  1284. return -ENODEV;
  1285. }
  1286. /*
  1287. * Work around for errant bit in 895A. The 66Mhz
  1288. * capable bit is set erroneously. Clear this bit.
  1289. * (Item 1 DEL 533)
  1290. *
  1291. * Make sure Config space and Features agree.
  1292. *
  1293. * Recall: writes are not normal to status register -
  1294. * write a 1 to clear and a 0 to leave unchanged.
  1295. * Can only reset bits.
  1296. */
  1297. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1298. if (chip->features & FE_66MHZ) {
  1299. if (!(status_reg & PCI_STATUS_66MHZ))
  1300. chip->features &= ~FE_66MHZ;
  1301. } else {
  1302. if (status_reg & PCI_STATUS_66MHZ) {
  1303. status_reg = PCI_STATUS_66MHZ;
  1304. pci_write_config_word(pdev, PCI_STATUS, status_reg);
  1305. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1306. }
  1307. }
  1308. return 0;
  1309. }
  1310. /*
  1311. * Map HBA registers and on-chip SRAM (if present).
  1312. */
  1313. static int sym_iomap_device(struct sym_device *device)
  1314. {
  1315. struct pci_dev *pdev = device->pdev;
  1316. struct pci_bus_region bus_addr;
  1317. int i = 2;
  1318. pcibios_resource_to_bus(pdev->bus, &bus_addr, &pdev->resource[1]);
  1319. device->mmio_base = bus_addr.start;
  1320. if (device->chip.features & FE_RAM) {
  1321. /*
  1322. * If the BAR is 64-bit, resource 2 will be occupied by the
  1323. * upper 32 bits
  1324. */
  1325. if (!pdev->resource[i].flags)
  1326. i++;
  1327. pcibios_resource_to_bus(pdev->bus, &bus_addr,
  1328. &pdev->resource[i]);
  1329. device->ram_base = bus_addr.start;
  1330. }
  1331. #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
  1332. if (device->mmio_base)
  1333. device->s.ioaddr = pci_iomap(pdev, 1,
  1334. pci_resource_len(pdev, 1));
  1335. #endif
  1336. if (!device->s.ioaddr)
  1337. device->s.ioaddr = pci_iomap(pdev, 0,
  1338. pci_resource_len(pdev, 0));
  1339. if (!device->s.ioaddr) {
  1340. dev_err(&pdev->dev, "could not map registers; giving up.\n");
  1341. return -EIO;
  1342. }
  1343. if (device->ram_base) {
  1344. device->s.ramaddr = pci_iomap(pdev, i,
  1345. pci_resource_len(pdev, i));
  1346. if (!device->s.ramaddr) {
  1347. dev_warn(&pdev->dev,
  1348. "could not map SRAM; continuing anyway.\n");
  1349. device->ram_base = 0;
  1350. }
  1351. }
  1352. return 0;
  1353. }
  1354. /*
  1355. * The NCR PQS and PDS cards are constructed as a DEC bridge
  1356. * behind which sits a proprietary NCR memory controller and
  1357. * either four or two 53c875s as separate devices. We can tell
  1358. * if an 875 is part of a PQS/PDS or not since if it is, it will
  1359. * be on the same bus as the memory controller. In its usual
  1360. * mode of operation, the 875s are slaved to the memory
  1361. * controller for all transfers. To operate with the Linux
  1362. * driver, the memory controller is disabled and the 875s
  1363. * freed to function independently. The only wrinkle is that
  1364. * the preset SCSI ID (which may be zero) must be read in from
  1365. * a special configuration space register of the 875.
  1366. */
  1367. static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
  1368. {
  1369. int slot;
  1370. u8 tmp;
  1371. for (slot = 0; slot < 256; slot++) {
  1372. struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
  1373. if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
  1374. pci_dev_put(memc);
  1375. continue;
  1376. }
  1377. /* bit 1: allow individual 875 configuration */
  1378. pci_read_config_byte(memc, 0x44, &tmp);
  1379. if ((tmp & 0x2) == 0) {
  1380. tmp |= 0x2;
  1381. pci_write_config_byte(memc, 0x44, tmp);
  1382. }
  1383. /* bit 2: drive individual 875 interrupts to the bus */
  1384. pci_read_config_byte(memc, 0x45, &tmp);
  1385. if ((tmp & 0x4) == 0) {
  1386. tmp |= 0x4;
  1387. pci_write_config_byte(memc, 0x45, tmp);
  1388. }
  1389. pci_dev_put(memc);
  1390. break;
  1391. }
  1392. pci_read_config_byte(pdev, 0x84, &tmp);
  1393. sym_dev->host_id = tmp;
  1394. }
  1395. /*
  1396. * Called before unloading the module.
  1397. * Detach the host.
  1398. * We have to free resources and halt the NCR chip.
  1399. */
  1400. static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
  1401. {
  1402. struct sym_hcb *np = sym_get_hcb(shost);
  1403. printk("%s: detaching ...\n", sym_name(np));
  1404. del_timer_sync(&np->s.timer);
  1405. /*
  1406. * Reset NCR chip.
  1407. * We should use sym_soft_reset(), but we don't want to do
  1408. * so, since we may not be safe if interrupts occur.
  1409. */
  1410. printk("%s: resetting chip\n", sym_name(np));
  1411. OUTB(np, nc_istat, SRST);
  1412. INB(np, nc_mbox1);
  1413. udelay(10);
  1414. OUTB(np, nc_istat, 0);
  1415. sym_free_resources(np, pdev, 1);
  1416. scsi_host_put(shost);
  1417. return 1;
  1418. }
  1419. /*
  1420. * Driver host template.
  1421. */
  1422. static struct scsi_host_template sym2_template = {
  1423. .module = THIS_MODULE,
  1424. .name = "sym53c8xx",
  1425. .info = sym53c8xx_info,
  1426. .cmd_size = sizeof(struct sym_ucmd),
  1427. .queuecommand = sym53c8xx_queue_command,
  1428. .slave_alloc = sym53c8xx_slave_alloc,
  1429. .slave_configure = sym53c8xx_slave_configure,
  1430. .slave_destroy = sym53c8xx_slave_destroy,
  1431. .eh_abort_handler = sym53c8xx_eh_abort_handler,
  1432. .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler,
  1433. .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
  1434. .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
  1435. .this_id = 7,
  1436. .max_sectors = 0xFFFF,
  1437. #ifdef SYM_LINUX_PROC_INFO_SUPPORT
  1438. .show_info = sym_show_info,
  1439. #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
  1440. .write_info = sym_user_command,
  1441. #endif
  1442. .proc_name = NAME53C8XX,
  1443. #endif
  1444. };
  1445. static int attach_count;
  1446. static int sym2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1447. {
  1448. struct sym_device sym_dev;
  1449. struct sym_nvram nvram;
  1450. struct Scsi_Host *shost;
  1451. int do_iounmap = 0;
  1452. int do_disable_device = 1;
  1453. memset(&sym_dev, 0, sizeof(sym_dev));
  1454. memset(&nvram, 0, sizeof(nvram));
  1455. sym_dev.pdev = pdev;
  1456. sym_dev.host_id = SYM_SETUP_HOST_ID;
  1457. if (pci_enable_device(pdev))
  1458. goto leave;
  1459. pci_set_master(pdev);
  1460. if (pci_request_regions(pdev, NAME53C8XX))
  1461. goto disable;
  1462. if (sym_check_supported(&sym_dev))
  1463. goto free;
  1464. if (sym_iomap_device(&sym_dev))
  1465. goto free;
  1466. do_iounmap = 1;
  1467. if (sym_check_raid(&sym_dev)) {
  1468. do_disable_device = 0; /* Don't disable the device */
  1469. goto free;
  1470. }
  1471. if (sym_set_workarounds(&sym_dev))
  1472. goto free;
  1473. sym_config_pqs(pdev, &sym_dev);
  1474. sym_get_nvram(&sym_dev, &nvram);
  1475. do_iounmap = 0; /* Don't sym_iounmap_device() after sym_attach(). */
  1476. shost = sym_attach(&sym2_template, attach_count, &sym_dev);
  1477. if (!shost)
  1478. goto free;
  1479. if (scsi_add_host(shost, &pdev->dev))
  1480. goto detach;
  1481. scsi_scan_host(shost);
  1482. attach_count++;
  1483. return 0;
  1484. detach:
  1485. sym_detach(pci_get_drvdata(pdev), pdev);
  1486. free:
  1487. if (do_iounmap)
  1488. sym_iounmap_device(&sym_dev);
  1489. pci_release_regions(pdev);
  1490. disable:
  1491. if (do_disable_device)
  1492. pci_disable_device(pdev);
  1493. leave:
  1494. return -ENODEV;
  1495. }
  1496. static void sym2_remove(struct pci_dev *pdev)
  1497. {
  1498. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1499. scsi_remove_host(shost);
  1500. sym_detach(shost, pdev);
  1501. pci_release_regions(pdev);
  1502. pci_disable_device(pdev);
  1503. attach_count--;
  1504. }
  1505. /**
  1506. * sym2_io_error_detected() - called when PCI error is detected
  1507. * @pdev: pointer to PCI device
  1508. * @state: current state of the PCI slot
  1509. */
  1510. static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
  1511. pci_channel_state_t state)
  1512. {
  1513. /* If slot is permanently frozen, turn everything off */
  1514. if (state == pci_channel_io_perm_failure) {
  1515. sym2_remove(pdev);
  1516. return PCI_ERS_RESULT_DISCONNECT;
  1517. }
  1518. disable_irq(pdev->irq);
  1519. pci_disable_device(pdev);
  1520. /* Request that MMIO be enabled, so register dump can be taken. */
  1521. return PCI_ERS_RESULT_CAN_RECOVER;
  1522. }
  1523. /**
  1524. * sym2_io_slot_dump - Enable MMIO and dump debug registers
  1525. * @pdev: pointer to PCI device
  1526. */
  1527. static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
  1528. {
  1529. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1530. sym_dump_registers(shost);
  1531. /* Request a slot reset. */
  1532. return PCI_ERS_RESULT_NEED_RESET;
  1533. }
  1534. /**
  1535. * sym2_reset_workarounds - hardware-specific work-arounds
  1536. * @pdev: pointer to PCI device
  1537. *
  1538. * This routine is similar to sym_set_workarounds(), except
  1539. * that, at this point, we already know that the device was
  1540. * successfully initialized at least once before, and so most
  1541. * of the steps taken there are un-needed here.
  1542. */
  1543. static void sym2_reset_workarounds(struct pci_dev *pdev)
  1544. {
  1545. u_short status_reg;
  1546. struct sym_chip *chip;
  1547. chip = sym_lookup_chip_table(pdev->device, pdev->revision);
  1548. /* Work around for errant bit in 895A, in a fashion
  1549. * similar to what is done in sym_set_workarounds().
  1550. */
  1551. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1552. if (!(chip->features & FE_66MHZ) && (status_reg & PCI_STATUS_66MHZ)) {
  1553. status_reg = PCI_STATUS_66MHZ;
  1554. pci_write_config_word(pdev, PCI_STATUS, status_reg);
  1555. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1556. }
  1557. }
  1558. /**
  1559. * sym2_io_slot_reset() - called when the pci bus has been reset.
  1560. * @pdev: pointer to PCI device
  1561. *
  1562. * Restart the card from scratch.
  1563. */
  1564. static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
  1565. {
  1566. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1567. struct sym_hcb *np = sym_get_hcb(shost);
  1568. printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
  1569. sym_name(np));
  1570. if (pci_enable_device(pdev)) {
  1571. printk(KERN_ERR "%s: Unable to enable after PCI reset\n",
  1572. sym_name(np));
  1573. return PCI_ERS_RESULT_DISCONNECT;
  1574. }
  1575. pci_set_master(pdev);
  1576. enable_irq(pdev->irq);
  1577. /* If the chip can do Memory Write Invalidate, enable it */
  1578. if (np->features & FE_WRIE) {
  1579. if (pci_set_mwi(pdev))
  1580. return PCI_ERS_RESULT_DISCONNECT;
  1581. }
  1582. /* Perform work-arounds, analogous to sym_set_workarounds() */
  1583. sym2_reset_workarounds(pdev);
  1584. /* Perform host reset only on one instance of the card */
  1585. if (PCI_FUNC(pdev->devfn) == 0) {
  1586. if (sym_reset_scsi_bus(np, 0)) {
  1587. printk(KERN_ERR "%s: Unable to reset scsi host\n",
  1588. sym_name(np));
  1589. return PCI_ERS_RESULT_DISCONNECT;
  1590. }
  1591. sym_start_up(shost, 1);
  1592. }
  1593. return PCI_ERS_RESULT_RECOVERED;
  1594. }
  1595. /**
  1596. * sym2_io_resume() - resume normal ops after PCI reset
  1597. * @pdev: pointer to PCI device
  1598. *
  1599. * Called when the error recovery driver tells us that its
  1600. * OK to resume normal operation. Use completion to allow
  1601. * halted scsi ops to resume.
  1602. */
  1603. static void sym2_io_resume(struct pci_dev *pdev)
  1604. {
  1605. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1606. struct sym_data *sym_data = shost_priv(shost);
  1607. spin_lock_irq(shost->host_lock);
  1608. if (sym_data->io_reset)
  1609. complete(sym_data->io_reset);
  1610. spin_unlock_irq(shost->host_lock);
  1611. }
  1612. static void sym2_get_signalling(struct Scsi_Host *shost)
  1613. {
  1614. struct sym_hcb *np = sym_get_hcb(shost);
  1615. enum spi_signal_type type;
  1616. switch (np->scsi_mode) {
  1617. case SMODE_SE:
  1618. type = SPI_SIGNAL_SE;
  1619. break;
  1620. case SMODE_LVD:
  1621. type = SPI_SIGNAL_LVD;
  1622. break;
  1623. case SMODE_HVD:
  1624. type = SPI_SIGNAL_HVD;
  1625. break;
  1626. default:
  1627. type = SPI_SIGNAL_UNKNOWN;
  1628. break;
  1629. }
  1630. spi_signalling(shost) = type;
  1631. }
  1632. static void sym2_set_offset(struct scsi_target *starget, int offset)
  1633. {
  1634. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1635. struct sym_hcb *np = sym_get_hcb(shost);
  1636. struct sym_tcb *tp = &np->target[starget->id];
  1637. tp->tgoal.offset = offset;
  1638. tp->tgoal.check_nego = 1;
  1639. }
  1640. static void sym2_set_period(struct scsi_target *starget, int period)
  1641. {
  1642. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1643. struct sym_hcb *np = sym_get_hcb(shost);
  1644. struct sym_tcb *tp = &np->target[starget->id];
  1645. /* have to have DT for these transfers, but DT will also
  1646. * set width, so check that this is allowed */
  1647. if (period <= np->minsync && spi_width(starget))
  1648. tp->tgoal.dt = 1;
  1649. tp->tgoal.period = period;
  1650. tp->tgoal.check_nego = 1;
  1651. }
  1652. static void sym2_set_width(struct scsi_target *starget, int width)
  1653. {
  1654. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1655. struct sym_hcb *np = sym_get_hcb(shost);
  1656. struct sym_tcb *tp = &np->target[starget->id];
  1657. /* It is illegal to have DT set on narrow transfers. If DT is
  1658. * clear, we must also clear IU and QAS. */
  1659. if (width == 0)
  1660. tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
  1661. tp->tgoal.width = width;
  1662. tp->tgoal.check_nego = 1;
  1663. }
  1664. static void sym2_set_dt(struct scsi_target *starget, int dt)
  1665. {
  1666. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1667. struct sym_hcb *np = sym_get_hcb(shost);
  1668. struct sym_tcb *tp = &np->target[starget->id];
  1669. /* We must clear QAS and IU if DT is clear */
  1670. if (dt)
  1671. tp->tgoal.dt = 1;
  1672. else
  1673. tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
  1674. tp->tgoal.check_nego = 1;
  1675. }
  1676. #if 0
  1677. static void sym2_set_iu(struct scsi_target *starget, int iu)
  1678. {
  1679. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1680. struct sym_hcb *np = sym_get_hcb(shost);
  1681. struct sym_tcb *tp = &np->target[starget->id];
  1682. if (iu)
  1683. tp->tgoal.iu = tp->tgoal.dt = 1;
  1684. else
  1685. tp->tgoal.iu = 0;
  1686. tp->tgoal.check_nego = 1;
  1687. }
  1688. static void sym2_set_qas(struct scsi_target *starget, int qas)
  1689. {
  1690. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1691. struct sym_hcb *np = sym_get_hcb(shost);
  1692. struct sym_tcb *tp = &np->target[starget->id];
  1693. if (qas)
  1694. tp->tgoal.dt = tp->tgoal.qas = 1;
  1695. else
  1696. tp->tgoal.qas = 0;
  1697. tp->tgoal.check_nego = 1;
  1698. }
  1699. #endif
  1700. static struct spi_function_template sym2_transport_functions = {
  1701. .set_offset = sym2_set_offset,
  1702. .show_offset = 1,
  1703. .set_period = sym2_set_period,
  1704. .show_period = 1,
  1705. .set_width = sym2_set_width,
  1706. .show_width = 1,
  1707. .set_dt = sym2_set_dt,
  1708. .show_dt = 1,
  1709. #if 0
  1710. .set_iu = sym2_set_iu,
  1711. .show_iu = 1,
  1712. .set_qas = sym2_set_qas,
  1713. .show_qas = 1,
  1714. #endif
  1715. .get_signalling = sym2_get_signalling,
  1716. };
  1717. static struct pci_device_id sym2_id_table[] = {
  1718. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
  1719. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1720. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
  1721. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
  1722. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
  1723. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1724. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
  1725. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1726. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
  1727. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
  1728. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
  1729. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1730. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
  1731. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
  1732. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
  1733. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1734. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
  1735. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1736. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
  1737. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1738. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
  1739. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1740. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
  1741. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
  1742. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
  1743. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1744. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
  1745. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1746. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
  1747. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1748. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
  1749. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1750. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
  1751. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1752. { 0, }
  1753. };
  1754. MODULE_DEVICE_TABLE(pci, sym2_id_table);
  1755. static const struct pci_error_handlers sym2_err_handler = {
  1756. .error_detected = sym2_io_error_detected,
  1757. .mmio_enabled = sym2_io_slot_dump,
  1758. .slot_reset = sym2_io_slot_reset,
  1759. .resume = sym2_io_resume,
  1760. };
  1761. static struct pci_driver sym2_driver = {
  1762. .name = NAME53C8XX,
  1763. .id_table = sym2_id_table,
  1764. .probe = sym2_probe,
  1765. .remove = sym2_remove,
  1766. .err_handler = &sym2_err_handler,
  1767. };
  1768. static int __init sym2_init(void)
  1769. {
  1770. int error;
  1771. sym2_setup_params();
  1772. sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
  1773. if (!sym2_transport_template)
  1774. return -ENODEV;
  1775. error = pci_register_driver(&sym2_driver);
  1776. if (error)
  1777. spi_release_transport(sym2_transport_template);
  1778. return error;
  1779. }
  1780. static void __exit sym2_exit(void)
  1781. {
  1782. pci_unregister_driver(&sym2_driver);
  1783. spi_release_transport(sym2_transport_template);
  1784. }
  1785. module_init(sym2_init);
  1786. module_exit(sym2_exit);