verbs.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  1. // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
  2. /*
  3. * Copyright(c) 2015 - 2020 Intel Corporation.
  4. */
  5. #include <rdma/ib_mad.h>
  6. #include <rdma/ib_user_verbs.h>
  7. #include <linux/io.h>
  8. #include <linux/module.h>
  9. #include <linux/utsname.h>
  10. #include <linux/rculist.h>
  11. #include <linux/mm.h>
  12. #include <linux/vmalloc.h>
  13. #include <rdma/opa_addr.h>
  14. #include <linux/nospec.h>
  15. #include "hfi.h"
  16. #include "common.h"
  17. #include "device.h"
  18. #include "trace.h"
  19. #include "qp.h"
  20. #include "verbs_txreq.h"
  21. #include "debugfs.h"
  22. #include "vnic.h"
  23. #include "fault.h"
  24. #include "affinity.h"
  25. #include "ipoib.h"
  26. static unsigned int hfi1_lkey_table_size = 16;
  27. module_param_named(lkey_table_size, hfi1_lkey_table_size, uint,
  28. S_IRUGO);
  29. MODULE_PARM_DESC(lkey_table_size,
  30. "LKEY table size in bits (2^n, 1 <= n <= 23)");
  31. static unsigned int hfi1_max_pds = 0xFFFF;
  32. module_param_named(max_pds, hfi1_max_pds, uint, S_IRUGO);
  33. MODULE_PARM_DESC(max_pds,
  34. "Maximum number of protection domains to support");
  35. static unsigned int hfi1_max_ahs = 0xFFFF;
  36. module_param_named(max_ahs, hfi1_max_ahs, uint, S_IRUGO);
  37. MODULE_PARM_DESC(max_ahs, "Maximum number of address handles to support");
  38. unsigned int hfi1_max_cqes = 0x2FFFFF;
  39. module_param_named(max_cqes, hfi1_max_cqes, uint, S_IRUGO);
  40. MODULE_PARM_DESC(max_cqes,
  41. "Maximum number of completion queue entries to support");
  42. unsigned int hfi1_max_cqs = 0x1FFFF;
  43. module_param_named(max_cqs, hfi1_max_cqs, uint, S_IRUGO);
  44. MODULE_PARM_DESC(max_cqs, "Maximum number of completion queues to support");
  45. unsigned int hfi1_max_qp_wrs = 0x3FFF;
  46. module_param_named(max_qp_wrs, hfi1_max_qp_wrs, uint, S_IRUGO);
  47. MODULE_PARM_DESC(max_qp_wrs, "Maximum number of QP WRs to support");
  48. unsigned int hfi1_max_qps = 32768;
  49. module_param_named(max_qps, hfi1_max_qps, uint, S_IRUGO);
  50. MODULE_PARM_DESC(max_qps, "Maximum number of QPs to support");
  51. unsigned int hfi1_max_sges = 0x60;
  52. module_param_named(max_sges, hfi1_max_sges, uint, S_IRUGO);
  53. MODULE_PARM_DESC(max_sges, "Maximum number of SGEs to support");
  54. unsigned int hfi1_max_mcast_grps = 16384;
  55. module_param_named(max_mcast_grps, hfi1_max_mcast_grps, uint, S_IRUGO);
  56. MODULE_PARM_DESC(max_mcast_grps,
  57. "Maximum number of multicast groups to support");
  58. unsigned int hfi1_max_mcast_qp_attached = 16;
  59. module_param_named(max_mcast_qp_attached, hfi1_max_mcast_qp_attached,
  60. uint, S_IRUGO);
  61. MODULE_PARM_DESC(max_mcast_qp_attached,
  62. "Maximum number of attached QPs to support");
  63. unsigned int hfi1_max_srqs = 1024;
  64. module_param_named(max_srqs, hfi1_max_srqs, uint, S_IRUGO);
  65. MODULE_PARM_DESC(max_srqs, "Maximum number of SRQs to support");
  66. unsigned int hfi1_max_srq_sges = 128;
  67. module_param_named(max_srq_sges, hfi1_max_srq_sges, uint, S_IRUGO);
  68. MODULE_PARM_DESC(max_srq_sges, "Maximum number of SRQ SGEs to support");
  69. unsigned int hfi1_max_srq_wrs = 0x1FFFF;
  70. module_param_named(max_srq_wrs, hfi1_max_srq_wrs, uint, S_IRUGO);
  71. MODULE_PARM_DESC(max_srq_wrs, "Maximum number of SRQ WRs support");
  72. unsigned short piothreshold = 256;
  73. module_param(piothreshold, ushort, S_IRUGO);
  74. MODULE_PARM_DESC(piothreshold, "size used to determine sdma vs. pio");
  75. static unsigned int sge_copy_mode;
  76. module_param(sge_copy_mode, uint, S_IRUGO);
  77. MODULE_PARM_DESC(sge_copy_mode,
  78. "Verbs copy mode: 0 use memcpy, 1 use cacheless copy, 2 adapt based on WSS");
  79. static void verbs_sdma_complete(
  80. struct sdma_txreq *cookie,
  81. int status);
  82. static int pio_wait(struct rvt_qp *qp,
  83. struct send_context *sc,
  84. struct hfi1_pkt_state *ps,
  85. u32 flag);
  86. /* Length of buffer to create verbs txreq cache name */
  87. #define TXREQ_NAME_LEN 24
  88. static uint wss_threshold = 80;
  89. module_param(wss_threshold, uint, S_IRUGO);
  90. MODULE_PARM_DESC(wss_threshold, "Percentage (1-100) of LLC to use as a threshold for a cacheless copy");
  91. static uint wss_clean_period = 256;
  92. module_param(wss_clean_period, uint, S_IRUGO);
  93. MODULE_PARM_DESC(wss_clean_period, "Count of verbs copies before an entry in the page copy table is cleaned");
  94. /*
  95. * Translate ib_wr_opcode into ib_wc_opcode.
  96. */
  97. const enum ib_wc_opcode ib_hfi1_wc_opcode[] = {
  98. [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
  99. [IB_WR_TID_RDMA_WRITE] = IB_WC_RDMA_WRITE,
  100. [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
  101. [IB_WR_SEND] = IB_WC_SEND,
  102. [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
  103. [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
  104. [IB_WR_TID_RDMA_READ] = IB_WC_RDMA_READ,
  105. [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
  106. [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD,
  107. [IB_WR_SEND_WITH_INV] = IB_WC_SEND,
  108. [IB_WR_LOCAL_INV] = IB_WC_LOCAL_INV,
  109. [IB_WR_REG_MR] = IB_WC_REG_MR
  110. };
  111. /*
  112. * Length of header by opcode, 0 --> not supported
  113. */
  114. const u8 hdr_len_by_opcode[256] = {
  115. /* RC */
  116. [IB_OPCODE_RC_SEND_FIRST] = 12 + 8,
  117. [IB_OPCODE_RC_SEND_MIDDLE] = 12 + 8,
  118. [IB_OPCODE_RC_SEND_LAST] = 12 + 8,
  119. [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
  120. [IB_OPCODE_RC_SEND_ONLY] = 12 + 8,
  121. [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4,
  122. [IB_OPCODE_RC_RDMA_WRITE_FIRST] = 12 + 8 + 16,
  123. [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = 12 + 8,
  124. [IB_OPCODE_RC_RDMA_WRITE_LAST] = 12 + 8,
  125. [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
  126. [IB_OPCODE_RC_RDMA_WRITE_ONLY] = 12 + 8 + 16,
  127. [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20,
  128. [IB_OPCODE_RC_RDMA_READ_REQUEST] = 12 + 8 + 16,
  129. [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = 12 + 8 + 4,
  130. [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = 12 + 8,
  131. [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = 12 + 8 + 4,
  132. [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = 12 + 8 + 4,
  133. [IB_OPCODE_RC_ACKNOWLEDGE] = 12 + 8 + 4,
  134. [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = 12 + 8 + 4 + 8,
  135. [IB_OPCODE_RC_COMPARE_SWAP] = 12 + 8 + 28,
  136. [IB_OPCODE_RC_FETCH_ADD] = 12 + 8 + 28,
  137. [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = 12 + 8 + 4,
  138. [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = 12 + 8 + 4,
  139. [IB_OPCODE_TID_RDMA_READ_REQ] = 12 + 8 + 36,
  140. [IB_OPCODE_TID_RDMA_READ_RESP] = 12 + 8 + 36,
  141. [IB_OPCODE_TID_RDMA_WRITE_REQ] = 12 + 8 + 36,
  142. [IB_OPCODE_TID_RDMA_WRITE_RESP] = 12 + 8 + 36,
  143. [IB_OPCODE_TID_RDMA_WRITE_DATA] = 12 + 8 + 36,
  144. [IB_OPCODE_TID_RDMA_WRITE_DATA_LAST] = 12 + 8 + 36,
  145. [IB_OPCODE_TID_RDMA_ACK] = 12 + 8 + 36,
  146. [IB_OPCODE_TID_RDMA_RESYNC] = 12 + 8 + 36,
  147. /* UC */
  148. [IB_OPCODE_UC_SEND_FIRST] = 12 + 8,
  149. [IB_OPCODE_UC_SEND_MIDDLE] = 12 + 8,
  150. [IB_OPCODE_UC_SEND_LAST] = 12 + 8,
  151. [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
  152. [IB_OPCODE_UC_SEND_ONLY] = 12 + 8,
  153. [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 4,
  154. [IB_OPCODE_UC_RDMA_WRITE_FIRST] = 12 + 8 + 16,
  155. [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = 12 + 8,
  156. [IB_OPCODE_UC_RDMA_WRITE_LAST] = 12 + 8,
  157. [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = 12 + 8 + 4,
  158. [IB_OPCODE_UC_RDMA_WRITE_ONLY] = 12 + 8 + 16,
  159. [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = 12 + 8 + 20,
  160. /* UD */
  161. [IB_OPCODE_UD_SEND_ONLY] = 12 + 8 + 8,
  162. [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = 12 + 8 + 12
  163. };
  164. static const opcode_handler opcode_handler_tbl[256] = {
  165. /* RC */
  166. [IB_OPCODE_RC_SEND_FIRST] = &hfi1_rc_rcv,
  167. [IB_OPCODE_RC_SEND_MIDDLE] = &hfi1_rc_rcv,
  168. [IB_OPCODE_RC_SEND_LAST] = &hfi1_rc_rcv,
  169. [IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv,
  170. [IB_OPCODE_RC_SEND_ONLY] = &hfi1_rc_rcv,
  171. [IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv,
  172. [IB_OPCODE_RC_RDMA_WRITE_FIRST] = &hfi1_rc_rcv,
  173. [IB_OPCODE_RC_RDMA_WRITE_MIDDLE] = &hfi1_rc_rcv,
  174. [IB_OPCODE_RC_RDMA_WRITE_LAST] = &hfi1_rc_rcv,
  175. [IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_rc_rcv,
  176. [IB_OPCODE_RC_RDMA_WRITE_ONLY] = &hfi1_rc_rcv,
  177. [IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_rc_rcv,
  178. [IB_OPCODE_RC_RDMA_READ_REQUEST] = &hfi1_rc_rcv,
  179. [IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST] = &hfi1_rc_rcv,
  180. [IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE] = &hfi1_rc_rcv,
  181. [IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST] = &hfi1_rc_rcv,
  182. [IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY] = &hfi1_rc_rcv,
  183. [IB_OPCODE_RC_ACKNOWLEDGE] = &hfi1_rc_rcv,
  184. [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = &hfi1_rc_rcv,
  185. [IB_OPCODE_RC_COMPARE_SWAP] = &hfi1_rc_rcv,
  186. [IB_OPCODE_RC_FETCH_ADD] = &hfi1_rc_rcv,
  187. [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = &hfi1_rc_rcv,
  188. [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = &hfi1_rc_rcv,
  189. /* TID RDMA has separate handlers for different opcodes.*/
  190. [IB_OPCODE_TID_RDMA_WRITE_REQ] = &hfi1_rc_rcv_tid_rdma_write_req,
  191. [IB_OPCODE_TID_RDMA_WRITE_RESP] = &hfi1_rc_rcv_tid_rdma_write_resp,
  192. [IB_OPCODE_TID_RDMA_WRITE_DATA] = &hfi1_rc_rcv_tid_rdma_write_data,
  193. [IB_OPCODE_TID_RDMA_WRITE_DATA_LAST] = &hfi1_rc_rcv_tid_rdma_write_data,
  194. [IB_OPCODE_TID_RDMA_READ_REQ] = &hfi1_rc_rcv_tid_rdma_read_req,
  195. [IB_OPCODE_TID_RDMA_READ_RESP] = &hfi1_rc_rcv_tid_rdma_read_resp,
  196. [IB_OPCODE_TID_RDMA_RESYNC] = &hfi1_rc_rcv_tid_rdma_resync,
  197. [IB_OPCODE_TID_RDMA_ACK] = &hfi1_rc_rcv_tid_rdma_ack,
  198. /* UC */
  199. [IB_OPCODE_UC_SEND_FIRST] = &hfi1_uc_rcv,
  200. [IB_OPCODE_UC_SEND_MIDDLE] = &hfi1_uc_rcv,
  201. [IB_OPCODE_UC_SEND_LAST] = &hfi1_uc_rcv,
  202. [IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv,
  203. [IB_OPCODE_UC_SEND_ONLY] = &hfi1_uc_rcv,
  204. [IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv,
  205. [IB_OPCODE_UC_RDMA_WRITE_FIRST] = &hfi1_uc_rcv,
  206. [IB_OPCODE_UC_RDMA_WRITE_MIDDLE] = &hfi1_uc_rcv,
  207. [IB_OPCODE_UC_RDMA_WRITE_LAST] = &hfi1_uc_rcv,
  208. [IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE] = &hfi1_uc_rcv,
  209. [IB_OPCODE_UC_RDMA_WRITE_ONLY] = &hfi1_uc_rcv,
  210. [IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE] = &hfi1_uc_rcv,
  211. /* UD */
  212. [IB_OPCODE_UD_SEND_ONLY] = &hfi1_ud_rcv,
  213. [IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE] = &hfi1_ud_rcv,
  214. /* CNP */
  215. [IB_OPCODE_CNP] = &hfi1_cnp_rcv
  216. };
  217. #define OPMASK 0x1f
  218. static const u32 pio_opmask[BIT(3)] = {
  219. /* RC */
  220. [IB_OPCODE_RC >> 5] =
  221. BIT(RC_OP(SEND_ONLY) & OPMASK) |
  222. BIT(RC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) |
  223. BIT(RC_OP(RDMA_WRITE_ONLY) & OPMASK) |
  224. BIT(RC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK) |
  225. BIT(RC_OP(RDMA_READ_REQUEST) & OPMASK) |
  226. BIT(RC_OP(ACKNOWLEDGE) & OPMASK) |
  227. BIT(RC_OP(ATOMIC_ACKNOWLEDGE) & OPMASK) |
  228. BIT(RC_OP(COMPARE_SWAP) & OPMASK) |
  229. BIT(RC_OP(FETCH_ADD) & OPMASK),
  230. /* UC */
  231. [IB_OPCODE_UC >> 5] =
  232. BIT(UC_OP(SEND_ONLY) & OPMASK) |
  233. BIT(UC_OP(SEND_ONLY_WITH_IMMEDIATE) & OPMASK) |
  234. BIT(UC_OP(RDMA_WRITE_ONLY) & OPMASK) |
  235. BIT(UC_OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE) & OPMASK),
  236. };
  237. /*
  238. * System image GUID.
  239. */
  240. __be64 ib_hfi1_sys_image_guid;
  241. /*
  242. * Make sure the QP is ready and able to accept the given opcode.
  243. */
  244. static inline opcode_handler qp_ok(struct hfi1_packet *packet)
  245. {
  246. if (!(ib_rvt_state_ops[packet->qp->state] & RVT_PROCESS_RECV_OK))
  247. return NULL;
  248. if (((packet->opcode & RVT_OPCODE_QP_MASK) ==
  249. packet->qp->allowed_ops) ||
  250. (packet->opcode == IB_OPCODE_CNP))
  251. return opcode_handler_tbl[packet->opcode];
  252. return NULL;
  253. }
  254. static u64 hfi1_fault_tx(struct rvt_qp *qp, u8 opcode, u64 pbc)
  255. {
  256. #ifdef CONFIG_FAULT_INJECTION
  257. if ((opcode & IB_OPCODE_MSP) == IB_OPCODE_MSP) {
  258. /*
  259. * In order to drop non-IB traffic we
  260. * set PbcInsertHrc to NONE (0x2).
  261. * The packet will still be delivered
  262. * to the receiving node but a
  263. * KHdrHCRCErr (KDETH packet with a bad
  264. * HCRC) will be triggered and the
  265. * packet will not be delivered to the
  266. * correct context.
  267. */
  268. pbc &= ~PBC_INSERT_HCRC_SMASK;
  269. pbc |= (u64)PBC_IHCRC_NONE << PBC_INSERT_HCRC_SHIFT;
  270. } else {
  271. /*
  272. * In order to drop regular verbs
  273. * traffic we set the PbcTestEbp
  274. * flag. The packet will still be
  275. * delivered to the receiving node but
  276. * a 'late ebp error' will be
  277. * triggered and will be dropped.
  278. */
  279. pbc |= PBC_TEST_EBP;
  280. }
  281. #endif
  282. return pbc;
  283. }
  284. static opcode_handler tid_qp_ok(int opcode, struct hfi1_packet *packet)
  285. {
  286. if (packet->qp->ibqp.qp_type != IB_QPT_RC ||
  287. !(ib_rvt_state_ops[packet->qp->state] & RVT_PROCESS_RECV_OK))
  288. return NULL;
  289. if ((opcode & RVT_OPCODE_QP_MASK) == IB_OPCODE_TID_RDMA)
  290. return opcode_handler_tbl[opcode];
  291. return NULL;
  292. }
  293. void hfi1_kdeth_eager_rcv(struct hfi1_packet *packet)
  294. {
  295. struct hfi1_ctxtdata *rcd = packet->rcd;
  296. struct ib_header *hdr = packet->hdr;
  297. u32 tlen = packet->tlen;
  298. struct hfi1_pportdata *ppd = rcd->ppd;
  299. struct hfi1_ibport *ibp = &ppd->ibport_data;
  300. struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi;
  301. opcode_handler opcode_handler;
  302. unsigned long flags;
  303. u32 qp_num;
  304. int lnh;
  305. u8 opcode;
  306. /* DW == LRH (2) + BTH (3) + KDETH (9) + CRC (1) */
  307. if (unlikely(tlen < 15 * sizeof(u32)))
  308. goto drop;
  309. lnh = be16_to_cpu(hdr->lrh[0]) & 3;
  310. if (lnh != HFI1_LRH_BTH)
  311. goto drop;
  312. packet->ohdr = &hdr->u.oth;
  313. trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf)));
  314. opcode = (be32_to_cpu(packet->ohdr->bth[0]) >> 24);
  315. inc_opstats(tlen, &rcd->opstats->stats[opcode]);
  316. /* verbs_qp can be picked up from any tid_rdma header struct */
  317. qp_num = be32_to_cpu(packet->ohdr->u.tid_rdma.r_req.verbs_qp) &
  318. RVT_QPN_MASK;
  319. rcu_read_lock();
  320. packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
  321. if (!packet->qp)
  322. goto drop_rcu;
  323. spin_lock_irqsave(&packet->qp->r_lock, flags);
  324. opcode_handler = tid_qp_ok(opcode, packet);
  325. if (likely(opcode_handler))
  326. opcode_handler(packet);
  327. else
  328. goto drop_unlock;
  329. spin_unlock_irqrestore(&packet->qp->r_lock, flags);
  330. rcu_read_unlock();
  331. return;
  332. drop_unlock:
  333. spin_unlock_irqrestore(&packet->qp->r_lock, flags);
  334. drop_rcu:
  335. rcu_read_unlock();
  336. drop:
  337. ibp->rvp.n_pkt_drops++;
  338. }
  339. void hfi1_kdeth_expected_rcv(struct hfi1_packet *packet)
  340. {
  341. struct hfi1_ctxtdata *rcd = packet->rcd;
  342. struct ib_header *hdr = packet->hdr;
  343. u32 tlen = packet->tlen;
  344. struct hfi1_pportdata *ppd = rcd->ppd;
  345. struct hfi1_ibport *ibp = &ppd->ibport_data;
  346. struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi;
  347. opcode_handler opcode_handler;
  348. unsigned long flags;
  349. u32 qp_num;
  350. int lnh;
  351. u8 opcode;
  352. /* DW == LRH (2) + BTH (3) + KDETH (9) + CRC (1) */
  353. if (unlikely(tlen < 15 * sizeof(u32)))
  354. goto drop;
  355. lnh = be16_to_cpu(hdr->lrh[0]) & 3;
  356. if (lnh != HFI1_LRH_BTH)
  357. goto drop;
  358. packet->ohdr = &hdr->u.oth;
  359. trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf)));
  360. opcode = (be32_to_cpu(packet->ohdr->bth[0]) >> 24);
  361. inc_opstats(tlen, &rcd->opstats->stats[opcode]);
  362. /* verbs_qp can be picked up from any tid_rdma header struct */
  363. qp_num = be32_to_cpu(packet->ohdr->u.tid_rdma.r_rsp.verbs_qp) &
  364. RVT_QPN_MASK;
  365. rcu_read_lock();
  366. packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
  367. if (!packet->qp)
  368. goto drop_rcu;
  369. spin_lock_irqsave(&packet->qp->r_lock, flags);
  370. opcode_handler = tid_qp_ok(opcode, packet);
  371. if (likely(opcode_handler))
  372. opcode_handler(packet);
  373. else
  374. goto drop_unlock;
  375. spin_unlock_irqrestore(&packet->qp->r_lock, flags);
  376. rcu_read_unlock();
  377. return;
  378. drop_unlock:
  379. spin_unlock_irqrestore(&packet->qp->r_lock, flags);
  380. drop_rcu:
  381. rcu_read_unlock();
  382. drop:
  383. ibp->rvp.n_pkt_drops++;
  384. }
  385. static int hfi1_do_pkey_check(struct hfi1_packet *packet)
  386. {
  387. struct hfi1_ctxtdata *rcd = packet->rcd;
  388. struct hfi1_pportdata *ppd = rcd->ppd;
  389. struct hfi1_16b_header *hdr = packet->hdr;
  390. u16 pkey;
  391. /* Pkey check needed only for bypass packets */
  392. if (packet->etype != RHF_RCV_TYPE_BYPASS)
  393. return 0;
  394. /* Perform pkey check */
  395. pkey = hfi1_16B_get_pkey(hdr);
  396. return ingress_pkey_check(ppd, pkey, packet->sc,
  397. packet->qp->s_pkey_index,
  398. packet->slid, true);
  399. }
  400. static inline void hfi1_handle_packet(struct hfi1_packet *packet,
  401. bool is_mcast)
  402. {
  403. u32 qp_num;
  404. struct hfi1_ctxtdata *rcd = packet->rcd;
  405. struct hfi1_pportdata *ppd = rcd->ppd;
  406. struct hfi1_ibport *ibp = rcd_to_iport(rcd);
  407. struct rvt_dev_info *rdi = &ppd->dd->verbs_dev.rdi;
  408. opcode_handler packet_handler;
  409. unsigned long flags;
  410. inc_opstats(packet->tlen, &rcd->opstats->stats[packet->opcode]);
  411. if (unlikely(is_mcast)) {
  412. struct rvt_mcast *mcast;
  413. struct rvt_mcast_qp *p;
  414. if (!packet->grh)
  415. goto drop;
  416. mcast = rvt_mcast_find(&ibp->rvp,
  417. &packet->grh->dgid,
  418. opa_get_lid(packet->dlid, 9B));
  419. if (!mcast)
  420. goto drop;
  421. rcu_read_lock();
  422. list_for_each_entry_rcu(p, &mcast->qp_list, list) {
  423. packet->qp = p->qp;
  424. if (hfi1_do_pkey_check(packet))
  425. goto unlock_drop;
  426. spin_lock_irqsave(&packet->qp->r_lock, flags);
  427. packet_handler = qp_ok(packet);
  428. if (likely(packet_handler))
  429. packet_handler(packet);
  430. else
  431. ibp->rvp.n_pkt_drops++;
  432. spin_unlock_irqrestore(&packet->qp->r_lock, flags);
  433. }
  434. rcu_read_unlock();
  435. /*
  436. * Notify rvt_multicast_detach() if it is waiting for us
  437. * to finish.
  438. */
  439. if (atomic_dec_return(&mcast->refcount) <= 1)
  440. wake_up(&mcast->wait);
  441. } else {
  442. /* Get the destination QP number. */
  443. if (packet->etype == RHF_RCV_TYPE_BYPASS &&
  444. hfi1_16B_get_l4(packet->hdr) == OPA_16B_L4_FM)
  445. qp_num = hfi1_16B_get_dest_qpn(packet->mgmt);
  446. else
  447. qp_num = ib_bth_get_qpn(packet->ohdr);
  448. rcu_read_lock();
  449. packet->qp = rvt_lookup_qpn(rdi, &ibp->rvp, qp_num);
  450. if (!packet->qp)
  451. goto unlock_drop;
  452. if (hfi1_do_pkey_check(packet))
  453. goto unlock_drop;
  454. spin_lock_irqsave(&packet->qp->r_lock, flags);
  455. packet_handler = qp_ok(packet);
  456. if (likely(packet_handler))
  457. packet_handler(packet);
  458. else
  459. ibp->rvp.n_pkt_drops++;
  460. spin_unlock_irqrestore(&packet->qp->r_lock, flags);
  461. rcu_read_unlock();
  462. }
  463. return;
  464. unlock_drop:
  465. rcu_read_unlock();
  466. drop:
  467. ibp->rvp.n_pkt_drops++;
  468. }
  469. /**
  470. * hfi1_ib_rcv - process an incoming packet
  471. * @packet: data packet information
  472. *
  473. * This is called to process an incoming packet at interrupt level.
  474. */
  475. void hfi1_ib_rcv(struct hfi1_packet *packet)
  476. {
  477. struct hfi1_ctxtdata *rcd = packet->rcd;
  478. trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf)));
  479. hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid));
  480. }
  481. void hfi1_16B_rcv(struct hfi1_packet *packet)
  482. {
  483. struct hfi1_ctxtdata *rcd = packet->rcd;
  484. trace_input_ibhdr(rcd->dd, packet, false);
  485. hfi1_handle_packet(packet, hfi1_check_mcast(packet->dlid));
  486. }
  487. /*
  488. * This is called from a timer to check for QPs
  489. * which need kernel memory in order to send a packet.
  490. */
  491. static void mem_timer(struct timer_list *t)
  492. {
  493. struct hfi1_ibdev *dev = from_timer(dev, t, mem_timer);
  494. struct list_head *list = &dev->memwait;
  495. struct rvt_qp *qp = NULL;
  496. struct iowait *wait;
  497. unsigned long flags;
  498. struct hfi1_qp_priv *priv;
  499. write_seqlock_irqsave(&dev->iowait_lock, flags);
  500. if (!list_empty(list)) {
  501. wait = list_first_entry(list, struct iowait, list);
  502. qp = iowait_to_qp(wait);
  503. priv = qp->priv;
  504. list_del_init(&priv->s_iowait.list);
  505. priv->s_iowait.lock = NULL;
  506. /* refcount held until actual wake up */
  507. if (!list_empty(list))
  508. mod_timer(&dev->mem_timer, jiffies + 1);
  509. }
  510. write_sequnlock_irqrestore(&dev->iowait_lock, flags);
  511. if (qp)
  512. hfi1_qp_wakeup(qp, RVT_S_WAIT_KMEM);
  513. }
  514. /*
  515. * This is called with progress side lock held.
  516. */
  517. /* New API */
  518. static void verbs_sdma_complete(
  519. struct sdma_txreq *cookie,
  520. int status)
  521. {
  522. struct verbs_txreq *tx =
  523. container_of(cookie, struct verbs_txreq, txreq);
  524. struct rvt_qp *qp = tx->qp;
  525. spin_lock(&qp->s_lock);
  526. if (tx->wqe) {
  527. rvt_send_complete(qp, tx->wqe, IB_WC_SUCCESS);
  528. } else if (qp->ibqp.qp_type == IB_QPT_RC) {
  529. struct hfi1_opa_header *hdr;
  530. hdr = &tx->phdr.hdr;
  531. if (unlikely(status == SDMA_TXREQ_S_ABORTED))
  532. hfi1_rc_verbs_aborted(qp, hdr);
  533. hfi1_rc_send_complete(qp, hdr);
  534. }
  535. spin_unlock(&qp->s_lock);
  536. hfi1_put_txreq(tx);
  537. }
  538. void hfi1_wait_kmem(struct rvt_qp *qp)
  539. {
  540. struct hfi1_qp_priv *priv = qp->priv;
  541. struct ib_qp *ibqp = &qp->ibqp;
  542. struct ib_device *ibdev = ibqp->device;
  543. struct hfi1_ibdev *dev = to_idev(ibdev);
  544. if (list_empty(&priv->s_iowait.list)) {
  545. if (list_empty(&dev->memwait))
  546. mod_timer(&dev->mem_timer, jiffies + 1);
  547. qp->s_flags |= RVT_S_WAIT_KMEM;
  548. list_add_tail(&priv->s_iowait.list, &dev->memwait);
  549. priv->s_iowait.lock = &dev->iowait_lock;
  550. trace_hfi1_qpsleep(qp, RVT_S_WAIT_KMEM);
  551. rvt_get_qp(qp);
  552. }
  553. }
  554. static int wait_kmem(struct hfi1_ibdev *dev,
  555. struct rvt_qp *qp,
  556. struct hfi1_pkt_state *ps)
  557. {
  558. unsigned long flags;
  559. int ret = 0;
  560. spin_lock_irqsave(&qp->s_lock, flags);
  561. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  562. write_seqlock(&dev->iowait_lock);
  563. list_add_tail(&ps->s_txreq->txreq.list,
  564. &ps->wait->tx_head);
  565. hfi1_wait_kmem(qp);
  566. write_sequnlock(&dev->iowait_lock);
  567. hfi1_qp_unbusy(qp, ps->wait);
  568. ret = -EBUSY;
  569. }
  570. spin_unlock_irqrestore(&qp->s_lock, flags);
  571. return ret;
  572. }
  573. /*
  574. * This routine calls txadds for each sg entry.
  575. *
  576. * Add failures will revert the sge cursor
  577. */
  578. static noinline int build_verbs_ulp_payload(
  579. struct sdma_engine *sde,
  580. u32 length,
  581. struct verbs_txreq *tx)
  582. {
  583. struct rvt_sge_state *ss = tx->ss;
  584. struct rvt_sge *sg_list = ss->sg_list;
  585. struct rvt_sge sge = ss->sge;
  586. u8 num_sge = ss->num_sge;
  587. u32 len;
  588. int ret = 0;
  589. while (length) {
  590. len = rvt_get_sge_length(&ss->sge, length);
  591. WARN_ON_ONCE(len == 0);
  592. ret = sdma_txadd_kvaddr(
  593. sde->dd,
  594. &tx->txreq,
  595. ss->sge.vaddr,
  596. len);
  597. if (ret)
  598. goto bail_txadd;
  599. rvt_update_sge(ss, len, false);
  600. length -= len;
  601. }
  602. return ret;
  603. bail_txadd:
  604. /* unwind cursor */
  605. ss->sge = sge;
  606. ss->num_sge = num_sge;
  607. ss->sg_list = sg_list;
  608. return ret;
  609. }
  610. /**
  611. * update_tx_opstats - record stats by opcode
  612. * @qp: the qp
  613. * @ps: transmit packet state
  614. * @plen: the plen in dwords
  615. *
  616. * This is a routine to record the tx opstats after a
  617. * packet has been presented to the egress mechanism.
  618. */
  619. static void update_tx_opstats(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  620. u32 plen)
  621. {
  622. #ifdef CONFIG_DEBUG_FS
  623. struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  624. struct hfi1_opcode_stats_perctx *s = get_cpu_ptr(dd->tx_opstats);
  625. inc_opstats(plen * 4, &s->stats[ps->opcode]);
  626. put_cpu_ptr(s);
  627. #endif
  628. }
  629. /*
  630. * Build the number of DMA descriptors needed to send length bytes of data.
  631. *
  632. * NOTE: DMA mapping is held in the tx until completed in the ring or
  633. * the tx desc is freed without having been submitted to the ring
  634. *
  635. * This routine ensures all the helper routine calls succeed.
  636. */
  637. /* New API */
  638. static int build_verbs_tx_desc(
  639. struct sdma_engine *sde,
  640. u32 length,
  641. struct verbs_txreq *tx,
  642. struct hfi1_ahg_info *ahg_info,
  643. u64 pbc)
  644. {
  645. int ret = 0;
  646. struct hfi1_sdma_header *phdr = &tx->phdr;
  647. u16 hdrbytes = (tx->hdr_dwords + sizeof(pbc) / 4) << 2;
  648. u8 extra_bytes = 0;
  649. if (tx->phdr.hdr.hdr_type) {
  650. /*
  651. * hdrbytes accounts for PBC. Need to subtract 8 bytes
  652. * before calculating padding.
  653. */
  654. extra_bytes = hfi1_get_16b_padding(hdrbytes - 8, length) +
  655. (SIZE_OF_CRC << 2) + SIZE_OF_LT;
  656. }
  657. if (!ahg_info->ahgcount) {
  658. ret = sdma_txinit_ahg(
  659. &tx->txreq,
  660. ahg_info->tx_flags,
  661. hdrbytes + length +
  662. extra_bytes,
  663. ahg_info->ahgidx,
  664. 0,
  665. NULL,
  666. 0,
  667. verbs_sdma_complete);
  668. if (ret)
  669. goto bail_txadd;
  670. phdr->pbc = cpu_to_le64(pbc);
  671. ret = sdma_txadd_kvaddr(
  672. sde->dd,
  673. &tx->txreq,
  674. phdr,
  675. hdrbytes);
  676. if (ret)
  677. goto bail_txadd;
  678. } else {
  679. ret = sdma_txinit_ahg(
  680. &tx->txreq,
  681. ahg_info->tx_flags,
  682. length,
  683. ahg_info->ahgidx,
  684. ahg_info->ahgcount,
  685. ahg_info->ahgdesc,
  686. hdrbytes,
  687. verbs_sdma_complete);
  688. if (ret)
  689. goto bail_txadd;
  690. }
  691. /* add the ulp payload - if any. tx->ss can be NULL for acks */
  692. if (tx->ss) {
  693. ret = build_verbs_ulp_payload(sde, length, tx);
  694. if (ret)
  695. goto bail_txadd;
  696. }
  697. /* add icrc, lt byte, and padding to flit */
  698. if (extra_bytes)
  699. ret = sdma_txadd_daddr(sde->dd, &tx->txreq, sde->dd->sdma_pad_phys,
  700. extra_bytes);
  701. bail_txadd:
  702. return ret;
  703. }
  704. static u64 update_hcrc(u8 opcode, u64 pbc)
  705. {
  706. if ((opcode & IB_OPCODE_TID_RDMA) == IB_OPCODE_TID_RDMA) {
  707. pbc &= ~PBC_INSERT_HCRC_SMASK;
  708. pbc |= (u64)PBC_IHCRC_LKDETH << PBC_INSERT_HCRC_SHIFT;
  709. }
  710. return pbc;
  711. }
  712. int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  713. u64 pbc)
  714. {
  715. struct hfi1_qp_priv *priv = qp->priv;
  716. struct hfi1_ahg_info *ahg_info = priv->s_ahg;
  717. u32 hdrwords = ps->s_txreq->hdr_dwords;
  718. u32 len = ps->s_txreq->s_cur_size;
  719. u32 plen;
  720. struct hfi1_ibdev *dev = ps->dev;
  721. struct hfi1_pportdata *ppd = ps->ppd;
  722. struct verbs_txreq *tx;
  723. u8 sc5 = priv->s_sc;
  724. int ret;
  725. u32 dwords;
  726. if (ps->s_txreq->phdr.hdr.hdr_type) {
  727. u8 extra_bytes = hfi1_get_16b_padding((hdrwords << 2), len);
  728. dwords = (len + extra_bytes + (SIZE_OF_CRC << 2) +
  729. SIZE_OF_LT) >> 2;
  730. } else {
  731. dwords = (len + 3) >> 2;
  732. }
  733. plen = hdrwords + dwords + sizeof(pbc) / 4;
  734. tx = ps->s_txreq;
  735. if (!sdma_txreq_built(&tx->txreq)) {
  736. if (likely(pbc == 0)) {
  737. u32 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5);
  738. /* No vl15 here */
  739. /* set PBC_DC_INFO bit (aka SC[4]) in pbc */
  740. if (ps->s_txreq->phdr.hdr.hdr_type)
  741. pbc |= PBC_PACKET_BYPASS |
  742. PBC_INSERT_BYPASS_ICRC;
  743. else
  744. pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
  745. pbc = create_pbc(ppd,
  746. pbc,
  747. qp->srate_mbps,
  748. vl,
  749. plen);
  750. if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode)))
  751. pbc = hfi1_fault_tx(qp, ps->opcode, pbc);
  752. else
  753. /* Update HCRC based on packet opcode */
  754. pbc = update_hcrc(ps->opcode, pbc);
  755. }
  756. tx->wqe = qp->s_wqe;
  757. ret = build_verbs_tx_desc(tx->sde, len, tx, ahg_info, pbc);
  758. if (unlikely(ret))
  759. goto bail_build;
  760. }
  761. ret = sdma_send_txreq(tx->sde, ps->wait, &tx->txreq, ps->pkts_sent);
  762. if (unlikely(ret < 0)) {
  763. if (ret == -ECOMM)
  764. goto bail_ecomm;
  765. return ret;
  766. }
  767. update_tx_opstats(qp, ps, plen);
  768. trace_sdma_output_ibhdr(dd_from_ibdev(qp->ibqp.device),
  769. &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5));
  770. return ret;
  771. bail_ecomm:
  772. /* The current one got "sent" */
  773. return 0;
  774. bail_build:
  775. ret = wait_kmem(dev, qp, ps);
  776. if (!ret) {
  777. /* free txreq - bad state */
  778. hfi1_put_txreq(ps->s_txreq);
  779. ps->s_txreq = NULL;
  780. }
  781. return ret;
  782. }
  783. /*
  784. * If we are now in the error state, return zero to flush the
  785. * send work request.
  786. */
  787. static int pio_wait(struct rvt_qp *qp,
  788. struct send_context *sc,
  789. struct hfi1_pkt_state *ps,
  790. u32 flag)
  791. {
  792. struct hfi1_qp_priv *priv = qp->priv;
  793. struct hfi1_devdata *dd = sc->dd;
  794. unsigned long flags;
  795. int ret = 0;
  796. /*
  797. * Note that as soon as want_buffer() is called and
  798. * possibly before it returns, sc_piobufavail()
  799. * could be called. Therefore, put QP on the I/O wait list before
  800. * enabling the PIO avail interrupt.
  801. */
  802. spin_lock_irqsave(&qp->s_lock, flags);
  803. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  804. write_seqlock(&sc->waitlock);
  805. list_add_tail(&ps->s_txreq->txreq.list,
  806. &ps->wait->tx_head);
  807. if (list_empty(&priv->s_iowait.list)) {
  808. struct hfi1_ibdev *dev = &dd->verbs_dev;
  809. int was_empty;
  810. dev->n_piowait += !!(flag & RVT_S_WAIT_PIO);
  811. dev->n_piodrain += !!(flag & HFI1_S_WAIT_PIO_DRAIN);
  812. qp->s_flags |= flag;
  813. was_empty = list_empty(&sc->piowait);
  814. iowait_get_priority(&priv->s_iowait);
  815. iowait_queue(ps->pkts_sent, &priv->s_iowait,
  816. &sc->piowait);
  817. priv->s_iowait.lock = &sc->waitlock;
  818. trace_hfi1_qpsleep(qp, RVT_S_WAIT_PIO);
  819. rvt_get_qp(qp);
  820. /* counting: only call wantpiobuf_intr if first user */
  821. if (was_empty)
  822. hfi1_sc_wantpiobuf_intr(sc, 1);
  823. }
  824. write_sequnlock(&sc->waitlock);
  825. hfi1_qp_unbusy(qp, ps->wait);
  826. ret = -EBUSY;
  827. }
  828. spin_unlock_irqrestore(&qp->s_lock, flags);
  829. return ret;
  830. }
  831. static void verbs_pio_complete(void *arg, int code)
  832. {
  833. struct rvt_qp *qp = (struct rvt_qp *)arg;
  834. struct hfi1_qp_priv *priv = qp->priv;
  835. if (iowait_pio_dec(&priv->s_iowait))
  836. iowait_drain_wakeup(&priv->s_iowait);
  837. }
  838. int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  839. u64 pbc)
  840. {
  841. struct hfi1_qp_priv *priv = qp->priv;
  842. u32 hdrwords = ps->s_txreq->hdr_dwords;
  843. struct rvt_sge_state *ss = ps->s_txreq->ss;
  844. u32 len = ps->s_txreq->s_cur_size;
  845. u32 dwords;
  846. u32 plen;
  847. struct hfi1_pportdata *ppd = ps->ppd;
  848. u32 *hdr;
  849. u8 sc5;
  850. unsigned long flags = 0;
  851. struct send_context *sc;
  852. struct pio_buf *pbuf;
  853. int wc_status = IB_WC_SUCCESS;
  854. int ret = 0;
  855. pio_release_cb cb = NULL;
  856. u8 extra_bytes = 0;
  857. if (ps->s_txreq->phdr.hdr.hdr_type) {
  858. u8 pad_size = hfi1_get_16b_padding((hdrwords << 2), len);
  859. extra_bytes = pad_size + (SIZE_OF_CRC << 2) + SIZE_OF_LT;
  860. dwords = (len + extra_bytes) >> 2;
  861. hdr = (u32 *)&ps->s_txreq->phdr.hdr.opah;
  862. } else {
  863. dwords = (len + 3) >> 2;
  864. hdr = (u32 *)&ps->s_txreq->phdr.hdr.ibh;
  865. }
  866. plen = hdrwords + dwords + sizeof(pbc) / 4;
  867. /* only RC/UC use complete */
  868. switch (qp->ibqp.qp_type) {
  869. case IB_QPT_RC:
  870. case IB_QPT_UC:
  871. cb = verbs_pio_complete;
  872. break;
  873. default:
  874. break;
  875. }
  876. /* vl15 special case taken care of in ud.c */
  877. sc5 = priv->s_sc;
  878. sc = ps->s_txreq->psc;
  879. if (likely(pbc == 0)) {
  880. u8 vl = sc_to_vlt(dd_from_ibdev(qp->ibqp.device), sc5);
  881. /* set PBC_DC_INFO bit (aka SC[4]) in pbc */
  882. if (ps->s_txreq->phdr.hdr.hdr_type)
  883. pbc |= PBC_PACKET_BYPASS | PBC_INSERT_BYPASS_ICRC;
  884. else
  885. pbc |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
  886. pbc = create_pbc(ppd, pbc, qp->srate_mbps, vl, plen);
  887. if (unlikely(hfi1_dbg_should_fault_tx(qp, ps->opcode)))
  888. pbc = hfi1_fault_tx(qp, ps->opcode, pbc);
  889. else
  890. /* Update HCRC based on packet opcode */
  891. pbc = update_hcrc(ps->opcode, pbc);
  892. }
  893. if (cb)
  894. iowait_pio_inc(&priv->s_iowait);
  895. pbuf = sc_buffer_alloc(sc, plen, cb, qp);
  896. if (IS_ERR_OR_NULL(pbuf)) {
  897. if (cb)
  898. verbs_pio_complete(qp, 0);
  899. if (IS_ERR(pbuf)) {
  900. /*
  901. * If we have filled the PIO buffers to capacity and are
  902. * not in an active state this request is not going to
  903. * go out to so just complete it with an error or else a
  904. * ULP or the core may be stuck waiting.
  905. */
  906. hfi1_cdbg(
  907. PIO,
  908. "alloc failed. state not active, completing");
  909. wc_status = IB_WC_GENERAL_ERR;
  910. goto pio_bail;
  911. } else {
  912. /*
  913. * This is a normal occurrence. The PIO buffs are full
  914. * up but we are still happily sending, well we could be
  915. * so lets continue to queue the request.
  916. */
  917. hfi1_cdbg(PIO, "alloc failed. state active, queuing");
  918. ret = pio_wait(qp, sc, ps, RVT_S_WAIT_PIO);
  919. if (!ret)
  920. /* txreq not queued - free */
  921. goto bail;
  922. /* tx consumed in wait */
  923. return ret;
  924. }
  925. }
  926. if (dwords == 0) {
  927. pio_copy(ppd->dd, pbuf, pbc, hdr, hdrwords);
  928. } else {
  929. seg_pio_copy_start(pbuf, pbc,
  930. hdr, hdrwords * 4);
  931. if (ss) {
  932. while (len) {
  933. void *addr = ss->sge.vaddr;
  934. u32 slen = rvt_get_sge_length(&ss->sge, len);
  935. rvt_update_sge(ss, slen, false);
  936. seg_pio_copy_mid(pbuf, addr, slen);
  937. len -= slen;
  938. }
  939. }
  940. /* add icrc, lt byte, and padding to flit */
  941. if (extra_bytes)
  942. seg_pio_copy_mid(pbuf, ppd->dd->sdma_pad_dma,
  943. extra_bytes);
  944. seg_pio_copy_end(pbuf);
  945. }
  946. update_tx_opstats(qp, ps, plen);
  947. trace_pio_output_ibhdr(dd_from_ibdev(qp->ibqp.device),
  948. &ps->s_txreq->phdr.hdr, ib_is_sc5(sc5));
  949. pio_bail:
  950. spin_lock_irqsave(&qp->s_lock, flags);
  951. if (qp->s_wqe) {
  952. rvt_send_complete(qp, qp->s_wqe, wc_status);
  953. } else if (qp->ibqp.qp_type == IB_QPT_RC) {
  954. if (unlikely(wc_status == IB_WC_GENERAL_ERR))
  955. hfi1_rc_verbs_aborted(qp, &ps->s_txreq->phdr.hdr);
  956. hfi1_rc_send_complete(qp, &ps->s_txreq->phdr.hdr);
  957. }
  958. spin_unlock_irqrestore(&qp->s_lock, flags);
  959. ret = 0;
  960. bail:
  961. hfi1_put_txreq(ps->s_txreq);
  962. return ret;
  963. }
  964. /*
  965. * egress_pkey_matches_entry - return 1 if the pkey matches ent (ent
  966. * being an entry from the partition key table), return 0
  967. * otherwise. Use the matching criteria for egress partition keys
  968. * specified in the OPAv1 spec., section 9.1l.7.
  969. */
  970. static inline int egress_pkey_matches_entry(u16 pkey, u16 ent)
  971. {
  972. u16 mkey = pkey & PKEY_LOW_15_MASK;
  973. u16 mentry = ent & PKEY_LOW_15_MASK;
  974. if (mkey == mentry) {
  975. /*
  976. * If pkey[15] is set (full partition member),
  977. * is bit 15 in the corresponding table element
  978. * clear (limited member)?
  979. */
  980. if (pkey & PKEY_MEMBER_MASK)
  981. return !!(ent & PKEY_MEMBER_MASK);
  982. return 1;
  983. }
  984. return 0;
  985. }
  986. /**
  987. * egress_pkey_check - check P_KEY of a packet
  988. * @ppd: Physical IB port data
  989. * @slid: SLID for packet
  990. * @pkey: PKEY for header
  991. * @sc5: SC for packet
  992. * @s_pkey_index: It will be used for look up optimization for kernel contexts
  993. * only. If it is negative value, then it means user contexts is calling this
  994. * function.
  995. *
  996. * It checks if hdr's pkey is valid.
  997. *
  998. * Return: 0 on success, otherwise, 1
  999. */
  1000. int egress_pkey_check(struct hfi1_pportdata *ppd, u32 slid, u16 pkey,
  1001. u8 sc5, int8_t s_pkey_index)
  1002. {
  1003. struct hfi1_devdata *dd;
  1004. int i;
  1005. int is_user_ctxt_mechanism = (s_pkey_index < 0);
  1006. if (!(ppd->part_enforce & HFI1_PART_ENFORCE_OUT))
  1007. return 0;
  1008. /* If SC15, pkey[0:14] must be 0x7fff */
  1009. if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
  1010. goto bad;
  1011. /* Is the pkey = 0x0, or 0x8000? */
  1012. if ((pkey & PKEY_LOW_15_MASK) == 0)
  1013. goto bad;
  1014. /*
  1015. * For the kernel contexts only, if a qp is passed into the function,
  1016. * the most likely matching pkey has index qp->s_pkey_index
  1017. */
  1018. if (!is_user_ctxt_mechanism &&
  1019. egress_pkey_matches_entry(pkey, ppd->pkeys[s_pkey_index])) {
  1020. return 0;
  1021. }
  1022. for (i = 0; i < MAX_PKEY_VALUES; i++) {
  1023. if (egress_pkey_matches_entry(pkey, ppd->pkeys[i]))
  1024. return 0;
  1025. }
  1026. bad:
  1027. /*
  1028. * For the user-context mechanism, the P_KEY check would only happen
  1029. * once per SDMA request, not once per packet. Therefore, there's no
  1030. * need to increment the counter for the user-context mechanism.
  1031. */
  1032. if (!is_user_ctxt_mechanism) {
  1033. incr_cntr64(&ppd->port_xmit_constraint_errors);
  1034. dd = ppd->dd;
  1035. if (!(dd->err_info_xmit_constraint.status &
  1036. OPA_EI_STATUS_SMASK)) {
  1037. dd->err_info_xmit_constraint.status |=
  1038. OPA_EI_STATUS_SMASK;
  1039. dd->err_info_xmit_constraint.slid = slid;
  1040. dd->err_info_xmit_constraint.pkey = pkey;
  1041. }
  1042. }
  1043. return 1;
  1044. }
  1045. /*
  1046. * get_send_routine - choose an egress routine
  1047. *
  1048. * Choose an egress routine based on QP type
  1049. * and size
  1050. */
  1051. static inline send_routine get_send_routine(struct rvt_qp *qp,
  1052. struct hfi1_pkt_state *ps)
  1053. {
  1054. struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  1055. struct hfi1_qp_priv *priv = qp->priv;
  1056. struct verbs_txreq *tx = ps->s_txreq;
  1057. if (unlikely(!(dd->flags & HFI1_HAS_SEND_DMA)))
  1058. return dd->process_pio_send;
  1059. switch (qp->ibqp.qp_type) {
  1060. case IB_QPT_SMI:
  1061. return dd->process_pio_send;
  1062. case IB_QPT_GSI:
  1063. case IB_QPT_UD:
  1064. break;
  1065. case IB_QPT_UC:
  1066. case IB_QPT_RC:
  1067. priv->s_running_pkt_size =
  1068. (tx->s_cur_size + priv->s_running_pkt_size) / 2;
  1069. if (piothreshold &&
  1070. priv->s_running_pkt_size <= min(piothreshold, qp->pmtu) &&
  1071. (BIT(ps->opcode & OPMASK) & pio_opmask[ps->opcode >> 5]) &&
  1072. iowait_sdma_pending(&priv->s_iowait) == 0 &&
  1073. !sdma_txreq_built(&tx->txreq))
  1074. return dd->process_pio_send;
  1075. break;
  1076. default:
  1077. break;
  1078. }
  1079. return dd->process_dma_send;
  1080. }
  1081. /**
  1082. * hfi1_verbs_send - send a packet
  1083. * @qp: the QP to send on
  1084. * @ps: the state of the packet to send
  1085. *
  1086. * Return zero if packet is sent or queued OK.
  1087. * Return non-zero and clear qp->s_flags RVT_S_BUSY otherwise.
  1088. */
  1089. int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
  1090. {
  1091. struct hfi1_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  1092. struct hfi1_qp_priv *priv = qp->priv;
  1093. struct ib_other_headers *ohdr = NULL;
  1094. send_routine sr;
  1095. int ret;
  1096. u16 pkey;
  1097. u32 slid;
  1098. u8 l4 = 0;
  1099. /* locate the pkey within the headers */
  1100. if (ps->s_txreq->phdr.hdr.hdr_type) {
  1101. struct hfi1_16b_header *hdr = &ps->s_txreq->phdr.hdr.opah;
  1102. l4 = hfi1_16B_get_l4(hdr);
  1103. if (l4 == OPA_16B_L4_IB_LOCAL)
  1104. ohdr = &hdr->u.oth;
  1105. else if (l4 == OPA_16B_L4_IB_GLOBAL)
  1106. ohdr = &hdr->u.l.oth;
  1107. slid = hfi1_16B_get_slid(hdr);
  1108. pkey = hfi1_16B_get_pkey(hdr);
  1109. } else {
  1110. struct ib_header *hdr = &ps->s_txreq->phdr.hdr.ibh;
  1111. u8 lnh = ib_get_lnh(hdr);
  1112. if (lnh == HFI1_LRH_GRH)
  1113. ohdr = &hdr->u.l.oth;
  1114. else
  1115. ohdr = &hdr->u.oth;
  1116. slid = ib_get_slid(hdr);
  1117. pkey = ib_bth_get_pkey(ohdr);
  1118. }
  1119. if (likely(l4 != OPA_16B_L4_FM))
  1120. ps->opcode = ib_bth_get_opcode(ohdr);
  1121. else
  1122. ps->opcode = IB_OPCODE_UD_SEND_ONLY;
  1123. sr = get_send_routine(qp, ps);
  1124. ret = egress_pkey_check(dd->pport, slid, pkey,
  1125. priv->s_sc, qp->s_pkey_index);
  1126. if (unlikely(ret)) {
  1127. /*
  1128. * The value we are returning here does not get propagated to
  1129. * the verbs caller. Thus we need to complete the request with
  1130. * error otherwise the caller could be sitting waiting on the
  1131. * completion event. Only do this for PIO. SDMA has its own
  1132. * mechanism for handling the errors. So for SDMA we can just
  1133. * return.
  1134. */
  1135. if (sr == dd->process_pio_send) {
  1136. unsigned long flags;
  1137. hfi1_cdbg(PIO, "%s() Failed. Completing with err",
  1138. __func__);
  1139. spin_lock_irqsave(&qp->s_lock, flags);
  1140. rvt_send_complete(qp, qp->s_wqe, IB_WC_GENERAL_ERR);
  1141. spin_unlock_irqrestore(&qp->s_lock, flags);
  1142. }
  1143. return -EINVAL;
  1144. }
  1145. if (sr == dd->process_dma_send && iowait_pio_pending(&priv->s_iowait))
  1146. return pio_wait(qp,
  1147. ps->s_txreq->psc,
  1148. ps,
  1149. HFI1_S_WAIT_PIO_DRAIN);
  1150. return sr(qp, ps, 0);
  1151. }
  1152. /**
  1153. * hfi1_fill_device_attr - Fill in rvt dev info device attributes.
  1154. * @dd: the device data structure
  1155. */
  1156. static void hfi1_fill_device_attr(struct hfi1_devdata *dd)
  1157. {
  1158. struct rvt_dev_info *rdi = &dd->verbs_dev.rdi;
  1159. u32 ver = dd->dc8051_ver;
  1160. memset(&rdi->dparms.props, 0, sizeof(rdi->dparms.props));
  1161. rdi->dparms.props.fw_ver = ((u64)(dc8051_ver_maj(ver)) << 32) |
  1162. ((u64)(dc8051_ver_min(ver)) << 16) |
  1163. (u64)dc8051_ver_patch(ver);
  1164. rdi->dparms.props.device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
  1165. IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
  1166. IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_RC_RNR_NAK_GEN |
  1167. IB_DEVICE_PORT_ACTIVE_EVENT | IB_DEVICE_SRQ_RESIZE |
  1168. IB_DEVICE_MEM_MGT_EXTENSIONS;
  1169. rdi->dparms.props.kernel_cap_flags = IBK_RDMA_NETDEV_OPA;
  1170. rdi->dparms.props.page_size_cap = PAGE_SIZE;
  1171. rdi->dparms.props.vendor_id = dd->oui1 << 16 | dd->oui2 << 8 | dd->oui3;
  1172. rdi->dparms.props.vendor_part_id = dd->pcidev->device;
  1173. rdi->dparms.props.hw_ver = dd->minrev;
  1174. rdi->dparms.props.sys_image_guid = ib_hfi1_sys_image_guid;
  1175. rdi->dparms.props.max_mr_size = U64_MAX;
  1176. rdi->dparms.props.max_fast_reg_page_list_len = UINT_MAX;
  1177. rdi->dparms.props.max_qp = hfi1_max_qps;
  1178. rdi->dparms.props.max_qp_wr =
  1179. (hfi1_max_qp_wrs >= HFI1_QP_WQE_INVALID ?
  1180. HFI1_QP_WQE_INVALID - 1 : hfi1_max_qp_wrs);
  1181. rdi->dparms.props.max_send_sge = hfi1_max_sges;
  1182. rdi->dparms.props.max_recv_sge = hfi1_max_sges;
  1183. rdi->dparms.props.max_sge_rd = hfi1_max_sges;
  1184. rdi->dparms.props.max_cq = hfi1_max_cqs;
  1185. rdi->dparms.props.max_ah = hfi1_max_ahs;
  1186. rdi->dparms.props.max_cqe = hfi1_max_cqes;
  1187. rdi->dparms.props.max_pd = hfi1_max_pds;
  1188. rdi->dparms.props.max_qp_rd_atom = HFI1_MAX_RDMA_ATOMIC;
  1189. rdi->dparms.props.max_qp_init_rd_atom = 255;
  1190. rdi->dparms.props.max_srq = hfi1_max_srqs;
  1191. rdi->dparms.props.max_srq_wr = hfi1_max_srq_wrs;
  1192. rdi->dparms.props.max_srq_sge = hfi1_max_srq_sges;
  1193. rdi->dparms.props.atomic_cap = IB_ATOMIC_GLOB;
  1194. rdi->dparms.props.max_pkeys = hfi1_get_npkeys(dd);
  1195. rdi->dparms.props.max_mcast_grp = hfi1_max_mcast_grps;
  1196. rdi->dparms.props.max_mcast_qp_attach = hfi1_max_mcast_qp_attached;
  1197. rdi->dparms.props.max_total_mcast_qp_attach =
  1198. rdi->dparms.props.max_mcast_qp_attach *
  1199. rdi->dparms.props.max_mcast_grp;
  1200. }
  1201. static inline u16 opa_speed_to_ib(u16 in)
  1202. {
  1203. u16 out = 0;
  1204. if (in & OPA_LINK_SPEED_25G)
  1205. out |= IB_SPEED_EDR;
  1206. if (in & OPA_LINK_SPEED_12_5G)
  1207. out |= IB_SPEED_FDR;
  1208. return out;
  1209. }
  1210. /*
  1211. * Convert a single OPA link width (no multiple flags) to an IB value.
  1212. * A zero OPA link width means link down, which means the IB width value
  1213. * is a don't care.
  1214. */
  1215. static inline u16 opa_width_to_ib(u16 in)
  1216. {
  1217. switch (in) {
  1218. case OPA_LINK_WIDTH_1X:
  1219. /* map 2x and 3x to 1x as they don't exist in IB */
  1220. case OPA_LINK_WIDTH_2X:
  1221. case OPA_LINK_WIDTH_3X:
  1222. return IB_WIDTH_1X;
  1223. default: /* link down or unknown, return our largest width */
  1224. case OPA_LINK_WIDTH_4X:
  1225. return IB_WIDTH_4X;
  1226. }
  1227. }
  1228. static int query_port(struct rvt_dev_info *rdi, u32 port_num,
  1229. struct ib_port_attr *props)
  1230. {
  1231. struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
  1232. struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
  1233. struct hfi1_pportdata *ppd = &dd->pport[port_num - 1];
  1234. u32 lid = ppd->lid;
  1235. /* props being zeroed by the caller, avoid zeroing it here */
  1236. props->lid = lid ? lid : 0;
  1237. props->lmc = ppd->lmc;
  1238. /* OPA logical states match IB logical states */
  1239. props->state = driver_lstate(ppd);
  1240. props->phys_state = driver_pstate(ppd);
  1241. props->gid_tbl_len = HFI1_GUIDS_PER_PORT;
  1242. props->active_width = (u8)opa_width_to_ib(ppd->link_width_active);
  1243. /* see rate_show() in ib core/sysfs.c */
  1244. props->active_speed = opa_speed_to_ib(ppd->link_speed_active);
  1245. props->max_vl_num = ppd->vls_supported;
  1246. /* Once we are a "first class" citizen and have added the OPA MTUs to
  1247. * the core we can advertise the larger MTU enum to the ULPs, for now
  1248. * advertise only 4K.
  1249. *
  1250. * Those applications which are either OPA aware or pass the MTU enum
  1251. * from the Path Records to us will get the new 8k MTU. Those that
  1252. * attempt to process the MTU enum may fail in various ways.
  1253. */
  1254. props->max_mtu = mtu_to_enum((!valid_ib_mtu(hfi1_max_mtu) ?
  1255. 4096 : hfi1_max_mtu), IB_MTU_4096);
  1256. props->active_mtu = !valid_ib_mtu(ppd->ibmtu) ? props->max_mtu :
  1257. mtu_to_enum(ppd->ibmtu, IB_MTU_4096);
  1258. props->phys_mtu = hfi1_max_mtu;
  1259. return 0;
  1260. }
  1261. static int modify_device(struct ib_device *device,
  1262. int device_modify_mask,
  1263. struct ib_device_modify *device_modify)
  1264. {
  1265. struct hfi1_devdata *dd = dd_from_ibdev(device);
  1266. unsigned i;
  1267. int ret;
  1268. if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
  1269. IB_DEVICE_MODIFY_NODE_DESC)) {
  1270. ret = -EOPNOTSUPP;
  1271. goto bail;
  1272. }
  1273. if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC) {
  1274. memcpy(device->node_desc, device_modify->node_desc,
  1275. IB_DEVICE_NODE_DESC_MAX);
  1276. for (i = 0; i < dd->num_pports; i++) {
  1277. struct hfi1_ibport *ibp = &dd->pport[i].ibport_data;
  1278. hfi1_node_desc_chg(ibp);
  1279. }
  1280. }
  1281. if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID) {
  1282. ib_hfi1_sys_image_guid =
  1283. cpu_to_be64(device_modify->sys_image_guid);
  1284. for (i = 0; i < dd->num_pports; i++) {
  1285. struct hfi1_ibport *ibp = &dd->pport[i].ibport_data;
  1286. hfi1_sys_guid_chg(ibp);
  1287. }
  1288. }
  1289. ret = 0;
  1290. bail:
  1291. return ret;
  1292. }
  1293. static int shut_down_port(struct rvt_dev_info *rdi, u32 port_num)
  1294. {
  1295. struct hfi1_ibdev *verbs_dev = dev_from_rdi(rdi);
  1296. struct hfi1_devdata *dd = dd_from_dev(verbs_dev);
  1297. struct hfi1_pportdata *ppd = &dd->pport[port_num - 1];
  1298. set_link_down_reason(ppd, OPA_LINKDOWN_REASON_UNKNOWN, 0,
  1299. OPA_LINKDOWN_REASON_UNKNOWN);
  1300. return set_link_state(ppd, HLS_DN_DOWNDEF);
  1301. }
  1302. static int hfi1_get_guid_be(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
  1303. int guid_index, __be64 *guid)
  1304. {
  1305. struct hfi1_ibport *ibp = container_of(rvp, struct hfi1_ibport, rvp);
  1306. if (guid_index >= HFI1_GUIDS_PER_PORT)
  1307. return -EINVAL;
  1308. *guid = get_sguid(ibp, guid_index);
  1309. return 0;
  1310. }
  1311. /*
  1312. * convert ah port,sl to sc
  1313. */
  1314. u8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah)
  1315. {
  1316. struct hfi1_ibport *ibp = to_iport(ibdev, rdma_ah_get_port_num(ah));
  1317. return ibp->sl_to_sc[rdma_ah_get_sl(ah)];
  1318. }
  1319. static int hfi1_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr)
  1320. {
  1321. struct hfi1_ibport *ibp;
  1322. struct hfi1_pportdata *ppd;
  1323. struct hfi1_devdata *dd;
  1324. u8 sc5;
  1325. u8 sl;
  1326. if (hfi1_check_mcast(rdma_ah_get_dlid(ah_attr)) &&
  1327. !(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH))
  1328. return -EINVAL;
  1329. /* test the mapping for validity */
  1330. ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
  1331. ppd = ppd_from_ibp(ibp);
  1332. dd = dd_from_ppd(ppd);
  1333. sl = rdma_ah_get_sl(ah_attr);
  1334. if (sl >= ARRAY_SIZE(ibp->sl_to_sc))
  1335. return -EINVAL;
  1336. sl = array_index_nospec(sl, ARRAY_SIZE(ibp->sl_to_sc));
  1337. sc5 = ibp->sl_to_sc[sl];
  1338. if (sc_to_vlt(dd, sc5) > num_vls && sc_to_vlt(dd, sc5) != 0xf)
  1339. return -EINVAL;
  1340. return 0;
  1341. }
  1342. static void hfi1_notify_new_ah(struct ib_device *ibdev,
  1343. struct rdma_ah_attr *ah_attr,
  1344. struct rvt_ah *ah)
  1345. {
  1346. struct hfi1_ibport *ibp;
  1347. struct hfi1_pportdata *ppd;
  1348. struct hfi1_devdata *dd;
  1349. u8 sc5;
  1350. struct rdma_ah_attr *attr = &ah->attr;
  1351. /*
  1352. * Do not trust reading anything from rvt_ah at this point as it is not
  1353. * done being setup. We can however modify things which we need to set.
  1354. */
  1355. ibp = to_iport(ibdev, rdma_ah_get_port_num(ah_attr));
  1356. ppd = ppd_from_ibp(ibp);
  1357. sc5 = ibp->sl_to_sc[rdma_ah_get_sl(&ah->attr)];
  1358. hfi1_update_ah_attr(ibdev, attr);
  1359. hfi1_make_opa_lid(attr);
  1360. dd = dd_from_ppd(ppd);
  1361. ah->vl = sc_to_vlt(dd, sc5);
  1362. if (ah->vl < num_vls || ah->vl == 15)
  1363. ah->log_pmtu = ilog2(dd->vld[ah->vl].mtu);
  1364. }
  1365. /**
  1366. * hfi1_get_npkeys - return the size of the PKEY table for context 0
  1367. * @dd: the hfi1_ib device
  1368. */
  1369. unsigned hfi1_get_npkeys(struct hfi1_devdata *dd)
  1370. {
  1371. return ARRAY_SIZE(dd->pport[0].pkeys);
  1372. }
  1373. static void init_ibport(struct hfi1_pportdata *ppd)
  1374. {
  1375. struct hfi1_ibport *ibp = &ppd->ibport_data;
  1376. size_t sz = ARRAY_SIZE(ibp->sl_to_sc);
  1377. int i;
  1378. for (i = 0; i < sz; i++) {
  1379. ibp->sl_to_sc[i] = i;
  1380. ibp->sc_to_sl[i] = i;
  1381. }
  1382. for (i = 0; i < RVT_MAX_TRAP_LISTS ; i++)
  1383. INIT_LIST_HEAD(&ibp->rvp.trap_lists[i].list);
  1384. timer_setup(&ibp->rvp.trap_timer, hfi1_handle_trap_timer, 0);
  1385. spin_lock_init(&ibp->rvp.lock);
  1386. /* Set the prefix to the default value (see ch. 4.1.1) */
  1387. ibp->rvp.gid_prefix = IB_DEFAULT_GID_PREFIX;
  1388. ibp->rvp.sm_lid = 0;
  1389. /*
  1390. * Below should only set bits defined in OPA PortInfo.CapabilityMask
  1391. * and PortInfo.CapabilityMask3
  1392. */
  1393. ibp->rvp.port_cap_flags = IB_PORT_AUTO_MIGR_SUP |
  1394. IB_PORT_CAP_MASK_NOTICE_SUP;
  1395. ibp->rvp.port_cap3_flags = OPA_CAP_MASK3_IsSharedSpaceSupported;
  1396. ibp->rvp.pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
  1397. ibp->rvp.pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
  1398. ibp->rvp.pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
  1399. ibp->rvp.pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
  1400. ibp->rvp.pma_counter_select[4] = IB_PMA_PORT_XMIT_WAIT;
  1401. RCU_INIT_POINTER(ibp->rvp.qp[0], NULL);
  1402. RCU_INIT_POINTER(ibp->rvp.qp[1], NULL);
  1403. }
  1404. static void hfi1_get_dev_fw_str(struct ib_device *ibdev, char *str)
  1405. {
  1406. struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
  1407. struct hfi1_ibdev *dev = dev_from_rdi(rdi);
  1408. u32 ver = dd_from_dev(dev)->dc8051_ver;
  1409. snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u", dc8051_ver_maj(ver),
  1410. dc8051_ver_min(ver), dc8051_ver_patch(ver));
  1411. }
  1412. static const char * const driver_cntr_names[] = {
  1413. /* must be element 0*/
  1414. "DRIVER_KernIntr",
  1415. "DRIVER_ErrorIntr",
  1416. "DRIVER_Tx_Errs",
  1417. "DRIVER_Rcv_Errs",
  1418. "DRIVER_HW_Errs",
  1419. "DRIVER_NoPIOBufs",
  1420. "DRIVER_CtxtsOpen",
  1421. "DRIVER_RcvLen_Errs",
  1422. "DRIVER_EgrBufFull",
  1423. "DRIVER_EgrHdrFull"
  1424. };
  1425. static DEFINE_MUTEX(cntr_names_lock); /* protects the *_cntr_names bufers */
  1426. static struct rdma_stat_desc *dev_cntr_descs;
  1427. static struct rdma_stat_desc *port_cntr_descs;
  1428. int num_driver_cntrs = ARRAY_SIZE(driver_cntr_names);
  1429. static int num_dev_cntrs;
  1430. static int num_port_cntrs;
  1431. static int cntr_names_initialized;
  1432. /*
  1433. * Convert a list of names separated by '\n' into an array of NULL terminated
  1434. * strings. Optionally some entries can be reserved in the array to hold extra
  1435. * external strings.
  1436. */
  1437. static int init_cntr_names(const char *names_in, const size_t names_len,
  1438. int num_extra_names, int *num_cntrs,
  1439. struct rdma_stat_desc **cntr_descs)
  1440. {
  1441. struct rdma_stat_desc *q;
  1442. char *names_out, *p;
  1443. int i, n;
  1444. n = 0;
  1445. for (i = 0; i < names_len; i++)
  1446. if (names_in[i] == '\n')
  1447. n++;
  1448. names_out =
  1449. kzalloc((n + num_extra_names) * sizeof(*q) + names_len,
  1450. GFP_KERNEL);
  1451. if (!names_out) {
  1452. *num_cntrs = 0;
  1453. *cntr_descs = NULL;
  1454. return -ENOMEM;
  1455. }
  1456. p = names_out + (n + num_extra_names) * sizeof(*q);
  1457. memcpy(p, names_in, names_len);
  1458. q = (struct rdma_stat_desc *)names_out;
  1459. for (i = 0; i < n; i++) {
  1460. q[i].name = p;
  1461. p = strchr(p, '\n');
  1462. *p++ = '\0';
  1463. }
  1464. *num_cntrs = n;
  1465. *cntr_descs = (struct rdma_stat_desc *)names_out;
  1466. return 0;
  1467. }
  1468. static int init_counters(struct ib_device *ibdev)
  1469. {
  1470. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1471. int i, err = 0;
  1472. mutex_lock(&cntr_names_lock);
  1473. if (cntr_names_initialized)
  1474. goto out_unlock;
  1475. err = init_cntr_names(dd->cntrnames, dd->cntrnameslen, num_driver_cntrs,
  1476. &num_dev_cntrs, &dev_cntr_descs);
  1477. if (err)
  1478. goto out_unlock;
  1479. for (i = 0; i < num_driver_cntrs; i++)
  1480. dev_cntr_descs[num_dev_cntrs + i].name = driver_cntr_names[i];
  1481. err = init_cntr_names(dd->portcntrnames, dd->portcntrnameslen, 0,
  1482. &num_port_cntrs, &port_cntr_descs);
  1483. if (err) {
  1484. kfree(dev_cntr_descs);
  1485. dev_cntr_descs = NULL;
  1486. goto out_unlock;
  1487. }
  1488. cntr_names_initialized = 1;
  1489. out_unlock:
  1490. mutex_unlock(&cntr_names_lock);
  1491. return err;
  1492. }
  1493. static struct rdma_hw_stats *hfi1_alloc_hw_device_stats(struct ib_device *ibdev)
  1494. {
  1495. if (init_counters(ibdev))
  1496. return NULL;
  1497. return rdma_alloc_hw_stats_struct(dev_cntr_descs,
  1498. num_dev_cntrs + num_driver_cntrs,
  1499. RDMA_HW_STATS_DEFAULT_LIFESPAN);
  1500. }
  1501. static struct rdma_hw_stats *hfi_alloc_hw_port_stats(struct ib_device *ibdev,
  1502. u32 port_num)
  1503. {
  1504. if (init_counters(ibdev))
  1505. return NULL;
  1506. return rdma_alloc_hw_stats_struct(port_cntr_descs, num_port_cntrs,
  1507. RDMA_HW_STATS_DEFAULT_LIFESPAN);
  1508. }
  1509. static u64 hfi1_sps_ints(void)
  1510. {
  1511. unsigned long index, flags;
  1512. struct hfi1_devdata *dd;
  1513. u64 sps_ints = 0;
  1514. xa_lock_irqsave(&hfi1_dev_table, flags);
  1515. xa_for_each(&hfi1_dev_table, index, dd) {
  1516. sps_ints += get_all_cpu_total(dd->int_counter);
  1517. }
  1518. xa_unlock_irqrestore(&hfi1_dev_table, flags);
  1519. return sps_ints;
  1520. }
  1521. static int get_hw_stats(struct ib_device *ibdev, struct rdma_hw_stats *stats,
  1522. u32 port, int index)
  1523. {
  1524. u64 *values;
  1525. int count;
  1526. if (!port) {
  1527. u64 *stats = (u64 *)&hfi1_stats;
  1528. int i;
  1529. hfi1_read_cntrs(dd_from_ibdev(ibdev), NULL, &values);
  1530. values[num_dev_cntrs] = hfi1_sps_ints();
  1531. for (i = 1; i < num_driver_cntrs; i++)
  1532. values[num_dev_cntrs + i] = stats[i];
  1533. count = num_dev_cntrs + num_driver_cntrs;
  1534. } else {
  1535. struct hfi1_ibport *ibp = to_iport(ibdev, port);
  1536. hfi1_read_portcntrs(ppd_from_ibp(ibp), NULL, &values);
  1537. count = num_port_cntrs;
  1538. }
  1539. memcpy(stats->value, values, count * sizeof(u64));
  1540. return count;
  1541. }
  1542. static const struct ib_device_ops hfi1_dev_ops = {
  1543. .owner = THIS_MODULE,
  1544. .driver_id = RDMA_DRIVER_HFI1,
  1545. .alloc_hw_device_stats = hfi1_alloc_hw_device_stats,
  1546. .alloc_hw_port_stats = hfi_alloc_hw_port_stats,
  1547. .alloc_rdma_netdev = hfi1_vnic_alloc_rn,
  1548. .device_group = &ib_hfi1_attr_group,
  1549. .get_dev_fw_str = hfi1_get_dev_fw_str,
  1550. .get_hw_stats = get_hw_stats,
  1551. .modify_device = modify_device,
  1552. .port_groups = hfi1_attr_port_groups,
  1553. /* keep process mad in the driver */
  1554. .process_mad = hfi1_process_mad,
  1555. .rdma_netdev_get_params = hfi1_ipoib_rn_get_params,
  1556. };
  1557. /**
  1558. * hfi1_register_ib_device - register our device with the infiniband core
  1559. * @dd: the device data structure
  1560. * Return 0 if successful, errno if unsuccessful.
  1561. */
  1562. int hfi1_register_ib_device(struct hfi1_devdata *dd)
  1563. {
  1564. struct hfi1_ibdev *dev = &dd->verbs_dev;
  1565. struct ib_device *ibdev = &dev->rdi.ibdev;
  1566. struct hfi1_pportdata *ppd = dd->pport;
  1567. struct hfi1_ibport *ibp = &ppd->ibport_data;
  1568. unsigned i;
  1569. int ret;
  1570. for (i = 0; i < dd->num_pports; i++)
  1571. init_ibport(ppd + i);
  1572. /* Only need to initialize non-zero fields. */
  1573. timer_setup(&dev->mem_timer, mem_timer, 0);
  1574. seqlock_init(&dev->iowait_lock);
  1575. seqlock_init(&dev->txwait_lock);
  1576. INIT_LIST_HEAD(&dev->txwait);
  1577. INIT_LIST_HEAD(&dev->memwait);
  1578. ret = verbs_txreq_init(dev);
  1579. if (ret)
  1580. goto err_verbs_txreq;
  1581. /* Use first-port GUID as node guid */
  1582. ibdev->node_guid = get_sguid(ibp, HFI1_PORT_GUID_INDEX);
  1583. /*
  1584. * The system image GUID is supposed to be the same for all
  1585. * HFIs in a single system but since there can be other
  1586. * device types in the system, we can't be sure this is unique.
  1587. */
  1588. if (!ib_hfi1_sys_image_guid)
  1589. ib_hfi1_sys_image_guid = ibdev->node_guid;
  1590. ibdev->phys_port_cnt = dd->num_pports;
  1591. ibdev->dev.parent = &dd->pcidev->dev;
  1592. ib_set_device_ops(ibdev, &hfi1_dev_ops);
  1593. strscpy(ibdev->node_desc, init_utsname()->nodename,
  1594. sizeof(ibdev->node_desc));
  1595. /*
  1596. * Fill in rvt info object.
  1597. */
  1598. dd->verbs_dev.rdi.driver_f.get_pci_dev = get_pci_dev;
  1599. dd->verbs_dev.rdi.driver_f.check_ah = hfi1_check_ah;
  1600. dd->verbs_dev.rdi.driver_f.notify_new_ah = hfi1_notify_new_ah;
  1601. dd->verbs_dev.rdi.driver_f.get_guid_be = hfi1_get_guid_be;
  1602. dd->verbs_dev.rdi.driver_f.query_port_state = query_port;
  1603. dd->verbs_dev.rdi.driver_f.shut_down_port = shut_down_port;
  1604. dd->verbs_dev.rdi.driver_f.cap_mask_chg = hfi1_cap_mask_chg;
  1605. /*
  1606. * Fill in rvt info device attributes.
  1607. */
  1608. hfi1_fill_device_attr(dd);
  1609. /* queue pair */
  1610. dd->verbs_dev.rdi.dparms.qp_table_size = hfi1_qp_table_size;
  1611. dd->verbs_dev.rdi.dparms.qpn_start = 0;
  1612. dd->verbs_dev.rdi.dparms.qpn_inc = 1;
  1613. dd->verbs_dev.rdi.dparms.qos_shift = dd->qos_shift;
  1614. dd->verbs_dev.rdi.dparms.qpn_res_start = RVT_KDETH_QP_BASE;
  1615. dd->verbs_dev.rdi.dparms.qpn_res_end = RVT_AIP_QP_MAX;
  1616. dd->verbs_dev.rdi.dparms.max_rdma_atomic = HFI1_MAX_RDMA_ATOMIC;
  1617. dd->verbs_dev.rdi.dparms.psn_mask = PSN_MASK;
  1618. dd->verbs_dev.rdi.dparms.psn_shift = PSN_SHIFT;
  1619. dd->verbs_dev.rdi.dparms.psn_modify_mask = PSN_MODIFY_MASK;
  1620. dd->verbs_dev.rdi.dparms.core_cap_flags = RDMA_CORE_PORT_INTEL_OPA |
  1621. RDMA_CORE_CAP_OPA_AH;
  1622. dd->verbs_dev.rdi.dparms.max_mad_size = OPA_MGMT_MAD_SIZE;
  1623. dd->verbs_dev.rdi.driver_f.qp_priv_alloc = qp_priv_alloc;
  1624. dd->verbs_dev.rdi.driver_f.qp_priv_init = hfi1_qp_priv_init;
  1625. dd->verbs_dev.rdi.driver_f.qp_priv_free = qp_priv_free;
  1626. dd->verbs_dev.rdi.driver_f.free_all_qps = free_all_qps;
  1627. dd->verbs_dev.rdi.driver_f.notify_qp_reset = notify_qp_reset;
  1628. dd->verbs_dev.rdi.driver_f.do_send = hfi1_do_send_from_rvt;
  1629. dd->verbs_dev.rdi.driver_f.schedule_send = hfi1_schedule_send;
  1630. dd->verbs_dev.rdi.driver_f.schedule_send_no_lock = _hfi1_schedule_send;
  1631. dd->verbs_dev.rdi.driver_f.get_pmtu_from_attr = get_pmtu_from_attr;
  1632. dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp;
  1633. dd->verbs_dev.rdi.driver_f.flush_qp_waiters = flush_qp_waiters;
  1634. dd->verbs_dev.rdi.driver_f.stop_send_queue = stop_send_queue;
  1635. dd->verbs_dev.rdi.driver_f.quiesce_qp = quiesce_qp;
  1636. dd->verbs_dev.rdi.driver_f.notify_error_qp = notify_error_qp;
  1637. dd->verbs_dev.rdi.driver_f.mtu_from_qp = mtu_from_qp;
  1638. dd->verbs_dev.rdi.driver_f.mtu_to_path_mtu = mtu_to_path_mtu;
  1639. dd->verbs_dev.rdi.driver_f.check_modify_qp = hfi1_check_modify_qp;
  1640. dd->verbs_dev.rdi.driver_f.modify_qp = hfi1_modify_qp;
  1641. dd->verbs_dev.rdi.driver_f.notify_restart_rc = hfi1_restart_rc;
  1642. dd->verbs_dev.rdi.driver_f.setup_wqe = hfi1_setup_wqe;
  1643. dd->verbs_dev.rdi.driver_f.comp_vect_cpu_lookup =
  1644. hfi1_comp_vect_mappings_lookup;
  1645. /* completeion queue */
  1646. dd->verbs_dev.rdi.ibdev.num_comp_vectors = dd->comp_vect_possible_cpus;
  1647. dd->verbs_dev.rdi.dparms.node = dd->node;
  1648. /* misc settings */
  1649. dd->verbs_dev.rdi.flags = 0; /* Let rdmavt handle it all */
  1650. dd->verbs_dev.rdi.dparms.lkey_table_size = hfi1_lkey_table_size;
  1651. dd->verbs_dev.rdi.dparms.nports = dd->num_pports;
  1652. dd->verbs_dev.rdi.dparms.npkeys = hfi1_get_npkeys(dd);
  1653. dd->verbs_dev.rdi.dparms.sge_copy_mode = sge_copy_mode;
  1654. dd->verbs_dev.rdi.dparms.wss_threshold = wss_threshold;
  1655. dd->verbs_dev.rdi.dparms.wss_clean_period = wss_clean_period;
  1656. dd->verbs_dev.rdi.dparms.reserved_operations = 1;
  1657. dd->verbs_dev.rdi.dparms.extra_rdma_atomic = HFI1_TID_RDMA_WRITE_CNT;
  1658. /* post send table */
  1659. dd->verbs_dev.rdi.post_parms = hfi1_post_parms;
  1660. /* opcode translation table */
  1661. dd->verbs_dev.rdi.wc_opcode = ib_hfi1_wc_opcode;
  1662. ppd = dd->pport;
  1663. for (i = 0; i < dd->num_pports; i++, ppd++)
  1664. rvt_init_port(&dd->verbs_dev.rdi,
  1665. &ppd->ibport_data.rvp,
  1666. i,
  1667. ppd->pkeys);
  1668. ret = rvt_register_device(&dd->verbs_dev.rdi);
  1669. if (ret)
  1670. goto err_verbs_txreq;
  1671. ret = hfi1_verbs_register_sysfs(dd);
  1672. if (ret)
  1673. goto err_class;
  1674. return ret;
  1675. err_class:
  1676. rvt_unregister_device(&dd->verbs_dev.rdi);
  1677. err_verbs_txreq:
  1678. verbs_txreq_exit(dev);
  1679. dd_dev_err(dd, "cannot register verbs: %d!\n", -ret);
  1680. return ret;
  1681. }
  1682. void hfi1_unregister_ib_device(struct hfi1_devdata *dd)
  1683. {
  1684. struct hfi1_ibdev *dev = &dd->verbs_dev;
  1685. hfi1_verbs_unregister_sysfs(dd);
  1686. rvt_unregister_device(&dd->verbs_dev.rdi);
  1687. if (!list_empty(&dev->txwait))
  1688. dd_dev_err(dd, "txwait list not empty!\n");
  1689. if (!list_empty(&dev->memwait))
  1690. dd_dev_err(dd, "memwait list not empty!\n");
  1691. del_timer_sync(&dev->mem_timer);
  1692. verbs_txreq_exit(dev);
  1693. mutex_lock(&cntr_names_lock);
  1694. kfree(dev_cntr_descs);
  1695. kfree(port_cntr_descs);
  1696. dev_cntr_descs = NULL;
  1697. port_cntr_descs = NULL;
  1698. cntr_names_initialized = 0;
  1699. mutex_unlock(&cntr_names_lock);
  1700. }
  1701. void hfi1_cnp_rcv(struct hfi1_packet *packet)
  1702. {
  1703. struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd);
  1704. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  1705. struct ib_header *hdr = packet->hdr;
  1706. struct rvt_qp *qp = packet->qp;
  1707. u32 lqpn, rqpn = 0;
  1708. u16 rlid = 0;
  1709. u8 sl, sc5, svc_type;
  1710. switch (packet->qp->ibqp.qp_type) {
  1711. case IB_QPT_UC:
  1712. rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
  1713. rqpn = qp->remote_qpn;
  1714. svc_type = IB_CC_SVCTYPE_UC;
  1715. break;
  1716. case IB_QPT_RC:
  1717. rlid = rdma_ah_get_dlid(&qp->remote_ah_attr);
  1718. rqpn = qp->remote_qpn;
  1719. svc_type = IB_CC_SVCTYPE_RC;
  1720. break;
  1721. case IB_QPT_SMI:
  1722. case IB_QPT_GSI:
  1723. case IB_QPT_UD:
  1724. svc_type = IB_CC_SVCTYPE_UD;
  1725. break;
  1726. default:
  1727. ibp->rvp.n_pkt_drops++;
  1728. return;
  1729. }
  1730. sc5 = hfi1_9B_get_sc5(hdr, packet->rhf);
  1731. sl = ibp->sc_to_sl[sc5];
  1732. lqpn = qp->ibqp.qp_num;
  1733. process_becn(ppd, sl, rlid, lqpn, rqpn, svc_type);
  1734. }