cm.c 90 KB

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