hptiop.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /*
  2. * HighPoint RR3xxx/4xxx controller driver for Linux
  3. * Copyright (C) 2006-2007 HighPoint Technologies, Inc. All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * Please report bugs/comments/suggestions to linux@highpoint-tech.com
  15. *
  16. * For more information, visit http://www.highpoint-tech.com
  17. */
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/string.h>
  21. #include <linux/kernel.h>
  22. #include <linux/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/errno.h>
  25. #include <linux/delay.h>
  26. #include <linux/timer.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/hdreg.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/io.h>
  31. #include <asm/div64.h>
  32. #include <scsi/scsi_cmnd.h>
  33. #include <scsi/scsi_device.h>
  34. #include <scsi/scsi.h>
  35. #include <scsi/scsi_tcq.h>
  36. #include <scsi/scsi_host.h>
  37. #include "hptiop.h"
  38. MODULE_AUTHOR("HighPoint Technologies, Inc.");
  39. MODULE_DESCRIPTION("HighPoint RocketRAID 3xxx/4xxx Controller Driver");
  40. static char driver_name[] = "hptiop";
  41. static const char driver_name_long[] = "RocketRAID 3xxx/4xxx Controller driver";
  42. static const char driver_ver[] = "v1.3 (071203)";
  43. static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec);
  44. static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
  45. struct hpt_iop_request_scsi_command *req);
  46. static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 tag);
  47. static void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag);
  48. static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg);
  49. static int iop_wait_ready_itl(struct hptiop_hba *hba, u32 millisec)
  50. {
  51. u32 req = 0;
  52. int i;
  53. for (i = 0; i < millisec; i++) {
  54. req = readl(&hba->u.itl.iop->inbound_queue);
  55. if (req != IOPMU_QUEUE_EMPTY)
  56. break;
  57. msleep(1);
  58. }
  59. if (req != IOPMU_QUEUE_EMPTY) {
  60. writel(req, &hba->u.itl.iop->outbound_queue);
  61. readl(&hba->u.itl.iop->outbound_intstatus);
  62. return 0;
  63. }
  64. return -1;
  65. }
  66. static int iop_wait_ready_mv(struct hptiop_hba *hba, u32 millisec)
  67. {
  68. return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
  69. }
  70. static void hptiop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
  71. {
  72. if (tag & IOPMU_QUEUE_ADDR_HOST_BIT)
  73. hptiop_host_request_callback_itl(hba,
  74. tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
  75. else
  76. hptiop_iop_request_callback_itl(hba, tag);
  77. }
  78. static void hptiop_drain_outbound_queue_itl(struct hptiop_hba *hba)
  79. {
  80. u32 req;
  81. while ((req = readl(&hba->u.itl.iop->outbound_queue)) !=
  82. IOPMU_QUEUE_EMPTY) {
  83. if (req & IOPMU_QUEUE_MASK_HOST_BITS)
  84. hptiop_request_callback_itl(hba, req);
  85. else {
  86. struct hpt_iop_request_header __iomem * p;
  87. p = (struct hpt_iop_request_header __iomem *)
  88. ((char __iomem *)hba->u.itl.iop + req);
  89. if (readl(&p->flags) & IOP_REQUEST_FLAG_SYNC_REQUEST) {
  90. if (readl(&p->context))
  91. hptiop_request_callback_itl(hba, req);
  92. else
  93. writel(1, &p->context);
  94. }
  95. else
  96. hptiop_request_callback_itl(hba, req);
  97. }
  98. }
  99. }
  100. static int iop_intr_itl(struct hptiop_hba *hba)
  101. {
  102. struct hpt_iopmu_itl __iomem *iop = hba->u.itl.iop;
  103. u32 status;
  104. int ret = 0;
  105. status = readl(&iop->outbound_intstatus);
  106. if (status & IOPMU_OUTBOUND_INT_MSG0) {
  107. u32 msg = readl(&iop->outbound_msgaddr0);
  108. dprintk("received outbound msg %x\n", msg);
  109. writel(IOPMU_OUTBOUND_INT_MSG0, &iop->outbound_intstatus);
  110. hptiop_message_callback(hba, msg);
  111. ret = 1;
  112. }
  113. if (status & IOPMU_OUTBOUND_INT_POSTQUEUE) {
  114. hptiop_drain_outbound_queue_itl(hba);
  115. ret = 1;
  116. }
  117. return ret;
  118. }
  119. static u64 mv_outbound_read(struct hpt_iopmu_mv __iomem *mu)
  120. {
  121. u32 outbound_tail = readl(&mu->outbound_tail);
  122. u32 outbound_head = readl(&mu->outbound_head);
  123. if (outbound_tail != outbound_head) {
  124. u64 p;
  125. memcpy_fromio(&p, &mu->outbound_q[mu->outbound_tail], 8);
  126. outbound_tail++;
  127. if (outbound_tail == MVIOP_QUEUE_LEN)
  128. outbound_tail = 0;
  129. writel(outbound_tail, &mu->outbound_tail);
  130. return p;
  131. } else
  132. return 0;
  133. }
  134. static void mv_inbound_write(u64 p, struct hptiop_hba *hba)
  135. {
  136. u32 inbound_head = readl(&hba->u.mv.mu->inbound_head);
  137. u32 head = inbound_head + 1;
  138. if (head == MVIOP_QUEUE_LEN)
  139. head = 0;
  140. memcpy_toio(&hba->u.mv.mu->inbound_q[inbound_head], &p, 8);
  141. writel(head, &hba->u.mv.mu->inbound_head);
  142. writel(MVIOP_MU_INBOUND_INT_POSTQUEUE,
  143. &hba->u.mv.regs->inbound_doorbell);
  144. }
  145. static void hptiop_request_callback_mv(struct hptiop_hba *hba, u64 tag)
  146. {
  147. u32 req_type = (tag >> 5) & 0x7;
  148. struct hpt_iop_request_scsi_command *req;
  149. dprintk("hptiop_request_callback_mv: tag=%llx\n", tag);
  150. BUG_ON((tag & MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT) == 0);
  151. switch (req_type) {
  152. case IOP_REQUEST_TYPE_GET_CONFIG:
  153. case IOP_REQUEST_TYPE_SET_CONFIG:
  154. hba->msg_done = 1;
  155. break;
  156. case IOP_REQUEST_TYPE_SCSI_COMMAND:
  157. req = hba->reqs[tag >> 8].req_virt;
  158. if (likely(tag & MVIOP_MU_QUEUE_REQUEST_RESULT_BIT))
  159. req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
  160. hptiop_finish_scsi_req(hba, tag>>8, req);
  161. break;
  162. default:
  163. break;
  164. }
  165. }
  166. static int iop_intr_mv(struct hptiop_hba *hba)
  167. {
  168. u32 status;
  169. int ret = 0;
  170. status = readl(&hba->u.mv.regs->outbound_doorbell);
  171. writel(~status, &hba->u.mv.regs->outbound_doorbell);
  172. if (status & MVIOP_MU_OUTBOUND_INT_MSG) {
  173. u32 msg;
  174. msg = readl(&hba->u.mv.mu->outbound_msg);
  175. dprintk("received outbound msg %x\n", msg);
  176. hptiop_message_callback(hba, msg);
  177. ret = 1;
  178. }
  179. if (status & MVIOP_MU_OUTBOUND_INT_POSTQUEUE) {
  180. u64 tag;
  181. while ((tag = mv_outbound_read(hba->u.mv.mu)))
  182. hptiop_request_callback_mv(hba, tag);
  183. ret = 1;
  184. }
  185. return ret;
  186. }
  187. static int iop_send_sync_request_itl(struct hptiop_hba *hba,
  188. void __iomem *_req, u32 millisec)
  189. {
  190. struct hpt_iop_request_header __iomem *req = _req;
  191. u32 i;
  192. writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST, &req->flags);
  193. writel(0, &req->context);
  194. writel((unsigned long)req - (unsigned long)hba->u.itl.iop,
  195. &hba->u.itl.iop->inbound_queue);
  196. readl(&hba->u.itl.iop->outbound_intstatus);
  197. for (i = 0; i < millisec; i++) {
  198. iop_intr_itl(hba);
  199. if (readl(&req->context))
  200. return 0;
  201. msleep(1);
  202. }
  203. return -1;
  204. }
  205. static int iop_send_sync_request_mv(struct hptiop_hba *hba,
  206. u32 size_bits, u32 millisec)
  207. {
  208. struct hpt_iop_request_header *reqhdr = hba->u.mv.internal_req;
  209. u32 i;
  210. hba->msg_done = 0;
  211. reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
  212. mv_inbound_write(hba->u.mv.internal_req_phy |
  213. MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bits, hba);
  214. for (i = 0; i < millisec; i++) {
  215. iop_intr_mv(hba);
  216. if (hba->msg_done)
  217. return 0;
  218. msleep(1);
  219. }
  220. return -1;
  221. }
  222. static void hptiop_post_msg_itl(struct hptiop_hba *hba, u32 msg)
  223. {
  224. writel(msg, &hba->u.itl.iop->inbound_msgaddr0);
  225. readl(&hba->u.itl.iop->outbound_intstatus);
  226. }
  227. static void hptiop_post_msg_mv(struct hptiop_hba *hba, u32 msg)
  228. {
  229. writel(msg, &hba->u.mv.mu->inbound_msg);
  230. writel(MVIOP_MU_INBOUND_INT_MSG, &hba->u.mv.regs->inbound_doorbell);
  231. readl(&hba->u.mv.regs->inbound_doorbell);
  232. }
  233. static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
  234. {
  235. u32 i;
  236. hba->msg_done = 0;
  237. hba->ops->post_msg(hba, msg);
  238. for (i = 0; i < millisec; i++) {
  239. spin_lock_irq(hba->host->host_lock);
  240. hba->ops->iop_intr(hba);
  241. spin_unlock_irq(hba->host->host_lock);
  242. if (hba->msg_done)
  243. break;
  244. msleep(1);
  245. }
  246. return hba->msg_done? 0 : -1;
  247. }
  248. static int iop_get_config_itl(struct hptiop_hba *hba,
  249. struct hpt_iop_request_get_config *config)
  250. {
  251. u32 req32;
  252. struct hpt_iop_request_get_config __iomem *req;
  253. req32 = readl(&hba->u.itl.iop->inbound_queue);
  254. if (req32 == IOPMU_QUEUE_EMPTY)
  255. return -1;
  256. req = (struct hpt_iop_request_get_config __iomem *)
  257. ((unsigned long)hba->u.itl.iop + req32);
  258. writel(0, &req->header.flags);
  259. writel(IOP_REQUEST_TYPE_GET_CONFIG, &req->header.type);
  260. writel(sizeof(struct hpt_iop_request_get_config), &req->header.size);
  261. writel(IOP_RESULT_PENDING, &req->header.result);
  262. if (iop_send_sync_request_itl(hba, req, 20000)) {
  263. dprintk("Get config send cmd failed\n");
  264. return -1;
  265. }
  266. memcpy_fromio(config, req, sizeof(*config));
  267. writel(req32, &hba->u.itl.iop->outbound_queue);
  268. return 0;
  269. }
  270. static int iop_get_config_mv(struct hptiop_hba *hba,
  271. struct hpt_iop_request_get_config *config)
  272. {
  273. struct hpt_iop_request_get_config *req = hba->u.mv.internal_req;
  274. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  275. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG);
  276. req->header.size =
  277. cpu_to_le32(sizeof(struct hpt_iop_request_get_config));
  278. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  279. req->header.context = cpu_to_le64(IOP_REQUEST_TYPE_GET_CONFIG<<5);
  280. if (iop_send_sync_request_mv(hba, 0, 20000)) {
  281. dprintk("Get config send cmd failed\n");
  282. return -1;
  283. }
  284. memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
  285. return 0;
  286. }
  287. static int iop_set_config_itl(struct hptiop_hba *hba,
  288. struct hpt_iop_request_set_config *config)
  289. {
  290. u32 req32;
  291. struct hpt_iop_request_set_config __iomem *req;
  292. req32 = readl(&hba->u.itl.iop->inbound_queue);
  293. if (req32 == IOPMU_QUEUE_EMPTY)
  294. return -1;
  295. req = (struct hpt_iop_request_set_config __iomem *)
  296. ((unsigned long)hba->u.itl.iop + req32);
  297. memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
  298. (u8 *)config + sizeof(struct hpt_iop_request_header),
  299. sizeof(struct hpt_iop_request_set_config) -
  300. sizeof(struct hpt_iop_request_header));
  301. writel(0, &req->header.flags);
  302. writel(IOP_REQUEST_TYPE_SET_CONFIG, &req->header.type);
  303. writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
  304. writel(IOP_RESULT_PENDING, &req->header.result);
  305. if (iop_send_sync_request_itl(hba, req, 20000)) {
  306. dprintk("Set config send cmd failed\n");
  307. return -1;
  308. }
  309. writel(req32, &hba->u.itl.iop->outbound_queue);
  310. return 0;
  311. }
  312. static int iop_set_config_mv(struct hptiop_hba *hba,
  313. struct hpt_iop_request_set_config *config)
  314. {
  315. struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
  316. memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
  317. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  318. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
  319. req->header.size =
  320. cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
  321. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  322. req->header.context = cpu_to_le64(IOP_REQUEST_TYPE_SET_CONFIG<<5);
  323. if (iop_send_sync_request_mv(hba, 0, 20000)) {
  324. dprintk("Set config send cmd failed\n");
  325. return -1;
  326. }
  327. return 0;
  328. }
  329. static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
  330. {
  331. writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
  332. &hba->u.itl.iop->outbound_intmask);
  333. }
  334. static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
  335. {
  336. writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
  337. &hba->u.mv.regs->outbound_intmask);
  338. }
  339. static int hptiop_initialize_iop(struct hptiop_hba *hba)
  340. {
  341. /* enable interrupts */
  342. hba->ops->enable_intr(hba);
  343. hba->initialized = 1;
  344. /* start background tasks */
  345. if (iop_send_sync_msg(hba,
  346. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
  347. printk(KERN_ERR "scsi%d: fail to start background task\n",
  348. hba->host->host_no);
  349. return -1;
  350. }
  351. return 0;
  352. }
  353. static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
  354. {
  355. u32 mem_base_phy, length;
  356. void __iomem *mem_base_virt;
  357. struct pci_dev *pcidev = hba->pcidev;
  358. if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
  359. printk(KERN_ERR "scsi%d: pci resource invalid\n",
  360. hba->host->host_no);
  361. return 0;
  362. }
  363. mem_base_phy = pci_resource_start(pcidev, index);
  364. length = pci_resource_len(pcidev, index);
  365. mem_base_virt = ioremap(mem_base_phy, length);
  366. if (!mem_base_virt) {
  367. printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
  368. hba->host->host_no);
  369. return 0;
  370. }
  371. return mem_base_virt;
  372. }
  373. static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
  374. {
  375. hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
  376. if (hba->u.itl.iop)
  377. return 0;
  378. else
  379. return -1;
  380. }
  381. static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
  382. {
  383. iounmap(hba->u.itl.iop);
  384. }
  385. static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
  386. {
  387. hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
  388. if (hba->u.mv.regs == 0)
  389. return -1;
  390. hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
  391. if (hba->u.mv.mu == 0) {
  392. iounmap(hba->u.mv.regs);
  393. return -1;
  394. }
  395. return 0;
  396. }
  397. static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
  398. {
  399. iounmap(hba->u.mv.regs);
  400. iounmap(hba->u.mv.mu);
  401. }
  402. static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
  403. {
  404. dprintk("iop message 0x%x\n", msg);
  405. if (msg == IOPMU_INBOUND_MSG0_NOP)
  406. hba->msg_done = 1;
  407. if (!hba->initialized)
  408. return;
  409. if (msg == IOPMU_INBOUND_MSG0_RESET) {
  410. atomic_set(&hba->resetting, 0);
  411. wake_up(&hba->reset_wq);
  412. }
  413. else if (msg <= IOPMU_INBOUND_MSG0_MAX)
  414. hba->msg_done = 1;
  415. }
  416. static struct hptiop_request *get_req(struct hptiop_hba *hba)
  417. {
  418. struct hptiop_request *ret;
  419. dprintk("get_req : req=%p\n", hba->req_list);
  420. ret = hba->req_list;
  421. if (ret)
  422. hba->req_list = ret->next;
  423. return ret;
  424. }
  425. static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
  426. {
  427. dprintk("free_req(%d, %p)\n", req->index, req);
  428. req->next = hba->req_list;
  429. hba->req_list = req;
  430. }
  431. static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
  432. struct hpt_iop_request_scsi_command *req)
  433. {
  434. struct scsi_cmnd *scp;
  435. dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
  436. "result=%d, context=0x%x tag=%d\n",
  437. req, req->header.type, req->header.result,
  438. req->header.context, tag);
  439. BUG_ON(!req->header.result);
  440. BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));
  441. scp = hba->reqs[tag].scp;
  442. if (HPT_SCP(scp)->mapped)
  443. scsi_dma_unmap(scp);
  444. switch (le32_to_cpu(req->header.result)) {
  445. case IOP_RESULT_SUCCESS:
  446. scsi_set_resid(scp,
  447. scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
  448. scp->result = (DID_OK<<16);
  449. break;
  450. case IOP_RESULT_BAD_TARGET:
  451. scp->result = (DID_BAD_TARGET<<16);
  452. break;
  453. case IOP_RESULT_BUSY:
  454. scp->result = (DID_BUS_BUSY<<16);
  455. break;
  456. case IOP_RESULT_RESET:
  457. scp->result = (DID_RESET<<16);
  458. break;
  459. case IOP_RESULT_FAIL:
  460. scp->result = (DID_ERROR<<16);
  461. break;
  462. case IOP_RESULT_INVALID_REQUEST:
  463. scp->result = (DID_ABORT<<16);
  464. break;
  465. case IOP_RESULT_CHECK_CONDITION:
  466. scsi_set_resid(scp,
  467. scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
  468. scp->result = SAM_STAT_CHECK_CONDITION;
  469. memcpy(scp->sense_buffer, &req->sg_list,
  470. min_t(size_t, SCSI_SENSE_BUFFERSIZE,
  471. le32_to_cpu(req->dataxfer_length)));
  472. break;
  473. default:
  474. scp->result = ((DRIVER_INVALID|SUGGEST_ABORT)<<24) |
  475. (DID_ABORT<<16);
  476. break;
  477. }
  478. dprintk("scsi_done(%p)\n", scp);
  479. scp->scsi_done(scp);
  480. free_req(hba, &hba->reqs[tag]);
  481. }
  482. static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
  483. {
  484. struct hpt_iop_request_scsi_command *req;
  485. u32 tag;
  486. if (hba->iopintf_v2) {
  487. tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
  488. req = hba->reqs[tag].req_virt;
  489. if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
  490. req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
  491. } else {
  492. tag = _tag;
  493. req = hba->reqs[tag].req_virt;
  494. }
  495. hptiop_finish_scsi_req(hba, tag, req);
  496. }
  497. void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
  498. {
  499. struct hpt_iop_request_header __iomem *req;
  500. struct hpt_iop_request_ioctl_command __iomem *p;
  501. struct hpt_ioctl_k *arg;
  502. req = (struct hpt_iop_request_header __iomem *)
  503. ((unsigned long)hba->u.itl.iop + tag);
  504. dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
  505. "result=%d, context=0x%x tag=%d\n",
  506. req, readl(&req->type), readl(&req->result),
  507. readl(&req->context), tag);
  508. BUG_ON(!readl(&req->result));
  509. BUG_ON(readl(&req->type) != IOP_REQUEST_TYPE_IOCTL_COMMAND);
  510. p = (struct hpt_iop_request_ioctl_command __iomem *)req;
  511. arg = (struct hpt_ioctl_k *)(unsigned long)
  512. (readl(&req->context) |
  513. ((u64)readl(&req->context_hi32)<<32));
  514. if (readl(&req->result) == IOP_RESULT_SUCCESS) {
  515. arg->result = HPT_IOCTL_RESULT_OK;
  516. if (arg->outbuf_size)
  517. memcpy_fromio(arg->outbuf,
  518. &p->buf[(readl(&p->inbuf_size) + 3)& ~3],
  519. arg->outbuf_size);
  520. if (arg->bytes_returned)
  521. *arg->bytes_returned = arg->outbuf_size;
  522. }
  523. else
  524. arg->result = HPT_IOCTL_RESULT_FAILED;
  525. arg->done(arg);
  526. writel(tag, &hba->u.itl.iop->outbound_queue);
  527. }
  528. static irqreturn_t hptiop_intr(int irq, void *dev_id)
  529. {
  530. struct hptiop_hba *hba = dev_id;
  531. int handled;
  532. unsigned long flags;
  533. spin_lock_irqsave(hba->host->host_lock, flags);
  534. handled = hba->ops->iop_intr(hba);
  535. spin_unlock_irqrestore(hba->host->host_lock, flags);
  536. return handled;
  537. }
  538. static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
  539. {
  540. struct Scsi_Host *host = scp->device->host;
  541. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  542. struct scatterlist *sg;
  543. int idx, nseg;
  544. nseg = scsi_dma_map(scp);
  545. BUG_ON(nseg < 0);
  546. if (!nseg)
  547. return 0;
  548. HPT_SCP(scp)->sgcnt = nseg;
  549. HPT_SCP(scp)->mapped = 1;
  550. BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
  551. scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
  552. psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg));
  553. psg[idx].size = cpu_to_le32(sg_dma_len(sg));
  554. psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
  555. cpu_to_le32(1) : 0;
  556. }
  557. return HPT_SCP(scp)->sgcnt;
  558. }
  559. static void hptiop_post_req_itl(struct hptiop_hba *hba,
  560. struct hptiop_request *_req)
  561. {
  562. struct hpt_iop_request_header *reqhdr = _req->req_virt;
  563. reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
  564. (u32)_req->index);
  565. reqhdr->context_hi32 = 0;
  566. if (hba->iopintf_v2) {
  567. u32 size, size_bits;
  568. size = le32_to_cpu(reqhdr->size);
  569. if (size < 256)
  570. size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
  571. else if (size < 512)
  572. size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
  573. else
  574. size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
  575. IOPMU_QUEUE_ADDR_HOST_BIT;
  576. writel(_req->req_shifted_phy | size_bits,
  577. &hba->u.itl.iop->inbound_queue);
  578. } else
  579. writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
  580. &hba->u.itl.iop->inbound_queue);
  581. }
  582. static void hptiop_post_req_mv(struct hptiop_hba *hba,
  583. struct hptiop_request *_req)
  584. {
  585. struct hpt_iop_request_header *reqhdr = _req->req_virt;
  586. u32 size, size_bit;
  587. reqhdr->context = cpu_to_le32(_req->index<<8 |
  588. IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
  589. reqhdr->context_hi32 = 0;
  590. size = le32_to_cpu(reqhdr->size);
  591. if (size <= 256)
  592. size_bit = 0;
  593. else if (size <= 256*2)
  594. size_bit = 1;
  595. else if (size <= 256*3)
  596. size_bit = 2;
  597. else
  598. size_bit = 3;
  599. mv_inbound_write((_req->req_shifted_phy << 5) |
  600. MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
  601. }
  602. static int hptiop_queuecommand(struct scsi_cmnd *scp,
  603. void (*done)(struct scsi_cmnd *))
  604. {
  605. struct Scsi_Host *host = scp->device->host;
  606. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  607. struct hpt_iop_request_scsi_command *req;
  608. int sg_count = 0;
  609. struct hptiop_request *_req;
  610. BUG_ON(!done);
  611. scp->scsi_done = done;
  612. _req = get_req(hba);
  613. if (_req == NULL) {
  614. dprintk("hptiop_queuecmd : no free req\n");
  615. return SCSI_MLQUEUE_HOST_BUSY;
  616. }
  617. _req->scp = scp;
  618. dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%d cdb=(%x-%x-%x) "
  619. "req_index=%d, req=%p\n",
  620. scp,
  621. host->host_no, scp->device->channel,
  622. scp->device->id, scp->device->lun,
  623. *((u32 *)&scp->cmnd),
  624. *((u32 *)&scp->cmnd + 1),
  625. *((u32 *)&scp->cmnd + 2),
  626. _req->index, _req->req_virt);
  627. scp->result = 0;
  628. if (scp->device->channel || scp->device->lun ||
  629. scp->device->id > hba->max_devices) {
  630. scp->result = DID_BAD_TARGET << 16;
  631. free_req(hba, _req);
  632. goto cmd_done;
  633. }
  634. req = _req->req_virt;
  635. /* build S/G table */
  636. sg_count = hptiop_buildsgl(scp, req->sg_list);
  637. if (!sg_count)
  638. HPT_SCP(scp)->mapped = 0;
  639. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  640. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
  641. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  642. req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
  643. req->channel = scp->device->channel;
  644. req->target = scp->device->id;
  645. req->lun = scp->device->lun;
  646. req->header.size = cpu_to_le32(
  647. sizeof(struct hpt_iop_request_scsi_command)
  648. - sizeof(struct hpt_iopsg)
  649. + sg_count * sizeof(struct hpt_iopsg));
  650. memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
  651. hba->ops->post_req(hba, _req);
  652. return 0;
  653. cmd_done:
  654. dprintk("scsi_done(scp=%p)\n", scp);
  655. scp->scsi_done(scp);
  656. return 0;
  657. }
  658. static const char *hptiop_info(struct Scsi_Host *host)
  659. {
  660. return driver_name_long;
  661. }
  662. static int hptiop_reset_hba(struct hptiop_hba *hba)
  663. {
  664. if (atomic_xchg(&hba->resetting, 1) == 0) {
  665. atomic_inc(&hba->reset_count);
  666. hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
  667. }
  668. wait_event_timeout(hba->reset_wq,
  669. atomic_read(&hba->resetting) == 0, 60 * HZ);
  670. if (atomic_read(&hba->resetting)) {
  671. /* IOP is in unkown state, abort reset */
  672. printk(KERN_ERR "scsi%d: reset failed\n", hba->host->host_no);
  673. return -1;
  674. }
  675. if (iop_send_sync_msg(hba,
  676. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
  677. dprintk("scsi%d: fail to start background task\n",
  678. hba->host->host_no);
  679. }
  680. return 0;
  681. }
  682. static int hptiop_reset(struct scsi_cmnd *scp)
  683. {
  684. struct Scsi_Host * host = scp->device->host;
  685. struct hptiop_hba * hba = (struct hptiop_hba *)host->hostdata;
  686. printk(KERN_WARNING "hptiop_reset(%d/%d/%d) scp=%p\n",
  687. scp->device->host->host_no, scp->device->channel,
  688. scp->device->id, scp);
  689. return hptiop_reset_hba(hba)? FAILED : SUCCESS;
  690. }
  691. static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
  692. int queue_depth)
  693. {
  694. struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
  695. if (queue_depth > hba->max_requests)
  696. queue_depth = hba->max_requests;
  697. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
  698. return queue_depth;
  699. }
  700. static ssize_t hptiop_show_version(struct class_device *class_dev, char *buf)
  701. {
  702. return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
  703. }
  704. static ssize_t hptiop_show_fw_version(struct class_device *class_dev, char *buf)
  705. {
  706. struct Scsi_Host *host = class_to_shost(class_dev);
  707. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  708. return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
  709. hba->firmware_version >> 24,
  710. (hba->firmware_version >> 16) & 0xff,
  711. (hba->firmware_version >> 8) & 0xff,
  712. hba->firmware_version & 0xff);
  713. }
  714. static struct class_device_attribute hptiop_attr_version = {
  715. .attr = {
  716. .name = "driver-version",
  717. .mode = S_IRUGO,
  718. },
  719. .show = hptiop_show_version,
  720. };
  721. static struct class_device_attribute hptiop_attr_fw_version = {
  722. .attr = {
  723. .name = "firmware-version",
  724. .mode = S_IRUGO,
  725. },
  726. .show = hptiop_show_fw_version,
  727. };
  728. static struct class_device_attribute *hptiop_attrs[] = {
  729. &hptiop_attr_version,
  730. &hptiop_attr_fw_version,
  731. NULL
  732. };
  733. static struct scsi_host_template driver_template = {
  734. .module = THIS_MODULE,
  735. .name = driver_name,
  736. .queuecommand = hptiop_queuecommand,
  737. .eh_device_reset_handler = hptiop_reset,
  738. .eh_bus_reset_handler = hptiop_reset,
  739. .info = hptiop_info,
  740. .emulated = 0,
  741. .use_clustering = ENABLE_CLUSTERING,
  742. .proc_name = driver_name,
  743. .shost_attrs = hptiop_attrs,
  744. .this_id = -1,
  745. .change_queue_depth = hptiop_adjust_disk_queue_depth,
  746. };
  747. static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
  748. {
  749. hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
  750. 0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
  751. if (hba->u.mv.internal_req)
  752. return 0;
  753. else
  754. return -1;
  755. }
  756. static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
  757. {
  758. if (hba->u.mv.internal_req) {
  759. dma_free_coherent(&hba->pcidev->dev, 0x800,
  760. hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
  761. return 0;
  762. } else
  763. return -1;
  764. }
  765. static int __devinit hptiop_probe(struct pci_dev *pcidev,
  766. const struct pci_device_id *id)
  767. {
  768. struct Scsi_Host *host = NULL;
  769. struct hptiop_hba *hba;
  770. struct hpt_iop_request_get_config iop_config;
  771. struct hpt_iop_request_set_config set_config;
  772. dma_addr_t start_phy;
  773. void *start_virt;
  774. u32 offset, i, req_size;
  775. dprintk("hptiop_probe(%p)\n", pcidev);
  776. if (pci_enable_device(pcidev)) {
  777. printk(KERN_ERR "hptiop: fail to enable pci device\n");
  778. return -ENODEV;
  779. }
  780. printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
  781. pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
  782. pcidev->irq);
  783. pci_set_master(pcidev);
  784. /* Enable 64bit DMA if possible */
  785. if (pci_set_dma_mask(pcidev, DMA_64BIT_MASK)) {
  786. if (pci_set_dma_mask(pcidev, DMA_32BIT_MASK)) {
  787. printk(KERN_ERR "hptiop: fail to set dma_mask\n");
  788. goto disable_pci_device;
  789. }
  790. }
  791. if (pci_request_regions(pcidev, driver_name)) {
  792. printk(KERN_ERR "hptiop: pci_request_regions failed\n");
  793. goto disable_pci_device;
  794. }
  795. host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
  796. if (!host) {
  797. printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
  798. goto free_pci_regions;
  799. }
  800. hba = (struct hptiop_hba *)host->hostdata;
  801. hba->ops = (struct hptiop_adapter_ops *)id->driver_data;
  802. hba->pcidev = pcidev;
  803. hba->host = host;
  804. hba->initialized = 0;
  805. hba->iopintf_v2 = 0;
  806. atomic_set(&hba->resetting, 0);
  807. atomic_set(&hba->reset_count, 0);
  808. init_waitqueue_head(&hba->reset_wq);
  809. init_waitqueue_head(&hba->ioctl_wq);
  810. host->max_lun = 1;
  811. host->max_channel = 0;
  812. host->io_port = 0;
  813. host->n_io_port = 0;
  814. host->irq = pcidev->irq;
  815. if (hba->ops->map_pci_bar(hba))
  816. goto free_scsi_host;
  817. if (hba->ops->iop_wait_ready(hba, 20000)) {
  818. printk(KERN_ERR "scsi%d: firmware not ready\n",
  819. hba->host->host_no);
  820. goto unmap_pci_bar;
  821. }
  822. if (hba->ops->internal_memalloc) {
  823. if (hba->ops->internal_memalloc(hba)) {
  824. printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
  825. hba->host->host_no);
  826. goto unmap_pci_bar;
  827. }
  828. }
  829. if (hba->ops->get_config(hba, &iop_config)) {
  830. printk(KERN_ERR "scsi%d: get config failed\n",
  831. hba->host->host_no);
  832. goto unmap_pci_bar;
  833. }
  834. hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
  835. HPTIOP_MAX_REQUESTS);
  836. hba->max_devices = le32_to_cpu(iop_config.max_devices);
  837. hba->max_request_size = le32_to_cpu(iop_config.request_size);
  838. hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
  839. hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
  840. hba->interface_version = le32_to_cpu(iop_config.interface_version);
  841. hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
  842. if (hba->firmware_version > 0x01020000 ||
  843. hba->interface_version > 0x01020000)
  844. hba->iopintf_v2 = 1;
  845. host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
  846. host->max_id = le32_to_cpu(iop_config.max_devices);
  847. host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
  848. host->can_queue = le32_to_cpu(iop_config.max_requests);
  849. host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
  850. host->max_cmd_len = 16;
  851. req_size = sizeof(struct hpt_iop_request_scsi_command)
  852. + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
  853. if ((req_size & 0x1f) != 0)
  854. req_size = (req_size + 0x1f) & ~0x1f;
  855. memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
  856. set_config.iop_id = cpu_to_le32(host->host_no);
  857. set_config.vbus_id = cpu_to_le16(host->host_no);
  858. set_config.max_host_request_size = cpu_to_le16(req_size);
  859. if (hba->ops->set_config(hba, &set_config)) {
  860. printk(KERN_ERR "scsi%d: set config failed\n",
  861. hba->host->host_no);
  862. goto unmap_pci_bar;
  863. }
  864. pci_set_drvdata(pcidev, host);
  865. if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
  866. driver_name, hba)) {
  867. printk(KERN_ERR "scsi%d: request irq %d failed\n",
  868. hba->host->host_no, pcidev->irq);
  869. goto unmap_pci_bar;
  870. }
  871. /* Allocate request mem */
  872. dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
  873. hba->req_size = req_size;
  874. start_virt = dma_alloc_coherent(&pcidev->dev,
  875. hba->req_size*hba->max_requests + 0x20,
  876. &start_phy, GFP_KERNEL);
  877. if (!start_virt) {
  878. printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
  879. hba->host->host_no);
  880. goto free_request_irq;
  881. }
  882. hba->dma_coherent = start_virt;
  883. hba->dma_coherent_handle = start_phy;
  884. if ((start_phy & 0x1f) != 0)
  885. {
  886. offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
  887. start_phy += offset;
  888. start_virt += offset;
  889. }
  890. hba->req_list = start_virt;
  891. for (i = 0; i < hba->max_requests; i++) {
  892. hba->reqs[i].next = NULL;
  893. hba->reqs[i].req_virt = start_virt;
  894. hba->reqs[i].req_shifted_phy = start_phy >> 5;
  895. hba->reqs[i].index = i;
  896. free_req(hba, &hba->reqs[i]);
  897. start_virt = (char *)start_virt + hba->req_size;
  898. start_phy = start_phy + hba->req_size;
  899. }
  900. /* Enable Interrupt and start background task */
  901. if (hptiop_initialize_iop(hba))
  902. goto free_request_mem;
  903. if (scsi_add_host(host, &pcidev->dev)) {
  904. printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
  905. hba->host->host_no);
  906. goto free_request_mem;
  907. }
  908. scsi_scan_host(host);
  909. dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
  910. return 0;
  911. free_request_mem:
  912. dma_free_coherent(&hba->pcidev->dev,
  913. hba->req_size * hba->max_requests + 0x20,
  914. hba->dma_coherent, hba->dma_coherent_handle);
  915. free_request_irq:
  916. free_irq(hba->pcidev->irq, hba);
  917. unmap_pci_bar:
  918. if (hba->ops->internal_memfree)
  919. hba->ops->internal_memfree(hba);
  920. hba->ops->unmap_pci_bar(hba);
  921. free_scsi_host:
  922. scsi_host_put(host);
  923. free_pci_regions:
  924. pci_release_regions(pcidev);
  925. disable_pci_device:
  926. pci_disable_device(pcidev);
  927. dprintk("scsi%d: hptiop_probe fail\n", host->host_no);
  928. return -ENODEV;
  929. }
  930. static void hptiop_shutdown(struct pci_dev *pcidev)
  931. {
  932. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  933. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  934. dprintk("hptiop_shutdown(%p)\n", hba);
  935. /* stop the iop */
  936. if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
  937. printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
  938. hba->host->host_no);
  939. /* disable all outbound interrupts */
  940. hba->ops->disable_intr(hba);
  941. }
  942. static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
  943. {
  944. u32 int_mask;
  945. int_mask = readl(&hba->u.itl.iop->outbound_intmask);
  946. writel(int_mask |
  947. IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
  948. &hba->u.itl.iop->outbound_intmask);
  949. readl(&hba->u.itl.iop->outbound_intmask);
  950. }
  951. static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
  952. {
  953. writel(0, &hba->u.mv.regs->outbound_intmask);
  954. readl(&hba->u.mv.regs->outbound_intmask);
  955. }
  956. static void hptiop_remove(struct pci_dev *pcidev)
  957. {
  958. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  959. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  960. dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
  961. scsi_remove_host(host);
  962. hptiop_shutdown(pcidev);
  963. free_irq(hba->pcidev->irq, hba);
  964. dma_free_coherent(&hba->pcidev->dev,
  965. hba->req_size * hba->max_requests + 0x20,
  966. hba->dma_coherent,
  967. hba->dma_coherent_handle);
  968. if (hba->ops->internal_memfree)
  969. hba->ops->internal_memfree(hba);
  970. hba->ops->unmap_pci_bar(hba);
  971. pci_release_regions(hba->pcidev);
  972. pci_set_drvdata(hba->pcidev, NULL);
  973. pci_disable_device(hba->pcidev);
  974. scsi_host_put(host);
  975. }
  976. static struct hptiop_adapter_ops hptiop_itl_ops = {
  977. .iop_wait_ready = iop_wait_ready_itl,
  978. .internal_memalloc = 0,
  979. .internal_memfree = 0,
  980. .map_pci_bar = hptiop_map_pci_bar_itl,
  981. .unmap_pci_bar = hptiop_unmap_pci_bar_itl,
  982. .enable_intr = hptiop_enable_intr_itl,
  983. .disable_intr = hptiop_disable_intr_itl,
  984. .get_config = iop_get_config_itl,
  985. .set_config = iop_set_config_itl,
  986. .iop_intr = iop_intr_itl,
  987. .post_msg = hptiop_post_msg_itl,
  988. .post_req = hptiop_post_req_itl,
  989. };
  990. static struct hptiop_adapter_ops hptiop_mv_ops = {
  991. .iop_wait_ready = iop_wait_ready_mv,
  992. .internal_memalloc = hptiop_internal_memalloc_mv,
  993. .internal_memfree = hptiop_internal_memfree_mv,
  994. .map_pci_bar = hptiop_map_pci_bar_mv,
  995. .unmap_pci_bar = hptiop_unmap_pci_bar_mv,
  996. .enable_intr = hptiop_enable_intr_mv,
  997. .disable_intr = hptiop_disable_intr_mv,
  998. .get_config = iop_get_config_mv,
  999. .set_config = iop_set_config_mv,
  1000. .iop_intr = iop_intr_mv,
  1001. .post_msg = hptiop_post_msg_mv,
  1002. .post_req = hptiop_post_req_mv,
  1003. };
  1004. static struct pci_device_id hptiop_id_table[] = {
  1005. { PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
  1006. { PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
  1007. { PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
  1008. { PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
  1009. { PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
  1010. { PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
  1011. { PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
  1012. { PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
  1013. { PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
  1014. { PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
  1015. { PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
  1016. { PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
  1017. { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
  1018. {},
  1019. };
  1020. MODULE_DEVICE_TABLE(pci, hptiop_id_table);
  1021. static struct pci_driver hptiop_pci_driver = {
  1022. .name = driver_name,
  1023. .id_table = hptiop_id_table,
  1024. .probe = hptiop_probe,
  1025. .remove = hptiop_remove,
  1026. .shutdown = hptiop_shutdown,
  1027. };
  1028. static int __init hptiop_module_init(void)
  1029. {
  1030. printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
  1031. return pci_register_driver(&hptiop_pci_driver);
  1032. }
  1033. static void __exit hptiop_module_exit(void)
  1034. {
  1035. pci_unregister_driver(&hptiop_pci_driver);
  1036. }
  1037. module_init(hptiop_module_init);
  1038. module_exit(hptiop_module_exit);
  1039. MODULE_LICENSE("GPL");