qed_roce.c 87 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/types.h>
  33. #include <asm/byteorder.h>
  34. #include <linux/bitops.h>
  35. #include <linux/delay.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/errno.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/if_ether.h>
  40. #include <linux/if_vlan.h>
  41. #include <linux/io.h>
  42. #include <linux/ip.h>
  43. #include <linux/ipv6.h>
  44. #include <linux/kernel.h>
  45. #include <linux/list.h>
  46. #include <linux/module.h>
  47. #include <linux/mutex.h>
  48. #include <linux/pci.h>
  49. #include <linux/slab.h>
  50. #include <linux/spinlock.h>
  51. #include <linux/string.h>
  52. #include <linux/tcp.h>
  53. #include <linux/bitops.h>
  54. #include <linux/qed/qed_roce_if.h>
  55. #include <linux/qed/qed_roce_if.h>
  56. #include "qed.h"
  57. #include "qed_cxt.h"
  58. #include "qed_hsi.h"
  59. #include "qed_hw.h"
  60. #include "qed_init_ops.h"
  61. #include "qed_int.h"
  62. #include "qed_ll2.h"
  63. #include "qed_mcp.h"
  64. #include "qed_reg_addr.h"
  65. #include "qed_sp.h"
  66. #include "qed_roce.h"
  67. #include "qed_ll2.h"
  68. static void qed_roce_free_real_icid(struct qed_hwfn *p_hwfn, u16 icid);
  69. void qed_roce_async_event(struct qed_hwfn *p_hwfn,
  70. u8 fw_event_code, union rdma_eqe_data *rdma_data)
  71. {
  72. if (fw_event_code == ROCE_ASYNC_EVENT_DESTROY_QP_DONE) {
  73. u16 icid =
  74. (u16)le32_to_cpu(rdma_data->rdma_destroy_qp_data.cid);
  75. /* icid release in this async event can occur only if the icid
  76. * was offloaded to the FW. In case it wasn't offloaded this is
  77. * handled in qed_roce_sp_destroy_qp.
  78. */
  79. qed_roce_free_real_icid(p_hwfn, icid);
  80. } else {
  81. struct qed_rdma_events *events = &p_hwfn->p_rdma_info->events;
  82. events->affiliated_event(p_hwfn->p_rdma_info->events.context,
  83. fw_event_code,
  84. &rdma_data->async_handle);
  85. }
  86. }
  87. static int qed_rdma_bmap_alloc(struct qed_hwfn *p_hwfn,
  88. struct qed_bmap *bmap, u32 max_count, char *name)
  89. {
  90. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "max_count = %08x\n", max_count);
  91. bmap->max_count = max_count;
  92. bmap->bitmap = kzalloc(BITS_TO_LONGS(max_count) * sizeof(long),
  93. GFP_KERNEL);
  94. if (!bmap->bitmap) {
  95. DP_NOTICE(p_hwfn,
  96. "qed bmap alloc failed: cannot allocate memory (bitmap)\n");
  97. return -ENOMEM;
  98. }
  99. snprintf(bmap->name, QED_RDMA_MAX_BMAP_NAME, "%s", name);
  100. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "0\n");
  101. return 0;
  102. }
  103. static int qed_rdma_bmap_alloc_id(struct qed_hwfn *p_hwfn,
  104. struct qed_bmap *bmap, u32 *id_num)
  105. {
  106. *id_num = find_first_zero_bit(bmap->bitmap, bmap->max_count);
  107. if (*id_num >= bmap->max_count)
  108. return -EINVAL;
  109. __set_bit(*id_num, bmap->bitmap);
  110. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: allocated id %d\n",
  111. bmap->name, *id_num);
  112. return 0;
  113. }
  114. static void qed_bmap_set_id(struct qed_hwfn *p_hwfn,
  115. struct qed_bmap *bmap, u32 id_num)
  116. {
  117. if (id_num >= bmap->max_count)
  118. return;
  119. __set_bit(id_num, bmap->bitmap);
  120. }
  121. static void qed_bmap_release_id(struct qed_hwfn *p_hwfn,
  122. struct qed_bmap *bmap, u32 id_num)
  123. {
  124. bool b_acquired;
  125. if (id_num >= bmap->max_count)
  126. return;
  127. b_acquired = test_and_clear_bit(id_num, bmap->bitmap);
  128. if (!b_acquired) {
  129. DP_NOTICE(p_hwfn, "%s bitmap: id %d already released\n",
  130. bmap->name, id_num);
  131. return;
  132. }
  133. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: released id %d\n",
  134. bmap->name, id_num);
  135. }
  136. static int qed_bmap_test_id(struct qed_hwfn *p_hwfn,
  137. struct qed_bmap *bmap, u32 id_num)
  138. {
  139. if (id_num >= bmap->max_count)
  140. return -1;
  141. return test_bit(id_num, bmap->bitmap);
  142. }
  143. static u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id)
  144. {
  145. /* First sb id for RoCE is after all the l2 sb */
  146. return FEAT_NUM((struct qed_hwfn *)p_hwfn, QED_PF_L2_QUE) + rel_sb_id;
  147. }
  148. static int qed_rdma_alloc(struct qed_hwfn *p_hwfn,
  149. struct qed_ptt *p_ptt,
  150. struct qed_rdma_start_in_params *params)
  151. {
  152. struct qed_rdma_info *p_rdma_info;
  153. u32 num_cons, num_tasks;
  154. int rc = -ENOMEM;
  155. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocating RDMA\n");
  156. /* Allocate a struct with current pf rdma info */
  157. p_rdma_info = kzalloc(sizeof(*p_rdma_info), GFP_KERNEL);
  158. if (!p_rdma_info) {
  159. DP_NOTICE(p_hwfn,
  160. "qed rdma alloc failed: cannot allocate memory (rdma info). rc = %d\n",
  161. rc);
  162. return rc;
  163. }
  164. p_hwfn->p_rdma_info = p_rdma_info;
  165. p_rdma_info->proto = PROTOCOLID_ROCE;
  166. num_cons = qed_cxt_get_proto_cid_count(p_hwfn, p_rdma_info->proto,
  167. NULL);
  168. p_rdma_info->num_qps = num_cons / 2;
  169. num_tasks = qed_cxt_get_proto_tid_count(p_hwfn, PROTOCOLID_ROCE);
  170. /* Each MR uses a single task */
  171. p_rdma_info->num_mrs = num_tasks;
  172. /* Queue zone lines are shared between RoCE and L2 in such a way that
  173. * they can be used by each without obstructing the other.
  174. */
  175. p_rdma_info->queue_zone_base = (u16)RESC_START(p_hwfn, QED_L2_QUEUE);
  176. p_rdma_info->max_queue_zones = (u16)RESC_NUM(p_hwfn, QED_L2_QUEUE);
  177. /* Allocate a struct with device params and fill it */
  178. p_rdma_info->dev = kzalloc(sizeof(*p_rdma_info->dev), GFP_KERNEL);
  179. if (!p_rdma_info->dev) {
  180. DP_NOTICE(p_hwfn,
  181. "qed rdma alloc failed: cannot allocate memory (rdma info dev). rc = %d\n",
  182. rc);
  183. goto free_rdma_info;
  184. }
  185. /* Allocate a struct with port params and fill it */
  186. p_rdma_info->port = kzalloc(sizeof(*p_rdma_info->port), GFP_KERNEL);
  187. if (!p_rdma_info->port) {
  188. DP_NOTICE(p_hwfn,
  189. "qed rdma alloc failed: cannot allocate memory (rdma info port). rc = %d\n",
  190. rc);
  191. goto free_rdma_dev;
  192. }
  193. /* Allocate bit map for pd's */
  194. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->pd_map, RDMA_MAX_PDS,
  195. "PD");
  196. if (rc) {
  197. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  198. "Failed to allocate pd_map, rc = %d\n",
  199. rc);
  200. goto free_rdma_port;
  201. }
  202. /* Allocate DPI bitmap */
  203. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->dpi_map,
  204. p_hwfn->dpi_count, "DPI");
  205. if (rc) {
  206. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  207. "Failed to allocate DPI bitmap, rc = %d\n", rc);
  208. goto free_pd_map;
  209. }
  210. /* Allocate bitmap for cq's. The maximum number of CQs is bounded to
  211. * twice the number of QPs.
  212. */
  213. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cq_map,
  214. p_rdma_info->num_qps * 2, "CQ");
  215. if (rc) {
  216. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  217. "Failed to allocate cq bitmap, rc = %d\n", rc);
  218. goto free_dpi_map;
  219. }
  220. /* Allocate bitmap for toggle bit for cq icids
  221. * We toggle the bit every time we create or resize cq for a given icid.
  222. * The maximum number of CQs is bounded to twice the number of QPs.
  223. */
  224. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->toggle_bits,
  225. p_rdma_info->num_qps * 2, "Toggle");
  226. if (rc) {
  227. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  228. "Failed to allocate toogle bits, rc = %d\n", rc);
  229. goto free_cq_map;
  230. }
  231. /* Allocate bitmap for itids */
  232. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->tid_map,
  233. p_rdma_info->num_mrs, "MR");
  234. if (rc) {
  235. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  236. "Failed to allocate itids bitmaps, rc = %d\n", rc);
  237. goto free_toggle_map;
  238. }
  239. /* Allocate bitmap for cids used for qps. */
  240. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cid_map, num_cons,
  241. "CID");
  242. if (rc) {
  243. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  244. "Failed to allocate cid bitmap, rc = %d\n", rc);
  245. goto free_tid_map;
  246. }
  247. /* Allocate bitmap for cids used for responders/requesters. */
  248. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->real_cid_map, num_cons,
  249. "REAL_CID");
  250. if (rc) {
  251. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  252. "Failed to allocate real cid bitmap, rc = %d\n", rc);
  253. goto free_cid_map;
  254. }
  255. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocation successful\n");
  256. return 0;
  257. free_cid_map:
  258. kfree(p_rdma_info->cid_map.bitmap);
  259. free_tid_map:
  260. kfree(p_rdma_info->tid_map.bitmap);
  261. free_toggle_map:
  262. kfree(p_rdma_info->toggle_bits.bitmap);
  263. free_cq_map:
  264. kfree(p_rdma_info->cq_map.bitmap);
  265. free_dpi_map:
  266. kfree(p_rdma_info->dpi_map.bitmap);
  267. free_pd_map:
  268. kfree(p_rdma_info->pd_map.bitmap);
  269. free_rdma_port:
  270. kfree(p_rdma_info->port);
  271. free_rdma_dev:
  272. kfree(p_rdma_info->dev);
  273. free_rdma_info:
  274. kfree(p_rdma_info);
  275. return rc;
  276. }
  277. static void qed_rdma_bmap_free(struct qed_hwfn *p_hwfn,
  278. struct qed_bmap *bmap, bool check)
  279. {
  280. int weight = bitmap_weight(bmap->bitmap, bmap->max_count);
  281. int last_line = bmap->max_count / (64 * 8);
  282. int last_item = last_line * 8 +
  283. DIV_ROUND_UP(bmap->max_count % (64 * 8), 64);
  284. u64 *pmap = (u64 *)bmap->bitmap;
  285. int line, item, offset;
  286. u8 str_last_line[200] = { 0 };
  287. if (!weight || !check)
  288. goto end;
  289. DP_NOTICE(p_hwfn,
  290. "%s bitmap not free - size=%d, weight=%d, 512 bits per line\n",
  291. bmap->name, bmap->max_count, weight);
  292. /* print aligned non-zero lines, if any */
  293. for (item = 0, line = 0; line < last_line; line++, item += 8)
  294. if (bitmap_weight((unsigned long *)&pmap[item], 64 * 8))
  295. DP_NOTICE(p_hwfn,
  296. "line 0x%04x: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
  297. line,
  298. pmap[item],
  299. pmap[item + 1],
  300. pmap[item + 2],
  301. pmap[item + 3],
  302. pmap[item + 4],
  303. pmap[item + 5],
  304. pmap[item + 6], pmap[item + 7]);
  305. /* print last unaligned non-zero line, if any */
  306. if ((bmap->max_count % (64 * 8)) &&
  307. (bitmap_weight((unsigned long *)&pmap[item],
  308. bmap->max_count - item * 64))) {
  309. offset = sprintf(str_last_line, "line 0x%04x: ", line);
  310. for (; item < last_item; item++)
  311. offset += sprintf(str_last_line + offset,
  312. "0x%016llx ", pmap[item]);
  313. DP_NOTICE(p_hwfn, "%s\n", str_last_line);
  314. }
  315. end:
  316. kfree(bmap->bitmap);
  317. bmap->bitmap = NULL;
  318. }
  319. static void qed_rdma_resc_free(struct qed_hwfn *p_hwfn)
  320. {
  321. struct qed_bmap *rcid_map = &p_hwfn->p_rdma_info->real_cid_map;
  322. struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
  323. int wait_count = 0;
  324. /* when destroying a_RoCE QP the control is returned to the user after
  325. * the synchronous part. The asynchronous part may take a little longer.
  326. * We delay for a short while if an async destroy QP is still expected.
  327. * Beyond the added delay we clear the bitmap anyway.
  328. */
  329. while (bitmap_weight(rcid_map->bitmap, rcid_map->max_count)) {
  330. msleep(100);
  331. if (wait_count++ > 20) {
  332. DP_NOTICE(p_hwfn, "cid bitmap wait timed out\n");
  333. break;
  334. }
  335. }
  336. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cid_map, 1);
  337. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->pd_map, 1);
  338. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, 1);
  339. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cq_map, 1);
  340. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->toggle_bits, 0);
  341. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tid_map, 1);
  342. kfree(p_rdma_info->port);
  343. kfree(p_rdma_info->dev);
  344. kfree(p_rdma_info);
  345. }
  346. static void qed_rdma_free(struct qed_hwfn *p_hwfn)
  347. {
  348. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Freeing RDMA\n");
  349. qed_rdma_resc_free(p_hwfn);
  350. }
  351. static void qed_rdma_get_guid(struct qed_hwfn *p_hwfn, u8 *guid)
  352. {
  353. guid[0] = p_hwfn->hw_info.hw_mac_addr[0] ^ 2;
  354. guid[1] = p_hwfn->hw_info.hw_mac_addr[1];
  355. guid[2] = p_hwfn->hw_info.hw_mac_addr[2];
  356. guid[3] = 0xff;
  357. guid[4] = 0xfe;
  358. guid[5] = p_hwfn->hw_info.hw_mac_addr[3];
  359. guid[6] = p_hwfn->hw_info.hw_mac_addr[4];
  360. guid[7] = p_hwfn->hw_info.hw_mac_addr[5];
  361. }
  362. static void qed_rdma_init_events(struct qed_hwfn *p_hwfn,
  363. struct qed_rdma_start_in_params *params)
  364. {
  365. struct qed_rdma_events *events;
  366. events = &p_hwfn->p_rdma_info->events;
  367. events->unaffiliated_event = params->events->unaffiliated_event;
  368. events->affiliated_event = params->events->affiliated_event;
  369. events->context = params->events->context;
  370. }
  371. static void qed_rdma_init_devinfo(struct qed_hwfn *p_hwfn,
  372. struct qed_rdma_start_in_params *params)
  373. {
  374. struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
  375. struct qed_dev *cdev = p_hwfn->cdev;
  376. u32 pci_status_control;
  377. u32 num_qps;
  378. /* Vendor specific information */
  379. dev->vendor_id = cdev->vendor_id;
  380. dev->vendor_part_id = cdev->device_id;
  381. dev->hw_ver = 0;
  382. dev->fw_ver = (FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) |
  383. (FW_REVISION_VERSION << 8) | (FW_ENGINEERING_VERSION);
  384. qed_rdma_get_guid(p_hwfn, (u8 *)&dev->sys_image_guid);
  385. dev->node_guid = dev->sys_image_guid;
  386. dev->max_sge = min_t(u32, RDMA_MAX_SGE_PER_SQ_WQE,
  387. RDMA_MAX_SGE_PER_RQ_WQE);
  388. if (cdev->rdma_max_sge)
  389. dev->max_sge = min_t(u32, cdev->rdma_max_sge, dev->max_sge);
  390. dev->max_inline = ROCE_REQ_MAX_INLINE_DATA_SIZE;
  391. dev->max_inline = (cdev->rdma_max_inline) ?
  392. min_t(u32, cdev->rdma_max_inline, dev->max_inline) :
  393. dev->max_inline;
  394. dev->max_wqe = QED_RDMA_MAX_WQE;
  395. dev->max_cnq = (u8)FEAT_NUM(p_hwfn, QED_RDMA_CNQ);
  396. /* The number of QPs may be higher than QED_ROCE_MAX_QPS, because
  397. * it is up-aligned to 16 and then to ILT page size within qed cxt.
  398. * This is OK in terms of ILT but we don't want to configure the FW
  399. * above its abilities
  400. */
  401. num_qps = ROCE_MAX_QPS;
  402. num_qps = min_t(u64, num_qps, p_hwfn->p_rdma_info->num_qps);
  403. dev->max_qp = num_qps;
  404. /* CQs uses the same icids that QPs use hence they are limited by the
  405. * number of icids. There are two icids per QP.
  406. */
  407. dev->max_cq = num_qps * 2;
  408. /* The number of mrs is smaller by 1 since the first is reserved */
  409. dev->max_mr = p_hwfn->p_rdma_info->num_mrs - 1;
  410. dev->max_mr_size = QED_RDMA_MAX_MR_SIZE;
  411. /* The maximum CQE capacity per CQ supported.
  412. * max number of cqes will be in two layer pbl,
  413. * 8 is the pointer size in bytes
  414. * 32 is the size of cq element in bytes
  415. */
  416. if (params->cq_mode == QED_RDMA_CQ_MODE_32_BITS)
  417. dev->max_cqe = QED_RDMA_MAX_CQE_32_BIT;
  418. else
  419. dev->max_cqe = QED_RDMA_MAX_CQE_16_BIT;
  420. dev->max_mw = 0;
  421. dev->max_fmr = QED_RDMA_MAX_FMR;
  422. dev->max_mr_mw_fmr_pbl = (PAGE_SIZE / 8) * (PAGE_SIZE / 8);
  423. dev->max_mr_mw_fmr_size = dev->max_mr_mw_fmr_pbl * PAGE_SIZE;
  424. dev->max_pkey = QED_RDMA_MAX_P_KEY;
  425. dev->max_qp_resp_rd_atomic_resc = RDMA_RING_PAGE_SIZE /
  426. (RDMA_RESP_RD_ATOMIC_ELM_SIZE * 2);
  427. dev->max_qp_req_rd_atomic_resc = RDMA_RING_PAGE_SIZE /
  428. RDMA_REQ_RD_ATOMIC_ELM_SIZE;
  429. dev->max_dev_resp_rd_atomic_resc = dev->max_qp_resp_rd_atomic_resc *
  430. p_hwfn->p_rdma_info->num_qps;
  431. dev->page_size_caps = QED_RDMA_PAGE_SIZE_CAPS;
  432. dev->dev_ack_delay = QED_RDMA_ACK_DELAY;
  433. dev->max_pd = RDMA_MAX_PDS;
  434. dev->max_ah = p_hwfn->p_rdma_info->num_qps;
  435. dev->max_stats_queues = (u8)RESC_NUM(p_hwfn, QED_RDMA_STATS_QUEUE);
  436. /* Set capablities */
  437. dev->dev_caps = 0;
  438. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RNR_NAK, 1);
  439. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_ACTIVE_EVENT, 1);
  440. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_CHANGE_EVENT, 1);
  441. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RESIZE_CQ, 1);
  442. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_MEMORY_EXT, 1);
  443. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_QUEUE_EXT, 1);
  444. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ZBVA, 1);
  445. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_LOCAL_INV_FENCE, 1);
  446. /* Check atomic operations support in PCI configuration space. */
  447. pci_read_config_dword(cdev->pdev,
  448. cdev->pdev->pcie_cap + PCI_EXP_DEVCTL2,
  449. &pci_status_control);
  450. if (pci_status_control & PCI_EXP_DEVCTL2_LTR_EN)
  451. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ATOMIC_OP, 1);
  452. }
  453. static void qed_rdma_init_port(struct qed_hwfn *p_hwfn)
  454. {
  455. struct qed_rdma_port *port = p_hwfn->p_rdma_info->port;
  456. struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
  457. port->port_state = p_hwfn->mcp_info->link_output.link_up ?
  458. QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN;
  459. port->max_msg_size = min_t(u64,
  460. (dev->max_mr_mw_fmr_size *
  461. p_hwfn->cdev->rdma_max_sge),
  462. BIT(31));
  463. port->pkey_bad_counter = 0;
  464. }
  465. static int qed_rdma_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  466. {
  467. u32 ll2_ethertype_en;
  468. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Initializing HW\n");
  469. p_hwfn->b_rdma_enabled_in_prs = false;
  470. qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 0);
  471. p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_ROCE;
  472. /* We delay writing to this reg until first cid is allocated. See
  473. * qed_cxt_dynamic_ilt_alloc function for more details
  474. */
  475. ll2_ethertype_en = qed_rd(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN);
  476. qed_wr(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN,
  477. (ll2_ethertype_en | 0x01));
  478. if (qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_ROCE) % 2) {
  479. DP_NOTICE(p_hwfn, "The first RoCE's cid should be even\n");
  480. return -EINVAL;
  481. }
  482. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Initializing HW - Done\n");
  483. return 0;
  484. }
  485. static int qed_rdma_start_fw(struct qed_hwfn *p_hwfn,
  486. struct qed_rdma_start_in_params *params,
  487. struct qed_ptt *p_ptt)
  488. {
  489. struct rdma_init_func_ramrod_data *p_ramrod;
  490. struct qed_rdma_cnq_params *p_cnq_pbl_list;
  491. struct rdma_init_func_hdr *p_params_header;
  492. struct rdma_cnq_params *p_cnq_params;
  493. struct qed_sp_init_data init_data;
  494. struct qed_spq_entry *p_ent;
  495. u32 cnq_id, sb_id;
  496. int rc;
  497. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Starting FW\n");
  498. /* Save the number of cnqs for the function close ramrod */
  499. p_hwfn->p_rdma_info->num_cnqs = params->desired_cnq;
  500. /* Get SPQ entry */
  501. memset(&init_data, 0, sizeof(init_data));
  502. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  503. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  504. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_INIT,
  505. p_hwfn->p_rdma_info->proto, &init_data);
  506. if (rc)
  507. return rc;
  508. p_ramrod = &p_ent->ramrod.roce_init_func.rdma;
  509. p_params_header = &p_ramrod->params_header;
  510. p_params_header->cnq_start_offset = (u8)RESC_START(p_hwfn,
  511. QED_RDMA_CNQ_RAM);
  512. p_params_header->num_cnqs = params->desired_cnq;
  513. if (params->cq_mode == QED_RDMA_CQ_MODE_16_BITS)
  514. p_params_header->cq_ring_mode = 1;
  515. else
  516. p_params_header->cq_ring_mode = 0;
  517. for (cnq_id = 0; cnq_id < params->desired_cnq; cnq_id++) {
  518. sb_id = qed_rdma_get_sb_id(p_hwfn, cnq_id);
  519. p_cnq_params = &p_ramrod->cnq_params[cnq_id];
  520. p_cnq_pbl_list = &params->cnq_pbl_list[cnq_id];
  521. p_cnq_params->sb_num =
  522. cpu_to_le16(p_hwfn->sbs_info[sb_id]->igu_sb_id);
  523. p_cnq_params->sb_index = p_hwfn->pf_params.rdma_pf_params.gl_pi;
  524. p_cnq_params->num_pbl_pages = p_cnq_pbl_list->num_pbl_pages;
  525. DMA_REGPAIR_LE(p_cnq_params->pbl_base_addr,
  526. p_cnq_pbl_list->pbl_ptr);
  527. /* we assume here that cnq_id and qz_offset are the same */
  528. p_cnq_params->queue_zone_num =
  529. cpu_to_le16(p_hwfn->p_rdma_info->queue_zone_base +
  530. cnq_id);
  531. }
  532. return qed_spq_post(p_hwfn, p_ent, NULL);
  533. }
  534. static int qed_rdma_alloc_tid(void *rdma_cxt, u32 *itid)
  535. {
  536. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  537. int rc;
  538. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID\n");
  539. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  540. rc = qed_rdma_bmap_alloc_id(p_hwfn,
  541. &p_hwfn->p_rdma_info->tid_map, itid);
  542. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  543. if (rc)
  544. goto out;
  545. rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_TASK, *itid);
  546. out:
  547. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID - done, rc = %d\n", rc);
  548. return rc;
  549. }
  550. static int qed_rdma_reserve_lkey(struct qed_hwfn *p_hwfn)
  551. {
  552. struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
  553. /* The first DPI is reserved for the Kernel */
  554. __set_bit(0, p_hwfn->p_rdma_info->dpi_map.bitmap);
  555. /* Tid 0 will be used as the key for "reserved MR".
  556. * The driver should allocate memory for it so it can be loaded but no
  557. * ramrod should be passed on it.
  558. */
  559. qed_rdma_alloc_tid(p_hwfn, &dev->reserved_lkey);
  560. if (dev->reserved_lkey != RDMA_RESERVED_LKEY) {
  561. DP_NOTICE(p_hwfn,
  562. "Reserved lkey should be equal to RDMA_RESERVED_LKEY\n");
  563. return -EINVAL;
  564. }
  565. return 0;
  566. }
  567. static int qed_rdma_setup(struct qed_hwfn *p_hwfn,
  568. struct qed_ptt *p_ptt,
  569. struct qed_rdma_start_in_params *params)
  570. {
  571. int rc;
  572. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA setup\n");
  573. spin_lock_init(&p_hwfn->p_rdma_info->lock);
  574. qed_rdma_init_devinfo(p_hwfn, params);
  575. qed_rdma_init_port(p_hwfn);
  576. qed_rdma_init_events(p_hwfn, params);
  577. rc = qed_rdma_reserve_lkey(p_hwfn);
  578. if (rc)
  579. return rc;
  580. rc = qed_rdma_init_hw(p_hwfn, p_ptt);
  581. if (rc)
  582. return rc;
  583. return qed_rdma_start_fw(p_hwfn, params, p_ptt);
  584. }
  585. static int qed_rdma_stop(void *rdma_cxt)
  586. {
  587. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  588. struct rdma_close_func_ramrod_data *p_ramrod;
  589. struct qed_sp_init_data init_data;
  590. struct qed_spq_entry *p_ent;
  591. struct qed_ptt *p_ptt;
  592. u32 ll2_ethertype_en;
  593. int rc = -EBUSY;
  594. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop\n");
  595. p_ptt = qed_ptt_acquire(p_hwfn);
  596. if (!p_ptt) {
  597. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Failed to acquire PTT\n");
  598. return rc;
  599. }
  600. /* Disable RoCE search */
  601. qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0);
  602. p_hwfn->b_rdma_enabled_in_prs = false;
  603. qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 0);
  604. ll2_ethertype_en = qed_rd(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN);
  605. qed_wr(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN,
  606. (ll2_ethertype_en & 0xFFFE));
  607. qed_ptt_release(p_hwfn, p_ptt);
  608. /* Get SPQ entry */
  609. memset(&init_data, 0, sizeof(init_data));
  610. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  611. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  612. /* Stop RoCE */
  613. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_CLOSE,
  614. p_hwfn->p_rdma_info->proto, &init_data);
  615. if (rc)
  616. goto out;
  617. p_ramrod = &p_ent->ramrod.rdma_close_func;
  618. p_ramrod->num_cnqs = p_hwfn->p_rdma_info->num_cnqs;
  619. p_ramrod->cnq_start_offset = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM);
  620. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  621. out:
  622. qed_rdma_free(p_hwfn);
  623. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop done, rc = %d\n", rc);
  624. return rc;
  625. }
  626. static int qed_rdma_add_user(void *rdma_cxt,
  627. struct qed_rdma_add_user_out_params *out_params)
  628. {
  629. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  630. u32 dpi_start_offset;
  631. u32 returned_id = 0;
  632. int rc;
  633. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding User\n");
  634. /* Allocate DPI */
  635. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  636. rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map,
  637. &returned_id);
  638. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  639. out_params->dpi = (u16)returned_id;
  640. /* Calculate the corresponding DPI address */
  641. dpi_start_offset = p_hwfn->dpi_start_offset;
  642. out_params->dpi_addr = (u64)((u8 __iomem *)p_hwfn->doorbells +
  643. dpi_start_offset +
  644. ((out_params->dpi) * p_hwfn->dpi_size));
  645. out_params->dpi_phys_addr = p_hwfn->cdev->db_phys_addr +
  646. dpi_start_offset +
  647. ((out_params->dpi) * p_hwfn->dpi_size);
  648. out_params->dpi_size = p_hwfn->dpi_size;
  649. out_params->wid_count = p_hwfn->wid_count;
  650. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding user - done, rc = %d\n", rc);
  651. return rc;
  652. }
  653. static struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt)
  654. {
  655. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  656. struct qed_rdma_port *p_port = p_hwfn->p_rdma_info->port;
  657. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA Query port\n");
  658. /* Link may have changed */
  659. p_port->port_state = p_hwfn->mcp_info->link_output.link_up ?
  660. QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN;
  661. p_port->link_speed = p_hwfn->mcp_info->link_output.speed;
  662. p_port->max_msg_size = RDMA_MAX_DATA_SIZE_IN_WQE;
  663. return p_port;
  664. }
  665. static struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt)
  666. {
  667. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  668. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query device\n");
  669. /* Return struct with device parameters */
  670. return p_hwfn->p_rdma_info->dev;
  671. }
  672. static void qed_rdma_free_tid(void *rdma_cxt, u32 itid)
  673. {
  674. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  675. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid);
  676. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  677. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tid_map, itid);
  678. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  679. }
  680. static void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 qz_offset, u16 prod)
  681. {
  682. struct qed_hwfn *p_hwfn;
  683. u16 qz_num;
  684. u32 addr;
  685. p_hwfn = (struct qed_hwfn *)rdma_cxt;
  686. if (qz_offset > p_hwfn->p_rdma_info->max_queue_zones) {
  687. DP_NOTICE(p_hwfn,
  688. "queue zone offset %d is too large (max is %d)\n",
  689. qz_offset, p_hwfn->p_rdma_info->max_queue_zones);
  690. return;
  691. }
  692. qz_num = p_hwfn->p_rdma_info->queue_zone_base + qz_offset;
  693. addr = GTT_BAR0_MAP_REG_USDM_RAM +
  694. USTORM_COMMON_QUEUE_CONS_OFFSET(qz_num);
  695. REG_WR16(p_hwfn, addr, prod);
  696. /* keep prod updates ordered */
  697. wmb();
  698. }
  699. static int qed_fill_rdma_dev_info(struct qed_dev *cdev,
  700. struct qed_dev_rdma_info *info)
  701. {
  702. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  703. memset(info, 0, sizeof(*info));
  704. info->rdma_type = QED_RDMA_TYPE_ROCE;
  705. info->user_dpm_enabled = (p_hwfn->db_bar_no_edpm == 0);
  706. qed_fill_dev_info(cdev, &info->common);
  707. return 0;
  708. }
  709. static int qed_rdma_get_sb_start(struct qed_dev *cdev)
  710. {
  711. int feat_num;
  712. if (cdev->num_hwfns > 1)
  713. feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE);
  714. else
  715. feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE) *
  716. cdev->num_hwfns;
  717. return feat_num;
  718. }
  719. static int qed_rdma_get_min_cnq_msix(struct qed_dev *cdev)
  720. {
  721. int n_cnq = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_RDMA_CNQ);
  722. int n_msix = cdev->int_params.rdma_msix_cnt;
  723. return min_t(int, n_cnq, n_msix);
  724. }
  725. static int qed_rdma_set_int(struct qed_dev *cdev, u16 cnt)
  726. {
  727. int limit = 0;
  728. /* Mark the fastpath as free/used */
  729. cdev->int_params.fp_initialized = cnt ? true : false;
  730. if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX) {
  731. DP_ERR(cdev,
  732. "qed roce supports only MSI-X interrupts (detected %d).\n",
  733. cdev->int_params.out.int_mode);
  734. return -EINVAL;
  735. } else if (cdev->int_params.fp_msix_cnt) {
  736. limit = cdev->int_params.rdma_msix_cnt;
  737. }
  738. if (!limit)
  739. return -ENOMEM;
  740. return min_t(int, cnt, limit);
  741. }
  742. static int qed_rdma_get_int(struct qed_dev *cdev, struct qed_int_info *info)
  743. {
  744. memset(info, 0, sizeof(*info));
  745. if (!cdev->int_params.fp_initialized) {
  746. DP_INFO(cdev,
  747. "Protocol driver requested interrupt information, but its support is not yet configured\n");
  748. return -EINVAL;
  749. }
  750. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  751. int msix_base = cdev->int_params.rdma_msix_base;
  752. info->msix_cnt = cdev->int_params.rdma_msix_cnt;
  753. info->msix = &cdev->int_params.msix_table[msix_base];
  754. DP_VERBOSE(cdev, QED_MSG_RDMA, "msix_cnt = %d msix_base=%d\n",
  755. info->msix_cnt, msix_base);
  756. }
  757. return 0;
  758. }
  759. static int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd)
  760. {
  761. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  762. u32 returned_id;
  763. int rc;
  764. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD\n");
  765. /* Allocates an unused protection domain */
  766. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  767. rc = qed_rdma_bmap_alloc_id(p_hwfn,
  768. &p_hwfn->p_rdma_info->pd_map, &returned_id);
  769. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  770. *pd = (u16)returned_id;
  771. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD - done, rc = %d\n", rc);
  772. return rc;
  773. }
  774. static void qed_rdma_free_pd(void *rdma_cxt, u16 pd)
  775. {
  776. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  777. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "pd = %08x\n", pd);
  778. /* Returns a previously allocated protection domain for reuse */
  779. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  780. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->pd_map, pd);
  781. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  782. }
  783. static enum qed_rdma_toggle_bit
  784. qed_rdma_toggle_bit_create_resize_cq(struct qed_hwfn *p_hwfn, u16 icid)
  785. {
  786. struct qed_rdma_info *p_info = p_hwfn->p_rdma_info;
  787. enum qed_rdma_toggle_bit toggle_bit;
  788. u32 bmap_id;
  789. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", icid);
  790. /* the function toggle the bit that is related to a given icid
  791. * and returns the new toggle bit's value
  792. */
  793. bmap_id = icid - qed_cxt_get_proto_cid_start(p_hwfn, p_info->proto);
  794. spin_lock_bh(&p_info->lock);
  795. toggle_bit = !test_and_change_bit(bmap_id,
  796. p_info->toggle_bits.bitmap);
  797. spin_unlock_bh(&p_info->lock);
  798. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QED_RDMA_TOGGLE_BIT_= %d\n",
  799. toggle_bit);
  800. return toggle_bit;
  801. }
  802. static int qed_rdma_create_cq(void *rdma_cxt,
  803. struct qed_rdma_create_cq_in_params *params,
  804. u16 *icid)
  805. {
  806. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  807. struct qed_rdma_info *p_info = p_hwfn->p_rdma_info;
  808. struct rdma_create_cq_ramrod_data *p_ramrod;
  809. enum qed_rdma_toggle_bit toggle_bit;
  810. struct qed_sp_init_data init_data;
  811. struct qed_spq_entry *p_ent;
  812. u32 returned_id, start_cid;
  813. int rc;
  814. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "cq_handle = %08x%08x\n",
  815. params->cq_handle_hi, params->cq_handle_lo);
  816. /* Allocate icid */
  817. spin_lock_bh(&p_info->lock);
  818. rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_info->cq_map, &returned_id);
  819. spin_unlock_bh(&p_info->lock);
  820. if (rc) {
  821. DP_NOTICE(p_hwfn, "Can't create CQ, rc = %d\n", rc);
  822. return rc;
  823. }
  824. start_cid = qed_cxt_get_proto_cid_start(p_hwfn,
  825. p_info->proto);
  826. *icid = returned_id + start_cid;
  827. /* Check if icid requires a page allocation */
  828. rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *icid);
  829. if (rc)
  830. goto err;
  831. /* Get SPQ entry */
  832. memset(&init_data, 0, sizeof(init_data));
  833. init_data.cid = *icid;
  834. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  835. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  836. /* Send create CQ ramrod */
  837. rc = qed_sp_init_request(p_hwfn, &p_ent,
  838. RDMA_RAMROD_CREATE_CQ,
  839. p_info->proto, &init_data);
  840. if (rc)
  841. goto err;
  842. p_ramrod = &p_ent->ramrod.rdma_create_cq;
  843. p_ramrod->cq_handle.hi = cpu_to_le32(params->cq_handle_hi);
  844. p_ramrod->cq_handle.lo = cpu_to_le32(params->cq_handle_lo);
  845. p_ramrod->dpi = cpu_to_le16(params->dpi);
  846. p_ramrod->is_two_level_pbl = params->pbl_two_level;
  847. p_ramrod->max_cqes = cpu_to_le32(params->cq_size);
  848. DMA_REGPAIR_LE(p_ramrod->pbl_addr, params->pbl_ptr);
  849. p_ramrod->pbl_num_pages = cpu_to_le16(params->pbl_num_pages);
  850. p_ramrod->cnq_id = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM) +
  851. params->cnq_id;
  852. p_ramrod->int_timeout = params->int_timeout;
  853. /* toggle the bit for every resize or create cq for a given icid */
  854. toggle_bit = qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid);
  855. p_ramrod->toggle_bit = toggle_bit;
  856. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  857. if (rc) {
  858. /* restore toggle bit */
  859. qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid);
  860. goto err;
  861. }
  862. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Created CQ, rc = %d\n", rc);
  863. return rc;
  864. err:
  865. /* release allocated icid */
  866. spin_lock_bh(&p_info->lock);
  867. qed_bmap_release_id(p_hwfn, &p_info->cq_map, returned_id);
  868. spin_unlock_bh(&p_info->lock);
  869. DP_NOTICE(p_hwfn, "Create CQ failed, rc = %d\n", rc);
  870. return rc;
  871. }
  872. static int
  873. qed_rdma_destroy_cq(void *rdma_cxt,
  874. struct qed_rdma_destroy_cq_in_params *in_params,
  875. struct qed_rdma_destroy_cq_out_params *out_params)
  876. {
  877. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  878. struct rdma_destroy_cq_output_params *p_ramrod_res;
  879. struct rdma_destroy_cq_ramrod_data *p_ramrod;
  880. struct qed_sp_init_data init_data;
  881. struct qed_spq_entry *p_ent;
  882. dma_addr_t ramrod_res_phys;
  883. int rc = -ENOMEM;
  884. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", in_params->icid);
  885. p_ramrod_res =
  886. (struct rdma_destroy_cq_output_params *)
  887. dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  888. sizeof(struct rdma_destroy_cq_output_params),
  889. &ramrod_res_phys, GFP_KERNEL);
  890. if (!p_ramrod_res) {
  891. DP_NOTICE(p_hwfn,
  892. "qed destroy cq failed: cannot allocate memory (ramrod)\n");
  893. return rc;
  894. }
  895. /* Get SPQ entry */
  896. memset(&init_data, 0, sizeof(init_data));
  897. init_data.cid = in_params->icid;
  898. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  899. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  900. /* Send destroy CQ ramrod */
  901. rc = qed_sp_init_request(p_hwfn, &p_ent,
  902. RDMA_RAMROD_DESTROY_CQ,
  903. p_hwfn->p_rdma_info->proto, &init_data);
  904. if (rc)
  905. goto err;
  906. p_ramrod = &p_ent->ramrod.rdma_destroy_cq;
  907. DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
  908. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  909. if (rc)
  910. goto err;
  911. out_params->num_cq_notif = le16_to_cpu(p_ramrod_res->cnq_num);
  912. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  913. sizeof(struct rdma_destroy_cq_output_params),
  914. p_ramrod_res, ramrod_res_phys);
  915. /* Free icid */
  916. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  917. qed_bmap_release_id(p_hwfn,
  918. &p_hwfn->p_rdma_info->cq_map,
  919. (in_params->icid -
  920. qed_cxt_get_proto_cid_start(p_hwfn,
  921. p_hwfn->
  922. p_rdma_info->proto)));
  923. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  924. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroyed CQ, rc = %d\n", rc);
  925. return rc;
  926. err: dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  927. sizeof(struct rdma_destroy_cq_output_params),
  928. p_ramrod_res, ramrod_res_phys);
  929. return rc;
  930. }
  931. static void qed_rdma_set_fw_mac(u16 *p_fw_mac, u8 *p_qed_mac)
  932. {
  933. p_fw_mac[0] = cpu_to_le16((p_qed_mac[0] << 8) + p_qed_mac[1]);
  934. p_fw_mac[1] = cpu_to_le16((p_qed_mac[2] << 8) + p_qed_mac[3]);
  935. p_fw_mac[2] = cpu_to_le16((p_qed_mac[4] << 8) + p_qed_mac[5]);
  936. }
  937. static void qed_rdma_copy_gids(struct qed_rdma_qp *qp, __le32 *src_gid,
  938. __le32 *dst_gid)
  939. {
  940. u32 i;
  941. if (qp->roce_mode == ROCE_V2_IPV4) {
  942. /* The IPv4 addresses shall be aligned to the highest word.
  943. * The lower words must be zero.
  944. */
  945. memset(src_gid, 0, sizeof(union qed_gid));
  946. memset(dst_gid, 0, sizeof(union qed_gid));
  947. src_gid[3] = cpu_to_le32(qp->sgid.ipv4_addr);
  948. dst_gid[3] = cpu_to_le32(qp->dgid.ipv4_addr);
  949. } else {
  950. /* GIDs and IPv6 addresses coincide in location and size */
  951. for (i = 0; i < ARRAY_SIZE(qp->sgid.dwords); i++) {
  952. src_gid[i] = cpu_to_le32(qp->sgid.dwords[i]);
  953. dst_gid[i] = cpu_to_le32(qp->dgid.dwords[i]);
  954. }
  955. }
  956. }
  957. static enum roce_flavor qed_roce_mode_to_flavor(enum roce_mode roce_mode)
  958. {
  959. enum roce_flavor flavor;
  960. switch (roce_mode) {
  961. case ROCE_V1:
  962. flavor = PLAIN_ROCE;
  963. break;
  964. case ROCE_V2_IPV4:
  965. flavor = RROCE_IPV4;
  966. break;
  967. case ROCE_V2_IPV6:
  968. flavor = ROCE_V2_IPV6;
  969. break;
  970. default:
  971. flavor = MAX_ROCE_MODE;
  972. break;
  973. }
  974. return flavor;
  975. }
  976. void qed_roce_free_cid_pair(struct qed_hwfn *p_hwfn, u16 cid)
  977. {
  978. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  979. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
  980. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid + 1);
  981. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  982. }
  983. static int qed_roce_alloc_cid(struct qed_hwfn *p_hwfn, u16 *cid)
  984. {
  985. struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
  986. u32 responder_icid;
  987. u32 requester_icid;
  988. int rc;
  989. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  990. rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_rdma_info->cid_map,
  991. &responder_icid);
  992. if (rc) {
  993. spin_unlock_bh(&p_rdma_info->lock);
  994. return rc;
  995. }
  996. rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_rdma_info->cid_map,
  997. &requester_icid);
  998. spin_unlock_bh(&p_rdma_info->lock);
  999. if (rc)
  1000. goto err;
  1001. /* the two icid's should be adjacent */
  1002. if ((requester_icid - responder_icid) != 1) {
  1003. DP_NOTICE(p_hwfn, "Failed to allocate two adjacent qp's'\n");
  1004. rc = -EINVAL;
  1005. goto err;
  1006. }
  1007. responder_icid += qed_cxt_get_proto_cid_start(p_hwfn,
  1008. p_rdma_info->proto);
  1009. requester_icid += qed_cxt_get_proto_cid_start(p_hwfn,
  1010. p_rdma_info->proto);
  1011. /* If these icids require a new ILT line allocate DMA-able context for
  1012. * an ILT page
  1013. */
  1014. rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, responder_icid);
  1015. if (rc)
  1016. goto err;
  1017. rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, requester_icid);
  1018. if (rc)
  1019. goto err;
  1020. *cid = (u16)responder_icid;
  1021. return rc;
  1022. err:
  1023. spin_lock_bh(&p_rdma_info->lock);
  1024. qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, responder_icid);
  1025. qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, requester_icid);
  1026. spin_unlock_bh(&p_rdma_info->lock);
  1027. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1028. "Allocate CID - failed, rc = %d\n", rc);
  1029. return rc;
  1030. }
  1031. static void qed_roce_set_real_cid(struct qed_hwfn *p_hwfn, u32 cid)
  1032. {
  1033. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  1034. qed_bmap_set_id(p_hwfn, &p_hwfn->p_rdma_info->real_cid_map, cid);
  1035. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  1036. }
  1037. static int qed_roce_sp_create_responder(struct qed_hwfn *p_hwfn,
  1038. struct qed_rdma_qp *qp)
  1039. {
  1040. struct roce_create_qp_resp_ramrod_data *p_ramrod;
  1041. struct qed_sp_init_data init_data;
  1042. enum roce_flavor roce_flavor;
  1043. struct qed_spq_entry *p_ent;
  1044. u16 regular_latency_queue;
  1045. enum protocol_type proto;
  1046. int rc;
  1047. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1048. /* Allocate DMA-able memory for IRQ */
  1049. qp->irq_num_pages = 1;
  1050. qp->irq = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  1051. RDMA_RING_PAGE_SIZE,
  1052. &qp->irq_phys_addr, GFP_KERNEL);
  1053. if (!qp->irq) {
  1054. rc = -ENOMEM;
  1055. DP_NOTICE(p_hwfn,
  1056. "qed create responder failed: cannot allocate memory (irq). rc = %d\n",
  1057. rc);
  1058. return rc;
  1059. }
  1060. /* Get SPQ entry */
  1061. memset(&init_data, 0, sizeof(init_data));
  1062. init_data.cid = qp->icid;
  1063. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1064. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1065. rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_CREATE_QP,
  1066. PROTOCOLID_ROCE, &init_data);
  1067. if (rc)
  1068. goto err;
  1069. p_ramrod = &p_ent->ramrod.roce_create_qp_resp;
  1070. p_ramrod->flags = 0;
  1071. roce_flavor = qed_roce_mode_to_flavor(qp->roce_mode);
  1072. SET_FIELD(p_ramrod->flags,
  1073. ROCE_CREATE_QP_RESP_RAMROD_DATA_ROCE_FLAVOR, roce_flavor);
  1074. SET_FIELD(p_ramrod->flags,
  1075. ROCE_CREATE_QP_RESP_RAMROD_DATA_RDMA_RD_EN,
  1076. qp->incoming_rdma_read_en);
  1077. SET_FIELD(p_ramrod->flags,
  1078. ROCE_CREATE_QP_RESP_RAMROD_DATA_RDMA_WR_EN,
  1079. qp->incoming_rdma_write_en);
  1080. SET_FIELD(p_ramrod->flags,
  1081. ROCE_CREATE_QP_RESP_RAMROD_DATA_ATOMIC_EN,
  1082. qp->incoming_atomic_en);
  1083. SET_FIELD(p_ramrod->flags,
  1084. ROCE_CREATE_QP_RESP_RAMROD_DATA_E2E_FLOW_CONTROL_EN,
  1085. qp->e2e_flow_control_en);
  1086. SET_FIELD(p_ramrod->flags,
  1087. ROCE_CREATE_QP_RESP_RAMROD_DATA_SRQ_FLG, qp->use_srq);
  1088. SET_FIELD(p_ramrod->flags,
  1089. ROCE_CREATE_QP_RESP_RAMROD_DATA_RESERVED_KEY_EN,
  1090. qp->fmr_and_reserved_lkey);
  1091. SET_FIELD(p_ramrod->flags,
  1092. ROCE_CREATE_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER,
  1093. qp->min_rnr_nak_timer);
  1094. p_ramrod->max_ird = qp->max_rd_atomic_resp;
  1095. p_ramrod->traffic_class = qp->traffic_class_tos;
  1096. p_ramrod->hop_limit = qp->hop_limit_ttl;
  1097. p_ramrod->irq_num_pages = qp->irq_num_pages;
  1098. p_ramrod->p_key = cpu_to_le16(qp->pkey);
  1099. p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
  1100. p_ramrod->dst_qp_id = cpu_to_le32(qp->dest_qp);
  1101. p_ramrod->mtu = cpu_to_le16(qp->mtu);
  1102. p_ramrod->initial_psn = cpu_to_le32(qp->rq_psn);
  1103. p_ramrod->pd = cpu_to_le16(qp->pd);
  1104. p_ramrod->rq_num_pages = cpu_to_le16(qp->rq_num_pages);
  1105. DMA_REGPAIR_LE(p_ramrod->rq_pbl_addr, qp->rq_pbl_ptr);
  1106. DMA_REGPAIR_LE(p_ramrod->irq_pbl_addr, qp->irq_phys_addr);
  1107. qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
  1108. p_ramrod->qp_handle_for_async.hi = cpu_to_le32(qp->qp_handle_async.hi);
  1109. p_ramrod->qp_handle_for_async.lo = cpu_to_le32(qp->qp_handle_async.lo);
  1110. p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
  1111. p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
  1112. p_ramrod->cq_cid = cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) |
  1113. qp->rq_cq_id);
  1114. regular_latency_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
  1115. p_ramrod->regular_latency_phy_queue =
  1116. cpu_to_le16(regular_latency_queue);
  1117. p_ramrod->low_latency_phy_queue =
  1118. cpu_to_le16(regular_latency_queue);
  1119. p_ramrod->dpi = cpu_to_le16(qp->dpi);
  1120. qed_rdma_set_fw_mac(p_ramrod->remote_mac_addr, qp->remote_mac_addr);
  1121. qed_rdma_set_fw_mac(p_ramrod->local_mac_addr, qp->local_mac_addr);
  1122. p_ramrod->udp_src_port = qp->udp_src_port;
  1123. p_ramrod->vlan_id = cpu_to_le16(qp->vlan_id);
  1124. p_ramrod->srq_id.srq_idx = cpu_to_le16(qp->srq_id);
  1125. p_ramrod->srq_id.opaque_fid = cpu_to_le16(p_hwfn->hw_info.opaque_fid);
  1126. p_ramrod->stats_counter_id = RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) +
  1127. qp->stats_queue;
  1128. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1129. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1130. "rc = %d regular physical queue = 0x%x\n", rc,
  1131. regular_latency_queue);
  1132. if (rc)
  1133. goto err;
  1134. qp->resp_offloaded = true;
  1135. qp->cq_prod = 0;
  1136. proto = p_hwfn->p_rdma_info->proto;
  1137. qed_roce_set_real_cid(p_hwfn, qp->icid -
  1138. qed_cxt_get_proto_cid_start(p_hwfn, proto));
  1139. return rc;
  1140. err:
  1141. DP_NOTICE(p_hwfn, "create responder - failed, rc = %d\n", rc);
  1142. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  1143. qp->irq_num_pages * RDMA_RING_PAGE_SIZE,
  1144. qp->irq, qp->irq_phys_addr);
  1145. return rc;
  1146. }
  1147. static int qed_roce_sp_create_requester(struct qed_hwfn *p_hwfn,
  1148. struct qed_rdma_qp *qp)
  1149. {
  1150. struct roce_create_qp_req_ramrod_data *p_ramrod;
  1151. struct qed_sp_init_data init_data;
  1152. enum roce_flavor roce_flavor;
  1153. struct qed_spq_entry *p_ent;
  1154. u16 regular_latency_queue;
  1155. enum protocol_type proto;
  1156. int rc;
  1157. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1158. /* Allocate DMA-able memory for ORQ */
  1159. qp->orq_num_pages = 1;
  1160. qp->orq = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  1161. RDMA_RING_PAGE_SIZE,
  1162. &qp->orq_phys_addr, GFP_KERNEL);
  1163. if (!qp->orq) {
  1164. rc = -ENOMEM;
  1165. DP_NOTICE(p_hwfn,
  1166. "qed create requester failed: cannot allocate memory (orq). rc = %d\n",
  1167. rc);
  1168. return rc;
  1169. }
  1170. /* Get SPQ entry */
  1171. memset(&init_data, 0, sizeof(init_data));
  1172. init_data.cid = qp->icid + 1;
  1173. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1174. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1175. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1176. ROCE_RAMROD_CREATE_QP,
  1177. PROTOCOLID_ROCE, &init_data);
  1178. if (rc)
  1179. goto err;
  1180. p_ramrod = &p_ent->ramrod.roce_create_qp_req;
  1181. p_ramrod->flags = 0;
  1182. roce_flavor = qed_roce_mode_to_flavor(qp->roce_mode);
  1183. SET_FIELD(p_ramrod->flags,
  1184. ROCE_CREATE_QP_REQ_RAMROD_DATA_ROCE_FLAVOR, roce_flavor);
  1185. SET_FIELD(p_ramrod->flags,
  1186. ROCE_CREATE_QP_REQ_RAMROD_DATA_FMR_AND_RESERVED_EN,
  1187. qp->fmr_and_reserved_lkey);
  1188. SET_FIELD(p_ramrod->flags,
  1189. ROCE_CREATE_QP_REQ_RAMROD_DATA_SIGNALED_COMP, qp->signal_all);
  1190. SET_FIELD(p_ramrod->flags,
  1191. ROCE_CREATE_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT, qp->retry_cnt);
  1192. SET_FIELD(p_ramrod->flags,
  1193. ROCE_CREATE_QP_REQ_RAMROD_DATA_RNR_NAK_CNT,
  1194. qp->rnr_retry_cnt);
  1195. p_ramrod->max_ord = qp->max_rd_atomic_req;
  1196. p_ramrod->traffic_class = qp->traffic_class_tos;
  1197. p_ramrod->hop_limit = qp->hop_limit_ttl;
  1198. p_ramrod->orq_num_pages = qp->orq_num_pages;
  1199. p_ramrod->p_key = cpu_to_le16(qp->pkey);
  1200. p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
  1201. p_ramrod->dst_qp_id = cpu_to_le32(qp->dest_qp);
  1202. p_ramrod->ack_timeout_val = cpu_to_le32(qp->ack_timeout);
  1203. p_ramrod->mtu = cpu_to_le16(qp->mtu);
  1204. p_ramrod->initial_psn = cpu_to_le32(qp->sq_psn);
  1205. p_ramrod->pd = cpu_to_le16(qp->pd);
  1206. p_ramrod->sq_num_pages = cpu_to_le16(qp->sq_num_pages);
  1207. DMA_REGPAIR_LE(p_ramrod->sq_pbl_addr, qp->sq_pbl_ptr);
  1208. DMA_REGPAIR_LE(p_ramrod->orq_pbl_addr, qp->orq_phys_addr);
  1209. qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
  1210. p_ramrod->qp_handle_for_async.hi = cpu_to_le32(qp->qp_handle_async.hi);
  1211. p_ramrod->qp_handle_for_async.lo = cpu_to_le32(qp->qp_handle_async.lo);
  1212. p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
  1213. p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
  1214. p_ramrod->cq_cid =
  1215. cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id);
  1216. regular_latency_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
  1217. p_ramrod->regular_latency_phy_queue =
  1218. cpu_to_le16(regular_latency_queue);
  1219. p_ramrod->low_latency_phy_queue =
  1220. cpu_to_le16(regular_latency_queue);
  1221. p_ramrod->dpi = cpu_to_le16(qp->dpi);
  1222. qed_rdma_set_fw_mac(p_ramrod->remote_mac_addr, qp->remote_mac_addr);
  1223. qed_rdma_set_fw_mac(p_ramrod->local_mac_addr, qp->local_mac_addr);
  1224. p_ramrod->udp_src_port = qp->udp_src_port;
  1225. p_ramrod->vlan_id = cpu_to_le16(qp->vlan_id);
  1226. p_ramrod->stats_counter_id = RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) +
  1227. qp->stats_queue;
  1228. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1229. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1230. if (rc)
  1231. goto err;
  1232. qp->req_offloaded = true;
  1233. proto = p_hwfn->p_rdma_info->proto;
  1234. qed_roce_set_real_cid(p_hwfn,
  1235. qp->icid + 1 -
  1236. qed_cxt_get_proto_cid_start(p_hwfn, proto));
  1237. return rc;
  1238. err:
  1239. DP_NOTICE(p_hwfn, "Create requested - failed, rc = %d\n", rc);
  1240. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  1241. qp->orq_num_pages * RDMA_RING_PAGE_SIZE,
  1242. qp->orq, qp->orq_phys_addr);
  1243. return rc;
  1244. }
  1245. static int qed_roce_sp_modify_responder(struct qed_hwfn *p_hwfn,
  1246. struct qed_rdma_qp *qp,
  1247. bool move_to_err, u32 modify_flags)
  1248. {
  1249. struct roce_modify_qp_resp_ramrod_data *p_ramrod;
  1250. struct qed_sp_init_data init_data;
  1251. struct qed_spq_entry *p_ent;
  1252. int rc;
  1253. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1254. if (move_to_err && !qp->resp_offloaded)
  1255. return 0;
  1256. /* Get SPQ entry */
  1257. memset(&init_data, 0, sizeof(init_data));
  1258. init_data.cid = qp->icid;
  1259. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1260. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1261. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1262. ROCE_EVENT_MODIFY_QP,
  1263. PROTOCOLID_ROCE, &init_data);
  1264. if (rc) {
  1265. DP_NOTICE(p_hwfn, "rc = %d\n", rc);
  1266. return rc;
  1267. }
  1268. p_ramrod = &p_ent->ramrod.roce_modify_qp_resp;
  1269. p_ramrod->flags = 0;
  1270. SET_FIELD(p_ramrod->flags,
  1271. ROCE_MODIFY_QP_RESP_RAMROD_DATA_MOVE_TO_ERR_FLG, move_to_err);
  1272. SET_FIELD(p_ramrod->flags,
  1273. ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_RD_EN,
  1274. qp->incoming_rdma_read_en);
  1275. SET_FIELD(p_ramrod->flags,
  1276. ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_WR_EN,
  1277. qp->incoming_rdma_write_en);
  1278. SET_FIELD(p_ramrod->flags,
  1279. ROCE_MODIFY_QP_RESP_RAMROD_DATA_ATOMIC_EN,
  1280. qp->incoming_atomic_en);
  1281. SET_FIELD(p_ramrod->flags,
  1282. ROCE_CREATE_QP_RESP_RAMROD_DATA_E2E_FLOW_CONTROL_EN,
  1283. qp->e2e_flow_control_en);
  1284. SET_FIELD(p_ramrod->flags,
  1285. ROCE_MODIFY_QP_RESP_RAMROD_DATA_RDMA_OPS_EN_FLG,
  1286. GET_FIELD(modify_flags,
  1287. QED_RDMA_MODIFY_QP_VALID_RDMA_OPS_EN));
  1288. SET_FIELD(p_ramrod->flags,
  1289. ROCE_MODIFY_QP_RESP_RAMROD_DATA_P_KEY_FLG,
  1290. GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY));
  1291. SET_FIELD(p_ramrod->flags,
  1292. ROCE_MODIFY_QP_RESP_RAMROD_DATA_ADDRESS_VECTOR_FLG,
  1293. GET_FIELD(modify_flags,
  1294. QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR));
  1295. SET_FIELD(p_ramrod->flags,
  1296. ROCE_MODIFY_QP_RESP_RAMROD_DATA_MAX_IRD_FLG,
  1297. GET_FIELD(modify_flags,
  1298. QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_RESP));
  1299. SET_FIELD(p_ramrod->flags,
  1300. ROCE_MODIFY_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER_FLG,
  1301. GET_FIELD(modify_flags,
  1302. QED_ROCE_MODIFY_QP_VALID_MIN_RNR_NAK_TIMER));
  1303. p_ramrod->fields = 0;
  1304. SET_FIELD(p_ramrod->fields,
  1305. ROCE_MODIFY_QP_RESP_RAMROD_DATA_MIN_RNR_NAK_TIMER,
  1306. qp->min_rnr_nak_timer);
  1307. p_ramrod->max_ird = qp->max_rd_atomic_resp;
  1308. p_ramrod->traffic_class = qp->traffic_class_tos;
  1309. p_ramrod->hop_limit = qp->hop_limit_ttl;
  1310. p_ramrod->p_key = cpu_to_le16(qp->pkey);
  1311. p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
  1312. p_ramrod->mtu = cpu_to_le16(qp->mtu);
  1313. qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
  1314. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1315. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify responder, rc = %d\n", rc);
  1316. return rc;
  1317. }
  1318. static int qed_roce_sp_modify_requester(struct qed_hwfn *p_hwfn,
  1319. struct qed_rdma_qp *qp,
  1320. bool move_to_sqd,
  1321. bool move_to_err, u32 modify_flags)
  1322. {
  1323. struct roce_modify_qp_req_ramrod_data *p_ramrod;
  1324. struct qed_sp_init_data init_data;
  1325. struct qed_spq_entry *p_ent;
  1326. int rc;
  1327. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1328. if (move_to_err && !(qp->req_offloaded))
  1329. return 0;
  1330. /* Get SPQ entry */
  1331. memset(&init_data, 0, sizeof(init_data));
  1332. init_data.cid = qp->icid + 1;
  1333. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1334. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1335. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1336. ROCE_EVENT_MODIFY_QP,
  1337. PROTOCOLID_ROCE, &init_data);
  1338. if (rc) {
  1339. DP_NOTICE(p_hwfn, "rc = %d\n", rc);
  1340. return rc;
  1341. }
  1342. p_ramrod = &p_ent->ramrod.roce_modify_qp_req;
  1343. p_ramrod->flags = 0;
  1344. SET_FIELD(p_ramrod->flags,
  1345. ROCE_MODIFY_QP_REQ_RAMROD_DATA_MOVE_TO_ERR_FLG, move_to_err);
  1346. SET_FIELD(p_ramrod->flags,
  1347. ROCE_MODIFY_QP_REQ_RAMROD_DATA_MOVE_TO_SQD_FLG, move_to_sqd);
  1348. SET_FIELD(p_ramrod->flags,
  1349. ROCE_MODIFY_QP_REQ_RAMROD_DATA_EN_SQD_ASYNC_NOTIFY,
  1350. qp->sqd_async);
  1351. SET_FIELD(p_ramrod->flags,
  1352. ROCE_MODIFY_QP_REQ_RAMROD_DATA_P_KEY_FLG,
  1353. GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY));
  1354. SET_FIELD(p_ramrod->flags,
  1355. ROCE_MODIFY_QP_REQ_RAMROD_DATA_ADDRESS_VECTOR_FLG,
  1356. GET_FIELD(modify_flags,
  1357. QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR));
  1358. SET_FIELD(p_ramrod->flags,
  1359. ROCE_MODIFY_QP_REQ_RAMROD_DATA_MAX_ORD_FLG,
  1360. GET_FIELD(modify_flags,
  1361. QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_REQ));
  1362. SET_FIELD(p_ramrod->flags,
  1363. ROCE_MODIFY_QP_REQ_RAMROD_DATA_RNR_NAK_CNT_FLG,
  1364. GET_FIELD(modify_flags,
  1365. QED_ROCE_MODIFY_QP_VALID_RNR_RETRY_CNT));
  1366. SET_FIELD(p_ramrod->flags,
  1367. ROCE_MODIFY_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT_FLG,
  1368. GET_FIELD(modify_flags, QED_ROCE_MODIFY_QP_VALID_RETRY_CNT));
  1369. SET_FIELD(p_ramrod->flags,
  1370. ROCE_MODIFY_QP_REQ_RAMROD_DATA_ACK_TIMEOUT_FLG,
  1371. GET_FIELD(modify_flags,
  1372. QED_ROCE_MODIFY_QP_VALID_ACK_TIMEOUT));
  1373. p_ramrod->fields = 0;
  1374. SET_FIELD(p_ramrod->fields,
  1375. ROCE_MODIFY_QP_REQ_RAMROD_DATA_ERR_RETRY_CNT, qp->retry_cnt);
  1376. SET_FIELD(p_ramrod->fields,
  1377. ROCE_MODIFY_QP_REQ_RAMROD_DATA_RNR_NAK_CNT,
  1378. qp->rnr_retry_cnt);
  1379. p_ramrod->max_ord = qp->max_rd_atomic_req;
  1380. p_ramrod->traffic_class = qp->traffic_class_tos;
  1381. p_ramrod->hop_limit = qp->hop_limit_ttl;
  1382. p_ramrod->p_key = cpu_to_le16(qp->pkey);
  1383. p_ramrod->flow_label = cpu_to_le32(qp->flow_label);
  1384. p_ramrod->ack_timeout_val = cpu_to_le32(qp->ack_timeout);
  1385. p_ramrod->mtu = cpu_to_le16(qp->mtu);
  1386. qed_rdma_copy_gids(qp, p_ramrod->src_gid, p_ramrod->dst_gid);
  1387. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1388. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify requester, rc = %d\n", rc);
  1389. return rc;
  1390. }
  1391. static int qed_roce_sp_destroy_qp_responder(struct qed_hwfn *p_hwfn,
  1392. struct qed_rdma_qp *qp,
  1393. u32 *num_invalidated_mw,
  1394. u32 *cq_prod)
  1395. {
  1396. struct roce_destroy_qp_resp_output_params *p_ramrod_res;
  1397. struct roce_destroy_qp_resp_ramrod_data *p_ramrod;
  1398. struct qed_sp_init_data init_data;
  1399. struct qed_spq_entry *p_ent;
  1400. dma_addr_t ramrod_res_phys;
  1401. int rc;
  1402. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1403. *num_invalidated_mw = 0;
  1404. *cq_prod = qp->cq_prod;
  1405. if (!qp->resp_offloaded) {
  1406. /* If a responder was never offload, we need to free the cids
  1407. * allocated in create_qp as a FW async event will never arrive
  1408. */
  1409. u32 cid;
  1410. cid = qp->icid -
  1411. qed_cxt_get_proto_cid_start(p_hwfn,
  1412. p_hwfn->p_rdma_info->proto);
  1413. qed_roce_free_cid_pair(p_hwfn, (u16)cid);
  1414. return 0;
  1415. }
  1416. /* Get SPQ entry */
  1417. memset(&init_data, 0, sizeof(init_data));
  1418. init_data.cid = qp->icid;
  1419. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1420. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1421. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1422. ROCE_RAMROD_DESTROY_QP,
  1423. PROTOCOLID_ROCE, &init_data);
  1424. if (rc)
  1425. return rc;
  1426. p_ramrod = &p_ent->ramrod.roce_destroy_qp_resp;
  1427. p_ramrod_res = (struct roce_destroy_qp_resp_output_params *)
  1428. dma_alloc_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_ramrod_res),
  1429. &ramrod_res_phys, GFP_KERNEL);
  1430. if (!p_ramrod_res) {
  1431. rc = -ENOMEM;
  1432. DP_NOTICE(p_hwfn,
  1433. "qed destroy responder failed: cannot allocate memory (ramrod). rc = %d\n",
  1434. rc);
  1435. return rc;
  1436. }
  1437. DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
  1438. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1439. if (rc)
  1440. goto err;
  1441. *num_invalidated_mw = le32_to_cpu(p_ramrod_res->num_invalidated_mw);
  1442. *cq_prod = le32_to_cpu(p_ramrod_res->cq_prod);
  1443. qp->cq_prod = *cq_prod;
  1444. /* Free IRQ - only if ramrod succeeded, in case FW is still using it */
  1445. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  1446. qp->irq_num_pages * RDMA_RING_PAGE_SIZE,
  1447. qp->irq, qp->irq_phys_addr);
  1448. qp->resp_offloaded = false;
  1449. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroy responder, rc = %d\n", rc);
  1450. err:
  1451. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  1452. sizeof(struct roce_destroy_qp_resp_output_params),
  1453. p_ramrod_res, ramrod_res_phys);
  1454. return rc;
  1455. }
  1456. static int qed_roce_sp_destroy_qp_requester(struct qed_hwfn *p_hwfn,
  1457. struct qed_rdma_qp *qp,
  1458. u32 *num_bound_mw)
  1459. {
  1460. struct roce_destroy_qp_req_output_params *p_ramrod_res;
  1461. struct roce_destroy_qp_req_ramrod_data *p_ramrod;
  1462. struct qed_sp_init_data init_data;
  1463. struct qed_spq_entry *p_ent;
  1464. dma_addr_t ramrod_res_phys;
  1465. int rc = -ENOMEM;
  1466. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1467. if (!qp->req_offloaded)
  1468. return 0;
  1469. p_ramrod_res = (struct roce_destroy_qp_req_output_params *)
  1470. dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  1471. sizeof(*p_ramrod_res),
  1472. &ramrod_res_phys, GFP_KERNEL);
  1473. if (!p_ramrod_res) {
  1474. DP_NOTICE(p_hwfn,
  1475. "qed destroy requester failed: cannot allocate memory (ramrod)\n");
  1476. return rc;
  1477. }
  1478. /* Get SPQ entry */
  1479. memset(&init_data, 0, sizeof(init_data));
  1480. init_data.cid = qp->icid + 1;
  1481. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1482. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1483. rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_DESTROY_QP,
  1484. PROTOCOLID_ROCE, &init_data);
  1485. if (rc)
  1486. goto err;
  1487. p_ramrod = &p_ent->ramrod.roce_destroy_qp_req;
  1488. DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
  1489. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1490. if (rc)
  1491. goto err;
  1492. *num_bound_mw = le32_to_cpu(p_ramrod_res->num_bound_mw);
  1493. /* Free ORQ - only if ramrod succeeded, in case FW is still using it */
  1494. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  1495. qp->orq_num_pages * RDMA_RING_PAGE_SIZE,
  1496. qp->orq, qp->orq_phys_addr);
  1497. qp->req_offloaded = false;
  1498. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroy requester, rc = %d\n", rc);
  1499. err:
  1500. dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_ramrod_res),
  1501. p_ramrod_res, ramrod_res_phys);
  1502. return rc;
  1503. }
  1504. static int qed_roce_query_qp(struct qed_hwfn *p_hwfn,
  1505. struct qed_rdma_qp *qp,
  1506. struct qed_rdma_query_qp_out_params *out_params)
  1507. {
  1508. struct roce_query_qp_resp_output_params *p_resp_ramrod_res;
  1509. struct roce_query_qp_req_output_params *p_req_ramrod_res;
  1510. struct roce_query_qp_resp_ramrod_data *p_resp_ramrod;
  1511. struct roce_query_qp_req_ramrod_data *p_req_ramrod;
  1512. struct qed_sp_init_data init_data;
  1513. dma_addr_t resp_ramrod_res_phys;
  1514. dma_addr_t req_ramrod_res_phys;
  1515. struct qed_spq_entry *p_ent;
  1516. bool rq_err_state;
  1517. bool sq_err_state;
  1518. bool sq_draining;
  1519. int rc = -ENOMEM;
  1520. if ((!(qp->resp_offloaded)) && (!(qp->req_offloaded))) {
  1521. /* We can't send ramrod to the fw since this qp wasn't offloaded
  1522. * to the fw yet
  1523. */
  1524. out_params->draining = false;
  1525. out_params->rq_psn = qp->rq_psn;
  1526. out_params->sq_psn = qp->sq_psn;
  1527. out_params->state = qp->cur_state;
  1528. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "No QPs as no offload\n");
  1529. return 0;
  1530. }
  1531. if (!(qp->resp_offloaded)) {
  1532. DP_NOTICE(p_hwfn,
  1533. "The responder's qp should be offloded before requester's\n");
  1534. return -EINVAL;
  1535. }
  1536. /* Send a query responder ramrod to FW to get RQ-PSN and state */
  1537. p_resp_ramrod_res = (struct roce_query_qp_resp_output_params *)
  1538. dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  1539. sizeof(*p_resp_ramrod_res),
  1540. &resp_ramrod_res_phys, GFP_KERNEL);
  1541. if (!p_resp_ramrod_res) {
  1542. DP_NOTICE(p_hwfn,
  1543. "qed query qp failed: cannot allocate memory (ramrod)\n");
  1544. return rc;
  1545. }
  1546. /* Get SPQ entry */
  1547. memset(&init_data, 0, sizeof(init_data));
  1548. init_data.cid = qp->icid;
  1549. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1550. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1551. rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_QUERY_QP,
  1552. PROTOCOLID_ROCE, &init_data);
  1553. if (rc)
  1554. goto err_resp;
  1555. p_resp_ramrod = &p_ent->ramrod.roce_query_qp_resp;
  1556. DMA_REGPAIR_LE(p_resp_ramrod->output_params_addr, resp_ramrod_res_phys);
  1557. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1558. if (rc)
  1559. goto err_resp;
  1560. out_params->rq_psn = le32_to_cpu(p_resp_ramrod_res->psn);
  1561. rq_err_state = GET_FIELD(le32_to_cpu(p_resp_ramrod_res->err_flag),
  1562. ROCE_QUERY_QP_RESP_OUTPUT_PARAMS_ERROR_FLG);
  1563. dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_resp_ramrod_res),
  1564. p_resp_ramrod_res, resp_ramrod_res_phys);
  1565. if (!(qp->req_offloaded)) {
  1566. /* Don't send query qp for the requester */
  1567. out_params->sq_psn = qp->sq_psn;
  1568. out_params->draining = false;
  1569. if (rq_err_state)
  1570. qp->cur_state = QED_ROCE_QP_STATE_ERR;
  1571. out_params->state = qp->cur_state;
  1572. return 0;
  1573. }
  1574. /* Send a query requester ramrod to FW to get SQ-PSN and state */
  1575. p_req_ramrod_res = (struct roce_query_qp_req_output_params *)
  1576. dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  1577. sizeof(*p_req_ramrod_res),
  1578. &req_ramrod_res_phys,
  1579. GFP_KERNEL);
  1580. if (!p_req_ramrod_res) {
  1581. rc = -ENOMEM;
  1582. DP_NOTICE(p_hwfn,
  1583. "qed query qp failed: cannot allocate memory (ramrod)\n");
  1584. return rc;
  1585. }
  1586. /* Get SPQ entry */
  1587. init_data.cid = qp->icid + 1;
  1588. rc = qed_sp_init_request(p_hwfn, &p_ent, ROCE_RAMROD_QUERY_QP,
  1589. PROTOCOLID_ROCE, &init_data);
  1590. if (rc)
  1591. goto err_req;
  1592. p_req_ramrod = &p_ent->ramrod.roce_query_qp_req;
  1593. DMA_REGPAIR_LE(p_req_ramrod->output_params_addr, req_ramrod_res_phys);
  1594. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  1595. if (rc)
  1596. goto err_req;
  1597. out_params->sq_psn = le32_to_cpu(p_req_ramrod_res->psn);
  1598. sq_err_state = GET_FIELD(le32_to_cpu(p_req_ramrod_res->flags),
  1599. ROCE_QUERY_QP_REQ_OUTPUT_PARAMS_ERR_FLG);
  1600. sq_draining =
  1601. GET_FIELD(le32_to_cpu(p_req_ramrod_res->flags),
  1602. ROCE_QUERY_QP_REQ_OUTPUT_PARAMS_SQ_DRAINING_FLG);
  1603. dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_req_ramrod_res),
  1604. p_req_ramrod_res, req_ramrod_res_phys);
  1605. out_params->draining = false;
  1606. if (rq_err_state || sq_err_state)
  1607. qp->cur_state = QED_ROCE_QP_STATE_ERR;
  1608. else if (sq_draining)
  1609. out_params->draining = true;
  1610. out_params->state = qp->cur_state;
  1611. return 0;
  1612. err_req:
  1613. dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_req_ramrod_res),
  1614. p_req_ramrod_res, req_ramrod_res_phys);
  1615. return rc;
  1616. err_resp:
  1617. dma_free_coherent(&p_hwfn->cdev->pdev->dev, sizeof(*p_resp_ramrod_res),
  1618. p_resp_ramrod_res, resp_ramrod_res_phys);
  1619. return rc;
  1620. }
  1621. static int qed_roce_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
  1622. {
  1623. u32 num_invalidated_mw = 0;
  1624. u32 num_bound_mw = 0;
  1625. u32 cq_prod;
  1626. int rc;
  1627. /* Destroys the specified QP */
  1628. if ((qp->cur_state != QED_ROCE_QP_STATE_RESET) &&
  1629. (qp->cur_state != QED_ROCE_QP_STATE_ERR) &&
  1630. (qp->cur_state != QED_ROCE_QP_STATE_INIT)) {
  1631. DP_NOTICE(p_hwfn,
  1632. "QP must be in error, reset or init state before destroying it\n");
  1633. return -EINVAL;
  1634. }
  1635. if (qp->cur_state != QED_ROCE_QP_STATE_RESET) {
  1636. rc = qed_roce_sp_destroy_qp_responder(p_hwfn, qp,
  1637. &num_invalidated_mw,
  1638. &cq_prod);
  1639. if (rc)
  1640. return rc;
  1641. /* Send destroy requester ramrod */
  1642. rc = qed_roce_sp_destroy_qp_requester(p_hwfn, qp,
  1643. &num_bound_mw);
  1644. if (rc)
  1645. return rc;
  1646. if (num_invalidated_mw != num_bound_mw) {
  1647. DP_NOTICE(p_hwfn,
  1648. "number of invalidate memory windows is different from bounded ones\n");
  1649. return -EINVAL;
  1650. }
  1651. }
  1652. return 0;
  1653. }
  1654. static int qed_rdma_query_qp(void *rdma_cxt,
  1655. struct qed_rdma_qp *qp,
  1656. struct qed_rdma_query_qp_out_params *out_params)
  1657. {
  1658. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1659. int rc;
  1660. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1661. /* The following fields are filled in from qp and not FW as they can't
  1662. * be modified by FW
  1663. */
  1664. out_params->mtu = qp->mtu;
  1665. out_params->dest_qp = qp->dest_qp;
  1666. out_params->incoming_atomic_en = qp->incoming_atomic_en;
  1667. out_params->e2e_flow_control_en = qp->e2e_flow_control_en;
  1668. out_params->incoming_rdma_read_en = qp->incoming_rdma_read_en;
  1669. out_params->incoming_rdma_write_en = qp->incoming_rdma_write_en;
  1670. out_params->dgid = qp->dgid;
  1671. out_params->flow_label = qp->flow_label;
  1672. out_params->hop_limit_ttl = qp->hop_limit_ttl;
  1673. out_params->traffic_class_tos = qp->traffic_class_tos;
  1674. out_params->timeout = qp->ack_timeout;
  1675. out_params->rnr_retry = qp->rnr_retry_cnt;
  1676. out_params->retry_cnt = qp->retry_cnt;
  1677. out_params->min_rnr_nak_timer = qp->min_rnr_nak_timer;
  1678. out_params->pkey_index = 0;
  1679. out_params->max_rd_atomic = qp->max_rd_atomic_req;
  1680. out_params->max_dest_rd_atomic = qp->max_rd_atomic_resp;
  1681. out_params->sqd_async = qp->sqd_async;
  1682. rc = qed_roce_query_qp(p_hwfn, qp, out_params);
  1683. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query QP, rc = %d\n", rc);
  1684. return rc;
  1685. }
  1686. static int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp)
  1687. {
  1688. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1689. int rc = 0;
  1690. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  1691. rc = qed_roce_destroy_qp(p_hwfn, qp);
  1692. /* free qp params struct */
  1693. kfree(qp);
  1694. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP destroyed\n");
  1695. return rc;
  1696. }
  1697. static struct qed_rdma_qp *
  1698. qed_rdma_create_qp(void *rdma_cxt,
  1699. struct qed_rdma_create_qp_in_params *in_params,
  1700. struct qed_rdma_create_qp_out_params *out_params)
  1701. {
  1702. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1703. struct qed_rdma_qp *qp;
  1704. u8 max_stats_queues;
  1705. int rc;
  1706. if (!rdma_cxt || !in_params || !out_params || !p_hwfn->p_rdma_info) {
  1707. DP_ERR(p_hwfn->cdev,
  1708. "qed roce create qp failed due to NULL entry (rdma_cxt=%p, in=%p, out=%p, roce_info=?\n",
  1709. rdma_cxt, in_params, out_params);
  1710. return NULL;
  1711. }
  1712. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1713. "qed rdma create qp called with qp_handle = %08x%08x\n",
  1714. in_params->qp_handle_hi, in_params->qp_handle_lo);
  1715. /* Some sanity checks... */
  1716. max_stats_queues = p_hwfn->p_rdma_info->dev->max_stats_queues;
  1717. if (in_params->stats_queue >= max_stats_queues) {
  1718. DP_ERR(p_hwfn->cdev,
  1719. "qed rdma create qp failed due to invalid statistics queue %d. maximum is %d\n",
  1720. in_params->stats_queue, max_stats_queues);
  1721. return NULL;
  1722. }
  1723. qp = kzalloc(sizeof(*qp), GFP_KERNEL);
  1724. if (!qp) {
  1725. DP_NOTICE(p_hwfn, "Failed to allocate qed_rdma_qp\n");
  1726. return NULL;
  1727. }
  1728. rc = qed_roce_alloc_cid(p_hwfn, &qp->icid);
  1729. qp->qpid = ((0xFF << 16) | qp->icid);
  1730. DP_INFO(p_hwfn, "ROCE qpid=%x\n", qp->qpid);
  1731. if (rc) {
  1732. kfree(qp);
  1733. return NULL;
  1734. }
  1735. qp->cur_state = QED_ROCE_QP_STATE_RESET;
  1736. qp->qp_handle.hi = cpu_to_le32(in_params->qp_handle_hi);
  1737. qp->qp_handle.lo = cpu_to_le32(in_params->qp_handle_lo);
  1738. qp->qp_handle_async.hi = cpu_to_le32(in_params->qp_handle_async_hi);
  1739. qp->qp_handle_async.lo = cpu_to_le32(in_params->qp_handle_async_lo);
  1740. qp->use_srq = in_params->use_srq;
  1741. qp->signal_all = in_params->signal_all;
  1742. qp->fmr_and_reserved_lkey = in_params->fmr_and_reserved_lkey;
  1743. qp->pd = in_params->pd;
  1744. qp->dpi = in_params->dpi;
  1745. qp->sq_cq_id = in_params->sq_cq_id;
  1746. qp->sq_num_pages = in_params->sq_num_pages;
  1747. qp->sq_pbl_ptr = in_params->sq_pbl_ptr;
  1748. qp->rq_cq_id = in_params->rq_cq_id;
  1749. qp->rq_num_pages = in_params->rq_num_pages;
  1750. qp->rq_pbl_ptr = in_params->rq_pbl_ptr;
  1751. qp->srq_id = in_params->srq_id;
  1752. qp->req_offloaded = false;
  1753. qp->resp_offloaded = false;
  1754. qp->e2e_flow_control_en = qp->use_srq ? false : true;
  1755. qp->stats_queue = in_params->stats_queue;
  1756. out_params->icid = qp->icid;
  1757. out_params->qp_id = qp->qpid;
  1758. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Create QP, rc = %d\n", rc);
  1759. return qp;
  1760. }
  1761. static int qed_roce_modify_qp(struct qed_hwfn *p_hwfn,
  1762. struct qed_rdma_qp *qp,
  1763. enum qed_roce_qp_state prev_state,
  1764. struct qed_rdma_modify_qp_in_params *params)
  1765. {
  1766. u32 num_invalidated_mw = 0, num_bound_mw = 0;
  1767. int rc = 0;
  1768. /* Perform additional operations according to the current state and the
  1769. * next state
  1770. */
  1771. if (((prev_state == QED_ROCE_QP_STATE_INIT) ||
  1772. (prev_state == QED_ROCE_QP_STATE_RESET)) &&
  1773. (qp->cur_state == QED_ROCE_QP_STATE_RTR)) {
  1774. /* Init->RTR or Reset->RTR */
  1775. rc = qed_roce_sp_create_responder(p_hwfn, qp);
  1776. return rc;
  1777. } else if ((prev_state == QED_ROCE_QP_STATE_RTR) &&
  1778. (qp->cur_state == QED_ROCE_QP_STATE_RTS)) {
  1779. /* RTR-> RTS */
  1780. rc = qed_roce_sp_create_requester(p_hwfn, qp);
  1781. if (rc)
  1782. return rc;
  1783. /* Send modify responder ramrod */
  1784. rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
  1785. params->modify_flags);
  1786. return rc;
  1787. } else if ((prev_state == QED_ROCE_QP_STATE_RTS) &&
  1788. (qp->cur_state == QED_ROCE_QP_STATE_RTS)) {
  1789. /* RTS->RTS */
  1790. rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
  1791. params->modify_flags);
  1792. if (rc)
  1793. return rc;
  1794. rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false,
  1795. params->modify_flags);
  1796. return rc;
  1797. } else if ((prev_state == QED_ROCE_QP_STATE_RTS) &&
  1798. (qp->cur_state == QED_ROCE_QP_STATE_SQD)) {
  1799. /* RTS->SQD */
  1800. rc = qed_roce_sp_modify_requester(p_hwfn, qp, true, false,
  1801. params->modify_flags);
  1802. return rc;
  1803. } else if ((prev_state == QED_ROCE_QP_STATE_SQD) &&
  1804. (qp->cur_state == QED_ROCE_QP_STATE_SQD)) {
  1805. /* SQD->SQD */
  1806. rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
  1807. params->modify_flags);
  1808. if (rc)
  1809. return rc;
  1810. rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false,
  1811. params->modify_flags);
  1812. return rc;
  1813. } else if ((prev_state == QED_ROCE_QP_STATE_SQD) &&
  1814. (qp->cur_state == QED_ROCE_QP_STATE_RTS)) {
  1815. /* SQD->RTS */
  1816. rc = qed_roce_sp_modify_responder(p_hwfn, qp, false,
  1817. params->modify_flags);
  1818. if (rc)
  1819. return rc;
  1820. rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, false,
  1821. params->modify_flags);
  1822. return rc;
  1823. } else if (qp->cur_state == QED_ROCE_QP_STATE_ERR) {
  1824. /* ->ERR */
  1825. rc = qed_roce_sp_modify_responder(p_hwfn, qp, true,
  1826. params->modify_flags);
  1827. if (rc)
  1828. return rc;
  1829. rc = qed_roce_sp_modify_requester(p_hwfn, qp, false, true,
  1830. params->modify_flags);
  1831. return rc;
  1832. } else if (qp->cur_state == QED_ROCE_QP_STATE_RESET) {
  1833. /* Any state -> RESET */
  1834. u32 cq_prod;
  1835. /* Send destroy responder ramrod */
  1836. rc = qed_roce_sp_destroy_qp_responder(p_hwfn,
  1837. qp,
  1838. &num_invalidated_mw,
  1839. &cq_prod);
  1840. if (rc)
  1841. return rc;
  1842. qp->cq_prod = cq_prod;
  1843. rc = qed_roce_sp_destroy_qp_requester(p_hwfn, qp,
  1844. &num_bound_mw);
  1845. if (num_invalidated_mw != num_bound_mw) {
  1846. DP_NOTICE(p_hwfn,
  1847. "number of invalidate memory windows is different from bounded ones\n");
  1848. return -EINVAL;
  1849. }
  1850. } else {
  1851. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "0\n");
  1852. }
  1853. return rc;
  1854. }
  1855. static int qed_rdma_modify_qp(void *rdma_cxt,
  1856. struct qed_rdma_qp *qp,
  1857. struct qed_rdma_modify_qp_in_params *params)
  1858. {
  1859. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1860. enum qed_roce_qp_state prev_state;
  1861. int rc = 0;
  1862. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x params->new_state=%d\n",
  1863. qp->icid, params->new_state);
  1864. if (rc) {
  1865. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1866. return rc;
  1867. }
  1868. if (GET_FIELD(params->modify_flags,
  1869. QED_RDMA_MODIFY_QP_VALID_RDMA_OPS_EN)) {
  1870. qp->incoming_rdma_read_en = params->incoming_rdma_read_en;
  1871. qp->incoming_rdma_write_en = params->incoming_rdma_write_en;
  1872. qp->incoming_atomic_en = params->incoming_atomic_en;
  1873. }
  1874. /* Update QP structure with the updated values */
  1875. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_ROCE_MODE))
  1876. qp->roce_mode = params->roce_mode;
  1877. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY))
  1878. qp->pkey = params->pkey;
  1879. if (GET_FIELD(params->modify_flags,
  1880. QED_ROCE_MODIFY_QP_VALID_E2E_FLOW_CONTROL_EN))
  1881. qp->e2e_flow_control_en = params->e2e_flow_control_en;
  1882. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_DEST_QP))
  1883. qp->dest_qp = params->dest_qp;
  1884. if (GET_FIELD(params->modify_flags,
  1885. QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR)) {
  1886. /* Indicates that the following parameters have changed:
  1887. * Traffic class, flow label, hop limit, source GID,
  1888. * destination GID, loopback indicator
  1889. */
  1890. qp->traffic_class_tos = params->traffic_class_tos;
  1891. qp->flow_label = params->flow_label;
  1892. qp->hop_limit_ttl = params->hop_limit_ttl;
  1893. qp->sgid = params->sgid;
  1894. qp->dgid = params->dgid;
  1895. qp->udp_src_port = 0;
  1896. qp->vlan_id = params->vlan_id;
  1897. qp->mtu = params->mtu;
  1898. qp->lb_indication = params->lb_indication;
  1899. memcpy((u8 *)&qp->remote_mac_addr[0],
  1900. (u8 *)&params->remote_mac_addr[0], ETH_ALEN);
  1901. if (params->use_local_mac) {
  1902. memcpy((u8 *)&qp->local_mac_addr[0],
  1903. (u8 *)&params->local_mac_addr[0], ETH_ALEN);
  1904. } else {
  1905. memcpy((u8 *)&qp->local_mac_addr[0],
  1906. (u8 *)&p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
  1907. }
  1908. }
  1909. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RQ_PSN))
  1910. qp->rq_psn = params->rq_psn;
  1911. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_SQ_PSN))
  1912. qp->sq_psn = params->sq_psn;
  1913. if (GET_FIELD(params->modify_flags,
  1914. QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_REQ))
  1915. qp->max_rd_atomic_req = params->max_rd_atomic_req;
  1916. if (GET_FIELD(params->modify_flags,
  1917. QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_RESP))
  1918. qp->max_rd_atomic_resp = params->max_rd_atomic_resp;
  1919. if (GET_FIELD(params->modify_flags,
  1920. QED_ROCE_MODIFY_QP_VALID_ACK_TIMEOUT))
  1921. qp->ack_timeout = params->ack_timeout;
  1922. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RETRY_CNT))
  1923. qp->retry_cnt = params->retry_cnt;
  1924. if (GET_FIELD(params->modify_flags,
  1925. QED_ROCE_MODIFY_QP_VALID_RNR_RETRY_CNT))
  1926. qp->rnr_retry_cnt = params->rnr_retry_cnt;
  1927. if (GET_FIELD(params->modify_flags,
  1928. QED_ROCE_MODIFY_QP_VALID_MIN_RNR_NAK_TIMER))
  1929. qp->min_rnr_nak_timer = params->min_rnr_nak_timer;
  1930. qp->sqd_async = params->sqd_async;
  1931. prev_state = qp->cur_state;
  1932. if (GET_FIELD(params->modify_flags,
  1933. QED_RDMA_MODIFY_QP_VALID_NEW_STATE)) {
  1934. qp->cur_state = params->new_state;
  1935. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "qp->cur_state=%d\n",
  1936. qp->cur_state);
  1937. }
  1938. rc = qed_roce_modify_qp(p_hwfn, qp, prev_state, params);
  1939. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify QP, rc = %d\n", rc);
  1940. return rc;
  1941. }
  1942. static int
  1943. qed_rdma_register_tid(void *rdma_cxt,
  1944. struct qed_rdma_register_tid_in_params *params)
  1945. {
  1946. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1947. struct rdma_register_tid_ramrod_data *p_ramrod;
  1948. struct qed_sp_init_data init_data;
  1949. struct qed_spq_entry *p_ent;
  1950. enum rdma_tid_type tid_type;
  1951. u8 fw_return_code;
  1952. int rc;
  1953. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", params->itid);
  1954. /* Get SPQ entry */
  1955. memset(&init_data, 0, sizeof(init_data));
  1956. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1957. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1958. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_REGISTER_MR,
  1959. p_hwfn->p_rdma_info->proto, &init_data);
  1960. if (rc) {
  1961. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1962. return rc;
  1963. }
  1964. if (p_hwfn->p_rdma_info->last_tid < params->itid)
  1965. p_hwfn->p_rdma_info->last_tid = params->itid;
  1966. p_ramrod = &p_ent->ramrod.rdma_register_tid;
  1967. p_ramrod->flags = 0;
  1968. SET_FIELD(p_ramrod->flags,
  1969. RDMA_REGISTER_TID_RAMROD_DATA_TWO_LEVEL_PBL,
  1970. params->pbl_two_level);
  1971. SET_FIELD(p_ramrod->flags,
  1972. RDMA_REGISTER_TID_RAMROD_DATA_ZERO_BASED, params->zbva);
  1973. SET_FIELD(p_ramrod->flags,
  1974. RDMA_REGISTER_TID_RAMROD_DATA_PHY_MR, params->phy_mr);
  1975. /* Don't initialize D/C field, as it may override other bits. */
  1976. if (!(params->tid_type == QED_RDMA_TID_FMR) && !(params->dma_mr))
  1977. SET_FIELD(p_ramrod->flags,
  1978. RDMA_REGISTER_TID_RAMROD_DATA_PAGE_SIZE_LOG,
  1979. params->page_size_log - 12);
  1980. SET_FIELD(p_ramrod->flags,
  1981. RDMA_REGISTER_TID_RAMROD_DATA_MAX_ID,
  1982. p_hwfn->p_rdma_info->last_tid);
  1983. SET_FIELD(p_ramrod->flags,
  1984. RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_READ,
  1985. params->remote_read);
  1986. SET_FIELD(p_ramrod->flags,
  1987. RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_WRITE,
  1988. params->remote_write);
  1989. SET_FIELD(p_ramrod->flags,
  1990. RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_ATOMIC,
  1991. params->remote_atomic);
  1992. SET_FIELD(p_ramrod->flags,
  1993. RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_WRITE,
  1994. params->local_write);
  1995. SET_FIELD(p_ramrod->flags,
  1996. RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_READ, params->local_read);
  1997. SET_FIELD(p_ramrod->flags,
  1998. RDMA_REGISTER_TID_RAMROD_DATA_ENABLE_MW_BIND,
  1999. params->mw_bind);
  2000. SET_FIELD(p_ramrod->flags1,
  2001. RDMA_REGISTER_TID_RAMROD_DATA_PBL_PAGE_SIZE_LOG,
  2002. params->pbl_page_size_log - 12);
  2003. SET_FIELD(p_ramrod->flags2,
  2004. RDMA_REGISTER_TID_RAMROD_DATA_DMA_MR, params->dma_mr);
  2005. switch (params->tid_type) {
  2006. case QED_RDMA_TID_REGISTERED_MR:
  2007. tid_type = RDMA_TID_REGISTERED_MR;
  2008. break;
  2009. case QED_RDMA_TID_FMR:
  2010. tid_type = RDMA_TID_FMR;
  2011. break;
  2012. case QED_RDMA_TID_MW_TYPE1:
  2013. tid_type = RDMA_TID_MW_TYPE1;
  2014. break;
  2015. case QED_RDMA_TID_MW_TYPE2A:
  2016. tid_type = RDMA_TID_MW_TYPE2A;
  2017. break;
  2018. default:
  2019. rc = -EINVAL;
  2020. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  2021. return rc;
  2022. }
  2023. SET_FIELD(p_ramrod->flags1,
  2024. RDMA_REGISTER_TID_RAMROD_DATA_TID_TYPE, tid_type);
  2025. p_ramrod->itid = cpu_to_le32(params->itid);
  2026. p_ramrod->key = params->key;
  2027. p_ramrod->pd = cpu_to_le16(params->pd);
  2028. p_ramrod->length_hi = (u8)(params->length >> 32);
  2029. p_ramrod->length_lo = DMA_LO_LE(params->length);
  2030. if (params->zbva) {
  2031. /* Lower 32 bits of the registered MR address.
  2032. * In case of zero based MR, will hold FBO
  2033. */
  2034. p_ramrod->va.hi = 0;
  2035. p_ramrod->va.lo = cpu_to_le32(params->fbo);
  2036. } else {
  2037. DMA_REGPAIR_LE(p_ramrod->va, params->vaddr);
  2038. }
  2039. DMA_REGPAIR_LE(p_ramrod->pbl_base, params->pbl_ptr);
  2040. /* DIF */
  2041. if (params->dif_enabled) {
  2042. SET_FIELD(p_ramrod->flags2,
  2043. RDMA_REGISTER_TID_RAMROD_DATA_DIF_ON_HOST_FLG, 1);
  2044. DMA_REGPAIR_LE(p_ramrod->dif_error_addr,
  2045. params->dif_error_addr);
  2046. DMA_REGPAIR_LE(p_ramrod->dif_runt_addr, params->dif_runt_addr);
  2047. }
  2048. rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
  2049. if (rc)
  2050. return rc;
  2051. if (fw_return_code != RDMA_RETURN_OK) {
  2052. DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code);
  2053. return -EINVAL;
  2054. }
  2055. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Register TID, rc = %d\n", rc);
  2056. return rc;
  2057. }
  2058. static int qed_rdma_deregister_tid(void *rdma_cxt, u32 itid)
  2059. {
  2060. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  2061. struct rdma_deregister_tid_ramrod_data *p_ramrod;
  2062. struct qed_sp_init_data init_data;
  2063. struct qed_spq_entry *p_ent;
  2064. struct qed_ptt *p_ptt;
  2065. u8 fw_return_code;
  2066. int rc;
  2067. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid);
  2068. /* Get SPQ entry */
  2069. memset(&init_data, 0, sizeof(init_data));
  2070. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  2071. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  2072. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_DEREGISTER_MR,
  2073. p_hwfn->p_rdma_info->proto, &init_data);
  2074. if (rc) {
  2075. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  2076. return rc;
  2077. }
  2078. p_ramrod = &p_ent->ramrod.rdma_deregister_tid;
  2079. p_ramrod->itid = cpu_to_le32(itid);
  2080. rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
  2081. if (rc) {
  2082. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  2083. return rc;
  2084. }
  2085. if (fw_return_code == RDMA_RETURN_DEREGISTER_MR_BAD_STATE_ERR) {
  2086. DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code);
  2087. return -EINVAL;
  2088. } else if (fw_return_code == RDMA_RETURN_NIG_DRAIN_REQ) {
  2089. /* Bit indicating that the TID is in use and a nig drain is
  2090. * required before sending the ramrod again
  2091. */
  2092. p_ptt = qed_ptt_acquire(p_hwfn);
  2093. if (!p_ptt) {
  2094. rc = -EBUSY;
  2095. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2096. "Failed to acquire PTT\n");
  2097. return rc;
  2098. }
  2099. rc = qed_mcp_drain(p_hwfn, p_ptt);
  2100. if (rc) {
  2101. qed_ptt_release(p_hwfn, p_ptt);
  2102. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2103. "Drain failed\n");
  2104. return rc;
  2105. }
  2106. qed_ptt_release(p_hwfn, p_ptt);
  2107. /* Resend the ramrod */
  2108. rc = qed_sp_init_request(p_hwfn, &p_ent,
  2109. RDMA_RAMROD_DEREGISTER_MR,
  2110. p_hwfn->p_rdma_info->proto,
  2111. &init_data);
  2112. if (rc) {
  2113. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2114. "Failed to init sp-element\n");
  2115. return rc;
  2116. }
  2117. rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
  2118. if (rc) {
  2119. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2120. "Ramrod failed\n");
  2121. return rc;
  2122. }
  2123. if (fw_return_code != RDMA_RETURN_OK) {
  2124. DP_NOTICE(p_hwfn, "fw_return_code = %d\n",
  2125. fw_return_code);
  2126. return rc;
  2127. }
  2128. }
  2129. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "De-registered TID, rc = %d\n", rc);
  2130. return rc;
  2131. }
  2132. static void qed_roce_free_real_icid(struct qed_hwfn *p_hwfn, u16 icid)
  2133. {
  2134. struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
  2135. u32 start_cid, cid, xcid;
  2136. /* an even icid belongs to a responder while an odd icid belongs to a
  2137. * requester. The 'cid' received as an input can be either. We calculate
  2138. * the "partner" icid and call it xcid. Only if both are free then the
  2139. * "cid" map can be cleared.
  2140. */
  2141. start_cid = qed_cxt_get_proto_cid_start(p_hwfn, p_rdma_info->proto);
  2142. cid = icid - start_cid;
  2143. xcid = cid ^ 1;
  2144. spin_lock_bh(&p_rdma_info->lock);
  2145. qed_bmap_release_id(p_hwfn, &p_rdma_info->real_cid_map, cid);
  2146. if (qed_bmap_test_id(p_hwfn, &p_rdma_info->real_cid_map, xcid) == 0) {
  2147. qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, cid);
  2148. qed_bmap_release_id(p_hwfn, &p_rdma_info->cid_map, xcid);
  2149. }
  2150. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  2151. }
  2152. static void *qed_rdma_get_rdma_ctx(struct qed_dev *cdev)
  2153. {
  2154. return QED_LEADING_HWFN(cdev);
  2155. }
  2156. static void qed_rdma_dpm_conf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2157. {
  2158. u32 val;
  2159. val = (p_hwfn->dcbx_no_edpm || p_hwfn->db_bar_no_edpm) ? 0 : 1;
  2160. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPM_ENABLE, val);
  2161. DP_VERBOSE(p_hwfn, (QED_MSG_DCB | QED_MSG_RDMA),
  2162. "Changing DPM_EN state to %d (DCBX=%d, DB_BAR=%d)\n",
  2163. val, p_hwfn->dcbx_no_edpm, p_hwfn->db_bar_no_edpm);
  2164. }
  2165. void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2166. {
  2167. p_hwfn->db_bar_no_edpm = true;
  2168. qed_rdma_dpm_conf(p_hwfn, p_ptt);
  2169. }
  2170. static int qed_rdma_start(void *rdma_cxt,
  2171. struct qed_rdma_start_in_params *params)
  2172. {
  2173. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  2174. struct qed_ptt *p_ptt;
  2175. int rc = -EBUSY;
  2176. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2177. "desired_cnq = %08x\n", params->desired_cnq);
  2178. p_ptt = qed_ptt_acquire(p_hwfn);
  2179. if (!p_ptt)
  2180. goto err;
  2181. rc = qed_rdma_alloc(p_hwfn, p_ptt, params);
  2182. if (rc)
  2183. goto err1;
  2184. rc = qed_rdma_setup(p_hwfn, p_ptt, params);
  2185. if (rc)
  2186. goto err2;
  2187. qed_ptt_release(p_hwfn, p_ptt);
  2188. return rc;
  2189. err2:
  2190. qed_rdma_free(p_hwfn);
  2191. err1:
  2192. qed_ptt_release(p_hwfn, p_ptt);
  2193. err:
  2194. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA start - error, rc = %d\n", rc);
  2195. return rc;
  2196. }
  2197. static int qed_rdma_init(struct qed_dev *cdev,
  2198. struct qed_rdma_start_in_params *params)
  2199. {
  2200. return qed_rdma_start(QED_LEADING_HWFN(cdev), params);
  2201. }
  2202. static void qed_rdma_remove_user(void *rdma_cxt, u16 dpi)
  2203. {
  2204. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  2205. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "dpi = %08x\n", dpi);
  2206. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  2207. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, dpi);
  2208. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  2209. }
  2210. void qed_ll2b_complete_tx_gsi_packet(struct qed_hwfn *p_hwfn,
  2211. u8 connection_handle,
  2212. void *cookie,
  2213. dma_addr_t first_frag_addr,
  2214. bool b_last_fragment, bool b_last_packet)
  2215. {
  2216. struct qed_roce_ll2_packet *packet = cookie;
  2217. struct qed_roce_ll2_info *roce_ll2 = p_hwfn->ll2;
  2218. roce_ll2->cbs.tx_cb(roce_ll2->cb_cookie, packet);
  2219. }
  2220. void qed_ll2b_release_tx_gsi_packet(struct qed_hwfn *p_hwfn,
  2221. u8 connection_handle,
  2222. void *cookie,
  2223. dma_addr_t first_frag_addr,
  2224. bool b_last_fragment, bool b_last_packet)
  2225. {
  2226. qed_ll2b_complete_tx_gsi_packet(p_hwfn, connection_handle,
  2227. cookie, first_frag_addr,
  2228. b_last_fragment, b_last_packet);
  2229. }
  2230. void qed_ll2b_complete_rx_gsi_packet(struct qed_hwfn *p_hwfn,
  2231. u8 connection_handle,
  2232. void *cookie,
  2233. dma_addr_t rx_buf_addr,
  2234. u16 data_length,
  2235. u8 data_length_error,
  2236. u16 parse_flags,
  2237. u16 vlan,
  2238. u32 src_mac_addr_hi,
  2239. u16 src_mac_addr_lo, bool b_last_packet)
  2240. {
  2241. struct qed_roce_ll2_info *roce_ll2 = p_hwfn->ll2;
  2242. struct qed_roce_ll2_rx_params params;
  2243. struct qed_dev *cdev = p_hwfn->cdev;
  2244. struct qed_roce_ll2_packet pkt;
  2245. DP_VERBOSE(cdev,
  2246. QED_MSG_LL2,
  2247. "roce ll2 rx complete: bus_addr=%p, len=%d, data_len_err=%d\n",
  2248. (void *)(uintptr_t)rx_buf_addr,
  2249. data_length, data_length_error);
  2250. memset(&pkt, 0, sizeof(pkt));
  2251. pkt.n_seg = 1;
  2252. pkt.payload[0].baddr = rx_buf_addr;
  2253. pkt.payload[0].len = data_length;
  2254. memset(&params, 0, sizeof(params));
  2255. params.vlan_id = vlan;
  2256. *((u32 *)&params.smac[0]) = ntohl(src_mac_addr_hi);
  2257. *((u16 *)&params.smac[4]) = ntohs(src_mac_addr_lo);
  2258. if (data_length_error) {
  2259. DP_ERR(cdev,
  2260. "roce ll2 rx complete: data length error %d, length=%d\n",
  2261. data_length_error, data_length);
  2262. params.rc = -EINVAL;
  2263. }
  2264. roce_ll2->cbs.rx_cb(roce_ll2->cb_cookie, &pkt, &params);
  2265. }
  2266. static int qed_roce_ll2_set_mac_filter(struct qed_dev *cdev,
  2267. u8 *old_mac_address,
  2268. u8 *new_mac_address)
  2269. {
  2270. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  2271. struct qed_ptt *p_ptt;
  2272. int rc = 0;
  2273. if (!hwfn->ll2 || hwfn->ll2->handle == QED_LL2_UNUSED_HANDLE) {
  2274. DP_ERR(cdev,
  2275. "qed roce mac filter failed - roce_info/ll2 NULL\n");
  2276. return -EINVAL;
  2277. }
  2278. p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
  2279. if (!p_ptt) {
  2280. DP_ERR(cdev,
  2281. "qed roce ll2 mac filter set: failed to acquire PTT\n");
  2282. return -EINVAL;
  2283. }
  2284. mutex_lock(&hwfn->ll2->lock);
  2285. if (old_mac_address)
  2286. qed_llh_remove_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
  2287. old_mac_address);
  2288. if (new_mac_address)
  2289. rc = qed_llh_add_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
  2290. new_mac_address);
  2291. mutex_unlock(&hwfn->ll2->lock);
  2292. qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
  2293. if (rc)
  2294. DP_ERR(cdev,
  2295. "qed roce ll2 mac filter set: failed to add mac filter\n");
  2296. return rc;
  2297. }
  2298. static int qed_roce_ll2_start(struct qed_dev *cdev,
  2299. struct qed_roce_ll2_params *params)
  2300. {
  2301. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  2302. struct qed_roce_ll2_info *roce_ll2;
  2303. struct qed_ll2_conn ll2_params;
  2304. int rc;
  2305. if (!params) {
  2306. DP_ERR(cdev, "qed roce ll2 start: failed due to NULL params\n");
  2307. return -EINVAL;
  2308. }
  2309. if (!params->cbs.tx_cb || !params->cbs.rx_cb) {
  2310. DP_ERR(cdev,
  2311. "qed roce ll2 start: failed due to NULL tx/rx. tx_cb=%p, rx_cb=%p\n",
  2312. params->cbs.tx_cb, params->cbs.rx_cb);
  2313. return -EINVAL;
  2314. }
  2315. if (!is_valid_ether_addr(params->mac_address)) {
  2316. DP_ERR(cdev,
  2317. "qed roce ll2 start: failed due to invalid Ethernet address %pM\n",
  2318. params->mac_address);
  2319. return -EINVAL;
  2320. }
  2321. /* Initialize */
  2322. roce_ll2 = kzalloc(sizeof(*roce_ll2), GFP_ATOMIC);
  2323. if (!roce_ll2) {
  2324. DP_ERR(cdev, "qed roce ll2 start: failed memory allocation\n");
  2325. return -ENOMEM;
  2326. }
  2327. roce_ll2->handle = QED_LL2_UNUSED_HANDLE;
  2328. roce_ll2->cbs = params->cbs;
  2329. roce_ll2->cb_cookie = params->cb_cookie;
  2330. mutex_init(&roce_ll2->lock);
  2331. memset(&ll2_params, 0, sizeof(ll2_params));
  2332. ll2_params.conn_type = QED_LL2_TYPE_ROCE;
  2333. ll2_params.mtu = params->mtu;
  2334. ll2_params.rx_drop_ttl0_flg = true;
  2335. ll2_params.rx_vlan_removal_en = false;
  2336. ll2_params.tx_dest = CORE_TX_DEST_NW;
  2337. ll2_params.ai_err_packet_too_big = LL2_DROP_PACKET;
  2338. ll2_params.ai_err_no_buf = LL2_DROP_PACKET;
  2339. ll2_params.gsi_enable = true;
  2340. rc = qed_ll2_acquire_connection(QED_LEADING_HWFN(cdev), &ll2_params,
  2341. params->max_rx_buffers,
  2342. params->max_tx_buffers,
  2343. &roce_ll2->handle);
  2344. if (rc) {
  2345. DP_ERR(cdev,
  2346. "qed roce ll2 start: failed to acquire LL2 connection (rc=%d)\n",
  2347. rc);
  2348. goto err;
  2349. }
  2350. rc = qed_ll2_establish_connection(QED_LEADING_HWFN(cdev),
  2351. roce_ll2->handle);
  2352. if (rc) {
  2353. DP_ERR(cdev,
  2354. "qed roce ll2 start: failed to establish LL2 connection (rc=%d)\n",
  2355. rc);
  2356. goto err1;
  2357. }
  2358. hwfn->ll2 = roce_ll2;
  2359. rc = qed_roce_ll2_set_mac_filter(cdev, NULL, params->mac_address);
  2360. if (rc) {
  2361. hwfn->ll2 = NULL;
  2362. goto err2;
  2363. }
  2364. ether_addr_copy(roce_ll2->mac_address, params->mac_address);
  2365. return 0;
  2366. err2:
  2367. qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev), roce_ll2->handle);
  2368. err1:
  2369. qed_ll2_release_connection(QED_LEADING_HWFN(cdev), roce_ll2->handle);
  2370. err:
  2371. kfree(roce_ll2);
  2372. return rc;
  2373. }
  2374. static int qed_roce_ll2_stop(struct qed_dev *cdev)
  2375. {
  2376. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  2377. struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2;
  2378. int rc;
  2379. if (roce_ll2->handle == QED_LL2_UNUSED_HANDLE) {
  2380. DP_ERR(cdev, "qed roce ll2 stop: cannot stop an unused LL2\n");
  2381. return -EINVAL;
  2382. }
  2383. /* remove LL2 MAC address filter */
  2384. rc = qed_roce_ll2_set_mac_filter(cdev, roce_ll2->mac_address, NULL);
  2385. eth_zero_addr(roce_ll2->mac_address);
  2386. rc = qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev),
  2387. roce_ll2->handle);
  2388. if (rc)
  2389. DP_ERR(cdev,
  2390. "qed roce ll2 stop: failed to terminate LL2 connection (rc=%d)\n",
  2391. rc);
  2392. qed_ll2_release_connection(QED_LEADING_HWFN(cdev), roce_ll2->handle);
  2393. roce_ll2->handle = QED_LL2_UNUSED_HANDLE;
  2394. kfree(roce_ll2);
  2395. return rc;
  2396. }
  2397. static int qed_roce_ll2_tx(struct qed_dev *cdev,
  2398. struct qed_roce_ll2_packet *pkt,
  2399. struct qed_roce_ll2_tx_params *params)
  2400. {
  2401. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  2402. struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2;
  2403. enum qed_ll2_roce_flavor_type qed_roce_flavor;
  2404. u8 flags = 0;
  2405. int rc;
  2406. int i;
  2407. if (!pkt || !params) {
  2408. DP_ERR(cdev,
  2409. "roce ll2 tx: failed tx because one of the following is NULL - drv=%p, pkt=%p, params=%p\n",
  2410. cdev, pkt, params);
  2411. return -EINVAL;
  2412. }
  2413. qed_roce_flavor = (pkt->roce_mode == ROCE_V1) ? QED_LL2_ROCE
  2414. : QED_LL2_RROCE;
  2415. if (pkt->roce_mode == ROCE_V2_IPV4)
  2416. flags |= BIT(CORE_TX_BD_DATA_IP_CSUM_SHIFT);
  2417. /* Tx header */
  2418. rc = qed_ll2_prepare_tx_packet(QED_LEADING_HWFN(cdev), roce_ll2->handle,
  2419. 1 + pkt->n_seg, 0, flags, 0,
  2420. QED_LL2_TX_DEST_NW,
  2421. qed_roce_flavor, pkt->header.baddr,
  2422. pkt->header.len, pkt, 1);
  2423. if (rc) {
  2424. DP_ERR(cdev, "roce ll2 tx: header failed (rc=%d)\n", rc);
  2425. return QED_ROCE_TX_HEAD_FAILURE;
  2426. }
  2427. /* Tx payload */
  2428. for (i = 0; i < pkt->n_seg; i++) {
  2429. rc = qed_ll2_set_fragment_of_tx_packet(QED_LEADING_HWFN(cdev),
  2430. roce_ll2->handle,
  2431. pkt->payload[i].baddr,
  2432. pkt->payload[i].len);
  2433. if (rc) {
  2434. /* If failed not much to do here, partial packet has
  2435. * been posted * we can't free memory, will need to wait
  2436. * for completion
  2437. */
  2438. DP_ERR(cdev,
  2439. "roce ll2 tx: payload failed (rc=%d)\n", rc);
  2440. return QED_ROCE_TX_FRAG_FAILURE;
  2441. }
  2442. }
  2443. return 0;
  2444. }
  2445. static int qed_roce_ll2_post_rx_buffer(struct qed_dev *cdev,
  2446. struct qed_roce_ll2_buffer *buf,
  2447. u64 cookie, u8 notify_fw)
  2448. {
  2449. return qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev),
  2450. QED_LEADING_HWFN(cdev)->ll2->handle,
  2451. buf->baddr, buf->len,
  2452. (void *)(uintptr_t)cookie, notify_fw);
  2453. }
  2454. static int qed_roce_ll2_stats(struct qed_dev *cdev, struct qed_ll2_stats *stats)
  2455. {
  2456. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  2457. struct qed_roce_ll2_info *roce_ll2 = hwfn->ll2;
  2458. return qed_ll2_get_stats(QED_LEADING_HWFN(cdev),
  2459. roce_ll2->handle, stats);
  2460. }
  2461. static const struct qed_rdma_ops qed_rdma_ops_pass = {
  2462. .common = &qed_common_ops_pass,
  2463. .fill_dev_info = &qed_fill_rdma_dev_info,
  2464. .rdma_get_rdma_ctx = &qed_rdma_get_rdma_ctx,
  2465. .rdma_init = &qed_rdma_init,
  2466. .rdma_add_user = &qed_rdma_add_user,
  2467. .rdma_remove_user = &qed_rdma_remove_user,
  2468. .rdma_stop = &qed_rdma_stop,
  2469. .rdma_query_port = &qed_rdma_query_port,
  2470. .rdma_query_device = &qed_rdma_query_device,
  2471. .rdma_get_start_sb = &qed_rdma_get_sb_start,
  2472. .rdma_get_rdma_int = &qed_rdma_get_int,
  2473. .rdma_set_rdma_int = &qed_rdma_set_int,
  2474. .rdma_get_min_cnq_msix = &qed_rdma_get_min_cnq_msix,
  2475. .rdma_cnq_prod_update = &qed_rdma_cnq_prod_update,
  2476. .rdma_alloc_pd = &qed_rdma_alloc_pd,
  2477. .rdma_dealloc_pd = &qed_rdma_free_pd,
  2478. .rdma_create_cq = &qed_rdma_create_cq,
  2479. .rdma_destroy_cq = &qed_rdma_destroy_cq,
  2480. .rdma_create_qp = &qed_rdma_create_qp,
  2481. .rdma_modify_qp = &qed_rdma_modify_qp,
  2482. .rdma_query_qp = &qed_rdma_query_qp,
  2483. .rdma_destroy_qp = &qed_rdma_destroy_qp,
  2484. .rdma_alloc_tid = &qed_rdma_alloc_tid,
  2485. .rdma_free_tid = &qed_rdma_free_tid,
  2486. .rdma_register_tid = &qed_rdma_register_tid,
  2487. .rdma_deregister_tid = &qed_rdma_deregister_tid,
  2488. .roce_ll2_start = &qed_roce_ll2_start,
  2489. .roce_ll2_stop = &qed_roce_ll2_stop,
  2490. .roce_ll2_tx = &qed_roce_ll2_tx,
  2491. .roce_ll2_post_rx_buffer = &qed_roce_ll2_post_rx_buffer,
  2492. .roce_ll2_set_mac_filter = &qed_roce_ll2_set_mac_filter,
  2493. .roce_ll2_stats = &qed_roce_ll2_stats,
  2494. };
  2495. const struct qed_rdma_ops *qed_get_rdma_ops(void)
  2496. {
  2497. return &qed_rdma_ops_pass;
  2498. }
  2499. EXPORT_SYMBOL(qed_get_rdma_ops);