iwch_cm.c 55 KB

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