iwch_cm.c 53 KB

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