iwch_cm.c 57 KB

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