iwch_cm.c 57 KB

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