sym_glue.c 51 KB

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