ipath_init_chip.c 33 KB

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