cm.c 89 KB

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