sym_glue.c 51 KB

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