stex.c 31 KB

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