cm.c 61 KB

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