cm.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769
  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 <net/neighbour.h>
  42. #include <net/netevent.h>
  43. #include <net/route.h>
  44. #include "iw_cxgb4.h"
  45. static char *states[] = {
  46. "idle",
  47. "listen",
  48. "connecting",
  49. "mpa_wait_req",
  50. "mpa_req_sent",
  51. "mpa_req_rcvd",
  52. "mpa_rep_sent",
  53. "fpdu_mode",
  54. "aborting",
  55. "closing",
  56. "moribund",
  57. "dead",
  58. NULL,
  59. };
  60. static int dack_mode = 1;
  61. module_param(dack_mode, int, 0644);
  62. MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
  63. int c4iw_max_read_depth = 8;
  64. module_param(c4iw_max_read_depth, int, 0644);
  65. MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
  66. static int enable_tcp_timestamps;
  67. module_param(enable_tcp_timestamps, int, 0644);
  68. MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
  69. static int enable_tcp_sack;
  70. module_param(enable_tcp_sack, int, 0644);
  71. MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
  72. static int enable_tcp_window_scaling = 1;
  73. module_param(enable_tcp_window_scaling, int, 0644);
  74. MODULE_PARM_DESC(enable_tcp_window_scaling,
  75. "Enable tcp window scaling (default=1)");
  76. int c4iw_debug;
  77. module_param(c4iw_debug, int, 0644);
  78. MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
  79. static int peer2peer;
  80. module_param(peer2peer, int, 0644);
  81. MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
  82. static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
  83. module_param(p2p_type, int, 0644);
  84. MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
  85. "1=RDMA_READ 0=RDMA_WRITE (default 1)");
  86. static int ep_timeout_secs = 60;
  87. module_param(ep_timeout_secs, int, 0644);
  88. MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
  89. "in seconds (default=60)");
  90. static int mpa_rev = 1;
  91. module_param(mpa_rev, int, 0644);
  92. MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
  93. "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
  94. " compliant (default=1)");
  95. static int markers_enabled;
  96. module_param(markers_enabled, int, 0644);
  97. MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
  98. static int crc_enabled = 1;
  99. module_param(crc_enabled, int, 0644);
  100. MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
  101. static int rcv_win = 256 * 1024;
  102. module_param(rcv_win, int, 0644);
  103. MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
  104. static int snd_win = 128 * 1024;
  105. module_param(snd_win, int, 0644);
  106. MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
  107. static struct workqueue_struct *workq;
  108. static struct sk_buff_head rxq;
  109. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
  110. static void ep_timeout(unsigned long arg);
  111. static void connect_reply_upcall(struct c4iw_ep *ep, int status);
  112. static LIST_HEAD(timeout_list);
  113. static spinlock_t timeout_lock;
  114. static void start_ep_timer(struct c4iw_ep *ep)
  115. {
  116. PDBG("%s ep %p\n", __func__, ep);
  117. if (timer_pending(&ep->timer)) {
  118. PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
  119. del_timer_sync(&ep->timer);
  120. } else
  121. c4iw_get_ep(&ep->com);
  122. ep->timer.expires = jiffies + ep_timeout_secs * HZ;
  123. ep->timer.data = (unsigned long)ep;
  124. ep->timer.function = ep_timeout;
  125. add_timer(&ep->timer);
  126. }
  127. static void stop_ep_timer(struct c4iw_ep *ep)
  128. {
  129. PDBG("%s ep %p\n", __func__, ep);
  130. if (!timer_pending(&ep->timer)) {
  131. printk(KERN_ERR "%s timer stopped when its not running! "
  132. "ep %p state %u\n", __func__, ep, ep->com.state);
  133. WARN_ON(1);
  134. return;
  135. }
  136. del_timer_sync(&ep->timer);
  137. c4iw_put_ep(&ep->com);
  138. }
  139. static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
  140. struct l2t_entry *l2e)
  141. {
  142. int error = 0;
  143. if (c4iw_fatal_error(rdev)) {
  144. kfree_skb(skb);
  145. PDBG("%s - device in error state - dropping\n", __func__);
  146. return -EIO;
  147. }
  148. error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
  149. if (error < 0)
  150. kfree_skb(skb);
  151. return error < 0 ? error : 0;
  152. }
  153. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
  154. {
  155. int error = 0;
  156. if (c4iw_fatal_error(rdev)) {
  157. kfree_skb(skb);
  158. PDBG("%s - device in error state - dropping\n", __func__);
  159. return -EIO;
  160. }
  161. error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
  162. if (error < 0)
  163. kfree_skb(skb);
  164. return error < 0 ? error : 0;
  165. }
  166. static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
  167. {
  168. struct cpl_tid_release *req;
  169. skb = get_skb(skb, sizeof *req, GFP_KERNEL);
  170. if (!skb)
  171. return;
  172. req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
  173. INIT_TP_WR(req, hwtid);
  174. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
  175. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  176. c4iw_ofld_send(rdev, skb);
  177. return;
  178. }
  179. static void set_emss(struct c4iw_ep *ep, u16 opt)
  180. {
  181. ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
  182. ep->mss = ep->emss;
  183. if (GET_TCPOPT_TSTAMP(opt))
  184. ep->emss -= 12;
  185. if (ep->emss < 128)
  186. ep->emss = 128;
  187. PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
  188. ep->mss, ep->emss);
  189. }
  190. static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
  191. {
  192. enum c4iw_ep_state state;
  193. mutex_lock(&epc->mutex);
  194. state = epc->state;
  195. mutex_unlock(&epc->mutex);
  196. return state;
  197. }
  198. static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  199. {
  200. epc->state = new;
  201. }
  202. static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  203. {
  204. mutex_lock(&epc->mutex);
  205. PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
  206. __state_set(epc, new);
  207. mutex_unlock(&epc->mutex);
  208. return;
  209. }
  210. static void *alloc_ep(int size, gfp_t gfp)
  211. {
  212. struct c4iw_ep_common *epc;
  213. epc = kzalloc(size, gfp);
  214. if (epc) {
  215. kref_init(&epc->kref);
  216. mutex_init(&epc->mutex);
  217. c4iw_init_wr_wait(&epc->wr_wait);
  218. }
  219. PDBG("%s alloc ep %p\n", __func__, epc);
  220. return epc;
  221. }
  222. void _c4iw_free_ep(struct kref *kref)
  223. {
  224. struct c4iw_ep *ep;
  225. ep = container_of(kref, struct c4iw_ep, com.kref);
  226. PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
  227. if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
  228. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  229. dst_release(ep->dst);
  230. cxgb4_l2t_release(ep->l2t);
  231. }
  232. kfree(ep);
  233. }
  234. static void release_ep_resources(struct c4iw_ep *ep)
  235. {
  236. set_bit(RELEASE_RESOURCES, &ep->com.flags);
  237. c4iw_put_ep(&ep->com);
  238. }
  239. static int status2errno(int status)
  240. {
  241. switch (status) {
  242. case CPL_ERR_NONE:
  243. return 0;
  244. case CPL_ERR_CONN_RESET:
  245. return -ECONNRESET;
  246. case CPL_ERR_ARP_MISS:
  247. return -EHOSTUNREACH;
  248. case CPL_ERR_CONN_TIMEDOUT:
  249. return -ETIMEDOUT;
  250. case CPL_ERR_TCAM_FULL:
  251. return -ENOMEM;
  252. case CPL_ERR_CONN_EXIST:
  253. return -EADDRINUSE;
  254. default:
  255. return -EIO;
  256. }
  257. }
  258. /*
  259. * Try and reuse skbs already allocated...
  260. */
  261. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
  262. {
  263. if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
  264. skb_trim(skb, 0);
  265. skb_get(skb);
  266. skb_reset_transport_header(skb);
  267. } else {
  268. skb = alloc_skb(len, gfp);
  269. }
  270. return skb;
  271. }
  272. static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
  273. __be32 peer_ip, __be16 local_port,
  274. __be16 peer_port, u8 tos)
  275. {
  276. struct rtable *rt;
  277. struct flowi4 fl4;
  278. rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
  279. peer_port, local_port, IPPROTO_TCP,
  280. tos, 0);
  281. if (IS_ERR(rt))
  282. return NULL;
  283. return rt;
  284. }
  285. static void arp_failure_discard(void *handle, struct sk_buff *skb)
  286. {
  287. PDBG("%s c4iw_dev %p\n", __func__, handle);
  288. kfree_skb(skb);
  289. }
  290. /*
  291. * Handle an ARP failure for an active open.
  292. */
  293. static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
  294. {
  295. printk(KERN_ERR MOD "ARP failure duing connect\n");
  296. kfree_skb(skb);
  297. }
  298. /*
  299. * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
  300. * and send it along.
  301. */
  302. static void abort_arp_failure(void *handle, struct sk_buff *skb)
  303. {
  304. struct c4iw_rdev *rdev = handle;
  305. struct cpl_abort_req *req = cplhdr(skb);
  306. PDBG("%s rdev %p\n", __func__, rdev);
  307. req->cmd = CPL_ABORT_NO_RST;
  308. c4iw_ofld_send(rdev, skb);
  309. }
  310. static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
  311. {
  312. unsigned int flowclen = 80;
  313. struct fw_flowc_wr *flowc;
  314. int i;
  315. skb = get_skb(skb, flowclen, GFP_KERNEL);
  316. flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
  317. flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
  318. FW_FLOWC_WR_NPARAMS(8));
  319. flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
  320. 16)) | FW_WR_FLOWID(ep->hwtid));
  321. flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
  322. flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
  323. flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
  324. flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
  325. flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
  326. flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
  327. flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
  328. flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
  329. flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
  330. flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
  331. flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
  332. flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
  333. flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
  334. flowc->mnemval[6].val = cpu_to_be32(snd_win);
  335. flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
  336. flowc->mnemval[7].val = cpu_to_be32(ep->emss);
  337. /* Pad WR to 16 byte boundary */
  338. flowc->mnemval[8].mnemonic = 0;
  339. flowc->mnemval[8].val = 0;
  340. for (i = 0; i < 9; i++) {
  341. flowc->mnemval[i].r4[0] = 0;
  342. flowc->mnemval[i].r4[1] = 0;
  343. flowc->mnemval[i].r4[2] = 0;
  344. }
  345. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  346. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  347. }
  348. static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
  349. {
  350. struct cpl_close_con_req *req;
  351. struct sk_buff *skb;
  352. int wrlen = roundup(sizeof *req, 16);
  353. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  354. skb = get_skb(NULL, wrlen, gfp);
  355. if (!skb) {
  356. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  357. return -ENOMEM;
  358. }
  359. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  360. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  361. req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
  362. memset(req, 0, wrlen);
  363. INIT_TP_WR(req, ep->hwtid);
  364. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
  365. ep->hwtid));
  366. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  367. }
  368. static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  369. {
  370. struct cpl_abort_req *req;
  371. int wrlen = roundup(sizeof *req, 16);
  372. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  373. skb = get_skb(skb, wrlen, gfp);
  374. if (!skb) {
  375. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  376. __func__);
  377. return -ENOMEM;
  378. }
  379. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  380. t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
  381. req = (struct cpl_abort_req *) skb_put(skb, wrlen);
  382. memset(req, 0, wrlen);
  383. INIT_TP_WR(req, ep->hwtid);
  384. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
  385. req->cmd = CPL_ABORT_SEND_RST;
  386. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  387. }
  388. static int send_connect(struct c4iw_ep *ep)
  389. {
  390. struct cpl_act_open_req *req;
  391. struct sk_buff *skb;
  392. u64 opt0;
  393. u32 opt2;
  394. unsigned int mtu_idx;
  395. int wscale;
  396. int wrlen = roundup(sizeof *req, 16);
  397. PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
  398. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  399. if (!skb) {
  400. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  401. __func__);
  402. return -ENOMEM;
  403. }
  404. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  405. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  406. wscale = compute_wscale(rcv_win);
  407. opt0 = KEEP_ALIVE(1) |
  408. DELACK(1) |
  409. WND_SCALE(wscale) |
  410. MSS_IDX(mtu_idx) |
  411. L2T_IDX(ep->l2t->idx) |
  412. TX_CHAN(ep->tx_chan) |
  413. SMAC_SEL(ep->smac_idx) |
  414. DSCP(ep->tos) |
  415. ULP_MODE(ULP_MODE_TCPDDP) |
  416. RCV_BUFSIZ(rcv_win>>10);
  417. opt2 = RX_CHANNEL(0) |
  418. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  419. if (enable_tcp_timestamps)
  420. opt2 |= TSTAMPS_EN(1);
  421. if (enable_tcp_sack)
  422. opt2 |= SACK_EN(1);
  423. if (wscale && enable_tcp_window_scaling)
  424. opt2 |= WND_SCALE_EN(1);
  425. t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
  426. req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
  427. INIT_TP_WR(req, 0);
  428. OPCODE_TID(req) = cpu_to_be32(
  429. MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
  430. req->local_port = ep->com.local_addr.sin_port;
  431. req->peer_port = ep->com.remote_addr.sin_port;
  432. req->local_ip = ep->com.local_addr.sin_addr.s_addr;
  433. req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
  434. req->opt0 = cpu_to_be64(opt0);
  435. req->params = 0;
  436. req->opt2 = cpu_to_be32(opt2);
  437. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  438. }
  439. static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
  440. u8 mpa_rev_to_use)
  441. {
  442. int mpalen, wrlen;
  443. struct fw_ofld_tx_data_wr *req;
  444. struct mpa_message *mpa;
  445. struct mpa_v2_conn_params mpa_v2_params;
  446. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  447. BUG_ON(skb_cloned(skb));
  448. mpalen = sizeof(*mpa) + ep->plen;
  449. if (mpa_rev_to_use == 2)
  450. mpalen += sizeof(struct mpa_v2_conn_params);
  451. wrlen = roundup(mpalen + sizeof *req, 16);
  452. skb = get_skb(skb, wrlen, GFP_KERNEL);
  453. if (!skb) {
  454. connect_reply_upcall(ep, -ENOMEM);
  455. return;
  456. }
  457. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  458. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  459. memset(req, 0, wrlen);
  460. req->op_to_immdlen = cpu_to_be32(
  461. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  462. FW_WR_COMPL(1) |
  463. FW_WR_IMMDLEN(mpalen));
  464. req->flowid_len16 = cpu_to_be32(
  465. FW_WR_FLOWID(ep->hwtid) |
  466. FW_WR_LEN16(wrlen >> 4));
  467. req->plen = cpu_to_be32(mpalen);
  468. req->tunnel_to_proxy = cpu_to_be32(
  469. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  470. FW_OFLD_TX_DATA_WR_SHOVE(1));
  471. mpa = (struct mpa_message *)(req + 1);
  472. memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
  473. mpa->flags = (crc_enabled ? MPA_CRC : 0) |
  474. (markers_enabled ? MPA_MARKERS : 0) |
  475. (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
  476. mpa->private_data_size = htons(ep->plen);
  477. mpa->revision = mpa_rev_to_use;
  478. if (mpa_rev_to_use == 1)
  479. ep->tried_with_mpa_v1 = 1;
  480. if (mpa_rev_to_use == 2) {
  481. mpa->private_data_size +=
  482. htons(sizeof(struct mpa_v2_conn_params));
  483. mpa_v2_params.ird = htons((u16)ep->ird);
  484. mpa_v2_params.ord = htons((u16)ep->ord);
  485. if (peer2peer) {
  486. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  487. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  488. mpa_v2_params.ord |=
  489. htons(MPA_V2_RDMA_WRITE_RTR);
  490. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  491. mpa_v2_params.ord |=
  492. htons(MPA_V2_RDMA_READ_RTR);
  493. }
  494. memcpy(mpa->private_data, &mpa_v2_params,
  495. sizeof(struct mpa_v2_conn_params));
  496. if (ep->plen)
  497. memcpy(mpa->private_data +
  498. sizeof(struct mpa_v2_conn_params),
  499. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  500. } else
  501. if (ep->plen)
  502. memcpy(mpa->private_data,
  503. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  504. /*
  505. * Reference the mpa skb. This ensures the data area
  506. * will remain in memory until the hw acks the tx.
  507. * Function fw4_ack() will deref it.
  508. */
  509. skb_get(skb);
  510. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  511. BUG_ON(ep->mpa_skb);
  512. ep->mpa_skb = skb;
  513. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  514. start_ep_timer(ep);
  515. state_set(&ep->com, MPA_REQ_SENT);
  516. ep->mpa_attr.initiator = 1;
  517. return;
  518. }
  519. static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
  520. {
  521. int mpalen, wrlen;
  522. struct fw_ofld_tx_data_wr *req;
  523. struct mpa_message *mpa;
  524. struct sk_buff *skb;
  525. struct mpa_v2_conn_params mpa_v2_params;
  526. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  527. mpalen = sizeof(*mpa) + plen;
  528. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  529. mpalen += sizeof(struct mpa_v2_conn_params);
  530. wrlen = roundup(mpalen + sizeof *req, 16);
  531. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  532. if (!skb) {
  533. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  534. return -ENOMEM;
  535. }
  536. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  537. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  538. memset(req, 0, wrlen);
  539. req->op_to_immdlen = cpu_to_be32(
  540. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  541. FW_WR_COMPL(1) |
  542. FW_WR_IMMDLEN(mpalen));
  543. req->flowid_len16 = cpu_to_be32(
  544. FW_WR_FLOWID(ep->hwtid) |
  545. FW_WR_LEN16(wrlen >> 4));
  546. req->plen = cpu_to_be32(mpalen);
  547. req->tunnel_to_proxy = cpu_to_be32(
  548. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  549. FW_OFLD_TX_DATA_WR_SHOVE(1));
  550. mpa = (struct mpa_message *)(req + 1);
  551. memset(mpa, 0, sizeof(*mpa));
  552. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  553. mpa->flags = MPA_REJECT;
  554. mpa->revision = mpa_rev;
  555. mpa->private_data_size = htons(plen);
  556. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  557. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  558. mpa->private_data_size +=
  559. htons(sizeof(struct mpa_v2_conn_params));
  560. mpa_v2_params.ird = htons(((u16)ep->ird) |
  561. (peer2peer ? MPA_V2_PEER2PEER_MODEL :
  562. 0));
  563. mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
  564. (p2p_type ==
  565. FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
  566. MPA_V2_RDMA_WRITE_RTR : p2p_type ==
  567. FW_RI_INIT_P2PTYPE_READ_REQ ?
  568. MPA_V2_RDMA_READ_RTR : 0) : 0));
  569. memcpy(mpa->private_data, &mpa_v2_params,
  570. sizeof(struct mpa_v2_conn_params));
  571. if (ep->plen)
  572. memcpy(mpa->private_data +
  573. sizeof(struct mpa_v2_conn_params), pdata, plen);
  574. } else
  575. if (plen)
  576. memcpy(mpa->private_data, pdata, plen);
  577. /*
  578. * Reference the mpa skb again. This ensures the data area
  579. * will remain in memory until the hw acks the tx.
  580. * Function fw4_ack() will deref it.
  581. */
  582. skb_get(skb);
  583. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  584. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  585. BUG_ON(ep->mpa_skb);
  586. ep->mpa_skb = skb;
  587. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  588. }
  589. static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
  590. {
  591. int mpalen, wrlen;
  592. struct fw_ofld_tx_data_wr *req;
  593. struct mpa_message *mpa;
  594. struct sk_buff *skb;
  595. struct mpa_v2_conn_params mpa_v2_params;
  596. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  597. mpalen = sizeof(*mpa) + plen;
  598. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  599. mpalen += sizeof(struct mpa_v2_conn_params);
  600. wrlen = roundup(mpalen + sizeof *req, 16);
  601. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  602. if (!skb) {
  603. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  604. return -ENOMEM;
  605. }
  606. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  607. req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
  608. memset(req, 0, wrlen);
  609. req->op_to_immdlen = cpu_to_be32(
  610. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  611. FW_WR_COMPL(1) |
  612. FW_WR_IMMDLEN(mpalen));
  613. req->flowid_len16 = cpu_to_be32(
  614. FW_WR_FLOWID(ep->hwtid) |
  615. FW_WR_LEN16(wrlen >> 4));
  616. req->plen = cpu_to_be32(mpalen);
  617. req->tunnel_to_proxy = cpu_to_be32(
  618. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  619. FW_OFLD_TX_DATA_WR_SHOVE(1));
  620. mpa = (struct mpa_message *)(req + 1);
  621. memset(mpa, 0, sizeof(*mpa));
  622. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  623. mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
  624. (markers_enabled ? MPA_MARKERS : 0);
  625. mpa->revision = ep->mpa_attr.version;
  626. mpa->private_data_size = htons(plen);
  627. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  628. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  629. mpa->private_data_size +=
  630. htons(sizeof(struct mpa_v2_conn_params));
  631. mpa_v2_params.ird = htons((u16)ep->ird);
  632. mpa_v2_params.ord = htons((u16)ep->ord);
  633. if (peer2peer && (ep->mpa_attr.p2p_type !=
  634. FW_RI_INIT_P2PTYPE_DISABLED)) {
  635. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  636. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  637. mpa_v2_params.ord |=
  638. htons(MPA_V2_RDMA_WRITE_RTR);
  639. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  640. mpa_v2_params.ord |=
  641. htons(MPA_V2_RDMA_READ_RTR);
  642. }
  643. memcpy(mpa->private_data, &mpa_v2_params,
  644. sizeof(struct mpa_v2_conn_params));
  645. if (ep->plen)
  646. memcpy(mpa->private_data +
  647. sizeof(struct mpa_v2_conn_params), pdata, plen);
  648. } else
  649. if (plen)
  650. memcpy(mpa->private_data, pdata, plen);
  651. /*
  652. * Reference the mpa skb. This ensures the data area
  653. * will remain in memory until the hw acks the tx.
  654. * Function fw4_ack() will deref it.
  655. */
  656. skb_get(skb);
  657. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  658. ep->mpa_skb = skb;
  659. state_set(&ep->com, MPA_REP_SENT);
  660. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  661. }
  662. static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  663. {
  664. struct c4iw_ep *ep;
  665. struct cpl_act_establish *req = cplhdr(skb);
  666. unsigned int tid = GET_TID(req);
  667. unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
  668. struct tid_info *t = dev->rdev.lldi.tids;
  669. ep = lookup_atid(t, atid);
  670. PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
  671. be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
  672. dst_confirm(ep->dst);
  673. /* setup the hwtid for this connection */
  674. ep->hwtid = tid;
  675. cxgb4_insert_tid(t, ep, tid);
  676. ep->snd_seq = be32_to_cpu(req->snd_isn);
  677. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  678. set_emss(ep, ntohs(req->tcp_opt));
  679. /* dealloc the atid */
  680. cxgb4_free_atid(t, atid);
  681. /* start MPA negotiation */
  682. send_flowc(ep, NULL);
  683. if (ep->retry_with_mpa_v1)
  684. send_mpa_req(ep, skb, 1);
  685. else
  686. send_mpa_req(ep, skb, mpa_rev);
  687. return 0;
  688. }
  689. static void close_complete_upcall(struct c4iw_ep *ep)
  690. {
  691. struct iw_cm_event event;
  692. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  693. memset(&event, 0, sizeof(event));
  694. event.event = IW_CM_EVENT_CLOSE;
  695. if (ep->com.cm_id) {
  696. PDBG("close complete delivered ep %p cm_id %p tid %u\n",
  697. ep, ep->com.cm_id, ep->hwtid);
  698. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  699. ep->com.cm_id->rem_ref(ep->com.cm_id);
  700. ep->com.cm_id = NULL;
  701. ep->com.qp = NULL;
  702. }
  703. }
  704. static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  705. {
  706. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  707. close_complete_upcall(ep);
  708. state_set(&ep->com, ABORTING);
  709. return send_abort(ep, skb, gfp);
  710. }
  711. static void peer_close_upcall(struct c4iw_ep *ep)
  712. {
  713. struct iw_cm_event event;
  714. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  715. memset(&event, 0, sizeof(event));
  716. event.event = IW_CM_EVENT_DISCONNECT;
  717. if (ep->com.cm_id) {
  718. PDBG("peer close delivered ep %p cm_id %p tid %u\n",
  719. ep, ep->com.cm_id, ep->hwtid);
  720. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  721. }
  722. }
  723. static void peer_abort_upcall(struct c4iw_ep *ep)
  724. {
  725. struct iw_cm_event event;
  726. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  727. memset(&event, 0, sizeof(event));
  728. event.event = IW_CM_EVENT_CLOSE;
  729. event.status = -ECONNRESET;
  730. if (ep->com.cm_id) {
  731. PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
  732. ep->com.cm_id, ep->hwtid);
  733. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  734. ep->com.cm_id->rem_ref(ep->com.cm_id);
  735. ep->com.cm_id = NULL;
  736. ep->com.qp = NULL;
  737. }
  738. }
  739. static void connect_reply_upcall(struct c4iw_ep *ep, int status)
  740. {
  741. struct iw_cm_event event;
  742. PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
  743. memset(&event, 0, sizeof(event));
  744. event.event = IW_CM_EVENT_CONNECT_REPLY;
  745. event.status = status;
  746. event.local_addr = ep->com.local_addr;
  747. event.remote_addr = ep->com.remote_addr;
  748. if ((status == 0) || (status == -ECONNREFUSED)) {
  749. if (!ep->tried_with_mpa_v1) {
  750. /* this means MPA_v2 is used */
  751. event.private_data_len = ep->plen -
  752. sizeof(struct mpa_v2_conn_params);
  753. event.private_data = ep->mpa_pkt +
  754. sizeof(struct mpa_message) +
  755. sizeof(struct mpa_v2_conn_params);
  756. } else {
  757. /* this means MPA_v1 is used */
  758. event.private_data_len = ep->plen;
  759. event.private_data = ep->mpa_pkt +
  760. sizeof(struct mpa_message);
  761. }
  762. }
  763. PDBG("%s ep %p tid %u status %d\n", __func__, ep,
  764. ep->hwtid, status);
  765. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  766. if (status < 0) {
  767. ep->com.cm_id->rem_ref(ep->com.cm_id);
  768. ep->com.cm_id = NULL;
  769. ep->com.qp = NULL;
  770. }
  771. }
  772. static void connect_request_upcall(struct c4iw_ep *ep)
  773. {
  774. struct iw_cm_event event;
  775. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  776. memset(&event, 0, sizeof(event));
  777. event.event = IW_CM_EVENT_CONNECT_REQUEST;
  778. event.local_addr = ep->com.local_addr;
  779. event.remote_addr = ep->com.remote_addr;
  780. event.provider_data = ep;
  781. if (!ep->tried_with_mpa_v1) {
  782. /* this means MPA_v2 is used */
  783. event.ord = ep->ord;
  784. event.ird = ep->ird;
  785. event.private_data_len = ep->plen -
  786. sizeof(struct mpa_v2_conn_params);
  787. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
  788. sizeof(struct mpa_v2_conn_params);
  789. } else {
  790. /* this means MPA_v1 is used. Send max supported */
  791. event.ord = c4iw_max_read_depth;
  792. event.ird = c4iw_max_read_depth;
  793. event.private_data_len = ep->plen;
  794. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  795. }
  796. if (state_read(&ep->parent_ep->com) != DEAD) {
  797. c4iw_get_ep(&ep->com);
  798. ep->parent_ep->com.cm_id->event_handler(
  799. ep->parent_ep->com.cm_id,
  800. &event);
  801. }
  802. c4iw_put_ep(&ep->parent_ep->com);
  803. ep->parent_ep = NULL;
  804. }
  805. static void established_upcall(struct c4iw_ep *ep)
  806. {
  807. struct iw_cm_event event;
  808. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  809. memset(&event, 0, sizeof(event));
  810. event.event = IW_CM_EVENT_ESTABLISHED;
  811. event.ird = ep->ird;
  812. event.ord = ep->ord;
  813. if (ep->com.cm_id) {
  814. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  815. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  816. }
  817. }
  818. static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
  819. {
  820. struct cpl_rx_data_ack *req;
  821. struct sk_buff *skb;
  822. int wrlen = roundup(sizeof *req, 16);
  823. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  824. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  825. if (!skb) {
  826. printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
  827. return 0;
  828. }
  829. req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
  830. memset(req, 0, wrlen);
  831. INIT_TP_WR(req, ep->hwtid);
  832. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
  833. ep->hwtid));
  834. req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
  835. F_RX_DACK_CHANGE |
  836. V_RX_DACK_MODE(dack_mode));
  837. set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
  838. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  839. return credits;
  840. }
  841. static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
  842. {
  843. struct mpa_message *mpa;
  844. struct mpa_v2_conn_params *mpa_v2_params;
  845. u16 plen;
  846. u16 resp_ird, resp_ord;
  847. u8 rtr_mismatch = 0, insuff_ird = 0;
  848. struct c4iw_qp_attributes attrs;
  849. enum c4iw_qp_attr_mask mask;
  850. int err;
  851. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  852. /*
  853. * Stop mpa timer. If it expired, then the state has
  854. * changed and we bail since ep_timeout already aborted
  855. * the connection.
  856. */
  857. stop_ep_timer(ep);
  858. if (state_read(&ep->com) != MPA_REQ_SENT)
  859. return;
  860. /*
  861. * If we get more than the supported amount of private data
  862. * then we must fail this connection.
  863. */
  864. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  865. err = -EINVAL;
  866. goto err;
  867. }
  868. /*
  869. * copy the new data into our accumulation buffer.
  870. */
  871. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  872. skb->len);
  873. ep->mpa_pkt_len += skb->len;
  874. /*
  875. * if we don't even have the mpa message, then bail.
  876. */
  877. if (ep->mpa_pkt_len < sizeof(*mpa))
  878. return;
  879. mpa = (struct mpa_message *) ep->mpa_pkt;
  880. /* Validate MPA header. */
  881. if (mpa->revision > mpa_rev) {
  882. printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
  883. " Received = %d\n", __func__, mpa_rev, mpa->revision);
  884. err = -EPROTO;
  885. goto err;
  886. }
  887. if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
  888. err = -EPROTO;
  889. goto err;
  890. }
  891. plen = ntohs(mpa->private_data_size);
  892. /*
  893. * Fail if there's too much private data.
  894. */
  895. if (plen > MPA_MAX_PRIVATE_DATA) {
  896. err = -EPROTO;
  897. goto err;
  898. }
  899. /*
  900. * If plen does not account for pkt size
  901. */
  902. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  903. err = -EPROTO;
  904. goto err;
  905. }
  906. ep->plen = (u8) plen;
  907. /*
  908. * If we don't have all the pdata yet, then bail.
  909. * We'll continue process when more data arrives.
  910. */
  911. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  912. return;
  913. if (mpa->flags & MPA_REJECT) {
  914. err = -ECONNREFUSED;
  915. goto err;
  916. }
  917. /*
  918. * If we get here we have accumulated the entire mpa
  919. * start reply message including private data. And
  920. * the MPA header is valid.
  921. */
  922. state_set(&ep->com, FPDU_MODE);
  923. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  924. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  925. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  926. ep->mpa_attr.version = mpa->revision;
  927. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  928. if (mpa->revision == 2) {
  929. ep->mpa_attr.enhanced_rdma_conn =
  930. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  931. if (ep->mpa_attr.enhanced_rdma_conn) {
  932. mpa_v2_params = (struct mpa_v2_conn_params *)
  933. (ep->mpa_pkt + sizeof(*mpa));
  934. resp_ird = ntohs(mpa_v2_params->ird) &
  935. MPA_V2_IRD_ORD_MASK;
  936. resp_ord = ntohs(mpa_v2_params->ord) &
  937. MPA_V2_IRD_ORD_MASK;
  938. /*
  939. * This is a double-check. Ideally, below checks are
  940. * not required since ird/ord stuff has been taken
  941. * care of in c4iw_accept_cr
  942. */
  943. if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
  944. err = -ENOMEM;
  945. ep->ird = resp_ord;
  946. ep->ord = resp_ird;
  947. insuff_ird = 1;
  948. }
  949. if (ntohs(mpa_v2_params->ird) &
  950. MPA_V2_PEER2PEER_MODEL) {
  951. if (ntohs(mpa_v2_params->ord) &
  952. MPA_V2_RDMA_WRITE_RTR)
  953. ep->mpa_attr.p2p_type =
  954. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  955. else if (ntohs(mpa_v2_params->ord) &
  956. MPA_V2_RDMA_READ_RTR)
  957. ep->mpa_attr.p2p_type =
  958. FW_RI_INIT_P2PTYPE_READ_REQ;
  959. }
  960. }
  961. } else if (mpa->revision == 1)
  962. if (peer2peer)
  963. ep->mpa_attr.p2p_type = p2p_type;
  964. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  965. "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
  966. "%d\n", __func__, ep->mpa_attr.crc_enabled,
  967. ep->mpa_attr.recv_marker_enabled,
  968. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  969. ep->mpa_attr.p2p_type, p2p_type);
  970. /*
  971. * If responder's RTR does not match with that of initiator, assign
  972. * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
  973. * generated when moving QP to RTS state.
  974. * A TERM message will be sent after QP has moved to RTS state
  975. */
  976. if ((ep->mpa_attr.version == 2) &&
  977. (ep->mpa_attr.p2p_type != p2p_type)) {
  978. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  979. rtr_mismatch = 1;
  980. }
  981. attrs.mpa_attr = ep->mpa_attr;
  982. attrs.max_ird = ep->ird;
  983. attrs.max_ord = ep->ord;
  984. attrs.llp_stream_handle = ep;
  985. attrs.next_state = C4IW_QP_STATE_RTS;
  986. mask = C4IW_QP_ATTR_NEXT_STATE |
  987. C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
  988. C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
  989. /* bind QP and TID with INIT_WR */
  990. err = c4iw_modify_qp(ep->com.qp->rhp,
  991. ep->com.qp, mask, &attrs, 1);
  992. if (err)
  993. goto err;
  994. /*
  995. * If responder's RTR requirement did not match with what initiator
  996. * supports, generate TERM message
  997. */
  998. if (rtr_mismatch) {
  999. printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
  1000. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1001. attrs.ecode = MPA_NOMATCH_RTR;
  1002. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1003. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1004. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1005. err = -ENOMEM;
  1006. goto out;
  1007. }
  1008. /*
  1009. * Generate TERM if initiator IRD is not sufficient for responder
  1010. * provided ORD. Currently, we do the same behaviour even when
  1011. * responder provided IRD is also not sufficient as regards to
  1012. * initiator ORD.
  1013. */
  1014. if (insuff_ird) {
  1015. printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
  1016. __func__);
  1017. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1018. attrs.ecode = MPA_INSUFF_IRD;
  1019. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1020. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1021. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1022. err = -ENOMEM;
  1023. goto out;
  1024. }
  1025. goto out;
  1026. err:
  1027. state_set(&ep->com, ABORTING);
  1028. send_abort(ep, skb, GFP_KERNEL);
  1029. out:
  1030. connect_reply_upcall(ep, err);
  1031. return;
  1032. }
  1033. static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
  1034. {
  1035. struct mpa_message *mpa;
  1036. struct mpa_v2_conn_params *mpa_v2_params;
  1037. u16 plen;
  1038. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1039. if (state_read(&ep->com) != MPA_REQ_WAIT)
  1040. return;
  1041. /*
  1042. * If we get more than the supported amount of private data
  1043. * then we must fail this connection.
  1044. */
  1045. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  1046. stop_ep_timer(ep);
  1047. abort_connection(ep, skb, GFP_KERNEL);
  1048. return;
  1049. }
  1050. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  1051. /*
  1052. * Copy the new data into our accumulation buffer.
  1053. */
  1054. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  1055. skb->len);
  1056. ep->mpa_pkt_len += skb->len;
  1057. /*
  1058. * If we don't even have the mpa message, then bail.
  1059. * We'll continue process when more data arrives.
  1060. */
  1061. if (ep->mpa_pkt_len < sizeof(*mpa))
  1062. return;
  1063. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  1064. stop_ep_timer(ep);
  1065. mpa = (struct mpa_message *) ep->mpa_pkt;
  1066. /*
  1067. * Validate MPA Header.
  1068. */
  1069. if (mpa->revision > mpa_rev) {
  1070. printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
  1071. " Received = %d\n", __func__, mpa_rev, mpa->revision);
  1072. abort_connection(ep, skb, GFP_KERNEL);
  1073. return;
  1074. }
  1075. if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
  1076. abort_connection(ep, skb, GFP_KERNEL);
  1077. return;
  1078. }
  1079. plen = ntohs(mpa->private_data_size);
  1080. /*
  1081. * Fail if there's too much private data.
  1082. */
  1083. if (plen > MPA_MAX_PRIVATE_DATA) {
  1084. abort_connection(ep, skb, GFP_KERNEL);
  1085. return;
  1086. }
  1087. /*
  1088. * If plen does not account for pkt size
  1089. */
  1090. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  1091. abort_connection(ep, skb, GFP_KERNEL);
  1092. return;
  1093. }
  1094. ep->plen = (u8) plen;
  1095. /*
  1096. * If we don't have all the pdata yet, then bail.
  1097. */
  1098. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  1099. return;
  1100. /*
  1101. * If we get here we have accumulated the entire mpa
  1102. * start reply message including private data.
  1103. */
  1104. ep->mpa_attr.initiator = 0;
  1105. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  1106. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  1107. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  1108. ep->mpa_attr.version = mpa->revision;
  1109. if (mpa->revision == 1)
  1110. ep->tried_with_mpa_v1 = 1;
  1111. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1112. if (mpa->revision == 2) {
  1113. ep->mpa_attr.enhanced_rdma_conn =
  1114. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  1115. if (ep->mpa_attr.enhanced_rdma_conn) {
  1116. mpa_v2_params = (struct mpa_v2_conn_params *)
  1117. (ep->mpa_pkt + sizeof(*mpa));
  1118. ep->ird = ntohs(mpa_v2_params->ird) &
  1119. MPA_V2_IRD_ORD_MASK;
  1120. ep->ord = ntohs(mpa_v2_params->ord) &
  1121. MPA_V2_IRD_ORD_MASK;
  1122. if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
  1123. if (peer2peer) {
  1124. if (ntohs(mpa_v2_params->ord) &
  1125. MPA_V2_RDMA_WRITE_RTR)
  1126. ep->mpa_attr.p2p_type =
  1127. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  1128. else if (ntohs(mpa_v2_params->ord) &
  1129. MPA_V2_RDMA_READ_RTR)
  1130. ep->mpa_attr.p2p_type =
  1131. FW_RI_INIT_P2PTYPE_READ_REQ;
  1132. }
  1133. }
  1134. } else if (mpa->revision == 1)
  1135. if (peer2peer)
  1136. ep->mpa_attr.p2p_type = p2p_type;
  1137. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  1138. "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
  1139. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  1140. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  1141. ep->mpa_attr.p2p_type);
  1142. state_set(&ep->com, MPA_REQ_RCVD);
  1143. /* drive upcall */
  1144. connect_request_upcall(ep);
  1145. return;
  1146. }
  1147. static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
  1148. {
  1149. struct c4iw_ep *ep;
  1150. struct cpl_rx_data *hdr = cplhdr(skb);
  1151. unsigned int dlen = ntohs(hdr->len);
  1152. unsigned int tid = GET_TID(hdr);
  1153. struct tid_info *t = dev->rdev.lldi.tids;
  1154. ep = lookup_tid(t, tid);
  1155. PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
  1156. skb_pull(skb, sizeof(*hdr));
  1157. skb_trim(skb, dlen);
  1158. ep->rcv_seq += dlen;
  1159. BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
  1160. /* update RX credits */
  1161. update_rx_credits(ep, dlen);
  1162. switch (state_read(&ep->com)) {
  1163. case MPA_REQ_SENT:
  1164. process_mpa_reply(ep, skb);
  1165. break;
  1166. case MPA_REQ_WAIT:
  1167. process_mpa_request(ep, skb);
  1168. break;
  1169. case MPA_REP_SENT:
  1170. break;
  1171. default:
  1172. printk(KERN_ERR MOD "%s Unexpected streaming data."
  1173. " ep %p state %d tid %u\n",
  1174. __func__, ep, state_read(&ep->com), ep->hwtid);
  1175. /*
  1176. * The ep will timeout and inform the ULP of the failure.
  1177. * See ep_timeout().
  1178. */
  1179. break;
  1180. }
  1181. return 0;
  1182. }
  1183. static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1184. {
  1185. struct c4iw_ep *ep;
  1186. struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
  1187. int release = 0;
  1188. unsigned int tid = GET_TID(rpl);
  1189. struct tid_info *t = dev->rdev.lldi.tids;
  1190. ep = lookup_tid(t, tid);
  1191. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1192. BUG_ON(!ep);
  1193. mutex_lock(&ep->com.mutex);
  1194. switch (ep->com.state) {
  1195. case ABORTING:
  1196. __state_set(&ep->com, DEAD);
  1197. release = 1;
  1198. break;
  1199. default:
  1200. printk(KERN_ERR "%s ep %p state %d\n",
  1201. __func__, ep, ep->com.state);
  1202. break;
  1203. }
  1204. mutex_unlock(&ep->com.mutex);
  1205. if (release)
  1206. release_ep_resources(ep);
  1207. return 0;
  1208. }
  1209. /*
  1210. * Return whether a failed active open has allocated a TID
  1211. */
  1212. static inline int act_open_has_tid(int status)
  1213. {
  1214. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1215. status != CPL_ERR_ARP_MISS;
  1216. }
  1217. static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1218. {
  1219. struct c4iw_ep *ep;
  1220. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1221. unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
  1222. ntohl(rpl->atid_status)));
  1223. struct tid_info *t = dev->rdev.lldi.tids;
  1224. int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
  1225. ep = lookup_atid(t, atid);
  1226. PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
  1227. status, status2errno(status));
  1228. if (status == CPL_ERR_RTX_NEG_ADVICE) {
  1229. printk(KERN_WARNING MOD "Connection problems for atid %u\n",
  1230. atid);
  1231. return 0;
  1232. }
  1233. connect_reply_upcall(ep, status2errno(status));
  1234. state_set(&ep->com, DEAD);
  1235. if (status && act_open_has_tid(status))
  1236. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
  1237. cxgb4_free_atid(t, atid);
  1238. dst_release(ep->dst);
  1239. cxgb4_l2t_release(ep->l2t);
  1240. c4iw_put_ep(&ep->com);
  1241. return 0;
  1242. }
  1243. static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1244. {
  1245. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1246. struct tid_info *t = dev->rdev.lldi.tids;
  1247. unsigned int stid = GET_TID(rpl);
  1248. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1249. if (!ep) {
  1250. printk(KERN_ERR MOD "stid %d lookup failure!\n", stid);
  1251. return 0;
  1252. }
  1253. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1254. rpl->status, status2errno(rpl->status));
  1255. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1256. return 0;
  1257. }
  1258. static int listen_stop(struct c4iw_listen_ep *ep)
  1259. {
  1260. struct sk_buff *skb;
  1261. struct cpl_close_listsvr_req *req;
  1262. PDBG("%s ep %p\n", __func__, ep);
  1263. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1264. if (!skb) {
  1265. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  1266. return -ENOMEM;
  1267. }
  1268. req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
  1269. INIT_TP_WR(req, 0);
  1270. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
  1271. ep->stid));
  1272. req->reply_ctrl = cpu_to_be16(
  1273. QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
  1274. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  1275. return c4iw_ofld_send(&ep->com.dev->rdev, skb);
  1276. }
  1277. static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1278. {
  1279. struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
  1280. struct tid_info *t = dev->rdev.lldi.tids;
  1281. unsigned int stid = GET_TID(rpl);
  1282. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1283. PDBG("%s ep %p\n", __func__, ep);
  1284. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1285. return 0;
  1286. }
  1287. static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
  1288. struct cpl_pass_accept_req *req)
  1289. {
  1290. struct cpl_pass_accept_rpl *rpl;
  1291. unsigned int mtu_idx;
  1292. u64 opt0;
  1293. u32 opt2;
  1294. int wscale;
  1295. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1296. BUG_ON(skb_cloned(skb));
  1297. skb_trim(skb, sizeof(*rpl));
  1298. skb_get(skb);
  1299. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1300. wscale = compute_wscale(rcv_win);
  1301. opt0 = KEEP_ALIVE(1) |
  1302. DELACK(1) |
  1303. WND_SCALE(wscale) |
  1304. MSS_IDX(mtu_idx) |
  1305. L2T_IDX(ep->l2t->idx) |
  1306. TX_CHAN(ep->tx_chan) |
  1307. SMAC_SEL(ep->smac_idx) |
  1308. DSCP(ep->tos) |
  1309. ULP_MODE(ULP_MODE_TCPDDP) |
  1310. RCV_BUFSIZ(rcv_win>>10);
  1311. opt2 = RX_CHANNEL(0) |
  1312. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  1313. if (enable_tcp_timestamps && req->tcpopt.tstamp)
  1314. opt2 |= TSTAMPS_EN(1);
  1315. if (enable_tcp_sack && req->tcpopt.sack)
  1316. opt2 |= SACK_EN(1);
  1317. if (wscale && enable_tcp_window_scaling)
  1318. opt2 |= WND_SCALE_EN(1);
  1319. rpl = cplhdr(skb);
  1320. INIT_TP_WR(rpl, ep->hwtid);
  1321. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1322. ep->hwtid));
  1323. rpl->opt0 = cpu_to_be64(opt0);
  1324. rpl->opt2 = cpu_to_be32(opt2);
  1325. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  1326. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1327. return;
  1328. }
  1329. static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
  1330. struct sk_buff *skb)
  1331. {
  1332. PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
  1333. peer_ip);
  1334. BUG_ON(skb_cloned(skb));
  1335. skb_trim(skb, sizeof(struct cpl_tid_release));
  1336. skb_get(skb);
  1337. release_tid(&dev->rdev, hwtid, skb);
  1338. return;
  1339. }
  1340. static void get_4tuple(struct cpl_pass_accept_req *req,
  1341. __be32 *local_ip, __be32 *peer_ip,
  1342. __be16 *local_port, __be16 *peer_port)
  1343. {
  1344. int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
  1345. int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
  1346. struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
  1347. struct tcphdr *tcp = (struct tcphdr *)
  1348. ((u8 *)(req + 1) + eth_len + ip_len);
  1349. PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
  1350. ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
  1351. ntohs(tcp->dest));
  1352. *peer_ip = ip->saddr;
  1353. *local_ip = ip->daddr;
  1354. *peer_port = tcp->source;
  1355. *local_port = tcp->dest;
  1356. return;
  1357. }
  1358. static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
  1359. {
  1360. struct c4iw_ep *child_ep, *parent_ep;
  1361. struct cpl_pass_accept_req *req = cplhdr(skb);
  1362. unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
  1363. struct tid_info *t = dev->rdev.lldi.tids;
  1364. unsigned int hwtid = GET_TID(req);
  1365. struct neighbour *neigh;
  1366. struct dst_entry *dst;
  1367. struct l2t_entry *l2t;
  1368. struct rtable *rt;
  1369. __be32 local_ip, peer_ip;
  1370. __be16 local_port, peer_port;
  1371. struct net_device *pdev;
  1372. u32 tx_chan, smac_idx;
  1373. u16 rss_qid;
  1374. u32 mtu;
  1375. int step;
  1376. int txq_idx, ctrlq_idx;
  1377. parent_ep = lookup_stid(t, stid);
  1378. PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
  1379. get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
  1380. if (state_read(&parent_ep->com) != LISTEN) {
  1381. printk(KERN_ERR "%s - listening ep not in LISTEN\n",
  1382. __func__);
  1383. goto reject;
  1384. }
  1385. /* Find output route */
  1386. rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
  1387. GET_POPEN_TOS(ntohl(req->tos_stid)));
  1388. if (!rt) {
  1389. printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
  1390. __func__);
  1391. goto reject;
  1392. }
  1393. dst = &rt->dst;
  1394. neigh = dst_get_neighbour(dst);
  1395. if (neigh->dev->flags & IFF_LOOPBACK) {
  1396. pdev = ip_dev_find(&init_net, peer_ip);
  1397. BUG_ON(!pdev);
  1398. l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, pdev, 0);
  1399. mtu = pdev->mtu;
  1400. tx_chan = cxgb4_port_chan(pdev);
  1401. smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1402. step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
  1403. txq_idx = cxgb4_port_idx(pdev) * step;
  1404. ctrlq_idx = cxgb4_port_idx(pdev);
  1405. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  1406. rss_qid = dev->rdev.lldi.rxq_ids[cxgb4_port_idx(pdev) * step];
  1407. dev_put(pdev);
  1408. } else {
  1409. l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, neigh->dev, 0);
  1410. mtu = dst_mtu(dst);
  1411. tx_chan = cxgb4_port_chan(neigh->dev);
  1412. smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
  1413. step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
  1414. txq_idx = cxgb4_port_idx(neigh->dev) * step;
  1415. ctrlq_idx = cxgb4_port_idx(neigh->dev);
  1416. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  1417. rss_qid = dev->rdev.lldi.rxq_ids[
  1418. cxgb4_port_idx(neigh->dev) * step];
  1419. }
  1420. if (!l2t) {
  1421. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1422. __func__);
  1423. dst_release(dst);
  1424. goto reject;
  1425. }
  1426. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1427. if (!child_ep) {
  1428. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1429. __func__);
  1430. cxgb4_l2t_release(l2t);
  1431. dst_release(dst);
  1432. goto reject;
  1433. }
  1434. state_set(&child_ep->com, CONNECTING);
  1435. child_ep->com.dev = dev;
  1436. child_ep->com.cm_id = NULL;
  1437. child_ep->com.local_addr.sin_family = PF_INET;
  1438. child_ep->com.local_addr.sin_port = local_port;
  1439. child_ep->com.local_addr.sin_addr.s_addr = local_ip;
  1440. child_ep->com.remote_addr.sin_family = PF_INET;
  1441. child_ep->com.remote_addr.sin_port = peer_port;
  1442. child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
  1443. c4iw_get_ep(&parent_ep->com);
  1444. child_ep->parent_ep = parent_ep;
  1445. child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
  1446. child_ep->l2t = l2t;
  1447. child_ep->dst = dst;
  1448. child_ep->hwtid = hwtid;
  1449. child_ep->tx_chan = tx_chan;
  1450. child_ep->smac_idx = smac_idx;
  1451. child_ep->rss_qid = rss_qid;
  1452. child_ep->mtu = mtu;
  1453. child_ep->txq_idx = txq_idx;
  1454. child_ep->ctrlq_idx = ctrlq_idx;
  1455. PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
  1456. tx_chan, smac_idx, rss_qid);
  1457. init_timer(&child_ep->timer);
  1458. cxgb4_insert_tid(t, child_ep, hwtid);
  1459. accept_cr(child_ep, peer_ip, skb, req);
  1460. goto out;
  1461. reject:
  1462. reject_cr(dev, hwtid, peer_ip, skb);
  1463. out:
  1464. return 0;
  1465. }
  1466. static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  1467. {
  1468. struct c4iw_ep *ep;
  1469. struct cpl_pass_establish *req = cplhdr(skb);
  1470. struct tid_info *t = dev->rdev.lldi.tids;
  1471. unsigned int tid = GET_TID(req);
  1472. ep = lookup_tid(t, tid);
  1473. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1474. ep->snd_seq = be32_to_cpu(req->snd_isn);
  1475. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  1476. set_emss(ep, ntohs(req->tcp_opt));
  1477. dst_confirm(ep->dst);
  1478. state_set(&ep->com, MPA_REQ_WAIT);
  1479. start_ep_timer(ep);
  1480. send_flowc(ep, skb);
  1481. return 0;
  1482. }
  1483. static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
  1484. {
  1485. struct cpl_peer_close *hdr = cplhdr(skb);
  1486. struct c4iw_ep *ep;
  1487. struct c4iw_qp_attributes attrs;
  1488. int disconnect = 1;
  1489. int release = 0;
  1490. struct tid_info *t = dev->rdev.lldi.tids;
  1491. unsigned int tid = GET_TID(hdr);
  1492. int ret;
  1493. ep = lookup_tid(t, tid);
  1494. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1495. dst_confirm(ep->dst);
  1496. mutex_lock(&ep->com.mutex);
  1497. switch (ep->com.state) {
  1498. case MPA_REQ_WAIT:
  1499. __state_set(&ep->com, CLOSING);
  1500. break;
  1501. case MPA_REQ_SENT:
  1502. __state_set(&ep->com, CLOSING);
  1503. connect_reply_upcall(ep, -ECONNRESET);
  1504. break;
  1505. case MPA_REQ_RCVD:
  1506. /*
  1507. * We're gonna mark this puppy DEAD, but keep
  1508. * the reference on it until the ULP accepts or
  1509. * rejects the CR. Also wake up anyone waiting
  1510. * in rdma connection migration (see c4iw_accept_cr()).
  1511. */
  1512. __state_set(&ep->com, CLOSING);
  1513. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1514. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1515. break;
  1516. case MPA_REP_SENT:
  1517. __state_set(&ep->com, CLOSING);
  1518. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1519. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1520. break;
  1521. case FPDU_MODE:
  1522. start_ep_timer(ep);
  1523. __state_set(&ep->com, CLOSING);
  1524. attrs.next_state = C4IW_QP_STATE_CLOSING;
  1525. ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1526. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1527. if (ret != -ECONNRESET) {
  1528. peer_close_upcall(ep);
  1529. disconnect = 1;
  1530. }
  1531. break;
  1532. case ABORTING:
  1533. disconnect = 0;
  1534. break;
  1535. case CLOSING:
  1536. __state_set(&ep->com, MORIBUND);
  1537. disconnect = 0;
  1538. break;
  1539. case MORIBUND:
  1540. stop_ep_timer(ep);
  1541. if (ep->com.cm_id && ep->com.qp) {
  1542. attrs.next_state = C4IW_QP_STATE_IDLE;
  1543. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1544. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1545. }
  1546. close_complete_upcall(ep);
  1547. __state_set(&ep->com, DEAD);
  1548. release = 1;
  1549. disconnect = 0;
  1550. break;
  1551. case DEAD:
  1552. disconnect = 0;
  1553. break;
  1554. default:
  1555. BUG_ON(1);
  1556. }
  1557. mutex_unlock(&ep->com.mutex);
  1558. if (disconnect)
  1559. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1560. if (release)
  1561. release_ep_resources(ep);
  1562. return 0;
  1563. }
  1564. /*
  1565. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  1566. */
  1567. static int is_neg_adv_abort(unsigned int status)
  1568. {
  1569. return status == CPL_ERR_RTX_NEG_ADVICE ||
  1570. status == CPL_ERR_PERSIST_NEG_ADVICE;
  1571. }
  1572. static int c4iw_reconnect(struct c4iw_ep *ep)
  1573. {
  1574. int err = 0;
  1575. struct rtable *rt;
  1576. struct net_device *pdev;
  1577. struct neighbour *neigh;
  1578. int step;
  1579. PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
  1580. init_timer(&ep->timer);
  1581. /*
  1582. * Allocate an active TID to initiate a TCP connection.
  1583. */
  1584. ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
  1585. if (ep->atid == -1) {
  1586. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1587. err = -ENOMEM;
  1588. goto fail2;
  1589. }
  1590. /* find a route */
  1591. rt = find_route(ep->com.dev,
  1592. ep->com.cm_id->local_addr.sin_addr.s_addr,
  1593. ep->com.cm_id->remote_addr.sin_addr.s_addr,
  1594. ep->com.cm_id->local_addr.sin_port,
  1595. ep->com.cm_id->remote_addr.sin_port, 0);
  1596. if (!rt) {
  1597. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  1598. err = -EHOSTUNREACH;
  1599. goto fail3;
  1600. }
  1601. ep->dst = &rt->dst;
  1602. neigh = dst_get_neighbour(ep->dst);
  1603. /* get a l2t entry */
  1604. if (neigh->dev->flags & IFF_LOOPBACK) {
  1605. PDBG("%s LOOPBACK\n", __func__);
  1606. pdev = ip_dev_find(&init_net,
  1607. ep->com.cm_id->remote_addr.sin_addr.s_addr);
  1608. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  1609. neigh, pdev, 0);
  1610. ep->mtu = pdev->mtu;
  1611. ep->tx_chan = cxgb4_port_chan(pdev);
  1612. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1613. step = ep->com.dev->rdev.lldi.ntxq /
  1614. ep->com.dev->rdev.lldi.nchan;
  1615. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1616. step = ep->com.dev->rdev.lldi.nrxq /
  1617. ep->com.dev->rdev.lldi.nchan;
  1618. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  1619. ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
  1620. cxgb4_port_idx(pdev) * step];
  1621. dev_put(pdev);
  1622. } else {
  1623. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  1624. neigh, neigh->dev, 0);
  1625. ep->mtu = dst_mtu(ep->dst);
  1626. ep->tx_chan = cxgb4_port_chan(neigh->dev);
  1627. ep->smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
  1628. step = ep->com.dev->rdev.lldi.ntxq /
  1629. ep->com.dev->rdev.lldi.nchan;
  1630. ep->txq_idx = cxgb4_port_idx(neigh->dev) * step;
  1631. ep->ctrlq_idx = cxgb4_port_idx(neigh->dev);
  1632. step = ep->com.dev->rdev.lldi.nrxq /
  1633. ep->com.dev->rdev.lldi.nchan;
  1634. ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
  1635. cxgb4_port_idx(neigh->dev) * step];
  1636. }
  1637. if (!ep->l2t) {
  1638. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  1639. err = -ENOMEM;
  1640. goto fail4;
  1641. }
  1642. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  1643. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  1644. ep->l2t->idx);
  1645. state_set(&ep->com, CONNECTING);
  1646. ep->tos = 0;
  1647. /* send connect request to rnic */
  1648. err = send_connect(ep);
  1649. if (!err)
  1650. goto out;
  1651. cxgb4_l2t_release(ep->l2t);
  1652. fail4:
  1653. dst_release(ep->dst);
  1654. fail3:
  1655. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  1656. fail2:
  1657. /*
  1658. * remember to send notification to upper layer.
  1659. * We are in here so the upper layer is not aware that this is
  1660. * re-connect attempt and so, upper layer is still waiting for
  1661. * response of 1st connect request.
  1662. */
  1663. connect_reply_upcall(ep, -ECONNRESET);
  1664. c4iw_put_ep(&ep->com);
  1665. out:
  1666. return err;
  1667. }
  1668. static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
  1669. {
  1670. struct cpl_abort_req_rss *req = cplhdr(skb);
  1671. struct c4iw_ep *ep;
  1672. struct cpl_abort_rpl *rpl;
  1673. struct sk_buff *rpl_skb;
  1674. struct c4iw_qp_attributes attrs;
  1675. int ret;
  1676. int release = 0;
  1677. struct tid_info *t = dev->rdev.lldi.tids;
  1678. unsigned int tid = GET_TID(req);
  1679. ep = lookup_tid(t, tid);
  1680. if (is_neg_adv_abort(req->status)) {
  1681. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  1682. ep->hwtid);
  1683. return 0;
  1684. }
  1685. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  1686. ep->com.state);
  1687. /*
  1688. * Wake up any threads in rdma_init() or rdma_fini().
  1689. * However, this is not needed if com state is just
  1690. * MPA_REQ_SENT
  1691. */
  1692. if (ep->com.state != MPA_REQ_SENT)
  1693. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1694. mutex_lock(&ep->com.mutex);
  1695. switch (ep->com.state) {
  1696. case CONNECTING:
  1697. break;
  1698. case MPA_REQ_WAIT:
  1699. stop_ep_timer(ep);
  1700. break;
  1701. case MPA_REQ_SENT:
  1702. stop_ep_timer(ep);
  1703. if (mpa_rev == 2 && ep->tried_with_mpa_v1)
  1704. connect_reply_upcall(ep, -ECONNRESET);
  1705. else {
  1706. /*
  1707. * we just don't send notification upwards because we
  1708. * want to retry with mpa_v1 without upper layers even
  1709. * knowing it.
  1710. *
  1711. * do some housekeeping so as to re-initiate the
  1712. * connection
  1713. */
  1714. PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
  1715. mpa_rev);
  1716. ep->retry_with_mpa_v1 = 1;
  1717. }
  1718. break;
  1719. case MPA_REP_SENT:
  1720. break;
  1721. case MPA_REQ_RCVD:
  1722. break;
  1723. case MORIBUND:
  1724. case CLOSING:
  1725. stop_ep_timer(ep);
  1726. /*FALLTHROUGH*/
  1727. case FPDU_MODE:
  1728. if (ep->com.cm_id && ep->com.qp) {
  1729. attrs.next_state = C4IW_QP_STATE_ERROR;
  1730. ret = c4iw_modify_qp(ep->com.qp->rhp,
  1731. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  1732. &attrs, 1);
  1733. if (ret)
  1734. printk(KERN_ERR MOD
  1735. "%s - qp <- error failed!\n",
  1736. __func__);
  1737. }
  1738. peer_abort_upcall(ep);
  1739. break;
  1740. case ABORTING:
  1741. break;
  1742. case DEAD:
  1743. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1744. mutex_unlock(&ep->com.mutex);
  1745. return 0;
  1746. default:
  1747. BUG_ON(1);
  1748. break;
  1749. }
  1750. dst_confirm(ep->dst);
  1751. if (ep->com.state != ABORTING) {
  1752. __state_set(&ep->com, DEAD);
  1753. /* we don't release if we want to retry with mpa_v1 */
  1754. if (!ep->retry_with_mpa_v1)
  1755. release = 1;
  1756. }
  1757. mutex_unlock(&ep->com.mutex);
  1758. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1759. if (!rpl_skb) {
  1760. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  1761. __func__);
  1762. release = 1;
  1763. goto out;
  1764. }
  1765. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  1766. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  1767. INIT_TP_WR(rpl, ep->hwtid);
  1768. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  1769. rpl->cmd = CPL_ABORT_NO_RST;
  1770. c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
  1771. out:
  1772. if (release)
  1773. release_ep_resources(ep);
  1774. /* retry with mpa-v1 */
  1775. if (ep && ep->retry_with_mpa_v1) {
  1776. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  1777. dst_release(ep->dst);
  1778. cxgb4_l2t_release(ep->l2t);
  1779. c4iw_reconnect(ep);
  1780. }
  1781. return 0;
  1782. }
  1783. static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1784. {
  1785. struct c4iw_ep *ep;
  1786. struct c4iw_qp_attributes attrs;
  1787. struct cpl_close_con_rpl *rpl = cplhdr(skb);
  1788. int release = 0;
  1789. struct tid_info *t = dev->rdev.lldi.tids;
  1790. unsigned int tid = GET_TID(rpl);
  1791. ep = lookup_tid(t, tid);
  1792. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1793. BUG_ON(!ep);
  1794. /* The cm_id may be null if we failed to connect */
  1795. mutex_lock(&ep->com.mutex);
  1796. switch (ep->com.state) {
  1797. case CLOSING:
  1798. __state_set(&ep->com, MORIBUND);
  1799. break;
  1800. case MORIBUND:
  1801. stop_ep_timer(ep);
  1802. if ((ep->com.cm_id) && (ep->com.qp)) {
  1803. attrs.next_state = C4IW_QP_STATE_IDLE;
  1804. c4iw_modify_qp(ep->com.qp->rhp,
  1805. ep->com.qp,
  1806. C4IW_QP_ATTR_NEXT_STATE,
  1807. &attrs, 1);
  1808. }
  1809. close_complete_upcall(ep);
  1810. __state_set(&ep->com, DEAD);
  1811. release = 1;
  1812. break;
  1813. case ABORTING:
  1814. case DEAD:
  1815. break;
  1816. default:
  1817. BUG_ON(1);
  1818. break;
  1819. }
  1820. mutex_unlock(&ep->com.mutex);
  1821. if (release)
  1822. release_ep_resources(ep);
  1823. return 0;
  1824. }
  1825. static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
  1826. {
  1827. struct cpl_rdma_terminate *rpl = cplhdr(skb);
  1828. struct tid_info *t = dev->rdev.lldi.tids;
  1829. unsigned int tid = GET_TID(rpl);
  1830. struct c4iw_ep *ep;
  1831. struct c4iw_qp_attributes attrs;
  1832. ep = lookup_tid(t, tid);
  1833. BUG_ON(!ep);
  1834. if (ep && ep->com.qp) {
  1835. printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
  1836. ep->com.qp->wq.sq.qid);
  1837. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1838. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1839. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1840. } else
  1841. printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
  1842. return 0;
  1843. }
  1844. /*
  1845. * Upcall from the adapter indicating data has been transmitted.
  1846. * For us its just the single MPA request or reply. We can now free
  1847. * the skb holding the mpa message.
  1848. */
  1849. static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
  1850. {
  1851. struct c4iw_ep *ep;
  1852. struct cpl_fw4_ack *hdr = cplhdr(skb);
  1853. u8 credits = hdr->credits;
  1854. unsigned int tid = GET_TID(hdr);
  1855. struct tid_info *t = dev->rdev.lldi.tids;
  1856. ep = lookup_tid(t, tid);
  1857. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  1858. if (credits == 0) {
  1859. PDBG("%s 0 credit ack ep %p tid %u state %u\n",
  1860. __func__, ep, ep->hwtid, state_read(&ep->com));
  1861. return 0;
  1862. }
  1863. dst_confirm(ep->dst);
  1864. if (ep->mpa_skb) {
  1865. PDBG("%s last streaming msg ack ep %p tid %u state %u "
  1866. "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
  1867. state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
  1868. kfree_skb(ep->mpa_skb);
  1869. ep->mpa_skb = NULL;
  1870. }
  1871. return 0;
  1872. }
  1873. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  1874. {
  1875. int err;
  1876. struct c4iw_ep *ep = to_ep(cm_id);
  1877. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1878. if (state_read(&ep->com) == DEAD) {
  1879. c4iw_put_ep(&ep->com);
  1880. return -ECONNRESET;
  1881. }
  1882. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1883. if (mpa_rev == 0)
  1884. abort_connection(ep, NULL, GFP_KERNEL);
  1885. else {
  1886. err = send_mpa_reject(ep, pdata, pdata_len);
  1887. err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1888. }
  1889. c4iw_put_ep(&ep->com);
  1890. return 0;
  1891. }
  1892. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1893. {
  1894. int err;
  1895. struct c4iw_qp_attributes attrs;
  1896. enum c4iw_qp_attr_mask mask;
  1897. struct c4iw_ep *ep = to_ep(cm_id);
  1898. struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
  1899. struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
  1900. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1901. if (state_read(&ep->com) == DEAD) {
  1902. err = -ECONNRESET;
  1903. goto err;
  1904. }
  1905. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1906. BUG_ON(!qp);
  1907. if ((conn_param->ord > c4iw_max_read_depth) ||
  1908. (conn_param->ird > c4iw_max_read_depth)) {
  1909. abort_connection(ep, NULL, GFP_KERNEL);
  1910. err = -EINVAL;
  1911. goto err;
  1912. }
  1913. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  1914. if (conn_param->ord > ep->ird) {
  1915. ep->ird = conn_param->ird;
  1916. ep->ord = conn_param->ord;
  1917. send_mpa_reject(ep, conn_param->private_data,
  1918. conn_param->private_data_len);
  1919. abort_connection(ep, NULL, GFP_KERNEL);
  1920. err = -ENOMEM;
  1921. goto err;
  1922. }
  1923. if (conn_param->ird > ep->ord) {
  1924. if (!ep->ord)
  1925. conn_param->ird = 1;
  1926. else {
  1927. abort_connection(ep, NULL, GFP_KERNEL);
  1928. err = -ENOMEM;
  1929. goto err;
  1930. }
  1931. }
  1932. }
  1933. ep->ird = conn_param->ird;
  1934. ep->ord = conn_param->ord;
  1935. if (ep->mpa_attr.version != 2)
  1936. if (peer2peer && ep->ird == 0)
  1937. ep->ird = 1;
  1938. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  1939. cm_id->add_ref(cm_id);
  1940. ep->com.cm_id = cm_id;
  1941. ep->com.qp = qp;
  1942. /* bind QP to EP and move to RTS */
  1943. attrs.mpa_attr = ep->mpa_attr;
  1944. attrs.max_ird = ep->ird;
  1945. attrs.max_ord = ep->ord;
  1946. attrs.llp_stream_handle = ep;
  1947. attrs.next_state = C4IW_QP_STATE_RTS;
  1948. /* bind QP and TID with INIT_WR */
  1949. mask = C4IW_QP_ATTR_NEXT_STATE |
  1950. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  1951. C4IW_QP_ATTR_MPA_ATTR |
  1952. C4IW_QP_ATTR_MAX_IRD |
  1953. C4IW_QP_ATTR_MAX_ORD;
  1954. err = c4iw_modify_qp(ep->com.qp->rhp,
  1955. ep->com.qp, mask, &attrs, 1);
  1956. if (err)
  1957. goto err1;
  1958. err = send_mpa_reply(ep, conn_param->private_data,
  1959. conn_param->private_data_len);
  1960. if (err)
  1961. goto err1;
  1962. state_set(&ep->com, FPDU_MODE);
  1963. established_upcall(ep);
  1964. c4iw_put_ep(&ep->com);
  1965. return 0;
  1966. err1:
  1967. ep->com.cm_id = NULL;
  1968. ep->com.qp = NULL;
  1969. cm_id->rem_ref(cm_id);
  1970. err:
  1971. c4iw_put_ep(&ep->com);
  1972. return err;
  1973. }
  1974. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1975. {
  1976. int err = 0;
  1977. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  1978. struct c4iw_ep *ep;
  1979. struct rtable *rt;
  1980. struct net_device *pdev;
  1981. struct neighbour *neigh;
  1982. int step;
  1983. if ((conn_param->ord > c4iw_max_read_depth) ||
  1984. (conn_param->ird > c4iw_max_read_depth)) {
  1985. err = -EINVAL;
  1986. goto out;
  1987. }
  1988. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1989. if (!ep) {
  1990. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1991. err = -ENOMEM;
  1992. goto out;
  1993. }
  1994. init_timer(&ep->timer);
  1995. ep->plen = conn_param->private_data_len;
  1996. if (ep->plen)
  1997. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  1998. conn_param->private_data, ep->plen);
  1999. ep->ird = conn_param->ird;
  2000. ep->ord = conn_param->ord;
  2001. if (peer2peer && ep->ord == 0)
  2002. ep->ord = 1;
  2003. cm_id->add_ref(cm_id);
  2004. ep->com.dev = dev;
  2005. ep->com.cm_id = cm_id;
  2006. ep->com.qp = get_qhp(dev, conn_param->qpn);
  2007. BUG_ON(!ep->com.qp);
  2008. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  2009. ep->com.qp, cm_id);
  2010. /*
  2011. * Allocate an active TID to initiate a TCP connection.
  2012. */
  2013. ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
  2014. if (ep->atid == -1) {
  2015. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  2016. err = -ENOMEM;
  2017. goto fail2;
  2018. }
  2019. PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
  2020. ntohl(cm_id->local_addr.sin_addr.s_addr),
  2021. ntohs(cm_id->local_addr.sin_port),
  2022. ntohl(cm_id->remote_addr.sin_addr.s_addr),
  2023. ntohs(cm_id->remote_addr.sin_port));
  2024. /* find a route */
  2025. rt = find_route(dev,
  2026. cm_id->local_addr.sin_addr.s_addr,
  2027. cm_id->remote_addr.sin_addr.s_addr,
  2028. cm_id->local_addr.sin_port,
  2029. cm_id->remote_addr.sin_port, 0);
  2030. if (!rt) {
  2031. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  2032. err = -EHOSTUNREACH;
  2033. goto fail3;
  2034. }
  2035. ep->dst = &rt->dst;
  2036. neigh = dst_get_neighbour(ep->dst);
  2037. /* get a l2t entry */
  2038. if (neigh->dev->flags & IFF_LOOPBACK) {
  2039. PDBG("%s LOOPBACK\n", __func__);
  2040. pdev = ip_dev_find(&init_net,
  2041. cm_id->remote_addr.sin_addr.s_addr);
  2042. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  2043. neigh, pdev, 0);
  2044. ep->mtu = pdev->mtu;
  2045. ep->tx_chan = cxgb4_port_chan(pdev);
  2046. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  2047. step = ep->com.dev->rdev.lldi.ntxq /
  2048. ep->com.dev->rdev.lldi.nchan;
  2049. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  2050. step = ep->com.dev->rdev.lldi.nrxq /
  2051. ep->com.dev->rdev.lldi.nchan;
  2052. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  2053. ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
  2054. cxgb4_port_idx(pdev) * step];
  2055. dev_put(pdev);
  2056. } else {
  2057. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  2058. neigh, neigh->dev, 0);
  2059. ep->mtu = dst_mtu(ep->dst);
  2060. ep->tx_chan = cxgb4_port_chan(neigh->dev);
  2061. ep->smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
  2062. step = ep->com.dev->rdev.lldi.ntxq /
  2063. ep->com.dev->rdev.lldi.nchan;
  2064. ep->txq_idx = cxgb4_port_idx(neigh->dev) * step;
  2065. ep->ctrlq_idx = cxgb4_port_idx(neigh->dev);
  2066. step = ep->com.dev->rdev.lldi.nrxq /
  2067. ep->com.dev->rdev.lldi.nchan;
  2068. ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
  2069. cxgb4_port_idx(neigh->dev) * step];
  2070. ep->retry_with_mpa_v1 = 0;
  2071. ep->tried_with_mpa_v1 = 0;
  2072. }
  2073. if (!ep->l2t) {
  2074. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  2075. err = -ENOMEM;
  2076. goto fail4;
  2077. }
  2078. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  2079. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  2080. ep->l2t->idx);
  2081. state_set(&ep->com, CONNECTING);
  2082. ep->tos = 0;
  2083. ep->com.local_addr = cm_id->local_addr;
  2084. ep->com.remote_addr = cm_id->remote_addr;
  2085. /* send connect request to rnic */
  2086. err = send_connect(ep);
  2087. if (!err)
  2088. goto out;
  2089. cxgb4_l2t_release(ep->l2t);
  2090. fail4:
  2091. dst_release(ep->dst);
  2092. fail3:
  2093. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  2094. fail2:
  2095. cm_id->rem_ref(cm_id);
  2096. c4iw_put_ep(&ep->com);
  2097. out:
  2098. return err;
  2099. }
  2100. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
  2101. {
  2102. int err = 0;
  2103. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2104. struct c4iw_listen_ep *ep;
  2105. might_sleep();
  2106. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2107. if (!ep) {
  2108. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2109. err = -ENOMEM;
  2110. goto fail1;
  2111. }
  2112. PDBG("%s ep %p\n", __func__, ep);
  2113. cm_id->add_ref(cm_id);
  2114. ep->com.cm_id = cm_id;
  2115. ep->com.dev = dev;
  2116. ep->backlog = backlog;
  2117. ep->com.local_addr = cm_id->local_addr;
  2118. /*
  2119. * Allocate a server TID.
  2120. */
  2121. ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
  2122. if (ep->stid == -1) {
  2123. printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
  2124. err = -ENOMEM;
  2125. goto fail2;
  2126. }
  2127. state_set(&ep->com, LISTEN);
  2128. c4iw_init_wr_wait(&ep->com.wr_wait);
  2129. err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2130. ep->com.local_addr.sin_addr.s_addr,
  2131. ep->com.local_addr.sin_port,
  2132. ep->com.dev->rdev.lldi.rxq_ids[0]);
  2133. if (err)
  2134. goto fail3;
  2135. /* wait for pass_open_rpl */
  2136. err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
  2137. __func__);
  2138. if (!err) {
  2139. cm_id->provider_data = ep;
  2140. goto out;
  2141. }
  2142. fail3:
  2143. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  2144. fail2:
  2145. cm_id->rem_ref(cm_id);
  2146. c4iw_put_ep(&ep->com);
  2147. fail1:
  2148. out:
  2149. return err;
  2150. }
  2151. int c4iw_destroy_listen(struct iw_cm_id *cm_id)
  2152. {
  2153. int err;
  2154. struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
  2155. PDBG("%s ep %p\n", __func__, ep);
  2156. might_sleep();
  2157. state_set(&ep->com, DEAD);
  2158. c4iw_init_wr_wait(&ep->com.wr_wait);
  2159. err = listen_stop(ep);
  2160. if (err)
  2161. goto done;
  2162. err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
  2163. __func__);
  2164. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  2165. done:
  2166. cm_id->rem_ref(cm_id);
  2167. c4iw_put_ep(&ep->com);
  2168. return err;
  2169. }
  2170. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
  2171. {
  2172. int ret = 0;
  2173. int close = 0;
  2174. int fatal = 0;
  2175. struct c4iw_rdev *rdev;
  2176. mutex_lock(&ep->com.mutex);
  2177. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  2178. states[ep->com.state], abrupt);
  2179. rdev = &ep->com.dev->rdev;
  2180. if (c4iw_fatal_error(rdev)) {
  2181. fatal = 1;
  2182. close_complete_upcall(ep);
  2183. ep->com.state = DEAD;
  2184. }
  2185. switch (ep->com.state) {
  2186. case MPA_REQ_WAIT:
  2187. case MPA_REQ_SENT:
  2188. case MPA_REQ_RCVD:
  2189. case MPA_REP_SENT:
  2190. case FPDU_MODE:
  2191. close = 1;
  2192. if (abrupt)
  2193. ep->com.state = ABORTING;
  2194. else {
  2195. ep->com.state = CLOSING;
  2196. start_ep_timer(ep);
  2197. }
  2198. set_bit(CLOSE_SENT, &ep->com.flags);
  2199. break;
  2200. case CLOSING:
  2201. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  2202. close = 1;
  2203. if (abrupt) {
  2204. stop_ep_timer(ep);
  2205. ep->com.state = ABORTING;
  2206. } else
  2207. ep->com.state = MORIBUND;
  2208. }
  2209. break;
  2210. case MORIBUND:
  2211. case ABORTING:
  2212. case DEAD:
  2213. PDBG("%s ignoring disconnect ep %p state %u\n",
  2214. __func__, ep, ep->com.state);
  2215. break;
  2216. default:
  2217. BUG();
  2218. break;
  2219. }
  2220. if (close) {
  2221. if (abrupt) {
  2222. close_complete_upcall(ep);
  2223. ret = send_abort(ep, NULL, gfp);
  2224. } else
  2225. ret = send_halfclose(ep, gfp);
  2226. if (ret)
  2227. fatal = 1;
  2228. }
  2229. mutex_unlock(&ep->com.mutex);
  2230. if (fatal)
  2231. release_ep_resources(ep);
  2232. return ret;
  2233. }
  2234. static int async_event(struct c4iw_dev *dev, struct sk_buff *skb)
  2235. {
  2236. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2237. c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
  2238. return 0;
  2239. }
  2240. /*
  2241. * These are the real handlers that are called from a
  2242. * work queue.
  2243. */
  2244. static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
  2245. [CPL_ACT_ESTABLISH] = act_establish,
  2246. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  2247. [CPL_RX_DATA] = rx_data,
  2248. [CPL_ABORT_RPL_RSS] = abort_rpl,
  2249. [CPL_ABORT_RPL] = abort_rpl,
  2250. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  2251. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  2252. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  2253. [CPL_PASS_ESTABLISH] = pass_establish,
  2254. [CPL_PEER_CLOSE] = peer_close,
  2255. [CPL_ABORT_REQ_RSS] = peer_abort,
  2256. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  2257. [CPL_RDMA_TERMINATE] = terminate,
  2258. [CPL_FW4_ACK] = fw4_ack,
  2259. [CPL_FW6_MSG] = async_event
  2260. };
  2261. static void process_timeout(struct c4iw_ep *ep)
  2262. {
  2263. struct c4iw_qp_attributes attrs;
  2264. int abort = 1;
  2265. mutex_lock(&ep->com.mutex);
  2266. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  2267. ep->com.state);
  2268. switch (ep->com.state) {
  2269. case MPA_REQ_SENT:
  2270. __state_set(&ep->com, ABORTING);
  2271. connect_reply_upcall(ep, -ETIMEDOUT);
  2272. break;
  2273. case MPA_REQ_WAIT:
  2274. __state_set(&ep->com, ABORTING);
  2275. break;
  2276. case CLOSING:
  2277. case MORIBUND:
  2278. if (ep->com.cm_id && ep->com.qp) {
  2279. attrs.next_state = C4IW_QP_STATE_ERROR;
  2280. c4iw_modify_qp(ep->com.qp->rhp,
  2281. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  2282. &attrs, 1);
  2283. }
  2284. __state_set(&ep->com, ABORTING);
  2285. break;
  2286. default:
  2287. printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n",
  2288. __func__, ep, ep->hwtid, ep->com.state);
  2289. WARN_ON(1);
  2290. abort = 0;
  2291. }
  2292. mutex_unlock(&ep->com.mutex);
  2293. if (abort)
  2294. abort_connection(ep, NULL, GFP_KERNEL);
  2295. c4iw_put_ep(&ep->com);
  2296. }
  2297. static void process_timedout_eps(void)
  2298. {
  2299. struct c4iw_ep *ep;
  2300. spin_lock_irq(&timeout_lock);
  2301. while (!list_empty(&timeout_list)) {
  2302. struct list_head *tmp;
  2303. tmp = timeout_list.next;
  2304. list_del(tmp);
  2305. spin_unlock_irq(&timeout_lock);
  2306. ep = list_entry(tmp, struct c4iw_ep, entry);
  2307. process_timeout(ep);
  2308. spin_lock_irq(&timeout_lock);
  2309. }
  2310. spin_unlock_irq(&timeout_lock);
  2311. }
  2312. static void process_work(struct work_struct *work)
  2313. {
  2314. struct sk_buff *skb = NULL;
  2315. struct c4iw_dev *dev;
  2316. struct cpl_act_establish *rpl;
  2317. unsigned int opcode;
  2318. int ret;
  2319. while ((skb = skb_dequeue(&rxq))) {
  2320. rpl = cplhdr(skb);
  2321. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  2322. opcode = rpl->ot.opcode;
  2323. BUG_ON(!work_handlers[opcode]);
  2324. ret = work_handlers[opcode](dev, skb);
  2325. if (!ret)
  2326. kfree_skb(skb);
  2327. }
  2328. process_timedout_eps();
  2329. }
  2330. static DECLARE_WORK(skb_work, process_work);
  2331. static void ep_timeout(unsigned long arg)
  2332. {
  2333. struct c4iw_ep *ep = (struct c4iw_ep *)arg;
  2334. spin_lock(&timeout_lock);
  2335. list_add_tail(&ep->entry, &timeout_list);
  2336. spin_unlock(&timeout_lock);
  2337. queue_work(workq, &skb_work);
  2338. }
  2339. /*
  2340. * All the CM events are handled on a work queue to have a safe context.
  2341. */
  2342. static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
  2343. {
  2344. /*
  2345. * Save dev in the skb->cb area.
  2346. */
  2347. *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
  2348. /*
  2349. * Queue the skb and schedule the worker thread.
  2350. */
  2351. skb_queue_tail(&rxq, skb);
  2352. queue_work(workq, &skb_work);
  2353. return 0;
  2354. }
  2355. static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2356. {
  2357. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  2358. if (rpl->status != CPL_ERR_NONE) {
  2359. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  2360. "for tid %u\n", rpl->status, GET_TID(rpl));
  2361. }
  2362. kfree_skb(skb);
  2363. return 0;
  2364. }
  2365. static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  2366. {
  2367. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2368. struct c4iw_wr_wait *wr_waitp;
  2369. int ret;
  2370. PDBG("%s type %u\n", __func__, rpl->type);
  2371. switch (rpl->type) {
  2372. case 1:
  2373. ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
  2374. wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
  2375. PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
  2376. if (wr_waitp)
  2377. c4iw_wake_up(wr_waitp, ret ? -ret : 0);
  2378. kfree_skb(skb);
  2379. break;
  2380. case 2:
  2381. sched(dev, skb);
  2382. break;
  2383. default:
  2384. printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
  2385. rpl->type);
  2386. kfree_skb(skb);
  2387. break;
  2388. }
  2389. return 0;
  2390. }
  2391. static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
  2392. {
  2393. struct cpl_abort_req_rss *req = cplhdr(skb);
  2394. struct c4iw_ep *ep;
  2395. struct tid_info *t = dev->rdev.lldi.tids;
  2396. unsigned int tid = GET_TID(req);
  2397. ep = lookup_tid(t, tid);
  2398. if (is_neg_adv_abort(req->status)) {
  2399. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  2400. ep->hwtid);
  2401. kfree_skb(skb);
  2402. return 0;
  2403. }
  2404. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  2405. ep->com.state);
  2406. /*
  2407. * Wake up any threads in rdma_init() or rdma_fini().
  2408. * However, this is not needed if com state is just
  2409. * MPA_REQ_SENT
  2410. */
  2411. if (ep->com.state != MPA_REQ_SENT)
  2412. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2413. sched(dev, skb);
  2414. return 0;
  2415. }
  2416. /*
  2417. * Most upcalls from the T4 Core go to sched() to
  2418. * schedule the processing on a work queue.
  2419. */
  2420. c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
  2421. [CPL_ACT_ESTABLISH] = sched,
  2422. [CPL_ACT_OPEN_RPL] = sched,
  2423. [CPL_RX_DATA] = sched,
  2424. [CPL_ABORT_RPL_RSS] = sched,
  2425. [CPL_ABORT_RPL] = sched,
  2426. [CPL_PASS_OPEN_RPL] = sched,
  2427. [CPL_CLOSE_LISTSRV_RPL] = sched,
  2428. [CPL_PASS_ACCEPT_REQ] = sched,
  2429. [CPL_PASS_ESTABLISH] = sched,
  2430. [CPL_PEER_CLOSE] = sched,
  2431. [CPL_CLOSE_CON_RPL] = sched,
  2432. [CPL_ABORT_REQ_RSS] = peer_abort_intr,
  2433. [CPL_RDMA_TERMINATE] = sched,
  2434. [CPL_FW4_ACK] = sched,
  2435. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  2436. [CPL_FW6_MSG] = fw6_msg
  2437. };
  2438. int __init c4iw_cm_init(void)
  2439. {
  2440. spin_lock_init(&timeout_lock);
  2441. skb_queue_head_init(&rxq);
  2442. workq = create_singlethread_workqueue("iw_cxgb4");
  2443. if (!workq)
  2444. return -ENOMEM;
  2445. return 0;
  2446. }
  2447. void __exit c4iw_cm_term(void)
  2448. {
  2449. WARN_ON(!list_empty(&timeout_list));
  2450. flush_workqueue(workq);
  2451. destroy_workqueue(workq);
  2452. }