stex.c 43 KB

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