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