cm.c 61 KB

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