driver.c 47 KB

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