stex.c 43 KB

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