driver.c 49 KB

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