cm.c 89 KB

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