driver.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  1. /*
  2. * Copyright(c) 2015-2017 Intel Corporation.
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * BSD LICENSE
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. *
  24. * - Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * - Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in
  28. * the documentation and/or other materials provided with the
  29. * distribution.
  30. * - Neither the name of Intel Corporation nor the names of its
  31. * contributors may be used to endorse or promote products derived
  32. * from this software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  37. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  38. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  39. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  40. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  41. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  42. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  44. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. */
  47. #include <linux/spinlock.h>
  48. #include <linux/pci.h>
  49. #include <linux/io.h>
  50. #include <linux/delay.h>
  51. #include <linux/netdevice.h>
  52. #include <linux/vmalloc.h>
  53. #include <linux/module.h>
  54. #include <linux/prefetch.h>
  55. #include <rdma/ib_verbs.h>
  56. #include "hfi.h"
  57. #include "trace.h"
  58. #include "qp.h"
  59. #include "sdma.h"
  60. #include "debugfs.h"
  61. #include "vnic.h"
  62. #undef pr_fmt
  63. #define pr_fmt(fmt) DRIVER_NAME ": " fmt
  64. /*
  65. * The size has to be longer than this string, so we can append
  66. * board/chip information to it in the initialization code.
  67. */
  68. const char ib_hfi1_version[] = HFI1_DRIVER_VERSION "\n";
  69. DEFINE_SPINLOCK(hfi1_devs_lock);
  70. LIST_HEAD(hfi1_dev_list);
  71. DEFINE_MUTEX(hfi1_mutex); /* general driver use */
  72. unsigned int hfi1_max_mtu = HFI1_DEFAULT_MAX_MTU;
  73. module_param_named(max_mtu, hfi1_max_mtu, uint, S_IRUGO);
  74. MODULE_PARM_DESC(max_mtu, "Set max MTU bytes, default is " __stringify(
  75. HFI1_DEFAULT_MAX_MTU));
  76. unsigned int hfi1_cu = 1;
  77. module_param_named(cu, hfi1_cu, uint, S_IRUGO);
  78. MODULE_PARM_DESC(cu, "Credit return units");
  79. unsigned long hfi1_cap_mask = HFI1_CAP_MASK_DEFAULT;
  80. static int hfi1_caps_set(const char *val, const struct kernel_param *kp);
  81. static int hfi1_caps_get(char *buffer, const struct kernel_param *kp);
  82. static const struct kernel_param_ops cap_ops = {
  83. .set = hfi1_caps_set,
  84. .get = hfi1_caps_get
  85. };
  86. module_param_cb(cap_mask, &cap_ops, &hfi1_cap_mask, S_IWUSR | S_IRUGO);
  87. MODULE_PARM_DESC(cap_mask, "Bit mask of enabled/disabled HW features");
  88. MODULE_LICENSE("Dual BSD/GPL");
  89. MODULE_DESCRIPTION("Intel Omni-Path Architecture driver");
  90. /*
  91. * MAX_PKT_RCV is the max # if packets processed per receive interrupt.
  92. */
  93. #define MAX_PKT_RECV 64
  94. /*
  95. * MAX_PKT_THREAD_RCV is the max # of packets processed before
  96. * the qp_wait_list queue is flushed.
  97. */
  98. #define MAX_PKT_RECV_THREAD (MAX_PKT_RECV * 4)
  99. #define EGR_HEAD_UPDATE_THRESHOLD 16
  100. struct hfi1_ib_stats hfi1_stats;
  101. static int hfi1_caps_set(const char *val, const struct kernel_param *kp)
  102. {
  103. int ret = 0;
  104. unsigned long *cap_mask_ptr = (unsigned long *)kp->arg,
  105. cap_mask = *cap_mask_ptr, value, diff,
  106. write_mask = ((HFI1_CAP_WRITABLE_MASK << HFI1_CAP_USER_SHIFT) |
  107. HFI1_CAP_WRITABLE_MASK);
  108. ret = kstrtoul(val, 0, &value);
  109. if (ret) {
  110. pr_warn("Invalid module parameter value for 'cap_mask'\n");
  111. goto done;
  112. }
  113. /* Get the changed bits (except the locked bit) */
  114. diff = value ^ (cap_mask & ~HFI1_CAP_LOCKED_SMASK);
  115. /* Remove any bits that are not allowed to change after driver load */
  116. if (HFI1_CAP_LOCKED() && (diff & ~write_mask)) {
  117. pr_warn("Ignoring non-writable capability bits %#lx\n",
  118. diff & ~write_mask);
  119. diff &= write_mask;
  120. }
  121. /* Mask off any reserved bits */
  122. diff &= ~HFI1_CAP_RESERVED_MASK;
  123. /* Clear any previously set and changing bits */
  124. cap_mask &= ~diff;
  125. /* Update the bits with the new capability */
  126. cap_mask |= (value & diff);
  127. /* Check for any kernel/user restrictions */
  128. diff = (cap_mask & (HFI1_CAP_MUST_HAVE_KERN << HFI1_CAP_USER_SHIFT)) ^
  129. ((cap_mask & HFI1_CAP_MUST_HAVE_KERN) << HFI1_CAP_USER_SHIFT);
  130. cap_mask &= ~diff;
  131. /* Set the bitmask to the final set */
  132. *cap_mask_ptr = cap_mask;
  133. done:
  134. return ret;
  135. }
  136. static int hfi1_caps_get(char *buffer, const struct kernel_param *kp)
  137. {
  138. unsigned long cap_mask = *(unsigned long *)kp->arg;
  139. cap_mask &= ~HFI1_CAP_LOCKED_SMASK;
  140. cap_mask |= ((cap_mask & HFI1_CAP_K2U) << HFI1_CAP_USER_SHIFT);
  141. return scnprintf(buffer, PAGE_SIZE, "0x%lx", cap_mask);
  142. }
  143. const char *get_unit_name(int unit)
  144. {
  145. static char iname[16];
  146. snprintf(iname, sizeof(iname), DRIVER_NAME "_%u", unit);
  147. return iname;
  148. }
  149. const char *get_card_name(struct rvt_dev_info *rdi)
  150. {
  151. struct hfi1_ibdev *ibdev = container_of(rdi, struct hfi1_ibdev, rdi);
  152. struct hfi1_devdata *dd = container_of(ibdev,
  153. struct hfi1_devdata, verbs_dev);
  154. return get_unit_name(dd->unit);
  155. }
  156. struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi)
  157. {
  158. struct hfi1_ibdev *ibdev = container_of(rdi, struct hfi1_ibdev, rdi);
  159. struct hfi1_devdata *dd = container_of(ibdev,
  160. struct hfi1_devdata, verbs_dev);
  161. return dd->pcidev;
  162. }
  163. /*
  164. * Return count of units with at least one port ACTIVE.
  165. */
  166. int hfi1_count_active_units(void)
  167. {
  168. struct hfi1_devdata *dd;
  169. struct hfi1_pportdata *ppd;
  170. unsigned long flags;
  171. int pidx, nunits_active = 0;
  172. spin_lock_irqsave(&hfi1_devs_lock, flags);
  173. list_for_each_entry(dd, &hfi1_dev_list, list) {
  174. if (!(dd->flags & HFI1_PRESENT) || !dd->kregbase1)
  175. continue;
  176. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  177. ppd = dd->pport + pidx;
  178. if (ppd->lid && ppd->linkup) {
  179. nunits_active++;
  180. break;
  181. }
  182. }
  183. }
  184. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  185. return nunits_active;
  186. }
  187. /*
  188. * Get address of eager buffer from it's index (allocated in chunks, not
  189. * contiguous).
  190. */
  191. static inline void *get_egrbuf(const struct hfi1_ctxtdata *rcd, u64 rhf,
  192. u8 *update)
  193. {
  194. u32 idx = rhf_egr_index(rhf), offset = rhf_egr_buf_offset(rhf);
  195. *update |= !(idx & (rcd->egrbufs.threshold - 1)) && !offset;
  196. return (void *)(((u64)(rcd->egrbufs.rcvtids[idx].addr)) +
  197. (offset * RCV_BUF_BLOCK_SIZE));
  198. }
  199. static inline void *hfi1_get_header(struct hfi1_devdata *dd,
  200. __le32 *rhf_addr)
  201. {
  202. u32 offset = rhf_hdrq_offset(rhf_to_cpu(rhf_addr));
  203. return (void *)(rhf_addr - dd->rhf_offset + offset);
  204. }
  205. static inline struct ib_header *hfi1_get_msgheader(struct hfi1_devdata *dd,
  206. __le32 *rhf_addr)
  207. {
  208. return (struct ib_header *)hfi1_get_header(dd, rhf_addr);
  209. }
  210. static inline struct hfi1_16b_header
  211. *hfi1_get_16B_header(struct hfi1_devdata *dd,
  212. __le32 *rhf_addr)
  213. {
  214. return (struct hfi1_16b_header *)hfi1_get_header(dd, rhf_addr);
  215. }
  216. /*
  217. * Validate and encode the a given RcvArray Buffer size.
  218. * The function will check whether the given size falls within
  219. * allowed size ranges for the respective type and, optionally,
  220. * return the proper encoding.
  221. */
  222. int hfi1_rcvbuf_validate(u32 size, u8 type, u16 *encoded)
  223. {
  224. if (unlikely(!PAGE_ALIGNED(size)))
  225. return 0;
  226. if (unlikely(size < MIN_EAGER_BUFFER))
  227. return 0;
  228. if (size >
  229. (type == PT_EAGER ? MAX_EAGER_BUFFER : MAX_EXPECTED_BUFFER))
  230. return 0;
  231. if (encoded)
  232. *encoded = ilog2(size / PAGE_SIZE) + 1;
  233. return 1;
  234. }
  235. static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
  236. struct hfi1_packet *packet)
  237. {
  238. struct ib_header *rhdr = packet->hdr;
  239. u32 rte = rhf_rcv_type_err(packet->rhf);
  240. u32 mlid_base;
  241. struct hfi1_ibport *ibp = rcd_to_iport(rcd);
  242. struct hfi1_devdata *dd = ppd->dd;
  243. struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
  244. if (packet->rhf & (RHF_VCRC_ERR | RHF_ICRC_ERR))
  245. return;
  246. if (packet->etype == RHF_RCV_TYPE_BYPASS) {
  247. goto drop;
  248. } else {
  249. u8 lnh = ib_get_lnh(rhdr);
  250. mlid_base = be16_to_cpu(IB_MULTICAST_LID_BASE);
  251. if (lnh == HFI1_LRH_BTH) {
  252. packet->ohdr = &rhdr->u.oth;
  253. } else if (lnh == HFI1_LRH_GRH) {
  254. packet->ohdr = &rhdr->u.l.oth;
  255. packet->grh = &rhdr->u.l.grh;
  256. } else {
  257. goto drop;
  258. }
  259. }
  260. if (packet->rhf & RHF_TID_ERR) {
  261. /* For TIDERR and RC QPs preemptively schedule a NAK */
  262. u32 tlen = rhf_pkt_len(packet->rhf); /* in bytes */
  263. u32 dlid = ib_get_dlid(rhdr);
  264. u32 qp_num;
  265. /* Sanity check packet */
  266. if (tlen < 24)
  267. goto drop;
  268. /* Check for GRH */
  269. if (packet->grh) {
  270. u32 vtf;
  271. struct ib_grh *grh = packet->grh;
  272. if (grh->next_hdr != IB_GRH_NEXT_HDR)
  273. goto drop;
  274. vtf = be32_to_cpu(grh->version_tclass_flow);
  275. if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
  276. goto drop;
  277. }
  278. /* Get the destination QP number. */
  279. qp_num = ib_bth_get_qpn(packet->ohdr);
  280. if (dlid < mlid_base) {
  281. struct rvt_qp *qp;
  282. unsigned long flags;
  283. rcu_read_lock();
  284. qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
  285. if (!qp) {
  286. rcu_read_unlock();
  287. goto drop;
  288. }
  289. /*
  290. * Handle only RC QPs - for other QP types drop error
  291. * packet.
  292. */
  293. spin_lock_irqsave(&qp->r_lock, flags);
  294. /* Check for valid receive state. */
  295. if (!(ib_rvt_state_ops[qp->state] &
  296. RVT_PROCESS_RECV_OK)) {
  297. ibp->rvp.n_pkt_drops++;
  298. }
  299. switch (qp->ibqp.qp_type) {
  300. case IB_QPT_RC:
  301. hfi1_rc_hdrerr(rcd, packet, qp);
  302. break;
  303. default:
  304. /* For now don't handle any other QP types */
  305. break;
  306. }
  307. spin_unlock_irqrestore(&qp->r_lock, flags);
  308. rcu_read_unlock();
  309. } /* Unicast QP */
  310. } /* Valid packet with TIDErr */
  311. /* handle "RcvTypeErr" flags */
  312. switch (rte) {
  313. case RHF_RTE_ERROR_OP_CODE_ERR:
  314. {
  315. void *ebuf = NULL;
  316. u8 opcode;
  317. if (rhf_use_egr_bfr(packet->rhf))
  318. ebuf = packet->ebuf;
  319. if (!ebuf)
  320. goto drop; /* this should never happen */
  321. opcode = ib_bth_get_opcode(packet->ohdr);
  322. if (opcode == IB_OPCODE_CNP) {
  323. /*
  324. * Only in pre-B0 h/w is the CNP_OPCODE handled
  325. * via this code path.
  326. */
  327. struct rvt_qp *qp = NULL;
  328. u32 lqpn, rqpn;
  329. u16 rlid;
  330. u8 svc_type, sl, sc5;
  331. sc5 = hfi1_9B_get_sc5(rhdr, packet->rhf);
  332. sl = ibp->sc_to_sl[sc5];
  333. lqpn = ib_bth_get_qpn(packet->ohdr);
  334. rcu_read_lock();
  335. qp = rvt_lookup_qpn(rdi, &ibp->rvp, lqpn);
  336. if (!qp) {
  337. rcu_read_unlock();
  338. goto drop;
  339. }
  340. switch (qp->ibqp.qp_type) {
  341. case IB_QPT_UD:
  342. rlid = 0;
  343. rqpn = 0;
  344. svc_type = IB_CC_SVCTYPE_UD;
  345. break;
  346. case IB_QPT_UC:
  347. rlid = ib_get_slid(rhdr);
  348. rqpn = qp->remote_qpn;
  349. svc_type = IB_CC_SVCTYPE_UC;
  350. break;
  351. default:
  352. goto drop;
  353. }
  354. process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type);
  355. rcu_read_unlock();
  356. }
  357. packet->rhf &= ~RHF_RCV_TYPE_ERR_SMASK;
  358. break;
  359. }
  360. default:
  361. break;
  362. }
  363. drop:
  364. return;
  365. }
  366. static inline void init_packet(struct hfi1_ctxtdata *rcd,
  367. struct hfi1_packet *packet)
  368. {
  369. packet->rsize = rcd->rcvhdrqentsize; /* words */
  370. packet->maxcnt = rcd->rcvhdrq_cnt * packet->rsize; /* words */
  371. packet->rcd = rcd;
  372. packet->updegr = 0;
  373. packet->etail = -1;
  374. packet->rhf_addr = get_rhf_addr(rcd);
  375. packet->rhf = rhf_to_cpu(packet->rhf_addr);
  376. packet->rhqoff = rcd->head;
  377. packet->numpkt = 0;
  378. }
  379. void hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt,
  380. bool do_cnp)
  381. {
  382. struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
  383. struct ib_other_headers *ohdr = pkt->ohdr;
  384. struct ib_grh *grh = pkt->grh;
  385. u32 rqpn = 0, bth1;
  386. u16 pkey, rlid, dlid = ib_get_dlid(pkt->hdr);
  387. u8 hdr_type, sc, svc_type;
  388. bool is_mcast = false;
  389. if (pkt->etype == RHF_RCV_TYPE_BYPASS) {
  390. is_mcast = hfi1_is_16B_mcast(dlid);
  391. pkey = hfi1_16B_get_pkey(pkt->hdr);
  392. sc = hfi1_16B_get_sc(pkt->hdr);
  393. hdr_type = HFI1_PKT_TYPE_16B;
  394. } else {
  395. is_mcast = (dlid > be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
  396. (dlid != be16_to_cpu(IB_LID_PERMISSIVE));
  397. pkey = ib_bth_get_pkey(ohdr);
  398. sc = hfi1_9B_get_sc5(pkt->hdr, pkt->rhf);
  399. hdr_type = HFI1_PKT_TYPE_9B;
  400. }
  401. switch (qp->ibqp.qp_type) {
  402. case IB_QPT_SMI:
  403. case IB_QPT_GSI:
  404. case IB_QPT_UD:
  405. rlid = ib_get_slid(pkt->hdr);
  406. rqpn = ib_get_sqpn(pkt->ohdr);
  407. svc_type = IB_CC_SVCTYPE_UD;
  408. break;
  409. case IB_QPT_UC:
  410. rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
  411. rqpn = qp->remote_qpn;
  412. svc_type = IB_CC_SVCTYPE_UC;
  413. break;
  414. case IB_QPT_RC:
  415. rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
  416. rqpn = qp->remote_qpn;
  417. svc_type = IB_CC_SVCTYPE_RC;
  418. break;
  419. default:
  420. return;
  421. }
  422. bth1 = be32_to_cpu(ohdr->bth[1]);
  423. /* Call appropriate CNP handler */
  424. if (do_cnp && (bth1 & IB_FECN_SMASK))
  425. hfi1_handle_cnp_tbl[hdr_type](ibp, qp, rqpn, pkey,
  426. dlid, rlid, sc, grh);
  427. if (!is_mcast && (bth1 & IB_BECN_SMASK)) {
  428. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  429. u32 lqpn = bth1 & RVT_QPN_MASK;
  430. u8 sl = ibp->sc_to_sl[sc];
  431. process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type);
  432. }
  433. }
  434. struct ps_mdata {
  435. struct hfi1_ctxtdata *rcd;
  436. u32 rsize;
  437. u32 maxcnt;
  438. u32 ps_head;
  439. u32 ps_tail;
  440. u32 ps_seq;
  441. };
  442. static inline void init_ps_mdata(struct ps_mdata *mdata,
  443. struct hfi1_packet *packet)
  444. {
  445. struct hfi1_ctxtdata *rcd = packet->rcd;
  446. mdata->rcd = rcd;
  447. mdata->rsize = packet->rsize;
  448. mdata->maxcnt = packet->maxcnt;
  449. mdata->ps_head = packet->rhqoff;
  450. if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
  451. mdata->ps_tail = get_rcvhdrtail(rcd);
  452. if (rcd->ctxt == HFI1_CTRL_CTXT)
  453. mdata->ps_seq = rcd->seq_cnt;
  454. else
  455. mdata->ps_seq = 0; /* not used with DMA_RTAIL */
  456. } else {
  457. mdata->ps_tail = 0; /* used only with DMA_RTAIL*/
  458. mdata->ps_seq = rcd->seq_cnt;
  459. }
  460. }
  461. static inline int ps_done(struct ps_mdata *mdata, u64 rhf,
  462. struct hfi1_ctxtdata *rcd)
  463. {
  464. if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
  465. return mdata->ps_head == mdata->ps_tail;
  466. return mdata->ps_seq != rhf_rcv_seq(rhf);
  467. }
  468. static inline int ps_skip(struct ps_mdata *mdata, u64 rhf,
  469. struct hfi1_ctxtdata *rcd)
  470. {
  471. /*
  472. * Control context can potentially receive an invalid rhf.
  473. * Drop such packets.
  474. */
  475. if ((rcd->ctxt == HFI1_CTRL_CTXT) && (mdata->ps_head != mdata->ps_tail))
  476. return mdata->ps_seq != rhf_rcv_seq(rhf);
  477. return 0;
  478. }
  479. static inline void update_ps_mdata(struct ps_mdata *mdata,
  480. struct hfi1_ctxtdata *rcd)
  481. {
  482. mdata->ps_head += mdata->rsize;
  483. if (mdata->ps_head >= mdata->maxcnt)
  484. mdata->ps_head = 0;
  485. /* Control context must do seq counting */
  486. if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ||
  487. (rcd->ctxt == HFI1_CTRL_CTXT)) {
  488. if (++mdata->ps_seq > 13)
  489. mdata->ps_seq = 1;
  490. }
  491. }
  492. /*
  493. * prescan_rxq - search through the receive queue looking for packets
  494. * containing Excplicit Congestion Notifications (FECNs, or BECNs).
  495. * When an ECN is found, process the Congestion Notification, and toggle
  496. * it off.
  497. * This is declared as a macro to allow quick checking of the port to avoid
  498. * the overhead of a function call if not enabled.
  499. */
  500. #define prescan_rxq(rcd, packet) \
  501. do { \
  502. if (rcd->ppd->cc_prescan) \
  503. __prescan_rxq(packet); \
  504. } while (0)
  505. static void __prescan_rxq(struct hfi1_packet *packet)
  506. {
  507. struct hfi1_ctxtdata *rcd = packet->rcd;
  508. struct ps_mdata mdata;
  509. init_ps_mdata(&mdata, packet);
  510. while (1) {
  511. struct hfi1_devdata *dd = rcd->dd;
  512. struct hfi1_ibport *ibp = rcd_to_iport(rcd);
  513. __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head +
  514. dd->rhf_offset;
  515. struct rvt_qp *qp;
  516. struct ib_header *hdr;
  517. struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
  518. u64 rhf = rhf_to_cpu(rhf_addr);
  519. u32 etype = rhf_rcv_type(rhf), qpn, bth1;
  520. int is_ecn = 0;
  521. u8 lnh;
  522. if (ps_done(&mdata, rhf, rcd))
  523. break;
  524. if (ps_skip(&mdata, rhf, rcd))
  525. goto next;
  526. if (etype != RHF_RCV_TYPE_IB)
  527. goto next;
  528. packet->hdr = hfi1_get_msgheader(dd, rhf_addr);
  529. hdr = packet->hdr;
  530. lnh = ib_get_lnh(hdr);
  531. if (lnh == HFI1_LRH_BTH) {
  532. packet->ohdr = &hdr->u.oth;
  533. packet->grh = NULL;
  534. } else if (lnh == HFI1_LRH_GRH) {
  535. packet->ohdr = &hdr->u.l.oth;
  536. packet->grh = &hdr->u.l.grh;
  537. } else {
  538. goto next; /* just in case */
  539. }
  540. bth1 = be32_to_cpu(packet->ohdr->bth[1]);
  541. is_ecn = !!(bth1 & (IB_FECN_SMASK | IB_BECN_SMASK));
  542. if (!is_ecn)
  543. goto next;
  544. qpn = bth1 & RVT_QPN_MASK;
  545. rcu_read_lock();
  546. qp = rvt_lookup_qpn(rdi, &ibp->rvp, qpn);
  547. if (!qp) {
  548. rcu_read_unlock();
  549. goto next;
  550. }
  551. process_ecn(qp, packet, true);
  552. rcu_read_unlock();
  553. /* turn off BECN, FECN */
  554. bth1 &= ~(IB_FECN_SMASK | IB_BECN_SMASK);
  555. packet->ohdr->bth[1] = cpu_to_be32(bth1);
  556. next:
  557. update_ps_mdata(&mdata, rcd);
  558. }
  559. }
  560. static void process_rcv_qp_work(struct hfi1_ctxtdata *rcd)
  561. {
  562. struct rvt_qp *qp, *nqp;
  563. /*
  564. * Iterate over all QPs waiting to respond.
  565. * The list won't change since the IRQ is only run on one CPU.
  566. */
  567. list_for_each_entry_safe(qp, nqp, &rcd->qp_wait_list, rspwait) {
  568. list_del_init(&qp->rspwait);
  569. if (qp->r_flags & RVT_R_RSP_NAK) {
  570. qp->r_flags &= ~RVT_R_RSP_NAK;
  571. hfi1_send_rc_ack(rcd, qp, 0);
  572. }
  573. if (qp->r_flags & RVT_R_RSP_SEND) {
  574. unsigned long flags;
  575. qp->r_flags &= ~RVT_R_RSP_SEND;
  576. spin_lock_irqsave(&qp->s_lock, flags);
  577. if (ib_rvt_state_ops[qp->state] &
  578. RVT_PROCESS_OR_FLUSH_SEND)
  579. hfi1_schedule_send(qp);
  580. spin_unlock_irqrestore(&qp->s_lock, flags);
  581. }
  582. rvt_put_qp(qp);
  583. }
  584. }
  585. static noinline int max_packet_exceeded(struct hfi1_packet *packet, int thread)
  586. {
  587. if (thread) {
  588. if ((packet->numpkt & (MAX_PKT_RECV_THREAD - 1)) == 0)
  589. /* allow defered processing */
  590. process_rcv_qp_work(packet->rcd);
  591. cond_resched();
  592. return RCV_PKT_OK;
  593. } else {
  594. this_cpu_inc(*packet->rcd->dd->rcv_limit);
  595. return RCV_PKT_LIMIT;
  596. }
  597. }
  598. static inline int check_max_packet(struct hfi1_packet *packet, int thread)
  599. {
  600. int ret = RCV_PKT_OK;
  601. if (unlikely((packet->numpkt & (MAX_PKT_RECV - 1)) == 0))
  602. ret = max_packet_exceeded(packet, thread);
  603. return ret;
  604. }
  605. static noinline int skip_rcv_packet(struct hfi1_packet *packet, int thread)
  606. {
  607. int ret;
  608. /* Set up for the next packet */
  609. packet->rhqoff += packet->rsize;
  610. if (packet->rhqoff >= packet->maxcnt)
  611. packet->rhqoff = 0;
  612. packet->numpkt++;
  613. ret = check_max_packet(packet, thread);
  614. packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff +
  615. packet->rcd->dd->rhf_offset;
  616. packet->rhf = rhf_to_cpu(packet->rhf_addr);
  617. return ret;
  618. }
  619. static inline int process_rcv_packet(struct hfi1_packet *packet, int thread)
  620. {
  621. int ret;
  622. packet->etype = rhf_rcv_type(packet->rhf);
  623. /* total length */
  624. packet->tlen = rhf_pkt_len(packet->rhf); /* in bytes */
  625. /* retrieve eager buffer details */
  626. packet->ebuf = NULL;
  627. if (rhf_use_egr_bfr(packet->rhf)) {
  628. packet->etail = rhf_egr_index(packet->rhf);
  629. packet->ebuf = get_egrbuf(packet->rcd, packet->rhf,
  630. &packet->updegr);
  631. /*
  632. * Prefetch the contents of the eager buffer. It is
  633. * OK to send a negative length to prefetch_range().
  634. * The +2 is the size of the RHF.
  635. */
  636. prefetch_range(packet->ebuf,
  637. packet->tlen - ((packet->rcd->rcvhdrqentsize -
  638. (rhf_hdrq_offset(packet->rhf)
  639. + 2)) * 4));
  640. }
  641. /*
  642. * Call a type specific handler for the packet. We
  643. * should be able to trust that etype won't be beyond
  644. * the range of valid indexes. If so something is really
  645. * wrong and we can probably just let things come
  646. * crashing down. There is no need to eat another
  647. * comparison in this performance critical code.
  648. */
  649. packet->rcd->dd->rhf_rcv_function_map[packet->etype](packet);
  650. packet->numpkt++;
  651. /* Set up for the next packet */
  652. packet->rhqoff += packet->rsize;
  653. if (packet->rhqoff >= packet->maxcnt)
  654. packet->rhqoff = 0;
  655. ret = check_max_packet(packet, thread);
  656. packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff +
  657. packet->rcd->dd->rhf_offset;
  658. packet->rhf = rhf_to_cpu(packet->rhf_addr);
  659. return ret;
  660. }
  661. static inline void process_rcv_update(int last, struct hfi1_packet *packet)
  662. {
  663. /*
  664. * Update head regs etc., every 16 packets, if not last pkt,
  665. * to help prevent rcvhdrq overflows, when many packets
  666. * are processed and queue is nearly full.
  667. * Don't request an interrupt for intermediate updates.
  668. */
  669. if (!last && !(packet->numpkt & 0xf)) {
  670. update_usrhead(packet->rcd, packet->rhqoff, packet->updegr,
  671. packet->etail, 0, 0);
  672. packet->updegr = 0;
  673. }
  674. packet->grh = NULL;
  675. }
  676. static inline void finish_packet(struct hfi1_packet *packet)
  677. {
  678. /*
  679. * Nothing we need to free for the packet.
  680. *
  681. * The only thing we need to do is a final update and call for an
  682. * interrupt
  683. */
  684. update_usrhead(packet->rcd, packet->rcd->head, packet->updegr,
  685. packet->etail, rcv_intr_dynamic, packet->numpkt);
  686. }
  687. /*
  688. * Handle receive interrupts when using the no dma rtail option.
  689. */
  690. int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread)
  691. {
  692. u32 seq;
  693. int last = RCV_PKT_OK;
  694. struct hfi1_packet packet;
  695. init_packet(rcd, &packet);
  696. seq = rhf_rcv_seq(packet.rhf);
  697. if (seq != rcd->seq_cnt) {
  698. last = RCV_PKT_DONE;
  699. goto bail;
  700. }
  701. prescan_rxq(rcd, &packet);
  702. while (last == RCV_PKT_OK) {
  703. last = process_rcv_packet(&packet, thread);
  704. seq = rhf_rcv_seq(packet.rhf);
  705. if (++rcd->seq_cnt > 13)
  706. rcd->seq_cnt = 1;
  707. if (seq != rcd->seq_cnt)
  708. last = RCV_PKT_DONE;
  709. process_rcv_update(last, &packet);
  710. }
  711. process_rcv_qp_work(rcd);
  712. rcd->head = packet.rhqoff;
  713. bail:
  714. finish_packet(&packet);
  715. return last;
  716. }
  717. int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread)
  718. {
  719. u32 hdrqtail;
  720. int last = RCV_PKT_OK;
  721. struct hfi1_packet packet;
  722. init_packet(rcd, &packet);
  723. hdrqtail = get_rcvhdrtail(rcd);
  724. if (packet.rhqoff == hdrqtail) {
  725. last = RCV_PKT_DONE;
  726. goto bail;
  727. }
  728. smp_rmb(); /* prevent speculative reads of dma'ed hdrq */
  729. prescan_rxq(rcd, &packet);
  730. while (last == RCV_PKT_OK) {
  731. last = process_rcv_packet(&packet, thread);
  732. if (packet.rhqoff == hdrqtail)
  733. last = RCV_PKT_DONE;
  734. process_rcv_update(last, &packet);
  735. }
  736. process_rcv_qp_work(rcd);
  737. rcd->head = packet.rhqoff;
  738. bail:
  739. finish_packet(&packet);
  740. return last;
  741. }
  742. static inline void set_nodma_rtail(struct hfi1_devdata *dd, u16 ctxt)
  743. {
  744. struct hfi1_ctxtdata *rcd;
  745. u16 i;
  746. /*
  747. * For dynamically allocated kernel contexts (like vnic) switch
  748. * interrupt handler only for that context. Otherwise, switch
  749. * interrupt handler for all statically allocated kernel contexts.
  750. */
  751. if (ctxt >= dd->first_dyn_alloc_ctxt) {
  752. rcd = hfi1_rcd_get_by_index(dd, ctxt);
  753. if (rcd) {
  754. rcd->do_interrupt =
  755. &handle_receive_interrupt_nodma_rtail;
  756. hfi1_rcd_put(rcd);
  757. }
  758. return;
  759. }
  760. for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) {
  761. rcd = hfi1_rcd_get_by_index(dd, i);
  762. if (rcd)
  763. rcd->do_interrupt =
  764. &handle_receive_interrupt_nodma_rtail;
  765. hfi1_rcd_put(rcd);
  766. }
  767. }
  768. static inline void set_dma_rtail(struct hfi1_devdata *dd, u16 ctxt)
  769. {
  770. struct hfi1_ctxtdata *rcd;
  771. u16 i;
  772. /*
  773. * For dynamically allocated kernel contexts (like vnic) switch
  774. * interrupt handler only for that context. Otherwise, switch
  775. * interrupt handler for all statically allocated kernel contexts.
  776. */
  777. if (ctxt >= dd->first_dyn_alloc_ctxt) {
  778. rcd = hfi1_rcd_get_by_index(dd, ctxt);
  779. if (rcd) {
  780. rcd->do_interrupt =
  781. &handle_receive_interrupt_dma_rtail;
  782. hfi1_rcd_put(rcd);
  783. }
  784. return;
  785. }
  786. for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) {
  787. rcd = hfi1_rcd_get_by_index(dd, i);
  788. if (rcd)
  789. rcd->do_interrupt =
  790. &handle_receive_interrupt_dma_rtail;
  791. hfi1_rcd_put(rcd);
  792. }
  793. }
  794. void set_all_slowpath(struct hfi1_devdata *dd)
  795. {
  796. struct hfi1_ctxtdata *rcd;
  797. u16 i;
  798. /* HFI1_CTRL_CTXT must always use the slow path interrupt handler */
  799. for (i = HFI1_CTRL_CTXT + 1; i < dd->num_rcv_contexts; i++) {
  800. rcd = hfi1_rcd_get_by_index(dd, i);
  801. if (!rcd)
  802. continue;
  803. if ((i < dd->first_dyn_alloc_ctxt) ||
  804. (rcd->sc && (rcd->sc->type == SC_KERNEL))) {
  805. rcd->do_interrupt = &handle_receive_interrupt;
  806. }
  807. hfi1_rcd_put(rcd);
  808. }
  809. }
  810. static inline int set_armed_to_active(struct hfi1_ctxtdata *rcd,
  811. struct hfi1_packet *packet,
  812. struct hfi1_devdata *dd)
  813. {
  814. struct work_struct *lsaw = &rcd->ppd->linkstate_active_work;
  815. u8 etype = rhf_rcv_type(packet->rhf);
  816. u8 sc = SC15_PACKET;
  817. if (etype == RHF_RCV_TYPE_IB) {
  818. struct ib_header *hdr = hfi1_get_msgheader(packet->rcd->dd,
  819. packet->rhf_addr);
  820. sc = hfi1_9B_get_sc5(hdr, packet->rhf);
  821. } else if (etype == RHF_RCV_TYPE_BYPASS) {
  822. struct hfi1_16b_header *hdr = hfi1_get_16B_header(
  823. packet->rcd->dd,
  824. packet->rhf_addr);
  825. sc = hfi1_16B_get_sc(hdr);
  826. }
  827. if (sc != SC15_PACKET) {
  828. int hwstate = driver_lstate(rcd->ppd);
  829. if (hwstate != IB_PORT_ACTIVE) {
  830. dd_dev_info(dd,
  831. "Unexpected link state %s\n",
  832. opa_lstate_name(hwstate));
  833. return 0;
  834. }
  835. queue_work(rcd->ppd->link_wq, lsaw);
  836. return 1;
  837. }
  838. return 0;
  839. }
  840. /*
  841. * handle_receive_interrupt - receive a packet
  842. * @rcd: the context
  843. *
  844. * Called from interrupt handler for errors or receive interrupt.
  845. * This is the slow path interrupt handler.
  846. */
  847. int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
  848. {
  849. struct hfi1_devdata *dd = rcd->dd;
  850. u32 hdrqtail;
  851. int needset, last = RCV_PKT_OK;
  852. struct hfi1_packet packet;
  853. int skip_pkt = 0;
  854. /* Control context will always use the slow path interrupt handler */
  855. needset = (rcd->ctxt == HFI1_CTRL_CTXT) ? 0 : 1;
  856. init_packet(rcd, &packet);
  857. if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
  858. u32 seq = rhf_rcv_seq(packet.rhf);
  859. if (seq != rcd->seq_cnt) {
  860. last = RCV_PKT_DONE;
  861. goto bail;
  862. }
  863. hdrqtail = 0;
  864. } else {
  865. hdrqtail = get_rcvhdrtail(rcd);
  866. if (packet.rhqoff == hdrqtail) {
  867. last = RCV_PKT_DONE;
  868. goto bail;
  869. }
  870. smp_rmb(); /* prevent speculative reads of dma'ed hdrq */
  871. /*
  872. * Control context can potentially receive an invalid
  873. * rhf. Drop such packets.
  874. */
  875. if (rcd->ctxt == HFI1_CTRL_CTXT) {
  876. u32 seq = rhf_rcv_seq(packet.rhf);
  877. if (seq != rcd->seq_cnt)
  878. skip_pkt = 1;
  879. }
  880. }
  881. prescan_rxq(rcd, &packet);
  882. while (last == RCV_PKT_OK) {
  883. if (unlikely(dd->do_drop &&
  884. atomic_xchg(&dd->drop_packet, DROP_PACKET_OFF) ==
  885. DROP_PACKET_ON)) {
  886. dd->do_drop = 0;
  887. /* On to the next packet */
  888. packet.rhqoff += packet.rsize;
  889. packet.rhf_addr = (__le32 *)rcd->rcvhdrq +
  890. packet.rhqoff +
  891. dd->rhf_offset;
  892. packet.rhf = rhf_to_cpu(packet.rhf_addr);
  893. } else if (skip_pkt) {
  894. last = skip_rcv_packet(&packet, thread);
  895. skip_pkt = 0;
  896. } else {
  897. /* Auto activate link on non-SC15 packet receive */
  898. if (unlikely(rcd->ppd->host_link_state ==
  899. HLS_UP_ARMED) &&
  900. set_armed_to_active(rcd, &packet, dd))
  901. goto bail;
  902. last = process_rcv_packet(&packet, thread);
  903. }
  904. if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
  905. u32 seq = rhf_rcv_seq(packet.rhf);
  906. if (++rcd->seq_cnt > 13)
  907. rcd->seq_cnt = 1;
  908. if (seq != rcd->seq_cnt)
  909. last = RCV_PKT_DONE;
  910. if (needset) {
  911. dd_dev_info(dd, "Switching to NO_DMA_RTAIL\n");
  912. set_nodma_rtail(dd, rcd->ctxt);
  913. needset = 0;
  914. }
  915. } else {
  916. if (packet.rhqoff == hdrqtail)
  917. last = RCV_PKT_DONE;
  918. /*
  919. * Control context can potentially receive an invalid
  920. * rhf. Drop such packets.
  921. */
  922. if (rcd->ctxt == HFI1_CTRL_CTXT) {
  923. u32 seq = rhf_rcv_seq(packet.rhf);
  924. if (++rcd->seq_cnt > 13)
  925. rcd->seq_cnt = 1;
  926. if (!last && (seq != rcd->seq_cnt))
  927. skip_pkt = 1;
  928. }
  929. if (needset) {
  930. dd_dev_info(dd,
  931. "Switching to DMA_RTAIL\n");
  932. set_dma_rtail(dd, rcd->ctxt);
  933. needset = 0;
  934. }
  935. }
  936. process_rcv_update(last, &packet);
  937. }
  938. process_rcv_qp_work(rcd);
  939. rcd->head = packet.rhqoff;
  940. bail:
  941. /*
  942. * Always write head at end, and setup rcv interrupt, even
  943. * if no packets were processed.
  944. */
  945. finish_packet(&packet);
  946. return last;
  947. }
  948. /*
  949. * We may discover in the interrupt that the hardware link state has
  950. * changed from ARMED to ACTIVE (due to the arrival of a non-SC15 packet),
  951. * and we need to update the driver's notion of the link state. We cannot
  952. * run set_link_state from interrupt context, so we queue this function on
  953. * a workqueue.
  954. *
  955. * We delay the regular interrupt processing until after the state changes
  956. * so that the link will be in the correct state by the time any application
  957. * we wake up attempts to send a reply to any message it received.
  958. * (Subsequent receive interrupts may possibly force the wakeup before we
  959. * update the link state.)
  960. *
  961. * The rcd is freed in hfi1_free_ctxtdata after hfi1_postinit_cleanup invokes
  962. * dd->f_cleanup(dd) to disable the interrupt handler and flush workqueues,
  963. * so we're safe from use-after-free of the rcd.
  964. */
  965. void receive_interrupt_work(struct work_struct *work)
  966. {
  967. struct hfi1_pportdata *ppd = container_of(work, struct hfi1_pportdata,
  968. linkstate_active_work);
  969. struct hfi1_devdata *dd = ppd->dd;
  970. struct hfi1_ctxtdata *rcd;
  971. u16 i;
  972. /* Received non-SC15 packet implies neighbor_normal */
  973. ppd->neighbor_normal = 1;
  974. set_link_state(ppd, HLS_UP_ACTIVE);
  975. /*
  976. * Interrupt all statically allocated kernel contexts that could
  977. * have had an interrupt during auto activation.
  978. */
  979. for (i = HFI1_CTRL_CTXT; i < dd->first_dyn_alloc_ctxt; i++) {
  980. rcd = hfi1_rcd_get_by_index(dd, i);
  981. if (rcd)
  982. force_recv_intr(rcd);
  983. hfi1_rcd_put(rcd);
  984. }
  985. }
  986. /*
  987. * Convert a given MTU size to the on-wire MAD packet enumeration.
  988. * Return -1 if the size is invalid.
  989. */
  990. int mtu_to_enum(u32 mtu, int default_if_bad)
  991. {
  992. switch (mtu) {
  993. case 0: return OPA_MTU_0;
  994. case 256: return OPA_MTU_256;
  995. case 512: return OPA_MTU_512;
  996. case 1024: return OPA_MTU_1024;
  997. case 2048: return OPA_MTU_2048;
  998. case 4096: return OPA_MTU_4096;
  999. case 8192: return OPA_MTU_8192;
  1000. case 10240: return OPA_MTU_10240;
  1001. }
  1002. return default_if_bad;
  1003. }
  1004. u16 enum_to_mtu(int mtu)
  1005. {
  1006. switch (mtu) {
  1007. case OPA_MTU_0: return 0;
  1008. case OPA_MTU_256: return 256;
  1009. case OPA_MTU_512: return 512;
  1010. case OPA_MTU_1024: return 1024;
  1011. case OPA_MTU_2048: return 2048;
  1012. case OPA_MTU_4096: return 4096;
  1013. case OPA_MTU_8192: return 8192;
  1014. case OPA_MTU_10240: return 10240;
  1015. default: return 0xffff;
  1016. }
  1017. }
  1018. /*
  1019. * set_mtu - set the MTU
  1020. * @ppd: the per port data
  1021. *
  1022. * We can handle "any" incoming size, the issue here is whether we
  1023. * need to restrict our outgoing size. We do not deal with what happens
  1024. * to programs that are already running when the size changes.
  1025. */
  1026. int set_mtu(struct hfi1_pportdata *ppd)
  1027. {
  1028. struct hfi1_devdata *dd = ppd->dd;
  1029. int i, drain, ret = 0, is_up = 0;
  1030. ppd->ibmtu = 0;
  1031. for (i = 0; i < ppd->vls_supported; i++)
  1032. if (ppd->ibmtu < dd->vld[i].mtu)
  1033. ppd->ibmtu = dd->vld[i].mtu;
  1034. ppd->ibmaxlen = ppd->ibmtu + lrh_max_header_bytes(ppd->dd);
  1035. mutex_lock(&ppd->hls_lock);
  1036. if (ppd->host_link_state == HLS_UP_INIT ||
  1037. ppd->host_link_state == HLS_UP_ARMED ||
  1038. ppd->host_link_state == HLS_UP_ACTIVE)
  1039. is_up = 1;
  1040. drain = !is_ax(dd) && is_up;
  1041. if (drain)
  1042. /*
  1043. * MTU is specified per-VL. To ensure that no packet gets
  1044. * stuck (due, e.g., to the MTU for the packet's VL being
  1045. * reduced), empty the per-VL FIFOs before adjusting MTU.
  1046. */
  1047. ret = stop_drain_data_vls(dd);
  1048. if (ret) {
  1049. dd_dev_err(dd, "%s: cannot stop/drain VLs - refusing to change per-VL MTUs\n",
  1050. __func__);
  1051. goto err;
  1052. }
  1053. hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_MTU, 0);
  1054. if (drain)
  1055. open_fill_data_vls(dd); /* reopen all VLs */
  1056. err:
  1057. mutex_unlock(&ppd->hls_lock);
  1058. return ret;
  1059. }
  1060. int hfi1_set_lid(struct hfi1_pportdata *ppd, u32 lid, u8 lmc)
  1061. {
  1062. struct hfi1_devdata *dd = ppd->dd;
  1063. ppd->lid = lid;
  1064. ppd->lmc = lmc;
  1065. hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LIDLMC, 0);
  1066. dd_dev_info(dd, "port %u: got a lid: 0x%x\n", ppd->port, lid);
  1067. return 0;
  1068. }
  1069. void shutdown_led_override(struct hfi1_pportdata *ppd)
  1070. {
  1071. struct hfi1_devdata *dd = ppd->dd;
  1072. /*
  1073. * This pairs with the memory barrier in hfi1_start_led_override to
  1074. * ensure that we read the correct state of LED beaconing represented
  1075. * by led_override_timer_active
  1076. */
  1077. smp_rmb();
  1078. if (atomic_read(&ppd->led_override_timer_active)) {
  1079. del_timer_sync(&ppd->led_override_timer);
  1080. atomic_set(&ppd->led_override_timer_active, 0);
  1081. /* Ensure the atomic_set is visible to all CPUs */
  1082. smp_wmb();
  1083. }
  1084. /* Hand control of the LED to the DC for normal operation */
  1085. write_csr(dd, DCC_CFG_LED_CNTRL, 0);
  1086. }
  1087. static void run_led_override(unsigned long opaque)
  1088. {
  1089. struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)opaque;
  1090. struct hfi1_devdata *dd = ppd->dd;
  1091. unsigned long timeout;
  1092. int phase_idx;
  1093. if (!(dd->flags & HFI1_INITTED))
  1094. return;
  1095. phase_idx = ppd->led_override_phase & 1;
  1096. setextled(dd, phase_idx);
  1097. timeout = ppd->led_override_vals[phase_idx];
  1098. /* Set up for next phase */
  1099. ppd->led_override_phase = !ppd->led_override_phase;
  1100. mod_timer(&ppd->led_override_timer, jiffies + timeout);
  1101. }
  1102. /*
  1103. * To have the LED blink in a particular pattern, provide timeon and timeoff
  1104. * in milliseconds.
  1105. * To turn off custom blinking and return to normal operation, use
  1106. * shutdown_led_override()
  1107. */
  1108. void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon,
  1109. unsigned int timeoff)
  1110. {
  1111. if (!(ppd->dd->flags & HFI1_INITTED))
  1112. return;
  1113. /* Convert to jiffies for direct use in timer */
  1114. ppd->led_override_vals[0] = msecs_to_jiffies(timeoff);
  1115. ppd->led_override_vals[1] = msecs_to_jiffies(timeon);
  1116. /* Arbitrarily start from LED on phase */
  1117. ppd->led_override_phase = 1;
  1118. /*
  1119. * If the timer has not already been started, do so. Use a "quick"
  1120. * timeout so the handler will be called soon to look at our request.
  1121. */
  1122. if (!timer_pending(&ppd->led_override_timer)) {
  1123. setup_timer(&ppd->led_override_timer, run_led_override,
  1124. (unsigned long)ppd);
  1125. ppd->led_override_timer.expires = jiffies + 1;
  1126. add_timer(&ppd->led_override_timer);
  1127. atomic_set(&ppd->led_override_timer_active, 1);
  1128. /* Ensure the atomic_set is visible to all CPUs */
  1129. smp_wmb();
  1130. }
  1131. }
  1132. /**
  1133. * hfi1_reset_device - reset the chip if possible
  1134. * @unit: the device to reset
  1135. *
  1136. * Whether or not reset is successful, we attempt to re-initialize the chip
  1137. * (that is, much like a driver unload/reload). We clear the INITTED flag
  1138. * so that the various entry points will fail until we reinitialize. For
  1139. * now, we only allow this if no user contexts are open that use chip resources
  1140. */
  1141. int hfi1_reset_device(int unit)
  1142. {
  1143. int ret;
  1144. struct hfi1_devdata *dd = hfi1_lookup(unit);
  1145. struct hfi1_pportdata *ppd;
  1146. int pidx;
  1147. if (!dd) {
  1148. ret = -ENODEV;
  1149. goto bail;
  1150. }
  1151. dd_dev_info(dd, "Reset on unit %u requested\n", unit);
  1152. if (!dd->kregbase1 || !(dd->flags & HFI1_PRESENT)) {
  1153. dd_dev_info(dd,
  1154. "Invalid unit number %u or not initialized or not present\n",
  1155. unit);
  1156. ret = -ENXIO;
  1157. goto bail;
  1158. }
  1159. /* If there are any user/vnic contexts, we cannot reset */
  1160. mutex_lock(&hfi1_mutex);
  1161. if (dd->rcd)
  1162. if (hfi1_stats.sps_ctxts) {
  1163. mutex_unlock(&hfi1_mutex);
  1164. ret = -EBUSY;
  1165. goto bail;
  1166. }
  1167. mutex_unlock(&hfi1_mutex);
  1168. for (pidx = 0; pidx < dd->num_pports; ++pidx) {
  1169. ppd = dd->pport + pidx;
  1170. shutdown_led_override(ppd);
  1171. }
  1172. if (dd->flags & HFI1_HAS_SEND_DMA)
  1173. sdma_exit(dd);
  1174. hfi1_reset_cpu_counters(dd);
  1175. ret = hfi1_init(dd, 1);
  1176. if (ret)
  1177. dd_dev_err(dd,
  1178. "Reinitialize unit %u after reset failed with %d\n",
  1179. unit, ret);
  1180. else
  1181. dd_dev_info(dd, "Reinitialized unit %u after resetting\n",
  1182. unit);
  1183. bail:
  1184. return ret;
  1185. }
  1186. static inline void hfi1_setup_ib_header(struct hfi1_packet *packet)
  1187. {
  1188. packet->hdr = (struct hfi1_ib_message_header *)
  1189. hfi1_get_msgheader(packet->rcd->dd,
  1190. packet->rhf_addr);
  1191. packet->hlen = (u8 *)packet->rhf_addr - (u8 *)packet->hdr;
  1192. }
  1193. static int hfi1_bypass_ingress_pkt_check(struct hfi1_packet *packet)
  1194. {
  1195. struct hfi1_pportdata *ppd = packet->rcd->ppd;
  1196. /* slid and dlid cannot be 0 */
  1197. if ((!packet->slid) || (!packet->dlid))
  1198. return -EINVAL;
  1199. /* Compare port lid with incoming packet dlid */
  1200. if ((!(hfi1_is_16B_mcast(packet->dlid))) &&
  1201. (packet->dlid !=
  1202. opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B))) {
  1203. if (packet->dlid != ppd->lid)
  1204. return -EINVAL;
  1205. }
  1206. /* No multicast packets with SC15 */
  1207. if ((hfi1_is_16B_mcast(packet->dlid)) && (packet->sc == 0xF))
  1208. return -EINVAL;
  1209. /* Packets with permissive DLID always on SC15 */
  1210. if ((packet->dlid == opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE),
  1211. 16B)) &&
  1212. (packet->sc != 0xF))
  1213. return -EINVAL;
  1214. return 0;
  1215. }
  1216. static int hfi1_setup_9B_packet(struct hfi1_packet *packet)
  1217. {
  1218. struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd);
  1219. struct ib_header *hdr;
  1220. u8 lnh;
  1221. hfi1_setup_ib_header(packet);
  1222. hdr = packet->hdr;
  1223. lnh = ib_get_lnh(hdr);
  1224. if (lnh == HFI1_LRH_BTH) {
  1225. packet->ohdr = &hdr->u.oth;
  1226. packet->grh = NULL;
  1227. } else if (lnh == HFI1_LRH_GRH) {
  1228. u32 vtf;
  1229. packet->ohdr = &hdr->u.l.oth;
  1230. packet->grh = &hdr->u.l.grh;
  1231. if (packet->grh->next_hdr != IB_GRH_NEXT_HDR)
  1232. goto drop;
  1233. vtf = be32_to_cpu(packet->grh->version_tclass_flow);
  1234. if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
  1235. goto drop;
  1236. } else {
  1237. goto drop;
  1238. }
  1239. /* Query commonly used fields from packet header */
  1240. packet->payload = packet->ebuf;
  1241. packet->opcode = ib_bth_get_opcode(packet->ohdr);
  1242. packet->slid = ib_get_slid(hdr);
  1243. packet->dlid = ib_get_dlid(hdr);
  1244. if (unlikely((packet->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
  1245. (packet->dlid != be16_to_cpu(IB_LID_PERMISSIVE))))
  1246. packet->dlid += opa_get_mcast_base(OPA_MCAST_NR) -
  1247. be16_to_cpu(IB_MULTICAST_LID_BASE);
  1248. packet->sl = ib_get_sl(hdr);
  1249. packet->sc = hfi1_9B_get_sc5(hdr, packet->rhf);
  1250. packet->pad = ib_bth_get_pad(packet->ohdr);
  1251. packet->extra_byte = 0;
  1252. packet->fecn = ib_bth_get_fecn(packet->ohdr);
  1253. packet->becn = ib_bth_get_becn(packet->ohdr);
  1254. return 0;
  1255. drop:
  1256. ibp->rvp.n_pkt_drops++;
  1257. return -EINVAL;
  1258. }
  1259. static int hfi1_setup_bypass_packet(struct hfi1_packet *packet)
  1260. {
  1261. /*
  1262. * Bypass packets have a different header/payload split
  1263. * compared to an IB packet.
  1264. * Current split is set such that 16 bytes of the actual
  1265. * header is in the header buffer and the remining is in
  1266. * the eager buffer. We chose 16 since hfi1 driver only
  1267. * supports 16B bypass packets and we will be able to
  1268. * receive the entire LRH with such a split.
  1269. */
  1270. struct hfi1_ctxtdata *rcd = packet->rcd;
  1271. struct hfi1_pportdata *ppd = rcd->ppd;
  1272. struct hfi1_ibport *ibp = &ppd->ibport_data;
  1273. u8 l4;
  1274. u8 grh_len;
  1275. packet->hdr = (struct hfi1_16b_header *)
  1276. hfi1_get_16B_header(packet->rcd->dd,
  1277. packet->rhf_addr);
  1278. packet->hlen = (u8 *)packet->rhf_addr - (u8 *)packet->hdr;
  1279. l4 = hfi1_16B_get_l4(packet->hdr);
  1280. if (l4 == OPA_16B_L4_IB_LOCAL) {
  1281. grh_len = 0;
  1282. packet->ohdr = packet->ebuf;
  1283. packet->grh = NULL;
  1284. } else if (l4 == OPA_16B_L4_IB_GLOBAL) {
  1285. u32 vtf;
  1286. grh_len = sizeof(struct ib_grh);
  1287. packet->ohdr = packet->ebuf + grh_len;
  1288. packet->grh = packet->ebuf;
  1289. if (packet->grh->next_hdr != IB_GRH_NEXT_HDR)
  1290. goto drop;
  1291. vtf = be32_to_cpu(packet->grh->version_tclass_flow);
  1292. if ((vtf >> IB_GRH_VERSION_SHIFT) != IB_GRH_VERSION)
  1293. goto drop;
  1294. } else {
  1295. goto drop;
  1296. }
  1297. /* Query commonly used fields from packet header */
  1298. packet->opcode = ib_bth_get_opcode(packet->ohdr);
  1299. packet->hlen = hdr_len_by_opcode[packet->opcode] + 8 + grh_len;
  1300. packet->payload = packet->ebuf + packet->hlen - (4 * sizeof(u32));
  1301. packet->slid = hfi1_16B_get_slid(packet->hdr);
  1302. packet->dlid = hfi1_16B_get_dlid(packet->hdr);
  1303. if (unlikely(hfi1_is_16B_mcast(packet->dlid)))
  1304. packet->dlid += opa_get_mcast_base(OPA_MCAST_NR) -
  1305. opa_get_lid(opa_get_mcast_base(OPA_MCAST_NR),
  1306. 16B);
  1307. packet->sc = hfi1_16B_get_sc(packet->hdr);
  1308. packet->sl = ibp->sc_to_sl[packet->sc];
  1309. packet->pad = hfi1_16B_bth_get_pad(packet->ohdr);
  1310. packet->extra_byte = SIZE_OF_LT;
  1311. packet->fecn = hfi1_16B_get_fecn(packet->hdr);
  1312. packet->becn = hfi1_16B_get_becn(packet->hdr);
  1313. if (hfi1_bypass_ingress_pkt_check(packet))
  1314. goto drop;
  1315. return 0;
  1316. drop:
  1317. hfi1_cdbg(PKT, "%s: packet dropped\n", __func__);
  1318. ibp->rvp.n_pkt_drops++;
  1319. return -EINVAL;
  1320. }
  1321. void handle_eflags(struct hfi1_packet *packet)
  1322. {
  1323. struct hfi1_ctxtdata *rcd = packet->rcd;
  1324. u32 rte = rhf_rcv_type_err(packet->rhf);
  1325. rcv_hdrerr(rcd, rcd->ppd, packet);
  1326. if (rhf_err_flags(packet->rhf))
  1327. dd_dev_err(rcd->dd,
  1328. "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s%s] rte 0x%x\n",
  1329. rcd->ctxt, packet->rhf,
  1330. packet->rhf & RHF_K_HDR_LEN_ERR ? "k_hdr_len " : "",
  1331. packet->rhf & RHF_DC_UNC_ERR ? "dc_unc " : "",
  1332. packet->rhf & RHF_DC_ERR ? "dc " : "",
  1333. packet->rhf & RHF_TID_ERR ? "tid " : "",
  1334. packet->rhf & RHF_LEN_ERR ? "len " : "",
  1335. packet->rhf & RHF_ECC_ERR ? "ecc " : "",
  1336. packet->rhf & RHF_VCRC_ERR ? "vcrc " : "",
  1337. packet->rhf & RHF_ICRC_ERR ? "icrc " : "",
  1338. rte);
  1339. }
  1340. /*
  1341. * The following functions are called by the interrupt handler. They are type
  1342. * specific handlers for each packet type.
  1343. */
  1344. int process_receive_ib(struct hfi1_packet *packet)
  1345. {
  1346. if (unlikely(hfi1_dbg_fault_packet(packet)))
  1347. return RHF_RCV_CONTINUE;
  1348. if (hfi1_setup_9B_packet(packet))
  1349. return RHF_RCV_CONTINUE;
  1350. trace_hfi1_rcvhdr(packet->rcd->ppd->dd,
  1351. packet->rcd->ctxt,
  1352. rhf_err_flags(packet->rhf),
  1353. RHF_RCV_TYPE_IB,
  1354. packet->hlen,
  1355. packet->tlen,
  1356. packet->updegr,
  1357. rhf_egr_index(packet->rhf));
  1358. if (unlikely(
  1359. (hfi1_dbg_fault_suppress_err(&packet->rcd->dd->verbs_dev) &&
  1360. (packet->rhf & RHF_DC_ERR))))
  1361. return RHF_RCV_CONTINUE;
  1362. if (unlikely(rhf_err_flags(packet->rhf))) {
  1363. handle_eflags(packet);
  1364. return RHF_RCV_CONTINUE;
  1365. }
  1366. hfi1_ib_rcv(packet);
  1367. return RHF_RCV_CONTINUE;
  1368. }
  1369. static inline bool hfi1_is_vnic_packet(struct hfi1_packet *packet)
  1370. {
  1371. /* Packet received in VNIC context via RSM */
  1372. if (packet->rcd->is_vnic)
  1373. return true;
  1374. if ((hfi1_16B_get_l2(packet->ebuf) == OPA_16B_L2_TYPE) &&
  1375. (hfi1_16B_get_l4(packet->ebuf) == OPA_16B_L4_ETHR))
  1376. return true;
  1377. return false;
  1378. }
  1379. int process_receive_bypass(struct hfi1_packet *packet)
  1380. {
  1381. struct hfi1_devdata *dd = packet->rcd->dd;
  1382. if (hfi1_is_vnic_packet(packet)) {
  1383. hfi1_vnic_bypass_rcv(packet);
  1384. return RHF_RCV_CONTINUE;
  1385. }
  1386. if (hfi1_setup_bypass_packet(packet))
  1387. return RHF_RCV_CONTINUE;
  1388. if (unlikely(rhf_err_flags(packet->rhf))) {
  1389. handle_eflags(packet);
  1390. return RHF_RCV_CONTINUE;
  1391. }
  1392. if (hfi1_16B_get_l2(packet->hdr) == 0x2) {
  1393. hfi1_16B_rcv(packet);
  1394. } else {
  1395. dd_dev_err(dd,
  1396. "Bypass packets other than 16B are not supported in normal operation. Dropping\n");
  1397. incr_cntr64(&dd->sw_rcv_bypass_packet_errors);
  1398. if (!(dd->err_info_rcvport.status_and_code &
  1399. OPA_EI_STATUS_SMASK)) {
  1400. u64 *flits = packet->ebuf;
  1401. if (flits && !(packet->rhf & RHF_LEN_ERR)) {
  1402. dd->err_info_rcvport.packet_flit1 = flits[0];
  1403. dd->err_info_rcvport.packet_flit2 =
  1404. packet->tlen > sizeof(flits[0]) ?
  1405. flits[1] : 0;
  1406. }
  1407. dd->err_info_rcvport.status_and_code |=
  1408. (OPA_EI_STATUS_SMASK | BAD_L2_ERR);
  1409. }
  1410. }
  1411. return RHF_RCV_CONTINUE;
  1412. }
  1413. int process_receive_error(struct hfi1_packet *packet)
  1414. {
  1415. /* KHdrHCRCErr -- KDETH packet with a bad HCRC */
  1416. if (unlikely(
  1417. hfi1_dbg_fault_suppress_err(&packet->rcd->dd->verbs_dev) &&
  1418. rhf_rcv_type_err(packet->rhf) == 3))
  1419. return RHF_RCV_CONTINUE;
  1420. hfi1_setup_ib_header(packet);
  1421. handle_eflags(packet);
  1422. if (unlikely(rhf_err_flags(packet->rhf)))
  1423. dd_dev_err(packet->rcd->dd,
  1424. "Unhandled error packet received. Dropping.\n");
  1425. return RHF_RCV_CONTINUE;
  1426. }
  1427. int kdeth_process_expected(struct hfi1_packet *packet)
  1428. {
  1429. if (unlikely(hfi1_dbg_fault_packet(packet)))
  1430. return RHF_RCV_CONTINUE;
  1431. hfi1_setup_ib_header(packet);
  1432. if (unlikely(rhf_err_flags(packet->rhf)))
  1433. handle_eflags(packet);
  1434. dd_dev_err(packet->rcd->dd,
  1435. "Unhandled expected packet received. Dropping.\n");
  1436. return RHF_RCV_CONTINUE;
  1437. }
  1438. int kdeth_process_eager(struct hfi1_packet *packet)
  1439. {
  1440. hfi1_setup_ib_header(packet);
  1441. if (unlikely(rhf_err_flags(packet->rhf)))
  1442. handle_eflags(packet);
  1443. if (unlikely(hfi1_dbg_fault_packet(packet)))
  1444. return RHF_RCV_CONTINUE;
  1445. dd_dev_err(packet->rcd->dd,
  1446. "Unhandled eager packet received. Dropping.\n");
  1447. return RHF_RCV_CONTINUE;
  1448. }
  1449. int process_receive_invalid(struct hfi1_packet *packet)
  1450. {
  1451. dd_dev_err(packet->rcd->dd, "Invalid packet type %d. Dropping\n",
  1452. rhf_rcv_type(packet->rhf));
  1453. return RHF_RCV_CONTINUE;
  1454. }
  1455. void seqfile_dump_rcd(struct seq_file *s, struct hfi1_ctxtdata *rcd)
  1456. {
  1457. struct hfi1_packet packet;
  1458. struct ps_mdata mdata;
  1459. seq_printf(s, "Rcd %u: RcvHdr cnt %u entsize %u %s head %llu tail %llu\n",
  1460. rcd->ctxt, rcd->rcvhdrq_cnt, rcd->rcvhdrqentsize,
  1461. HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
  1462. "dma_rtail" : "nodma_rtail",
  1463. read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD) &
  1464. RCV_HDR_HEAD_HEAD_MASK,
  1465. read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL));
  1466. init_packet(rcd, &packet);
  1467. init_ps_mdata(&mdata, &packet);
  1468. while (1) {
  1469. struct hfi1_devdata *dd = rcd->dd;
  1470. __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head +
  1471. dd->rhf_offset;
  1472. struct ib_header *hdr;
  1473. u64 rhf = rhf_to_cpu(rhf_addr);
  1474. u32 etype = rhf_rcv_type(rhf), qpn;
  1475. u8 opcode;
  1476. u32 psn;
  1477. u8 lnh;
  1478. if (ps_done(&mdata, rhf, rcd))
  1479. break;
  1480. if (ps_skip(&mdata, rhf, rcd))
  1481. goto next;
  1482. if (etype > RHF_RCV_TYPE_IB)
  1483. goto next;
  1484. packet.hdr = hfi1_get_msgheader(dd, rhf_addr);
  1485. hdr = packet.hdr;
  1486. lnh = be16_to_cpu(hdr->lrh[0]) & 3;
  1487. if (lnh == HFI1_LRH_BTH)
  1488. packet.ohdr = &hdr->u.oth;
  1489. else if (lnh == HFI1_LRH_GRH)
  1490. packet.ohdr = &hdr->u.l.oth;
  1491. else
  1492. goto next; /* just in case */
  1493. opcode = (be32_to_cpu(packet.ohdr->bth[0]) >> 24);
  1494. qpn = be32_to_cpu(packet.ohdr->bth[1]) & RVT_QPN_MASK;
  1495. psn = mask_psn(be32_to_cpu(packet.ohdr->bth[2]));
  1496. seq_printf(s, "\tEnt %u: opcode 0x%x, qpn 0x%x, psn 0x%x\n",
  1497. mdata.ps_head, opcode, qpn, psn);
  1498. next:
  1499. update_ps_mdata(&mdata, rcd);
  1500. }
  1501. }