qed_iwarp.c 88 KB

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