hptiop.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. /*
  2. * HighPoint RR3xxx/4xxx controller driver for Linux
  3. * Copyright (C) 2006-2012 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/gfp.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.8";
  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 int iop_wait_ready_mvfrey(struct hptiop_hba *hba, u32 millisec)
  71. {
  72. return iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_NOP, millisec);
  73. }
  74. static void hptiop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
  75. {
  76. if (tag & IOPMU_QUEUE_ADDR_HOST_BIT)
  77. hptiop_host_request_callback_itl(hba,
  78. tag & ~IOPMU_QUEUE_ADDR_HOST_BIT);
  79. else
  80. hptiop_iop_request_callback_itl(hba, tag);
  81. }
  82. static void hptiop_drain_outbound_queue_itl(struct hptiop_hba *hba)
  83. {
  84. u32 req;
  85. while ((req = readl(&hba->u.itl.iop->outbound_queue)) !=
  86. IOPMU_QUEUE_EMPTY) {
  87. if (req & IOPMU_QUEUE_MASK_HOST_BITS)
  88. hptiop_request_callback_itl(hba, req);
  89. else {
  90. struct hpt_iop_request_header __iomem * p;
  91. p = (struct hpt_iop_request_header __iomem *)
  92. ((char __iomem *)hba->u.itl.iop + req);
  93. if (readl(&p->flags) & IOP_REQUEST_FLAG_SYNC_REQUEST) {
  94. if (readl(&p->context))
  95. hptiop_request_callback_itl(hba, req);
  96. else
  97. writel(1, &p->context);
  98. }
  99. else
  100. hptiop_request_callback_itl(hba, req);
  101. }
  102. }
  103. }
  104. static int iop_intr_itl(struct hptiop_hba *hba)
  105. {
  106. struct hpt_iopmu_itl __iomem *iop = hba->u.itl.iop;
  107. void __iomem *plx = hba->u.itl.plx;
  108. u32 status;
  109. int ret = 0;
  110. if (plx && readl(plx + 0x11C5C) & 0xf)
  111. writel(1, plx + 0x11C60);
  112. status = readl(&iop->outbound_intstatus);
  113. if (status & IOPMU_OUTBOUND_INT_MSG0) {
  114. u32 msg = readl(&iop->outbound_msgaddr0);
  115. dprintk("received outbound msg %x\n", msg);
  116. writel(IOPMU_OUTBOUND_INT_MSG0, &iop->outbound_intstatus);
  117. hptiop_message_callback(hba, msg);
  118. ret = 1;
  119. }
  120. if (status & IOPMU_OUTBOUND_INT_POSTQUEUE) {
  121. hptiop_drain_outbound_queue_itl(hba);
  122. ret = 1;
  123. }
  124. return ret;
  125. }
  126. static u64 mv_outbound_read(struct hpt_iopmu_mv __iomem *mu)
  127. {
  128. u32 outbound_tail = readl(&mu->outbound_tail);
  129. u32 outbound_head = readl(&mu->outbound_head);
  130. if (outbound_tail != outbound_head) {
  131. u64 p;
  132. memcpy_fromio(&p, &mu->outbound_q[mu->outbound_tail], 8);
  133. outbound_tail++;
  134. if (outbound_tail == MVIOP_QUEUE_LEN)
  135. outbound_tail = 0;
  136. writel(outbound_tail, &mu->outbound_tail);
  137. return p;
  138. } else
  139. return 0;
  140. }
  141. static void mv_inbound_write(u64 p, struct hptiop_hba *hba)
  142. {
  143. u32 inbound_head = readl(&hba->u.mv.mu->inbound_head);
  144. u32 head = inbound_head + 1;
  145. if (head == MVIOP_QUEUE_LEN)
  146. head = 0;
  147. memcpy_toio(&hba->u.mv.mu->inbound_q[inbound_head], &p, 8);
  148. writel(head, &hba->u.mv.mu->inbound_head);
  149. writel(MVIOP_MU_INBOUND_INT_POSTQUEUE,
  150. &hba->u.mv.regs->inbound_doorbell);
  151. }
  152. static void hptiop_request_callback_mv(struct hptiop_hba *hba, u64 tag)
  153. {
  154. u32 req_type = (tag >> 5) & 0x7;
  155. struct hpt_iop_request_scsi_command *req;
  156. dprintk("hptiop_request_callback_mv: tag=%llx\n", tag);
  157. BUG_ON((tag & MVIOP_MU_QUEUE_REQUEST_RETURN_CONTEXT) == 0);
  158. switch (req_type) {
  159. case IOP_REQUEST_TYPE_GET_CONFIG:
  160. case IOP_REQUEST_TYPE_SET_CONFIG:
  161. hba->msg_done = 1;
  162. break;
  163. case IOP_REQUEST_TYPE_SCSI_COMMAND:
  164. req = hba->reqs[tag >> 8].req_virt;
  165. if (likely(tag & MVIOP_MU_QUEUE_REQUEST_RESULT_BIT))
  166. req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
  167. hptiop_finish_scsi_req(hba, tag>>8, req);
  168. break;
  169. default:
  170. break;
  171. }
  172. }
  173. static int iop_intr_mv(struct hptiop_hba *hba)
  174. {
  175. u32 status;
  176. int ret = 0;
  177. status = readl(&hba->u.mv.regs->outbound_doorbell);
  178. writel(~status, &hba->u.mv.regs->outbound_doorbell);
  179. if (status & MVIOP_MU_OUTBOUND_INT_MSG) {
  180. u32 msg;
  181. msg = readl(&hba->u.mv.mu->outbound_msg);
  182. dprintk("received outbound msg %x\n", msg);
  183. hptiop_message_callback(hba, msg);
  184. ret = 1;
  185. }
  186. if (status & MVIOP_MU_OUTBOUND_INT_POSTQUEUE) {
  187. u64 tag;
  188. while ((tag = mv_outbound_read(hba->u.mv.mu)))
  189. hptiop_request_callback_mv(hba, tag);
  190. ret = 1;
  191. }
  192. return ret;
  193. }
  194. static void hptiop_request_callback_mvfrey(struct hptiop_hba *hba, u32 _tag)
  195. {
  196. u32 req_type = _tag & 0xf;
  197. struct hpt_iop_request_scsi_command *req;
  198. switch (req_type) {
  199. case IOP_REQUEST_TYPE_GET_CONFIG:
  200. case IOP_REQUEST_TYPE_SET_CONFIG:
  201. hba->msg_done = 1;
  202. break;
  203. case IOP_REQUEST_TYPE_SCSI_COMMAND:
  204. req = hba->reqs[(_tag >> 4) & 0xff].req_virt;
  205. if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
  206. req->header.result = IOP_RESULT_SUCCESS;
  207. hptiop_finish_scsi_req(hba, (_tag >> 4) & 0xff, req);
  208. break;
  209. default:
  210. break;
  211. }
  212. }
  213. static int iop_intr_mvfrey(struct hptiop_hba *hba)
  214. {
  215. u32 _tag, status, cptr, cur_rptr;
  216. int ret = 0;
  217. if (hba->initialized)
  218. writel(0, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
  219. status = readl(&(hba->u.mvfrey.mu->f0_doorbell));
  220. if (status) {
  221. writel(status, &(hba->u.mvfrey.mu->f0_doorbell));
  222. if (status & CPU_TO_F0_DRBL_MSG_BIT) {
  223. u32 msg = readl(&(hba->u.mvfrey.mu->cpu_to_f0_msg_a));
  224. dprintk("received outbound msg %x\n", msg);
  225. hptiop_message_callback(hba, msg);
  226. }
  227. ret = 1;
  228. }
  229. status = readl(&(hba->u.mvfrey.mu->isr_cause));
  230. if (status) {
  231. writel(status, &(hba->u.mvfrey.mu->isr_cause));
  232. do {
  233. cptr = *hba->u.mvfrey.outlist_cptr & 0xff;
  234. cur_rptr = hba->u.mvfrey.outlist_rptr;
  235. while (cur_rptr != cptr) {
  236. cur_rptr++;
  237. if (cur_rptr == hba->u.mvfrey.list_count)
  238. cur_rptr = 0;
  239. _tag = hba->u.mvfrey.outlist[cur_rptr].val;
  240. BUG_ON(!(_tag & IOPMU_QUEUE_MASK_HOST_BITS));
  241. hptiop_request_callback_mvfrey(hba, _tag);
  242. ret = 1;
  243. }
  244. hba->u.mvfrey.outlist_rptr = cur_rptr;
  245. } while (cptr != (*hba->u.mvfrey.outlist_cptr & 0xff));
  246. }
  247. if (hba->initialized)
  248. writel(0x1010, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
  249. return ret;
  250. }
  251. static int iop_send_sync_request_itl(struct hptiop_hba *hba,
  252. void __iomem *_req, u32 millisec)
  253. {
  254. struct hpt_iop_request_header __iomem *req = _req;
  255. u32 i;
  256. writel(readl(&req->flags) | IOP_REQUEST_FLAG_SYNC_REQUEST, &req->flags);
  257. writel(0, &req->context);
  258. writel((unsigned long)req - (unsigned long)hba->u.itl.iop,
  259. &hba->u.itl.iop->inbound_queue);
  260. readl(&hba->u.itl.iop->outbound_intstatus);
  261. for (i = 0; i < millisec; i++) {
  262. iop_intr_itl(hba);
  263. if (readl(&req->context))
  264. return 0;
  265. msleep(1);
  266. }
  267. return -1;
  268. }
  269. static int iop_send_sync_request_mv(struct hptiop_hba *hba,
  270. u32 size_bits, u32 millisec)
  271. {
  272. struct hpt_iop_request_header *reqhdr = hba->u.mv.internal_req;
  273. u32 i;
  274. hba->msg_done = 0;
  275. reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
  276. mv_inbound_write(hba->u.mv.internal_req_phy |
  277. MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bits, hba);
  278. for (i = 0; i < millisec; i++) {
  279. iop_intr_mv(hba);
  280. if (hba->msg_done)
  281. return 0;
  282. msleep(1);
  283. }
  284. return -1;
  285. }
  286. static int iop_send_sync_request_mvfrey(struct hptiop_hba *hba,
  287. u32 size_bits, u32 millisec)
  288. {
  289. struct hpt_iop_request_header *reqhdr =
  290. hba->u.mvfrey.internal_req.req_virt;
  291. u32 i;
  292. hba->msg_done = 0;
  293. reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_SYNC_REQUEST);
  294. hba->ops->post_req(hba, &(hba->u.mvfrey.internal_req));
  295. for (i = 0; i < millisec; i++) {
  296. iop_intr_mvfrey(hba);
  297. if (hba->msg_done)
  298. break;
  299. msleep(1);
  300. }
  301. return hba->msg_done ? 0 : -1;
  302. }
  303. static void hptiop_post_msg_itl(struct hptiop_hba *hba, u32 msg)
  304. {
  305. writel(msg, &hba->u.itl.iop->inbound_msgaddr0);
  306. readl(&hba->u.itl.iop->outbound_intstatus);
  307. }
  308. static void hptiop_post_msg_mv(struct hptiop_hba *hba, u32 msg)
  309. {
  310. writel(msg, &hba->u.mv.mu->inbound_msg);
  311. writel(MVIOP_MU_INBOUND_INT_MSG, &hba->u.mv.regs->inbound_doorbell);
  312. readl(&hba->u.mv.regs->inbound_doorbell);
  313. }
  314. static void hptiop_post_msg_mvfrey(struct hptiop_hba *hba, u32 msg)
  315. {
  316. writel(msg, &(hba->u.mvfrey.mu->f0_to_cpu_msg_a));
  317. readl(&(hba->u.mvfrey.mu->f0_to_cpu_msg_a));
  318. }
  319. static int iop_send_sync_msg(struct hptiop_hba *hba, u32 msg, u32 millisec)
  320. {
  321. u32 i;
  322. hba->msg_done = 0;
  323. hba->ops->disable_intr(hba);
  324. hba->ops->post_msg(hba, msg);
  325. for (i = 0; i < millisec; i++) {
  326. spin_lock_irq(hba->host->host_lock);
  327. hba->ops->iop_intr(hba);
  328. spin_unlock_irq(hba->host->host_lock);
  329. if (hba->msg_done)
  330. break;
  331. msleep(1);
  332. }
  333. hba->ops->enable_intr(hba);
  334. return hba->msg_done? 0 : -1;
  335. }
  336. static int iop_get_config_itl(struct hptiop_hba *hba,
  337. struct hpt_iop_request_get_config *config)
  338. {
  339. u32 req32;
  340. struct hpt_iop_request_get_config __iomem *req;
  341. req32 = readl(&hba->u.itl.iop->inbound_queue);
  342. if (req32 == IOPMU_QUEUE_EMPTY)
  343. return -1;
  344. req = (struct hpt_iop_request_get_config __iomem *)
  345. ((unsigned long)hba->u.itl.iop + req32);
  346. writel(0, &req->header.flags);
  347. writel(IOP_REQUEST_TYPE_GET_CONFIG, &req->header.type);
  348. writel(sizeof(struct hpt_iop_request_get_config), &req->header.size);
  349. writel(IOP_RESULT_PENDING, &req->header.result);
  350. if (iop_send_sync_request_itl(hba, req, 20000)) {
  351. dprintk("Get config send cmd failed\n");
  352. return -1;
  353. }
  354. memcpy_fromio(config, req, sizeof(*config));
  355. writel(req32, &hba->u.itl.iop->outbound_queue);
  356. return 0;
  357. }
  358. static int iop_get_config_mv(struct hptiop_hba *hba,
  359. struct hpt_iop_request_get_config *config)
  360. {
  361. struct hpt_iop_request_get_config *req = hba->u.mv.internal_req;
  362. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  363. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG);
  364. req->header.size =
  365. cpu_to_le32(sizeof(struct hpt_iop_request_get_config));
  366. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  367. req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_GET_CONFIG<<5);
  368. req->header.context_hi32 = 0;
  369. if (iop_send_sync_request_mv(hba, 0, 20000)) {
  370. dprintk("Get config send cmd failed\n");
  371. return -1;
  372. }
  373. memcpy(config, req, sizeof(struct hpt_iop_request_get_config));
  374. return 0;
  375. }
  376. static int iop_get_config_mvfrey(struct hptiop_hba *hba,
  377. struct hpt_iop_request_get_config *config)
  378. {
  379. struct hpt_iop_request_get_config *info = hba->u.mvfrey.config;
  380. if (info->header.size != sizeof(struct hpt_iop_request_get_config) ||
  381. info->header.type != IOP_REQUEST_TYPE_GET_CONFIG)
  382. return -1;
  383. config->interface_version = info->interface_version;
  384. config->firmware_version = info->firmware_version;
  385. config->max_requests = info->max_requests;
  386. config->request_size = info->request_size;
  387. config->max_sg_count = info->max_sg_count;
  388. config->data_transfer_length = info->data_transfer_length;
  389. config->alignment_mask = info->alignment_mask;
  390. config->max_devices = info->max_devices;
  391. config->sdram_size = info->sdram_size;
  392. return 0;
  393. }
  394. static int iop_set_config_itl(struct hptiop_hba *hba,
  395. struct hpt_iop_request_set_config *config)
  396. {
  397. u32 req32;
  398. struct hpt_iop_request_set_config __iomem *req;
  399. req32 = readl(&hba->u.itl.iop->inbound_queue);
  400. if (req32 == IOPMU_QUEUE_EMPTY)
  401. return -1;
  402. req = (struct hpt_iop_request_set_config __iomem *)
  403. ((unsigned long)hba->u.itl.iop + req32);
  404. memcpy_toio((u8 __iomem *)req + sizeof(struct hpt_iop_request_header),
  405. (u8 *)config + sizeof(struct hpt_iop_request_header),
  406. sizeof(struct hpt_iop_request_set_config) -
  407. sizeof(struct hpt_iop_request_header));
  408. writel(0, &req->header.flags);
  409. writel(IOP_REQUEST_TYPE_SET_CONFIG, &req->header.type);
  410. writel(sizeof(struct hpt_iop_request_set_config), &req->header.size);
  411. writel(IOP_RESULT_PENDING, &req->header.result);
  412. if (iop_send_sync_request_itl(hba, req, 20000)) {
  413. dprintk("Set config send cmd failed\n");
  414. return -1;
  415. }
  416. writel(req32, &hba->u.itl.iop->outbound_queue);
  417. return 0;
  418. }
  419. static int iop_set_config_mv(struct hptiop_hba *hba,
  420. struct hpt_iop_request_set_config *config)
  421. {
  422. struct hpt_iop_request_set_config *req = hba->u.mv.internal_req;
  423. memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
  424. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  425. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
  426. req->header.size =
  427. cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
  428. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  429. req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
  430. req->header.context_hi32 = 0;
  431. if (iop_send_sync_request_mv(hba, 0, 20000)) {
  432. dprintk("Set config send cmd failed\n");
  433. return -1;
  434. }
  435. return 0;
  436. }
  437. static int iop_set_config_mvfrey(struct hptiop_hba *hba,
  438. struct hpt_iop_request_set_config *config)
  439. {
  440. struct hpt_iop_request_set_config *req =
  441. hba->u.mvfrey.internal_req.req_virt;
  442. memcpy(req, config, sizeof(struct hpt_iop_request_set_config));
  443. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  444. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG);
  445. req->header.size =
  446. cpu_to_le32(sizeof(struct hpt_iop_request_set_config));
  447. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  448. req->header.context = cpu_to_le32(IOP_REQUEST_TYPE_SET_CONFIG<<5);
  449. req->header.context_hi32 = 0;
  450. if (iop_send_sync_request_mvfrey(hba, 0, 20000)) {
  451. dprintk("Set config send cmd failed\n");
  452. return -1;
  453. }
  454. return 0;
  455. }
  456. static void hptiop_enable_intr_itl(struct hptiop_hba *hba)
  457. {
  458. writel(~(IOPMU_OUTBOUND_INT_POSTQUEUE | IOPMU_OUTBOUND_INT_MSG0),
  459. &hba->u.itl.iop->outbound_intmask);
  460. }
  461. static void hptiop_enable_intr_mv(struct hptiop_hba *hba)
  462. {
  463. writel(MVIOP_MU_OUTBOUND_INT_POSTQUEUE | MVIOP_MU_OUTBOUND_INT_MSG,
  464. &hba->u.mv.regs->outbound_intmask);
  465. }
  466. static void hptiop_enable_intr_mvfrey(struct hptiop_hba *hba)
  467. {
  468. writel(CPU_TO_F0_DRBL_MSG_BIT, &(hba->u.mvfrey.mu->f0_doorbell_enable));
  469. writel(0x1, &(hba->u.mvfrey.mu->isr_enable));
  470. writel(0x1010, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
  471. }
  472. static int hptiop_initialize_iop(struct hptiop_hba *hba)
  473. {
  474. /* enable interrupts */
  475. hba->ops->enable_intr(hba);
  476. hba->initialized = 1;
  477. /* start background tasks */
  478. if (iop_send_sync_msg(hba,
  479. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
  480. printk(KERN_ERR "scsi%d: fail to start background task\n",
  481. hba->host->host_no);
  482. return -1;
  483. }
  484. return 0;
  485. }
  486. static void __iomem *hptiop_map_pci_bar(struct hptiop_hba *hba, int index)
  487. {
  488. u32 mem_base_phy, length;
  489. void __iomem *mem_base_virt;
  490. struct pci_dev *pcidev = hba->pcidev;
  491. if (!(pci_resource_flags(pcidev, index) & IORESOURCE_MEM)) {
  492. printk(KERN_ERR "scsi%d: pci resource invalid\n",
  493. hba->host->host_no);
  494. return NULL;
  495. }
  496. mem_base_phy = pci_resource_start(pcidev, index);
  497. length = pci_resource_len(pcidev, index);
  498. mem_base_virt = ioremap(mem_base_phy, length);
  499. if (!mem_base_virt) {
  500. printk(KERN_ERR "scsi%d: Fail to ioremap memory space\n",
  501. hba->host->host_no);
  502. return NULL;
  503. }
  504. return mem_base_virt;
  505. }
  506. static int hptiop_map_pci_bar_itl(struct hptiop_hba *hba)
  507. {
  508. struct pci_dev *pcidev = hba->pcidev;
  509. hba->u.itl.iop = hptiop_map_pci_bar(hba, 0);
  510. if (hba->u.itl.iop == NULL)
  511. return -1;
  512. if ((pcidev->device & 0xff00) == 0x4400) {
  513. hba->u.itl.plx = hba->u.itl.iop;
  514. hba->u.itl.iop = hptiop_map_pci_bar(hba, 2);
  515. if (hba->u.itl.iop == NULL) {
  516. iounmap(hba->u.itl.plx);
  517. return -1;
  518. }
  519. }
  520. return 0;
  521. }
  522. static void hptiop_unmap_pci_bar_itl(struct hptiop_hba *hba)
  523. {
  524. if (hba->u.itl.plx)
  525. iounmap(hba->u.itl.plx);
  526. iounmap(hba->u.itl.iop);
  527. }
  528. static int hptiop_map_pci_bar_mv(struct hptiop_hba *hba)
  529. {
  530. hba->u.mv.regs = hptiop_map_pci_bar(hba, 0);
  531. if (hba->u.mv.regs == NULL)
  532. return -1;
  533. hba->u.mv.mu = hptiop_map_pci_bar(hba, 2);
  534. if (hba->u.mv.mu == NULL) {
  535. iounmap(hba->u.mv.regs);
  536. return -1;
  537. }
  538. return 0;
  539. }
  540. static int hptiop_map_pci_bar_mvfrey(struct hptiop_hba *hba)
  541. {
  542. hba->u.mvfrey.config = hptiop_map_pci_bar(hba, 0);
  543. if (hba->u.mvfrey.config == NULL)
  544. return -1;
  545. hba->u.mvfrey.mu = hptiop_map_pci_bar(hba, 2);
  546. if (hba->u.mvfrey.mu == NULL) {
  547. iounmap(hba->u.mvfrey.config);
  548. return -1;
  549. }
  550. return 0;
  551. }
  552. static void hptiop_unmap_pci_bar_mv(struct hptiop_hba *hba)
  553. {
  554. iounmap(hba->u.mv.regs);
  555. iounmap(hba->u.mv.mu);
  556. }
  557. static void hptiop_unmap_pci_bar_mvfrey(struct hptiop_hba *hba)
  558. {
  559. iounmap(hba->u.mvfrey.config);
  560. iounmap(hba->u.mvfrey.mu);
  561. }
  562. static void hptiop_message_callback(struct hptiop_hba *hba, u32 msg)
  563. {
  564. dprintk("iop message 0x%x\n", msg);
  565. if (msg == IOPMU_INBOUND_MSG0_NOP ||
  566. msg == IOPMU_INBOUND_MSG0_RESET_COMM)
  567. hba->msg_done = 1;
  568. if (!hba->initialized)
  569. return;
  570. if (msg == IOPMU_INBOUND_MSG0_RESET) {
  571. atomic_set(&hba->resetting, 0);
  572. wake_up(&hba->reset_wq);
  573. }
  574. else if (msg <= IOPMU_INBOUND_MSG0_MAX)
  575. hba->msg_done = 1;
  576. }
  577. static struct hptiop_request *get_req(struct hptiop_hba *hba)
  578. {
  579. struct hptiop_request *ret;
  580. dprintk("get_req : req=%p\n", hba->req_list);
  581. ret = hba->req_list;
  582. if (ret)
  583. hba->req_list = ret->next;
  584. return ret;
  585. }
  586. static void free_req(struct hptiop_hba *hba, struct hptiop_request *req)
  587. {
  588. dprintk("free_req(%d, %p)\n", req->index, req);
  589. req->next = hba->req_list;
  590. hba->req_list = req;
  591. }
  592. static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
  593. struct hpt_iop_request_scsi_command *req)
  594. {
  595. struct scsi_cmnd *scp;
  596. dprintk("hptiop_finish_scsi_req: req=%p, type=%d, "
  597. "result=%d, context=0x%x tag=%d\n",
  598. req, req->header.type, req->header.result,
  599. req->header.context, tag);
  600. BUG_ON(!req->header.result);
  601. BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));
  602. scp = hba->reqs[tag].scp;
  603. if (HPT_SCP(scp)->mapped)
  604. scsi_dma_unmap(scp);
  605. switch (le32_to_cpu(req->header.result)) {
  606. case IOP_RESULT_SUCCESS:
  607. scsi_set_resid(scp,
  608. scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
  609. scp->result = (DID_OK<<16);
  610. break;
  611. case IOP_RESULT_BAD_TARGET:
  612. scp->result = (DID_BAD_TARGET<<16);
  613. break;
  614. case IOP_RESULT_BUSY:
  615. scp->result = (DID_BUS_BUSY<<16);
  616. break;
  617. case IOP_RESULT_RESET:
  618. scp->result = (DID_RESET<<16);
  619. break;
  620. case IOP_RESULT_FAIL:
  621. scp->result = (DID_ERROR<<16);
  622. break;
  623. case IOP_RESULT_INVALID_REQUEST:
  624. scp->result = (DID_ABORT<<16);
  625. break;
  626. case IOP_RESULT_CHECK_CONDITION:
  627. scsi_set_resid(scp,
  628. scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
  629. scp->result = SAM_STAT_CHECK_CONDITION;
  630. memcpy(scp->sense_buffer, &req->sg_list,
  631. min_t(size_t, SCSI_SENSE_BUFFERSIZE,
  632. le32_to_cpu(req->dataxfer_length)));
  633. goto skip_resid;
  634. break;
  635. default:
  636. scp->result = DRIVER_INVALID << 24 | DID_ABORT << 16;
  637. break;
  638. }
  639. scsi_set_resid(scp,
  640. scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
  641. skip_resid:
  642. dprintk("scsi_done(%p)\n", scp);
  643. scp->scsi_done(scp);
  644. free_req(hba, &hba->reqs[tag]);
  645. }
  646. static void hptiop_host_request_callback_itl(struct hptiop_hba *hba, u32 _tag)
  647. {
  648. struct hpt_iop_request_scsi_command *req;
  649. u32 tag;
  650. if (hba->iopintf_v2) {
  651. tag = _tag & ~IOPMU_QUEUE_REQUEST_RESULT_BIT;
  652. req = hba->reqs[tag].req_virt;
  653. if (likely(_tag & IOPMU_QUEUE_REQUEST_RESULT_BIT))
  654. req->header.result = cpu_to_le32(IOP_RESULT_SUCCESS);
  655. } else {
  656. tag = _tag;
  657. req = hba->reqs[tag].req_virt;
  658. }
  659. hptiop_finish_scsi_req(hba, tag, req);
  660. }
  661. void hptiop_iop_request_callback_itl(struct hptiop_hba *hba, u32 tag)
  662. {
  663. struct hpt_iop_request_header __iomem *req;
  664. struct hpt_iop_request_ioctl_command __iomem *p;
  665. struct hpt_ioctl_k *arg;
  666. req = (struct hpt_iop_request_header __iomem *)
  667. ((unsigned long)hba->u.itl.iop + tag);
  668. dprintk("hptiop_iop_request_callback_itl: req=%p, type=%d, "
  669. "result=%d, context=0x%x tag=%d\n",
  670. req, readl(&req->type), readl(&req->result),
  671. readl(&req->context), tag);
  672. BUG_ON(!readl(&req->result));
  673. BUG_ON(readl(&req->type) != IOP_REQUEST_TYPE_IOCTL_COMMAND);
  674. p = (struct hpt_iop_request_ioctl_command __iomem *)req;
  675. arg = (struct hpt_ioctl_k *)(unsigned long)
  676. (readl(&req->context) |
  677. ((u64)readl(&req->context_hi32)<<32));
  678. if (readl(&req->result) == IOP_RESULT_SUCCESS) {
  679. arg->result = HPT_IOCTL_RESULT_OK;
  680. if (arg->outbuf_size)
  681. memcpy_fromio(arg->outbuf,
  682. &p->buf[(readl(&p->inbuf_size) + 3)& ~3],
  683. arg->outbuf_size);
  684. if (arg->bytes_returned)
  685. *arg->bytes_returned = arg->outbuf_size;
  686. }
  687. else
  688. arg->result = HPT_IOCTL_RESULT_FAILED;
  689. arg->done(arg);
  690. writel(tag, &hba->u.itl.iop->outbound_queue);
  691. }
  692. static irqreturn_t hptiop_intr(int irq, void *dev_id)
  693. {
  694. struct hptiop_hba *hba = dev_id;
  695. int handled;
  696. unsigned long flags;
  697. spin_lock_irqsave(hba->host->host_lock, flags);
  698. handled = hba->ops->iop_intr(hba);
  699. spin_unlock_irqrestore(hba->host->host_lock, flags);
  700. return handled;
  701. }
  702. static int hptiop_buildsgl(struct scsi_cmnd *scp, struct hpt_iopsg *psg)
  703. {
  704. struct Scsi_Host *host = scp->device->host;
  705. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  706. struct scatterlist *sg;
  707. int idx, nseg;
  708. nseg = scsi_dma_map(scp);
  709. BUG_ON(nseg < 0);
  710. if (!nseg)
  711. return 0;
  712. HPT_SCP(scp)->sgcnt = nseg;
  713. HPT_SCP(scp)->mapped = 1;
  714. BUG_ON(HPT_SCP(scp)->sgcnt > hba->max_sg_descriptors);
  715. scsi_for_each_sg(scp, sg, HPT_SCP(scp)->sgcnt, idx) {
  716. psg[idx].pci_address = cpu_to_le64(sg_dma_address(sg)) |
  717. hba->ops->host_phy_flag;
  718. psg[idx].size = cpu_to_le32(sg_dma_len(sg));
  719. psg[idx].eot = (idx == HPT_SCP(scp)->sgcnt - 1) ?
  720. cpu_to_le32(1) : 0;
  721. }
  722. return HPT_SCP(scp)->sgcnt;
  723. }
  724. static void hptiop_post_req_itl(struct hptiop_hba *hba,
  725. struct hptiop_request *_req)
  726. {
  727. struct hpt_iop_request_header *reqhdr = _req->req_virt;
  728. reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
  729. (u32)_req->index);
  730. reqhdr->context_hi32 = 0;
  731. if (hba->iopintf_v2) {
  732. u32 size, size_bits;
  733. size = le32_to_cpu(reqhdr->size);
  734. if (size < 256)
  735. size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT;
  736. else if (size < 512)
  737. size_bits = IOPMU_QUEUE_ADDR_HOST_BIT;
  738. else
  739. size_bits = IOPMU_QUEUE_REQUEST_SIZE_BIT |
  740. IOPMU_QUEUE_ADDR_HOST_BIT;
  741. writel(_req->req_shifted_phy | size_bits,
  742. &hba->u.itl.iop->inbound_queue);
  743. } else
  744. writel(_req->req_shifted_phy | IOPMU_QUEUE_ADDR_HOST_BIT,
  745. &hba->u.itl.iop->inbound_queue);
  746. }
  747. static void hptiop_post_req_mv(struct hptiop_hba *hba,
  748. struct hptiop_request *_req)
  749. {
  750. struct hpt_iop_request_header *reqhdr = _req->req_virt;
  751. u32 size, size_bit;
  752. reqhdr->context = cpu_to_le32(_req->index<<8 |
  753. IOP_REQUEST_TYPE_SCSI_COMMAND<<5);
  754. reqhdr->context_hi32 = 0;
  755. size = le32_to_cpu(reqhdr->size);
  756. if (size <= 256)
  757. size_bit = 0;
  758. else if (size <= 256*2)
  759. size_bit = 1;
  760. else if (size <= 256*3)
  761. size_bit = 2;
  762. else
  763. size_bit = 3;
  764. mv_inbound_write((_req->req_shifted_phy << 5) |
  765. MVIOP_MU_QUEUE_ADDR_HOST_BIT | size_bit, hba);
  766. }
  767. static void hptiop_post_req_mvfrey(struct hptiop_hba *hba,
  768. struct hptiop_request *_req)
  769. {
  770. struct hpt_iop_request_header *reqhdr = _req->req_virt;
  771. u32 index;
  772. reqhdr->flags |= cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT |
  773. IOP_REQUEST_FLAG_ADDR_BITS |
  774. ((_req->req_shifted_phy >> 11) & 0xffff0000));
  775. reqhdr->context = cpu_to_le32(IOPMU_QUEUE_ADDR_HOST_BIT |
  776. (_req->index << 4) | reqhdr->type);
  777. reqhdr->context_hi32 = cpu_to_le32((_req->req_shifted_phy << 5) &
  778. 0xffffffff);
  779. hba->u.mvfrey.inlist_wptr++;
  780. index = hba->u.mvfrey.inlist_wptr & 0x3fff;
  781. if (index == hba->u.mvfrey.list_count) {
  782. index = 0;
  783. hba->u.mvfrey.inlist_wptr &= ~0x3fff;
  784. hba->u.mvfrey.inlist_wptr ^= CL_POINTER_TOGGLE;
  785. }
  786. hba->u.mvfrey.inlist[index].addr =
  787. (dma_addr_t)_req->req_shifted_phy << 5;
  788. hba->u.mvfrey.inlist[index].intrfc_len = (reqhdr->size + 3) / 4;
  789. writel(hba->u.mvfrey.inlist_wptr,
  790. &(hba->u.mvfrey.mu->inbound_write_ptr));
  791. readl(&(hba->u.mvfrey.mu->inbound_write_ptr));
  792. }
  793. static int hptiop_reset_comm_itl(struct hptiop_hba *hba)
  794. {
  795. return 0;
  796. }
  797. static int hptiop_reset_comm_mv(struct hptiop_hba *hba)
  798. {
  799. return 0;
  800. }
  801. static int hptiop_reset_comm_mvfrey(struct hptiop_hba *hba)
  802. {
  803. u32 list_count = hba->u.mvfrey.list_count;
  804. if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_RESET_COMM, 3000))
  805. return -1;
  806. /* wait 100ms for MCU ready */
  807. msleep(100);
  808. writel(cpu_to_le32(hba->u.mvfrey.inlist_phy & 0xffffffff),
  809. &(hba->u.mvfrey.mu->inbound_base));
  810. writel(cpu_to_le32((hba->u.mvfrey.inlist_phy >> 16) >> 16),
  811. &(hba->u.mvfrey.mu->inbound_base_high));
  812. writel(cpu_to_le32(hba->u.mvfrey.outlist_phy & 0xffffffff),
  813. &(hba->u.mvfrey.mu->outbound_base));
  814. writel(cpu_to_le32((hba->u.mvfrey.outlist_phy >> 16) >> 16),
  815. &(hba->u.mvfrey.mu->outbound_base_high));
  816. writel(cpu_to_le32(hba->u.mvfrey.outlist_cptr_phy & 0xffffffff),
  817. &(hba->u.mvfrey.mu->outbound_shadow_base));
  818. writel(cpu_to_le32((hba->u.mvfrey.outlist_cptr_phy >> 16) >> 16),
  819. &(hba->u.mvfrey.mu->outbound_shadow_base_high));
  820. hba->u.mvfrey.inlist_wptr = (list_count - 1) | CL_POINTER_TOGGLE;
  821. *hba->u.mvfrey.outlist_cptr = (list_count - 1) | CL_POINTER_TOGGLE;
  822. hba->u.mvfrey.outlist_rptr = list_count - 1;
  823. return 0;
  824. }
  825. static int hptiop_queuecommand_lck(struct scsi_cmnd *scp,
  826. void (*done)(struct scsi_cmnd *))
  827. {
  828. struct Scsi_Host *host = scp->device->host;
  829. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  830. struct hpt_iop_request_scsi_command *req;
  831. int sg_count = 0;
  832. struct hptiop_request *_req;
  833. BUG_ON(!done);
  834. scp->scsi_done = done;
  835. _req = get_req(hba);
  836. if (_req == NULL) {
  837. dprintk("hptiop_queuecmd : no free req\n");
  838. return SCSI_MLQUEUE_HOST_BUSY;
  839. }
  840. _req->scp = scp;
  841. dprintk("hptiop_queuecmd(scp=%p) %d/%d/%d/%d cdb=(%08x-%08x-%08x-%08x) "
  842. "req_index=%d, req=%p\n",
  843. scp,
  844. host->host_no, scp->device->channel,
  845. scp->device->id, scp->device->lun,
  846. cpu_to_be32(((u32 *)scp->cmnd)[0]),
  847. cpu_to_be32(((u32 *)scp->cmnd)[1]),
  848. cpu_to_be32(((u32 *)scp->cmnd)[2]),
  849. cpu_to_be32(((u32 *)scp->cmnd)[3]),
  850. _req->index, _req->req_virt);
  851. scp->result = 0;
  852. if (scp->device->channel || scp->device->lun ||
  853. scp->device->id > hba->max_devices) {
  854. scp->result = DID_BAD_TARGET << 16;
  855. free_req(hba, _req);
  856. goto cmd_done;
  857. }
  858. req = _req->req_virt;
  859. /* build S/G table */
  860. sg_count = hptiop_buildsgl(scp, req->sg_list);
  861. if (!sg_count)
  862. HPT_SCP(scp)->mapped = 0;
  863. req->header.flags = cpu_to_le32(IOP_REQUEST_FLAG_OUTPUT_CONTEXT);
  864. req->header.type = cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND);
  865. req->header.result = cpu_to_le32(IOP_RESULT_PENDING);
  866. req->dataxfer_length = cpu_to_le32(scsi_bufflen(scp));
  867. req->channel = scp->device->channel;
  868. req->target = scp->device->id;
  869. req->lun = scp->device->lun;
  870. req->header.size = cpu_to_le32(
  871. sizeof(struct hpt_iop_request_scsi_command)
  872. - sizeof(struct hpt_iopsg)
  873. + sg_count * sizeof(struct hpt_iopsg));
  874. memcpy(req->cdb, scp->cmnd, sizeof(req->cdb));
  875. hba->ops->post_req(hba, _req);
  876. return 0;
  877. cmd_done:
  878. dprintk("scsi_done(scp=%p)\n", scp);
  879. scp->scsi_done(scp);
  880. return 0;
  881. }
  882. static DEF_SCSI_QCMD(hptiop_queuecommand)
  883. static const char *hptiop_info(struct Scsi_Host *host)
  884. {
  885. return driver_name_long;
  886. }
  887. static int hptiop_reset_hba(struct hptiop_hba *hba)
  888. {
  889. if (atomic_xchg(&hba->resetting, 1) == 0) {
  890. atomic_inc(&hba->reset_count);
  891. hba->ops->post_msg(hba, IOPMU_INBOUND_MSG0_RESET);
  892. }
  893. wait_event_timeout(hba->reset_wq,
  894. atomic_read(&hba->resetting) == 0, 60 * HZ);
  895. if (atomic_read(&hba->resetting)) {
  896. /* IOP is in unknown state, abort reset */
  897. printk(KERN_ERR "scsi%d: reset failed\n", hba->host->host_no);
  898. return -1;
  899. }
  900. if (iop_send_sync_msg(hba,
  901. IOPMU_INBOUND_MSG0_START_BACKGROUND_TASK, 5000)) {
  902. dprintk("scsi%d: fail to start background task\n",
  903. hba->host->host_no);
  904. }
  905. return 0;
  906. }
  907. static int hptiop_reset(struct scsi_cmnd *scp)
  908. {
  909. struct Scsi_Host * host = scp->device->host;
  910. struct hptiop_hba * hba = (struct hptiop_hba *)host->hostdata;
  911. printk(KERN_WARNING "hptiop_reset(%d/%d/%d) scp=%p\n",
  912. scp->device->host->host_no, scp->device->channel,
  913. scp->device->id, scp);
  914. return hptiop_reset_hba(hba)? FAILED : SUCCESS;
  915. }
  916. static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
  917. int queue_depth, int reason)
  918. {
  919. struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
  920. if (reason != SCSI_QDEPTH_DEFAULT)
  921. return -EOPNOTSUPP;
  922. if (queue_depth > hba->max_requests)
  923. queue_depth = hba->max_requests;
  924. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
  925. return queue_depth;
  926. }
  927. static ssize_t hptiop_show_version(struct device *dev,
  928. struct device_attribute *attr, char *buf)
  929. {
  930. return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
  931. }
  932. static ssize_t hptiop_show_fw_version(struct device *dev,
  933. struct device_attribute *attr, char *buf)
  934. {
  935. struct Scsi_Host *host = class_to_shost(dev);
  936. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  937. return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
  938. hba->firmware_version >> 24,
  939. (hba->firmware_version >> 16) & 0xff,
  940. (hba->firmware_version >> 8) & 0xff,
  941. hba->firmware_version & 0xff);
  942. }
  943. static struct device_attribute hptiop_attr_version = {
  944. .attr = {
  945. .name = "driver-version",
  946. .mode = S_IRUGO,
  947. },
  948. .show = hptiop_show_version,
  949. };
  950. static struct device_attribute hptiop_attr_fw_version = {
  951. .attr = {
  952. .name = "firmware-version",
  953. .mode = S_IRUGO,
  954. },
  955. .show = hptiop_show_fw_version,
  956. };
  957. static struct device_attribute *hptiop_attrs[] = {
  958. &hptiop_attr_version,
  959. &hptiop_attr_fw_version,
  960. NULL
  961. };
  962. static struct scsi_host_template driver_template = {
  963. .module = THIS_MODULE,
  964. .name = driver_name,
  965. .queuecommand = hptiop_queuecommand,
  966. .eh_device_reset_handler = hptiop_reset,
  967. .eh_bus_reset_handler = hptiop_reset,
  968. .info = hptiop_info,
  969. .emulated = 0,
  970. .use_clustering = ENABLE_CLUSTERING,
  971. .proc_name = driver_name,
  972. .shost_attrs = hptiop_attrs,
  973. .this_id = -1,
  974. .change_queue_depth = hptiop_adjust_disk_queue_depth,
  975. };
  976. static int hptiop_internal_memalloc_itl(struct hptiop_hba *hba)
  977. {
  978. return 0;
  979. }
  980. static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
  981. {
  982. hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
  983. 0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
  984. if (hba->u.mv.internal_req)
  985. return 0;
  986. else
  987. return -1;
  988. }
  989. static int hptiop_internal_memalloc_mvfrey(struct hptiop_hba *hba)
  990. {
  991. u32 list_count = readl(&hba->u.mvfrey.mu->inbound_conf_ctl);
  992. char *p;
  993. dma_addr_t phy;
  994. BUG_ON(hba->max_request_size == 0);
  995. if (list_count == 0) {
  996. BUG_ON(1);
  997. return -1;
  998. }
  999. list_count >>= 16;
  1000. hba->u.mvfrey.list_count = list_count;
  1001. hba->u.mvfrey.internal_mem_size = 0x800 +
  1002. list_count * sizeof(struct mvfrey_inlist_entry) +
  1003. list_count * sizeof(struct mvfrey_outlist_entry) +
  1004. sizeof(int);
  1005. p = dma_alloc_coherent(&hba->pcidev->dev,
  1006. hba->u.mvfrey.internal_mem_size, &phy, GFP_KERNEL);
  1007. if (!p)
  1008. return -1;
  1009. hba->u.mvfrey.internal_req.req_virt = p;
  1010. hba->u.mvfrey.internal_req.req_shifted_phy = phy >> 5;
  1011. hba->u.mvfrey.internal_req.scp = NULL;
  1012. hba->u.mvfrey.internal_req.next = NULL;
  1013. p += 0x800;
  1014. phy += 0x800;
  1015. hba->u.mvfrey.inlist = (struct mvfrey_inlist_entry *)p;
  1016. hba->u.mvfrey.inlist_phy = phy;
  1017. p += list_count * sizeof(struct mvfrey_inlist_entry);
  1018. phy += list_count * sizeof(struct mvfrey_inlist_entry);
  1019. hba->u.mvfrey.outlist = (struct mvfrey_outlist_entry *)p;
  1020. hba->u.mvfrey.outlist_phy = phy;
  1021. p += list_count * sizeof(struct mvfrey_outlist_entry);
  1022. phy += list_count * sizeof(struct mvfrey_outlist_entry);
  1023. hba->u.mvfrey.outlist_cptr = (__le32 *)p;
  1024. hba->u.mvfrey.outlist_cptr_phy = phy;
  1025. return 0;
  1026. }
  1027. static int hptiop_internal_memfree_itl(struct hptiop_hba *hba)
  1028. {
  1029. return 0;
  1030. }
  1031. static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
  1032. {
  1033. if (hba->u.mv.internal_req) {
  1034. dma_free_coherent(&hba->pcidev->dev, 0x800,
  1035. hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
  1036. return 0;
  1037. } else
  1038. return -1;
  1039. }
  1040. static int hptiop_internal_memfree_mvfrey(struct hptiop_hba *hba)
  1041. {
  1042. if (hba->u.mvfrey.internal_req.req_virt) {
  1043. dma_free_coherent(&hba->pcidev->dev,
  1044. hba->u.mvfrey.internal_mem_size,
  1045. hba->u.mvfrey.internal_req.req_virt,
  1046. (dma_addr_t)
  1047. hba->u.mvfrey.internal_req.req_shifted_phy << 5);
  1048. return 0;
  1049. } else
  1050. return -1;
  1051. }
  1052. static int __devinit hptiop_probe(struct pci_dev *pcidev,
  1053. const struct pci_device_id *id)
  1054. {
  1055. struct Scsi_Host *host = NULL;
  1056. struct hptiop_hba *hba;
  1057. struct hptiop_adapter_ops *iop_ops;
  1058. struct hpt_iop_request_get_config iop_config;
  1059. struct hpt_iop_request_set_config set_config;
  1060. dma_addr_t start_phy;
  1061. void *start_virt;
  1062. u32 offset, i, req_size;
  1063. dprintk("hptiop_probe(%p)\n", pcidev);
  1064. if (pci_enable_device(pcidev)) {
  1065. printk(KERN_ERR "hptiop: fail to enable pci device\n");
  1066. return -ENODEV;
  1067. }
  1068. printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
  1069. pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
  1070. pcidev->irq);
  1071. pci_set_master(pcidev);
  1072. /* Enable 64bit DMA if possible */
  1073. iop_ops = (struct hptiop_adapter_ops *)id->driver_data;
  1074. if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(iop_ops->hw_dma_bit_mask))) {
  1075. if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(32))) {
  1076. printk(KERN_ERR "hptiop: fail to set dma_mask\n");
  1077. goto disable_pci_device;
  1078. }
  1079. }
  1080. if (pci_request_regions(pcidev, driver_name)) {
  1081. printk(KERN_ERR "hptiop: pci_request_regions failed\n");
  1082. goto disable_pci_device;
  1083. }
  1084. host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
  1085. if (!host) {
  1086. printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
  1087. goto free_pci_regions;
  1088. }
  1089. hba = (struct hptiop_hba *)host->hostdata;
  1090. hba->ops = iop_ops;
  1091. hba->pcidev = pcidev;
  1092. hba->host = host;
  1093. hba->initialized = 0;
  1094. hba->iopintf_v2 = 0;
  1095. atomic_set(&hba->resetting, 0);
  1096. atomic_set(&hba->reset_count, 0);
  1097. init_waitqueue_head(&hba->reset_wq);
  1098. init_waitqueue_head(&hba->ioctl_wq);
  1099. host->max_lun = 1;
  1100. host->max_channel = 0;
  1101. host->io_port = 0;
  1102. host->n_io_port = 0;
  1103. host->irq = pcidev->irq;
  1104. if (hba->ops->map_pci_bar(hba))
  1105. goto free_scsi_host;
  1106. if (hba->ops->iop_wait_ready(hba, 20000)) {
  1107. printk(KERN_ERR "scsi%d: firmware not ready\n",
  1108. hba->host->host_no);
  1109. goto unmap_pci_bar;
  1110. }
  1111. if (hba->ops->family == MV_BASED_IOP) {
  1112. if (hba->ops->internal_memalloc(hba)) {
  1113. printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
  1114. hba->host->host_no);
  1115. goto unmap_pci_bar;
  1116. }
  1117. }
  1118. if (hba->ops->get_config(hba, &iop_config)) {
  1119. printk(KERN_ERR "scsi%d: get config failed\n",
  1120. hba->host->host_no);
  1121. goto unmap_pci_bar;
  1122. }
  1123. hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
  1124. HPTIOP_MAX_REQUESTS);
  1125. hba->max_devices = le32_to_cpu(iop_config.max_devices);
  1126. hba->max_request_size = le32_to_cpu(iop_config.request_size);
  1127. hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
  1128. hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
  1129. hba->interface_version = le32_to_cpu(iop_config.interface_version);
  1130. hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
  1131. if (hba->ops->family == MVFREY_BASED_IOP) {
  1132. if (hba->ops->internal_memalloc(hba)) {
  1133. printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
  1134. hba->host->host_no);
  1135. goto unmap_pci_bar;
  1136. }
  1137. if (hba->ops->reset_comm(hba)) {
  1138. printk(KERN_ERR "scsi%d: reset comm failed\n",
  1139. hba->host->host_no);
  1140. goto unmap_pci_bar;
  1141. }
  1142. }
  1143. if (hba->firmware_version > 0x01020000 ||
  1144. hba->interface_version > 0x01020000)
  1145. hba->iopintf_v2 = 1;
  1146. host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
  1147. host->max_id = le32_to_cpu(iop_config.max_devices);
  1148. host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
  1149. host->can_queue = le32_to_cpu(iop_config.max_requests);
  1150. host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
  1151. host->max_cmd_len = 16;
  1152. req_size = sizeof(struct hpt_iop_request_scsi_command)
  1153. + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
  1154. if ((req_size & 0x1f) != 0)
  1155. req_size = (req_size + 0x1f) & ~0x1f;
  1156. memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
  1157. set_config.iop_id = cpu_to_le32(host->host_no);
  1158. set_config.vbus_id = cpu_to_le16(host->host_no);
  1159. set_config.max_host_request_size = cpu_to_le16(req_size);
  1160. if (hba->ops->set_config(hba, &set_config)) {
  1161. printk(KERN_ERR "scsi%d: set config failed\n",
  1162. hba->host->host_no);
  1163. goto unmap_pci_bar;
  1164. }
  1165. pci_set_drvdata(pcidev, host);
  1166. if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
  1167. driver_name, hba)) {
  1168. printk(KERN_ERR "scsi%d: request irq %d failed\n",
  1169. hba->host->host_no, pcidev->irq);
  1170. goto unmap_pci_bar;
  1171. }
  1172. /* Allocate request mem */
  1173. dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
  1174. hba->req_size = req_size;
  1175. start_virt = dma_alloc_coherent(&pcidev->dev,
  1176. hba->req_size*hba->max_requests + 0x20,
  1177. &start_phy, GFP_KERNEL);
  1178. if (!start_virt) {
  1179. printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
  1180. hba->host->host_no);
  1181. goto free_request_irq;
  1182. }
  1183. hba->dma_coherent = start_virt;
  1184. hba->dma_coherent_handle = start_phy;
  1185. if ((start_phy & 0x1f) != 0) {
  1186. offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
  1187. start_phy += offset;
  1188. start_virt += offset;
  1189. }
  1190. hba->req_list = NULL;
  1191. for (i = 0; i < hba->max_requests; i++) {
  1192. hba->reqs[i].next = NULL;
  1193. hba->reqs[i].req_virt = start_virt;
  1194. hba->reqs[i].req_shifted_phy = start_phy >> 5;
  1195. hba->reqs[i].index = i;
  1196. free_req(hba, &hba->reqs[i]);
  1197. start_virt = (char *)start_virt + hba->req_size;
  1198. start_phy = start_phy + hba->req_size;
  1199. }
  1200. /* Enable Interrupt and start background task */
  1201. if (hptiop_initialize_iop(hba))
  1202. goto free_request_mem;
  1203. if (scsi_add_host(host, &pcidev->dev)) {
  1204. printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
  1205. hba->host->host_no);
  1206. goto free_request_mem;
  1207. }
  1208. scsi_scan_host(host);
  1209. dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
  1210. return 0;
  1211. free_request_mem:
  1212. dma_free_coherent(&hba->pcidev->dev,
  1213. hba->req_size * hba->max_requests + 0x20,
  1214. hba->dma_coherent, hba->dma_coherent_handle);
  1215. free_request_irq:
  1216. free_irq(hba->pcidev->irq, hba);
  1217. unmap_pci_bar:
  1218. hba->ops->internal_memfree(hba);
  1219. hba->ops->unmap_pci_bar(hba);
  1220. free_scsi_host:
  1221. scsi_host_put(host);
  1222. free_pci_regions:
  1223. pci_release_regions(pcidev);
  1224. disable_pci_device:
  1225. pci_disable_device(pcidev);
  1226. dprintk("scsi%d: hptiop_probe fail\n", host ? host->host_no : 0);
  1227. return -ENODEV;
  1228. }
  1229. static void hptiop_shutdown(struct pci_dev *pcidev)
  1230. {
  1231. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  1232. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  1233. dprintk("hptiop_shutdown(%p)\n", hba);
  1234. /* stop the iop */
  1235. if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
  1236. printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
  1237. hba->host->host_no);
  1238. /* disable all outbound interrupts */
  1239. hba->ops->disable_intr(hba);
  1240. }
  1241. static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
  1242. {
  1243. u32 int_mask;
  1244. int_mask = readl(&hba->u.itl.iop->outbound_intmask);
  1245. writel(int_mask |
  1246. IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
  1247. &hba->u.itl.iop->outbound_intmask);
  1248. readl(&hba->u.itl.iop->outbound_intmask);
  1249. }
  1250. static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
  1251. {
  1252. writel(0, &hba->u.mv.regs->outbound_intmask);
  1253. readl(&hba->u.mv.regs->outbound_intmask);
  1254. }
  1255. static void hptiop_disable_intr_mvfrey(struct hptiop_hba *hba)
  1256. {
  1257. writel(0, &(hba->u.mvfrey.mu->f0_doorbell_enable));
  1258. readl(&(hba->u.mvfrey.mu->f0_doorbell_enable));
  1259. writel(0, &(hba->u.mvfrey.mu->isr_enable));
  1260. readl(&(hba->u.mvfrey.mu->isr_enable));
  1261. writel(0, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
  1262. readl(&(hba->u.mvfrey.mu->pcie_f0_int_enable));
  1263. }
  1264. static void hptiop_remove(struct pci_dev *pcidev)
  1265. {
  1266. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  1267. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  1268. dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
  1269. scsi_remove_host(host);
  1270. hptiop_shutdown(pcidev);
  1271. free_irq(hba->pcidev->irq, hba);
  1272. dma_free_coherent(&hba->pcidev->dev,
  1273. hba->req_size * hba->max_requests + 0x20,
  1274. hba->dma_coherent,
  1275. hba->dma_coherent_handle);
  1276. hba->ops->internal_memfree(hba);
  1277. hba->ops->unmap_pci_bar(hba);
  1278. pci_release_regions(hba->pcidev);
  1279. pci_set_drvdata(hba->pcidev, NULL);
  1280. pci_disable_device(hba->pcidev);
  1281. scsi_host_put(host);
  1282. }
  1283. static struct hptiop_adapter_ops hptiop_itl_ops = {
  1284. .family = INTEL_BASED_IOP,
  1285. .iop_wait_ready = iop_wait_ready_itl,
  1286. .internal_memalloc = hptiop_internal_memalloc_itl,
  1287. .internal_memfree = hptiop_internal_memfree_itl,
  1288. .map_pci_bar = hptiop_map_pci_bar_itl,
  1289. .unmap_pci_bar = hptiop_unmap_pci_bar_itl,
  1290. .enable_intr = hptiop_enable_intr_itl,
  1291. .disable_intr = hptiop_disable_intr_itl,
  1292. .get_config = iop_get_config_itl,
  1293. .set_config = iop_set_config_itl,
  1294. .iop_intr = iop_intr_itl,
  1295. .post_msg = hptiop_post_msg_itl,
  1296. .post_req = hptiop_post_req_itl,
  1297. .hw_dma_bit_mask = 64,
  1298. .reset_comm = hptiop_reset_comm_itl,
  1299. .host_phy_flag = cpu_to_le64(0),
  1300. };
  1301. static struct hptiop_adapter_ops hptiop_mv_ops = {
  1302. .family = MV_BASED_IOP,
  1303. .iop_wait_ready = iop_wait_ready_mv,
  1304. .internal_memalloc = hptiop_internal_memalloc_mv,
  1305. .internal_memfree = hptiop_internal_memfree_mv,
  1306. .map_pci_bar = hptiop_map_pci_bar_mv,
  1307. .unmap_pci_bar = hptiop_unmap_pci_bar_mv,
  1308. .enable_intr = hptiop_enable_intr_mv,
  1309. .disable_intr = hptiop_disable_intr_mv,
  1310. .get_config = iop_get_config_mv,
  1311. .set_config = iop_set_config_mv,
  1312. .iop_intr = iop_intr_mv,
  1313. .post_msg = hptiop_post_msg_mv,
  1314. .post_req = hptiop_post_req_mv,
  1315. .hw_dma_bit_mask = 33,
  1316. .reset_comm = hptiop_reset_comm_mv,
  1317. .host_phy_flag = cpu_to_le64(0),
  1318. };
  1319. static struct hptiop_adapter_ops hptiop_mvfrey_ops = {
  1320. .family = MVFREY_BASED_IOP,
  1321. .iop_wait_ready = iop_wait_ready_mvfrey,
  1322. .internal_memalloc = hptiop_internal_memalloc_mvfrey,
  1323. .internal_memfree = hptiop_internal_memfree_mvfrey,
  1324. .map_pci_bar = hptiop_map_pci_bar_mvfrey,
  1325. .unmap_pci_bar = hptiop_unmap_pci_bar_mvfrey,
  1326. .enable_intr = hptiop_enable_intr_mvfrey,
  1327. .disable_intr = hptiop_disable_intr_mvfrey,
  1328. .get_config = iop_get_config_mvfrey,
  1329. .set_config = iop_set_config_mvfrey,
  1330. .iop_intr = iop_intr_mvfrey,
  1331. .post_msg = hptiop_post_msg_mvfrey,
  1332. .post_req = hptiop_post_req_mvfrey,
  1333. .hw_dma_bit_mask = 64,
  1334. .reset_comm = hptiop_reset_comm_mvfrey,
  1335. .host_phy_flag = cpu_to_le64(1),
  1336. };
  1337. static struct pci_device_id hptiop_id_table[] = {
  1338. { PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
  1339. { PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
  1340. { PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
  1341. { PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
  1342. { PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
  1343. { PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
  1344. { PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
  1345. { PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
  1346. { PCI_VDEVICE(TTI, 0x3530), (kernel_ulong_t)&hptiop_itl_ops },
  1347. { PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
  1348. { PCI_VDEVICE(TTI, 0x3560), (kernel_ulong_t)&hptiop_itl_ops },
  1349. { PCI_VDEVICE(TTI, 0x4210), (kernel_ulong_t)&hptiop_itl_ops },
  1350. { PCI_VDEVICE(TTI, 0x4211), (kernel_ulong_t)&hptiop_itl_ops },
  1351. { PCI_VDEVICE(TTI, 0x4310), (kernel_ulong_t)&hptiop_itl_ops },
  1352. { PCI_VDEVICE(TTI, 0x4311), (kernel_ulong_t)&hptiop_itl_ops },
  1353. { PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
  1354. { PCI_VDEVICE(TTI, 0x4321), (kernel_ulong_t)&hptiop_itl_ops },
  1355. { PCI_VDEVICE(TTI, 0x4322), (kernel_ulong_t)&hptiop_itl_ops },
  1356. { PCI_VDEVICE(TTI, 0x4400), (kernel_ulong_t)&hptiop_itl_ops },
  1357. { PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
  1358. { PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
  1359. { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
  1360. { PCI_VDEVICE(TTI, 0x4520), (kernel_ulong_t)&hptiop_mvfrey_ops },
  1361. { PCI_VDEVICE(TTI, 0x4522), (kernel_ulong_t)&hptiop_mvfrey_ops },
  1362. {},
  1363. };
  1364. MODULE_DEVICE_TABLE(pci, hptiop_id_table);
  1365. static struct pci_driver hptiop_pci_driver = {
  1366. .name = driver_name,
  1367. .id_table = hptiop_id_table,
  1368. .probe = hptiop_probe,
  1369. .remove = hptiop_remove,
  1370. .shutdown = hptiop_shutdown,
  1371. };
  1372. static int __init hptiop_module_init(void)
  1373. {
  1374. printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
  1375. return pci_register_driver(&hptiop_pci_driver);
  1376. }
  1377. static void __exit hptiop_module_exit(void)
  1378. {
  1379. pci_unregister_driver(&hptiop_pci_driver);
  1380. }
  1381. module_init(hptiop_module_init);
  1382. module_exit(hptiop_module_exit);
  1383. MODULE_LICENSE("GPL");