ipath_init_chip.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /*
  2. * Copyright (c) 2006, 2007, 2008 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/pci.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/slab.h>
  37. #include <linux/stat.h>
  38. #include <linux/vmalloc.h>
  39. #include "ipath_kernel.h"
  40. #include "ipath_common.h"
  41. /*
  42. * min buffers we want to have per port, after driver
  43. */
  44. #define IPATH_MIN_USER_PORT_BUFCNT 7
  45. /*
  46. * Number of ports we are configured to use (to allow for more pio
  47. * buffers per port, etc.) Zero means use chip value.
  48. */
  49. static ushort ipath_cfgports;
  50. module_param_named(cfgports, ipath_cfgports, ushort, S_IRUGO);
  51. MODULE_PARM_DESC(cfgports, "Set max number of ports to use");
  52. /*
  53. * Number of buffers reserved for driver (verbs and layered drivers.)
  54. * Initialized based on number of PIO buffers if not set via module interface.
  55. * The problem with this is that it's global, but we'll use different
  56. * numbers for different chip types.
  57. */
  58. static ushort ipath_kpiobufs;
  59. static int ipath_set_kpiobufs(const char *val, struct kernel_param *kp);
  60. module_param_call(kpiobufs, ipath_set_kpiobufs, param_get_ushort,
  61. &ipath_kpiobufs, S_IWUSR | S_IRUGO);
  62. MODULE_PARM_DESC(kpiobufs, "Set number of PIO buffers for driver");
  63. /**
  64. * create_port0_egr - allocate the eager TID buffers
  65. * @dd: the infinipath device
  66. *
  67. * This code is now quite different for user and kernel, because
  68. * the kernel uses skb's, for the accelerated network performance.
  69. * This is the kernel (port0) version.
  70. *
  71. * Allocate the eager TID buffers and program them into infinipath.
  72. * We use the network layer alloc_skb() allocator to allocate the
  73. * memory, and either use the buffers as is for things like verbs
  74. * packets, or pass the buffers up to the ipath layered driver and
  75. * thence the network layer, replacing them as we do so (see
  76. * ipath_rcv_layer()).
  77. */
  78. static int create_port0_egr(struct ipath_devdata *dd)
  79. {
  80. unsigned e, egrcnt;
  81. struct ipath_skbinfo *skbinfo;
  82. int ret;
  83. egrcnt = dd->ipath_p0_rcvegrcnt;
  84. skbinfo = vmalloc(sizeof(*dd->ipath_port0_skbinfo) * egrcnt);
  85. if (skbinfo == NULL) {
  86. ipath_dev_err(dd, "allocation error for eager TID "
  87. "skb array\n");
  88. ret = -ENOMEM;
  89. goto bail;
  90. }
  91. for (e = 0; e < egrcnt; e++) {
  92. /*
  93. * This is a bit tricky in that we allocate extra
  94. * space for 2 bytes of the 14 byte ethernet header.
  95. * These two bytes are passed in the ipath header so
  96. * the rest of the data is word aligned. We allocate
  97. * 4 bytes so that the data buffer stays word aligned.
  98. * See ipath_kreceive() for more details.
  99. */
  100. skbinfo[e].skb = ipath_alloc_skb(dd, GFP_KERNEL);
  101. if (!skbinfo[e].skb) {
  102. ipath_dev_err(dd, "SKB allocation error for "
  103. "eager TID %u\n", e);
  104. while (e != 0)
  105. dev_kfree_skb(skbinfo[--e].skb);
  106. vfree(skbinfo);
  107. ret = -ENOMEM;
  108. goto bail;
  109. }
  110. }
  111. /*
  112. * After loop above, so we can test non-NULL to see if ready
  113. * to use at receive, etc.
  114. */
  115. dd->ipath_port0_skbinfo = skbinfo;
  116. for (e = 0; e < egrcnt; e++) {
  117. dd->ipath_port0_skbinfo[e].phys =
  118. ipath_map_single(dd->pcidev,
  119. dd->ipath_port0_skbinfo[e].skb->data,
  120. dd->ipath_ibmaxlen, PCI_DMA_FROMDEVICE);
  121. dd->ipath_f_put_tid(dd, e + (u64 __iomem *)
  122. ((char __iomem *) dd->ipath_kregbase +
  123. dd->ipath_rcvegrbase),
  124. RCVHQ_RCV_TYPE_EAGER,
  125. dd->ipath_port0_skbinfo[e].phys);
  126. }
  127. ret = 0;
  128. bail:
  129. return ret;
  130. }
  131. static int bringup_link(struct ipath_devdata *dd)
  132. {
  133. u64 val, ibc;
  134. int ret = 0;
  135. /* hold IBC in reset */
  136. dd->ipath_control &= ~INFINIPATH_C_LINKENABLE;
  137. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  138. dd->ipath_control);
  139. /*
  140. * set initial max size pkt IBC will send, including ICRC; it's the
  141. * PIO buffer size in dwords, less 1; also see ipath_set_mtu()
  142. */
  143. val = (dd->ipath_ibmaxlen >> 2) + 1;
  144. ibc = val << dd->ibcc_mpl_shift;
  145. /* flowcontrolwatermark is in units of KBytes */
  146. ibc |= 0x5ULL << INFINIPATH_IBCC_FLOWCTRLWATERMARK_SHIFT;
  147. /*
  148. * How often flowctrl sent. More or less in usecs; balance against
  149. * watermark value, so that in theory senders always get a flow
  150. * control update in time to not let the IB link go idle.
  151. */
  152. ibc |= 0x3ULL << INFINIPATH_IBCC_FLOWCTRLPERIOD_SHIFT;
  153. /* max error tolerance */
  154. ibc |= 0xfULL << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
  155. /* use "real" buffer space for */
  156. ibc |= 4ULL << INFINIPATH_IBCC_CREDITSCALE_SHIFT;
  157. /* IB credit flow control. */
  158. ibc |= 0xfULL << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
  159. /* initially come up waiting for TS1, without sending anything. */
  160. dd->ipath_ibcctrl = ibc;
  161. /*
  162. * Want to start out with both LINKCMD and LINKINITCMD in NOP
  163. * (0 and 0). Don't put linkinitcmd in ipath_ibcctrl, want that
  164. * to stay a NOP. Flag that we are disabled, for the (unlikely)
  165. * case that some recovery path is trying to bring the link up
  166. * before we are ready.
  167. */
  168. ibc |= INFINIPATH_IBCC_LINKINITCMD_DISABLE <<
  169. INFINIPATH_IBCC_LINKINITCMD_SHIFT;
  170. dd->ipath_flags |= IPATH_IB_LINK_DISABLED;
  171. ipath_cdbg(VERBOSE, "Writing 0x%llx to ibcctrl\n",
  172. (unsigned long long) ibc);
  173. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl, ibc);
  174. // be sure chip saw it
  175. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  176. ret = dd->ipath_f_bringup_serdes(dd);
  177. if (ret)
  178. dev_info(&dd->pcidev->dev, "Could not initialize SerDes, "
  179. "not usable\n");
  180. else {
  181. /* enable IBC */
  182. dd->ipath_control |= INFINIPATH_C_LINKENABLE;
  183. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  184. dd->ipath_control);
  185. }
  186. return ret;
  187. }
  188. static struct ipath_portdata *create_portdata0(struct ipath_devdata *dd)
  189. {
  190. struct ipath_portdata *pd = NULL;
  191. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  192. if (pd) {
  193. pd->port_dd = dd;
  194. pd->port_cnt = 1;
  195. /* The port 0 pkey table is used by the layer interface. */
  196. pd->port_pkeys[0] = IPATH_DEFAULT_P_KEY;
  197. pd->port_seq_cnt = 1;
  198. }
  199. return pd;
  200. }
  201. static int init_chip_first(struct ipath_devdata *dd)
  202. {
  203. struct ipath_portdata *pd;
  204. int ret = 0;
  205. u64 val;
  206. spin_lock_init(&dd->ipath_kernel_tid_lock);
  207. spin_lock_init(&dd->ipath_user_tid_lock);
  208. spin_lock_init(&dd->ipath_sendctrl_lock);
  209. spin_lock_init(&dd->ipath_uctxt_lock);
  210. spin_lock_init(&dd->ipath_sdma_lock);
  211. spin_lock_init(&dd->ipath_gpio_lock);
  212. spin_lock_init(&dd->ipath_eep_st_lock);
  213. spin_lock_init(&dd->ipath_sdepb_lock);
  214. mutex_init(&dd->ipath_eep_lock);
  215. /*
  216. * skip cfgports stuff because we are not allocating memory,
  217. * and we don't want problems if the portcnt changed due to
  218. * cfgports. We do still check and report a difference, if
  219. * not same (should be impossible).
  220. */
  221. dd->ipath_f_config_ports(dd, ipath_cfgports);
  222. if (!ipath_cfgports)
  223. dd->ipath_cfgports = dd->ipath_portcnt;
  224. else if (ipath_cfgports <= dd->ipath_portcnt) {
  225. dd->ipath_cfgports = ipath_cfgports;
  226. ipath_dbg("Configured to use %u ports out of %u in chip\n",
  227. dd->ipath_cfgports, ipath_read_kreg32(dd,
  228. dd->ipath_kregs->kr_portcnt));
  229. } else {
  230. dd->ipath_cfgports = dd->ipath_portcnt;
  231. ipath_dbg("Tried to configured to use %u ports; chip "
  232. "only supports %u\n", ipath_cfgports,
  233. ipath_read_kreg32(dd,
  234. dd->ipath_kregs->kr_portcnt));
  235. }
  236. /*
  237. * Allocate full portcnt array, rather than just cfgports, because
  238. * cleanup iterates across all possible ports.
  239. */
  240. dd->ipath_pd = kzalloc(sizeof(*dd->ipath_pd) * dd->ipath_portcnt,
  241. GFP_KERNEL);
  242. if (!dd->ipath_pd) {
  243. ipath_dev_err(dd, "Unable to allocate portdata array, "
  244. "failing\n");
  245. ret = -ENOMEM;
  246. goto done;
  247. }
  248. pd = create_portdata0(dd);
  249. if (!pd) {
  250. ipath_dev_err(dd, "Unable to allocate portdata for port "
  251. "0, failing\n");
  252. ret = -ENOMEM;
  253. goto done;
  254. }
  255. dd->ipath_pd[0] = pd;
  256. dd->ipath_rcvtidcnt =
  257. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidcnt);
  258. dd->ipath_rcvtidbase =
  259. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidbase);
  260. dd->ipath_rcvegrcnt =
  261. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
  262. dd->ipath_rcvegrbase =
  263. ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrbase);
  264. dd->ipath_palign =
  265. ipath_read_kreg32(dd, dd->ipath_kregs->kr_pagealign);
  266. dd->ipath_piobufbase =
  267. ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpiobufbase);
  268. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpiosize);
  269. dd->ipath_piosize2k = val & ~0U;
  270. dd->ipath_piosize4k = val >> 32;
  271. if (dd->ipath_piosize4k == 0 && ipath_mtu4096)
  272. ipath_mtu4096 = 0; /* 4KB not supported by this chip */
  273. dd->ipath_ibmtu = ipath_mtu4096 ? 4096 : 2048;
  274. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpiobufcnt);
  275. dd->ipath_piobcnt2k = val & ~0U;
  276. dd->ipath_piobcnt4k = val >> 32;
  277. dd->ipath_pio2kbase =
  278. (u32 __iomem *) (((char __iomem *) dd->ipath_kregbase) +
  279. (dd->ipath_piobufbase & 0xffffffff));
  280. if (dd->ipath_piobcnt4k) {
  281. dd->ipath_pio4kbase = (u32 __iomem *)
  282. (((char __iomem *) dd->ipath_kregbase) +
  283. (dd->ipath_piobufbase >> 32));
  284. /*
  285. * 4K buffers take 2 pages; we use roundup just to be
  286. * paranoid; we calculate it once here, rather than on
  287. * ever buf allocate
  288. */
  289. dd->ipath_4kalign = ALIGN(dd->ipath_piosize4k,
  290. dd->ipath_palign);
  291. ipath_dbg("%u 2k(%x) piobufs @ %p, %u 4k(%x) @ %p "
  292. "(%x aligned)\n",
  293. dd->ipath_piobcnt2k, dd->ipath_piosize2k,
  294. dd->ipath_pio2kbase, dd->ipath_piobcnt4k,
  295. dd->ipath_piosize4k, dd->ipath_pio4kbase,
  296. dd->ipath_4kalign);
  297. }
  298. else ipath_dbg("%u 2k piobufs @ %p\n",
  299. dd->ipath_piobcnt2k, dd->ipath_pio2kbase);
  300. done:
  301. return ret;
  302. }
  303. /**
  304. * init_chip_reset - re-initialize after a reset, or enable
  305. * @dd: the infinipath device
  306. *
  307. * sanity check at least some of the values after reset, and
  308. * ensure no receive or transmit (explicitly, in case reset
  309. * failed
  310. */
  311. static int init_chip_reset(struct ipath_devdata *dd)
  312. {
  313. u32 rtmp;
  314. int i;
  315. unsigned long flags;
  316. /*
  317. * ensure chip does no sends or receives, tail updates, or
  318. * pioavail updates while we re-initialize
  319. */
  320. dd->ipath_rcvctrl &= ~(1ULL << dd->ipath_r_tailupd_shift);
  321. for (i = 0; i < dd->ipath_portcnt; i++) {
  322. clear_bit(dd->ipath_r_portenable_shift + i,
  323. &dd->ipath_rcvctrl);
  324. clear_bit(dd->ipath_r_intravail_shift + i,
  325. &dd->ipath_rcvctrl);
  326. }
  327. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  328. dd->ipath_rcvctrl);
  329. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  330. dd->ipath_sendctrl = 0U; /* no sdma, etc */
  331. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, dd->ipath_sendctrl);
  332. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  333. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  334. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, 0ULL);
  335. rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidcnt);
  336. if (rtmp != dd->ipath_rcvtidcnt)
  337. dev_info(&dd->pcidev->dev, "tidcnt was %u before "
  338. "reset, now %u, using original\n",
  339. dd->ipath_rcvtidcnt, rtmp);
  340. rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidbase);
  341. if (rtmp != dd->ipath_rcvtidbase)
  342. dev_info(&dd->pcidev->dev, "tidbase was %u before "
  343. "reset, now %u, using original\n",
  344. dd->ipath_rcvtidbase, rtmp);
  345. rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
  346. if (rtmp != dd->ipath_rcvegrcnt)
  347. dev_info(&dd->pcidev->dev, "egrcnt was %u before "
  348. "reset, now %u, using original\n",
  349. dd->ipath_rcvegrcnt, rtmp);
  350. rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrbase);
  351. if (rtmp != dd->ipath_rcvegrbase)
  352. dev_info(&dd->pcidev->dev, "egrbase was %u before "
  353. "reset, now %u, using original\n",
  354. dd->ipath_rcvegrbase, rtmp);
  355. return 0;
  356. }
  357. static int init_pioavailregs(struct ipath_devdata *dd)
  358. {
  359. int ret;
  360. dd->ipath_pioavailregs_dma = dma_alloc_coherent(
  361. &dd->pcidev->dev, PAGE_SIZE, &dd->ipath_pioavailregs_phys,
  362. GFP_KERNEL);
  363. if (!dd->ipath_pioavailregs_dma) {
  364. ipath_dev_err(dd, "failed to allocate PIOavail reg area "
  365. "in memory\n");
  366. ret = -ENOMEM;
  367. goto done;
  368. }
  369. /*
  370. * we really want L2 cache aligned, but for current CPUs of
  371. * interest, they are the same.
  372. */
  373. dd->ipath_statusp = (u64 *)
  374. ((char *)dd->ipath_pioavailregs_dma +
  375. ((2 * L1_CACHE_BYTES +
  376. dd->ipath_pioavregs * sizeof(u64)) & ~L1_CACHE_BYTES));
  377. /* copy the current value now that it's really allocated */
  378. *dd->ipath_statusp = dd->_ipath_status;
  379. /*
  380. * setup buffer to hold freeze msg, accessible to apps,
  381. * following statusp
  382. */
  383. dd->ipath_freezemsg = (char *)&dd->ipath_statusp[1];
  384. /* and its length */
  385. dd->ipath_freezelen = L1_CACHE_BYTES - sizeof(dd->ipath_statusp[0]);
  386. ret = 0;
  387. done:
  388. return ret;
  389. }
  390. /**
  391. * init_shadow_tids - allocate the shadow TID array
  392. * @dd: the infinipath device
  393. *
  394. * allocate the shadow TID array, so we can ipath_munlock previous
  395. * entries. It may make more sense to move the pageshadow to the
  396. * port data structure, so we only allocate memory for ports actually
  397. * in use, since we at 8k per port, now.
  398. */
  399. static void init_shadow_tids(struct ipath_devdata *dd)
  400. {
  401. struct page **pages;
  402. dma_addr_t *addrs;
  403. pages = vzalloc(dd->ipath_cfgports * dd->ipath_rcvtidcnt *
  404. sizeof(struct page *));
  405. if (!pages) {
  406. ipath_dev_err(dd, "failed to allocate shadow page * "
  407. "array, no expected sends!\n");
  408. dd->ipath_pageshadow = NULL;
  409. return;
  410. }
  411. addrs = vmalloc(dd->ipath_cfgports * dd->ipath_rcvtidcnt *
  412. sizeof(dma_addr_t));
  413. if (!addrs) {
  414. ipath_dev_err(dd, "failed to allocate shadow dma handle "
  415. "array, no expected sends!\n");
  416. vfree(pages);
  417. dd->ipath_pageshadow = NULL;
  418. return;
  419. }
  420. dd->ipath_pageshadow = pages;
  421. dd->ipath_physshadow = addrs;
  422. }
  423. static void enable_chip(struct ipath_devdata *dd, int reinit)
  424. {
  425. u32 val;
  426. u64 rcvmask;
  427. unsigned long flags;
  428. int i;
  429. if (!reinit)
  430. init_waitqueue_head(&ipath_state_wait);
  431. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  432. dd->ipath_rcvctrl);
  433. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  434. /* Enable PIO send, and update of PIOavail regs to memory. */
  435. dd->ipath_sendctrl = INFINIPATH_S_PIOENABLE |
  436. INFINIPATH_S_PIOBUFAVAILUPD;
  437. /*
  438. * Set the PIO avail update threshold to host memory
  439. * on chips that support it.
  440. */
  441. if (dd->ipath_pioupd_thresh)
  442. dd->ipath_sendctrl |= dd->ipath_pioupd_thresh
  443. << INFINIPATH_S_UPDTHRESH_SHIFT;
  444. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, dd->ipath_sendctrl);
  445. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  446. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  447. /*
  448. * Enable kernel ports' receive and receive interrupt.
  449. * Other ports done as user opens and inits them.
  450. */
  451. rcvmask = 1ULL;
  452. dd->ipath_rcvctrl |= (rcvmask << dd->ipath_r_portenable_shift) |
  453. (rcvmask << dd->ipath_r_intravail_shift);
  454. if (!(dd->ipath_flags & IPATH_NODMA_RTAIL))
  455. dd->ipath_rcvctrl |= (1ULL << dd->ipath_r_tailupd_shift);
  456. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  457. dd->ipath_rcvctrl);
  458. /*
  459. * now ready for use. this should be cleared whenever we
  460. * detect a reset, or initiate one.
  461. */
  462. dd->ipath_flags |= IPATH_INITTED;
  463. /*
  464. * Init our shadow copies of head from tail values,
  465. * and write head values to match.
  466. */
  467. val = ipath_read_ureg32(dd, ur_rcvegrindextail, 0);
  468. ipath_write_ureg(dd, ur_rcvegrindexhead, val, 0);
  469. /* Initialize so we interrupt on next packet received */
  470. ipath_write_ureg(dd, ur_rcvhdrhead,
  471. dd->ipath_rhdrhead_intr_off |
  472. dd->ipath_pd[0]->port_head, 0);
  473. /*
  474. * by now pioavail updates to memory should have occurred, so
  475. * copy them into our working/shadow registers; this is in
  476. * case something went wrong with abort, but mostly to get the
  477. * initial values of the generation bit correct.
  478. */
  479. for (i = 0; i < dd->ipath_pioavregs; i++) {
  480. __le64 pioavail;
  481. /*
  482. * Chip Errata bug 6641; even and odd qwords>3 are swapped.
  483. */
  484. if (i > 3 && (dd->ipath_flags & IPATH_SWAP_PIOBUFS))
  485. pioavail = dd->ipath_pioavailregs_dma[i ^ 1];
  486. else
  487. pioavail = dd->ipath_pioavailregs_dma[i];
  488. /*
  489. * don't need to worry about ipath_pioavailkernel here
  490. * because we will call ipath_chg_pioavailkernel() later
  491. * in initialization, to busy out buffers as needed
  492. */
  493. dd->ipath_pioavailshadow[i] = le64_to_cpu(pioavail);
  494. }
  495. /* can get counters, stats, etc. */
  496. dd->ipath_flags |= IPATH_PRESENT;
  497. }
  498. static int init_housekeeping(struct ipath_devdata *dd, int reinit)
  499. {
  500. char boardn[40];
  501. int ret = 0;
  502. /*
  503. * have to clear shadow copies of registers at init that are
  504. * not otherwise set here, or all kinds of bizarre things
  505. * happen with driver on chip reset
  506. */
  507. dd->ipath_rcvhdrsize = 0;
  508. /*
  509. * Don't clear ipath_flags as 8bit mode was set before
  510. * entering this func. However, we do set the linkstate to
  511. * unknown, so we can watch for a transition.
  512. * PRESENT is set because we want register reads to work,
  513. * and the kernel infrastructure saw it in config space;
  514. * We clear it if we have failures.
  515. */
  516. dd->ipath_flags |= IPATH_LINKUNK | IPATH_PRESENT;
  517. dd->ipath_flags &= ~(IPATH_LINKACTIVE | IPATH_LINKARMED |
  518. IPATH_LINKDOWN | IPATH_LINKINIT);
  519. ipath_cdbg(VERBOSE, "Try to read spc chip revision\n");
  520. dd->ipath_revision =
  521. ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
  522. /*
  523. * set up fundamental info we need to use the chip; we assume
  524. * if the revision reg and these regs are OK, we don't need to
  525. * special case the rest
  526. */
  527. dd->ipath_sregbase =
  528. ipath_read_kreg32(dd, dd->ipath_kregs->kr_sendregbase);
  529. dd->ipath_cregbase =
  530. ipath_read_kreg32(dd, dd->ipath_kregs->kr_counterregbase);
  531. dd->ipath_uregbase =
  532. ipath_read_kreg32(dd, dd->ipath_kregs->kr_userregbase);
  533. ipath_cdbg(VERBOSE, "ipath_kregbase %p, sendbase %x usrbase %x, "
  534. "cntrbase %x\n", dd->ipath_kregbase, dd->ipath_sregbase,
  535. dd->ipath_uregbase, dd->ipath_cregbase);
  536. if ((dd->ipath_revision & 0xffffffff) == 0xffffffff
  537. || (dd->ipath_sregbase & 0xffffffff) == 0xffffffff
  538. || (dd->ipath_cregbase & 0xffffffff) == 0xffffffff
  539. || (dd->ipath_uregbase & 0xffffffff) == 0xffffffff) {
  540. ipath_dev_err(dd, "Register read failures from chip, "
  541. "giving up initialization\n");
  542. dd->ipath_flags &= ~IPATH_PRESENT;
  543. ret = -ENODEV;
  544. goto done;
  545. }
  546. /* clear diagctrl register, in case diags were running and crashed */
  547. ipath_write_kreg (dd, dd->ipath_kregs->kr_hwdiagctrl, 0);
  548. /* clear the initial reset flag, in case first driver load */
  549. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear,
  550. INFINIPATH_E_RESET);
  551. ipath_cdbg(VERBOSE, "Revision %llx (PCI %x)\n",
  552. (unsigned long long) dd->ipath_revision,
  553. dd->ipath_pcirev);
  554. if (((dd->ipath_revision >> INFINIPATH_R_SOFTWARE_SHIFT) &
  555. INFINIPATH_R_SOFTWARE_MASK) != IPATH_CHIP_SWVERSION) {
  556. ipath_dev_err(dd, "Driver only handles version %d, "
  557. "chip swversion is %d (%llx), failng\n",
  558. IPATH_CHIP_SWVERSION,
  559. (int)(dd->ipath_revision >>
  560. INFINIPATH_R_SOFTWARE_SHIFT) &
  561. INFINIPATH_R_SOFTWARE_MASK,
  562. (unsigned long long) dd->ipath_revision);
  563. ret = -ENOSYS;
  564. goto done;
  565. }
  566. dd->ipath_majrev = (u8) ((dd->ipath_revision >>
  567. INFINIPATH_R_CHIPREVMAJOR_SHIFT) &
  568. INFINIPATH_R_CHIPREVMAJOR_MASK);
  569. dd->ipath_minrev = (u8) ((dd->ipath_revision >>
  570. INFINIPATH_R_CHIPREVMINOR_SHIFT) &
  571. INFINIPATH_R_CHIPREVMINOR_MASK);
  572. dd->ipath_boardrev = (u8) ((dd->ipath_revision >>
  573. INFINIPATH_R_BOARDID_SHIFT) &
  574. INFINIPATH_R_BOARDID_MASK);
  575. ret = dd->ipath_f_get_boardname(dd, boardn, sizeof boardn);
  576. snprintf(dd->ipath_boardversion, sizeof(dd->ipath_boardversion),
  577. "ChipABI %u.%u, %s, InfiniPath%u %u.%u, PCI %u, "
  578. "SW Compat %u\n",
  579. IPATH_CHIP_VERS_MAJ, IPATH_CHIP_VERS_MIN, boardn,
  580. (unsigned)(dd->ipath_revision >> INFINIPATH_R_ARCH_SHIFT) &
  581. INFINIPATH_R_ARCH_MASK,
  582. dd->ipath_majrev, dd->ipath_minrev, dd->ipath_pcirev,
  583. (unsigned)(dd->ipath_revision >>
  584. INFINIPATH_R_SOFTWARE_SHIFT) &
  585. INFINIPATH_R_SOFTWARE_MASK);
  586. ipath_dbg("%s", dd->ipath_boardversion);
  587. if (ret)
  588. goto done;
  589. if (reinit)
  590. ret = init_chip_reset(dd);
  591. else
  592. ret = init_chip_first(dd);
  593. done:
  594. return ret;
  595. }
  596. static void verify_interrupt(unsigned long opaque)
  597. {
  598. struct ipath_devdata *dd = (struct ipath_devdata *) opaque;
  599. if (!dd)
  600. return; /* being torn down */
  601. /*
  602. * If we don't have any interrupts, let the user know and
  603. * don't bother checking again.
  604. */
  605. if (dd->ipath_int_counter == 0) {
  606. if (!dd->ipath_f_intr_fallback(dd))
  607. dev_err(&dd->pcidev->dev, "No interrupts detected, "
  608. "not usable.\n");
  609. else /* re-arm the timer to see if fallback works */
  610. mod_timer(&dd->ipath_intrchk_timer, jiffies + HZ/2);
  611. } else
  612. ipath_cdbg(VERBOSE, "%u interrupts at timer check\n",
  613. dd->ipath_int_counter);
  614. }
  615. /**
  616. * ipath_init_chip - do the actual initialization sequence on the chip
  617. * @dd: the infinipath device
  618. * @reinit: reinitializing, so don't allocate new memory
  619. *
  620. * Do the actual initialization sequence on the chip. This is done
  621. * both from the init routine called from the PCI infrastructure, and
  622. * when we reset the chip, or detect that it was reset internally,
  623. * or it's administratively re-enabled.
  624. *
  625. * Memory allocation here and in called routines is only done in
  626. * the first case (reinit == 0). We have to be careful, because even
  627. * without memory allocation, we need to re-write all the chip registers
  628. * TIDs, etc. after the reset or enable has completed.
  629. */
  630. int ipath_init_chip(struct ipath_devdata *dd, int reinit)
  631. {
  632. int ret = 0;
  633. u32 kpiobufs, defkbufs;
  634. u32 piobufs, uports;
  635. u64 val;
  636. struct ipath_portdata *pd;
  637. gfp_t gfp_flags = GFP_USER | __GFP_COMP;
  638. ret = init_housekeeping(dd, reinit);
  639. if (ret)
  640. goto done;
  641. /*
  642. * we ignore most issues after reporting them, but have to specially
  643. * handle hardware-disabled chips.
  644. */
  645. if (ret == 2) {
  646. /* unique error, known to ipath_init_one */
  647. ret = -EPERM;
  648. goto done;
  649. }
  650. /*
  651. * We could bump this to allow for full rcvegrcnt + rcvtidcnt,
  652. * but then it no longer nicely fits power of two, and since
  653. * we now use routines that backend onto __get_free_pages, the
  654. * rest would be wasted.
  655. */
  656. dd->ipath_rcvhdrcnt = max(dd->ipath_p0_rcvegrcnt, dd->ipath_rcvegrcnt);
  657. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrcnt,
  658. dd->ipath_rcvhdrcnt);
  659. /*
  660. * Set up the shadow copies of the piobufavail registers,
  661. * which we compare against the chip registers for now, and
  662. * the in memory DMA'ed copies of the registers. This has to
  663. * be done early, before we calculate lastport, etc.
  664. */
  665. piobufs = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
  666. /*
  667. * calc number of pioavail registers, and save it; we have 2
  668. * bits per buffer.
  669. */
  670. dd->ipath_pioavregs = ALIGN(piobufs, sizeof(u64) * BITS_PER_BYTE / 2)
  671. / (sizeof(u64) * BITS_PER_BYTE / 2);
  672. uports = dd->ipath_cfgports ? dd->ipath_cfgports - 1 : 0;
  673. if (piobufs > 144)
  674. defkbufs = 32 + dd->ipath_pioreserved;
  675. else
  676. defkbufs = 16 + dd->ipath_pioreserved;
  677. if (ipath_kpiobufs && (ipath_kpiobufs +
  678. (uports * IPATH_MIN_USER_PORT_BUFCNT)) > piobufs) {
  679. int i = (int) piobufs -
  680. (int) (uports * IPATH_MIN_USER_PORT_BUFCNT);
  681. if (i < 1)
  682. i = 1;
  683. dev_info(&dd->pcidev->dev, "Allocating %d PIO bufs of "
  684. "%d for kernel leaves too few for %d user ports "
  685. "(%d each); using %u\n", ipath_kpiobufs,
  686. piobufs, uports, IPATH_MIN_USER_PORT_BUFCNT, i);
  687. /*
  688. * shouldn't change ipath_kpiobufs, because could be
  689. * different for different devices...
  690. */
  691. kpiobufs = i;
  692. } else if (ipath_kpiobufs)
  693. kpiobufs = ipath_kpiobufs;
  694. else
  695. kpiobufs = defkbufs;
  696. dd->ipath_lastport_piobuf = piobufs - kpiobufs;
  697. dd->ipath_pbufsport =
  698. uports ? dd->ipath_lastport_piobuf / uports : 0;
  699. /* if not an even divisor, some user ports get extra buffers */
  700. dd->ipath_ports_extrabuf = dd->ipath_lastport_piobuf -
  701. (dd->ipath_pbufsport * uports);
  702. if (dd->ipath_ports_extrabuf)
  703. ipath_dbg("%u pbufs/port leaves some unused, add 1 buffer to "
  704. "ports <= %u\n", dd->ipath_pbufsport,
  705. dd->ipath_ports_extrabuf);
  706. dd->ipath_lastpioindex = 0;
  707. dd->ipath_lastpioindexl = dd->ipath_piobcnt2k;
  708. /* ipath_pioavailshadow initialized earlier */
  709. ipath_cdbg(VERBOSE, "%d PIO bufs for kernel out of %d total %u "
  710. "each for %u user ports\n", kpiobufs,
  711. piobufs, dd->ipath_pbufsport, uports);
  712. ret = dd->ipath_f_early_init(dd);
  713. if (ret) {
  714. ipath_dev_err(dd, "Early initialization failure\n");
  715. goto done;
  716. }
  717. /*
  718. * Early_init sets rcvhdrentsize and rcvhdrsize, so this must be
  719. * done after early_init.
  720. */
  721. dd->ipath_hdrqlast =
  722. dd->ipath_rcvhdrentsize * (dd->ipath_rcvhdrcnt - 1);
  723. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrentsize,
  724. dd->ipath_rcvhdrentsize);
  725. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrsize,
  726. dd->ipath_rcvhdrsize);
  727. if (!reinit) {
  728. ret = init_pioavailregs(dd);
  729. init_shadow_tids(dd);
  730. if (ret)
  731. goto done;
  732. }
  733. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendpioavailaddr,
  734. dd->ipath_pioavailregs_phys);
  735. /*
  736. * this is to detect s/w errors, which the h/w works around by
  737. * ignoring the low 6 bits of address, if it wasn't aligned.
  738. */
  739. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpioavailaddr);
  740. if (val != dd->ipath_pioavailregs_phys) {
  741. ipath_dev_err(dd, "Catastrophic software error, "
  742. "SendPIOAvailAddr written as %lx, "
  743. "read back as %llx\n",
  744. (unsigned long) dd->ipath_pioavailregs_phys,
  745. (unsigned long long) val);
  746. ret = -EINVAL;
  747. goto done;
  748. }
  749. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvbthqp, IPATH_KD_QP);
  750. /*
  751. * make sure we are not in freeze, and PIO send enabled, so
  752. * writes to pbc happen
  753. */
  754. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, 0ULL);
  755. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  756. ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);
  757. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, 0ULL);
  758. /*
  759. * before error clears, since we expect serdes pll errors during
  760. * this, the first time after reset
  761. */
  762. if (bringup_link(dd)) {
  763. dev_info(&dd->pcidev->dev, "Failed to bringup IB link\n");
  764. ret = -ENETDOWN;
  765. goto done;
  766. }
  767. /*
  768. * clear any "expected" hwerrs from reset and/or initialization
  769. * clear any that aren't enabled (at least this once), and then
  770. * set the enable mask
  771. */
  772. dd->ipath_f_init_hwerrors(dd);
  773. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  774. ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);
  775. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  776. dd->ipath_hwerrmask);
  777. /* clear all */
  778. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, -1LL);
  779. /* enable errors that are masked, at least this first time. */
  780. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  781. ~dd->ipath_maskederrs);
  782. dd->ipath_maskederrs = 0; /* don't re-enable ignored in timer */
  783. dd->ipath_errormask =
  784. ipath_read_kreg64(dd, dd->ipath_kregs->kr_errormask);
  785. /* clear any interrupts up to this point (ints still not enabled) */
  786. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, -1LL);
  787. dd->ipath_f_tidtemplate(dd);
  788. /*
  789. * Set up the port 0 (kernel) rcvhdr q and egr TIDs. If doing
  790. * re-init, the simplest way to handle this is to free
  791. * existing, and re-allocate.
  792. * Need to re-create rest of port 0 portdata as well.
  793. */
  794. pd = dd->ipath_pd[0];
  795. if (reinit) {
  796. struct ipath_portdata *npd;
  797. /*
  798. * Alloc and init new ipath_portdata for port0,
  799. * Then free old pd. Could lead to fragmentation, but also
  800. * makes later support for hot-swap easier.
  801. */
  802. npd = create_portdata0(dd);
  803. if (npd) {
  804. ipath_free_pddata(dd, pd);
  805. dd->ipath_pd[0] = npd;
  806. pd = npd;
  807. } else {
  808. ipath_dev_err(dd, "Unable to allocate portdata"
  809. " for port 0, failing\n");
  810. ret = -ENOMEM;
  811. goto done;
  812. }
  813. }
  814. ret = ipath_create_rcvhdrq(dd, pd);
  815. if (!ret)
  816. ret = create_port0_egr(dd);
  817. if (ret) {
  818. ipath_dev_err(dd, "failed to allocate kernel port's "
  819. "rcvhdrq and/or egr bufs\n");
  820. goto done;
  821. }
  822. else
  823. enable_chip(dd, reinit);
  824. /* after enable_chip, so pioavailshadow setup */
  825. ipath_chg_pioavailkernel(dd, 0, piobufs, 1);
  826. /*
  827. * Cancel any possible active sends from early driver load.
  828. * Follows early_init because some chips have to initialize
  829. * PIO buffers in early_init to avoid false parity errors.
  830. * After enable and ipath_chg_pioavailkernel so we can safely
  831. * enable pioavail updates and PIOENABLE; packets are now
  832. * ready to go out.
  833. */
  834. ipath_cancel_sends(dd, 1);
  835. if (!reinit) {
  836. /*
  837. * Used when we close a port, for DMA already in flight
  838. * at close.
  839. */
  840. dd->ipath_dummy_hdrq = dma_alloc_coherent(
  841. &dd->pcidev->dev, dd->ipath_pd[0]->port_rcvhdrq_size,
  842. &dd->ipath_dummy_hdrq_phys,
  843. gfp_flags);
  844. if (!dd->ipath_dummy_hdrq) {
  845. dev_info(&dd->pcidev->dev,
  846. "Couldn't allocate 0x%lx bytes for dummy hdrq\n",
  847. dd->ipath_pd[0]->port_rcvhdrq_size);
  848. /* fallback to just 0'ing */
  849. dd->ipath_dummy_hdrq_phys = 0UL;
  850. }
  851. }
  852. /*
  853. * cause retrigger of pending interrupts ignored during init,
  854. * even if we had errors
  855. */
  856. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
  857. if (!dd->ipath_stats_timer_active) {
  858. /*
  859. * first init, or after an admin disable/enable
  860. * set up stats retrieval timer, even if we had errors
  861. * in last portion of setup
  862. */
  863. init_timer(&dd->ipath_stats_timer);
  864. dd->ipath_stats_timer.function = ipath_get_faststats;
  865. dd->ipath_stats_timer.data = (unsigned long) dd;
  866. /* every 5 seconds; */
  867. dd->ipath_stats_timer.expires = jiffies + 5 * HZ;
  868. /* takes ~16 seconds to overflow at full IB 4x bandwdith */
  869. add_timer(&dd->ipath_stats_timer);
  870. dd->ipath_stats_timer_active = 1;
  871. }
  872. /* Set up SendDMA if chip supports it */
  873. if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
  874. ret = setup_sdma(dd);
  875. /* Set up HoL state */
  876. init_timer(&dd->ipath_hol_timer);
  877. dd->ipath_hol_timer.function = ipath_hol_event;
  878. dd->ipath_hol_timer.data = (unsigned long)dd;
  879. dd->ipath_hol_state = IPATH_HOL_UP;
  880. done:
  881. if (!ret) {
  882. *dd->ipath_statusp |= IPATH_STATUS_CHIP_PRESENT;
  883. if (!dd->ipath_f_intrsetup(dd)) {
  884. /* now we can enable all interrupts from the chip */
  885. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
  886. -1LL);
  887. /* force re-interrupt of any pending interrupts. */
  888. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear,
  889. 0ULL);
  890. /* chip is usable; mark it as initialized */
  891. *dd->ipath_statusp |= IPATH_STATUS_INITTED;
  892. /*
  893. * setup to verify we get an interrupt, and fallback
  894. * to an alternate if necessary and possible
  895. */
  896. if (!reinit) {
  897. init_timer(&dd->ipath_intrchk_timer);
  898. dd->ipath_intrchk_timer.function =
  899. verify_interrupt;
  900. dd->ipath_intrchk_timer.data =
  901. (unsigned long) dd;
  902. }
  903. dd->ipath_intrchk_timer.expires = jiffies + HZ/2;
  904. add_timer(&dd->ipath_intrchk_timer);
  905. } else
  906. ipath_dev_err(dd, "No interrupts enabled, couldn't "
  907. "setup interrupt address\n");
  908. if (dd->ipath_cfgports > ipath_stats.sps_nports)
  909. /*
  910. * sps_nports is a global, so, we set it to
  911. * the highest number of ports of any of the
  912. * chips we find; we never decrement it, at
  913. * least for now. Since this might have changed
  914. * over disable/enable or prior to reset, always
  915. * do the check and potentially adjust.
  916. */
  917. ipath_stats.sps_nports = dd->ipath_cfgports;
  918. } else
  919. ipath_dbg("Failed (%d) to initialize chip\n", ret);
  920. /* if ret is non-zero, we probably should do some cleanup
  921. here... */
  922. return ret;
  923. }
  924. static int ipath_set_kpiobufs(const char *str, struct kernel_param *kp)
  925. {
  926. struct ipath_devdata *dd;
  927. unsigned long flags;
  928. unsigned short val;
  929. int ret;
  930. ret = ipath_parse_ushort(str, &val);
  931. spin_lock_irqsave(&ipath_devs_lock, flags);
  932. if (ret < 0)
  933. goto bail;
  934. if (val == 0) {
  935. ret = -EINVAL;
  936. goto bail;
  937. }
  938. list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
  939. if (dd->ipath_kregbase)
  940. continue;
  941. if (val > (dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -
  942. (dd->ipath_cfgports *
  943. IPATH_MIN_USER_PORT_BUFCNT)))
  944. {
  945. ipath_dev_err(
  946. dd,
  947. "Allocating %d PIO bufs for kernel leaves "
  948. "too few for %d user ports (%d each)\n",
  949. val, dd->ipath_cfgports - 1,
  950. IPATH_MIN_USER_PORT_BUFCNT);
  951. ret = -EINVAL;
  952. goto bail;
  953. }
  954. dd->ipath_lastport_piobuf =
  955. dd->ipath_piobcnt2k + dd->ipath_piobcnt4k - val;
  956. }
  957. ipath_kpiobufs = val;
  958. ret = 0;
  959. bail:
  960. spin_unlock_irqrestore(&ipath_devs_lock, flags);
  961. return ret;
  962. }