iwch_cm.c 57 KB

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