stex.c 31 KB

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