stex.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. err = scsi_init_shared_tag_map(host, ST_CAN_QUEUE);
  945. if (err) {
  946. printk(KERN_ERR DRV_NAME "(%s): init shared queue failed\n",
  947. pci_name(pdev));
  948. goto out_free_irq;
  949. }
  950. pci_set_drvdata(pdev, hba);
  951. err = scsi_add_host(host, &pdev->dev);
  952. if (err) {
  953. printk(KERN_ERR DRV_NAME "(%s): scsi_add_host failed\n",
  954. pci_name(pdev));
  955. goto out_free_irq;
  956. }
  957. scsi_scan_host(host);
  958. return 0;
  959. out_free_irq:
  960. free_irq(pdev->irq, hba);
  961. out_pci_free:
  962. dma_free_coherent(&pdev->dev, STEX_BUFFER_SIZE,
  963. hba->dma_mem, hba->dma_handle);
  964. out_iounmap:
  965. iounmap(hba->mmio_base);
  966. out_release_regions:
  967. pci_release_regions(pdev);
  968. out_scsi_host_put:
  969. scsi_host_put(host);
  970. out_disable:
  971. pci_disable_device(pdev);
  972. return err;
  973. }
  974. static void stex_hba_stop(struct st_hba *hba)
  975. {
  976. struct req_msg *req;
  977. unsigned long flags;
  978. unsigned long before;
  979. u16 tag = 0;
  980. spin_lock_irqsave(hba->host->host_lock, flags);
  981. req = stex_alloc_req(hba);
  982. memset(req->cdb, 0, STEX_CDB_LENGTH);
  983. req->cdb[0] = CONTROLLER_CMD;
  984. req->cdb[1] = CTLR_POWER_STATE_CHANGE;
  985. req->cdb[2] = CTLR_POWER_SAVING;
  986. hba->ccb[tag].cmd = NULL;
  987. hba->ccb[tag].sg_count = 0;
  988. hba->ccb[tag].sense_bufflen = 0;
  989. hba->ccb[tag].sense_buffer = NULL;
  990. hba->ccb[tag].req_type |= PASSTHRU_REQ_TYPE;
  991. stex_send_cmd(hba, req, tag);
  992. spin_unlock_irqrestore(hba->host->host_lock, flags);
  993. before = jiffies;
  994. while (hba->ccb[tag].req_type & PASSTHRU_REQ_TYPE) {
  995. if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ))
  996. return;
  997. msleep(10);
  998. }
  999. }
  1000. static void stex_hba_free(struct st_hba *hba)
  1001. {
  1002. free_irq(hba->pdev->irq, hba);
  1003. iounmap(hba->mmio_base);
  1004. pci_release_regions(hba->pdev);
  1005. dma_free_coherent(&hba->pdev->dev, STEX_BUFFER_SIZE,
  1006. hba->dma_mem, hba->dma_handle);
  1007. }
  1008. static void stex_remove(struct pci_dev *pdev)
  1009. {
  1010. struct st_hba *hba = pci_get_drvdata(pdev);
  1011. scsi_remove_host(hba->host);
  1012. pci_set_drvdata(pdev, NULL);
  1013. stex_hba_stop(hba);
  1014. stex_hba_free(hba);
  1015. scsi_host_put(hba->host);
  1016. pci_disable_device(pdev);
  1017. }
  1018. static void stex_shutdown(struct pci_dev *pdev)
  1019. {
  1020. struct st_hba *hba = pci_get_drvdata(pdev);
  1021. stex_hba_stop(hba);
  1022. }
  1023. static struct pci_device_id stex_pci_tbl[] = {
  1024. { 0x105a, 0x8350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1025. { 0x105a, 0xc350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1026. { 0x105a, 0xf350, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1027. { 0x105a, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1028. { 0x105a, 0x4302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1029. { 0x105a, 0x8301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1030. { 0x105a, 0x8302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_shasta },
  1031. { 0x1725, 0x7250, PCI_ANY_ID, PCI_ANY_ID, 0, 0, st_vsc },
  1032. { } /* terminate list */
  1033. };
  1034. MODULE_DEVICE_TABLE(pci, stex_pci_tbl);
  1035. static struct pci_driver stex_pci_driver = {
  1036. .name = DRV_NAME,
  1037. .id_table = stex_pci_tbl,
  1038. .probe = stex_probe,
  1039. .remove = __devexit_p(stex_remove),
  1040. .shutdown = stex_shutdown,
  1041. };
  1042. static int __init stex_init(void)
  1043. {
  1044. printk(KERN_INFO DRV_NAME
  1045. ": Promise SuperTrak EX Driver version: %s\n",
  1046. ST_DRIVER_VERSION);
  1047. return pci_register_driver(&stex_pci_driver);
  1048. }
  1049. static void __exit stex_exit(void)
  1050. {
  1051. pci_unregister_driver(&stex_pci_driver);
  1052. }
  1053. module_init(stex_init);
  1054. module_exit(stex_exit);