iwch_cm.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251
  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. static 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 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. PDBG("%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. printk(KERN_ERR MOD "ARP failure duing 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. PDBG("%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. PDBG("%s ep %p\n", __func__, ep);
  343. skb = get_skb(NULL, sizeof(*req), gfp);
  344. if (!skb) {
  345. printk(KERN_ERR MOD "%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 = (struct cpl_close_con_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. PDBG("%s ep %p\n", __func__, ep);
  360. skb = get_skb(skb, sizeof(*req), gfp);
  361. if (!skb) {
  362. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  363. __func__);
  364. return -ENOMEM;
  365. }
  366. skb->priority = CPL_PRIORITY_DATA;
  367. set_arp_failure_handler(skb, abort_arp_failure);
  368. req = (struct cpl_abort_req *) skb_put(skb, sizeof(*req));
  369. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ));
  370. req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  371. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
  372. req->cmd = CPL_ABORT_SEND_RST;
  373. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  374. }
  375. static int send_connect(struct iwch_ep *ep)
  376. {
  377. struct cpl_act_open_req *req;
  378. struct sk_buff *skb;
  379. u32 opt0h, opt0l, opt2;
  380. unsigned int mtu_idx;
  381. int wscale;
  382. PDBG("%s ep %p\n", __func__, ep);
  383. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  384. if (!skb) {
  385. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  386. __func__);
  387. return -ENOMEM;
  388. }
  389. mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst));
  390. wscale = compute_wscale(rcv_win);
  391. opt0h = V_NAGLE(0) |
  392. V_NO_CONG(nocong) |
  393. V_KEEP_ALIVE(1) |
  394. F_TCAM_BYPASS |
  395. V_WND_SCALE(wscale) |
  396. V_MSS_IDX(mtu_idx) |
  397. V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
  398. opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
  399. opt2 = F_RX_COALESCE_VALID | V_RX_COALESCE(0) | V_FLAVORS_VALID(1) |
  400. V_CONG_CONTROL_FLAVOR(cong_flavor);
  401. skb->priority = CPL_PRIORITY_SETUP;
  402. set_arp_failure_handler(skb, act_open_req_arp_failure);
  403. req = (struct cpl_act_open_req *) skb_put(skb, sizeof(*req));
  404. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  405. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ep->atid));
  406. req->local_port = ep->com.local_addr.sin_port;
  407. req->peer_port = ep->com.remote_addr.sin_port;
  408. req->local_ip = ep->com.local_addr.sin_addr.s_addr;
  409. req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
  410. req->opt0h = htonl(opt0h);
  411. req->opt0l = htonl(opt0l);
  412. req->params = 0;
  413. req->opt2 = htonl(opt2);
  414. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  415. }
  416. static void send_mpa_req(struct iwch_ep *ep, struct sk_buff *skb)
  417. {
  418. int mpalen;
  419. struct tx_data_wr *req;
  420. struct mpa_message *mpa;
  421. int len;
  422. PDBG("%s ep %p pd_len %d\n", __func__, ep, ep->plen);
  423. BUG_ON(skb_cloned(skb));
  424. mpalen = sizeof(*mpa) + ep->plen;
  425. if (skb->data + mpalen + sizeof(*req) > skb_end_pointer(skb)) {
  426. kfree_skb(skb);
  427. skb=alloc_skb(mpalen + sizeof(*req), GFP_KERNEL);
  428. if (!skb) {
  429. connect_reply_upcall(ep, -ENOMEM);
  430. return;
  431. }
  432. }
  433. skb_trim(skb, 0);
  434. skb_reserve(skb, sizeof(*req));
  435. skb_put(skb, mpalen);
  436. skb->priority = CPL_PRIORITY_DATA;
  437. mpa = (struct mpa_message *) skb->data;
  438. memset(mpa, 0, sizeof(*mpa));
  439. memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
  440. mpa->flags = (crc_enabled ? MPA_CRC : 0) |
  441. (markers_enabled ? MPA_MARKERS : 0);
  442. mpa->private_data_size = htons(ep->plen);
  443. mpa->revision = mpa_rev;
  444. if (ep->plen)
  445. memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen);
  446. /*
  447. * Reference the mpa skb. This ensures the data area
  448. * will remain in memory until the hw acks the tx.
  449. * Function tx_ack() will deref it.
  450. */
  451. skb_get(skb);
  452. set_arp_failure_handler(skb, arp_failure_discard);
  453. skb_reset_transport_header(skb);
  454. len = skb->len;
  455. req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
  456. req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
  457. req->wr_lo = htonl(V_WR_TID(ep->hwtid));
  458. req->len = htonl(len);
  459. req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
  460. V_TX_SNDBUF(snd_win>>15));
  461. req->flags = htonl(F_TX_INIT);
  462. req->sndseq = htonl(ep->snd_seq);
  463. BUG_ON(ep->mpa_skb);
  464. ep->mpa_skb = skb;
  465. iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  466. start_ep_timer(ep);
  467. state_set(&ep->com, MPA_REQ_SENT);
  468. return;
  469. }
  470. static int send_mpa_reject(struct iwch_ep *ep, const void *pdata, u8 plen)
  471. {
  472. int mpalen;
  473. struct tx_data_wr *req;
  474. struct mpa_message *mpa;
  475. struct sk_buff *skb;
  476. PDBG("%s ep %p plen %d\n", __func__, ep, plen);
  477. mpalen = sizeof(*mpa) + plen;
  478. skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL);
  479. if (!skb) {
  480. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  481. return -ENOMEM;
  482. }
  483. skb_reserve(skb, sizeof(*req));
  484. mpa = (struct mpa_message *) skb_put(skb, mpalen);
  485. memset(mpa, 0, sizeof(*mpa));
  486. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  487. mpa->flags = MPA_REJECT;
  488. mpa->revision = mpa_rev;
  489. mpa->private_data_size = htons(plen);
  490. if (plen)
  491. memcpy(mpa->private_data, pdata, plen);
  492. /*
  493. * Reference the mpa skb again. This ensures the data area
  494. * will remain in memory until the hw acks the tx.
  495. * Function tx_ack() will deref it.
  496. */
  497. skb_get(skb);
  498. skb->priority = CPL_PRIORITY_DATA;
  499. set_arp_failure_handler(skb, arp_failure_discard);
  500. skb_reset_transport_header(skb);
  501. req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
  502. req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
  503. req->wr_lo = htonl(V_WR_TID(ep->hwtid));
  504. req->len = htonl(mpalen);
  505. req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
  506. V_TX_SNDBUF(snd_win>>15));
  507. req->flags = htonl(F_TX_INIT);
  508. req->sndseq = htonl(ep->snd_seq);
  509. BUG_ON(ep->mpa_skb);
  510. ep->mpa_skb = skb;
  511. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  512. }
  513. static int send_mpa_reply(struct iwch_ep *ep, const void *pdata, u8 plen)
  514. {
  515. int mpalen;
  516. struct tx_data_wr *req;
  517. struct mpa_message *mpa;
  518. int len;
  519. struct sk_buff *skb;
  520. PDBG("%s ep %p plen %d\n", __func__, ep, plen);
  521. mpalen = sizeof(*mpa) + plen;
  522. skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL);
  523. if (!skb) {
  524. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  525. return -ENOMEM;
  526. }
  527. skb->priority = CPL_PRIORITY_DATA;
  528. skb_reserve(skb, sizeof(*req));
  529. mpa = (struct mpa_message *) skb_put(skb, mpalen);
  530. memset(mpa, 0, sizeof(*mpa));
  531. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  532. mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
  533. (markers_enabled ? MPA_MARKERS : 0);
  534. mpa->revision = mpa_rev;
  535. mpa->private_data_size = htons(plen);
  536. if (plen)
  537. memcpy(mpa->private_data, pdata, plen);
  538. /*
  539. * Reference the mpa skb. This ensures the data area
  540. * will remain in memory until the hw acks the tx.
  541. * Function tx_ack() will deref it.
  542. */
  543. skb_get(skb);
  544. set_arp_failure_handler(skb, arp_failure_discard);
  545. skb_reset_transport_header(skb);
  546. len = skb->len;
  547. req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
  548. req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
  549. req->wr_lo = htonl(V_WR_TID(ep->hwtid));
  550. req->len = htonl(len);
  551. req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
  552. V_TX_SNDBUF(snd_win>>15));
  553. req->flags = htonl(F_TX_INIT);
  554. req->sndseq = htonl(ep->snd_seq);
  555. ep->mpa_skb = skb;
  556. state_set(&ep->com, MPA_REP_SENT);
  557. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  558. }
  559. static int act_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  560. {
  561. struct iwch_ep *ep = ctx;
  562. struct cpl_act_establish *req = cplhdr(skb);
  563. unsigned int tid = GET_TID(req);
  564. PDBG("%s ep %p tid %d\n", __func__, ep, tid);
  565. dst_confirm(ep->dst);
  566. /* setup the hwtid for this connection */
  567. ep->hwtid = tid;
  568. cxgb3_insert_tid(ep->com.tdev, &t3c_client, ep, tid);
  569. ep->snd_seq = ntohl(req->snd_isn);
  570. ep->rcv_seq = ntohl(req->rcv_isn);
  571. set_emss(ep, ntohs(req->tcp_opt));
  572. /* dealloc the atid */
  573. cxgb3_free_atid(ep->com.tdev, ep->atid);
  574. /* start MPA negotiation */
  575. send_mpa_req(ep, skb);
  576. return 0;
  577. }
  578. static void abort_connection(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp)
  579. {
  580. PDBG("%s ep %p\n", __FILE__, ep);
  581. state_set(&ep->com, ABORTING);
  582. send_abort(ep, skb, gfp);
  583. }
  584. static void close_complete_upcall(struct iwch_ep *ep)
  585. {
  586. struct iw_cm_event event;
  587. PDBG("%s ep %p\n", __func__, ep);
  588. memset(&event, 0, sizeof(event));
  589. event.event = IW_CM_EVENT_CLOSE;
  590. if (ep->com.cm_id) {
  591. PDBG("close complete delivered ep %p cm_id %p tid %d\n",
  592. ep, ep->com.cm_id, ep->hwtid);
  593. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  594. ep->com.cm_id->rem_ref(ep->com.cm_id);
  595. ep->com.cm_id = NULL;
  596. ep->com.qp = NULL;
  597. }
  598. }
  599. static void peer_close_upcall(struct iwch_ep *ep)
  600. {
  601. struct iw_cm_event event;
  602. PDBG("%s ep %p\n", __func__, ep);
  603. memset(&event, 0, sizeof(event));
  604. event.event = IW_CM_EVENT_DISCONNECT;
  605. if (ep->com.cm_id) {
  606. PDBG("peer close delivered ep %p cm_id %p tid %d\n",
  607. ep, ep->com.cm_id, ep->hwtid);
  608. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  609. }
  610. }
  611. static void peer_abort_upcall(struct iwch_ep *ep)
  612. {
  613. struct iw_cm_event event;
  614. PDBG("%s ep %p\n", __func__, ep);
  615. memset(&event, 0, sizeof(event));
  616. event.event = IW_CM_EVENT_CLOSE;
  617. event.status = -ECONNRESET;
  618. if (ep->com.cm_id) {
  619. PDBG("abort delivered ep %p cm_id %p tid %d\n", ep,
  620. ep->com.cm_id, ep->hwtid);
  621. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  622. ep->com.cm_id->rem_ref(ep->com.cm_id);
  623. ep->com.cm_id = NULL;
  624. ep->com.qp = NULL;
  625. }
  626. }
  627. static void connect_reply_upcall(struct iwch_ep *ep, int status)
  628. {
  629. struct iw_cm_event event;
  630. PDBG("%s ep %p status %d\n", __func__, ep, status);
  631. memset(&event, 0, sizeof(event));
  632. event.event = IW_CM_EVENT_CONNECT_REPLY;
  633. event.status = status;
  634. event.local_addr = ep->com.local_addr;
  635. event.remote_addr = 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. PDBG("%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. PDBG("%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. event.local_addr = ep->com.local_addr;
  658. event.remote_addr = ep->com.remote_addr;
  659. event.private_data_len = ep->plen;
  660. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  661. event.provider_data = ep;
  662. if (state_read(&ep->parent_ep->com) != DEAD) {
  663. get_ep(&ep->com);
  664. ep->parent_ep->com.cm_id->event_handler(
  665. ep->parent_ep->com.cm_id,
  666. &event);
  667. }
  668. put_ep(&ep->parent_ep->com);
  669. ep->parent_ep = NULL;
  670. }
  671. static void established_upcall(struct iwch_ep *ep)
  672. {
  673. struct iw_cm_event event;
  674. PDBG("%s ep %p\n", __func__, ep);
  675. memset(&event, 0, sizeof(event));
  676. event.event = IW_CM_EVENT_ESTABLISHED;
  677. if (ep->com.cm_id) {
  678. PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
  679. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  680. }
  681. }
  682. static int update_rx_credits(struct iwch_ep *ep, u32 credits)
  683. {
  684. struct cpl_rx_data_ack *req;
  685. struct sk_buff *skb;
  686. PDBG("%s ep %p credits %u\n", __func__, ep, credits);
  687. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  688. if (!skb) {
  689. printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
  690. return 0;
  691. }
  692. req = (struct cpl_rx_data_ack *) skb_put(skb, sizeof(*req));
  693. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  694. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_RX_DATA_ACK, ep->hwtid));
  695. req->credit_dack = htonl(V_RX_CREDITS(credits) | V_RX_FORCE_ACK(1));
  696. skb->priority = CPL_PRIORITY_ACK;
  697. iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  698. return credits;
  699. }
  700. static void process_mpa_reply(struct iwch_ep *ep, struct sk_buff *skb)
  701. {
  702. struct mpa_message *mpa;
  703. u16 plen;
  704. struct iwch_qp_attributes attrs;
  705. enum iwch_qp_attr_mask mask;
  706. int err;
  707. PDBG("%s ep %p\n", __func__, ep);
  708. /*
  709. * Stop mpa timer. If it expired, then the state has
  710. * changed and we bail since ep_timeout already aborted
  711. * the connection.
  712. */
  713. stop_ep_timer(ep);
  714. if (state_read(&ep->com) != MPA_REQ_SENT)
  715. return;
  716. /*
  717. * If we get more than the supported amount of private data
  718. * then we must fail this connection.
  719. */
  720. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  721. err = -EINVAL;
  722. goto err;
  723. }
  724. /*
  725. * copy the new data into our accumulation buffer.
  726. */
  727. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  728. skb->len);
  729. ep->mpa_pkt_len += skb->len;
  730. /*
  731. * if we don't even have the mpa message, then bail.
  732. */
  733. if (ep->mpa_pkt_len < sizeof(*mpa))
  734. return;
  735. mpa = (struct mpa_message *) ep->mpa_pkt;
  736. /* Validate MPA header. */
  737. if (mpa->revision != mpa_rev) {
  738. err = -EPROTO;
  739. goto err;
  740. }
  741. if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
  742. err = -EPROTO;
  743. goto err;
  744. }
  745. plen = ntohs(mpa->private_data_size);
  746. /*
  747. * Fail if there's too much private data.
  748. */
  749. if (plen > MPA_MAX_PRIVATE_DATA) {
  750. err = -EPROTO;
  751. goto err;
  752. }
  753. /*
  754. * If plen does not account for pkt size
  755. */
  756. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  757. err = -EPROTO;
  758. goto err;
  759. }
  760. ep->plen = (u8) plen;
  761. /*
  762. * If we don't have all the pdata yet, then bail.
  763. * We'll continue process when more data arrives.
  764. */
  765. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  766. return;
  767. if (mpa->flags & MPA_REJECT) {
  768. err = -ECONNREFUSED;
  769. goto err;
  770. }
  771. /*
  772. * If we get here we have accumulated the entire mpa
  773. * start reply message including private data. And
  774. * the MPA header is valid.
  775. */
  776. state_set(&ep->com, FPDU_MODE);
  777. ep->mpa_attr.initiator = 1;
  778. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  779. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  780. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  781. ep->mpa_attr.version = mpa_rev;
  782. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  783. "xmit_marker_enabled=%d, version=%d\n", __func__,
  784. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  785. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
  786. attrs.mpa_attr = ep->mpa_attr;
  787. attrs.max_ird = ep->ird;
  788. attrs.max_ord = ep->ord;
  789. attrs.llp_stream_handle = ep;
  790. attrs.next_state = IWCH_QP_STATE_RTS;
  791. mask = IWCH_QP_ATTR_NEXT_STATE |
  792. IWCH_QP_ATTR_LLP_STREAM_HANDLE | IWCH_QP_ATTR_MPA_ATTR |
  793. IWCH_QP_ATTR_MAX_IRD | IWCH_QP_ATTR_MAX_ORD;
  794. /* bind QP and TID with INIT_WR */
  795. err = iwch_modify_qp(ep->com.qp->rhp,
  796. ep->com.qp, mask, &attrs, 1);
  797. if (err)
  798. goto err;
  799. if (peer2peer && iwch_rqes_posted(ep->com.qp) == 0) {
  800. iwch_post_zb_read(ep);
  801. }
  802. goto out;
  803. err:
  804. abort_connection(ep, skb, GFP_KERNEL);
  805. out:
  806. connect_reply_upcall(ep, err);
  807. return;
  808. }
  809. static void process_mpa_request(struct iwch_ep *ep, struct sk_buff *skb)
  810. {
  811. struct mpa_message *mpa;
  812. u16 plen;
  813. PDBG("%s ep %p\n", __func__, ep);
  814. /*
  815. * Stop mpa timer. If it expired, then the state has
  816. * changed and we bail since ep_timeout already aborted
  817. * the connection.
  818. */
  819. stop_ep_timer(ep);
  820. if (state_read(&ep->com) != MPA_REQ_WAIT)
  821. return;
  822. /*
  823. * If we get more than the supported amount of private data
  824. * then we must fail this connection.
  825. */
  826. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  827. abort_connection(ep, skb, GFP_KERNEL);
  828. return;
  829. }
  830. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  831. /*
  832. * Copy the new data into our accumulation buffer.
  833. */
  834. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  835. skb->len);
  836. ep->mpa_pkt_len += skb->len;
  837. /*
  838. * If we don't even have the mpa message, then bail.
  839. * We'll continue process when more data arrives.
  840. */
  841. if (ep->mpa_pkt_len < sizeof(*mpa))
  842. return;
  843. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  844. mpa = (struct mpa_message *) ep->mpa_pkt;
  845. /*
  846. * Validate MPA Header.
  847. */
  848. if (mpa->revision != mpa_rev) {
  849. abort_connection(ep, skb, GFP_KERNEL);
  850. return;
  851. }
  852. if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
  853. abort_connection(ep, skb, GFP_KERNEL);
  854. return;
  855. }
  856. plen = ntohs(mpa->private_data_size);
  857. /*
  858. * Fail if there's too much private data.
  859. */
  860. if (plen > MPA_MAX_PRIVATE_DATA) {
  861. abort_connection(ep, skb, GFP_KERNEL);
  862. return;
  863. }
  864. /*
  865. * If plen does not account for pkt size
  866. */
  867. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  868. abort_connection(ep, skb, GFP_KERNEL);
  869. return;
  870. }
  871. ep->plen = (u8) plen;
  872. /*
  873. * If we don't have all the pdata yet, then bail.
  874. */
  875. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  876. return;
  877. /*
  878. * If we get here we have accumulated the entire mpa
  879. * start reply message including private data.
  880. */
  881. ep->mpa_attr.initiator = 0;
  882. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  883. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  884. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  885. ep->mpa_attr.version = mpa_rev;
  886. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  887. "xmit_marker_enabled=%d, version=%d\n", __func__,
  888. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  889. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
  890. state_set(&ep->com, MPA_REQ_RCVD);
  891. /* drive upcall */
  892. connect_request_upcall(ep);
  893. return;
  894. }
  895. static int rx_data(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  896. {
  897. struct iwch_ep *ep = ctx;
  898. struct cpl_rx_data *hdr = cplhdr(skb);
  899. unsigned int dlen = ntohs(hdr->len);
  900. PDBG("%s ep %p dlen %u\n", __func__, ep, dlen);
  901. skb_pull(skb, sizeof(*hdr));
  902. skb_trim(skb, dlen);
  903. ep->rcv_seq += dlen;
  904. BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
  905. switch (state_read(&ep->com)) {
  906. case MPA_REQ_SENT:
  907. process_mpa_reply(ep, skb);
  908. break;
  909. case MPA_REQ_WAIT:
  910. process_mpa_request(ep, skb);
  911. break;
  912. case MPA_REP_SENT:
  913. break;
  914. default:
  915. printk(KERN_ERR MOD "%s Unexpected streaming data."
  916. " ep %p state %d tid %d\n",
  917. __func__, ep, state_read(&ep->com), ep->hwtid);
  918. /*
  919. * The ep will timeout and inform the ULP of the failure.
  920. * See ep_timeout().
  921. */
  922. break;
  923. }
  924. /* update RX credits */
  925. update_rx_credits(ep, dlen);
  926. return CPL_RET_BUF_DONE;
  927. }
  928. /*
  929. * Upcall from the adapter indicating data has been transmitted.
  930. * For us its just the single MPA request or reply. We can now free
  931. * the skb holding the mpa message.
  932. */
  933. static int tx_ack(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  934. {
  935. struct iwch_ep *ep = ctx;
  936. struct cpl_wr_ack *hdr = cplhdr(skb);
  937. unsigned int credits = ntohs(hdr->credits);
  938. unsigned long flags;
  939. int post_zb = 0;
  940. PDBG("%s ep %p credits %u\n", __func__, ep, credits);
  941. if (credits == 0) {
  942. PDBG("%s 0 credit ack ep %p state %u\n",
  943. __func__, ep, state_read(&ep->com));
  944. return CPL_RET_BUF_DONE;
  945. }
  946. spin_lock_irqsave(&ep->com.lock, flags);
  947. BUG_ON(credits != 1);
  948. dst_confirm(ep->dst);
  949. if (!ep->mpa_skb) {
  950. PDBG("%s rdma_init wr_ack ep %p state %u\n",
  951. __func__, ep, ep->com.state);
  952. if (ep->mpa_attr.initiator) {
  953. PDBG("%s initiator ep %p state %u\n",
  954. __func__, ep, ep->com.state);
  955. if (peer2peer && ep->com.state == FPDU_MODE)
  956. post_zb = 1;
  957. } else {
  958. PDBG("%s responder ep %p state %u\n",
  959. __func__, ep, ep->com.state);
  960. if (ep->com.state == MPA_REQ_RCVD) {
  961. ep->com.rpl_done = 1;
  962. wake_up(&ep->com.waitq);
  963. }
  964. }
  965. } else {
  966. PDBG("%s lsm ack ep %p state %u freeing skb\n",
  967. __func__, ep, ep->com.state);
  968. kfree_skb(ep->mpa_skb);
  969. ep->mpa_skb = NULL;
  970. }
  971. spin_unlock_irqrestore(&ep->com.lock, flags);
  972. if (post_zb)
  973. iwch_post_zb_read(ep);
  974. return CPL_RET_BUF_DONE;
  975. }
  976. static int abort_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  977. {
  978. struct iwch_ep *ep = ctx;
  979. unsigned long flags;
  980. int release = 0;
  981. PDBG("%s ep %p\n", __func__, ep);
  982. BUG_ON(!ep);
  983. /*
  984. * We get 2 abort replies from the HW. The first one must
  985. * be ignored except for scribbling that we need one more.
  986. */
  987. if (!test_and_set_bit(ABORT_REQ_IN_PROGRESS, &ep->com.flags)) {
  988. return CPL_RET_BUF_DONE;
  989. }
  990. spin_lock_irqsave(&ep->com.lock, flags);
  991. switch (ep->com.state) {
  992. case ABORTING:
  993. close_complete_upcall(ep);
  994. __state_set(&ep->com, DEAD);
  995. release = 1;
  996. break;
  997. default:
  998. printk(KERN_ERR "%s ep %p state %d\n",
  999. __func__, ep, ep->com.state);
  1000. break;
  1001. }
  1002. spin_unlock_irqrestore(&ep->com.lock, flags);
  1003. if (release)
  1004. release_ep_resources(ep);
  1005. return CPL_RET_BUF_DONE;
  1006. }
  1007. /*
  1008. * Return whether a failed active open has allocated a TID
  1009. */
  1010. static inline int act_open_has_tid(int status)
  1011. {
  1012. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1013. status != CPL_ERR_ARP_MISS;
  1014. }
  1015. static int act_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1016. {
  1017. struct iwch_ep *ep = ctx;
  1018. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1019. PDBG("%s ep %p status %u errno %d\n", __func__, ep, rpl->status,
  1020. status2errno(rpl->status));
  1021. connect_reply_upcall(ep, status2errno(rpl->status));
  1022. state_set(&ep->com, DEAD);
  1023. if (ep->com.tdev->type != T3A && act_open_has_tid(rpl->status))
  1024. release_tid(ep->com.tdev, GET_TID(rpl), NULL);
  1025. cxgb3_free_atid(ep->com.tdev, ep->atid);
  1026. dst_release(ep->dst);
  1027. l2t_release(L2DATA(ep->com.tdev), ep->l2t);
  1028. put_ep(&ep->com);
  1029. return CPL_RET_BUF_DONE;
  1030. }
  1031. static int listen_start(struct iwch_listen_ep *ep)
  1032. {
  1033. struct sk_buff *skb;
  1034. struct cpl_pass_open_req *req;
  1035. PDBG("%s ep %p\n", __func__, ep);
  1036. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1037. if (!skb) {
  1038. printk(KERN_ERR MOD "t3c_listen_start failed to alloc skb!\n");
  1039. return -ENOMEM;
  1040. }
  1041. req = (struct cpl_pass_open_req *) skb_put(skb, sizeof(*req));
  1042. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1043. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, ep->stid));
  1044. req->local_port = ep->com.local_addr.sin_port;
  1045. req->local_ip = ep->com.local_addr.sin_addr.s_addr;
  1046. req->peer_port = 0;
  1047. req->peer_ip = 0;
  1048. req->peer_netmask = 0;
  1049. req->opt0h = htonl(F_DELACK | F_TCAM_BYPASS);
  1050. req->opt0l = htonl(V_RCV_BUFSIZ(rcv_win>>10));
  1051. req->opt1 = htonl(V_CONN_POLICY(CPL_CONN_POLICY_ASK));
  1052. skb->priority = 1;
  1053. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  1054. }
  1055. static int pass_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1056. {
  1057. struct iwch_listen_ep *ep = ctx;
  1058. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1059. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1060. rpl->status, status2errno(rpl->status));
  1061. ep->com.rpl_err = status2errno(rpl->status);
  1062. ep->com.rpl_done = 1;
  1063. wake_up(&ep->com.waitq);
  1064. return CPL_RET_BUF_DONE;
  1065. }
  1066. static int listen_stop(struct iwch_listen_ep *ep)
  1067. {
  1068. struct sk_buff *skb;
  1069. struct cpl_close_listserv_req *req;
  1070. PDBG("%s ep %p\n", __func__, ep);
  1071. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1072. if (!skb) {
  1073. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  1074. return -ENOMEM;
  1075. }
  1076. req = (struct cpl_close_listserv_req *) skb_put(skb, sizeof(*req));
  1077. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1078. req->cpu_idx = 0;
  1079. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, ep->stid));
  1080. skb->priority = 1;
  1081. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  1082. }
  1083. static int close_listsrv_rpl(struct t3cdev *tdev, struct sk_buff *skb,
  1084. void *ctx)
  1085. {
  1086. struct iwch_listen_ep *ep = ctx;
  1087. struct cpl_close_listserv_rpl *rpl = cplhdr(skb);
  1088. PDBG("%s ep %p\n", __func__, ep);
  1089. ep->com.rpl_err = status2errno(rpl->status);
  1090. ep->com.rpl_done = 1;
  1091. wake_up(&ep->com.waitq);
  1092. return CPL_RET_BUF_DONE;
  1093. }
  1094. static void accept_cr(struct iwch_ep *ep, __be32 peer_ip, struct sk_buff *skb)
  1095. {
  1096. struct cpl_pass_accept_rpl *rpl;
  1097. unsigned int mtu_idx;
  1098. u32 opt0h, opt0l, opt2;
  1099. int wscale;
  1100. PDBG("%s ep %p\n", __func__, ep);
  1101. BUG_ON(skb_cloned(skb));
  1102. skb_trim(skb, sizeof(*rpl));
  1103. skb_get(skb);
  1104. mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst));
  1105. wscale = compute_wscale(rcv_win);
  1106. opt0h = V_NAGLE(0) |
  1107. V_NO_CONG(nocong) |
  1108. V_KEEP_ALIVE(1) |
  1109. F_TCAM_BYPASS |
  1110. V_WND_SCALE(wscale) |
  1111. V_MSS_IDX(mtu_idx) |
  1112. V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
  1113. opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
  1114. opt2 = F_RX_COALESCE_VALID | V_RX_COALESCE(0) | V_FLAVORS_VALID(1) |
  1115. V_CONG_CONTROL_FLAVOR(cong_flavor);
  1116. rpl = cplhdr(skb);
  1117. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1118. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, ep->hwtid));
  1119. rpl->peer_ip = peer_ip;
  1120. rpl->opt0h = htonl(opt0h);
  1121. rpl->opt0l_status = htonl(opt0l | CPL_PASS_OPEN_ACCEPT);
  1122. rpl->opt2 = htonl(opt2);
  1123. rpl->rsvd = rpl->opt2; /* workaround for HW bug */
  1124. skb->priority = CPL_PRIORITY_SETUP;
  1125. iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  1126. return;
  1127. }
  1128. static void reject_cr(struct t3cdev *tdev, u32 hwtid, __be32 peer_ip,
  1129. struct sk_buff *skb)
  1130. {
  1131. PDBG("%s t3cdev %p tid %u peer_ip %x\n", __func__, tdev, hwtid,
  1132. peer_ip);
  1133. BUG_ON(skb_cloned(skb));
  1134. skb_trim(skb, sizeof(struct cpl_tid_release));
  1135. skb_get(skb);
  1136. if (tdev->type != T3A)
  1137. release_tid(tdev, hwtid, skb);
  1138. else {
  1139. struct cpl_pass_accept_rpl *rpl;
  1140. rpl = cplhdr(skb);
  1141. skb->priority = CPL_PRIORITY_SETUP;
  1142. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1143. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1144. hwtid));
  1145. rpl->peer_ip = peer_ip;
  1146. rpl->opt0h = htonl(F_TCAM_BYPASS);
  1147. rpl->opt0l_status = htonl(CPL_PASS_OPEN_REJECT);
  1148. rpl->opt2 = 0;
  1149. rpl->rsvd = rpl->opt2;
  1150. iwch_cxgb3_ofld_send(tdev, skb);
  1151. }
  1152. }
  1153. static int pass_accept_req(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1154. {
  1155. struct iwch_ep *child_ep, *parent_ep = ctx;
  1156. struct cpl_pass_accept_req *req = cplhdr(skb);
  1157. unsigned int hwtid = GET_TID(req);
  1158. struct neighbour *neigh;
  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. neigh = dst_get_neighbour(dst);
  1192. l2t = t3_l2t_get(tdev, neigh, neigh->dev);
  1193. if (!l2t) {
  1194. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1195. __func__);
  1196. dst_release(dst);
  1197. goto reject;
  1198. }
  1199. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1200. if (!child_ep) {
  1201. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1202. __func__);
  1203. l2t_release(L2DATA(tdev), l2t);
  1204. dst_release(dst);
  1205. goto reject;
  1206. }
  1207. state_set(&child_ep->com, CONNECTING);
  1208. child_ep->com.tdev = tdev;
  1209. child_ep->com.cm_id = NULL;
  1210. child_ep->com.local_addr.sin_family = PF_INET;
  1211. child_ep->com.local_addr.sin_port = req->local_port;
  1212. child_ep->com.local_addr.sin_addr.s_addr = req->local_ip;
  1213. child_ep->com.remote_addr.sin_family = PF_INET;
  1214. child_ep->com.remote_addr.sin_port = req->peer_port;
  1215. child_ep->com.remote_addr.sin_addr.s_addr = req->peer_ip;
  1216. get_ep(&parent_ep->com);
  1217. child_ep->parent_ep = parent_ep;
  1218. child_ep->tos = G_PASS_OPEN_TOS(ntohl(req->tos_tid));
  1219. child_ep->l2t = l2t;
  1220. child_ep->dst = dst;
  1221. child_ep->hwtid = hwtid;
  1222. init_timer(&child_ep->timer);
  1223. cxgb3_insert_tid(tdev, &t3c_client, child_ep, hwtid);
  1224. accept_cr(child_ep, req->peer_ip, skb);
  1225. goto out;
  1226. reject:
  1227. reject_cr(tdev, hwtid, req->peer_ip, skb);
  1228. out:
  1229. return CPL_RET_BUF_DONE;
  1230. }
  1231. static int pass_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1232. {
  1233. struct iwch_ep *ep = ctx;
  1234. struct cpl_pass_establish *req = cplhdr(skb);
  1235. PDBG("%s ep %p\n", __func__, ep);
  1236. ep->snd_seq = ntohl(req->snd_isn);
  1237. ep->rcv_seq = ntohl(req->rcv_isn);
  1238. set_emss(ep, ntohs(req->tcp_opt));
  1239. dst_confirm(ep->dst);
  1240. state_set(&ep->com, MPA_REQ_WAIT);
  1241. start_ep_timer(ep);
  1242. return CPL_RET_BUF_DONE;
  1243. }
  1244. static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1245. {
  1246. struct iwch_ep *ep = ctx;
  1247. struct iwch_qp_attributes attrs;
  1248. unsigned long flags;
  1249. int disconnect = 1;
  1250. int release = 0;
  1251. PDBG("%s ep %p\n", __func__, ep);
  1252. dst_confirm(ep->dst);
  1253. spin_lock_irqsave(&ep->com.lock, flags);
  1254. switch (ep->com.state) {
  1255. case MPA_REQ_WAIT:
  1256. __state_set(&ep->com, CLOSING);
  1257. break;
  1258. case MPA_REQ_SENT:
  1259. __state_set(&ep->com, CLOSING);
  1260. connect_reply_upcall(ep, -ECONNRESET);
  1261. break;
  1262. case MPA_REQ_RCVD:
  1263. /*
  1264. * We're gonna mark this puppy DEAD, but keep
  1265. * the reference on it until the ULP accepts or
  1266. * rejects the CR. Also wake up anyone waiting
  1267. * in rdma connection migration (see iwch_accept_cr()).
  1268. */
  1269. __state_set(&ep->com, CLOSING);
  1270. ep->com.rpl_done = 1;
  1271. ep->com.rpl_err = -ECONNRESET;
  1272. PDBG("waking up ep %p\n", ep);
  1273. wake_up(&ep->com.waitq);
  1274. break;
  1275. case MPA_REP_SENT:
  1276. __state_set(&ep->com, CLOSING);
  1277. ep->com.rpl_done = 1;
  1278. ep->com.rpl_err = -ECONNRESET;
  1279. PDBG("waking up ep %p\n", ep);
  1280. wake_up(&ep->com.waitq);
  1281. break;
  1282. case FPDU_MODE:
  1283. start_ep_timer(ep);
  1284. __state_set(&ep->com, CLOSING);
  1285. attrs.next_state = IWCH_QP_STATE_CLOSING;
  1286. iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1287. IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
  1288. peer_close_upcall(ep);
  1289. break;
  1290. case ABORTING:
  1291. disconnect = 0;
  1292. break;
  1293. case CLOSING:
  1294. __state_set(&ep->com, MORIBUND);
  1295. disconnect = 0;
  1296. break;
  1297. case MORIBUND:
  1298. stop_ep_timer(ep);
  1299. if (ep->com.cm_id && ep->com.qp) {
  1300. attrs.next_state = IWCH_QP_STATE_IDLE;
  1301. iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1302. IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
  1303. }
  1304. close_complete_upcall(ep);
  1305. __state_set(&ep->com, DEAD);
  1306. release = 1;
  1307. disconnect = 0;
  1308. break;
  1309. case DEAD:
  1310. disconnect = 0;
  1311. break;
  1312. default:
  1313. BUG_ON(1);
  1314. }
  1315. spin_unlock_irqrestore(&ep->com.lock, flags);
  1316. if (disconnect)
  1317. iwch_ep_disconnect(ep, 0, GFP_KERNEL);
  1318. if (release)
  1319. release_ep_resources(ep);
  1320. return CPL_RET_BUF_DONE;
  1321. }
  1322. /*
  1323. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  1324. */
  1325. static int is_neg_adv_abort(unsigned int status)
  1326. {
  1327. return status == CPL_ERR_RTX_NEG_ADVICE ||
  1328. status == CPL_ERR_PERSIST_NEG_ADVICE;
  1329. }
  1330. static int peer_abort(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1331. {
  1332. struct cpl_abort_req_rss *req = cplhdr(skb);
  1333. struct iwch_ep *ep = ctx;
  1334. struct cpl_abort_rpl *rpl;
  1335. struct sk_buff *rpl_skb;
  1336. struct iwch_qp_attributes attrs;
  1337. int ret;
  1338. int release = 0;
  1339. unsigned long flags;
  1340. if (is_neg_adv_abort(req->status)) {
  1341. PDBG("%s neg_adv_abort ep %p tid %d\n", __func__, ep,
  1342. ep->hwtid);
  1343. t3_l2t_send_event(ep->com.tdev, ep->l2t);
  1344. return CPL_RET_BUF_DONE;
  1345. }
  1346. /*
  1347. * We get 2 peer aborts from the HW. The first one must
  1348. * be ignored except for scribbling that we need one more.
  1349. */
  1350. if (!test_and_set_bit(PEER_ABORT_IN_PROGRESS, &ep->com.flags)) {
  1351. return CPL_RET_BUF_DONE;
  1352. }
  1353. spin_lock_irqsave(&ep->com.lock, flags);
  1354. PDBG("%s ep %p state %u\n", __func__, ep, ep->com.state);
  1355. switch (ep->com.state) {
  1356. case CONNECTING:
  1357. break;
  1358. case MPA_REQ_WAIT:
  1359. stop_ep_timer(ep);
  1360. break;
  1361. case MPA_REQ_SENT:
  1362. stop_ep_timer(ep);
  1363. connect_reply_upcall(ep, -ECONNRESET);
  1364. break;
  1365. case MPA_REP_SENT:
  1366. ep->com.rpl_done = 1;
  1367. ep->com.rpl_err = -ECONNRESET;
  1368. PDBG("waking up ep %p\n", ep);
  1369. wake_up(&ep->com.waitq);
  1370. break;
  1371. case MPA_REQ_RCVD:
  1372. /*
  1373. * We're gonna mark this puppy DEAD, but keep
  1374. * the reference on it until the ULP accepts or
  1375. * rejects the CR. Also wake up anyone waiting
  1376. * in rdma connection migration (see iwch_accept_cr()).
  1377. */
  1378. ep->com.rpl_done = 1;
  1379. ep->com.rpl_err = -ECONNRESET;
  1380. PDBG("waking up ep %p\n", ep);
  1381. wake_up(&ep->com.waitq);
  1382. break;
  1383. case MORIBUND:
  1384. case CLOSING:
  1385. stop_ep_timer(ep);
  1386. /*FALLTHROUGH*/
  1387. case FPDU_MODE:
  1388. if (ep->com.cm_id && ep->com.qp) {
  1389. attrs.next_state = IWCH_QP_STATE_ERROR;
  1390. ret = iwch_modify_qp(ep->com.qp->rhp,
  1391. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1392. &attrs, 1);
  1393. if (ret)
  1394. printk(KERN_ERR MOD
  1395. "%s - qp <- error failed!\n",
  1396. __func__);
  1397. }
  1398. peer_abort_upcall(ep);
  1399. break;
  1400. case ABORTING:
  1401. break;
  1402. case DEAD:
  1403. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1404. spin_unlock_irqrestore(&ep->com.lock, flags);
  1405. return CPL_RET_BUF_DONE;
  1406. default:
  1407. BUG_ON(1);
  1408. break;
  1409. }
  1410. dst_confirm(ep->dst);
  1411. if (ep->com.state != ABORTING) {
  1412. __state_set(&ep->com, DEAD);
  1413. release = 1;
  1414. }
  1415. spin_unlock_irqrestore(&ep->com.lock, flags);
  1416. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1417. if (!rpl_skb) {
  1418. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  1419. __func__);
  1420. release = 1;
  1421. goto out;
  1422. }
  1423. rpl_skb->priority = CPL_PRIORITY_DATA;
  1424. rpl = (struct cpl_abort_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. PDBG("%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 opcde 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. PDBG("%s ep %p\n", __func__, ep);
  1492. skb_pull(skb, sizeof(struct cpl_rdma_terminate));
  1493. PDBG("%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. PDBG("%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. printk(KERN_ERR MOD "%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. PDBG("%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. printk(KERN_ERR "%s unexpected state ep %p state %u\n",
  1548. __func__, ep, ep->com.state);
  1549. WARN_ON(1);
  1550. abort = 0;
  1551. }
  1552. spin_unlock_irqrestore(&ep->com.lock, flags);
  1553. if (abort)
  1554. abort_connection(ep, NULL, GFP_ATOMIC);
  1555. put_ep(&ep->com);
  1556. }
  1557. int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  1558. {
  1559. int err;
  1560. struct iwch_ep *ep = to_ep(cm_id);
  1561. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1562. if (state_read(&ep->com) == DEAD) {
  1563. put_ep(&ep->com);
  1564. return -ECONNRESET;
  1565. }
  1566. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1567. if (mpa_rev == 0)
  1568. abort_connection(ep, NULL, GFP_KERNEL);
  1569. else {
  1570. err = send_mpa_reject(ep, pdata, pdata_len);
  1571. err = iwch_ep_disconnect(ep, 0, GFP_KERNEL);
  1572. }
  1573. put_ep(&ep->com);
  1574. return 0;
  1575. }
  1576. int iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1577. {
  1578. int err;
  1579. struct iwch_qp_attributes attrs;
  1580. enum iwch_qp_attr_mask mask;
  1581. struct iwch_ep *ep = to_ep(cm_id);
  1582. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1583. struct iwch_qp *qp = get_qhp(h, conn_param->qpn);
  1584. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1585. if (state_read(&ep->com) == DEAD) {
  1586. err = -ECONNRESET;
  1587. goto err;
  1588. }
  1589. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1590. BUG_ON(!qp);
  1591. if ((conn_param->ord > qp->rhp->attr.max_rdma_read_qp_depth) ||
  1592. (conn_param->ird > qp->rhp->attr.max_rdma_reads_per_qp)) {
  1593. abort_connection(ep, NULL, GFP_KERNEL);
  1594. err = -EINVAL;
  1595. goto err;
  1596. }
  1597. cm_id->add_ref(cm_id);
  1598. ep->com.cm_id = cm_id;
  1599. ep->com.qp = qp;
  1600. ep->ird = conn_param->ird;
  1601. ep->ord = conn_param->ord;
  1602. if (peer2peer && ep->ird == 0)
  1603. ep->ird = 1;
  1604. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  1605. /* bind QP to EP and move to RTS */
  1606. attrs.mpa_attr = ep->mpa_attr;
  1607. attrs.max_ird = ep->ird;
  1608. attrs.max_ord = ep->ord;
  1609. attrs.llp_stream_handle = ep;
  1610. attrs.next_state = IWCH_QP_STATE_RTS;
  1611. /* bind QP and TID with INIT_WR */
  1612. mask = IWCH_QP_ATTR_NEXT_STATE |
  1613. IWCH_QP_ATTR_LLP_STREAM_HANDLE |
  1614. IWCH_QP_ATTR_MPA_ATTR |
  1615. IWCH_QP_ATTR_MAX_IRD |
  1616. IWCH_QP_ATTR_MAX_ORD;
  1617. err = iwch_modify_qp(ep->com.qp->rhp,
  1618. ep->com.qp, mask, &attrs, 1);
  1619. if (err)
  1620. goto err1;
  1621. /* if needed, wait for wr_ack */
  1622. if (iwch_rqes_posted(qp)) {
  1623. wait_event(ep->com.waitq, ep->com.rpl_done);
  1624. err = ep->com.rpl_err;
  1625. if (err)
  1626. goto err1;
  1627. }
  1628. err = send_mpa_reply(ep, conn_param->private_data,
  1629. conn_param->private_data_len);
  1630. if (err)
  1631. goto err1;
  1632. state_set(&ep->com, FPDU_MODE);
  1633. established_upcall(ep);
  1634. put_ep(&ep->com);
  1635. return 0;
  1636. err1:
  1637. ep->com.cm_id = NULL;
  1638. ep->com.qp = NULL;
  1639. cm_id->rem_ref(cm_id);
  1640. err:
  1641. put_ep(&ep->com);
  1642. return err;
  1643. }
  1644. static int is_loopback_dst(struct iw_cm_id *cm_id)
  1645. {
  1646. struct net_device *dev;
  1647. dev = ip_dev_find(&init_net, cm_id->remote_addr.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 neighbour *neigh;
  1657. struct iwch_ep *ep;
  1658. struct rtable *rt;
  1659. int err = 0;
  1660. if (is_loopback_dst(cm_id)) {
  1661. err = -ENOSYS;
  1662. goto out;
  1663. }
  1664. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1665. if (!ep) {
  1666. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1667. err = -ENOMEM;
  1668. goto out;
  1669. }
  1670. init_timer(&ep->timer);
  1671. ep->plen = conn_param->private_data_len;
  1672. if (ep->plen)
  1673. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  1674. conn_param->private_data, ep->plen);
  1675. ep->ird = conn_param->ird;
  1676. ep->ord = conn_param->ord;
  1677. if (peer2peer && ep->ord == 0)
  1678. ep->ord = 1;
  1679. ep->com.tdev = h->rdev.t3cdev_p;
  1680. cm_id->add_ref(cm_id);
  1681. ep->com.cm_id = cm_id;
  1682. ep->com.qp = get_qhp(h, conn_param->qpn);
  1683. BUG_ON(!ep->com.qp);
  1684. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  1685. ep->com.qp, cm_id);
  1686. /*
  1687. * Allocate an active TID to initiate a TCP connection.
  1688. */
  1689. ep->atid = cxgb3_alloc_atid(h->rdev.t3cdev_p, &t3c_client, ep);
  1690. if (ep->atid == -1) {
  1691. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1692. err = -ENOMEM;
  1693. goto fail2;
  1694. }
  1695. /* find a route */
  1696. rt = find_route(h->rdev.t3cdev_p,
  1697. cm_id->local_addr.sin_addr.s_addr,
  1698. cm_id->remote_addr.sin_addr.s_addr,
  1699. cm_id->local_addr.sin_port,
  1700. cm_id->remote_addr.sin_port, IPTOS_LOWDELAY);
  1701. if (!rt) {
  1702. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  1703. err = -EHOSTUNREACH;
  1704. goto fail3;
  1705. }
  1706. ep->dst = &rt->dst;
  1707. neigh = dst_get_neighbour(ep->dst);
  1708. /* get a l2t entry */
  1709. ep->l2t = t3_l2t_get(ep->com.tdev, neigh, neigh->dev);
  1710. if (!ep->l2t) {
  1711. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  1712. err = -ENOMEM;
  1713. goto fail4;
  1714. }
  1715. state_set(&ep->com, CONNECTING);
  1716. ep->tos = IPTOS_LOWDELAY;
  1717. ep->com.local_addr = cm_id->local_addr;
  1718. ep->com.remote_addr = cm_id->remote_addr;
  1719. /* send connect request to rnic */
  1720. err = send_connect(ep);
  1721. if (!err)
  1722. goto out;
  1723. l2t_release(L2DATA(h->rdev.t3cdev_p), ep->l2t);
  1724. fail4:
  1725. dst_release(ep->dst);
  1726. fail3:
  1727. cxgb3_free_atid(ep->com.tdev, ep->atid);
  1728. fail2:
  1729. cm_id->rem_ref(cm_id);
  1730. put_ep(&ep->com);
  1731. out:
  1732. return err;
  1733. }
  1734. int iwch_create_listen(struct iw_cm_id *cm_id, int backlog)
  1735. {
  1736. int err = 0;
  1737. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1738. struct iwch_listen_ep *ep;
  1739. might_sleep();
  1740. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1741. if (!ep) {
  1742. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1743. err = -ENOMEM;
  1744. goto fail1;
  1745. }
  1746. PDBG("%s ep %p\n", __func__, ep);
  1747. ep->com.tdev = h->rdev.t3cdev_p;
  1748. cm_id->add_ref(cm_id);
  1749. ep->com.cm_id = cm_id;
  1750. ep->backlog = backlog;
  1751. ep->com.local_addr = cm_id->local_addr;
  1752. /*
  1753. * Allocate a server TID.
  1754. */
  1755. ep->stid = cxgb3_alloc_stid(h->rdev.t3cdev_p, &t3c_client, ep);
  1756. if (ep->stid == -1) {
  1757. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1758. err = -ENOMEM;
  1759. goto fail2;
  1760. }
  1761. state_set(&ep->com, LISTEN);
  1762. err = listen_start(ep);
  1763. if (err)
  1764. goto fail3;
  1765. /* wait for pass_open_rpl */
  1766. wait_event(ep->com.waitq, ep->com.rpl_done);
  1767. err = ep->com.rpl_err;
  1768. if (!err) {
  1769. cm_id->provider_data = ep;
  1770. goto out;
  1771. }
  1772. fail3:
  1773. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1774. fail2:
  1775. cm_id->rem_ref(cm_id);
  1776. put_ep(&ep->com);
  1777. fail1:
  1778. out:
  1779. return err;
  1780. }
  1781. int iwch_destroy_listen(struct iw_cm_id *cm_id)
  1782. {
  1783. int err;
  1784. struct iwch_listen_ep *ep = to_listen_ep(cm_id);
  1785. PDBG("%s ep %p\n", __func__, ep);
  1786. might_sleep();
  1787. state_set(&ep->com, DEAD);
  1788. ep->com.rpl_done = 0;
  1789. ep->com.rpl_err = 0;
  1790. err = listen_stop(ep);
  1791. if (err)
  1792. goto done;
  1793. wait_event(ep->com.waitq, ep->com.rpl_done);
  1794. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1795. done:
  1796. err = ep->com.rpl_err;
  1797. cm_id->rem_ref(cm_id);
  1798. put_ep(&ep->com);
  1799. return err;
  1800. }
  1801. int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp)
  1802. {
  1803. int ret=0;
  1804. unsigned long flags;
  1805. int close = 0;
  1806. int fatal = 0;
  1807. struct t3cdev *tdev;
  1808. struct cxio_rdev *rdev;
  1809. spin_lock_irqsave(&ep->com.lock, flags);
  1810. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  1811. states[ep->com.state], abrupt);
  1812. tdev = (struct t3cdev *)ep->com.tdev;
  1813. rdev = (struct cxio_rdev *)tdev->ulp;
  1814. if (cxio_fatal_error(rdev)) {
  1815. fatal = 1;
  1816. close_complete_upcall(ep);
  1817. ep->com.state = DEAD;
  1818. }
  1819. switch (ep->com.state) {
  1820. case MPA_REQ_WAIT:
  1821. case MPA_REQ_SENT:
  1822. case MPA_REQ_RCVD:
  1823. case MPA_REP_SENT:
  1824. case FPDU_MODE:
  1825. close = 1;
  1826. if (abrupt)
  1827. ep->com.state = ABORTING;
  1828. else {
  1829. ep->com.state = CLOSING;
  1830. start_ep_timer(ep);
  1831. }
  1832. set_bit(CLOSE_SENT, &ep->com.flags);
  1833. break;
  1834. case CLOSING:
  1835. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  1836. close = 1;
  1837. if (abrupt) {
  1838. stop_ep_timer(ep);
  1839. ep->com.state = ABORTING;
  1840. } else
  1841. ep->com.state = MORIBUND;
  1842. }
  1843. break;
  1844. case MORIBUND:
  1845. case ABORTING:
  1846. case DEAD:
  1847. PDBG("%s ignoring disconnect ep %p state %u\n",
  1848. __func__, ep, ep->com.state);
  1849. break;
  1850. default:
  1851. BUG();
  1852. break;
  1853. }
  1854. spin_unlock_irqrestore(&ep->com.lock, flags);
  1855. if (close) {
  1856. if (abrupt)
  1857. ret = send_abort(ep, NULL, gfp);
  1858. else
  1859. ret = send_halfclose(ep, gfp);
  1860. if (ret)
  1861. fatal = 1;
  1862. }
  1863. if (fatal)
  1864. release_ep_resources(ep);
  1865. return ret;
  1866. }
  1867. int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
  1868. struct l2t_entry *l2t)
  1869. {
  1870. struct iwch_ep *ep = ctx;
  1871. if (ep->dst != old)
  1872. return 0;
  1873. PDBG("%s ep %p redirect to dst %p l2t %p\n", __func__, ep, new,
  1874. l2t);
  1875. dst_hold(new);
  1876. l2t_release(L2DATA(ep->com.tdev), ep->l2t);
  1877. ep->l2t = l2t;
  1878. dst_release(old);
  1879. ep->dst = new;
  1880. return 1;
  1881. }
  1882. /*
  1883. * All the CM events are handled on a work queue to have a safe context.
  1884. * These are the real handlers that are called from the work queue.
  1885. */
  1886. static const cxgb3_cpl_handler_func work_handlers[NUM_CPL_CMDS] = {
  1887. [CPL_ACT_ESTABLISH] = act_establish,
  1888. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  1889. [CPL_RX_DATA] = rx_data,
  1890. [CPL_TX_DMA_ACK] = tx_ack,
  1891. [CPL_ABORT_RPL_RSS] = abort_rpl,
  1892. [CPL_ABORT_RPL] = abort_rpl,
  1893. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  1894. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  1895. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  1896. [CPL_PASS_ESTABLISH] = pass_establish,
  1897. [CPL_PEER_CLOSE] = peer_close,
  1898. [CPL_ABORT_REQ_RSS] = peer_abort,
  1899. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  1900. [CPL_RDMA_TERMINATE] = terminate,
  1901. [CPL_RDMA_EC_STATUS] = ec_status,
  1902. };
  1903. static void process_work(struct work_struct *work)
  1904. {
  1905. struct sk_buff *skb = NULL;
  1906. void *ep;
  1907. struct t3cdev *tdev;
  1908. int ret;
  1909. while ((skb = skb_dequeue(&rxq))) {
  1910. ep = *((void **) (skb->cb));
  1911. tdev = *((struct t3cdev **) (skb->cb + sizeof(void *)));
  1912. ret = work_handlers[G_OPCODE(ntohl((__force __be32)skb->csum))](tdev, skb, ep);
  1913. if (ret & CPL_RET_BUF_DONE)
  1914. kfree_skb(skb);
  1915. /*
  1916. * ep was referenced in sched(), and is freed here.
  1917. */
  1918. put_ep((struct iwch_ep_common *)ep);
  1919. }
  1920. }
  1921. static DECLARE_WORK(skb_work, process_work);
  1922. static int sched(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1923. {
  1924. struct iwch_ep_common *epc = ctx;
  1925. get_ep(epc);
  1926. /*
  1927. * Save ctx and tdev in the skb->cb area.
  1928. */
  1929. *((void **) skb->cb) = ctx;
  1930. *((struct t3cdev **) (skb->cb + sizeof(void *))) = tdev;
  1931. /*
  1932. * Queue the skb and schedule the worker thread.
  1933. */
  1934. skb_queue_tail(&rxq, skb);
  1935. queue_work(workq, &skb_work);
  1936. return 0;
  1937. }
  1938. static int set_tcb_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1939. {
  1940. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  1941. if (rpl->status != CPL_ERR_NONE) {
  1942. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  1943. "for tid %u\n", rpl->status, GET_TID(rpl));
  1944. }
  1945. return CPL_RET_BUF_DONE;
  1946. }
  1947. /*
  1948. * All upcalls from the T3 Core go to sched() to schedule the
  1949. * processing on a work queue.
  1950. */
  1951. cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS] = {
  1952. [CPL_ACT_ESTABLISH] = sched,
  1953. [CPL_ACT_OPEN_RPL] = sched,
  1954. [CPL_RX_DATA] = sched,
  1955. [CPL_TX_DMA_ACK] = sched,
  1956. [CPL_ABORT_RPL_RSS] = sched,
  1957. [CPL_ABORT_RPL] = sched,
  1958. [CPL_PASS_OPEN_RPL] = sched,
  1959. [CPL_CLOSE_LISTSRV_RPL] = sched,
  1960. [CPL_PASS_ACCEPT_REQ] = sched,
  1961. [CPL_PASS_ESTABLISH] = sched,
  1962. [CPL_PEER_CLOSE] = sched,
  1963. [CPL_CLOSE_CON_RPL] = sched,
  1964. [CPL_ABORT_REQ_RSS] = sched,
  1965. [CPL_RDMA_TERMINATE] = sched,
  1966. [CPL_RDMA_EC_STATUS] = sched,
  1967. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  1968. };
  1969. int __init iwch_cm_init(void)
  1970. {
  1971. skb_queue_head_init(&rxq);
  1972. workq = create_singlethread_workqueue("iw_cxgb3");
  1973. if (!workq)
  1974. return -ENOMEM;
  1975. return 0;
  1976. }
  1977. void __exit iwch_cm_term(void)
  1978. {
  1979. flush_workqueue(workq);
  1980. destroy_workqueue(workq);
  1981. }