stex.c 43 KB

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