stex.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797
  1. /*
  2. * SuperTrak EX Series Storage Controller driver for Linux
  3. *
  4. * Copyright (C) 2005-2009 Promise Technology Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Written By:
  12. * Ed Lin <promise_linux@promise.com>
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/kernel.h>
  18. #include <linux/delay.h>
  19. #include <linux/slab.h>
  20. #include <linux/time.h>
  21. #include <linux/pci.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/types.h>
  25. #include <linux/module.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/ktime.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/byteorder.h>
  31. #include <scsi/scsi.h>
  32. #include <scsi/scsi_device.h>
  33. #include <scsi/scsi_cmnd.h>
  34. #include <scsi/scsi_host.h>
  35. #include <scsi/scsi_tcq.h>
  36. #include <scsi/scsi_dbg.h>
  37. #include <scsi/scsi_eh.h>
  38. #define DRV_NAME "stex"
  39. #define ST_DRIVER_VERSION "4.6.0000.4"
  40. #define ST_VER_MAJOR 4
  41. #define ST_VER_MINOR 6
  42. #define ST_OEM 0
  43. #define ST_BUILD_VER 4
  44. enum {
  45. /* MU register offset */
  46. IMR0 = 0x10, /* MU_INBOUND_MESSAGE_REG0 */
  47. IMR1 = 0x14, /* MU_INBOUND_MESSAGE_REG1 */
  48. OMR0 = 0x18, /* MU_OUTBOUND_MESSAGE_REG0 */
  49. OMR1 = 0x1c, /* MU_OUTBOUND_MESSAGE_REG1 */
  50. IDBL = 0x20, /* MU_INBOUND_DOORBELL */
  51. IIS = 0x24, /* MU_INBOUND_INTERRUPT_STATUS */
  52. IIM = 0x28, /* MU_INBOUND_INTERRUPT_MASK */
  53. ODBL = 0x2c, /* MU_OUTBOUND_DOORBELL */
  54. OIS = 0x30, /* MU_OUTBOUND_INTERRUPT_STATUS */
  55. OIM = 0x3c, /* MU_OUTBOUND_INTERRUPT_MASK */
  56. YIOA_STATUS = 0x00,
  57. YH2I_INT = 0x20,
  58. YINT_EN = 0x34,
  59. YI2H_INT = 0x9c,
  60. YI2H_INT_C = 0xa0,
  61. YH2I_REQ = 0xc0,
  62. YH2I_REQ_HI = 0xc4,
  63. /* MU register value */
  64. MU_INBOUND_DOORBELL_HANDSHAKE = (1 << 0),
  65. MU_INBOUND_DOORBELL_REQHEADCHANGED = (1 << 1),
  66. MU_INBOUND_DOORBELL_STATUSTAILCHANGED = (1 << 2),
  67. MU_INBOUND_DOORBELL_HMUSTOPPED = (1 << 3),
  68. MU_INBOUND_DOORBELL_RESET = (1 << 4),
  69. MU_OUTBOUND_DOORBELL_HANDSHAKE = (1 << 0),
  70. MU_OUTBOUND_DOORBELL_REQUESTTAILCHANGED = (1 << 1),
  71. MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED = (1 << 2),
  72. MU_OUTBOUND_DOORBELL_BUSCHANGE = (1 << 3),
  73. MU_OUTBOUND_DOORBELL_HASEVENT = (1 << 4),
  74. MU_OUTBOUND_DOORBELL_REQUEST_RESET = (1 << 27),
  75. /* MU status code */
  76. MU_STATE_STARTING = 1,
  77. MU_STATE_STARTED = 2,
  78. MU_STATE_RESETTING = 3,
  79. MU_STATE_FAILED = 4,
  80. MU_MAX_DELAY = 120,
  81. MU_HANDSHAKE_SIGNATURE = 0x55aaaa55,
  82. MU_HANDSHAKE_SIGNATURE_HALF = 0x5a5a0000,
  83. MU_HARD_RESET_WAIT = 30000,
  84. HMU_PARTNER_TYPE = 2,
  85. /* firmware returned values */
  86. SRB_STATUS_SUCCESS = 0x01,
  87. SRB_STATUS_ERROR = 0x04,
  88. SRB_STATUS_BUSY = 0x05,
  89. SRB_STATUS_INVALID_REQUEST = 0x06,
  90. SRB_STATUS_SELECTION_TIMEOUT = 0x0A,
  91. SRB_SEE_SENSE = 0x80,
  92. /* task attribute */
  93. TASK_ATTRIBUTE_SIMPLE = 0x0,
  94. TASK_ATTRIBUTE_HEADOFQUEUE = 0x1,
  95. TASK_ATTRIBUTE_ORDERED = 0x2,
  96. TASK_ATTRIBUTE_ACA = 0x4,
  97. SS_STS_NORMAL = 0x80000000,
  98. SS_STS_DONE = 0x40000000,
  99. SS_STS_HANDSHAKE = 0x20000000,
  100. SS_HEAD_HANDSHAKE = 0x80,
  101. SS_H2I_INT_RESET = 0x100,
  102. SS_I2H_REQUEST_RESET = 0x2000,
  103. SS_MU_OPERATIONAL = 0x80000000,
  104. STEX_CDB_LENGTH = 16,
  105. STATUS_VAR_LEN = 128,
  106. /* sg flags */
  107. SG_CF_EOT = 0x80, /* end of table */
  108. SG_CF_64B = 0x40, /* 64 bit item */
  109. SG_CF_HOST = 0x20, /* sg in host memory */
  110. MSG_DATA_DIR_ND = 0,
  111. MSG_DATA_DIR_IN = 1,
  112. MSG_DATA_DIR_OUT = 2,
  113. st_shasta = 0,
  114. st_vsc = 1,
  115. st_yosemite = 2,
  116. st_seq = 3,
  117. st_yel = 4,
  118. PASSTHRU_REQ_TYPE = 0x00000001,
  119. PASSTHRU_REQ_NO_WAKEUP = 0x00000100,
  120. ST_INTERNAL_TIMEOUT = 180,
  121. ST_TO_CMD = 0,
  122. ST_FROM_CMD = 1,
  123. /* vendor specific commands of Promise */
  124. MGT_CMD = 0xd8,
  125. SINBAND_MGT_CMD = 0xd9,
  126. ARRAY_CMD = 0xe0,
  127. CONTROLLER_CMD = 0xe1,
  128. DEBUGGING_CMD = 0xe2,
  129. PASSTHRU_CMD = 0xe3,
  130. PASSTHRU_GET_ADAPTER = 0x05,
  131. PASSTHRU_GET_DRVVER = 0x10,
  132. CTLR_CONFIG_CMD = 0x03,
  133. CTLR_SHUTDOWN = 0x0d,
  134. CTLR_POWER_STATE_CHANGE = 0x0e,
  135. CTLR_POWER_SAVING = 0x01,
  136. PASSTHRU_SIGNATURE = 0x4e415041,
  137. MGT_CMD_SIGNATURE = 0xba,
  138. INQUIRY_EVPD = 0x01,
  139. ST_ADDITIONAL_MEM = 0x200000,
  140. ST_ADDITIONAL_MEM_MIN = 0x80000,
  141. };
  142. struct st_sgitem {
  143. u8 ctrl; /* SG_CF_xxx */
  144. u8 reserved[3];
  145. __le32 count;
  146. __le64 addr;
  147. };
  148. struct st_ss_sgitem {
  149. __le32 addr;
  150. __le32 addr_hi;
  151. __le32 count;
  152. };
  153. struct st_sgtable {
  154. __le16 sg_count;
  155. __le16 max_sg_count;
  156. __le32 sz_in_byte;
  157. };
  158. struct st_msg_header {
  159. __le64 handle;
  160. u8 flag;
  161. u8 channel;
  162. __le16 timeout;
  163. u32 reserved;
  164. };
  165. struct handshake_frame {
  166. __le64 rb_phy; /* request payload queue physical address */
  167. __le16 req_sz; /* size of each request payload */
  168. __le16 req_cnt; /* count of reqs the buffer can hold */
  169. __le16 status_sz; /* size of each status payload */
  170. __le16 status_cnt; /* count of status the buffer can hold */
  171. __le64 hosttime; /* seconds from Jan 1, 1970 (GMT) */
  172. u8 partner_type; /* who sends this frame */
  173. u8 reserved0[7];
  174. __le32 partner_ver_major;
  175. __le32 partner_ver_minor;
  176. __le32 partner_ver_oem;
  177. __le32 partner_ver_build;
  178. __le32 extra_offset; /* NEW */
  179. __le32 extra_size; /* NEW */
  180. __le32 scratch_size;
  181. u32 reserved1;
  182. };
  183. struct req_msg {
  184. __le16 tag;
  185. u8 lun;
  186. u8 target;
  187. u8 task_attr;
  188. u8 task_manage;
  189. u8 data_dir;
  190. u8 payload_sz; /* payload size in 4-byte, not used */
  191. u8 cdb[STEX_CDB_LENGTH];
  192. u32 variable[0];
  193. };
  194. struct status_msg {
  195. __le16 tag;
  196. u8 lun;
  197. u8 target;
  198. u8 srb_status;
  199. u8 scsi_status;
  200. u8 reserved;
  201. u8 payload_sz; /* payload size in 4-byte */
  202. u8 variable[STATUS_VAR_LEN];
  203. };
  204. struct ver_info {
  205. u32 major;
  206. u32 minor;
  207. u32 oem;
  208. u32 build;
  209. u32 reserved[2];
  210. };
  211. struct st_frame {
  212. u32 base[6];
  213. u32 rom_addr;
  214. struct ver_info drv_ver;
  215. struct ver_info bios_ver;
  216. u32 bus;
  217. u32 slot;
  218. u32 irq_level;
  219. u32 irq_vec;
  220. u32 id;
  221. u32 subid;
  222. u32 dimm_size;
  223. u8 dimm_type;
  224. u8 reserved[3];
  225. u32 channel;
  226. u32 reserved1;
  227. };
  228. struct st_drvver {
  229. u32 major;
  230. u32 minor;
  231. u32 oem;
  232. u32 build;
  233. u32 signature[2];
  234. u8 console_id;
  235. u8 host_no;
  236. u8 reserved0[2];
  237. u32 reserved[3];
  238. };
  239. struct st_ccb {
  240. struct req_msg *req;
  241. struct scsi_cmnd *cmd;
  242. void *sense_buffer;
  243. unsigned int sense_bufflen;
  244. int sg_count;
  245. u32 req_type;
  246. u8 srb_status;
  247. u8 scsi_status;
  248. u8 reserved[2];
  249. };
  250. struct st_hba {
  251. void __iomem *mmio_base; /* iomapped PCI memory space */
  252. void *dma_mem;
  253. dma_addr_t dma_handle;
  254. size_t dma_size;
  255. struct Scsi_Host *host;
  256. struct pci_dev *pdev;
  257. struct req_msg * (*alloc_rq) (struct st_hba *);
  258. int (*map_sg)(struct st_hba *, struct req_msg *, struct st_ccb *);
  259. void (*send) (struct st_hba *, struct req_msg *, u16);
  260. u32 req_head;
  261. u32 req_tail;
  262. u32 status_head;
  263. u32 status_tail;
  264. struct status_msg *status_buffer;
  265. void *copy_buffer; /* temp buffer for driver-handled commands */
  266. struct st_ccb *ccb;
  267. struct st_ccb *wait_ccb;
  268. __le32 *scratch;
  269. char work_q_name[20];
  270. struct workqueue_struct *work_q;
  271. struct work_struct reset_work;
  272. wait_queue_head_t reset_waitq;
  273. unsigned int mu_status;
  274. unsigned int cardtype;
  275. int msi_enabled;
  276. int out_req_cnt;
  277. u32 extra_offset;
  278. u16 rq_count;
  279. u16 rq_size;
  280. u16 sts_count;
  281. };
  282. struct st_card_info {
  283. struct req_msg * (*alloc_rq) (struct st_hba *);
  284. int (*map_sg)(struct st_hba *, struct req_msg *, struct st_ccb *);
  285. void (*send) (struct st_hba *, struct req_msg *, u16);
  286. unsigned int max_id;
  287. unsigned int max_lun;
  288. unsigned int max_channel;
  289. u16 rq_count;
  290. u16 rq_size;
  291. u16 sts_count;
  292. };
  293. static int msi;
  294. module_param(msi, int, 0);
  295. MODULE_PARM_DESC(msi, "Enable Message Signaled Interrupts(0=off, 1=on)");
  296. static const char console_inq_page[] =
  297. {
  298. 0x03,0x00,0x03,0x03,0xFA,0x00,0x00,0x30,
  299. 0x50,0x72,0x6F,0x6D,0x69,0x73,0x65,0x20, /* "Promise " */
  300. 0x52,0x41,0x49,0x44,0x20,0x43,0x6F,0x6E, /* "RAID Con" */
  301. 0x73,0x6F,0x6C,0x65,0x20,0x20,0x20,0x20, /* "sole " */
  302. 0x31,0x2E,0x30,0x30,0x20,0x20,0x20,0x20, /* "1.00 " */
  303. 0x53,0x58,0x2F,0x52,0x53,0x41,0x46,0x2D, /* "SX/RSAF-" */
  304. 0x54,0x45,0x31,0x2E,0x30,0x30,0x20,0x20, /* "TE1.00 " */
  305. 0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20
  306. };
  307. MODULE_AUTHOR("Ed Lin");
  308. MODULE_DESCRIPTION("Promise Technology SuperTrak EX Controllers");
  309. MODULE_LICENSE("GPL");
  310. MODULE_VERSION(ST_DRIVER_VERSION);
  311. static struct status_msg *stex_get_status(struct st_hba *hba)
  312. {
  313. struct status_msg *status = hba->status_buffer + hba->status_tail;
  314. ++hba->status_tail;
  315. hba->status_tail %= hba->sts_count+1;
  316. return status;
  317. }
  318. static void stex_invalid_field(struct scsi_cmnd *cmd,
  319. void (*done)(struct scsi_cmnd *))
  320. {
  321. cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
  322. /* "Invalid field in cdb" */
  323. scsi_build_sense_buffer(0, cmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
  324. 0x0);
  325. done(cmd);
  326. }
  327. static struct req_msg *stex_alloc_req(struct st_hba *hba)
  328. {
  329. struct req_msg *req = hba->dma_mem + hba->req_head * hba->rq_size;
  330. ++hba->req_head;
  331. hba->req_head %= hba->rq_count+1;
  332. return req;
  333. }
  334. static struct req_msg *stex_ss_alloc_req(struct st_hba *hba)
  335. {
  336. return (struct req_msg *)(hba->dma_mem +
  337. hba->req_head * hba->rq_size + sizeof(struct st_msg_header));
  338. }
  339. static int stex_map_sg(struct st_hba *hba,
  340. struct req_msg *req, struct st_ccb *ccb)
  341. {
  342. struct scsi_cmnd *cmd;
  343. struct scatterlist *sg;
  344. struct st_sgtable *dst;
  345. struct st_sgitem *table;
  346. int i, nseg;
  347. cmd = ccb->cmd;
  348. nseg = scsi_dma_map(cmd);
  349. BUG_ON(nseg < 0);
  350. if (nseg) {
  351. dst = (struct st_sgtable *)req->variable;
  352. ccb->sg_count = nseg;
  353. dst->sg_count = cpu_to_le16((u16)nseg);
  354. dst->max_sg_count = cpu_to_le16(hba->host->sg_tablesize);
  355. dst->sz_in_byte = cpu_to_le32(scsi_bufflen(cmd));
  356. table = (struct st_sgitem *)(dst + 1);
  357. scsi_for_each_sg(cmd, sg, nseg, i) {
  358. table[i].count = cpu_to_le32((u32)sg_dma_len(sg));
  359. table[i].addr = cpu_to_le64(sg_dma_address(sg));
  360. table[i].ctrl = SG_CF_64B | SG_CF_HOST;
  361. }
  362. table[--i].ctrl |= SG_CF_EOT;
  363. }
  364. return nseg;
  365. }
  366. static int stex_ss_map_sg(struct st_hba *hba,
  367. struct req_msg *req, struct st_ccb *ccb)
  368. {
  369. struct scsi_cmnd *cmd;
  370. struct scatterlist *sg;
  371. struct st_sgtable *dst;
  372. struct st_ss_sgitem *table;
  373. int i, nseg;
  374. cmd = ccb->cmd;
  375. nseg = scsi_dma_map(cmd);
  376. BUG_ON(nseg < 0);
  377. if (nseg) {
  378. dst = (struct st_sgtable *)req->variable;
  379. ccb->sg_count = nseg;
  380. dst->sg_count = cpu_to_le16((u16)nseg);
  381. dst->max_sg_count = cpu_to_le16(hba->host->sg_tablesize);
  382. dst->sz_in_byte = cpu_to_le32(scsi_bufflen(cmd));
  383. table = (struct st_ss_sgitem *)(dst + 1);
  384. scsi_for_each_sg(cmd, sg, nseg, i) {
  385. table[i].count = cpu_to_le32((u32)sg_dma_len(sg));
  386. table[i].addr =
  387. cpu_to_le32(sg_dma_address(sg) & 0xffffffff);
  388. table[i].addr_hi =
  389. cpu_to_le32((sg_dma_address(sg) >> 16) >> 16);
  390. }
  391. }
  392. return nseg;
  393. }
  394. static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb)
  395. {
  396. struct st_frame *p;
  397. size_t count = sizeof(struct st_frame);
  398. p = hba->copy_buffer;
  399. scsi_sg_copy_to_buffer(ccb->cmd, p, count);
  400. memset(p->base, 0, sizeof(u32)*6);
  401. *(unsigned long *)(p->base) = pci_resource_start(hba->pdev, 0);
  402. p->rom_addr = 0;
  403. p->drv_ver.major = ST_VER_MAJOR;
  404. p->drv_ver.minor = ST_VER_MINOR;
  405. p->drv_ver.oem = ST_OEM;
  406. p->drv_ver.build = ST_BUILD_VER;
  407. p->bus = hba->pdev->bus->number;
  408. p->slot = hba->pdev->devfn;
  409. p->irq_level = 0;
  410. p->irq_vec = hba->pdev->irq;
  411. p->id = hba->pdev->vendor << 16 | hba->pdev->device;
  412. p->subid =
  413. hba->pdev->subsystem_vendor << 16 | hba->pdev->subsystem_device;
  414. scsi_sg_copy_from_buffer(ccb->cmd, p, count);
  415. }
  416. static void
  417. stex_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
  418. {
  419. req->tag = cpu_to_le16(tag);
  420. hba->ccb[tag].req = req;
  421. hba->out_req_cnt++;
  422. writel(hba->req_head, hba->mmio_base + IMR0);
  423. writel(MU_INBOUND_DOORBELL_REQHEADCHANGED, hba->mmio_base + IDBL);
  424. readl(hba->mmio_base + IDBL); /* flush */
  425. }
  426. static void
  427. stex_ss_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
  428. {
  429. struct scsi_cmnd *cmd;
  430. struct st_msg_header *msg_h;
  431. dma_addr_t addr;
  432. req->tag = cpu_to_le16(tag);
  433. hba->ccb[tag].req = req;
  434. hba->out_req_cnt++;
  435. cmd = hba->ccb[tag].cmd;
  436. msg_h = (struct st_msg_header *)req - 1;
  437. if (likely(cmd)) {
  438. msg_h->channel = (u8)cmd->device->channel;
  439. msg_h->timeout = cpu_to_le16(cmd->request->timeout/HZ);
  440. }
  441. addr = hba->dma_handle + hba->req_head * hba->rq_size;
  442. addr += (hba->ccb[tag].sg_count+4)/11;
  443. msg_h->handle = cpu_to_le64(addr);
  444. ++hba->req_head;
  445. hba->req_head %= hba->rq_count+1;
  446. writel((addr >> 16) >> 16, hba->mmio_base + YH2I_REQ_HI);
  447. readl(hba->mmio_base + YH2I_REQ_HI); /* flush */
  448. writel(addr, hba->mmio_base + YH2I_REQ);
  449. readl(hba->mmio_base + YH2I_REQ); /* flush */
  450. }
  451. static int
  452. stex_slave_config(struct scsi_device *sdev)
  453. {
  454. sdev->use_10_for_rw = 1;
  455. sdev->use_10_for_ms = 1;
  456. blk_queue_rq_timeout(sdev->request_queue, 60 * HZ);
  457. return 0;
  458. }
  459. static int
  460. stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  461. {
  462. struct st_hba *hba;
  463. struct Scsi_Host *host;
  464. unsigned int id, lun;
  465. struct req_msg *req;
  466. u16 tag;
  467. host = cmd->device->host;
  468. id = cmd->device->id;
  469. lun = cmd->device->lun;
  470. hba = (struct st_hba *) &host->hostdata[0];
  471. if (unlikely(hba->mu_status == MU_STATE_RESETTING))
  472. return SCSI_MLQUEUE_HOST_BUSY;
  473. switch (cmd->cmnd[0]) {
  474. case MODE_SENSE_10:
  475. {
  476. static char ms10_caching_page[12] =
  477. { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 };
  478. unsigned char page;
  479. page = cmd->cmnd[2] & 0x3f;
  480. if (page == 0x8 || page == 0x3f) {
  481. scsi_sg_copy_from_buffer(cmd, ms10_caching_page,
  482. sizeof(ms10_caching_page));
  483. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  484. done(cmd);
  485. } else
  486. stex_invalid_field(cmd, done);
  487. return 0;
  488. }
  489. case REPORT_LUNS:
  490. /*
  491. * The shasta firmware does not report actual luns in the
  492. * target, so fail the command to force sequential lun scan.
  493. * Also, the console device does not support this command.
  494. */
  495. if (hba->cardtype == st_shasta || id == host->max_id - 1) {
  496. stex_invalid_field(cmd, done);
  497. return 0;
  498. }
  499. break;
  500. case TEST_UNIT_READY:
  501. if (id == host->max_id - 1) {
  502. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  503. done(cmd);
  504. return 0;
  505. }
  506. break;
  507. case INQUIRY:
  508. if (lun >= host->max_lun) {
  509. cmd->result = DID_NO_CONNECT << 16;
  510. done(cmd);
  511. return 0;
  512. }
  513. if (id != host->max_id - 1)
  514. break;
  515. if (!lun && !cmd->device->channel &&
  516. (cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
  517. scsi_sg_copy_from_buffer(cmd, (void *)console_inq_page,
  518. sizeof(console_inq_page));
  519. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  520. done(cmd);
  521. } else
  522. stex_invalid_field(cmd, done);
  523. return 0;
  524. case PASSTHRU_CMD:
  525. if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
  526. struct st_drvver ver;
  527. size_t cp_len = sizeof(ver);
  528. ver.major = ST_VER_MAJOR;
  529. ver.minor = ST_VER_MINOR;
  530. ver.oem = ST_OEM;
  531. ver.build = ST_BUILD_VER;
  532. ver.signature[0] = PASSTHRU_SIGNATURE;
  533. ver.console_id = host->max_id - 1;
  534. ver.host_no = hba->host->host_no;
  535. cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
  536. cmd->result = sizeof(ver) == cp_len ?
  537. DID_OK << 16 | COMMAND_COMPLETE << 8 :
  538. DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  539. done(cmd);
  540. return 0;
  541. }
  542. default:
  543. break;
  544. }
  545. cmd->scsi_done = done;
  546. tag = cmd->request->tag;
  547. if (unlikely(tag >= host->can_queue))
  548. return SCSI_MLQUEUE_HOST_BUSY;
  549. req = hba->alloc_rq(hba);
  550. req->lun = lun;
  551. req->target = id;
  552. /* cdb */
  553. memcpy(req->cdb, cmd->cmnd, STEX_CDB_LENGTH);
  554. if (cmd->sc_data_direction == DMA_FROM_DEVICE)
  555. req->data_dir = MSG_DATA_DIR_IN;
  556. else if (cmd->sc_data_direction == DMA_TO_DEVICE)
  557. req->data_dir = MSG_DATA_DIR_OUT;
  558. else
  559. req->data_dir = MSG_DATA_DIR_ND;
  560. hba->ccb[tag].cmd = cmd;
  561. hba->ccb[tag].sense_bufflen = SCSI_SENSE_BUFFERSIZE;
  562. hba->ccb[tag].sense_buffer = cmd->sense_buffer;
  563. if (!hba->map_sg(hba, req, &hba->ccb[tag])) {
  564. hba->ccb[tag].sg_count = 0;
  565. memset(&req->variable[0], 0, 8);
  566. }
  567. hba->send(hba, req, tag);
  568. return 0;
  569. }
  570. static DEF_SCSI_QCMD(stex_queuecommand)
  571. static void stex_scsi_done(struct st_ccb *ccb)
  572. {
  573. struct scsi_cmnd *cmd = ccb->cmd;
  574. int result;
  575. if (ccb->srb_status == SRB_STATUS_SUCCESS || ccb->srb_status == 0) {
  576. result = ccb->scsi_status;
  577. switch (ccb->scsi_status) {
  578. case SAM_STAT_GOOD:
  579. result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
  580. break;
  581. case SAM_STAT_CHECK_CONDITION:
  582. result |= DRIVER_SENSE << 24;
  583. break;
  584. case SAM_STAT_BUSY:
  585. result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
  586. break;
  587. default:
  588. result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  589. break;
  590. }
  591. }
  592. else if (ccb->srb_status & SRB_SEE_SENSE)
  593. result = DRIVER_SENSE << 24 | SAM_STAT_CHECK_CONDITION;
  594. else switch (ccb->srb_status) {
  595. case SRB_STATUS_SELECTION_TIMEOUT:
  596. result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  597. break;
  598. case SRB_STATUS_BUSY:
  599. result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
  600. break;
  601. case SRB_STATUS_INVALID_REQUEST:
  602. case SRB_STATUS_ERROR:
  603. default:
  604. result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  605. break;
  606. }
  607. cmd->result = result;
  608. cmd->scsi_done(cmd);
  609. }
  610. static void stex_copy_data(struct st_ccb *ccb,
  611. struct status_msg *resp, unsigned int variable)
  612. {
  613. if (resp->scsi_status != SAM_STAT_GOOD) {
  614. if (ccb->sense_buffer != NULL)
  615. memcpy(ccb->sense_buffer, resp->variable,
  616. min(variable, ccb->sense_bufflen));
  617. return;
  618. }
  619. if (ccb->cmd == NULL)
  620. return;
  621. scsi_sg_copy_from_buffer(ccb->cmd, resp->variable, variable);
  622. }
  623. static void stex_check_cmd(struct st_hba *hba,
  624. struct st_ccb *ccb, struct status_msg *resp)
  625. {
  626. if (ccb->cmd->cmnd[0] == MGT_CMD &&
  627. resp->scsi_status != SAM_STAT_CHECK_CONDITION)
  628. scsi_set_resid(ccb->cmd, scsi_bufflen(ccb->cmd) -
  629. le32_to_cpu(*(__le32 *)&resp->variable[0]));
  630. }
  631. static void stex_mu_intr(struct st_hba *hba, u32 doorbell)
  632. {
  633. void __iomem *base = hba->mmio_base;
  634. struct status_msg *resp;
  635. struct st_ccb *ccb;
  636. unsigned int size;
  637. u16 tag;
  638. if (unlikely(!(doorbell & MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED)))
  639. return;
  640. /* status payloads */
  641. hba->status_head = readl(base + OMR1);
  642. if (unlikely(hba->status_head > hba->sts_count)) {
  643. printk(KERN_WARNING DRV_NAME "(%s): invalid status head\n",
  644. pci_name(hba->pdev));
  645. return;
  646. }
  647. /*
  648. * it's not a valid status payload if:
  649. * 1. there are no pending requests(e.g. during init stage)
  650. * 2. there are some pending requests, but the controller is in
  651. * reset status, and its type is not st_yosemite
  652. * firmware of st_yosemite in reset status will return pending requests
  653. * to driver, so we allow it to pass
  654. */
  655. if (unlikely(hba->out_req_cnt <= 0 ||
  656. (hba->mu_status == MU_STATE_RESETTING &&
  657. hba->cardtype != st_yosemite))) {
  658. hba->status_tail = hba->status_head;
  659. goto update_status;
  660. }
  661. while (hba->status_tail != hba->status_head) {
  662. resp = stex_get_status(hba);
  663. tag = le16_to_cpu(resp->tag);
  664. if (unlikely(tag >= hba->host->can_queue)) {
  665. printk(KERN_WARNING DRV_NAME
  666. "(%s): invalid tag\n", pci_name(hba->pdev));
  667. continue;
  668. }
  669. hba->out_req_cnt--;
  670. ccb = &hba->ccb[tag];
  671. if (unlikely(hba->wait_ccb == ccb))
  672. hba->wait_ccb = NULL;
  673. if (unlikely(ccb->req == NULL)) {
  674. printk(KERN_WARNING DRV_NAME
  675. "(%s): lagging req\n", pci_name(hba->pdev));
  676. continue;
  677. }
  678. size = resp->payload_sz * sizeof(u32); /* payload size */
  679. if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN ||
  680. size > sizeof(*resp))) {
  681. printk(KERN_WARNING DRV_NAME "(%s): bad status size\n",
  682. pci_name(hba->pdev));
  683. } else {
  684. size -= sizeof(*resp) - STATUS_VAR_LEN; /* copy size */
  685. if (size)
  686. stex_copy_data(ccb, resp, size);
  687. }
  688. ccb->req = NULL;
  689. ccb->srb_status = resp->srb_status;
  690. ccb->scsi_status = resp->scsi_status;
  691. if (likely(ccb->cmd != NULL)) {
  692. if (hba->cardtype == st_yosemite)
  693. stex_check_cmd(hba, ccb, resp);
  694. if (unlikely(ccb->cmd->cmnd[0] == PASSTHRU_CMD &&
  695. ccb->cmd->cmnd[1] == PASSTHRU_GET_ADAPTER))
  696. stex_controller_info(hba, ccb);
  697. scsi_dma_unmap(ccb->cmd);
  698. stex_scsi_done(ccb);
  699. } else
  700. ccb->req_type = 0;
  701. }
  702. update_status:
  703. writel(hba->status_head, base + IMR1);
  704. readl(base + IMR1); /* flush */
  705. }
  706. static irqreturn_t stex_intr(int irq, void *__hba)
  707. {
  708. struct st_hba *hba = __hba;
  709. void __iomem *base = hba->mmio_base;
  710. u32 data;
  711. unsigned long flags;
  712. spin_lock_irqsave(hba->host->host_lock, flags);
  713. data = readl(base + ODBL);
  714. if (data && data != 0xffffffff) {
  715. /* clear the interrupt */
  716. writel(data, base + ODBL);
  717. readl(base + ODBL); /* flush */
  718. stex_mu_intr(hba, data);
  719. spin_unlock_irqrestore(hba->host->host_lock, flags);
  720. if (unlikely(data & MU_OUTBOUND_DOORBELL_REQUEST_RESET &&
  721. hba->cardtype == st_shasta))
  722. queue_work(hba->work_q, &hba->reset_work);
  723. return IRQ_HANDLED;
  724. }
  725. spin_unlock_irqrestore(hba->host->host_lock, flags);
  726. return IRQ_NONE;
  727. }
  728. static void stex_ss_mu_intr(struct st_hba *hba)
  729. {
  730. struct status_msg *resp;
  731. struct st_ccb *ccb;
  732. __le32 *scratch;
  733. unsigned int size;
  734. int count = 0;
  735. u32 value;
  736. u16 tag;
  737. if (unlikely(hba->out_req_cnt <= 0 ||
  738. hba->mu_status == MU_STATE_RESETTING))
  739. return;
  740. while (count < hba->sts_count) {
  741. scratch = hba->scratch + hba->status_tail;
  742. value = le32_to_cpu(*scratch);
  743. if (unlikely(!(value & SS_STS_NORMAL)))
  744. return;
  745. resp = hba->status_buffer + hba->status_tail;
  746. *scratch = 0;
  747. ++count;
  748. ++hba->status_tail;
  749. hba->status_tail %= hba->sts_count+1;
  750. tag = (u16)value;
  751. if (unlikely(tag >= hba->host->can_queue)) {
  752. printk(KERN_WARNING DRV_NAME
  753. "(%s): invalid tag\n", pci_name(hba->pdev));
  754. continue;
  755. }
  756. hba->out_req_cnt--;
  757. ccb = &hba->ccb[tag];
  758. if (unlikely(hba->wait_ccb == ccb))
  759. hba->wait_ccb = NULL;
  760. if (unlikely(ccb->req == NULL)) {
  761. printk(KERN_WARNING DRV_NAME
  762. "(%s): lagging req\n", pci_name(hba->pdev));
  763. continue;
  764. }
  765. ccb->req = NULL;
  766. if (likely(value & SS_STS_DONE)) { /* normal case */
  767. ccb->srb_status = SRB_STATUS_SUCCESS;
  768. ccb->scsi_status = SAM_STAT_GOOD;
  769. } else {
  770. ccb->srb_status = resp->srb_status;
  771. ccb->scsi_status = resp->scsi_status;
  772. size = resp->payload_sz * sizeof(u32);
  773. if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN ||
  774. size > sizeof(*resp))) {
  775. printk(KERN_WARNING DRV_NAME
  776. "(%s): bad status size\n",
  777. pci_name(hba->pdev));
  778. } else {
  779. size -= sizeof(*resp) - STATUS_VAR_LEN;
  780. if (size)
  781. stex_copy_data(ccb, resp, size);
  782. }
  783. if (likely(ccb->cmd != NULL))
  784. stex_check_cmd(hba, ccb, resp);
  785. }
  786. if (likely(ccb->cmd != NULL)) {
  787. scsi_dma_unmap(ccb->cmd);
  788. stex_scsi_done(ccb);
  789. } else
  790. ccb->req_type = 0;
  791. }
  792. }
  793. static irqreturn_t stex_ss_intr(int irq, void *__hba)
  794. {
  795. struct st_hba *hba = __hba;
  796. void __iomem *base = hba->mmio_base;
  797. u32 data;
  798. unsigned long flags;
  799. spin_lock_irqsave(hba->host->host_lock, flags);
  800. data = readl(base + YI2H_INT);
  801. if (data && data != 0xffffffff) {
  802. /* clear the interrupt */
  803. writel(data, base + YI2H_INT_C);
  804. stex_ss_mu_intr(hba);
  805. spin_unlock_irqrestore(hba->host->host_lock, flags);
  806. if (unlikely(data & SS_I2H_REQUEST_RESET))
  807. queue_work(hba->work_q, &hba->reset_work);
  808. return IRQ_HANDLED;
  809. }
  810. spin_unlock_irqrestore(hba->host->host_lock, flags);
  811. return IRQ_NONE;
  812. }
  813. static int stex_common_handshake(struct st_hba *hba)
  814. {
  815. void __iomem *base = hba->mmio_base;
  816. struct handshake_frame *h;
  817. dma_addr_t status_phys;
  818. u32 data;
  819. unsigned long before;
  820. if (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
  821. writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
  822. readl(base + IDBL);
  823. before = jiffies;
  824. while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
  825. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  826. printk(KERN_ERR DRV_NAME
  827. "(%s): no handshake signature\n",
  828. pci_name(hba->pdev));
  829. return -1;
  830. }
  831. rmb();
  832. msleep(1);
  833. }
  834. }
  835. udelay(10);
  836. data = readl(base + OMR1);
  837. if ((data & 0xffff0000) == MU_HANDSHAKE_SIGNATURE_HALF) {
  838. data &= 0x0000ffff;
  839. if (hba->host->can_queue > data) {
  840. hba->host->can_queue = data;
  841. hba->host->cmd_per_lun = data;
  842. }
  843. }
  844. h = (struct handshake_frame *)hba->status_buffer;
  845. h->rb_phy = cpu_to_le64(hba->dma_handle);
  846. h->req_sz = cpu_to_le16(hba->rq_size);
  847. h->req_cnt = cpu_to_le16(hba->rq_count+1);
  848. h->status_sz = cpu_to_le16(sizeof(struct status_msg));
  849. h->status_cnt = cpu_to_le16(hba->sts_count+1);
  850. h->hosttime = cpu_to_le64(ktime_get_real_seconds());
  851. h->partner_type = HMU_PARTNER_TYPE;
  852. if (hba->extra_offset) {
  853. h->extra_offset = cpu_to_le32(hba->extra_offset);
  854. h->extra_size = cpu_to_le32(hba->dma_size - hba->extra_offset);
  855. } else
  856. h->extra_offset = h->extra_size = 0;
  857. status_phys = hba->dma_handle + (hba->rq_count+1) * hba->rq_size;
  858. writel(status_phys, base + IMR0);
  859. readl(base + IMR0);
  860. writel((status_phys >> 16) >> 16, base + IMR1);
  861. readl(base + IMR1);
  862. writel((status_phys >> 16) >> 16, base + OMR0); /* old fw compatible */
  863. readl(base + OMR0);
  864. writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
  865. readl(base + IDBL); /* flush */
  866. udelay(10);
  867. before = jiffies;
  868. while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
  869. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  870. printk(KERN_ERR DRV_NAME
  871. "(%s): no signature after handshake frame\n",
  872. pci_name(hba->pdev));
  873. return -1;
  874. }
  875. rmb();
  876. msleep(1);
  877. }
  878. writel(0, base + IMR0);
  879. readl(base + IMR0);
  880. writel(0, base + OMR0);
  881. readl(base + OMR0);
  882. writel(0, base + IMR1);
  883. readl(base + IMR1);
  884. writel(0, base + OMR1);
  885. readl(base + OMR1); /* flush */
  886. return 0;
  887. }
  888. static int stex_ss_handshake(struct st_hba *hba)
  889. {
  890. void __iomem *base = hba->mmio_base;
  891. struct st_msg_header *msg_h;
  892. struct handshake_frame *h;
  893. __le32 *scratch;
  894. u32 data, scratch_size;
  895. unsigned long before;
  896. int ret = 0;
  897. before = jiffies;
  898. while ((readl(base + YIOA_STATUS) & SS_MU_OPERATIONAL) == 0) {
  899. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  900. printk(KERN_ERR DRV_NAME
  901. "(%s): firmware not operational\n",
  902. pci_name(hba->pdev));
  903. return -1;
  904. }
  905. msleep(1);
  906. }
  907. msg_h = (struct st_msg_header *)hba->dma_mem;
  908. msg_h->handle = cpu_to_le64(hba->dma_handle);
  909. msg_h->flag = SS_HEAD_HANDSHAKE;
  910. h = (struct handshake_frame *)(msg_h + 1);
  911. h->rb_phy = cpu_to_le64(hba->dma_handle);
  912. h->req_sz = cpu_to_le16(hba->rq_size);
  913. h->req_cnt = cpu_to_le16(hba->rq_count+1);
  914. h->status_sz = cpu_to_le16(sizeof(struct status_msg));
  915. h->status_cnt = cpu_to_le16(hba->sts_count+1);
  916. h->hosttime = cpu_to_le64(ktime_get_real_seconds());
  917. h->partner_type = HMU_PARTNER_TYPE;
  918. h->extra_offset = h->extra_size = 0;
  919. scratch_size = (hba->sts_count+1)*sizeof(u32);
  920. h->scratch_size = cpu_to_le32(scratch_size);
  921. data = readl(base + YINT_EN);
  922. data &= ~4;
  923. writel(data, base + YINT_EN);
  924. writel((hba->dma_handle >> 16) >> 16, base + YH2I_REQ_HI);
  925. readl(base + YH2I_REQ_HI);
  926. writel(hba->dma_handle, base + YH2I_REQ);
  927. readl(base + YH2I_REQ); /* flush */
  928. scratch = hba->scratch;
  929. before = jiffies;
  930. while (!(le32_to_cpu(*scratch) & SS_STS_HANDSHAKE)) {
  931. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  932. printk(KERN_ERR DRV_NAME
  933. "(%s): no signature after handshake frame\n",
  934. pci_name(hba->pdev));
  935. ret = -1;
  936. break;
  937. }
  938. rmb();
  939. msleep(1);
  940. }
  941. memset(scratch, 0, scratch_size);
  942. msg_h->flag = 0;
  943. return ret;
  944. }
  945. static int stex_handshake(struct st_hba *hba)
  946. {
  947. int err;
  948. unsigned long flags;
  949. unsigned int mu_status;
  950. err = (hba->cardtype == st_yel) ?
  951. stex_ss_handshake(hba) : stex_common_handshake(hba);
  952. spin_lock_irqsave(hba->host->host_lock, flags);
  953. mu_status = hba->mu_status;
  954. if (err == 0) {
  955. hba->req_head = 0;
  956. hba->req_tail = 0;
  957. hba->status_head = 0;
  958. hba->status_tail = 0;
  959. hba->out_req_cnt = 0;
  960. hba->mu_status = MU_STATE_STARTED;
  961. } else
  962. hba->mu_status = MU_STATE_FAILED;
  963. if (mu_status == MU_STATE_RESETTING)
  964. wake_up_all(&hba->reset_waitq);
  965. spin_unlock_irqrestore(hba->host->host_lock, flags);
  966. return err;
  967. }
  968. static int stex_abort(struct scsi_cmnd *cmd)
  969. {
  970. struct Scsi_Host *host = cmd->device->host;
  971. struct st_hba *hba = (struct st_hba *)host->hostdata;
  972. u16 tag = cmd->request->tag;
  973. void __iomem *base;
  974. u32 data;
  975. int result = SUCCESS;
  976. unsigned long flags;
  977. scmd_printk(KERN_INFO, cmd, "aborting command\n");
  978. base = hba->mmio_base;
  979. spin_lock_irqsave(host->host_lock, flags);
  980. if (tag < host->can_queue &&
  981. hba->ccb[tag].req && hba->ccb[tag].cmd == cmd)
  982. hba->wait_ccb = &hba->ccb[tag];
  983. else
  984. goto out;
  985. if (hba->cardtype == st_yel) {
  986. data = readl(base + YI2H_INT);
  987. if (data == 0 || data == 0xffffffff)
  988. goto fail_out;
  989. writel(data, base + YI2H_INT_C);
  990. stex_ss_mu_intr(hba);
  991. } else {
  992. data = readl(base + ODBL);
  993. if (data == 0 || data == 0xffffffff)
  994. goto fail_out;
  995. writel(data, base + ODBL);
  996. readl(base + ODBL); /* flush */
  997. stex_mu_intr(hba, data);
  998. }
  999. if (hba->wait_ccb == NULL) {
  1000. printk(KERN_WARNING DRV_NAME
  1001. "(%s): lost interrupt\n", pci_name(hba->pdev));
  1002. goto out;
  1003. }
  1004. fail_out:
  1005. scsi_dma_unmap(cmd);
  1006. hba->wait_ccb->req = NULL; /* nullify the req's future return */
  1007. hba->wait_ccb = NULL;
  1008. result = FAILED;
  1009. out:
  1010. spin_unlock_irqrestore(host->host_lock, flags);
  1011. return result;
  1012. }
  1013. static void stex_hard_reset(struct st_hba *hba)
  1014. {
  1015. struct pci_bus *bus;
  1016. int i;
  1017. u16 pci_cmd;
  1018. u8 pci_bctl;
  1019. for (i = 0; i < 16; i++)
  1020. pci_read_config_dword(hba->pdev, i * 4,
  1021. &hba->pdev->saved_config_space[i]);
  1022. /* Reset secondary bus. Our controller(MU/ATU) is the only device on
  1023. secondary bus. Consult Intel 80331/3 developer's manual for detail */
  1024. bus = hba->pdev->bus;
  1025. pci_read_config_byte(bus->self, PCI_BRIDGE_CONTROL, &pci_bctl);
  1026. pci_bctl |= PCI_BRIDGE_CTL_BUS_RESET;
  1027. pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
  1028. /*
  1029. * 1 ms may be enough for 8-port controllers. But 16-port controllers
  1030. * require more time to finish bus reset. Use 100 ms here for safety
  1031. */
  1032. msleep(100);
  1033. pci_bctl &= ~PCI_BRIDGE_CTL_BUS_RESET;
  1034. pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
  1035. for (i = 0; i < MU_HARD_RESET_WAIT; i++) {
  1036. pci_read_config_word(hba->pdev, PCI_COMMAND, &pci_cmd);
  1037. if (pci_cmd != 0xffff && (pci_cmd & PCI_COMMAND_MASTER))
  1038. break;
  1039. msleep(1);
  1040. }
  1041. ssleep(5);
  1042. for (i = 0; i < 16; i++)
  1043. pci_write_config_dword(hba->pdev, i * 4,
  1044. hba->pdev->saved_config_space[i]);
  1045. }
  1046. static int stex_yos_reset(struct st_hba *hba)
  1047. {
  1048. void __iomem *base;
  1049. unsigned long flags, before;
  1050. int ret = 0;
  1051. base = hba->mmio_base;
  1052. writel(MU_INBOUND_DOORBELL_RESET, base + IDBL);
  1053. readl(base + IDBL); /* flush */
  1054. before = jiffies;
  1055. while (hba->out_req_cnt > 0) {
  1056. if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) {
  1057. printk(KERN_WARNING DRV_NAME
  1058. "(%s): reset timeout\n", pci_name(hba->pdev));
  1059. ret = -1;
  1060. break;
  1061. }
  1062. msleep(1);
  1063. }
  1064. spin_lock_irqsave(hba->host->host_lock, flags);
  1065. if (ret == -1)
  1066. hba->mu_status = MU_STATE_FAILED;
  1067. else
  1068. hba->mu_status = MU_STATE_STARTED;
  1069. wake_up_all(&hba->reset_waitq);
  1070. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1071. return ret;
  1072. }
  1073. static void stex_ss_reset(struct st_hba *hba)
  1074. {
  1075. writel(SS_H2I_INT_RESET, hba->mmio_base + YH2I_INT);
  1076. readl(hba->mmio_base + YH2I_INT);
  1077. ssleep(5);
  1078. }
  1079. static int stex_do_reset(struct st_hba *hba)
  1080. {
  1081. struct st_ccb *ccb;
  1082. unsigned long flags;
  1083. unsigned int mu_status = MU_STATE_RESETTING;
  1084. u16 tag;
  1085. spin_lock_irqsave(hba->host->host_lock, flags);
  1086. if (hba->mu_status == MU_STATE_STARTING) {
  1087. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1088. printk(KERN_INFO DRV_NAME "(%s): request reset during init\n",
  1089. pci_name(hba->pdev));
  1090. return 0;
  1091. }
  1092. while (hba->mu_status == MU_STATE_RESETTING) {
  1093. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1094. wait_event_timeout(hba->reset_waitq,
  1095. hba->mu_status != MU_STATE_RESETTING,
  1096. MU_MAX_DELAY * HZ);
  1097. spin_lock_irqsave(hba->host->host_lock, flags);
  1098. mu_status = hba->mu_status;
  1099. }
  1100. if (mu_status != MU_STATE_RESETTING) {
  1101. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1102. return (mu_status == MU_STATE_STARTED) ? 0 : -1;
  1103. }
  1104. hba->mu_status = MU_STATE_RESETTING;
  1105. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1106. if (hba->cardtype == st_yosemite)
  1107. return stex_yos_reset(hba);
  1108. if (hba->cardtype == st_shasta)
  1109. stex_hard_reset(hba);
  1110. else if (hba->cardtype == st_yel)
  1111. stex_ss_reset(hba);
  1112. spin_lock_irqsave(hba->host->host_lock, flags);
  1113. for (tag = 0; tag < hba->host->can_queue; tag++) {
  1114. ccb = &hba->ccb[tag];
  1115. if (ccb->req == NULL)
  1116. continue;
  1117. ccb->req = NULL;
  1118. if (ccb->cmd) {
  1119. scsi_dma_unmap(ccb->cmd);
  1120. ccb->cmd->result = DID_RESET << 16;
  1121. ccb->cmd->scsi_done(ccb->cmd);
  1122. ccb->cmd = NULL;
  1123. }
  1124. }
  1125. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1126. if (stex_handshake(hba) == 0)
  1127. return 0;
  1128. printk(KERN_WARNING DRV_NAME "(%s): resetting: handshake failed\n",
  1129. pci_name(hba->pdev));
  1130. return -1;
  1131. }
  1132. static int stex_reset(struct scsi_cmnd *cmd)
  1133. {
  1134. struct st_hba *hba;
  1135. hba = (struct st_hba *) &cmd->device->host->hostdata[0];
  1136. shost_printk(KERN_INFO, cmd->device->host,
  1137. "resetting host\n");
  1138. return stex_do_reset(hba) ? FAILED : SUCCESS;
  1139. }
  1140. static void stex_reset_work(struct work_struct *work)
  1141. {
  1142. struct st_hba *hba = container_of(work, struct st_hba, reset_work);
  1143. stex_do_reset(hba);
  1144. }
  1145. static int stex_biosparam(struct scsi_device *sdev,
  1146. struct block_device *bdev, sector_t capacity, int geom[])
  1147. {
  1148. int heads = 255, sectors = 63;
  1149. if (capacity < 0x200000) {
  1150. heads = 64;
  1151. sectors = 32;
  1152. }
  1153. sector_div(capacity, heads * sectors);
  1154. geom[0] = heads;
  1155. geom[1] = sectors;
  1156. geom[2] = capacity;
  1157. return 0;
  1158. }
  1159. static struct scsi_host_template driver_template = {
  1160. .module = THIS_MODULE,
  1161. .name = DRV_NAME,
  1162. .proc_name = DRV_NAME,
  1163. .bios_param = stex_biosparam,
  1164. .queuecommand = stex_queuecommand,
  1165. .slave_configure = stex_slave_config,
  1166. .eh_abort_handler = stex_abort,
  1167. .eh_host_reset_handler = stex_reset,
  1168. .this_id = -1,
  1169. };
  1170. static struct pci_device_id stex_pci_tbl[] = {
  1171. /* st_shasta */
  1172. { 0x105a, 0x8350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1173. st_shasta }, /* SuperTrak EX8350/8300/16350/16300 */
  1174. { 0x105a, 0xc350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1175. st_shasta }, /* SuperTrak EX12350 */
  1176. { 0x105a, 0x4302, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1177. st_shasta }, /* SuperTrak EX4350 */
  1178. { 0x105a, 0xe350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1179. st_shasta }, /* SuperTrak EX24350 */
  1180. /* st_vsc */
  1181. { 0x105a, 0x7250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_vsc },
  1182. /* st_yosemite */
  1183. { 0x105a, 0x8650, 0x105a, PCI_ANY_ID, 0, 0, st_yosemite },
  1184. /* st_seq */
  1185. { 0x105a, 0x3360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_seq },
  1186. /* st_yel */
  1187. { 0x105a, 0x8650, 0x1033, PCI_ANY_ID, 0, 0, st_yel },
  1188. { 0x105a, 0x8760, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_yel },
  1189. { } /* terminate list */
  1190. };
  1191. static struct st_card_info stex_card_info[] = {
  1192. /* st_shasta */
  1193. {
  1194. .max_id = 17,
  1195. .max_lun = 8,
  1196. .max_channel = 0,
  1197. .rq_count = 32,
  1198. .rq_size = 1048,
  1199. .sts_count = 32,
  1200. .alloc_rq = stex_alloc_req,
  1201. .map_sg = stex_map_sg,
  1202. .send = stex_send_cmd,
  1203. },
  1204. /* st_vsc */
  1205. {
  1206. .max_id = 129,
  1207. .max_lun = 1,
  1208. .max_channel = 0,
  1209. .rq_count = 32,
  1210. .rq_size = 1048,
  1211. .sts_count = 32,
  1212. .alloc_rq = stex_alloc_req,
  1213. .map_sg = stex_map_sg,
  1214. .send = stex_send_cmd,
  1215. },
  1216. /* st_yosemite */
  1217. {
  1218. .max_id = 2,
  1219. .max_lun = 256,
  1220. .max_channel = 0,
  1221. .rq_count = 256,
  1222. .rq_size = 1048,
  1223. .sts_count = 256,
  1224. .alloc_rq = stex_alloc_req,
  1225. .map_sg = stex_map_sg,
  1226. .send = stex_send_cmd,
  1227. },
  1228. /* st_seq */
  1229. {
  1230. .max_id = 129,
  1231. .max_lun = 1,
  1232. .max_channel = 0,
  1233. .rq_count = 32,
  1234. .rq_size = 1048,
  1235. .sts_count = 32,
  1236. .alloc_rq = stex_alloc_req,
  1237. .map_sg = stex_map_sg,
  1238. .send = stex_send_cmd,
  1239. },
  1240. /* st_yel */
  1241. {
  1242. .max_id = 129,
  1243. .max_lun = 256,
  1244. .max_channel = 3,
  1245. .rq_count = 801,
  1246. .rq_size = 512,
  1247. .sts_count = 801,
  1248. .alloc_rq = stex_ss_alloc_req,
  1249. .map_sg = stex_ss_map_sg,
  1250. .send = stex_ss_send_cmd,
  1251. },
  1252. };
  1253. static int stex_set_dma_mask(struct pci_dev * pdev)
  1254. {
  1255. int ret;
  1256. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
  1257. && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
  1258. return 0;
  1259. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1260. if (!ret)
  1261. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1262. return ret;
  1263. }
  1264. static int stex_request_irq(struct st_hba *hba)
  1265. {
  1266. struct pci_dev *pdev = hba->pdev;
  1267. int status;
  1268. if (msi) {
  1269. status = pci_enable_msi(pdev);
  1270. if (status != 0)
  1271. printk(KERN_ERR DRV_NAME
  1272. "(%s): error %d setting up MSI\n",
  1273. pci_name(pdev), status);
  1274. else
  1275. hba->msi_enabled = 1;
  1276. } else
  1277. hba->msi_enabled = 0;
  1278. status = request_irq(pdev->irq, hba->cardtype == st_yel ?
  1279. stex_ss_intr : stex_intr, IRQF_SHARED, DRV_NAME, hba);
  1280. if (status != 0) {
  1281. if (hba->msi_enabled)
  1282. pci_disable_msi(pdev);
  1283. }
  1284. return status;
  1285. }
  1286. static void stex_free_irq(struct st_hba *hba)
  1287. {
  1288. struct pci_dev *pdev = hba->pdev;
  1289. free_irq(pdev->irq, hba);
  1290. if (hba->msi_enabled)
  1291. pci_disable_msi(pdev);
  1292. }
  1293. static int stex_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1294. {
  1295. struct st_hba *hba;
  1296. struct Scsi_Host *host;
  1297. const struct st_card_info *ci = NULL;
  1298. u32 sts_offset, cp_offset, scratch_offset;
  1299. int err;
  1300. err = pci_enable_device(pdev);
  1301. if (err)
  1302. return err;
  1303. pci_set_master(pdev);
  1304. host = scsi_host_alloc(&driver_template, sizeof(struct st_hba));
  1305. if (!host) {
  1306. printk(KERN_ERR DRV_NAME "(%s): scsi_host_alloc failed\n",
  1307. pci_name(pdev));
  1308. err = -ENOMEM;
  1309. goto out_disable;
  1310. }
  1311. hba = (struct st_hba *)host->hostdata;
  1312. memset(hba, 0, sizeof(struct st_hba));
  1313. err = pci_request_regions(pdev, DRV_NAME);
  1314. if (err < 0) {
  1315. printk(KERN_ERR DRV_NAME "(%s): request regions failed\n",
  1316. pci_name(pdev));
  1317. goto out_scsi_host_put;
  1318. }
  1319. hba->mmio_base = pci_ioremap_bar(pdev, 0);
  1320. if ( !hba->mmio_base) {
  1321. printk(KERN_ERR DRV_NAME "(%s): memory map failed\n",
  1322. pci_name(pdev));
  1323. err = -ENOMEM;
  1324. goto out_release_regions;
  1325. }
  1326. err = stex_set_dma_mask(pdev);
  1327. if (err) {
  1328. printk(KERN_ERR DRV_NAME "(%s): set dma mask failed\n",
  1329. pci_name(pdev));
  1330. goto out_iounmap;
  1331. }
  1332. hba->cardtype = (unsigned int) id->driver_data;
  1333. ci = &stex_card_info[hba->cardtype];
  1334. sts_offset = scratch_offset = (ci->rq_count+1) * ci->rq_size;
  1335. if (hba->cardtype == st_yel)
  1336. sts_offset += (ci->sts_count+1) * sizeof(u32);
  1337. cp_offset = sts_offset + (ci->sts_count+1) * sizeof(struct status_msg);
  1338. hba->dma_size = cp_offset + sizeof(struct st_frame);
  1339. if (hba->cardtype == st_seq ||
  1340. (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) {
  1341. hba->extra_offset = hba->dma_size;
  1342. hba->dma_size += ST_ADDITIONAL_MEM;
  1343. }
  1344. hba->dma_mem = dma_alloc_coherent(&pdev->dev,
  1345. hba->dma_size, &hba->dma_handle, GFP_KERNEL);
  1346. if (!hba->dma_mem) {
  1347. /* Retry minimum coherent mapping for st_seq and st_vsc */
  1348. if (hba->cardtype == st_seq ||
  1349. (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) {
  1350. printk(KERN_WARNING DRV_NAME
  1351. "(%s): allocating min buffer for controller\n",
  1352. pci_name(pdev));
  1353. hba->dma_size = hba->extra_offset
  1354. + ST_ADDITIONAL_MEM_MIN;
  1355. hba->dma_mem = dma_alloc_coherent(&pdev->dev,
  1356. hba->dma_size, &hba->dma_handle, GFP_KERNEL);
  1357. }
  1358. if (!hba->dma_mem) {
  1359. err = -ENOMEM;
  1360. printk(KERN_ERR DRV_NAME "(%s): dma mem alloc failed\n",
  1361. pci_name(pdev));
  1362. goto out_iounmap;
  1363. }
  1364. }
  1365. hba->ccb = kcalloc(ci->rq_count, sizeof(struct st_ccb), GFP_KERNEL);
  1366. if (!hba->ccb) {
  1367. err = -ENOMEM;
  1368. printk(KERN_ERR DRV_NAME "(%s): ccb alloc failed\n",
  1369. pci_name(pdev));
  1370. goto out_pci_free;
  1371. }
  1372. if (hba->cardtype == st_yel)
  1373. hba->scratch = (__le32 *)(hba->dma_mem + scratch_offset);
  1374. hba->status_buffer = (struct status_msg *)(hba->dma_mem + sts_offset);
  1375. hba->copy_buffer = hba->dma_mem + cp_offset;
  1376. hba->rq_count = ci->rq_count;
  1377. hba->rq_size = ci->rq_size;
  1378. hba->sts_count = ci->sts_count;
  1379. hba->alloc_rq = ci->alloc_rq;
  1380. hba->map_sg = ci->map_sg;
  1381. hba->send = ci->send;
  1382. hba->mu_status = MU_STATE_STARTING;
  1383. if (hba->cardtype == st_yel)
  1384. host->sg_tablesize = 38;
  1385. else
  1386. host->sg_tablesize = 32;
  1387. host->can_queue = ci->rq_count;
  1388. host->cmd_per_lun = ci->rq_count;
  1389. host->max_id = ci->max_id;
  1390. host->max_lun = ci->max_lun;
  1391. host->max_channel = ci->max_channel;
  1392. host->unique_id = host->host_no;
  1393. host->max_cmd_len = STEX_CDB_LENGTH;
  1394. hba->host = host;
  1395. hba->pdev = pdev;
  1396. init_waitqueue_head(&hba->reset_waitq);
  1397. snprintf(hba->work_q_name, sizeof(hba->work_q_name),
  1398. "stex_wq_%d", host->host_no);
  1399. hba->work_q = create_singlethread_workqueue(hba->work_q_name);
  1400. if (!hba->work_q) {
  1401. printk(KERN_ERR DRV_NAME "(%s): create workqueue failed\n",
  1402. pci_name(pdev));
  1403. err = -ENOMEM;
  1404. goto out_ccb_free;
  1405. }
  1406. INIT_WORK(&hba->reset_work, stex_reset_work);
  1407. err = stex_request_irq(hba);
  1408. if (err) {
  1409. printk(KERN_ERR DRV_NAME "(%s): request irq failed\n",
  1410. pci_name(pdev));
  1411. goto out_free_wq;
  1412. }
  1413. err = stex_handshake(hba);
  1414. if (err)
  1415. goto out_free_irq;
  1416. pci_set_drvdata(pdev, hba);
  1417. err = scsi_add_host(host, &pdev->dev);
  1418. if (err) {
  1419. printk(KERN_ERR DRV_NAME "(%s): scsi_add_host failed\n",
  1420. pci_name(pdev));
  1421. goto out_free_irq;
  1422. }
  1423. scsi_scan_host(host);
  1424. return 0;
  1425. out_free_irq:
  1426. stex_free_irq(hba);
  1427. out_free_wq:
  1428. destroy_workqueue(hba->work_q);
  1429. out_ccb_free:
  1430. kfree(hba->ccb);
  1431. out_pci_free:
  1432. dma_free_coherent(&pdev->dev, hba->dma_size,
  1433. hba->dma_mem, hba->dma_handle);
  1434. out_iounmap:
  1435. iounmap(hba->mmio_base);
  1436. out_release_regions:
  1437. pci_release_regions(pdev);
  1438. out_scsi_host_put:
  1439. scsi_host_put(host);
  1440. out_disable:
  1441. pci_disable_device(pdev);
  1442. return err;
  1443. }
  1444. static void stex_hba_stop(struct st_hba *hba)
  1445. {
  1446. struct req_msg *req;
  1447. struct st_msg_header *msg_h;
  1448. unsigned long flags;
  1449. unsigned long before;
  1450. u16 tag = 0;
  1451. spin_lock_irqsave(hba->host->host_lock, flags);
  1452. req = hba->alloc_rq(hba);
  1453. if (hba->cardtype == st_yel) {
  1454. msg_h = (struct st_msg_header *)req - 1;
  1455. memset(msg_h, 0, hba->rq_size);
  1456. } else
  1457. memset(req, 0, hba->rq_size);
  1458. if (hba->cardtype == st_yosemite || hba->cardtype == st_yel) {
  1459. req->cdb[0] = MGT_CMD;
  1460. req->cdb[1] = MGT_CMD_SIGNATURE;
  1461. req->cdb[2] = CTLR_CONFIG_CMD;
  1462. req->cdb[3] = CTLR_SHUTDOWN;
  1463. } else {
  1464. req->cdb[0] = CONTROLLER_CMD;
  1465. req->cdb[1] = CTLR_POWER_STATE_CHANGE;
  1466. req->cdb[2] = CTLR_POWER_SAVING;
  1467. }
  1468. hba->ccb[tag].cmd = NULL;
  1469. hba->ccb[tag].sg_count = 0;
  1470. hba->ccb[tag].sense_bufflen = 0;
  1471. hba->ccb[tag].sense_buffer = NULL;
  1472. hba->ccb[tag].req_type = PASSTHRU_REQ_TYPE;
  1473. hba->send(hba, req, tag);
  1474. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1475. before = jiffies;
  1476. while (hba->ccb[tag].req_type & PASSTHRU_REQ_TYPE) {
  1477. if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) {
  1478. hba->ccb[tag].req_type = 0;
  1479. return;
  1480. }
  1481. msleep(1);
  1482. }
  1483. }
  1484. static void stex_hba_free(struct st_hba *hba)
  1485. {
  1486. stex_free_irq(hba);
  1487. destroy_workqueue(hba->work_q);
  1488. iounmap(hba->mmio_base);
  1489. pci_release_regions(hba->pdev);
  1490. kfree(hba->ccb);
  1491. dma_free_coherent(&hba->pdev->dev, hba->dma_size,
  1492. hba->dma_mem, hba->dma_handle);
  1493. }
  1494. static void stex_remove(struct pci_dev *pdev)
  1495. {
  1496. struct st_hba *hba = pci_get_drvdata(pdev);
  1497. scsi_remove_host(hba->host);
  1498. stex_hba_stop(hba);
  1499. stex_hba_free(hba);
  1500. scsi_host_put(hba->host);
  1501. pci_disable_device(pdev);
  1502. }
  1503. static void stex_shutdown(struct pci_dev *pdev)
  1504. {
  1505. struct st_hba *hba = pci_get_drvdata(pdev);
  1506. stex_hba_stop(hba);
  1507. }
  1508. MODULE_DEVICE_TABLE(pci, stex_pci_tbl);
  1509. static struct pci_driver stex_pci_driver = {
  1510. .name = DRV_NAME,
  1511. .id_table = stex_pci_tbl,
  1512. .probe = stex_probe,
  1513. .remove = stex_remove,
  1514. .shutdown = stex_shutdown,
  1515. };
  1516. static int __init stex_init(void)
  1517. {
  1518. printk(KERN_INFO DRV_NAME
  1519. ": Promise SuperTrak EX Driver version: %s\n",
  1520. ST_DRIVER_VERSION);
  1521. return pci_register_driver(&stex_pci_driver);
  1522. }
  1523. static void __exit stex_exit(void)
  1524. {
  1525. pci_unregister_driver(&stex_pci_driver);
  1526. }
  1527. module_init(stex_init);
  1528. module_exit(stex_exit);