cm.c 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301
  1. /*
  2. * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
  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/module.h>
  33. #include <linux/list.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/timer.h>
  37. #include <linux/notifier.h>
  38. #include <linux/inetdevice.h>
  39. #include <linux/ip.h>
  40. #include <linux/tcp.h>
  41. #include <linux/if_vlan.h>
  42. #include <net/neighbour.h>
  43. #include <net/netevent.h>
  44. #include <net/route.h>
  45. #include <net/tcp.h>
  46. #include <net/ip6_route.h>
  47. #include <net/addrconf.h>
  48. #include <rdma/ib_addr.h>
  49. #include <libcxgb_cm.h>
  50. #include "iw_cxgb4.h"
  51. #include "clip_tbl.h"
  52. static char *states[] = {
  53. "idle",
  54. "listen",
  55. "connecting",
  56. "mpa_wait_req",
  57. "mpa_req_sent",
  58. "mpa_req_rcvd",
  59. "mpa_rep_sent",
  60. "fpdu_mode",
  61. "aborting",
  62. "closing",
  63. "moribund",
  64. "dead",
  65. NULL,
  66. };
  67. static int nocong;
  68. module_param(nocong, int, 0644);
  69. MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
  70. static int enable_ecn;
  71. module_param(enable_ecn, int, 0644);
  72. MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
  73. static int dack_mode = 1;
  74. module_param(dack_mode, int, 0644);
  75. MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
  76. uint c4iw_max_read_depth = 32;
  77. module_param(c4iw_max_read_depth, int, 0644);
  78. MODULE_PARM_DESC(c4iw_max_read_depth,
  79. "Per-connection max ORD/IRD (default=32)");
  80. static int enable_tcp_timestamps;
  81. module_param(enable_tcp_timestamps, int, 0644);
  82. MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
  83. static int enable_tcp_sack;
  84. module_param(enable_tcp_sack, int, 0644);
  85. MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
  86. static int enable_tcp_window_scaling = 1;
  87. module_param(enable_tcp_window_scaling, int, 0644);
  88. MODULE_PARM_DESC(enable_tcp_window_scaling,
  89. "Enable tcp window scaling (default=1)");
  90. static int peer2peer = 1;
  91. module_param(peer2peer, int, 0644);
  92. MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
  93. static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
  94. module_param(p2p_type, int, 0644);
  95. MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
  96. "1=RDMA_READ 0=RDMA_WRITE (default 1)");
  97. static int ep_timeout_secs = 60;
  98. module_param(ep_timeout_secs, int, 0644);
  99. MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
  100. "in seconds (default=60)");
  101. static int mpa_rev = 2;
  102. module_param(mpa_rev, int, 0644);
  103. MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
  104. "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
  105. " compliant (default=2)");
  106. static int markers_enabled;
  107. module_param(markers_enabled, int, 0644);
  108. MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
  109. static int crc_enabled = 1;
  110. module_param(crc_enabled, int, 0644);
  111. MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
  112. static int rcv_win = 256 * 1024;
  113. module_param(rcv_win, int, 0644);
  114. MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
  115. static int snd_win = 128 * 1024;
  116. module_param(snd_win, int, 0644);
  117. MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
  118. static struct workqueue_struct *workq;
  119. static struct sk_buff_head rxq;
  120. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
  121. static void ep_timeout(struct timer_list *t);
  122. static void connect_reply_upcall(struct c4iw_ep *ep, int status);
  123. static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
  124. static LIST_HEAD(timeout_list);
  125. static spinlock_t timeout_lock;
  126. static void deref_cm_id(struct c4iw_ep_common *epc)
  127. {
  128. epc->cm_id->rem_ref(epc->cm_id);
  129. epc->cm_id = NULL;
  130. set_bit(CM_ID_DEREFED, &epc->history);
  131. }
  132. static void ref_cm_id(struct c4iw_ep_common *epc)
  133. {
  134. set_bit(CM_ID_REFED, &epc->history);
  135. epc->cm_id->add_ref(epc->cm_id);
  136. }
  137. static void deref_qp(struct c4iw_ep *ep)
  138. {
  139. c4iw_qp_rem_ref(&ep->com.qp->ibqp);
  140. clear_bit(QP_REFERENCED, &ep->com.flags);
  141. set_bit(QP_DEREFED, &ep->com.history);
  142. }
  143. static void ref_qp(struct c4iw_ep *ep)
  144. {
  145. set_bit(QP_REFERENCED, &ep->com.flags);
  146. set_bit(QP_REFED, &ep->com.history);
  147. c4iw_qp_add_ref(&ep->com.qp->ibqp);
  148. }
  149. static void start_ep_timer(struct c4iw_ep *ep)
  150. {
  151. pr_debug("ep %p\n", ep);
  152. if (timer_pending(&ep->timer)) {
  153. pr_err("%s timer already started! ep %p\n",
  154. __func__, ep);
  155. return;
  156. }
  157. clear_bit(TIMEOUT, &ep->com.flags);
  158. c4iw_get_ep(&ep->com);
  159. ep->timer.expires = jiffies + ep_timeout_secs * HZ;
  160. add_timer(&ep->timer);
  161. }
  162. static int stop_ep_timer(struct c4iw_ep *ep)
  163. {
  164. pr_debug("ep %p stopping\n", ep);
  165. del_timer_sync(&ep->timer);
  166. if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
  167. c4iw_put_ep(&ep->com);
  168. return 0;
  169. }
  170. return 1;
  171. }
  172. static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
  173. struct l2t_entry *l2e)
  174. {
  175. int error = 0;
  176. if (c4iw_fatal_error(rdev)) {
  177. kfree_skb(skb);
  178. pr_err("%s - device in error state - dropping\n", __func__);
  179. return -EIO;
  180. }
  181. error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
  182. if (error < 0)
  183. kfree_skb(skb);
  184. else if (error == NET_XMIT_DROP)
  185. return -ENOMEM;
  186. return error < 0 ? error : 0;
  187. }
  188. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
  189. {
  190. int error = 0;
  191. if (c4iw_fatal_error(rdev)) {
  192. kfree_skb(skb);
  193. pr_err("%s - device in error state - dropping\n", __func__);
  194. return -EIO;
  195. }
  196. error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
  197. if (error < 0)
  198. kfree_skb(skb);
  199. return error < 0 ? error : 0;
  200. }
  201. static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
  202. {
  203. u32 len = roundup(sizeof(struct cpl_tid_release), 16);
  204. skb = get_skb(skb, len, GFP_KERNEL);
  205. if (!skb)
  206. return;
  207. cxgb_mk_tid_release(skb, len, hwtid, 0);
  208. c4iw_ofld_send(rdev, skb);
  209. return;
  210. }
  211. static void set_emss(struct c4iw_ep *ep, u16 opt)
  212. {
  213. ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
  214. ((AF_INET == ep->com.remote_addr.ss_family) ?
  215. sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
  216. sizeof(struct tcphdr);
  217. ep->mss = ep->emss;
  218. if (TCPOPT_TSTAMP_G(opt))
  219. ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
  220. if (ep->emss < 128)
  221. ep->emss = 128;
  222. if (ep->emss & 7)
  223. pr_debug("Warning: misaligned mtu idx %u mss %u emss=%u\n",
  224. TCPOPT_MSS_G(opt), ep->mss, ep->emss);
  225. pr_debug("mss_idx %u mss %u emss=%u\n", TCPOPT_MSS_G(opt), ep->mss,
  226. ep->emss);
  227. }
  228. static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
  229. {
  230. enum c4iw_ep_state state;
  231. mutex_lock(&epc->mutex);
  232. state = epc->state;
  233. mutex_unlock(&epc->mutex);
  234. return state;
  235. }
  236. static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  237. {
  238. epc->state = new;
  239. }
  240. static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  241. {
  242. mutex_lock(&epc->mutex);
  243. pr_debug("%s -> %s\n", states[epc->state], states[new]);
  244. __state_set(epc, new);
  245. mutex_unlock(&epc->mutex);
  246. return;
  247. }
  248. static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
  249. {
  250. struct sk_buff *skb;
  251. unsigned int i;
  252. size_t len;
  253. len = roundup(sizeof(union cpl_wr_size), 16);
  254. for (i = 0; i < size; i++) {
  255. skb = alloc_skb(len, GFP_KERNEL);
  256. if (!skb)
  257. goto fail;
  258. skb_queue_tail(ep_skb_list, skb);
  259. }
  260. return 0;
  261. fail:
  262. skb_queue_purge(ep_skb_list);
  263. return -ENOMEM;
  264. }
  265. static void *alloc_ep(int size, gfp_t gfp)
  266. {
  267. struct c4iw_ep_common *epc;
  268. epc = kzalloc(size, gfp);
  269. if (epc) {
  270. epc->wr_waitp = c4iw_alloc_wr_wait(gfp);
  271. if (!epc->wr_waitp) {
  272. kfree(epc);
  273. epc = NULL;
  274. goto out;
  275. }
  276. kref_init(&epc->kref);
  277. mutex_init(&epc->mutex);
  278. c4iw_init_wr_wait(epc->wr_waitp);
  279. }
  280. pr_debug("alloc ep %p\n", epc);
  281. out:
  282. return epc;
  283. }
  284. static void remove_ep_tid(struct c4iw_ep *ep)
  285. {
  286. unsigned long flags;
  287. spin_lock_irqsave(&ep->com.dev->lock, flags);
  288. _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
  289. if (idr_is_empty(&ep->com.dev->hwtid_idr))
  290. wake_up(&ep->com.dev->wait);
  291. spin_unlock_irqrestore(&ep->com.dev->lock, flags);
  292. }
  293. static void insert_ep_tid(struct c4iw_ep *ep)
  294. {
  295. unsigned long flags;
  296. spin_lock_irqsave(&ep->com.dev->lock, flags);
  297. _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
  298. spin_unlock_irqrestore(&ep->com.dev->lock, flags);
  299. }
  300. /*
  301. * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
  302. */
  303. static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
  304. {
  305. struct c4iw_ep *ep;
  306. unsigned long flags;
  307. spin_lock_irqsave(&dev->lock, flags);
  308. ep = idr_find(&dev->hwtid_idr, tid);
  309. if (ep)
  310. c4iw_get_ep(&ep->com);
  311. spin_unlock_irqrestore(&dev->lock, flags);
  312. return ep;
  313. }
  314. /*
  315. * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
  316. */
  317. static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
  318. unsigned int stid)
  319. {
  320. struct c4iw_listen_ep *ep;
  321. unsigned long flags;
  322. spin_lock_irqsave(&dev->lock, flags);
  323. ep = idr_find(&dev->stid_idr, stid);
  324. if (ep)
  325. c4iw_get_ep(&ep->com);
  326. spin_unlock_irqrestore(&dev->lock, flags);
  327. return ep;
  328. }
  329. void _c4iw_free_ep(struct kref *kref)
  330. {
  331. struct c4iw_ep *ep;
  332. ep = container_of(kref, struct c4iw_ep, com.kref);
  333. pr_debug("ep %p state %s\n", ep, states[ep->com.state]);
  334. if (test_bit(QP_REFERENCED, &ep->com.flags))
  335. deref_qp(ep);
  336. if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
  337. if (ep->com.remote_addr.ss_family == AF_INET6) {
  338. struct sockaddr_in6 *sin6 =
  339. (struct sockaddr_in6 *)
  340. &ep->com.local_addr;
  341. cxgb4_clip_release(
  342. ep->com.dev->rdev.lldi.ports[0],
  343. (const u32 *)&sin6->sin6_addr.s6_addr,
  344. 1);
  345. }
  346. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid,
  347. ep->com.local_addr.ss_family);
  348. dst_release(ep->dst);
  349. cxgb4_l2t_release(ep->l2t);
  350. if (ep->mpa_skb)
  351. kfree_skb(ep->mpa_skb);
  352. }
  353. if (!skb_queue_empty(&ep->com.ep_skb_list))
  354. skb_queue_purge(&ep->com.ep_skb_list);
  355. c4iw_put_wr_wait(ep->com.wr_waitp);
  356. kfree(ep);
  357. }
  358. static void release_ep_resources(struct c4iw_ep *ep)
  359. {
  360. set_bit(RELEASE_RESOURCES, &ep->com.flags);
  361. /*
  362. * If we have a hwtid, then remove it from the idr table
  363. * so lookups will no longer find this endpoint. Otherwise
  364. * we have a race where one thread finds the ep ptr just
  365. * before the other thread is freeing the ep memory.
  366. */
  367. if (ep->hwtid != -1)
  368. remove_ep_tid(ep);
  369. c4iw_put_ep(&ep->com);
  370. }
  371. static int status2errno(int status)
  372. {
  373. switch (status) {
  374. case CPL_ERR_NONE:
  375. return 0;
  376. case CPL_ERR_CONN_RESET:
  377. return -ECONNRESET;
  378. case CPL_ERR_ARP_MISS:
  379. return -EHOSTUNREACH;
  380. case CPL_ERR_CONN_TIMEDOUT:
  381. return -ETIMEDOUT;
  382. case CPL_ERR_TCAM_FULL:
  383. return -ENOMEM;
  384. case CPL_ERR_CONN_EXIST:
  385. return -EADDRINUSE;
  386. default:
  387. return -EIO;
  388. }
  389. }
  390. /*
  391. * Try and reuse skbs already allocated...
  392. */
  393. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
  394. {
  395. if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
  396. skb_trim(skb, 0);
  397. skb_get(skb);
  398. skb_reset_transport_header(skb);
  399. } else {
  400. skb = alloc_skb(len, gfp);
  401. if (!skb)
  402. return NULL;
  403. }
  404. t4_set_arp_err_handler(skb, NULL, NULL);
  405. return skb;
  406. }
  407. static struct net_device *get_real_dev(struct net_device *egress_dev)
  408. {
  409. return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
  410. }
  411. static void arp_failure_discard(void *handle, struct sk_buff *skb)
  412. {
  413. pr_err("ARP failure\n");
  414. kfree_skb(skb);
  415. }
  416. static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
  417. {
  418. pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
  419. }
  420. enum {
  421. NUM_FAKE_CPLS = 2,
  422. FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
  423. FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
  424. };
  425. static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
  426. {
  427. struct c4iw_ep *ep;
  428. ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
  429. release_ep_resources(ep);
  430. return 0;
  431. }
  432. static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
  433. {
  434. struct c4iw_ep *ep;
  435. ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
  436. c4iw_put_ep(&ep->parent_ep->com);
  437. release_ep_resources(ep);
  438. return 0;
  439. }
  440. /*
  441. * Fake up a special CPL opcode and call sched() so process_work() will call
  442. * _put_ep_safe() in a safe context to free the ep resources. This is needed
  443. * because ARP error handlers are called in an ATOMIC context, and
  444. * _c4iw_free_ep() needs to block.
  445. */
  446. static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
  447. int cpl)
  448. {
  449. struct cpl_act_establish *rpl = cplhdr(skb);
  450. /* Set our special ARP_FAILURE opcode */
  451. rpl->ot.opcode = cpl;
  452. /*
  453. * Save ep in the skb->cb area, after where sched() will save the dev
  454. * ptr.
  455. */
  456. *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
  457. sched(ep->com.dev, skb);
  458. }
  459. /* Handle an ARP failure for an accept */
  460. static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
  461. {
  462. struct c4iw_ep *ep = handle;
  463. pr_err("ARP failure during accept - tid %u - dropping connection\n",
  464. ep->hwtid);
  465. __state_set(&ep->com, DEAD);
  466. queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
  467. }
  468. /*
  469. * Handle an ARP failure for an active open.
  470. */
  471. static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
  472. {
  473. struct c4iw_ep *ep = handle;
  474. pr_err("ARP failure during connect\n");
  475. connect_reply_upcall(ep, -EHOSTUNREACH);
  476. __state_set(&ep->com, DEAD);
  477. if (ep->com.remote_addr.ss_family == AF_INET6) {
  478. struct sockaddr_in6 *sin6 =
  479. (struct sockaddr_in6 *)&ep->com.local_addr;
  480. cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
  481. (const u32 *)&sin6->sin6_addr.s6_addr, 1);
  482. }
  483. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  484. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  485. queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
  486. }
  487. /*
  488. * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
  489. * and send it along.
  490. */
  491. static void abort_arp_failure(void *handle, struct sk_buff *skb)
  492. {
  493. int ret;
  494. struct c4iw_ep *ep = handle;
  495. struct c4iw_rdev *rdev = &ep->com.dev->rdev;
  496. struct cpl_abort_req *req = cplhdr(skb);
  497. pr_debug("rdev %p\n", rdev);
  498. req->cmd = CPL_ABORT_NO_RST;
  499. skb_get(skb);
  500. ret = c4iw_ofld_send(rdev, skb);
  501. if (ret) {
  502. __state_set(&ep->com, DEAD);
  503. queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
  504. } else
  505. kfree_skb(skb);
  506. }
  507. static int send_flowc(struct c4iw_ep *ep)
  508. {
  509. struct fw_flowc_wr *flowc;
  510. struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
  511. u16 vlan = ep->l2t->vlan;
  512. int nparams;
  513. int flowclen, flowclen16;
  514. if (WARN_ON(!skb))
  515. return -ENOMEM;
  516. if (vlan == CPL_L2T_VLAN_NONE)
  517. nparams = 9;
  518. else
  519. nparams = 10;
  520. flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
  521. flowclen16 = DIV_ROUND_UP(flowclen, 16);
  522. flowclen = flowclen16 * 16;
  523. flowc = __skb_put(skb, flowclen);
  524. memset(flowc, 0, flowclen);
  525. flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
  526. FW_FLOWC_WR_NPARAMS_V(nparams));
  527. flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(flowclen16) |
  528. FW_WR_FLOWID_V(ep->hwtid));
  529. flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
  530. flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
  531. (ep->com.dev->rdev.lldi.pf));
  532. flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
  533. flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
  534. flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
  535. flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
  536. flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
  537. flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
  538. flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
  539. flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
  540. flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
  541. flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
  542. flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
  543. flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
  544. flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
  545. flowc->mnemval[7].val = cpu_to_be32(ep->emss);
  546. flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_RCV_SCALE;
  547. flowc->mnemval[8].val = cpu_to_be32(ep->snd_wscale);
  548. if (nparams == 10) {
  549. u16 pri;
  550. pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  551. flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
  552. flowc->mnemval[9].val = cpu_to_be32(pri);
  553. }
  554. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  555. return c4iw_ofld_send(&ep->com.dev->rdev, skb);
  556. }
  557. static int send_halfclose(struct c4iw_ep *ep)
  558. {
  559. struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
  560. u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
  561. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  562. if (WARN_ON(!skb))
  563. return -ENOMEM;
  564. cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
  565. NULL, arp_failure_discard);
  566. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  567. }
  568. static int send_abort(struct c4iw_ep *ep)
  569. {
  570. u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
  571. struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
  572. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  573. if (WARN_ON(!req_skb))
  574. return -ENOMEM;
  575. cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
  576. ep, abort_arp_failure);
  577. return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
  578. }
  579. static int send_connect(struct c4iw_ep *ep)
  580. {
  581. struct cpl_act_open_req *req = NULL;
  582. struct cpl_t5_act_open_req *t5req = NULL;
  583. struct cpl_t6_act_open_req *t6req = NULL;
  584. struct cpl_act_open_req6 *req6 = NULL;
  585. struct cpl_t5_act_open_req6 *t5req6 = NULL;
  586. struct cpl_t6_act_open_req6 *t6req6 = NULL;
  587. struct sk_buff *skb;
  588. u64 opt0;
  589. u32 opt2;
  590. unsigned int mtu_idx;
  591. u32 wscale;
  592. int win, sizev4, sizev6, wrlen;
  593. struct sockaddr_in *la = (struct sockaddr_in *)
  594. &ep->com.local_addr;
  595. struct sockaddr_in *ra = (struct sockaddr_in *)
  596. &ep->com.remote_addr;
  597. struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
  598. &ep->com.local_addr;
  599. struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
  600. &ep->com.remote_addr;
  601. int ret;
  602. enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
  603. u32 isn = (prandom_u32() & ~7UL) - 1;
  604. struct net_device *netdev;
  605. u64 params;
  606. netdev = ep->com.dev->rdev.lldi.ports[0];
  607. switch (CHELSIO_CHIP_VERSION(adapter_type)) {
  608. case CHELSIO_T4:
  609. sizev4 = sizeof(struct cpl_act_open_req);
  610. sizev6 = sizeof(struct cpl_act_open_req6);
  611. break;
  612. case CHELSIO_T5:
  613. sizev4 = sizeof(struct cpl_t5_act_open_req);
  614. sizev6 = sizeof(struct cpl_t5_act_open_req6);
  615. break;
  616. case CHELSIO_T6:
  617. sizev4 = sizeof(struct cpl_t6_act_open_req);
  618. sizev6 = sizeof(struct cpl_t6_act_open_req6);
  619. break;
  620. default:
  621. pr_err("T%d Chip is not supported\n",
  622. CHELSIO_CHIP_VERSION(adapter_type));
  623. return -EINVAL;
  624. }
  625. wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
  626. roundup(sizev4, 16) :
  627. roundup(sizev6, 16);
  628. pr_debug("ep %p atid %u\n", ep, ep->atid);
  629. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  630. if (!skb) {
  631. pr_err("%s - failed to alloc skb\n", __func__);
  632. return -ENOMEM;
  633. }
  634. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  635. cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
  636. enable_tcp_timestamps,
  637. (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
  638. wscale = cxgb_compute_wscale(rcv_win);
  639. /*
  640. * Specify the largest window that will fit in opt0. The
  641. * remainder will be specified in the rx_data_ack.
  642. */
  643. win = ep->rcv_win >> 10;
  644. if (win > RCV_BUFSIZ_M)
  645. win = RCV_BUFSIZ_M;
  646. opt0 = (nocong ? NO_CONG_F : 0) |
  647. KEEP_ALIVE_F |
  648. DELACK_F |
  649. WND_SCALE_V(wscale) |
  650. MSS_IDX_V(mtu_idx) |
  651. L2T_IDX_V(ep->l2t->idx) |
  652. TX_CHAN_V(ep->tx_chan) |
  653. SMAC_SEL_V(ep->smac_idx) |
  654. DSCP_V(ep->tos >> 2) |
  655. ULP_MODE_V(ULP_MODE_TCPDDP) |
  656. RCV_BUFSIZ_V(win);
  657. opt2 = RX_CHANNEL_V(0) |
  658. CCTRL_ECN_V(enable_ecn) |
  659. RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
  660. if (enable_tcp_timestamps)
  661. opt2 |= TSTAMPS_EN_F;
  662. if (enable_tcp_sack)
  663. opt2 |= SACK_EN_F;
  664. if (wscale && enable_tcp_window_scaling)
  665. opt2 |= WND_SCALE_EN_F;
  666. if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
  667. if (peer2peer)
  668. isn += 4;
  669. opt2 |= T5_OPT_2_VALID_F;
  670. opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
  671. opt2 |= T5_ISS_F;
  672. }
  673. params = cxgb4_select_ntuple(netdev, ep->l2t);
  674. if (ep->com.remote_addr.ss_family == AF_INET6)
  675. cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
  676. (const u32 *)&la6->sin6_addr.s6_addr, 1);
  677. t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
  678. if (ep->com.remote_addr.ss_family == AF_INET) {
  679. switch (CHELSIO_CHIP_VERSION(adapter_type)) {
  680. case CHELSIO_T4:
  681. req = skb_put(skb, wrlen);
  682. INIT_TP_WR(req, 0);
  683. break;
  684. case CHELSIO_T5:
  685. t5req = skb_put(skb, wrlen);
  686. INIT_TP_WR(t5req, 0);
  687. req = (struct cpl_act_open_req *)t5req;
  688. break;
  689. case CHELSIO_T6:
  690. t6req = skb_put(skb, wrlen);
  691. INIT_TP_WR(t6req, 0);
  692. req = (struct cpl_act_open_req *)t6req;
  693. t5req = (struct cpl_t5_act_open_req *)t6req;
  694. break;
  695. default:
  696. pr_err("T%d Chip is not supported\n",
  697. CHELSIO_CHIP_VERSION(adapter_type));
  698. ret = -EINVAL;
  699. goto clip_release;
  700. }
  701. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  702. ((ep->rss_qid<<14) | ep->atid)));
  703. req->local_port = la->sin_port;
  704. req->peer_port = ra->sin_port;
  705. req->local_ip = la->sin_addr.s_addr;
  706. req->peer_ip = ra->sin_addr.s_addr;
  707. req->opt0 = cpu_to_be64(opt0);
  708. if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
  709. req->params = cpu_to_be32(params);
  710. req->opt2 = cpu_to_be32(opt2);
  711. } else {
  712. if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
  713. t5req->params =
  714. cpu_to_be64(FILTER_TUPLE_V(params));
  715. t5req->rsvd = cpu_to_be32(isn);
  716. pr_debug("snd_isn %u\n", t5req->rsvd);
  717. t5req->opt2 = cpu_to_be32(opt2);
  718. } else {
  719. t6req->params =
  720. cpu_to_be64(FILTER_TUPLE_V(params));
  721. t6req->rsvd = cpu_to_be32(isn);
  722. pr_debug("snd_isn %u\n", t6req->rsvd);
  723. t6req->opt2 = cpu_to_be32(opt2);
  724. }
  725. }
  726. } else {
  727. switch (CHELSIO_CHIP_VERSION(adapter_type)) {
  728. case CHELSIO_T4:
  729. req6 = skb_put(skb, wrlen);
  730. INIT_TP_WR(req6, 0);
  731. break;
  732. case CHELSIO_T5:
  733. t5req6 = skb_put(skb, wrlen);
  734. INIT_TP_WR(t5req6, 0);
  735. req6 = (struct cpl_act_open_req6 *)t5req6;
  736. break;
  737. case CHELSIO_T6:
  738. t6req6 = skb_put(skb, wrlen);
  739. INIT_TP_WR(t6req6, 0);
  740. req6 = (struct cpl_act_open_req6 *)t6req6;
  741. t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
  742. break;
  743. default:
  744. pr_err("T%d Chip is not supported\n",
  745. CHELSIO_CHIP_VERSION(adapter_type));
  746. ret = -EINVAL;
  747. goto clip_release;
  748. }
  749. OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
  750. ((ep->rss_qid<<14)|ep->atid)));
  751. req6->local_port = la6->sin6_port;
  752. req6->peer_port = ra6->sin6_port;
  753. req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
  754. req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
  755. req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
  756. req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
  757. req6->opt0 = cpu_to_be64(opt0);
  758. if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
  759. req6->params = cpu_to_be32(cxgb4_select_ntuple(netdev,
  760. ep->l2t));
  761. req6->opt2 = cpu_to_be32(opt2);
  762. } else {
  763. if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
  764. t5req6->params =
  765. cpu_to_be64(FILTER_TUPLE_V(params));
  766. t5req6->rsvd = cpu_to_be32(isn);
  767. pr_debug("snd_isn %u\n", t5req6->rsvd);
  768. t5req6->opt2 = cpu_to_be32(opt2);
  769. } else {
  770. t6req6->params =
  771. cpu_to_be64(FILTER_TUPLE_V(params));
  772. t6req6->rsvd = cpu_to_be32(isn);
  773. pr_debug("snd_isn %u\n", t6req6->rsvd);
  774. t6req6->opt2 = cpu_to_be32(opt2);
  775. }
  776. }
  777. }
  778. set_bit(ACT_OPEN_REQ, &ep->com.history);
  779. ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  780. clip_release:
  781. if (ret && ep->com.remote_addr.ss_family == AF_INET6)
  782. cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
  783. (const u32 *)&la6->sin6_addr.s6_addr, 1);
  784. return ret;
  785. }
  786. static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
  787. u8 mpa_rev_to_use)
  788. {
  789. int mpalen, wrlen, ret;
  790. struct fw_ofld_tx_data_wr *req;
  791. struct mpa_message *mpa;
  792. struct mpa_v2_conn_params mpa_v2_params;
  793. pr_debug("ep %p tid %u pd_len %d\n",
  794. ep, ep->hwtid, ep->plen);
  795. mpalen = sizeof(*mpa) + ep->plen;
  796. if (mpa_rev_to_use == 2)
  797. mpalen += sizeof(struct mpa_v2_conn_params);
  798. wrlen = roundup(mpalen + sizeof *req, 16);
  799. skb = get_skb(skb, wrlen, GFP_KERNEL);
  800. if (!skb) {
  801. connect_reply_upcall(ep, -ENOMEM);
  802. return -ENOMEM;
  803. }
  804. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  805. req = skb_put_zero(skb, wrlen);
  806. req->op_to_immdlen = cpu_to_be32(
  807. FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
  808. FW_WR_COMPL_F |
  809. FW_WR_IMMDLEN_V(mpalen));
  810. req->flowid_len16 = cpu_to_be32(
  811. FW_WR_FLOWID_V(ep->hwtid) |
  812. FW_WR_LEN16_V(wrlen >> 4));
  813. req->plen = cpu_to_be32(mpalen);
  814. req->tunnel_to_proxy = cpu_to_be32(
  815. FW_OFLD_TX_DATA_WR_FLUSH_F |
  816. FW_OFLD_TX_DATA_WR_SHOVE_F);
  817. mpa = (struct mpa_message *)(req + 1);
  818. memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
  819. mpa->flags = 0;
  820. if (crc_enabled)
  821. mpa->flags |= MPA_CRC;
  822. if (markers_enabled) {
  823. mpa->flags |= MPA_MARKERS;
  824. ep->mpa_attr.recv_marker_enabled = 1;
  825. } else {
  826. ep->mpa_attr.recv_marker_enabled = 0;
  827. }
  828. if (mpa_rev_to_use == 2)
  829. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  830. mpa->private_data_size = htons(ep->plen);
  831. mpa->revision = mpa_rev_to_use;
  832. if (mpa_rev_to_use == 1) {
  833. ep->tried_with_mpa_v1 = 1;
  834. ep->retry_with_mpa_v1 = 0;
  835. }
  836. if (mpa_rev_to_use == 2) {
  837. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  838. sizeof (struct mpa_v2_conn_params));
  839. pr_debug("initiator ird %u ord %u\n", ep->ird,
  840. ep->ord);
  841. mpa_v2_params.ird = htons((u16)ep->ird);
  842. mpa_v2_params.ord = htons((u16)ep->ord);
  843. if (peer2peer) {
  844. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  845. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  846. mpa_v2_params.ord |=
  847. htons(MPA_V2_RDMA_WRITE_RTR);
  848. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  849. mpa_v2_params.ord |=
  850. htons(MPA_V2_RDMA_READ_RTR);
  851. }
  852. memcpy(mpa->private_data, &mpa_v2_params,
  853. sizeof(struct mpa_v2_conn_params));
  854. if (ep->plen)
  855. memcpy(mpa->private_data +
  856. sizeof(struct mpa_v2_conn_params),
  857. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  858. } else
  859. if (ep->plen)
  860. memcpy(mpa->private_data,
  861. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  862. /*
  863. * Reference the mpa skb. This ensures the data area
  864. * will remain in memory until the hw acks the tx.
  865. * Function fw4_ack() will deref it.
  866. */
  867. skb_get(skb);
  868. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  869. ep->mpa_skb = skb;
  870. ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  871. if (ret)
  872. return ret;
  873. start_ep_timer(ep);
  874. __state_set(&ep->com, MPA_REQ_SENT);
  875. ep->mpa_attr.initiator = 1;
  876. ep->snd_seq += mpalen;
  877. return ret;
  878. }
  879. static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
  880. {
  881. int mpalen, wrlen;
  882. struct fw_ofld_tx_data_wr *req;
  883. struct mpa_message *mpa;
  884. struct sk_buff *skb;
  885. struct mpa_v2_conn_params mpa_v2_params;
  886. pr_debug("ep %p tid %u pd_len %d\n",
  887. ep, ep->hwtid, ep->plen);
  888. mpalen = sizeof(*mpa) + plen;
  889. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  890. mpalen += sizeof(struct mpa_v2_conn_params);
  891. wrlen = roundup(mpalen + sizeof *req, 16);
  892. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  893. if (!skb) {
  894. pr_err("%s - cannot alloc skb!\n", __func__);
  895. return -ENOMEM;
  896. }
  897. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  898. req = skb_put_zero(skb, wrlen);
  899. req->op_to_immdlen = cpu_to_be32(
  900. FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
  901. FW_WR_COMPL_F |
  902. FW_WR_IMMDLEN_V(mpalen));
  903. req->flowid_len16 = cpu_to_be32(
  904. FW_WR_FLOWID_V(ep->hwtid) |
  905. FW_WR_LEN16_V(wrlen >> 4));
  906. req->plen = cpu_to_be32(mpalen);
  907. req->tunnel_to_proxy = cpu_to_be32(
  908. FW_OFLD_TX_DATA_WR_FLUSH_F |
  909. FW_OFLD_TX_DATA_WR_SHOVE_F);
  910. mpa = (struct mpa_message *)(req + 1);
  911. memset(mpa, 0, sizeof(*mpa));
  912. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  913. mpa->flags = MPA_REJECT;
  914. mpa->revision = ep->mpa_attr.version;
  915. mpa->private_data_size = htons(plen);
  916. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  917. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  918. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  919. sizeof (struct mpa_v2_conn_params));
  920. mpa_v2_params.ird = htons(((u16)ep->ird) |
  921. (peer2peer ? MPA_V2_PEER2PEER_MODEL :
  922. 0));
  923. mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
  924. (p2p_type ==
  925. FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
  926. MPA_V2_RDMA_WRITE_RTR : p2p_type ==
  927. FW_RI_INIT_P2PTYPE_READ_REQ ?
  928. MPA_V2_RDMA_READ_RTR : 0) : 0));
  929. memcpy(mpa->private_data, &mpa_v2_params,
  930. sizeof(struct mpa_v2_conn_params));
  931. if (ep->plen)
  932. memcpy(mpa->private_data +
  933. sizeof(struct mpa_v2_conn_params), pdata, plen);
  934. } else
  935. if (plen)
  936. memcpy(mpa->private_data, pdata, plen);
  937. /*
  938. * Reference the mpa skb again. This ensures the data area
  939. * will remain in memory until the hw acks the tx.
  940. * Function fw4_ack() will deref it.
  941. */
  942. skb_get(skb);
  943. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  944. t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
  945. ep->mpa_skb = skb;
  946. ep->snd_seq += mpalen;
  947. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  948. }
  949. static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
  950. {
  951. int mpalen, wrlen;
  952. struct fw_ofld_tx_data_wr *req;
  953. struct mpa_message *mpa;
  954. struct sk_buff *skb;
  955. struct mpa_v2_conn_params mpa_v2_params;
  956. pr_debug("ep %p tid %u pd_len %d\n",
  957. ep, ep->hwtid, ep->plen);
  958. mpalen = sizeof(*mpa) + plen;
  959. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  960. mpalen += sizeof(struct mpa_v2_conn_params);
  961. wrlen = roundup(mpalen + sizeof *req, 16);
  962. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  963. if (!skb) {
  964. pr_err("%s - cannot alloc skb!\n", __func__);
  965. return -ENOMEM;
  966. }
  967. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  968. req = skb_put_zero(skb, wrlen);
  969. req->op_to_immdlen = cpu_to_be32(
  970. FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
  971. FW_WR_COMPL_F |
  972. FW_WR_IMMDLEN_V(mpalen));
  973. req->flowid_len16 = cpu_to_be32(
  974. FW_WR_FLOWID_V(ep->hwtid) |
  975. FW_WR_LEN16_V(wrlen >> 4));
  976. req->plen = cpu_to_be32(mpalen);
  977. req->tunnel_to_proxy = cpu_to_be32(
  978. FW_OFLD_TX_DATA_WR_FLUSH_F |
  979. FW_OFLD_TX_DATA_WR_SHOVE_F);
  980. mpa = (struct mpa_message *)(req + 1);
  981. memset(mpa, 0, sizeof(*mpa));
  982. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  983. mpa->flags = 0;
  984. if (ep->mpa_attr.crc_enabled)
  985. mpa->flags |= MPA_CRC;
  986. if (ep->mpa_attr.recv_marker_enabled)
  987. mpa->flags |= MPA_MARKERS;
  988. mpa->revision = ep->mpa_attr.version;
  989. mpa->private_data_size = htons(plen);
  990. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  991. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  992. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  993. sizeof (struct mpa_v2_conn_params));
  994. mpa_v2_params.ird = htons((u16)ep->ird);
  995. mpa_v2_params.ord = htons((u16)ep->ord);
  996. if (peer2peer && (ep->mpa_attr.p2p_type !=
  997. FW_RI_INIT_P2PTYPE_DISABLED)) {
  998. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  999. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  1000. mpa_v2_params.ord |=
  1001. htons(MPA_V2_RDMA_WRITE_RTR);
  1002. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  1003. mpa_v2_params.ord |=
  1004. htons(MPA_V2_RDMA_READ_RTR);
  1005. }
  1006. memcpy(mpa->private_data, &mpa_v2_params,
  1007. sizeof(struct mpa_v2_conn_params));
  1008. if (ep->plen)
  1009. memcpy(mpa->private_data +
  1010. sizeof(struct mpa_v2_conn_params), pdata, plen);
  1011. } else
  1012. if (plen)
  1013. memcpy(mpa->private_data, pdata, plen);
  1014. /*
  1015. * Reference the mpa skb. This ensures the data area
  1016. * will remain in memory until the hw acks the tx.
  1017. * Function fw4_ack() will deref it.
  1018. */
  1019. skb_get(skb);
  1020. t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
  1021. ep->mpa_skb = skb;
  1022. __state_set(&ep->com, MPA_REP_SENT);
  1023. ep->snd_seq += mpalen;
  1024. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1025. }
  1026. static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  1027. {
  1028. struct c4iw_ep *ep;
  1029. struct cpl_act_establish *req = cplhdr(skb);
  1030. unsigned short tcp_opt = ntohs(req->tcp_opt);
  1031. unsigned int tid = GET_TID(req);
  1032. unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
  1033. struct tid_info *t = dev->rdev.lldi.tids;
  1034. int ret;
  1035. ep = lookup_atid(t, atid);
  1036. pr_debug("ep %p tid %u snd_isn %u rcv_isn %u\n", ep, tid,
  1037. be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
  1038. mutex_lock(&ep->com.mutex);
  1039. dst_confirm(ep->dst);
  1040. /* setup the hwtid for this connection */
  1041. ep->hwtid = tid;
  1042. cxgb4_insert_tid(t, ep, tid, ep->com.local_addr.ss_family);
  1043. insert_ep_tid(ep);
  1044. ep->snd_seq = be32_to_cpu(req->snd_isn);
  1045. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  1046. ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
  1047. set_emss(ep, tcp_opt);
  1048. /* dealloc the atid */
  1049. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
  1050. cxgb4_free_atid(t, atid);
  1051. set_bit(ACT_ESTAB, &ep->com.history);
  1052. /* start MPA negotiation */
  1053. ret = send_flowc(ep);
  1054. if (ret)
  1055. goto err;
  1056. if (ep->retry_with_mpa_v1)
  1057. ret = send_mpa_req(ep, skb, 1);
  1058. else
  1059. ret = send_mpa_req(ep, skb, mpa_rev);
  1060. if (ret)
  1061. goto err;
  1062. mutex_unlock(&ep->com.mutex);
  1063. return 0;
  1064. err:
  1065. mutex_unlock(&ep->com.mutex);
  1066. connect_reply_upcall(ep, -ENOMEM);
  1067. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1068. return 0;
  1069. }
  1070. static void close_complete_upcall(struct c4iw_ep *ep, int status)
  1071. {
  1072. struct iw_cm_event event;
  1073. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1074. memset(&event, 0, sizeof(event));
  1075. event.event = IW_CM_EVENT_CLOSE;
  1076. event.status = status;
  1077. if (ep->com.cm_id) {
  1078. pr_debug("close complete delivered ep %p cm_id %p tid %u\n",
  1079. ep, ep->com.cm_id, ep->hwtid);
  1080. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  1081. deref_cm_id(&ep->com);
  1082. set_bit(CLOSE_UPCALL, &ep->com.history);
  1083. }
  1084. }
  1085. static void peer_close_upcall(struct c4iw_ep *ep)
  1086. {
  1087. struct iw_cm_event event;
  1088. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1089. memset(&event, 0, sizeof(event));
  1090. event.event = IW_CM_EVENT_DISCONNECT;
  1091. if (ep->com.cm_id) {
  1092. pr_debug("peer close delivered ep %p cm_id %p tid %u\n",
  1093. ep, ep->com.cm_id, ep->hwtid);
  1094. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  1095. set_bit(DISCONN_UPCALL, &ep->com.history);
  1096. }
  1097. }
  1098. static void peer_abort_upcall(struct c4iw_ep *ep)
  1099. {
  1100. struct iw_cm_event event;
  1101. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1102. memset(&event, 0, sizeof(event));
  1103. event.event = IW_CM_EVENT_CLOSE;
  1104. event.status = -ECONNRESET;
  1105. if (ep->com.cm_id) {
  1106. pr_debug("abort delivered ep %p cm_id %p tid %u\n", ep,
  1107. ep->com.cm_id, ep->hwtid);
  1108. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  1109. deref_cm_id(&ep->com);
  1110. set_bit(ABORT_UPCALL, &ep->com.history);
  1111. }
  1112. }
  1113. static void connect_reply_upcall(struct c4iw_ep *ep, int status)
  1114. {
  1115. struct iw_cm_event event;
  1116. pr_debug("ep %p tid %u status %d\n",
  1117. ep, ep->hwtid, status);
  1118. memset(&event, 0, sizeof(event));
  1119. event.event = IW_CM_EVENT_CONNECT_REPLY;
  1120. event.status = status;
  1121. memcpy(&event.local_addr, &ep->com.local_addr,
  1122. sizeof(ep->com.local_addr));
  1123. memcpy(&event.remote_addr, &ep->com.remote_addr,
  1124. sizeof(ep->com.remote_addr));
  1125. if ((status == 0) || (status == -ECONNREFUSED)) {
  1126. if (!ep->tried_with_mpa_v1) {
  1127. /* this means MPA_v2 is used */
  1128. event.ord = ep->ird;
  1129. event.ird = ep->ord;
  1130. event.private_data_len = ep->plen -
  1131. sizeof(struct mpa_v2_conn_params);
  1132. event.private_data = ep->mpa_pkt +
  1133. sizeof(struct mpa_message) +
  1134. sizeof(struct mpa_v2_conn_params);
  1135. } else {
  1136. /* this means MPA_v1 is used */
  1137. event.ord = cur_max_read_depth(ep->com.dev);
  1138. event.ird = cur_max_read_depth(ep->com.dev);
  1139. event.private_data_len = ep->plen;
  1140. event.private_data = ep->mpa_pkt +
  1141. sizeof(struct mpa_message);
  1142. }
  1143. }
  1144. pr_debug("ep %p tid %u status %d\n", ep,
  1145. ep->hwtid, status);
  1146. set_bit(CONN_RPL_UPCALL, &ep->com.history);
  1147. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  1148. if (status < 0)
  1149. deref_cm_id(&ep->com);
  1150. }
  1151. static int connect_request_upcall(struct c4iw_ep *ep)
  1152. {
  1153. struct iw_cm_event event;
  1154. int ret;
  1155. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1156. memset(&event, 0, sizeof(event));
  1157. event.event = IW_CM_EVENT_CONNECT_REQUEST;
  1158. memcpy(&event.local_addr, &ep->com.local_addr,
  1159. sizeof(ep->com.local_addr));
  1160. memcpy(&event.remote_addr, &ep->com.remote_addr,
  1161. sizeof(ep->com.remote_addr));
  1162. event.provider_data = ep;
  1163. if (!ep->tried_with_mpa_v1) {
  1164. /* this means MPA_v2 is used */
  1165. event.ord = ep->ord;
  1166. event.ird = ep->ird;
  1167. event.private_data_len = ep->plen -
  1168. sizeof(struct mpa_v2_conn_params);
  1169. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
  1170. sizeof(struct mpa_v2_conn_params);
  1171. } else {
  1172. /* this means MPA_v1 is used. Send max supported */
  1173. event.ord = cur_max_read_depth(ep->com.dev);
  1174. event.ird = cur_max_read_depth(ep->com.dev);
  1175. event.private_data_len = ep->plen;
  1176. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  1177. }
  1178. c4iw_get_ep(&ep->com);
  1179. ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
  1180. &event);
  1181. if (ret)
  1182. c4iw_put_ep(&ep->com);
  1183. set_bit(CONNREQ_UPCALL, &ep->com.history);
  1184. c4iw_put_ep(&ep->parent_ep->com);
  1185. return ret;
  1186. }
  1187. static void established_upcall(struct c4iw_ep *ep)
  1188. {
  1189. struct iw_cm_event event;
  1190. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1191. memset(&event, 0, sizeof(event));
  1192. event.event = IW_CM_EVENT_ESTABLISHED;
  1193. event.ird = ep->ord;
  1194. event.ord = ep->ird;
  1195. if (ep->com.cm_id) {
  1196. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1197. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  1198. set_bit(ESTAB_UPCALL, &ep->com.history);
  1199. }
  1200. }
  1201. static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
  1202. {
  1203. struct sk_buff *skb;
  1204. u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
  1205. u32 credit_dack;
  1206. pr_debug("ep %p tid %u credits %u\n",
  1207. ep, ep->hwtid, credits);
  1208. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  1209. if (!skb) {
  1210. pr_err("update_rx_credits - cannot alloc skb!\n");
  1211. return 0;
  1212. }
  1213. /*
  1214. * If we couldn't specify the entire rcv window at connection setup
  1215. * due to the limit in the number of bits in the RCV_BUFSIZ field,
  1216. * then add the overage in to the credits returned.
  1217. */
  1218. if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
  1219. credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
  1220. credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
  1221. RX_DACK_MODE_V(dack_mode);
  1222. cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
  1223. credit_dack);
  1224. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  1225. return credits;
  1226. }
  1227. #define RELAXED_IRD_NEGOTIATION 1
  1228. /*
  1229. * process_mpa_reply - process streaming mode MPA reply
  1230. *
  1231. * Returns:
  1232. *
  1233. * 0 upon success indicating a connect request was delivered to the ULP
  1234. * or the mpa request is incomplete but valid so far.
  1235. *
  1236. * 1 if a failure requires the caller to close the connection.
  1237. *
  1238. * 2 if a failure requires the caller to abort the connection.
  1239. */
  1240. static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
  1241. {
  1242. struct mpa_message *mpa;
  1243. struct mpa_v2_conn_params *mpa_v2_params;
  1244. u16 plen;
  1245. u16 resp_ird, resp_ord;
  1246. u8 rtr_mismatch = 0, insuff_ird = 0;
  1247. struct c4iw_qp_attributes attrs;
  1248. enum c4iw_qp_attr_mask mask;
  1249. int err;
  1250. int disconnect = 0;
  1251. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1252. /*
  1253. * If we get more than the supported amount of private data
  1254. * then we must fail this connection.
  1255. */
  1256. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  1257. err = -EINVAL;
  1258. goto err_stop_timer;
  1259. }
  1260. /*
  1261. * copy the new data into our accumulation buffer.
  1262. */
  1263. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  1264. skb->len);
  1265. ep->mpa_pkt_len += skb->len;
  1266. /*
  1267. * if we don't even have the mpa message, then bail.
  1268. */
  1269. if (ep->mpa_pkt_len < sizeof(*mpa))
  1270. return 0;
  1271. mpa = (struct mpa_message *) ep->mpa_pkt;
  1272. /* Validate MPA header. */
  1273. if (mpa->revision > mpa_rev) {
  1274. pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
  1275. __func__, mpa_rev, mpa->revision);
  1276. err = -EPROTO;
  1277. goto err_stop_timer;
  1278. }
  1279. if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
  1280. err = -EPROTO;
  1281. goto err_stop_timer;
  1282. }
  1283. plen = ntohs(mpa->private_data_size);
  1284. /*
  1285. * Fail if there's too much private data.
  1286. */
  1287. if (plen > MPA_MAX_PRIVATE_DATA) {
  1288. err = -EPROTO;
  1289. goto err_stop_timer;
  1290. }
  1291. /*
  1292. * If plen does not account for pkt size
  1293. */
  1294. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  1295. err = -EPROTO;
  1296. goto err_stop_timer;
  1297. }
  1298. ep->plen = (u8) plen;
  1299. /*
  1300. * If we don't have all the pdata yet, then bail.
  1301. * We'll continue process when more data arrives.
  1302. */
  1303. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  1304. return 0;
  1305. if (mpa->flags & MPA_REJECT) {
  1306. err = -ECONNREFUSED;
  1307. goto err_stop_timer;
  1308. }
  1309. /*
  1310. * Stop mpa timer. If it expired, then
  1311. * we ignore the MPA reply. process_timeout()
  1312. * will abort the connection.
  1313. */
  1314. if (stop_ep_timer(ep))
  1315. return 0;
  1316. /*
  1317. * If we get here we have accumulated the entire mpa
  1318. * start reply message including private data. And
  1319. * the MPA header is valid.
  1320. */
  1321. __state_set(&ep->com, FPDU_MODE);
  1322. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  1323. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  1324. ep->mpa_attr.version = mpa->revision;
  1325. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1326. if (mpa->revision == 2) {
  1327. ep->mpa_attr.enhanced_rdma_conn =
  1328. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  1329. if (ep->mpa_attr.enhanced_rdma_conn) {
  1330. mpa_v2_params = (struct mpa_v2_conn_params *)
  1331. (ep->mpa_pkt + sizeof(*mpa));
  1332. resp_ird = ntohs(mpa_v2_params->ird) &
  1333. MPA_V2_IRD_ORD_MASK;
  1334. resp_ord = ntohs(mpa_v2_params->ord) &
  1335. MPA_V2_IRD_ORD_MASK;
  1336. pr_debug("responder ird %u ord %u ep ird %u ord %u\n",
  1337. resp_ird, resp_ord, ep->ird, ep->ord);
  1338. /*
  1339. * This is a double-check. Ideally, below checks are
  1340. * not required since ird/ord stuff has been taken
  1341. * care of in c4iw_accept_cr
  1342. */
  1343. if (ep->ird < resp_ord) {
  1344. if (RELAXED_IRD_NEGOTIATION && resp_ord <=
  1345. ep->com.dev->rdev.lldi.max_ordird_qp)
  1346. ep->ird = resp_ord;
  1347. else
  1348. insuff_ird = 1;
  1349. } else if (ep->ird > resp_ord) {
  1350. ep->ird = resp_ord;
  1351. }
  1352. if (ep->ord > resp_ird) {
  1353. if (RELAXED_IRD_NEGOTIATION)
  1354. ep->ord = resp_ird;
  1355. else
  1356. insuff_ird = 1;
  1357. }
  1358. if (insuff_ird) {
  1359. err = -ENOMEM;
  1360. ep->ird = resp_ord;
  1361. ep->ord = resp_ird;
  1362. }
  1363. if (ntohs(mpa_v2_params->ird) &
  1364. MPA_V2_PEER2PEER_MODEL) {
  1365. if (ntohs(mpa_v2_params->ord) &
  1366. MPA_V2_RDMA_WRITE_RTR)
  1367. ep->mpa_attr.p2p_type =
  1368. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  1369. else if (ntohs(mpa_v2_params->ord) &
  1370. MPA_V2_RDMA_READ_RTR)
  1371. ep->mpa_attr.p2p_type =
  1372. FW_RI_INIT_P2PTYPE_READ_REQ;
  1373. }
  1374. }
  1375. } else if (mpa->revision == 1)
  1376. if (peer2peer)
  1377. ep->mpa_attr.p2p_type = p2p_type;
  1378. pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = %d\n",
  1379. ep->mpa_attr.crc_enabled,
  1380. ep->mpa_attr.recv_marker_enabled,
  1381. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  1382. ep->mpa_attr.p2p_type, p2p_type);
  1383. /*
  1384. * If responder's RTR does not match with that of initiator, assign
  1385. * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
  1386. * generated when moving QP to RTS state.
  1387. * A TERM message will be sent after QP has moved to RTS state
  1388. */
  1389. if ((ep->mpa_attr.version == 2) && peer2peer &&
  1390. (ep->mpa_attr.p2p_type != p2p_type)) {
  1391. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1392. rtr_mismatch = 1;
  1393. }
  1394. attrs.mpa_attr = ep->mpa_attr;
  1395. attrs.max_ird = ep->ird;
  1396. attrs.max_ord = ep->ord;
  1397. attrs.llp_stream_handle = ep;
  1398. attrs.next_state = C4IW_QP_STATE_RTS;
  1399. mask = C4IW_QP_ATTR_NEXT_STATE |
  1400. C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
  1401. C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
  1402. /* bind QP and TID with INIT_WR */
  1403. err = c4iw_modify_qp(ep->com.qp->rhp,
  1404. ep->com.qp, mask, &attrs, 1);
  1405. if (err)
  1406. goto err;
  1407. /*
  1408. * If responder's RTR requirement did not match with what initiator
  1409. * supports, generate TERM message
  1410. */
  1411. if (rtr_mismatch) {
  1412. pr_err("%s: RTR mismatch, sending TERM\n", __func__);
  1413. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1414. attrs.ecode = MPA_NOMATCH_RTR;
  1415. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1416. attrs.send_term = 1;
  1417. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1418. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1419. err = -ENOMEM;
  1420. disconnect = 1;
  1421. goto out;
  1422. }
  1423. /*
  1424. * Generate TERM if initiator IRD is not sufficient for responder
  1425. * provided ORD. Currently, we do the same behaviour even when
  1426. * responder provided IRD is also not sufficient as regards to
  1427. * initiator ORD.
  1428. */
  1429. if (insuff_ird) {
  1430. pr_err("%s: Insufficient IRD, sending TERM\n", __func__);
  1431. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1432. attrs.ecode = MPA_INSUFF_IRD;
  1433. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1434. attrs.send_term = 1;
  1435. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1436. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1437. err = -ENOMEM;
  1438. disconnect = 1;
  1439. goto out;
  1440. }
  1441. goto out;
  1442. err_stop_timer:
  1443. stop_ep_timer(ep);
  1444. err:
  1445. disconnect = 2;
  1446. out:
  1447. connect_reply_upcall(ep, err);
  1448. return disconnect;
  1449. }
  1450. /*
  1451. * process_mpa_request - process streaming mode MPA request
  1452. *
  1453. * Returns:
  1454. *
  1455. * 0 upon success indicating a connect request was delivered to the ULP
  1456. * or the mpa request is incomplete but valid so far.
  1457. *
  1458. * 1 if a failure requires the caller to close the connection.
  1459. *
  1460. * 2 if a failure requires the caller to abort the connection.
  1461. */
  1462. static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
  1463. {
  1464. struct mpa_message *mpa;
  1465. struct mpa_v2_conn_params *mpa_v2_params;
  1466. u16 plen;
  1467. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1468. /*
  1469. * If we get more than the supported amount of private data
  1470. * then we must fail this connection.
  1471. */
  1472. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
  1473. goto err_stop_timer;
  1474. pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
  1475. /*
  1476. * Copy the new data into our accumulation buffer.
  1477. */
  1478. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  1479. skb->len);
  1480. ep->mpa_pkt_len += skb->len;
  1481. /*
  1482. * If we don't even have the mpa message, then bail.
  1483. * We'll continue process when more data arrives.
  1484. */
  1485. if (ep->mpa_pkt_len < sizeof(*mpa))
  1486. return 0;
  1487. pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
  1488. mpa = (struct mpa_message *) ep->mpa_pkt;
  1489. /*
  1490. * Validate MPA Header.
  1491. */
  1492. if (mpa->revision > mpa_rev) {
  1493. pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
  1494. __func__, mpa_rev, mpa->revision);
  1495. goto err_stop_timer;
  1496. }
  1497. if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
  1498. goto err_stop_timer;
  1499. plen = ntohs(mpa->private_data_size);
  1500. /*
  1501. * Fail if there's too much private data.
  1502. */
  1503. if (plen > MPA_MAX_PRIVATE_DATA)
  1504. goto err_stop_timer;
  1505. /*
  1506. * If plen does not account for pkt size
  1507. */
  1508. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
  1509. goto err_stop_timer;
  1510. ep->plen = (u8) plen;
  1511. /*
  1512. * If we don't have all the pdata yet, then bail.
  1513. */
  1514. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  1515. return 0;
  1516. /*
  1517. * If we get here we have accumulated the entire mpa
  1518. * start reply message including private data.
  1519. */
  1520. ep->mpa_attr.initiator = 0;
  1521. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  1522. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  1523. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  1524. ep->mpa_attr.version = mpa->revision;
  1525. if (mpa->revision == 1)
  1526. ep->tried_with_mpa_v1 = 1;
  1527. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1528. if (mpa->revision == 2) {
  1529. ep->mpa_attr.enhanced_rdma_conn =
  1530. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  1531. if (ep->mpa_attr.enhanced_rdma_conn) {
  1532. mpa_v2_params = (struct mpa_v2_conn_params *)
  1533. (ep->mpa_pkt + sizeof(*mpa));
  1534. ep->ird = ntohs(mpa_v2_params->ird) &
  1535. MPA_V2_IRD_ORD_MASK;
  1536. ep->ird = min_t(u32, ep->ird,
  1537. cur_max_read_depth(ep->com.dev));
  1538. ep->ord = ntohs(mpa_v2_params->ord) &
  1539. MPA_V2_IRD_ORD_MASK;
  1540. ep->ord = min_t(u32, ep->ord,
  1541. cur_max_read_depth(ep->com.dev));
  1542. pr_debug("initiator ird %u ord %u\n",
  1543. ep->ird, ep->ord);
  1544. if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
  1545. if (peer2peer) {
  1546. if (ntohs(mpa_v2_params->ord) &
  1547. MPA_V2_RDMA_WRITE_RTR)
  1548. ep->mpa_attr.p2p_type =
  1549. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  1550. else if (ntohs(mpa_v2_params->ord) &
  1551. MPA_V2_RDMA_READ_RTR)
  1552. ep->mpa_attr.p2p_type =
  1553. FW_RI_INIT_P2PTYPE_READ_REQ;
  1554. }
  1555. }
  1556. } else if (mpa->revision == 1)
  1557. if (peer2peer)
  1558. ep->mpa_attr.p2p_type = p2p_type;
  1559. pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d\n",
  1560. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  1561. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  1562. ep->mpa_attr.p2p_type);
  1563. __state_set(&ep->com, MPA_REQ_RCVD);
  1564. /* drive upcall */
  1565. mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
  1566. if (ep->parent_ep->com.state != DEAD) {
  1567. if (connect_request_upcall(ep))
  1568. goto err_unlock_parent;
  1569. } else {
  1570. goto err_unlock_parent;
  1571. }
  1572. mutex_unlock(&ep->parent_ep->com.mutex);
  1573. return 0;
  1574. err_unlock_parent:
  1575. mutex_unlock(&ep->parent_ep->com.mutex);
  1576. goto err_out;
  1577. err_stop_timer:
  1578. (void)stop_ep_timer(ep);
  1579. err_out:
  1580. return 2;
  1581. }
  1582. static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
  1583. {
  1584. struct c4iw_ep *ep;
  1585. struct cpl_rx_data *hdr = cplhdr(skb);
  1586. unsigned int dlen = ntohs(hdr->len);
  1587. unsigned int tid = GET_TID(hdr);
  1588. __u8 status = hdr->status;
  1589. int disconnect = 0;
  1590. ep = get_ep_from_tid(dev, tid);
  1591. if (!ep)
  1592. return 0;
  1593. pr_debug("ep %p tid %u dlen %u\n", ep, ep->hwtid, dlen);
  1594. skb_pull(skb, sizeof(*hdr));
  1595. skb_trim(skb, dlen);
  1596. mutex_lock(&ep->com.mutex);
  1597. switch (ep->com.state) {
  1598. case MPA_REQ_SENT:
  1599. update_rx_credits(ep, dlen);
  1600. ep->rcv_seq += dlen;
  1601. disconnect = process_mpa_reply(ep, skb);
  1602. break;
  1603. case MPA_REQ_WAIT:
  1604. update_rx_credits(ep, dlen);
  1605. ep->rcv_seq += dlen;
  1606. disconnect = process_mpa_request(ep, skb);
  1607. break;
  1608. case FPDU_MODE: {
  1609. struct c4iw_qp_attributes attrs;
  1610. update_rx_credits(ep, dlen);
  1611. if (status)
  1612. pr_err("%s Unexpected streaming data." \
  1613. " qpid %u ep %p state %d tid %u status %d\n",
  1614. __func__, ep->com.qp->wq.sq.qid, ep,
  1615. ep->com.state, ep->hwtid, status);
  1616. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1617. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1618. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1619. disconnect = 1;
  1620. break;
  1621. }
  1622. default:
  1623. break;
  1624. }
  1625. mutex_unlock(&ep->com.mutex);
  1626. if (disconnect)
  1627. c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
  1628. c4iw_put_ep(&ep->com);
  1629. return 0;
  1630. }
  1631. static void complete_cached_srq_buffers(struct c4iw_ep *ep,
  1632. __be32 srqidx_status)
  1633. {
  1634. enum chip_type adapter_type;
  1635. u32 srqidx;
  1636. adapter_type = ep->com.dev->rdev.lldi.adapter_type;
  1637. srqidx = ABORT_RSS_SRQIDX_G(be32_to_cpu(srqidx_status));
  1638. /*
  1639. * If this TCB had a srq buffer cached, then we must complete
  1640. * it. For user mode, that means saving the srqidx in the
  1641. * user/kernel status page for this qp. For kernel mode, just
  1642. * synthesize the CQE now.
  1643. */
  1644. if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T5 && srqidx) {
  1645. if (ep->com.qp->ibqp.uobject)
  1646. t4_set_wq_in_error(&ep->com.qp->wq, srqidx);
  1647. else
  1648. c4iw_flush_srqidx(ep->com.qp, srqidx);
  1649. }
  1650. }
  1651. static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1652. {
  1653. struct c4iw_ep *ep;
  1654. struct cpl_abort_rpl_rss6 *rpl = cplhdr(skb);
  1655. int release = 0;
  1656. unsigned int tid = GET_TID(rpl);
  1657. ep = get_ep_from_tid(dev, tid);
  1658. if (!ep) {
  1659. pr_warn("Abort rpl to freed endpoint\n");
  1660. return 0;
  1661. }
  1662. complete_cached_srq_buffers(ep, rpl->srqidx_status);
  1663. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  1664. mutex_lock(&ep->com.mutex);
  1665. switch (ep->com.state) {
  1666. case ABORTING:
  1667. c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
  1668. __state_set(&ep->com, DEAD);
  1669. release = 1;
  1670. break;
  1671. default:
  1672. pr_err("%s ep %p state %d\n", __func__, ep, ep->com.state);
  1673. break;
  1674. }
  1675. mutex_unlock(&ep->com.mutex);
  1676. if (release) {
  1677. close_complete_upcall(ep, -ECONNRESET);
  1678. release_ep_resources(ep);
  1679. }
  1680. c4iw_put_ep(&ep->com);
  1681. return 0;
  1682. }
  1683. static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
  1684. {
  1685. struct sk_buff *skb;
  1686. struct fw_ofld_connection_wr *req;
  1687. unsigned int mtu_idx;
  1688. u32 wscale;
  1689. struct sockaddr_in *sin;
  1690. int win;
  1691. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1692. req = __skb_put_zero(skb, sizeof(*req));
  1693. req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
  1694. req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
  1695. req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
  1696. ep->com.dev->rdev.lldi.ports[0],
  1697. ep->l2t));
  1698. sin = (struct sockaddr_in *)&ep->com.local_addr;
  1699. req->le.lport = sin->sin_port;
  1700. req->le.u.ipv4.lip = sin->sin_addr.s_addr;
  1701. sin = (struct sockaddr_in *)&ep->com.remote_addr;
  1702. req->le.pport = sin->sin_port;
  1703. req->le.u.ipv4.pip = sin->sin_addr.s_addr;
  1704. req->tcb.t_state_to_astid =
  1705. htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
  1706. FW_OFLD_CONNECTION_WR_ASTID_V(atid));
  1707. req->tcb.cplrxdataack_cplpassacceptrpl =
  1708. htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
  1709. req->tcb.tx_max = (__force __be32) jiffies;
  1710. req->tcb.rcv_adv = htons(1);
  1711. cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
  1712. enable_tcp_timestamps,
  1713. (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
  1714. wscale = cxgb_compute_wscale(rcv_win);
  1715. /*
  1716. * Specify the largest window that will fit in opt0. The
  1717. * remainder will be specified in the rx_data_ack.
  1718. */
  1719. win = ep->rcv_win >> 10;
  1720. if (win > RCV_BUFSIZ_M)
  1721. win = RCV_BUFSIZ_M;
  1722. req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
  1723. (nocong ? NO_CONG_F : 0) |
  1724. KEEP_ALIVE_F |
  1725. DELACK_F |
  1726. WND_SCALE_V(wscale) |
  1727. MSS_IDX_V(mtu_idx) |
  1728. L2T_IDX_V(ep->l2t->idx) |
  1729. TX_CHAN_V(ep->tx_chan) |
  1730. SMAC_SEL_V(ep->smac_idx) |
  1731. DSCP_V(ep->tos >> 2) |
  1732. ULP_MODE_V(ULP_MODE_TCPDDP) |
  1733. RCV_BUFSIZ_V(win));
  1734. req->tcb.opt2 = (__force __be32) (PACE_V(1) |
  1735. TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
  1736. RX_CHANNEL_V(0) |
  1737. CCTRL_ECN_V(enable_ecn) |
  1738. RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
  1739. if (enable_tcp_timestamps)
  1740. req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
  1741. if (enable_tcp_sack)
  1742. req->tcb.opt2 |= (__force __be32)SACK_EN_F;
  1743. if (wscale && enable_tcp_window_scaling)
  1744. req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
  1745. req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
  1746. req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
  1747. set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
  1748. set_bit(ACT_OFLD_CONN, &ep->com.history);
  1749. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1750. }
  1751. /*
  1752. * Some of the error codes above implicitly indicate that there is no TID
  1753. * allocated with the result of an ACT_OPEN. We use this predicate to make
  1754. * that explicit.
  1755. */
  1756. static inline int act_open_has_tid(int status)
  1757. {
  1758. return (status != CPL_ERR_TCAM_PARITY &&
  1759. status != CPL_ERR_TCAM_MISS &&
  1760. status != CPL_ERR_TCAM_FULL &&
  1761. status != CPL_ERR_CONN_EXIST_SYNRECV &&
  1762. status != CPL_ERR_CONN_EXIST);
  1763. }
  1764. static char *neg_adv_str(unsigned int status)
  1765. {
  1766. switch (status) {
  1767. case CPL_ERR_RTX_NEG_ADVICE:
  1768. return "Retransmit timeout";
  1769. case CPL_ERR_PERSIST_NEG_ADVICE:
  1770. return "Persist timeout";
  1771. case CPL_ERR_KEEPALV_NEG_ADVICE:
  1772. return "Keepalive timeout";
  1773. default:
  1774. return "Unknown";
  1775. }
  1776. }
  1777. static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
  1778. {
  1779. ep->snd_win = snd_win;
  1780. ep->rcv_win = rcv_win;
  1781. pr_debug("snd_win %d rcv_win %d\n",
  1782. ep->snd_win, ep->rcv_win);
  1783. }
  1784. #define ACT_OPEN_RETRY_COUNT 2
  1785. static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
  1786. struct dst_entry *dst, struct c4iw_dev *cdev,
  1787. bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
  1788. {
  1789. struct neighbour *n;
  1790. int err, step;
  1791. struct net_device *pdev;
  1792. n = dst_neigh_lookup(dst, peer_ip);
  1793. if (!n)
  1794. return -ENODEV;
  1795. rcu_read_lock();
  1796. err = -ENOMEM;
  1797. if (n->dev->flags & IFF_LOOPBACK) {
  1798. if (iptype == 4)
  1799. pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
  1800. else if (IS_ENABLED(CONFIG_IPV6))
  1801. for_each_netdev(&init_net, pdev) {
  1802. if (ipv6_chk_addr(&init_net,
  1803. (struct in6_addr *)peer_ip,
  1804. pdev, 1))
  1805. break;
  1806. }
  1807. else
  1808. pdev = NULL;
  1809. if (!pdev) {
  1810. err = -ENODEV;
  1811. goto out;
  1812. }
  1813. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1814. n, pdev, rt_tos2priority(tos));
  1815. if (!ep->l2t) {
  1816. dev_put(pdev);
  1817. goto out;
  1818. }
  1819. ep->mtu = pdev->mtu;
  1820. ep->tx_chan = cxgb4_port_chan(pdev);
  1821. ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
  1822. cxgb4_port_viid(pdev));
  1823. step = cdev->rdev.lldi.ntxq /
  1824. cdev->rdev.lldi.nchan;
  1825. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1826. step = cdev->rdev.lldi.nrxq /
  1827. cdev->rdev.lldi.nchan;
  1828. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  1829. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1830. cxgb4_port_idx(pdev) * step];
  1831. set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
  1832. dev_put(pdev);
  1833. } else {
  1834. pdev = get_real_dev(n->dev);
  1835. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1836. n, pdev, rt_tos2priority(tos));
  1837. if (!ep->l2t)
  1838. goto out;
  1839. ep->mtu = dst_mtu(dst);
  1840. ep->tx_chan = cxgb4_port_chan(pdev);
  1841. ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
  1842. cxgb4_port_viid(pdev));
  1843. step = cdev->rdev.lldi.ntxq /
  1844. cdev->rdev.lldi.nchan;
  1845. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1846. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  1847. step = cdev->rdev.lldi.nrxq /
  1848. cdev->rdev.lldi.nchan;
  1849. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1850. cxgb4_port_idx(pdev) * step];
  1851. set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
  1852. if (clear_mpa_v1) {
  1853. ep->retry_with_mpa_v1 = 0;
  1854. ep->tried_with_mpa_v1 = 0;
  1855. }
  1856. }
  1857. err = 0;
  1858. out:
  1859. rcu_read_unlock();
  1860. neigh_release(n);
  1861. return err;
  1862. }
  1863. static int c4iw_reconnect(struct c4iw_ep *ep)
  1864. {
  1865. int err = 0;
  1866. int size = 0;
  1867. struct sockaddr_in *laddr = (struct sockaddr_in *)
  1868. &ep->com.cm_id->m_local_addr;
  1869. struct sockaddr_in *raddr = (struct sockaddr_in *)
  1870. &ep->com.cm_id->m_remote_addr;
  1871. struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
  1872. &ep->com.cm_id->m_local_addr;
  1873. struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
  1874. &ep->com.cm_id->m_remote_addr;
  1875. int iptype;
  1876. __u8 *ra;
  1877. pr_debug("qp %p cm_id %p\n", ep->com.qp, ep->com.cm_id);
  1878. c4iw_init_wr_wait(ep->com.wr_waitp);
  1879. /* When MPA revision is different on nodes, the node with MPA_rev=2
  1880. * tries to reconnect with MPA_rev 1 for the same EP through
  1881. * c4iw_reconnect(), where the same EP is assigned with new tid for
  1882. * further connection establishment. As we are using the same EP pointer
  1883. * for reconnect, few skbs are used during the previous c4iw_connect(),
  1884. * which leaves the EP with inadequate skbs for further
  1885. * c4iw_reconnect(), Further causing a crash due to an empty
  1886. * skb_list() during peer_abort(). Allocate skbs which is already used.
  1887. */
  1888. size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
  1889. if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
  1890. err = -ENOMEM;
  1891. goto fail1;
  1892. }
  1893. /*
  1894. * Allocate an active TID to initiate a TCP connection.
  1895. */
  1896. ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
  1897. if (ep->atid == -1) {
  1898. pr_err("%s - cannot alloc atid\n", __func__);
  1899. err = -ENOMEM;
  1900. goto fail2;
  1901. }
  1902. insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
  1903. /* find a route */
  1904. if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
  1905. ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
  1906. laddr->sin_addr.s_addr,
  1907. raddr->sin_addr.s_addr,
  1908. laddr->sin_port,
  1909. raddr->sin_port, ep->com.cm_id->tos);
  1910. iptype = 4;
  1911. ra = (__u8 *)&raddr->sin_addr;
  1912. } else {
  1913. ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
  1914. get_real_dev,
  1915. laddr6->sin6_addr.s6_addr,
  1916. raddr6->sin6_addr.s6_addr,
  1917. laddr6->sin6_port,
  1918. raddr6->sin6_port,
  1919. ep->com.cm_id->tos,
  1920. raddr6->sin6_scope_id);
  1921. iptype = 6;
  1922. ra = (__u8 *)&raddr6->sin6_addr;
  1923. }
  1924. if (!ep->dst) {
  1925. pr_err("%s - cannot find route\n", __func__);
  1926. err = -EHOSTUNREACH;
  1927. goto fail3;
  1928. }
  1929. err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
  1930. ep->com.dev->rdev.lldi.adapter_type,
  1931. ep->com.cm_id->tos);
  1932. if (err) {
  1933. pr_err("%s - cannot alloc l2e\n", __func__);
  1934. goto fail4;
  1935. }
  1936. pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  1937. ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  1938. ep->l2t->idx);
  1939. state_set(&ep->com, CONNECTING);
  1940. ep->tos = ep->com.cm_id->tos;
  1941. /* send connect request to rnic */
  1942. err = send_connect(ep);
  1943. if (!err)
  1944. goto out;
  1945. cxgb4_l2t_release(ep->l2t);
  1946. fail4:
  1947. dst_release(ep->dst);
  1948. fail3:
  1949. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  1950. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  1951. fail2:
  1952. /*
  1953. * remember to send notification to upper layer.
  1954. * We are in here so the upper layer is not aware that this is
  1955. * re-connect attempt and so, upper layer is still waiting for
  1956. * response of 1st connect request.
  1957. */
  1958. connect_reply_upcall(ep, -ECONNRESET);
  1959. fail1:
  1960. c4iw_put_ep(&ep->com);
  1961. out:
  1962. return err;
  1963. }
  1964. static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1965. {
  1966. struct c4iw_ep *ep;
  1967. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1968. unsigned int atid = TID_TID_G(AOPEN_ATID_G(
  1969. ntohl(rpl->atid_status)));
  1970. struct tid_info *t = dev->rdev.lldi.tids;
  1971. int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
  1972. struct sockaddr_in *la;
  1973. struct sockaddr_in *ra;
  1974. struct sockaddr_in6 *la6;
  1975. struct sockaddr_in6 *ra6;
  1976. int ret = 0;
  1977. ep = lookup_atid(t, atid);
  1978. la = (struct sockaddr_in *)&ep->com.local_addr;
  1979. ra = (struct sockaddr_in *)&ep->com.remote_addr;
  1980. la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  1981. ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
  1982. pr_debug("ep %p atid %u status %u errno %d\n", ep, atid,
  1983. status, status2errno(status));
  1984. if (cxgb_is_neg_adv(status)) {
  1985. pr_debug("Connection problems for atid %u status %u (%s)\n",
  1986. atid, status, neg_adv_str(status));
  1987. ep->stats.connect_neg_adv++;
  1988. mutex_lock(&dev->rdev.stats.lock);
  1989. dev->rdev.stats.neg_adv++;
  1990. mutex_unlock(&dev->rdev.stats.lock);
  1991. return 0;
  1992. }
  1993. set_bit(ACT_OPEN_RPL, &ep->com.history);
  1994. /*
  1995. * Log interesting failures.
  1996. */
  1997. switch (status) {
  1998. case CPL_ERR_CONN_RESET:
  1999. case CPL_ERR_CONN_TIMEDOUT:
  2000. break;
  2001. case CPL_ERR_TCAM_FULL:
  2002. mutex_lock(&dev->rdev.stats.lock);
  2003. dev->rdev.stats.tcam_full++;
  2004. mutex_unlock(&dev->rdev.stats.lock);
  2005. if (ep->com.local_addr.ss_family == AF_INET &&
  2006. dev->rdev.lldi.enable_fw_ofld_conn) {
  2007. ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
  2008. ntohl(rpl->atid_status))));
  2009. if (ret)
  2010. goto fail;
  2011. return 0;
  2012. }
  2013. break;
  2014. case CPL_ERR_CONN_EXIST:
  2015. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  2016. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  2017. if (ep->com.remote_addr.ss_family == AF_INET6) {
  2018. struct sockaddr_in6 *sin6 =
  2019. (struct sockaddr_in6 *)
  2020. &ep->com.local_addr;
  2021. cxgb4_clip_release(
  2022. ep->com.dev->rdev.lldi.ports[0],
  2023. (const u32 *)
  2024. &sin6->sin6_addr.s6_addr, 1);
  2025. }
  2026. remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
  2027. atid);
  2028. cxgb4_free_atid(t, atid);
  2029. dst_release(ep->dst);
  2030. cxgb4_l2t_release(ep->l2t);
  2031. c4iw_reconnect(ep);
  2032. return 0;
  2033. }
  2034. break;
  2035. default:
  2036. if (ep->com.local_addr.ss_family == AF_INET) {
  2037. pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
  2038. atid, status, status2errno(status),
  2039. &la->sin_addr.s_addr, ntohs(la->sin_port),
  2040. &ra->sin_addr.s_addr, ntohs(ra->sin_port));
  2041. } else {
  2042. pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
  2043. atid, status, status2errno(status),
  2044. la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
  2045. ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
  2046. }
  2047. break;
  2048. }
  2049. fail:
  2050. connect_reply_upcall(ep, status2errno(status));
  2051. state_set(&ep->com, DEAD);
  2052. if (ep->com.remote_addr.ss_family == AF_INET6) {
  2053. struct sockaddr_in6 *sin6 =
  2054. (struct sockaddr_in6 *)&ep->com.local_addr;
  2055. cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
  2056. (const u32 *)&sin6->sin6_addr.s6_addr, 1);
  2057. }
  2058. if (status && act_open_has_tid(status))
  2059. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl),
  2060. ep->com.local_addr.ss_family);
  2061. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
  2062. cxgb4_free_atid(t, atid);
  2063. dst_release(ep->dst);
  2064. cxgb4_l2t_release(ep->l2t);
  2065. c4iw_put_ep(&ep->com);
  2066. return 0;
  2067. }
  2068. static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2069. {
  2070. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  2071. unsigned int stid = GET_TID(rpl);
  2072. struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
  2073. if (!ep) {
  2074. pr_warn("%s stid %d lookup failure!\n", __func__, stid);
  2075. goto out;
  2076. }
  2077. pr_debug("ep %p status %d error %d\n", ep,
  2078. rpl->status, status2errno(rpl->status));
  2079. c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
  2080. c4iw_put_ep(&ep->com);
  2081. out:
  2082. return 0;
  2083. }
  2084. static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2085. {
  2086. struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
  2087. unsigned int stid = GET_TID(rpl);
  2088. struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
  2089. if (!ep) {
  2090. pr_warn("%s stid %d lookup failure!\n", __func__, stid);
  2091. goto out;
  2092. }
  2093. pr_debug("ep %p\n", ep);
  2094. c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
  2095. c4iw_put_ep(&ep->com);
  2096. out:
  2097. return 0;
  2098. }
  2099. static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
  2100. struct cpl_pass_accept_req *req)
  2101. {
  2102. struct cpl_pass_accept_rpl *rpl;
  2103. unsigned int mtu_idx;
  2104. u64 opt0;
  2105. u32 opt2;
  2106. u32 wscale;
  2107. struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
  2108. int win;
  2109. enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
  2110. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  2111. cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
  2112. enable_tcp_timestamps && req->tcpopt.tstamp,
  2113. (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
  2114. wscale = cxgb_compute_wscale(rcv_win);
  2115. /*
  2116. * Specify the largest window that will fit in opt0. The
  2117. * remainder will be specified in the rx_data_ack.
  2118. */
  2119. win = ep->rcv_win >> 10;
  2120. if (win > RCV_BUFSIZ_M)
  2121. win = RCV_BUFSIZ_M;
  2122. opt0 = (nocong ? NO_CONG_F : 0) |
  2123. KEEP_ALIVE_F |
  2124. DELACK_F |
  2125. WND_SCALE_V(wscale) |
  2126. MSS_IDX_V(mtu_idx) |
  2127. L2T_IDX_V(ep->l2t->idx) |
  2128. TX_CHAN_V(ep->tx_chan) |
  2129. SMAC_SEL_V(ep->smac_idx) |
  2130. DSCP_V(ep->tos >> 2) |
  2131. ULP_MODE_V(ULP_MODE_TCPDDP) |
  2132. RCV_BUFSIZ_V(win);
  2133. opt2 = RX_CHANNEL_V(0) |
  2134. RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
  2135. if (enable_tcp_timestamps && req->tcpopt.tstamp)
  2136. opt2 |= TSTAMPS_EN_F;
  2137. if (enable_tcp_sack && req->tcpopt.sack)
  2138. opt2 |= SACK_EN_F;
  2139. if (wscale && enable_tcp_window_scaling)
  2140. opt2 |= WND_SCALE_EN_F;
  2141. if (enable_ecn) {
  2142. const struct tcphdr *tcph;
  2143. u32 hlen = ntohl(req->hdr_len);
  2144. if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
  2145. tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
  2146. IP_HDR_LEN_G(hlen);
  2147. else
  2148. tcph = (const void *)(req + 1) +
  2149. T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
  2150. if (tcph->ece && tcph->cwr)
  2151. opt2 |= CCTRL_ECN_V(1);
  2152. }
  2153. skb_get(skb);
  2154. rpl = cplhdr(skb);
  2155. if (!is_t4(adapter_type)) {
  2156. skb_trim(skb, roundup(sizeof(*rpl5), 16));
  2157. rpl5 = (void *)rpl;
  2158. INIT_TP_WR(rpl5, ep->hwtid);
  2159. } else {
  2160. skb_trim(skb, sizeof(*rpl));
  2161. INIT_TP_WR(rpl, ep->hwtid);
  2162. }
  2163. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  2164. ep->hwtid));
  2165. if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
  2166. u32 isn = (prandom_u32() & ~7UL) - 1;
  2167. opt2 |= T5_OPT_2_VALID_F;
  2168. opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
  2169. opt2 |= T5_ISS_F;
  2170. rpl5 = (void *)rpl;
  2171. memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
  2172. if (peer2peer)
  2173. isn += 4;
  2174. rpl5->iss = cpu_to_be32(isn);
  2175. pr_debug("iss %u\n", be32_to_cpu(rpl5->iss));
  2176. }
  2177. rpl->opt0 = cpu_to_be64(opt0);
  2178. rpl->opt2 = cpu_to_be32(opt2);
  2179. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  2180. t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
  2181. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  2182. }
  2183. static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
  2184. {
  2185. pr_debug("c4iw_dev %p tid %u\n", dev, hwtid);
  2186. skb_trim(skb, sizeof(struct cpl_tid_release));
  2187. release_tid(&dev->rdev, hwtid, skb);
  2188. return;
  2189. }
  2190. static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
  2191. {
  2192. struct c4iw_ep *child_ep = NULL, *parent_ep;
  2193. struct cpl_pass_accept_req *req = cplhdr(skb);
  2194. unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
  2195. struct tid_info *t = dev->rdev.lldi.tids;
  2196. unsigned int hwtid = GET_TID(req);
  2197. struct dst_entry *dst;
  2198. __u8 local_ip[16], peer_ip[16];
  2199. __be16 local_port, peer_port;
  2200. struct sockaddr_in6 *sin6;
  2201. int err;
  2202. u16 peer_mss = ntohs(req->tcpopt.mss);
  2203. int iptype;
  2204. unsigned short hdrs;
  2205. u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
  2206. parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
  2207. if (!parent_ep) {
  2208. pr_err("%s connect request on invalid stid %d\n",
  2209. __func__, stid);
  2210. goto reject;
  2211. }
  2212. if (state_read(&parent_ep->com) != LISTEN) {
  2213. pr_err("%s - listening ep not in LISTEN\n", __func__);
  2214. goto reject;
  2215. }
  2216. cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
  2217. &iptype, local_ip, peer_ip, &local_port, &peer_port);
  2218. /* Find output route */
  2219. if (iptype == 4) {
  2220. pr_debug("parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
  2221. , parent_ep, hwtid,
  2222. local_ip, peer_ip, ntohs(local_port),
  2223. ntohs(peer_port), peer_mss);
  2224. dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
  2225. *(__be32 *)local_ip, *(__be32 *)peer_ip,
  2226. local_port, peer_port, tos);
  2227. } else {
  2228. pr_debug("parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
  2229. , parent_ep, hwtid,
  2230. local_ip, peer_ip, ntohs(local_port),
  2231. ntohs(peer_port), peer_mss);
  2232. dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
  2233. local_ip, peer_ip, local_port, peer_port,
  2234. PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
  2235. ((struct sockaddr_in6 *)
  2236. &parent_ep->com.local_addr)->sin6_scope_id);
  2237. }
  2238. if (!dst) {
  2239. pr_err("%s - failed to find dst entry!\n", __func__);
  2240. goto reject;
  2241. }
  2242. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  2243. if (!child_ep) {
  2244. pr_err("%s - failed to allocate ep entry!\n", __func__);
  2245. dst_release(dst);
  2246. goto reject;
  2247. }
  2248. err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
  2249. parent_ep->com.dev->rdev.lldi.adapter_type, tos);
  2250. if (err) {
  2251. pr_err("%s - failed to allocate l2t entry!\n", __func__);
  2252. dst_release(dst);
  2253. kfree(child_ep);
  2254. goto reject;
  2255. }
  2256. hdrs = ((iptype == 4) ? sizeof(struct iphdr) : sizeof(struct ipv6hdr)) +
  2257. sizeof(struct tcphdr) +
  2258. ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
  2259. if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
  2260. child_ep->mtu = peer_mss + hdrs;
  2261. skb_queue_head_init(&child_ep->com.ep_skb_list);
  2262. if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
  2263. goto fail;
  2264. state_set(&child_ep->com, CONNECTING);
  2265. child_ep->com.dev = dev;
  2266. child_ep->com.cm_id = NULL;
  2267. if (iptype == 4) {
  2268. struct sockaddr_in *sin = (struct sockaddr_in *)
  2269. &child_ep->com.local_addr;
  2270. sin->sin_family = AF_INET;
  2271. sin->sin_port = local_port;
  2272. sin->sin_addr.s_addr = *(__be32 *)local_ip;
  2273. sin = (struct sockaddr_in *)&child_ep->com.local_addr;
  2274. sin->sin_family = AF_INET;
  2275. sin->sin_port = ((struct sockaddr_in *)
  2276. &parent_ep->com.local_addr)->sin_port;
  2277. sin->sin_addr.s_addr = *(__be32 *)local_ip;
  2278. sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
  2279. sin->sin_family = AF_INET;
  2280. sin->sin_port = peer_port;
  2281. sin->sin_addr.s_addr = *(__be32 *)peer_ip;
  2282. } else {
  2283. sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
  2284. sin6->sin6_family = PF_INET6;
  2285. sin6->sin6_port = local_port;
  2286. memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
  2287. sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
  2288. sin6->sin6_family = PF_INET6;
  2289. sin6->sin6_port = ((struct sockaddr_in6 *)
  2290. &parent_ep->com.local_addr)->sin6_port;
  2291. memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
  2292. sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
  2293. sin6->sin6_family = PF_INET6;
  2294. sin6->sin6_port = peer_port;
  2295. memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
  2296. }
  2297. c4iw_get_ep(&parent_ep->com);
  2298. child_ep->parent_ep = parent_ep;
  2299. child_ep->tos = tos;
  2300. child_ep->dst = dst;
  2301. child_ep->hwtid = hwtid;
  2302. pr_debug("tx_chan %u smac_idx %u rss_qid %u\n",
  2303. child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
  2304. timer_setup(&child_ep->timer, ep_timeout, 0);
  2305. cxgb4_insert_tid(t, child_ep, hwtid,
  2306. child_ep->com.local_addr.ss_family);
  2307. insert_ep_tid(child_ep);
  2308. if (accept_cr(child_ep, skb, req)) {
  2309. c4iw_put_ep(&parent_ep->com);
  2310. release_ep_resources(child_ep);
  2311. } else {
  2312. set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
  2313. }
  2314. if (iptype == 6) {
  2315. sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
  2316. cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
  2317. (const u32 *)&sin6->sin6_addr.s6_addr, 1);
  2318. }
  2319. goto out;
  2320. fail:
  2321. c4iw_put_ep(&child_ep->com);
  2322. reject:
  2323. reject_cr(dev, hwtid, skb);
  2324. out:
  2325. if (parent_ep)
  2326. c4iw_put_ep(&parent_ep->com);
  2327. return 0;
  2328. }
  2329. static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  2330. {
  2331. struct c4iw_ep *ep;
  2332. struct cpl_pass_establish *req = cplhdr(skb);
  2333. unsigned int tid = GET_TID(req);
  2334. int ret;
  2335. u16 tcp_opt = ntohs(req->tcp_opt);
  2336. ep = get_ep_from_tid(dev, tid);
  2337. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  2338. ep->snd_seq = be32_to_cpu(req->snd_isn);
  2339. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  2340. ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
  2341. pr_debug("ep %p hwtid %u tcp_opt 0x%02x\n", ep, tid, tcp_opt);
  2342. set_emss(ep, tcp_opt);
  2343. dst_confirm(ep->dst);
  2344. mutex_lock(&ep->com.mutex);
  2345. ep->com.state = MPA_REQ_WAIT;
  2346. start_ep_timer(ep);
  2347. set_bit(PASS_ESTAB, &ep->com.history);
  2348. ret = send_flowc(ep);
  2349. mutex_unlock(&ep->com.mutex);
  2350. if (ret)
  2351. c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
  2352. c4iw_put_ep(&ep->com);
  2353. return 0;
  2354. }
  2355. static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
  2356. {
  2357. struct cpl_peer_close *hdr = cplhdr(skb);
  2358. struct c4iw_ep *ep;
  2359. struct c4iw_qp_attributes attrs;
  2360. int disconnect = 1;
  2361. int release = 0;
  2362. unsigned int tid = GET_TID(hdr);
  2363. int ret;
  2364. ep = get_ep_from_tid(dev, tid);
  2365. if (!ep)
  2366. return 0;
  2367. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  2368. dst_confirm(ep->dst);
  2369. set_bit(PEER_CLOSE, &ep->com.history);
  2370. mutex_lock(&ep->com.mutex);
  2371. switch (ep->com.state) {
  2372. case MPA_REQ_WAIT:
  2373. __state_set(&ep->com, CLOSING);
  2374. break;
  2375. case MPA_REQ_SENT:
  2376. __state_set(&ep->com, CLOSING);
  2377. connect_reply_upcall(ep, -ECONNRESET);
  2378. break;
  2379. case MPA_REQ_RCVD:
  2380. /*
  2381. * We're gonna mark this puppy DEAD, but keep
  2382. * the reference on it until the ULP accepts or
  2383. * rejects the CR. Also wake up anyone waiting
  2384. * in rdma connection migration (see c4iw_accept_cr()).
  2385. */
  2386. __state_set(&ep->com, CLOSING);
  2387. pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
  2388. c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
  2389. break;
  2390. case MPA_REP_SENT:
  2391. __state_set(&ep->com, CLOSING);
  2392. pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
  2393. c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
  2394. break;
  2395. case FPDU_MODE:
  2396. start_ep_timer(ep);
  2397. __state_set(&ep->com, CLOSING);
  2398. attrs.next_state = C4IW_QP_STATE_CLOSING;
  2399. ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2400. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2401. if (ret != -ECONNRESET) {
  2402. peer_close_upcall(ep);
  2403. disconnect = 1;
  2404. }
  2405. break;
  2406. case ABORTING:
  2407. disconnect = 0;
  2408. break;
  2409. case CLOSING:
  2410. __state_set(&ep->com, MORIBUND);
  2411. disconnect = 0;
  2412. break;
  2413. case MORIBUND:
  2414. (void)stop_ep_timer(ep);
  2415. if (ep->com.cm_id && ep->com.qp) {
  2416. attrs.next_state = C4IW_QP_STATE_IDLE;
  2417. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2418. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2419. }
  2420. close_complete_upcall(ep, 0);
  2421. __state_set(&ep->com, DEAD);
  2422. release = 1;
  2423. disconnect = 0;
  2424. break;
  2425. case DEAD:
  2426. disconnect = 0;
  2427. break;
  2428. default:
  2429. WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
  2430. }
  2431. mutex_unlock(&ep->com.mutex);
  2432. if (disconnect)
  2433. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  2434. if (release)
  2435. release_ep_resources(ep);
  2436. c4iw_put_ep(&ep->com);
  2437. return 0;
  2438. }
  2439. static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
  2440. {
  2441. struct cpl_abort_req_rss6 *req = cplhdr(skb);
  2442. struct c4iw_ep *ep;
  2443. struct sk_buff *rpl_skb;
  2444. struct c4iw_qp_attributes attrs;
  2445. int ret;
  2446. int release = 0;
  2447. unsigned int tid = GET_TID(req);
  2448. u8 status;
  2449. u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
  2450. ep = get_ep_from_tid(dev, tid);
  2451. if (!ep)
  2452. return 0;
  2453. status = ABORT_RSS_STATUS_G(be32_to_cpu(req->srqidx_status));
  2454. if (cxgb_is_neg_adv(status)) {
  2455. pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
  2456. ep->hwtid, status, neg_adv_str(status));
  2457. ep->stats.abort_neg_adv++;
  2458. mutex_lock(&dev->rdev.stats.lock);
  2459. dev->rdev.stats.neg_adv++;
  2460. mutex_unlock(&dev->rdev.stats.lock);
  2461. goto deref_ep;
  2462. }
  2463. complete_cached_srq_buffers(ep, req->srqidx_status);
  2464. pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid,
  2465. ep->com.state);
  2466. set_bit(PEER_ABORT, &ep->com.history);
  2467. /*
  2468. * Wake up any threads in rdma_init() or rdma_fini().
  2469. * However, this is not needed if com state is just
  2470. * MPA_REQ_SENT
  2471. */
  2472. if (ep->com.state != MPA_REQ_SENT)
  2473. c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
  2474. mutex_lock(&ep->com.mutex);
  2475. switch (ep->com.state) {
  2476. case CONNECTING:
  2477. c4iw_put_ep(&ep->parent_ep->com);
  2478. break;
  2479. case MPA_REQ_WAIT:
  2480. (void)stop_ep_timer(ep);
  2481. break;
  2482. case MPA_REQ_SENT:
  2483. (void)stop_ep_timer(ep);
  2484. if (status != CPL_ERR_CONN_RESET || mpa_rev == 1 ||
  2485. (mpa_rev == 2 && ep->tried_with_mpa_v1))
  2486. connect_reply_upcall(ep, -ECONNRESET);
  2487. else {
  2488. /*
  2489. * we just don't send notification upwards because we
  2490. * want to retry with mpa_v1 without upper layers even
  2491. * knowing it.
  2492. *
  2493. * do some housekeeping so as to re-initiate the
  2494. * connection
  2495. */
  2496. pr_info("%s: mpa_rev=%d. Retrying with mpav1\n",
  2497. __func__, mpa_rev);
  2498. ep->retry_with_mpa_v1 = 1;
  2499. }
  2500. break;
  2501. case MPA_REP_SENT:
  2502. break;
  2503. case MPA_REQ_RCVD:
  2504. break;
  2505. case MORIBUND:
  2506. case CLOSING:
  2507. stop_ep_timer(ep);
  2508. /*FALLTHROUGH*/
  2509. case FPDU_MODE:
  2510. if (ep->com.cm_id && ep->com.qp) {
  2511. attrs.next_state = C4IW_QP_STATE_ERROR;
  2512. ret = c4iw_modify_qp(ep->com.qp->rhp,
  2513. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  2514. &attrs, 1);
  2515. if (ret)
  2516. pr_err("%s - qp <- error failed!\n", __func__);
  2517. }
  2518. peer_abort_upcall(ep);
  2519. break;
  2520. case ABORTING:
  2521. break;
  2522. case DEAD:
  2523. pr_warn("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  2524. mutex_unlock(&ep->com.mutex);
  2525. goto deref_ep;
  2526. default:
  2527. WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
  2528. break;
  2529. }
  2530. dst_confirm(ep->dst);
  2531. if (ep->com.state != ABORTING) {
  2532. __state_set(&ep->com, DEAD);
  2533. /* we don't release if we want to retry with mpa_v1 */
  2534. if (!ep->retry_with_mpa_v1)
  2535. release = 1;
  2536. }
  2537. mutex_unlock(&ep->com.mutex);
  2538. rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
  2539. if (WARN_ON(!rpl_skb)) {
  2540. release = 1;
  2541. goto out;
  2542. }
  2543. cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
  2544. c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
  2545. out:
  2546. if (release)
  2547. release_ep_resources(ep);
  2548. else if (ep->retry_with_mpa_v1) {
  2549. if (ep->com.remote_addr.ss_family == AF_INET6) {
  2550. struct sockaddr_in6 *sin6 =
  2551. (struct sockaddr_in6 *)
  2552. &ep->com.local_addr;
  2553. cxgb4_clip_release(
  2554. ep->com.dev->rdev.lldi.ports[0],
  2555. (const u32 *)&sin6->sin6_addr.s6_addr,
  2556. 1);
  2557. }
  2558. remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
  2559. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid,
  2560. ep->com.local_addr.ss_family);
  2561. dst_release(ep->dst);
  2562. cxgb4_l2t_release(ep->l2t);
  2563. c4iw_reconnect(ep);
  2564. }
  2565. deref_ep:
  2566. c4iw_put_ep(&ep->com);
  2567. /* Dereferencing ep, referenced in peer_abort_intr() */
  2568. c4iw_put_ep(&ep->com);
  2569. return 0;
  2570. }
  2571. static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2572. {
  2573. struct c4iw_ep *ep;
  2574. struct c4iw_qp_attributes attrs;
  2575. struct cpl_close_con_rpl *rpl = cplhdr(skb);
  2576. int release = 0;
  2577. unsigned int tid = GET_TID(rpl);
  2578. ep = get_ep_from_tid(dev, tid);
  2579. if (!ep)
  2580. return 0;
  2581. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  2582. /* The cm_id may be null if we failed to connect */
  2583. mutex_lock(&ep->com.mutex);
  2584. set_bit(CLOSE_CON_RPL, &ep->com.history);
  2585. switch (ep->com.state) {
  2586. case CLOSING:
  2587. __state_set(&ep->com, MORIBUND);
  2588. break;
  2589. case MORIBUND:
  2590. (void)stop_ep_timer(ep);
  2591. if ((ep->com.cm_id) && (ep->com.qp)) {
  2592. attrs.next_state = C4IW_QP_STATE_IDLE;
  2593. c4iw_modify_qp(ep->com.qp->rhp,
  2594. ep->com.qp,
  2595. C4IW_QP_ATTR_NEXT_STATE,
  2596. &attrs, 1);
  2597. }
  2598. close_complete_upcall(ep, 0);
  2599. __state_set(&ep->com, DEAD);
  2600. release = 1;
  2601. break;
  2602. case ABORTING:
  2603. case DEAD:
  2604. break;
  2605. default:
  2606. WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
  2607. break;
  2608. }
  2609. mutex_unlock(&ep->com.mutex);
  2610. if (release)
  2611. release_ep_resources(ep);
  2612. c4iw_put_ep(&ep->com);
  2613. return 0;
  2614. }
  2615. static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
  2616. {
  2617. struct cpl_rdma_terminate *rpl = cplhdr(skb);
  2618. unsigned int tid = GET_TID(rpl);
  2619. struct c4iw_ep *ep;
  2620. struct c4iw_qp_attributes attrs;
  2621. ep = get_ep_from_tid(dev, tid);
  2622. if (ep) {
  2623. if (ep->com.qp) {
  2624. pr_warn("TERM received tid %u qpid %u\n", tid,
  2625. ep->com.qp->wq.sq.qid);
  2626. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  2627. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2628. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2629. }
  2630. c4iw_put_ep(&ep->com);
  2631. } else
  2632. pr_warn("TERM received tid %u no ep/qp\n", tid);
  2633. return 0;
  2634. }
  2635. /*
  2636. * Upcall from the adapter indicating data has been transmitted.
  2637. * For us its just the single MPA request or reply. We can now free
  2638. * the skb holding the mpa message.
  2639. */
  2640. static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
  2641. {
  2642. struct c4iw_ep *ep;
  2643. struct cpl_fw4_ack *hdr = cplhdr(skb);
  2644. u8 credits = hdr->credits;
  2645. unsigned int tid = GET_TID(hdr);
  2646. ep = get_ep_from_tid(dev, tid);
  2647. if (!ep)
  2648. return 0;
  2649. pr_debug("ep %p tid %u credits %u\n",
  2650. ep, ep->hwtid, credits);
  2651. if (credits == 0) {
  2652. pr_debug("0 credit ack ep %p tid %u state %u\n",
  2653. ep, ep->hwtid, state_read(&ep->com));
  2654. goto out;
  2655. }
  2656. dst_confirm(ep->dst);
  2657. if (ep->mpa_skb) {
  2658. pr_debug("last streaming msg ack ep %p tid %u state %u initiator %u freeing skb\n",
  2659. ep, ep->hwtid, state_read(&ep->com),
  2660. ep->mpa_attr.initiator ? 1 : 0);
  2661. mutex_lock(&ep->com.mutex);
  2662. kfree_skb(ep->mpa_skb);
  2663. ep->mpa_skb = NULL;
  2664. if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
  2665. stop_ep_timer(ep);
  2666. mutex_unlock(&ep->com.mutex);
  2667. }
  2668. out:
  2669. c4iw_put_ep(&ep->com);
  2670. return 0;
  2671. }
  2672. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  2673. {
  2674. int abort;
  2675. struct c4iw_ep *ep = to_ep(cm_id);
  2676. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  2677. mutex_lock(&ep->com.mutex);
  2678. if (ep->com.state != MPA_REQ_RCVD) {
  2679. mutex_unlock(&ep->com.mutex);
  2680. c4iw_put_ep(&ep->com);
  2681. return -ECONNRESET;
  2682. }
  2683. set_bit(ULP_REJECT, &ep->com.history);
  2684. if (mpa_rev == 0)
  2685. abort = 1;
  2686. else
  2687. abort = send_mpa_reject(ep, pdata, pdata_len);
  2688. mutex_unlock(&ep->com.mutex);
  2689. stop_ep_timer(ep);
  2690. c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
  2691. c4iw_put_ep(&ep->com);
  2692. return 0;
  2693. }
  2694. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2695. {
  2696. int err;
  2697. struct c4iw_qp_attributes attrs;
  2698. enum c4iw_qp_attr_mask mask;
  2699. struct c4iw_ep *ep = to_ep(cm_id);
  2700. struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
  2701. struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
  2702. int abort = 0;
  2703. pr_debug("ep %p tid %u\n", ep, ep->hwtid);
  2704. mutex_lock(&ep->com.mutex);
  2705. if (ep->com.state != MPA_REQ_RCVD) {
  2706. err = -ECONNRESET;
  2707. goto err_out;
  2708. }
  2709. if (!qp) {
  2710. err = -EINVAL;
  2711. goto err_out;
  2712. }
  2713. set_bit(ULP_ACCEPT, &ep->com.history);
  2714. if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
  2715. (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
  2716. err = -EINVAL;
  2717. goto err_abort;
  2718. }
  2719. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  2720. if (conn_param->ord > ep->ird) {
  2721. if (RELAXED_IRD_NEGOTIATION) {
  2722. conn_param->ord = ep->ird;
  2723. } else {
  2724. ep->ird = conn_param->ird;
  2725. ep->ord = conn_param->ord;
  2726. send_mpa_reject(ep, conn_param->private_data,
  2727. conn_param->private_data_len);
  2728. err = -ENOMEM;
  2729. goto err_abort;
  2730. }
  2731. }
  2732. if (conn_param->ird < ep->ord) {
  2733. if (RELAXED_IRD_NEGOTIATION &&
  2734. ep->ord <= h->rdev.lldi.max_ordird_qp) {
  2735. conn_param->ird = ep->ord;
  2736. } else {
  2737. err = -ENOMEM;
  2738. goto err_abort;
  2739. }
  2740. }
  2741. }
  2742. ep->ird = conn_param->ird;
  2743. ep->ord = conn_param->ord;
  2744. if (ep->mpa_attr.version == 1) {
  2745. if (peer2peer && ep->ird == 0)
  2746. ep->ird = 1;
  2747. } else {
  2748. if (peer2peer &&
  2749. (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
  2750. (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
  2751. ep->ird = 1;
  2752. }
  2753. pr_debug("ird %d ord %d\n", ep->ird, ep->ord);
  2754. ep->com.cm_id = cm_id;
  2755. ref_cm_id(&ep->com);
  2756. ep->com.qp = qp;
  2757. ref_qp(ep);
  2758. /* bind QP to EP and move to RTS */
  2759. attrs.mpa_attr = ep->mpa_attr;
  2760. attrs.max_ird = ep->ird;
  2761. attrs.max_ord = ep->ord;
  2762. attrs.llp_stream_handle = ep;
  2763. attrs.next_state = C4IW_QP_STATE_RTS;
  2764. /* bind QP and TID with INIT_WR */
  2765. mask = C4IW_QP_ATTR_NEXT_STATE |
  2766. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  2767. C4IW_QP_ATTR_MPA_ATTR |
  2768. C4IW_QP_ATTR_MAX_IRD |
  2769. C4IW_QP_ATTR_MAX_ORD;
  2770. err = c4iw_modify_qp(ep->com.qp->rhp,
  2771. ep->com.qp, mask, &attrs, 1);
  2772. if (err)
  2773. goto err_deref_cm_id;
  2774. set_bit(STOP_MPA_TIMER, &ep->com.flags);
  2775. err = send_mpa_reply(ep, conn_param->private_data,
  2776. conn_param->private_data_len);
  2777. if (err)
  2778. goto err_deref_cm_id;
  2779. __state_set(&ep->com, FPDU_MODE);
  2780. established_upcall(ep);
  2781. mutex_unlock(&ep->com.mutex);
  2782. c4iw_put_ep(&ep->com);
  2783. return 0;
  2784. err_deref_cm_id:
  2785. deref_cm_id(&ep->com);
  2786. err_abort:
  2787. abort = 1;
  2788. err_out:
  2789. mutex_unlock(&ep->com.mutex);
  2790. if (abort)
  2791. c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
  2792. c4iw_put_ep(&ep->com);
  2793. return err;
  2794. }
  2795. static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
  2796. {
  2797. struct in_device *ind;
  2798. int found = 0;
  2799. struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
  2800. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
  2801. ind = in_dev_get(dev->rdev.lldi.ports[0]);
  2802. if (!ind)
  2803. return -EADDRNOTAVAIL;
  2804. for_primary_ifa(ind) {
  2805. laddr->sin_addr.s_addr = ifa->ifa_address;
  2806. raddr->sin_addr.s_addr = ifa->ifa_address;
  2807. found = 1;
  2808. break;
  2809. }
  2810. endfor_ifa(ind);
  2811. in_dev_put(ind);
  2812. return found ? 0 : -EADDRNOTAVAIL;
  2813. }
  2814. static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
  2815. unsigned char banned_flags)
  2816. {
  2817. struct inet6_dev *idev;
  2818. int err = -EADDRNOTAVAIL;
  2819. rcu_read_lock();
  2820. idev = __in6_dev_get(dev);
  2821. if (idev != NULL) {
  2822. struct inet6_ifaddr *ifp;
  2823. read_lock_bh(&idev->lock);
  2824. list_for_each_entry(ifp, &idev->addr_list, if_list) {
  2825. if (ifp->scope == IFA_LINK &&
  2826. !(ifp->flags & banned_flags)) {
  2827. memcpy(addr, &ifp->addr, 16);
  2828. err = 0;
  2829. break;
  2830. }
  2831. }
  2832. read_unlock_bh(&idev->lock);
  2833. }
  2834. rcu_read_unlock();
  2835. return err;
  2836. }
  2837. static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
  2838. {
  2839. struct in6_addr uninitialized_var(addr);
  2840. struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
  2841. struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
  2842. if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
  2843. memcpy(la6->sin6_addr.s6_addr, &addr, 16);
  2844. memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
  2845. return 0;
  2846. }
  2847. return -EADDRNOTAVAIL;
  2848. }
  2849. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2850. {
  2851. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2852. struct c4iw_ep *ep;
  2853. int err = 0;
  2854. struct sockaddr_in *laddr;
  2855. struct sockaddr_in *raddr;
  2856. struct sockaddr_in6 *laddr6;
  2857. struct sockaddr_in6 *raddr6;
  2858. __u8 *ra;
  2859. int iptype;
  2860. if ((conn_param->ord > cur_max_read_depth(dev)) ||
  2861. (conn_param->ird > cur_max_read_depth(dev))) {
  2862. err = -EINVAL;
  2863. goto out;
  2864. }
  2865. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2866. if (!ep) {
  2867. pr_err("%s - cannot alloc ep\n", __func__);
  2868. err = -ENOMEM;
  2869. goto out;
  2870. }
  2871. skb_queue_head_init(&ep->com.ep_skb_list);
  2872. if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
  2873. err = -ENOMEM;
  2874. goto fail1;
  2875. }
  2876. timer_setup(&ep->timer, ep_timeout, 0);
  2877. ep->plen = conn_param->private_data_len;
  2878. if (ep->plen)
  2879. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  2880. conn_param->private_data, ep->plen);
  2881. ep->ird = conn_param->ird;
  2882. ep->ord = conn_param->ord;
  2883. if (peer2peer && ep->ord == 0)
  2884. ep->ord = 1;
  2885. ep->com.cm_id = cm_id;
  2886. ref_cm_id(&ep->com);
  2887. cm_id->provider_data = ep;
  2888. ep->com.dev = dev;
  2889. ep->com.qp = get_qhp(dev, conn_param->qpn);
  2890. if (!ep->com.qp) {
  2891. pr_warn("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
  2892. err = -EINVAL;
  2893. goto fail2;
  2894. }
  2895. ref_qp(ep);
  2896. pr_debug("qpn 0x%x qp %p cm_id %p\n", conn_param->qpn,
  2897. ep->com.qp, cm_id);
  2898. /*
  2899. * Allocate an active TID to initiate a TCP connection.
  2900. */
  2901. ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
  2902. if (ep->atid == -1) {
  2903. pr_err("%s - cannot alloc atid\n", __func__);
  2904. err = -ENOMEM;
  2905. goto fail2;
  2906. }
  2907. insert_handle(dev, &dev->atid_idr, ep, ep->atid);
  2908. memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
  2909. sizeof(ep->com.local_addr));
  2910. memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
  2911. sizeof(ep->com.remote_addr));
  2912. laddr = (struct sockaddr_in *)&ep->com.local_addr;
  2913. raddr = (struct sockaddr_in *)&ep->com.remote_addr;
  2914. laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  2915. raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
  2916. if (cm_id->m_remote_addr.ss_family == AF_INET) {
  2917. iptype = 4;
  2918. ra = (__u8 *)&raddr->sin_addr;
  2919. /*
  2920. * Handle loopback requests to INADDR_ANY.
  2921. */
  2922. if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
  2923. err = pick_local_ipaddrs(dev, cm_id);
  2924. if (err)
  2925. goto fail2;
  2926. }
  2927. /* find a route */
  2928. pr_debug("saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
  2929. &laddr->sin_addr, ntohs(laddr->sin_port),
  2930. ra, ntohs(raddr->sin_port));
  2931. ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
  2932. laddr->sin_addr.s_addr,
  2933. raddr->sin_addr.s_addr,
  2934. laddr->sin_port,
  2935. raddr->sin_port, cm_id->tos);
  2936. } else {
  2937. iptype = 6;
  2938. ra = (__u8 *)&raddr6->sin6_addr;
  2939. /*
  2940. * Handle loopback requests to INADDR_ANY.
  2941. */
  2942. if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
  2943. err = pick_local_ip6addrs(dev, cm_id);
  2944. if (err)
  2945. goto fail2;
  2946. }
  2947. /* find a route */
  2948. pr_debug("saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
  2949. laddr6->sin6_addr.s6_addr,
  2950. ntohs(laddr6->sin6_port),
  2951. raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
  2952. ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
  2953. laddr6->sin6_addr.s6_addr,
  2954. raddr6->sin6_addr.s6_addr,
  2955. laddr6->sin6_port,
  2956. raddr6->sin6_port, cm_id->tos,
  2957. raddr6->sin6_scope_id);
  2958. }
  2959. if (!ep->dst) {
  2960. pr_err("%s - cannot find route\n", __func__);
  2961. err = -EHOSTUNREACH;
  2962. goto fail3;
  2963. }
  2964. err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
  2965. ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
  2966. if (err) {
  2967. pr_err("%s - cannot alloc l2e\n", __func__);
  2968. goto fail4;
  2969. }
  2970. pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  2971. ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  2972. ep->l2t->idx);
  2973. state_set(&ep->com, CONNECTING);
  2974. ep->tos = cm_id->tos;
  2975. /* send connect request to rnic */
  2976. err = send_connect(ep);
  2977. if (!err)
  2978. goto out;
  2979. cxgb4_l2t_release(ep->l2t);
  2980. fail4:
  2981. dst_release(ep->dst);
  2982. fail3:
  2983. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  2984. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  2985. fail2:
  2986. skb_queue_purge(&ep->com.ep_skb_list);
  2987. deref_cm_id(&ep->com);
  2988. fail1:
  2989. c4iw_put_ep(&ep->com);
  2990. out:
  2991. return err;
  2992. }
  2993. static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
  2994. {
  2995. int err;
  2996. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
  2997. &ep->com.local_addr;
  2998. if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
  2999. err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
  3000. (const u32 *)&sin6->sin6_addr.s6_addr, 1);
  3001. if (err)
  3002. return err;
  3003. }
  3004. c4iw_init_wr_wait(ep->com.wr_waitp);
  3005. err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
  3006. ep->stid, &sin6->sin6_addr,
  3007. sin6->sin6_port,
  3008. ep->com.dev->rdev.lldi.rxq_ids[0]);
  3009. if (!err)
  3010. err = c4iw_wait_for_reply(&ep->com.dev->rdev,
  3011. ep->com.wr_waitp,
  3012. 0, 0, __func__);
  3013. else if (err > 0)
  3014. err = net_xmit_errno(err);
  3015. if (err) {
  3016. cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
  3017. (const u32 *)&sin6->sin6_addr.s6_addr, 1);
  3018. pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
  3019. err, ep->stid,
  3020. sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
  3021. }
  3022. return err;
  3023. }
  3024. static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
  3025. {
  3026. int err;
  3027. struct sockaddr_in *sin = (struct sockaddr_in *)
  3028. &ep->com.local_addr;
  3029. if (dev->rdev.lldi.enable_fw_ofld_conn) {
  3030. do {
  3031. err = cxgb4_create_server_filter(
  3032. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  3033. sin->sin_addr.s_addr, sin->sin_port, 0,
  3034. ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
  3035. if (err == -EBUSY) {
  3036. if (c4iw_fatal_error(&ep->com.dev->rdev)) {
  3037. err = -EIO;
  3038. break;
  3039. }
  3040. set_current_state(TASK_UNINTERRUPTIBLE);
  3041. schedule_timeout(usecs_to_jiffies(100));
  3042. }
  3043. } while (err == -EBUSY);
  3044. } else {
  3045. c4iw_init_wr_wait(ep->com.wr_waitp);
  3046. err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
  3047. ep->stid, sin->sin_addr.s_addr, sin->sin_port,
  3048. 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
  3049. if (!err)
  3050. err = c4iw_wait_for_reply(&ep->com.dev->rdev,
  3051. ep->com.wr_waitp,
  3052. 0, 0, __func__);
  3053. else if (err > 0)
  3054. err = net_xmit_errno(err);
  3055. }
  3056. if (err)
  3057. pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
  3058. , err, ep->stid,
  3059. &sin->sin_addr, ntohs(sin->sin_port));
  3060. return err;
  3061. }
  3062. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
  3063. {
  3064. int err = 0;
  3065. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  3066. struct c4iw_listen_ep *ep;
  3067. might_sleep();
  3068. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  3069. if (!ep) {
  3070. pr_err("%s - cannot alloc ep\n", __func__);
  3071. err = -ENOMEM;
  3072. goto fail1;
  3073. }
  3074. skb_queue_head_init(&ep->com.ep_skb_list);
  3075. pr_debug("ep %p\n", ep);
  3076. ep->com.cm_id = cm_id;
  3077. ref_cm_id(&ep->com);
  3078. ep->com.dev = dev;
  3079. ep->backlog = backlog;
  3080. memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
  3081. sizeof(ep->com.local_addr));
  3082. /*
  3083. * Allocate a server TID.
  3084. */
  3085. if (dev->rdev.lldi.enable_fw_ofld_conn &&
  3086. ep->com.local_addr.ss_family == AF_INET)
  3087. ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
  3088. cm_id->m_local_addr.ss_family, ep);
  3089. else
  3090. ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
  3091. cm_id->m_local_addr.ss_family, ep);
  3092. if (ep->stid == -1) {
  3093. pr_err("%s - cannot alloc stid\n", __func__);
  3094. err = -ENOMEM;
  3095. goto fail2;
  3096. }
  3097. insert_handle(dev, &dev->stid_idr, ep, ep->stid);
  3098. state_set(&ep->com, LISTEN);
  3099. if (ep->com.local_addr.ss_family == AF_INET)
  3100. err = create_server4(dev, ep);
  3101. else
  3102. err = create_server6(dev, ep);
  3103. if (!err) {
  3104. cm_id->provider_data = ep;
  3105. goto out;
  3106. }
  3107. remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
  3108. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
  3109. ep->com.local_addr.ss_family);
  3110. fail2:
  3111. deref_cm_id(&ep->com);
  3112. c4iw_put_ep(&ep->com);
  3113. fail1:
  3114. out:
  3115. return err;
  3116. }
  3117. int c4iw_destroy_listen(struct iw_cm_id *cm_id)
  3118. {
  3119. int err;
  3120. struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
  3121. pr_debug("ep %p\n", ep);
  3122. might_sleep();
  3123. state_set(&ep->com, DEAD);
  3124. if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
  3125. ep->com.local_addr.ss_family == AF_INET) {
  3126. err = cxgb4_remove_server_filter(
  3127. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  3128. ep->com.dev->rdev.lldi.rxq_ids[0], 0);
  3129. } else {
  3130. struct sockaddr_in6 *sin6;
  3131. c4iw_init_wr_wait(ep->com.wr_waitp);
  3132. err = cxgb4_remove_server(
  3133. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  3134. ep->com.dev->rdev.lldi.rxq_ids[0], 0);
  3135. if (err)
  3136. goto done;
  3137. err = c4iw_wait_for_reply(&ep->com.dev->rdev, ep->com.wr_waitp,
  3138. 0, 0, __func__);
  3139. sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  3140. cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
  3141. (const u32 *)&sin6->sin6_addr.s6_addr, 1);
  3142. }
  3143. remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
  3144. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
  3145. ep->com.local_addr.ss_family);
  3146. done:
  3147. deref_cm_id(&ep->com);
  3148. c4iw_put_ep(&ep->com);
  3149. return err;
  3150. }
  3151. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
  3152. {
  3153. int ret = 0;
  3154. int close = 0;
  3155. int fatal = 0;
  3156. struct c4iw_rdev *rdev;
  3157. mutex_lock(&ep->com.mutex);
  3158. pr_debug("ep %p state %s, abrupt %d\n", ep,
  3159. states[ep->com.state], abrupt);
  3160. /*
  3161. * Ref the ep here in case we have fatal errors causing the
  3162. * ep to be released and freed.
  3163. */
  3164. c4iw_get_ep(&ep->com);
  3165. rdev = &ep->com.dev->rdev;
  3166. if (c4iw_fatal_error(rdev)) {
  3167. fatal = 1;
  3168. close_complete_upcall(ep, -EIO);
  3169. ep->com.state = DEAD;
  3170. }
  3171. switch (ep->com.state) {
  3172. case MPA_REQ_WAIT:
  3173. case MPA_REQ_SENT:
  3174. case MPA_REQ_RCVD:
  3175. case MPA_REP_SENT:
  3176. case FPDU_MODE:
  3177. case CONNECTING:
  3178. close = 1;
  3179. if (abrupt)
  3180. ep->com.state = ABORTING;
  3181. else {
  3182. ep->com.state = CLOSING;
  3183. /*
  3184. * if we close before we see the fw4_ack() then we fix
  3185. * up the timer state since we're reusing it.
  3186. */
  3187. if (ep->mpa_skb &&
  3188. test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
  3189. clear_bit(STOP_MPA_TIMER, &ep->com.flags);
  3190. stop_ep_timer(ep);
  3191. }
  3192. start_ep_timer(ep);
  3193. }
  3194. set_bit(CLOSE_SENT, &ep->com.flags);
  3195. break;
  3196. case CLOSING:
  3197. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  3198. close = 1;
  3199. if (abrupt) {
  3200. (void)stop_ep_timer(ep);
  3201. ep->com.state = ABORTING;
  3202. } else
  3203. ep->com.state = MORIBUND;
  3204. }
  3205. break;
  3206. case MORIBUND:
  3207. case ABORTING:
  3208. case DEAD:
  3209. pr_debug("ignoring disconnect ep %p state %u\n",
  3210. ep, ep->com.state);
  3211. break;
  3212. default:
  3213. WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
  3214. break;
  3215. }
  3216. if (close) {
  3217. if (abrupt) {
  3218. set_bit(EP_DISC_ABORT, &ep->com.history);
  3219. ret = send_abort(ep);
  3220. } else {
  3221. set_bit(EP_DISC_CLOSE, &ep->com.history);
  3222. ret = send_halfclose(ep);
  3223. }
  3224. if (ret) {
  3225. set_bit(EP_DISC_FAIL, &ep->com.history);
  3226. if (!abrupt) {
  3227. stop_ep_timer(ep);
  3228. close_complete_upcall(ep, -EIO);
  3229. }
  3230. if (ep->com.qp) {
  3231. struct c4iw_qp_attributes attrs;
  3232. attrs.next_state = C4IW_QP_STATE_ERROR;
  3233. ret = c4iw_modify_qp(ep->com.qp->rhp,
  3234. ep->com.qp,
  3235. C4IW_QP_ATTR_NEXT_STATE,
  3236. &attrs, 1);
  3237. if (ret)
  3238. pr_err("%s - qp <- error failed!\n",
  3239. __func__);
  3240. }
  3241. fatal = 1;
  3242. }
  3243. }
  3244. mutex_unlock(&ep->com.mutex);
  3245. c4iw_put_ep(&ep->com);
  3246. if (fatal)
  3247. release_ep_resources(ep);
  3248. return ret;
  3249. }
  3250. static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  3251. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  3252. {
  3253. struct c4iw_ep *ep;
  3254. int atid = be32_to_cpu(req->tid);
  3255. ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
  3256. (__force u32) req->tid);
  3257. if (!ep)
  3258. return;
  3259. switch (req->retval) {
  3260. case FW_ENOMEM:
  3261. set_bit(ACT_RETRY_NOMEM, &ep->com.history);
  3262. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  3263. send_fw_act_open_req(ep, atid);
  3264. return;
  3265. }
  3266. /* fall through */
  3267. case FW_EADDRINUSE:
  3268. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  3269. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  3270. send_fw_act_open_req(ep, atid);
  3271. return;
  3272. }
  3273. break;
  3274. default:
  3275. pr_info("%s unexpected ofld conn wr retval %d\n",
  3276. __func__, req->retval);
  3277. break;
  3278. }
  3279. pr_err("active ofld_connect_wr failure %d atid %d\n",
  3280. req->retval, atid);
  3281. mutex_lock(&dev->rdev.stats.lock);
  3282. dev->rdev.stats.act_ofld_conn_fails++;
  3283. mutex_unlock(&dev->rdev.stats.lock);
  3284. connect_reply_upcall(ep, status2errno(req->retval));
  3285. state_set(&ep->com, DEAD);
  3286. if (ep->com.remote_addr.ss_family == AF_INET6) {
  3287. struct sockaddr_in6 *sin6 =
  3288. (struct sockaddr_in6 *)&ep->com.local_addr;
  3289. cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
  3290. (const u32 *)&sin6->sin6_addr.s6_addr, 1);
  3291. }
  3292. remove_handle(dev, &dev->atid_idr, atid);
  3293. cxgb4_free_atid(dev->rdev.lldi.tids, atid);
  3294. dst_release(ep->dst);
  3295. cxgb4_l2t_release(ep->l2t);
  3296. c4iw_put_ep(&ep->com);
  3297. }
  3298. static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  3299. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  3300. {
  3301. struct sk_buff *rpl_skb;
  3302. struct cpl_pass_accept_req *cpl;
  3303. int ret;
  3304. rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
  3305. if (req->retval) {
  3306. pr_err("%s passive open failure %d\n", __func__, req->retval);
  3307. mutex_lock(&dev->rdev.stats.lock);
  3308. dev->rdev.stats.pas_ofld_conn_fails++;
  3309. mutex_unlock(&dev->rdev.stats.lock);
  3310. kfree_skb(rpl_skb);
  3311. } else {
  3312. cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
  3313. OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
  3314. (__force u32) htonl(
  3315. (__force u32) req->tid)));
  3316. ret = pass_accept_req(dev, rpl_skb);
  3317. if (!ret)
  3318. kfree_skb(rpl_skb);
  3319. }
  3320. return;
  3321. }
  3322. static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  3323. {
  3324. struct cpl_fw6_msg *rpl = cplhdr(skb);
  3325. struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
  3326. switch (rpl->type) {
  3327. case FW6_TYPE_CQE:
  3328. c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
  3329. break;
  3330. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  3331. req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
  3332. switch (req->t_state) {
  3333. case TCP_SYN_SENT:
  3334. active_ofld_conn_reply(dev, skb, req);
  3335. break;
  3336. case TCP_SYN_RECV:
  3337. passive_ofld_conn_reply(dev, skb, req);
  3338. break;
  3339. default:
  3340. pr_err("%s unexpected ofld conn wr state %d\n",
  3341. __func__, req->t_state);
  3342. break;
  3343. }
  3344. break;
  3345. }
  3346. return 0;
  3347. }
  3348. static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
  3349. {
  3350. __be32 l2info;
  3351. __be16 hdr_len, vlantag, len;
  3352. u16 eth_hdr_len;
  3353. int tcp_hdr_len, ip_hdr_len;
  3354. u8 intf;
  3355. struct cpl_rx_pkt *cpl = cplhdr(skb);
  3356. struct cpl_pass_accept_req *req;
  3357. struct tcp_options_received tmp_opt;
  3358. struct c4iw_dev *dev;
  3359. enum chip_type type;
  3360. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  3361. /* Store values from cpl_rx_pkt in temporary location. */
  3362. vlantag = cpl->vlan;
  3363. len = cpl->len;
  3364. l2info = cpl->l2info;
  3365. hdr_len = cpl->hdr_len;
  3366. intf = cpl->iff;
  3367. __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
  3368. /*
  3369. * We need to parse the TCP options from SYN packet.
  3370. * to generate cpl_pass_accept_req.
  3371. */
  3372. memset(&tmp_opt, 0, sizeof(tmp_opt));
  3373. tcp_clear_options(&tmp_opt);
  3374. tcp_parse_options(&init_net, skb, &tmp_opt, 0, NULL);
  3375. req = __skb_push(skb, sizeof(*req));
  3376. memset(req, 0, sizeof(*req));
  3377. req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
  3378. SYN_MAC_IDX_V(RX_MACIDX_G(
  3379. be32_to_cpu(l2info))) |
  3380. SYN_XACT_MATCH_F);
  3381. type = dev->rdev.lldi.adapter_type;
  3382. tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
  3383. ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
  3384. req->hdr_len =
  3385. cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
  3386. if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
  3387. eth_hdr_len = is_t4(type) ?
  3388. RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
  3389. RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
  3390. req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
  3391. IP_HDR_LEN_V(ip_hdr_len) |
  3392. ETH_HDR_LEN_V(eth_hdr_len));
  3393. } else { /* T6 and later */
  3394. eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
  3395. req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
  3396. T6_IP_HDR_LEN_V(ip_hdr_len) |
  3397. T6_ETH_HDR_LEN_V(eth_hdr_len));
  3398. }
  3399. req->vlan = vlantag;
  3400. req->len = len;
  3401. req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
  3402. PASS_OPEN_TOS_V(tos));
  3403. req->tcpopt.mss = htons(tmp_opt.mss_clamp);
  3404. if (tmp_opt.wscale_ok)
  3405. req->tcpopt.wsf = tmp_opt.snd_wscale;
  3406. req->tcpopt.tstamp = tmp_opt.saw_tstamp;
  3407. if (tmp_opt.sack_ok)
  3408. req->tcpopt.sack = 1;
  3409. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
  3410. return;
  3411. }
  3412. static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
  3413. __be32 laddr, __be16 lport,
  3414. __be32 raddr, __be16 rport,
  3415. u32 rcv_isn, u32 filter, u16 window,
  3416. u32 rss_qid, u8 port_id)
  3417. {
  3418. struct sk_buff *req_skb;
  3419. struct fw_ofld_connection_wr *req;
  3420. struct cpl_pass_accept_req *cpl = cplhdr(skb);
  3421. int ret;
  3422. req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
  3423. if (!req_skb)
  3424. return;
  3425. req = __skb_put_zero(req_skb, sizeof(*req));
  3426. req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
  3427. req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
  3428. req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
  3429. req->le.filter = (__force __be32) filter;
  3430. req->le.lport = lport;
  3431. req->le.pport = rport;
  3432. req->le.u.ipv4.lip = laddr;
  3433. req->le.u.ipv4.pip = raddr;
  3434. req->tcb.rcv_nxt = htonl(rcv_isn + 1);
  3435. req->tcb.rcv_adv = htons(window);
  3436. req->tcb.t_state_to_astid =
  3437. htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
  3438. FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
  3439. FW_OFLD_CONNECTION_WR_ASTID_V(
  3440. PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
  3441. /*
  3442. * We store the qid in opt2 which will be used by the firmware
  3443. * to send us the wr response.
  3444. */
  3445. req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
  3446. /*
  3447. * We initialize the MSS index in TCB to 0xF.
  3448. * So that when driver sends cpl_pass_accept_rpl
  3449. * TCB picks up the correct value. If this was 0
  3450. * TP will ignore any value > 0 for MSS index.
  3451. */
  3452. req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
  3453. req->cookie = (uintptr_t)skb;
  3454. set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
  3455. ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
  3456. if (ret < 0) {
  3457. pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
  3458. ret);
  3459. kfree_skb(skb);
  3460. kfree_skb(req_skb);
  3461. }
  3462. }
  3463. /*
  3464. * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
  3465. * messages when a filter is being used instead of server to
  3466. * redirect a syn packet. When packets hit filter they are redirected
  3467. * to the offload queue and driver tries to establish the connection
  3468. * using firmware work request.
  3469. */
  3470. static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
  3471. {
  3472. int stid;
  3473. unsigned int filter;
  3474. struct ethhdr *eh = NULL;
  3475. struct vlan_ethhdr *vlan_eh = NULL;
  3476. struct iphdr *iph;
  3477. struct tcphdr *tcph;
  3478. struct rss_header *rss = (void *)skb->data;
  3479. struct cpl_rx_pkt *cpl = (void *)skb->data;
  3480. struct cpl_pass_accept_req *req = (void *)(rss + 1);
  3481. struct l2t_entry *e;
  3482. struct dst_entry *dst;
  3483. struct c4iw_ep *lep = NULL;
  3484. u16 window;
  3485. struct port_info *pi;
  3486. struct net_device *pdev;
  3487. u16 rss_qid, eth_hdr_len;
  3488. int step;
  3489. struct neighbour *neigh;
  3490. /* Drop all non-SYN packets */
  3491. if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
  3492. goto reject;
  3493. /*
  3494. * Drop all packets which did not hit the filter.
  3495. * Unlikely to happen.
  3496. */
  3497. if (!(rss->filter_hit && rss->filter_tid))
  3498. goto reject;
  3499. /*
  3500. * Calculate the server tid from filter hit index from cpl_rx_pkt.
  3501. */
  3502. stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
  3503. lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
  3504. if (!lep) {
  3505. pr_warn("%s connect request on invalid stid %d\n",
  3506. __func__, stid);
  3507. goto reject;
  3508. }
  3509. switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
  3510. case CHELSIO_T4:
  3511. eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
  3512. break;
  3513. case CHELSIO_T5:
  3514. eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
  3515. break;
  3516. case CHELSIO_T6:
  3517. eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
  3518. break;
  3519. default:
  3520. pr_err("T%d Chip is not supported\n",
  3521. CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
  3522. goto reject;
  3523. }
  3524. if (eth_hdr_len == ETH_HLEN) {
  3525. eh = (struct ethhdr *)(req + 1);
  3526. iph = (struct iphdr *)(eh + 1);
  3527. } else {
  3528. vlan_eh = (struct vlan_ethhdr *)(req + 1);
  3529. iph = (struct iphdr *)(vlan_eh + 1);
  3530. skb->vlan_tci = ntohs(cpl->vlan);
  3531. }
  3532. if (iph->version != 0x4)
  3533. goto reject;
  3534. tcph = (struct tcphdr *)(iph + 1);
  3535. skb_set_network_header(skb, (void *)iph - (void *)rss);
  3536. skb_set_transport_header(skb, (void *)tcph - (void *)rss);
  3537. skb_get(skb);
  3538. pr_debug("lip 0x%x lport %u pip 0x%x pport %u tos %d\n",
  3539. ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
  3540. ntohs(tcph->source), iph->tos);
  3541. dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
  3542. iph->daddr, iph->saddr, tcph->dest,
  3543. tcph->source, iph->tos);
  3544. if (!dst) {
  3545. pr_err("%s - failed to find dst entry!\n", __func__);
  3546. goto reject;
  3547. }
  3548. neigh = dst_neigh_lookup_skb(dst, skb);
  3549. if (!neigh) {
  3550. pr_err("%s - failed to allocate neigh!\n", __func__);
  3551. goto free_dst;
  3552. }
  3553. if (neigh->dev->flags & IFF_LOOPBACK) {
  3554. pdev = ip_dev_find(&init_net, iph->daddr);
  3555. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  3556. pdev, 0);
  3557. pi = (struct port_info *)netdev_priv(pdev);
  3558. dev_put(pdev);
  3559. } else {
  3560. pdev = get_real_dev(neigh->dev);
  3561. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  3562. pdev, 0);
  3563. pi = (struct port_info *)netdev_priv(pdev);
  3564. }
  3565. neigh_release(neigh);
  3566. if (!e) {
  3567. pr_err("%s - failed to allocate l2t entry!\n",
  3568. __func__);
  3569. goto free_dst;
  3570. }
  3571. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  3572. rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
  3573. window = (__force u16) htons((__force u16)tcph->window);
  3574. /* Calcuate filter portion for LE region. */
  3575. filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
  3576. dev->rdev.lldi.ports[0],
  3577. e));
  3578. /*
  3579. * Synthesize the cpl_pass_accept_req. We have everything except the
  3580. * TID. Once firmware sends a reply with TID we update the TID field
  3581. * in cpl and pass it through the regular cpl_pass_accept_req path.
  3582. */
  3583. build_cpl_pass_accept_req(skb, stid, iph->tos);
  3584. send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
  3585. tcph->source, ntohl(tcph->seq), filter, window,
  3586. rss_qid, pi->port_id);
  3587. cxgb4_l2t_release(e);
  3588. free_dst:
  3589. dst_release(dst);
  3590. reject:
  3591. if (lep)
  3592. c4iw_put_ep(&lep->com);
  3593. return 0;
  3594. }
  3595. /*
  3596. * These are the real handlers that are called from a
  3597. * work queue.
  3598. */
  3599. static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
  3600. [CPL_ACT_ESTABLISH] = act_establish,
  3601. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  3602. [CPL_RX_DATA] = rx_data,
  3603. [CPL_ABORT_RPL_RSS] = abort_rpl,
  3604. [CPL_ABORT_RPL] = abort_rpl,
  3605. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  3606. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  3607. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  3608. [CPL_PASS_ESTABLISH] = pass_establish,
  3609. [CPL_PEER_CLOSE] = peer_close,
  3610. [CPL_ABORT_REQ_RSS] = peer_abort,
  3611. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  3612. [CPL_RDMA_TERMINATE] = terminate,
  3613. [CPL_FW4_ACK] = fw4_ack,
  3614. [CPL_FW6_MSG] = deferred_fw6_msg,
  3615. [CPL_RX_PKT] = rx_pkt,
  3616. [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
  3617. [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
  3618. };
  3619. static void process_timeout(struct c4iw_ep *ep)
  3620. {
  3621. struct c4iw_qp_attributes attrs;
  3622. int abort = 1;
  3623. mutex_lock(&ep->com.mutex);
  3624. pr_debug("ep %p tid %u state %d\n", ep, ep->hwtid, ep->com.state);
  3625. set_bit(TIMEDOUT, &ep->com.history);
  3626. switch (ep->com.state) {
  3627. case MPA_REQ_SENT:
  3628. connect_reply_upcall(ep, -ETIMEDOUT);
  3629. break;
  3630. case MPA_REQ_WAIT:
  3631. case MPA_REQ_RCVD:
  3632. case MPA_REP_SENT:
  3633. case FPDU_MODE:
  3634. break;
  3635. case CLOSING:
  3636. case MORIBUND:
  3637. if (ep->com.cm_id && ep->com.qp) {
  3638. attrs.next_state = C4IW_QP_STATE_ERROR;
  3639. c4iw_modify_qp(ep->com.qp->rhp,
  3640. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  3641. &attrs, 1);
  3642. }
  3643. close_complete_upcall(ep, -ETIMEDOUT);
  3644. break;
  3645. case ABORTING:
  3646. case DEAD:
  3647. /*
  3648. * These states are expected if the ep timed out at the same
  3649. * time as another thread was calling stop_ep_timer().
  3650. * So we silently do nothing for these states.
  3651. */
  3652. abort = 0;
  3653. break;
  3654. default:
  3655. WARN(1, "%s unexpected state ep %p tid %u state %u\n",
  3656. __func__, ep, ep->hwtid, ep->com.state);
  3657. abort = 0;
  3658. }
  3659. mutex_unlock(&ep->com.mutex);
  3660. if (abort)
  3661. c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
  3662. c4iw_put_ep(&ep->com);
  3663. }
  3664. static void process_timedout_eps(void)
  3665. {
  3666. struct c4iw_ep *ep;
  3667. spin_lock_irq(&timeout_lock);
  3668. while (!list_empty(&timeout_list)) {
  3669. struct list_head *tmp;
  3670. tmp = timeout_list.next;
  3671. list_del(tmp);
  3672. tmp->next = NULL;
  3673. tmp->prev = NULL;
  3674. spin_unlock_irq(&timeout_lock);
  3675. ep = list_entry(tmp, struct c4iw_ep, entry);
  3676. process_timeout(ep);
  3677. spin_lock_irq(&timeout_lock);
  3678. }
  3679. spin_unlock_irq(&timeout_lock);
  3680. }
  3681. static void process_work(struct work_struct *work)
  3682. {
  3683. struct sk_buff *skb = NULL;
  3684. struct c4iw_dev *dev;
  3685. struct cpl_act_establish *rpl;
  3686. unsigned int opcode;
  3687. int ret;
  3688. process_timedout_eps();
  3689. while ((skb = skb_dequeue(&rxq))) {
  3690. rpl = cplhdr(skb);
  3691. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  3692. opcode = rpl->ot.opcode;
  3693. if (opcode >= ARRAY_SIZE(work_handlers) ||
  3694. !work_handlers[opcode]) {
  3695. pr_err("No handler for opcode 0x%x.\n", opcode);
  3696. kfree_skb(skb);
  3697. } else {
  3698. ret = work_handlers[opcode](dev, skb);
  3699. if (!ret)
  3700. kfree_skb(skb);
  3701. }
  3702. process_timedout_eps();
  3703. }
  3704. }
  3705. static DECLARE_WORK(skb_work, process_work);
  3706. static void ep_timeout(struct timer_list *t)
  3707. {
  3708. struct c4iw_ep *ep = from_timer(ep, t, timer);
  3709. int kickit = 0;
  3710. spin_lock(&timeout_lock);
  3711. if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
  3712. /*
  3713. * Only insert if it is not already on the list.
  3714. */
  3715. if (!ep->entry.next) {
  3716. list_add_tail(&ep->entry, &timeout_list);
  3717. kickit = 1;
  3718. }
  3719. }
  3720. spin_unlock(&timeout_lock);
  3721. if (kickit)
  3722. queue_work(workq, &skb_work);
  3723. }
  3724. /*
  3725. * All the CM events are handled on a work queue to have a safe context.
  3726. */
  3727. static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
  3728. {
  3729. /*
  3730. * Save dev in the skb->cb area.
  3731. */
  3732. *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
  3733. /*
  3734. * Queue the skb and schedule the worker thread.
  3735. */
  3736. skb_queue_tail(&rxq, skb);
  3737. queue_work(workq, &skb_work);
  3738. return 0;
  3739. }
  3740. static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  3741. {
  3742. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  3743. if (rpl->status != CPL_ERR_NONE) {
  3744. pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
  3745. rpl->status, GET_TID(rpl));
  3746. }
  3747. kfree_skb(skb);
  3748. return 0;
  3749. }
  3750. static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  3751. {
  3752. struct cpl_fw6_msg *rpl = cplhdr(skb);
  3753. struct c4iw_wr_wait *wr_waitp;
  3754. int ret;
  3755. pr_debug("type %u\n", rpl->type);
  3756. switch (rpl->type) {
  3757. case FW6_TYPE_WR_RPL:
  3758. ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
  3759. wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
  3760. pr_debug("wr_waitp %p ret %u\n", wr_waitp, ret);
  3761. if (wr_waitp)
  3762. c4iw_wake_up_deref(wr_waitp, ret ? -ret : 0);
  3763. kfree_skb(skb);
  3764. break;
  3765. case FW6_TYPE_CQE:
  3766. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  3767. sched(dev, skb);
  3768. break;
  3769. default:
  3770. pr_err("%s unexpected fw6 msg type %u\n",
  3771. __func__, rpl->type);
  3772. kfree_skb(skb);
  3773. break;
  3774. }
  3775. return 0;
  3776. }
  3777. static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
  3778. {
  3779. struct cpl_abort_req_rss *req = cplhdr(skb);
  3780. struct c4iw_ep *ep;
  3781. unsigned int tid = GET_TID(req);
  3782. ep = get_ep_from_tid(dev, tid);
  3783. /* This EP will be dereferenced in peer_abort() */
  3784. if (!ep) {
  3785. pr_warn("Abort on non-existent endpoint, tid %d\n", tid);
  3786. kfree_skb(skb);
  3787. return 0;
  3788. }
  3789. if (cxgb_is_neg_adv(req->status)) {
  3790. pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
  3791. ep->hwtid, req->status,
  3792. neg_adv_str(req->status));
  3793. goto out;
  3794. }
  3795. pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid, ep->com.state);
  3796. c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
  3797. out:
  3798. sched(dev, skb);
  3799. return 0;
  3800. }
  3801. /*
  3802. * Most upcalls from the T4 Core go to sched() to
  3803. * schedule the processing on a work queue.
  3804. */
  3805. c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
  3806. [CPL_ACT_ESTABLISH] = sched,
  3807. [CPL_ACT_OPEN_RPL] = sched,
  3808. [CPL_RX_DATA] = sched,
  3809. [CPL_ABORT_RPL_RSS] = sched,
  3810. [CPL_ABORT_RPL] = sched,
  3811. [CPL_PASS_OPEN_RPL] = sched,
  3812. [CPL_CLOSE_LISTSRV_RPL] = sched,
  3813. [CPL_PASS_ACCEPT_REQ] = sched,
  3814. [CPL_PASS_ESTABLISH] = sched,
  3815. [CPL_PEER_CLOSE] = sched,
  3816. [CPL_CLOSE_CON_RPL] = sched,
  3817. [CPL_ABORT_REQ_RSS] = peer_abort_intr,
  3818. [CPL_RDMA_TERMINATE] = sched,
  3819. [CPL_FW4_ACK] = sched,
  3820. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  3821. [CPL_FW6_MSG] = fw6_msg,
  3822. [CPL_RX_PKT] = sched
  3823. };
  3824. int __init c4iw_cm_init(void)
  3825. {
  3826. spin_lock_init(&timeout_lock);
  3827. skb_queue_head_init(&rxq);
  3828. workq = alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM);
  3829. if (!workq)
  3830. return -ENOMEM;
  3831. return 0;
  3832. }
  3833. void c4iw_cm_term(void)
  3834. {
  3835. WARN_ON(!list_empty(&timeout_list));
  3836. flush_workqueue(workq);
  3837. destroy_workqueue(workq);
  3838. }