iwch_cm.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  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.
  1293. */
  1294. __state_set(&ep->com, CLOSING);
  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 (!test_and_set_bit(PEER_ABORT_IN_PROGRESS, &ep->com.flags)) {
  1372. return CPL_RET_BUF_DONE;
  1373. }
  1374. spin_lock_irqsave(&ep->com.lock, flags);
  1375. PDBG("%s ep %p state %u\n", __func__, ep, ep->com.state);
  1376. switch (ep->com.state) {
  1377. case CONNECTING:
  1378. break;
  1379. case MPA_REQ_WAIT:
  1380. stop_ep_timer(ep);
  1381. break;
  1382. case MPA_REQ_SENT:
  1383. stop_ep_timer(ep);
  1384. connect_reply_upcall(ep, -ECONNRESET);
  1385. break;
  1386. case MPA_REP_SENT:
  1387. ep->com.rpl_done = 1;
  1388. ep->com.rpl_err = -ECONNRESET;
  1389. PDBG("waking up ep %p\n", ep);
  1390. wake_up(&ep->com.waitq);
  1391. break;
  1392. case MPA_REQ_RCVD:
  1393. /*
  1394. * We're gonna mark this puppy DEAD, but keep
  1395. * the reference on it until the ULP accepts or
  1396. * rejects the CR.
  1397. */
  1398. break;
  1399. case MORIBUND:
  1400. case CLOSING:
  1401. stop_ep_timer(ep);
  1402. /*FALLTHROUGH*/
  1403. case FPDU_MODE:
  1404. if (ep->com.cm_id && ep->com.qp) {
  1405. attrs.next_state = IWCH_QP_STATE_ERROR;
  1406. ret = iwch_modify_qp(ep->com.qp->rhp,
  1407. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1408. &attrs, 1);
  1409. if (ret)
  1410. printk(KERN_ERR MOD
  1411. "%s - qp <- error failed!\n",
  1412. __func__);
  1413. }
  1414. peer_abort_upcall(ep);
  1415. break;
  1416. case ABORTING:
  1417. break;
  1418. case DEAD:
  1419. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1420. spin_unlock_irqrestore(&ep->com.lock, flags);
  1421. return CPL_RET_BUF_DONE;
  1422. default:
  1423. BUG_ON(1);
  1424. break;
  1425. }
  1426. dst_confirm(ep->dst);
  1427. if (ep->com.state != ABORTING) {
  1428. __state_set(&ep->com, DEAD);
  1429. release = 1;
  1430. }
  1431. spin_unlock_irqrestore(&ep->com.lock, flags);
  1432. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1433. if (!rpl_skb) {
  1434. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  1435. __func__);
  1436. release = 1;
  1437. goto out;
  1438. }
  1439. rpl_skb->priority = CPL_PRIORITY_DATA;
  1440. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  1441. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL));
  1442. rpl->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  1443. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  1444. rpl->cmd = CPL_ABORT_NO_RST;
  1445. iwch_cxgb3_ofld_send(ep->com.tdev, rpl_skb);
  1446. out:
  1447. if (release)
  1448. release_ep_resources(ep);
  1449. return CPL_RET_BUF_DONE;
  1450. }
  1451. static int close_con_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1452. {
  1453. struct iwch_ep *ep = ctx;
  1454. struct iwch_qp_attributes attrs;
  1455. unsigned long flags;
  1456. int release = 0;
  1457. PDBG("%s ep %p\n", __func__, ep);
  1458. BUG_ON(!ep);
  1459. /* The cm_id may be null if we failed to connect */
  1460. spin_lock_irqsave(&ep->com.lock, flags);
  1461. switch (ep->com.state) {
  1462. case CLOSING:
  1463. __state_set(&ep->com, MORIBUND);
  1464. break;
  1465. case MORIBUND:
  1466. stop_ep_timer(ep);
  1467. if ((ep->com.cm_id) && (ep->com.qp)) {
  1468. attrs.next_state = IWCH_QP_STATE_IDLE;
  1469. iwch_modify_qp(ep->com.qp->rhp,
  1470. ep->com.qp,
  1471. IWCH_QP_ATTR_NEXT_STATE,
  1472. &attrs, 1);
  1473. }
  1474. close_complete_upcall(ep);
  1475. __state_set(&ep->com, DEAD);
  1476. release = 1;
  1477. break;
  1478. case ABORTING:
  1479. case DEAD:
  1480. break;
  1481. default:
  1482. BUG_ON(1);
  1483. break;
  1484. }
  1485. spin_unlock_irqrestore(&ep->com.lock, flags);
  1486. if (release)
  1487. release_ep_resources(ep);
  1488. return CPL_RET_BUF_DONE;
  1489. }
  1490. /*
  1491. * T3A does 3 things when a TERM is received:
  1492. * 1) send up a CPL_RDMA_TERMINATE message with the TERM packet
  1493. * 2) generate an async event on the QP with the TERMINATE opcode
  1494. * 3) post a TERMINATE opcde cqe into the associated CQ.
  1495. *
  1496. * For (1), we save the message in the qp for later consumer consumption.
  1497. * For (2), we move the QP into TERMINATE, post a QP event and disconnect.
  1498. * For (3), we toss the CQE in cxio_poll_cq().
  1499. *
  1500. * terminate() handles case (1)...
  1501. */
  1502. static int terminate(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1503. {
  1504. struct iwch_ep *ep = ctx;
  1505. if (state_read(&ep->com) != FPDU_MODE)
  1506. return CPL_RET_BUF_DONE;
  1507. PDBG("%s ep %p\n", __func__, ep);
  1508. skb_pull(skb, sizeof(struct cpl_rdma_terminate));
  1509. PDBG("%s saving %d bytes of term msg\n", __func__, skb->len);
  1510. skb_copy_from_linear_data(skb, ep->com.qp->attr.terminate_buffer,
  1511. skb->len);
  1512. ep->com.qp->attr.terminate_msg_len = skb->len;
  1513. ep->com.qp->attr.is_terminate_local = 0;
  1514. return CPL_RET_BUF_DONE;
  1515. }
  1516. static int ec_status(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1517. {
  1518. struct cpl_rdma_ec_status *rep = cplhdr(skb);
  1519. struct iwch_ep *ep = ctx;
  1520. PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid,
  1521. rep->status);
  1522. if (rep->status) {
  1523. struct iwch_qp_attributes attrs;
  1524. printk(KERN_ERR MOD "%s BAD CLOSE - Aborting tid %u\n",
  1525. __func__, ep->hwtid);
  1526. stop_ep_timer(ep);
  1527. attrs.next_state = IWCH_QP_STATE_ERROR;
  1528. iwch_modify_qp(ep->com.qp->rhp,
  1529. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1530. &attrs, 1);
  1531. abort_connection(ep, NULL, GFP_KERNEL);
  1532. }
  1533. return CPL_RET_BUF_DONE;
  1534. }
  1535. static void ep_timeout(unsigned long arg)
  1536. {
  1537. struct iwch_ep *ep = (struct iwch_ep *)arg;
  1538. struct iwch_qp_attributes attrs;
  1539. unsigned long flags;
  1540. int abort = 1;
  1541. spin_lock_irqsave(&ep->com.lock, flags);
  1542. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  1543. ep->com.state);
  1544. switch (ep->com.state) {
  1545. case MPA_REQ_SENT:
  1546. __state_set(&ep->com, ABORTING);
  1547. connect_reply_upcall(ep, -ETIMEDOUT);
  1548. break;
  1549. case MPA_REQ_WAIT:
  1550. __state_set(&ep->com, ABORTING);
  1551. break;
  1552. case CLOSING:
  1553. case MORIBUND:
  1554. if (ep->com.cm_id && ep->com.qp) {
  1555. attrs.next_state = IWCH_QP_STATE_ERROR;
  1556. iwch_modify_qp(ep->com.qp->rhp,
  1557. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1558. &attrs, 1);
  1559. }
  1560. __state_set(&ep->com, ABORTING);
  1561. break;
  1562. default:
  1563. printk(KERN_ERR "%s unexpected state ep %p state %u\n",
  1564. __func__, ep, ep->com.state);
  1565. WARN_ON(1);
  1566. abort = 0;
  1567. }
  1568. spin_unlock_irqrestore(&ep->com.lock, flags);
  1569. if (abort)
  1570. abort_connection(ep, NULL, GFP_ATOMIC);
  1571. put_ep(&ep->com);
  1572. }
  1573. int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  1574. {
  1575. int err;
  1576. struct iwch_ep *ep = to_ep(cm_id);
  1577. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1578. if (state_read(&ep->com) == DEAD) {
  1579. put_ep(&ep->com);
  1580. return -ECONNRESET;
  1581. }
  1582. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1583. if (mpa_rev == 0)
  1584. abort_connection(ep, NULL, GFP_KERNEL);
  1585. else {
  1586. err = send_mpa_reject(ep, pdata, pdata_len);
  1587. err = iwch_ep_disconnect(ep, 0, GFP_KERNEL);
  1588. }
  1589. put_ep(&ep->com);
  1590. return 0;
  1591. }
  1592. int iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1593. {
  1594. int err;
  1595. struct iwch_qp_attributes attrs;
  1596. enum iwch_qp_attr_mask mask;
  1597. struct iwch_ep *ep = to_ep(cm_id);
  1598. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1599. struct iwch_qp *qp = get_qhp(h, conn_param->qpn);
  1600. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1601. if (state_read(&ep->com) == DEAD) {
  1602. err = -ECONNRESET;
  1603. goto err;
  1604. }
  1605. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1606. BUG_ON(!qp);
  1607. if ((conn_param->ord > qp->rhp->attr.max_rdma_read_qp_depth) ||
  1608. (conn_param->ird > qp->rhp->attr.max_rdma_reads_per_qp)) {
  1609. abort_connection(ep, NULL, GFP_KERNEL);
  1610. err = -EINVAL;
  1611. goto err;
  1612. }
  1613. cm_id->add_ref(cm_id);
  1614. ep->com.cm_id = cm_id;
  1615. ep->com.qp = qp;
  1616. ep->com.rpl_done = 0;
  1617. ep->com.rpl_err = 0;
  1618. ep->ird = conn_param->ird;
  1619. ep->ord = conn_param->ord;
  1620. if (peer2peer && ep->ird == 0)
  1621. ep->ird = 1;
  1622. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  1623. /* bind QP to EP and move to RTS */
  1624. attrs.mpa_attr = ep->mpa_attr;
  1625. attrs.max_ird = ep->ird;
  1626. attrs.max_ord = ep->ord;
  1627. attrs.llp_stream_handle = ep;
  1628. attrs.next_state = IWCH_QP_STATE_RTS;
  1629. /* bind QP and TID with INIT_WR */
  1630. mask = IWCH_QP_ATTR_NEXT_STATE |
  1631. IWCH_QP_ATTR_LLP_STREAM_HANDLE |
  1632. IWCH_QP_ATTR_MPA_ATTR |
  1633. IWCH_QP_ATTR_MAX_IRD |
  1634. IWCH_QP_ATTR_MAX_ORD;
  1635. err = iwch_modify_qp(ep->com.qp->rhp,
  1636. ep->com.qp, mask, &attrs, 1);
  1637. if (err)
  1638. goto err1;
  1639. /* if needed, wait for wr_ack */
  1640. if (iwch_rqes_posted(qp)) {
  1641. wait_event(ep->com.waitq, ep->com.rpl_done);
  1642. err = ep->com.rpl_err;
  1643. if (err)
  1644. goto err1;
  1645. }
  1646. err = send_mpa_reply(ep, conn_param->private_data,
  1647. conn_param->private_data_len);
  1648. if (err)
  1649. goto err1;
  1650. state_set(&ep->com, FPDU_MODE);
  1651. established_upcall(ep);
  1652. put_ep(&ep->com);
  1653. return 0;
  1654. err1:
  1655. ep->com.cm_id = NULL;
  1656. ep->com.qp = NULL;
  1657. cm_id->rem_ref(cm_id);
  1658. err:
  1659. put_ep(&ep->com);
  1660. return err;
  1661. }
  1662. static int is_loopback_dst(struct iw_cm_id *cm_id)
  1663. {
  1664. struct net_device *dev;
  1665. dev = ip_dev_find(&init_net, cm_id->remote_addr.sin_addr.s_addr);
  1666. if (!dev)
  1667. return 0;
  1668. dev_put(dev);
  1669. return 1;
  1670. }
  1671. int iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1672. {
  1673. int err = 0;
  1674. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1675. struct iwch_ep *ep;
  1676. struct rtable *rt;
  1677. if (is_loopback_dst(cm_id)) {
  1678. err = -ENOSYS;
  1679. goto out;
  1680. }
  1681. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1682. if (!ep) {
  1683. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1684. err = -ENOMEM;
  1685. goto out;
  1686. }
  1687. init_timer(&ep->timer);
  1688. ep->plen = conn_param->private_data_len;
  1689. if (ep->plen)
  1690. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  1691. conn_param->private_data, ep->plen);
  1692. ep->ird = conn_param->ird;
  1693. ep->ord = conn_param->ord;
  1694. if (peer2peer && ep->ord == 0)
  1695. ep->ord = 1;
  1696. ep->com.tdev = h->rdev.t3cdev_p;
  1697. cm_id->add_ref(cm_id);
  1698. ep->com.cm_id = cm_id;
  1699. ep->com.qp = get_qhp(h, conn_param->qpn);
  1700. BUG_ON(!ep->com.qp);
  1701. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  1702. ep->com.qp, cm_id);
  1703. /*
  1704. * Allocate an active TID to initiate a TCP connection.
  1705. */
  1706. ep->atid = cxgb3_alloc_atid(h->rdev.t3cdev_p, &t3c_client, ep);
  1707. if (ep->atid == -1) {
  1708. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1709. err = -ENOMEM;
  1710. goto fail2;
  1711. }
  1712. /* find a route */
  1713. rt = find_route(h->rdev.t3cdev_p,
  1714. cm_id->local_addr.sin_addr.s_addr,
  1715. cm_id->remote_addr.sin_addr.s_addr,
  1716. cm_id->local_addr.sin_port,
  1717. cm_id->remote_addr.sin_port, IPTOS_LOWDELAY);
  1718. if (!rt) {
  1719. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  1720. err = -EHOSTUNREACH;
  1721. goto fail3;
  1722. }
  1723. ep->dst = &rt->u.dst;
  1724. /* get a l2t entry */
  1725. ep->l2t = t3_l2t_get(ep->com.tdev, ep->dst->neighbour,
  1726. ep->dst->neighbour->dev);
  1727. if (!ep->l2t) {
  1728. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  1729. err = -ENOMEM;
  1730. goto fail4;
  1731. }
  1732. state_set(&ep->com, CONNECTING);
  1733. ep->tos = IPTOS_LOWDELAY;
  1734. ep->com.local_addr = cm_id->local_addr;
  1735. ep->com.remote_addr = cm_id->remote_addr;
  1736. /* send connect request to rnic */
  1737. err = send_connect(ep);
  1738. if (!err)
  1739. goto out;
  1740. l2t_release(L2DATA(h->rdev.t3cdev_p), ep->l2t);
  1741. fail4:
  1742. dst_release(ep->dst);
  1743. fail3:
  1744. cxgb3_free_atid(ep->com.tdev, ep->atid);
  1745. fail2:
  1746. cm_id->rem_ref(cm_id);
  1747. put_ep(&ep->com);
  1748. out:
  1749. return err;
  1750. }
  1751. int iwch_create_listen(struct iw_cm_id *cm_id, int backlog)
  1752. {
  1753. int err = 0;
  1754. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1755. struct iwch_listen_ep *ep;
  1756. might_sleep();
  1757. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1758. if (!ep) {
  1759. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1760. err = -ENOMEM;
  1761. goto fail1;
  1762. }
  1763. PDBG("%s ep %p\n", __func__, ep);
  1764. ep->com.tdev = h->rdev.t3cdev_p;
  1765. cm_id->add_ref(cm_id);
  1766. ep->com.cm_id = cm_id;
  1767. ep->backlog = backlog;
  1768. ep->com.local_addr = cm_id->local_addr;
  1769. /*
  1770. * Allocate a server TID.
  1771. */
  1772. ep->stid = cxgb3_alloc_stid(h->rdev.t3cdev_p, &t3c_client, ep);
  1773. if (ep->stid == -1) {
  1774. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1775. err = -ENOMEM;
  1776. goto fail2;
  1777. }
  1778. state_set(&ep->com, LISTEN);
  1779. err = listen_start(ep);
  1780. if (err)
  1781. goto fail3;
  1782. /* wait for pass_open_rpl */
  1783. wait_event(ep->com.waitq, ep->com.rpl_done);
  1784. err = ep->com.rpl_err;
  1785. if (!err) {
  1786. cm_id->provider_data = ep;
  1787. goto out;
  1788. }
  1789. fail3:
  1790. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1791. fail2:
  1792. cm_id->rem_ref(cm_id);
  1793. put_ep(&ep->com);
  1794. fail1:
  1795. out:
  1796. return err;
  1797. }
  1798. int iwch_destroy_listen(struct iw_cm_id *cm_id)
  1799. {
  1800. int err;
  1801. struct iwch_listen_ep *ep = to_listen_ep(cm_id);
  1802. PDBG("%s ep %p\n", __func__, ep);
  1803. might_sleep();
  1804. state_set(&ep->com, DEAD);
  1805. ep->com.rpl_done = 0;
  1806. ep->com.rpl_err = 0;
  1807. err = listen_stop(ep);
  1808. if (err)
  1809. goto done;
  1810. wait_event(ep->com.waitq, ep->com.rpl_done);
  1811. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1812. done:
  1813. err = ep->com.rpl_err;
  1814. cm_id->rem_ref(cm_id);
  1815. put_ep(&ep->com);
  1816. return err;
  1817. }
  1818. int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp)
  1819. {
  1820. int ret=0;
  1821. unsigned long flags;
  1822. int close = 0;
  1823. int fatal = 0;
  1824. struct t3cdev *tdev;
  1825. struct cxio_rdev *rdev;
  1826. spin_lock_irqsave(&ep->com.lock, flags);
  1827. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  1828. states[ep->com.state], abrupt);
  1829. tdev = (struct t3cdev *)ep->com.tdev;
  1830. rdev = (struct cxio_rdev *)tdev->ulp;
  1831. if (cxio_fatal_error(rdev)) {
  1832. fatal = 1;
  1833. close_complete_upcall(ep);
  1834. ep->com.state = DEAD;
  1835. }
  1836. switch (ep->com.state) {
  1837. case MPA_REQ_WAIT:
  1838. case MPA_REQ_SENT:
  1839. case MPA_REQ_RCVD:
  1840. case MPA_REP_SENT:
  1841. case FPDU_MODE:
  1842. close = 1;
  1843. if (abrupt)
  1844. ep->com.state = ABORTING;
  1845. else {
  1846. ep->com.state = CLOSING;
  1847. start_ep_timer(ep);
  1848. }
  1849. set_bit(CLOSE_SENT, &ep->com.flags);
  1850. break;
  1851. case CLOSING:
  1852. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  1853. close = 1;
  1854. if (abrupt) {
  1855. stop_ep_timer(ep);
  1856. ep->com.state = ABORTING;
  1857. } else
  1858. ep->com.state = MORIBUND;
  1859. }
  1860. break;
  1861. case MORIBUND:
  1862. case ABORTING:
  1863. case DEAD:
  1864. PDBG("%s ignoring disconnect ep %p state %u\n",
  1865. __func__, ep, ep->com.state);
  1866. break;
  1867. default:
  1868. BUG();
  1869. break;
  1870. }
  1871. spin_unlock_irqrestore(&ep->com.lock, flags);
  1872. if (close) {
  1873. if (abrupt)
  1874. ret = send_abort(ep, NULL, gfp);
  1875. else
  1876. ret = send_halfclose(ep, gfp);
  1877. if (ret)
  1878. fatal = 1;
  1879. }
  1880. if (fatal)
  1881. release_ep_resources(ep);
  1882. return ret;
  1883. }
  1884. int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
  1885. struct l2t_entry *l2t)
  1886. {
  1887. struct iwch_ep *ep = ctx;
  1888. if (ep->dst != old)
  1889. return 0;
  1890. PDBG("%s ep %p redirect to dst %p l2t %p\n", __func__, ep, new,
  1891. l2t);
  1892. dst_hold(new);
  1893. l2t_release(L2DATA(ep->com.tdev), ep->l2t);
  1894. ep->l2t = l2t;
  1895. dst_release(old);
  1896. ep->dst = new;
  1897. return 1;
  1898. }
  1899. /*
  1900. * All the CM events are handled on a work queue to have a safe context.
  1901. */
  1902. static int sched(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1903. {
  1904. struct iwch_ep_common *epc = ctx;
  1905. get_ep(epc);
  1906. /*
  1907. * Save ctx and tdev in the skb->cb area.
  1908. */
  1909. *((void **) skb->cb) = ctx;
  1910. *((struct t3cdev **) (skb->cb + sizeof(void *))) = tdev;
  1911. /*
  1912. * Queue the skb and schedule the worker thread.
  1913. */
  1914. skb_queue_tail(&rxq, skb);
  1915. queue_work(workq, &skb_work);
  1916. return 0;
  1917. }
  1918. static int set_tcb_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1919. {
  1920. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  1921. if (rpl->status != CPL_ERR_NONE) {
  1922. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  1923. "for tid %u\n", rpl->status, GET_TID(rpl));
  1924. }
  1925. return CPL_RET_BUF_DONE;
  1926. }
  1927. int __init iwch_cm_init(void)
  1928. {
  1929. skb_queue_head_init(&rxq);
  1930. workq = create_singlethread_workqueue("iw_cxgb3");
  1931. if (!workq)
  1932. return -ENOMEM;
  1933. /*
  1934. * All upcalls from the T3 Core go to sched() to
  1935. * schedule the processing on a work queue.
  1936. */
  1937. t3c_handlers[CPL_ACT_ESTABLISH] = sched;
  1938. t3c_handlers[CPL_ACT_OPEN_RPL] = sched;
  1939. t3c_handlers[CPL_RX_DATA] = sched;
  1940. t3c_handlers[CPL_TX_DMA_ACK] = sched;
  1941. t3c_handlers[CPL_ABORT_RPL_RSS] = sched;
  1942. t3c_handlers[CPL_ABORT_RPL] = sched;
  1943. t3c_handlers[CPL_PASS_OPEN_RPL] = sched;
  1944. t3c_handlers[CPL_CLOSE_LISTSRV_RPL] = sched;
  1945. t3c_handlers[CPL_PASS_ACCEPT_REQ] = sched;
  1946. t3c_handlers[CPL_PASS_ESTABLISH] = sched;
  1947. t3c_handlers[CPL_PEER_CLOSE] = sched;
  1948. t3c_handlers[CPL_CLOSE_CON_RPL] = sched;
  1949. t3c_handlers[CPL_ABORT_REQ_RSS] = sched;
  1950. t3c_handlers[CPL_RDMA_TERMINATE] = sched;
  1951. t3c_handlers[CPL_RDMA_EC_STATUS] = sched;
  1952. t3c_handlers[CPL_SET_TCB_RPL] = set_tcb_rpl;
  1953. /*
  1954. * These are the real handlers that are called from a
  1955. * work queue.
  1956. */
  1957. work_handlers[CPL_ACT_ESTABLISH] = act_establish;
  1958. work_handlers[CPL_ACT_OPEN_RPL] = act_open_rpl;
  1959. work_handlers[CPL_RX_DATA] = rx_data;
  1960. work_handlers[CPL_TX_DMA_ACK] = tx_ack;
  1961. work_handlers[CPL_ABORT_RPL_RSS] = abort_rpl;
  1962. work_handlers[CPL_ABORT_RPL] = abort_rpl;
  1963. work_handlers[CPL_PASS_OPEN_RPL] = pass_open_rpl;
  1964. work_handlers[CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl;
  1965. work_handlers[CPL_PASS_ACCEPT_REQ] = pass_accept_req;
  1966. work_handlers[CPL_PASS_ESTABLISH] = pass_establish;
  1967. work_handlers[CPL_PEER_CLOSE] = peer_close;
  1968. work_handlers[CPL_ABORT_REQ_RSS] = peer_abort;
  1969. work_handlers[CPL_CLOSE_CON_RPL] = close_con_rpl;
  1970. work_handlers[CPL_RDMA_TERMINATE] = terminate;
  1971. work_handlers[CPL_RDMA_EC_STATUS] = ec_status;
  1972. return 0;
  1973. }
  1974. void __exit iwch_cm_term(void)
  1975. {
  1976. flush_workqueue(workq);
  1977. destroy_workqueue(workq);
  1978. }