iwch_cm.c 57 KB

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