ipath_init_chip.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. /*
  2. * Copyright (c) 2006, 2007 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 8
  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. * Reserved at end of buffer list. Initialized based on
  52. * number of PIO buffers if not set via module interface.
  53. * The problem with this is that it's global, but we'll use different
  54. * numbers for different chip types. So the default value is not
  55. * very useful. I've redefined it for the 1.3 release so that it's
  56. * zero unless set by the user to something else, in which case we
  57. * try to respect it.
  58. */
  59. static ushort ipath_kpiobufs;
  60. static int ipath_set_kpiobufs(const char *val, struct kernel_param *kp);
  61. module_param_call(kpiobufs, ipath_set_kpiobufs, param_get_ushort,
  62. &ipath_kpiobufs, S_IWUSR | S_IRUGO);
  63. MODULE_PARM_DESC(kpiobufs, "Set number of PIO buffers for driver");
  64. /**
  65. * create_port0_egr - allocate the eager TID buffers
  66. * @dd: the infinipath device
  67. *
  68. * This code is now quite different for user and kernel, because
  69. * the kernel uses skb's, for the accelerated network performance.
  70. * This is the kernel (port0) version.
  71. *
  72. * Allocate the eager TID buffers and program them into infinipath.
  73. * We use the network layer alloc_skb() allocator to allocate the
  74. * memory, and either use the buffers as is for things like verbs
  75. * packets, or pass the buffers up to the ipath layered driver and
  76. * thence the network layer, replacing them as we do so (see
  77. * ipath_rcv_layer()).
  78. */
  79. static int create_port0_egr(struct ipath_devdata *dd)
  80. {
  81. unsigned e, egrcnt;
  82. struct ipath_skbinfo *skbinfo;
  83. int ret;
  84. egrcnt = dd->ipath_p0_rcvegrcnt;
  85. skbinfo = vmalloc(sizeof(*dd->ipath_port0_skbinfo) * egrcnt);
  86. if (skbinfo == NULL) {
  87. ipath_dev_err(dd, "allocation error for eager TID "
  88. "skb array\n");
  89. ret = -ENOMEM;
  90. goto bail;
  91. }
  92. for (e = 0; e < egrcnt; e++) {
  93. /*
  94. * This is a bit tricky in that we allocate extra
  95. * space for 2 bytes of the 14 byte ethernet header.
  96. * These two bytes are passed in the ipath header so
  97. * the rest of the data is word aligned. We allocate
  98. * 4 bytes so that the data buffer stays word aligned.
  99. * See ipath_kreceive() for more details.
  100. */
  101. skbinfo[e].skb = ipath_alloc_skb(dd, GFP_KERNEL);
  102. if (!skbinfo[e].skb) {
  103. ipath_dev_err(dd, "SKB allocation error for "
  104. "eager TID %u\n", e);
  105. while (e != 0)
  106. dev_kfree_skb(skbinfo[--e].skb);
  107. vfree(skbinfo);
  108. ret = -ENOMEM;
  109. goto bail;
  110. }
  111. }
  112. /*
  113. * After loop above, so we can test non-NULL to see if ready
  114. * to use at receive, etc.
  115. */
  116. dd->ipath_port0_skbinfo = skbinfo;
  117. for (e = 0; e < egrcnt; e++) {
  118. dd->ipath_port0_skbinfo[e].phys =
  119. ipath_map_single(dd->pcidev,
  120. dd->ipath_port0_skbinfo[e].skb->data,
  121. dd->ipath_ibmaxlen, PCI_DMA_FROMDEVICE);
  122. dd->ipath_f_put_tid(dd, e + (u64 __iomem *)
  123. ((char __iomem *) dd->ipath_kregbase +
  124. dd->ipath_rcvegrbase),
  125. RCVHQ_RCV_TYPE_EAGER,
  126. dd->ipath_port0_skbinfo[e].phys);
  127. }
  128. ret = 0;
  129. bail:
  130. return ret;
  131. }
  132. static int bringup_link(struct ipath_devdata *dd)
  133. {
  134. u64 val, ibc;
  135. int ret = 0;
  136. /* hold IBC in reset */
  137. dd->ipath_control &= ~INFINIPATH_C_LINKENABLE;
  138. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  139. dd->ipath_control);
  140. /*
  141. * set initial max size pkt IBC will send, including ICRC; it's the
  142. * PIO buffer size in dwords, less 1; also see ipath_set_mtu()
  143. */
  144. val = (dd->ipath_ibmaxlen >> 2) + 1;
  145. ibc = val << dd->ibcc_mpl_shift;
  146. /* flowcontrolwatermark is in units of KBytes */
  147. ibc |= 0x5ULL << INFINIPATH_IBCC_FLOWCTRLWATERMARK_SHIFT;
  148. /*
  149. * How often flowctrl sent. More or less in usecs; balance against
  150. * watermark value, so that in theory senders always get a flow
  151. * control update in time to not let the IB link go idle.
  152. */
  153. ibc |= 0x3ULL << INFINIPATH_IBCC_FLOWCTRLPERIOD_SHIFT;
  154. /* max error tolerance */
  155. ibc |= 0xfULL << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
  156. /* use "real" buffer space for */
  157. ibc |= 4ULL << INFINIPATH_IBCC_CREDITSCALE_SHIFT;
  158. /* IB credit flow control. */
  159. ibc |= 0xfULL << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
  160. /* initially come up waiting for TS1, without sending anything. */
  161. dd->ipath_ibcctrl = ibc;
  162. /*
  163. * Want to start out with both LINKCMD and LINKINITCMD in NOP
  164. * (0 and 0). Don't put linkinitcmd in ipath_ibcctrl, want that
  165. * to stay a NOP. Flag that we are disabled, for the (unlikely)
  166. * case that some recovery path is trying to bring the link up
  167. * before we are ready.
  168. */
  169. ibc |= INFINIPATH_IBCC_LINKINITCMD_DISABLE <<
  170. INFINIPATH_IBCC_LINKINITCMD_SHIFT;
  171. dd->ipath_flags |= IPATH_IB_LINK_DISABLED;
  172. ipath_cdbg(VERBOSE, "Writing 0x%llx to ibcctrl\n",
  173. (unsigned long long) ibc);
  174. ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl, ibc);
  175. // be sure chip saw it
  176. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  177. ret = dd->ipath_f_bringup_serdes(dd);
  178. if (ret)
  179. dev_info(&dd->pcidev->dev, "Could not initialize SerDes, "
  180. "not usable\n");
  181. else {
  182. /* enable IBC */
  183. dd->ipath_control |= INFINIPATH_C_LINKENABLE;
  184. ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
  185. dd->ipath_control);
  186. }
  187. return ret;
  188. }
  189. static struct ipath_portdata *create_portdata0(struct ipath_devdata *dd)
  190. {
  191. struct ipath_portdata *pd = NULL;
  192. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  193. if (pd) {
  194. pd->port_dd = dd;
  195. pd->port_cnt = 1;
  196. /* The port 0 pkey table is used by the layer interface. */
  197. pd->port_pkeys[0] = IPATH_DEFAULT_P_KEY;
  198. pd->port_seq_cnt = 1;
  199. }
  200. return pd;
  201. }
  202. static int init_chip_first(struct ipath_devdata *dd)
  203. {
  204. struct ipath_portdata *pd;
  205. int ret = 0;
  206. u64 val;
  207. spin_lock_init(&dd->ipath_kernel_tid_lock);
  208. spin_lock_init(&dd->ipath_user_tid_lock);
  209. spin_lock_init(&dd->ipath_sendctrl_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 (explictly, 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 = vmalloc(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(dd->ipath_pageshadow);
  417. dd->ipath_pageshadow = NULL;
  418. return;
  419. }
  420. memset(pages, 0, dd->ipath_cfgports * dd->ipath_rcvtidcnt *
  421. sizeof(struct page *));
  422. dd->ipath_pageshadow = pages;
  423. dd->ipath_physshadow = addrs;
  424. }
  425. static void enable_chip(struct ipath_devdata *dd, int reinit)
  426. {
  427. u32 val;
  428. u64 rcvmask;
  429. unsigned long flags;
  430. int i;
  431. if (!reinit)
  432. init_waitqueue_head(&ipath_state_wait);
  433. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  434. dd->ipath_rcvctrl);
  435. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  436. /* Enable PIO send, and update of PIOavail regs to memory. */
  437. dd->ipath_sendctrl = INFINIPATH_S_PIOENABLE |
  438. INFINIPATH_S_PIOBUFAVAILUPD;
  439. /*
  440. * Set the PIO avail update threshold to host memory
  441. * on chips that support it.
  442. */
  443. if (dd->ipath_pioupd_thresh)
  444. dd->ipath_sendctrl |= dd->ipath_pioupd_thresh
  445. << INFINIPATH_S_UPDTHRESH_SHIFT;
  446. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, dd->ipath_sendctrl);
  447. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  448. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  449. /*
  450. * Enable kernel ports' receive and receive interrupt.
  451. * Other ports done as user opens and inits them.
  452. */
  453. rcvmask = 1ULL;
  454. dd->ipath_rcvctrl |= (rcvmask << dd->ipath_r_portenable_shift) |
  455. (rcvmask << dd->ipath_r_intravail_shift);
  456. if (!(dd->ipath_flags & IPATH_NODMA_RTAIL))
  457. dd->ipath_rcvctrl |= (1ULL << dd->ipath_r_tailupd_shift);
  458. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
  459. dd->ipath_rcvctrl);
  460. /*
  461. * now ready for use. this should be cleared whenever we
  462. * detect a reset, or initiate one.
  463. */
  464. dd->ipath_flags |= IPATH_INITTED;
  465. /*
  466. * Init our shadow copies of head from tail values,
  467. * and write head values to match.
  468. */
  469. val = ipath_read_ureg32(dd, ur_rcvegrindextail, 0);
  470. ipath_write_ureg(dd, ur_rcvegrindexhead, val, 0);
  471. /* Initialize so we interrupt on next packet received */
  472. ipath_write_ureg(dd, ur_rcvhdrhead,
  473. dd->ipath_rhdrhead_intr_off |
  474. dd->ipath_pd[0]->port_head, 0);
  475. /*
  476. * by now pioavail updates to memory should have occurred, so
  477. * copy them into our working/shadow registers; this is in
  478. * case something went wrong with abort, but mostly to get the
  479. * initial values of the generation bit correct.
  480. */
  481. for (i = 0; i < dd->ipath_pioavregs; i++) {
  482. __le64 pioavail;
  483. /*
  484. * Chip Errata bug 6641; even and odd qwords>3 are swapped.
  485. */
  486. if (i > 3 && (dd->ipath_flags & IPATH_SWAP_PIOBUFS))
  487. pioavail = dd->ipath_pioavailregs_dma[i ^ 1];
  488. else
  489. pioavail = dd->ipath_pioavailregs_dma[i];
  490. dd->ipath_pioavailshadow[i] = le64_to_cpu(pioavail) |
  491. (~dd->ipath_pioavailkernel[i] <<
  492. INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT);
  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 val32, kpiobufs;
  633. u32 piobufs, uports;
  634. u64 val;
  635. struct ipath_portdata *pd;
  636. gfp_t gfp_flags = GFP_USER | __GFP_COMP;
  637. unsigned long flags;
  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 (ipath_kpiobufs == 0) {
  674. /* not set by user (this is default) */
  675. if (piobufs > 144)
  676. kpiobufs = 32;
  677. else
  678. kpiobufs = 16;
  679. }
  680. else
  681. kpiobufs = ipath_kpiobufs;
  682. if (kpiobufs + (uports * IPATH_MIN_USER_PORT_BUFCNT) > piobufs) {
  683. int i = (int) piobufs -
  684. (int) (uports * IPATH_MIN_USER_PORT_BUFCNT);
  685. if (i < 1)
  686. i = 1;
  687. dev_info(&dd->pcidev->dev, "Allocating %d PIO bufs of "
  688. "%d for kernel leaves too few for %d user ports "
  689. "(%d each); using %u\n", kpiobufs,
  690. piobufs, uports, IPATH_MIN_USER_PORT_BUFCNT, i);
  691. /*
  692. * shouldn't change ipath_kpiobufs, because could be
  693. * different for different devices...
  694. */
  695. kpiobufs = i;
  696. }
  697. dd->ipath_lastport_piobuf = piobufs - kpiobufs;
  698. dd->ipath_pbufsport =
  699. uports ? dd->ipath_lastport_piobuf / uports : 0;
  700. val32 = dd->ipath_lastport_piobuf - (dd->ipath_pbufsport * uports);
  701. if (val32 > 0) {
  702. ipath_dbg("allocating %u pbufs/port leaves %u unused, "
  703. "add to kernel\n", dd->ipath_pbufsport, val32);
  704. dd->ipath_lastport_piobuf -= val32;
  705. kpiobufs += val32;
  706. ipath_dbg("%u pbufs/port leaves %u unused, add to kernel\n",
  707. dd->ipath_pbufsport, val32);
  708. }
  709. dd->ipath_lastpioindex = 0;
  710. dd->ipath_lastpioindexl = dd->ipath_piobcnt2k;
  711. ipath_chg_pioavailkernel(dd, 0, piobufs, 1);
  712. ipath_cdbg(VERBOSE, "%d PIO bufs for kernel out of %d total %u "
  713. "each for %u user ports\n", kpiobufs,
  714. piobufs, dd->ipath_pbufsport, uports);
  715. if (dd->ipath_pioupd_thresh) {
  716. if (dd->ipath_pbufsport < dd->ipath_pioupd_thresh)
  717. dd->ipath_pioupd_thresh = dd->ipath_pbufsport;
  718. if (kpiobufs < dd->ipath_pioupd_thresh)
  719. dd->ipath_pioupd_thresh = kpiobufs;
  720. }
  721. ret = dd->ipath_f_early_init(dd);
  722. if (ret) {
  723. ipath_dev_err(dd, "Early initialization failure\n");
  724. goto done;
  725. }
  726. /*
  727. * Cancel any possible active sends from early driver load.
  728. * Follows early_init because some chips have to initialize
  729. * PIO buffers in early_init to avoid false parity errors.
  730. */
  731. ipath_cancel_sends(dd, 0);
  732. /*
  733. * Early_init sets rcvhdrentsize and rcvhdrsize, so this must be
  734. * done after early_init.
  735. */
  736. dd->ipath_hdrqlast =
  737. dd->ipath_rcvhdrentsize * (dd->ipath_rcvhdrcnt - 1);
  738. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrentsize,
  739. dd->ipath_rcvhdrentsize);
  740. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrsize,
  741. dd->ipath_rcvhdrsize);
  742. if (!reinit) {
  743. ret = init_pioavailregs(dd);
  744. init_shadow_tids(dd);
  745. if (ret)
  746. goto done;
  747. }
  748. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendpioavailaddr,
  749. dd->ipath_pioavailregs_phys);
  750. /*
  751. * this is to detect s/w errors, which the h/w works around by
  752. * ignoring the low 6 bits of address, if it wasn't aligned.
  753. */
  754. val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpioavailaddr);
  755. if (val != dd->ipath_pioavailregs_phys) {
  756. ipath_dev_err(dd, "Catastrophic software error, "
  757. "SendPIOAvailAddr written as %lx, "
  758. "read back as %llx\n",
  759. (unsigned long) dd->ipath_pioavailregs_phys,
  760. (unsigned long long) val);
  761. ret = -EINVAL;
  762. goto done;
  763. }
  764. ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvbthqp, IPATH_KD_QP);
  765. /*
  766. * make sure we are not in freeze, and PIO send enabled, so
  767. * writes to pbc happen
  768. */
  769. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, 0ULL);
  770. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  771. ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);
  772. ipath_write_kreg(dd, dd->ipath_kregs->kr_control, 0ULL);
  773. spin_lock_irqsave(&dd->ipath_sendctrl_lock, flags);
  774. dd->ipath_sendctrl = INFINIPATH_S_PIOENABLE;
  775. ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, dd->ipath_sendctrl);
  776. ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
  777. spin_unlock_irqrestore(&dd->ipath_sendctrl_lock, flags);
  778. /*
  779. * before error clears, since we expect serdes pll errors during
  780. * this, the first time after reset
  781. */
  782. if (bringup_link(dd)) {
  783. dev_info(&dd->pcidev->dev, "Failed to bringup IB link\n");
  784. ret = -ENETDOWN;
  785. goto done;
  786. }
  787. /*
  788. * clear any "expected" hwerrs from reset and/or initialization
  789. * clear any that aren't enabled (at least this once), and then
  790. * set the enable mask
  791. */
  792. dd->ipath_f_init_hwerrors(dd);
  793. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
  794. ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);
  795. ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
  796. dd->ipath_hwerrmask);
  797. /* clear all */
  798. ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, -1LL);
  799. /* enable errors that are masked, at least this first time. */
  800. ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
  801. ~dd->ipath_maskederrs);
  802. dd->ipath_maskederrs = 0; /* don't re-enable ignored in timer */
  803. dd->ipath_errormask =
  804. ipath_read_kreg64(dd, dd->ipath_kregs->kr_errormask);
  805. /* clear any interrupts up to this point (ints still not enabled) */
  806. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, -1LL);
  807. dd->ipath_f_tidtemplate(dd);
  808. /*
  809. * Set up the port 0 (kernel) rcvhdr q and egr TIDs. If doing
  810. * re-init, the simplest way to handle this is to free
  811. * existing, and re-allocate.
  812. * Need to re-create rest of port 0 portdata as well.
  813. */
  814. pd = dd->ipath_pd[0];
  815. if (reinit) {
  816. struct ipath_portdata *npd;
  817. /*
  818. * Alloc and init new ipath_portdata for port0,
  819. * Then free old pd. Could lead to fragmentation, but also
  820. * makes later support for hot-swap easier.
  821. */
  822. npd = create_portdata0(dd);
  823. if (npd) {
  824. ipath_free_pddata(dd, pd);
  825. dd->ipath_pd[0] = npd;
  826. pd = npd;
  827. } else {
  828. ipath_dev_err(dd, "Unable to allocate portdata"
  829. " for port 0, failing\n");
  830. ret = -ENOMEM;
  831. goto done;
  832. }
  833. }
  834. ret = ipath_create_rcvhdrq(dd, pd);
  835. if (!ret)
  836. ret = create_port0_egr(dd);
  837. if (ret) {
  838. ipath_dev_err(dd, "failed to allocate kernel port's "
  839. "rcvhdrq and/or egr bufs\n");
  840. goto done;
  841. }
  842. else
  843. enable_chip(dd, reinit);
  844. if (!reinit) {
  845. /*
  846. * Used when we close a port, for DMA already in flight
  847. * at close.
  848. */
  849. dd->ipath_dummy_hdrq = dma_alloc_coherent(
  850. &dd->pcidev->dev, dd->ipath_pd[0]->port_rcvhdrq_size,
  851. &dd->ipath_dummy_hdrq_phys,
  852. gfp_flags);
  853. if (!dd->ipath_dummy_hdrq) {
  854. dev_info(&dd->pcidev->dev,
  855. "Couldn't allocate 0x%lx bytes for dummy hdrq\n",
  856. dd->ipath_pd[0]->port_rcvhdrq_size);
  857. /* fallback to just 0'ing */
  858. dd->ipath_dummy_hdrq_phys = 0UL;
  859. }
  860. }
  861. /*
  862. * cause retrigger of pending interrupts ignored during init,
  863. * even if we had errors
  864. */
  865. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
  866. if (!dd->ipath_stats_timer_active) {
  867. /*
  868. * first init, or after an admin disable/enable
  869. * set up stats retrieval timer, even if we had errors
  870. * in last portion of setup
  871. */
  872. init_timer(&dd->ipath_stats_timer);
  873. dd->ipath_stats_timer.function = ipath_get_faststats;
  874. dd->ipath_stats_timer.data = (unsigned long) dd;
  875. /* every 5 seconds; */
  876. dd->ipath_stats_timer.expires = jiffies + 5 * HZ;
  877. /* takes ~16 seconds to overflow at full IB 4x bandwdith */
  878. add_timer(&dd->ipath_stats_timer);
  879. dd->ipath_stats_timer_active = 1;
  880. }
  881. /* Set up HoL state */
  882. init_timer(&dd->ipath_hol_timer);
  883. dd->ipath_hol_timer.function = ipath_hol_event;
  884. dd->ipath_hol_timer.data = (unsigned long)dd;
  885. dd->ipath_hol_state = IPATH_HOL_UP;
  886. done:
  887. if (!ret) {
  888. *dd->ipath_statusp |= IPATH_STATUS_CHIP_PRESENT;
  889. if (!dd->ipath_f_intrsetup(dd)) {
  890. /* now we can enable all interrupts from the chip */
  891. ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
  892. -1LL);
  893. /* force re-interrupt of any pending interrupts. */
  894. ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear,
  895. 0ULL);
  896. /* chip is usable; mark it as initialized */
  897. *dd->ipath_statusp |= IPATH_STATUS_INITTED;
  898. /*
  899. * setup to verify we get an interrupt, and fallback
  900. * to an alternate if necessary and possible
  901. */
  902. if (!reinit) {
  903. init_timer(&dd->ipath_intrchk_timer);
  904. dd->ipath_intrchk_timer.function =
  905. verify_interrupt;
  906. dd->ipath_intrchk_timer.data =
  907. (unsigned long) dd;
  908. }
  909. dd->ipath_intrchk_timer.expires = jiffies + HZ/2;
  910. add_timer(&dd->ipath_intrchk_timer);
  911. } else
  912. ipath_dev_err(dd, "No interrupts enabled, couldn't "
  913. "setup interrupt address\n");
  914. if (dd->ipath_cfgports > ipath_stats.sps_nports)
  915. /*
  916. * sps_nports is a global, so, we set it to
  917. * the highest number of ports of any of the
  918. * chips we find; we never decrement it, at
  919. * least for now. Since this might have changed
  920. * over disable/enable or prior to reset, always
  921. * do the check and potentially adjust.
  922. */
  923. ipath_stats.sps_nports = dd->ipath_cfgports;
  924. } else
  925. ipath_dbg("Failed (%d) to initialize chip\n", ret);
  926. /* if ret is non-zero, we probably should do some cleanup
  927. here... */
  928. return ret;
  929. }
  930. static int ipath_set_kpiobufs(const char *str, struct kernel_param *kp)
  931. {
  932. struct ipath_devdata *dd;
  933. unsigned long flags;
  934. unsigned short val;
  935. int ret;
  936. ret = ipath_parse_ushort(str, &val);
  937. spin_lock_irqsave(&ipath_devs_lock, flags);
  938. if (ret < 0)
  939. goto bail;
  940. if (val == 0) {
  941. ret = -EINVAL;
  942. goto bail;
  943. }
  944. list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
  945. if (dd->ipath_kregbase)
  946. continue;
  947. if (val > (dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -
  948. (dd->ipath_cfgports *
  949. IPATH_MIN_USER_PORT_BUFCNT)))
  950. {
  951. ipath_dev_err(
  952. dd,
  953. "Allocating %d PIO bufs for kernel leaves "
  954. "too few for %d user ports (%d each)\n",
  955. val, dd->ipath_cfgports - 1,
  956. IPATH_MIN_USER_PORT_BUFCNT);
  957. ret = -EINVAL;
  958. goto bail;
  959. }
  960. dd->ipath_lastport_piobuf =
  961. dd->ipath_piobcnt2k + dd->ipath_piobcnt4k - val;
  962. }
  963. ipath_kpiobufs = val;
  964. ret = 0;
  965. bail:
  966. spin_unlock_irqrestore(&ipath_devs_lock, flags);
  967. return ret;
  968. }