cm.c 107 KB

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