iwch_cm.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261
  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. pr_debug("%s ep %p\n", __func__, ep);
  100. if (timer_pending(&ep->timer)) {
  101. pr_debug("%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. pr_debug("%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 < 0 ? error : 0;
  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 < 0 ? error : 0;
  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. pr_debug("%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. pr_debug("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. pr_debug("%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. pr_debug("%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. pr_debug("%s ep %p state %s\n",
  248. __func__, ep, states[state_read(&ep->com)]);
  249. if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
  250. cxgb3_remove_tid(ep->com.tdev, (void *)ep, ep->hwtid);
  251. dst_release(ep->dst);
  252. l2t_release(ep->com.tdev, ep->l2t);
  253. }
  254. kfree(ep);
  255. }
  256. static void release_ep_resources(struct iwch_ep *ep)
  257. {
  258. pr_debug("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
  259. set_bit(RELEASE_RESOURCES, &ep->com.flags);
  260. put_ep(&ep->com);
  261. }
  262. static int status2errno(int status)
  263. {
  264. switch (status) {
  265. case CPL_ERR_NONE:
  266. return 0;
  267. case CPL_ERR_CONN_RESET:
  268. return -ECONNRESET;
  269. case CPL_ERR_ARP_MISS:
  270. return -EHOSTUNREACH;
  271. case CPL_ERR_CONN_TIMEDOUT:
  272. return -ETIMEDOUT;
  273. case CPL_ERR_TCAM_FULL:
  274. return -ENOMEM;
  275. case CPL_ERR_CONN_EXIST:
  276. return -EADDRINUSE;
  277. default:
  278. return -EIO;
  279. }
  280. }
  281. /*
  282. * Try and reuse skbs already allocated...
  283. */
  284. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
  285. {
  286. if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
  287. skb_trim(skb, 0);
  288. skb_get(skb);
  289. } else {
  290. skb = alloc_skb(len, gfp);
  291. }
  292. return skb;
  293. }
  294. static struct rtable *find_route(struct t3cdev *dev, __be32 local_ip,
  295. __be32 peer_ip, __be16 local_port,
  296. __be16 peer_port, u8 tos)
  297. {
  298. struct rtable *rt;
  299. struct flowi4 fl4;
  300. rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
  301. peer_port, local_port, IPPROTO_TCP,
  302. tos, 0);
  303. if (IS_ERR(rt))
  304. return NULL;
  305. return rt;
  306. }
  307. static unsigned int find_best_mtu(const struct t3c_data *d, unsigned short mtu)
  308. {
  309. int i = 0;
  310. while (i < d->nmtus - 1 && d->mtus[i + 1] <= mtu)
  311. ++i;
  312. return i;
  313. }
  314. static void arp_failure_discard(struct t3cdev *dev, struct sk_buff *skb)
  315. {
  316. pr_debug("%s t3cdev %p\n", __func__, dev);
  317. kfree_skb(skb);
  318. }
  319. /*
  320. * Handle an ARP failure for an active open.
  321. */
  322. static void act_open_req_arp_failure(struct t3cdev *dev, struct sk_buff *skb)
  323. {
  324. pr_err("ARP failure during connect\n");
  325. kfree_skb(skb);
  326. }
  327. /*
  328. * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
  329. * and send it along.
  330. */
  331. static void abort_arp_failure(struct t3cdev *dev, struct sk_buff *skb)
  332. {
  333. struct cpl_abort_req *req = cplhdr(skb);
  334. pr_debug("%s t3cdev %p\n", __func__, dev);
  335. req->cmd = CPL_ABORT_NO_RST;
  336. iwch_cxgb3_ofld_send(dev, skb);
  337. }
  338. static int send_halfclose(struct iwch_ep *ep, gfp_t gfp)
  339. {
  340. struct cpl_close_con_req *req;
  341. struct sk_buff *skb;
  342. pr_debug("%s ep %p\n", __func__, ep);
  343. skb = get_skb(NULL, sizeof(*req), gfp);
  344. if (!skb) {
  345. pr_err("%s - failed to alloc skb\n", __func__);
  346. return -ENOMEM;
  347. }
  348. skb->priority = CPL_PRIORITY_DATA;
  349. set_arp_failure_handler(skb, arp_failure_discard);
  350. req = (struct cpl_close_con_req *) skb_put(skb, sizeof(*req));
  351. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_CLOSE_CON));
  352. req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  353. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, ep->hwtid));
  354. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  355. }
  356. static int send_abort(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp)
  357. {
  358. struct cpl_abort_req *req;
  359. pr_debug("%s ep %p\n", __func__, ep);
  360. skb = get_skb(skb, sizeof(*req), gfp);
  361. if (!skb) {
  362. pr_err("%s - failed to alloc skb\n", __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. memset(req, 0, sizeof(*req));
  369. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ));
  370. req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  371. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
  372. req->cmd = CPL_ABORT_SEND_RST;
  373. return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  374. }
  375. static int send_connect(struct iwch_ep *ep)
  376. {
  377. struct cpl_act_open_req *req;
  378. struct sk_buff *skb;
  379. u32 opt0h, opt0l, opt2;
  380. unsigned int mtu_idx;
  381. int wscale;
  382. pr_debug("%s ep %p\n", __func__, ep);
  383. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  384. if (!skb) {
  385. pr_err("%s - failed to alloc skb\n", __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. pr_debug("%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. pr_debug("%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. pr_err("%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. pr_debug("%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. pr_err("%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. pr_debug("%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. pr_debug("%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. pr_debug("%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. pr_debug("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. pr_debug("%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. pr_debug("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. pr_debug("%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. pr_debug("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. pr_debug("%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. pr_debug("%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. pr_debug("%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. pr_debug("%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. pr_debug("%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. pr_debug("%s ep %p credits %u\n", __func__, ep, credits);
  700. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  701. if (!skb) {
  702. pr_err("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. pr_debug("%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. pr_debug("%s - crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d\n",
  796. __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. pr_debug("%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. pr_debug("%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. pr_debug("%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. pr_debug("%s - crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d\n",
  900. __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. pr_debug("%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. pr_err("%s Unexpected streaming data. ep %p state %d tid %d\n",
  929. __func__, ep, state_read(&ep->com), ep->hwtid);
  930. /*
  931. * The ep will timeout and inform the ULP of the failure.
  932. * See ep_timeout().
  933. */
  934. break;
  935. }
  936. /* update RX credits */
  937. update_rx_credits(ep, dlen);
  938. return CPL_RET_BUF_DONE;
  939. }
  940. /*
  941. * Upcall from the adapter indicating data has been transmitted.
  942. * For us its just the single MPA request or reply. We can now free
  943. * the skb holding the mpa message.
  944. */
  945. static int tx_ack(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  946. {
  947. struct iwch_ep *ep = ctx;
  948. struct cpl_wr_ack *hdr = cplhdr(skb);
  949. unsigned int credits = ntohs(hdr->credits);
  950. unsigned long flags;
  951. int post_zb = 0;
  952. pr_debug("%s ep %p credits %u\n", __func__, ep, credits);
  953. if (credits == 0) {
  954. pr_debug("%s 0 credit ack ep %p state %u\n",
  955. __func__, ep, state_read(&ep->com));
  956. return CPL_RET_BUF_DONE;
  957. }
  958. spin_lock_irqsave(&ep->com.lock, flags);
  959. BUG_ON(credits != 1);
  960. dst_confirm(ep->dst);
  961. if (!ep->mpa_skb) {
  962. pr_debug("%s rdma_init wr_ack ep %p state %u\n",
  963. __func__, ep, ep->com.state);
  964. if (ep->mpa_attr.initiator) {
  965. pr_debug("%s initiator ep %p state %u\n",
  966. __func__, ep, ep->com.state);
  967. if (peer2peer && ep->com.state == FPDU_MODE)
  968. post_zb = 1;
  969. } else {
  970. pr_debug("%s responder ep %p state %u\n",
  971. __func__, ep, ep->com.state);
  972. if (ep->com.state == MPA_REQ_RCVD) {
  973. ep->com.rpl_done = 1;
  974. wake_up(&ep->com.waitq);
  975. }
  976. }
  977. } else {
  978. pr_debug("%s lsm ack ep %p state %u freeing skb\n",
  979. __func__, ep, ep->com.state);
  980. kfree_skb(ep->mpa_skb);
  981. ep->mpa_skb = NULL;
  982. }
  983. spin_unlock_irqrestore(&ep->com.lock, flags);
  984. if (post_zb)
  985. iwch_post_zb_read(ep);
  986. return CPL_RET_BUF_DONE;
  987. }
  988. static int abort_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  989. {
  990. struct iwch_ep *ep = ctx;
  991. unsigned long flags;
  992. int release = 0;
  993. pr_debug("%s ep %p\n", __func__, ep);
  994. BUG_ON(!ep);
  995. /*
  996. * We get 2 abort replies from the HW. The first one must
  997. * be ignored except for scribbling that we need one more.
  998. */
  999. if (!test_and_set_bit(ABORT_REQ_IN_PROGRESS, &ep->com.flags)) {
  1000. return CPL_RET_BUF_DONE;
  1001. }
  1002. spin_lock_irqsave(&ep->com.lock, flags);
  1003. switch (ep->com.state) {
  1004. case ABORTING:
  1005. close_complete_upcall(ep);
  1006. __state_set(&ep->com, DEAD);
  1007. release = 1;
  1008. break;
  1009. default:
  1010. pr_err("%s ep %p state %d\n", __func__, ep, ep->com.state);
  1011. break;
  1012. }
  1013. spin_unlock_irqrestore(&ep->com.lock, flags);
  1014. if (release)
  1015. release_ep_resources(ep);
  1016. return CPL_RET_BUF_DONE;
  1017. }
  1018. /*
  1019. * Return whether a failed active open has allocated a TID
  1020. */
  1021. static inline int act_open_has_tid(int status)
  1022. {
  1023. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1024. status != CPL_ERR_ARP_MISS;
  1025. }
  1026. static int act_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1027. {
  1028. struct iwch_ep *ep = ctx;
  1029. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1030. pr_debug("%s ep %p status %u errno %d\n", __func__, ep, rpl->status,
  1031. status2errno(rpl->status));
  1032. connect_reply_upcall(ep, status2errno(rpl->status));
  1033. state_set(&ep->com, DEAD);
  1034. if (ep->com.tdev->type != T3A && act_open_has_tid(rpl->status))
  1035. release_tid(ep->com.tdev, GET_TID(rpl), NULL);
  1036. cxgb3_free_atid(ep->com.tdev, ep->atid);
  1037. dst_release(ep->dst);
  1038. l2t_release(ep->com.tdev, ep->l2t);
  1039. put_ep(&ep->com);
  1040. return CPL_RET_BUF_DONE;
  1041. }
  1042. static int listen_start(struct iwch_listen_ep *ep)
  1043. {
  1044. struct sk_buff *skb;
  1045. struct cpl_pass_open_req *req;
  1046. pr_debug("%s ep %p\n", __func__, ep);
  1047. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1048. if (!skb) {
  1049. pr_err("t3c_listen_start failed to alloc skb!\n");
  1050. return -ENOMEM;
  1051. }
  1052. req = (struct cpl_pass_open_req *) skb_put(skb, sizeof(*req));
  1053. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1054. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, ep->stid));
  1055. req->local_port = ep->com.local_addr.sin_port;
  1056. req->local_ip = ep->com.local_addr.sin_addr.s_addr;
  1057. req->peer_port = 0;
  1058. req->peer_ip = 0;
  1059. req->peer_netmask = 0;
  1060. req->opt0h = htonl(F_DELACK | F_TCAM_BYPASS);
  1061. req->opt0l = htonl(V_RCV_BUFSIZ(rcv_win>>10));
  1062. req->opt1 = htonl(V_CONN_POLICY(CPL_CONN_POLICY_ASK));
  1063. skb->priority = 1;
  1064. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  1065. }
  1066. static int pass_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1067. {
  1068. struct iwch_listen_ep *ep = ctx;
  1069. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1070. pr_debug("%s ep %p status %d error %d\n", __func__, ep,
  1071. rpl->status, status2errno(rpl->status));
  1072. ep->com.rpl_err = status2errno(rpl->status);
  1073. ep->com.rpl_done = 1;
  1074. wake_up(&ep->com.waitq);
  1075. return CPL_RET_BUF_DONE;
  1076. }
  1077. static int listen_stop(struct iwch_listen_ep *ep)
  1078. {
  1079. struct sk_buff *skb;
  1080. struct cpl_close_listserv_req *req;
  1081. pr_debug("%s ep %p\n", __func__, ep);
  1082. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1083. if (!skb) {
  1084. pr_err("%s - failed to alloc skb\n", __func__);
  1085. return -ENOMEM;
  1086. }
  1087. req = (struct cpl_close_listserv_req *) skb_put(skb, sizeof(*req));
  1088. req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1089. req->cpu_idx = 0;
  1090. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, ep->stid));
  1091. skb->priority = 1;
  1092. return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
  1093. }
  1094. static int close_listsrv_rpl(struct t3cdev *tdev, struct sk_buff *skb,
  1095. void *ctx)
  1096. {
  1097. struct iwch_listen_ep *ep = ctx;
  1098. struct cpl_close_listserv_rpl *rpl = cplhdr(skb);
  1099. pr_debug("%s ep %p\n", __func__, ep);
  1100. ep->com.rpl_err = status2errno(rpl->status);
  1101. ep->com.rpl_done = 1;
  1102. wake_up(&ep->com.waitq);
  1103. return CPL_RET_BUF_DONE;
  1104. }
  1105. static void accept_cr(struct iwch_ep *ep, __be32 peer_ip, struct sk_buff *skb)
  1106. {
  1107. struct cpl_pass_accept_rpl *rpl;
  1108. unsigned int mtu_idx;
  1109. u32 opt0h, opt0l, opt2;
  1110. int wscale;
  1111. pr_debug("%s ep %p\n", __func__, ep);
  1112. BUG_ON(skb_cloned(skb));
  1113. skb_trim(skb, sizeof(*rpl));
  1114. skb_get(skb);
  1115. mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst));
  1116. wscale = compute_wscale(rcv_win);
  1117. opt0h = V_NAGLE(0) |
  1118. V_NO_CONG(nocong) |
  1119. V_KEEP_ALIVE(1) |
  1120. F_TCAM_BYPASS |
  1121. V_WND_SCALE(wscale) |
  1122. V_MSS_IDX(mtu_idx) |
  1123. V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
  1124. opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
  1125. opt2 = F_RX_COALESCE_VALID | V_RX_COALESCE(0) | V_FLAVORS_VALID(1) |
  1126. V_CONG_CONTROL_FLAVOR(cong_flavor);
  1127. rpl = cplhdr(skb);
  1128. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1129. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, ep->hwtid));
  1130. rpl->peer_ip = peer_ip;
  1131. rpl->opt0h = htonl(opt0h);
  1132. rpl->opt0l_status = htonl(opt0l | CPL_PASS_OPEN_ACCEPT);
  1133. rpl->opt2 = htonl(opt2);
  1134. rpl->rsvd = rpl->opt2; /* workaround for HW bug */
  1135. skb->priority = CPL_PRIORITY_SETUP;
  1136. iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
  1137. return;
  1138. }
  1139. static void reject_cr(struct t3cdev *tdev, u32 hwtid, __be32 peer_ip,
  1140. struct sk_buff *skb)
  1141. {
  1142. pr_debug("%s t3cdev %p tid %u peer_ip %x\n", __func__, tdev, hwtid,
  1143. peer_ip);
  1144. BUG_ON(skb_cloned(skb));
  1145. skb_trim(skb, sizeof(struct cpl_tid_release));
  1146. skb_get(skb);
  1147. if (tdev->type != T3A)
  1148. release_tid(tdev, hwtid, skb);
  1149. else {
  1150. struct cpl_pass_accept_rpl *rpl;
  1151. rpl = cplhdr(skb);
  1152. skb->priority = CPL_PRIORITY_SETUP;
  1153. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
  1154. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1155. hwtid));
  1156. rpl->peer_ip = peer_ip;
  1157. rpl->opt0h = htonl(F_TCAM_BYPASS);
  1158. rpl->opt0l_status = htonl(CPL_PASS_OPEN_REJECT);
  1159. rpl->opt2 = 0;
  1160. rpl->rsvd = rpl->opt2;
  1161. iwch_cxgb3_ofld_send(tdev, skb);
  1162. }
  1163. }
  1164. static int pass_accept_req(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1165. {
  1166. struct iwch_ep *child_ep, *parent_ep = ctx;
  1167. struct cpl_pass_accept_req *req = cplhdr(skb);
  1168. unsigned int hwtid = GET_TID(req);
  1169. struct dst_entry *dst;
  1170. struct l2t_entry *l2t;
  1171. struct rtable *rt;
  1172. struct iff_mac tim;
  1173. pr_debug("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
  1174. if (state_read(&parent_ep->com) != LISTEN) {
  1175. pr_err("%s - listening ep not in LISTEN\n", __func__);
  1176. goto reject;
  1177. }
  1178. /*
  1179. * Find the netdev for this connection request.
  1180. */
  1181. tim.mac_addr = req->dst_mac;
  1182. tim.vlan_tag = ntohs(req->vlan_tag);
  1183. if (tdev->ctl(tdev, GET_IFF_FROM_MAC, &tim) < 0 || !tim.dev) {
  1184. pr_err("%s bad dst mac %pM\n", __func__, req->dst_mac);
  1185. goto reject;
  1186. }
  1187. /* Find output route */
  1188. rt = find_route(tdev,
  1189. req->local_ip,
  1190. req->peer_ip,
  1191. req->local_port,
  1192. req->peer_port, G_PASS_OPEN_TOS(ntohl(req->tos_tid)));
  1193. if (!rt) {
  1194. pr_err("%s - failed to find dst entry!\n", __func__);
  1195. goto reject;
  1196. }
  1197. dst = &rt->dst;
  1198. l2t = t3_l2t_get(tdev, dst, NULL, &req->peer_ip);
  1199. if (!l2t) {
  1200. pr_err("%s - failed to allocate l2t entry!\n", __func__);
  1201. dst_release(dst);
  1202. goto reject;
  1203. }
  1204. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1205. if (!child_ep) {
  1206. pr_err("%s - failed to allocate ep entry!\n", __func__);
  1207. l2t_release(tdev, l2t);
  1208. dst_release(dst);
  1209. goto reject;
  1210. }
  1211. state_set(&child_ep->com, CONNECTING);
  1212. child_ep->com.tdev = tdev;
  1213. child_ep->com.cm_id = NULL;
  1214. child_ep->com.local_addr.sin_family = AF_INET;
  1215. child_ep->com.local_addr.sin_port = req->local_port;
  1216. child_ep->com.local_addr.sin_addr.s_addr = req->local_ip;
  1217. child_ep->com.remote_addr.sin_family = AF_INET;
  1218. child_ep->com.remote_addr.sin_port = req->peer_port;
  1219. child_ep->com.remote_addr.sin_addr.s_addr = req->peer_ip;
  1220. get_ep(&parent_ep->com);
  1221. child_ep->parent_ep = parent_ep;
  1222. child_ep->tos = G_PASS_OPEN_TOS(ntohl(req->tos_tid));
  1223. child_ep->l2t = l2t;
  1224. child_ep->dst = dst;
  1225. child_ep->hwtid = hwtid;
  1226. init_timer(&child_ep->timer);
  1227. cxgb3_insert_tid(tdev, &t3c_client, child_ep, hwtid);
  1228. accept_cr(child_ep, req->peer_ip, skb);
  1229. goto out;
  1230. reject:
  1231. reject_cr(tdev, hwtid, req->peer_ip, skb);
  1232. out:
  1233. return CPL_RET_BUF_DONE;
  1234. }
  1235. static int pass_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1236. {
  1237. struct iwch_ep *ep = ctx;
  1238. struct cpl_pass_establish *req = cplhdr(skb);
  1239. pr_debug("%s ep %p\n", __func__, ep);
  1240. ep->snd_seq = ntohl(req->snd_isn);
  1241. ep->rcv_seq = ntohl(req->rcv_isn);
  1242. set_emss(ep, ntohs(req->tcp_opt));
  1243. dst_confirm(ep->dst);
  1244. state_set(&ep->com, MPA_REQ_WAIT);
  1245. start_ep_timer(ep);
  1246. return CPL_RET_BUF_DONE;
  1247. }
  1248. static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1249. {
  1250. struct iwch_ep *ep = ctx;
  1251. struct iwch_qp_attributes attrs;
  1252. unsigned long flags;
  1253. int disconnect = 1;
  1254. int release = 0;
  1255. pr_debug("%s ep %p\n", __func__, ep);
  1256. dst_confirm(ep->dst);
  1257. spin_lock_irqsave(&ep->com.lock, flags);
  1258. switch (ep->com.state) {
  1259. case MPA_REQ_WAIT:
  1260. __state_set(&ep->com, CLOSING);
  1261. break;
  1262. case MPA_REQ_SENT:
  1263. __state_set(&ep->com, CLOSING);
  1264. connect_reply_upcall(ep, -ECONNRESET);
  1265. break;
  1266. case MPA_REQ_RCVD:
  1267. /*
  1268. * We're gonna mark this puppy DEAD, but keep
  1269. * the reference on it until the ULP accepts or
  1270. * rejects the CR. Also wake up anyone waiting
  1271. * in rdma connection migration (see iwch_accept_cr()).
  1272. */
  1273. __state_set(&ep->com, CLOSING);
  1274. ep->com.rpl_done = 1;
  1275. ep->com.rpl_err = -ECONNRESET;
  1276. pr_debug("waking up ep %p\n", ep);
  1277. wake_up(&ep->com.waitq);
  1278. break;
  1279. case MPA_REP_SENT:
  1280. __state_set(&ep->com, CLOSING);
  1281. ep->com.rpl_done = 1;
  1282. ep->com.rpl_err = -ECONNRESET;
  1283. pr_debug("waking up ep %p\n", ep);
  1284. wake_up(&ep->com.waitq);
  1285. break;
  1286. case FPDU_MODE:
  1287. start_ep_timer(ep);
  1288. __state_set(&ep->com, CLOSING);
  1289. attrs.next_state = IWCH_QP_STATE_CLOSING;
  1290. iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1291. IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
  1292. peer_close_upcall(ep);
  1293. break;
  1294. case ABORTING:
  1295. disconnect = 0;
  1296. break;
  1297. case CLOSING:
  1298. __state_set(&ep->com, MORIBUND);
  1299. disconnect = 0;
  1300. break;
  1301. case MORIBUND:
  1302. stop_ep_timer(ep);
  1303. if (ep->com.cm_id && ep->com.qp) {
  1304. attrs.next_state = IWCH_QP_STATE_IDLE;
  1305. iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1306. IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
  1307. }
  1308. close_complete_upcall(ep);
  1309. __state_set(&ep->com, DEAD);
  1310. release = 1;
  1311. disconnect = 0;
  1312. break;
  1313. case DEAD:
  1314. disconnect = 0;
  1315. break;
  1316. default:
  1317. BUG_ON(1);
  1318. }
  1319. spin_unlock_irqrestore(&ep->com.lock, flags);
  1320. if (disconnect)
  1321. iwch_ep_disconnect(ep, 0, GFP_KERNEL);
  1322. if (release)
  1323. release_ep_resources(ep);
  1324. return CPL_RET_BUF_DONE;
  1325. }
  1326. /*
  1327. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  1328. */
  1329. static int is_neg_adv_abort(unsigned int status)
  1330. {
  1331. return status == CPL_ERR_RTX_NEG_ADVICE ||
  1332. status == CPL_ERR_PERSIST_NEG_ADVICE;
  1333. }
  1334. static int peer_abort(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1335. {
  1336. struct cpl_abort_req_rss *req = cplhdr(skb);
  1337. struct iwch_ep *ep = ctx;
  1338. struct cpl_abort_rpl *rpl;
  1339. struct sk_buff *rpl_skb;
  1340. struct iwch_qp_attributes attrs;
  1341. int ret;
  1342. int release = 0;
  1343. unsigned long flags;
  1344. if (is_neg_adv_abort(req->status)) {
  1345. pr_debug("%s neg_adv_abort ep %p tid %d\n", __func__, ep,
  1346. ep->hwtid);
  1347. t3_l2t_send_event(ep->com.tdev, ep->l2t);
  1348. return CPL_RET_BUF_DONE;
  1349. }
  1350. /*
  1351. * We get 2 peer aborts from the HW. The first one must
  1352. * be ignored except for scribbling that we need one more.
  1353. */
  1354. if (!test_and_set_bit(PEER_ABORT_IN_PROGRESS, &ep->com.flags)) {
  1355. return CPL_RET_BUF_DONE;
  1356. }
  1357. spin_lock_irqsave(&ep->com.lock, flags);
  1358. pr_debug("%s ep %p state %u\n", __func__, ep, ep->com.state);
  1359. switch (ep->com.state) {
  1360. case CONNECTING:
  1361. break;
  1362. case MPA_REQ_WAIT:
  1363. stop_ep_timer(ep);
  1364. break;
  1365. case MPA_REQ_SENT:
  1366. stop_ep_timer(ep);
  1367. connect_reply_upcall(ep, -ECONNRESET);
  1368. break;
  1369. case MPA_REP_SENT:
  1370. ep->com.rpl_done = 1;
  1371. ep->com.rpl_err = -ECONNRESET;
  1372. pr_debug("waking up ep %p\n", ep);
  1373. wake_up(&ep->com.waitq);
  1374. break;
  1375. case MPA_REQ_RCVD:
  1376. /*
  1377. * We're gonna mark this puppy DEAD, but keep
  1378. * the reference on it until the ULP accepts or
  1379. * rejects the CR. Also wake up anyone waiting
  1380. * in rdma connection migration (see iwch_accept_cr()).
  1381. */
  1382. ep->com.rpl_done = 1;
  1383. ep->com.rpl_err = -ECONNRESET;
  1384. pr_debug("waking up ep %p\n", ep);
  1385. wake_up(&ep->com.waitq);
  1386. break;
  1387. case MORIBUND:
  1388. case CLOSING:
  1389. stop_ep_timer(ep);
  1390. /*FALLTHROUGH*/
  1391. case FPDU_MODE:
  1392. if (ep->com.cm_id && ep->com.qp) {
  1393. attrs.next_state = IWCH_QP_STATE_ERROR;
  1394. ret = iwch_modify_qp(ep->com.qp->rhp,
  1395. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1396. &attrs, 1);
  1397. if (ret)
  1398. pr_err("%s - qp <- error failed!\n", __func__);
  1399. }
  1400. peer_abort_upcall(ep);
  1401. break;
  1402. case ABORTING:
  1403. break;
  1404. case DEAD:
  1405. pr_debug("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1406. spin_unlock_irqrestore(&ep->com.lock, flags);
  1407. return CPL_RET_BUF_DONE;
  1408. default:
  1409. BUG_ON(1);
  1410. break;
  1411. }
  1412. dst_confirm(ep->dst);
  1413. if (ep->com.state != ABORTING) {
  1414. __state_set(&ep->com, DEAD);
  1415. release = 1;
  1416. }
  1417. spin_unlock_irqrestore(&ep->com.lock, flags);
  1418. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1419. if (!rpl_skb) {
  1420. pr_err("%s - cannot allocate skb!\n", __func__);
  1421. release = 1;
  1422. goto out;
  1423. }
  1424. rpl_skb->priority = CPL_PRIORITY_DATA;
  1425. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  1426. rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL));
  1427. rpl->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
  1428. OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  1429. rpl->cmd = CPL_ABORT_NO_RST;
  1430. iwch_cxgb3_ofld_send(ep->com.tdev, rpl_skb);
  1431. out:
  1432. if (release)
  1433. release_ep_resources(ep);
  1434. return CPL_RET_BUF_DONE;
  1435. }
  1436. static int close_con_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1437. {
  1438. struct iwch_ep *ep = ctx;
  1439. struct iwch_qp_attributes attrs;
  1440. unsigned long flags;
  1441. int release = 0;
  1442. pr_debug("%s ep %p\n", __func__, ep);
  1443. BUG_ON(!ep);
  1444. /* The cm_id may be null if we failed to connect */
  1445. spin_lock_irqsave(&ep->com.lock, flags);
  1446. switch (ep->com.state) {
  1447. case CLOSING:
  1448. __state_set(&ep->com, MORIBUND);
  1449. break;
  1450. case MORIBUND:
  1451. stop_ep_timer(ep);
  1452. if ((ep->com.cm_id) && (ep->com.qp)) {
  1453. attrs.next_state = IWCH_QP_STATE_IDLE;
  1454. iwch_modify_qp(ep->com.qp->rhp,
  1455. ep->com.qp,
  1456. IWCH_QP_ATTR_NEXT_STATE,
  1457. &attrs, 1);
  1458. }
  1459. close_complete_upcall(ep);
  1460. __state_set(&ep->com, DEAD);
  1461. release = 1;
  1462. break;
  1463. case ABORTING:
  1464. case DEAD:
  1465. break;
  1466. default:
  1467. BUG_ON(1);
  1468. break;
  1469. }
  1470. spin_unlock_irqrestore(&ep->com.lock, flags);
  1471. if (release)
  1472. release_ep_resources(ep);
  1473. return CPL_RET_BUF_DONE;
  1474. }
  1475. /*
  1476. * T3A does 3 things when a TERM is received:
  1477. * 1) send up a CPL_RDMA_TERMINATE message with the TERM packet
  1478. * 2) generate an async event on the QP with the TERMINATE opcode
  1479. * 3) post a TERMINATE opcode cqe into the associated CQ.
  1480. *
  1481. * For (1), we save the message in the qp for later consumer consumption.
  1482. * For (2), we move the QP into TERMINATE, post a QP event and disconnect.
  1483. * For (3), we toss the CQE in cxio_poll_cq().
  1484. *
  1485. * terminate() handles case (1)...
  1486. */
  1487. static int terminate(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1488. {
  1489. struct iwch_ep *ep = ctx;
  1490. if (state_read(&ep->com) != FPDU_MODE)
  1491. return CPL_RET_BUF_DONE;
  1492. pr_debug("%s ep %p\n", __func__, ep);
  1493. skb_pull(skb, sizeof(struct cpl_rdma_terminate));
  1494. pr_debug("%s saving %d bytes of term msg\n", __func__, skb->len);
  1495. skb_copy_from_linear_data(skb, ep->com.qp->attr.terminate_buffer,
  1496. skb->len);
  1497. ep->com.qp->attr.terminate_msg_len = skb->len;
  1498. ep->com.qp->attr.is_terminate_local = 0;
  1499. return CPL_RET_BUF_DONE;
  1500. }
  1501. static int ec_status(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1502. {
  1503. struct cpl_rdma_ec_status *rep = cplhdr(skb);
  1504. struct iwch_ep *ep = ctx;
  1505. pr_debug("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid,
  1506. rep->status);
  1507. if (rep->status) {
  1508. struct iwch_qp_attributes attrs;
  1509. pr_err("%s BAD CLOSE - Aborting tid %u\n",
  1510. __func__, ep->hwtid);
  1511. stop_ep_timer(ep);
  1512. attrs.next_state = IWCH_QP_STATE_ERROR;
  1513. iwch_modify_qp(ep->com.qp->rhp,
  1514. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1515. &attrs, 1);
  1516. abort_connection(ep, NULL, GFP_KERNEL);
  1517. }
  1518. return CPL_RET_BUF_DONE;
  1519. }
  1520. static void ep_timeout(unsigned long arg)
  1521. {
  1522. struct iwch_ep *ep = (struct iwch_ep *)arg;
  1523. struct iwch_qp_attributes attrs;
  1524. unsigned long flags;
  1525. int abort = 1;
  1526. spin_lock_irqsave(&ep->com.lock, flags);
  1527. pr_debug("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  1528. ep->com.state);
  1529. switch (ep->com.state) {
  1530. case MPA_REQ_SENT:
  1531. __state_set(&ep->com, ABORTING);
  1532. connect_reply_upcall(ep, -ETIMEDOUT);
  1533. break;
  1534. case MPA_REQ_WAIT:
  1535. __state_set(&ep->com, ABORTING);
  1536. break;
  1537. case CLOSING:
  1538. case MORIBUND:
  1539. if (ep->com.cm_id && ep->com.qp) {
  1540. attrs.next_state = IWCH_QP_STATE_ERROR;
  1541. iwch_modify_qp(ep->com.qp->rhp,
  1542. ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
  1543. &attrs, 1);
  1544. }
  1545. __state_set(&ep->com, ABORTING);
  1546. break;
  1547. default:
  1548. WARN(1, "%s unexpected state ep %p state %u\n",
  1549. __func__, ep, ep->com.state);
  1550. abort = 0;
  1551. }
  1552. spin_unlock_irqrestore(&ep->com.lock, flags);
  1553. if (abort)
  1554. abort_connection(ep, NULL, GFP_ATOMIC);
  1555. put_ep(&ep->com);
  1556. }
  1557. int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  1558. {
  1559. int err;
  1560. struct iwch_ep *ep = to_ep(cm_id);
  1561. pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1562. if (state_read(&ep->com) == DEAD) {
  1563. put_ep(&ep->com);
  1564. return -ECONNRESET;
  1565. }
  1566. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1567. if (mpa_rev == 0)
  1568. abort_connection(ep, NULL, GFP_KERNEL);
  1569. else {
  1570. err = send_mpa_reject(ep, pdata, pdata_len);
  1571. err = iwch_ep_disconnect(ep, 0, GFP_KERNEL);
  1572. }
  1573. put_ep(&ep->com);
  1574. return 0;
  1575. }
  1576. int iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1577. {
  1578. int err;
  1579. struct iwch_qp_attributes attrs;
  1580. enum iwch_qp_attr_mask mask;
  1581. struct iwch_ep *ep = to_ep(cm_id);
  1582. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1583. struct iwch_qp *qp = get_qhp(h, conn_param->qpn);
  1584. pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1585. if (state_read(&ep->com) == DEAD) {
  1586. err = -ECONNRESET;
  1587. goto err;
  1588. }
  1589. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1590. BUG_ON(!qp);
  1591. if ((conn_param->ord > qp->rhp->attr.max_rdma_read_qp_depth) ||
  1592. (conn_param->ird > qp->rhp->attr.max_rdma_reads_per_qp)) {
  1593. abort_connection(ep, NULL, GFP_KERNEL);
  1594. err = -EINVAL;
  1595. goto err;
  1596. }
  1597. cm_id->add_ref(cm_id);
  1598. ep->com.cm_id = cm_id;
  1599. ep->com.qp = qp;
  1600. ep->ird = conn_param->ird;
  1601. ep->ord = conn_param->ord;
  1602. if (peer2peer && ep->ird == 0)
  1603. ep->ird = 1;
  1604. pr_debug("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  1605. /* bind QP to EP and move to RTS */
  1606. attrs.mpa_attr = ep->mpa_attr;
  1607. attrs.max_ird = ep->ird;
  1608. attrs.max_ord = ep->ord;
  1609. attrs.llp_stream_handle = ep;
  1610. attrs.next_state = IWCH_QP_STATE_RTS;
  1611. /* bind QP and TID with INIT_WR */
  1612. mask = IWCH_QP_ATTR_NEXT_STATE |
  1613. IWCH_QP_ATTR_LLP_STREAM_HANDLE |
  1614. IWCH_QP_ATTR_MPA_ATTR |
  1615. IWCH_QP_ATTR_MAX_IRD |
  1616. IWCH_QP_ATTR_MAX_ORD;
  1617. err = iwch_modify_qp(ep->com.qp->rhp,
  1618. ep->com.qp, mask, &attrs, 1);
  1619. if (err)
  1620. goto err1;
  1621. /* if needed, wait for wr_ack */
  1622. if (iwch_rqes_posted(qp)) {
  1623. wait_event(ep->com.waitq, ep->com.rpl_done);
  1624. err = ep->com.rpl_err;
  1625. if (err)
  1626. goto err1;
  1627. }
  1628. err = send_mpa_reply(ep, conn_param->private_data,
  1629. conn_param->private_data_len);
  1630. if (err)
  1631. goto err1;
  1632. state_set(&ep->com, FPDU_MODE);
  1633. established_upcall(ep);
  1634. put_ep(&ep->com);
  1635. return 0;
  1636. err1:
  1637. ep->com.cm_id = NULL;
  1638. ep->com.qp = NULL;
  1639. cm_id->rem_ref(cm_id);
  1640. err:
  1641. put_ep(&ep->com);
  1642. return err;
  1643. }
  1644. static int is_loopback_dst(struct iw_cm_id *cm_id)
  1645. {
  1646. struct net_device *dev;
  1647. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
  1648. dev = ip_dev_find(&init_net, raddr->sin_addr.s_addr);
  1649. if (!dev)
  1650. return 0;
  1651. dev_put(dev);
  1652. return 1;
  1653. }
  1654. int iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1655. {
  1656. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1657. struct iwch_ep *ep;
  1658. struct rtable *rt;
  1659. int err = 0;
  1660. struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
  1661. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
  1662. if (cm_id->m_remote_addr.ss_family != PF_INET) {
  1663. err = -ENOSYS;
  1664. goto out;
  1665. }
  1666. if (is_loopback_dst(cm_id)) {
  1667. err = -ENOSYS;
  1668. goto out;
  1669. }
  1670. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1671. if (!ep) {
  1672. pr_err("%s - cannot alloc ep\n", __func__);
  1673. err = -ENOMEM;
  1674. goto out;
  1675. }
  1676. init_timer(&ep->timer);
  1677. ep->plen = conn_param->private_data_len;
  1678. if (ep->plen)
  1679. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  1680. conn_param->private_data, ep->plen);
  1681. ep->ird = conn_param->ird;
  1682. ep->ord = conn_param->ord;
  1683. if (peer2peer && ep->ord == 0)
  1684. ep->ord = 1;
  1685. ep->com.tdev = h->rdev.t3cdev_p;
  1686. cm_id->add_ref(cm_id);
  1687. ep->com.cm_id = cm_id;
  1688. ep->com.qp = get_qhp(h, conn_param->qpn);
  1689. BUG_ON(!ep->com.qp);
  1690. pr_debug("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  1691. ep->com.qp, cm_id);
  1692. /*
  1693. * Allocate an active TID to initiate a TCP connection.
  1694. */
  1695. ep->atid = cxgb3_alloc_atid(h->rdev.t3cdev_p, &t3c_client, ep);
  1696. if (ep->atid == -1) {
  1697. pr_err("%s - cannot alloc atid\n", __func__);
  1698. err = -ENOMEM;
  1699. goto fail2;
  1700. }
  1701. /* find a route */
  1702. rt = find_route(h->rdev.t3cdev_p, laddr->sin_addr.s_addr,
  1703. raddr->sin_addr.s_addr, laddr->sin_port,
  1704. raddr->sin_port, IPTOS_LOWDELAY);
  1705. if (!rt) {
  1706. pr_err("%s - cannot find route\n", __func__);
  1707. err = -EHOSTUNREACH;
  1708. goto fail3;
  1709. }
  1710. ep->dst = &rt->dst;
  1711. ep->l2t = t3_l2t_get(ep->com.tdev, ep->dst, NULL,
  1712. &raddr->sin_addr.s_addr);
  1713. if (!ep->l2t) {
  1714. pr_err("%s - cannot alloc l2e\n", __func__);
  1715. err = -ENOMEM;
  1716. goto fail4;
  1717. }
  1718. state_set(&ep->com, CONNECTING);
  1719. ep->tos = IPTOS_LOWDELAY;
  1720. memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
  1721. sizeof(ep->com.local_addr));
  1722. memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
  1723. sizeof(ep->com.remote_addr));
  1724. /* send connect request to rnic */
  1725. err = send_connect(ep);
  1726. if (!err)
  1727. goto out;
  1728. l2t_release(h->rdev.t3cdev_p, ep->l2t);
  1729. fail4:
  1730. dst_release(ep->dst);
  1731. fail3:
  1732. cxgb3_free_atid(ep->com.tdev, ep->atid);
  1733. fail2:
  1734. cm_id->rem_ref(cm_id);
  1735. put_ep(&ep->com);
  1736. out:
  1737. return err;
  1738. }
  1739. int iwch_create_listen(struct iw_cm_id *cm_id, int backlog)
  1740. {
  1741. int err = 0;
  1742. struct iwch_dev *h = to_iwch_dev(cm_id->device);
  1743. struct iwch_listen_ep *ep;
  1744. might_sleep();
  1745. if (cm_id->m_local_addr.ss_family != PF_INET) {
  1746. err = -ENOSYS;
  1747. goto fail1;
  1748. }
  1749. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1750. if (!ep) {
  1751. pr_err("%s - cannot alloc ep\n", __func__);
  1752. err = -ENOMEM;
  1753. goto fail1;
  1754. }
  1755. pr_debug("%s ep %p\n", __func__, ep);
  1756. ep->com.tdev = h->rdev.t3cdev_p;
  1757. cm_id->add_ref(cm_id);
  1758. ep->com.cm_id = cm_id;
  1759. ep->backlog = backlog;
  1760. memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
  1761. sizeof(ep->com.local_addr));
  1762. /*
  1763. * Allocate a server TID.
  1764. */
  1765. ep->stid = cxgb3_alloc_stid(h->rdev.t3cdev_p, &t3c_client, ep);
  1766. if (ep->stid == -1) {
  1767. pr_err("%s - cannot alloc atid\n", __func__);
  1768. err = -ENOMEM;
  1769. goto fail2;
  1770. }
  1771. state_set(&ep->com, LISTEN);
  1772. err = listen_start(ep);
  1773. if (err)
  1774. goto fail3;
  1775. /* wait for pass_open_rpl */
  1776. wait_event(ep->com.waitq, ep->com.rpl_done);
  1777. err = ep->com.rpl_err;
  1778. if (!err) {
  1779. cm_id->provider_data = ep;
  1780. goto out;
  1781. }
  1782. fail3:
  1783. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1784. fail2:
  1785. cm_id->rem_ref(cm_id);
  1786. put_ep(&ep->com);
  1787. fail1:
  1788. out:
  1789. return err;
  1790. }
  1791. int iwch_destroy_listen(struct iw_cm_id *cm_id)
  1792. {
  1793. int err;
  1794. struct iwch_listen_ep *ep = to_listen_ep(cm_id);
  1795. pr_debug("%s ep %p\n", __func__, ep);
  1796. might_sleep();
  1797. state_set(&ep->com, DEAD);
  1798. ep->com.rpl_done = 0;
  1799. ep->com.rpl_err = 0;
  1800. err = listen_stop(ep);
  1801. if (err)
  1802. goto done;
  1803. wait_event(ep->com.waitq, ep->com.rpl_done);
  1804. cxgb3_free_stid(ep->com.tdev, ep->stid);
  1805. done:
  1806. err = ep->com.rpl_err;
  1807. cm_id->rem_ref(cm_id);
  1808. put_ep(&ep->com);
  1809. return err;
  1810. }
  1811. int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp)
  1812. {
  1813. int ret=0;
  1814. unsigned long flags;
  1815. int close = 0;
  1816. int fatal = 0;
  1817. struct t3cdev *tdev;
  1818. struct cxio_rdev *rdev;
  1819. spin_lock_irqsave(&ep->com.lock, flags);
  1820. pr_debug("%s ep %p state %s, abrupt %d\n", __func__, ep,
  1821. states[ep->com.state], abrupt);
  1822. tdev = (struct t3cdev *)ep->com.tdev;
  1823. rdev = (struct cxio_rdev *)tdev->ulp;
  1824. if (cxio_fatal_error(rdev)) {
  1825. fatal = 1;
  1826. close_complete_upcall(ep);
  1827. ep->com.state = DEAD;
  1828. }
  1829. switch (ep->com.state) {
  1830. case MPA_REQ_WAIT:
  1831. case MPA_REQ_SENT:
  1832. case MPA_REQ_RCVD:
  1833. case MPA_REP_SENT:
  1834. case FPDU_MODE:
  1835. close = 1;
  1836. if (abrupt)
  1837. ep->com.state = ABORTING;
  1838. else {
  1839. ep->com.state = CLOSING;
  1840. start_ep_timer(ep);
  1841. }
  1842. set_bit(CLOSE_SENT, &ep->com.flags);
  1843. break;
  1844. case CLOSING:
  1845. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  1846. close = 1;
  1847. if (abrupt) {
  1848. stop_ep_timer(ep);
  1849. ep->com.state = ABORTING;
  1850. } else
  1851. ep->com.state = MORIBUND;
  1852. }
  1853. break;
  1854. case MORIBUND:
  1855. case ABORTING:
  1856. case DEAD:
  1857. pr_debug("%s ignoring disconnect ep %p state %u\n",
  1858. __func__, ep, ep->com.state);
  1859. break;
  1860. default:
  1861. BUG();
  1862. break;
  1863. }
  1864. spin_unlock_irqrestore(&ep->com.lock, flags);
  1865. if (close) {
  1866. if (abrupt)
  1867. ret = send_abort(ep, NULL, gfp);
  1868. else
  1869. ret = send_halfclose(ep, gfp);
  1870. if (ret)
  1871. fatal = 1;
  1872. }
  1873. if (fatal)
  1874. release_ep_resources(ep);
  1875. return ret;
  1876. }
  1877. int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
  1878. struct l2t_entry *l2t)
  1879. {
  1880. struct iwch_ep *ep = ctx;
  1881. if (ep->dst != old)
  1882. return 0;
  1883. pr_debug("%s ep %p redirect to dst %p l2t %p\n", __func__, ep, new,
  1884. l2t);
  1885. dst_hold(new);
  1886. l2t_release(ep->com.tdev, ep->l2t);
  1887. ep->l2t = l2t;
  1888. dst_release(old);
  1889. ep->dst = new;
  1890. return 1;
  1891. }
  1892. /*
  1893. * All the CM events are handled on a work queue to have a safe context.
  1894. * These are the real handlers that are called from the work queue.
  1895. */
  1896. static const cxgb3_cpl_handler_func work_handlers[NUM_CPL_CMDS] = {
  1897. [CPL_ACT_ESTABLISH] = act_establish,
  1898. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  1899. [CPL_RX_DATA] = rx_data,
  1900. [CPL_TX_DMA_ACK] = tx_ack,
  1901. [CPL_ABORT_RPL_RSS] = abort_rpl,
  1902. [CPL_ABORT_RPL] = abort_rpl,
  1903. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  1904. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  1905. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  1906. [CPL_PASS_ESTABLISH] = pass_establish,
  1907. [CPL_PEER_CLOSE] = peer_close,
  1908. [CPL_ABORT_REQ_RSS] = peer_abort,
  1909. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  1910. [CPL_RDMA_TERMINATE] = terminate,
  1911. [CPL_RDMA_EC_STATUS] = ec_status,
  1912. };
  1913. static void process_work(struct work_struct *work)
  1914. {
  1915. struct sk_buff *skb = NULL;
  1916. void *ep;
  1917. struct t3cdev *tdev;
  1918. int ret;
  1919. while ((skb = skb_dequeue(&rxq))) {
  1920. ep = *((void **) (skb->cb));
  1921. tdev = *((struct t3cdev **) (skb->cb + sizeof(void *)));
  1922. ret = work_handlers[G_OPCODE(ntohl((__force __be32)skb->csum))](tdev, skb, ep);
  1923. if (ret & CPL_RET_BUF_DONE)
  1924. kfree_skb(skb);
  1925. /*
  1926. * ep was referenced in sched(), and is freed here.
  1927. */
  1928. put_ep((struct iwch_ep_common *)ep);
  1929. }
  1930. }
  1931. static DECLARE_WORK(skb_work, process_work);
  1932. static int sched(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1933. {
  1934. struct iwch_ep_common *epc = ctx;
  1935. get_ep(epc);
  1936. /*
  1937. * Save ctx and tdev in the skb->cb area.
  1938. */
  1939. *((void **) skb->cb) = ctx;
  1940. *((struct t3cdev **) (skb->cb + sizeof(void *))) = tdev;
  1941. /*
  1942. * Queue the skb and schedule the worker thread.
  1943. */
  1944. skb_queue_tail(&rxq, skb);
  1945. queue_work(workq, &skb_work);
  1946. return 0;
  1947. }
  1948. static int set_tcb_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
  1949. {
  1950. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  1951. if (rpl->status != CPL_ERR_NONE) {
  1952. pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
  1953. rpl->status, GET_TID(rpl));
  1954. }
  1955. return CPL_RET_BUF_DONE;
  1956. }
  1957. /*
  1958. * All upcalls from the T3 Core go to sched() to schedule the
  1959. * processing on a work queue.
  1960. */
  1961. cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS] = {
  1962. [CPL_ACT_ESTABLISH] = sched,
  1963. [CPL_ACT_OPEN_RPL] = sched,
  1964. [CPL_RX_DATA] = sched,
  1965. [CPL_TX_DMA_ACK] = sched,
  1966. [CPL_ABORT_RPL_RSS] = sched,
  1967. [CPL_ABORT_RPL] = sched,
  1968. [CPL_PASS_OPEN_RPL] = sched,
  1969. [CPL_CLOSE_LISTSRV_RPL] = sched,
  1970. [CPL_PASS_ACCEPT_REQ] = sched,
  1971. [CPL_PASS_ESTABLISH] = sched,
  1972. [CPL_PEER_CLOSE] = sched,
  1973. [CPL_CLOSE_CON_RPL] = sched,
  1974. [CPL_ABORT_REQ_RSS] = sched,
  1975. [CPL_RDMA_TERMINATE] = sched,
  1976. [CPL_RDMA_EC_STATUS] = sched,
  1977. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  1978. };
  1979. int __init iwch_cm_init(void)
  1980. {
  1981. skb_queue_head_init(&rxq);
  1982. workq = alloc_ordered_workqueue("iw_cxgb3", WQ_MEM_RECLAIM);
  1983. if (!workq)
  1984. return -ENOMEM;
  1985. return 0;
  1986. }
  1987. void __exit iwch_cm_term(void)
  1988. {
  1989. flush_workqueue(workq);
  1990. destroy_workqueue(workq);
  1991. }