hptiop.c 34 KB

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