verbs.c 58 KB

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