hptiop.c 45 KB

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