verbs.c 58 KB

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