cm.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354
  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. /* get a l2t entry */
  1391. if (neigh->dev->flags & IFF_LOOPBACK) {
  1392. PDBG("%s LOOPBACK\n", __func__);
  1393. pdev = ip_dev_find(&init_net,
  1394. ep->com.cm_id->remote_addr.sin_addr.s_addr);
  1395. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  1396. neigh, pdev, 0);
  1397. pi = (struct port_info *)netdev_priv(pdev);
  1398. ep->mtu = pdev->mtu;
  1399. ep->tx_chan = cxgb4_port_chan(pdev);
  1400. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1401. dev_put(pdev);
  1402. } else {
  1403. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  1404. neigh, neigh->dev, 0);
  1405. pi = (struct port_info *)netdev_priv(neigh->dev);
  1406. ep->mtu = dst_mtu(ep->dst);
  1407. ep->tx_chan = cxgb4_port_chan(neigh->dev);
  1408. ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
  1409. 0x7F) << 1;
  1410. }
  1411. step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
  1412. ep->txq_idx = pi->port_id * step;
  1413. ep->ctrlq_idx = pi->port_id;
  1414. step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
  1415. ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
  1416. if (!ep->l2t) {
  1417. pr_err("%s - cannot alloc l2e.\n", __func__);
  1418. err = -ENOMEM;
  1419. goto fail4;
  1420. }
  1421. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  1422. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  1423. ep->l2t->idx);
  1424. state_set(&ep->com, CONNECTING);
  1425. ep->tos = 0;
  1426. /* send connect request to rnic */
  1427. err = send_connect(ep);
  1428. if (!err)
  1429. goto out;
  1430. cxgb4_l2t_release(ep->l2t);
  1431. fail4:
  1432. dst_release(ep->dst);
  1433. fail3:
  1434. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  1435. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  1436. fail2:
  1437. /*
  1438. * remember to send notification to upper layer.
  1439. * We are in here so the upper layer is not aware that this is
  1440. * re-connect attempt and so, upper layer is still waiting for
  1441. * response of 1st connect request.
  1442. */
  1443. connect_reply_upcall(ep, -ECONNRESET);
  1444. c4iw_put_ep(&ep->com);
  1445. out:
  1446. return err;
  1447. }
  1448. static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1449. {
  1450. struct c4iw_ep *ep;
  1451. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1452. unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
  1453. ntohl(rpl->atid_status)));
  1454. struct tid_info *t = dev->rdev.lldi.tids;
  1455. int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
  1456. ep = lookup_atid(t, atid);
  1457. PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
  1458. status, status2errno(status));
  1459. if (status == CPL_ERR_RTX_NEG_ADVICE) {
  1460. printk(KERN_WARNING MOD "Connection problems for atid %u\n",
  1461. atid);
  1462. return 0;
  1463. }
  1464. set_bit(ACT_OPEN_RPL, &ep->com.history);
  1465. /*
  1466. * Log interesting failures.
  1467. */
  1468. switch (status) {
  1469. case CPL_ERR_CONN_RESET:
  1470. case CPL_ERR_CONN_TIMEDOUT:
  1471. break;
  1472. case CPL_ERR_TCAM_FULL:
  1473. if (dev->rdev.lldi.enable_fw_ofld_conn) {
  1474. mutex_lock(&dev->rdev.stats.lock);
  1475. dev->rdev.stats.tcam_full++;
  1476. mutex_unlock(&dev->rdev.stats.lock);
  1477. send_fw_act_open_req(ep,
  1478. GET_TID_TID(GET_AOPEN_ATID(
  1479. ntohl(rpl->atid_status))));
  1480. return 0;
  1481. }
  1482. break;
  1483. case CPL_ERR_CONN_EXIST:
  1484. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  1485. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  1486. remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
  1487. atid);
  1488. cxgb4_free_atid(t, atid);
  1489. dst_release(ep->dst);
  1490. cxgb4_l2t_release(ep->l2t);
  1491. c4iw_reconnect(ep);
  1492. return 0;
  1493. }
  1494. break;
  1495. default:
  1496. printk(KERN_INFO MOD "Active open failure - "
  1497. "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
  1498. atid, status, status2errno(status),
  1499. &ep->com.local_addr.sin_addr.s_addr,
  1500. ntohs(ep->com.local_addr.sin_port),
  1501. &ep->com.remote_addr.sin_addr.s_addr,
  1502. ntohs(ep->com.remote_addr.sin_port));
  1503. break;
  1504. }
  1505. connect_reply_upcall(ep, status2errno(status));
  1506. state_set(&ep->com, DEAD);
  1507. if (status && act_open_has_tid(status))
  1508. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
  1509. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
  1510. cxgb4_free_atid(t, atid);
  1511. dst_release(ep->dst);
  1512. cxgb4_l2t_release(ep->l2t);
  1513. c4iw_put_ep(&ep->com);
  1514. return 0;
  1515. }
  1516. static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1517. {
  1518. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1519. struct tid_info *t = dev->rdev.lldi.tids;
  1520. unsigned int stid = GET_TID(rpl);
  1521. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1522. if (!ep) {
  1523. PDBG("%s stid %d lookup failure!\n", __func__, stid);
  1524. goto out;
  1525. }
  1526. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1527. rpl->status, status2errno(rpl->status));
  1528. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1529. out:
  1530. return 0;
  1531. }
  1532. static int listen_stop(struct c4iw_listen_ep *ep)
  1533. {
  1534. struct sk_buff *skb;
  1535. struct cpl_close_listsvr_req *req;
  1536. PDBG("%s ep %p\n", __func__, ep);
  1537. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1538. if (!skb) {
  1539. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  1540. return -ENOMEM;
  1541. }
  1542. req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
  1543. INIT_TP_WR(req, 0);
  1544. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
  1545. ep->stid));
  1546. req->reply_ctrl = cpu_to_be16(
  1547. QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
  1548. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  1549. return c4iw_ofld_send(&ep->com.dev->rdev, skb);
  1550. }
  1551. static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1552. {
  1553. struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
  1554. struct tid_info *t = dev->rdev.lldi.tids;
  1555. unsigned int stid = GET_TID(rpl);
  1556. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1557. PDBG("%s ep %p\n", __func__, ep);
  1558. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1559. return 0;
  1560. }
  1561. static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
  1562. struct cpl_pass_accept_req *req)
  1563. {
  1564. struct cpl_pass_accept_rpl *rpl;
  1565. unsigned int mtu_idx;
  1566. u64 opt0;
  1567. u32 opt2;
  1568. int wscale;
  1569. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1570. BUG_ON(skb_cloned(skb));
  1571. skb_trim(skb, sizeof(*rpl));
  1572. skb_get(skb);
  1573. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1574. wscale = compute_wscale(rcv_win);
  1575. opt0 = (nocong ? NO_CONG(1) : 0) |
  1576. KEEP_ALIVE(1) |
  1577. DELACK(1) |
  1578. WND_SCALE(wscale) |
  1579. MSS_IDX(mtu_idx) |
  1580. L2T_IDX(ep->l2t->idx) |
  1581. TX_CHAN(ep->tx_chan) |
  1582. SMAC_SEL(ep->smac_idx) |
  1583. DSCP(ep->tos >> 2) |
  1584. ULP_MODE(ULP_MODE_TCPDDP) |
  1585. RCV_BUFSIZ(rcv_win>>10);
  1586. opt2 = RX_CHANNEL(0) |
  1587. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  1588. if (enable_tcp_timestamps && req->tcpopt.tstamp)
  1589. opt2 |= TSTAMPS_EN(1);
  1590. if (enable_tcp_sack && req->tcpopt.sack)
  1591. opt2 |= SACK_EN(1);
  1592. if (wscale && enable_tcp_window_scaling)
  1593. opt2 |= WND_SCALE_EN(1);
  1594. if (enable_ecn) {
  1595. const struct tcphdr *tcph;
  1596. u32 hlen = ntohl(req->hdr_len);
  1597. tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
  1598. G_IP_HDR_LEN(hlen);
  1599. if (tcph->ece && tcph->cwr)
  1600. opt2 |= CCTRL_ECN(1);
  1601. }
  1602. rpl = cplhdr(skb);
  1603. INIT_TP_WR(rpl, ep->hwtid);
  1604. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1605. ep->hwtid));
  1606. rpl->opt0 = cpu_to_be64(opt0);
  1607. rpl->opt2 = cpu_to_be32(opt2);
  1608. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  1609. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1610. return;
  1611. }
  1612. static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
  1613. struct sk_buff *skb)
  1614. {
  1615. PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
  1616. peer_ip);
  1617. BUG_ON(skb_cloned(skb));
  1618. skb_trim(skb, sizeof(struct cpl_tid_release));
  1619. skb_get(skb);
  1620. release_tid(&dev->rdev, hwtid, skb);
  1621. return;
  1622. }
  1623. static void get_4tuple(struct cpl_pass_accept_req *req,
  1624. __be32 *local_ip, __be32 *peer_ip,
  1625. __be16 *local_port, __be16 *peer_port)
  1626. {
  1627. int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
  1628. int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
  1629. struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
  1630. struct tcphdr *tcp = (struct tcphdr *)
  1631. ((u8 *)(req + 1) + eth_len + ip_len);
  1632. PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
  1633. ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
  1634. ntohs(tcp->dest));
  1635. *peer_ip = ip->saddr;
  1636. *local_ip = ip->daddr;
  1637. *peer_port = tcp->source;
  1638. *local_port = tcp->dest;
  1639. return;
  1640. }
  1641. static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
  1642. struct c4iw_dev *cdev, bool clear_mpa_v1)
  1643. {
  1644. struct neighbour *n;
  1645. int err, step;
  1646. n = dst_neigh_lookup(dst, &peer_ip);
  1647. if (!n)
  1648. return -ENODEV;
  1649. rcu_read_lock();
  1650. err = -ENOMEM;
  1651. if (n->dev->flags & IFF_LOOPBACK) {
  1652. struct net_device *pdev;
  1653. pdev = ip_dev_find(&init_net, peer_ip);
  1654. if (!pdev) {
  1655. err = -ENODEV;
  1656. goto out;
  1657. }
  1658. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1659. n, pdev, 0);
  1660. if (!ep->l2t)
  1661. goto out;
  1662. ep->mtu = pdev->mtu;
  1663. ep->tx_chan = cxgb4_port_chan(pdev);
  1664. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1665. step = cdev->rdev.lldi.ntxq /
  1666. cdev->rdev.lldi.nchan;
  1667. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1668. step = cdev->rdev.lldi.nrxq /
  1669. cdev->rdev.lldi.nchan;
  1670. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  1671. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1672. cxgb4_port_idx(pdev) * step];
  1673. dev_put(pdev);
  1674. } else {
  1675. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1676. n, n->dev, 0);
  1677. if (!ep->l2t)
  1678. goto out;
  1679. ep->mtu = dst_mtu(dst);
  1680. ep->tx_chan = cxgb4_port_chan(n->dev);
  1681. ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
  1682. step = cdev->rdev.lldi.ntxq /
  1683. cdev->rdev.lldi.nchan;
  1684. ep->txq_idx = cxgb4_port_idx(n->dev) * step;
  1685. ep->ctrlq_idx = cxgb4_port_idx(n->dev);
  1686. step = cdev->rdev.lldi.nrxq /
  1687. cdev->rdev.lldi.nchan;
  1688. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1689. cxgb4_port_idx(n->dev) * step];
  1690. if (clear_mpa_v1) {
  1691. ep->retry_with_mpa_v1 = 0;
  1692. ep->tried_with_mpa_v1 = 0;
  1693. }
  1694. }
  1695. err = 0;
  1696. out:
  1697. rcu_read_unlock();
  1698. neigh_release(n);
  1699. return err;
  1700. }
  1701. static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
  1702. {
  1703. struct c4iw_ep *child_ep = NULL, *parent_ep;
  1704. struct cpl_pass_accept_req *req = cplhdr(skb);
  1705. unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
  1706. struct tid_info *t = dev->rdev.lldi.tids;
  1707. unsigned int hwtid = GET_TID(req);
  1708. struct dst_entry *dst;
  1709. struct rtable *rt;
  1710. __be32 local_ip, peer_ip = 0;
  1711. __be16 local_port, peer_port;
  1712. int err;
  1713. u16 peer_mss = ntohs(req->tcpopt.mss);
  1714. parent_ep = lookup_stid(t, stid);
  1715. if (!parent_ep) {
  1716. PDBG("%s connect request on invalid stid %d\n", __func__, stid);
  1717. goto reject;
  1718. }
  1719. get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
  1720. PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
  1721. "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
  1722. ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
  1723. ntohs(peer_port), peer_mss);
  1724. if (state_read(&parent_ep->com) != LISTEN) {
  1725. printk(KERN_ERR "%s - listening ep not in LISTEN\n",
  1726. __func__);
  1727. goto reject;
  1728. }
  1729. /* Find output route */
  1730. rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
  1731. GET_POPEN_TOS(ntohl(req->tos_stid)));
  1732. if (!rt) {
  1733. printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
  1734. __func__);
  1735. goto reject;
  1736. }
  1737. dst = &rt->dst;
  1738. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1739. if (!child_ep) {
  1740. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1741. __func__);
  1742. dst_release(dst);
  1743. goto reject;
  1744. }
  1745. err = import_ep(child_ep, peer_ip, dst, dev, false);
  1746. if (err) {
  1747. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1748. __func__);
  1749. dst_release(dst);
  1750. kfree(child_ep);
  1751. goto reject;
  1752. }
  1753. if (peer_mss && child_ep->mtu > (peer_mss + 40))
  1754. child_ep->mtu = peer_mss + 40;
  1755. state_set(&child_ep->com, CONNECTING);
  1756. child_ep->com.dev = dev;
  1757. child_ep->com.cm_id = NULL;
  1758. child_ep->com.local_addr.sin_family = PF_INET;
  1759. child_ep->com.local_addr.sin_port = local_port;
  1760. child_ep->com.local_addr.sin_addr.s_addr = local_ip;
  1761. child_ep->com.remote_addr.sin_family = PF_INET;
  1762. child_ep->com.remote_addr.sin_port = peer_port;
  1763. child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
  1764. c4iw_get_ep(&parent_ep->com);
  1765. child_ep->parent_ep = parent_ep;
  1766. child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
  1767. child_ep->dst = dst;
  1768. child_ep->hwtid = hwtid;
  1769. PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
  1770. child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
  1771. init_timer(&child_ep->timer);
  1772. cxgb4_insert_tid(t, child_ep, hwtid);
  1773. insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
  1774. accept_cr(child_ep, peer_ip, skb, req);
  1775. set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
  1776. goto out;
  1777. reject:
  1778. reject_cr(dev, hwtid, peer_ip, skb);
  1779. out:
  1780. return 0;
  1781. }
  1782. static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  1783. {
  1784. struct c4iw_ep *ep;
  1785. struct cpl_pass_establish *req = cplhdr(skb);
  1786. struct tid_info *t = dev->rdev.lldi.tids;
  1787. unsigned int tid = GET_TID(req);
  1788. ep = lookup_tid(t, tid);
  1789. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1790. ep->snd_seq = be32_to_cpu(req->snd_isn);
  1791. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  1792. PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
  1793. ntohs(req->tcp_opt));
  1794. set_emss(ep, ntohs(req->tcp_opt));
  1795. dst_confirm(ep->dst);
  1796. state_set(&ep->com, MPA_REQ_WAIT);
  1797. start_ep_timer(ep);
  1798. send_flowc(ep, skb);
  1799. set_bit(PASS_ESTAB, &ep->com.history);
  1800. return 0;
  1801. }
  1802. static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
  1803. {
  1804. struct cpl_peer_close *hdr = cplhdr(skb);
  1805. struct c4iw_ep *ep;
  1806. struct c4iw_qp_attributes attrs;
  1807. int disconnect = 1;
  1808. int release = 0;
  1809. struct tid_info *t = dev->rdev.lldi.tids;
  1810. unsigned int tid = GET_TID(hdr);
  1811. int ret;
  1812. ep = lookup_tid(t, tid);
  1813. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1814. dst_confirm(ep->dst);
  1815. set_bit(PEER_CLOSE, &ep->com.history);
  1816. mutex_lock(&ep->com.mutex);
  1817. switch (ep->com.state) {
  1818. case MPA_REQ_WAIT:
  1819. __state_set(&ep->com, CLOSING);
  1820. break;
  1821. case MPA_REQ_SENT:
  1822. __state_set(&ep->com, CLOSING);
  1823. connect_reply_upcall(ep, -ECONNRESET);
  1824. break;
  1825. case MPA_REQ_RCVD:
  1826. /*
  1827. * We're gonna mark this puppy DEAD, but keep
  1828. * the reference on it until the ULP accepts or
  1829. * rejects the CR. Also wake up anyone waiting
  1830. * in rdma connection migration (see c4iw_accept_cr()).
  1831. */
  1832. __state_set(&ep->com, CLOSING);
  1833. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1834. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1835. break;
  1836. case MPA_REP_SENT:
  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 FPDU_MODE:
  1842. start_ep_timer(ep);
  1843. __state_set(&ep->com, CLOSING);
  1844. attrs.next_state = C4IW_QP_STATE_CLOSING;
  1845. ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1846. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1847. if (ret != -ECONNRESET) {
  1848. peer_close_upcall(ep);
  1849. disconnect = 1;
  1850. }
  1851. break;
  1852. case ABORTING:
  1853. disconnect = 0;
  1854. break;
  1855. case CLOSING:
  1856. __state_set(&ep->com, MORIBUND);
  1857. disconnect = 0;
  1858. break;
  1859. case MORIBUND:
  1860. stop_ep_timer(ep);
  1861. if (ep->com.cm_id && ep->com.qp) {
  1862. attrs.next_state = C4IW_QP_STATE_IDLE;
  1863. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1864. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1865. }
  1866. close_complete_upcall(ep);
  1867. __state_set(&ep->com, DEAD);
  1868. release = 1;
  1869. disconnect = 0;
  1870. break;
  1871. case DEAD:
  1872. disconnect = 0;
  1873. break;
  1874. default:
  1875. BUG_ON(1);
  1876. }
  1877. mutex_unlock(&ep->com.mutex);
  1878. if (disconnect)
  1879. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1880. if (release)
  1881. release_ep_resources(ep);
  1882. return 0;
  1883. }
  1884. /*
  1885. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  1886. */
  1887. static int is_neg_adv_abort(unsigned int status)
  1888. {
  1889. return status == CPL_ERR_RTX_NEG_ADVICE ||
  1890. status == CPL_ERR_PERSIST_NEG_ADVICE;
  1891. }
  1892. static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
  1893. {
  1894. struct cpl_abort_req_rss *req = cplhdr(skb);
  1895. struct c4iw_ep *ep;
  1896. struct cpl_abort_rpl *rpl;
  1897. struct sk_buff *rpl_skb;
  1898. struct c4iw_qp_attributes attrs;
  1899. int ret;
  1900. int release = 0;
  1901. struct tid_info *t = dev->rdev.lldi.tids;
  1902. unsigned int tid = GET_TID(req);
  1903. ep = lookup_tid(t, tid);
  1904. if (is_neg_adv_abort(req->status)) {
  1905. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  1906. ep->hwtid);
  1907. return 0;
  1908. }
  1909. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  1910. ep->com.state);
  1911. set_bit(PEER_ABORT, &ep->com.history);
  1912. /*
  1913. * Wake up any threads in rdma_init() or rdma_fini().
  1914. * However, this is not needed if com state is just
  1915. * MPA_REQ_SENT
  1916. */
  1917. if (ep->com.state != MPA_REQ_SENT)
  1918. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1919. mutex_lock(&ep->com.mutex);
  1920. switch (ep->com.state) {
  1921. case CONNECTING:
  1922. break;
  1923. case MPA_REQ_WAIT:
  1924. stop_ep_timer(ep);
  1925. break;
  1926. case MPA_REQ_SENT:
  1927. stop_ep_timer(ep);
  1928. if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
  1929. connect_reply_upcall(ep, -ECONNRESET);
  1930. else {
  1931. /*
  1932. * we just don't send notification upwards because we
  1933. * want to retry with mpa_v1 without upper layers even
  1934. * knowing it.
  1935. *
  1936. * do some housekeeping so as to re-initiate the
  1937. * connection
  1938. */
  1939. PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
  1940. mpa_rev);
  1941. ep->retry_with_mpa_v1 = 1;
  1942. }
  1943. break;
  1944. case MPA_REP_SENT:
  1945. break;
  1946. case MPA_REQ_RCVD:
  1947. break;
  1948. case MORIBUND:
  1949. case CLOSING:
  1950. stop_ep_timer(ep);
  1951. /*FALLTHROUGH*/
  1952. case FPDU_MODE:
  1953. if (ep->com.cm_id && ep->com.qp) {
  1954. attrs.next_state = C4IW_QP_STATE_ERROR;
  1955. ret = c4iw_modify_qp(ep->com.qp->rhp,
  1956. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  1957. &attrs, 1);
  1958. if (ret)
  1959. printk(KERN_ERR MOD
  1960. "%s - qp <- error failed!\n",
  1961. __func__);
  1962. }
  1963. peer_abort_upcall(ep);
  1964. break;
  1965. case ABORTING:
  1966. break;
  1967. case DEAD:
  1968. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1969. mutex_unlock(&ep->com.mutex);
  1970. return 0;
  1971. default:
  1972. BUG_ON(1);
  1973. break;
  1974. }
  1975. dst_confirm(ep->dst);
  1976. if (ep->com.state != ABORTING) {
  1977. __state_set(&ep->com, DEAD);
  1978. /* we don't release if we want to retry with mpa_v1 */
  1979. if (!ep->retry_with_mpa_v1)
  1980. release = 1;
  1981. }
  1982. mutex_unlock(&ep->com.mutex);
  1983. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1984. if (!rpl_skb) {
  1985. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  1986. __func__);
  1987. release = 1;
  1988. goto out;
  1989. }
  1990. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  1991. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  1992. INIT_TP_WR(rpl, ep->hwtid);
  1993. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  1994. rpl->cmd = CPL_ABORT_NO_RST;
  1995. c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
  1996. out:
  1997. if (release)
  1998. release_ep_resources(ep);
  1999. else if (ep->retry_with_mpa_v1) {
  2000. remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
  2001. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  2002. dst_release(ep->dst);
  2003. cxgb4_l2t_release(ep->l2t);
  2004. c4iw_reconnect(ep);
  2005. }
  2006. return 0;
  2007. }
  2008. static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2009. {
  2010. struct c4iw_ep *ep;
  2011. struct c4iw_qp_attributes attrs;
  2012. struct cpl_close_con_rpl *rpl = cplhdr(skb);
  2013. int release = 0;
  2014. struct tid_info *t = dev->rdev.lldi.tids;
  2015. unsigned int tid = GET_TID(rpl);
  2016. ep = lookup_tid(t, tid);
  2017. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2018. BUG_ON(!ep);
  2019. /* The cm_id may be null if we failed to connect */
  2020. mutex_lock(&ep->com.mutex);
  2021. switch (ep->com.state) {
  2022. case CLOSING:
  2023. __state_set(&ep->com, MORIBUND);
  2024. break;
  2025. case MORIBUND:
  2026. stop_ep_timer(ep);
  2027. if ((ep->com.cm_id) && (ep->com.qp)) {
  2028. attrs.next_state = C4IW_QP_STATE_IDLE;
  2029. c4iw_modify_qp(ep->com.qp->rhp,
  2030. ep->com.qp,
  2031. C4IW_QP_ATTR_NEXT_STATE,
  2032. &attrs, 1);
  2033. }
  2034. close_complete_upcall(ep);
  2035. __state_set(&ep->com, DEAD);
  2036. release = 1;
  2037. break;
  2038. case ABORTING:
  2039. case DEAD:
  2040. break;
  2041. default:
  2042. BUG_ON(1);
  2043. break;
  2044. }
  2045. mutex_unlock(&ep->com.mutex);
  2046. if (release)
  2047. release_ep_resources(ep);
  2048. return 0;
  2049. }
  2050. static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
  2051. {
  2052. struct cpl_rdma_terminate *rpl = cplhdr(skb);
  2053. struct tid_info *t = dev->rdev.lldi.tids;
  2054. unsigned int tid = GET_TID(rpl);
  2055. struct c4iw_ep *ep;
  2056. struct c4iw_qp_attributes attrs;
  2057. ep = lookup_tid(t, tid);
  2058. BUG_ON(!ep);
  2059. if (ep && ep->com.qp) {
  2060. printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
  2061. ep->com.qp->wq.sq.qid);
  2062. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  2063. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2064. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2065. } else
  2066. printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
  2067. return 0;
  2068. }
  2069. /*
  2070. * Upcall from the adapter indicating data has been transmitted.
  2071. * For us its just the single MPA request or reply. We can now free
  2072. * the skb holding the mpa message.
  2073. */
  2074. static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
  2075. {
  2076. struct c4iw_ep *ep;
  2077. struct cpl_fw4_ack *hdr = cplhdr(skb);
  2078. u8 credits = hdr->credits;
  2079. unsigned int tid = GET_TID(hdr);
  2080. struct tid_info *t = dev->rdev.lldi.tids;
  2081. ep = lookup_tid(t, tid);
  2082. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  2083. if (credits == 0) {
  2084. PDBG("%s 0 credit ack ep %p tid %u state %u\n",
  2085. __func__, ep, ep->hwtid, state_read(&ep->com));
  2086. return 0;
  2087. }
  2088. dst_confirm(ep->dst);
  2089. if (ep->mpa_skb) {
  2090. PDBG("%s last streaming msg ack ep %p tid %u state %u "
  2091. "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
  2092. state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
  2093. kfree_skb(ep->mpa_skb);
  2094. ep->mpa_skb = NULL;
  2095. }
  2096. return 0;
  2097. }
  2098. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  2099. {
  2100. int err;
  2101. struct c4iw_ep *ep = to_ep(cm_id);
  2102. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2103. if (state_read(&ep->com) == DEAD) {
  2104. c4iw_put_ep(&ep->com);
  2105. return -ECONNRESET;
  2106. }
  2107. set_bit(ULP_REJECT, &ep->com.history);
  2108. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  2109. if (mpa_rev == 0)
  2110. abort_connection(ep, NULL, GFP_KERNEL);
  2111. else {
  2112. err = send_mpa_reject(ep, pdata, pdata_len);
  2113. err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  2114. }
  2115. c4iw_put_ep(&ep->com);
  2116. return 0;
  2117. }
  2118. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2119. {
  2120. int err;
  2121. struct c4iw_qp_attributes attrs;
  2122. enum c4iw_qp_attr_mask mask;
  2123. struct c4iw_ep *ep = to_ep(cm_id);
  2124. struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
  2125. struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
  2126. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2127. if (state_read(&ep->com) == DEAD) {
  2128. err = -ECONNRESET;
  2129. goto err;
  2130. }
  2131. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  2132. BUG_ON(!qp);
  2133. set_bit(ULP_ACCEPT, &ep->com.history);
  2134. if ((conn_param->ord > c4iw_max_read_depth) ||
  2135. (conn_param->ird > c4iw_max_read_depth)) {
  2136. abort_connection(ep, NULL, GFP_KERNEL);
  2137. err = -EINVAL;
  2138. goto err;
  2139. }
  2140. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  2141. if (conn_param->ord > ep->ird) {
  2142. ep->ird = conn_param->ird;
  2143. ep->ord = conn_param->ord;
  2144. send_mpa_reject(ep, conn_param->private_data,
  2145. conn_param->private_data_len);
  2146. abort_connection(ep, NULL, GFP_KERNEL);
  2147. err = -ENOMEM;
  2148. goto err;
  2149. }
  2150. if (conn_param->ird > ep->ord) {
  2151. if (!ep->ord)
  2152. conn_param->ird = 1;
  2153. else {
  2154. abort_connection(ep, NULL, GFP_KERNEL);
  2155. err = -ENOMEM;
  2156. goto err;
  2157. }
  2158. }
  2159. }
  2160. ep->ird = conn_param->ird;
  2161. ep->ord = conn_param->ord;
  2162. if (ep->mpa_attr.version != 2)
  2163. if (peer2peer && ep->ird == 0)
  2164. ep->ird = 1;
  2165. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  2166. cm_id->add_ref(cm_id);
  2167. ep->com.cm_id = cm_id;
  2168. ep->com.qp = qp;
  2169. ref_qp(ep);
  2170. /* bind QP to EP and move to RTS */
  2171. attrs.mpa_attr = ep->mpa_attr;
  2172. attrs.max_ird = ep->ird;
  2173. attrs.max_ord = ep->ord;
  2174. attrs.llp_stream_handle = ep;
  2175. attrs.next_state = C4IW_QP_STATE_RTS;
  2176. /* bind QP and TID with INIT_WR */
  2177. mask = C4IW_QP_ATTR_NEXT_STATE |
  2178. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  2179. C4IW_QP_ATTR_MPA_ATTR |
  2180. C4IW_QP_ATTR_MAX_IRD |
  2181. C4IW_QP_ATTR_MAX_ORD;
  2182. err = c4iw_modify_qp(ep->com.qp->rhp,
  2183. ep->com.qp, mask, &attrs, 1);
  2184. if (err)
  2185. goto err1;
  2186. err = send_mpa_reply(ep, conn_param->private_data,
  2187. conn_param->private_data_len);
  2188. if (err)
  2189. goto err1;
  2190. state_set(&ep->com, FPDU_MODE);
  2191. established_upcall(ep);
  2192. c4iw_put_ep(&ep->com);
  2193. return 0;
  2194. err1:
  2195. ep->com.cm_id = NULL;
  2196. cm_id->rem_ref(cm_id);
  2197. err:
  2198. c4iw_put_ep(&ep->com);
  2199. return err;
  2200. }
  2201. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2202. {
  2203. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2204. struct c4iw_ep *ep;
  2205. struct rtable *rt;
  2206. int err = 0;
  2207. if ((conn_param->ord > c4iw_max_read_depth) ||
  2208. (conn_param->ird > c4iw_max_read_depth)) {
  2209. err = -EINVAL;
  2210. goto out;
  2211. }
  2212. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2213. if (!ep) {
  2214. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2215. err = -ENOMEM;
  2216. goto out;
  2217. }
  2218. init_timer(&ep->timer);
  2219. ep->plen = conn_param->private_data_len;
  2220. if (ep->plen)
  2221. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  2222. conn_param->private_data, ep->plen);
  2223. ep->ird = conn_param->ird;
  2224. ep->ord = conn_param->ord;
  2225. if (peer2peer && ep->ord == 0)
  2226. ep->ord = 1;
  2227. cm_id->add_ref(cm_id);
  2228. ep->com.dev = dev;
  2229. ep->com.cm_id = cm_id;
  2230. ep->com.qp = get_qhp(dev, conn_param->qpn);
  2231. BUG_ON(!ep->com.qp);
  2232. ref_qp(ep);
  2233. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  2234. ep->com.qp, cm_id);
  2235. /*
  2236. * Allocate an active TID to initiate a TCP connection.
  2237. */
  2238. ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
  2239. if (ep->atid == -1) {
  2240. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  2241. err = -ENOMEM;
  2242. goto fail2;
  2243. }
  2244. insert_handle(dev, &dev->atid_idr, ep, ep->atid);
  2245. PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
  2246. ntohl(cm_id->local_addr.sin_addr.s_addr),
  2247. ntohs(cm_id->local_addr.sin_port),
  2248. ntohl(cm_id->remote_addr.sin_addr.s_addr),
  2249. ntohs(cm_id->remote_addr.sin_port));
  2250. /* find a route */
  2251. rt = find_route(dev,
  2252. cm_id->local_addr.sin_addr.s_addr,
  2253. cm_id->remote_addr.sin_addr.s_addr,
  2254. cm_id->local_addr.sin_port,
  2255. cm_id->remote_addr.sin_port, 0);
  2256. if (!rt) {
  2257. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  2258. err = -EHOSTUNREACH;
  2259. goto fail3;
  2260. }
  2261. ep->dst = &rt->dst;
  2262. err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
  2263. ep->dst, ep->com.dev, true);
  2264. if (err) {
  2265. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  2266. goto fail4;
  2267. }
  2268. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  2269. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  2270. ep->l2t->idx);
  2271. state_set(&ep->com, CONNECTING);
  2272. ep->tos = 0;
  2273. ep->com.local_addr = cm_id->local_addr;
  2274. ep->com.remote_addr = cm_id->remote_addr;
  2275. /* send connect request to rnic */
  2276. err = send_connect(ep);
  2277. if (!err)
  2278. goto out;
  2279. cxgb4_l2t_release(ep->l2t);
  2280. fail4:
  2281. dst_release(ep->dst);
  2282. fail3:
  2283. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  2284. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  2285. fail2:
  2286. cm_id->rem_ref(cm_id);
  2287. c4iw_put_ep(&ep->com);
  2288. out:
  2289. return err;
  2290. }
  2291. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
  2292. {
  2293. int err = 0;
  2294. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2295. struct c4iw_listen_ep *ep;
  2296. might_sleep();
  2297. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2298. if (!ep) {
  2299. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2300. err = -ENOMEM;
  2301. goto fail1;
  2302. }
  2303. PDBG("%s ep %p\n", __func__, ep);
  2304. cm_id->add_ref(cm_id);
  2305. ep->com.cm_id = cm_id;
  2306. ep->com.dev = dev;
  2307. ep->backlog = backlog;
  2308. ep->com.local_addr = cm_id->local_addr;
  2309. /*
  2310. * Allocate a server TID.
  2311. */
  2312. if (dev->rdev.lldi.enable_fw_ofld_conn)
  2313. ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
  2314. else
  2315. ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
  2316. if (ep->stid == -1) {
  2317. printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
  2318. err = -ENOMEM;
  2319. goto fail2;
  2320. }
  2321. insert_handle(dev, &dev->stid_idr, ep, ep->stid);
  2322. state_set(&ep->com, LISTEN);
  2323. if (dev->rdev.lldi.enable_fw_ofld_conn) {
  2324. do {
  2325. err = cxgb4_create_server_filter(
  2326. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2327. ep->com.local_addr.sin_addr.s_addr,
  2328. ep->com.local_addr.sin_port,
  2329. 0,
  2330. ep->com.dev->rdev.lldi.rxq_ids[0],
  2331. 0,
  2332. 0);
  2333. if (err == -EBUSY) {
  2334. set_current_state(TASK_UNINTERRUPTIBLE);
  2335. schedule_timeout(usecs_to_jiffies(100));
  2336. }
  2337. } while (err == -EBUSY);
  2338. } else {
  2339. c4iw_init_wr_wait(&ep->com.wr_wait);
  2340. err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
  2341. ep->stid, ep->com.local_addr.sin_addr.s_addr,
  2342. ep->com.local_addr.sin_port,
  2343. 0,
  2344. ep->com.dev->rdev.lldi.rxq_ids[0]);
  2345. if (!err)
  2346. err = c4iw_wait_for_reply(&ep->com.dev->rdev,
  2347. &ep->com.wr_wait,
  2348. 0, 0, __func__);
  2349. }
  2350. if (!err) {
  2351. cm_id->provider_data = ep;
  2352. goto out;
  2353. }
  2354. pr_err("%s cxgb4_create_server/filter failed err %d " \
  2355. "stid %d laddr %08x lport %d\n", \
  2356. __func__, err, ep->stid,
  2357. ntohl(ep->com.local_addr.sin_addr.s_addr),
  2358. ntohs(ep->com.local_addr.sin_port));
  2359. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  2360. fail2:
  2361. cm_id->rem_ref(cm_id);
  2362. c4iw_put_ep(&ep->com);
  2363. fail1:
  2364. out:
  2365. return err;
  2366. }
  2367. int c4iw_destroy_listen(struct iw_cm_id *cm_id)
  2368. {
  2369. int err;
  2370. struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
  2371. PDBG("%s ep %p\n", __func__, ep);
  2372. might_sleep();
  2373. state_set(&ep->com, DEAD);
  2374. if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
  2375. err = cxgb4_remove_server_filter(
  2376. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2377. ep->com.dev->rdev.lldi.rxq_ids[0], 0);
  2378. } else {
  2379. c4iw_init_wr_wait(&ep->com.wr_wait);
  2380. err = listen_stop(ep);
  2381. if (err)
  2382. goto done;
  2383. err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
  2384. 0, 0, __func__);
  2385. }
  2386. remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
  2387. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  2388. done:
  2389. cm_id->rem_ref(cm_id);
  2390. c4iw_put_ep(&ep->com);
  2391. return err;
  2392. }
  2393. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
  2394. {
  2395. int ret = 0;
  2396. int close = 0;
  2397. int fatal = 0;
  2398. struct c4iw_rdev *rdev;
  2399. mutex_lock(&ep->com.mutex);
  2400. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  2401. states[ep->com.state], abrupt);
  2402. rdev = &ep->com.dev->rdev;
  2403. if (c4iw_fatal_error(rdev)) {
  2404. fatal = 1;
  2405. close_complete_upcall(ep);
  2406. ep->com.state = DEAD;
  2407. }
  2408. switch (ep->com.state) {
  2409. case MPA_REQ_WAIT:
  2410. case MPA_REQ_SENT:
  2411. case MPA_REQ_RCVD:
  2412. case MPA_REP_SENT:
  2413. case FPDU_MODE:
  2414. close = 1;
  2415. if (abrupt)
  2416. ep->com.state = ABORTING;
  2417. else {
  2418. ep->com.state = CLOSING;
  2419. start_ep_timer(ep);
  2420. }
  2421. set_bit(CLOSE_SENT, &ep->com.flags);
  2422. break;
  2423. case CLOSING:
  2424. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  2425. close = 1;
  2426. if (abrupt) {
  2427. stop_ep_timer(ep);
  2428. ep->com.state = ABORTING;
  2429. } else
  2430. ep->com.state = MORIBUND;
  2431. }
  2432. break;
  2433. case MORIBUND:
  2434. case ABORTING:
  2435. case DEAD:
  2436. PDBG("%s ignoring disconnect ep %p state %u\n",
  2437. __func__, ep, ep->com.state);
  2438. break;
  2439. default:
  2440. BUG();
  2441. break;
  2442. }
  2443. if (close) {
  2444. if (abrupt) {
  2445. set_bit(EP_DISC_ABORT, &ep->com.history);
  2446. close_complete_upcall(ep);
  2447. ret = send_abort(ep, NULL, gfp);
  2448. } else {
  2449. set_bit(EP_DISC_CLOSE, &ep->com.history);
  2450. ret = send_halfclose(ep, gfp);
  2451. }
  2452. if (ret)
  2453. fatal = 1;
  2454. }
  2455. mutex_unlock(&ep->com.mutex);
  2456. if (fatal)
  2457. release_ep_resources(ep);
  2458. return ret;
  2459. }
  2460. static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  2461. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  2462. {
  2463. struct c4iw_ep *ep;
  2464. int atid = be32_to_cpu(req->tid);
  2465. ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
  2466. (__force u32) req->tid);
  2467. if (!ep)
  2468. return;
  2469. switch (req->retval) {
  2470. case FW_ENOMEM:
  2471. set_bit(ACT_RETRY_NOMEM, &ep->com.history);
  2472. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  2473. send_fw_act_open_req(ep, atid);
  2474. return;
  2475. }
  2476. case FW_EADDRINUSE:
  2477. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  2478. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  2479. send_fw_act_open_req(ep, atid);
  2480. return;
  2481. }
  2482. break;
  2483. default:
  2484. pr_info("%s unexpected ofld conn wr retval %d\n",
  2485. __func__, req->retval);
  2486. break;
  2487. }
  2488. pr_err("active ofld_connect_wr failure %d atid %d\n",
  2489. req->retval, atid);
  2490. mutex_lock(&dev->rdev.stats.lock);
  2491. dev->rdev.stats.act_ofld_conn_fails++;
  2492. mutex_unlock(&dev->rdev.stats.lock);
  2493. connect_reply_upcall(ep, status2errno(req->retval));
  2494. state_set(&ep->com, DEAD);
  2495. remove_handle(dev, &dev->atid_idr, atid);
  2496. cxgb4_free_atid(dev->rdev.lldi.tids, atid);
  2497. dst_release(ep->dst);
  2498. cxgb4_l2t_release(ep->l2t);
  2499. c4iw_put_ep(&ep->com);
  2500. }
  2501. static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  2502. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  2503. {
  2504. struct sk_buff *rpl_skb;
  2505. struct cpl_pass_accept_req *cpl;
  2506. int ret;
  2507. rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
  2508. BUG_ON(!rpl_skb);
  2509. if (req->retval) {
  2510. PDBG("%s passive open failure %d\n", __func__, req->retval);
  2511. mutex_lock(&dev->rdev.stats.lock);
  2512. dev->rdev.stats.pas_ofld_conn_fails++;
  2513. mutex_unlock(&dev->rdev.stats.lock);
  2514. kfree_skb(rpl_skb);
  2515. } else {
  2516. cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
  2517. OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
  2518. (__force u32) htonl(
  2519. (__force u32) req->tid)));
  2520. ret = pass_accept_req(dev, rpl_skb);
  2521. if (!ret)
  2522. kfree_skb(rpl_skb);
  2523. }
  2524. return;
  2525. }
  2526. static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  2527. {
  2528. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2529. struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
  2530. switch (rpl->type) {
  2531. case FW6_TYPE_CQE:
  2532. c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
  2533. break;
  2534. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  2535. req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
  2536. switch (req->t_state) {
  2537. case TCP_SYN_SENT:
  2538. active_ofld_conn_reply(dev, skb, req);
  2539. break;
  2540. case TCP_SYN_RECV:
  2541. passive_ofld_conn_reply(dev, skb, req);
  2542. break;
  2543. default:
  2544. pr_err("%s unexpected ofld conn wr state %d\n",
  2545. __func__, req->t_state);
  2546. break;
  2547. }
  2548. break;
  2549. }
  2550. return 0;
  2551. }
  2552. static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
  2553. {
  2554. u32 l2info;
  2555. u16 vlantag, len, hdr_len;
  2556. u8 intf;
  2557. struct cpl_rx_pkt *cpl = cplhdr(skb);
  2558. struct cpl_pass_accept_req *req;
  2559. struct tcp_options_received tmp_opt;
  2560. /* Store values from cpl_rx_pkt in temporary location. */
  2561. vlantag = (__force u16) cpl->vlan;
  2562. len = (__force u16) cpl->len;
  2563. l2info = (__force u32) cpl->l2info;
  2564. hdr_len = (__force u16) cpl->hdr_len;
  2565. intf = cpl->iff;
  2566. __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
  2567. /*
  2568. * We need to parse the TCP options from SYN packet.
  2569. * to generate cpl_pass_accept_req.
  2570. */
  2571. memset(&tmp_opt, 0, sizeof(tmp_opt));
  2572. tcp_clear_options(&tmp_opt);
  2573. tcp_parse_options(skb, &tmp_opt, NULL, 0, NULL);
  2574. req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
  2575. memset(req, 0, sizeof(*req));
  2576. req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
  2577. V_SYN_MAC_IDX(G_RX_MACIDX(
  2578. (__force int) htonl(l2info))) |
  2579. F_SYN_XACT_MATCH);
  2580. req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
  2581. (__force int) htonl(l2info))) |
  2582. V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
  2583. (__force int) htons(hdr_len))) |
  2584. V_IP_HDR_LEN(G_RX_IPHDR_LEN(
  2585. (__force int) htons(hdr_len))) |
  2586. V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(
  2587. (__force int) htonl(l2info))));
  2588. req->vlan = (__force __be16) vlantag;
  2589. req->len = (__force __be16) len;
  2590. req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
  2591. PASS_OPEN_TOS(tos));
  2592. req->tcpopt.mss = htons(tmp_opt.mss_clamp);
  2593. if (tmp_opt.wscale_ok)
  2594. req->tcpopt.wsf = tmp_opt.snd_wscale;
  2595. req->tcpopt.tstamp = tmp_opt.saw_tstamp;
  2596. if (tmp_opt.sack_ok)
  2597. req->tcpopt.sack = 1;
  2598. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
  2599. return;
  2600. }
  2601. static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
  2602. __be32 laddr, __be16 lport,
  2603. __be32 raddr, __be16 rport,
  2604. u32 rcv_isn, u32 filter, u16 window,
  2605. u32 rss_qid, u8 port_id)
  2606. {
  2607. struct sk_buff *req_skb;
  2608. struct fw_ofld_connection_wr *req;
  2609. struct cpl_pass_accept_req *cpl = cplhdr(skb);
  2610. req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
  2611. req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
  2612. memset(req, 0, sizeof(*req));
  2613. req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
  2614. req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
  2615. req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
  2616. req->le.filter = (__force __be32) filter;
  2617. req->le.lport = lport;
  2618. req->le.pport = rport;
  2619. req->le.u.ipv4.lip = laddr;
  2620. req->le.u.ipv4.pip = raddr;
  2621. req->tcb.rcv_nxt = htonl(rcv_isn + 1);
  2622. req->tcb.rcv_adv = htons(window);
  2623. req->tcb.t_state_to_astid =
  2624. htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
  2625. V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
  2626. V_FW_OFLD_CONNECTION_WR_ASTID(
  2627. GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
  2628. /*
  2629. * We store the qid in opt2 which will be used by the firmware
  2630. * to send us the wr response.
  2631. */
  2632. req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
  2633. /*
  2634. * We initialize the MSS index in TCB to 0xF.
  2635. * So that when driver sends cpl_pass_accept_rpl
  2636. * TCB picks up the correct value. If this was 0
  2637. * TP will ignore any value > 0 for MSS index.
  2638. */
  2639. req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
  2640. req->cookie = (unsigned long)skb;
  2641. set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
  2642. cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
  2643. }
  2644. /*
  2645. * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
  2646. * messages when a filter is being used instead of server to
  2647. * redirect a syn packet. When packets hit filter they are redirected
  2648. * to the offload queue and driver tries to establish the connection
  2649. * using firmware work request.
  2650. */
  2651. static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
  2652. {
  2653. int stid;
  2654. unsigned int filter;
  2655. struct ethhdr *eh = NULL;
  2656. struct vlan_ethhdr *vlan_eh = NULL;
  2657. struct iphdr *iph;
  2658. struct tcphdr *tcph;
  2659. struct rss_header *rss = (void *)skb->data;
  2660. struct cpl_rx_pkt *cpl = (void *)skb->data;
  2661. struct cpl_pass_accept_req *req = (void *)(rss + 1);
  2662. struct l2t_entry *e;
  2663. struct dst_entry *dst;
  2664. struct rtable *rt;
  2665. struct c4iw_ep *lep;
  2666. u16 window;
  2667. struct port_info *pi;
  2668. struct net_device *pdev;
  2669. u16 rss_qid;
  2670. int step;
  2671. u32 tx_chan;
  2672. struct neighbour *neigh;
  2673. /* Drop all non-SYN packets */
  2674. if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
  2675. goto reject;
  2676. /*
  2677. * Drop all packets which did not hit the filter.
  2678. * Unlikely to happen.
  2679. */
  2680. if (!(rss->filter_hit && rss->filter_tid))
  2681. goto reject;
  2682. /*
  2683. * Calculate the server tid from filter hit index from cpl_rx_pkt.
  2684. */
  2685. stid = (__force int) cpu_to_be32((__force u32) rss->hash_val)
  2686. - dev->rdev.lldi.tids->sftid_base
  2687. + dev->rdev.lldi.tids->nstids;
  2688. lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
  2689. if (!lep) {
  2690. PDBG("%s connect request on invalid stid %d\n", __func__, stid);
  2691. goto reject;
  2692. }
  2693. if (G_RX_ETHHDR_LEN(ntohl(cpl->l2info)) == ETH_HLEN) {
  2694. eh = (struct ethhdr *)(req + 1);
  2695. iph = (struct iphdr *)(eh + 1);
  2696. } else {
  2697. vlan_eh = (struct vlan_ethhdr *)(req + 1);
  2698. iph = (struct iphdr *)(vlan_eh + 1);
  2699. skb->vlan_tci = ntohs(cpl->vlan);
  2700. }
  2701. if (iph->version != 0x4)
  2702. goto reject;
  2703. tcph = (struct tcphdr *)(iph + 1);
  2704. skb_set_network_header(skb, (void *)iph - (void *)rss);
  2705. skb_set_transport_header(skb, (void *)tcph - (void *)rss);
  2706. skb_get(skb);
  2707. PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
  2708. ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
  2709. ntohs(tcph->source), iph->tos);
  2710. rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
  2711. iph->tos);
  2712. if (!rt) {
  2713. pr_err("%s - failed to find dst entry!\n",
  2714. __func__);
  2715. goto reject;
  2716. }
  2717. dst = &rt->dst;
  2718. neigh = dst_neigh_lookup_skb(dst, skb);
  2719. if (neigh->dev->flags & IFF_LOOPBACK) {
  2720. pdev = ip_dev_find(&init_net, iph->daddr);
  2721. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  2722. pdev, 0);
  2723. pi = (struct port_info *)netdev_priv(pdev);
  2724. tx_chan = cxgb4_port_chan(pdev);
  2725. dev_put(pdev);
  2726. } else {
  2727. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  2728. neigh->dev, 0);
  2729. pi = (struct port_info *)netdev_priv(neigh->dev);
  2730. tx_chan = cxgb4_port_chan(neigh->dev);
  2731. }
  2732. if (!e) {
  2733. pr_err("%s - failed to allocate l2t entry!\n",
  2734. __func__);
  2735. goto free_dst;
  2736. }
  2737. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  2738. rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
  2739. window = (__force u16) htons((__force u16)tcph->window);
  2740. /* Calcuate filter portion for LE region. */
  2741. filter = (__force unsigned int) cpu_to_be32(select_ntuple(dev, dst, e));
  2742. /*
  2743. * Synthesize the cpl_pass_accept_req. We have everything except the
  2744. * TID. Once firmware sends a reply with TID we update the TID field
  2745. * in cpl and pass it through the regular cpl_pass_accept_req path.
  2746. */
  2747. build_cpl_pass_accept_req(skb, stid, iph->tos);
  2748. send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
  2749. tcph->source, ntohl(tcph->seq), filter, window,
  2750. rss_qid, pi->port_id);
  2751. cxgb4_l2t_release(e);
  2752. free_dst:
  2753. dst_release(dst);
  2754. reject:
  2755. return 0;
  2756. }
  2757. /*
  2758. * These are the real handlers that are called from a
  2759. * work queue.
  2760. */
  2761. static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
  2762. [CPL_ACT_ESTABLISH] = act_establish,
  2763. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  2764. [CPL_RX_DATA] = rx_data,
  2765. [CPL_ABORT_RPL_RSS] = abort_rpl,
  2766. [CPL_ABORT_RPL] = abort_rpl,
  2767. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  2768. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  2769. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  2770. [CPL_PASS_ESTABLISH] = pass_establish,
  2771. [CPL_PEER_CLOSE] = peer_close,
  2772. [CPL_ABORT_REQ_RSS] = peer_abort,
  2773. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  2774. [CPL_RDMA_TERMINATE] = terminate,
  2775. [CPL_FW4_ACK] = fw4_ack,
  2776. [CPL_FW6_MSG] = deferred_fw6_msg,
  2777. [CPL_RX_PKT] = rx_pkt
  2778. };
  2779. static void process_timeout(struct c4iw_ep *ep)
  2780. {
  2781. struct c4iw_qp_attributes attrs;
  2782. int abort = 1;
  2783. mutex_lock(&ep->com.mutex);
  2784. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  2785. ep->com.state);
  2786. set_bit(TIMEDOUT, &ep->com.history);
  2787. switch (ep->com.state) {
  2788. case MPA_REQ_SENT:
  2789. __state_set(&ep->com, ABORTING);
  2790. connect_reply_upcall(ep, -ETIMEDOUT);
  2791. break;
  2792. case MPA_REQ_WAIT:
  2793. __state_set(&ep->com, ABORTING);
  2794. break;
  2795. case CLOSING:
  2796. case MORIBUND:
  2797. if (ep->com.cm_id && ep->com.qp) {
  2798. attrs.next_state = C4IW_QP_STATE_ERROR;
  2799. c4iw_modify_qp(ep->com.qp->rhp,
  2800. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  2801. &attrs, 1);
  2802. }
  2803. __state_set(&ep->com, ABORTING);
  2804. break;
  2805. default:
  2806. WARN(1, "%s unexpected state ep %p tid %u state %u\n",
  2807. __func__, ep, ep->hwtid, ep->com.state);
  2808. abort = 0;
  2809. }
  2810. mutex_unlock(&ep->com.mutex);
  2811. if (abort)
  2812. abort_connection(ep, NULL, GFP_KERNEL);
  2813. c4iw_put_ep(&ep->com);
  2814. }
  2815. static void process_timedout_eps(void)
  2816. {
  2817. struct c4iw_ep *ep;
  2818. spin_lock_irq(&timeout_lock);
  2819. while (!list_empty(&timeout_list)) {
  2820. struct list_head *tmp;
  2821. tmp = timeout_list.next;
  2822. list_del(tmp);
  2823. spin_unlock_irq(&timeout_lock);
  2824. ep = list_entry(tmp, struct c4iw_ep, entry);
  2825. process_timeout(ep);
  2826. spin_lock_irq(&timeout_lock);
  2827. }
  2828. spin_unlock_irq(&timeout_lock);
  2829. }
  2830. static void process_work(struct work_struct *work)
  2831. {
  2832. struct sk_buff *skb = NULL;
  2833. struct c4iw_dev *dev;
  2834. struct cpl_act_establish *rpl;
  2835. unsigned int opcode;
  2836. int ret;
  2837. while ((skb = skb_dequeue(&rxq))) {
  2838. rpl = cplhdr(skb);
  2839. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  2840. opcode = rpl->ot.opcode;
  2841. BUG_ON(!work_handlers[opcode]);
  2842. ret = work_handlers[opcode](dev, skb);
  2843. if (!ret)
  2844. kfree_skb(skb);
  2845. }
  2846. process_timedout_eps();
  2847. }
  2848. static DECLARE_WORK(skb_work, process_work);
  2849. static void ep_timeout(unsigned long arg)
  2850. {
  2851. struct c4iw_ep *ep = (struct c4iw_ep *)arg;
  2852. int kickit = 0;
  2853. spin_lock(&timeout_lock);
  2854. if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
  2855. list_add_tail(&ep->entry, &timeout_list);
  2856. kickit = 1;
  2857. }
  2858. spin_unlock(&timeout_lock);
  2859. if (kickit)
  2860. queue_work(workq, &skb_work);
  2861. }
  2862. /*
  2863. * All the CM events are handled on a work queue to have a safe context.
  2864. */
  2865. static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
  2866. {
  2867. /*
  2868. * Save dev in the skb->cb area.
  2869. */
  2870. *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
  2871. /*
  2872. * Queue the skb and schedule the worker thread.
  2873. */
  2874. skb_queue_tail(&rxq, skb);
  2875. queue_work(workq, &skb_work);
  2876. return 0;
  2877. }
  2878. static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2879. {
  2880. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  2881. if (rpl->status != CPL_ERR_NONE) {
  2882. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  2883. "for tid %u\n", rpl->status, GET_TID(rpl));
  2884. }
  2885. kfree_skb(skb);
  2886. return 0;
  2887. }
  2888. static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  2889. {
  2890. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2891. struct c4iw_wr_wait *wr_waitp;
  2892. int ret;
  2893. PDBG("%s type %u\n", __func__, rpl->type);
  2894. switch (rpl->type) {
  2895. case FW6_TYPE_WR_RPL:
  2896. ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
  2897. wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
  2898. PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
  2899. if (wr_waitp)
  2900. c4iw_wake_up(wr_waitp, ret ? -ret : 0);
  2901. kfree_skb(skb);
  2902. break;
  2903. case FW6_TYPE_CQE:
  2904. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  2905. sched(dev, skb);
  2906. break;
  2907. default:
  2908. printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
  2909. rpl->type);
  2910. kfree_skb(skb);
  2911. break;
  2912. }
  2913. return 0;
  2914. }
  2915. static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
  2916. {
  2917. struct cpl_abort_req_rss *req = cplhdr(skb);
  2918. struct c4iw_ep *ep;
  2919. struct tid_info *t = dev->rdev.lldi.tids;
  2920. unsigned int tid = GET_TID(req);
  2921. ep = lookup_tid(t, tid);
  2922. if (!ep) {
  2923. printk(KERN_WARNING MOD
  2924. "Abort on non-existent endpoint, tid %d\n", tid);
  2925. kfree_skb(skb);
  2926. return 0;
  2927. }
  2928. if (is_neg_adv_abort(req->status)) {
  2929. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  2930. ep->hwtid);
  2931. kfree_skb(skb);
  2932. return 0;
  2933. }
  2934. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  2935. ep->com.state);
  2936. /*
  2937. * Wake up any threads in rdma_init() or rdma_fini().
  2938. * However, if we are on MPAv2 and want to retry with MPAv1
  2939. * then, don't wake up yet.
  2940. */
  2941. if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
  2942. if (ep->com.state != MPA_REQ_SENT)
  2943. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2944. } else
  2945. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2946. sched(dev, skb);
  2947. return 0;
  2948. }
  2949. /*
  2950. * Most upcalls from the T4 Core go to sched() to
  2951. * schedule the processing on a work queue.
  2952. */
  2953. c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
  2954. [CPL_ACT_ESTABLISH] = sched,
  2955. [CPL_ACT_OPEN_RPL] = sched,
  2956. [CPL_RX_DATA] = sched,
  2957. [CPL_ABORT_RPL_RSS] = sched,
  2958. [CPL_ABORT_RPL] = sched,
  2959. [CPL_PASS_OPEN_RPL] = sched,
  2960. [CPL_CLOSE_LISTSRV_RPL] = sched,
  2961. [CPL_PASS_ACCEPT_REQ] = sched,
  2962. [CPL_PASS_ESTABLISH] = sched,
  2963. [CPL_PEER_CLOSE] = sched,
  2964. [CPL_CLOSE_CON_RPL] = sched,
  2965. [CPL_ABORT_REQ_RSS] = peer_abort_intr,
  2966. [CPL_RDMA_TERMINATE] = sched,
  2967. [CPL_FW4_ACK] = sched,
  2968. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  2969. [CPL_FW6_MSG] = fw6_msg,
  2970. [CPL_RX_PKT] = sched
  2971. };
  2972. int __init c4iw_cm_init(void)
  2973. {
  2974. spin_lock_init(&timeout_lock);
  2975. skb_queue_head_init(&rxq);
  2976. workq = create_singlethread_workqueue("iw_cxgb4");
  2977. if (!workq)
  2978. return -ENOMEM;
  2979. return 0;
  2980. }
  2981. void __exit c4iw_cm_term(void)
  2982. {
  2983. WARN_ON(!list_empty(&timeout_list));
  2984. flush_workqueue(workq);
  2985. destroy_workqueue(workq);
  2986. }