qed_iwarp.c 89 KB

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