iwch_cm.c 57 KB

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