iwch_cm.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  1. /*
  2. * Copyright (c) 2006 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/slab.h>
  35. #include <linux/workqueue.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/timer.h>
  38. #include <linux/notifier.h>
  39. #include <linux/inetdevice.h>
  40. #include <net/neighbour.h>
  41. #include <net/netevent.h>
  42. #include <net/route.h>
  43. #include "tcb.h"
  44. #include "cxgb3_offload.h"
  45. #include "iwch.h"
  46. #include "iwch_provider.h"
  47. #include "iwch_cm.h"
  48. static char *states[] = {
  49. "idle",
  50. "listen",
  51. "connecting",
  52. "mpa_wait_req",
  53. "mpa_req_sent",
  54. "mpa_req_rcvd",
  55. "mpa_rep_sent",
  56. "fpdu_mode",
  57. "aborting",
  58. "closing",
  59. "moribund",
  60. "dead",
  61. NULL,
  62. };
  63. int peer2peer = 0;
  64. module_param(peer2peer, int, 0644);
  65. MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
  66. static int ep_timeout_secs = 60;
  67. module_param(ep_timeout_secs, int, 0644);
  68. MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
  69. "in seconds (default=60)");
  70. static int mpa_rev = 1;
  71. module_param(mpa_rev, int, 0644);
  72. MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
  73. "1 is spec compliant. (default=1)");
  74. static int markers_enabled = 0;
  75. module_param(markers_enabled, int, 0644);
  76. MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
  77. static int crc_enabled = 1;
  78. module_param(crc_enabled, int, 0644);
  79. MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
  80. static int rcv_win = 256 * 1024;
  81. module_param(rcv_win, int, 0644);
  82. MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256)");
  83. static int snd_win = 32 * 1024;
  84. module_param(snd_win, int, 0644);
  85. MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=32KB)");
  86. static unsigned int nocong = 0;
  87. module_param(nocong, uint, 0644);
  88. MODULE_PARM_DESC(nocong, "Turn off congestion control (default=0)");
  89. static unsigned int cong_flavor = 1;
  90. module_param(cong_flavor, uint, 0644);
  91. MODULE_PARM_DESC(cong_flavor, "TCP Congestion control flavor (default=1)");
  92. static struct workqueue_struct *workq;
  93. static struct sk_buff_head rxq;
  94. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
  95. static void ep_timeout(unsigned long arg);
  96. static void connect_reply_upcall(struct iwch_ep *ep, int status);
  97. static void start_ep_timer(struct iwch_ep *ep)
  98. {
  99. PDBG("%s ep %p\n", __func__, ep);
  100. if (timer_pending(&ep->timer)) {
  101. PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
  102. del_timer_sync(&ep->timer);
  103. } else
  104. get_ep(&ep->com);
  105. ep->timer.expires = jiffies + ep_timeout_secs * HZ;
  106. ep->timer.data = (unsigned long)ep;
  107. ep->timer.function = ep_timeout;
  108. add_timer(&ep->timer);
  109. }
  110. static void stop_ep_timer(struct iwch_ep *ep)
  111. {
  112. PDBG("%s ep %p\n", __func__, ep);
  113. if (!timer_pending(&ep->timer)) {
  114. printk(KERN_ERR "%s timer stopped when its not running! ep %p state %u\n",
  115. __func__, ep, ep->com.state);
  116. WARN_ON(1);
  117. return;
  118. }
  119. del_timer_sync(&ep->timer);
  120. put_ep(&ep->com);
  121. }
  122. static int iwch_l2t_send(struct t3cdev *tdev, struct sk_buff *skb, struct l2t_entry *l2e)
  123. {
  124. int error = 0;
  125. struct cxio_rdev *rdev;
  126. rdev = (struct cxio_rdev *)tdev->ulp;
  127. if (cxio_fatal_error(rdev)) {
  128. kfree_skb(skb);
  129. return -EIO;
  130. }
  131. error = l2t_send(tdev, skb, l2e);
  132. if (error < 0)
  133. kfree_skb(skb);
  134. return error;
  135. }
  136. int iwch_cxgb3_ofld_send(struct t3cdev *tdev, struct sk_buff *skb)
  137. {
  138. int error = 0;
  139. struct cxio_rdev *rdev;
  140. rdev = (struct cxio_rdev *)tdev->ulp;
  141. if (cxio_fatal_error(rdev)) {
  142. kfree_skb(skb);
  143. return -EIO;
  144. }
  145. error = cxgb3_ofld_send(tdev, skb);
  146. if (error < 0)
  147. kfree_skb(skb);
  148. return error;
  149. }
  150. static void release_tid(struct t3cdev *tdev, u32 hwtid, struct sk_buff *skb)
  151. {
  152. struct cpl_tid_release *req;
  153. skb = get_skb(skb, sizeof *req, GFP_KERNEL);
  154. if (!skb)
  155. return;
  156. req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
  157. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  158. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
  159. skb->priority = CPL_PRIORITY_SETUP;
  160. iwch_cxgb3_ofld_send(tdev, skb);
  161. return;
  162. }
  163. int iwch_quiesce_tid(struct iwch_ep *ep)
  164. {
  165. struct cpl_set_tcb_field *req;
  166. struct sk_buff *skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  167. if (!skb)
  168. return -ENOMEM;
  169. req = (struct cpl_set_tcb_field *) skb_put(skb, sizeof(*req));
  170. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  171. req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  172. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, ep->hwtid));
  173. req->reply = 0;
  174. req->cpu_idx = 0;
  175. req->word = htons(W_TCB_RX_QUIESCE);
  176. req->mask = cpu_to_be64(1ULL << S_TCB_RX_QUIESCE);
  177. req->val = cpu_to_be64(1 << S_TCB_RX_QUIESCE);
  178. skb->priority = CPL_PRIORITY_DATA;
  179. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  180. }
  181. int iwch_resume_tid(struct iwch_ep *ep)
  182. {
  183. struct cpl_set_tcb_field *req;
  184. struct sk_buff *skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  185. if (!skb)
  186. return -ENOMEM;
  187. req = (struct cpl_set_tcb_field *) skb_put(skb, sizeof(*req));
  188. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  189. req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  190. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, ep->hwtid));
  191. req->reply = 0;
  192. req->cpu_idx = 0;
  193. req->word = htons(W_TCB_RX_QUIESCE);
  194. req->mask = cpu_to_be64(1ULL << S_TCB_RX_QUIESCE);
  195. req->val = 0;
  196. skb->priority = CPL_PRIORITY_DATA;
  197. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  198. }
  199. static void set_emss(struct iwch_ep *ep, u16 opt)
  200. {
  201. PDBG("%s ep %p opt %u\n", __func__, ep, opt);
  202. ep->emss = T3C_DATA(ep->com.tdev)->mtus[G_TCPOPT_MSS(opt)] - 40;
  203. if (G_TCPOPT_TSTAMP(opt))
  204. ep->emss -= 12;
  205. if (ep->emss < 128)
  206. ep->emss = 128;
  207. PDBG("emss=%d\n", ep->emss);
  208. }
  209. static enum iwch_ep_state state_read(struct iwch_ep_common *epc)
  210. {
  211. unsigned long flags;
  212. enum iwch_ep_state state;
  213. spin_lock_irqsave(&epc->lock, flags);
  214. state = epc->state;
  215. spin_unlock_irqrestore(&epc->lock, flags);
  216. return state;
  217. }
  218. static void __state_set(struct iwch_ep_common *epc, enum iwch_ep_state new)
  219. {
  220. epc->state = new;
  221. }
  222. static void state_set(struct iwch_ep_common *epc, enum iwch_ep_state new)
  223. {
  224. unsigned long flags;
  225. spin_lock_irqsave(&epc->lock, flags);
  226. PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
  227. __state_set(epc, new);
  228. spin_unlock_irqrestore(&epc->lock, flags);
  229. return;
  230. }
  231. static void *alloc_ep(int size, gfp_t gfp)
  232. {
  233. struct iwch_ep_common *epc;
  234. epc = kzalloc(size, gfp);
  235. if (epc) {
  236. kref_init(&epc->kref);
  237. spin_lock_init(&epc->lock);
  238. init_waitqueue_head(&epc->waitq);
  239. }
  240. PDBG("%s alloc ep %p\n", __func__, epc);
  241. return epc;
  242. }
  243. void __free_ep(struct kref *kref)
  244. {
  245. struct iwch_ep *ep;
  246. ep = container_of(container_of(kref, struct iwch_ep_common, kref),
  247. struct iwch_ep, com);
  248. PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
  249. if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
  250. cxgb3_remove_tid(ep->com.tdev, (void *)ep, ep->hwtid);
  251. dst_release(ep->dst);
  252. l2t_release(ep->com.tdev, ep->l2t);
  253. }
  254. kfree(ep);
  255. }
  256. static void release_ep_resources(struct iwch_ep *ep)
  257. {
  258. PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
  259. set_bit(RELEASE_RESOURCES, &ep->com.flags);
  260. put_ep(&ep->com);
  261. }
  262. static int status2errno(int status)
  263. {
  264. switch (status) {
  265. case CPL_ERR_NONE:
  266. return 0;
  267. case CPL_ERR_CONN_RESET:
  268. return -ECONNRESET;
  269. case CPL_ERR_ARP_MISS:
  270. return -EHOSTUNREACH;
  271. case CPL_ERR_CONN_TIMEDOUT:
  272. return -ETIMEDOUT;
  273. case CPL_ERR_TCAM_FULL:
  274. return -ENOMEM;
  275. case CPL_ERR_CONN_EXIST:
  276. return -EADDRINUSE;
  277. default:
  278. return -EIO;
  279. }
  280. }
  281. /*
  282. * Try and reuse skbs already allocated...
  283. */
  284. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
  285. {
  286. if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
  287. skb_trim(skb, 0);
  288. skb_get(skb);
  289. } else {
  290. skb = alloc_skb(len, gfp);
  291. }
  292. return skb;
  293. }
  294. static struct rtable *find_route(struct t3cdev *dev, __be32 local_ip,
  295. __be32 peer_ip, __be16 local_port,
  296. __be16 peer_port, u8 tos)
  297. {
  298. struct rtable *rt;
  299. struct flowi4 fl4;
  300. rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
  301. peer_port, local_port, IPPROTO_TCP,
  302. tos, 0);
  303. if (IS_ERR(rt))
  304. return NULL;
  305. return rt;
  306. }
  307. static unsigned int find_best_mtu(const struct t3c_data *d, unsigned short mtu)
  308. {
  309. int i = 0;
  310. while (i < d->nmtus - 1 && d->mtus[i + 1] <= mtu)
  311. ++i;
  312. return i;
  313. }
  314. static void arp_failure_discard(struct t3cdev *dev, struct sk_buff *skb)
  315. {
  316. PDBG("%s t3cdev %p\n", __func__, dev);
  317. kfree_skb(skb);
  318. }
  319. /*
  320. * Handle an ARP failure for an active open.
  321. */
  322. static void act_open_req_arp_failure(struct t3cdev *dev, struct sk_buff *skb)
  323. {
  324. printk(KERN_ERR MOD "ARP failure duing connect\n");
  325. kfree_skb(skb);
  326. }
  327. /*
  328. * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
  329. * and send it along.
  330. */
  331. static void abort_arp_failure(struct t3cdev *dev, struct sk_buff *skb)
  332. {
  333. struct cpl_abort_req *req = cplhdr(skb);
  334. PDBG("%s t3cdev %p\n", __func__, dev);
  335. req->cmd = CPL_ABORT_NO_RST;
  336. iwch_cxgb3_ofld_send(dev, skb);
  337. }
  338. static int send_halfclose(struct iwch_ep *ep, gfp_t gfp)
  339. {
  340. struct cpl_close_con_req *req;
  341. struct sk_buff *skb;
  342. PDBG("%s ep %p\n", __func__, ep);
  343. skb = get_skb(NULL, sizeof(*req), gfp);
  344. if (!skb) {
  345. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  346. return -ENOMEM;
  347. }
  348. skb->priority = CPL_PRIORITY_DATA;
  349. set_arp_failure_handler(skb, arp_failure_discard);
  350. req = (struct cpl_close_con_req *) skb_put(skb, sizeof(*req));
  351. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_CLOSE_CON));
  352. req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  353. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, ep->hwtid));
  354. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  355. }
  356. static int send_abort(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp)
  357. {
  358. struct cpl_abort_req *req;
  359. PDBG("%s ep %p\n", __func__, ep);
  360. skb = get_skb(skb, sizeof(*req), gfp);
  361. if (!skb) {
  362. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  363. __func__);
  364. return -ENOMEM;
  365. }
  366. skb->priority = CPL_PRIORITY_DATA;
  367. set_arp_failure_handler(skb, abort_arp_failure);
  368. req = (struct cpl_abort_req *) skb_put(skb, sizeof(*req));
  369. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ));
  370. req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  371. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
  372. req->cmd = CPL_ABORT_SEND_RST;
  373. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  374. }
  375. static int send_connect(struct iwch_ep *ep)
  376. {
  377. struct cpl_act_open_req *req;
  378. struct sk_buff *skb;
  379. u32 opt0h, opt0l, opt2;
  380. unsigned int mtu_idx;
  381. int wscale;
  382. PDBG("%s ep %p\n", __func__, ep);
  383. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  384. if (!skb) {
  385. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  386. __func__);
  387. return -ENOMEM;
  388. }
  389. mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst));
  390. wscale = compute_wscale(rcv_win);
  391. opt0h = V_NAGLE(0) |
  392. V_NO_CONG(nocong) |
  393. V_KEEP_ALIVE(1) |
  394. F_TCAM_BYPASS |
  395. V_WND_SCALE(wscale) |
  396. V_MSS_IDX(mtu_idx) |
  397. V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
  398. opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
  399. opt2 = F_RX_COALESCE_VALID | V_RX_COALESCE(0) | V_FLAVORS_VALID(1) |
  400. V_CONG_CONTROL_FLAVOR(cong_flavor);
  401. skb->priority = CPL_PRIORITY_SETUP;
  402. set_arp_failure_handler(skb, act_open_req_arp_failure);
  403. req = (struct cpl_act_open_req *) skb_put(skb, sizeof(*req));
  404. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  405. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ep->atid));
  406. req->local_port = ep->com.local_addr.sin_port;
  407. req->peer_port = ep->com.remote_addr.sin_port;
  408. req->local_ip = ep->com.local_addr.sin_addr.s_addr;
  409. req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
  410. req->opt0h = htonl(opt0h);
  411. req->opt0l = htonl(opt0l);
  412. req->params = 0;
  413. req->opt2 = htonl(opt2);
  414. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  415. }
  416. static void send_mpa_req(struct iwch_ep *ep, struct sk_buff *skb)
  417. {
  418. int mpalen;
  419. struct tx_data_wr *req;
  420. struct mpa_message *mpa;
  421. int len;
  422. PDBG("%s ep %p pd_len %d\n", __func__, ep, ep->plen);
  423. BUG_ON(skb_cloned(skb));
  424. mpalen = sizeof(*mpa) + ep->plen;
  425. if (skb->data + mpalen + sizeof(*req) > skb_end_pointer(skb)) {
  426. kfree_skb(skb);
  427. skb=alloc_skb(mpalen + sizeof(*req), GFP_KERNEL);
  428. if (!skb) {
  429. connect_reply_upcall(ep, -ENOMEM);
  430. return;
  431. }
  432. }
  433. skb_trim(skb, 0);
  434. skb_reserve(skb, sizeof(*req));
  435. skb_put(skb, mpalen);
  436. skb->priority = CPL_PRIORITY_DATA;
  437. mpa = (struct mpa_message *) skb->data;
  438. memset(mpa, 0, sizeof(*mpa));
  439. memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
  440. mpa->flags = (crc_enabled ? MPA_CRC : 0) |
  441. (markers_enabled ? MPA_MARKERS : 0);
  442. mpa->private_data_size = htons(ep->plen);
  443. mpa->revision = mpa_rev;
  444. if (ep->plen)
  445. memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen);
  446. /*
  447. * Reference the mpa skb. This ensures the data area
  448. * will remain in memory until the hw acks the tx.
  449. * Function tx_ack() will deref it.
  450. */
  451. skb_get(skb);
  452. set_arp_failure_handler(skb, arp_failure_discard);
  453. skb_reset_transport_header(skb);
  454. len = skb->len;
  455. req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
  456. req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
  457. req->wr_lo = htonl(V_WR_TID(ep->hwtid));
  458. req->len = htonl(len);
  459. req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
  460. V_TX_SNDBUF(snd_win>>15));
  461. req->flags = htonl(F_TX_INIT);
  462. req->sndseq = htonl(ep->snd_seq);
  463. BUG_ON(ep->mpa_skb);
  464. ep->mpa_skb = skb;
  465. iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  466. start_ep_timer(ep);
  467. state_set(&ep->com, MPA_REQ_SENT);
  468. return;
  469. }
  470. static int send_mpa_reject(struct iwch_ep *ep, const void *pdata, u8 plen)
  471. {
  472. int mpalen;
  473. struct tx_data_wr *req;
  474. struct mpa_message *mpa;
  475. struct sk_buff *skb;
  476. PDBG("%s ep %p plen %d\n", __func__, ep, plen);
  477. mpalen = sizeof(*mpa) + plen;
  478. skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL);
  479. if (!skb) {
  480. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  481. return -ENOMEM;
  482. }
  483. skb_reserve(skb, sizeof(*req));
  484. mpa = (struct mpa_message *) skb_put(skb, mpalen);
  485. memset(mpa, 0, sizeof(*mpa));
  486. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  487. mpa->flags = MPA_REJECT;
  488. mpa->revision = mpa_rev;
  489. mpa->private_data_size = htons(plen);
  490. if (plen)
  491. memcpy(mpa->private_data, pdata, plen);
  492. /*
  493. * Reference the mpa skb again. This ensures the data area
  494. * will remain in memory until the hw acks the tx.
  495. * Function tx_ack() will deref it.
  496. */
  497. skb_get(skb);
  498. skb->priority = CPL_PRIORITY_DATA;
  499. set_arp_failure_handler(skb, arp_failure_discard);
  500. skb_reset_transport_header(skb);
  501. req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
  502. req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
  503. req->wr_lo = htonl(V_WR_TID(ep->hwtid));
  504. req->len = htonl(mpalen);
  505. req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
  506. V_TX_SNDBUF(snd_win>>15));
  507. req->flags = htonl(F_TX_INIT);
  508. req->sndseq = htonl(ep->snd_seq);
  509. BUG_ON(ep->mpa_skb);
  510. ep->mpa_skb = skb;
  511. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  512. }
  513. static int send_mpa_reply(struct iwch_ep *ep, const void *pdata, u8 plen)
  514. {
  515. int mpalen;
  516. struct tx_data_wr *req;
  517. struct mpa_message *mpa;
  518. int len;
  519. struct sk_buff *skb;
  520. PDBG("%s ep %p plen %d\n", __func__, ep, plen);
  521. mpalen = sizeof(*mpa) + plen;
  522. skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL);
  523. if (!skb) {
  524. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  525. return -ENOMEM;
  526. }
  527. skb->priority = CPL_PRIORITY_DATA;
  528. skb_reserve(skb, sizeof(*req));
  529. mpa = (struct mpa_message *) skb_put(skb, mpalen);
  530. memset(mpa, 0, sizeof(*mpa));
  531. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  532. mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
  533. (markers_enabled ? MPA_MARKERS : 0);
  534. mpa->revision = mpa_rev;
  535. mpa->private_data_size = htons(plen);
  536. if (plen)
  537. memcpy(mpa->private_data, pdata, plen);
  538. /*
  539. * Reference the mpa skb. This ensures the data area
  540. * will remain in memory until the hw acks the tx.
  541. * Function tx_ack() will deref it.
  542. */
  543. skb_get(skb);
  544. set_arp_failure_handler(skb, arp_failure_discard);
  545. skb_reset_transport_header(skb);
  546. len = skb->len;
  547. req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
  548. req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
  549. req->wr_lo = htonl(V_WR_TID(ep->hwtid));
  550. req->len = htonl(len);
  551. req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
  552. V_TX_SNDBUF(snd_win>>15));
  553. req->flags = htonl(F_TX_INIT);
  554. req->sndseq = htonl(ep->snd_seq);
  555. ep->mpa_skb = skb;
  556. state_set(&ep->com, MPA_REP_SENT);
  557. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  558. }
  559. static int act_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  560. {
  561. struct iwch_ep *ep = ctx;
  562. struct cpl_act_establish *req = cplhdr(skb);
  563. unsigned int tid = GET_TID(req);
  564. PDBG("%s ep %p tid %d\n", __func__, ep, tid);
  565. dst_confirm(ep->dst);
  566. /* setup the hwtid for this connection */
  567. ep->hwtid = tid;
  568. cxgb3_insert_tid(ep->com.tdev, &t3c_client, ep, tid);
  569. ep->snd_seq = ntohl(req->snd_isn);
  570. ep->rcv_seq = ntohl(req->rcv_isn);
  571. set_emss(ep, ntohs(req->tcp_opt));
  572. /* dealloc the atid */
  573. cxgb3_free_atid(ep->com.tdev, ep->atid);
  574. /* start MPA negotiation */
  575. send_mpa_req(ep, skb);
  576. return 0;
  577. }
  578. static void abort_connection(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp)
  579. {
  580. PDBG("%s ep %p\n", __FILE__, ep);
  581. state_set(&ep->com, ABORTING);
  582. send_abort(ep, skb, gfp);
  583. }
  584. static void close_complete_upcall(struct iwch_ep *ep)
  585. {
  586. struct iw_cm_event event;
  587. PDBG("%s ep %p\n", __func__, ep);
  588. memset(&event, 0, sizeof(event));
  589. event.event = IW_CM_EVENT_CLOSE;
  590. if (ep->com.cm_id) {
  591. PDBG("close complete delivered ep %p cm_id %p tid %d\n",
  592. ep, ep->com.cm_id, ep->hwtid);
  593. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  594. ep->com.cm_id->rem_ref(ep->com.cm_id);
  595. ep->com.cm_id = NULL;
  596. ep->com.qp = NULL;
  597. }
  598. }
  599. static void peer_close_upcall(struct iwch_ep *ep)
  600. {
  601. struct iw_cm_event event;
  602. PDBG("%s ep %p\n", __func__, ep);
  603. memset(&event, 0, sizeof(event));
  604. event.event = IW_CM_EVENT_DISCONNECT;
  605. if (ep->com.cm_id) {
  606. PDBG("peer close delivered ep %p cm_id %p tid %d\n",
  607. ep, ep->com.cm_id, ep->hwtid);
  608. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  609. }
  610. }
  611. static void peer_abort_upcall(struct iwch_ep *ep)
  612. {
  613. struct iw_cm_event event;
  614. PDBG("%s ep %p\n", __func__, ep);
  615. memset(&event, 0, sizeof(event));
  616. event.event = IW_CM_EVENT_CLOSE;
  617. event.status = -ECONNRESET;
  618. if (ep->com.cm_id) {
  619. PDBG("abort delivered ep %p cm_id %p tid %d\n", ep,
  620. ep->com.cm_id, ep->hwtid);
  621. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  622. ep->com.cm_id->rem_ref(ep->com.cm_id);
  623. ep->com.cm_id = NULL;
  624. ep->com.qp = NULL;
  625. }
  626. }
  627. static void connect_reply_upcall(struct iwch_ep *ep, int status)
  628. {
  629. struct iw_cm_event event;
  630. PDBG("%s ep %p status %d\n", __func__, ep, status);
  631. memset(&event, 0, sizeof(event));
  632. event.event = IW_CM_EVENT_CONNECT_REPLY;
  633. event.status = status;
  634. event.local_addr = ep->com.local_addr;
  635. event.remote_addr = ep->com.remote_addr;
  636. if ((status == 0) || (status == -ECONNREFUSED)) {
  637. event.private_data_len = ep->plen;
  638. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  639. }
  640. if (ep->com.cm_id) {
  641. PDBG("%s ep %p tid %d status %d\n", __func__, ep,
  642. ep->hwtid, status);
  643. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  644. }
  645. if (status < 0) {
  646. ep->com.cm_id->rem_ref(ep->com.cm_id);
  647. ep->com.cm_id = NULL;
  648. ep->com.qp = NULL;
  649. }
  650. }
  651. static void connect_request_upcall(struct iwch_ep *ep)
  652. {
  653. struct iw_cm_event event;
  654. PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
  655. memset(&event, 0, sizeof(event));
  656. event.event = IW_CM_EVENT_CONNECT_REQUEST;
  657. event.local_addr = ep->com.local_addr;
  658. event.remote_addr = ep->com.remote_addr;
  659. event.private_data_len = ep->plen;
  660. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  661. event.provider_data = ep;
  662. /*
  663. * Until ird/ord negotiation via MPAv2 support is added, send max
  664. * supported values
  665. */
  666. event.ird = event.ord = 8;
  667. if (state_read(&ep->parent_ep->com) != DEAD) {
  668. get_ep(&ep->com);
  669. ep->parent_ep->com.cm_id->event_handler(
  670. ep->parent_ep->com.cm_id,
  671. &event);
  672. }
  673. put_ep(&ep->parent_ep->com);
  674. ep->parent_ep = NULL;
  675. }
  676. static void established_upcall(struct iwch_ep *ep)
  677. {
  678. struct iw_cm_event event;
  679. PDBG("%s ep %p\n", __func__, ep);
  680. memset(&event, 0, sizeof(event));
  681. event.event = IW_CM_EVENT_ESTABLISHED;
  682. /*
  683. * Until ird/ord negotiation via MPAv2 support is added, send max
  684. * supported values
  685. */
  686. event.ird = event.ord = 8;
  687. if (ep->com.cm_id) {
  688. PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
  689. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  690. }
  691. }
  692. static int update_rx_credits(struct iwch_ep *ep, u32 credits)
  693. {
  694. struct cpl_rx_data_ack *req;
  695. struct sk_buff *skb;
  696. PDBG("%s ep %p credits %u\n", __func__, ep, credits);
  697. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  698. if (!skb) {
  699. printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
  700. return 0;
  701. }
  702. req = (struct cpl_rx_data_ack *) skb_put(skb, sizeof(*req));
  703. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  704. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_RX_DATA_ACK, ep->hwtid));
  705. req->credit_dack = htonl(V_RX_CREDITS(credits) | V_RX_FORCE_ACK(1));
  706. skb->priority = CPL_PRIORITY_ACK;
  707. iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  708. return credits;
  709. }
  710. static void process_mpa_reply(struct iwch_ep *ep, struct sk_buff *skb)
  711. {
  712. struct mpa_message *mpa;
  713. u16 plen;
  714. struct iwch_qp_attributes attrs;
  715. enum iwch_qp_attr_mask mask;
  716. int err;
  717. PDBG("%s ep %p\n", __func__, ep);
  718. /*
  719. * Stop mpa timer. If it expired, then the state has
  720. * changed and we bail since ep_timeout already aborted
  721. * the connection.
  722. */
  723. stop_ep_timer(ep);
  724. if (state_read(&ep->com) != MPA_REQ_SENT)
  725. return;
  726. /*
  727. * If we get more than the supported amount of private data
  728. * then we must fail this connection.
  729. */
  730. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  731. err = -EINVAL;
  732. goto err;
  733. }
  734. /*
  735. * copy the new data into our accumulation buffer.
  736. */
  737. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  738. skb->len);
  739. ep->mpa_pkt_len += skb->len;
  740. /*
  741. * if we don't even have the mpa message, then bail.
  742. */
  743. if (ep->mpa_pkt_len < sizeof(*mpa))
  744. return;
  745. mpa = (struct mpa_message *) ep->mpa_pkt;
  746. /* Validate MPA header. */
  747. if (mpa->revision != mpa_rev) {
  748. err = -EPROTO;
  749. goto err;
  750. }
  751. if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
  752. err = -EPROTO;
  753. goto err;
  754. }
  755. plen = ntohs(mpa->private_data_size);
  756. /*
  757. * Fail if there's too much private data.
  758. */
  759. if (plen > MPA_MAX_PRIVATE_DATA) {
  760. err = -EPROTO;
  761. goto err;
  762. }
  763. /*
  764. * If plen does not account for pkt size
  765. */
  766. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  767. err = -EPROTO;
  768. goto err;
  769. }
  770. ep->plen = (u8) plen;
  771. /*
  772. * If we don't have all the pdata yet, then bail.
  773. * We'll continue process when more data arrives.
  774. */
  775. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  776. return;
  777. if (mpa->flags & MPA_REJECT) {
  778. err = -ECONNREFUSED;
  779. goto err;
  780. }
  781. /*
  782. * If we get here we have accumulated the entire mpa
  783. * start reply message including private data. And
  784. * the MPA header is valid.
  785. */
  786. state_set(&ep->com, FPDU_MODE);
  787. ep->mpa_attr.initiator = 1;
  788. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  789. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  790. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  791. ep->mpa_attr.version = mpa_rev;
  792. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  793. "xmit_marker_enabled=%d, version=%d\n", __func__,
  794. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  795. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
  796. attrs.mpa_attr = ep->mpa_attr;
  797. attrs.max_ird = ep->ird;
  798. attrs.max_ord = ep->ord;
  799. attrs.llp_stream_handle = ep;
  800. attrs.next_state = IWCH_QP_STATE_RTS;
  801. mask = IWCH_QP_ATTR_NEXT_STATE |
  802. IWCH_QP_ATTR_LLP_STREAM_HANDLE | IWCH_QP_ATTR_MPA_ATTR |
  803. IWCH_QP_ATTR_MAX_IRD | IWCH_QP_ATTR_MAX_ORD;
  804. /* bind QP and TID with INIT_WR */
  805. err = iwch_modify_qp(ep->com.qp->rhp,
  806. ep->com.qp, mask, &attrs, 1);
  807. if (err)
  808. goto err;
  809. if (peer2peer && iwch_rqes_posted(ep->com.qp) == 0) {
  810. iwch_post_zb_read(ep);
  811. }
  812. goto out;
  813. err:
  814. abort_connection(ep, skb, GFP_KERNEL);
  815. out:
  816. connect_reply_upcall(ep, err);
  817. return;
  818. }
  819. static void process_mpa_request(struct iwch_ep *ep, struct sk_buff *skb)
  820. {
  821. struct mpa_message *mpa;
  822. u16 plen;
  823. PDBG("%s ep %p\n", __func__, ep);
  824. /*
  825. * Stop mpa timer. If it expired, then the state has
  826. * changed and we bail since ep_timeout already aborted
  827. * the connection.
  828. */
  829. stop_ep_timer(ep);
  830. if (state_read(&ep->com) != MPA_REQ_WAIT)
  831. return;
  832. /*
  833. * If we get more than the supported amount of private data
  834. * then we must fail this connection.
  835. */
  836. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  837. abort_connection(ep, skb, GFP_KERNEL);
  838. return;
  839. }
  840. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  841. /*
  842. * Copy the new data into our accumulation buffer.
  843. */
  844. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  845. skb->len);
  846. ep->mpa_pkt_len += skb->len;
  847. /*
  848. * If we don't even have the mpa message, then bail.
  849. * We'll continue process when more data arrives.
  850. */
  851. if (ep->mpa_pkt_len < sizeof(*mpa))
  852. return;
  853. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  854. mpa = (struct mpa_message *) ep->mpa_pkt;
  855. /*
  856. * Validate MPA Header.
  857. */
  858. if (mpa->revision != mpa_rev) {
  859. abort_connection(ep, skb, GFP_KERNEL);
  860. return;
  861. }
  862. if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
  863. abort_connection(ep, skb, GFP_KERNEL);
  864. return;
  865. }
  866. plen = ntohs(mpa->private_data_size);
  867. /*
  868. * Fail if there's too much private data.
  869. */
  870. if (plen > MPA_MAX_PRIVATE_DATA) {
  871. abort_connection(ep, skb, GFP_KERNEL);
  872. return;
  873. }
  874. /*
  875. * If plen does not account for pkt size
  876. */
  877. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  878. abort_connection(ep, skb, GFP_KERNEL);
  879. return;
  880. }
  881. ep->plen = (u8) plen;
  882. /*
  883. * If we don't have all the pdata yet, then bail.
  884. */
  885. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  886. return;
  887. /*
  888. * If we get here we have accumulated the entire mpa
  889. * start reply message including private data.
  890. */
  891. ep->mpa_attr.initiator = 0;
  892. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  893. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  894. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  895. ep->mpa_attr.version = mpa_rev;
  896. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  897. "xmit_marker_enabled=%d, version=%d\n", __func__,
  898. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  899. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
  900. state_set(&ep->com, MPA_REQ_RCVD);
  901. /* drive upcall */
  902. connect_request_upcall(ep);
  903. return;
  904. }
  905. static int rx_data(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  906. {
  907. struct iwch_ep *ep = ctx;
  908. struct cpl_rx_data *hdr = cplhdr(skb);
  909. unsigned int dlen = ntohs(hdr->len);
  910. PDBG("%s ep %p dlen %u\n", __func__, ep, dlen);
  911. skb_pull(skb, sizeof(*hdr));
  912. skb_trim(skb, dlen);
  913. ep->rcv_seq += dlen;
  914. BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
  915. switch (state_read(&ep->com)) {
  916. case MPA_REQ_SENT:
  917. process_mpa_reply(ep, skb);
  918. break;
  919. case MPA_REQ_WAIT:
  920. process_mpa_request(ep, skb);
  921. break;
  922. case MPA_REP_SENT:
  923. break;
  924. default:
  925. printk(KERN_ERR MOD "%s Unexpected streaming data."
  926. " ep %p state %d tid %d\n",
  927. __func__, ep, state_read(&ep->com), ep->hwtid);
  928. /*
  929. * The ep will timeout and inform the ULP of the failure.
  930. * See ep_timeout().
  931. */
  932. break;
  933. }
  934. /* update RX credits */
  935. update_rx_credits(ep, dlen);
  936. return CPL_RET_BUF_DONE;
  937. }
  938. /*
  939. * Upcall from the adapter indicating data has been transmitted.
  940. * For us its just the single MPA request or reply. We can now free
  941. * the skb holding the mpa message.
  942. */
  943. static int tx_ack(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  944. {
  945. struct iwch_ep *ep = ctx;
  946. struct cpl_wr_ack *hdr = cplhdr(skb);
  947. unsigned int credits = ntohs(hdr->credits);
  948. unsigned long flags;
  949. int post_zb = 0;
  950. PDBG("%s ep %p credits %u\n", __func__, ep, credits);
  951. if (credits == 0) {
  952. PDBG("%s 0 credit ack ep %p state %u\n",
  953. __func__, ep, state_read(&ep->com));
  954. return CPL_RET_BUF_DONE;
  955. }
  956. spin_lock_irqsave(&ep->com.lock, flags);
  957. BUG_ON(credits != 1);
  958. dst_confirm(ep->dst);
  959. if (!ep->mpa_skb) {
  960. PDBG("%s rdma_init wr_ack ep %p state %u\n",
  961. __func__, ep, ep->com.state);
  962. if (ep->mpa_attr.initiator) {
  963. PDBG("%s initiator ep %p state %u\n",
  964. __func__, ep, ep->com.state);
  965. if (peer2peer && ep->com.state == FPDU_MODE)
  966. post_zb = 1;
  967. } else {
  968. PDBG("%s responder ep %p state %u\n",
  969. __func__, ep, ep->com.state);
  970. if (ep->com.state == MPA_REQ_RCVD) {
  971. ep->com.rpl_done = 1;
  972. wake_up(&ep->com.waitq);
  973. }
  974. }
  975. } else {
  976. PDBG("%s lsm ack ep %p state %u freeing skb\n",
  977. __func__, ep, ep->com.state);
  978. kfree_skb(ep->mpa_skb);
  979. ep->mpa_skb = NULL;
  980. }
  981. spin_unlock_irqrestore(&ep->com.lock, flags);
  982. if (post_zb)
  983. iwch_post_zb_read(ep);
  984. return CPL_RET_BUF_DONE;
  985. }
  986. static int abort_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  987. {
  988. struct iwch_ep *ep = ctx;
  989. unsigned long flags;
  990. int release = 0;
  991. PDBG("%s ep %p\n", __func__, ep);
  992. BUG_ON(!ep);
  993. /*
  994. * We get 2 abort replies from the HW. The first one must
  995. * be ignored except for scribbling that we need one more.
  996. */
  997. if (!test_and_set_bit(ABORT_REQ_IN_PROGRESS, &ep->com.flags)) {
  998. return CPL_RET_BUF_DONE;
  999. }
  1000. spin_lock_irqsave(&ep->com.lock, flags);
  1001. switch (ep->com.state) {
  1002. case ABORTING:
  1003. close_complete_upcall(ep);
  1004. __state_set(&ep->com, DEAD);
  1005. release = 1;
  1006. break;
  1007. default:
  1008. printk(KERN_ERR "%s ep %p state %d\n",
  1009. __func__, ep, ep->com.state);
  1010. break;
  1011. }
  1012. spin_unlock_irqrestore(&ep->com.lock, flags);
  1013. if (release)
  1014. release_ep_resources(ep);
  1015. return CPL_RET_BUF_DONE;
  1016. }
  1017. /*
  1018. * Return whether a failed active open has allocated a TID
  1019. */
  1020. static inline int act_open_has_tid(int status)
  1021. {
  1022. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1023. status != CPL_ERR_ARP_MISS;
  1024. }
  1025. static int act_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1026. {
  1027. struct iwch_ep *ep = ctx;
  1028. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1029. PDBG("%s ep %p status %u errno %d\n", __func__, ep, rpl->status,
  1030. status2errno(rpl->status));
  1031. connect_reply_upcall(ep, status2errno(rpl->status));
  1032. state_set(&ep->com, DEAD);
  1033. if (ep->com.tdev->type != T3A && act_open_has_tid(rpl->status))
  1034. release_tid(ep->com.tdev, GET_TID(rpl), NULL);
  1035. cxgb3_free_atid(ep->com.tdev, ep->atid);
  1036. dst_release(ep->dst);
  1037. l2t_release(ep->com.tdev, ep->l2t);
  1038. put_ep(&ep->com);
  1039. return CPL_RET_BUF_DONE;
  1040. }
  1041. static int listen_start(struct iwch_listen_ep *ep)
  1042. {
  1043. struct sk_buff *skb;
  1044. struct cpl_pass_open_req *req;
  1045. PDBG("%s ep %p\n", __func__, ep);
  1046. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1047. if (!skb) {
  1048. printk(KERN_ERR MOD "t3c_listen_start failed to alloc skb!\n");
  1049. return -ENOMEM;
  1050. }
  1051. req = (struct cpl_pass_open_req *) skb_put(skb, sizeof(*req));
  1052. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1053. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, ep->stid));
  1054. req->local_port = ep->com.local_addr.sin_port;
  1055. req->local_ip = ep->com.local_addr.sin_addr.s_addr;
  1056. req->peer_port = 0;
  1057. req->peer_ip = 0;
  1058. req->peer_netmask = 0;
  1059. req->opt0h = htonl(F_DELACK | F_TCAM_BYPASS);
  1060. req->opt0l = htonl(V_RCV_BUFSIZ(rcv_win>>10));
  1061. req->opt1 = htonl(V_CONN_POLICY(CPL_CONN_POLICY_ASK));
  1062. skb->priority = 1;
  1063. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  1064. }
  1065. static int pass_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1066. {
  1067. struct iwch_listen_ep *ep = ctx;
  1068. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1069. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1070. rpl->status, status2errno(rpl->status));
  1071. ep->com.rpl_err = status2errno(rpl->status);
  1072. ep->com.rpl_done = 1;
  1073. wake_up(&ep->com.waitq);
  1074. return CPL_RET_BUF_DONE;
  1075. }
  1076. static int listen_stop(struct iwch_listen_ep *ep)
  1077. {
  1078. struct sk_buff *skb;
  1079. struct cpl_close_listserv_req *req;
  1080. PDBG("%s ep %p\n", __func__, ep);
  1081. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1082. if (!skb) {
  1083. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  1084. return -ENOMEM;
  1085. }
  1086. req = (struct cpl_close_listserv_req *) skb_put(skb, sizeof(*req));
  1087. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1088. req->cpu_idx = 0;
  1089. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, ep->stid));
  1090. skb->priority = 1;
  1091. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  1092. }
  1093. static int close_listsrv_rpl(struct t3cdev *tdev, struct sk_buff *skb,
  1094. void *ctx)
  1095. {
  1096. struct iwch_listen_ep *ep = ctx;
  1097. struct cpl_close_listserv_rpl *rpl = cplhdr(skb);
  1098. PDBG("%s ep %p\n", __func__, ep);
  1099. ep->com.rpl_err = status2errno(rpl->status);
  1100. ep->com.rpl_done = 1;
  1101. wake_up(&ep->com.waitq);
  1102. return CPL_RET_BUF_DONE;
  1103. }
  1104. static void accept_cr(struct iwch_ep *ep, __be32 peer_ip, struct sk_buff *skb)
  1105. {
  1106. struct cpl_pass_accept_rpl *rpl;
  1107. unsigned int mtu_idx;
  1108. u32 opt0h, opt0l, opt2;
  1109. int wscale;
  1110. PDBG("%s ep %p\n", __func__, ep);
  1111. BUG_ON(skb_cloned(skb));
  1112. skb_trim(skb, sizeof(*rpl));
  1113. skb_get(skb);
  1114. mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst));
  1115. wscale = compute_wscale(rcv_win);
  1116. opt0h = V_NAGLE(0) |
  1117. V_NO_CONG(nocong) |
  1118. V_KEEP_ALIVE(1) |
  1119. F_TCAM_BYPASS |
  1120. V_WND_SCALE(wscale) |
  1121. V_MSS_IDX(mtu_idx) |
  1122. V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
  1123. opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
  1124. opt2 = F_RX_COALESCE_VALID | V_RX_COALESCE(0) | V_FLAVORS_VALID(1) |
  1125. V_CONG_CONTROL_FLAVOR(cong_flavor);
  1126. rpl = cplhdr(skb);
  1127. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1128. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, ep->hwtid));
  1129. rpl->peer_ip = peer_ip;
  1130. rpl->opt0h = htonl(opt0h);
  1131. rpl->opt0l_status = htonl(opt0l | CPL_PASS_OPEN_ACCEPT);
  1132. rpl->opt2 = htonl(opt2);
  1133. rpl->rsvd = rpl->opt2; /* workaround for HW bug */
  1134. skb->priority = CPL_PRIORITY_SETUP;
  1135. iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  1136. return;
  1137. }
  1138. static void reject_cr(struct t3cdev *tdev, u32 hwtid, __be32 peer_ip,
  1139. struct sk_buff *skb)
  1140. {
  1141. PDBG("%s t3cdev %p tid %u peer_ip %x\n", __func__, tdev, hwtid,
  1142. peer_ip);
  1143. BUG_ON(skb_cloned(skb));
  1144. skb_trim(skb, sizeof(struct cpl_tid_release));
  1145. skb_get(skb);
  1146. if (tdev->type != T3A)
  1147. release_tid(tdev, hwtid, skb);
  1148. else {
  1149. struct cpl_pass_accept_rpl *rpl;
  1150. rpl = cplhdr(skb);
  1151. skb->priority = CPL_PRIORITY_SETUP;
  1152. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1153. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1154. hwtid));
  1155. rpl->peer_ip = peer_ip;
  1156. rpl->opt0h = htonl(F_TCAM_BYPASS);
  1157. rpl->opt0l_status = htonl(CPL_PASS_OPEN_REJECT);
  1158. rpl->opt2 = 0;
  1159. rpl->rsvd = rpl->opt2;
  1160. iwch_cxgb3_ofld_send(tdev, skb);
  1161. }
  1162. }
  1163. static int pass_accept_req(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1164. {
  1165. struct iwch_ep *child_ep, *parent_ep = ctx;
  1166. struct cpl_pass_accept_req *req = cplhdr(skb);
  1167. unsigned int hwtid = GET_TID(req);
  1168. struct neighbour *neigh;
  1169. struct dst_entry *dst;
  1170. struct l2t_entry *l2t;
  1171. struct rtable *rt;
  1172. struct iff_mac tim;
  1173. PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
  1174. if (state_read(&parent_ep->com) != LISTEN) {
  1175. printk(KERN_ERR "%s - listening ep not in LISTEN\n",
  1176. __func__);
  1177. goto reject;
  1178. }
  1179. /*
  1180. * Find the netdev for this connection request.
  1181. */
  1182. tim.mac_addr = req->dst_mac;
  1183. tim.vlan_tag = ntohs(req->vlan_tag);
  1184. if (tdev->ctl(tdev, GET_IFF_FROM_MAC, &tim) < 0 || !tim.dev) {
  1185. printk(KERN_ERR "%s bad dst mac %pM\n",
  1186. __func__, req->dst_mac);
  1187. goto reject;
  1188. }
  1189. /* Find output route */
  1190. rt = find_route(tdev,
  1191. req->local_ip,
  1192. req->peer_ip,
  1193. req->local_port,
  1194. req->peer_port, G_PASS_OPEN_TOS(ntohl(req->tos_tid)));
  1195. if (!rt) {
  1196. printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
  1197. __func__);
  1198. goto reject;
  1199. }
  1200. dst = &rt->dst;
  1201. rcu_read_lock();
  1202. neigh = dst_get_neighbour(dst);
  1203. l2t = t3_l2t_get(tdev, neigh, neigh->dev);
  1204. rcu_read_unlock();
  1205. if (!l2t) {
  1206. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1207. __func__);
  1208. dst_release(dst);
  1209. goto reject;
  1210. }
  1211. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1212. if (!child_ep) {
  1213. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1214. __func__);
  1215. l2t_release(tdev, l2t);
  1216. dst_release(dst);
  1217. goto reject;
  1218. }
  1219. state_set(&child_ep->com, CONNECTING);
  1220. child_ep->com.tdev = tdev;
  1221. child_ep->com.cm_id = NULL;
  1222. child_ep->com.local_addr.sin_family = PF_INET;
  1223. child_ep->com.local_addr.sin_port = req->local_port;
  1224. child_ep->com.local_addr.sin_addr.s_addr = req->local_ip;
  1225. child_ep->com.remote_addr.sin_family = PF_INET;
  1226. child_ep->com.remote_addr.sin_port = req->peer_port;
  1227. child_ep->com.remote_addr.sin_addr.s_addr = req->peer_ip;
  1228. get_ep(&parent_ep->com);
  1229. child_ep->parent_ep = parent_ep;
  1230. child_ep->tos = G_PASS_OPEN_TOS(ntohl(req->tos_tid));
  1231. child_ep->l2t = l2t;
  1232. child_ep->dst = dst;
  1233. child_ep->hwtid = hwtid;
  1234. init_timer(&child_ep->timer);
  1235. cxgb3_insert_tid(tdev, &t3c_client, child_ep, hwtid);
  1236. accept_cr(child_ep, req->peer_ip, skb);
  1237. goto out;
  1238. reject:
  1239. reject_cr(tdev, hwtid, req->peer_ip, skb);
  1240. out:
  1241. return CPL_RET_BUF_DONE;
  1242. }
  1243. static int pass_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1244. {
  1245. struct iwch_ep *ep = ctx;
  1246. struct cpl_pass_establish *req = cplhdr(skb);
  1247. PDBG("%s ep %p\n", __func__, ep);
  1248. ep->snd_seq = ntohl(req->snd_isn);
  1249. ep->rcv_seq = ntohl(req->rcv_isn);
  1250. set_emss(ep, ntohs(req->tcp_opt));
  1251. dst_confirm(ep->dst);
  1252. state_set(&ep->com, MPA_REQ_WAIT);
  1253. start_ep_timer(ep);
  1254. return CPL_RET_BUF_DONE;
  1255. }
  1256. static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1257. {
  1258. struct iwch_ep *ep = ctx;
  1259. struct iwch_qp_attributes attrs;
  1260. unsigned long flags;
  1261. int disconnect = 1;
  1262. int release = 0;
  1263. PDBG("%s ep %p\n", __func__, ep);
  1264. dst_confirm(ep->dst);
  1265. spin_lock_irqsave(&ep->com.lock, flags);
  1266. switch (ep->com.state) {
  1267. case MPA_REQ_WAIT:
  1268. __state_set(&ep->com, CLOSING);
  1269. break;
  1270. case MPA_REQ_SENT:
  1271. __state_set(&ep->com, CLOSING);
  1272. connect_reply_upcall(ep, -ECONNRESET);
  1273. break;
  1274. case MPA_REQ_RCVD:
  1275. /*
  1276. * We're gonna mark this puppy DEAD, but keep
  1277. * the reference on it until the ULP accepts or
  1278. * rejects the CR. Also wake up anyone waiting
  1279. * in rdma connection migration (see iwch_accept_cr()).
  1280. */
  1281. __state_set(&ep->com, CLOSING);
  1282. ep->com.rpl_done = 1;
  1283. ep->com.rpl_err = -ECONNRESET;
  1284. PDBG("waking up ep %p\n", ep);
  1285. wake_up(&ep->com.waitq);
  1286. break;
  1287. case MPA_REP_SENT:
  1288. __state_set(&ep->com, CLOSING);
  1289. ep->com.rpl_done = 1;
  1290. ep->com.rpl_err = -ECONNRESET;
  1291. PDBG("waking up ep %p\n", ep);
  1292. wake_up(&ep->com.waitq);
  1293. break;
  1294. case FPDU_MODE:
  1295. start_ep_timer(ep);
  1296. __state_set(&ep->com, CLOSING);
  1297. attrs.next_state = IWCH_QP_STATE_CLOSING;
  1298. iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1299. IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
  1300. peer_close_upcall(ep);
  1301. break;
  1302. case ABORTING:
  1303. disconnect = 0;
  1304. break;
  1305. case CLOSING:
  1306. __state_set(&ep->com, MORIBUND);
  1307. disconnect = 0;
  1308. break;
  1309. case MORIBUND:
  1310. stop_ep_timer(ep);
  1311. if (ep->com.cm_id && ep->com.qp) {
  1312. attrs.next_state = IWCH_QP_STATE_IDLE;
  1313. iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1314. IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
  1315. }
  1316. close_complete_upcall(ep);
  1317. __state_set(&ep->com, DEAD);
  1318. release = 1;
  1319. disconnect = 0;
  1320. break;
  1321. case DEAD:
  1322. disconnect = 0;
  1323. break;
  1324. default:
  1325. BUG_ON(1);
  1326. }
  1327. spin_unlock_irqrestore(&ep->com.lock, flags);
  1328. if (disconnect)
  1329. iwch_ep_disconnect(ep, 0, GFP_KERNEL);
  1330. if (release)
  1331. release_ep_resources(ep);
  1332. return CPL_RET_BUF_DONE;
  1333. }
  1334. /*
  1335. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  1336. */
  1337. static int is_neg_adv_abort(unsigned int status)
  1338. {
  1339. return status == CPL_ERR_RTX_NEG_ADVICE ||
  1340. status == CPL_ERR_PERSIST_NEG_ADVICE;
  1341. }
  1342. static int peer_abort(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1343. {
  1344. struct cpl_abort_req_rss *req = cplhdr(skb);
  1345. struct iwch_ep *ep = ctx;
  1346. struct cpl_abort_rpl *rpl;
  1347. struct sk_buff *rpl_skb;
  1348. struct iwch_qp_attributes attrs;
  1349. int ret;
  1350. int release = 0;
  1351. unsigned long flags;
  1352. if (is_neg_adv_abort(req->status)) {
  1353. PDBG("%s neg_adv_abort ep %p tid %d\n", __func__, ep,
  1354. ep->hwtid);
  1355. t3_l2t_send_event(ep->com.tdev, ep->l2t);
  1356. return CPL_RET_BUF_DONE;
  1357. }
  1358. /*
  1359. * We get 2 peer aborts from the HW. The first one must
  1360. * be ignored except for scribbling that we need one more.
  1361. */
  1362. if (!test_and_set_bit(PEER_ABORT_IN_PROGRESS, &ep->com.flags)) {
  1363. return CPL_RET_BUF_DONE;
  1364. }
  1365. spin_lock_irqsave(&ep->com.lock, flags);
  1366. PDBG("%s ep %p state %u\n", __func__, ep, ep->com.state);
  1367. switch (ep->com.state) {
  1368. case CONNECTING:
  1369. break;
  1370. case MPA_REQ_WAIT:
  1371. stop_ep_timer(ep);
  1372. break;
  1373. case MPA_REQ_SENT:
  1374. stop_ep_timer(ep);
  1375. connect_reply_upcall(ep, -ECONNRESET);
  1376. break;
  1377. case MPA_REP_SENT:
  1378. ep->com.rpl_done = 1;
  1379. ep->com.rpl_err = -ECONNRESET;
  1380. PDBG("waking up ep %p\n", ep);
  1381. wake_up(&ep->com.waitq);
  1382. break;
  1383. case MPA_REQ_RCVD:
  1384. /*
  1385. * We're gonna mark this puppy DEAD, but keep
  1386. * the reference on it until the ULP accepts or
  1387. * rejects the CR. Also wake up anyone waiting
  1388. * in rdma connection migration (see iwch_accept_cr()).
  1389. */
  1390. ep->com.rpl_done = 1;
  1391. ep->com.rpl_err = -ECONNRESET;
  1392. PDBG("waking up ep %p\n", ep);
  1393. wake_up(&ep->com.waitq);
  1394. break;
  1395. case MORIBUND:
  1396. case CLOSING:
  1397. stop_ep_timer(ep);
  1398. /*FALLTHROUGH*/
  1399. case FPDU_MODE:
  1400. if (ep->com.cm_id && ep->com.qp) {
  1401. attrs.next_state = IWCH_QP_STATE_ERROR;
  1402. ret = iwch_modify_qp(ep->com.qp->rhp,
  1403. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1404. &attrs, 1);
  1405. if (ret)
  1406. printk(KERN_ERR MOD
  1407. "%s - qp <- error failed!\n",
  1408. __func__);
  1409. }
  1410. peer_abort_upcall(ep);
  1411. break;
  1412. case ABORTING:
  1413. break;
  1414. case DEAD:
  1415. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1416. spin_unlock_irqrestore(&ep->com.lock, flags);
  1417. return CPL_RET_BUF_DONE;
  1418. default:
  1419. BUG_ON(1);
  1420. break;
  1421. }
  1422. dst_confirm(ep->dst);
  1423. if (ep->com.state != ABORTING) {
  1424. __state_set(&ep->com, DEAD);
  1425. release = 1;
  1426. }
  1427. spin_unlock_irqrestore(&ep->com.lock, flags);
  1428. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1429. if (!rpl_skb) {
  1430. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  1431. __func__);
  1432. release = 1;
  1433. goto out;
  1434. }
  1435. rpl_skb->priority = CPL_PRIORITY_DATA;
  1436. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  1437. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL));
  1438. rpl->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  1439. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  1440. rpl->cmd = CPL_ABORT_NO_RST;
  1441. iwch_cxgb3_ofld_send(ep->com.tdev, rpl_skb);
  1442. out:
  1443. if (release)
  1444. release_ep_resources(ep);
  1445. return CPL_RET_BUF_DONE;
  1446. }
  1447. static int close_con_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1448. {
  1449. struct iwch_ep *ep = ctx;
  1450. struct iwch_qp_attributes attrs;
  1451. unsigned long flags;
  1452. int release = 0;
  1453. PDBG("%s ep %p\n", __func__, ep);
  1454. BUG_ON(!ep);
  1455. /* The cm_id may be null if we failed to connect */
  1456. spin_lock_irqsave(&ep->com.lock, flags);
  1457. switch (ep->com.state) {
  1458. case CLOSING:
  1459. __state_set(&ep->com, MORIBUND);
  1460. break;
  1461. case MORIBUND:
  1462. stop_ep_timer(ep);
  1463. if ((ep->com.cm_id) && (ep->com.qp)) {
  1464. attrs.next_state = IWCH_QP_STATE_IDLE;
  1465. iwch_modify_qp(ep->com.qp->rhp,
  1466. ep->com.qp,
  1467. IWCH_QP_ATTR_NEXT_STATE,
  1468. &attrs, 1);
  1469. }
  1470. close_complete_upcall(ep);
  1471. __state_set(&ep->com, DEAD);
  1472. release = 1;
  1473. break;
  1474. case ABORTING:
  1475. case DEAD:
  1476. break;
  1477. default:
  1478. BUG_ON(1);
  1479. break;
  1480. }
  1481. spin_unlock_irqrestore(&ep->com.lock, flags);
  1482. if (release)
  1483. release_ep_resources(ep);
  1484. return CPL_RET_BUF_DONE;
  1485. }
  1486. /*
  1487. * T3A does 3 things when a TERM is received:
  1488. * 1) send up a CPL_RDMA_TERMINATE message with the TERM packet
  1489. * 2) generate an async event on the QP with the TERMINATE opcode
  1490. * 3) post a TERMINATE opcde cqe into the associated CQ.
  1491. *
  1492. * For (1), we save the message in the qp for later consumer consumption.
  1493. * For (2), we move the QP into TERMINATE, post a QP event and disconnect.
  1494. * For (3), we toss the CQE in cxio_poll_cq().
  1495. *
  1496. * terminate() handles case (1)...
  1497. */
  1498. static int terminate(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1499. {
  1500. struct iwch_ep *ep = ctx;
  1501. if (state_read(&ep->com) != FPDU_MODE)
  1502. return CPL_RET_BUF_DONE;
  1503. PDBG("%s ep %p\n", __func__, ep);
  1504. skb_pull(skb, sizeof(struct cpl_rdma_terminate));
  1505. PDBG("%s saving %d bytes of term msg\n", __func__, skb->len);
  1506. skb_copy_from_linear_data(skb, ep->com.qp->attr.terminate_buffer,
  1507. skb->len);
  1508. ep->com.qp->attr.terminate_msg_len = skb->len;
  1509. ep->com.qp->attr.is_terminate_local = 0;
  1510. return CPL_RET_BUF_DONE;
  1511. }
  1512. static int ec_status(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1513. {
  1514. struct cpl_rdma_ec_status *rep = cplhdr(skb);
  1515. struct iwch_ep *ep = ctx;
  1516. PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid,
  1517. rep->status);
  1518. if (rep->status) {
  1519. struct iwch_qp_attributes attrs;
  1520. printk(KERN_ERR MOD "%s BAD CLOSE - Aborting tid %u\n",
  1521. __func__, ep->hwtid);
  1522. stop_ep_timer(ep);
  1523. attrs.next_state = IWCH_QP_STATE_ERROR;
  1524. iwch_modify_qp(ep->com.qp->rhp,
  1525. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1526. &attrs, 1);
  1527. abort_connection(ep, NULL, GFP_KERNEL);
  1528. }
  1529. return CPL_RET_BUF_DONE;
  1530. }
  1531. static void ep_timeout(unsigned long arg)
  1532. {
  1533. struct iwch_ep *ep = (struct iwch_ep *)arg;
  1534. struct iwch_qp_attributes attrs;
  1535. unsigned long flags;
  1536. int abort = 1;
  1537. spin_lock_irqsave(&ep->com.lock, flags);
  1538. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  1539. ep->com.state);
  1540. switch (ep->com.state) {
  1541. case MPA_REQ_SENT:
  1542. __state_set(&ep->com, ABORTING);
  1543. connect_reply_upcall(ep, -ETIMEDOUT);
  1544. break;
  1545. case MPA_REQ_WAIT:
  1546. __state_set(&ep->com, ABORTING);
  1547. break;
  1548. case CLOSING:
  1549. case MORIBUND:
  1550. if (ep->com.cm_id && ep->com.qp) {
  1551. attrs.next_state = IWCH_QP_STATE_ERROR;
  1552. iwch_modify_qp(ep->com.qp->rhp,
  1553. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1554. &attrs, 1);
  1555. }
  1556. __state_set(&ep->com, ABORTING);
  1557. break;
  1558. default:
  1559. printk(KERN_ERR "%s unexpected state ep %p state %u\n",
  1560. __func__, ep, ep->com.state);
  1561. WARN_ON(1);
  1562. abort = 0;
  1563. }
  1564. spin_unlock_irqrestore(&ep->com.lock, flags);
  1565. if (abort)
  1566. abort_connection(ep, NULL, GFP_ATOMIC);
  1567. put_ep(&ep->com);
  1568. }
  1569. int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  1570. {
  1571. int err;
  1572. struct iwch_ep *ep = to_ep(cm_id);
  1573. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1574. if (state_read(&ep->com) == DEAD) {
  1575. put_ep(&ep->com);
  1576. return -ECONNRESET;
  1577. }
  1578. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1579. if (mpa_rev == 0)
  1580. abort_connection(ep, NULL, GFP_KERNEL);
  1581. else {
  1582. err = send_mpa_reject(ep, pdata, pdata_len);
  1583. err = iwch_ep_disconnect(ep, 0, GFP_KERNEL);
  1584. }
  1585. put_ep(&ep->com);
  1586. return 0;
  1587. }
  1588. int iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1589. {
  1590. int err;
  1591. struct iwch_qp_attributes attrs;
  1592. enum iwch_qp_attr_mask mask;
  1593. struct iwch_ep *ep = to_ep(cm_id);
  1594. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1595. struct iwch_qp *qp = get_qhp(h, conn_param->qpn);
  1596. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1597. if (state_read(&ep->com) == DEAD) {
  1598. err = -ECONNRESET;
  1599. goto err;
  1600. }
  1601. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1602. BUG_ON(!qp);
  1603. if ((conn_param->ord > qp->rhp->attr.max_rdma_read_qp_depth) ||
  1604. (conn_param->ird > qp->rhp->attr.max_rdma_reads_per_qp)) {
  1605. abort_connection(ep, NULL, GFP_KERNEL);
  1606. err = -EINVAL;
  1607. goto err;
  1608. }
  1609. cm_id->add_ref(cm_id);
  1610. ep->com.cm_id = cm_id;
  1611. ep->com.qp = qp;
  1612. ep->ird = conn_param->ird;
  1613. ep->ord = conn_param->ord;
  1614. if (peer2peer && ep->ird == 0)
  1615. ep->ird = 1;
  1616. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  1617. /* bind QP to EP and move to RTS */
  1618. attrs.mpa_attr = ep->mpa_attr;
  1619. attrs.max_ird = ep->ird;
  1620. attrs.max_ord = ep->ord;
  1621. attrs.llp_stream_handle = ep;
  1622. attrs.next_state = IWCH_QP_STATE_RTS;
  1623. /* bind QP and TID with INIT_WR */
  1624. mask = IWCH_QP_ATTR_NEXT_STATE |
  1625. IWCH_QP_ATTR_LLP_STREAM_HANDLE |
  1626. IWCH_QP_ATTR_MPA_ATTR |
  1627. IWCH_QP_ATTR_MAX_IRD |
  1628. IWCH_QP_ATTR_MAX_ORD;
  1629. err = iwch_modify_qp(ep->com.qp->rhp,
  1630. ep->com.qp, mask, &attrs, 1);
  1631. if (err)
  1632. goto err1;
  1633. /* if needed, wait for wr_ack */
  1634. if (iwch_rqes_posted(qp)) {
  1635. wait_event(ep->com.waitq, ep->com.rpl_done);
  1636. err = ep->com.rpl_err;
  1637. if (err)
  1638. goto err1;
  1639. }
  1640. err = send_mpa_reply(ep, conn_param->private_data,
  1641. conn_param->private_data_len);
  1642. if (err)
  1643. goto err1;
  1644. state_set(&ep->com, FPDU_MODE);
  1645. established_upcall(ep);
  1646. put_ep(&ep->com);
  1647. return 0;
  1648. err1:
  1649. ep->com.cm_id = NULL;
  1650. ep->com.qp = NULL;
  1651. cm_id->rem_ref(cm_id);
  1652. err:
  1653. put_ep(&ep->com);
  1654. return err;
  1655. }
  1656. static int is_loopback_dst(struct iw_cm_id *cm_id)
  1657. {
  1658. struct net_device *dev;
  1659. dev = ip_dev_find(&init_net, cm_id->remote_addr.sin_addr.s_addr);
  1660. if (!dev)
  1661. return 0;
  1662. dev_put(dev);
  1663. return 1;
  1664. }
  1665. int iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1666. {
  1667. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1668. struct neighbour *neigh;
  1669. struct iwch_ep *ep;
  1670. struct rtable *rt;
  1671. int err = 0;
  1672. if (is_loopback_dst(cm_id)) {
  1673. err = -ENOSYS;
  1674. goto out;
  1675. }
  1676. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1677. if (!ep) {
  1678. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1679. err = -ENOMEM;
  1680. goto out;
  1681. }
  1682. init_timer(&ep->timer);
  1683. ep->plen = conn_param->private_data_len;
  1684. if (ep->plen)
  1685. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  1686. conn_param->private_data, ep->plen);
  1687. ep->ird = conn_param->ird;
  1688. ep->ord = conn_param->ord;
  1689. if (peer2peer && ep->ord == 0)
  1690. ep->ord = 1;
  1691. ep->com.tdev = h->rdev.t3cdev_p;
  1692. cm_id->add_ref(cm_id);
  1693. ep->com.cm_id = cm_id;
  1694. ep->com.qp = get_qhp(h, conn_param->qpn);
  1695. BUG_ON(!ep->com.qp);
  1696. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  1697. ep->com.qp, cm_id);
  1698. /*
  1699. * Allocate an active TID to initiate a TCP connection.
  1700. */
  1701. ep->atid = cxgb3_alloc_atid(h->rdev.t3cdev_p, &t3c_client, ep);
  1702. if (ep->atid == -1) {
  1703. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1704. err = -ENOMEM;
  1705. goto fail2;
  1706. }
  1707. /* find a route */
  1708. rt = find_route(h->rdev.t3cdev_p,
  1709. cm_id->local_addr.sin_addr.s_addr,
  1710. cm_id->remote_addr.sin_addr.s_addr,
  1711. cm_id->local_addr.sin_port,
  1712. cm_id->remote_addr.sin_port, IPTOS_LOWDELAY);
  1713. if (!rt) {
  1714. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  1715. err = -EHOSTUNREACH;
  1716. goto fail3;
  1717. }
  1718. ep->dst = &rt->dst;
  1719. rcu_read_lock();
  1720. neigh = dst_get_neighbour(ep->dst);
  1721. /* get a l2t entry */
  1722. ep->l2t = t3_l2t_get(ep->com.tdev, neigh, neigh->dev);
  1723. rcu_read_unlock();
  1724. if (!ep->l2t) {
  1725. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  1726. err = -ENOMEM;
  1727. goto fail4;
  1728. }
  1729. state_set(&ep->com, CONNECTING);
  1730. ep->tos = IPTOS_LOWDELAY;
  1731. ep->com.local_addr = cm_id->local_addr;
  1732. ep->com.remote_addr = cm_id->remote_addr;
  1733. /* send connect request to rnic */
  1734. err = send_connect(ep);
  1735. if (!err)
  1736. goto out;
  1737. l2t_release(h->rdev.t3cdev_p, ep->l2t);
  1738. fail4:
  1739. dst_release(ep->dst);
  1740. fail3:
  1741. cxgb3_free_atid(ep->com.tdev, ep->atid);
  1742. fail2:
  1743. cm_id->rem_ref(cm_id);
  1744. put_ep(&ep->com);
  1745. out:
  1746. return err;
  1747. }
  1748. int iwch_create_listen(struct iw_cm_id *cm_id, int backlog)
  1749. {
  1750. int err = 0;
  1751. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1752. struct iwch_listen_ep *ep;
  1753. might_sleep();
  1754. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1755. if (!ep) {
  1756. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1757. err = -ENOMEM;
  1758. goto fail1;
  1759. }
  1760. PDBG("%s ep %p\n", __func__, ep);
  1761. ep->com.tdev = h->rdev.t3cdev_p;
  1762. cm_id->add_ref(cm_id);
  1763. ep->com.cm_id = cm_id;
  1764. ep->backlog = backlog;
  1765. ep->com.local_addr = cm_id->local_addr;
  1766. /*
  1767. * Allocate a server TID.
  1768. */
  1769. ep->stid = cxgb3_alloc_stid(h->rdev.t3cdev_p, &t3c_client, ep);
  1770. if (ep->stid == -1) {
  1771. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1772. err = -ENOMEM;
  1773. goto fail2;
  1774. }
  1775. state_set(&ep->com, LISTEN);
  1776. err = listen_start(ep);
  1777. if (err)
  1778. goto fail3;
  1779. /* wait for pass_open_rpl */
  1780. wait_event(ep->com.waitq, ep->com.rpl_done);
  1781. err = ep->com.rpl_err;
  1782. if (!err) {
  1783. cm_id->provider_data = ep;
  1784. goto out;
  1785. }
  1786. fail3:
  1787. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1788. fail2:
  1789. cm_id->rem_ref(cm_id);
  1790. put_ep(&ep->com);
  1791. fail1:
  1792. out:
  1793. return err;
  1794. }
  1795. int iwch_destroy_listen(struct iw_cm_id *cm_id)
  1796. {
  1797. int err;
  1798. struct iwch_listen_ep *ep = to_listen_ep(cm_id);
  1799. PDBG("%s ep %p\n", __func__, ep);
  1800. might_sleep();
  1801. state_set(&ep->com, DEAD);
  1802. ep->com.rpl_done = 0;
  1803. ep->com.rpl_err = 0;
  1804. err = listen_stop(ep);
  1805. if (err)
  1806. goto done;
  1807. wait_event(ep->com.waitq, ep->com.rpl_done);
  1808. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1809. done:
  1810. err = ep->com.rpl_err;
  1811. cm_id->rem_ref(cm_id);
  1812. put_ep(&ep->com);
  1813. return err;
  1814. }
  1815. int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp)
  1816. {
  1817. int ret=0;
  1818. unsigned long flags;
  1819. int close = 0;
  1820. int fatal = 0;
  1821. struct t3cdev *tdev;
  1822. struct cxio_rdev *rdev;
  1823. spin_lock_irqsave(&ep->com.lock, flags);
  1824. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  1825. states[ep->com.state], abrupt);
  1826. tdev = (struct t3cdev *)ep->com.tdev;
  1827. rdev = (struct cxio_rdev *)tdev->ulp;
  1828. if (cxio_fatal_error(rdev)) {
  1829. fatal = 1;
  1830. close_complete_upcall(ep);
  1831. ep->com.state = DEAD;
  1832. }
  1833. switch (ep->com.state) {
  1834. case MPA_REQ_WAIT:
  1835. case MPA_REQ_SENT:
  1836. case MPA_REQ_RCVD:
  1837. case MPA_REP_SENT:
  1838. case FPDU_MODE:
  1839. close = 1;
  1840. if (abrupt)
  1841. ep->com.state = ABORTING;
  1842. else {
  1843. ep->com.state = CLOSING;
  1844. start_ep_timer(ep);
  1845. }
  1846. set_bit(CLOSE_SENT, &ep->com.flags);
  1847. break;
  1848. case CLOSING:
  1849. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  1850. close = 1;
  1851. if (abrupt) {
  1852. stop_ep_timer(ep);
  1853. ep->com.state = ABORTING;
  1854. } else
  1855. ep->com.state = MORIBUND;
  1856. }
  1857. break;
  1858. case MORIBUND:
  1859. case ABORTING:
  1860. case DEAD:
  1861. PDBG("%s ignoring disconnect ep %p state %u\n",
  1862. __func__, ep, ep->com.state);
  1863. break;
  1864. default:
  1865. BUG();
  1866. break;
  1867. }
  1868. spin_unlock_irqrestore(&ep->com.lock, flags);
  1869. if (close) {
  1870. if (abrupt)
  1871. ret = send_abort(ep, NULL, gfp);
  1872. else
  1873. ret = send_halfclose(ep, gfp);
  1874. if (ret)
  1875. fatal = 1;
  1876. }
  1877. if (fatal)
  1878. release_ep_resources(ep);
  1879. return ret;
  1880. }
  1881. int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
  1882. struct l2t_entry *l2t)
  1883. {
  1884. struct iwch_ep *ep = ctx;
  1885. if (ep->dst != old)
  1886. return 0;
  1887. PDBG("%s ep %p redirect to dst %p l2t %p\n", __func__, ep, new,
  1888. l2t);
  1889. dst_hold(new);
  1890. l2t_release(ep->com.tdev, ep->l2t);
  1891. ep->l2t = l2t;
  1892. dst_release(old);
  1893. ep->dst = new;
  1894. return 1;
  1895. }
  1896. /*
  1897. * All the CM events are handled on a work queue to have a safe context.
  1898. * These are the real handlers that are called from the work queue.
  1899. */
  1900. static const cxgb3_cpl_handler_func work_handlers[NUM_CPL_CMDS] = {
  1901. [CPL_ACT_ESTABLISH] = act_establish,
  1902. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  1903. [CPL_RX_DATA] = rx_data,
  1904. [CPL_TX_DMA_ACK] = tx_ack,
  1905. [CPL_ABORT_RPL_RSS] = abort_rpl,
  1906. [CPL_ABORT_RPL] = abort_rpl,
  1907. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  1908. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  1909. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  1910. [CPL_PASS_ESTABLISH] = pass_establish,
  1911. [CPL_PEER_CLOSE] = peer_close,
  1912. [CPL_ABORT_REQ_RSS] = peer_abort,
  1913. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  1914. [CPL_RDMA_TERMINATE] = terminate,
  1915. [CPL_RDMA_EC_STATUS] = ec_status,
  1916. };
  1917. static void process_work(struct work_struct *work)
  1918. {
  1919. struct sk_buff *skb = NULL;
  1920. void *ep;
  1921. struct t3cdev *tdev;
  1922. int ret;
  1923. while ((skb = skb_dequeue(&rxq))) {
  1924. ep = *((void **) (skb->cb));
  1925. tdev = *((struct t3cdev **) (skb->cb + sizeof(void *)));
  1926. ret = work_handlers[G_OPCODE(ntohl((__force __be32)skb->csum))](tdev, skb, ep);
  1927. if (ret & CPL_RET_BUF_DONE)
  1928. kfree_skb(skb);
  1929. /*
  1930. * ep was referenced in sched(), and is freed here.
  1931. */
  1932. put_ep((struct iwch_ep_common *)ep);
  1933. }
  1934. }
  1935. static DECLARE_WORK(skb_work, process_work);
  1936. static int sched(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1937. {
  1938. struct iwch_ep_common *epc = ctx;
  1939. get_ep(epc);
  1940. /*
  1941. * Save ctx and tdev in the skb->cb area.
  1942. */
  1943. *((void **) skb->cb) = ctx;
  1944. *((struct t3cdev **) (skb->cb + sizeof(void *))) = tdev;
  1945. /*
  1946. * Queue the skb and schedule the worker thread.
  1947. */
  1948. skb_queue_tail(&rxq, skb);
  1949. queue_work(workq, &skb_work);
  1950. return 0;
  1951. }
  1952. static int set_tcb_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1953. {
  1954. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  1955. if (rpl->status != CPL_ERR_NONE) {
  1956. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  1957. "for tid %u\n", rpl->status, GET_TID(rpl));
  1958. }
  1959. return CPL_RET_BUF_DONE;
  1960. }
  1961. /*
  1962. * All upcalls from the T3 Core go to sched() to schedule the
  1963. * processing on a work queue.
  1964. */
  1965. cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS] = {
  1966. [CPL_ACT_ESTABLISH] = sched,
  1967. [CPL_ACT_OPEN_RPL] = sched,
  1968. [CPL_RX_DATA] = sched,
  1969. [CPL_TX_DMA_ACK] = sched,
  1970. [CPL_ABORT_RPL_RSS] = sched,
  1971. [CPL_ABORT_RPL] = sched,
  1972. [CPL_PASS_OPEN_RPL] = sched,
  1973. [CPL_CLOSE_LISTSRV_RPL] = sched,
  1974. [CPL_PASS_ACCEPT_REQ] = sched,
  1975. [CPL_PASS_ESTABLISH] = sched,
  1976. [CPL_PEER_CLOSE] = sched,
  1977. [CPL_CLOSE_CON_RPL] = sched,
  1978. [CPL_ABORT_REQ_RSS] = sched,
  1979. [CPL_RDMA_TERMINATE] = sched,
  1980. [CPL_RDMA_EC_STATUS] = sched,
  1981. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  1982. };
  1983. int __init iwch_cm_init(void)
  1984. {
  1985. skb_queue_head_init(&rxq);
  1986. workq = create_singlethread_workqueue("iw_cxgb3");
  1987. if (!workq)
  1988. return -ENOMEM;
  1989. return 0;
  1990. }
  1991. void __exit iwch_cm_term(void)
  1992. {
  1993. flush_workqueue(workq);
  1994. destroy_workqueue(workq);
  1995. }