iwch_cm.c 53 KB

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