iwch_cm.c 53 KB

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