iwch_cm.c 57 KB

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