hptiop.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  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_le32(IOP_REQUEST_TYPE_GET_CONFIG<<5);
  280. req->header.context_hi32 = 0;
  281. if (iop_send_sync_request_mv(hba, 0, 20000)) {
  282. dprintk("Get config send cmd failed\n");
  283. return -1;
  284. }
  285. memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
  286. return 0;
  287. }
  288. static int iop_set_config_itl(struct hptiop_hba *hba,
  289. struct hpt_iop_request_set_config *config)
  290. {
  291. u32 req32;
  292. struct hpt_iop_request_set_config __iomem *req;
  293. req32 = readl(&hba->u.itl.iop->inbound_queue);
  294. if (req32 == IOPMU_QUEUE_EMPTY)
  295. return -1;
  296. req = (struct hpt_iop_request_set_config __iomem *)
  297. ((unsigned long)hba->u.itl.iop + req32);
  298. memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
  299. (u8 *)config + sizeof(struct hpt_iop_request_header),
  300. sizeof(struct hpt_iop_request_set_config) -
  301. sizeof(struct hpt_iop_request_header));
  302. writel(0, &req->header.flags);
  303. writel(IOP_REQUEST_TYPE_SET_CONFIG, &req->header.type);
  304. writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
  305. writel(IOP_RESULT_PENDING, &req->header.result);
  306. if (iop_send_sync_request_itl(hba, req, 20000)) {
  307. dprintk("Set config send cmd failed\n");
  308. return -1;
  309. }
  310. writel(req32, &hba->u.itl.iop->outbound_queue);
  311. return 0;
  312. }
  313. static int iop_set_config_mv(struct hptiop_hba *hba,
  314. struct hpt_iop_request_set_config *config)
  315. {
  316. struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
  317. memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
  318. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  319. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
  320. req->header.size =
  321. cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
  322. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  323. req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
  324. req->header.context_hi32 = 0;
  325. if (iop_send_sync_request_mv(hba, 0, 20000)) {
  326. dprintk("Set config send cmd failed\n");
  327. return -1;
  328. }
  329. return 0;
  330. }
  331. static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
  332. {
  333. writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
  334. &hba->u.itl.iop->outbound_intmask);
  335. }
  336. static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
  337. {
  338. writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
  339. &hba->u.mv.regs->outbound_intmask);
  340. }
  341. static int hptiop_initialize_iop(struct hptiop_hba *hba)
  342. {
  343. /* enable interrupts */
  344. hba->ops->enable_intr(hba);
  345. hba->initialized = 1;
  346. /* start background tasks */
  347. if (iop_send_sync_msg(hba,
  348. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
  349. printk(KERN_ERR "scsi%d: fail to start background task\n",
  350. hba->host->host_no);
  351. return -1;
  352. }
  353. return 0;
  354. }
  355. static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
  356. {
  357. u32 mem_base_phy, length;
  358. void __iomem *mem_base_virt;
  359. struct pci_dev *pcidev = hba->pcidev;
  360. if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
  361. printk(KERN_ERR "scsi%d: pci resource invalid\n",
  362. hba->host->host_no);
  363. return 0;
  364. }
  365. mem_base_phy = pci_resource_start(pcidev, index);
  366. length = pci_resource_len(pcidev, index);
  367. mem_base_virt = ioremap(mem_base_phy, length);
  368. if (!mem_base_virt) {
  369. printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
  370. hba->host->host_no);
  371. return 0;
  372. }
  373. return mem_base_virt;
  374. }
  375. static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
  376. {
  377. hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
  378. if (hba->u.itl.iop)
  379. return 0;
  380. else
  381. return -1;
  382. }
  383. static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
  384. {
  385. iounmap(hba->u.itl.iop);
  386. }
  387. static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
  388. {
  389. hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
  390. if (hba->u.mv.regs == 0)
  391. return -1;
  392. hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
  393. if (hba->u.mv.mu == 0) {
  394. iounmap(hba->u.mv.regs);
  395. return -1;
  396. }
  397. return 0;
  398. }
  399. static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
  400. {
  401. iounmap(hba->u.mv.regs);
  402. iounmap(hba->u.mv.mu);
  403. }
  404. static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
  405. {
  406. dprintk("iop message 0x%x\n", msg);
  407. if (msg == IOPMU_INBOUND_MSG0_NOP)
  408. hba->msg_done = 1;
  409. if (!hba->initialized)
  410. return;
  411. if (msg == IOPMU_INBOUND_MSG0_RESET) {
  412. atomic_set(&hba->resetting, 0);
  413. wake_up(&hba->reset_wq);
  414. }
  415. else if (msg <= IOPMU_INBOUND_MSG0_MAX)
  416. hba->msg_done = 1;
  417. }
  418. static struct hptiop_request *get_req(struct hptiop_hba *hba)
  419. {
  420. struct hptiop_request *ret;
  421. dprintk("get_req : req=%p\n", hba->req_list);
  422. ret = hba->req_list;
  423. if (ret)
  424. hba->req_list = ret->next;
  425. return ret;
  426. }
  427. static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
  428. {
  429. dprintk("free_req(%d, %p)\n", req->index, req);
  430. req->next = hba->req_list;
  431. hba->req_list = req;
  432. }
  433. static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
  434. struct hpt_iop_request_scsi_command *req)
  435. {
  436. struct scsi_cmnd *scp;
  437. dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
  438. "result=%d, context=0x%x tag=%d\n",
  439. req, req->header.type, req->header.result,
  440. req->header.context, tag);
  441. BUG_ON(!req->header.result);
  442. BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));
  443. scp = hba->reqs[tag].scp;
  444. if (HPT_SCP(scp)->mapped)
  445. scsi_dma_unmap(scp);
  446. switch (le32_to_cpu(req->header.result)) {
  447. case IOP_RESULT_SUCCESS:
  448. scsi_set_resid(scp,
  449. scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
  450. scp->result = (DID_OK<<16);
  451. break;
  452. case IOP_RESULT_BAD_TARGET:
  453. scp->result = (DID_BAD_TARGET<<16);
  454. break;
  455. case IOP_RESULT_BUSY:
  456. scp->result = (DID_BUS_BUSY<<16);
  457. break;
  458. case IOP_RESULT_RESET:
  459. scp->result = (DID_RESET<<16);
  460. break;
  461. case IOP_RESULT_FAIL:
  462. scp->result = (DID_ERROR<<16);
  463. break;
  464. case IOP_RESULT_INVALID_REQUEST:
  465. scp->result = (DID_ABORT<<16);
  466. break;
  467. case IOP_RESULT_CHECK_CONDITION:
  468. scsi_set_resid(scp,
  469. scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
  470. scp->result = SAM_STAT_CHECK_CONDITION;
  471. memcpy(scp->sense_buffer, &req->sg_list,
  472. min_t(size_t, SCSI_SENSE_BUFFERSIZE,
  473. le32_to_cpu(req->dataxfer_length)));
  474. break;
  475. default:
  476. scp->result = ((DRIVER_INVALID|SUGGEST_ABORT)<<24) |
  477. (DID_ABORT<<16);
  478. break;
  479. }
  480. dprintk("scsi_done(%p)\n", scp);
  481. scp->scsi_done(scp);
  482. free_req(hba, &hba->reqs[tag]);
  483. }
  484. static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
  485. {
  486. struct hpt_iop_request_scsi_command *req;
  487. u32 tag;
  488. if (hba->iopintf_v2) {
  489. tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
  490. req = hba->reqs[tag].req_virt;
  491. if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
  492. req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
  493. } else {
  494. tag = _tag;
  495. req = hba->reqs[tag].req_virt;
  496. }
  497. hptiop_finish_scsi_req(hba, tag, req);
  498. }
  499. void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
  500. {
  501. struct hpt_iop_request_header __iomem *req;
  502. struct hpt_iop_request_ioctl_command __iomem *p;
  503. struct hpt_ioctl_k *arg;
  504. req = (struct hpt_iop_request_header __iomem *)
  505. ((unsigned long)hba->u.itl.iop + tag);
  506. dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
  507. "result=%d, context=0x%x tag=%d\n",
  508. req, readl(&req->type), readl(&req->result),
  509. readl(&req->context), tag);
  510. BUG_ON(!readl(&req->result));
  511. BUG_ON(readl(&req->type) != IOP_REQUEST_TYPE_IOCTL_COMMAND);
  512. p = (struct hpt_iop_request_ioctl_command __iomem *)req;
  513. arg = (struct hpt_ioctl_k *)(unsigned long)
  514. (readl(&req->context) |
  515. ((u64)readl(&req->context_hi32)<<32));
  516. if (readl(&req->result) == IOP_RESULT_SUCCESS) {
  517. arg->result = HPT_IOCTL_RESULT_OK;
  518. if (arg->outbuf_size)
  519. memcpy_fromio(arg->outbuf,
  520. &p->buf[(readl(&p->inbuf_size) + 3)& ~3],
  521. arg->outbuf_size);
  522. if (arg->bytes_returned)
  523. *arg->bytes_returned = arg->outbuf_size;
  524. }
  525. else
  526. arg->result = HPT_IOCTL_RESULT_FAILED;
  527. arg->done(arg);
  528. writel(tag, &hba->u.itl.iop->outbound_queue);
  529. }
  530. static irqreturn_t hptiop_intr(int irq, void *dev_id)
  531. {
  532. struct hptiop_hba *hba = dev_id;
  533. int handled;
  534. unsigned long flags;
  535. spin_lock_irqsave(hba->host->host_lock, flags);
  536. handled = hba->ops->iop_intr(hba);
  537. spin_unlock_irqrestore(hba->host->host_lock, flags);
  538. return handled;
  539. }
  540. static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
  541. {
  542. struct Scsi_Host *host = scp->device->host;
  543. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  544. struct scatterlist *sg;
  545. int idx, nseg;
  546. nseg = scsi_dma_map(scp);
  547. BUG_ON(nseg < 0);
  548. if (!nseg)
  549. return 0;
  550. HPT_SCP(scp)->sgcnt = nseg;
  551. HPT_SCP(scp)->mapped = 1;
  552. BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
  553. scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
  554. psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg));
  555. psg[idx].size = cpu_to_le32(sg_dma_len(sg));
  556. psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
  557. cpu_to_le32(1) : 0;
  558. }
  559. return HPT_SCP(scp)->sgcnt;
  560. }
  561. static void hptiop_post_req_itl(struct hptiop_hba *hba,
  562. struct hptiop_request *_req)
  563. {
  564. struct hpt_iop_request_header *reqhdr = _req->req_virt;
  565. reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
  566. (u32)_req->index);
  567. reqhdr->context_hi32 = 0;
  568. if (hba->iopintf_v2) {
  569. u32 size, size_bits;
  570. size = le32_to_cpu(reqhdr->size);
  571. if (size < 256)
  572. size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
  573. else if (size < 512)
  574. size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
  575. else
  576. size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
  577. IOPMU_QUEUE_ADDR_HOST_BIT;
  578. writel(_req->req_shifted_phy | size_bits,
  579. &hba->u.itl.iop->inbound_queue);
  580. } else
  581. writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
  582. &hba->u.itl.iop->inbound_queue);
  583. }
  584. static void hptiop_post_req_mv(struct hptiop_hba *hba,
  585. struct hptiop_request *_req)
  586. {
  587. struct hpt_iop_request_header *reqhdr = _req->req_virt;
  588. u32 size, size_bit;
  589. reqhdr->context = cpu_to_le32(_req->index<<8 |
  590. IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
  591. reqhdr->context_hi32 = 0;
  592. size = le32_to_cpu(reqhdr->size);
  593. if (size <= 256)
  594. size_bit = 0;
  595. else if (size <= 256*2)
  596. size_bit = 1;
  597. else if (size <= 256*3)
  598. size_bit = 2;
  599. else
  600. size_bit = 3;
  601. mv_inbound_write((_req->req_shifted_phy << 5) |
  602. MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
  603. }
  604. static int hptiop_queuecommand(struct scsi_cmnd *scp,
  605. void (*done)(struct scsi_cmnd *))
  606. {
  607. struct Scsi_Host *host = scp->device->host;
  608. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  609. struct hpt_iop_request_scsi_command *req;
  610. int sg_count = 0;
  611. struct hptiop_request *_req;
  612. BUG_ON(!done);
  613. scp->scsi_done = done;
  614. _req = get_req(hba);
  615. if (_req == NULL) {
  616. dprintk("hptiop_queuecmd : no free req\n");
  617. return SCSI_MLQUEUE_HOST_BUSY;
  618. }
  619. _req->scp = scp;
  620. dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%d cdb=(%x-%x-%x) "
  621. "req_index=%d, req=%p\n",
  622. scp,
  623. host->host_no, scp->device->channel,
  624. scp->device->id, scp->device->lun,
  625. *((u32 *)&scp->cmnd),
  626. *((u32 *)&scp->cmnd + 1),
  627. *((u32 *)&scp->cmnd + 2),
  628. _req->index, _req->req_virt);
  629. scp->result = 0;
  630. if (scp->device->channel || scp->device->lun ||
  631. scp->device->id > hba->max_devices) {
  632. scp->result = DID_BAD_TARGET << 16;
  633. free_req(hba, _req);
  634. goto cmd_done;
  635. }
  636. req = _req->req_virt;
  637. /* build S/G table */
  638. sg_count = hptiop_buildsgl(scp, req->sg_list);
  639. if (!sg_count)
  640. HPT_SCP(scp)->mapped = 0;
  641. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  642. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
  643. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  644. req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
  645. req->channel = scp->device->channel;
  646. req->target = scp->device->id;
  647. req->lun = scp->device->lun;
  648. req->header.size = cpu_to_le32(
  649. sizeof(struct hpt_iop_request_scsi_command)
  650. - sizeof(struct hpt_iopsg)
  651. + sg_count * sizeof(struct hpt_iopsg));
  652. memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
  653. hba->ops->post_req(hba, _req);
  654. return 0;
  655. cmd_done:
  656. dprintk("scsi_done(scp=%p)\n", scp);
  657. scp->scsi_done(scp);
  658. return 0;
  659. }
  660. static const char *hptiop_info(struct Scsi_Host *host)
  661. {
  662. return driver_name_long;
  663. }
  664. static int hptiop_reset_hba(struct hptiop_hba *hba)
  665. {
  666. if (atomic_xchg(&hba->resetting, 1) == 0) {
  667. atomic_inc(&hba->reset_count);
  668. hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
  669. }
  670. wait_event_timeout(hba->reset_wq,
  671. atomic_read(&hba->resetting) == 0, 60 * HZ);
  672. if (atomic_read(&hba->resetting)) {
  673. /* IOP is in unkown state, abort reset */
  674. printk(KERN_ERR "scsi%d: reset failed\n", hba->host->host_no);
  675. return -1;
  676. }
  677. if (iop_send_sync_msg(hba,
  678. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
  679. dprintk("scsi%d: fail to start background task\n",
  680. hba->host->host_no);
  681. }
  682. return 0;
  683. }
  684. static int hptiop_reset(struct scsi_cmnd *scp)
  685. {
  686. struct Scsi_Host * host = scp->device->host;
  687. struct hptiop_hba * hba = (struct hptiop_hba *)host->hostdata;
  688. printk(KERN_WARNING "hptiop_reset(%d/%d/%d) scp=%p\n",
  689. scp->device->host->host_no, scp->device->channel,
  690. scp->device->id, scp);
  691. return hptiop_reset_hba(hba)? FAILED : SUCCESS;
  692. }
  693. static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
  694. int queue_depth)
  695. {
  696. struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
  697. if (queue_depth > hba->max_requests)
  698. queue_depth = hba->max_requests;
  699. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
  700. return queue_depth;
  701. }
  702. static ssize_t hptiop_show_version(struct class_device *class_dev, char *buf)
  703. {
  704. return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
  705. }
  706. static ssize_t hptiop_show_fw_version(struct class_device *class_dev, char *buf)
  707. {
  708. struct Scsi_Host *host = class_to_shost(class_dev);
  709. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  710. return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
  711. hba->firmware_version >> 24,
  712. (hba->firmware_version >> 16) & 0xff,
  713. (hba->firmware_version >> 8) & 0xff,
  714. hba->firmware_version & 0xff);
  715. }
  716. static struct class_device_attribute hptiop_attr_version = {
  717. .attr = {
  718. .name = "driver-version",
  719. .mode = S_IRUGO,
  720. },
  721. .show = hptiop_show_version,
  722. };
  723. static struct class_device_attribute hptiop_attr_fw_version = {
  724. .attr = {
  725. .name = "firmware-version",
  726. .mode = S_IRUGO,
  727. },
  728. .show = hptiop_show_fw_version,
  729. };
  730. static struct class_device_attribute *hptiop_attrs[] = {
  731. &hptiop_attr_version,
  732. &hptiop_attr_fw_version,
  733. NULL
  734. };
  735. static struct scsi_host_template driver_template = {
  736. .module = THIS_MODULE,
  737. .name = driver_name,
  738. .queuecommand = hptiop_queuecommand,
  739. .eh_device_reset_handler = hptiop_reset,
  740. .eh_bus_reset_handler = hptiop_reset,
  741. .info = hptiop_info,
  742. .emulated = 0,
  743. .use_clustering = ENABLE_CLUSTERING,
  744. .proc_name = driver_name,
  745. .shost_attrs = hptiop_attrs,
  746. .this_id = -1,
  747. .change_queue_depth = hptiop_adjust_disk_queue_depth,
  748. };
  749. static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
  750. {
  751. hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
  752. 0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
  753. if (hba->u.mv.internal_req)
  754. return 0;
  755. else
  756. return -1;
  757. }
  758. static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
  759. {
  760. if (hba->u.mv.internal_req) {
  761. dma_free_coherent(&hba->pcidev->dev, 0x800,
  762. hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
  763. return 0;
  764. } else
  765. return -1;
  766. }
  767. static int __devinit hptiop_probe(struct pci_dev *pcidev,
  768. const struct pci_device_id *id)
  769. {
  770. struct Scsi_Host *host = NULL;
  771. struct hptiop_hba *hba;
  772. struct hpt_iop_request_get_config iop_config;
  773. struct hpt_iop_request_set_config set_config;
  774. dma_addr_t start_phy;
  775. void *start_virt;
  776. u32 offset, i, req_size;
  777. dprintk("hptiop_probe(%p)\n", pcidev);
  778. if (pci_enable_device(pcidev)) {
  779. printk(KERN_ERR "hptiop: fail to enable pci device\n");
  780. return -ENODEV;
  781. }
  782. printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
  783. pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
  784. pcidev->irq);
  785. pci_set_master(pcidev);
  786. /* Enable 64bit DMA if possible */
  787. if (pci_set_dma_mask(pcidev, DMA_64BIT_MASK)) {
  788. if (pci_set_dma_mask(pcidev, DMA_32BIT_MASK)) {
  789. printk(KERN_ERR "hptiop: fail to set dma_mask\n");
  790. goto disable_pci_device;
  791. }
  792. }
  793. if (pci_request_regions(pcidev, driver_name)) {
  794. printk(KERN_ERR "hptiop: pci_request_regions failed\n");
  795. goto disable_pci_device;
  796. }
  797. host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
  798. if (!host) {
  799. printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
  800. goto free_pci_regions;
  801. }
  802. hba = (struct hptiop_hba *)host->hostdata;
  803. hba->ops = (struct hptiop_adapter_ops *)id->driver_data;
  804. hba->pcidev = pcidev;
  805. hba->host = host;
  806. hba->initialized = 0;
  807. hba->iopintf_v2 = 0;
  808. atomic_set(&hba->resetting, 0);
  809. atomic_set(&hba->reset_count, 0);
  810. init_waitqueue_head(&hba->reset_wq);
  811. init_waitqueue_head(&hba->ioctl_wq);
  812. host->max_lun = 1;
  813. host->max_channel = 0;
  814. host->io_port = 0;
  815. host->n_io_port = 0;
  816. host->irq = pcidev->irq;
  817. if (hba->ops->map_pci_bar(hba))
  818. goto free_scsi_host;
  819. if (hba->ops->iop_wait_ready(hba, 20000)) {
  820. printk(KERN_ERR "scsi%d: firmware not ready\n",
  821. hba->host->host_no);
  822. goto unmap_pci_bar;
  823. }
  824. if (hba->ops->internal_memalloc) {
  825. if (hba->ops->internal_memalloc(hba)) {
  826. printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
  827. hba->host->host_no);
  828. goto unmap_pci_bar;
  829. }
  830. }
  831. if (hba->ops->get_config(hba, &iop_config)) {
  832. printk(KERN_ERR "scsi%d: get config failed\n",
  833. hba->host->host_no);
  834. goto unmap_pci_bar;
  835. }
  836. hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
  837. HPTIOP_MAX_REQUESTS);
  838. hba->max_devices = le32_to_cpu(iop_config.max_devices);
  839. hba->max_request_size = le32_to_cpu(iop_config.request_size);
  840. hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
  841. hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
  842. hba->interface_version = le32_to_cpu(iop_config.interface_version);
  843. hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
  844. if (hba->firmware_version > 0x01020000 ||
  845. hba->interface_version > 0x01020000)
  846. hba->iopintf_v2 = 1;
  847. host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
  848. host->max_id = le32_to_cpu(iop_config.max_devices);
  849. host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
  850. host->can_queue = le32_to_cpu(iop_config.max_requests);
  851. host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
  852. host->max_cmd_len = 16;
  853. req_size = sizeof(struct hpt_iop_request_scsi_command)
  854. + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
  855. if ((req_size & 0x1f) != 0)
  856. req_size = (req_size + 0x1f) & ~0x1f;
  857. memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
  858. set_config.iop_id = cpu_to_le32(host->host_no);
  859. set_config.vbus_id = cpu_to_le16(host->host_no);
  860. set_config.max_host_request_size = cpu_to_le16(req_size);
  861. if (hba->ops->set_config(hba, &set_config)) {
  862. printk(KERN_ERR "scsi%d: set config failed\n",
  863. hba->host->host_no);
  864. goto unmap_pci_bar;
  865. }
  866. pci_set_drvdata(pcidev, host);
  867. if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
  868. driver_name, hba)) {
  869. printk(KERN_ERR "scsi%d: request irq %d failed\n",
  870. hba->host->host_no, pcidev->irq);
  871. goto unmap_pci_bar;
  872. }
  873. /* Allocate request mem */
  874. dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
  875. hba->req_size = req_size;
  876. start_virt = dma_alloc_coherent(&pcidev->dev,
  877. hba->req_size*hba->max_requests + 0x20,
  878. &start_phy, GFP_KERNEL);
  879. if (!start_virt) {
  880. printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
  881. hba->host->host_no);
  882. goto free_request_irq;
  883. }
  884. hba->dma_coherent = start_virt;
  885. hba->dma_coherent_handle = start_phy;
  886. if ((start_phy & 0x1f) != 0)
  887. {
  888. offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
  889. start_phy += offset;
  890. start_virt += offset;
  891. }
  892. hba->req_list = start_virt;
  893. for (i = 0; i < hba->max_requests; i++) {
  894. hba->reqs[i].next = NULL;
  895. hba->reqs[i].req_virt = start_virt;
  896. hba->reqs[i].req_shifted_phy = start_phy >> 5;
  897. hba->reqs[i].index = i;
  898. free_req(hba, &hba->reqs[i]);
  899. start_virt = (char *)start_virt + hba->req_size;
  900. start_phy = start_phy + hba->req_size;
  901. }
  902. /* Enable Interrupt and start background task */
  903. if (hptiop_initialize_iop(hba))
  904. goto free_request_mem;
  905. if (scsi_add_host(host, &pcidev->dev)) {
  906. printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
  907. hba->host->host_no);
  908. goto free_request_mem;
  909. }
  910. scsi_scan_host(host);
  911. dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
  912. return 0;
  913. free_request_mem:
  914. dma_free_coherent(&hba->pcidev->dev,
  915. hba->req_size * hba->max_requests + 0x20,
  916. hba->dma_coherent, hba->dma_coherent_handle);
  917. free_request_irq:
  918. free_irq(hba->pcidev->irq, hba);
  919. unmap_pci_bar:
  920. if (hba->ops->internal_memfree)
  921. hba->ops->internal_memfree(hba);
  922. hba->ops->unmap_pci_bar(hba);
  923. free_scsi_host:
  924. scsi_host_put(host);
  925. free_pci_regions:
  926. pci_release_regions(pcidev);
  927. disable_pci_device:
  928. pci_disable_device(pcidev);
  929. dprintk("scsi%d: hptiop_probe fail\n", host->host_no);
  930. return -ENODEV;
  931. }
  932. static void hptiop_shutdown(struct pci_dev *pcidev)
  933. {
  934. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  935. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  936. dprintk("hptiop_shutdown(%p)\n", hba);
  937. /* stop the iop */
  938. if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
  939. printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
  940. hba->host->host_no);
  941. /* disable all outbound interrupts */
  942. hba->ops->disable_intr(hba);
  943. }
  944. static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
  945. {
  946. u32 int_mask;
  947. int_mask = readl(&hba->u.itl.iop->outbound_intmask);
  948. writel(int_mask |
  949. IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
  950. &hba->u.itl.iop->outbound_intmask);
  951. readl(&hba->u.itl.iop->outbound_intmask);
  952. }
  953. static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
  954. {
  955. writel(0, &hba->u.mv.regs->outbound_intmask);
  956. readl(&hba->u.mv.regs->outbound_intmask);
  957. }
  958. static void hptiop_remove(struct pci_dev *pcidev)
  959. {
  960. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  961. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  962. dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
  963. scsi_remove_host(host);
  964. hptiop_shutdown(pcidev);
  965. free_irq(hba->pcidev->irq, hba);
  966. dma_free_coherent(&hba->pcidev->dev,
  967. hba->req_size * hba->max_requests + 0x20,
  968. hba->dma_coherent,
  969. hba->dma_coherent_handle);
  970. if (hba->ops->internal_memfree)
  971. hba->ops->internal_memfree(hba);
  972. hba->ops->unmap_pci_bar(hba);
  973. pci_release_regions(hba->pcidev);
  974. pci_set_drvdata(hba->pcidev, NULL);
  975. pci_disable_device(hba->pcidev);
  976. scsi_host_put(host);
  977. }
  978. static struct hptiop_adapter_ops hptiop_itl_ops = {
  979. .iop_wait_ready = iop_wait_ready_itl,
  980. .internal_memalloc = 0,
  981. .internal_memfree = 0,
  982. .map_pci_bar = hptiop_map_pci_bar_itl,
  983. .unmap_pci_bar = hptiop_unmap_pci_bar_itl,
  984. .enable_intr = hptiop_enable_intr_itl,
  985. .disable_intr = hptiop_disable_intr_itl,
  986. .get_config = iop_get_config_itl,
  987. .set_config = iop_set_config_itl,
  988. .iop_intr = iop_intr_itl,
  989. .post_msg = hptiop_post_msg_itl,
  990. .post_req = hptiop_post_req_itl,
  991. };
  992. static struct hptiop_adapter_ops hptiop_mv_ops = {
  993. .iop_wait_ready = iop_wait_ready_mv,
  994. .internal_memalloc = hptiop_internal_memalloc_mv,
  995. .internal_memfree = hptiop_internal_memfree_mv,
  996. .map_pci_bar = hptiop_map_pci_bar_mv,
  997. .unmap_pci_bar = hptiop_unmap_pci_bar_mv,
  998. .enable_intr = hptiop_enable_intr_mv,
  999. .disable_intr = hptiop_disable_intr_mv,
  1000. .get_config = iop_get_config_mv,
  1001. .set_config = iop_set_config_mv,
  1002. .iop_intr = iop_intr_mv,
  1003. .post_msg = hptiop_post_msg_mv,
  1004. .post_req = hptiop_post_req_mv,
  1005. };
  1006. static struct pci_device_id hptiop_id_table[] = {
  1007. { PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
  1008. { PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
  1009. { PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
  1010. { PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
  1011. { PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
  1012. { PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
  1013. { PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
  1014. { PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
  1015. { PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
  1016. { PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
  1017. { PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
  1018. { PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
  1019. { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
  1020. {},
  1021. };
  1022. MODULE_DEVICE_TABLE(pci, hptiop_id_table);
  1023. static struct pci_driver hptiop_pci_driver = {
  1024. .name = driver_name,
  1025. .id_table = hptiop_id_table,
  1026. .probe = hptiop_probe,
  1027. .remove = hptiop_remove,
  1028. .shutdown = hptiop_shutdown,
  1029. };
  1030. static int __init hptiop_module_init(void)
  1031. {
  1032. printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
  1033. return pci_register_driver(&hptiop_pci_driver);
  1034. }
  1035. static void __exit hptiop_module_exit(void)
  1036. {
  1037. pci_unregister_driver(&hptiop_pci_driver);
  1038. }
  1039. module_init(hptiop_module_init);
  1040. module_exit(hptiop_module_exit);
  1041. MODULE_LICENSE("GPL");