driver.c 45 KB

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