iwch_cm.c 58 KB

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