qib_init.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. /*
  2. * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
  3. * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
  4. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/pci.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/vmalloc.h>
  37. #include <linux/delay.h>
  38. #include <linux/idr.h>
  39. #include <linux/module.h>
  40. #include <linux/printk.h>
  41. #ifdef CONFIG_INFINIBAND_QIB_DCA
  42. #include <linux/dca.h>
  43. #endif
  44. #include "qib.h"
  45. #include "qib_common.h"
  46. #include "qib_mad.h"
  47. #undef pr_fmt
  48. #define pr_fmt(fmt) QIB_DRV_NAME ": " fmt
  49. /*
  50. * min buffers we want to have per context, after driver
  51. */
  52. #define QIB_MIN_USER_CTXT_BUFCNT 7
  53. #define QLOGIC_IB_R_SOFTWARE_MASK 0xFF
  54. #define QLOGIC_IB_R_SOFTWARE_SHIFT 24
  55. #define QLOGIC_IB_R_EMULATOR_MASK (1ULL<<62)
  56. /*
  57. * Number of ctxts we are configured to use (to allow for more pio
  58. * buffers per ctxt, etc.) Zero means use chip value.
  59. */
  60. ushort qib_cfgctxts;
  61. module_param_named(cfgctxts, qib_cfgctxts, ushort, S_IRUGO);
  62. MODULE_PARM_DESC(cfgctxts, "Set max number of contexts to use");
  63. /*
  64. * If set, do not write to any regs if avoidable, hack to allow
  65. * check for deranged default register values.
  66. */
  67. ushort qib_mini_init;
  68. module_param_named(mini_init, qib_mini_init, ushort, S_IRUGO);
  69. MODULE_PARM_DESC(mini_init, "If set, do minimal diag init");
  70. unsigned qib_n_krcv_queues;
  71. module_param_named(krcvqs, qib_n_krcv_queues, uint, S_IRUGO);
  72. MODULE_PARM_DESC(krcvqs, "number of kernel receive queues per IB port");
  73. unsigned qib_cc_table_size;
  74. module_param_named(cc_table_size, qib_cc_table_size, uint, S_IRUGO);
  75. MODULE_PARM_DESC(cc_table_size, "Congestion control table entries 0 (CCA disabled - default), min = 128, max = 1984");
  76. /*
  77. * qib_wc_pat parameter:
  78. * 0 is WC via MTRR
  79. * 1 is WC via PAT
  80. * If PAT initialization fails, code reverts back to MTRR
  81. */
  82. unsigned qib_wc_pat = 1; /* default (1) is to use PAT, not MTRR */
  83. module_param_named(wc_pat, qib_wc_pat, uint, S_IRUGO);
  84. MODULE_PARM_DESC(wc_pat, "enable write-combining via PAT mechanism");
  85. struct workqueue_struct *qib_cq_wq;
  86. static void verify_interrupt(unsigned long);
  87. static struct idr qib_unit_table;
  88. u32 qib_cpulist_count;
  89. unsigned long *qib_cpulist;
  90. /* set number of contexts we'll actually use */
  91. void qib_set_ctxtcnt(struct qib_devdata *dd)
  92. {
  93. if (!qib_cfgctxts) {
  94. dd->cfgctxts = dd->first_user_ctxt + num_online_cpus();
  95. if (dd->cfgctxts > dd->ctxtcnt)
  96. dd->cfgctxts = dd->ctxtcnt;
  97. } else if (qib_cfgctxts < dd->num_pports)
  98. dd->cfgctxts = dd->ctxtcnt;
  99. else if (qib_cfgctxts <= dd->ctxtcnt)
  100. dd->cfgctxts = qib_cfgctxts;
  101. else
  102. dd->cfgctxts = dd->ctxtcnt;
  103. dd->freectxts = (dd->first_user_ctxt > dd->cfgctxts) ? 0 :
  104. dd->cfgctxts - dd->first_user_ctxt;
  105. }
  106. /*
  107. * Common code for creating the receive context array.
  108. */
  109. int qib_create_ctxts(struct qib_devdata *dd)
  110. {
  111. unsigned i;
  112. int ret;
  113. /*
  114. * Allocate full ctxtcnt array, rather than just cfgctxts, because
  115. * cleanup iterates across all possible ctxts.
  116. */
  117. dd->rcd = kzalloc(sizeof(*dd->rcd) * dd->ctxtcnt, GFP_KERNEL);
  118. if (!dd->rcd) {
  119. qib_dev_err(dd,
  120. "Unable to allocate ctxtdata array, failing\n");
  121. ret = -ENOMEM;
  122. goto done;
  123. }
  124. /* create (one or more) kctxt */
  125. for (i = 0; i < dd->first_user_ctxt; ++i) {
  126. struct qib_pportdata *ppd;
  127. struct qib_ctxtdata *rcd;
  128. if (dd->skip_kctxt_mask & (1 << i))
  129. continue;
  130. ppd = dd->pport + (i % dd->num_pports);
  131. rcd = qib_create_ctxtdata(ppd, i);
  132. if (!rcd) {
  133. qib_dev_err(dd,
  134. "Unable to allocate ctxtdata for Kernel ctxt, failing\n");
  135. ret = -ENOMEM;
  136. goto done;
  137. }
  138. rcd->pkeys[0] = QIB_DEFAULT_P_KEY;
  139. rcd->seq_cnt = 1;
  140. }
  141. ret = 0;
  142. done:
  143. return ret;
  144. }
  145. /*
  146. * Common code for user and kernel context setup.
  147. */
  148. struct qib_ctxtdata *qib_create_ctxtdata(struct qib_pportdata *ppd, u32 ctxt)
  149. {
  150. struct qib_devdata *dd = ppd->dd;
  151. struct qib_ctxtdata *rcd;
  152. rcd = kzalloc(sizeof(*rcd), GFP_KERNEL);
  153. if (rcd) {
  154. INIT_LIST_HEAD(&rcd->qp_wait_list);
  155. rcd->ppd = ppd;
  156. rcd->dd = dd;
  157. rcd->cnt = 1;
  158. rcd->ctxt = ctxt;
  159. dd->rcd[ctxt] = rcd;
  160. dd->f_init_ctxt(rcd);
  161. /*
  162. * To avoid wasting a lot of memory, we allocate 32KB chunks
  163. * of physically contiguous memory, advance through it until
  164. * used up and then allocate more. Of course, we need
  165. * memory to store those extra pointers, now. 32KB seems to
  166. * be the most that is "safe" under memory pressure
  167. * (creating large files and then copying them over
  168. * NFS while doing lots of MPI jobs). The OOM killer can
  169. * get invoked, even though we say we can sleep and this can
  170. * cause significant system problems....
  171. */
  172. rcd->rcvegrbuf_size = 0x8000;
  173. rcd->rcvegrbufs_perchunk =
  174. rcd->rcvegrbuf_size / dd->rcvegrbufsize;
  175. rcd->rcvegrbuf_chunks = (rcd->rcvegrcnt +
  176. rcd->rcvegrbufs_perchunk - 1) /
  177. rcd->rcvegrbufs_perchunk;
  178. BUG_ON(!is_power_of_2(rcd->rcvegrbufs_perchunk));
  179. rcd->rcvegrbufs_perchunk_shift =
  180. ilog2(rcd->rcvegrbufs_perchunk);
  181. }
  182. return rcd;
  183. }
  184. /*
  185. * Common code for initializing the physical port structure.
  186. */
  187. void qib_init_pportdata(struct qib_pportdata *ppd, struct qib_devdata *dd,
  188. u8 hw_pidx, u8 port)
  189. {
  190. int size;
  191. ppd->dd = dd;
  192. ppd->hw_pidx = hw_pidx;
  193. ppd->port = port; /* IB port number, not index */
  194. spin_lock_init(&ppd->sdma_lock);
  195. spin_lock_init(&ppd->lflags_lock);
  196. init_waitqueue_head(&ppd->state_wait);
  197. init_timer(&ppd->symerr_clear_timer);
  198. ppd->symerr_clear_timer.function = qib_clear_symerror_on_linkup;
  199. ppd->symerr_clear_timer.data = (unsigned long)ppd;
  200. ppd->qib_wq = NULL;
  201. spin_lock_init(&ppd->cc_shadow_lock);
  202. if (qib_cc_table_size < IB_CCT_MIN_ENTRIES)
  203. goto bail;
  204. ppd->cc_supported_table_entries = min(max_t(int, qib_cc_table_size,
  205. IB_CCT_MIN_ENTRIES), IB_CCT_ENTRIES*IB_CC_TABLE_CAP_DEFAULT);
  206. ppd->cc_max_table_entries =
  207. ppd->cc_supported_table_entries/IB_CCT_ENTRIES;
  208. size = IB_CC_TABLE_CAP_DEFAULT * sizeof(struct ib_cc_table_entry)
  209. * IB_CCT_ENTRIES;
  210. ppd->ccti_entries = kzalloc(size, GFP_KERNEL);
  211. if (!ppd->ccti_entries) {
  212. qib_dev_err(dd,
  213. "failed to allocate congestion control table for port %d!\n",
  214. port);
  215. goto bail;
  216. }
  217. size = IB_CC_CCS_ENTRIES * sizeof(struct ib_cc_congestion_entry);
  218. ppd->congestion_entries = kzalloc(size, GFP_KERNEL);
  219. if (!ppd->congestion_entries) {
  220. qib_dev_err(dd,
  221. "failed to allocate congestion setting list for port %d!\n",
  222. port);
  223. goto bail_1;
  224. }
  225. size = sizeof(struct cc_table_shadow);
  226. ppd->ccti_entries_shadow = kzalloc(size, GFP_KERNEL);
  227. if (!ppd->ccti_entries_shadow) {
  228. qib_dev_err(dd,
  229. "failed to allocate shadow ccti list for port %d!\n",
  230. port);
  231. goto bail_2;
  232. }
  233. size = sizeof(struct ib_cc_congestion_setting_attr);
  234. ppd->congestion_entries_shadow = kzalloc(size, GFP_KERNEL);
  235. if (!ppd->congestion_entries_shadow) {
  236. qib_dev_err(dd,
  237. "failed to allocate shadow congestion setting list for port %d!\n",
  238. port);
  239. goto bail_3;
  240. }
  241. return;
  242. bail_3:
  243. kfree(ppd->ccti_entries_shadow);
  244. ppd->ccti_entries_shadow = NULL;
  245. bail_2:
  246. kfree(ppd->congestion_entries);
  247. ppd->congestion_entries = NULL;
  248. bail_1:
  249. kfree(ppd->ccti_entries);
  250. ppd->ccti_entries = NULL;
  251. bail:
  252. /* User is intentionally disabling the congestion control agent */
  253. if (!qib_cc_table_size)
  254. return;
  255. if (qib_cc_table_size < IB_CCT_MIN_ENTRIES) {
  256. qib_cc_table_size = 0;
  257. qib_dev_err(dd,
  258. "Congestion Control table size %d less than minimum %d for port %d\n",
  259. qib_cc_table_size, IB_CCT_MIN_ENTRIES, port);
  260. }
  261. qib_dev_err(dd, "Congestion Control Agent disabled for port %d\n",
  262. port);
  263. return;
  264. }
  265. static int init_pioavailregs(struct qib_devdata *dd)
  266. {
  267. int ret, pidx;
  268. u64 *status_page;
  269. dd->pioavailregs_dma = dma_alloc_coherent(
  270. &dd->pcidev->dev, PAGE_SIZE, &dd->pioavailregs_phys,
  271. GFP_KERNEL);
  272. if (!dd->pioavailregs_dma) {
  273. qib_dev_err(dd,
  274. "failed to allocate PIOavail reg area in memory\n");
  275. ret = -ENOMEM;
  276. goto done;
  277. }
  278. /*
  279. * We really want L2 cache aligned, but for current CPUs of
  280. * interest, they are the same.
  281. */
  282. status_page = (u64 *)
  283. ((char *) dd->pioavailregs_dma +
  284. ((2 * L1_CACHE_BYTES +
  285. dd->pioavregs * sizeof(u64)) & ~L1_CACHE_BYTES));
  286. /* device status comes first, for backwards compatibility */
  287. dd->devstatusp = status_page;
  288. *status_page++ = 0;
  289. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  290. dd->pport[pidx].statusp = status_page;
  291. *status_page++ = 0;
  292. }
  293. /*
  294. * Setup buffer to hold freeze and other messages, accessible to
  295. * apps, following statusp. This is per-unit, not per port.
  296. */
  297. dd->freezemsg = (char *) status_page;
  298. *dd->freezemsg = 0;
  299. /* length of msg buffer is "whatever is left" */
  300. ret = (char *) status_page - (char *) dd->pioavailregs_dma;
  301. dd->freezelen = PAGE_SIZE - ret;
  302. ret = 0;
  303. done:
  304. return ret;
  305. }
  306. /**
  307. * init_shadow_tids - allocate the shadow TID array
  308. * @dd: the qlogic_ib device
  309. *
  310. * allocate the shadow TID array, so we can qib_munlock previous
  311. * entries. It may make more sense to move the pageshadow to the
  312. * ctxt data structure, so we only allocate memory for ctxts actually
  313. * in use, since we at 8k per ctxt, now.
  314. * We don't want failures here to prevent use of the driver/chip,
  315. * so no return value.
  316. */
  317. static void init_shadow_tids(struct qib_devdata *dd)
  318. {
  319. struct page **pages;
  320. dma_addr_t *addrs;
  321. pages = vzalloc(dd->cfgctxts * dd->rcvtidcnt * sizeof(struct page *));
  322. if (!pages) {
  323. qib_dev_err(dd,
  324. "failed to allocate shadow page * array, no expected sends!\n");
  325. goto bail;
  326. }
  327. addrs = vzalloc(dd->cfgctxts * dd->rcvtidcnt * sizeof(dma_addr_t));
  328. if (!addrs) {
  329. qib_dev_err(dd,
  330. "failed to allocate shadow dma handle array, no expected sends!\n");
  331. goto bail_free;
  332. }
  333. dd->pageshadow = pages;
  334. dd->physshadow = addrs;
  335. return;
  336. bail_free:
  337. vfree(pages);
  338. bail:
  339. dd->pageshadow = NULL;
  340. }
  341. /*
  342. * Do initialization for device that is only needed on
  343. * first detect, not on resets.
  344. */
  345. static int loadtime_init(struct qib_devdata *dd)
  346. {
  347. int ret = 0;
  348. if (((dd->revision >> QLOGIC_IB_R_SOFTWARE_SHIFT) &
  349. QLOGIC_IB_R_SOFTWARE_MASK) != QIB_CHIP_SWVERSION) {
  350. qib_dev_err(dd,
  351. "Driver only handles version %d, chip swversion is %d (%llx), failng\n",
  352. QIB_CHIP_SWVERSION,
  353. (int)(dd->revision >>
  354. QLOGIC_IB_R_SOFTWARE_SHIFT) &
  355. QLOGIC_IB_R_SOFTWARE_MASK,
  356. (unsigned long long) dd->revision);
  357. ret = -ENOSYS;
  358. goto done;
  359. }
  360. if (dd->revision & QLOGIC_IB_R_EMULATOR_MASK)
  361. qib_devinfo(dd->pcidev, "%s", dd->boardversion);
  362. spin_lock_init(&dd->pioavail_lock);
  363. spin_lock_init(&dd->sendctrl_lock);
  364. spin_lock_init(&dd->uctxt_lock);
  365. spin_lock_init(&dd->qib_diag_trans_lock);
  366. spin_lock_init(&dd->eep_st_lock);
  367. mutex_init(&dd->eep_lock);
  368. if (qib_mini_init)
  369. goto done;
  370. ret = init_pioavailregs(dd);
  371. init_shadow_tids(dd);
  372. qib_get_eeprom_info(dd);
  373. /* setup time (don't start yet) to verify we got interrupt */
  374. init_timer(&dd->intrchk_timer);
  375. dd->intrchk_timer.function = verify_interrupt;
  376. dd->intrchk_timer.data = (unsigned long) dd;
  377. done:
  378. return ret;
  379. }
  380. /**
  381. * init_after_reset - re-initialize after a reset
  382. * @dd: the qlogic_ib device
  383. *
  384. * sanity check at least some of the values after reset, and
  385. * ensure no receive or transmit (explicitly, in case reset
  386. * failed
  387. */
  388. static int init_after_reset(struct qib_devdata *dd)
  389. {
  390. int i;
  391. /*
  392. * Ensure chip does no sends or receives, tail updates, or
  393. * pioavail updates while we re-initialize. This is mostly
  394. * for the driver data structures, not chip registers.
  395. */
  396. for (i = 0; i < dd->num_pports; ++i) {
  397. /*
  398. * ctxt == -1 means "all contexts". Only really safe for
  399. * _dis_abling things, as here.
  400. */
  401. dd->f_rcvctrl(dd->pport + i, QIB_RCVCTRL_CTXT_DIS |
  402. QIB_RCVCTRL_INTRAVAIL_DIS |
  403. QIB_RCVCTRL_TAILUPD_DIS, -1);
  404. /* Redundant across ports for some, but no big deal. */
  405. dd->f_sendctrl(dd->pport + i, QIB_SENDCTRL_SEND_DIS |
  406. QIB_SENDCTRL_AVAIL_DIS);
  407. }
  408. return 0;
  409. }
  410. static void enable_chip(struct qib_devdata *dd)
  411. {
  412. u64 rcvmask;
  413. int i;
  414. /*
  415. * Enable PIO send, and update of PIOavail regs to memory.
  416. */
  417. for (i = 0; i < dd->num_pports; ++i)
  418. dd->f_sendctrl(dd->pport + i, QIB_SENDCTRL_SEND_ENB |
  419. QIB_SENDCTRL_AVAIL_ENB);
  420. /*
  421. * Enable kernel ctxts' receive and receive interrupt.
  422. * Other ctxts done as user opens and inits them.
  423. */
  424. rcvmask = QIB_RCVCTRL_CTXT_ENB | QIB_RCVCTRL_INTRAVAIL_ENB;
  425. rcvmask |= (dd->flags & QIB_NODMA_RTAIL) ?
  426. QIB_RCVCTRL_TAILUPD_DIS : QIB_RCVCTRL_TAILUPD_ENB;
  427. for (i = 0; dd->rcd && i < dd->first_user_ctxt; ++i) {
  428. struct qib_ctxtdata *rcd = dd->rcd[i];
  429. if (rcd)
  430. dd->f_rcvctrl(rcd->ppd, rcvmask, i);
  431. }
  432. }
  433. static void verify_interrupt(unsigned long opaque)
  434. {
  435. struct qib_devdata *dd = (struct qib_devdata *) opaque;
  436. if (!dd)
  437. return; /* being torn down */
  438. /*
  439. * If we don't have a lid or any interrupts, let the user know and
  440. * don't bother checking again.
  441. */
  442. if (dd->int_counter == 0) {
  443. if (!dd->f_intr_fallback(dd))
  444. dev_err(&dd->pcidev->dev,
  445. "No interrupts detected, not usable.\n");
  446. else /* re-arm the timer to see if fallback works */
  447. mod_timer(&dd->intrchk_timer, jiffies + HZ/2);
  448. }
  449. }
  450. static void init_piobuf_state(struct qib_devdata *dd)
  451. {
  452. int i, pidx;
  453. u32 uctxts;
  454. /*
  455. * Ensure all buffers are free, and fifos empty. Buffers
  456. * are common, so only do once for port 0.
  457. *
  458. * After enable and qib_chg_pioavailkernel so we can safely
  459. * enable pioavail updates and PIOENABLE. After this, packets
  460. * are ready and able to go out.
  461. */
  462. dd->f_sendctrl(dd->pport, QIB_SENDCTRL_DISARM_ALL);
  463. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  464. dd->f_sendctrl(dd->pport + pidx, QIB_SENDCTRL_FLUSH);
  465. /*
  466. * If not all sendbufs are used, add the one to each of the lower
  467. * numbered contexts. pbufsctxt and lastctxt_piobuf are
  468. * calculated in chip-specific code because it may cause some
  469. * chip-specific adjustments to be made.
  470. */
  471. uctxts = dd->cfgctxts - dd->first_user_ctxt;
  472. dd->ctxts_extrabuf = dd->pbufsctxt ?
  473. dd->lastctxt_piobuf - (dd->pbufsctxt * uctxts) : 0;
  474. /*
  475. * Set up the shadow copies of the piobufavail registers,
  476. * which we compare against the chip registers for now, and
  477. * the in memory DMA'ed copies of the registers.
  478. * By now pioavail updates to memory should have occurred, so
  479. * copy them into our working/shadow registers; this is in
  480. * case something went wrong with abort, but mostly to get the
  481. * initial values of the generation bit correct.
  482. */
  483. for (i = 0; i < dd->pioavregs; i++) {
  484. __le64 tmp;
  485. tmp = dd->pioavailregs_dma[i];
  486. /*
  487. * Don't need to worry about pioavailkernel here
  488. * because we will call qib_chg_pioavailkernel() later
  489. * in initialization, to busy out buffers as needed.
  490. */
  491. dd->pioavailshadow[i] = le64_to_cpu(tmp);
  492. }
  493. while (i < ARRAY_SIZE(dd->pioavailshadow))
  494. dd->pioavailshadow[i++] = 0; /* for debugging sanity */
  495. /* after pioavailshadow is setup */
  496. qib_chg_pioavailkernel(dd, 0, dd->piobcnt2k + dd->piobcnt4k,
  497. TXCHK_CHG_TYPE_KERN, NULL);
  498. dd->f_initvl15_bufs(dd);
  499. }
  500. /**
  501. * qib_create_workqueues - create per port workqueues
  502. * @dd: the qlogic_ib device
  503. */
  504. static int qib_create_workqueues(struct qib_devdata *dd)
  505. {
  506. int pidx;
  507. struct qib_pportdata *ppd;
  508. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  509. ppd = dd->pport + pidx;
  510. if (!ppd->qib_wq) {
  511. char wq_name[8]; /* 3 + 2 + 1 + 1 + 1 */
  512. snprintf(wq_name, sizeof(wq_name), "qib%d_%d",
  513. dd->unit, pidx);
  514. ppd->qib_wq =
  515. create_singlethread_workqueue(wq_name);
  516. if (!ppd->qib_wq)
  517. goto wq_error;
  518. }
  519. }
  520. return 0;
  521. wq_error:
  522. pr_err("create_singlethread_workqueue failed for port %d\n",
  523. pidx + 1);
  524. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  525. ppd = dd->pport + pidx;
  526. if (ppd->qib_wq) {
  527. destroy_workqueue(ppd->qib_wq);
  528. ppd->qib_wq = NULL;
  529. }
  530. }
  531. return -ENOMEM;
  532. }
  533. /**
  534. * qib_init - do the actual initialization sequence on the chip
  535. * @dd: the qlogic_ib device
  536. * @reinit: reinitializing, so don't allocate new memory
  537. *
  538. * Do the actual initialization sequence on the chip. This is done
  539. * both from the init routine called from the PCI infrastructure, and
  540. * when we reset the chip, or detect that it was reset internally,
  541. * or it's administratively re-enabled.
  542. *
  543. * Memory allocation here and in called routines is only done in
  544. * the first case (reinit == 0). We have to be careful, because even
  545. * without memory allocation, we need to re-write all the chip registers
  546. * TIDs, etc. after the reset or enable has completed.
  547. */
  548. int qib_init(struct qib_devdata *dd, int reinit)
  549. {
  550. int ret = 0, pidx, lastfail = 0;
  551. u32 portok = 0;
  552. unsigned i;
  553. struct qib_ctxtdata *rcd;
  554. struct qib_pportdata *ppd;
  555. unsigned long flags;
  556. /* Set linkstate to unknown, so we can watch for a transition. */
  557. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  558. ppd = dd->pport + pidx;
  559. spin_lock_irqsave(&ppd->lflags_lock, flags);
  560. ppd->lflags &= ~(QIBL_LINKACTIVE | QIBL_LINKARMED |
  561. QIBL_LINKDOWN | QIBL_LINKINIT |
  562. QIBL_LINKV);
  563. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  564. }
  565. if (reinit)
  566. ret = init_after_reset(dd);
  567. else
  568. ret = loadtime_init(dd);
  569. if (ret)
  570. goto done;
  571. /* Bypass most chip-init, to get to device creation */
  572. if (qib_mini_init)
  573. return 0;
  574. ret = dd->f_late_initreg(dd);
  575. if (ret)
  576. goto done;
  577. /* dd->rcd can be NULL if early init failed */
  578. for (i = 0; dd->rcd && i < dd->first_user_ctxt; ++i) {
  579. /*
  580. * Set up the (kernel) rcvhdr queue and egr TIDs. If doing
  581. * re-init, the simplest way to handle this is to free
  582. * existing, and re-allocate.
  583. * Need to re-create rest of ctxt 0 ctxtdata as well.
  584. */
  585. rcd = dd->rcd[i];
  586. if (!rcd)
  587. continue;
  588. lastfail = qib_create_rcvhdrq(dd, rcd);
  589. if (!lastfail)
  590. lastfail = qib_setup_eagerbufs(rcd);
  591. if (lastfail) {
  592. qib_dev_err(dd,
  593. "failed to allocate kernel ctxt's rcvhdrq and/or egr bufs\n");
  594. continue;
  595. }
  596. }
  597. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  598. int mtu;
  599. if (lastfail)
  600. ret = lastfail;
  601. ppd = dd->pport + pidx;
  602. mtu = ib_mtu_enum_to_int(qib_ibmtu);
  603. if (mtu == -1) {
  604. mtu = QIB_DEFAULT_MTU;
  605. qib_ibmtu = 0; /* don't leave invalid value */
  606. }
  607. /* set max we can ever have for this driver load */
  608. ppd->init_ibmaxlen = min(mtu > 2048 ?
  609. dd->piosize4k : dd->piosize2k,
  610. dd->rcvegrbufsize +
  611. (dd->rcvhdrentsize << 2));
  612. /*
  613. * Have to initialize ibmaxlen, but this will normally
  614. * change immediately in qib_set_mtu().
  615. */
  616. ppd->ibmaxlen = ppd->init_ibmaxlen;
  617. qib_set_mtu(ppd, mtu);
  618. spin_lock_irqsave(&ppd->lflags_lock, flags);
  619. ppd->lflags |= QIBL_IB_LINK_DISABLED;
  620. spin_unlock_irqrestore(&ppd->lflags_lock, flags);
  621. lastfail = dd->f_bringup_serdes(ppd);
  622. if (lastfail) {
  623. qib_devinfo(dd->pcidev,
  624. "Failed to bringup IB port %u\n", ppd->port);
  625. lastfail = -ENETDOWN;
  626. continue;
  627. }
  628. portok++;
  629. }
  630. if (!portok) {
  631. /* none of the ports initialized */
  632. if (!ret && lastfail)
  633. ret = lastfail;
  634. else if (!ret)
  635. ret = -ENETDOWN;
  636. /* but continue on, so we can debug cause */
  637. }
  638. enable_chip(dd);
  639. init_piobuf_state(dd);
  640. done:
  641. if (!ret) {
  642. /* chip is OK for user apps; mark it as initialized */
  643. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  644. ppd = dd->pport + pidx;
  645. /*
  646. * Set status even if port serdes is not initialized
  647. * so that diags will work.
  648. */
  649. *ppd->statusp |= QIB_STATUS_CHIP_PRESENT |
  650. QIB_STATUS_INITTED;
  651. if (!ppd->link_speed_enabled)
  652. continue;
  653. if (dd->flags & QIB_HAS_SEND_DMA)
  654. ret = qib_setup_sdma(ppd);
  655. init_timer(&ppd->hol_timer);
  656. ppd->hol_timer.function = qib_hol_event;
  657. ppd->hol_timer.data = (unsigned long)ppd;
  658. ppd->hol_state = QIB_HOL_UP;
  659. }
  660. /* now we can enable all interrupts from the chip */
  661. dd->f_set_intr_state(dd, 1);
  662. /*
  663. * Setup to verify we get an interrupt, and fallback
  664. * to an alternate if necessary and possible.
  665. */
  666. mod_timer(&dd->intrchk_timer, jiffies + HZ/2);
  667. /* start stats retrieval timer */
  668. mod_timer(&dd->stats_timer, jiffies + HZ * ACTIVITY_TIMER);
  669. }
  670. /* if ret is non-zero, we probably should do some cleanup here... */
  671. return ret;
  672. }
  673. /*
  674. * These next two routines are placeholders in case we don't have per-arch
  675. * code for controlling write combining. If explicit control of write
  676. * combining is not available, performance will probably be awful.
  677. */
  678. int __attribute__((weak)) qib_enable_wc(struct qib_devdata *dd)
  679. {
  680. return -EOPNOTSUPP;
  681. }
  682. void __attribute__((weak)) qib_disable_wc(struct qib_devdata *dd)
  683. {
  684. }
  685. static inline struct qib_devdata *__qib_lookup(int unit)
  686. {
  687. return idr_find(&qib_unit_table, unit);
  688. }
  689. struct qib_devdata *qib_lookup(int unit)
  690. {
  691. struct qib_devdata *dd;
  692. unsigned long flags;
  693. spin_lock_irqsave(&qib_devs_lock, flags);
  694. dd = __qib_lookup(unit);
  695. spin_unlock_irqrestore(&qib_devs_lock, flags);
  696. return dd;
  697. }
  698. /*
  699. * Stop the timers during unit shutdown, or after an error late
  700. * in initialization.
  701. */
  702. static void qib_stop_timers(struct qib_devdata *dd)
  703. {
  704. struct qib_pportdata *ppd;
  705. int pidx;
  706. if (dd->stats_timer.data) {
  707. del_timer_sync(&dd->stats_timer);
  708. dd->stats_timer.data = 0;
  709. }
  710. if (dd->intrchk_timer.data) {
  711. del_timer_sync(&dd->intrchk_timer);
  712. dd->intrchk_timer.data = 0;
  713. }
  714. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  715. ppd = dd->pport + pidx;
  716. if (ppd->hol_timer.data)
  717. del_timer_sync(&ppd->hol_timer);
  718. if (ppd->led_override_timer.data) {
  719. del_timer_sync(&ppd->led_override_timer);
  720. atomic_set(&ppd->led_override_timer_active, 0);
  721. }
  722. if (ppd->symerr_clear_timer.data)
  723. del_timer_sync(&ppd->symerr_clear_timer);
  724. }
  725. }
  726. /**
  727. * qib_shutdown_device - shut down a device
  728. * @dd: the qlogic_ib device
  729. *
  730. * This is called to make the device quiet when we are about to
  731. * unload the driver, and also when the device is administratively
  732. * disabled. It does not free any data structures.
  733. * Everything it does has to be setup again by qib_init(dd, 1)
  734. */
  735. static void qib_shutdown_device(struct qib_devdata *dd)
  736. {
  737. struct qib_pportdata *ppd;
  738. unsigned pidx;
  739. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  740. ppd = dd->pport + pidx;
  741. spin_lock_irq(&ppd->lflags_lock);
  742. ppd->lflags &= ~(QIBL_LINKDOWN | QIBL_LINKINIT |
  743. QIBL_LINKARMED | QIBL_LINKACTIVE |
  744. QIBL_LINKV);
  745. spin_unlock_irq(&ppd->lflags_lock);
  746. *ppd->statusp &= ~(QIB_STATUS_IB_CONF | QIB_STATUS_IB_READY);
  747. }
  748. dd->flags &= ~QIB_INITTED;
  749. /* mask interrupts, but not errors */
  750. dd->f_set_intr_state(dd, 0);
  751. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  752. ppd = dd->pport + pidx;
  753. dd->f_rcvctrl(ppd, QIB_RCVCTRL_TAILUPD_DIS |
  754. QIB_RCVCTRL_CTXT_DIS |
  755. QIB_RCVCTRL_INTRAVAIL_DIS |
  756. QIB_RCVCTRL_PKEY_ENB, -1);
  757. /*
  758. * Gracefully stop all sends allowing any in progress to
  759. * trickle out first.
  760. */
  761. dd->f_sendctrl(ppd, QIB_SENDCTRL_CLEAR);
  762. }
  763. /*
  764. * Enough for anything that's going to trickle out to have actually
  765. * done so.
  766. */
  767. udelay(20);
  768. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  769. ppd = dd->pport + pidx;
  770. dd->f_setextled(ppd, 0); /* make sure LEDs are off */
  771. if (dd->flags & QIB_HAS_SEND_DMA)
  772. qib_teardown_sdma(ppd);
  773. dd->f_sendctrl(ppd, QIB_SENDCTRL_AVAIL_DIS |
  774. QIB_SENDCTRL_SEND_DIS);
  775. /*
  776. * Clear SerdesEnable.
  777. * We can't count on interrupts since we are stopping.
  778. */
  779. dd->f_quiet_serdes(ppd);
  780. if (ppd->qib_wq) {
  781. destroy_workqueue(ppd->qib_wq);
  782. ppd->qib_wq = NULL;
  783. }
  784. }
  785. qib_update_eeprom_log(dd);
  786. }
  787. /**
  788. * qib_free_ctxtdata - free a context's allocated data
  789. * @dd: the qlogic_ib device
  790. * @rcd: the ctxtdata structure
  791. *
  792. * free up any allocated data for a context
  793. * This should not touch anything that would affect a simultaneous
  794. * re-allocation of context data, because it is called after qib_mutex
  795. * is released (and can be called from reinit as well).
  796. * It should never change any chip state, or global driver state.
  797. */
  798. void qib_free_ctxtdata(struct qib_devdata *dd, struct qib_ctxtdata *rcd)
  799. {
  800. if (!rcd)
  801. return;
  802. if (rcd->rcvhdrq) {
  803. dma_free_coherent(&dd->pcidev->dev, rcd->rcvhdrq_size,
  804. rcd->rcvhdrq, rcd->rcvhdrq_phys);
  805. rcd->rcvhdrq = NULL;
  806. if (rcd->rcvhdrtail_kvaddr) {
  807. dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
  808. rcd->rcvhdrtail_kvaddr,
  809. rcd->rcvhdrqtailaddr_phys);
  810. rcd->rcvhdrtail_kvaddr = NULL;
  811. }
  812. }
  813. if (rcd->rcvegrbuf) {
  814. unsigned e;
  815. for (e = 0; e < rcd->rcvegrbuf_chunks; e++) {
  816. void *base = rcd->rcvegrbuf[e];
  817. size_t size = rcd->rcvegrbuf_size;
  818. dma_free_coherent(&dd->pcidev->dev, size,
  819. base, rcd->rcvegrbuf_phys[e]);
  820. }
  821. kfree(rcd->rcvegrbuf);
  822. rcd->rcvegrbuf = NULL;
  823. kfree(rcd->rcvegrbuf_phys);
  824. rcd->rcvegrbuf_phys = NULL;
  825. rcd->rcvegrbuf_chunks = 0;
  826. }
  827. kfree(rcd->tid_pg_list);
  828. vfree(rcd->user_event_mask);
  829. vfree(rcd->subctxt_uregbase);
  830. vfree(rcd->subctxt_rcvegrbuf);
  831. vfree(rcd->subctxt_rcvhdr_base);
  832. kfree(rcd);
  833. }
  834. /*
  835. * Perform a PIO buffer bandwidth write test, to verify proper system
  836. * configuration. Even when all the setup calls work, occasionally
  837. * BIOS or other issues can prevent write combining from working, or
  838. * can cause other bandwidth problems to the chip.
  839. *
  840. * This test simply writes the same buffer over and over again, and
  841. * measures close to the peak bandwidth to the chip (not testing
  842. * data bandwidth to the wire). On chips that use an address-based
  843. * trigger to send packets to the wire, this is easy. On chips that
  844. * use a count to trigger, we want to make sure that the packet doesn't
  845. * go out on the wire, or trigger flow control checks.
  846. */
  847. static void qib_verify_pioperf(struct qib_devdata *dd)
  848. {
  849. u32 pbnum, cnt, lcnt;
  850. u32 __iomem *piobuf;
  851. u32 *addr;
  852. u64 msecs, emsecs;
  853. piobuf = dd->f_getsendbuf(dd->pport, 0ULL, &pbnum);
  854. if (!piobuf) {
  855. qib_devinfo(dd->pcidev,
  856. "No PIObufs for checking perf, skipping\n");
  857. return;
  858. }
  859. /*
  860. * Enough to give us a reasonable test, less than piobuf size, and
  861. * likely multiple of store buffer length.
  862. */
  863. cnt = 1024;
  864. addr = vmalloc(cnt);
  865. if (!addr) {
  866. qib_devinfo(dd->pcidev,
  867. "Couldn't get memory for checking PIO perf,"
  868. " skipping\n");
  869. goto done;
  870. }
  871. preempt_disable(); /* we want reasonably accurate elapsed time */
  872. msecs = 1 + jiffies_to_msecs(jiffies);
  873. for (lcnt = 0; lcnt < 10000U; lcnt++) {
  874. /* wait until we cross msec boundary */
  875. if (jiffies_to_msecs(jiffies) >= msecs)
  876. break;
  877. udelay(1);
  878. }
  879. dd->f_set_armlaunch(dd, 0);
  880. /*
  881. * length 0, no dwords actually sent
  882. */
  883. writeq(0, piobuf);
  884. qib_flush_wc();
  885. /*
  886. * This is only roughly accurate, since even with preempt we
  887. * still take interrupts that could take a while. Running for
  888. * >= 5 msec seems to get us "close enough" to accurate values.
  889. */
  890. msecs = jiffies_to_msecs(jiffies);
  891. for (emsecs = lcnt = 0; emsecs <= 5UL; lcnt++) {
  892. qib_pio_copy(piobuf + 64, addr, cnt >> 2);
  893. emsecs = jiffies_to_msecs(jiffies) - msecs;
  894. }
  895. /* 1 GiB/sec, slightly over IB SDR line rate */
  896. if (lcnt < (emsecs * 1024U))
  897. qib_dev_err(dd,
  898. "Performance problem: bandwidth to PIO buffers is only %u MiB/sec\n",
  899. lcnt / (u32) emsecs);
  900. preempt_enable();
  901. vfree(addr);
  902. done:
  903. /* disarm piobuf, so it's available again */
  904. dd->f_sendctrl(dd->pport, QIB_SENDCTRL_DISARM_BUF(pbnum));
  905. qib_sendbuf_done(dd, pbnum);
  906. dd->f_set_armlaunch(dd, 1);
  907. }
  908. void qib_free_devdata(struct qib_devdata *dd)
  909. {
  910. unsigned long flags;
  911. spin_lock_irqsave(&qib_devs_lock, flags);
  912. idr_remove(&qib_unit_table, dd->unit);
  913. list_del(&dd->list);
  914. spin_unlock_irqrestore(&qib_devs_lock, flags);
  915. ib_dealloc_device(&dd->verbs_dev.ibdev);
  916. }
  917. /*
  918. * Allocate our primary per-unit data structure. Must be done via verbs
  919. * allocator, because the verbs cleanup process both does cleanup and
  920. * free of the data structure.
  921. * "extra" is for chip-specific data.
  922. *
  923. * Use the idr mechanism to get a unit number for this unit.
  924. */
  925. struct qib_devdata *qib_alloc_devdata(struct pci_dev *pdev, size_t extra)
  926. {
  927. unsigned long flags;
  928. struct qib_devdata *dd;
  929. int ret;
  930. dd = (struct qib_devdata *) ib_alloc_device(sizeof(*dd) + extra);
  931. if (!dd) {
  932. dd = ERR_PTR(-ENOMEM);
  933. goto bail;
  934. }
  935. idr_preload(GFP_KERNEL);
  936. spin_lock_irqsave(&qib_devs_lock, flags);
  937. ret = idr_alloc(&qib_unit_table, dd, 0, 0, GFP_NOWAIT);
  938. if (ret >= 0) {
  939. dd->unit = ret;
  940. list_add(&dd->list, &qib_dev_list);
  941. }
  942. spin_unlock_irqrestore(&qib_devs_lock, flags);
  943. idr_preload_end();
  944. if (ret < 0) {
  945. qib_early_err(&pdev->dev,
  946. "Could not allocate unit ID: error %d\n", -ret);
  947. ib_dealloc_device(&dd->verbs_dev.ibdev);
  948. dd = ERR_PTR(ret);
  949. goto bail;
  950. }
  951. if (!qib_cpulist_count) {
  952. u32 count = num_online_cpus();
  953. qib_cpulist = kzalloc(BITS_TO_LONGS(count) *
  954. sizeof(long), GFP_KERNEL);
  955. if (qib_cpulist)
  956. qib_cpulist_count = count;
  957. else
  958. qib_early_err(&pdev->dev,
  959. "Could not alloc cpulist info, cpu affinity might be wrong\n");
  960. }
  961. bail:
  962. return dd;
  963. }
  964. /*
  965. * Called from freeze mode handlers, and from PCI error
  966. * reporting code. Should be paranoid about state of
  967. * system and data structures.
  968. */
  969. void qib_disable_after_error(struct qib_devdata *dd)
  970. {
  971. if (dd->flags & QIB_INITTED) {
  972. u32 pidx;
  973. dd->flags &= ~QIB_INITTED;
  974. if (dd->pport)
  975. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  976. struct qib_pportdata *ppd;
  977. ppd = dd->pport + pidx;
  978. if (dd->flags & QIB_PRESENT) {
  979. qib_set_linkstate(ppd,
  980. QIB_IB_LINKDOWN_DISABLE);
  981. dd->f_setextled(ppd, 0);
  982. }
  983. *ppd->statusp &= ~QIB_STATUS_IB_READY;
  984. }
  985. }
  986. /*
  987. * Mark as having had an error for driver, and also
  988. * for /sys and status word mapped to user programs.
  989. * This marks unit as not usable, until reset.
  990. */
  991. if (dd->devstatusp)
  992. *dd->devstatusp |= QIB_STATUS_HWERROR;
  993. }
  994. static void qib_remove_one(struct pci_dev *);
  995. static int qib_init_one(struct pci_dev *, const struct pci_device_id *);
  996. #define DRIVER_LOAD_MSG "Intel " QIB_DRV_NAME " loaded: "
  997. #define PFX QIB_DRV_NAME ": "
  998. static DEFINE_PCI_DEVICE_TABLE(qib_pci_tbl) = {
  999. { PCI_DEVICE(PCI_VENDOR_ID_PATHSCALE, PCI_DEVICE_ID_QLOGIC_IB_6120) },
  1000. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_IB_7220) },
  1001. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_IB_7322) },
  1002. { 0, }
  1003. };
  1004. MODULE_DEVICE_TABLE(pci, qib_pci_tbl);
  1005. struct pci_driver qib_driver = {
  1006. .name = QIB_DRV_NAME,
  1007. .probe = qib_init_one,
  1008. .remove = qib_remove_one,
  1009. .id_table = qib_pci_tbl,
  1010. .err_handler = &qib_pci_err_handler,
  1011. };
  1012. #ifdef CONFIG_INFINIBAND_QIB_DCA
  1013. static int qib_notify_dca(struct notifier_block *, unsigned long, void *);
  1014. static struct notifier_block dca_notifier = {
  1015. .notifier_call = qib_notify_dca,
  1016. .next = NULL,
  1017. .priority = 0
  1018. };
  1019. static int qib_notify_dca_device(struct device *device, void *data)
  1020. {
  1021. struct qib_devdata *dd = dev_get_drvdata(device);
  1022. unsigned long event = *(unsigned long *)data;
  1023. return dd->f_notify_dca(dd, event);
  1024. }
  1025. static int qib_notify_dca(struct notifier_block *nb, unsigned long event,
  1026. void *p)
  1027. {
  1028. int rval;
  1029. rval = driver_for_each_device(&qib_driver.driver, NULL,
  1030. &event, qib_notify_dca_device);
  1031. return rval ? NOTIFY_BAD : NOTIFY_DONE;
  1032. }
  1033. #endif
  1034. /*
  1035. * Do all the generic driver unit- and chip-independent memory
  1036. * allocation and initialization.
  1037. */
  1038. static int __init qlogic_ib_init(void)
  1039. {
  1040. int ret;
  1041. ret = qib_dev_init();
  1042. if (ret)
  1043. goto bail;
  1044. qib_cq_wq = create_singlethread_workqueue("qib_cq");
  1045. if (!qib_cq_wq) {
  1046. ret = -ENOMEM;
  1047. goto bail_dev;
  1048. }
  1049. /*
  1050. * These must be called before the driver is registered with
  1051. * the PCI subsystem.
  1052. */
  1053. idr_init(&qib_unit_table);
  1054. #ifdef CONFIG_INFINIBAND_QIB_DCA
  1055. dca_register_notify(&dca_notifier);
  1056. #endif
  1057. ret = pci_register_driver(&qib_driver);
  1058. if (ret < 0) {
  1059. pr_err("Unable to register driver: error %d\n", -ret);
  1060. goto bail_unit;
  1061. }
  1062. /* not fatal if it doesn't work */
  1063. if (qib_init_qibfs())
  1064. pr_err("Unable to register ipathfs\n");
  1065. goto bail; /* all OK */
  1066. bail_unit:
  1067. #ifdef CONFIG_INFINIBAND_QIB_DCA
  1068. dca_unregister_notify(&dca_notifier);
  1069. #endif
  1070. idr_destroy(&qib_unit_table);
  1071. destroy_workqueue(qib_cq_wq);
  1072. bail_dev:
  1073. qib_dev_cleanup();
  1074. bail:
  1075. return ret;
  1076. }
  1077. module_init(qlogic_ib_init);
  1078. /*
  1079. * Do the non-unit driver cleanup, memory free, etc. at unload.
  1080. */
  1081. static void __exit qlogic_ib_cleanup(void)
  1082. {
  1083. int ret;
  1084. ret = qib_exit_qibfs();
  1085. if (ret)
  1086. pr_err(
  1087. "Unable to cleanup counter filesystem: error %d\n",
  1088. -ret);
  1089. #ifdef CONFIG_INFINIBAND_QIB_DCA
  1090. dca_unregister_notify(&dca_notifier);
  1091. #endif
  1092. pci_unregister_driver(&qib_driver);
  1093. destroy_workqueue(qib_cq_wq);
  1094. qib_cpulist_count = 0;
  1095. kfree(qib_cpulist);
  1096. idr_destroy(&qib_unit_table);
  1097. qib_dev_cleanup();
  1098. }
  1099. module_exit(qlogic_ib_cleanup);
  1100. /* this can only be called after a successful initialization */
  1101. static void cleanup_device_data(struct qib_devdata *dd)
  1102. {
  1103. int ctxt;
  1104. int pidx;
  1105. struct qib_ctxtdata **tmp;
  1106. unsigned long flags;
  1107. /* users can't do anything more with chip */
  1108. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  1109. if (dd->pport[pidx].statusp)
  1110. *dd->pport[pidx].statusp &= ~QIB_STATUS_CHIP_PRESENT;
  1111. spin_lock(&dd->pport[pidx].cc_shadow_lock);
  1112. kfree(dd->pport[pidx].congestion_entries);
  1113. dd->pport[pidx].congestion_entries = NULL;
  1114. kfree(dd->pport[pidx].ccti_entries);
  1115. dd->pport[pidx].ccti_entries = NULL;
  1116. kfree(dd->pport[pidx].ccti_entries_shadow);
  1117. dd->pport[pidx].ccti_entries_shadow = NULL;
  1118. kfree(dd->pport[pidx].congestion_entries_shadow);
  1119. dd->pport[pidx].congestion_entries_shadow = NULL;
  1120. spin_unlock(&dd->pport[pidx].cc_shadow_lock);
  1121. }
  1122. if (!qib_wc_pat)
  1123. qib_disable_wc(dd);
  1124. if (dd->pioavailregs_dma) {
  1125. dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
  1126. (void *) dd->pioavailregs_dma,
  1127. dd->pioavailregs_phys);
  1128. dd->pioavailregs_dma = NULL;
  1129. }
  1130. if (dd->pageshadow) {
  1131. struct page **tmpp = dd->pageshadow;
  1132. dma_addr_t *tmpd = dd->physshadow;
  1133. int i, cnt = 0;
  1134. for (ctxt = 0; ctxt < dd->cfgctxts; ctxt++) {
  1135. int ctxt_tidbase = ctxt * dd->rcvtidcnt;
  1136. int maxtid = ctxt_tidbase + dd->rcvtidcnt;
  1137. for (i = ctxt_tidbase; i < maxtid; i++) {
  1138. if (!tmpp[i])
  1139. continue;
  1140. pci_unmap_page(dd->pcidev, tmpd[i],
  1141. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  1142. qib_release_user_pages(&tmpp[i], 1);
  1143. tmpp[i] = NULL;
  1144. cnt++;
  1145. }
  1146. }
  1147. tmpp = dd->pageshadow;
  1148. dd->pageshadow = NULL;
  1149. vfree(tmpp);
  1150. }
  1151. /*
  1152. * Free any resources still in use (usually just kernel contexts)
  1153. * at unload; we do for ctxtcnt, because that's what we allocate.
  1154. * We acquire lock to be really paranoid that rcd isn't being
  1155. * accessed from some interrupt-related code (that should not happen,
  1156. * but best to be sure).
  1157. */
  1158. spin_lock_irqsave(&dd->uctxt_lock, flags);
  1159. tmp = dd->rcd;
  1160. dd->rcd = NULL;
  1161. spin_unlock_irqrestore(&dd->uctxt_lock, flags);
  1162. for (ctxt = 0; tmp && ctxt < dd->ctxtcnt; ctxt++) {
  1163. struct qib_ctxtdata *rcd = tmp[ctxt];
  1164. tmp[ctxt] = NULL; /* debugging paranoia */
  1165. qib_free_ctxtdata(dd, rcd);
  1166. }
  1167. kfree(tmp);
  1168. kfree(dd->boardname);
  1169. }
  1170. /*
  1171. * Clean up on unit shutdown, or error during unit load after
  1172. * successful initialization.
  1173. */
  1174. static void qib_postinit_cleanup(struct qib_devdata *dd)
  1175. {
  1176. /*
  1177. * Clean up chip-specific stuff.
  1178. * We check for NULL here, because it's outside
  1179. * the kregbase check, and we need to call it
  1180. * after the free_irq. Thus it's possible that
  1181. * the function pointers were never initialized.
  1182. */
  1183. if (dd->f_cleanup)
  1184. dd->f_cleanup(dd);
  1185. qib_pcie_ddcleanup(dd);
  1186. cleanup_device_data(dd);
  1187. qib_free_devdata(dd);
  1188. }
  1189. static int qib_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  1190. {
  1191. int ret, j, pidx, initfail;
  1192. struct qib_devdata *dd = NULL;
  1193. ret = qib_pcie_init(pdev, ent);
  1194. if (ret)
  1195. goto bail;
  1196. /*
  1197. * Do device-specific initialiation, function table setup, dd
  1198. * allocation, etc.
  1199. */
  1200. switch (ent->device) {
  1201. case PCI_DEVICE_ID_QLOGIC_IB_6120:
  1202. #ifdef CONFIG_PCI_MSI
  1203. dd = qib_init_iba6120_funcs(pdev, ent);
  1204. #else
  1205. qib_early_err(&pdev->dev,
  1206. "Intel PCIE device 0x%x cannot work if CONFIG_PCI_MSI is not enabled\n",
  1207. ent->device);
  1208. dd = ERR_PTR(-ENODEV);
  1209. #endif
  1210. break;
  1211. case PCI_DEVICE_ID_QLOGIC_IB_7220:
  1212. dd = qib_init_iba7220_funcs(pdev, ent);
  1213. break;
  1214. case PCI_DEVICE_ID_QLOGIC_IB_7322:
  1215. dd = qib_init_iba7322_funcs(pdev, ent);
  1216. break;
  1217. default:
  1218. qib_early_err(&pdev->dev,
  1219. "Failing on unknown Intel deviceid 0x%x\n",
  1220. ent->device);
  1221. ret = -ENODEV;
  1222. }
  1223. if (IS_ERR(dd))
  1224. ret = PTR_ERR(dd);
  1225. if (ret)
  1226. goto bail; /* error already printed */
  1227. ret = qib_create_workqueues(dd);
  1228. if (ret)
  1229. goto bail;
  1230. /* do the generic initialization */
  1231. initfail = qib_init(dd, 0);
  1232. ret = qib_register_ib_device(dd);
  1233. /*
  1234. * Now ready for use. this should be cleared whenever we
  1235. * detect a reset, or initiate one. If earlier failure,
  1236. * we still create devices, so diags, etc. can be used
  1237. * to determine cause of problem.
  1238. */
  1239. if (!qib_mini_init && !initfail && !ret)
  1240. dd->flags |= QIB_INITTED;
  1241. j = qib_device_create(dd);
  1242. if (j)
  1243. qib_dev_err(dd, "Failed to create /dev devices: %d\n", -j);
  1244. j = qibfs_add(dd);
  1245. if (j)
  1246. qib_dev_err(dd, "Failed filesystem setup for counters: %d\n",
  1247. -j);
  1248. if (qib_mini_init || initfail || ret) {
  1249. qib_stop_timers(dd);
  1250. flush_workqueue(ib_wq);
  1251. for (pidx = 0; pidx < dd->num_pports; ++pidx)
  1252. dd->f_quiet_serdes(dd->pport + pidx);
  1253. if (qib_mini_init)
  1254. goto bail;
  1255. if (!j) {
  1256. (void) qibfs_remove(dd);
  1257. qib_device_remove(dd);
  1258. }
  1259. if (!ret)
  1260. qib_unregister_ib_device(dd);
  1261. qib_postinit_cleanup(dd);
  1262. if (initfail)
  1263. ret = initfail;
  1264. goto bail;
  1265. }
  1266. if (!qib_wc_pat) {
  1267. ret = qib_enable_wc(dd);
  1268. if (ret) {
  1269. qib_dev_err(dd,
  1270. "Write combining not enabled (err %d): performance may be poor\n",
  1271. -ret);
  1272. ret = 0;
  1273. }
  1274. }
  1275. qib_verify_pioperf(dd);
  1276. bail:
  1277. return ret;
  1278. }
  1279. static void qib_remove_one(struct pci_dev *pdev)
  1280. {
  1281. struct qib_devdata *dd = pci_get_drvdata(pdev);
  1282. int ret;
  1283. /* unregister from IB core */
  1284. qib_unregister_ib_device(dd);
  1285. /*
  1286. * Disable the IB link, disable interrupts on the device,
  1287. * clear dma engines, etc.
  1288. */
  1289. if (!qib_mini_init)
  1290. qib_shutdown_device(dd);
  1291. qib_stop_timers(dd);
  1292. /* wait until all of our (qsfp) queue_work() calls complete */
  1293. flush_workqueue(ib_wq);
  1294. ret = qibfs_remove(dd);
  1295. if (ret)
  1296. qib_dev_err(dd, "Failed counters filesystem cleanup: %d\n",
  1297. -ret);
  1298. qib_device_remove(dd);
  1299. qib_postinit_cleanup(dd);
  1300. }
  1301. /**
  1302. * qib_create_rcvhdrq - create a receive header queue
  1303. * @dd: the qlogic_ib device
  1304. * @rcd: the context data
  1305. *
  1306. * This must be contiguous memory (from an i/o perspective), and must be
  1307. * DMA'able (which means for some systems, it will go through an IOMMU,
  1308. * or be forced into a low address range).
  1309. */
  1310. int qib_create_rcvhdrq(struct qib_devdata *dd, struct qib_ctxtdata *rcd)
  1311. {
  1312. unsigned amt;
  1313. if (!rcd->rcvhdrq) {
  1314. dma_addr_t phys_hdrqtail;
  1315. gfp_t gfp_flags;
  1316. amt = ALIGN(dd->rcvhdrcnt * dd->rcvhdrentsize *
  1317. sizeof(u32), PAGE_SIZE);
  1318. gfp_flags = (rcd->ctxt >= dd->first_user_ctxt) ?
  1319. GFP_USER : GFP_KERNEL;
  1320. rcd->rcvhdrq = dma_alloc_coherent(
  1321. &dd->pcidev->dev, amt, &rcd->rcvhdrq_phys,
  1322. gfp_flags | __GFP_COMP);
  1323. if (!rcd->rcvhdrq) {
  1324. qib_dev_err(dd,
  1325. "attempt to allocate %d bytes for ctxt %u rcvhdrq failed\n",
  1326. amt, rcd->ctxt);
  1327. goto bail;
  1328. }
  1329. if (rcd->ctxt >= dd->first_user_ctxt) {
  1330. rcd->user_event_mask = vmalloc_user(PAGE_SIZE);
  1331. if (!rcd->user_event_mask)
  1332. goto bail_free_hdrq;
  1333. }
  1334. if (!(dd->flags & QIB_NODMA_RTAIL)) {
  1335. rcd->rcvhdrtail_kvaddr = dma_alloc_coherent(
  1336. &dd->pcidev->dev, PAGE_SIZE, &phys_hdrqtail,
  1337. gfp_flags);
  1338. if (!rcd->rcvhdrtail_kvaddr)
  1339. goto bail_free;
  1340. rcd->rcvhdrqtailaddr_phys = phys_hdrqtail;
  1341. }
  1342. rcd->rcvhdrq_size = amt;
  1343. }
  1344. /* clear for security and sanity on each use */
  1345. memset(rcd->rcvhdrq, 0, rcd->rcvhdrq_size);
  1346. if (rcd->rcvhdrtail_kvaddr)
  1347. memset(rcd->rcvhdrtail_kvaddr, 0, PAGE_SIZE);
  1348. return 0;
  1349. bail_free:
  1350. qib_dev_err(dd,
  1351. "attempt to allocate 1 page for ctxt %u rcvhdrqtailaddr failed\n",
  1352. rcd->ctxt);
  1353. vfree(rcd->user_event_mask);
  1354. rcd->user_event_mask = NULL;
  1355. bail_free_hdrq:
  1356. dma_free_coherent(&dd->pcidev->dev, amt, rcd->rcvhdrq,
  1357. rcd->rcvhdrq_phys);
  1358. rcd->rcvhdrq = NULL;
  1359. bail:
  1360. return -ENOMEM;
  1361. }
  1362. /**
  1363. * allocate eager buffers, both kernel and user contexts.
  1364. * @rcd: the context we are setting up.
  1365. *
  1366. * Allocate the eager TID buffers and program them into hip.
  1367. * They are no longer completely contiguous, we do multiple allocation
  1368. * calls. Otherwise we get the OOM code involved, by asking for too
  1369. * much per call, with disastrous results on some kernels.
  1370. */
  1371. int qib_setup_eagerbufs(struct qib_ctxtdata *rcd)
  1372. {
  1373. struct qib_devdata *dd = rcd->dd;
  1374. unsigned e, egrcnt, egrperchunk, chunk, egrsize, egroff;
  1375. size_t size;
  1376. gfp_t gfp_flags;
  1377. /*
  1378. * GFP_USER, but without GFP_FS, so buffer cache can be
  1379. * coalesced (we hope); otherwise, even at order 4,
  1380. * heavy filesystem activity makes these fail, and we can
  1381. * use compound pages.
  1382. */
  1383. gfp_flags = __GFP_WAIT | __GFP_IO | __GFP_COMP;
  1384. egrcnt = rcd->rcvegrcnt;
  1385. egroff = rcd->rcvegr_tid_base;
  1386. egrsize = dd->rcvegrbufsize;
  1387. chunk = rcd->rcvegrbuf_chunks;
  1388. egrperchunk = rcd->rcvegrbufs_perchunk;
  1389. size = rcd->rcvegrbuf_size;
  1390. if (!rcd->rcvegrbuf) {
  1391. rcd->rcvegrbuf =
  1392. kzalloc(chunk * sizeof(rcd->rcvegrbuf[0]),
  1393. GFP_KERNEL);
  1394. if (!rcd->rcvegrbuf)
  1395. goto bail;
  1396. }
  1397. if (!rcd->rcvegrbuf_phys) {
  1398. rcd->rcvegrbuf_phys =
  1399. kmalloc(chunk * sizeof(rcd->rcvegrbuf_phys[0]),
  1400. GFP_KERNEL);
  1401. if (!rcd->rcvegrbuf_phys)
  1402. goto bail_rcvegrbuf;
  1403. }
  1404. for (e = 0; e < rcd->rcvegrbuf_chunks; e++) {
  1405. if (rcd->rcvegrbuf[e])
  1406. continue;
  1407. rcd->rcvegrbuf[e] =
  1408. dma_alloc_coherent(&dd->pcidev->dev, size,
  1409. &rcd->rcvegrbuf_phys[e],
  1410. gfp_flags);
  1411. if (!rcd->rcvegrbuf[e])
  1412. goto bail_rcvegrbuf_phys;
  1413. }
  1414. rcd->rcvegr_phys = rcd->rcvegrbuf_phys[0];
  1415. for (e = chunk = 0; chunk < rcd->rcvegrbuf_chunks; chunk++) {
  1416. dma_addr_t pa = rcd->rcvegrbuf_phys[chunk];
  1417. unsigned i;
  1418. /* clear for security and sanity on each use */
  1419. memset(rcd->rcvegrbuf[chunk], 0, size);
  1420. for (i = 0; e < egrcnt && i < egrperchunk; e++, i++) {
  1421. dd->f_put_tid(dd, e + egroff +
  1422. (u64 __iomem *)
  1423. ((char __iomem *)
  1424. dd->kregbase +
  1425. dd->rcvegrbase),
  1426. RCVHQ_RCV_TYPE_EAGER, pa);
  1427. pa += egrsize;
  1428. }
  1429. cond_resched(); /* don't hog the cpu */
  1430. }
  1431. return 0;
  1432. bail_rcvegrbuf_phys:
  1433. for (e = 0; e < rcd->rcvegrbuf_chunks && rcd->rcvegrbuf[e]; e++)
  1434. dma_free_coherent(&dd->pcidev->dev, size,
  1435. rcd->rcvegrbuf[e], rcd->rcvegrbuf_phys[e]);
  1436. kfree(rcd->rcvegrbuf_phys);
  1437. rcd->rcvegrbuf_phys = NULL;
  1438. bail_rcvegrbuf:
  1439. kfree(rcd->rcvegrbuf);
  1440. rcd->rcvegrbuf = NULL;
  1441. bail:
  1442. return -ENOMEM;
  1443. }
  1444. /*
  1445. * Note: Changes to this routine should be mirrored
  1446. * for the diagnostics routine qib_remap_ioaddr32().
  1447. * There is also related code for VL15 buffers in qib_init_7322_variables().
  1448. * The teardown code that unmaps is in qib_pcie_ddcleanup()
  1449. */
  1450. int init_chip_wc_pat(struct qib_devdata *dd, u32 vl15buflen)
  1451. {
  1452. u64 __iomem *qib_kregbase = NULL;
  1453. void __iomem *qib_piobase = NULL;
  1454. u64 __iomem *qib_userbase = NULL;
  1455. u64 qib_kreglen;
  1456. u64 qib_pio2koffset = dd->piobufbase & 0xffffffff;
  1457. u64 qib_pio4koffset = dd->piobufbase >> 32;
  1458. u64 qib_pio2klen = dd->piobcnt2k * dd->palign;
  1459. u64 qib_pio4klen = dd->piobcnt4k * dd->align4k;
  1460. u64 qib_physaddr = dd->physaddr;
  1461. u64 qib_piolen;
  1462. u64 qib_userlen = 0;
  1463. /*
  1464. * Free the old mapping because the kernel will try to reuse the
  1465. * old mapping and not create a new mapping with the
  1466. * write combining attribute.
  1467. */
  1468. iounmap(dd->kregbase);
  1469. dd->kregbase = NULL;
  1470. /*
  1471. * Assumes chip address space looks like:
  1472. * - kregs + sregs + cregs + uregs (in any order)
  1473. * - piobufs (2K and 4K bufs in either order)
  1474. * or:
  1475. * - kregs + sregs + cregs (in any order)
  1476. * - piobufs (2K and 4K bufs in either order)
  1477. * - uregs
  1478. */
  1479. if (dd->piobcnt4k == 0) {
  1480. qib_kreglen = qib_pio2koffset;
  1481. qib_piolen = qib_pio2klen;
  1482. } else if (qib_pio2koffset < qib_pio4koffset) {
  1483. qib_kreglen = qib_pio2koffset;
  1484. qib_piolen = qib_pio4koffset + qib_pio4klen - qib_kreglen;
  1485. } else {
  1486. qib_kreglen = qib_pio4koffset;
  1487. qib_piolen = qib_pio2koffset + qib_pio2klen - qib_kreglen;
  1488. }
  1489. qib_piolen += vl15buflen;
  1490. /* Map just the configured ports (not all hw ports) */
  1491. if (dd->uregbase > qib_kreglen)
  1492. qib_userlen = dd->ureg_align * dd->cfgctxts;
  1493. /* Sanity checks passed, now create the new mappings */
  1494. qib_kregbase = ioremap_nocache(qib_physaddr, qib_kreglen);
  1495. if (!qib_kregbase)
  1496. goto bail;
  1497. qib_piobase = ioremap_wc(qib_physaddr + qib_kreglen, qib_piolen);
  1498. if (!qib_piobase)
  1499. goto bail_kregbase;
  1500. if (qib_userlen) {
  1501. qib_userbase = ioremap_nocache(qib_physaddr + dd->uregbase,
  1502. qib_userlen);
  1503. if (!qib_userbase)
  1504. goto bail_piobase;
  1505. }
  1506. dd->kregbase = qib_kregbase;
  1507. dd->kregend = (u64 __iomem *)
  1508. ((char __iomem *) qib_kregbase + qib_kreglen);
  1509. dd->piobase = qib_piobase;
  1510. dd->pio2kbase = (void __iomem *)
  1511. (((char __iomem *) dd->piobase) +
  1512. qib_pio2koffset - qib_kreglen);
  1513. if (dd->piobcnt4k)
  1514. dd->pio4kbase = (void __iomem *)
  1515. (((char __iomem *) dd->piobase) +
  1516. qib_pio4koffset - qib_kreglen);
  1517. if (qib_userlen)
  1518. /* ureg will now be accessed relative to dd->userbase */
  1519. dd->userbase = qib_userbase;
  1520. return 0;
  1521. bail_piobase:
  1522. iounmap(qib_piobase);
  1523. bail_kregbase:
  1524. iounmap(qib_kregbase);
  1525. bail:
  1526. return -ENOMEM;
  1527. }