qed_iwarp.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186
  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/if_ether.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/ip.h>
  35. #include <linux/ipv6.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/tcp.h>
  38. #include "qed_cxt.h"
  39. #include "qed_hw.h"
  40. #include "qed_ll2.h"
  41. #include "qed_rdma.h"
  42. #include "qed_reg_addr.h"
  43. #include "qed_sp.h"
  44. #include "qed_ooo.h"
  45. #define QED_IWARP_ORD_DEFAULT 32
  46. #define QED_IWARP_IRD_DEFAULT 32
  47. #define QED_IWARP_MAX_FW_MSS 4120
  48. #define QED_EP_SIG 0xecabcdef
  49. struct mpa_v2_hdr {
  50. __be16 ird;
  51. __be16 ord;
  52. };
  53. #define MPA_V2_PEER2PEER_MODEL 0x8000
  54. #define MPA_V2_SEND_RTR 0x4000 /* on ird */
  55. #define MPA_V2_READ_RTR 0x4000 /* on ord */
  56. #define MPA_V2_WRITE_RTR 0x8000
  57. #define MPA_V2_IRD_ORD_MASK 0x3FFF
  58. #define MPA_REV2(_mpa_rev) ((_mpa_rev) == MPA_NEGOTIATION_TYPE_ENHANCED)
  59. #define QED_IWARP_INVALID_TCP_CID 0xffffffff
  60. #define QED_IWARP_RCV_WND_SIZE_DEF (256 * 1024)
  61. #define QED_IWARP_RCV_WND_SIZE_MIN (0xffff)
  62. #define TIMESTAMP_HEADER_SIZE (12)
  63. #define QED_IWARP_MAX_FIN_RT_DEFAULT (2)
  64. #define QED_IWARP_TS_EN BIT(0)
  65. #define QED_IWARP_DA_EN BIT(1)
  66. #define QED_IWARP_PARAM_CRC_NEEDED (1)
  67. #define QED_IWARP_PARAM_P2P (1)
  68. #define QED_IWARP_DEF_MAX_RT_TIME (0)
  69. #define QED_IWARP_DEF_CWND_FACTOR (4)
  70. #define QED_IWARP_DEF_KA_MAX_PROBE_CNT (5)
  71. #define QED_IWARP_DEF_KA_TIMEOUT (1200000) /* 20 min */
  72. #define QED_IWARP_DEF_KA_INTERVAL (1000) /* 1 sec */
  73. static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
  74. u8 fw_event_code, u16 echo,
  75. union event_ring_data *data,
  76. u8 fw_return_code);
  77. /* Override devinfo with iWARP specific values */
  78. void qed_iwarp_init_devinfo(struct qed_hwfn *p_hwfn)
  79. {
  80. struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
  81. dev->max_inline = IWARP_REQ_MAX_INLINE_DATA_SIZE;
  82. dev->max_qp = min_t(u32,
  83. IWARP_MAX_QPS,
  84. p_hwfn->p_rdma_info->num_qps) -
  85. QED_IWARP_PREALLOC_CNT;
  86. dev->max_cq = dev->max_qp;
  87. dev->max_qp_resp_rd_atomic_resc = QED_IWARP_IRD_DEFAULT;
  88. dev->max_qp_req_rd_atomic_resc = QED_IWARP_ORD_DEFAULT;
  89. }
  90. void qed_iwarp_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  91. {
  92. p_hwfn->rdma_prs_search_reg = PRS_REG_SEARCH_TCP;
  93. qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
  94. p_hwfn->b_rdma_enabled_in_prs = true;
  95. }
  96. /* We have two cid maps, one for tcp which should be used only from passive
  97. * syn processing and replacing a pre-allocated ep in the list. The second
  98. * for active tcp and for QPs.
  99. */
  100. static void qed_iwarp_cid_cleaned(struct qed_hwfn *p_hwfn, u32 cid)
  101. {
  102. cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
  103. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  104. if (cid < QED_IWARP_PREALLOC_CNT)
  105. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map,
  106. cid);
  107. else
  108. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
  109. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  110. }
  111. void
  112. qed_iwarp_init_fw_ramrod(struct qed_hwfn *p_hwfn,
  113. struct iwarp_init_func_ramrod_data *p_ramrod)
  114. {
  115. p_ramrod->iwarp.ll2_ooo_q_index =
  116. RESC_START(p_hwfn, QED_LL2_QUEUE) +
  117. p_hwfn->p_rdma_info->iwarp.ll2_ooo_handle;
  118. p_ramrod->tcp.max_fin_rt = QED_IWARP_MAX_FIN_RT_DEFAULT;
  119. return;
  120. }
  121. static int qed_iwarp_alloc_cid(struct qed_hwfn *p_hwfn, u32 *cid)
  122. {
  123. int rc;
  124. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  125. rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, cid);
  126. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  127. if (rc) {
  128. DP_NOTICE(p_hwfn, "Failed in allocating iwarp cid\n");
  129. return rc;
  130. }
  131. *cid += qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
  132. rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *cid);
  133. if (rc)
  134. qed_iwarp_cid_cleaned(p_hwfn, *cid);
  135. return rc;
  136. }
  137. static void qed_iwarp_set_tcp_cid(struct qed_hwfn *p_hwfn, u32 cid)
  138. {
  139. cid -= qed_cxt_get_proto_cid_start(p_hwfn, p_hwfn->p_rdma_info->proto);
  140. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  141. qed_bmap_set_id(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, cid);
  142. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  143. }
  144. /* This function allocates a cid for passive tcp (called from syn receive)
  145. * the reason it's separate from the regular cid allocation is because it
  146. * is assured that these cids already have ilt allocated. They are preallocated
  147. * to ensure that we won't need to allocate memory during syn processing
  148. */
  149. static int qed_iwarp_alloc_tcp_cid(struct qed_hwfn *p_hwfn, u32 *cid)
  150. {
  151. int rc;
  152. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  153. rc = qed_rdma_bmap_alloc_id(p_hwfn,
  154. &p_hwfn->p_rdma_info->tcp_cid_map, cid);
  155. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  156. if (rc) {
  157. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  158. "can't allocate iwarp tcp cid max-count=%d\n",
  159. p_hwfn->p_rdma_info->tcp_cid_map.max_count);
  160. *cid = QED_IWARP_INVALID_TCP_CID;
  161. return rc;
  162. }
  163. *cid += qed_cxt_get_proto_cid_start(p_hwfn,
  164. p_hwfn->p_rdma_info->proto);
  165. return 0;
  166. }
  167. int qed_iwarp_create_qp(struct qed_hwfn *p_hwfn,
  168. struct qed_rdma_qp *qp,
  169. struct qed_rdma_create_qp_out_params *out_params)
  170. {
  171. struct iwarp_create_qp_ramrod_data *p_ramrod;
  172. struct qed_sp_init_data init_data;
  173. struct qed_spq_entry *p_ent;
  174. u16 physical_queue;
  175. u32 cid;
  176. int rc;
  177. qp->shared_queue = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  178. IWARP_SHARED_QUEUE_PAGE_SIZE,
  179. &qp->shared_queue_phys_addr,
  180. GFP_KERNEL);
  181. if (!qp->shared_queue)
  182. return -ENOMEM;
  183. out_params->sq_pbl_virt = (u8 *)qp->shared_queue +
  184. IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
  185. out_params->sq_pbl_phys = qp->shared_queue_phys_addr +
  186. IWARP_SHARED_QUEUE_PAGE_SQ_PBL_OFFSET;
  187. out_params->rq_pbl_virt = (u8 *)qp->shared_queue +
  188. IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
  189. out_params->rq_pbl_phys = qp->shared_queue_phys_addr +
  190. IWARP_SHARED_QUEUE_PAGE_RQ_PBL_OFFSET;
  191. rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
  192. if (rc)
  193. goto err1;
  194. qp->icid = (u16)cid;
  195. memset(&init_data, 0, sizeof(init_data));
  196. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  197. init_data.cid = qp->icid;
  198. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  199. rc = qed_sp_init_request(p_hwfn, &p_ent,
  200. IWARP_RAMROD_CMD_ID_CREATE_QP,
  201. PROTOCOLID_IWARP, &init_data);
  202. if (rc)
  203. goto err2;
  204. p_ramrod = &p_ent->ramrod.iwarp_create_qp;
  205. SET_FIELD(p_ramrod->flags,
  206. IWARP_CREATE_QP_RAMROD_DATA_FMR_AND_RESERVED_EN,
  207. qp->fmr_and_reserved_lkey);
  208. SET_FIELD(p_ramrod->flags,
  209. IWARP_CREATE_QP_RAMROD_DATA_SIGNALED_COMP, qp->signal_all);
  210. SET_FIELD(p_ramrod->flags,
  211. IWARP_CREATE_QP_RAMROD_DATA_RDMA_RD_EN,
  212. qp->incoming_rdma_read_en);
  213. SET_FIELD(p_ramrod->flags,
  214. IWARP_CREATE_QP_RAMROD_DATA_RDMA_WR_EN,
  215. qp->incoming_rdma_write_en);
  216. SET_FIELD(p_ramrod->flags,
  217. IWARP_CREATE_QP_RAMROD_DATA_ATOMIC_EN,
  218. qp->incoming_atomic_en);
  219. SET_FIELD(p_ramrod->flags,
  220. IWARP_CREATE_QP_RAMROD_DATA_SRQ_FLG, qp->use_srq);
  221. p_ramrod->pd = qp->pd;
  222. p_ramrod->sq_num_pages = qp->sq_num_pages;
  223. p_ramrod->rq_num_pages = qp->rq_num_pages;
  224. p_ramrod->qp_handle_for_cqe.hi = cpu_to_le32(qp->qp_handle.hi);
  225. p_ramrod->qp_handle_for_cqe.lo = cpu_to_le32(qp->qp_handle.lo);
  226. p_ramrod->cq_cid_for_sq =
  227. cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->sq_cq_id);
  228. p_ramrod->cq_cid_for_rq =
  229. cpu_to_le32((p_hwfn->hw_info.opaque_fid << 16) | qp->rq_cq_id);
  230. p_ramrod->dpi = cpu_to_le16(qp->dpi);
  231. physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
  232. p_ramrod->physical_q0 = cpu_to_le16(physical_queue);
  233. physical_queue = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
  234. p_ramrod->physical_q1 = cpu_to_le16(physical_queue);
  235. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  236. if (rc)
  237. goto err2;
  238. return rc;
  239. err2:
  240. qed_iwarp_cid_cleaned(p_hwfn, cid);
  241. err1:
  242. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  243. IWARP_SHARED_QUEUE_PAGE_SIZE,
  244. qp->shared_queue, qp->shared_queue_phys_addr);
  245. return rc;
  246. }
  247. static int qed_iwarp_modify_fw(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
  248. {
  249. struct iwarp_modify_qp_ramrod_data *p_ramrod;
  250. struct qed_sp_init_data init_data;
  251. struct qed_spq_entry *p_ent;
  252. int rc;
  253. /* Get SPQ entry */
  254. memset(&init_data, 0, sizeof(init_data));
  255. init_data.cid = qp->icid;
  256. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  257. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  258. rc = qed_sp_init_request(p_hwfn, &p_ent,
  259. IWARP_RAMROD_CMD_ID_MODIFY_QP,
  260. p_hwfn->p_rdma_info->proto, &init_data);
  261. if (rc)
  262. return rc;
  263. p_ramrod = &p_ent->ramrod.iwarp_modify_qp;
  264. SET_FIELD(p_ramrod->flags, IWARP_MODIFY_QP_RAMROD_DATA_STATE_TRANS_EN,
  265. 0x1);
  266. if (qp->iwarp_state == QED_IWARP_QP_STATE_CLOSING)
  267. p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_CLOSING;
  268. else
  269. p_ramrod->transition_to_state = IWARP_MODIFY_QP_STATE_ERROR;
  270. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  271. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x)rc=%d\n", qp->icid, rc);
  272. return rc;
  273. }
  274. enum qed_iwarp_qp_state qed_roce2iwarp_state(enum qed_roce_qp_state state)
  275. {
  276. switch (state) {
  277. case QED_ROCE_QP_STATE_RESET:
  278. case QED_ROCE_QP_STATE_INIT:
  279. case QED_ROCE_QP_STATE_RTR:
  280. return QED_IWARP_QP_STATE_IDLE;
  281. case QED_ROCE_QP_STATE_RTS:
  282. return QED_IWARP_QP_STATE_RTS;
  283. case QED_ROCE_QP_STATE_SQD:
  284. return QED_IWARP_QP_STATE_CLOSING;
  285. case QED_ROCE_QP_STATE_ERR:
  286. return QED_IWARP_QP_STATE_ERROR;
  287. case QED_ROCE_QP_STATE_SQE:
  288. return QED_IWARP_QP_STATE_TERMINATE;
  289. default:
  290. return QED_IWARP_QP_STATE_ERROR;
  291. }
  292. }
  293. static enum qed_roce_qp_state
  294. qed_iwarp2roce_state(enum qed_iwarp_qp_state state)
  295. {
  296. switch (state) {
  297. case QED_IWARP_QP_STATE_IDLE:
  298. return QED_ROCE_QP_STATE_INIT;
  299. case QED_IWARP_QP_STATE_RTS:
  300. return QED_ROCE_QP_STATE_RTS;
  301. case QED_IWARP_QP_STATE_TERMINATE:
  302. return QED_ROCE_QP_STATE_SQE;
  303. case QED_IWARP_QP_STATE_CLOSING:
  304. return QED_ROCE_QP_STATE_SQD;
  305. case QED_IWARP_QP_STATE_ERROR:
  306. return QED_ROCE_QP_STATE_ERR;
  307. default:
  308. return QED_ROCE_QP_STATE_ERR;
  309. }
  310. }
  311. const char *iwarp_state_names[] = {
  312. "IDLE",
  313. "RTS",
  314. "TERMINATE",
  315. "CLOSING",
  316. "ERROR",
  317. };
  318. int
  319. qed_iwarp_modify_qp(struct qed_hwfn *p_hwfn,
  320. struct qed_rdma_qp *qp,
  321. enum qed_iwarp_qp_state new_state, bool internal)
  322. {
  323. enum qed_iwarp_qp_state prev_iw_state;
  324. bool modify_fw = false;
  325. int rc = 0;
  326. /* modify QP can be called from upper-layer or as a result of async
  327. * RST/FIN... therefore need to protect
  328. */
  329. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
  330. prev_iw_state = qp->iwarp_state;
  331. if (prev_iw_state == new_state) {
  332. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
  333. return 0;
  334. }
  335. switch (prev_iw_state) {
  336. case QED_IWARP_QP_STATE_IDLE:
  337. switch (new_state) {
  338. case QED_IWARP_QP_STATE_RTS:
  339. qp->iwarp_state = QED_IWARP_QP_STATE_RTS;
  340. break;
  341. case QED_IWARP_QP_STATE_ERROR:
  342. qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
  343. if (!internal)
  344. modify_fw = true;
  345. break;
  346. default:
  347. break;
  348. }
  349. break;
  350. case QED_IWARP_QP_STATE_RTS:
  351. switch (new_state) {
  352. case QED_IWARP_QP_STATE_CLOSING:
  353. if (!internal)
  354. modify_fw = true;
  355. qp->iwarp_state = QED_IWARP_QP_STATE_CLOSING;
  356. break;
  357. case QED_IWARP_QP_STATE_ERROR:
  358. if (!internal)
  359. modify_fw = true;
  360. qp->iwarp_state = QED_IWARP_QP_STATE_ERROR;
  361. break;
  362. default:
  363. break;
  364. }
  365. break;
  366. case QED_IWARP_QP_STATE_ERROR:
  367. switch (new_state) {
  368. case QED_IWARP_QP_STATE_IDLE:
  369. qp->iwarp_state = new_state;
  370. break;
  371. case QED_IWARP_QP_STATE_CLOSING:
  372. /* could happen due to race... do nothing.... */
  373. break;
  374. default:
  375. rc = -EINVAL;
  376. }
  377. break;
  378. case QED_IWARP_QP_STATE_TERMINATE:
  379. case QED_IWARP_QP_STATE_CLOSING:
  380. qp->iwarp_state = new_state;
  381. break;
  382. default:
  383. break;
  384. }
  385. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) %s --> %s%s\n",
  386. qp->icid,
  387. iwarp_state_names[prev_iw_state],
  388. iwarp_state_names[qp->iwarp_state],
  389. internal ? "internal" : "");
  390. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.qp_lock);
  391. if (modify_fw)
  392. rc = qed_iwarp_modify_fw(p_hwfn, qp);
  393. return rc;
  394. }
  395. int qed_iwarp_fw_destroy(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
  396. {
  397. struct qed_sp_init_data init_data;
  398. struct qed_spq_entry *p_ent;
  399. int rc;
  400. /* Get SPQ entry */
  401. memset(&init_data, 0, sizeof(init_data));
  402. init_data.cid = qp->icid;
  403. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  404. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  405. rc = qed_sp_init_request(p_hwfn, &p_ent,
  406. IWARP_RAMROD_CMD_ID_DESTROY_QP,
  407. p_hwfn->p_rdma_info->proto, &init_data);
  408. if (rc)
  409. return rc;
  410. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  411. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) rc = %d\n", qp->icid, rc);
  412. return rc;
  413. }
  414. static void qed_iwarp_destroy_ep(struct qed_hwfn *p_hwfn,
  415. struct qed_iwarp_ep *ep,
  416. bool remove_from_active_list)
  417. {
  418. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  419. sizeof(*ep->ep_buffer_virt),
  420. ep->ep_buffer_virt, ep->ep_buffer_phys);
  421. if (remove_from_active_list) {
  422. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  423. list_del(&ep->list_entry);
  424. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  425. }
  426. if (ep->qp)
  427. ep->qp->ep = NULL;
  428. kfree(ep);
  429. }
  430. int qed_iwarp_destroy_qp(struct qed_hwfn *p_hwfn, struct qed_rdma_qp *qp)
  431. {
  432. struct qed_iwarp_ep *ep = qp->ep;
  433. int wait_count = 0;
  434. int rc = 0;
  435. if (qp->iwarp_state != QED_IWARP_QP_STATE_ERROR) {
  436. rc = qed_iwarp_modify_qp(p_hwfn, qp,
  437. QED_IWARP_QP_STATE_ERROR, false);
  438. if (rc)
  439. return rc;
  440. }
  441. /* Make sure ep is closed before returning and freeing memory. */
  442. if (ep) {
  443. while (ep->state != QED_IWARP_EP_CLOSED && wait_count++ < 200)
  444. msleep(100);
  445. if (ep->state != QED_IWARP_EP_CLOSED)
  446. DP_NOTICE(p_hwfn, "ep state close timeout state=%x\n",
  447. ep->state);
  448. qed_iwarp_destroy_ep(p_hwfn, ep, false);
  449. }
  450. rc = qed_iwarp_fw_destroy(p_hwfn, qp);
  451. if (qp->shared_queue)
  452. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  453. IWARP_SHARED_QUEUE_PAGE_SIZE,
  454. qp->shared_queue, qp->shared_queue_phys_addr);
  455. return rc;
  456. }
  457. static int
  458. qed_iwarp_create_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep **ep_out)
  459. {
  460. struct qed_iwarp_ep *ep;
  461. int rc;
  462. ep = kzalloc(sizeof(*ep), GFP_KERNEL);
  463. if (!ep)
  464. return -ENOMEM;
  465. ep->state = QED_IWARP_EP_INIT;
  466. ep->ep_buffer_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  467. sizeof(*ep->ep_buffer_virt),
  468. &ep->ep_buffer_phys,
  469. GFP_KERNEL);
  470. if (!ep->ep_buffer_virt) {
  471. rc = -ENOMEM;
  472. goto err;
  473. }
  474. ep->sig = QED_EP_SIG;
  475. *ep_out = ep;
  476. return 0;
  477. err:
  478. kfree(ep);
  479. return rc;
  480. }
  481. static void
  482. qed_iwarp_print_tcp_ramrod(struct qed_hwfn *p_hwfn,
  483. struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod)
  484. {
  485. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "local_mac=%x %x %x, remote_mac=%x %x %x\n",
  486. p_tcp_ramrod->tcp.local_mac_addr_lo,
  487. p_tcp_ramrod->tcp.local_mac_addr_mid,
  488. p_tcp_ramrod->tcp.local_mac_addr_hi,
  489. p_tcp_ramrod->tcp.remote_mac_addr_lo,
  490. p_tcp_ramrod->tcp.remote_mac_addr_mid,
  491. p_tcp_ramrod->tcp.remote_mac_addr_hi);
  492. if (p_tcp_ramrod->tcp.ip_version == TCP_IPV4) {
  493. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  494. "local_ip=%pI4h:%x, remote_ip=%pI4h:%x, vlan=%x\n",
  495. p_tcp_ramrod->tcp.local_ip,
  496. p_tcp_ramrod->tcp.local_port,
  497. p_tcp_ramrod->tcp.remote_ip,
  498. p_tcp_ramrod->tcp.remote_port,
  499. p_tcp_ramrod->tcp.vlan_id);
  500. } else {
  501. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  502. "local_ip=%pI6:%x, remote_ip=%pI6:%x, vlan=%x\n",
  503. p_tcp_ramrod->tcp.local_ip,
  504. p_tcp_ramrod->tcp.local_port,
  505. p_tcp_ramrod->tcp.remote_ip,
  506. p_tcp_ramrod->tcp.remote_port,
  507. p_tcp_ramrod->tcp.vlan_id);
  508. }
  509. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  510. "flow_label=%x, ttl=%x, tos_or_tc=%x, mss=%x, rcv_wnd_scale=%x, connect_mode=%x, flags=%x\n",
  511. p_tcp_ramrod->tcp.flow_label,
  512. p_tcp_ramrod->tcp.ttl,
  513. p_tcp_ramrod->tcp.tos_or_tc,
  514. p_tcp_ramrod->tcp.mss,
  515. p_tcp_ramrod->tcp.rcv_wnd_scale,
  516. p_tcp_ramrod->tcp.connect_mode,
  517. p_tcp_ramrod->tcp.flags);
  518. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "syn_ip_payload_length=%x, lo=%x, hi=%x\n",
  519. p_tcp_ramrod->tcp.syn_ip_payload_length,
  520. p_tcp_ramrod->tcp.syn_phy_addr_lo,
  521. p_tcp_ramrod->tcp.syn_phy_addr_hi);
  522. }
  523. static int
  524. qed_iwarp_tcp_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
  525. {
  526. struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  527. struct iwarp_tcp_offload_ramrod_data *p_tcp_ramrod;
  528. struct tcp_offload_params_opt2 *tcp;
  529. struct qed_sp_init_data init_data;
  530. struct qed_spq_entry *p_ent;
  531. dma_addr_t async_output_phys;
  532. dma_addr_t in_pdata_phys;
  533. u16 physical_q;
  534. u8 tcp_flags;
  535. int rc;
  536. int i;
  537. memset(&init_data, 0, sizeof(init_data));
  538. init_data.cid = ep->tcp_cid;
  539. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  540. if (ep->connect_mode == TCP_CONNECT_PASSIVE)
  541. init_data.comp_mode = QED_SPQ_MODE_CB;
  542. else
  543. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  544. rc = qed_sp_init_request(p_hwfn, &p_ent,
  545. IWARP_RAMROD_CMD_ID_TCP_OFFLOAD,
  546. PROTOCOLID_IWARP, &init_data);
  547. if (rc)
  548. return rc;
  549. p_tcp_ramrod = &p_ent->ramrod.iwarp_tcp_offload;
  550. in_pdata_phys = ep->ep_buffer_phys +
  551. offsetof(struct qed_iwarp_ep_memory, in_pdata);
  552. DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.incoming_ulp_buffer.addr,
  553. in_pdata_phys);
  554. p_tcp_ramrod->iwarp.incoming_ulp_buffer.len =
  555. cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata));
  556. async_output_phys = ep->ep_buffer_phys +
  557. offsetof(struct qed_iwarp_ep_memory, async_output);
  558. DMA_REGPAIR_LE(p_tcp_ramrod->iwarp.async_eqe_output_buf,
  559. async_output_phys);
  560. p_tcp_ramrod->iwarp.handle_for_async.hi = cpu_to_le32(PTR_HI(ep));
  561. p_tcp_ramrod->iwarp.handle_for_async.lo = cpu_to_le32(PTR_LO(ep));
  562. physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
  563. p_tcp_ramrod->iwarp.physical_q0 = cpu_to_le16(physical_q);
  564. physical_q = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_ACK);
  565. p_tcp_ramrod->iwarp.physical_q1 = cpu_to_le16(physical_q);
  566. p_tcp_ramrod->iwarp.mpa_mode = iwarp_info->mpa_rev;
  567. tcp = &p_tcp_ramrod->tcp;
  568. qed_set_fw_mac_addr(&tcp->remote_mac_addr_hi,
  569. &tcp->remote_mac_addr_mid,
  570. &tcp->remote_mac_addr_lo, ep->remote_mac_addr);
  571. qed_set_fw_mac_addr(&tcp->local_mac_addr_hi, &tcp->local_mac_addr_mid,
  572. &tcp->local_mac_addr_lo, ep->local_mac_addr);
  573. tcp->vlan_id = cpu_to_le16(ep->cm_info.vlan);
  574. tcp_flags = p_hwfn->p_rdma_info->iwarp.tcp_flags;
  575. tcp->flags = 0;
  576. SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_TS_EN,
  577. !!(tcp_flags & QED_IWARP_TS_EN));
  578. SET_FIELD(tcp->flags, TCP_OFFLOAD_PARAMS_OPT2_DA_EN,
  579. !!(tcp_flags & QED_IWARP_DA_EN));
  580. tcp->ip_version = ep->cm_info.ip_version;
  581. for (i = 0; i < 4; i++) {
  582. tcp->remote_ip[i] = cpu_to_le32(ep->cm_info.remote_ip[i]);
  583. tcp->local_ip[i] = cpu_to_le32(ep->cm_info.local_ip[i]);
  584. }
  585. tcp->remote_port = cpu_to_le16(ep->cm_info.remote_port);
  586. tcp->local_port = cpu_to_le16(ep->cm_info.local_port);
  587. tcp->mss = cpu_to_le16(ep->mss);
  588. tcp->flow_label = 0;
  589. tcp->ttl = 0x40;
  590. tcp->tos_or_tc = 0;
  591. tcp->max_rt_time = QED_IWARP_DEF_MAX_RT_TIME;
  592. tcp->cwnd = QED_IWARP_DEF_CWND_FACTOR * tcp->mss;
  593. tcp->ka_max_probe_cnt = QED_IWARP_DEF_KA_MAX_PROBE_CNT;
  594. tcp->ka_timeout = QED_IWARP_DEF_KA_TIMEOUT;
  595. tcp->ka_interval = QED_IWARP_DEF_KA_INTERVAL;
  596. tcp->rcv_wnd_scale = (u8)p_hwfn->p_rdma_info->iwarp.rcv_wnd_scale;
  597. tcp->connect_mode = ep->connect_mode;
  598. if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
  599. tcp->syn_ip_payload_length =
  600. cpu_to_le16(ep->syn_ip_payload_length);
  601. tcp->syn_phy_addr_hi = DMA_HI_LE(ep->syn_phy_addr);
  602. tcp->syn_phy_addr_lo = DMA_LO_LE(ep->syn_phy_addr);
  603. }
  604. qed_iwarp_print_tcp_ramrod(p_hwfn, p_tcp_ramrod);
  605. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  606. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  607. "EP(0x%x) Offload completed rc=%d\n", ep->tcp_cid, rc);
  608. return rc;
  609. }
  610. static void
  611. qed_iwarp_mpa_received(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
  612. {
  613. struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  614. struct qed_iwarp_cm_event_params params;
  615. struct mpa_v2_hdr *mpa_v2;
  616. union async_output *async_data;
  617. u16 mpa_ord, mpa_ird;
  618. u8 mpa_hdr_size = 0;
  619. u8 mpa_rev;
  620. async_data = &ep->ep_buffer_virt->async_output;
  621. mpa_rev = async_data->mpa_request.mpa_handshake_mode;
  622. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  623. "private_data_len=%x handshake_mode=%x private_data=(%x)\n",
  624. async_data->mpa_request.ulp_data_len,
  625. mpa_rev, *((u32 *)(ep->ep_buffer_virt->in_pdata)));
  626. if (mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) {
  627. /* Read ord/ird values from private data buffer */
  628. mpa_v2 = (struct mpa_v2_hdr *)ep->ep_buffer_virt->in_pdata;
  629. mpa_hdr_size = sizeof(*mpa_v2);
  630. mpa_ord = ntohs(mpa_v2->ord);
  631. mpa_ird = ntohs(mpa_v2->ird);
  632. /* Temprary store in cm_info incoming ord/ird requested, later
  633. * replace with negotiated value during accept
  634. */
  635. ep->cm_info.ord = (u8)min_t(u16,
  636. (mpa_ord & MPA_V2_IRD_ORD_MASK),
  637. QED_IWARP_ORD_DEFAULT);
  638. ep->cm_info.ird = (u8)min_t(u16,
  639. (mpa_ird & MPA_V2_IRD_ORD_MASK),
  640. QED_IWARP_IRD_DEFAULT);
  641. /* Peer2Peer negotiation */
  642. ep->rtr_type = MPA_RTR_TYPE_NONE;
  643. if (mpa_ird & MPA_V2_PEER2PEER_MODEL) {
  644. if (mpa_ord & MPA_V2_WRITE_RTR)
  645. ep->rtr_type |= MPA_RTR_TYPE_ZERO_WRITE;
  646. if (mpa_ord & MPA_V2_READ_RTR)
  647. ep->rtr_type |= MPA_RTR_TYPE_ZERO_READ;
  648. if (mpa_ird & MPA_V2_SEND_RTR)
  649. ep->rtr_type |= MPA_RTR_TYPE_ZERO_SEND;
  650. ep->rtr_type &= iwarp_info->rtr_type;
  651. /* if we're left with no match send our capabilities */
  652. if (ep->rtr_type == MPA_RTR_TYPE_NONE)
  653. ep->rtr_type = iwarp_info->rtr_type;
  654. }
  655. ep->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
  656. } else {
  657. ep->cm_info.ord = QED_IWARP_ORD_DEFAULT;
  658. ep->cm_info.ird = QED_IWARP_IRD_DEFAULT;
  659. ep->mpa_rev = MPA_NEGOTIATION_TYPE_BASIC;
  660. }
  661. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  662. "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x rtr:0x%x ulp_data_len = %x mpa_hdr_size = %x\n",
  663. mpa_rev, ep->cm_info.ord, ep->cm_info.ird, ep->rtr_type,
  664. async_data->mpa_request.ulp_data_len, mpa_hdr_size);
  665. /* Strip mpa v2 hdr from private data before sending to upper layer */
  666. ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_hdr_size;
  667. ep->cm_info.private_data_len = async_data->mpa_request.ulp_data_len -
  668. mpa_hdr_size;
  669. params.event = QED_IWARP_EVENT_MPA_REQUEST;
  670. params.cm_info = &ep->cm_info;
  671. params.ep_context = ep;
  672. params.status = 0;
  673. ep->state = QED_IWARP_EP_MPA_REQ_RCVD;
  674. ep->event_cb(ep->cb_context, &params);
  675. }
  676. static int
  677. qed_iwarp_mpa_offload(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
  678. {
  679. struct iwarp_mpa_offload_ramrod_data *p_mpa_ramrod;
  680. struct qed_iwarp_info *iwarp_info;
  681. struct qed_sp_init_data init_data;
  682. dma_addr_t async_output_phys;
  683. struct qed_spq_entry *p_ent;
  684. dma_addr_t out_pdata_phys;
  685. dma_addr_t in_pdata_phys;
  686. struct qed_rdma_qp *qp;
  687. bool reject;
  688. int rc;
  689. if (!ep)
  690. return -EINVAL;
  691. qp = ep->qp;
  692. reject = !qp;
  693. memset(&init_data, 0, sizeof(init_data));
  694. init_data.cid = reject ? ep->tcp_cid : qp->icid;
  695. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  696. if (ep->connect_mode == TCP_CONNECT_ACTIVE)
  697. init_data.comp_mode = QED_SPQ_MODE_CB;
  698. else
  699. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  700. rc = qed_sp_init_request(p_hwfn, &p_ent,
  701. IWARP_RAMROD_CMD_ID_MPA_OFFLOAD,
  702. PROTOCOLID_IWARP, &init_data);
  703. if (rc)
  704. return rc;
  705. p_mpa_ramrod = &p_ent->ramrod.iwarp_mpa_offload;
  706. out_pdata_phys = ep->ep_buffer_phys +
  707. offsetof(struct qed_iwarp_ep_memory, out_pdata);
  708. DMA_REGPAIR_LE(p_mpa_ramrod->common.outgoing_ulp_buffer.addr,
  709. out_pdata_phys);
  710. p_mpa_ramrod->common.outgoing_ulp_buffer.len =
  711. ep->cm_info.private_data_len;
  712. p_mpa_ramrod->common.crc_needed = p_hwfn->p_rdma_info->iwarp.crc_needed;
  713. p_mpa_ramrod->common.out_rq.ord = ep->cm_info.ord;
  714. p_mpa_ramrod->common.out_rq.ird = ep->cm_info.ird;
  715. p_mpa_ramrod->tcp_cid = p_hwfn->hw_info.opaque_fid << 16 | ep->tcp_cid;
  716. in_pdata_phys = ep->ep_buffer_phys +
  717. offsetof(struct qed_iwarp_ep_memory, in_pdata);
  718. p_mpa_ramrod->tcp_connect_side = ep->connect_mode;
  719. DMA_REGPAIR_LE(p_mpa_ramrod->incoming_ulp_buffer.addr,
  720. in_pdata_phys);
  721. p_mpa_ramrod->incoming_ulp_buffer.len =
  722. cpu_to_le16(sizeof(ep->ep_buffer_virt->in_pdata));
  723. async_output_phys = ep->ep_buffer_phys +
  724. offsetof(struct qed_iwarp_ep_memory, async_output);
  725. DMA_REGPAIR_LE(p_mpa_ramrod->async_eqe_output_buf,
  726. async_output_phys);
  727. p_mpa_ramrod->handle_for_async.hi = cpu_to_le32(PTR_HI(ep));
  728. p_mpa_ramrod->handle_for_async.lo = cpu_to_le32(PTR_LO(ep));
  729. if (!reject) {
  730. DMA_REGPAIR_LE(p_mpa_ramrod->shared_queue_addr,
  731. qp->shared_queue_phys_addr);
  732. p_mpa_ramrod->stats_counter_id =
  733. RESC_START(p_hwfn, QED_RDMA_STATS_QUEUE) + qp->stats_queue;
  734. } else {
  735. p_mpa_ramrod->common.reject = 1;
  736. }
  737. iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  738. p_mpa_ramrod->rcv_wnd = iwarp_info->rcv_wnd_size;
  739. p_mpa_ramrod->mode = ep->mpa_rev;
  740. SET_FIELD(p_mpa_ramrod->rtr_pref,
  741. IWARP_MPA_OFFLOAD_RAMROD_DATA_RTR_SUPPORTED, ep->rtr_type);
  742. ep->state = QED_IWARP_EP_MPA_OFFLOADED;
  743. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  744. if (!reject)
  745. ep->cid = qp->icid; /* Now they're migrated. */
  746. DP_VERBOSE(p_hwfn,
  747. QED_MSG_RDMA,
  748. "QP(0x%x) EP(0x%x) MPA Offload rc = %d IRD=0x%x ORD=0x%x rtr_type=%d mpa_rev=%d reject=%d\n",
  749. reject ? 0xffff : qp->icid,
  750. ep->tcp_cid,
  751. rc,
  752. ep->cm_info.ird,
  753. ep->cm_info.ord, ep->rtr_type, ep->mpa_rev, reject);
  754. return rc;
  755. }
  756. static void
  757. qed_iwarp_return_ep(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
  758. {
  759. ep->state = QED_IWARP_EP_INIT;
  760. if (ep->qp)
  761. ep->qp->ep = NULL;
  762. ep->qp = NULL;
  763. memset(&ep->cm_info, 0, sizeof(ep->cm_info));
  764. if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) {
  765. /* We don't care about the return code, it's ok if tcp_cid
  766. * remains invalid...in this case we'll defer allocation
  767. */
  768. qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid);
  769. }
  770. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  771. list_del(&ep->list_entry);
  772. list_add_tail(&ep->list_entry,
  773. &p_hwfn->p_rdma_info->iwarp.ep_free_list);
  774. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  775. }
  776. void
  777. qed_iwarp_parse_private_data(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
  778. {
  779. struct mpa_v2_hdr *mpa_v2_params;
  780. union async_output *async_data;
  781. u16 mpa_ird, mpa_ord;
  782. u8 mpa_data_size = 0;
  783. if (MPA_REV2(p_hwfn->p_rdma_info->iwarp.mpa_rev)) {
  784. mpa_v2_params =
  785. (struct mpa_v2_hdr *)(ep->ep_buffer_virt->in_pdata);
  786. mpa_data_size = sizeof(*mpa_v2_params);
  787. mpa_ird = ntohs(mpa_v2_params->ird);
  788. mpa_ord = ntohs(mpa_v2_params->ord);
  789. ep->cm_info.ird = (u8)(mpa_ord & MPA_V2_IRD_ORD_MASK);
  790. ep->cm_info.ord = (u8)(mpa_ird & MPA_V2_IRD_ORD_MASK);
  791. }
  792. async_data = &ep->ep_buffer_virt->async_output;
  793. ep->cm_info.private_data = ep->ep_buffer_virt->in_pdata + mpa_data_size;
  794. ep->cm_info.private_data_len = async_data->mpa_response.ulp_data_len -
  795. mpa_data_size;
  796. }
  797. void
  798. qed_iwarp_mpa_reply_arrived(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
  799. {
  800. struct qed_iwarp_cm_event_params params;
  801. if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
  802. DP_NOTICE(p_hwfn,
  803. "MPA reply event not expected on passive side!\n");
  804. return;
  805. }
  806. params.event = QED_IWARP_EVENT_ACTIVE_MPA_REPLY;
  807. qed_iwarp_parse_private_data(p_hwfn, ep);
  808. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  809. "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n",
  810. ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird);
  811. params.cm_info = &ep->cm_info;
  812. params.ep_context = ep;
  813. params.status = 0;
  814. ep->mpa_reply_processed = true;
  815. ep->event_cb(ep->cb_context, &params);
  816. }
  817. #define QED_IWARP_CONNECT_MODE_STRING(ep) \
  818. ((ep)->connect_mode == TCP_CONNECT_PASSIVE) ? "Passive" : "Active"
  819. /* Called as a result of the event:
  820. * IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE
  821. */
  822. static void
  823. qed_iwarp_mpa_complete(struct qed_hwfn *p_hwfn,
  824. struct qed_iwarp_ep *ep, u8 fw_return_code)
  825. {
  826. struct qed_iwarp_cm_event_params params;
  827. if (ep->connect_mode == TCP_CONNECT_ACTIVE)
  828. params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE;
  829. else
  830. params.event = QED_IWARP_EVENT_PASSIVE_COMPLETE;
  831. if (ep->connect_mode == TCP_CONNECT_ACTIVE && !ep->mpa_reply_processed)
  832. qed_iwarp_parse_private_data(p_hwfn, ep);
  833. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  834. "MPA_NEGOTIATE (v%d): ORD: 0x%x IRD: 0x%x\n",
  835. ep->mpa_rev, ep->cm_info.ord, ep->cm_info.ird);
  836. params.cm_info = &ep->cm_info;
  837. params.ep_context = ep;
  838. ep->state = QED_IWARP_EP_CLOSED;
  839. switch (fw_return_code) {
  840. case RDMA_RETURN_OK:
  841. ep->qp->max_rd_atomic_req = ep->cm_info.ord;
  842. ep->qp->max_rd_atomic_resp = ep->cm_info.ird;
  843. qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_RTS, 1);
  844. ep->state = QED_IWARP_EP_ESTABLISHED;
  845. params.status = 0;
  846. break;
  847. case IWARP_CONN_ERROR_MPA_TIMEOUT:
  848. DP_NOTICE(p_hwfn, "%s(0x%x) MPA timeout\n",
  849. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  850. params.status = -EBUSY;
  851. break;
  852. case IWARP_CONN_ERROR_MPA_ERROR_REJECT:
  853. DP_NOTICE(p_hwfn, "%s(0x%x) MPA Reject\n",
  854. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  855. params.status = -ECONNREFUSED;
  856. break;
  857. case IWARP_CONN_ERROR_MPA_RST:
  858. DP_NOTICE(p_hwfn, "%s(0x%x) MPA reset(tcp cid: 0x%x)\n",
  859. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid,
  860. ep->tcp_cid);
  861. params.status = -ECONNRESET;
  862. break;
  863. case IWARP_CONN_ERROR_MPA_FIN:
  864. DP_NOTICE(p_hwfn, "%s(0x%x) MPA received FIN\n",
  865. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  866. params.status = -ECONNREFUSED;
  867. break;
  868. case IWARP_CONN_ERROR_MPA_INSUF_IRD:
  869. DP_NOTICE(p_hwfn, "%s(0x%x) MPA insufficient ird\n",
  870. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  871. params.status = -ECONNREFUSED;
  872. break;
  873. case IWARP_CONN_ERROR_MPA_RTR_MISMATCH:
  874. DP_NOTICE(p_hwfn, "%s(0x%x) MPA RTR MISMATCH\n",
  875. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  876. params.status = -ECONNREFUSED;
  877. break;
  878. case IWARP_CONN_ERROR_MPA_INVALID_PACKET:
  879. DP_NOTICE(p_hwfn, "%s(0x%x) MPA Invalid Packet\n",
  880. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  881. params.status = -ECONNREFUSED;
  882. break;
  883. case IWARP_CONN_ERROR_MPA_LOCAL_ERROR:
  884. DP_NOTICE(p_hwfn, "%s(0x%x) MPA Local Error\n",
  885. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  886. params.status = -ECONNREFUSED;
  887. break;
  888. case IWARP_CONN_ERROR_MPA_TERMINATE:
  889. DP_NOTICE(p_hwfn, "%s(0x%x) MPA TERMINATE\n",
  890. QED_IWARP_CONNECT_MODE_STRING(ep), ep->cid);
  891. params.status = -ECONNREFUSED;
  892. break;
  893. default:
  894. params.status = -ECONNRESET;
  895. break;
  896. }
  897. ep->event_cb(ep->cb_context, &params);
  898. /* on passive side, if there is no associated QP (REJECT) we need to
  899. * return the ep to the pool, (in the regular case we add an element
  900. * in accept instead of this one.
  901. * In both cases we need to remove it from the ep_list.
  902. */
  903. if (fw_return_code != RDMA_RETURN_OK) {
  904. ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
  905. if ((ep->connect_mode == TCP_CONNECT_PASSIVE) &&
  906. (!ep->qp)) { /* Rejected */
  907. qed_iwarp_return_ep(p_hwfn, ep);
  908. } else {
  909. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  910. list_del(&ep->list_entry);
  911. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  912. }
  913. }
  914. }
  915. static void
  916. qed_iwarp_mpa_v2_set_private(struct qed_hwfn *p_hwfn,
  917. struct qed_iwarp_ep *ep, u8 *mpa_data_size)
  918. {
  919. struct mpa_v2_hdr *mpa_v2_params;
  920. u16 mpa_ird, mpa_ord;
  921. *mpa_data_size = 0;
  922. if (MPA_REV2(ep->mpa_rev)) {
  923. mpa_v2_params =
  924. (struct mpa_v2_hdr *)ep->ep_buffer_virt->out_pdata;
  925. *mpa_data_size = sizeof(*mpa_v2_params);
  926. mpa_ird = (u16)ep->cm_info.ird;
  927. mpa_ord = (u16)ep->cm_info.ord;
  928. if (ep->rtr_type != MPA_RTR_TYPE_NONE) {
  929. mpa_ird |= MPA_V2_PEER2PEER_MODEL;
  930. if (ep->rtr_type & MPA_RTR_TYPE_ZERO_SEND)
  931. mpa_ird |= MPA_V2_SEND_RTR;
  932. if (ep->rtr_type & MPA_RTR_TYPE_ZERO_WRITE)
  933. mpa_ord |= MPA_V2_WRITE_RTR;
  934. if (ep->rtr_type & MPA_RTR_TYPE_ZERO_READ)
  935. mpa_ord |= MPA_V2_READ_RTR;
  936. }
  937. mpa_v2_params->ird = htons(mpa_ird);
  938. mpa_v2_params->ord = htons(mpa_ord);
  939. DP_VERBOSE(p_hwfn,
  940. QED_MSG_RDMA,
  941. "MPA_NEGOTIATE Header: [%x ord:%x ird] %x ord:%x ird:%x peer2peer:%x rtr_send:%x rtr_write:%x rtr_read:%x\n",
  942. mpa_v2_params->ird,
  943. mpa_v2_params->ord,
  944. *((u32 *)mpa_v2_params),
  945. mpa_ord & MPA_V2_IRD_ORD_MASK,
  946. mpa_ird & MPA_V2_IRD_ORD_MASK,
  947. !!(mpa_ird & MPA_V2_PEER2PEER_MODEL),
  948. !!(mpa_ird & MPA_V2_SEND_RTR),
  949. !!(mpa_ord & MPA_V2_WRITE_RTR),
  950. !!(mpa_ord & MPA_V2_READ_RTR));
  951. }
  952. }
  953. int qed_iwarp_connect(void *rdma_cxt,
  954. struct qed_iwarp_connect_in *iparams,
  955. struct qed_iwarp_connect_out *oparams)
  956. {
  957. struct qed_hwfn *p_hwfn = rdma_cxt;
  958. struct qed_iwarp_info *iwarp_info;
  959. struct qed_iwarp_ep *ep;
  960. u8 mpa_data_size = 0;
  961. u8 ts_hdr_size = 0;
  962. u32 cid;
  963. int rc;
  964. if ((iparams->cm_info.ord > QED_IWARP_ORD_DEFAULT) ||
  965. (iparams->cm_info.ird > QED_IWARP_IRD_DEFAULT)) {
  966. DP_NOTICE(p_hwfn,
  967. "QP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n",
  968. iparams->qp->icid, iparams->cm_info.ord,
  969. iparams->cm_info.ird);
  970. return -EINVAL;
  971. }
  972. iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  973. /* Allocate ep object */
  974. rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
  975. if (rc)
  976. return rc;
  977. rc = qed_iwarp_create_ep(p_hwfn, &ep);
  978. if (rc)
  979. goto err;
  980. ep->tcp_cid = cid;
  981. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  982. list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list);
  983. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  984. ep->qp = iparams->qp;
  985. ep->qp->ep = ep;
  986. ether_addr_copy(ep->remote_mac_addr, iparams->remote_mac_addr);
  987. ether_addr_copy(ep->local_mac_addr, iparams->local_mac_addr);
  988. memcpy(&ep->cm_info, &iparams->cm_info, sizeof(ep->cm_info));
  989. ep->cm_info.ord = iparams->cm_info.ord;
  990. ep->cm_info.ird = iparams->cm_info.ird;
  991. ep->rtr_type = iwarp_info->rtr_type;
  992. if (!iwarp_info->peer2peer)
  993. ep->rtr_type = MPA_RTR_TYPE_NONE;
  994. if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) && (ep->cm_info.ord == 0))
  995. ep->cm_info.ord = 1;
  996. ep->mpa_rev = iwarp_info->mpa_rev;
  997. qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
  998. ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
  999. ep->cm_info.private_data_len = iparams->cm_info.private_data_len +
  1000. mpa_data_size;
  1001. memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
  1002. iparams->cm_info.private_data,
  1003. iparams->cm_info.private_data_len);
  1004. if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN)
  1005. ts_hdr_size = TIMESTAMP_HEADER_SIZE;
  1006. ep->mss = iparams->mss - ts_hdr_size;
  1007. ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss);
  1008. ep->event_cb = iparams->event_cb;
  1009. ep->cb_context = iparams->cb_context;
  1010. ep->connect_mode = TCP_CONNECT_ACTIVE;
  1011. oparams->ep_context = ep;
  1012. rc = qed_iwarp_tcp_offload(p_hwfn, ep);
  1013. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x) rc = %d\n",
  1014. iparams->qp->icid, ep->tcp_cid, rc);
  1015. if (rc) {
  1016. qed_iwarp_destroy_ep(p_hwfn, ep, true);
  1017. goto err;
  1018. }
  1019. return rc;
  1020. err:
  1021. qed_iwarp_cid_cleaned(p_hwfn, cid);
  1022. return rc;
  1023. }
  1024. static struct qed_iwarp_ep *qed_iwarp_get_free_ep(struct qed_hwfn *p_hwfn)
  1025. {
  1026. struct qed_iwarp_ep *ep = NULL;
  1027. int rc;
  1028. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1029. if (list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) {
  1030. DP_ERR(p_hwfn, "Ep list is empty\n");
  1031. goto out;
  1032. }
  1033. ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list,
  1034. struct qed_iwarp_ep, list_entry);
  1035. /* in some cases we could have failed allocating a tcp cid when added
  1036. * from accept / failure... retry now..this is not the common case.
  1037. */
  1038. if (ep->tcp_cid == QED_IWARP_INVALID_TCP_CID) {
  1039. rc = qed_iwarp_alloc_tcp_cid(p_hwfn, &ep->tcp_cid);
  1040. /* if we fail we could look for another entry with a valid
  1041. * tcp_cid, but since we don't expect to reach this anyway
  1042. * it's not worth the handling
  1043. */
  1044. if (rc) {
  1045. ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
  1046. ep = NULL;
  1047. goto out;
  1048. }
  1049. }
  1050. list_del(&ep->list_entry);
  1051. out:
  1052. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1053. return ep;
  1054. }
  1055. #define QED_IWARP_MAX_CID_CLEAN_TIME 100
  1056. #define QED_IWARP_MAX_NO_PROGRESS_CNT 5
  1057. /* This function waits for all the bits of a bmap to be cleared, as long as
  1058. * there is progress ( i.e. the number of bits left to be cleared decreases )
  1059. * the function continues.
  1060. */
  1061. static int
  1062. qed_iwarp_wait_cid_map_cleared(struct qed_hwfn *p_hwfn, struct qed_bmap *bmap)
  1063. {
  1064. int prev_weight = 0;
  1065. int wait_count = 0;
  1066. int weight = 0;
  1067. weight = bitmap_weight(bmap->bitmap, bmap->max_count);
  1068. prev_weight = weight;
  1069. while (weight) {
  1070. msleep(QED_IWARP_MAX_CID_CLEAN_TIME);
  1071. weight = bitmap_weight(bmap->bitmap, bmap->max_count);
  1072. if (prev_weight == weight) {
  1073. wait_count++;
  1074. } else {
  1075. prev_weight = weight;
  1076. wait_count = 0;
  1077. }
  1078. if (wait_count > QED_IWARP_MAX_NO_PROGRESS_CNT) {
  1079. DP_NOTICE(p_hwfn,
  1080. "%s bitmap wait timed out (%d cids pending)\n",
  1081. bmap->name, weight);
  1082. return -EBUSY;
  1083. }
  1084. }
  1085. return 0;
  1086. }
  1087. static int qed_iwarp_wait_for_all_cids(struct qed_hwfn *p_hwfn)
  1088. {
  1089. int rc;
  1090. int i;
  1091. rc = qed_iwarp_wait_cid_map_cleared(p_hwfn,
  1092. &p_hwfn->p_rdma_info->tcp_cid_map);
  1093. if (rc)
  1094. return rc;
  1095. /* Now free the tcp cids from the main cid map */
  1096. for (i = 0; i < QED_IWARP_PREALLOC_CNT; i++)
  1097. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->cid_map, i);
  1098. /* Now wait for all cids to be completed */
  1099. return qed_iwarp_wait_cid_map_cleared(p_hwfn,
  1100. &p_hwfn->p_rdma_info->cid_map);
  1101. }
  1102. static void qed_iwarp_free_prealloc_ep(struct qed_hwfn *p_hwfn)
  1103. {
  1104. struct qed_iwarp_ep *ep;
  1105. while (!list_empty(&p_hwfn->p_rdma_info->iwarp.ep_free_list)) {
  1106. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1107. ep = list_first_entry(&p_hwfn->p_rdma_info->iwarp.ep_free_list,
  1108. struct qed_iwarp_ep, list_entry);
  1109. if (!ep) {
  1110. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1111. break;
  1112. }
  1113. list_del(&ep->list_entry);
  1114. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1115. if (ep->tcp_cid != QED_IWARP_INVALID_TCP_CID)
  1116. qed_iwarp_cid_cleaned(p_hwfn, ep->tcp_cid);
  1117. qed_iwarp_destroy_ep(p_hwfn, ep, false);
  1118. }
  1119. }
  1120. static int qed_iwarp_prealloc_ep(struct qed_hwfn *p_hwfn, bool init)
  1121. {
  1122. struct qed_iwarp_ep *ep;
  1123. int rc = 0;
  1124. int count;
  1125. u32 cid;
  1126. int i;
  1127. count = init ? QED_IWARP_PREALLOC_CNT : 1;
  1128. for (i = 0; i < count; i++) {
  1129. rc = qed_iwarp_create_ep(p_hwfn, &ep);
  1130. if (rc)
  1131. return rc;
  1132. /* During initialization we allocate from the main pool,
  1133. * afterwards we allocate only from the tcp_cid.
  1134. */
  1135. if (init) {
  1136. rc = qed_iwarp_alloc_cid(p_hwfn, &cid);
  1137. if (rc)
  1138. goto err;
  1139. qed_iwarp_set_tcp_cid(p_hwfn, cid);
  1140. } else {
  1141. /* We don't care about the return code, it's ok if
  1142. * tcp_cid remains invalid...in this case we'll
  1143. * defer allocation
  1144. */
  1145. qed_iwarp_alloc_tcp_cid(p_hwfn, &cid);
  1146. }
  1147. ep->tcp_cid = cid;
  1148. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1149. list_add_tail(&ep->list_entry,
  1150. &p_hwfn->p_rdma_info->iwarp.ep_free_list);
  1151. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1152. }
  1153. return rc;
  1154. err:
  1155. qed_iwarp_destroy_ep(p_hwfn, ep, false);
  1156. return rc;
  1157. }
  1158. int qed_iwarp_alloc(struct qed_hwfn *p_hwfn)
  1159. {
  1160. int rc;
  1161. /* Allocate bitmap for tcp cid. These are used by passive side
  1162. * to ensure it can allocate a tcp cid during dpc that was
  1163. * pre-acquired and doesn't require dynamic allocation of ilt
  1164. */
  1165. rc = qed_rdma_bmap_alloc(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map,
  1166. QED_IWARP_PREALLOC_CNT, "TCP_CID");
  1167. if (rc) {
  1168. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1169. "Failed to allocate tcp cid, rc = %d\n", rc);
  1170. return rc;
  1171. }
  1172. INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_free_list);
  1173. spin_lock_init(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1174. rc = qed_iwarp_prealloc_ep(p_hwfn, true);
  1175. if (rc)
  1176. return rc;
  1177. return qed_ooo_alloc(p_hwfn);
  1178. }
  1179. void qed_iwarp_resc_free(struct qed_hwfn *p_hwfn)
  1180. {
  1181. struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  1182. qed_ooo_free(p_hwfn);
  1183. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tcp_cid_map, 1);
  1184. kfree(iwarp_info->mpa_bufs);
  1185. kfree(iwarp_info->partial_fpdus);
  1186. kfree(iwarp_info->mpa_intermediate_buf);
  1187. }
  1188. int qed_iwarp_accept(void *rdma_cxt, struct qed_iwarp_accept_in *iparams)
  1189. {
  1190. struct qed_hwfn *p_hwfn = rdma_cxt;
  1191. struct qed_iwarp_ep *ep;
  1192. u8 mpa_data_size = 0;
  1193. int rc;
  1194. ep = iparams->ep_context;
  1195. if (!ep) {
  1196. DP_ERR(p_hwfn, "Ep Context receive in accept is NULL\n");
  1197. return -EINVAL;
  1198. }
  1199. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n",
  1200. iparams->qp->icid, ep->tcp_cid);
  1201. if ((iparams->ord > QED_IWARP_ORD_DEFAULT) ||
  1202. (iparams->ird > QED_IWARP_IRD_DEFAULT)) {
  1203. DP_VERBOSE(p_hwfn,
  1204. QED_MSG_RDMA,
  1205. "QP(0x%x) EP(0x%x) ERROR: Invalid ord(0x%x)/ird(0x%x)\n",
  1206. iparams->qp->icid,
  1207. ep->tcp_cid, iparams->ord, iparams->ord);
  1208. return -EINVAL;
  1209. }
  1210. qed_iwarp_prealloc_ep(p_hwfn, false);
  1211. ep->cb_context = iparams->cb_context;
  1212. ep->qp = iparams->qp;
  1213. ep->qp->ep = ep;
  1214. if (ep->mpa_rev == MPA_NEGOTIATION_TYPE_ENHANCED) {
  1215. /* Negotiate ord/ird: if upperlayer requested ord larger than
  1216. * ird advertised by remote, we need to decrease our ord
  1217. */
  1218. if (iparams->ord > ep->cm_info.ird)
  1219. iparams->ord = ep->cm_info.ird;
  1220. if ((ep->rtr_type & MPA_RTR_TYPE_ZERO_READ) &&
  1221. (iparams->ird == 0))
  1222. iparams->ird = 1;
  1223. }
  1224. /* Update cm_info ord/ird to be negotiated values */
  1225. ep->cm_info.ord = iparams->ord;
  1226. ep->cm_info.ird = iparams->ird;
  1227. qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
  1228. ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
  1229. ep->cm_info.private_data_len = iparams->private_data_len +
  1230. mpa_data_size;
  1231. memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
  1232. iparams->private_data, iparams->private_data_len);
  1233. rc = qed_iwarp_mpa_offload(p_hwfn, ep);
  1234. if (rc)
  1235. qed_iwarp_modify_qp(p_hwfn,
  1236. iparams->qp, QED_IWARP_QP_STATE_ERROR, 1);
  1237. return rc;
  1238. }
  1239. int qed_iwarp_reject(void *rdma_cxt, struct qed_iwarp_reject_in *iparams)
  1240. {
  1241. struct qed_hwfn *p_hwfn = rdma_cxt;
  1242. struct qed_iwarp_ep *ep;
  1243. u8 mpa_data_size = 0;
  1244. ep = iparams->ep_context;
  1245. if (!ep) {
  1246. DP_ERR(p_hwfn, "Ep Context receive in reject is NULL\n");
  1247. return -EINVAL;
  1248. }
  1249. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x)\n", ep->tcp_cid);
  1250. ep->cb_context = iparams->cb_context;
  1251. ep->qp = NULL;
  1252. qed_iwarp_mpa_v2_set_private(p_hwfn, ep, &mpa_data_size);
  1253. ep->cm_info.private_data = ep->ep_buffer_virt->out_pdata;
  1254. ep->cm_info.private_data_len = iparams->private_data_len +
  1255. mpa_data_size;
  1256. memcpy((u8 *)ep->ep_buffer_virt->out_pdata + mpa_data_size,
  1257. iparams->private_data, iparams->private_data_len);
  1258. return qed_iwarp_mpa_offload(p_hwfn, ep);
  1259. }
  1260. static void
  1261. qed_iwarp_print_cm_info(struct qed_hwfn *p_hwfn,
  1262. struct qed_iwarp_cm_info *cm_info)
  1263. {
  1264. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "ip_version = %d\n",
  1265. cm_info->ip_version);
  1266. if (cm_info->ip_version == QED_TCP_IPV4)
  1267. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1268. "remote_ip %pI4h:%x, local_ip %pI4h:%x vlan=%x\n",
  1269. cm_info->remote_ip, cm_info->remote_port,
  1270. cm_info->local_ip, cm_info->local_port,
  1271. cm_info->vlan);
  1272. else
  1273. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1274. "remote_ip %pI6:%x, local_ip %pI6:%x vlan=%x\n",
  1275. cm_info->remote_ip, cm_info->remote_port,
  1276. cm_info->local_ip, cm_info->local_port,
  1277. cm_info->vlan);
  1278. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1279. "private_data_len = %x ord = %d, ird = %d\n",
  1280. cm_info->private_data_len, cm_info->ord, cm_info->ird);
  1281. }
  1282. static int
  1283. qed_iwarp_ll2_post_rx(struct qed_hwfn *p_hwfn,
  1284. struct qed_iwarp_ll2_buff *buf, u8 handle)
  1285. {
  1286. int rc;
  1287. rc = qed_ll2_post_rx_buffer(p_hwfn, handle, buf->data_phys_addr,
  1288. (u16)buf->buff_size, buf, 1);
  1289. if (rc) {
  1290. DP_NOTICE(p_hwfn,
  1291. "Failed to repost rx buffer to ll2 rc = %d, handle=%d\n",
  1292. rc, handle);
  1293. dma_free_coherent(&p_hwfn->cdev->pdev->dev, buf->buff_size,
  1294. buf->data, buf->data_phys_addr);
  1295. kfree(buf);
  1296. }
  1297. return rc;
  1298. }
  1299. static bool
  1300. qed_iwarp_ep_exists(struct qed_hwfn *p_hwfn, struct qed_iwarp_cm_info *cm_info)
  1301. {
  1302. struct qed_iwarp_ep *ep = NULL;
  1303. bool found = false;
  1304. list_for_each_entry(ep,
  1305. &p_hwfn->p_rdma_info->iwarp.ep_list,
  1306. list_entry) {
  1307. if ((ep->cm_info.local_port == cm_info->local_port) &&
  1308. (ep->cm_info.remote_port == cm_info->remote_port) &&
  1309. (ep->cm_info.vlan == cm_info->vlan) &&
  1310. !memcmp(&ep->cm_info.local_ip, cm_info->local_ip,
  1311. sizeof(cm_info->local_ip)) &&
  1312. !memcmp(&ep->cm_info.remote_ip, cm_info->remote_ip,
  1313. sizeof(cm_info->remote_ip))) {
  1314. found = true;
  1315. break;
  1316. }
  1317. }
  1318. if (found) {
  1319. DP_NOTICE(p_hwfn,
  1320. "SYN received on active connection - dropping\n");
  1321. qed_iwarp_print_cm_info(p_hwfn, cm_info);
  1322. return true;
  1323. }
  1324. return false;
  1325. }
  1326. static struct qed_iwarp_listener *
  1327. qed_iwarp_get_listener(struct qed_hwfn *p_hwfn,
  1328. struct qed_iwarp_cm_info *cm_info)
  1329. {
  1330. struct qed_iwarp_listener *listener = NULL;
  1331. static const u32 ip_zero[4] = { 0, 0, 0, 0 };
  1332. bool found = false;
  1333. qed_iwarp_print_cm_info(p_hwfn, cm_info);
  1334. list_for_each_entry(listener,
  1335. &p_hwfn->p_rdma_info->iwarp.listen_list,
  1336. list_entry) {
  1337. if (listener->port == cm_info->local_port) {
  1338. if (!memcmp(listener->ip_addr,
  1339. ip_zero, sizeof(ip_zero))) {
  1340. found = true;
  1341. break;
  1342. }
  1343. if (!memcmp(listener->ip_addr,
  1344. cm_info->local_ip,
  1345. sizeof(cm_info->local_ip)) &&
  1346. (listener->vlan == cm_info->vlan)) {
  1347. found = true;
  1348. break;
  1349. }
  1350. }
  1351. }
  1352. if (found) {
  1353. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener found = %p\n",
  1354. listener);
  1355. return listener;
  1356. }
  1357. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "listener not found\n");
  1358. return NULL;
  1359. }
  1360. static int
  1361. qed_iwarp_parse_rx_pkt(struct qed_hwfn *p_hwfn,
  1362. struct qed_iwarp_cm_info *cm_info,
  1363. void *buf,
  1364. u8 *remote_mac_addr,
  1365. u8 *local_mac_addr,
  1366. int *payload_len, int *tcp_start_offset)
  1367. {
  1368. struct vlan_ethhdr *vethh;
  1369. bool vlan_valid = false;
  1370. struct ipv6hdr *ip6h;
  1371. struct ethhdr *ethh;
  1372. struct tcphdr *tcph;
  1373. struct iphdr *iph;
  1374. int eth_hlen;
  1375. int ip_hlen;
  1376. int eth_type;
  1377. int i;
  1378. ethh = buf;
  1379. eth_type = ntohs(ethh->h_proto);
  1380. if (eth_type == ETH_P_8021Q) {
  1381. vlan_valid = true;
  1382. vethh = (struct vlan_ethhdr *)ethh;
  1383. cm_info->vlan = ntohs(vethh->h_vlan_TCI) & VLAN_VID_MASK;
  1384. eth_type = ntohs(vethh->h_vlan_encapsulated_proto);
  1385. }
  1386. eth_hlen = ETH_HLEN + (vlan_valid ? sizeof(u32) : 0);
  1387. ether_addr_copy(remote_mac_addr, ethh->h_source);
  1388. ether_addr_copy(local_mac_addr, ethh->h_dest);
  1389. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_type =%d source mac: %pM\n",
  1390. eth_type, ethh->h_source);
  1391. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "eth_hlen=%d destination mac: %pM\n",
  1392. eth_hlen, ethh->h_dest);
  1393. iph = (struct iphdr *)((u8 *)(ethh) + eth_hlen);
  1394. if (eth_type == ETH_P_IP) {
  1395. if (iph->protocol != IPPROTO_TCP) {
  1396. DP_NOTICE(p_hwfn,
  1397. "Unexpected ip protocol on ll2 %x\n",
  1398. iph->protocol);
  1399. return -EINVAL;
  1400. }
  1401. cm_info->local_ip[0] = ntohl(iph->daddr);
  1402. cm_info->remote_ip[0] = ntohl(iph->saddr);
  1403. cm_info->ip_version = TCP_IPV4;
  1404. ip_hlen = (iph->ihl) * sizeof(u32);
  1405. *payload_len = ntohs(iph->tot_len) - ip_hlen;
  1406. } else if (eth_type == ETH_P_IPV6) {
  1407. ip6h = (struct ipv6hdr *)iph;
  1408. if (ip6h->nexthdr != IPPROTO_TCP) {
  1409. DP_NOTICE(p_hwfn,
  1410. "Unexpected ip protocol on ll2 %x\n",
  1411. iph->protocol);
  1412. return -EINVAL;
  1413. }
  1414. for (i = 0; i < 4; i++) {
  1415. cm_info->local_ip[i] =
  1416. ntohl(ip6h->daddr.in6_u.u6_addr32[i]);
  1417. cm_info->remote_ip[i] =
  1418. ntohl(ip6h->saddr.in6_u.u6_addr32[i]);
  1419. }
  1420. cm_info->ip_version = TCP_IPV6;
  1421. ip_hlen = sizeof(*ip6h);
  1422. *payload_len = ntohs(ip6h->payload_len);
  1423. } else {
  1424. DP_NOTICE(p_hwfn, "Unexpected ethertype on ll2 %x\n", eth_type);
  1425. return -EINVAL;
  1426. }
  1427. tcph = (struct tcphdr *)((u8 *)iph + ip_hlen);
  1428. if (!tcph->syn) {
  1429. DP_NOTICE(p_hwfn,
  1430. "Only SYN type packet expected on this ll2 conn, iph->ihl=%d source=%d dest=%d\n",
  1431. iph->ihl, tcph->source, tcph->dest);
  1432. return -EINVAL;
  1433. }
  1434. cm_info->local_port = ntohs(tcph->dest);
  1435. cm_info->remote_port = ntohs(tcph->source);
  1436. qed_iwarp_print_cm_info(p_hwfn, cm_info);
  1437. *tcp_start_offset = eth_hlen + ip_hlen;
  1438. return 0;
  1439. }
  1440. static struct qed_iwarp_fpdu *qed_iwarp_get_curr_fpdu(struct qed_hwfn *p_hwfn,
  1441. u16 cid)
  1442. {
  1443. struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  1444. struct qed_iwarp_fpdu *partial_fpdu;
  1445. u32 idx;
  1446. idx = cid - qed_cxt_get_proto_cid_start(p_hwfn, PROTOCOLID_IWARP);
  1447. if (idx >= iwarp_info->max_num_partial_fpdus) {
  1448. DP_ERR(p_hwfn, "Invalid cid %x max_num_partial_fpdus=%x\n", cid,
  1449. iwarp_info->max_num_partial_fpdus);
  1450. return NULL;
  1451. }
  1452. partial_fpdu = &iwarp_info->partial_fpdus[idx];
  1453. return partial_fpdu;
  1454. }
  1455. enum qed_iwarp_mpa_pkt_type {
  1456. QED_IWARP_MPA_PKT_PACKED,
  1457. QED_IWARP_MPA_PKT_PARTIAL,
  1458. QED_IWARP_MPA_PKT_UNALIGNED
  1459. };
  1460. #define QED_IWARP_INVALID_FPDU_LENGTH 0xffff
  1461. #define QED_IWARP_MPA_FPDU_LENGTH_SIZE (2)
  1462. #define QED_IWARP_MPA_CRC32_DIGEST_SIZE (4)
  1463. /* Pad to multiple of 4 */
  1464. #define QED_IWARP_PDU_DATA_LEN_WITH_PAD(data_len) ALIGN(data_len, 4)
  1465. #define QED_IWARP_FPDU_LEN_WITH_PAD(_mpa_len) \
  1466. (QED_IWARP_PDU_DATA_LEN_WITH_PAD((_mpa_len) + \
  1467. QED_IWARP_MPA_FPDU_LENGTH_SIZE) + \
  1468. QED_IWARP_MPA_CRC32_DIGEST_SIZE)
  1469. /* fpdu can be fragmented over maximum 3 bds: header, partial mpa, unaligned */
  1470. #define QED_IWARP_MAX_BDS_PER_FPDU 3
  1471. static const char * const pkt_type_str[] = {
  1472. "QED_IWARP_MPA_PKT_PACKED",
  1473. "QED_IWARP_MPA_PKT_PARTIAL",
  1474. "QED_IWARP_MPA_PKT_UNALIGNED"
  1475. };
  1476. static int
  1477. qed_iwarp_recycle_pkt(struct qed_hwfn *p_hwfn,
  1478. struct qed_iwarp_fpdu *fpdu,
  1479. struct qed_iwarp_ll2_buff *buf);
  1480. static enum qed_iwarp_mpa_pkt_type
  1481. qed_iwarp_mpa_classify(struct qed_hwfn *p_hwfn,
  1482. struct qed_iwarp_fpdu *fpdu,
  1483. u16 tcp_payload_len, u8 *mpa_data)
  1484. {
  1485. enum qed_iwarp_mpa_pkt_type pkt_type;
  1486. u16 mpa_len;
  1487. if (fpdu->incomplete_bytes) {
  1488. pkt_type = QED_IWARP_MPA_PKT_UNALIGNED;
  1489. goto out;
  1490. }
  1491. /* special case of one byte remaining...
  1492. * lower byte will be read next packet
  1493. */
  1494. if (tcp_payload_len == 1) {
  1495. fpdu->fpdu_length = *mpa_data << BITS_PER_BYTE;
  1496. pkt_type = QED_IWARP_MPA_PKT_PARTIAL;
  1497. goto out;
  1498. }
  1499. mpa_len = ntohs(*((u16 *)(mpa_data)));
  1500. fpdu->fpdu_length = QED_IWARP_FPDU_LEN_WITH_PAD(mpa_len);
  1501. if (fpdu->fpdu_length <= tcp_payload_len)
  1502. pkt_type = QED_IWARP_MPA_PKT_PACKED;
  1503. else
  1504. pkt_type = QED_IWARP_MPA_PKT_PARTIAL;
  1505. out:
  1506. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1507. "MPA_ALIGN: %s: fpdu_length=0x%x tcp_payload_len:0x%x\n",
  1508. pkt_type_str[pkt_type], fpdu->fpdu_length, tcp_payload_len);
  1509. return pkt_type;
  1510. }
  1511. static void
  1512. qed_iwarp_init_fpdu(struct qed_iwarp_ll2_buff *buf,
  1513. struct qed_iwarp_fpdu *fpdu,
  1514. struct unaligned_opaque_data *pkt_data,
  1515. u16 tcp_payload_size, u8 placement_offset)
  1516. {
  1517. fpdu->mpa_buf = buf;
  1518. fpdu->pkt_hdr = buf->data_phys_addr + placement_offset;
  1519. fpdu->pkt_hdr_size = pkt_data->tcp_payload_offset;
  1520. fpdu->mpa_frag = buf->data_phys_addr + pkt_data->first_mpa_offset;
  1521. fpdu->mpa_frag_virt = (u8 *)(buf->data) + pkt_data->first_mpa_offset;
  1522. if (tcp_payload_size == 1)
  1523. fpdu->incomplete_bytes = QED_IWARP_INVALID_FPDU_LENGTH;
  1524. else if (tcp_payload_size < fpdu->fpdu_length)
  1525. fpdu->incomplete_bytes = fpdu->fpdu_length - tcp_payload_size;
  1526. else
  1527. fpdu->incomplete_bytes = 0; /* complete fpdu */
  1528. fpdu->mpa_frag_len = fpdu->fpdu_length - fpdu->incomplete_bytes;
  1529. }
  1530. static int
  1531. qed_iwarp_cp_pkt(struct qed_hwfn *p_hwfn,
  1532. struct qed_iwarp_fpdu *fpdu,
  1533. struct unaligned_opaque_data *pkt_data,
  1534. struct qed_iwarp_ll2_buff *buf, u16 tcp_payload_size)
  1535. {
  1536. u8 *tmp_buf = p_hwfn->p_rdma_info->iwarp.mpa_intermediate_buf;
  1537. int rc;
  1538. /* need to copy the data from the partial packet stored in fpdu
  1539. * to the new buf, for this we also need to move the data currently
  1540. * placed on the buf. The assumption is that the buffer is big enough
  1541. * since fpdu_length <= mss, we use an intermediate buffer since
  1542. * we may need to copy the new data to an overlapping location
  1543. */
  1544. if ((fpdu->mpa_frag_len + tcp_payload_size) > (u16)buf->buff_size) {
  1545. DP_ERR(p_hwfn,
  1546. "MPA ALIGN: Unexpected: buffer is not large enough for split fpdu buff_size = %d mpa_frag_len = %d, tcp_payload_size = %d, incomplete_bytes = %d\n",
  1547. buf->buff_size, fpdu->mpa_frag_len,
  1548. tcp_payload_size, fpdu->incomplete_bytes);
  1549. return -EINVAL;
  1550. }
  1551. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1552. "MPA ALIGN Copying fpdu: [%p, %d] [%p, %d]\n",
  1553. fpdu->mpa_frag_virt, fpdu->mpa_frag_len,
  1554. (u8 *)(buf->data) + pkt_data->first_mpa_offset,
  1555. tcp_payload_size);
  1556. memcpy(tmp_buf, fpdu->mpa_frag_virt, fpdu->mpa_frag_len);
  1557. memcpy(tmp_buf + fpdu->mpa_frag_len,
  1558. (u8 *)(buf->data) + pkt_data->first_mpa_offset,
  1559. tcp_payload_size);
  1560. rc = qed_iwarp_recycle_pkt(p_hwfn, fpdu, fpdu->mpa_buf);
  1561. if (rc)
  1562. return rc;
  1563. /* If we managed to post the buffer copy the data to the new buffer
  1564. * o/w this will occur in the next round...
  1565. */
  1566. memcpy((u8 *)(buf->data), tmp_buf,
  1567. fpdu->mpa_frag_len + tcp_payload_size);
  1568. fpdu->mpa_buf = buf;
  1569. /* fpdu->pkt_hdr remains as is */
  1570. /* fpdu->mpa_frag is overridden with new buf */
  1571. fpdu->mpa_frag = buf->data_phys_addr;
  1572. fpdu->mpa_frag_virt = buf->data;
  1573. fpdu->mpa_frag_len += tcp_payload_size;
  1574. fpdu->incomplete_bytes -= tcp_payload_size;
  1575. DP_VERBOSE(p_hwfn,
  1576. QED_MSG_RDMA,
  1577. "MPA ALIGN: split fpdu buff_size = %d mpa_frag_len = %d, tcp_payload_size = %d, incomplete_bytes = %d\n",
  1578. buf->buff_size, fpdu->mpa_frag_len, tcp_payload_size,
  1579. fpdu->incomplete_bytes);
  1580. return 0;
  1581. }
  1582. static void
  1583. qed_iwarp_update_fpdu_length(struct qed_hwfn *p_hwfn,
  1584. struct qed_iwarp_fpdu *fpdu, u8 *mpa_data)
  1585. {
  1586. u16 mpa_len;
  1587. /* Update incomplete packets if needed */
  1588. if (fpdu->incomplete_bytes == QED_IWARP_INVALID_FPDU_LENGTH) {
  1589. /* Missing lower byte is now available */
  1590. mpa_len = fpdu->fpdu_length | *mpa_data;
  1591. fpdu->fpdu_length = QED_IWARP_FPDU_LEN_WITH_PAD(mpa_len);
  1592. /* one byte of hdr */
  1593. fpdu->mpa_frag_len = 1;
  1594. fpdu->incomplete_bytes = fpdu->fpdu_length - 1;
  1595. DP_VERBOSE(p_hwfn,
  1596. QED_MSG_RDMA,
  1597. "MPA_ALIGN: Partial header mpa_len=%x fpdu_length=%x incomplete_bytes=%x\n",
  1598. mpa_len, fpdu->fpdu_length, fpdu->incomplete_bytes);
  1599. }
  1600. }
  1601. #define QED_IWARP_IS_RIGHT_EDGE(_curr_pkt) \
  1602. (GET_FIELD((_curr_pkt)->flags, \
  1603. UNALIGNED_OPAQUE_DATA_PKT_REACHED_WIN_RIGHT_EDGE))
  1604. /* This function is used to recycle a buffer using the ll2 drop option. It
  1605. * uses the mechanism to ensure that all buffers posted to tx before this one
  1606. * were completed. The buffer sent here will be sent as a cookie in the tx
  1607. * completion function and can then be reposted to rx chain when done. The flow
  1608. * that requires this is the flow where a FPDU splits over more than 3 tcp
  1609. * segments. In this case the driver needs to re-post a rx buffer instead of
  1610. * the one received, but driver can't simply repost a buffer it copied from
  1611. * as there is a case where the buffer was originally a packed FPDU, and is
  1612. * partially posted to FW. Driver needs to ensure FW is done with it.
  1613. */
  1614. static int
  1615. qed_iwarp_recycle_pkt(struct qed_hwfn *p_hwfn,
  1616. struct qed_iwarp_fpdu *fpdu,
  1617. struct qed_iwarp_ll2_buff *buf)
  1618. {
  1619. struct qed_ll2_tx_pkt_info tx_pkt;
  1620. u8 ll2_handle;
  1621. int rc;
  1622. memset(&tx_pkt, 0, sizeof(tx_pkt));
  1623. tx_pkt.num_of_bds = 1;
  1624. tx_pkt.tx_dest = QED_LL2_TX_DEST_DROP;
  1625. tx_pkt.l4_hdr_offset_w = fpdu->pkt_hdr_size >> 2;
  1626. tx_pkt.first_frag = fpdu->pkt_hdr;
  1627. tx_pkt.first_frag_len = fpdu->pkt_hdr_size;
  1628. buf->piggy_buf = NULL;
  1629. tx_pkt.cookie = buf;
  1630. ll2_handle = p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle;
  1631. rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_handle, &tx_pkt, true);
  1632. if (rc)
  1633. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1634. "Can't drop packet rc=%d\n", rc);
  1635. DP_VERBOSE(p_hwfn,
  1636. QED_MSG_RDMA,
  1637. "MPA_ALIGN: send drop tx packet [%lx, 0x%x], buf=%p, rc=%d\n",
  1638. (unsigned long int)tx_pkt.first_frag,
  1639. tx_pkt.first_frag_len, buf, rc);
  1640. return rc;
  1641. }
  1642. static int
  1643. qed_iwarp_win_right_edge(struct qed_hwfn *p_hwfn, struct qed_iwarp_fpdu *fpdu)
  1644. {
  1645. struct qed_ll2_tx_pkt_info tx_pkt;
  1646. u8 ll2_handle;
  1647. int rc;
  1648. memset(&tx_pkt, 0, sizeof(tx_pkt));
  1649. tx_pkt.num_of_bds = 1;
  1650. tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
  1651. tx_pkt.l4_hdr_offset_w = fpdu->pkt_hdr_size >> 2;
  1652. tx_pkt.first_frag = fpdu->pkt_hdr;
  1653. tx_pkt.first_frag_len = fpdu->pkt_hdr_size;
  1654. tx_pkt.enable_ip_cksum = true;
  1655. tx_pkt.enable_l4_cksum = true;
  1656. tx_pkt.calc_ip_len = true;
  1657. /* vlan overload with enum iwarp_ll2_tx_queues */
  1658. tx_pkt.vlan = IWARP_LL2_ALIGNED_RIGHT_TRIMMED_TX_QUEUE;
  1659. ll2_handle = p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle;
  1660. rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_handle, &tx_pkt, true);
  1661. if (rc)
  1662. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1663. "Can't send right edge rc=%d\n", rc);
  1664. DP_VERBOSE(p_hwfn,
  1665. QED_MSG_RDMA,
  1666. "MPA_ALIGN: Sent right edge FPDU num_bds=%d [%lx, 0x%x], rc=%d\n",
  1667. tx_pkt.num_of_bds,
  1668. (unsigned long int)tx_pkt.first_frag,
  1669. tx_pkt.first_frag_len, rc);
  1670. return rc;
  1671. }
  1672. static int
  1673. qed_iwarp_send_fpdu(struct qed_hwfn *p_hwfn,
  1674. struct qed_iwarp_fpdu *fpdu,
  1675. struct unaligned_opaque_data *curr_pkt,
  1676. struct qed_iwarp_ll2_buff *buf,
  1677. u16 tcp_payload_size, enum qed_iwarp_mpa_pkt_type pkt_type)
  1678. {
  1679. struct qed_ll2_tx_pkt_info tx_pkt;
  1680. u8 ll2_handle;
  1681. int rc;
  1682. memset(&tx_pkt, 0, sizeof(tx_pkt));
  1683. /* An unaligned packet means it's split over two tcp segments. So the
  1684. * complete packet requires 3 bds, one for the header, one for the
  1685. * part of the fpdu of the first tcp segment, and the last fragment
  1686. * will point to the remainder of the fpdu. A packed pdu, requires only
  1687. * two bds, one for the header and one for the data.
  1688. */
  1689. tx_pkt.num_of_bds = (pkt_type == QED_IWARP_MPA_PKT_UNALIGNED) ? 3 : 2;
  1690. tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
  1691. tx_pkt.l4_hdr_offset_w = fpdu->pkt_hdr_size >> 2; /* offset in words */
  1692. /* Send the mpa_buf only with the last fpdu (in case of packed) */
  1693. if (pkt_type == QED_IWARP_MPA_PKT_UNALIGNED ||
  1694. tcp_payload_size <= fpdu->fpdu_length)
  1695. tx_pkt.cookie = fpdu->mpa_buf;
  1696. tx_pkt.first_frag = fpdu->pkt_hdr;
  1697. tx_pkt.first_frag_len = fpdu->pkt_hdr_size;
  1698. tx_pkt.enable_ip_cksum = true;
  1699. tx_pkt.enable_l4_cksum = true;
  1700. tx_pkt.calc_ip_len = true;
  1701. /* vlan overload with enum iwarp_ll2_tx_queues */
  1702. tx_pkt.vlan = IWARP_LL2_ALIGNED_TX_QUEUE;
  1703. /* special case of unaligned packet and not packed, need to send
  1704. * both buffers as cookie to release.
  1705. */
  1706. if (tcp_payload_size == fpdu->incomplete_bytes)
  1707. fpdu->mpa_buf->piggy_buf = buf;
  1708. ll2_handle = p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle;
  1709. /* Set first fragment to header */
  1710. rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_handle, &tx_pkt, true);
  1711. if (rc)
  1712. goto out;
  1713. /* Set second fragment to first part of packet */
  1714. rc = qed_ll2_set_fragment_of_tx_packet(p_hwfn, ll2_handle,
  1715. fpdu->mpa_frag,
  1716. fpdu->mpa_frag_len);
  1717. if (rc)
  1718. goto out;
  1719. if (!fpdu->incomplete_bytes)
  1720. goto out;
  1721. /* Set third fragment to second part of the packet */
  1722. rc = qed_ll2_set_fragment_of_tx_packet(p_hwfn,
  1723. ll2_handle,
  1724. buf->data_phys_addr +
  1725. curr_pkt->first_mpa_offset,
  1726. fpdu->incomplete_bytes);
  1727. out:
  1728. DP_VERBOSE(p_hwfn,
  1729. QED_MSG_RDMA,
  1730. "MPA_ALIGN: Sent FPDU num_bds=%d first_frag_len=%x, mpa_frag_len=0x%x, incomplete_bytes:0x%x rc=%d\n",
  1731. tx_pkt.num_of_bds,
  1732. tx_pkt.first_frag_len,
  1733. fpdu->mpa_frag_len,
  1734. fpdu->incomplete_bytes, rc);
  1735. return rc;
  1736. }
  1737. static void
  1738. qed_iwarp_mpa_get_data(struct qed_hwfn *p_hwfn,
  1739. struct unaligned_opaque_data *curr_pkt,
  1740. u32 opaque_data0, u32 opaque_data1)
  1741. {
  1742. u64 opaque_data;
  1743. opaque_data = HILO_64(opaque_data1, opaque_data0);
  1744. *curr_pkt = *((struct unaligned_opaque_data *)&opaque_data);
  1745. curr_pkt->first_mpa_offset = curr_pkt->tcp_payload_offset +
  1746. le16_to_cpu(curr_pkt->first_mpa_offset);
  1747. curr_pkt->cid = le32_to_cpu(curr_pkt->cid);
  1748. }
  1749. /* This function is called when an unaligned or incomplete MPA packet arrives
  1750. * driver needs to align the packet, perhaps using previous data and send
  1751. * it down to FW once it is aligned.
  1752. */
  1753. static int
  1754. qed_iwarp_process_mpa_pkt(struct qed_hwfn *p_hwfn,
  1755. struct qed_iwarp_ll2_mpa_buf *mpa_buf)
  1756. {
  1757. struct unaligned_opaque_data *curr_pkt = &mpa_buf->data;
  1758. struct qed_iwarp_ll2_buff *buf = mpa_buf->ll2_buf;
  1759. enum qed_iwarp_mpa_pkt_type pkt_type;
  1760. struct qed_iwarp_fpdu *fpdu;
  1761. int rc = -EINVAL;
  1762. u8 *mpa_data;
  1763. fpdu = qed_iwarp_get_curr_fpdu(p_hwfn, curr_pkt->cid & 0xffff);
  1764. if (!fpdu) { /* something corrupt with cid, post rx back */
  1765. DP_ERR(p_hwfn, "Invalid cid, drop and post back to rx cid=%x\n",
  1766. curr_pkt->cid);
  1767. goto err;
  1768. }
  1769. do {
  1770. mpa_data = ((u8 *)(buf->data) + curr_pkt->first_mpa_offset);
  1771. pkt_type = qed_iwarp_mpa_classify(p_hwfn, fpdu,
  1772. mpa_buf->tcp_payload_len,
  1773. mpa_data);
  1774. switch (pkt_type) {
  1775. case QED_IWARP_MPA_PKT_PARTIAL:
  1776. qed_iwarp_init_fpdu(buf, fpdu,
  1777. curr_pkt,
  1778. mpa_buf->tcp_payload_len,
  1779. mpa_buf->placement_offset);
  1780. if (!QED_IWARP_IS_RIGHT_EDGE(curr_pkt)) {
  1781. mpa_buf->tcp_payload_len = 0;
  1782. break;
  1783. }
  1784. rc = qed_iwarp_win_right_edge(p_hwfn, fpdu);
  1785. if (rc) {
  1786. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1787. "Can't send FPDU:reset rc=%d\n", rc);
  1788. memset(fpdu, 0, sizeof(*fpdu));
  1789. break;
  1790. }
  1791. mpa_buf->tcp_payload_len = 0;
  1792. break;
  1793. case QED_IWARP_MPA_PKT_PACKED:
  1794. qed_iwarp_init_fpdu(buf, fpdu,
  1795. curr_pkt,
  1796. mpa_buf->tcp_payload_len,
  1797. mpa_buf->placement_offset);
  1798. rc = qed_iwarp_send_fpdu(p_hwfn, fpdu, curr_pkt, buf,
  1799. mpa_buf->tcp_payload_len,
  1800. pkt_type);
  1801. if (rc) {
  1802. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1803. "Can't send FPDU:reset rc=%d\n", rc);
  1804. memset(fpdu, 0, sizeof(*fpdu));
  1805. break;
  1806. }
  1807. mpa_buf->tcp_payload_len -= fpdu->fpdu_length;
  1808. curr_pkt->first_mpa_offset += fpdu->fpdu_length;
  1809. break;
  1810. case QED_IWARP_MPA_PKT_UNALIGNED:
  1811. qed_iwarp_update_fpdu_length(p_hwfn, fpdu, mpa_data);
  1812. if (mpa_buf->tcp_payload_len < fpdu->incomplete_bytes) {
  1813. /* special handling of fpdu split over more
  1814. * than 2 segments
  1815. */
  1816. if (QED_IWARP_IS_RIGHT_EDGE(curr_pkt)) {
  1817. rc = qed_iwarp_win_right_edge(p_hwfn,
  1818. fpdu);
  1819. /* packet will be re-processed later */
  1820. if (rc)
  1821. return rc;
  1822. }
  1823. rc = qed_iwarp_cp_pkt(p_hwfn, fpdu, curr_pkt,
  1824. buf,
  1825. mpa_buf->tcp_payload_len);
  1826. if (rc) /* packet will be re-processed later */
  1827. return rc;
  1828. mpa_buf->tcp_payload_len = 0;
  1829. break;
  1830. }
  1831. rc = qed_iwarp_send_fpdu(p_hwfn, fpdu, curr_pkt, buf,
  1832. mpa_buf->tcp_payload_len,
  1833. pkt_type);
  1834. if (rc) {
  1835. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1836. "Can't send FPDU:delay rc=%d\n", rc);
  1837. /* don't reset fpdu -> we need it for next
  1838. * classify
  1839. */
  1840. break;
  1841. }
  1842. mpa_buf->tcp_payload_len -= fpdu->incomplete_bytes;
  1843. curr_pkt->first_mpa_offset += fpdu->incomplete_bytes;
  1844. /* The framed PDU was sent - no more incomplete bytes */
  1845. fpdu->incomplete_bytes = 0;
  1846. break;
  1847. }
  1848. } while (mpa_buf->tcp_payload_len && !rc);
  1849. return rc;
  1850. err:
  1851. qed_iwarp_ll2_post_rx(p_hwfn,
  1852. buf,
  1853. p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle);
  1854. return rc;
  1855. }
  1856. static void qed_iwarp_process_pending_pkts(struct qed_hwfn *p_hwfn)
  1857. {
  1858. struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  1859. struct qed_iwarp_ll2_mpa_buf *mpa_buf = NULL;
  1860. int rc;
  1861. while (!list_empty(&iwarp_info->mpa_buf_pending_list)) {
  1862. mpa_buf = list_first_entry(&iwarp_info->mpa_buf_pending_list,
  1863. struct qed_iwarp_ll2_mpa_buf,
  1864. list_entry);
  1865. rc = qed_iwarp_process_mpa_pkt(p_hwfn, mpa_buf);
  1866. /* busy means break and continue processing later, don't
  1867. * remove the buf from the pending list.
  1868. */
  1869. if (rc == -EBUSY)
  1870. break;
  1871. list_del(&mpa_buf->list_entry);
  1872. list_add_tail(&mpa_buf->list_entry, &iwarp_info->mpa_buf_list);
  1873. if (rc) { /* different error, don't continue */
  1874. DP_NOTICE(p_hwfn, "process pkts failed rc=%d\n", rc);
  1875. break;
  1876. }
  1877. }
  1878. }
  1879. static void
  1880. qed_iwarp_ll2_comp_mpa_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
  1881. {
  1882. struct qed_iwarp_ll2_mpa_buf *mpa_buf;
  1883. struct qed_iwarp_info *iwarp_info;
  1884. struct qed_hwfn *p_hwfn = cxt;
  1885. iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  1886. mpa_buf = list_first_entry(&iwarp_info->mpa_buf_list,
  1887. struct qed_iwarp_ll2_mpa_buf, list_entry);
  1888. if (!mpa_buf) {
  1889. DP_ERR(p_hwfn, "No free mpa buf\n");
  1890. goto err;
  1891. }
  1892. list_del(&mpa_buf->list_entry);
  1893. qed_iwarp_mpa_get_data(p_hwfn, &mpa_buf->data,
  1894. data->opaque_data_0, data->opaque_data_1);
  1895. DP_VERBOSE(p_hwfn,
  1896. QED_MSG_RDMA,
  1897. "LL2 MPA CompRx payload_len:0x%x\tfirst_mpa_offset:0x%x\ttcp_payload_offset:0x%x\tflags:0x%x\tcid:0x%x\n",
  1898. data->length.packet_length, mpa_buf->data.first_mpa_offset,
  1899. mpa_buf->data.tcp_payload_offset, mpa_buf->data.flags,
  1900. mpa_buf->data.cid);
  1901. mpa_buf->ll2_buf = data->cookie;
  1902. mpa_buf->tcp_payload_len = data->length.packet_length -
  1903. mpa_buf->data.first_mpa_offset;
  1904. mpa_buf->data.first_mpa_offset += data->u.placement_offset;
  1905. mpa_buf->placement_offset = data->u.placement_offset;
  1906. list_add_tail(&mpa_buf->list_entry, &iwarp_info->mpa_buf_pending_list);
  1907. qed_iwarp_process_pending_pkts(p_hwfn);
  1908. return;
  1909. err:
  1910. qed_iwarp_ll2_post_rx(p_hwfn, data->cookie,
  1911. iwarp_info->ll2_mpa_handle);
  1912. }
  1913. static void
  1914. qed_iwarp_ll2_comp_syn_pkt(void *cxt, struct qed_ll2_comp_rx_data *data)
  1915. {
  1916. struct qed_iwarp_ll2_buff *buf = data->cookie;
  1917. struct qed_iwarp_listener *listener;
  1918. struct qed_ll2_tx_pkt_info tx_pkt;
  1919. struct qed_iwarp_cm_info cm_info;
  1920. struct qed_hwfn *p_hwfn = cxt;
  1921. u8 remote_mac_addr[ETH_ALEN];
  1922. u8 local_mac_addr[ETH_ALEN];
  1923. struct qed_iwarp_ep *ep;
  1924. int tcp_start_offset;
  1925. u8 ts_hdr_size = 0;
  1926. u8 ll2_syn_handle;
  1927. int payload_len;
  1928. u32 hdr_size;
  1929. int rc;
  1930. memset(&cm_info, 0, sizeof(cm_info));
  1931. ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
  1932. /* Check if packet was received with errors... */
  1933. if (data->err_flags) {
  1934. DP_NOTICE(p_hwfn, "Error received on SYN packet: 0x%x\n",
  1935. data->err_flags);
  1936. goto err;
  1937. }
  1938. if (GET_FIELD(data->parse_flags,
  1939. PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED) &&
  1940. GET_FIELD(data->parse_flags, PARSING_AND_ERR_FLAGS_L4CHKSMERROR)) {
  1941. DP_NOTICE(p_hwfn, "Syn packet received with checksum error\n");
  1942. goto err;
  1943. }
  1944. rc = qed_iwarp_parse_rx_pkt(p_hwfn, &cm_info, (u8 *)(buf->data) +
  1945. data->u.placement_offset, remote_mac_addr,
  1946. local_mac_addr, &payload_len,
  1947. &tcp_start_offset);
  1948. if (rc)
  1949. goto err;
  1950. /* Check if there is a listener for this 4-tuple+vlan */
  1951. listener = qed_iwarp_get_listener(p_hwfn, &cm_info);
  1952. if (!listener) {
  1953. DP_VERBOSE(p_hwfn,
  1954. QED_MSG_RDMA,
  1955. "SYN received on tuple not listened on parse_flags=%d packet len=%d\n",
  1956. data->parse_flags, data->length.packet_length);
  1957. memset(&tx_pkt, 0, sizeof(tx_pkt));
  1958. tx_pkt.num_of_bds = 1;
  1959. tx_pkt.l4_hdr_offset_w = (data->length.packet_length) >> 2;
  1960. tx_pkt.tx_dest = QED_LL2_TX_DEST_LB;
  1961. tx_pkt.first_frag = buf->data_phys_addr +
  1962. data->u.placement_offset;
  1963. tx_pkt.first_frag_len = data->length.packet_length;
  1964. tx_pkt.cookie = buf;
  1965. rc = qed_ll2_prepare_tx_packet(p_hwfn, ll2_syn_handle,
  1966. &tx_pkt, true);
  1967. if (rc) {
  1968. DP_NOTICE(p_hwfn,
  1969. "Can't post SYN back to chip rc=%d\n", rc);
  1970. goto err;
  1971. }
  1972. return;
  1973. }
  1974. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Received syn on listening port\n");
  1975. /* There may be an open ep on this connection if this is a syn
  1976. * retrasnmit... need to make sure there isn't...
  1977. */
  1978. if (qed_iwarp_ep_exists(p_hwfn, &cm_info))
  1979. goto err;
  1980. ep = qed_iwarp_get_free_ep(p_hwfn);
  1981. if (!ep)
  1982. goto err;
  1983. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1984. list_add_tail(&ep->list_entry, &p_hwfn->p_rdma_info->iwarp.ep_list);
  1985. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  1986. ether_addr_copy(ep->remote_mac_addr, remote_mac_addr);
  1987. ether_addr_copy(ep->local_mac_addr, local_mac_addr);
  1988. memcpy(&ep->cm_info, &cm_info, sizeof(ep->cm_info));
  1989. if (p_hwfn->p_rdma_info->iwarp.tcp_flags & QED_IWARP_TS_EN)
  1990. ts_hdr_size = TIMESTAMP_HEADER_SIZE;
  1991. hdr_size = ((cm_info.ip_version == QED_TCP_IPV4) ? 40 : 60) +
  1992. ts_hdr_size;
  1993. ep->mss = p_hwfn->p_rdma_info->iwarp.max_mtu - hdr_size;
  1994. ep->mss = min_t(u16, QED_IWARP_MAX_FW_MSS, ep->mss);
  1995. ep->event_cb = listener->event_cb;
  1996. ep->cb_context = listener->cb_context;
  1997. ep->connect_mode = TCP_CONNECT_PASSIVE;
  1998. ep->syn = buf;
  1999. ep->syn_ip_payload_length = (u16)payload_len;
  2000. ep->syn_phy_addr = buf->data_phys_addr + data->u.placement_offset +
  2001. tcp_start_offset;
  2002. rc = qed_iwarp_tcp_offload(p_hwfn, ep);
  2003. if (rc) {
  2004. qed_iwarp_return_ep(p_hwfn, ep);
  2005. goto err;
  2006. }
  2007. return;
  2008. err:
  2009. qed_iwarp_ll2_post_rx(p_hwfn, buf, ll2_syn_handle);
  2010. }
  2011. static void qed_iwarp_ll2_rel_rx_pkt(void *cxt, u8 connection_handle,
  2012. void *cookie, dma_addr_t rx_buf_addr,
  2013. bool b_last_packet)
  2014. {
  2015. struct qed_iwarp_ll2_buff *buffer = cookie;
  2016. struct qed_hwfn *p_hwfn = cxt;
  2017. dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
  2018. buffer->data, buffer->data_phys_addr);
  2019. kfree(buffer);
  2020. }
  2021. static void qed_iwarp_ll2_comp_tx_pkt(void *cxt, u8 connection_handle,
  2022. void *cookie, dma_addr_t first_frag_addr,
  2023. bool b_last_fragment, bool b_last_packet)
  2024. {
  2025. struct qed_iwarp_ll2_buff *buffer = cookie;
  2026. struct qed_iwarp_ll2_buff *piggy;
  2027. struct qed_hwfn *p_hwfn = cxt;
  2028. if (!buffer) /* can happen in packed mpa unaligned... */
  2029. return;
  2030. /* this was originally an rx packet, post it back */
  2031. piggy = buffer->piggy_buf;
  2032. if (piggy) {
  2033. buffer->piggy_buf = NULL;
  2034. qed_iwarp_ll2_post_rx(p_hwfn, piggy, connection_handle);
  2035. }
  2036. qed_iwarp_ll2_post_rx(p_hwfn, buffer, connection_handle);
  2037. if (connection_handle == p_hwfn->p_rdma_info->iwarp.ll2_mpa_handle)
  2038. qed_iwarp_process_pending_pkts(p_hwfn);
  2039. return;
  2040. }
  2041. static void qed_iwarp_ll2_rel_tx_pkt(void *cxt, u8 connection_handle,
  2042. void *cookie, dma_addr_t first_frag_addr,
  2043. bool b_last_fragment, bool b_last_packet)
  2044. {
  2045. struct qed_iwarp_ll2_buff *buffer = cookie;
  2046. struct qed_hwfn *p_hwfn = cxt;
  2047. if (!buffer)
  2048. return;
  2049. if (buffer->piggy_buf) {
  2050. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  2051. buffer->piggy_buf->buff_size,
  2052. buffer->piggy_buf->data,
  2053. buffer->piggy_buf->data_phys_addr);
  2054. kfree(buffer->piggy_buf);
  2055. }
  2056. dma_free_coherent(&p_hwfn->cdev->pdev->dev, buffer->buff_size,
  2057. buffer->data, buffer->data_phys_addr);
  2058. kfree(buffer);
  2059. }
  2060. /* The only slowpath for iwarp ll2 is unalign flush. When this completion
  2061. * is received, need to reset the FPDU.
  2062. */
  2063. void
  2064. qed_iwarp_ll2_slowpath(void *cxt,
  2065. u8 connection_handle,
  2066. u32 opaque_data_0, u32 opaque_data_1)
  2067. {
  2068. struct unaligned_opaque_data unalign_data;
  2069. struct qed_hwfn *p_hwfn = cxt;
  2070. struct qed_iwarp_fpdu *fpdu;
  2071. qed_iwarp_mpa_get_data(p_hwfn, &unalign_data,
  2072. opaque_data_0, opaque_data_1);
  2073. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "(0x%x) Flush fpdu\n",
  2074. unalign_data.cid);
  2075. fpdu = qed_iwarp_get_curr_fpdu(p_hwfn, (u16)unalign_data.cid);
  2076. if (fpdu)
  2077. memset(fpdu, 0, sizeof(*fpdu));
  2078. }
  2079. static int qed_iwarp_ll2_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2080. {
  2081. struct qed_iwarp_info *iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  2082. int rc = 0;
  2083. if (iwarp_info->ll2_syn_handle != QED_IWARP_HANDLE_INVAL) {
  2084. rc = qed_ll2_terminate_connection(p_hwfn,
  2085. iwarp_info->ll2_syn_handle);
  2086. if (rc)
  2087. DP_INFO(p_hwfn, "Failed to terminate syn connection\n");
  2088. qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_syn_handle);
  2089. iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
  2090. }
  2091. if (iwarp_info->ll2_ooo_handle != QED_IWARP_HANDLE_INVAL) {
  2092. rc = qed_ll2_terminate_connection(p_hwfn,
  2093. iwarp_info->ll2_ooo_handle);
  2094. if (rc)
  2095. DP_INFO(p_hwfn, "Failed to terminate ooo connection\n");
  2096. qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_ooo_handle);
  2097. iwarp_info->ll2_ooo_handle = QED_IWARP_HANDLE_INVAL;
  2098. }
  2099. if (iwarp_info->ll2_mpa_handle != QED_IWARP_HANDLE_INVAL) {
  2100. rc = qed_ll2_terminate_connection(p_hwfn,
  2101. iwarp_info->ll2_mpa_handle);
  2102. if (rc)
  2103. DP_INFO(p_hwfn, "Failed to terminate mpa connection\n");
  2104. qed_ll2_release_connection(p_hwfn, iwarp_info->ll2_mpa_handle);
  2105. iwarp_info->ll2_mpa_handle = QED_IWARP_HANDLE_INVAL;
  2106. }
  2107. qed_llh_remove_mac_filter(p_hwfn,
  2108. p_ptt, p_hwfn->p_rdma_info->iwarp.mac_addr);
  2109. return rc;
  2110. }
  2111. static int
  2112. qed_iwarp_ll2_alloc_buffers(struct qed_hwfn *p_hwfn,
  2113. int num_rx_bufs, int buff_size, u8 ll2_handle)
  2114. {
  2115. struct qed_iwarp_ll2_buff *buffer;
  2116. int rc = 0;
  2117. int i;
  2118. for (i = 0; i < num_rx_bufs; i++) {
  2119. buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
  2120. if (!buffer) {
  2121. rc = -ENOMEM;
  2122. break;
  2123. }
  2124. buffer->data = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  2125. buff_size,
  2126. &buffer->data_phys_addr,
  2127. GFP_KERNEL);
  2128. if (!buffer->data) {
  2129. kfree(buffer);
  2130. rc = -ENOMEM;
  2131. break;
  2132. }
  2133. buffer->buff_size = buff_size;
  2134. rc = qed_iwarp_ll2_post_rx(p_hwfn, buffer, ll2_handle);
  2135. if (rc)
  2136. /* buffers will be deallocated by qed_ll2 */
  2137. break;
  2138. }
  2139. return rc;
  2140. }
  2141. #define QED_IWARP_MAX_BUF_SIZE(mtu) \
  2142. ALIGN((mtu) + ETH_HLEN + 2 * VLAN_HLEN + 2 + ETH_CACHE_LINE_SIZE, \
  2143. ETH_CACHE_LINE_SIZE)
  2144. static int
  2145. qed_iwarp_ll2_start(struct qed_hwfn *p_hwfn,
  2146. struct qed_rdma_start_in_params *params,
  2147. struct qed_ptt *p_ptt)
  2148. {
  2149. struct qed_iwarp_info *iwarp_info;
  2150. struct qed_ll2_acquire_data data;
  2151. struct qed_ll2_cbs cbs;
  2152. u32 mpa_buff_size;
  2153. u16 n_ooo_bufs;
  2154. int rc = 0;
  2155. int i;
  2156. iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  2157. iwarp_info->ll2_syn_handle = QED_IWARP_HANDLE_INVAL;
  2158. iwarp_info->ll2_ooo_handle = QED_IWARP_HANDLE_INVAL;
  2159. iwarp_info->ll2_mpa_handle = QED_IWARP_HANDLE_INVAL;
  2160. iwarp_info->max_mtu = params->max_mtu;
  2161. ether_addr_copy(p_hwfn->p_rdma_info->iwarp.mac_addr, params->mac_addr);
  2162. rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, params->mac_addr);
  2163. if (rc)
  2164. return rc;
  2165. /* Start SYN connection */
  2166. cbs.rx_comp_cb = qed_iwarp_ll2_comp_syn_pkt;
  2167. cbs.rx_release_cb = qed_iwarp_ll2_rel_rx_pkt;
  2168. cbs.tx_comp_cb = qed_iwarp_ll2_comp_tx_pkt;
  2169. cbs.tx_release_cb = qed_iwarp_ll2_rel_tx_pkt;
  2170. cbs.cookie = p_hwfn;
  2171. memset(&data, 0, sizeof(data));
  2172. data.input.conn_type = QED_LL2_TYPE_IWARP;
  2173. data.input.mtu = QED_IWARP_MAX_SYN_PKT_SIZE;
  2174. data.input.rx_num_desc = QED_IWARP_LL2_SYN_RX_SIZE;
  2175. data.input.tx_num_desc = QED_IWARP_LL2_SYN_TX_SIZE;
  2176. data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
  2177. data.input.tx_tc = PKT_LB_TC;
  2178. data.input.tx_dest = QED_LL2_TX_DEST_LB;
  2179. data.p_connection_handle = &iwarp_info->ll2_syn_handle;
  2180. data.cbs = &cbs;
  2181. rc = qed_ll2_acquire_connection(p_hwfn, &data);
  2182. if (rc) {
  2183. DP_NOTICE(p_hwfn, "Failed to acquire LL2 connection\n");
  2184. qed_llh_remove_mac_filter(p_hwfn, p_ptt, params->mac_addr);
  2185. return rc;
  2186. }
  2187. rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_syn_handle);
  2188. if (rc) {
  2189. DP_NOTICE(p_hwfn, "Failed to establish LL2 connection\n");
  2190. goto err;
  2191. }
  2192. rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
  2193. QED_IWARP_LL2_SYN_RX_SIZE,
  2194. QED_IWARP_MAX_SYN_PKT_SIZE,
  2195. iwarp_info->ll2_syn_handle);
  2196. if (rc)
  2197. goto err;
  2198. /* Start OOO connection */
  2199. data.input.conn_type = QED_LL2_TYPE_OOO;
  2200. data.input.mtu = params->max_mtu;
  2201. n_ooo_bufs = (QED_IWARP_MAX_OOO * QED_IWARP_RCV_WND_SIZE_DEF) /
  2202. iwarp_info->max_mtu;
  2203. n_ooo_bufs = min_t(u32, n_ooo_bufs, QED_IWARP_LL2_OOO_MAX_RX_SIZE);
  2204. data.input.rx_num_desc = n_ooo_bufs;
  2205. data.input.rx_num_ooo_buffers = n_ooo_bufs;
  2206. data.input.tx_max_bds_per_packet = 1; /* will never be fragmented */
  2207. data.input.tx_num_desc = QED_IWARP_LL2_OOO_DEF_TX_SIZE;
  2208. data.p_connection_handle = &iwarp_info->ll2_ooo_handle;
  2209. rc = qed_ll2_acquire_connection(p_hwfn, &data);
  2210. if (rc)
  2211. goto err;
  2212. rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_ooo_handle);
  2213. if (rc)
  2214. goto err;
  2215. /* Start Unaligned MPA connection */
  2216. cbs.rx_comp_cb = qed_iwarp_ll2_comp_mpa_pkt;
  2217. cbs.slowpath_cb = qed_iwarp_ll2_slowpath;
  2218. memset(&data, 0, sizeof(data));
  2219. data.input.conn_type = QED_LL2_TYPE_IWARP;
  2220. data.input.mtu = params->max_mtu;
  2221. /* FW requires that once a packet arrives OOO, it must have at
  2222. * least 2 rx buffers available on the unaligned connection
  2223. * for handling the case that it is a partial fpdu.
  2224. */
  2225. data.input.rx_num_desc = n_ooo_bufs * 2;
  2226. data.input.tx_num_desc = data.input.rx_num_desc;
  2227. data.input.tx_max_bds_per_packet = QED_IWARP_MAX_BDS_PER_FPDU;
  2228. data.p_connection_handle = &iwarp_info->ll2_mpa_handle;
  2229. data.input.secondary_queue = true;
  2230. data.cbs = &cbs;
  2231. rc = qed_ll2_acquire_connection(p_hwfn, &data);
  2232. if (rc)
  2233. goto err;
  2234. rc = qed_ll2_establish_connection(p_hwfn, iwarp_info->ll2_mpa_handle);
  2235. if (rc)
  2236. goto err;
  2237. mpa_buff_size = QED_IWARP_MAX_BUF_SIZE(params->max_mtu);
  2238. rc = qed_iwarp_ll2_alloc_buffers(p_hwfn,
  2239. data.input.rx_num_desc,
  2240. mpa_buff_size,
  2241. iwarp_info->ll2_mpa_handle);
  2242. if (rc)
  2243. goto err;
  2244. iwarp_info->partial_fpdus = kcalloc((u16)p_hwfn->p_rdma_info->num_qps,
  2245. sizeof(*iwarp_info->partial_fpdus),
  2246. GFP_KERNEL);
  2247. if (!iwarp_info->partial_fpdus)
  2248. goto err;
  2249. iwarp_info->max_num_partial_fpdus = (u16)p_hwfn->p_rdma_info->num_qps;
  2250. iwarp_info->mpa_intermediate_buf = kzalloc(mpa_buff_size, GFP_KERNEL);
  2251. if (!iwarp_info->mpa_intermediate_buf)
  2252. goto err;
  2253. /* The mpa_bufs array serves for pending RX packets received on the
  2254. * mpa ll2 that don't have place on the tx ring and require later
  2255. * processing. We can't fail on allocation of such a struct therefore
  2256. * we allocate enough to take care of all rx packets
  2257. */
  2258. iwarp_info->mpa_bufs = kcalloc(data.input.rx_num_desc,
  2259. sizeof(*iwarp_info->mpa_bufs),
  2260. GFP_KERNEL);
  2261. if (!iwarp_info->mpa_bufs)
  2262. goto err;
  2263. INIT_LIST_HEAD(&iwarp_info->mpa_buf_pending_list);
  2264. INIT_LIST_HEAD(&iwarp_info->mpa_buf_list);
  2265. for (i = 0; i < data.input.rx_num_desc; i++)
  2266. list_add_tail(&iwarp_info->mpa_bufs[i].list_entry,
  2267. &iwarp_info->mpa_buf_list);
  2268. return rc;
  2269. err:
  2270. qed_iwarp_ll2_stop(p_hwfn, p_ptt);
  2271. return rc;
  2272. }
  2273. int qed_iwarp_setup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt,
  2274. struct qed_rdma_start_in_params *params)
  2275. {
  2276. struct qed_iwarp_info *iwarp_info;
  2277. u32 rcv_wnd_size;
  2278. iwarp_info = &p_hwfn->p_rdma_info->iwarp;
  2279. iwarp_info->tcp_flags = QED_IWARP_TS_EN;
  2280. rcv_wnd_size = QED_IWARP_RCV_WND_SIZE_DEF;
  2281. /* value 0 is used for ilog2(QED_IWARP_RCV_WND_SIZE_MIN) */
  2282. iwarp_info->rcv_wnd_scale = ilog2(rcv_wnd_size) -
  2283. ilog2(QED_IWARP_RCV_WND_SIZE_MIN);
  2284. iwarp_info->rcv_wnd_size = rcv_wnd_size >> iwarp_info->rcv_wnd_scale;
  2285. iwarp_info->crc_needed = QED_IWARP_PARAM_CRC_NEEDED;
  2286. iwarp_info->mpa_rev = MPA_NEGOTIATION_TYPE_ENHANCED;
  2287. iwarp_info->peer2peer = QED_IWARP_PARAM_P2P;
  2288. iwarp_info->rtr_type = MPA_RTR_TYPE_ZERO_SEND |
  2289. MPA_RTR_TYPE_ZERO_WRITE |
  2290. MPA_RTR_TYPE_ZERO_READ;
  2291. spin_lock_init(&p_hwfn->p_rdma_info->iwarp.qp_lock);
  2292. INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.ep_list);
  2293. INIT_LIST_HEAD(&p_hwfn->p_rdma_info->iwarp.listen_list);
  2294. qed_spq_register_async_cb(p_hwfn, PROTOCOLID_IWARP,
  2295. qed_iwarp_async_event);
  2296. qed_ooo_setup(p_hwfn);
  2297. return qed_iwarp_ll2_start(p_hwfn, params, p_ptt);
  2298. }
  2299. int qed_iwarp_stop(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  2300. {
  2301. int rc;
  2302. qed_iwarp_free_prealloc_ep(p_hwfn);
  2303. rc = qed_iwarp_wait_for_all_cids(p_hwfn);
  2304. if (rc)
  2305. return rc;
  2306. qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_IWARP);
  2307. return qed_iwarp_ll2_stop(p_hwfn, p_ptt);
  2308. }
  2309. void qed_iwarp_qp_in_error(struct qed_hwfn *p_hwfn,
  2310. struct qed_iwarp_ep *ep, u8 fw_return_code)
  2311. {
  2312. struct qed_iwarp_cm_event_params params;
  2313. qed_iwarp_modify_qp(p_hwfn, ep->qp, QED_IWARP_QP_STATE_ERROR, true);
  2314. params.event = QED_IWARP_EVENT_CLOSE;
  2315. params.ep_context = ep;
  2316. params.cm_info = &ep->cm_info;
  2317. params.status = (fw_return_code == IWARP_QP_IN_ERROR_GOOD_CLOSE) ?
  2318. 0 : -ECONNRESET;
  2319. ep->state = QED_IWARP_EP_CLOSED;
  2320. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2321. list_del(&ep->list_entry);
  2322. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2323. ep->event_cb(ep->cb_context, &params);
  2324. }
  2325. void qed_iwarp_exception_received(struct qed_hwfn *p_hwfn,
  2326. struct qed_iwarp_ep *ep, int fw_ret_code)
  2327. {
  2328. struct qed_iwarp_cm_event_params params;
  2329. bool event_cb = false;
  2330. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "EP(0x%x) fw_ret_code=%d\n",
  2331. ep->cid, fw_ret_code);
  2332. switch (fw_ret_code) {
  2333. case IWARP_EXCEPTION_DETECTED_LLP_CLOSED:
  2334. params.status = 0;
  2335. params.event = QED_IWARP_EVENT_DISCONNECT;
  2336. event_cb = true;
  2337. break;
  2338. case IWARP_EXCEPTION_DETECTED_LLP_RESET:
  2339. params.status = -ECONNRESET;
  2340. params.event = QED_IWARP_EVENT_DISCONNECT;
  2341. event_cb = true;
  2342. break;
  2343. case IWARP_EXCEPTION_DETECTED_RQ_EMPTY:
  2344. params.event = QED_IWARP_EVENT_RQ_EMPTY;
  2345. event_cb = true;
  2346. break;
  2347. case IWARP_EXCEPTION_DETECTED_IRQ_FULL:
  2348. params.event = QED_IWARP_EVENT_IRQ_FULL;
  2349. event_cb = true;
  2350. break;
  2351. case IWARP_EXCEPTION_DETECTED_LLP_TIMEOUT:
  2352. params.event = QED_IWARP_EVENT_LLP_TIMEOUT;
  2353. event_cb = true;
  2354. break;
  2355. case IWARP_EXCEPTION_DETECTED_REMOTE_PROTECTION_ERROR:
  2356. params.event = QED_IWARP_EVENT_REMOTE_PROTECTION_ERROR;
  2357. event_cb = true;
  2358. break;
  2359. case IWARP_EXCEPTION_DETECTED_CQ_OVERFLOW:
  2360. params.event = QED_IWARP_EVENT_CQ_OVERFLOW;
  2361. event_cb = true;
  2362. break;
  2363. case IWARP_EXCEPTION_DETECTED_LOCAL_CATASTROPHIC:
  2364. params.event = QED_IWARP_EVENT_QP_CATASTROPHIC;
  2365. event_cb = true;
  2366. break;
  2367. case IWARP_EXCEPTION_DETECTED_LOCAL_ACCESS_ERROR:
  2368. params.event = QED_IWARP_EVENT_LOCAL_ACCESS_ERROR;
  2369. event_cb = true;
  2370. break;
  2371. case IWARP_EXCEPTION_DETECTED_REMOTE_OPERATION_ERROR:
  2372. params.event = QED_IWARP_EVENT_REMOTE_OPERATION_ERROR;
  2373. event_cb = true;
  2374. break;
  2375. case IWARP_EXCEPTION_DETECTED_TERMINATE_RECEIVED:
  2376. params.event = QED_IWARP_EVENT_TERMINATE_RECEIVED;
  2377. event_cb = true;
  2378. break;
  2379. default:
  2380. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2381. "Unhandled exception received...fw_ret_code=%d\n",
  2382. fw_ret_code);
  2383. break;
  2384. }
  2385. if (event_cb) {
  2386. params.ep_context = ep;
  2387. params.cm_info = &ep->cm_info;
  2388. ep->event_cb(ep->cb_context, &params);
  2389. }
  2390. }
  2391. static void
  2392. qed_iwarp_tcp_connect_unsuccessful(struct qed_hwfn *p_hwfn,
  2393. struct qed_iwarp_ep *ep, u8 fw_return_code)
  2394. {
  2395. struct qed_iwarp_cm_event_params params;
  2396. memset(&params, 0, sizeof(params));
  2397. params.event = QED_IWARP_EVENT_ACTIVE_COMPLETE;
  2398. params.ep_context = ep;
  2399. params.cm_info = &ep->cm_info;
  2400. ep->state = QED_IWARP_EP_CLOSED;
  2401. switch (fw_return_code) {
  2402. case IWARP_CONN_ERROR_TCP_CONNECT_INVALID_PACKET:
  2403. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2404. "%s(0x%x) TCP connect got invalid packet\n",
  2405. QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
  2406. params.status = -ECONNRESET;
  2407. break;
  2408. case IWARP_CONN_ERROR_TCP_CONNECTION_RST:
  2409. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2410. "%s(0x%x) TCP Connection Reset\n",
  2411. QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
  2412. params.status = -ECONNRESET;
  2413. break;
  2414. case IWARP_CONN_ERROR_TCP_CONNECT_TIMEOUT:
  2415. DP_NOTICE(p_hwfn, "%s(0x%x) TCP timeout\n",
  2416. QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
  2417. params.status = -EBUSY;
  2418. break;
  2419. case IWARP_CONN_ERROR_MPA_NOT_SUPPORTED_VER:
  2420. DP_NOTICE(p_hwfn, "%s(0x%x) MPA not supported VER\n",
  2421. QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
  2422. params.status = -ECONNREFUSED;
  2423. break;
  2424. case IWARP_CONN_ERROR_MPA_INVALID_PACKET:
  2425. DP_NOTICE(p_hwfn, "%s(0x%x) MPA Invalid Packet\n",
  2426. QED_IWARP_CONNECT_MODE_STRING(ep), ep->tcp_cid);
  2427. params.status = -ECONNRESET;
  2428. break;
  2429. default:
  2430. DP_ERR(p_hwfn,
  2431. "%s(0x%x) Unexpected return code tcp connect: %d\n",
  2432. QED_IWARP_CONNECT_MODE_STRING(ep),
  2433. ep->tcp_cid, fw_return_code);
  2434. params.status = -ECONNRESET;
  2435. break;
  2436. }
  2437. if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
  2438. ep->tcp_cid = QED_IWARP_INVALID_TCP_CID;
  2439. qed_iwarp_return_ep(p_hwfn, ep);
  2440. } else {
  2441. ep->event_cb(ep->cb_context, &params);
  2442. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2443. list_del(&ep->list_entry);
  2444. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2445. }
  2446. }
  2447. void
  2448. qed_iwarp_connect_complete(struct qed_hwfn *p_hwfn,
  2449. struct qed_iwarp_ep *ep, u8 fw_return_code)
  2450. {
  2451. u8 ll2_syn_handle = p_hwfn->p_rdma_info->iwarp.ll2_syn_handle;
  2452. if (ep->connect_mode == TCP_CONNECT_PASSIVE) {
  2453. /* Done with the SYN packet, post back to ll2 rx */
  2454. qed_iwarp_ll2_post_rx(p_hwfn, ep->syn, ll2_syn_handle);
  2455. ep->syn = NULL;
  2456. /* If connect failed - upper layer doesn't know about it */
  2457. if (fw_return_code == RDMA_RETURN_OK)
  2458. qed_iwarp_mpa_received(p_hwfn, ep);
  2459. else
  2460. qed_iwarp_tcp_connect_unsuccessful(p_hwfn, ep,
  2461. fw_return_code);
  2462. } else {
  2463. if (fw_return_code == RDMA_RETURN_OK)
  2464. qed_iwarp_mpa_offload(p_hwfn, ep);
  2465. else
  2466. qed_iwarp_tcp_connect_unsuccessful(p_hwfn, ep,
  2467. fw_return_code);
  2468. }
  2469. }
  2470. static inline bool
  2471. qed_iwarp_check_ep_ok(struct qed_hwfn *p_hwfn, struct qed_iwarp_ep *ep)
  2472. {
  2473. if (!ep || (ep->sig != QED_EP_SIG)) {
  2474. DP_ERR(p_hwfn, "ERROR ON ASYNC ep=%p\n", ep);
  2475. return false;
  2476. }
  2477. return true;
  2478. }
  2479. static int qed_iwarp_async_event(struct qed_hwfn *p_hwfn,
  2480. u8 fw_event_code, u16 echo,
  2481. union event_ring_data *data,
  2482. u8 fw_return_code)
  2483. {
  2484. struct regpair *fw_handle = &data->rdma_data.async_handle;
  2485. struct qed_iwarp_ep *ep = NULL;
  2486. u16 cid;
  2487. ep = (struct qed_iwarp_ep *)(uintptr_t)HILO_64(fw_handle->hi,
  2488. fw_handle->lo);
  2489. switch (fw_event_code) {
  2490. case IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE:
  2491. /* Async completion after TCP 3-way handshake */
  2492. if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
  2493. return -EINVAL;
  2494. DP_VERBOSE(p_hwfn,
  2495. QED_MSG_RDMA,
  2496. "EP(0x%x) IWARP_EVENT_TYPE_ASYNC_CONNECT_COMPLETE fw_ret_code=%d\n",
  2497. ep->tcp_cid, fw_return_code);
  2498. qed_iwarp_connect_complete(p_hwfn, ep, fw_return_code);
  2499. break;
  2500. case IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED:
  2501. if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
  2502. return -EINVAL;
  2503. DP_VERBOSE(p_hwfn,
  2504. QED_MSG_RDMA,
  2505. "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_EXCEPTION_DETECTED fw_ret_code=%d\n",
  2506. ep->cid, fw_return_code);
  2507. qed_iwarp_exception_received(p_hwfn, ep, fw_return_code);
  2508. break;
  2509. case IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE:
  2510. /* Async completion for Close Connection ramrod */
  2511. if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
  2512. return -EINVAL;
  2513. DP_VERBOSE(p_hwfn,
  2514. QED_MSG_RDMA,
  2515. "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_QP_IN_ERROR_STATE fw_ret_code=%d\n",
  2516. ep->cid, fw_return_code);
  2517. qed_iwarp_qp_in_error(p_hwfn, ep, fw_return_code);
  2518. break;
  2519. case IWARP_EVENT_TYPE_ASYNC_ENHANCED_MPA_REPLY_ARRIVED:
  2520. /* Async event for active side only */
  2521. if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
  2522. return -EINVAL;
  2523. DP_VERBOSE(p_hwfn,
  2524. QED_MSG_RDMA,
  2525. "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_MPA_REPLY_ARRIVED fw_ret_code=%d\n",
  2526. ep->cid, fw_return_code);
  2527. qed_iwarp_mpa_reply_arrived(p_hwfn, ep);
  2528. break;
  2529. case IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE:
  2530. if (!qed_iwarp_check_ep_ok(p_hwfn, ep))
  2531. return -EINVAL;
  2532. DP_VERBOSE(p_hwfn,
  2533. QED_MSG_RDMA,
  2534. "QP(0x%x) IWARP_EVENT_TYPE_ASYNC_MPA_HANDSHAKE_COMPLETE fw_ret_code=%d\n",
  2535. ep->cid, fw_return_code);
  2536. qed_iwarp_mpa_complete(p_hwfn, ep, fw_return_code);
  2537. break;
  2538. case IWARP_EVENT_TYPE_ASYNC_CID_CLEANED:
  2539. cid = (u16)le32_to_cpu(fw_handle->lo);
  2540. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  2541. "(0x%x)IWARP_EVENT_TYPE_ASYNC_CID_CLEANED\n", cid);
  2542. qed_iwarp_cid_cleaned(p_hwfn, cid);
  2543. break;
  2544. case IWARP_EVENT_TYPE_ASYNC_CQ_OVERFLOW:
  2545. DP_NOTICE(p_hwfn, "IWARP_EVENT_TYPE_ASYNC_CQ_OVERFLOW\n");
  2546. p_hwfn->p_rdma_info->events.affiliated_event(
  2547. p_hwfn->p_rdma_info->events.context,
  2548. QED_IWARP_EVENT_CQ_OVERFLOW,
  2549. (void *)fw_handle);
  2550. break;
  2551. default:
  2552. DP_ERR(p_hwfn, "Received unexpected async iwarp event %d\n",
  2553. fw_event_code);
  2554. return -EINVAL;
  2555. }
  2556. return 0;
  2557. }
  2558. int
  2559. qed_iwarp_create_listen(void *rdma_cxt,
  2560. struct qed_iwarp_listen_in *iparams,
  2561. struct qed_iwarp_listen_out *oparams)
  2562. {
  2563. struct qed_hwfn *p_hwfn = rdma_cxt;
  2564. struct qed_iwarp_listener *listener;
  2565. listener = kzalloc(sizeof(*listener), GFP_KERNEL);
  2566. if (!listener)
  2567. return -ENOMEM;
  2568. listener->ip_version = iparams->ip_version;
  2569. memcpy(listener->ip_addr, iparams->ip_addr, sizeof(listener->ip_addr));
  2570. listener->port = iparams->port;
  2571. listener->vlan = iparams->vlan;
  2572. listener->event_cb = iparams->event_cb;
  2573. listener->cb_context = iparams->cb_context;
  2574. listener->max_backlog = iparams->max_backlog;
  2575. oparams->handle = listener;
  2576. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2577. list_add_tail(&listener->list_entry,
  2578. &p_hwfn->p_rdma_info->iwarp.listen_list);
  2579. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2580. DP_VERBOSE(p_hwfn,
  2581. QED_MSG_RDMA,
  2582. "callback=%p handle=%p ip=%x:%x:%x:%x port=0x%x vlan=0x%x\n",
  2583. listener->event_cb,
  2584. listener,
  2585. listener->ip_addr[0],
  2586. listener->ip_addr[1],
  2587. listener->ip_addr[2],
  2588. listener->ip_addr[3], listener->port, listener->vlan);
  2589. return 0;
  2590. }
  2591. int qed_iwarp_destroy_listen(void *rdma_cxt, void *handle)
  2592. {
  2593. struct qed_iwarp_listener *listener = handle;
  2594. struct qed_hwfn *p_hwfn = rdma_cxt;
  2595. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "handle=%p\n", handle);
  2596. spin_lock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2597. list_del(&listener->list_entry);
  2598. spin_unlock_bh(&p_hwfn->p_rdma_info->iwarp.iw_lock);
  2599. kfree(listener);
  2600. return 0;
  2601. }
  2602. int qed_iwarp_send_rtr(void *rdma_cxt, struct qed_iwarp_send_rtr_in *iparams)
  2603. {
  2604. struct qed_hwfn *p_hwfn = rdma_cxt;
  2605. struct qed_sp_init_data init_data;
  2606. struct qed_spq_entry *p_ent;
  2607. struct qed_iwarp_ep *ep;
  2608. struct qed_rdma_qp *qp;
  2609. int rc;
  2610. ep = iparams->ep_context;
  2611. if (!ep) {
  2612. DP_ERR(p_hwfn, "Ep Context receive in send_rtr is NULL\n");
  2613. return -EINVAL;
  2614. }
  2615. qp = ep->qp;
  2616. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP(0x%x) EP(0x%x)\n",
  2617. qp->icid, ep->tcp_cid);
  2618. memset(&init_data, 0, sizeof(init_data));
  2619. init_data.cid = qp->icid;
  2620. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  2621. init_data.comp_mode = QED_SPQ_MODE_CB;
  2622. rc = qed_sp_init_request(p_hwfn, &p_ent,
  2623. IWARP_RAMROD_CMD_ID_MPA_OFFLOAD_SEND_RTR,
  2624. PROTOCOLID_IWARP, &init_data);
  2625. if (rc)
  2626. return rc;
  2627. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  2628. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = 0x%x\n", rc);
  2629. return rc;
  2630. }
  2631. void
  2632. qed_iwarp_query_qp(struct qed_rdma_qp *qp,
  2633. struct qed_rdma_query_qp_out_params *out_params)
  2634. {
  2635. out_params->state = qed_iwarp2roce_state(qp->iwarp_state);
  2636. }