cm.c 61 KB

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