iwch_cm.c 54 KB

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