cm.c 114 KB

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