sym_glue.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110
  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 <groudier@free.fr>
  7. * Copyright (c) 2003-2005 Matthew Wilcox <matthew@wil.cx>
  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 <wolf@cologne.de>
  17. * Stefan Esser <se@mi.Uni-Koeln.de>
  18. * Copyright (C) 1994 Wolfgang Stanglmeier
  19. *
  20. * Other major contributions:
  21. *
  22. * NVRAM detection and reading.
  23. * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
  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 <matthew@wil.cx>");
  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. /*
  494. * Generic method for our eh processing.
  495. * The 'op' argument tells what we have to do.
  496. */
  497. /*
  498. * Error handlers called from the eh thread (one thread per HBA).
  499. */
  500. static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
  501. {
  502. struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
  503. struct Scsi_Host *shost = cmd->device->host;
  504. struct sym_data *sym_data = shost_priv(shost);
  505. struct pci_dev *pdev = sym_data->pdev;
  506. struct sym_hcb *np = sym_data->ncb;
  507. SYM_QUEHEAD *qp;
  508. int cmd_queued = 0;
  509. int sts = -1;
  510. struct completion eh_done;
  511. scmd_printk(KERN_WARNING, cmd, "ABORT operation started\n");
  512. /*
  513. * Escalate to host reset if the PCI bus went down
  514. */
  515. if (pci_channel_offline(pdev))
  516. return SCSI_FAILED;
  517. spin_lock_irq(shost->host_lock);
  518. /* This one is queued in some place -> to wait for completion */
  519. FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
  520. struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
  521. if (cp->cmd == cmd) {
  522. cmd_queued = 1;
  523. break;
  524. }
  525. }
  526. sts = sym_abort_scsiio(np, cmd, 1);
  527. /* On error, restore everything and cross fingers :) */
  528. if (sts)
  529. cmd_queued = 0;
  530. if (cmd_queued) {
  531. init_completion(&eh_done);
  532. ucmd->eh_done = &eh_done;
  533. spin_unlock_irq(shost->host_lock);
  534. if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
  535. ucmd->eh_done = NULL;
  536. sts = -2;
  537. }
  538. } else {
  539. spin_unlock_irq(shost->host_lock);
  540. }
  541. dev_warn(&cmd->device->sdev_gendev, "ABORT operation %s.\n",
  542. sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
  543. return sts ? SCSI_FAILED : SCSI_SUCCESS;
  544. }
  545. static int sym53c8xx_eh_target_reset_handler(struct scsi_cmnd *cmd)
  546. {
  547. struct scsi_target *starget = scsi_target(cmd->device);
  548. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  549. struct sym_data *sym_data = shost_priv(shost);
  550. struct pci_dev *pdev = sym_data->pdev;
  551. struct sym_hcb *np = sym_data->ncb;
  552. SYM_QUEHEAD *qp;
  553. int sts;
  554. struct completion eh_done;
  555. starget_printk(KERN_WARNING, starget,
  556. "TARGET RESET operation started\n");
  557. /*
  558. * Escalate to host reset if the PCI bus went down
  559. */
  560. if (pci_channel_offline(pdev))
  561. return SCSI_FAILED;
  562. spin_lock_irq(shost->host_lock);
  563. sts = sym_reset_scsi_target(np, starget->id);
  564. if (!sts) {
  565. FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
  566. struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb,
  567. link_ccbq);
  568. struct scsi_cmnd *cmd = cp->cmd;
  569. struct sym_ucmd *ucmd;
  570. if (!cmd || cmd->device->channel != starget->channel ||
  571. cmd->device->id != starget->id)
  572. continue;
  573. ucmd = SYM_UCMD_PTR(cmd);
  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. spin_lock_irq(shost->host_lock);
  582. }
  583. }
  584. spin_unlock_irq(shost->host_lock);
  585. starget_printk(KERN_WARNING, starget, "TARGET RESET operation %s.\n",
  586. sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
  587. return SCSI_SUCCESS;
  588. }
  589. static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
  590. {
  591. struct Scsi_Host *shost = cmd->device->host;
  592. struct sym_data *sym_data = shost_priv(shost);
  593. struct pci_dev *pdev = sym_data->pdev;
  594. struct sym_hcb *np = sym_data->ncb;
  595. scmd_printk(KERN_WARNING, cmd, "BUS RESET operation started\n");
  596. /*
  597. * Escalate to host reset if the PCI bus went down
  598. */
  599. if (pci_channel_offline(pdev))
  600. return SCSI_FAILED;
  601. spin_lock_irq(shost->host_lock);
  602. sym_reset_scsi_bus(np, 1);
  603. spin_unlock_irq(shost->host_lock);
  604. dev_warn(&cmd->device->sdev_gendev, "BUS RESET operation complete.\n");
  605. return SCSI_SUCCESS;
  606. }
  607. static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
  608. {
  609. struct Scsi_Host *shost = cmd->device->host;
  610. struct sym_data *sym_data = shost_priv(shost);
  611. struct pci_dev *pdev = sym_data->pdev;
  612. struct sym_hcb *np = sym_data->ncb;
  613. struct completion eh_done;
  614. int finished_reset = 1;
  615. shost_printk(KERN_WARNING, shost, "HOST RESET operation started\n");
  616. /* We may be in an error condition because the PCI bus
  617. * went down. In this case, we need to wait until the
  618. * PCI bus is reset, the card is reset, and only then
  619. * proceed with the scsi error recovery. There's no
  620. * point in hurrying; take a leisurely wait.
  621. */
  622. #define WAIT_FOR_PCI_RECOVERY 35
  623. if (pci_channel_offline(pdev)) {
  624. init_completion(&eh_done);
  625. spin_lock_irq(shost->host_lock);
  626. /* Make sure we didn't race */
  627. if (pci_channel_offline(pdev)) {
  628. BUG_ON(sym_data->io_reset);
  629. sym_data->io_reset = &eh_done;
  630. finished_reset = 0;
  631. }
  632. spin_unlock_irq(shost->host_lock);
  633. if (!finished_reset)
  634. finished_reset = wait_for_completion_timeout
  635. (sym_data->io_reset,
  636. WAIT_FOR_PCI_RECOVERY*HZ);
  637. spin_lock_irq(shost->host_lock);
  638. sym_data->io_reset = NULL;
  639. spin_unlock_irq(shost->host_lock);
  640. }
  641. if (finished_reset) {
  642. sym_reset_scsi_bus(np, 0);
  643. sym_start_up(shost, 1);
  644. }
  645. shost_printk(KERN_WARNING, shost, "HOST RESET operation %s.\n",
  646. finished_reset==1 ? "complete" : "failed");
  647. return finished_reset ? SCSI_SUCCESS : SCSI_FAILED;
  648. }
  649. /*
  650. * Tune device queuing depth, according to various limits.
  651. */
  652. static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
  653. {
  654. struct sym_lcb *lp = sym_lp(tp, lun);
  655. u_short oldtags;
  656. if (!lp)
  657. return;
  658. oldtags = lp->s.reqtags;
  659. if (reqtags > lp->s.scdev_depth)
  660. reqtags = lp->s.scdev_depth;
  661. lp->s.reqtags = reqtags;
  662. if (reqtags != oldtags) {
  663. dev_info(&tp->starget->dev,
  664. "tagged command queuing %s, command queue depth %d.\n",
  665. lp->s.reqtags ? "enabled" : "disabled", reqtags);
  666. }
  667. }
  668. static int sym53c8xx_slave_alloc(struct scsi_device *sdev)
  669. {
  670. struct sym_hcb *np = sym_get_hcb(sdev->host);
  671. struct sym_tcb *tp = &np->target[sdev->id];
  672. struct sym_lcb *lp;
  673. unsigned long flags;
  674. int error;
  675. if (sdev->id >= SYM_CONF_MAX_TARGET || sdev->lun >= SYM_CONF_MAX_LUN)
  676. return -ENXIO;
  677. spin_lock_irqsave(np->s.host->host_lock, flags);
  678. /*
  679. * Fail the device init if the device is flagged NOSCAN at BOOT in
  680. * the NVRAM. This may speed up boot and maintain coherency with
  681. * BIOS device numbering. Clearing the flag allows the user to
  682. * rescan skipped devices later. We also return an error for
  683. * devices not flagged for SCAN LUNS in the NVRAM since some single
  684. * lun devices behave badly when asked for a non zero LUN.
  685. */
  686. if (tp->usrflags & SYM_SCAN_BOOT_DISABLED) {
  687. tp->usrflags &= ~SYM_SCAN_BOOT_DISABLED;
  688. starget_printk(KERN_INFO, sdev->sdev_target,
  689. "Scan at boot disabled in NVRAM\n");
  690. error = -ENXIO;
  691. goto out;
  692. }
  693. if (tp->usrflags & SYM_SCAN_LUNS_DISABLED) {
  694. if (sdev->lun != 0) {
  695. error = -ENXIO;
  696. goto out;
  697. }
  698. starget_printk(KERN_INFO, sdev->sdev_target,
  699. "Multiple LUNs disabled in NVRAM\n");
  700. }
  701. lp = sym_alloc_lcb(np, sdev->id, sdev->lun);
  702. if (!lp) {
  703. error = -ENOMEM;
  704. goto out;
  705. }
  706. if (tp->nlcb == 1)
  707. tp->starget = sdev->sdev_target;
  708. spi_min_period(tp->starget) = tp->usr_period;
  709. spi_max_width(tp->starget) = tp->usr_width;
  710. error = 0;
  711. out:
  712. spin_unlock_irqrestore(np->s.host->host_lock, flags);
  713. return error;
  714. }
  715. /*
  716. * Linux entry point for device queue sizing.
  717. */
  718. static int sym53c8xx_slave_configure(struct scsi_device *sdev)
  719. {
  720. struct sym_hcb *np = sym_get_hcb(sdev->host);
  721. struct sym_tcb *tp = &np->target[sdev->id];
  722. struct sym_lcb *lp = sym_lp(tp, sdev->lun);
  723. int reqtags, depth_to_use;
  724. /*
  725. * Get user flags.
  726. */
  727. lp->curr_flags = lp->user_flags;
  728. /*
  729. * Select queue depth from driver setup.
  730. * Do not use more than configured by user.
  731. * Use at least 1.
  732. * Do not use more than our maximum.
  733. */
  734. reqtags = sym_driver_setup.max_tag;
  735. if (reqtags > tp->usrtags)
  736. reqtags = tp->usrtags;
  737. if (!sdev->tagged_supported)
  738. reqtags = 0;
  739. if (reqtags > SYM_CONF_MAX_TAG)
  740. reqtags = SYM_CONF_MAX_TAG;
  741. depth_to_use = reqtags ? reqtags : 1;
  742. scsi_change_queue_depth(sdev, depth_to_use);
  743. lp->s.scdev_depth = depth_to_use;
  744. sym_tune_dev_queuing(tp, sdev->lun, reqtags);
  745. if (!spi_initial_dv(sdev->sdev_target))
  746. spi_dv_device(sdev);
  747. return 0;
  748. }
  749. static void sym53c8xx_slave_destroy(struct scsi_device *sdev)
  750. {
  751. struct sym_hcb *np = sym_get_hcb(sdev->host);
  752. struct sym_tcb *tp = &np->target[sdev->id];
  753. struct sym_lcb *lp = sym_lp(tp, sdev->lun);
  754. unsigned long flags;
  755. /* if slave_alloc returned before allocating a sym_lcb, return */
  756. if (!lp)
  757. return;
  758. spin_lock_irqsave(np->s.host->host_lock, flags);
  759. if (lp->busy_itlq || lp->busy_itl) {
  760. /*
  761. * This really shouldn't happen, but we can't return an error
  762. * so let's try to stop all on-going I/O.
  763. */
  764. starget_printk(KERN_WARNING, tp->starget,
  765. "Removing busy LCB (%d)\n", (u8)sdev->lun);
  766. sym_reset_scsi_bus(np, 1);
  767. }
  768. if (sym_free_lcb(np, sdev->id, sdev->lun) == 0) {
  769. /*
  770. * It was the last unit for this target.
  771. */
  772. tp->head.sval = 0;
  773. tp->head.wval = np->rv_scntl3;
  774. tp->head.uval = 0;
  775. tp->tgoal.check_nego = 1;
  776. tp->starget = NULL;
  777. }
  778. spin_unlock_irqrestore(np->s.host->host_lock, flags);
  779. }
  780. /*
  781. * Linux entry point for info() function
  782. */
  783. static const char *sym53c8xx_info (struct Scsi_Host *host)
  784. {
  785. return SYM_DRIVER_NAME;
  786. }
  787. #ifdef SYM_LINUX_PROC_INFO_SUPPORT
  788. /*
  789. * Proc file system stuff
  790. *
  791. * A read operation returns adapter information.
  792. * A write operation is a control command.
  793. * The string is parsed in the driver code and the command is passed
  794. * to the sym_usercmd() function.
  795. */
  796. #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
  797. struct sym_usrcmd {
  798. u_long target;
  799. u_long lun;
  800. u_long data;
  801. u_long cmd;
  802. };
  803. #define UC_SETSYNC 10
  804. #define UC_SETTAGS 11
  805. #define UC_SETDEBUG 12
  806. #define UC_SETWIDE 14
  807. #define UC_SETFLAG 15
  808. #define UC_SETVERBOSE 17
  809. #define UC_RESETDEV 18
  810. #define UC_CLEARDEV 19
  811. static void sym_exec_user_command (struct sym_hcb *np, struct sym_usrcmd *uc)
  812. {
  813. struct sym_tcb *tp;
  814. int t, l;
  815. switch (uc->cmd) {
  816. case 0: return;
  817. #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
  818. case UC_SETDEBUG:
  819. sym_debug_flags = uc->data;
  820. break;
  821. #endif
  822. case UC_SETVERBOSE:
  823. np->verbose = uc->data;
  824. break;
  825. default:
  826. /*
  827. * We assume that other commands apply to targets.
  828. * This should always be the case and avoid the below
  829. * 4 lines to be repeated 6 times.
  830. */
  831. for (t = 0; t < SYM_CONF_MAX_TARGET; t++) {
  832. if (!((uc->target >> t) & 1))
  833. continue;
  834. tp = &np->target[t];
  835. if (!tp->nlcb)
  836. continue;
  837. switch (uc->cmd) {
  838. case UC_SETSYNC:
  839. if (!uc->data || uc->data >= 255) {
  840. tp->tgoal.iu = tp->tgoal.dt =
  841. tp->tgoal.qas = 0;
  842. tp->tgoal.offset = 0;
  843. } else if (uc->data <= 9 && np->minsync_dt) {
  844. if (uc->data < np->minsync_dt)
  845. uc->data = np->minsync_dt;
  846. tp->tgoal.iu = tp->tgoal.dt =
  847. tp->tgoal.qas = 1;
  848. tp->tgoal.width = 1;
  849. tp->tgoal.period = uc->data;
  850. tp->tgoal.offset = np->maxoffs_dt;
  851. } else {
  852. if (uc->data < np->minsync)
  853. uc->data = np->minsync;
  854. tp->tgoal.iu = tp->tgoal.dt =
  855. tp->tgoal.qas = 0;
  856. tp->tgoal.period = uc->data;
  857. tp->tgoal.offset = np->maxoffs;
  858. }
  859. tp->tgoal.check_nego = 1;
  860. break;
  861. case UC_SETWIDE:
  862. tp->tgoal.width = uc->data ? 1 : 0;
  863. tp->tgoal.check_nego = 1;
  864. break;
  865. case UC_SETTAGS:
  866. for (l = 0; l < SYM_CONF_MAX_LUN; l++)
  867. sym_tune_dev_queuing(tp, l, uc->data);
  868. break;
  869. case UC_RESETDEV:
  870. tp->to_reset = 1;
  871. np->istat_sem = SEM;
  872. OUTB(np, nc_istat, SIGP|SEM);
  873. break;
  874. case UC_CLEARDEV:
  875. for (l = 0; l < SYM_CONF_MAX_LUN; l++) {
  876. struct sym_lcb *lp = sym_lp(tp, l);
  877. if (lp) lp->to_clear = 1;
  878. }
  879. np->istat_sem = SEM;
  880. OUTB(np, nc_istat, SIGP|SEM);
  881. break;
  882. case UC_SETFLAG:
  883. tp->usrflags = uc->data;
  884. break;
  885. }
  886. }
  887. break;
  888. }
  889. }
  890. static int sym_skip_spaces(char *ptr, int len)
  891. {
  892. int cnt, c;
  893. for (cnt = len; cnt > 0 && (c = *ptr++) && isspace(c); cnt--);
  894. return (len - cnt);
  895. }
  896. static int get_int_arg(char *ptr, int len, u_long *pv)
  897. {
  898. char *end;
  899. *pv = simple_strtoul(ptr, &end, 10);
  900. return (end - ptr);
  901. }
  902. static int is_keyword(char *ptr, int len, char *verb)
  903. {
  904. int verb_len = strlen(verb);
  905. if (len >= verb_len && !memcmp(verb, ptr, verb_len))
  906. return verb_len;
  907. else
  908. return 0;
  909. }
  910. #define SKIP_SPACES(ptr, len) \
  911. if ((arg_len = sym_skip_spaces(ptr, len)) < 1) \
  912. return -EINVAL; \
  913. ptr += arg_len; len -= arg_len;
  914. #define GET_INT_ARG(ptr, len, v) \
  915. if (!(arg_len = get_int_arg(ptr, len, &(v)))) \
  916. return -EINVAL; \
  917. ptr += arg_len; len -= arg_len;
  918. /*
  919. * Parse a control command
  920. */
  921. static int sym_user_command(struct Scsi_Host *shost, char *buffer, int length)
  922. {
  923. struct sym_hcb *np = sym_get_hcb(shost);
  924. char *ptr = buffer;
  925. int len = length;
  926. struct sym_usrcmd cmd, *uc = &cmd;
  927. int arg_len;
  928. u_long target;
  929. memset(uc, 0, sizeof(*uc));
  930. if (len > 0 && ptr[len-1] == '\n')
  931. --len;
  932. if ((arg_len = is_keyword(ptr, len, "setsync")) != 0)
  933. uc->cmd = UC_SETSYNC;
  934. else if ((arg_len = is_keyword(ptr, len, "settags")) != 0)
  935. uc->cmd = UC_SETTAGS;
  936. else if ((arg_len = is_keyword(ptr, len, "setverbose")) != 0)
  937. uc->cmd = UC_SETVERBOSE;
  938. else if ((arg_len = is_keyword(ptr, len, "setwide")) != 0)
  939. uc->cmd = UC_SETWIDE;
  940. #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
  941. else if ((arg_len = is_keyword(ptr, len, "setdebug")) != 0)
  942. uc->cmd = UC_SETDEBUG;
  943. #endif
  944. else if ((arg_len = is_keyword(ptr, len, "setflag")) != 0)
  945. uc->cmd = UC_SETFLAG;
  946. else if ((arg_len = is_keyword(ptr, len, "resetdev")) != 0)
  947. uc->cmd = UC_RESETDEV;
  948. else if ((arg_len = is_keyword(ptr, len, "cleardev")) != 0)
  949. uc->cmd = UC_CLEARDEV;
  950. else
  951. arg_len = 0;
  952. #ifdef DEBUG_PROC_INFO
  953. printk("sym_user_command: arg_len=%d, cmd=%ld\n", arg_len, uc->cmd);
  954. #endif
  955. if (!arg_len)
  956. return -EINVAL;
  957. ptr += arg_len; len -= arg_len;
  958. switch(uc->cmd) {
  959. case UC_SETSYNC:
  960. case UC_SETTAGS:
  961. case UC_SETWIDE:
  962. case UC_SETFLAG:
  963. case UC_RESETDEV:
  964. case UC_CLEARDEV:
  965. SKIP_SPACES(ptr, len);
  966. if ((arg_len = is_keyword(ptr, len, "all")) != 0) {
  967. ptr += arg_len; len -= arg_len;
  968. uc->target = ~0;
  969. } else {
  970. GET_INT_ARG(ptr, len, target);
  971. uc->target = (1<<target);
  972. #ifdef DEBUG_PROC_INFO
  973. printk("sym_user_command: target=%ld\n", target);
  974. #endif
  975. }
  976. break;
  977. }
  978. switch(uc->cmd) {
  979. case UC_SETVERBOSE:
  980. case UC_SETSYNC:
  981. case UC_SETTAGS:
  982. case UC_SETWIDE:
  983. SKIP_SPACES(ptr, len);
  984. GET_INT_ARG(ptr, len, uc->data);
  985. #ifdef DEBUG_PROC_INFO
  986. printk("sym_user_command: data=%ld\n", uc->data);
  987. #endif
  988. break;
  989. #ifdef SYM_LINUX_DEBUG_CONTROL_SUPPORT
  990. case UC_SETDEBUG:
  991. while (len > 0) {
  992. SKIP_SPACES(ptr, len);
  993. if ((arg_len = is_keyword(ptr, len, "alloc")))
  994. uc->data |= DEBUG_ALLOC;
  995. else if ((arg_len = is_keyword(ptr, len, "phase")))
  996. uc->data |= DEBUG_PHASE;
  997. else if ((arg_len = is_keyword(ptr, len, "queue")))
  998. uc->data |= DEBUG_QUEUE;
  999. else if ((arg_len = is_keyword(ptr, len, "result")))
  1000. uc->data |= DEBUG_RESULT;
  1001. else if ((arg_len = is_keyword(ptr, len, "scatter")))
  1002. uc->data |= DEBUG_SCATTER;
  1003. else if ((arg_len = is_keyword(ptr, len, "script")))
  1004. uc->data |= DEBUG_SCRIPT;
  1005. else if ((arg_len = is_keyword(ptr, len, "tiny")))
  1006. uc->data |= DEBUG_TINY;
  1007. else if ((arg_len = is_keyword(ptr, len, "timing")))
  1008. uc->data |= DEBUG_TIMING;
  1009. else if ((arg_len = is_keyword(ptr, len, "nego")))
  1010. uc->data |= DEBUG_NEGO;
  1011. else if ((arg_len = is_keyword(ptr, len, "tags")))
  1012. uc->data |= DEBUG_TAGS;
  1013. else if ((arg_len = is_keyword(ptr, len, "pointer")))
  1014. uc->data |= DEBUG_POINTER;
  1015. else
  1016. return -EINVAL;
  1017. ptr += arg_len; len -= arg_len;
  1018. }
  1019. #ifdef DEBUG_PROC_INFO
  1020. printk("sym_user_command: data=%ld\n", uc->data);
  1021. #endif
  1022. break;
  1023. #endif /* SYM_LINUX_DEBUG_CONTROL_SUPPORT */
  1024. case UC_SETFLAG:
  1025. while (len > 0) {
  1026. SKIP_SPACES(ptr, len);
  1027. if ((arg_len = is_keyword(ptr, len, "no_disc")))
  1028. uc->data &= ~SYM_DISC_ENABLED;
  1029. else
  1030. return -EINVAL;
  1031. ptr += arg_len; len -= arg_len;
  1032. }
  1033. break;
  1034. default:
  1035. break;
  1036. }
  1037. if (len)
  1038. return -EINVAL;
  1039. else {
  1040. unsigned long flags;
  1041. spin_lock_irqsave(shost->host_lock, flags);
  1042. sym_exec_user_command(np, uc);
  1043. spin_unlock_irqrestore(shost->host_lock, flags);
  1044. }
  1045. return length;
  1046. }
  1047. #endif /* SYM_LINUX_USER_COMMAND_SUPPORT */
  1048. /*
  1049. * Copy formatted information into the input buffer.
  1050. */
  1051. static int sym_show_info(struct seq_file *m, struct Scsi_Host *shost)
  1052. {
  1053. #ifdef SYM_LINUX_USER_INFO_SUPPORT
  1054. struct sym_data *sym_data = shost_priv(shost);
  1055. struct pci_dev *pdev = sym_data->pdev;
  1056. struct sym_hcb *np = sym_data->ncb;
  1057. seq_printf(m, "Chip " NAME53C "%s, device id 0x%x, "
  1058. "revision id 0x%x\n", np->s.chip_name,
  1059. pdev->device, pdev->revision);
  1060. seq_printf(m, "At PCI address %s, IRQ %u\n",
  1061. pci_name(pdev), pdev->irq);
  1062. seq_printf(m, "Min. period factor %d, %s SCSI BUS%s\n",
  1063. (int) (np->minsync_dt ? np->minsync_dt : np->minsync),
  1064. np->maxwide ? "Wide" : "Narrow",
  1065. np->minsync_dt ? ", DT capable" : "");
  1066. seq_printf(m, "Max. started commands %d, "
  1067. "max. commands per LUN %d\n",
  1068. SYM_CONF_MAX_START, SYM_CONF_MAX_TAG);
  1069. return 0;
  1070. #else
  1071. return -EINVAL;
  1072. #endif /* SYM_LINUX_USER_INFO_SUPPORT */
  1073. }
  1074. #endif /* SYM_LINUX_PROC_INFO_SUPPORT */
  1075. /*
  1076. * Free resources claimed by sym_iomap_device(). Note that
  1077. * sym_free_resources() should be used instead of this function after calling
  1078. * sym_attach().
  1079. */
  1080. static void sym_iounmap_device(struct sym_device *device)
  1081. {
  1082. if (device->s.ioaddr)
  1083. pci_iounmap(device->pdev, device->s.ioaddr);
  1084. if (device->s.ramaddr)
  1085. pci_iounmap(device->pdev, device->s.ramaddr);
  1086. }
  1087. /*
  1088. * Free controller resources.
  1089. */
  1090. static void sym_free_resources(struct sym_hcb *np, struct pci_dev *pdev,
  1091. int do_free_irq)
  1092. {
  1093. /*
  1094. * Free O/S specific resources.
  1095. */
  1096. if (do_free_irq)
  1097. free_irq(pdev->irq, np->s.host);
  1098. if (np->s.ioaddr)
  1099. pci_iounmap(pdev, np->s.ioaddr);
  1100. if (np->s.ramaddr)
  1101. pci_iounmap(pdev, np->s.ramaddr);
  1102. /*
  1103. * Free O/S independent resources.
  1104. */
  1105. sym_hcb_free(np);
  1106. sym_mfree_dma(np, sizeof(*np), "HCB");
  1107. }
  1108. /*
  1109. * Host attach and initialisations.
  1110. *
  1111. * Allocate host data and ncb structure.
  1112. * Remap MMIO region.
  1113. * Do chip initialization.
  1114. * If all is OK, install interrupt handling and
  1115. * start the timer daemon.
  1116. */
  1117. static struct Scsi_Host *sym_attach(const struct scsi_host_template *tpnt, int unit,
  1118. struct sym_device *dev)
  1119. {
  1120. struct sym_data *sym_data;
  1121. struct sym_hcb *np = NULL;
  1122. struct Scsi_Host *shost = NULL;
  1123. struct pci_dev *pdev = dev->pdev;
  1124. unsigned long flags;
  1125. struct sym_fw *fw;
  1126. int do_free_irq = 0;
  1127. printk(KERN_INFO "sym%d: <%s> rev 0x%x at pci %s irq %u\n",
  1128. unit, dev->chip.name, pdev->revision, pci_name(pdev),
  1129. pdev->irq);
  1130. /*
  1131. * Get the firmware for this chip.
  1132. */
  1133. fw = sym_find_firmware(&dev->chip);
  1134. if (!fw)
  1135. goto attach_failed;
  1136. shost = scsi_host_alloc(tpnt, sizeof(*sym_data));
  1137. if (!shost)
  1138. goto attach_failed;
  1139. sym_data = shost_priv(shost);
  1140. /*
  1141. * Allocate immediately the host control block,
  1142. * since we are only expecting to succeed. :)
  1143. * We keep track in the HCB of all the resources that
  1144. * are to be released on error.
  1145. */
  1146. np = __sym_calloc_dma(&pdev->dev, sizeof(*np), "HCB");
  1147. if (!np)
  1148. goto attach_failed;
  1149. np->bus_dmat = &pdev->dev; /* Result in 1 DMA pool per HBA */
  1150. sym_data->ncb = np;
  1151. sym_data->pdev = pdev;
  1152. np->s.host = shost;
  1153. pci_set_drvdata(pdev, shost);
  1154. /*
  1155. * Copy some useful infos to the HCB.
  1156. */
  1157. np->hcb_ba = vtobus(np);
  1158. np->verbose = sym_driver_setup.verbose;
  1159. np->s.unit = unit;
  1160. np->features = dev->chip.features;
  1161. np->clock_divn = dev->chip.nr_divisor;
  1162. np->maxoffs = dev->chip.offset_max;
  1163. np->maxburst = dev->chip.burst_max;
  1164. np->myaddr = dev->host_id;
  1165. np->mmio_ba = (u32)dev->mmio_base;
  1166. np->ram_ba = (u32)dev->ram_base;
  1167. np->s.ioaddr = dev->s.ioaddr;
  1168. np->s.ramaddr = dev->s.ramaddr;
  1169. /*
  1170. * Edit its name.
  1171. */
  1172. strscpy(np->s.chip_name, dev->chip.name, sizeof(np->s.chip_name));
  1173. sprintf(np->s.inst_name, "sym%d", np->s.unit);
  1174. if ((SYM_CONF_DMA_ADDRESSING_MODE > 0) && (np->features & FE_DAC) &&
  1175. !dma_set_mask(&pdev->dev, DMA_DAC_MASK)) {
  1176. set_dac(np);
  1177. } else if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
  1178. printf_warning("%s: No suitable DMA available\n", sym_name(np));
  1179. goto attach_failed;
  1180. }
  1181. if (sym_hcb_attach(shost, fw, dev->nvram))
  1182. goto attach_failed;
  1183. /*
  1184. * Install the interrupt handler.
  1185. * If we synchonize the C code with SCRIPTS on interrupt,
  1186. * we do not want to share the INTR line at all.
  1187. */
  1188. if (request_irq(pdev->irq, sym53c8xx_intr, IRQF_SHARED, NAME53C8XX,
  1189. shost)) {
  1190. printf_err("%s: request irq %u failure\n",
  1191. sym_name(np), pdev->irq);
  1192. goto attach_failed;
  1193. }
  1194. do_free_irq = 1;
  1195. /*
  1196. * After SCSI devices have been opened, we cannot
  1197. * reset the bus safely, so we do it here.
  1198. */
  1199. spin_lock_irqsave(shost->host_lock, flags);
  1200. if (sym_reset_scsi_bus(np, 0))
  1201. goto reset_failed;
  1202. /*
  1203. * Start the SCRIPTS.
  1204. */
  1205. sym_start_up(shost, 1);
  1206. /*
  1207. * Start the timer daemon
  1208. */
  1209. timer_setup(&np->s.timer, sym53c8xx_timer, 0);
  1210. np->s.lasttime=0;
  1211. sym_timer (np);
  1212. /*
  1213. * Fill Linux host instance structure
  1214. * and return success.
  1215. */
  1216. shost->max_channel = 0;
  1217. shost->this_id = np->myaddr;
  1218. shost->max_id = np->maxwide ? 16 : 8;
  1219. shost->max_lun = SYM_CONF_MAX_LUN;
  1220. shost->unique_id = pci_resource_start(pdev, 0);
  1221. shost->cmd_per_lun = SYM_CONF_MAX_TAG;
  1222. shost->can_queue = (SYM_CONF_MAX_START-2);
  1223. shost->sg_tablesize = SYM_CONF_MAX_SG;
  1224. shost->max_cmd_len = 16;
  1225. BUG_ON(sym2_transport_template == NULL);
  1226. shost->transportt = sym2_transport_template;
  1227. /* 53c896 rev 1 errata: DMA may not cross 16MB boundary */
  1228. if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 2)
  1229. shost->dma_boundary = 0xFFFFFF;
  1230. spin_unlock_irqrestore(shost->host_lock, flags);
  1231. return shost;
  1232. reset_failed:
  1233. printf_err("%s: FATAL ERROR: CHECK SCSI BUS - CABLES, "
  1234. "TERMINATION, DEVICE POWER etc.!\n", sym_name(np));
  1235. spin_unlock_irqrestore(shost->host_lock, flags);
  1236. attach_failed:
  1237. printf_info("sym%d: giving up ...\n", unit);
  1238. if (np)
  1239. sym_free_resources(np, pdev, do_free_irq);
  1240. else
  1241. sym_iounmap_device(dev);
  1242. if (shost)
  1243. scsi_host_put(shost);
  1244. return NULL;
  1245. }
  1246. /*
  1247. * Detect and try to read SYMBIOS and TEKRAM NVRAM.
  1248. */
  1249. #if SYM_CONF_NVRAM_SUPPORT
  1250. static void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
  1251. {
  1252. devp->nvram = nvp;
  1253. nvp->type = 0;
  1254. sym_read_nvram(devp, nvp);
  1255. }
  1256. #else
  1257. static inline void sym_get_nvram(struct sym_device *devp, struct sym_nvram *nvp)
  1258. {
  1259. }
  1260. #endif /* SYM_CONF_NVRAM_SUPPORT */
  1261. static int sym_check_supported(struct sym_device *device)
  1262. {
  1263. struct sym_chip *chip;
  1264. struct pci_dev *pdev = device->pdev;
  1265. unsigned long io_port = pci_resource_start(pdev, 0);
  1266. int i;
  1267. /*
  1268. * If user excluded this chip, do not initialize it.
  1269. * I hate this code so much. Must kill it.
  1270. */
  1271. if (io_port) {
  1272. for (i = 0 ; i < 8 ; i++) {
  1273. if (sym_driver_setup.excludes[i] == io_port)
  1274. return -ENODEV;
  1275. }
  1276. }
  1277. /*
  1278. * Check if the chip is supported. Then copy the chip description
  1279. * to our device structure so we can make it match the actual device
  1280. * and options.
  1281. */
  1282. chip = sym_lookup_chip_table(pdev->device, pdev->revision);
  1283. if (!chip) {
  1284. dev_info(&pdev->dev, "device not supported\n");
  1285. return -ENODEV;
  1286. }
  1287. memcpy(&device->chip, chip, sizeof(device->chip));
  1288. return 0;
  1289. }
  1290. /*
  1291. * Ignore Symbios chips controlled by various RAID controllers.
  1292. * These controllers set value 0x52414944 at RAM end - 16.
  1293. */
  1294. static int sym_check_raid(struct sym_device *device)
  1295. {
  1296. unsigned int ram_size, ram_val;
  1297. if (!device->s.ramaddr)
  1298. return 0;
  1299. if (device->chip.features & FE_RAM8K)
  1300. ram_size = 8192;
  1301. else
  1302. ram_size = 4096;
  1303. ram_val = readl(device->s.ramaddr + ram_size - 16);
  1304. if (ram_val != 0x52414944)
  1305. return 0;
  1306. dev_info(&device->pdev->dev,
  1307. "not initializing, driven by RAID controller.\n");
  1308. return -ENODEV;
  1309. }
  1310. static int sym_set_workarounds(struct sym_device *device)
  1311. {
  1312. struct sym_chip *chip = &device->chip;
  1313. struct pci_dev *pdev = device->pdev;
  1314. u_short status_reg;
  1315. /*
  1316. * (ITEM 12 of a DEL about the 896 I haven't yet).
  1317. * We must ensure the chip will use WRITE AND INVALIDATE.
  1318. * The revision number limit is for now arbitrary.
  1319. */
  1320. if (pdev->device == PCI_DEVICE_ID_NCR_53C896 && pdev->revision < 0x4) {
  1321. chip->features |= (FE_WRIE | FE_CLSE);
  1322. }
  1323. /* If the chip can do Memory Write Invalidate, enable it */
  1324. if (chip->features & FE_WRIE) {
  1325. if (pci_set_mwi(pdev))
  1326. return -ENODEV;
  1327. }
  1328. /*
  1329. * Work around for errant bit in 895A. The 66Mhz
  1330. * capable bit is set erroneously. Clear this bit.
  1331. * (Item 1 DEL 533)
  1332. *
  1333. * Make sure Config space and Features agree.
  1334. *
  1335. * Recall: writes are not normal to status register -
  1336. * write a 1 to clear and a 0 to leave unchanged.
  1337. * Can only reset bits.
  1338. */
  1339. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1340. if (chip->features & FE_66MHZ) {
  1341. if (!(status_reg & PCI_STATUS_66MHZ))
  1342. chip->features &= ~FE_66MHZ;
  1343. } else {
  1344. if (status_reg & PCI_STATUS_66MHZ) {
  1345. status_reg = PCI_STATUS_66MHZ;
  1346. pci_write_config_word(pdev, PCI_STATUS, status_reg);
  1347. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1348. }
  1349. }
  1350. return 0;
  1351. }
  1352. /*
  1353. * Map HBA registers and on-chip SRAM (if present).
  1354. */
  1355. static int sym_iomap_device(struct sym_device *device)
  1356. {
  1357. struct pci_dev *pdev = device->pdev;
  1358. struct pci_bus_region bus_addr;
  1359. int i = 2;
  1360. pcibios_resource_to_bus(pdev->bus, &bus_addr, &pdev->resource[1]);
  1361. device->mmio_base = bus_addr.start;
  1362. if (device->chip.features & FE_RAM) {
  1363. /*
  1364. * If the BAR is 64-bit, resource 2 will be occupied by the
  1365. * upper 32 bits
  1366. */
  1367. if (!pdev->resource[i].flags)
  1368. i++;
  1369. pcibios_resource_to_bus(pdev->bus, &bus_addr,
  1370. &pdev->resource[i]);
  1371. device->ram_base = bus_addr.start;
  1372. }
  1373. #ifdef CONFIG_SCSI_SYM53C8XX_MMIO
  1374. if (device->mmio_base)
  1375. device->s.ioaddr = pci_iomap(pdev, 1,
  1376. pci_resource_len(pdev, 1));
  1377. #endif
  1378. if (!device->s.ioaddr)
  1379. device->s.ioaddr = pci_iomap(pdev, 0,
  1380. pci_resource_len(pdev, 0));
  1381. if (!device->s.ioaddr) {
  1382. dev_err(&pdev->dev, "could not map registers; giving up.\n");
  1383. return -EIO;
  1384. }
  1385. if (device->ram_base) {
  1386. device->s.ramaddr = pci_iomap(pdev, i,
  1387. pci_resource_len(pdev, i));
  1388. if (!device->s.ramaddr) {
  1389. dev_warn(&pdev->dev,
  1390. "could not map SRAM; continuing anyway.\n");
  1391. device->ram_base = 0;
  1392. }
  1393. }
  1394. return 0;
  1395. }
  1396. /*
  1397. * The NCR PQS and PDS cards are constructed as a DEC bridge
  1398. * behind which sits a proprietary NCR memory controller and
  1399. * either four or two 53c875s as separate devices. We can tell
  1400. * if an 875 is part of a PQS/PDS or not since if it is, it will
  1401. * be on the same bus as the memory controller. In its usual
  1402. * mode of operation, the 875s are slaved to the memory
  1403. * controller for all transfers. To operate with the Linux
  1404. * driver, the memory controller is disabled and the 875s
  1405. * freed to function independently. The only wrinkle is that
  1406. * the preset SCSI ID (which may be zero) must be read in from
  1407. * a special configuration space register of the 875.
  1408. */
  1409. static void sym_config_pqs(struct pci_dev *pdev, struct sym_device *sym_dev)
  1410. {
  1411. int slot;
  1412. u8 tmp;
  1413. for (slot = 0; slot < 256; slot++) {
  1414. struct pci_dev *memc = pci_get_slot(pdev->bus, slot);
  1415. if (!memc || memc->vendor != 0x101a || memc->device == 0x0009) {
  1416. pci_dev_put(memc);
  1417. continue;
  1418. }
  1419. /* bit 1: allow individual 875 configuration */
  1420. pci_read_config_byte(memc, 0x44, &tmp);
  1421. if ((tmp & 0x2) == 0) {
  1422. tmp |= 0x2;
  1423. pci_write_config_byte(memc, 0x44, tmp);
  1424. }
  1425. /* bit 2: drive individual 875 interrupts to the bus */
  1426. pci_read_config_byte(memc, 0x45, &tmp);
  1427. if ((tmp & 0x4) == 0) {
  1428. tmp |= 0x4;
  1429. pci_write_config_byte(memc, 0x45, tmp);
  1430. }
  1431. pci_dev_put(memc);
  1432. break;
  1433. }
  1434. pci_read_config_byte(pdev, 0x84, &tmp);
  1435. sym_dev->host_id = tmp;
  1436. }
  1437. /*
  1438. * Called before unloading the module.
  1439. * Detach the host.
  1440. * We have to free resources and halt the NCR chip.
  1441. */
  1442. static int sym_detach(struct Scsi_Host *shost, struct pci_dev *pdev)
  1443. {
  1444. struct sym_hcb *np = sym_get_hcb(shost);
  1445. printk("%s: detaching ...\n", sym_name(np));
  1446. del_timer_sync(&np->s.timer);
  1447. /*
  1448. * Reset NCR chip.
  1449. * We should use sym_soft_reset(), but we don't want to do
  1450. * so, since we may not be safe if interrupts occur.
  1451. */
  1452. printk("%s: resetting chip\n", sym_name(np));
  1453. OUTB(np, nc_istat, SRST);
  1454. INB(np, nc_mbox1);
  1455. udelay(10);
  1456. OUTB(np, nc_istat, 0);
  1457. sym_free_resources(np, pdev, 1);
  1458. scsi_host_put(shost);
  1459. return 1;
  1460. }
  1461. /*
  1462. * Driver host template.
  1463. */
  1464. static const struct scsi_host_template sym2_template = {
  1465. .module = THIS_MODULE,
  1466. .name = "sym53c8xx",
  1467. .info = sym53c8xx_info,
  1468. .cmd_size = sizeof(struct sym_ucmd),
  1469. .queuecommand = sym53c8xx_queue_command,
  1470. .slave_alloc = sym53c8xx_slave_alloc,
  1471. .slave_configure = sym53c8xx_slave_configure,
  1472. .slave_destroy = sym53c8xx_slave_destroy,
  1473. .eh_abort_handler = sym53c8xx_eh_abort_handler,
  1474. .eh_target_reset_handler = sym53c8xx_eh_target_reset_handler,
  1475. .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
  1476. .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
  1477. .this_id = 7,
  1478. .max_sectors = 0xFFFF,
  1479. #ifdef SYM_LINUX_PROC_INFO_SUPPORT
  1480. .show_info = sym_show_info,
  1481. #ifdef SYM_LINUX_USER_COMMAND_SUPPORT
  1482. .write_info = sym_user_command,
  1483. #endif
  1484. .proc_name = NAME53C8XX,
  1485. #endif
  1486. };
  1487. static int attach_count;
  1488. static int sym2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1489. {
  1490. struct sym_device sym_dev;
  1491. struct sym_nvram nvram;
  1492. struct Scsi_Host *shost;
  1493. int do_iounmap = 0;
  1494. int do_disable_device = 1;
  1495. memset(&sym_dev, 0, sizeof(sym_dev));
  1496. memset(&nvram, 0, sizeof(nvram));
  1497. sym_dev.pdev = pdev;
  1498. sym_dev.host_id = SYM_SETUP_HOST_ID;
  1499. if (pci_enable_device(pdev))
  1500. goto leave;
  1501. pci_set_master(pdev);
  1502. if (pci_request_regions(pdev, NAME53C8XX))
  1503. goto disable;
  1504. if (sym_check_supported(&sym_dev))
  1505. goto free;
  1506. if (sym_iomap_device(&sym_dev))
  1507. goto free;
  1508. do_iounmap = 1;
  1509. if (sym_check_raid(&sym_dev)) {
  1510. do_disable_device = 0; /* Don't disable the device */
  1511. goto free;
  1512. }
  1513. if (sym_set_workarounds(&sym_dev))
  1514. goto free;
  1515. sym_config_pqs(pdev, &sym_dev);
  1516. sym_get_nvram(&sym_dev, &nvram);
  1517. do_iounmap = 0; /* Don't sym_iounmap_device() after sym_attach(). */
  1518. shost = sym_attach(&sym2_template, attach_count, &sym_dev);
  1519. if (!shost)
  1520. goto free;
  1521. if (scsi_add_host(shost, &pdev->dev))
  1522. goto detach;
  1523. scsi_scan_host(shost);
  1524. attach_count++;
  1525. return 0;
  1526. detach:
  1527. sym_detach(pci_get_drvdata(pdev), pdev);
  1528. free:
  1529. if (do_iounmap)
  1530. sym_iounmap_device(&sym_dev);
  1531. pci_release_regions(pdev);
  1532. disable:
  1533. if (do_disable_device)
  1534. pci_disable_device(pdev);
  1535. leave:
  1536. return -ENODEV;
  1537. }
  1538. static void sym2_remove(struct pci_dev *pdev)
  1539. {
  1540. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1541. scsi_remove_host(shost);
  1542. sym_detach(shost, pdev);
  1543. pci_release_regions(pdev);
  1544. pci_disable_device(pdev);
  1545. attach_count--;
  1546. }
  1547. /**
  1548. * sym2_io_error_detected() - called when PCI error is detected
  1549. * @pdev: pointer to PCI device
  1550. * @state: current state of the PCI slot
  1551. */
  1552. static pci_ers_result_t sym2_io_error_detected(struct pci_dev *pdev,
  1553. pci_channel_state_t state)
  1554. {
  1555. /* If slot is permanently frozen, turn everything off */
  1556. if (state == pci_channel_io_perm_failure) {
  1557. sym2_remove(pdev);
  1558. return PCI_ERS_RESULT_DISCONNECT;
  1559. }
  1560. disable_irq(pdev->irq);
  1561. pci_disable_device(pdev);
  1562. /* Request that MMIO be enabled, so register dump can be taken. */
  1563. return PCI_ERS_RESULT_CAN_RECOVER;
  1564. }
  1565. /**
  1566. * sym2_io_slot_dump - Enable MMIO and dump debug registers
  1567. * @pdev: pointer to PCI device
  1568. */
  1569. static pci_ers_result_t sym2_io_slot_dump(struct pci_dev *pdev)
  1570. {
  1571. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1572. sym_dump_registers(shost);
  1573. /* Request a slot reset. */
  1574. return PCI_ERS_RESULT_NEED_RESET;
  1575. }
  1576. /**
  1577. * sym2_reset_workarounds - hardware-specific work-arounds
  1578. * @pdev: pointer to PCI device
  1579. *
  1580. * This routine is similar to sym_set_workarounds(), except
  1581. * that, at this point, we already know that the device was
  1582. * successfully initialized at least once before, and so most
  1583. * of the steps taken there are un-needed here.
  1584. */
  1585. static void sym2_reset_workarounds(struct pci_dev *pdev)
  1586. {
  1587. u_short status_reg;
  1588. struct sym_chip *chip;
  1589. chip = sym_lookup_chip_table(pdev->device, pdev->revision);
  1590. /* Work around for errant bit in 895A, in a fashion
  1591. * similar to what is done in sym_set_workarounds().
  1592. */
  1593. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1594. if (!(chip->features & FE_66MHZ) && (status_reg & PCI_STATUS_66MHZ)) {
  1595. status_reg = PCI_STATUS_66MHZ;
  1596. pci_write_config_word(pdev, PCI_STATUS, status_reg);
  1597. pci_read_config_word(pdev, PCI_STATUS, &status_reg);
  1598. }
  1599. }
  1600. /**
  1601. * sym2_io_slot_reset() - called when the pci bus has been reset.
  1602. * @pdev: pointer to PCI device
  1603. *
  1604. * Restart the card from scratch.
  1605. */
  1606. static pci_ers_result_t sym2_io_slot_reset(struct pci_dev *pdev)
  1607. {
  1608. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1609. struct sym_hcb *np = sym_get_hcb(shost);
  1610. printk(KERN_INFO "%s: recovering from a PCI slot reset\n",
  1611. sym_name(np));
  1612. if (pci_enable_device(pdev)) {
  1613. printk(KERN_ERR "%s: Unable to enable after PCI reset\n",
  1614. sym_name(np));
  1615. return PCI_ERS_RESULT_DISCONNECT;
  1616. }
  1617. pci_set_master(pdev);
  1618. enable_irq(pdev->irq);
  1619. /* If the chip can do Memory Write Invalidate, enable it */
  1620. if (np->features & FE_WRIE) {
  1621. if (pci_set_mwi(pdev))
  1622. return PCI_ERS_RESULT_DISCONNECT;
  1623. }
  1624. /* Perform work-arounds, analogous to sym_set_workarounds() */
  1625. sym2_reset_workarounds(pdev);
  1626. /* Perform host reset only on one instance of the card */
  1627. if (PCI_FUNC(pdev->devfn) == 0) {
  1628. if (sym_reset_scsi_bus(np, 0)) {
  1629. printk(KERN_ERR "%s: Unable to reset scsi host\n",
  1630. sym_name(np));
  1631. return PCI_ERS_RESULT_DISCONNECT;
  1632. }
  1633. sym_start_up(shost, 1);
  1634. }
  1635. return PCI_ERS_RESULT_RECOVERED;
  1636. }
  1637. /**
  1638. * sym2_io_resume() - resume normal ops after PCI reset
  1639. * @pdev: pointer to PCI device
  1640. *
  1641. * Called when the error recovery driver tells us that its
  1642. * OK to resume normal operation. Use completion to allow
  1643. * halted scsi ops to resume.
  1644. */
  1645. static void sym2_io_resume(struct pci_dev *pdev)
  1646. {
  1647. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1648. struct sym_data *sym_data = shost_priv(shost);
  1649. spin_lock_irq(shost->host_lock);
  1650. if (sym_data->io_reset)
  1651. complete(sym_data->io_reset);
  1652. spin_unlock_irq(shost->host_lock);
  1653. }
  1654. static void sym2_get_signalling(struct Scsi_Host *shost)
  1655. {
  1656. struct sym_hcb *np = sym_get_hcb(shost);
  1657. enum spi_signal_type type;
  1658. switch (np->scsi_mode) {
  1659. case SMODE_SE:
  1660. type = SPI_SIGNAL_SE;
  1661. break;
  1662. case SMODE_LVD:
  1663. type = SPI_SIGNAL_LVD;
  1664. break;
  1665. case SMODE_HVD:
  1666. type = SPI_SIGNAL_HVD;
  1667. break;
  1668. default:
  1669. type = SPI_SIGNAL_UNKNOWN;
  1670. break;
  1671. }
  1672. spi_signalling(shost) = type;
  1673. }
  1674. static void sym2_set_offset(struct scsi_target *starget, int offset)
  1675. {
  1676. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1677. struct sym_hcb *np = sym_get_hcb(shost);
  1678. struct sym_tcb *tp = &np->target[starget->id];
  1679. tp->tgoal.offset = offset;
  1680. tp->tgoal.check_nego = 1;
  1681. }
  1682. static void sym2_set_period(struct scsi_target *starget, int period)
  1683. {
  1684. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1685. struct sym_hcb *np = sym_get_hcb(shost);
  1686. struct sym_tcb *tp = &np->target[starget->id];
  1687. /* have to have DT for these transfers, but DT will also
  1688. * set width, so check that this is allowed */
  1689. if (period <= np->minsync && spi_width(starget))
  1690. tp->tgoal.dt = 1;
  1691. tp->tgoal.period = period;
  1692. tp->tgoal.check_nego = 1;
  1693. }
  1694. static void sym2_set_width(struct scsi_target *starget, int width)
  1695. {
  1696. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1697. struct sym_hcb *np = sym_get_hcb(shost);
  1698. struct sym_tcb *tp = &np->target[starget->id];
  1699. /* It is illegal to have DT set on narrow transfers. If DT is
  1700. * clear, we must also clear IU and QAS. */
  1701. if (width == 0)
  1702. tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
  1703. tp->tgoal.width = width;
  1704. tp->tgoal.check_nego = 1;
  1705. }
  1706. static void sym2_set_dt(struct scsi_target *starget, int dt)
  1707. {
  1708. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1709. struct sym_hcb *np = sym_get_hcb(shost);
  1710. struct sym_tcb *tp = &np->target[starget->id];
  1711. /* We must clear QAS and IU if DT is clear */
  1712. if (dt)
  1713. tp->tgoal.dt = 1;
  1714. else
  1715. tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
  1716. tp->tgoal.check_nego = 1;
  1717. }
  1718. #if 0
  1719. static void sym2_set_iu(struct scsi_target *starget, int iu)
  1720. {
  1721. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1722. struct sym_hcb *np = sym_get_hcb(shost);
  1723. struct sym_tcb *tp = &np->target[starget->id];
  1724. if (iu)
  1725. tp->tgoal.iu = tp->tgoal.dt = 1;
  1726. else
  1727. tp->tgoal.iu = 0;
  1728. tp->tgoal.check_nego = 1;
  1729. }
  1730. static void sym2_set_qas(struct scsi_target *starget, int qas)
  1731. {
  1732. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1733. struct sym_hcb *np = sym_get_hcb(shost);
  1734. struct sym_tcb *tp = &np->target[starget->id];
  1735. if (qas)
  1736. tp->tgoal.dt = tp->tgoal.qas = 1;
  1737. else
  1738. tp->tgoal.qas = 0;
  1739. tp->tgoal.check_nego = 1;
  1740. }
  1741. #endif
  1742. static struct spi_function_template sym2_transport_functions = {
  1743. .set_offset = sym2_set_offset,
  1744. .show_offset = 1,
  1745. .set_period = sym2_set_period,
  1746. .show_period = 1,
  1747. .set_width = sym2_set_width,
  1748. .show_width = 1,
  1749. .set_dt = sym2_set_dt,
  1750. .show_dt = 1,
  1751. #if 0
  1752. .set_iu = sym2_set_iu,
  1753. .show_iu = 1,
  1754. .set_qas = sym2_set_qas,
  1755. .show_qas = 1,
  1756. #endif
  1757. .get_signalling = sym2_get_signalling,
  1758. };
  1759. static struct pci_device_id sym2_id_table[] = {
  1760. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
  1761. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1762. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
  1763. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
  1764. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
  1765. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1766. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
  1767. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1768. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
  1769. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
  1770. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
  1771. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1772. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
  1773. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
  1774. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
  1775. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1776. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
  1777. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1778. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
  1779. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1780. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
  1781. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1782. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
  1783. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
  1784. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
  1785. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1786. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
  1787. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1788. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
  1789. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1790. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
  1791. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1792. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
  1793. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1794. { 0, }
  1795. };
  1796. MODULE_DEVICE_TABLE(pci, sym2_id_table);
  1797. static const struct pci_error_handlers sym2_err_handler = {
  1798. .error_detected = sym2_io_error_detected,
  1799. .mmio_enabled = sym2_io_slot_dump,
  1800. .slot_reset = sym2_io_slot_reset,
  1801. .resume = sym2_io_resume,
  1802. };
  1803. static struct pci_driver sym2_driver = {
  1804. .name = NAME53C8XX,
  1805. .id_table = sym2_id_table,
  1806. .probe = sym2_probe,
  1807. .remove = sym2_remove,
  1808. .err_handler = &sym2_err_handler,
  1809. };
  1810. static int __init sym2_init(void)
  1811. {
  1812. int error;
  1813. sym2_setup_params();
  1814. sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
  1815. if (!sym2_transport_template)
  1816. return -ENODEV;
  1817. error = pci_register_driver(&sym2_driver);
  1818. if (error)
  1819. spi_release_transport(sym2_transport_template);
  1820. return error;
  1821. }
  1822. static void __exit sym2_exit(void)
  1823. {
  1824. pci_unregister_driver(&sym2_driver);
  1825. spi_release_transport(sym2_transport_template);
  1826. }
  1827. module_init(sym2_init);
  1828. module_exit(sym2_exit);