stex.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. /*
  2. * SuperTrak EX Series Storage Controller driver for Linux
  3. *
  4. * Copyright (C) 2005, 2006 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. * Version: 2.9.0.13
  15. *
  16. */
  17. #include <linux/init.h>
  18. #include <linux/errno.h>
  19. #include <linux/kernel.h>
  20. #include <linux/delay.h>
  21. #include <linux/sched.h>
  22. #include <linux/time.h>
  23. #include <linux/pci.h>
  24. #include <linux/blkdev.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/types.h>
  27. #include <linux/module.h>
  28. #include <linux/spinlock.h>
  29. #include <asm/io.h>
  30. #include <asm/irq.h>
  31. #include <asm/byteorder.h>
  32. #include <scsi/scsi.h>
  33. #include <scsi/scsi_device.h>
  34. #include <scsi/scsi_cmnd.h>
  35. #include <scsi/scsi_host.h>
  36. #include <scsi/scsi_tcq.h>
  37. #define DRV_NAME "stex"
  38. #define ST_DRIVER_VERSION "2.9.0.13"
  39. #define ST_VER_MAJOR 2
  40. #define ST_VER_MINOR 9
  41. #define ST_OEM 0
  42. #define ST_BUILD_VER 13
  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. /* MU register value */
  56. MU_INBOUND_DOORBELL_HANDSHAKE = 1,
  57. MU_INBOUND_DOORBELL_REQHEADCHANGED = 2,
  58. MU_INBOUND_DOORBELL_STATUSTAILCHANGED = 4,
  59. MU_INBOUND_DOORBELL_HMUSTOPPED = 8,
  60. MU_INBOUND_DOORBELL_RESET = 16,
  61. MU_OUTBOUND_DOORBELL_HANDSHAKE = 1,
  62. MU_OUTBOUND_DOORBELL_REQUESTTAILCHANGED = 2,
  63. MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED = 4,
  64. MU_OUTBOUND_DOORBELL_BUSCHANGE = 8,
  65. MU_OUTBOUND_DOORBELL_HASEVENT = 16,
  66. /* MU status code */
  67. MU_STATE_STARTING = 1,
  68. MU_STATE_FMU_READY_FOR_HANDSHAKE = 2,
  69. MU_STATE_SEND_HANDSHAKE_FRAME = 3,
  70. MU_STATE_STARTED = 4,
  71. MU_STATE_RESETTING = 5,
  72. MU_MAX_DELAY_TIME = 240000,
  73. MU_HANDSHAKE_SIGNATURE = 0x55aaaa55,
  74. HMU_PARTNER_TYPE = 2,
  75. /* firmware returned values */
  76. SRB_STATUS_SUCCESS = 0x01,
  77. SRB_STATUS_ERROR = 0x04,
  78. SRB_STATUS_BUSY = 0x05,
  79. SRB_STATUS_INVALID_REQUEST = 0x06,
  80. SRB_STATUS_SELECTION_TIMEOUT = 0x0A,
  81. SRB_SEE_SENSE = 0x80,
  82. /* task attribute */
  83. TASK_ATTRIBUTE_SIMPLE = 0x0,
  84. TASK_ATTRIBUTE_HEADOFQUEUE = 0x1,
  85. TASK_ATTRIBUTE_ORDERED = 0x2,
  86. TASK_ATTRIBUTE_ACA = 0x4,
  87. /* request count, etc. */
  88. MU_MAX_REQUEST = 32,
  89. /* one message wasted, use MU_MAX_REQUEST+1
  90. to handle MU_MAX_REQUEST messages */
  91. MU_REQ_COUNT = (MU_MAX_REQUEST + 1),
  92. MU_STATUS_COUNT = (MU_MAX_REQUEST + 1),
  93. STEX_CDB_LENGTH = MAX_COMMAND_SIZE,
  94. REQ_VARIABLE_LEN = 1024,
  95. STATUS_VAR_LEN = 128,
  96. ST_CAN_QUEUE = MU_MAX_REQUEST,
  97. ST_CMD_PER_LUN = MU_MAX_REQUEST,
  98. ST_MAX_SG = 32,
  99. /* sg flags */
  100. SG_CF_EOT = 0x80, /* end of table */
  101. SG_CF_64B = 0x40, /* 64 bit item */
  102. SG_CF_HOST = 0x20, /* sg in host memory */
  103. ST_MAX_ARRAY_SUPPORTED = 16,
  104. ST_MAX_TARGET_NUM = (ST_MAX_ARRAY_SUPPORTED+1),
  105. ST_MAX_LUN_PER_TARGET = 16,
  106. st_shasta = 0,
  107. st_vsc = 1,
  108. PASSTHRU_REQ_TYPE = 0x00000001,
  109. PASSTHRU_REQ_NO_WAKEUP = 0x00000100,
  110. ST_INTERNAL_TIMEOUT = 30,
  111. /* vendor specific commands of Promise */
  112. ARRAY_CMD = 0xe0,
  113. CONTROLLER_CMD = 0xe1,
  114. DEBUGGING_CMD = 0xe2,
  115. PASSTHRU_CMD = 0xe3,
  116. PASSTHRU_GET_ADAPTER = 0x05,
  117. PASSTHRU_GET_DRVVER = 0x10,
  118. CTLR_POWER_STATE_CHANGE = 0x0e,
  119. CTLR_POWER_SAVING = 0x01,
  120. PASSTHRU_SIGNATURE = 0x4e415041,
  121. INQUIRY_EVPD = 0x01,
  122. };
  123. struct st_sgitem {
  124. u8 ctrl; /* SG_CF_xxx */
  125. u8 reserved[3];
  126. __le32 count;
  127. __le32 addr;
  128. __le32 addr_hi;
  129. };
  130. struct st_sgtable {
  131. __le16 sg_count;
  132. __le16 max_sg_count;
  133. __le32 sz_in_byte;
  134. struct st_sgitem table[ST_MAX_SG];
  135. };
  136. struct handshake_frame {
  137. __le32 rb_phy; /* request payload queue physical address */
  138. __le32 rb_phy_hi;
  139. __le16 req_sz; /* size of each request payload */
  140. __le16 req_cnt; /* count of reqs the buffer can hold */
  141. __le16 status_sz; /* size of each status payload */
  142. __le16 status_cnt; /* count of status the buffer can hold */
  143. __le32 hosttime; /* seconds from Jan 1, 1970 (GMT) */
  144. __le32 hosttime_hi;
  145. u8 partner_type; /* who sends this frame */
  146. u8 reserved0[7];
  147. __le32 partner_ver_major;
  148. __le32 partner_ver_minor;
  149. __le32 partner_ver_oem;
  150. __le32 partner_ver_build;
  151. u32 reserved1[4];
  152. };
  153. struct req_msg {
  154. __le16 tag;
  155. u8 lun;
  156. u8 target;
  157. u8 task_attr;
  158. u8 task_manage;
  159. u8 prd_entry;
  160. u8 payload_sz; /* payload size in 4-byte */
  161. u8 cdb[STEX_CDB_LENGTH];
  162. u8 variable[REQ_VARIABLE_LEN];
  163. };
  164. struct status_msg {
  165. __le16 tag;
  166. u8 lun;
  167. u8 target;
  168. u8 srb_status;
  169. u8 scsi_status;
  170. u8 reserved;
  171. u8 payload_sz; /* payload size in 4-byte */
  172. u8 variable[STATUS_VAR_LEN];
  173. };
  174. struct ver_info {
  175. u32 major;
  176. u32 minor;
  177. u32 oem;
  178. u32 build;
  179. u32 reserved[2];
  180. };
  181. struct st_frame {
  182. u32 base[6];
  183. u32 rom_addr;
  184. struct ver_info drv_ver;
  185. struct ver_info bios_ver;
  186. u32 bus;
  187. u32 slot;
  188. u32 irq_level;
  189. u32 irq_vec;
  190. u32 id;
  191. u32 subid;
  192. u32 dimm_size;
  193. u8 dimm_type;
  194. u8 reserved[3];
  195. u32 channel;
  196. u32 reserved1;
  197. };
  198. struct st_drvver {
  199. u32 major;
  200. u32 minor;
  201. u32 oem;
  202. u32 build;
  203. u32 signature[2];
  204. u8 console_id;
  205. u8 host_no;
  206. u8 reserved0[2];
  207. u32 reserved[3];
  208. };
  209. #define MU_REQ_BUFFER_SIZE (MU_REQ_COUNT * sizeof(struct req_msg))
  210. #define MU_STATUS_BUFFER_SIZE (MU_STATUS_COUNT * sizeof(struct status_msg))
  211. #define MU_BUFFER_SIZE (MU_REQ_BUFFER_SIZE + MU_STATUS_BUFFER_SIZE)
  212. #define STEX_BUFFER_SIZE (MU_BUFFER_SIZE + sizeof(struct st_frame))
  213. struct st_ccb {
  214. struct req_msg *req;
  215. struct scsi_cmnd *cmd;
  216. void *sense_buffer;
  217. unsigned int sense_bufflen;
  218. int sg_count;
  219. u32 req_type;
  220. u8 srb_status;
  221. u8 scsi_status;
  222. };
  223. struct st_hba {
  224. void __iomem *mmio_base; /* iomapped PCI memory space */
  225. void *dma_mem;
  226. dma_addr_t dma_handle;
  227. struct Scsi_Host *host;
  228. struct pci_dev *pdev;
  229. u32 req_head;
  230. u32 req_tail;
  231. u32 status_head;
  232. u32 status_tail;
  233. struct status_msg *status_buffer;
  234. void *copy_buffer; /* temp buffer for driver-handled commands */
  235. struct st_ccb ccb[MU_MAX_REQUEST];
  236. struct st_ccb *wait_ccb;
  237. wait_queue_head_t waitq;
  238. unsigned int mu_status;
  239. int out_req_cnt;
  240. unsigned int cardtype;
  241. };
  242. static const char console_inq_page[] =
  243. {
  244. 0x03,0x00,0x03,0x03,0xFA,0x00,0x00,0x30,
  245. 0x50,0x72,0x6F,0x6D,0x69,0x73,0x65,0x20, /* "Promise " */
  246. 0x52,0x41,0x49,0x44,0x20,0x43,0x6F,0x6E, /* "RAID Con" */
  247. 0x73,0x6F,0x6C,0x65,0x20,0x20,0x20,0x20, /* "sole " */
  248. 0x31,0x2E,0x30,0x30,0x20,0x20,0x20,0x20, /* "1.00 " */
  249. 0x53,0x58,0x2F,0x52,0x53,0x41,0x46,0x2D, /* "SX/RSAF-" */
  250. 0x54,0x45,0x31,0x2E,0x30,0x30,0x20,0x20, /* "TE1.00 " */
  251. 0x0C,0x20,0x20,0x20,0x20,0x20,0x20,0x20
  252. };
  253. MODULE_AUTHOR("Ed Lin");
  254. MODULE_DESCRIPTION("Promise Technology SuperTrak EX Controllers");
  255. MODULE_LICENSE("GPL");
  256. MODULE_VERSION(ST_DRIVER_VERSION);
  257. static void stex_gettime(__le32 *time)
  258. {
  259. struct timeval tv;
  260. do_gettimeofday(&tv);
  261. *time = cpu_to_le32(tv.tv_sec & 0xffffffff);
  262. *(time + 1) = cpu_to_le32((tv.tv_sec >> 16) >> 16);
  263. }
  264. static struct status_msg *stex_get_status(struct st_hba *hba)
  265. {
  266. struct status_msg *status =
  267. hba->status_buffer + hba->status_tail;
  268. ++hba->status_tail;
  269. hba->status_tail %= MU_STATUS_COUNT;
  270. return status;
  271. }
  272. static void stex_set_sense(struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq)
  273. {
  274. cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
  275. cmd->sense_buffer[0] = 0x70; /* fixed format, current */
  276. cmd->sense_buffer[2] = sk;
  277. cmd->sense_buffer[7] = 18 - 8; /* additional sense length */
  278. cmd->sense_buffer[12] = asc;
  279. cmd->sense_buffer[13] = ascq;
  280. }
  281. static void stex_invalid_field(struct scsi_cmnd *cmd,
  282. void (*done)(struct scsi_cmnd *))
  283. {
  284. /* "Invalid field in cbd" */
  285. stex_set_sense(cmd, ILLEGAL_REQUEST, 0x24, 0x0);
  286. done(cmd);
  287. }
  288. static struct req_msg *stex_alloc_req(struct st_hba *hba)
  289. {
  290. struct req_msg *req = ((struct req_msg *)hba->dma_mem) +
  291. hba->req_head;
  292. ++hba->req_head;
  293. hba->req_head %= MU_REQ_COUNT;
  294. return req;
  295. }
  296. static int stex_map_sg(struct st_hba *hba,
  297. struct req_msg *req, struct st_ccb *ccb)
  298. {
  299. struct pci_dev *pdev = hba->pdev;
  300. struct scsi_cmnd *cmd;
  301. dma_addr_t dma_handle;
  302. struct scatterlist *src;
  303. struct st_sgtable *dst;
  304. int i;
  305. cmd = ccb->cmd;
  306. dst = (struct st_sgtable *)req->variable;
  307. dst->max_sg_count = cpu_to_le16(ST_MAX_SG);
  308. dst->sz_in_byte = cpu_to_le32(cmd->request_bufflen);
  309. if (cmd->use_sg) {
  310. int n_elem;
  311. src = (struct scatterlist *) cmd->request_buffer;
  312. n_elem = pci_map_sg(pdev, src,
  313. cmd->use_sg, cmd->sc_data_direction);
  314. if (n_elem <= 0)
  315. return -EIO;
  316. ccb->sg_count = n_elem;
  317. dst->sg_count = cpu_to_le16((u16)n_elem);
  318. for (i = 0; i < n_elem; i++, src++) {
  319. dst->table[i].count = cpu_to_le32((u32)sg_dma_len(src));
  320. dst->table[i].addr =
  321. cpu_to_le32(sg_dma_address(src) & 0xffffffff);
  322. dst->table[i].addr_hi =
  323. cpu_to_le32((sg_dma_address(src) >> 16) >> 16);
  324. dst->table[i].ctrl = SG_CF_64B | SG_CF_HOST;
  325. }
  326. dst->table[--i].ctrl |= SG_CF_EOT;
  327. return 0;
  328. }
  329. dma_handle = pci_map_single(pdev, cmd->request_buffer,
  330. cmd->request_bufflen, cmd->sc_data_direction);
  331. cmd->SCp.dma_handle = dma_handle;
  332. ccb->sg_count = 1;
  333. dst->sg_count = cpu_to_le16(1);
  334. dst->table[0].addr = cpu_to_le32(dma_handle & 0xffffffff);
  335. dst->table[0].addr_hi = cpu_to_le32((dma_handle >> 16) >> 16);
  336. dst->table[0].count = cpu_to_le32((u32)cmd->request_bufflen);
  337. dst->table[0].ctrl = SG_CF_EOT | SG_CF_64B | SG_CF_HOST;
  338. return 0;
  339. }
  340. static void stex_internal_copy(struct scsi_cmnd *cmd,
  341. const void *src, size_t *count, int sg_count)
  342. {
  343. size_t lcount;
  344. size_t len;
  345. void *s, *d, *base = NULL;
  346. if (*count > cmd->request_bufflen)
  347. *count = cmd->request_bufflen;
  348. lcount = *count;
  349. while (lcount) {
  350. len = lcount;
  351. s = (void *)src;
  352. if (cmd->use_sg) {
  353. size_t offset = *count - lcount;
  354. s += offset;
  355. base = scsi_kmap_atomic_sg(cmd->request_buffer,
  356. sg_count, &offset, &len);
  357. if (base == NULL) {
  358. *count -= lcount;
  359. return;
  360. }
  361. d = base + offset;
  362. } else
  363. d = cmd->request_buffer;
  364. memcpy(d, s, len);
  365. lcount -= len;
  366. if (cmd->use_sg)
  367. scsi_kunmap_atomic_sg(base);
  368. }
  369. }
  370. static int stex_direct_copy(struct scsi_cmnd *cmd,
  371. const void *src, size_t count)
  372. {
  373. struct st_hba *hba = (struct st_hba *) &cmd->device->host->hostdata[0];
  374. size_t cp_len = count;
  375. int n_elem = 0;
  376. if (cmd->use_sg) {
  377. n_elem = pci_map_sg(hba->pdev, cmd->request_buffer,
  378. cmd->use_sg, cmd->sc_data_direction);
  379. if (n_elem <= 0)
  380. return 0;
  381. }
  382. stex_internal_copy(cmd, src, &cp_len, n_elem);
  383. if (cmd->use_sg)
  384. pci_unmap_sg(hba->pdev, cmd->request_buffer,
  385. cmd->use_sg, cmd->sc_data_direction);
  386. return cp_len == count;
  387. }
  388. static void stex_controller_info(struct st_hba *hba, struct st_ccb *ccb)
  389. {
  390. struct st_frame *p;
  391. size_t count = sizeof(struct st_frame);
  392. p = hba->copy_buffer;
  393. memset(p->base, 0, sizeof(u32)*6);
  394. *(unsigned long *)(p->base) = pci_resource_start(hba->pdev, 0);
  395. p->rom_addr = 0;
  396. p->drv_ver.major = ST_VER_MAJOR;
  397. p->drv_ver.minor = ST_VER_MINOR;
  398. p->drv_ver.oem = ST_OEM;
  399. p->drv_ver.build = ST_BUILD_VER;
  400. p->bus = hba->pdev->bus->number;
  401. p->slot = hba->pdev->devfn;
  402. p->irq_level = 0;
  403. p->irq_vec = hba->pdev->irq;
  404. p->id = hba->pdev->vendor << 16 | hba->pdev->device;
  405. p->subid =
  406. hba->pdev->subsystem_vendor << 16 | hba->pdev->subsystem_device;
  407. stex_internal_copy(ccb->cmd, p, &count, ccb->sg_count);
  408. }
  409. static void
  410. stex_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
  411. {
  412. req->tag = cpu_to_le16(tag);
  413. req->task_attr = TASK_ATTRIBUTE_SIMPLE;
  414. req->task_manage = 0; /* not supported yet */
  415. req->payload_sz = (u8)(sizeof(struct req_msg)/sizeof(u32));
  416. hba->ccb[tag].req = req;
  417. hba->out_req_cnt++;
  418. writel(hba->req_head, hba->mmio_base + IMR0);
  419. writel(MU_INBOUND_DOORBELL_REQHEADCHANGED, hba->mmio_base + IDBL);
  420. readl(hba->mmio_base + IDBL); /* flush */
  421. }
  422. static int
  423. stex_slave_alloc(struct scsi_device *sdev)
  424. {
  425. /* Cheat: usually extracted from Inquiry data */
  426. sdev->tagged_supported = 1;
  427. scsi_activate_tcq(sdev, sdev->host->can_queue);
  428. return 0;
  429. }
  430. static int
  431. stex_slave_config(struct scsi_device *sdev)
  432. {
  433. sdev->use_10_for_rw = 1;
  434. sdev->use_10_for_ms = 1;
  435. sdev->timeout = 60 * HZ;
  436. sdev->tagged_supported = 1;
  437. return 0;
  438. }
  439. static void
  440. stex_slave_destroy(struct scsi_device *sdev)
  441. {
  442. scsi_deactivate_tcq(sdev, 1);
  443. }
  444. static int
  445. stex_queuecommand(struct scsi_cmnd *cmd, void (* done)(struct scsi_cmnd *))
  446. {
  447. struct st_hba *hba;
  448. struct Scsi_Host *host;
  449. unsigned int id,lun;
  450. struct req_msg *req;
  451. u16 tag;
  452. host = cmd->device->host;
  453. id = cmd->device->id;
  454. lun = cmd->device->channel; /* firmware lun issue work around */
  455. hba = (struct st_hba *) &host->hostdata[0];
  456. switch (cmd->cmnd[0]) {
  457. case MODE_SENSE_10:
  458. {
  459. static char ms10_caching_page[12] =
  460. { 0, 0x12, 0, 0, 0, 0, 0, 0, 0x8, 0xa, 0x4, 0 };
  461. unsigned char page;
  462. page = cmd->cmnd[2] & 0x3f;
  463. if (page == 0x8 || page == 0x3f) {
  464. stex_direct_copy(cmd, ms10_caching_page,
  465. sizeof(ms10_caching_page));
  466. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  467. done(cmd);
  468. } else
  469. stex_invalid_field(cmd, done);
  470. return 0;
  471. }
  472. case INQUIRY:
  473. if (id != ST_MAX_ARRAY_SUPPORTED)
  474. break;
  475. if (lun == 0 && (cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
  476. stex_direct_copy(cmd, console_inq_page,
  477. sizeof(console_inq_page));
  478. cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
  479. done(cmd);
  480. } else
  481. stex_invalid_field(cmd, done);
  482. return 0;
  483. case PASSTHRU_CMD:
  484. if (cmd->cmnd[1] == PASSTHRU_GET_DRVVER) {
  485. struct st_drvver ver;
  486. ver.major = ST_VER_MAJOR;
  487. ver.minor = ST_VER_MINOR;
  488. ver.oem = ST_OEM;
  489. ver.build = ST_BUILD_VER;
  490. ver.signature[0] = PASSTHRU_SIGNATURE;
  491. ver.console_id = ST_MAX_ARRAY_SUPPORTED;
  492. ver.host_no = hba->host->host_no;
  493. cmd->result = stex_direct_copy(cmd, &ver, sizeof(ver)) ?
  494. DID_OK << 16 | COMMAND_COMPLETE << 8 :
  495. DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  496. done(cmd);
  497. return 0;
  498. }
  499. default:
  500. break;
  501. }
  502. cmd->scsi_done = done;
  503. tag = cmd->request->tag;
  504. if (unlikely(tag >= host->can_queue))
  505. return SCSI_MLQUEUE_HOST_BUSY;
  506. req = stex_alloc_req(hba);
  507. req->lun = lun;
  508. req->target = id;
  509. /* cdb */
  510. memcpy(req->cdb, cmd->cmnd, STEX_CDB_LENGTH);
  511. hba->ccb[tag].cmd = cmd;
  512. hba->ccb[tag].sense_bufflen = SCSI_SENSE_BUFFERSIZE;
  513. hba->ccb[tag].sense_buffer = cmd->sense_buffer;
  514. hba->ccb[tag].req_type = 0;
  515. if (cmd->sc_data_direction != DMA_NONE)
  516. stex_map_sg(hba, req, &hba->ccb[tag]);
  517. stex_send_cmd(hba, req, tag);
  518. return 0;
  519. }
  520. static void stex_unmap_sg(struct st_hba *hba, struct scsi_cmnd *cmd)
  521. {
  522. if (cmd->sc_data_direction != DMA_NONE) {
  523. if (cmd->use_sg)
  524. pci_unmap_sg(hba->pdev, cmd->request_buffer,
  525. cmd->use_sg, cmd->sc_data_direction);
  526. else
  527. pci_unmap_single(hba->pdev, cmd->SCp.dma_handle,
  528. cmd->request_bufflen, cmd->sc_data_direction);
  529. }
  530. }
  531. static void stex_scsi_done(struct st_ccb *ccb)
  532. {
  533. struct scsi_cmnd *cmd = ccb->cmd;
  534. int result;
  535. if (ccb->srb_status == SRB_STATUS_SUCCESS || ccb->srb_status == 0) {
  536. result = ccb->scsi_status;
  537. switch (ccb->scsi_status) {
  538. case SAM_STAT_GOOD:
  539. result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
  540. break;
  541. case SAM_STAT_CHECK_CONDITION:
  542. result |= DRIVER_SENSE << 24;
  543. break;
  544. case SAM_STAT_BUSY:
  545. result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
  546. break;
  547. default:
  548. result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  549. break;
  550. }
  551. }
  552. else if (ccb->srb_status & SRB_SEE_SENSE)
  553. result = DRIVER_SENSE << 24 | SAM_STAT_CHECK_CONDITION;
  554. else switch (ccb->srb_status) {
  555. case SRB_STATUS_SELECTION_TIMEOUT:
  556. result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
  557. break;
  558. case SRB_STATUS_BUSY:
  559. result = DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
  560. break;
  561. case SRB_STATUS_INVALID_REQUEST:
  562. case SRB_STATUS_ERROR:
  563. default:
  564. result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
  565. break;
  566. }
  567. cmd->result = result;
  568. cmd->scsi_done(cmd);
  569. }
  570. static void stex_copy_data(struct st_ccb *ccb,
  571. struct status_msg *resp, unsigned int variable)
  572. {
  573. size_t count = variable;
  574. if (resp->scsi_status != SAM_STAT_GOOD) {
  575. if (ccb->sense_buffer != NULL)
  576. memcpy(ccb->sense_buffer, resp->variable,
  577. min(variable, ccb->sense_bufflen));
  578. return;
  579. }
  580. if (ccb->cmd == NULL)
  581. return;
  582. stex_internal_copy(ccb->cmd, resp->variable, &count, ccb->sg_count);
  583. }
  584. static void stex_mu_intr(struct st_hba *hba, u32 doorbell)
  585. {
  586. void __iomem *base = hba->mmio_base;
  587. struct status_msg *resp;
  588. struct st_ccb *ccb;
  589. unsigned int size;
  590. u16 tag;
  591. if (!(doorbell & MU_OUTBOUND_DOORBELL_STATUSHEADCHANGED))
  592. return;
  593. /* status payloads */
  594. hba->status_head = readl(base + OMR1);
  595. if (unlikely(hba->status_head >= MU_STATUS_COUNT)) {
  596. printk(KERN_WARNING DRV_NAME "(%s): invalid status head\n",
  597. pci_name(hba->pdev));
  598. return;
  599. }
  600. if (unlikely(hba->mu_status != MU_STATE_STARTED ||
  601. hba->out_req_cnt <= 0)) {
  602. hba->status_tail = hba->status_head;
  603. goto update_status;
  604. }
  605. while (hba->status_tail != hba->status_head) {
  606. resp = stex_get_status(hba);
  607. tag = le16_to_cpu(resp->tag);
  608. if (unlikely(tag >= hba->host->can_queue)) {
  609. printk(KERN_WARNING DRV_NAME
  610. "(%s): invalid tag\n", pci_name(hba->pdev));
  611. continue;
  612. }
  613. ccb = &hba->ccb[tag];
  614. if (hba->wait_ccb == ccb)
  615. hba->wait_ccb = NULL;
  616. if (unlikely(ccb->req == NULL)) {
  617. printk(KERN_WARNING DRV_NAME
  618. "(%s): lagging req\n", pci_name(hba->pdev));
  619. continue;
  620. }
  621. size = resp->payload_sz * sizeof(u32); /* payload size */
  622. if (unlikely(size < sizeof(*resp) - STATUS_VAR_LEN ||
  623. size > sizeof(*resp))) {
  624. printk(KERN_WARNING DRV_NAME "(%s): bad status size\n",
  625. pci_name(hba->pdev));
  626. } else {
  627. size -= sizeof(*resp) - STATUS_VAR_LEN; /* copy size */
  628. if (size)
  629. stex_copy_data(ccb, resp, size);
  630. }
  631. ccb->srb_status = resp->srb_status;
  632. ccb->scsi_status = resp->scsi_status;
  633. if (likely(ccb->cmd != NULL)) {
  634. if (unlikely(ccb->cmd->cmnd[0] == PASSTHRU_CMD &&
  635. ccb->cmd->cmnd[1] == PASSTHRU_GET_ADAPTER))
  636. stex_controller_info(hba, ccb);
  637. stex_unmap_sg(hba, ccb->cmd);
  638. stex_scsi_done(ccb);
  639. hba->out_req_cnt--;
  640. } else if (ccb->req_type & PASSTHRU_REQ_TYPE) {
  641. hba->out_req_cnt--;
  642. if (ccb->req_type & PASSTHRU_REQ_NO_WAKEUP) {
  643. ccb->req_type = 0;
  644. continue;
  645. }
  646. ccb->req_type = 0;
  647. if (waitqueue_active(&hba->waitq))
  648. wake_up(&hba->waitq);
  649. }
  650. }
  651. update_status:
  652. writel(hba->status_head, base + IMR1);
  653. readl(base + IMR1); /* flush */
  654. }
  655. static irqreturn_t stex_intr(int irq, void *__hba, struct pt_regs *regs)
  656. {
  657. struct st_hba *hba = __hba;
  658. void __iomem *base = hba->mmio_base;
  659. u32 data;
  660. unsigned long flags;
  661. int handled = 0;
  662. spin_lock_irqsave(hba->host->host_lock, flags);
  663. data = readl(base + ODBL);
  664. if (data && data != 0xffffffff) {
  665. /* clear the interrupt */
  666. writel(data, base + ODBL);
  667. readl(base + ODBL); /* flush */
  668. stex_mu_intr(hba, data);
  669. handled = 1;
  670. }
  671. spin_unlock_irqrestore(hba->host->host_lock, flags);
  672. return IRQ_RETVAL(handled);
  673. }
  674. static int stex_handshake(struct st_hba *hba)
  675. {
  676. void __iomem *base = hba->mmio_base;
  677. struct handshake_frame *h;
  678. dma_addr_t status_phys;
  679. int i;
  680. if (readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE) {
  681. writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
  682. readl(base + IDBL);
  683. for (i = 0; readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE
  684. && i < MU_MAX_DELAY_TIME; i++) {
  685. rmb();
  686. msleep(1);
  687. }
  688. if (i == MU_MAX_DELAY_TIME) {
  689. printk(KERN_ERR DRV_NAME
  690. "(%s): no handshake signature\n",
  691. pci_name(hba->pdev));
  692. return -1;
  693. }
  694. }
  695. udelay(10);
  696. h = (struct handshake_frame *)(hba->dma_mem + MU_REQ_BUFFER_SIZE);
  697. h->rb_phy = cpu_to_le32(hba->dma_handle);
  698. h->rb_phy_hi = cpu_to_le32((hba->dma_handle >> 16) >> 16);
  699. h->req_sz = cpu_to_le16(sizeof(struct req_msg));
  700. h->req_cnt = cpu_to_le16(MU_REQ_COUNT);
  701. h->status_sz = cpu_to_le16(sizeof(struct status_msg));
  702. h->status_cnt = cpu_to_le16(MU_STATUS_COUNT);
  703. stex_gettime(&h->hosttime);
  704. h->partner_type = HMU_PARTNER_TYPE;
  705. status_phys = hba->dma_handle + MU_REQ_BUFFER_SIZE;
  706. writel(status_phys, base + IMR0);
  707. readl(base + IMR0);
  708. writel((status_phys >> 16) >> 16, base + IMR1);
  709. readl(base + IMR1);
  710. writel((status_phys >> 16) >> 16, base + OMR0); /* old fw compatible */
  711. readl(base + OMR0);
  712. writel(MU_INBOUND_DOORBELL_HANDSHAKE, base + IDBL);
  713. readl(base + IDBL); /* flush */
  714. udelay(10);
  715. for (i = 0; readl(base + OMR0) != MU_HANDSHAKE_SIGNATURE
  716. && i < MU_MAX_DELAY_TIME; i++) {
  717. rmb();
  718. msleep(1);
  719. }
  720. if (i == MU_MAX_DELAY_TIME) {
  721. printk(KERN_ERR DRV_NAME
  722. "(%s): no signature after handshake frame\n",
  723. pci_name(hba->pdev));
  724. return -1;
  725. }
  726. writel(0, base + IMR0);
  727. readl(base + IMR0);
  728. writel(0, base + OMR0);
  729. readl(base + OMR0);
  730. writel(0, base + IMR1);
  731. readl(base + IMR1);
  732. writel(0, base + OMR1);
  733. readl(base + OMR1); /* flush */
  734. hba->mu_status = MU_STATE_STARTED;
  735. return 0;
  736. }
  737. static int stex_abort(struct scsi_cmnd *cmd)
  738. {
  739. struct Scsi_Host *host = cmd->device->host;
  740. struct st_hba *hba = (struct st_hba *)host->hostdata;
  741. u16 tag = cmd->request->tag;
  742. void __iomem *base;
  743. u32 data;
  744. int result = SUCCESS;
  745. unsigned long flags;
  746. base = hba->mmio_base;
  747. spin_lock_irqsave(host->host_lock, flags);
  748. if (tag < host->can_queue && hba->ccb[tag].cmd == cmd)
  749. hba->wait_ccb = &hba->ccb[tag];
  750. else {
  751. for (tag = 0; tag < host->can_queue; tag++)
  752. if (hba->ccb[tag].cmd == cmd) {
  753. hba->wait_ccb = &hba->ccb[tag];
  754. break;
  755. }
  756. if (tag >= host->can_queue)
  757. goto out;
  758. }
  759. data = readl(base + ODBL);
  760. if (data == 0 || data == 0xffffffff)
  761. goto fail_out;
  762. writel(data, base + ODBL);
  763. readl(base + ODBL); /* flush */
  764. stex_mu_intr(hba, data);
  765. if (hba->wait_ccb == NULL) {
  766. printk(KERN_WARNING DRV_NAME
  767. "(%s): lost interrupt\n", pci_name(hba->pdev));
  768. goto out;
  769. }
  770. fail_out:
  771. stex_unmap_sg(hba, cmd);
  772. hba->wait_ccb->req = NULL; /* nullify the req's future return */
  773. hba->wait_ccb = NULL;
  774. result = FAILED;
  775. out:
  776. spin_unlock_irqrestore(host->host_lock, flags);
  777. return result;
  778. }
  779. static void stex_hard_reset(struct st_hba *hba)
  780. {
  781. struct pci_bus *bus;
  782. int i;
  783. u16 pci_cmd;
  784. u8 pci_bctl;
  785. for (i = 0; i < 16; i++)
  786. pci_read_config_dword(hba->pdev, i * 4,
  787. &hba->pdev->saved_config_space[i]);
  788. /* Reset secondary bus. Our controller(MU/ATU) is the only device on
  789. secondary bus. Consult Intel 80331/3 developer's manual for detail */
  790. bus = hba->pdev->bus;
  791. pci_read_config_byte(bus->self, PCI_BRIDGE_CONTROL, &pci_bctl);
  792. pci_bctl |= PCI_BRIDGE_CTL_BUS_RESET;
  793. pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
  794. msleep(1);
  795. pci_bctl &= ~PCI_BRIDGE_CTL_BUS_RESET;
  796. pci_write_config_byte(bus->self, PCI_BRIDGE_CONTROL, pci_bctl);
  797. for (i = 0; i < MU_MAX_DELAY_TIME; i++) {
  798. pci_read_config_word(hba->pdev, PCI_COMMAND, &pci_cmd);
  799. if (pci_cmd & PCI_COMMAND_MASTER)
  800. break;
  801. msleep(1);
  802. }
  803. ssleep(5);
  804. for (i = 0; i < 16; i++)
  805. pci_write_config_dword(hba->pdev, i * 4,
  806. hba->pdev->saved_config_space[i]);
  807. }
  808. static int stex_reset(struct scsi_cmnd *cmd)
  809. {
  810. struct st_hba *hba;
  811. unsigned long flags;
  812. hba = (struct st_hba *) &cmd->device->host->hostdata[0];
  813. hba->mu_status = MU_STATE_RESETTING;
  814. if (hba->cardtype == st_shasta)
  815. stex_hard_reset(hba);
  816. if (stex_handshake(hba)) {
  817. printk(KERN_WARNING DRV_NAME
  818. "(%s): resetting: handshake failed\n",
  819. pci_name(hba->pdev));
  820. return FAILED;
  821. }
  822. spin_lock_irqsave(hba->host->host_lock, flags);
  823. hba->req_head = 0;
  824. hba->req_tail = 0;
  825. hba->status_head = 0;
  826. hba->status_tail = 0;
  827. hba->out_req_cnt = 0;
  828. spin_unlock_irqrestore(hba->host->host_lock, flags);
  829. return SUCCESS;
  830. }
  831. static int stex_biosparam(struct scsi_device *sdev,
  832. struct block_device *bdev, sector_t capacity, int geom[])
  833. {
  834. int heads = 255, sectors = 63, cylinders;
  835. if (capacity < 0x200000) {
  836. heads = 64;
  837. sectors = 32;
  838. }
  839. cylinders = sector_div(capacity, heads * sectors);
  840. geom[0] = heads;
  841. geom[1] = sectors;
  842. geom[2] = cylinders;
  843. return 0;
  844. }
  845. static struct scsi_host_template driver_template = {
  846. .module = THIS_MODULE,
  847. .name = DRV_NAME,
  848. .proc_name = DRV_NAME,
  849. .bios_param = stex_biosparam,
  850. .queuecommand = stex_queuecommand,
  851. .slave_alloc = stex_slave_alloc,
  852. .slave_configure = stex_slave_config,
  853. .slave_destroy = stex_slave_destroy,
  854. .eh_abort_handler = stex_abort,
  855. .eh_host_reset_handler = stex_reset,
  856. .can_queue = ST_CAN_QUEUE,
  857. .this_id = -1,
  858. .sg_tablesize = ST_MAX_SG,
  859. .cmd_per_lun = ST_CMD_PER_LUN,
  860. };
  861. static int stex_set_dma_mask(struct pci_dev * pdev)
  862. {
  863. int ret;
  864. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)
  865. && !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
  866. return 0;
  867. ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  868. if (!ret)
  869. ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  870. return ret;
  871. }
  872. static int __devinit
  873. stex_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  874. {
  875. struct st_hba *hba;
  876. struct Scsi_Host *host;
  877. int err;
  878. err = pci_enable_device(pdev);
  879. if (err)
  880. return err;
  881. pci_set_master(pdev);
  882. host = scsi_host_alloc(&driver_template, sizeof(struct st_hba));
  883. if (!host) {
  884. printk(KERN_ERR DRV_NAME "(%s): scsi_host_alloc failed\n",
  885. pci_name(pdev));
  886. err = -ENOMEM;
  887. goto out_disable;
  888. }
  889. hba = (struct st_hba *)host->hostdata;
  890. memset(hba, 0, sizeof(struct st_hba));
  891. err = pci_request_regions(pdev, DRV_NAME);
  892. if (err < 0) {
  893. printk(KERN_ERR DRV_NAME "(%s): request regions failed\n",
  894. pci_name(pdev));
  895. goto out_scsi_host_put;
  896. }
  897. hba->mmio_base = ioremap(pci_resource_start(pdev, 0),
  898. pci_resource_len(pdev, 0));
  899. if ( !hba->mmio_base) {
  900. printk(KERN_ERR DRV_NAME "(%s): memory map failed\n",
  901. pci_name(pdev));
  902. err = -ENOMEM;
  903. goto out_release_regions;
  904. }
  905. err = stex_set_dma_mask(pdev);
  906. if (err) {
  907. printk(KERN_ERR DRV_NAME "(%s): set dma mask failed\n",
  908. pci_name(pdev));
  909. goto out_iounmap;
  910. }
  911. hba->dma_mem = dma_alloc_coherent(&pdev->dev,
  912. STEX_BUFFER_SIZE, &hba->dma_handle, GFP_KERNEL);
  913. if (!hba->dma_mem) {
  914. err = -ENOMEM;
  915. printk(KERN_ERR DRV_NAME "(%s): dma mem alloc failed\n",
  916. pci_name(pdev));
  917. goto out_iounmap;
  918. }
  919. hba->status_buffer =
  920. (struct status_msg *)(hba->dma_mem + MU_REQ_BUFFER_SIZE);
  921. hba->copy_buffer = hba->dma_mem + MU_BUFFER_SIZE;
  922. hba->mu_status = MU_STATE_STARTING;
  923. hba->cardtype = (unsigned int) id->driver_data;
  924. /* firmware uses id/lun pair for a logical drive, but lun would be
  925. always 0 if CONFIG_SCSI_MULTI_LUN not configured, so we use
  926. channel to map lun here */
  927. host->max_channel = ST_MAX_LUN_PER_TARGET - 1;
  928. host->max_id = ST_MAX_TARGET_NUM;
  929. host->max_lun = 1;
  930. host->unique_id = host->host_no;
  931. host->max_cmd_len = STEX_CDB_LENGTH;
  932. hba->host = host;
  933. hba->pdev = pdev;
  934. init_waitqueue_head(&hba->waitq);
  935. err = request_irq(pdev->irq, stex_intr, IRQF_SHARED, DRV_NAME, hba);
  936. if (err) {
  937. printk(KERN_ERR DRV_NAME "(%s): request irq failed\n",
  938. pci_name(pdev));
  939. goto out_pci_free;
  940. }
  941. err = stex_handshake(hba);
  942. if (err)
  943. goto out_free_irq;
  944. scsi_init_shared_tag_map(host, ST_CAN_QUEUE);
  945. if (host->bqt == NULL) {
  946. err = -ENOMEM;
  947. printk(KERN_ERR DRV_NAME "(%s): init shared queue failed\n",
  948. pci_name(pdev));
  949. goto out_free_irq;
  950. }
  951. pci_set_drvdata(pdev, hba);
  952. err = scsi_add_host(host, &pdev->dev);
  953. if (err) {
  954. printk(KERN_ERR DRV_NAME "(%s): scsi_add_host failed\n",
  955. pci_name(pdev));
  956. goto out_free_irq;
  957. }
  958. scsi_scan_host(host);
  959. return 0;
  960. out_free_irq:
  961. free_irq(pdev->irq, hba);
  962. out_pci_free:
  963. dma_free_coherent(&pdev->dev, STEX_BUFFER_SIZE,
  964. hba->dma_mem, hba->dma_handle);
  965. out_iounmap:
  966. iounmap(hba->mmio_base);
  967. out_release_regions:
  968. pci_release_regions(pdev);
  969. out_scsi_host_put:
  970. scsi_host_put(host);
  971. out_disable:
  972. pci_disable_device(pdev);
  973. return err;
  974. }
  975. static void stex_hba_stop(struct st_hba *hba)
  976. {
  977. struct req_msg *req;
  978. unsigned long flags;
  979. unsigned long before;
  980. u16 tag = 0;
  981. spin_lock_irqsave(hba->host->host_lock, flags);
  982. req = stex_alloc_req(hba);
  983. memset(req->cdb, 0, STEX_CDB_LENGTH);
  984. req->cdb[0] = CONTROLLER_CMD;
  985. req->cdb[1] = CTLR_POWER_STATE_CHANGE;
  986. req->cdb[2] = CTLR_POWER_SAVING;
  987. hba->ccb[tag].cmd = NULL;
  988. hba->ccb[tag].sg_count = 0;
  989. hba->ccb[tag].sense_bufflen = 0;
  990. hba->ccb[tag].sense_buffer = NULL;
  991. hba->ccb[tag].req_type |= PASSTHRU_REQ_TYPE;
  992. stex_send_cmd(hba, req, tag);
  993. spin_unlock_irqrestore(hba->host->host_lock, flags);
  994. before = jiffies;
  995. while (hba->ccb[tag].req_type & PASSTHRU_REQ_TYPE) {
  996. if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ))
  997. return;
  998. msleep(10);
  999. }
  1000. }
  1001. static void stex_hba_free(struct st_hba *hba)
  1002. {
  1003. free_irq(hba->pdev->irq, hba);
  1004. iounmap(hba->mmio_base);
  1005. pci_release_regions(hba->pdev);
  1006. dma_free_coherent(&hba->pdev->dev, STEX_BUFFER_SIZE,
  1007. hba->dma_mem, hba->dma_handle);
  1008. }
  1009. static void stex_remove(struct pci_dev *pdev)
  1010. {
  1011. struct st_hba *hba = pci_get_drvdata(pdev);
  1012. scsi_remove_host(hba->host);
  1013. pci_set_drvdata(pdev, NULL);
  1014. stex_hba_stop(hba);
  1015. stex_hba_free(hba);
  1016. scsi_host_put(hba->host);
  1017. pci_disable_device(pdev);
  1018. }
  1019. static void stex_shutdown(struct pci_dev *pdev)
  1020. {
  1021. struct st_hba *hba = pci_get_drvdata(pdev);
  1022. stex_hba_stop(hba);
  1023. }
  1024. static struct pci_device_id stex_pci_tbl[] = {
  1025. { 0x105a, 0x8350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1026. { 0x105a, 0xc350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1027. { 0x105a, 0xf350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1028. { 0x105a, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1029. { 0x105a, 0x4302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1030. { 0x105a, 0x8301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1031. { 0x105a, 0x8302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1032. { 0x1725, 0x7250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_vsc },
  1033. { } /* terminate list */
  1034. };
  1035. MODULE_DEVICE_TABLE(pci, stex_pci_tbl);
  1036. static struct pci_driver stex_pci_driver = {
  1037. .name = DRV_NAME,
  1038. .id_table = stex_pci_tbl,
  1039. .probe = stex_probe,
  1040. .remove = __devexit_p(stex_remove),
  1041. .shutdown = stex_shutdown,
  1042. };
  1043. static int __init stex_init(void)
  1044. {
  1045. printk(KERN_INFO DRV_NAME
  1046. ": Promise SuperTrak EX Driver version: %s\n",
  1047. ST_DRIVER_VERSION);
  1048. return pci_register_driver(&stex_pci_driver);
  1049. }
  1050. static void __exit stex_exit(void)
  1051. {
  1052. pci_unregister_driver(&stex_pci_driver);
  1053. }
  1054. module_init(stex_init);
  1055. module_exit(stex_exit);