stex.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  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_activate_tcq(sdev, 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 void
  474. stex_slave_destroy(struct scsi_device *sdev)
  475. {
  476. scsi_deactivate_tcq(sdev, 1);
  477. }
  478. static int
  479. stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  480. {
  481. struct st_hba *hba;
  482. struct Scsi_Host *host;
  483. unsigned int id, lun;
  484. struct req_msg *req;
  485. u16 tag;
  486. host = cmd->device->host;
  487. id = cmd->device->id;
  488. lun = cmd->device->lun;
  489. hba = (struct st_hba *) &host->hostdata[0];
  490. if (unlikely(hba->mu_status == MU_STATE_RESETTING))
  491. return SCSI_MLQUEUE_HOST_BUSY;
  492. switch (cmd->cmnd[0]) {
  493. case MODE_SENSE_10:
  494. {
  495. static char ms10_caching_page[12] =
  496. { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 };
  497. unsigned char page;
  498. page = cmd->cmnd[2] & 0x3f;
  499. if (page == 0x8 || page == 0x3f) {
  500. scsi_sg_copy_from_buffer(cmd, ms10_caching_page,
  501. sizeof(ms10_caching_page));
  502. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  503. done(cmd);
  504. } else
  505. stex_invalid_field(cmd, done);
  506. return 0;
  507. }
  508. case REPORT_LUNS:
  509. /*
  510. * The shasta firmware does not report actual luns in the
  511. * target, so fail the command to force sequential lun scan.
  512. * Also, the console device does not support this command.
  513. */
  514. if (hba->cardtype == st_shasta || id == host->max_id - 1) {
  515. stex_invalid_field(cmd, done);
  516. return 0;
  517. }
  518. break;
  519. case TEST_UNIT_READY:
  520. if (id == host->max_id - 1) {
  521. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  522. done(cmd);
  523. return 0;
  524. }
  525. break;
  526. case INQUIRY:
  527. if (lun >= host->max_lun) {
  528. cmd->result = DID_NO_CONNECT << 16;
  529. done(cmd);
  530. return 0;
  531. }
  532. if (id != host->max_id - 1)
  533. break;
  534. if (!lun && !cmd->device->channel &&
  535. (cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
  536. scsi_sg_copy_from_buffer(cmd, (void *)console_inq_page,
  537. sizeof(console_inq_page));
  538. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  539. done(cmd);
  540. } else
  541. stex_invalid_field(cmd, done);
  542. return 0;
  543. case PASSTHRU_CMD:
  544. if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
  545. struct st_drvver ver;
  546. size_t cp_len = sizeof(ver);
  547. ver.major = ST_VER_MAJOR;
  548. ver.minor = ST_VER_MINOR;
  549. ver.oem = ST_OEM;
  550. ver.build = ST_BUILD_VER;
  551. ver.signature[0] = PASSTHRU_SIGNATURE;
  552. ver.console_id = host->max_id - 1;
  553. ver.host_no = hba->host->host_no;
  554. cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
  555. cmd->result = sizeof(ver) == cp_len ?
  556. DID_OK << 16 | COMMAND_COMPLETE << 8 :
  557. DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  558. done(cmd);
  559. return 0;
  560. }
  561. default:
  562. break;
  563. }
  564. cmd->scsi_done = done;
  565. tag = cmd->request->tag;
  566. if (unlikely(tag >= host->can_queue))
  567. return SCSI_MLQUEUE_HOST_BUSY;
  568. req = hba->alloc_rq(hba);
  569. req->lun = lun;
  570. req->target = id;
  571. /* cdb */
  572. memcpy(req->cdb, cmd->cmnd, STEX_CDB_LENGTH);
  573. if (cmd->sc_data_direction == DMA_FROM_DEVICE)
  574. req->data_dir = MSG_DATA_DIR_IN;
  575. else if (cmd->sc_data_direction == DMA_TO_DEVICE)
  576. req->data_dir = MSG_DATA_DIR_OUT;
  577. else
  578. req->data_dir = MSG_DATA_DIR_ND;
  579. hba->ccb[tag].cmd = cmd;
  580. hba->ccb[tag].sense_bufflen = SCSI_SENSE_BUFFERSIZE;
  581. hba->ccb[tag].sense_buffer = cmd->sense_buffer;
  582. if (!hba->map_sg(hba, req, &hba->ccb[tag])) {
  583. hba->ccb[tag].sg_count = 0;
  584. memset(&req->variable[0], 0, 8);
  585. }
  586. hba->send(hba, req, tag);
  587. return 0;
  588. }
  589. static DEF_SCSI_QCMD(stex_queuecommand)
  590. static void stex_scsi_done(struct st_ccb *ccb)
  591. {
  592. struct scsi_cmnd *cmd = ccb->cmd;
  593. int result;
  594. if (ccb->srb_status == SRB_STATUS_SUCCESS || ccb->srb_status == 0) {
  595. result = ccb->scsi_status;
  596. switch (ccb->scsi_status) {
  597. case SAM_STAT_GOOD:
  598. result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
  599. break;
  600. case SAM_STAT_CHECK_CONDITION:
  601. result |= DRIVER_SENSE << 24;
  602. break;
  603. case SAM_STAT_BUSY:
  604. result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
  605. break;
  606. default:
  607. result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  608. break;
  609. }
  610. }
  611. else if (ccb->srb_status & SRB_SEE_SENSE)
  612. result = DRIVER_SENSE << 24 | SAM_STAT_CHECK_CONDITION;
  613. else switch (ccb->srb_status) {
  614. case SRB_STATUS_SELECTION_TIMEOUT:
  615. result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  616. break;
  617. case SRB_STATUS_BUSY:
  618. result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
  619. break;
  620. case SRB_STATUS_INVALID_REQUEST:
  621. case SRB_STATUS_ERROR:
  622. default:
  623. result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  624. break;
  625. }
  626. cmd->result = result;
  627. cmd->scsi_done(cmd);
  628. }
  629. static void stex_copy_data(struct st_ccb *ccb,
  630. struct status_msg *resp, unsigned int variable)
  631. {
  632. if (resp->scsi_status != SAM_STAT_GOOD) {
  633. if (ccb->sense_buffer != NULL)
  634. memcpy(ccb->sense_buffer, resp->variable,
  635. min(variable, ccb->sense_bufflen));
  636. return;
  637. }
  638. if (ccb->cmd == NULL)
  639. return;
  640. scsi_sg_copy_from_buffer(ccb->cmd, resp->variable, variable);
  641. }
  642. static void stex_check_cmd(struct st_hba *hba,
  643. struct st_ccb *ccb, struct status_msg *resp)
  644. {
  645. if (ccb->cmd->cmnd[0] == MGT_CMD &&
  646. resp->scsi_status != SAM_STAT_CHECK_CONDITION)
  647. scsi_set_resid(ccb->cmd, scsi_bufflen(ccb->cmd) -
  648. le32_to_cpu(*(__le32 *)&resp->variable[0]));
  649. }
  650. static void stex_mu_intr(struct st_hba *hba, u32 doorbell)
  651. {
  652. void __iomem *base = hba->mmio_base;
  653. struct status_msg *resp;
  654. struct st_ccb *ccb;
  655. unsigned int size;
  656. u16 tag;
  657. if (unlikely(!(doorbell & MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED)))
  658. return;
  659. /* status payloads */
  660. hba->status_head = readl(base + OMR1);
  661. if (unlikely(hba->status_head > hba->sts_count)) {
  662. printk(KERN_WARNING DRV_NAME "(%s): invalid status head\n",
  663. pci_name(hba->pdev));
  664. return;
  665. }
  666. /*
  667. * it's not a valid status payload if:
  668. * 1. there are no pending requests(e.g. during init stage)
  669. * 2. there are some pending requests, but the controller is in
  670. * reset status, and its type is not st_yosemite
  671. * firmware of st_yosemite in reset status will return pending requests
  672. * to driver, so we allow it to pass
  673. */
  674. if (unlikely(hba->out_req_cnt <= 0 ||
  675. (hba->mu_status == MU_STATE_RESETTING &&
  676. hba->cardtype != st_yosemite))) {
  677. hba->status_tail = hba->status_head;
  678. goto update_status;
  679. }
  680. while (hba->status_tail != hba->status_head) {
  681. resp = stex_get_status(hba);
  682. tag = le16_to_cpu(resp->tag);
  683. if (unlikely(tag >= hba->host->can_queue)) {
  684. printk(KERN_WARNING DRV_NAME
  685. "(%s): invalid tag\n", pci_name(hba->pdev));
  686. continue;
  687. }
  688. hba->out_req_cnt--;
  689. ccb = &hba->ccb[tag];
  690. if (unlikely(hba->wait_ccb == ccb))
  691. hba->wait_ccb = NULL;
  692. if (unlikely(ccb->req == NULL)) {
  693. printk(KERN_WARNING DRV_NAME
  694. "(%s): lagging req\n", pci_name(hba->pdev));
  695. continue;
  696. }
  697. size = resp->payload_sz * sizeof(u32); /* payload size */
  698. if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN ||
  699. size > sizeof(*resp))) {
  700. printk(KERN_WARNING DRV_NAME "(%s): bad status size\n",
  701. pci_name(hba->pdev));
  702. } else {
  703. size -= sizeof(*resp) - STATUS_VAR_LEN; /* copy size */
  704. if (size)
  705. stex_copy_data(ccb, resp, size);
  706. }
  707. ccb->req = NULL;
  708. ccb->srb_status = resp->srb_status;
  709. ccb->scsi_status = resp->scsi_status;
  710. if (likely(ccb->cmd != NULL)) {
  711. if (hba->cardtype == st_yosemite)
  712. stex_check_cmd(hba, ccb, resp);
  713. if (unlikely(ccb->cmd->cmnd[0] == PASSTHRU_CMD &&
  714. ccb->cmd->cmnd[1] == PASSTHRU_GET_ADAPTER))
  715. stex_controller_info(hba, ccb);
  716. scsi_dma_unmap(ccb->cmd);
  717. stex_scsi_done(ccb);
  718. } else
  719. ccb->req_type = 0;
  720. }
  721. update_status:
  722. writel(hba->status_head, base + IMR1);
  723. readl(base + IMR1); /* flush */
  724. }
  725. static irqreturn_t stex_intr(int irq, void *__hba)
  726. {
  727. struct st_hba *hba = __hba;
  728. void __iomem *base = hba->mmio_base;
  729. u32 data;
  730. unsigned long flags;
  731. spin_lock_irqsave(hba->host->host_lock, flags);
  732. data = readl(base + ODBL);
  733. if (data && data != 0xffffffff) {
  734. /* clear the interrupt */
  735. writel(data, base + ODBL);
  736. readl(base + ODBL); /* flush */
  737. stex_mu_intr(hba, data);
  738. spin_unlock_irqrestore(hba->host->host_lock, flags);
  739. if (unlikely(data & MU_OUTBOUND_DOORBELL_REQUEST_RESET &&
  740. hba->cardtype == st_shasta))
  741. queue_work(hba->work_q, &hba->reset_work);
  742. return IRQ_HANDLED;
  743. }
  744. spin_unlock_irqrestore(hba->host->host_lock, flags);
  745. return IRQ_NONE;
  746. }
  747. static void stex_ss_mu_intr(struct st_hba *hba)
  748. {
  749. struct status_msg *resp;
  750. struct st_ccb *ccb;
  751. __le32 *scratch;
  752. unsigned int size;
  753. int count = 0;
  754. u32 value;
  755. u16 tag;
  756. if (unlikely(hba->out_req_cnt <= 0 ||
  757. hba->mu_status == MU_STATE_RESETTING))
  758. return;
  759. while (count < hba->sts_count) {
  760. scratch = hba->scratch + hba->status_tail;
  761. value = le32_to_cpu(*scratch);
  762. if (unlikely(!(value & SS_STS_NORMAL)))
  763. return;
  764. resp = hba->status_buffer + hba->status_tail;
  765. *scratch = 0;
  766. ++count;
  767. ++hba->status_tail;
  768. hba->status_tail %= hba->sts_count+1;
  769. tag = (u16)value;
  770. if (unlikely(tag >= hba->host->can_queue)) {
  771. printk(KERN_WARNING DRV_NAME
  772. "(%s): invalid tag\n", pci_name(hba->pdev));
  773. continue;
  774. }
  775. hba->out_req_cnt--;
  776. ccb = &hba->ccb[tag];
  777. if (unlikely(hba->wait_ccb == ccb))
  778. hba->wait_ccb = NULL;
  779. if (unlikely(ccb->req == NULL)) {
  780. printk(KERN_WARNING DRV_NAME
  781. "(%s): lagging req\n", pci_name(hba->pdev));
  782. continue;
  783. }
  784. ccb->req = NULL;
  785. if (likely(value & SS_STS_DONE)) { /* normal case */
  786. ccb->srb_status = SRB_STATUS_SUCCESS;
  787. ccb->scsi_status = SAM_STAT_GOOD;
  788. } else {
  789. ccb->srb_status = resp->srb_status;
  790. ccb->scsi_status = resp->scsi_status;
  791. size = resp->payload_sz * sizeof(u32);
  792. if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN ||
  793. size > sizeof(*resp))) {
  794. printk(KERN_WARNING DRV_NAME
  795. "(%s): bad status size\n",
  796. pci_name(hba->pdev));
  797. } else {
  798. size -= sizeof(*resp) - STATUS_VAR_LEN;
  799. if (size)
  800. stex_copy_data(ccb, resp, size);
  801. }
  802. if (likely(ccb->cmd != NULL))
  803. stex_check_cmd(hba, ccb, resp);
  804. }
  805. if (likely(ccb->cmd != NULL)) {
  806. scsi_dma_unmap(ccb->cmd);
  807. stex_scsi_done(ccb);
  808. } else
  809. ccb->req_type = 0;
  810. }
  811. }
  812. static irqreturn_t stex_ss_intr(int irq, void *__hba)
  813. {
  814. struct st_hba *hba = __hba;
  815. void __iomem *base = hba->mmio_base;
  816. u32 data;
  817. unsigned long flags;
  818. spin_lock_irqsave(hba->host->host_lock, flags);
  819. data = readl(base + YI2H_INT);
  820. if (data && data != 0xffffffff) {
  821. /* clear the interrupt */
  822. writel(data, base + YI2H_INT_C);
  823. stex_ss_mu_intr(hba);
  824. spin_unlock_irqrestore(hba->host->host_lock, flags);
  825. if (unlikely(data & SS_I2H_REQUEST_RESET))
  826. queue_work(hba->work_q, &hba->reset_work);
  827. return IRQ_HANDLED;
  828. }
  829. spin_unlock_irqrestore(hba->host->host_lock, flags);
  830. return IRQ_NONE;
  831. }
  832. static int stex_common_handshake(struct st_hba *hba)
  833. {
  834. void __iomem *base = hba->mmio_base;
  835. struct handshake_frame *h;
  836. dma_addr_t status_phys;
  837. u32 data;
  838. unsigned long before;
  839. if (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
  840. writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
  841. readl(base + IDBL);
  842. before = jiffies;
  843. while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
  844. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  845. printk(KERN_ERR DRV_NAME
  846. "(%s): no handshake signature\n",
  847. pci_name(hba->pdev));
  848. return -1;
  849. }
  850. rmb();
  851. msleep(1);
  852. }
  853. }
  854. udelay(10);
  855. data = readl(base + OMR1);
  856. if ((data & 0xffff0000) == MU_HANDSHAKE_SIGNATURE_HALF) {
  857. data &= 0x0000ffff;
  858. if (hba->host->can_queue > data) {
  859. hba->host->can_queue = data;
  860. hba->host->cmd_per_lun = data;
  861. }
  862. }
  863. h = (struct handshake_frame *)hba->status_buffer;
  864. h->rb_phy = cpu_to_le64(hba->dma_handle);
  865. h->req_sz = cpu_to_le16(hba->rq_size);
  866. h->req_cnt = cpu_to_le16(hba->rq_count+1);
  867. h->status_sz = cpu_to_le16(sizeof(struct status_msg));
  868. h->status_cnt = cpu_to_le16(hba->sts_count+1);
  869. stex_gettime(&h->hosttime);
  870. h->partner_type = HMU_PARTNER_TYPE;
  871. if (hba->extra_offset) {
  872. h->extra_offset = cpu_to_le32(hba->extra_offset);
  873. h->extra_size = cpu_to_le32(hba->dma_size - hba->extra_offset);
  874. } else
  875. h->extra_offset = h->extra_size = 0;
  876. status_phys = hba->dma_handle + (hba->rq_count+1) * hba->rq_size;
  877. writel(status_phys, base + IMR0);
  878. readl(base + IMR0);
  879. writel((status_phys >> 16) >> 16, base + IMR1);
  880. readl(base + IMR1);
  881. writel((status_phys >> 16) >> 16, base + OMR0); /* old fw compatible */
  882. readl(base + OMR0);
  883. writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
  884. readl(base + IDBL); /* flush */
  885. udelay(10);
  886. before = jiffies;
  887. while (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
  888. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  889. printk(KERN_ERR DRV_NAME
  890. "(%s): no signature after handshake frame\n",
  891. pci_name(hba->pdev));
  892. return -1;
  893. }
  894. rmb();
  895. msleep(1);
  896. }
  897. writel(0, base + IMR0);
  898. readl(base + IMR0);
  899. writel(0, base + OMR0);
  900. readl(base + OMR0);
  901. writel(0, base + IMR1);
  902. readl(base + IMR1);
  903. writel(0, base + OMR1);
  904. readl(base + OMR1); /* flush */
  905. return 0;
  906. }
  907. static int stex_ss_handshake(struct st_hba *hba)
  908. {
  909. void __iomem *base = hba->mmio_base;
  910. struct st_msg_header *msg_h;
  911. struct handshake_frame *h;
  912. __le32 *scratch;
  913. u32 data, scratch_size;
  914. unsigned long before;
  915. int ret = 0;
  916. before = jiffies;
  917. while ((readl(base + YIOA_STATUS) & SS_MU_OPERATIONAL) == 0) {
  918. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  919. printk(KERN_ERR DRV_NAME
  920. "(%s): firmware not operational\n",
  921. pci_name(hba->pdev));
  922. return -1;
  923. }
  924. msleep(1);
  925. }
  926. msg_h = (struct st_msg_header *)hba->dma_mem;
  927. msg_h->handle = cpu_to_le64(hba->dma_handle);
  928. msg_h->flag = SS_HEAD_HANDSHAKE;
  929. h = (struct handshake_frame *)(msg_h + 1);
  930. h->rb_phy = cpu_to_le64(hba->dma_handle);
  931. h->req_sz = cpu_to_le16(hba->rq_size);
  932. h->req_cnt = cpu_to_le16(hba->rq_count+1);
  933. h->status_sz = cpu_to_le16(sizeof(struct status_msg));
  934. h->status_cnt = cpu_to_le16(hba->sts_count+1);
  935. stex_gettime(&h->hosttime);
  936. h->partner_type = HMU_PARTNER_TYPE;
  937. h->extra_offset = h->extra_size = 0;
  938. scratch_size = (hba->sts_count+1)*sizeof(u32);
  939. h->scratch_size = cpu_to_le32(scratch_size);
  940. data = readl(base + YINT_EN);
  941. data &= ~4;
  942. writel(data, base + YINT_EN);
  943. writel((hba->dma_handle >> 16) >> 16, base + YH2I_REQ_HI);
  944. readl(base + YH2I_REQ_HI);
  945. writel(hba->dma_handle, base + YH2I_REQ);
  946. readl(base + YH2I_REQ); /* flush */
  947. scratch = hba->scratch;
  948. before = jiffies;
  949. while (!(le32_to_cpu(*scratch) & SS_STS_HANDSHAKE)) {
  950. if (time_after(jiffies, before + MU_MAX_DELAY * HZ)) {
  951. printk(KERN_ERR DRV_NAME
  952. "(%s): no signature after handshake frame\n",
  953. pci_name(hba->pdev));
  954. ret = -1;
  955. break;
  956. }
  957. rmb();
  958. msleep(1);
  959. }
  960. memset(scratch, 0, scratch_size);
  961. msg_h->flag = 0;
  962. return ret;
  963. }
  964. static int stex_handshake(struct st_hba *hba)
  965. {
  966. int err;
  967. unsigned long flags;
  968. unsigned int mu_status;
  969. err = (hba->cardtype == st_yel) ?
  970. stex_ss_handshake(hba) : stex_common_handshake(hba);
  971. spin_lock_irqsave(hba->host->host_lock, flags);
  972. mu_status = hba->mu_status;
  973. if (err == 0) {
  974. hba->req_head = 0;
  975. hba->req_tail = 0;
  976. hba->status_head = 0;
  977. hba->status_tail = 0;
  978. hba->out_req_cnt = 0;
  979. hba->mu_status = MU_STATE_STARTED;
  980. } else
  981. hba->mu_status = MU_STATE_FAILED;
  982. if (mu_status == MU_STATE_RESETTING)
  983. wake_up_all(&hba->reset_waitq);
  984. spin_unlock_irqrestore(hba->host->host_lock, flags);
  985. return err;
  986. }
  987. static int stex_abort(struct scsi_cmnd *cmd)
  988. {
  989. struct Scsi_Host *host = cmd->device->host;
  990. struct st_hba *hba = (struct st_hba *)host->hostdata;
  991. u16 tag = cmd->request->tag;
  992. void __iomem *base;
  993. u32 data;
  994. int result = SUCCESS;
  995. unsigned long flags;
  996. printk(KERN_INFO DRV_NAME
  997. "(%s): aborting command\n", pci_name(hba->pdev));
  998. scsi_print_command(cmd);
  999. base = hba->mmio_base;
  1000. spin_lock_irqsave(host->host_lock, flags);
  1001. if (tag < host->can_queue &&
  1002. hba->ccb[tag].req && hba->ccb[tag].cmd == cmd)
  1003. hba->wait_ccb = &hba->ccb[tag];
  1004. else
  1005. goto out;
  1006. if (hba->cardtype == st_yel) {
  1007. data = readl(base + YI2H_INT);
  1008. if (data == 0 || data == 0xffffffff)
  1009. goto fail_out;
  1010. writel(data, base + YI2H_INT_C);
  1011. stex_ss_mu_intr(hba);
  1012. } else {
  1013. data = readl(base + ODBL);
  1014. if (data == 0 || data == 0xffffffff)
  1015. goto fail_out;
  1016. writel(data, base + ODBL);
  1017. readl(base + ODBL); /* flush */
  1018. stex_mu_intr(hba, data);
  1019. }
  1020. if (hba->wait_ccb == NULL) {
  1021. printk(KERN_WARNING DRV_NAME
  1022. "(%s): lost interrupt\n", pci_name(hba->pdev));
  1023. goto out;
  1024. }
  1025. fail_out:
  1026. scsi_dma_unmap(cmd);
  1027. hba->wait_ccb->req = NULL; /* nullify the req's future return */
  1028. hba->wait_ccb = NULL;
  1029. result = FAILED;
  1030. out:
  1031. spin_unlock_irqrestore(host->host_lock, flags);
  1032. return result;
  1033. }
  1034. static void stex_hard_reset(struct st_hba *hba)
  1035. {
  1036. struct pci_bus *bus;
  1037. int i;
  1038. u16 pci_cmd;
  1039. u8 pci_bctl;
  1040. for (i = 0; i < 16; i++)
  1041. pci_read_config_dword(hba->pdev, i * 4,
  1042. &hba->pdev->saved_config_space[i]);
  1043. /* Reset secondary bus. Our controller(MU/ATU) is the only device on
  1044. secondary bus. Consult Intel 80331/3 developer's manual for detail */
  1045. bus = hba->pdev->bus;
  1046. pci_read_config_byte(bus->self, PCI_BRIDGE_CONTROL, &pci_bctl);
  1047. pci_bctl |= PCI_BRIDGE_CTL_BUS_RESET;
  1048. pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
  1049. /*
  1050. * 1 ms may be enough for 8-port controllers. But 16-port controllers
  1051. * require more time to finish bus reset. Use 100 ms here for safety
  1052. */
  1053. msleep(100);
  1054. pci_bctl &= ~PCI_BRIDGE_CTL_BUS_RESET;
  1055. pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
  1056. for (i = 0; i < MU_HARD_RESET_WAIT; i++) {
  1057. pci_read_config_word(hba->pdev, PCI_COMMAND, &pci_cmd);
  1058. if (pci_cmd != 0xffff && (pci_cmd & PCI_COMMAND_MASTER))
  1059. break;
  1060. msleep(1);
  1061. }
  1062. ssleep(5);
  1063. for (i = 0; i < 16; i++)
  1064. pci_write_config_dword(hba->pdev, i * 4,
  1065. hba->pdev->saved_config_space[i]);
  1066. }
  1067. static int stex_yos_reset(struct st_hba *hba)
  1068. {
  1069. void __iomem *base;
  1070. unsigned long flags, before;
  1071. int ret = 0;
  1072. base = hba->mmio_base;
  1073. writel(MU_INBOUND_DOORBELL_RESET, base + IDBL);
  1074. readl(base + IDBL); /* flush */
  1075. before = jiffies;
  1076. while (hba->out_req_cnt > 0) {
  1077. if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) {
  1078. printk(KERN_WARNING DRV_NAME
  1079. "(%s): reset timeout\n", pci_name(hba->pdev));
  1080. ret = -1;
  1081. break;
  1082. }
  1083. msleep(1);
  1084. }
  1085. spin_lock_irqsave(hba->host->host_lock, flags);
  1086. if (ret == -1)
  1087. hba->mu_status = MU_STATE_FAILED;
  1088. else
  1089. hba->mu_status = MU_STATE_STARTED;
  1090. wake_up_all(&hba->reset_waitq);
  1091. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1092. return ret;
  1093. }
  1094. static void stex_ss_reset(struct st_hba *hba)
  1095. {
  1096. writel(SS_H2I_INT_RESET, hba->mmio_base + YH2I_INT);
  1097. readl(hba->mmio_base + YH2I_INT);
  1098. ssleep(5);
  1099. }
  1100. static int stex_do_reset(struct st_hba *hba)
  1101. {
  1102. struct st_ccb *ccb;
  1103. unsigned long flags;
  1104. unsigned int mu_status = MU_STATE_RESETTING;
  1105. u16 tag;
  1106. spin_lock_irqsave(hba->host->host_lock, flags);
  1107. if (hba->mu_status == MU_STATE_STARTING) {
  1108. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1109. printk(KERN_INFO DRV_NAME "(%s): request reset during init\n",
  1110. pci_name(hba->pdev));
  1111. return 0;
  1112. }
  1113. while (hba->mu_status == MU_STATE_RESETTING) {
  1114. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1115. wait_event_timeout(hba->reset_waitq,
  1116. hba->mu_status != MU_STATE_RESETTING,
  1117. MU_MAX_DELAY * HZ);
  1118. spin_lock_irqsave(hba->host->host_lock, flags);
  1119. mu_status = hba->mu_status;
  1120. }
  1121. if (mu_status != MU_STATE_RESETTING) {
  1122. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1123. return (mu_status == MU_STATE_STARTED) ? 0 : -1;
  1124. }
  1125. hba->mu_status = MU_STATE_RESETTING;
  1126. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1127. if (hba->cardtype == st_yosemite)
  1128. return stex_yos_reset(hba);
  1129. if (hba->cardtype == st_shasta)
  1130. stex_hard_reset(hba);
  1131. else if (hba->cardtype == st_yel)
  1132. stex_ss_reset(hba);
  1133. spin_lock_irqsave(hba->host->host_lock, flags);
  1134. for (tag = 0; tag < hba->host->can_queue; tag++) {
  1135. ccb = &hba->ccb[tag];
  1136. if (ccb->req == NULL)
  1137. continue;
  1138. ccb->req = NULL;
  1139. if (ccb->cmd) {
  1140. scsi_dma_unmap(ccb->cmd);
  1141. ccb->cmd->result = DID_RESET << 16;
  1142. ccb->cmd->scsi_done(ccb->cmd);
  1143. ccb->cmd = NULL;
  1144. }
  1145. }
  1146. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1147. if (stex_handshake(hba) == 0)
  1148. return 0;
  1149. printk(KERN_WARNING DRV_NAME "(%s): resetting: handshake failed\n",
  1150. pci_name(hba->pdev));
  1151. return -1;
  1152. }
  1153. static int stex_reset(struct scsi_cmnd *cmd)
  1154. {
  1155. struct st_hba *hba;
  1156. hba = (struct st_hba *) &cmd->device->host->hostdata[0];
  1157. printk(KERN_INFO DRV_NAME
  1158. "(%s): resetting host\n", pci_name(hba->pdev));
  1159. scsi_print_command(cmd);
  1160. return stex_do_reset(hba) ? FAILED : SUCCESS;
  1161. }
  1162. static void stex_reset_work(struct work_struct *work)
  1163. {
  1164. struct st_hba *hba = container_of(work, struct st_hba, reset_work);
  1165. stex_do_reset(hba);
  1166. }
  1167. static int stex_biosparam(struct scsi_device *sdev,
  1168. struct block_device *bdev, sector_t capacity, int geom[])
  1169. {
  1170. int heads = 255, sectors = 63;
  1171. if (capacity < 0x200000) {
  1172. heads = 64;
  1173. sectors = 32;
  1174. }
  1175. sector_div(capacity, heads * sectors);
  1176. geom[0] = heads;
  1177. geom[1] = sectors;
  1178. geom[2] = capacity;
  1179. return 0;
  1180. }
  1181. static struct scsi_host_template driver_template = {
  1182. .module = THIS_MODULE,
  1183. .name = DRV_NAME,
  1184. .proc_name = DRV_NAME,
  1185. .bios_param = stex_biosparam,
  1186. .queuecommand = stex_queuecommand,
  1187. .slave_alloc = stex_slave_alloc,
  1188. .slave_configure = stex_slave_config,
  1189. .slave_destroy = stex_slave_destroy,
  1190. .eh_abort_handler = stex_abort,
  1191. .eh_host_reset_handler = stex_reset,
  1192. .this_id = -1,
  1193. };
  1194. static struct pci_device_id stex_pci_tbl[] = {
  1195. /* st_shasta */
  1196. { 0x105a, 0x8350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1197. st_shasta }, /* SuperTrak EX8350/8300/16350/16300 */
  1198. { 0x105a, 0xc350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1199. st_shasta }, /* SuperTrak EX12350 */
  1200. { 0x105a, 0x4302, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1201. st_shasta }, /* SuperTrak EX4350 */
  1202. { 0x105a, 0xe350, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
  1203. st_shasta }, /* SuperTrak EX24350 */
  1204. /* st_vsc */
  1205. { 0x105a, 0x7250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_vsc },
  1206. /* st_yosemite */
  1207. { 0x105a, 0x8650, 0x105a, PCI_ANY_ID, 0, 0, st_yosemite },
  1208. /* st_seq */
  1209. { 0x105a, 0x3360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_seq },
  1210. /* st_yel */
  1211. { 0x105a, 0x8650, 0x1033, PCI_ANY_ID, 0, 0, st_yel },
  1212. { 0x105a, 0x8760, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_yel },
  1213. { } /* terminate list */
  1214. };
  1215. static struct st_card_info stex_card_info[] = {
  1216. /* st_shasta */
  1217. {
  1218. .max_id = 17,
  1219. .max_lun = 8,
  1220. .max_channel = 0,
  1221. .rq_count = 32,
  1222. .rq_size = 1048,
  1223. .sts_count = 32,
  1224. .alloc_rq = stex_alloc_req,
  1225. .map_sg = stex_map_sg,
  1226. .send = stex_send_cmd,
  1227. },
  1228. /* st_vsc */
  1229. {
  1230. .max_id = 129,
  1231. .max_lun = 1,
  1232. .max_channel = 0,
  1233. .rq_count = 32,
  1234. .rq_size = 1048,
  1235. .sts_count = 32,
  1236. .alloc_rq = stex_alloc_req,
  1237. .map_sg = stex_map_sg,
  1238. .send = stex_send_cmd,
  1239. },
  1240. /* st_yosemite */
  1241. {
  1242. .max_id = 2,
  1243. .max_lun = 256,
  1244. .max_channel = 0,
  1245. .rq_count = 256,
  1246. .rq_size = 1048,
  1247. .sts_count = 256,
  1248. .alloc_rq = stex_alloc_req,
  1249. .map_sg = stex_map_sg,
  1250. .send = stex_send_cmd,
  1251. },
  1252. /* st_seq */
  1253. {
  1254. .max_id = 129,
  1255. .max_lun = 1,
  1256. .max_channel = 0,
  1257. .rq_count = 32,
  1258. .rq_size = 1048,
  1259. .sts_count = 32,
  1260. .alloc_rq = stex_alloc_req,
  1261. .map_sg = stex_map_sg,
  1262. .send = stex_send_cmd,
  1263. },
  1264. /* st_yel */
  1265. {
  1266. .max_id = 129,
  1267. .max_lun = 256,
  1268. .max_channel = 3,
  1269. .rq_count = 801,
  1270. .rq_size = 512,
  1271. .sts_count = 801,
  1272. .alloc_rq = stex_ss_alloc_req,
  1273. .map_sg = stex_ss_map_sg,
  1274. .send = stex_ss_send_cmd,
  1275. },
  1276. };
  1277. static int stex_set_dma_mask(struct pci_dev * pdev)
  1278. {
  1279. int ret;
  1280. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
  1281. && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
  1282. return 0;
  1283. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1284. if (!ret)
  1285. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1286. return ret;
  1287. }
  1288. static int stex_request_irq(struct st_hba *hba)
  1289. {
  1290. struct pci_dev *pdev = hba->pdev;
  1291. int status;
  1292. if (msi) {
  1293. status = pci_enable_msi(pdev);
  1294. if (status != 0)
  1295. printk(KERN_ERR DRV_NAME
  1296. "(%s): error %d setting up MSI\n",
  1297. pci_name(pdev), status);
  1298. else
  1299. hba->msi_enabled = 1;
  1300. } else
  1301. hba->msi_enabled = 0;
  1302. status = request_irq(pdev->irq, hba->cardtype == st_yel ?
  1303. stex_ss_intr : stex_intr, IRQF_SHARED, DRV_NAME, hba);
  1304. if (status != 0) {
  1305. if (hba->msi_enabled)
  1306. pci_disable_msi(pdev);
  1307. }
  1308. return status;
  1309. }
  1310. static void stex_free_irq(struct st_hba *hba)
  1311. {
  1312. struct pci_dev *pdev = hba->pdev;
  1313. free_irq(pdev->irq, hba);
  1314. if (hba->msi_enabled)
  1315. pci_disable_msi(pdev);
  1316. }
  1317. static int __devinit
  1318. stex_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1319. {
  1320. struct st_hba *hba;
  1321. struct Scsi_Host *host;
  1322. const struct st_card_info *ci = NULL;
  1323. u32 sts_offset, cp_offset, scratch_offset;
  1324. int err;
  1325. err = pci_enable_device(pdev);
  1326. if (err)
  1327. return err;
  1328. pci_set_master(pdev);
  1329. host = scsi_host_alloc(&driver_template, sizeof(struct st_hba));
  1330. if (!host) {
  1331. printk(KERN_ERR DRV_NAME "(%s): scsi_host_alloc failed\n",
  1332. pci_name(pdev));
  1333. err = -ENOMEM;
  1334. goto out_disable;
  1335. }
  1336. hba = (struct st_hba *)host->hostdata;
  1337. memset(hba, 0, sizeof(struct st_hba));
  1338. err = pci_request_regions(pdev, DRV_NAME);
  1339. if (err < 0) {
  1340. printk(KERN_ERR DRV_NAME "(%s): request regions failed\n",
  1341. pci_name(pdev));
  1342. goto out_scsi_host_put;
  1343. }
  1344. hba->mmio_base = pci_ioremap_bar(pdev, 0);
  1345. if ( !hba->mmio_base) {
  1346. printk(KERN_ERR DRV_NAME "(%s): memory map failed\n",
  1347. pci_name(pdev));
  1348. err = -ENOMEM;
  1349. goto out_release_regions;
  1350. }
  1351. err = stex_set_dma_mask(pdev);
  1352. if (err) {
  1353. printk(KERN_ERR DRV_NAME "(%s): set dma mask failed\n",
  1354. pci_name(pdev));
  1355. goto out_iounmap;
  1356. }
  1357. hba->cardtype = (unsigned int) id->driver_data;
  1358. ci = &stex_card_info[hba->cardtype];
  1359. sts_offset = scratch_offset = (ci->rq_count+1) * ci->rq_size;
  1360. if (hba->cardtype == st_yel)
  1361. sts_offset += (ci->sts_count+1) * sizeof(u32);
  1362. cp_offset = sts_offset + (ci->sts_count+1) * sizeof(struct status_msg);
  1363. hba->dma_size = cp_offset + sizeof(struct st_frame);
  1364. if (hba->cardtype == st_seq ||
  1365. (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) {
  1366. hba->extra_offset = hba->dma_size;
  1367. hba->dma_size += ST_ADDITIONAL_MEM;
  1368. }
  1369. hba->dma_mem = dma_alloc_coherent(&pdev->dev,
  1370. hba->dma_size, &hba->dma_handle, GFP_KERNEL);
  1371. if (!hba->dma_mem) {
  1372. /* Retry minimum coherent mapping for st_seq and st_vsc */
  1373. if (hba->cardtype == st_seq ||
  1374. (hba->cardtype == st_vsc && (pdev->subsystem_device & 1))) {
  1375. printk(KERN_WARNING DRV_NAME
  1376. "(%s): allocating min buffer for controller\n",
  1377. pci_name(pdev));
  1378. hba->dma_size = hba->extra_offset
  1379. + ST_ADDITIONAL_MEM_MIN;
  1380. hba->dma_mem = dma_alloc_coherent(&pdev->dev,
  1381. hba->dma_size, &hba->dma_handle, GFP_KERNEL);
  1382. }
  1383. if (!hba->dma_mem) {
  1384. err = -ENOMEM;
  1385. printk(KERN_ERR DRV_NAME "(%s): dma mem alloc failed\n",
  1386. pci_name(pdev));
  1387. goto out_iounmap;
  1388. }
  1389. }
  1390. hba->ccb = kcalloc(ci->rq_count, sizeof(struct st_ccb), GFP_KERNEL);
  1391. if (!hba->ccb) {
  1392. err = -ENOMEM;
  1393. printk(KERN_ERR DRV_NAME "(%s): ccb alloc failed\n",
  1394. pci_name(pdev));
  1395. goto out_pci_free;
  1396. }
  1397. if (hba->cardtype == st_yel)
  1398. hba->scratch = (__le32 *)(hba->dma_mem + scratch_offset);
  1399. hba->status_buffer = (struct status_msg *)(hba->dma_mem + sts_offset);
  1400. hba->copy_buffer = hba->dma_mem + cp_offset;
  1401. hba->rq_count = ci->rq_count;
  1402. hba->rq_size = ci->rq_size;
  1403. hba->sts_count = ci->sts_count;
  1404. hba->alloc_rq = ci->alloc_rq;
  1405. hba->map_sg = ci->map_sg;
  1406. hba->send = ci->send;
  1407. hba->mu_status = MU_STATE_STARTING;
  1408. if (hba->cardtype == st_yel)
  1409. host->sg_tablesize = 38;
  1410. else
  1411. host->sg_tablesize = 32;
  1412. host->can_queue = ci->rq_count;
  1413. host->cmd_per_lun = ci->rq_count;
  1414. host->max_id = ci->max_id;
  1415. host->max_lun = ci->max_lun;
  1416. host->max_channel = ci->max_channel;
  1417. host->unique_id = host->host_no;
  1418. host->max_cmd_len = STEX_CDB_LENGTH;
  1419. hba->host = host;
  1420. hba->pdev = pdev;
  1421. init_waitqueue_head(&hba->reset_waitq);
  1422. snprintf(hba->work_q_name, sizeof(hba->work_q_name),
  1423. "stex_wq_%d", host->host_no);
  1424. hba->work_q = create_singlethread_workqueue(hba->work_q_name);
  1425. if (!hba->work_q) {
  1426. printk(KERN_ERR DRV_NAME "(%s): create workqueue failed\n",
  1427. pci_name(pdev));
  1428. err = -ENOMEM;
  1429. goto out_ccb_free;
  1430. }
  1431. INIT_WORK(&hba->reset_work, stex_reset_work);
  1432. err = stex_request_irq(hba);
  1433. if (err) {
  1434. printk(KERN_ERR DRV_NAME "(%s): request irq failed\n",
  1435. pci_name(pdev));
  1436. goto out_free_wq;
  1437. }
  1438. err = stex_handshake(hba);
  1439. if (err)
  1440. goto out_free_irq;
  1441. err = scsi_init_shared_tag_map(host, host->can_queue);
  1442. if (err) {
  1443. printk(KERN_ERR DRV_NAME "(%s): init shared queue failed\n",
  1444. pci_name(pdev));
  1445. goto out_free_irq;
  1446. }
  1447. pci_set_drvdata(pdev, hba);
  1448. err = scsi_add_host(host, &pdev->dev);
  1449. if (err) {
  1450. printk(KERN_ERR DRV_NAME "(%s): scsi_add_host failed\n",
  1451. pci_name(pdev));
  1452. goto out_free_irq;
  1453. }
  1454. scsi_scan_host(host);
  1455. return 0;
  1456. out_free_irq:
  1457. stex_free_irq(hba);
  1458. out_free_wq:
  1459. destroy_workqueue(hba->work_q);
  1460. out_ccb_free:
  1461. kfree(hba->ccb);
  1462. out_pci_free:
  1463. dma_free_coherent(&pdev->dev, hba->dma_size,
  1464. hba->dma_mem, hba->dma_handle);
  1465. out_iounmap:
  1466. iounmap(hba->mmio_base);
  1467. out_release_regions:
  1468. pci_release_regions(pdev);
  1469. out_scsi_host_put:
  1470. scsi_host_put(host);
  1471. out_disable:
  1472. pci_disable_device(pdev);
  1473. return err;
  1474. }
  1475. static void stex_hba_stop(struct st_hba *hba)
  1476. {
  1477. struct req_msg *req;
  1478. struct st_msg_header *msg_h;
  1479. unsigned long flags;
  1480. unsigned long before;
  1481. u16 tag = 0;
  1482. spin_lock_irqsave(hba->host->host_lock, flags);
  1483. req = hba->alloc_rq(hba);
  1484. if (hba->cardtype == st_yel) {
  1485. msg_h = (struct st_msg_header *)req - 1;
  1486. memset(msg_h, 0, hba->rq_size);
  1487. } else
  1488. memset(req, 0, hba->rq_size);
  1489. if (hba->cardtype == st_yosemite || hba->cardtype == st_yel) {
  1490. req->cdb[0] = MGT_CMD;
  1491. req->cdb[1] = MGT_CMD_SIGNATURE;
  1492. req->cdb[2] = CTLR_CONFIG_CMD;
  1493. req->cdb[3] = CTLR_SHUTDOWN;
  1494. } else {
  1495. req->cdb[0] = CONTROLLER_CMD;
  1496. req->cdb[1] = CTLR_POWER_STATE_CHANGE;
  1497. req->cdb[2] = CTLR_POWER_SAVING;
  1498. }
  1499. hba->ccb[tag].cmd = NULL;
  1500. hba->ccb[tag].sg_count = 0;
  1501. hba->ccb[tag].sense_bufflen = 0;
  1502. hba->ccb[tag].sense_buffer = NULL;
  1503. hba->ccb[tag].req_type = PASSTHRU_REQ_TYPE;
  1504. hba->send(hba, req, tag);
  1505. spin_unlock_irqrestore(hba->host->host_lock, flags);
  1506. before = jiffies;
  1507. while (hba->ccb[tag].req_type & PASSTHRU_REQ_TYPE) {
  1508. if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) {
  1509. hba->ccb[tag].req_type = 0;
  1510. return;
  1511. }
  1512. msleep(1);
  1513. }
  1514. }
  1515. static void stex_hba_free(struct st_hba *hba)
  1516. {
  1517. stex_free_irq(hba);
  1518. destroy_workqueue(hba->work_q);
  1519. iounmap(hba->mmio_base);
  1520. pci_release_regions(hba->pdev);
  1521. kfree(hba->ccb);
  1522. dma_free_coherent(&hba->pdev->dev, hba->dma_size,
  1523. hba->dma_mem, hba->dma_handle);
  1524. }
  1525. static void stex_remove(struct pci_dev *pdev)
  1526. {
  1527. struct st_hba *hba = pci_get_drvdata(pdev);
  1528. scsi_remove_host(hba->host);
  1529. pci_set_drvdata(pdev, NULL);
  1530. stex_hba_stop(hba);
  1531. stex_hba_free(hba);
  1532. scsi_host_put(hba->host);
  1533. pci_disable_device(pdev);
  1534. }
  1535. static void stex_shutdown(struct pci_dev *pdev)
  1536. {
  1537. struct st_hba *hba = pci_get_drvdata(pdev);
  1538. stex_hba_stop(hba);
  1539. }
  1540. MODULE_DEVICE_TABLE(pci, stex_pci_tbl);
  1541. static struct pci_driver stex_pci_driver = {
  1542. .name = DRV_NAME,
  1543. .id_table = stex_pci_tbl,
  1544. .probe = stex_probe,
  1545. .remove = __devexit_p(stex_remove),
  1546. .shutdown = stex_shutdown,
  1547. };
  1548. static int __init stex_init(void)
  1549. {
  1550. printk(KERN_INFO DRV_NAME
  1551. ": Promise SuperTrak EX Driver version: %s\n",
  1552. ST_DRIVER_VERSION);
  1553. return pci_register_driver(&stex_pci_driver);
  1554. }
  1555. static void __exit stex_exit(void)
  1556. {
  1557. pci_unregister_driver(&stex_pci_driver);
  1558. }
  1559. module_init(stex_init);
  1560. module_exit(stex_exit);