sym_glue.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  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. .use_sg_chaining = ENABLE_SG_CHAINING,
  1586. .max_sectors = 0xFFFF,
  1587. #ifdef SYM_LINUX_PROC_INFO_SUPPORT
  1588. .proc_info = sym53c8xx_proc_info,
  1589. .proc_name = NAME53C8XX,
  1590. #endif
  1591. };
  1592. static int attach_count;
  1593. static int __devinit sym2_probe(struct pci_dev *pdev,
  1594. const struct pci_device_id *ent)
  1595. {
  1596. struct sym_device sym_dev;
  1597. struct sym_nvram nvram;
  1598. struct Scsi_Host *instance;
  1599. memset(&sym_dev, 0, sizeof(sym_dev));
  1600. memset(&nvram, 0, sizeof(nvram));
  1601. if (pci_enable_device(pdev))
  1602. goto leave;
  1603. pci_set_master(pdev);
  1604. if (pci_request_regions(pdev, NAME53C8XX))
  1605. goto disable;
  1606. sym_init_device(pdev, &sym_dev);
  1607. if (sym_check_supported(&sym_dev))
  1608. goto free;
  1609. if (sym_check_raid(&sym_dev))
  1610. goto leave; /* Don't disable the device */
  1611. if (sym_set_workarounds(&sym_dev))
  1612. goto free;
  1613. sym_config_pqs(pdev, &sym_dev);
  1614. sym_get_nvram(&sym_dev, &nvram);
  1615. instance = sym_attach(&sym2_template, attach_count, &sym_dev);
  1616. if (!instance)
  1617. goto free;
  1618. if (scsi_add_host(instance, &pdev->dev))
  1619. goto detach;
  1620. scsi_scan_host(instance);
  1621. attach_count++;
  1622. return 0;
  1623. detach:
  1624. sym_detach(pci_get_drvdata(pdev), pdev);
  1625. free:
  1626. pci_release_regions(pdev);
  1627. disable:
  1628. pci_disable_device(pdev);
  1629. leave:
  1630. return -ENODEV;
  1631. }
  1632. static void __devexit sym2_remove(struct pci_dev *pdev)
  1633. {
  1634. struct sym_hcb *np = pci_get_drvdata(pdev);
  1635. struct Scsi_Host *host = np->s.host;
  1636. scsi_remove_host(host);
  1637. scsi_host_put(host);
  1638. sym_detach(np, pdev);
  1639. pci_release_regions(pdev);
  1640. pci_disable_device(pdev);
  1641. attach_count--;
  1642. }
  1643. static void sym2_get_signalling(struct Scsi_Host *shost)
  1644. {
  1645. struct sym_hcb *np = sym_get_hcb(shost);
  1646. enum spi_signal_type type;
  1647. switch (np->scsi_mode) {
  1648. case SMODE_SE:
  1649. type = SPI_SIGNAL_SE;
  1650. break;
  1651. case SMODE_LVD:
  1652. type = SPI_SIGNAL_LVD;
  1653. break;
  1654. case SMODE_HVD:
  1655. type = SPI_SIGNAL_HVD;
  1656. break;
  1657. default:
  1658. type = SPI_SIGNAL_UNKNOWN;
  1659. break;
  1660. }
  1661. spi_signalling(shost) = type;
  1662. }
  1663. static void sym2_set_offset(struct scsi_target *starget, int offset)
  1664. {
  1665. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1666. struct sym_hcb *np = sym_get_hcb(shost);
  1667. struct sym_tcb *tp = &np->target[starget->id];
  1668. tp->tgoal.offset = offset;
  1669. tp->tgoal.check_nego = 1;
  1670. }
  1671. static void sym2_set_period(struct scsi_target *starget, int period)
  1672. {
  1673. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1674. struct sym_hcb *np = sym_get_hcb(shost);
  1675. struct sym_tcb *tp = &np->target[starget->id];
  1676. /* have to have DT for these transfers, but DT will also
  1677. * set width, so check that this is allowed */
  1678. if (period <= np->minsync && spi_width(starget))
  1679. tp->tgoal.dt = 1;
  1680. tp->tgoal.period = period;
  1681. tp->tgoal.check_nego = 1;
  1682. }
  1683. static void sym2_set_width(struct scsi_target *starget, int width)
  1684. {
  1685. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1686. struct sym_hcb *np = sym_get_hcb(shost);
  1687. struct sym_tcb *tp = &np->target[starget->id];
  1688. /* It is illegal to have DT set on narrow transfers. If DT is
  1689. * clear, we must also clear IU and QAS. */
  1690. if (width == 0)
  1691. tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
  1692. tp->tgoal.width = width;
  1693. tp->tgoal.check_nego = 1;
  1694. }
  1695. static void sym2_set_dt(struct scsi_target *starget, int dt)
  1696. {
  1697. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1698. struct sym_hcb *np = sym_get_hcb(shost);
  1699. struct sym_tcb *tp = &np->target[starget->id];
  1700. /* We must clear QAS and IU if DT is clear */
  1701. if (dt)
  1702. tp->tgoal.dt = 1;
  1703. else
  1704. tp->tgoal.iu = tp->tgoal.dt = tp->tgoal.qas = 0;
  1705. tp->tgoal.check_nego = 1;
  1706. }
  1707. #if 0
  1708. static void sym2_set_iu(struct scsi_target *starget, int iu)
  1709. {
  1710. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1711. struct sym_hcb *np = sym_get_hcb(shost);
  1712. struct sym_tcb *tp = &np->target[starget->id];
  1713. if (iu)
  1714. tp->tgoal.iu = tp->tgoal.dt = 1;
  1715. else
  1716. tp->tgoal.iu = 0;
  1717. tp->tgoal.check_nego = 1;
  1718. }
  1719. static void sym2_set_qas(struct scsi_target *starget, int qas)
  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 (qas)
  1725. tp->tgoal.dt = tp->tgoal.qas = 1;
  1726. else
  1727. tp->tgoal.qas = 0;
  1728. tp->tgoal.check_nego = 1;
  1729. }
  1730. #endif
  1731. static struct spi_function_template sym2_transport_functions = {
  1732. .set_offset = sym2_set_offset,
  1733. .show_offset = 1,
  1734. .set_period = sym2_set_period,
  1735. .show_period = 1,
  1736. .set_width = sym2_set_width,
  1737. .show_width = 1,
  1738. .set_dt = sym2_set_dt,
  1739. .show_dt = 1,
  1740. #if 0
  1741. .set_iu = sym2_set_iu,
  1742. .show_iu = 1,
  1743. .set_qas = sym2_set_qas,
  1744. .show_qas = 1,
  1745. #endif
  1746. .get_signalling = sym2_get_signalling,
  1747. };
  1748. static struct pci_device_id sym2_id_table[] __devinitdata = {
  1749. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C810,
  1750. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1751. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C820,
  1752. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
  1753. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C825,
  1754. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1755. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C815,
  1756. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1757. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C810AP,
  1758. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL }, /* new */
  1759. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C860,
  1760. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1761. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1510,
  1762. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL },
  1763. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C896,
  1764. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1765. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C895,
  1766. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1767. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C885,
  1768. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1769. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875,
  1770. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1771. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C1510,
  1772. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_SCSI<<8, 0xffff00, 0UL }, /* new */
  1773. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C895A,
  1774. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1775. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C875A,
  1776. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1777. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_33,
  1778. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1779. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_53C1010_66,
  1780. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1781. { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_NCR_53C875J,
  1782. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
  1783. { 0, }
  1784. };
  1785. MODULE_DEVICE_TABLE(pci, sym2_id_table);
  1786. static struct pci_driver sym2_driver = {
  1787. .name = NAME53C8XX,
  1788. .id_table = sym2_id_table,
  1789. .probe = sym2_probe,
  1790. .remove = __devexit_p(sym2_remove),
  1791. };
  1792. static int __init sym2_init(void)
  1793. {
  1794. int error;
  1795. sym2_setup_params();
  1796. sym2_transport_template = spi_attach_transport(&sym2_transport_functions);
  1797. if (!sym2_transport_template)
  1798. return -ENODEV;
  1799. error = pci_register_driver(&sym2_driver);
  1800. if (error)
  1801. spi_release_transport(sym2_transport_template);
  1802. return error;
  1803. }
  1804. static void __exit sym2_exit(void)
  1805. {
  1806. pci_unregister_driver(&sym2_driver);
  1807. spi_release_transport(sym2_transport_template);
  1808. }
  1809. module_init(sym2_init);
  1810. module_exit(sym2_exit);