hptiop.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  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/%llu 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)
  918. {
  919. struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
  920. if (queue_depth > hba->max_requests)
  921. queue_depth = hba->max_requests;
  922. return scsi_change_queue_depth(sdev, queue_depth);
  923. }
  924. static ssize_t hptiop_show_version(struct device *dev,
  925. struct device_attribute *attr, char *buf)
  926. {
  927. return snprintf(buf, PAGE_SIZE, "%s\n", driver_ver);
  928. }
  929. static ssize_t hptiop_show_fw_version(struct device *dev,
  930. struct device_attribute *attr, char *buf)
  931. {
  932. struct Scsi_Host *host = class_to_shost(dev);
  933. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  934. return snprintf(buf, PAGE_SIZE, "%d.%d.%d.%d\n",
  935. hba->firmware_version >> 24,
  936. (hba->firmware_version >> 16) & 0xff,
  937. (hba->firmware_version >> 8) & 0xff,
  938. hba->firmware_version & 0xff);
  939. }
  940. static struct device_attribute hptiop_attr_version = {
  941. .attr = {
  942. .name = "driver-version",
  943. .mode = S_IRUGO,
  944. },
  945. .show = hptiop_show_version,
  946. };
  947. static struct device_attribute hptiop_attr_fw_version = {
  948. .attr = {
  949. .name = "firmware-version",
  950. .mode = S_IRUGO,
  951. },
  952. .show = hptiop_show_fw_version,
  953. };
  954. static struct device_attribute *hptiop_attrs[] = {
  955. &hptiop_attr_version,
  956. &hptiop_attr_fw_version,
  957. NULL
  958. };
  959. static struct scsi_host_template driver_template = {
  960. .module = THIS_MODULE,
  961. .name = driver_name,
  962. .queuecommand = hptiop_queuecommand,
  963. .eh_device_reset_handler = hptiop_reset,
  964. .eh_bus_reset_handler = hptiop_reset,
  965. .info = hptiop_info,
  966. .emulated = 0,
  967. .use_clustering = ENABLE_CLUSTERING,
  968. .proc_name = driver_name,
  969. .shost_attrs = hptiop_attrs,
  970. .this_id = -1,
  971. .change_queue_depth = hptiop_adjust_disk_queue_depth,
  972. };
  973. static int hptiop_internal_memalloc_itl(struct hptiop_hba *hba)
  974. {
  975. return 0;
  976. }
  977. static int hptiop_internal_memalloc_mv(struct hptiop_hba *hba)
  978. {
  979. hba->u.mv.internal_req = dma_alloc_coherent(&hba->pcidev->dev,
  980. 0x800, &hba->u.mv.internal_req_phy, GFP_KERNEL);
  981. if (hba->u.mv.internal_req)
  982. return 0;
  983. else
  984. return -1;
  985. }
  986. static int hptiop_internal_memalloc_mvfrey(struct hptiop_hba *hba)
  987. {
  988. u32 list_count = readl(&hba->u.mvfrey.mu->inbound_conf_ctl);
  989. char *p;
  990. dma_addr_t phy;
  991. BUG_ON(hba->max_request_size == 0);
  992. if (list_count == 0) {
  993. BUG_ON(1);
  994. return -1;
  995. }
  996. list_count >>= 16;
  997. hba->u.mvfrey.list_count = list_count;
  998. hba->u.mvfrey.internal_mem_size = 0x800 +
  999. list_count * sizeof(struct mvfrey_inlist_entry) +
  1000. list_count * sizeof(struct mvfrey_outlist_entry) +
  1001. sizeof(int);
  1002. p = dma_alloc_coherent(&hba->pcidev->dev,
  1003. hba->u.mvfrey.internal_mem_size, &phy, GFP_KERNEL);
  1004. if (!p)
  1005. return -1;
  1006. hba->u.mvfrey.internal_req.req_virt = p;
  1007. hba->u.mvfrey.internal_req.req_shifted_phy = phy >> 5;
  1008. hba->u.mvfrey.internal_req.scp = NULL;
  1009. hba->u.mvfrey.internal_req.next = NULL;
  1010. p += 0x800;
  1011. phy += 0x800;
  1012. hba->u.mvfrey.inlist = (struct mvfrey_inlist_entry *)p;
  1013. hba->u.mvfrey.inlist_phy = phy;
  1014. p += list_count * sizeof(struct mvfrey_inlist_entry);
  1015. phy += list_count * sizeof(struct mvfrey_inlist_entry);
  1016. hba->u.mvfrey.outlist = (struct mvfrey_outlist_entry *)p;
  1017. hba->u.mvfrey.outlist_phy = phy;
  1018. p += list_count * sizeof(struct mvfrey_outlist_entry);
  1019. phy += list_count * sizeof(struct mvfrey_outlist_entry);
  1020. hba->u.mvfrey.outlist_cptr = (__le32 *)p;
  1021. hba->u.mvfrey.outlist_cptr_phy = phy;
  1022. return 0;
  1023. }
  1024. static int hptiop_internal_memfree_itl(struct hptiop_hba *hba)
  1025. {
  1026. return 0;
  1027. }
  1028. static int hptiop_internal_memfree_mv(struct hptiop_hba *hba)
  1029. {
  1030. if (hba->u.mv.internal_req) {
  1031. dma_free_coherent(&hba->pcidev->dev, 0x800,
  1032. hba->u.mv.internal_req, hba->u.mv.internal_req_phy);
  1033. return 0;
  1034. } else
  1035. return -1;
  1036. }
  1037. static int hptiop_internal_memfree_mvfrey(struct hptiop_hba *hba)
  1038. {
  1039. if (hba->u.mvfrey.internal_req.req_virt) {
  1040. dma_free_coherent(&hba->pcidev->dev,
  1041. hba->u.mvfrey.internal_mem_size,
  1042. hba->u.mvfrey.internal_req.req_virt,
  1043. (dma_addr_t)
  1044. hba->u.mvfrey.internal_req.req_shifted_phy << 5);
  1045. return 0;
  1046. } else
  1047. return -1;
  1048. }
  1049. static int hptiop_probe(struct pci_dev *pcidev, const struct pci_device_id *id)
  1050. {
  1051. struct Scsi_Host *host = NULL;
  1052. struct hptiop_hba *hba;
  1053. struct hptiop_adapter_ops *iop_ops;
  1054. struct hpt_iop_request_get_config iop_config;
  1055. struct hpt_iop_request_set_config set_config;
  1056. dma_addr_t start_phy;
  1057. void *start_virt;
  1058. u32 offset, i, req_size;
  1059. dprintk("hptiop_probe(%p)\n", pcidev);
  1060. if (pci_enable_device(pcidev)) {
  1061. printk(KERN_ERR "hptiop: fail to enable pci device\n");
  1062. return -ENODEV;
  1063. }
  1064. printk(KERN_INFO "adapter at PCI %d:%d:%d, IRQ %d\n",
  1065. pcidev->bus->number, pcidev->devfn >> 3, pcidev->devfn & 7,
  1066. pcidev->irq);
  1067. pci_set_master(pcidev);
  1068. /* Enable 64bit DMA if possible */
  1069. iop_ops = (struct hptiop_adapter_ops *)id->driver_data;
  1070. if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(iop_ops->hw_dma_bit_mask))) {
  1071. if (pci_set_dma_mask(pcidev, DMA_BIT_MASK(32))) {
  1072. printk(KERN_ERR "hptiop: fail to set dma_mask\n");
  1073. goto disable_pci_device;
  1074. }
  1075. }
  1076. if (pci_request_regions(pcidev, driver_name)) {
  1077. printk(KERN_ERR "hptiop: pci_request_regions failed\n");
  1078. goto disable_pci_device;
  1079. }
  1080. host = scsi_host_alloc(&driver_template, sizeof(struct hptiop_hba));
  1081. if (!host) {
  1082. printk(KERN_ERR "hptiop: fail to alloc scsi host\n");
  1083. goto free_pci_regions;
  1084. }
  1085. hba = (struct hptiop_hba *)host->hostdata;
  1086. hba->ops = iop_ops;
  1087. hba->pcidev = pcidev;
  1088. hba->host = host;
  1089. hba->initialized = 0;
  1090. hba->iopintf_v2 = 0;
  1091. atomic_set(&hba->resetting, 0);
  1092. atomic_set(&hba->reset_count, 0);
  1093. init_waitqueue_head(&hba->reset_wq);
  1094. init_waitqueue_head(&hba->ioctl_wq);
  1095. host->max_lun = 1;
  1096. host->max_channel = 0;
  1097. host->io_port = 0;
  1098. host->n_io_port = 0;
  1099. host->irq = pcidev->irq;
  1100. if (hba->ops->map_pci_bar(hba))
  1101. goto free_scsi_host;
  1102. if (hba->ops->iop_wait_ready(hba, 20000)) {
  1103. printk(KERN_ERR "scsi%d: firmware not ready\n",
  1104. hba->host->host_no);
  1105. goto unmap_pci_bar;
  1106. }
  1107. if (hba->ops->family == MV_BASED_IOP) {
  1108. if (hba->ops->internal_memalloc(hba)) {
  1109. printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
  1110. hba->host->host_no);
  1111. goto unmap_pci_bar;
  1112. }
  1113. }
  1114. if (hba->ops->get_config(hba, &iop_config)) {
  1115. printk(KERN_ERR "scsi%d: get config failed\n",
  1116. hba->host->host_no);
  1117. goto unmap_pci_bar;
  1118. }
  1119. hba->max_requests = min(le32_to_cpu(iop_config.max_requests),
  1120. HPTIOP_MAX_REQUESTS);
  1121. hba->max_devices = le32_to_cpu(iop_config.max_devices);
  1122. hba->max_request_size = le32_to_cpu(iop_config.request_size);
  1123. hba->max_sg_descriptors = le32_to_cpu(iop_config.max_sg_count);
  1124. hba->firmware_version = le32_to_cpu(iop_config.firmware_version);
  1125. hba->interface_version = le32_to_cpu(iop_config.interface_version);
  1126. hba->sdram_size = le32_to_cpu(iop_config.sdram_size);
  1127. if (hba->ops->family == MVFREY_BASED_IOP) {
  1128. if (hba->ops->internal_memalloc(hba)) {
  1129. printk(KERN_ERR "scsi%d: internal_memalloc failed\n",
  1130. hba->host->host_no);
  1131. goto unmap_pci_bar;
  1132. }
  1133. if (hba->ops->reset_comm(hba)) {
  1134. printk(KERN_ERR "scsi%d: reset comm failed\n",
  1135. hba->host->host_no);
  1136. goto unmap_pci_bar;
  1137. }
  1138. }
  1139. if (hba->firmware_version > 0x01020000 ||
  1140. hba->interface_version > 0x01020000)
  1141. hba->iopintf_v2 = 1;
  1142. host->max_sectors = le32_to_cpu(iop_config.data_transfer_length) >> 9;
  1143. host->max_id = le32_to_cpu(iop_config.max_devices);
  1144. host->sg_tablesize = le32_to_cpu(iop_config.max_sg_count);
  1145. host->can_queue = le32_to_cpu(iop_config.max_requests);
  1146. host->cmd_per_lun = le32_to_cpu(iop_config.max_requests);
  1147. host->max_cmd_len = 16;
  1148. req_size = sizeof(struct hpt_iop_request_scsi_command)
  1149. + sizeof(struct hpt_iopsg) * (hba->max_sg_descriptors - 1);
  1150. if ((req_size & 0x1f) != 0)
  1151. req_size = (req_size + 0x1f) & ~0x1f;
  1152. memset(&set_config, 0, sizeof(struct hpt_iop_request_set_config));
  1153. set_config.iop_id = cpu_to_le32(host->host_no);
  1154. set_config.vbus_id = cpu_to_le16(host->host_no);
  1155. set_config.max_host_request_size = cpu_to_le16(req_size);
  1156. if (hba->ops->set_config(hba, &set_config)) {
  1157. printk(KERN_ERR "scsi%d: set config failed\n",
  1158. hba->host->host_no);
  1159. goto unmap_pci_bar;
  1160. }
  1161. pci_set_drvdata(pcidev, host);
  1162. if (request_irq(pcidev->irq, hptiop_intr, IRQF_SHARED,
  1163. driver_name, hba)) {
  1164. printk(KERN_ERR "scsi%d: request irq %d failed\n",
  1165. hba->host->host_no, pcidev->irq);
  1166. goto unmap_pci_bar;
  1167. }
  1168. /* Allocate request mem */
  1169. dprintk("req_size=%d, max_requests=%d\n", req_size, hba->max_requests);
  1170. hba->req_size = req_size;
  1171. start_virt = dma_alloc_coherent(&pcidev->dev,
  1172. hba->req_size*hba->max_requests + 0x20,
  1173. &start_phy, GFP_KERNEL);
  1174. if (!start_virt) {
  1175. printk(KERN_ERR "scsi%d: fail to alloc request mem\n",
  1176. hba->host->host_no);
  1177. goto free_request_irq;
  1178. }
  1179. hba->dma_coherent = start_virt;
  1180. hba->dma_coherent_handle = start_phy;
  1181. if ((start_phy & 0x1f) != 0) {
  1182. offset = ((start_phy + 0x1f) & ~0x1f) - start_phy;
  1183. start_phy += offset;
  1184. start_virt += offset;
  1185. }
  1186. hba->req_list = NULL;
  1187. for (i = 0; i < hba->max_requests; i++) {
  1188. hba->reqs[i].next = NULL;
  1189. hba->reqs[i].req_virt = start_virt;
  1190. hba->reqs[i].req_shifted_phy = start_phy >> 5;
  1191. hba->reqs[i].index = i;
  1192. free_req(hba, &hba->reqs[i]);
  1193. start_virt = (char *)start_virt + hba->req_size;
  1194. start_phy = start_phy + hba->req_size;
  1195. }
  1196. /* Enable Interrupt and start background task */
  1197. if (hptiop_initialize_iop(hba))
  1198. goto free_request_mem;
  1199. if (scsi_add_host(host, &pcidev->dev)) {
  1200. printk(KERN_ERR "scsi%d: scsi_add_host failed\n",
  1201. hba->host->host_no);
  1202. goto free_request_mem;
  1203. }
  1204. scsi_scan_host(host);
  1205. dprintk("scsi%d: hptiop_probe successfully\n", hba->host->host_no);
  1206. return 0;
  1207. free_request_mem:
  1208. dma_free_coherent(&hba->pcidev->dev,
  1209. hba->req_size * hba->max_requests + 0x20,
  1210. hba->dma_coherent, hba->dma_coherent_handle);
  1211. free_request_irq:
  1212. free_irq(hba->pcidev->irq, hba);
  1213. unmap_pci_bar:
  1214. hba->ops->internal_memfree(hba);
  1215. hba->ops->unmap_pci_bar(hba);
  1216. free_scsi_host:
  1217. scsi_host_put(host);
  1218. free_pci_regions:
  1219. pci_release_regions(pcidev);
  1220. disable_pci_device:
  1221. pci_disable_device(pcidev);
  1222. dprintk("scsi%d: hptiop_probe fail\n", host ? host->host_no : 0);
  1223. return -ENODEV;
  1224. }
  1225. static void hptiop_shutdown(struct pci_dev *pcidev)
  1226. {
  1227. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  1228. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  1229. dprintk("hptiop_shutdown(%p)\n", hba);
  1230. /* stop the iop */
  1231. if (iop_send_sync_msg(hba, IOPMU_INBOUND_MSG0_SHUTDOWN, 60000))
  1232. printk(KERN_ERR "scsi%d: shutdown the iop timeout\n",
  1233. hba->host->host_no);
  1234. /* disable all outbound interrupts */
  1235. hba->ops->disable_intr(hba);
  1236. }
  1237. static void hptiop_disable_intr_itl(struct hptiop_hba *hba)
  1238. {
  1239. u32 int_mask;
  1240. int_mask = readl(&hba->u.itl.iop->outbound_intmask);
  1241. writel(int_mask |
  1242. IOPMU_OUTBOUND_INT_MSG0 | IOPMU_OUTBOUND_INT_POSTQUEUE,
  1243. &hba->u.itl.iop->outbound_intmask);
  1244. readl(&hba->u.itl.iop->outbound_intmask);
  1245. }
  1246. static void hptiop_disable_intr_mv(struct hptiop_hba *hba)
  1247. {
  1248. writel(0, &hba->u.mv.regs->outbound_intmask);
  1249. readl(&hba->u.mv.regs->outbound_intmask);
  1250. }
  1251. static void hptiop_disable_intr_mvfrey(struct hptiop_hba *hba)
  1252. {
  1253. writel(0, &(hba->u.mvfrey.mu->f0_doorbell_enable));
  1254. readl(&(hba->u.mvfrey.mu->f0_doorbell_enable));
  1255. writel(0, &(hba->u.mvfrey.mu->isr_enable));
  1256. readl(&(hba->u.mvfrey.mu->isr_enable));
  1257. writel(0, &(hba->u.mvfrey.mu->pcie_f0_int_enable));
  1258. readl(&(hba->u.mvfrey.mu->pcie_f0_int_enable));
  1259. }
  1260. static void hptiop_remove(struct pci_dev *pcidev)
  1261. {
  1262. struct Scsi_Host *host = pci_get_drvdata(pcidev);
  1263. struct hptiop_hba *hba = (struct hptiop_hba *)host->hostdata;
  1264. dprintk("scsi%d: hptiop_remove\n", hba->host->host_no);
  1265. scsi_remove_host(host);
  1266. hptiop_shutdown(pcidev);
  1267. free_irq(hba->pcidev->irq, hba);
  1268. dma_free_coherent(&hba->pcidev->dev,
  1269. hba->req_size * hba->max_requests + 0x20,
  1270. hba->dma_coherent,
  1271. hba->dma_coherent_handle);
  1272. hba->ops->internal_memfree(hba);
  1273. hba->ops->unmap_pci_bar(hba);
  1274. pci_release_regions(hba->pcidev);
  1275. pci_set_drvdata(hba->pcidev, NULL);
  1276. pci_disable_device(hba->pcidev);
  1277. scsi_host_put(host);
  1278. }
  1279. static struct hptiop_adapter_ops hptiop_itl_ops = {
  1280. .family = INTEL_BASED_IOP,
  1281. .iop_wait_ready = iop_wait_ready_itl,
  1282. .internal_memalloc = hptiop_internal_memalloc_itl,
  1283. .internal_memfree = hptiop_internal_memfree_itl,
  1284. .map_pci_bar = hptiop_map_pci_bar_itl,
  1285. .unmap_pci_bar = hptiop_unmap_pci_bar_itl,
  1286. .enable_intr = hptiop_enable_intr_itl,
  1287. .disable_intr = hptiop_disable_intr_itl,
  1288. .get_config = iop_get_config_itl,
  1289. .set_config = iop_set_config_itl,
  1290. .iop_intr = iop_intr_itl,
  1291. .post_msg = hptiop_post_msg_itl,
  1292. .post_req = hptiop_post_req_itl,
  1293. .hw_dma_bit_mask = 64,
  1294. .reset_comm = hptiop_reset_comm_itl,
  1295. .host_phy_flag = cpu_to_le64(0),
  1296. };
  1297. static struct hptiop_adapter_ops hptiop_mv_ops = {
  1298. .family = MV_BASED_IOP,
  1299. .iop_wait_ready = iop_wait_ready_mv,
  1300. .internal_memalloc = hptiop_internal_memalloc_mv,
  1301. .internal_memfree = hptiop_internal_memfree_mv,
  1302. .map_pci_bar = hptiop_map_pci_bar_mv,
  1303. .unmap_pci_bar = hptiop_unmap_pci_bar_mv,
  1304. .enable_intr = hptiop_enable_intr_mv,
  1305. .disable_intr = hptiop_disable_intr_mv,
  1306. .get_config = iop_get_config_mv,
  1307. .set_config = iop_set_config_mv,
  1308. .iop_intr = iop_intr_mv,
  1309. .post_msg = hptiop_post_msg_mv,
  1310. .post_req = hptiop_post_req_mv,
  1311. .hw_dma_bit_mask = 33,
  1312. .reset_comm = hptiop_reset_comm_mv,
  1313. .host_phy_flag = cpu_to_le64(0),
  1314. };
  1315. static struct hptiop_adapter_ops hptiop_mvfrey_ops = {
  1316. .family = MVFREY_BASED_IOP,
  1317. .iop_wait_ready = iop_wait_ready_mvfrey,
  1318. .internal_memalloc = hptiop_internal_memalloc_mvfrey,
  1319. .internal_memfree = hptiop_internal_memfree_mvfrey,
  1320. .map_pci_bar = hptiop_map_pci_bar_mvfrey,
  1321. .unmap_pci_bar = hptiop_unmap_pci_bar_mvfrey,
  1322. .enable_intr = hptiop_enable_intr_mvfrey,
  1323. .disable_intr = hptiop_disable_intr_mvfrey,
  1324. .get_config = iop_get_config_mvfrey,
  1325. .set_config = iop_set_config_mvfrey,
  1326. .iop_intr = iop_intr_mvfrey,
  1327. .post_msg = hptiop_post_msg_mvfrey,
  1328. .post_req = hptiop_post_req_mvfrey,
  1329. .hw_dma_bit_mask = 64,
  1330. .reset_comm = hptiop_reset_comm_mvfrey,
  1331. .host_phy_flag = cpu_to_le64(1),
  1332. };
  1333. static struct pci_device_id hptiop_id_table[] = {
  1334. { PCI_VDEVICE(TTI, 0x3220), (kernel_ulong_t)&hptiop_itl_ops },
  1335. { PCI_VDEVICE(TTI, 0x3320), (kernel_ulong_t)&hptiop_itl_ops },
  1336. { PCI_VDEVICE(TTI, 0x3410), (kernel_ulong_t)&hptiop_itl_ops },
  1337. { PCI_VDEVICE(TTI, 0x3510), (kernel_ulong_t)&hptiop_itl_ops },
  1338. { PCI_VDEVICE(TTI, 0x3511), (kernel_ulong_t)&hptiop_itl_ops },
  1339. { PCI_VDEVICE(TTI, 0x3520), (kernel_ulong_t)&hptiop_itl_ops },
  1340. { PCI_VDEVICE(TTI, 0x3521), (kernel_ulong_t)&hptiop_itl_ops },
  1341. { PCI_VDEVICE(TTI, 0x3522), (kernel_ulong_t)&hptiop_itl_ops },
  1342. { PCI_VDEVICE(TTI, 0x3530), (kernel_ulong_t)&hptiop_itl_ops },
  1343. { PCI_VDEVICE(TTI, 0x3540), (kernel_ulong_t)&hptiop_itl_ops },
  1344. { PCI_VDEVICE(TTI, 0x3560), (kernel_ulong_t)&hptiop_itl_ops },
  1345. { PCI_VDEVICE(TTI, 0x4210), (kernel_ulong_t)&hptiop_itl_ops },
  1346. { PCI_VDEVICE(TTI, 0x4211), (kernel_ulong_t)&hptiop_itl_ops },
  1347. { PCI_VDEVICE(TTI, 0x4310), (kernel_ulong_t)&hptiop_itl_ops },
  1348. { PCI_VDEVICE(TTI, 0x4311), (kernel_ulong_t)&hptiop_itl_ops },
  1349. { PCI_VDEVICE(TTI, 0x4320), (kernel_ulong_t)&hptiop_itl_ops },
  1350. { PCI_VDEVICE(TTI, 0x4321), (kernel_ulong_t)&hptiop_itl_ops },
  1351. { PCI_VDEVICE(TTI, 0x4322), (kernel_ulong_t)&hptiop_itl_ops },
  1352. { PCI_VDEVICE(TTI, 0x4400), (kernel_ulong_t)&hptiop_itl_ops },
  1353. { PCI_VDEVICE(TTI, 0x3120), (kernel_ulong_t)&hptiop_mv_ops },
  1354. { PCI_VDEVICE(TTI, 0x3122), (kernel_ulong_t)&hptiop_mv_ops },
  1355. { PCI_VDEVICE(TTI, 0x3020), (kernel_ulong_t)&hptiop_mv_ops },
  1356. { PCI_VDEVICE(TTI, 0x4520), (kernel_ulong_t)&hptiop_mvfrey_ops },
  1357. { PCI_VDEVICE(TTI, 0x4522), (kernel_ulong_t)&hptiop_mvfrey_ops },
  1358. {},
  1359. };
  1360. MODULE_DEVICE_TABLE(pci, hptiop_id_table);
  1361. static struct pci_driver hptiop_pci_driver = {
  1362. .name = driver_name,
  1363. .id_table = hptiop_id_table,
  1364. .probe = hptiop_probe,
  1365. .remove = hptiop_remove,
  1366. .shutdown = hptiop_shutdown,
  1367. };
  1368. static int __init hptiop_module_init(void)
  1369. {
  1370. printk(KERN_INFO "%s %s\n", driver_name_long, driver_ver);
  1371. return pci_register_driver(&hptiop_pci_driver);
  1372. }
  1373. static void __exit hptiop_module_exit(void)
  1374. {
  1375. pci_unregister_driver(&hptiop_pci_driver);
  1376. }
  1377. module_init(hptiop_module_init);
  1378. module_exit(hptiop_module_exit);
  1379. MODULE_LICENSE("GPL");