iwch_cm.c 57 KB

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