cm.c 114 KB

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