cm.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384
  1. /*
  2. * Copyright (c) 2009-2010 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 <linux/inetdevice.h>
  39. #include <linux/ip.h>
  40. #include <linux/tcp.h>
  41. #include <net/neighbour.h>
  42. #include <net/netevent.h>
  43. #include <net/route.h>
  44. #include "iw_cxgb4.h"
  45. static char *states[] = {
  46. "idle",
  47. "listen",
  48. "connecting",
  49. "mpa_wait_req",
  50. "mpa_req_sent",
  51. "mpa_req_rcvd",
  52. "mpa_rep_sent",
  53. "fpdu_mode",
  54. "aborting",
  55. "closing",
  56. "moribund",
  57. "dead",
  58. NULL,
  59. };
  60. static int dack_mode;
  61. module_param(dack_mode, int, 0644);
  62. MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=0)");
  63. int c4iw_max_read_depth = 8;
  64. module_param(c4iw_max_read_depth, int, 0644);
  65. MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
  66. static int enable_tcp_timestamps;
  67. module_param(enable_tcp_timestamps, int, 0644);
  68. MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
  69. static int enable_tcp_sack;
  70. module_param(enable_tcp_sack, int, 0644);
  71. MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
  72. static int enable_tcp_window_scaling = 1;
  73. module_param(enable_tcp_window_scaling, int, 0644);
  74. MODULE_PARM_DESC(enable_tcp_window_scaling,
  75. "Enable tcp window scaling (default=1)");
  76. int c4iw_debug;
  77. module_param(c4iw_debug, int, 0644);
  78. MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
  79. static int peer2peer;
  80. module_param(peer2peer, int, 0644);
  81. MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
  82. static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
  83. module_param(p2p_type, int, 0644);
  84. MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
  85. "1=RDMA_READ 0=RDMA_WRITE (default 1)");
  86. static int ep_timeout_secs = 60;
  87. module_param(ep_timeout_secs, int, 0644);
  88. MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
  89. "in seconds (default=60)");
  90. static int mpa_rev = 1;
  91. module_param(mpa_rev, int, 0644);
  92. MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
  93. "1 is spec compliant. (default=1)");
  94. static int markers_enabled;
  95. module_param(markers_enabled, int, 0644);
  96. MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
  97. static int crc_enabled = 1;
  98. module_param(crc_enabled, int, 0644);
  99. MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
  100. static int rcv_win = 256 * 1024;
  101. module_param(rcv_win, int, 0644);
  102. MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
  103. static int snd_win = 32 * 1024;
  104. module_param(snd_win, int, 0644);
  105. MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=32KB)");
  106. static struct workqueue_struct *workq;
  107. static struct sk_buff_head rxq;
  108. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
  109. static void ep_timeout(unsigned long arg);
  110. static void connect_reply_upcall(struct c4iw_ep *ep, int status);
  111. static LIST_HEAD(timeout_list);
  112. static spinlock_t timeout_lock;
  113. static void start_ep_timer(struct c4iw_ep *ep)
  114. {
  115. PDBG("%s ep %p\n", __func__, ep);
  116. if (timer_pending(&ep->timer)) {
  117. PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
  118. del_timer_sync(&ep->timer);
  119. } else
  120. c4iw_get_ep(&ep->com);
  121. ep->timer.expires = jiffies + ep_timeout_secs * HZ;
  122. ep->timer.data = (unsigned long)ep;
  123. ep->timer.function = ep_timeout;
  124. add_timer(&ep->timer);
  125. }
  126. static void stop_ep_timer(struct c4iw_ep *ep)
  127. {
  128. PDBG("%s ep %p\n", __func__, ep);
  129. if (!timer_pending(&ep->timer)) {
  130. printk(KERN_ERR "%s timer stopped when its not running! "
  131. "ep %p state %u\n", __func__, ep, ep->com.state);
  132. WARN_ON(1);
  133. return;
  134. }
  135. del_timer_sync(&ep->timer);
  136. c4iw_put_ep(&ep->com);
  137. }
  138. static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
  139. struct l2t_entry *l2e)
  140. {
  141. int error = 0;
  142. if (c4iw_fatal_error(rdev)) {
  143. kfree_skb(skb);
  144. PDBG("%s - device in error state - dropping\n", __func__);
  145. return -EIO;
  146. }
  147. error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
  148. if (error < 0)
  149. kfree_skb(skb);
  150. return error;
  151. }
  152. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
  153. {
  154. int error = 0;
  155. if (c4iw_fatal_error(rdev)) {
  156. kfree_skb(skb);
  157. PDBG("%s - device in error state - dropping\n", __func__);
  158. return -EIO;
  159. }
  160. error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
  161. if (error < 0)
  162. kfree_skb(skb);
  163. return error;
  164. }
  165. static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
  166. {
  167. struct cpl_tid_release *req;
  168. skb = get_skb(skb, sizeof *req, GFP_KERNEL);
  169. if (!skb)
  170. return;
  171. req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
  172. INIT_TP_WR(req, hwtid);
  173. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
  174. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  175. c4iw_ofld_send(rdev, skb);
  176. return;
  177. }
  178. static void set_emss(struct c4iw_ep *ep, u16 opt)
  179. {
  180. ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
  181. ep->mss = ep->emss;
  182. if (GET_TCPOPT_TSTAMP(opt))
  183. ep->emss -= 12;
  184. if (ep->emss < 128)
  185. ep->emss = 128;
  186. PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
  187. ep->mss, ep->emss);
  188. }
  189. static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
  190. {
  191. unsigned long flags;
  192. enum c4iw_ep_state state;
  193. spin_lock_irqsave(&epc->lock, flags);
  194. state = epc->state;
  195. spin_unlock_irqrestore(&epc->lock, flags);
  196. return state;
  197. }
  198. static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  199. {
  200. epc->state = new;
  201. }
  202. static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  203. {
  204. unsigned long flags;
  205. spin_lock_irqsave(&epc->lock, flags);
  206. PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
  207. __state_set(epc, new);
  208. spin_unlock_irqrestore(&epc->lock, flags);
  209. return;
  210. }
  211. static void *alloc_ep(int size, gfp_t gfp)
  212. {
  213. struct c4iw_ep_common *epc;
  214. epc = kzalloc(size, gfp);
  215. if (epc) {
  216. kref_init(&epc->kref);
  217. spin_lock_init(&epc->lock);
  218. init_waitqueue_head(&epc->waitq);
  219. }
  220. PDBG("%s alloc ep %p\n", __func__, epc);
  221. return epc;
  222. }
  223. void _c4iw_free_ep(struct kref *kref)
  224. {
  225. struct c4iw_ep *ep;
  226. ep = container_of(kref, struct c4iw_ep, com.kref);
  227. PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
  228. if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
  229. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  230. dst_release(ep->dst);
  231. cxgb4_l2t_release(ep->l2t);
  232. }
  233. kfree(ep);
  234. }
  235. static void release_ep_resources(struct c4iw_ep *ep)
  236. {
  237. set_bit(RELEASE_RESOURCES, &ep->com.flags);
  238. c4iw_put_ep(&ep->com);
  239. }
  240. static int status2errno(int status)
  241. {
  242. switch (status) {
  243. case CPL_ERR_NONE:
  244. return 0;
  245. case CPL_ERR_CONN_RESET:
  246. return -ECONNRESET;
  247. case CPL_ERR_ARP_MISS:
  248. return -EHOSTUNREACH;
  249. case CPL_ERR_CONN_TIMEDOUT:
  250. return -ETIMEDOUT;
  251. case CPL_ERR_TCAM_FULL:
  252. return -ENOMEM;
  253. case CPL_ERR_CONN_EXIST:
  254. return -EADDRINUSE;
  255. default:
  256. return -EIO;
  257. }
  258. }
  259. /*
  260. * Try and reuse skbs already allocated...
  261. */
  262. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
  263. {
  264. if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
  265. skb_trim(skb, 0);
  266. skb_get(skb);
  267. skb_reset_transport_header(skb);
  268. } else {
  269. skb = alloc_skb(len, gfp);
  270. }
  271. return skb;
  272. }
  273. static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
  274. __be32 peer_ip, __be16 local_port,
  275. __be16 peer_port, u8 tos)
  276. {
  277. struct rtable *rt;
  278. struct flowi fl = {
  279. .oif = 0,
  280. .nl_u = {
  281. .ip4_u = {
  282. .daddr = peer_ip,
  283. .saddr = local_ip,
  284. .tos = tos}
  285. },
  286. .proto = IPPROTO_TCP,
  287. .uli_u = {
  288. .ports = {
  289. .sport = local_port,
  290. .dport = peer_port}
  291. }
  292. };
  293. if (ip_route_output_flow(&init_net, &rt, &fl, NULL, 0))
  294. return NULL;
  295. return rt;
  296. }
  297. static void arp_failure_discard(void *handle, struct sk_buff *skb)
  298. {
  299. PDBG("%s c4iw_dev %p\n", __func__, handle);
  300. kfree_skb(skb);
  301. }
  302. /*
  303. * Handle an ARP failure for an active open.
  304. */
  305. static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
  306. {
  307. printk(KERN_ERR MOD "ARP failure duing connect\n");
  308. kfree_skb(skb);
  309. }
  310. /*
  311. * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
  312. * and send it along.
  313. */
  314. static void abort_arp_failure(void *handle, struct sk_buff *skb)
  315. {
  316. struct c4iw_rdev *rdev = handle;
  317. struct cpl_abort_req *req = cplhdr(skb);
  318. PDBG("%s rdev %p\n", __func__, rdev);
  319. req->cmd = CPL_ABORT_NO_RST;
  320. c4iw_ofld_send(rdev, skb);
  321. }
  322. static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
  323. {
  324. unsigned int flowclen = 80;
  325. struct fw_flowc_wr *flowc;
  326. int i;
  327. skb = get_skb(skb, flowclen, GFP_KERNEL);
  328. flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
  329. flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
  330. FW_FLOWC_WR_NPARAMS(8));
  331. flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
  332. 16)) | FW_WR_FLOWID(ep->hwtid));
  333. flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
  334. flowc->mnemval[0].val = cpu_to_be32(0);
  335. flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
  336. flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
  337. flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
  338. flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
  339. flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
  340. flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
  341. flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
  342. flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
  343. flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
  344. flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
  345. flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
  346. flowc->mnemval[6].val = cpu_to_be32(snd_win);
  347. flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
  348. flowc->mnemval[7].val = cpu_to_be32(ep->emss);
  349. /* Pad WR to 16 byte boundary */
  350. flowc->mnemval[8].mnemonic = 0;
  351. flowc->mnemval[8].val = 0;
  352. for (i = 0; i < 9; i++) {
  353. flowc->mnemval[i].r4[0] = 0;
  354. flowc->mnemval[i].r4[1] = 0;
  355. flowc->mnemval[i].r4[2] = 0;
  356. }
  357. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  358. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  359. }
  360. static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
  361. {
  362. struct cpl_close_con_req *req;
  363. struct sk_buff *skb;
  364. int wrlen = roundup(sizeof *req, 16);
  365. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  366. skb = get_skb(NULL, wrlen, gfp);
  367. if (!skb) {
  368. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  369. return -ENOMEM;
  370. }
  371. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  372. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  373. req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
  374. memset(req, 0, wrlen);
  375. INIT_TP_WR(req, ep->hwtid);
  376. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
  377. ep->hwtid));
  378. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  379. }
  380. static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  381. {
  382. struct cpl_abort_req *req;
  383. int wrlen = roundup(sizeof *req, 16);
  384. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  385. skb = get_skb(skb, wrlen, gfp);
  386. if (!skb) {
  387. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  388. __func__);
  389. return -ENOMEM;
  390. }
  391. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  392. t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
  393. req = (struct cpl_abort_req *) skb_put(skb, wrlen);
  394. memset(req, 0, wrlen);
  395. INIT_TP_WR(req, ep->hwtid);
  396. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
  397. req->cmd = CPL_ABORT_SEND_RST;
  398. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  399. }
  400. static int send_connect(struct c4iw_ep *ep)
  401. {
  402. struct cpl_act_open_req *req;
  403. struct sk_buff *skb;
  404. u64 opt0;
  405. u32 opt2;
  406. unsigned int mtu_idx;
  407. int wscale;
  408. int wrlen = roundup(sizeof *req, 16);
  409. PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
  410. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  411. if (!skb) {
  412. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  413. __func__);
  414. return -ENOMEM;
  415. }
  416. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->txq_idx);
  417. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  418. wscale = compute_wscale(rcv_win);
  419. opt0 = KEEP_ALIVE(1) |
  420. DELACK(1) |
  421. WND_SCALE(wscale) |
  422. MSS_IDX(mtu_idx) |
  423. L2T_IDX(ep->l2t->idx) |
  424. TX_CHAN(ep->tx_chan) |
  425. SMAC_SEL(ep->smac_idx) |
  426. DSCP(ep->tos) |
  427. RCV_BUFSIZ(rcv_win>>10);
  428. opt2 = RX_CHANNEL(0) |
  429. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  430. if (enable_tcp_timestamps)
  431. opt2 |= TSTAMPS_EN(1);
  432. if (enable_tcp_sack)
  433. opt2 |= SACK_EN(1);
  434. if (wscale && enable_tcp_window_scaling)
  435. opt2 |= WND_SCALE_EN(1);
  436. t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
  437. req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
  438. INIT_TP_WR(req, 0);
  439. OPCODE_TID(req) = cpu_to_be32(
  440. MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
  441. req->local_port = ep->com.local_addr.sin_port;
  442. req->peer_port = ep->com.remote_addr.sin_port;
  443. req->local_ip = ep->com.local_addr.sin_addr.s_addr;
  444. req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
  445. req->opt0 = cpu_to_be64(opt0);
  446. req->params = 0;
  447. req->opt2 = cpu_to_be32(opt2);
  448. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  449. }
  450. static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb)
  451. {
  452. int mpalen, wrlen;
  453. struct fw_ofld_tx_data_wr *req;
  454. struct mpa_message *mpa;
  455. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  456. BUG_ON(skb_cloned(skb));
  457. mpalen = sizeof(*mpa) + ep->plen;
  458. wrlen = roundup(mpalen + sizeof *req, 16);
  459. skb = get_skb(skb, wrlen, GFP_KERNEL);
  460. if (!skb) {
  461. connect_reply_upcall(ep, -ENOMEM);
  462. return;
  463. }
  464. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  465. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  466. memset(req, 0, wrlen);
  467. req->op_to_immdlen = cpu_to_be32(
  468. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  469. FW_WR_COMPL(1) |
  470. FW_WR_IMMDLEN(mpalen));
  471. req->flowid_len16 = cpu_to_be32(
  472. FW_WR_FLOWID(ep->hwtid) |
  473. FW_WR_LEN16(wrlen >> 4));
  474. req->plen = cpu_to_be32(mpalen);
  475. req->tunnel_to_proxy = cpu_to_be32(
  476. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  477. FW_OFLD_TX_DATA_WR_SHOVE(1));
  478. mpa = (struct mpa_message *)(req + 1);
  479. memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
  480. mpa->flags = (crc_enabled ? MPA_CRC : 0) |
  481. (markers_enabled ? MPA_MARKERS : 0);
  482. mpa->private_data_size = htons(ep->plen);
  483. mpa->revision = mpa_rev;
  484. if (ep->plen)
  485. memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen);
  486. /*
  487. * Reference the mpa skb. This ensures the data area
  488. * will remain in memory until the hw acks the tx.
  489. * Function fw4_ack() will deref it.
  490. */
  491. skb_get(skb);
  492. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  493. BUG_ON(ep->mpa_skb);
  494. ep->mpa_skb = skb;
  495. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  496. start_ep_timer(ep);
  497. state_set(&ep->com, MPA_REQ_SENT);
  498. ep->mpa_attr.initiator = 1;
  499. return;
  500. }
  501. static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
  502. {
  503. int mpalen, wrlen;
  504. struct fw_ofld_tx_data_wr *req;
  505. struct mpa_message *mpa;
  506. struct sk_buff *skb;
  507. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  508. mpalen = sizeof(*mpa) + plen;
  509. wrlen = roundup(mpalen + sizeof *req, 16);
  510. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  511. if (!skb) {
  512. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  513. return -ENOMEM;
  514. }
  515. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  516. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  517. memset(req, 0, wrlen);
  518. req->op_to_immdlen = cpu_to_be32(
  519. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  520. FW_WR_COMPL(1) |
  521. FW_WR_IMMDLEN(mpalen));
  522. req->flowid_len16 = cpu_to_be32(
  523. FW_WR_FLOWID(ep->hwtid) |
  524. FW_WR_LEN16(wrlen >> 4));
  525. req->plen = cpu_to_be32(mpalen);
  526. req->tunnel_to_proxy = cpu_to_be32(
  527. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  528. FW_OFLD_TX_DATA_WR_SHOVE(1));
  529. mpa = (struct mpa_message *)(req + 1);
  530. memset(mpa, 0, sizeof(*mpa));
  531. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  532. mpa->flags = MPA_REJECT;
  533. mpa->revision = mpa_rev;
  534. mpa->private_data_size = htons(plen);
  535. if (plen)
  536. memcpy(mpa->private_data, pdata, plen);
  537. /*
  538. * Reference the mpa skb again. This ensures the data area
  539. * will remain in memory until the hw acks the tx.
  540. * Function fw4_ack() will deref it.
  541. */
  542. skb_get(skb);
  543. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  544. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  545. BUG_ON(ep->mpa_skb);
  546. ep->mpa_skb = skb;
  547. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  548. }
  549. static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
  550. {
  551. int mpalen, wrlen;
  552. struct fw_ofld_tx_data_wr *req;
  553. struct mpa_message *mpa;
  554. struct sk_buff *skb;
  555. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  556. mpalen = sizeof(*mpa) + plen;
  557. wrlen = roundup(mpalen + sizeof *req, 16);
  558. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  559. if (!skb) {
  560. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  561. return -ENOMEM;
  562. }
  563. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  564. req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
  565. memset(req, 0, wrlen);
  566. req->op_to_immdlen = cpu_to_be32(
  567. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  568. FW_WR_COMPL(1) |
  569. FW_WR_IMMDLEN(mpalen));
  570. req->flowid_len16 = cpu_to_be32(
  571. FW_WR_FLOWID(ep->hwtid) |
  572. FW_WR_LEN16(wrlen >> 4));
  573. req->plen = cpu_to_be32(mpalen);
  574. req->tunnel_to_proxy = cpu_to_be32(
  575. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  576. FW_OFLD_TX_DATA_WR_SHOVE(1));
  577. mpa = (struct mpa_message *)(req + 1);
  578. memset(mpa, 0, sizeof(*mpa));
  579. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  580. mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
  581. (markers_enabled ? MPA_MARKERS : 0);
  582. mpa->revision = mpa_rev;
  583. mpa->private_data_size = htons(plen);
  584. if (plen)
  585. memcpy(mpa->private_data, pdata, plen);
  586. /*
  587. * Reference the mpa skb. This ensures the data area
  588. * will remain in memory until the hw acks the tx.
  589. * Function fw4_ack() will deref it.
  590. */
  591. skb_get(skb);
  592. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  593. ep->mpa_skb = skb;
  594. state_set(&ep->com, MPA_REP_SENT);
  595. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  596. }
  597. static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  598. {
  599. struct c4iw_ep *ep;
  600. struct cpl_act_establish *req = cplhdr(skb);
  601. unsigned int tid = GET_TID(req);
  602. unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
  603. struct tid_info *t = dev->rdev.lldi.tids;
  604. ep = lookup_atid(t, atid);
  605. PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
  606. be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
  607. dst_confirm(ep->dst);
  608. /* setup the hwtid for this connection */
  609. ep->hwtid = tid;
  610. cxgb4_insert_tid(t, ep, tid);
  611. ep->snd_seq = be32_to_cpu(req->snd_isn);
  612. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  613. set_emss(ep, ntohs(req->tcp_opt));
  614. /* dealloc the atid */
  615. cxgb4_free_atid(t, atid);
  616. /* start MPA negotiation */
  617. send_flowc(ep, NULL);
  618. send_mpa_req(ep, skb);
  619. return 0;
  620. }
  621. static void close_complete_upcall(struct c4iw_ep *ep)
  622. {
  623. struct iw_cm_event event;
  624. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  625. memset(&event, 0, sizeof(event));
  626. event.event = IW_CM_EVENT_CLOSE;
  627. if (ep->com.cm_id) {
  628. PDBG("close complete delivered ep %p cm_id %p tid %u\n",
  629. ep, ep->com.cm_id, ep->hwtid);
  630. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  631. ep->com.cm_id->rem_ref(ep->com.cm_id);
  632. ep->com.cm_id = NULL;
  633. ep->com.qp = NULL;
  634. }
  635. }
  636. static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  637. {
  638. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  639. close_complete_upcall(ep);
  640. state_set(&ep->com, ABORTING);
  641. return send_abort(ep, skb, gfp);
  642. }
  643. static void peer_close_upcall(struct c4iw_ep *ep)
  644. {
  645. struct iw_cm_event event;
  646. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  647. memset(&event, 0, sizeof(event));
  648. event.event = IW_CM_EVENT_DISCONNECT;
  649. if (ep->com.cm_id) {
  650. PDBG("peer close delivered ep %p cm_id %p tid %u\n",
  651. ep, ep->com.cm_id, ep->hwtid);
  652. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  653. }
  654. }
  655. static void peer_abort_upcall(struct c4iw_ep *ep)
  656. {
  657. struct iw_cm_event event;
  658. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  659. memset(&event, 0, sizeof(event));
  660. event.event = IW_CM_EVENT_CLOSE;
  661. event.status = -ECONNRESET;
  662. if (ep->com.cm_id) {
  663. PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
  664. ep->com.cm_id, ep->hwtid);
  665. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  666. ep->com.cm_id->rem_ref(ep->com.cm_id);
  667. ep->com.cm_id = NULL;
  668. ep->com.qp = NULL;
  669. }
  670. }
  671. static void connect_reply_upcall(struct c4iw_ep *ep, int status)
  672. {
  673. struct iw_cm_event event;
  674. PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
  675. memset(&event, 0, sizeof(event));
  676. event.event = IW_CM_EVENT_CONNECT_REPLY;
  677. event.status = status;
  678. event.local_addr = ep->com.local_addr;
  679. event.remote_addr = ep->com.remote_addr;
  680. if ((status == 0) || (status == -ECONNREFUSED)) {
  681. event.private_data_len = ep->plen;
  682. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  683. }
  684. PDBG("%s ep %p tid %u status %d\n", __func__, ep,
  685. ep->hwtid, status);
  686. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  687. if (status < 0) {
  688. ep->com.cm_id->rem_ref(ep->com.cm_id);
  689. ep->com.cm_id = NULL;
  690. ep->com.qp = NULL;
  691. }
  692. }
  693. static void connect_request_upcall(struct c4iw_ep *ep)
  694. {
  695. struct iw_cm_event event;
  696. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  697. memset(&event, 0, sizeof(event));
  698. event.event = IW_CM_EVENT_CONNECT_REQUEST;
  699. event.local_addr = ep->com.local_addr;
  700. event.remote_addr = ep->com.remote_addr;
  701. event.private_data_len = ep->plen;
  702. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  703. event.provider_data = ep;
  704. if (state_read(&ep->parent_ep->com) != DEAD) {
  705. c4iw_get_ep(&ep->com);
  706. ep->parent_ep->com.cm_id->event_handler(
  707. ep->parent_ep->com.cm_id,
  708. &event);
  709. }
  710. c4iw_put_ep(&ep->parent_ep->com);
  711. ep->parent_ep = NULL;
  712. }
  713. static void established_upcall(struct c4iw_ep *ep)
  714. {
  715. struct iw_cm_event event;
  716. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  717. memset(&event, 0, sizeof(event));
  718. event.event = IW_CM_EVENT_ESTABLISHED;
  719. if (ep->com.cm_id) {
  720. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  721. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  722. }
  723. }
  724. static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
  725. {
  726. struct cpl_rx_data_ack *req;
  727. struct sk_buff *skb;
  728. int wrlen = roundup(sizeof *req, 16);
  729. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  730. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  731. if (!skb) {
  732. printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
  733. return 0;
  734. }
  735. req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
  736. memset(req, 0, wrlen);
  737. INIT_TP_WR(req, ep->hwtid);
  738. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
  739. ep->hwtid));
  740. req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
  741. F_RX_DACK_CHANGE |
  742. V_RX_DACK_MODE(dack_mode));
  743. set_wr_txq(skb, CPL_PRIORITY_ACK, ep->txq_idx);
  744. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  745. return credits;
  746. }
  747. static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
  748. {
  749. struct mpa_message *mpa;
  750. u16 plen;
  751. struct c4iw_qp_attributes attrs;
  752. enum c4iw_qp_attr_mask mask;
  753. int err;
  754. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  755. /*
  756. * Stop mpa timer. If it expired, then the state has
  757. * changed and we bail since ep_timeout already aborted
  758. * the connection.
  759. */
  760. stop_ep_timer(ep);
  761. if (state_read(&ep->com) != MPA_REQ_SENT)
  762. return;
  763. /*
  764. * If we get more than the supported amount of private data
  765. * then we must fail this connection.
  766. */
  767. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  768. err = -EINVAL;
  769. goto err;
  770. }
  771. /*
  772. * copy the new data into our accumulation buffer.
  773. */
  774. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  775. skb->len);
  776. ep->mpa_pkt_len += skb->len;
  777. /*
  778. * if we don't even have the mpa message, then bail.
  779. */
  780. if (ep->mpa_pkt_len < sizeof(*mpa))
  781. return;
  782. mpa = (struct mpa_message *) ep->mpa_pkt;
  783. /* Validate MPA header. */
  784. if (mpa->revision != mpa_rev) {
  785. err = -EPROTO;
  786. goto err;
  787. }
  788. if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
  789. err = -EPROTO;
  790. goto err;
  791. }
  792. plen = ntohs(mpa->private_data_size);
  793. /*
  794. * Fail if there's too much private data.
  795. */
  796. if (plen > MPA_MAX_PRIVATE_DATA) {
  797. err = -EPROTO;
  798. goto err;
  799. }
  800. /*
  801. * If plen does not account for pkt size
  802. */
  803. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  804. err = -EPROTO;
  805. goto err;
  806. }
  807. ep->plen = (u8) plen;
  808. /*
  809. * If we don't have all the pdata yet, then bail.
  810. * We'll continue process when more data arrives.
  811. */
  812. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  813. return;
  814. if (mpa->flags & MPA_REJECT) {
  815. err = -ECONNREFUSED;
  816. goto err;
  817. }
  818. /*
  819. * If we get here we have accumulated the entire mpa
  820. * start reply message including private data. And
  821. * the MPA header is valid.
  822. */
  823. state_set(&ep->com, FPDU_MODE);
  824. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  825. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  826. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  827. ep->mpa_attr.version = mpa_rev;
  828. ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
  829. FW_RI_INIT_P2PTYPE_DISABLED;
  830. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  831. "xmit_marker_enabled=%d, version=%d\n", __func__,
  832. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  833. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
  834. attrs.mpa_attr = ep->mpa_attr;
  835. attrs.max_ird = ep->ird;
  836. attrs.max_ord = ep->ord;
  837. attrs.llp_stream_handle = ep;
  838. attrs.next_state = C4IW_QP_STATE_RTS;
  839. mask = C4IW_QP_ATTR_NEXT_STATE |
  840. C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
  841. C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
  842. /* bind QP and TID with INIT_WR */
  843. err = c4iw_modify_qp(ep->com.qp->rhp,
  844. ep->com.qp, mask, &attrs, 1);
  845. if (err)
  846. goto err;
  847. goto out;
  848. err:
  849. state_set(&ep->com, ABORTING);
  850. send_abort(ep, skb, GFP_KERNEL);
  851. out:
  852. connect_reply_upcall(ep, err);
  853. return;
  854. }
  855. static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
  856. {
  857. struct mpa_message *mpa;
  858. u16 plen;
  859. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  860. if (state_read(&ep->com) != MPA_REQ_WAIT)
  861. return;
  862. /*
  863. * If we get more than the supported amount of private data
  864. * then we must fail this connection.
  865. */
  866. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  867. stop_ep_timer(ep);
  868. abort_connection(ep, skb, GFP_KERNEL);
  869. return;
  870. }
  871. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  872. /*
  873. * Copy the new data into our accumulation buffer.
  874. */
  875. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  876. skb->len);
  877. ep->mpa_pkt_len += skb->len;
  878. /*
  879. * If we don't even have the mpa message, then bail.
  880. * We'll continue process when more data arrives.
  881. */
  882. if (ep->mpa_pkt_len < sizeof(*mpa))
  883. return;
  884. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  885. stop_ep_timer(ep);
  886. mpa = (struct mpa_message *) ep->mpa_pkt;
  887. /*
  888. * Validate MPA Header.
  889. */
  890. if (mpa->revision != mpa_rev) {
  891. abort_connection(ep, skb, GFP_KERNEL);
  892. return;
  893. }
  894. if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
  895. abort_connection(ep, skb, GFP_KERNEL);
  896. return;
  897. }
  898. plen = ntohs(mpa->private_data_size);
  899. /*
  900. * Fail if there's too much private data.
  901. */
  902. if (plen > MPA_MAX_PRIVATE_DATA) {
  903. abort_connection(ep, skb, GFP_KERNEL);
  904. return;
  905. }
  906. /*
  907. * If plen does not account for pkt size
  908. */
  909. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  910. abort_connection(ep, skb, GFP_KERNEL);
  911. return;
  912. }
  913. ep->plen = (u8) plen;
  914. /*
  915. * If we don't have all the pdata yet, then bail.
  916. */
  917. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  918. return;
  919. /*
  920. * If we get here we have accumulated the entire mpa
  921. * start reply message including private data.
  922. */
  923. ep->mpa_attr.initiator = 0;
  924. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  925. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  926. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  927. ep->mpa_attr.version = mpa_rev;
  928. ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
  929. FW_RI_INIT_P2PTYPE_DISABLED;
  930. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  931. "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
  932. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  933. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  934. ep->mpa_attr.p2p_type);
  935. state_set(&ep->com, MPA_REQ_RCVD);
  936. /* drive upcall */
  937. connect_request_upcall(ep);
  938. return;
  939. }
  940. static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
  941. {
  942. struct c4iw_ep *ep;
  943. struct cpl_rx_data *hdr = cplhdr(skb);
  944. unsigned int dlen = ntohs(hdr->len);
  945. unsigned int tid = GET_TID(hdr);
  946. struct tid_info *t = dev->rdev.lldi.tids;
  947. ep = lookup_tid(t, tid);
  948. PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
  949. skb_pull(skb, sizeof(*hdr));
  950. skb_trim(skb, dlen);
  951. ep->rcv_seq += dlen;
  952. BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
  953. /* update RX credits */
  954. update_rx_credits(ep, dlen);
  955. switch (state_read(&ep->com)) {
  956. case MPA_REQ_SENT:
  957. process_mpa_reply(ep, skb);
  958. break;
  959. case MPA_REQ_WAIT:
  960. process_mpa_request(ep, skb);
  961. break;
  962. case MPA_REP_SENT:
  963. break;
  964. default:
  965. printk(KERN_ERR MOD "%s Unexpected streaming data."
  966. " ep %p state %d tid %u\n",
  967. __func__, ep, state_read(&ep->com), ep->hwtid);
  968. /*
  969. * The ep will timeout and inform the ULP of the failure.
  970. * See ep_timeout().
  971. */
  972. break;
  973. }
  974. return 0;
  975. }
  976. static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  977. {
  978. struct c4iw_ep *ep;
  979. struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
  980. unsigned long flags;
  981. int release = 0;
  982. unsigned int tid = GET_TID(rpl);
  983. struct tid_info *t = dev->rdev.lldi.tids;
  984. ep = lookup_tid(t, tid);
  985. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  986. BUG_ON(!ep);
  987. spin_lock_irqsave(&ep->com.lock, flags);
  988. switch (ep->com.state) {
  989. case ABORTING:
  990. __state_set(&ep->com, DEAD);
  991. release = 1;
  992. break;
  993. default:
  994. printk(KERN_ERR "%s ep %p state %d\n",
  995. __func__, ep, ep->com.state);
  996. break;
  997. }
  998. spin_unlock_irqrestore(&ep->com.lock, flags);
  999. if (release)
  1000. release_ep_resources(ep);
  1001. return 0;
  1002. }
  1003. /*
  1004. * Return whether a failed active open has allocated a TID
  1005. */
  1006. static inline int act_open_has_tid(int status)
  1007. {
  1008. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1009. status != CPL_ERR_ARP_MISS;
  1010. }
  1011. static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1012. {
  1013. struct c4iw_ep *ep;
  1014. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1015. unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
  1016. ntohl(rpl->atid_status)));
  1017. struct tid_info *t = dev->rdev.lldi.tids;
  1018. int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
  1019. ep = lookup_atid(t, atid);
  1020. PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
  1021. status, status2errno(status));
  1022. if (status == CPL_ERR_RTX_NEG_ADVICE) {
  1023. printk(KERN_WARNING MOD "Connection problems for atid %u\n",
  1024. atid);
  1025. return 0;
  1026. }
  1027. connect_reply_upcall(ep, status2errno(status));
  1028. state_set(&ep->com, DEAD);
  1029. if (status && act_open_has_tid(status))
  1030. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
  1031. cxgb4_free_atid(t, atid);
  1032. dst_release(ep->dst);
  1033. cxgb4_l2t_release(ep->l2t);
  1034. c4iw_put_ep(&ep->com);
  1035. return 0;
  1036. }
  1037. static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1038. {
  1039. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1040. struct tid_info *t = dev->rdev.lldi.tids;
  1041. unsigned int stid = GET_TID(rpl);
  1042. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1043. if (!ep) {
  1044. printk(KERN_ERR MOD "stid %d lookup failure!\n", stid);
  1045. return 0;
  1046. }
  1047. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1048. rpl->status, status2errno(rpl->status));
  1049. ep->com.rpl_err = status2errno(rpl->status);
  1050. ep->com.rpl_done = 1;
  1051. wake_up(&ep->com.waitq);
  1052. return 0;
  1053. }
  1054. static int listen_stop(struct c4iw_listen_ep *ep)
  1055. {
  1056. struct sk_buff *skb;
  1057. struct cpl_close_listsvr_req *req;
  1058. PDBG("%s ep %p\n", __func__, ep);
  1059. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1060. if (!skb) {
  1061. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  1062. return -ENOMEM;
  1063. }
  1064. req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
  1065. INIT_TP_WR(req, 0);
  1066. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
  1067. ep->stid));
  1068. req->reply_ctrl = cpu_to_be16(
  1069. QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
  1070. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  1071. return c4iw_ofld_send(&ep->com.dev->rdev, skb);
  1072. }
  1073. static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1074. {
  1075. struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
  1076. struct tid_info *t = dev->rdev.lldi.tids;
  1077. unsigned int stid = GET_TID(rpl);
  1078. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1079. PDBG("%s ep %p\n", __func__, ep);
  1080. ep->com.rpl_err = status2errno(rpl->status);
  1081. ep->com.rpl_done = 1;
  1082. wake_up(&ep->com.waitq);
  1083. return 0;
  1084. }
  1085. static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
  1086. struct cpl_pass_accept_req *req)
  1087. {
  1088. struct cpl_pass_accept_rpl *rpl;
  1089. unsigned int mtu_idx;
  1090. u64 opt0;
  1091. u32 opt2;
  1092. int wscale;
  1093. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1094. BUG_ON(skb_cloned(skb));
  1095. skb_trim(skb, sizeof(*rpl));
  1096. skb_get(skb);
  1097. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1098. wscale = compute_wscale(rcv_win);
  1099. opt0 = KEEP_ALIVE(1) |
  1100. DELACK(1) |
  1101. WND_SCALE(wscale) |
  1102. MSS_IDX(mtu_idx) |
  1103. L2T_IDX(ep->l2t->idx) |
  1104. TX_CHAN(ep->tx_chan) |
  1105. SMAC_SEL(ep->smac_idx) |
  1106. DSCP(ep->tos) |
  1107. RCV_BUFSIZ(rcv_win>>10);
  1108. opt2 = RX_CHANNEL(0) |
  1109. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  1110. if (enable_tcp_timestamps && req->tcpopt.tstamp)
  1111. opt2 |= TSTAMPS_EN(1);
  1112. if (enable_tcp_sack && req->tcpopt.sack)
  1113. opt2 |= SACK_EN(1);
  1114. if (wscale && enable_tcp_window_scaling)
  1115. opt2 |= WND_SCALE_EN(1);
  1116. rpl = cplhdr(skb);
  1117. INIT_TP_WR(rpl, ep->hwtid);
  1118. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1119. ep->hwtid));
  1120. rpl->opt0 = cpu_to_be64(opt0);
  1121. rpl->opt2 = cpu_to_be32(opt2);
  1122. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->txq_idx);
  1123. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1124. return;
  1125. }
  1126. static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
  1127. struct sk_buff *skb)
  1128. {
  1129. PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
  1130. peer_ip);
  1131. BUG_ON(skb_cloned(skb));
  1132. skb_trim(skb, sizeof(struct cpl_tid_release));
  1133. skb_get(skb);
  1134. release_tid(&dev->rdev, hwtid, skb);
  1135. return;
  1136. }
  1137. static void get_4tuple(struct cpl_pass_accept_req *req,
  1138. __be32 *local_ip, __be32 *peer_ip,
  1139. __be16 *local_port, __be16 *peer_port)
  1140. {
  1141. int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
  1142. int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
  1143. struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
  1144. struct tcphdr *tcp = (struct tcphdr *)
  1145. ((u8 *)(req + 1) + eth_len + ip_len);
  1146. PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
  1147. ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
  1148. ntohs(tcp->dest));
  1149. *peer_ip = ip->saddr;
  1150. *local_ip = ip->daddr;
  1151. *peer_port = tcp->source;
  1152. *local_port = tcp->dest;
  1153. return;
  1154. }
  1155. static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
  1156. {
  1157. struct c4iw_ep *child_ep, *parent_ep;
  1158. struct cpl_pass_accept_req *req = cplhdr(skb);
  1159. unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
  1160. struct tid_info *t = dev->rdev.lldi.tids;
  1161. unsigned int hwtid = GET_TID(req);
  1162. struct dst_entry *dst;
  1163. struct l2t_entry *l2t;
  1164. struct rtable *rt;
  1165. __be32 local_ip, peer_ip;
  1166. __be16 local_port, peer_port;
  1167. struct net_device *pdev;
  1168. u32 tx_chan, smac_idx;
  1169. u16 rss_qid;
  1170. u32 mtu;
  1171. int step;
  1172. int txq_idx;
  1173. parent_ep = lookup_stid(t, stid);
  1174. PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
  1175. get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
  1176. if (state_read(&parent_ep->com) != LISTEN) {
  1177. printk(KERN_ERR "%s - listening ep not in LISTEN\n",
  1178. __func__);
  1179. goto reject;
  1180. }
  1181. /* Find output route */
  1182. rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
  1183. GET_POPEN_TOS(ntohl(req->tos_stid)));
  1184. if (!rt) {
  1185. printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
  1186. __func__);
  1187. goto reject;
  1188. }
  1189. dst = &rt->u.dst;
  1190. if (dst->neighbour->dev->flags & IFF_LOOPBACK) {
  1191. pdev = ip_dev_find(&init_net, peer_ip);
  1192. BUG_ON(!pdev);
  1193. l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour,
  1194. pdev, 0);
  1195. mtu = pdev->mtu;
  1196. tx_chan = cxgb4_port_chan(pdev);
  1197. smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1198. step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
  1199. txq_idx = cxgb4_port_idx(pdev) * step;
  1200. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  1201. rss_qid = dev->rdev.lldi.rxq_ids[cxgb4_port_idx(pdev) * step];
  1202. dev_put(pdev);
  1203. } else {
  1204. l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour,
  1205. dst->neighbour->dev, 0);
  1206. mtu = dst_mtu(dst);
  1207. tx_chan = cxgb4_port_chan(dst->neighbour->dev);
  1208. smac_idx = (cxgb4_port_viid(dst->neighbour->dev) & 0x7F) << 1;
  1209. step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
  1210. txq_idx = cxgb4_port_idx(dst->neighbour->dev) * step;
  1211. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  1212. rss_qid = dev->rdev.lldi.rxq_ids[
  1213. cxgb4_port_idx(dst->neighbour->dev) * step];
  1214. }
  1215. if (!l2t) {
  1216. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1217. __func__);
  1218. dst_release(dst);
  1219. goto reject;
  1220. }
  1221. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1222. if (!child_ep) {
  1223. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1224. __func__);
  1225. cxgb4_l2t_release(l2t);
  1226. dst_release(dst);
  1227. goto reject;
  1228. }
  1229. state_set(&child_ep->com, CONNECTING);
  1230. child_ep->com.dev = dev;
  1231. child_ep->com.cm_id = NULL;
  1232. child_ep->com.local_addr.sin_family = PF_INET;
  1233. child_ep->com.local_addr.sin_port = local_port;
  1234. child_ep->com.local_addr.sin_addr.s_addr = local_ip;
  1235. child_ep->com.remote_addr.sin_family = PF_INET;
  1236. child_ep->com.remote_addr.sin_port = peer_port;
  1237. child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
  1238. c4iw_get_ep(&parent_ep->com);
  1239. child_ep->parent_ep = parent_ep;
  1240. child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
  1241. child_ep->l2t = l2t;
  1242. child_ep->dst = dst;
  1243. child_ep->hwtid = hwtid;
  1244. child_ep->tx_chan = tx_chan;
  1245. child_ep->smac_idx = smac_idx;
  1246. child_ep->rss_qid = rss_qid;
  1247. child_ep->mtu = mtu;
  1248. child_ep->txq_idx = txq_idx;
  1249. PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
  1250. tx_chan, smac_idx, rss_qid);
  1251. init_timer(&child_ep->timer);
  1252. cxgb4_insert_tid(t, child_ep, hwtid);
  1253. accept_cr(child_ep, peer_ip, skb, req);
  1254. goto out;
  1255. reject:
  1256. reject_cr(dev, hwtid, peer_ip, skb);
  1257. out:
  1258. return 0;
  1259. }
  1260. static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  1261. {
  1262. struct c4iw_ep *ep;
  1263. struct cpl_pass_establish *req = cplhdr(skb);
  1264. struct tid_info *t = dev->rdev.lldi.tids;
  1265. unsigned int tid = GET_TID(req);
  1266. ep = lookup_tid(t, tid);
  1267. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1268. ep->snd_seq = be32_to_cpu(req->snd_isn);
  1269. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  1270. set_emss(ep, ntohs(req->tcp_opt));
  1271. dst_confirm(ep->dst);
  1272. state_set(&ep->com, MPA_REQ_WAIT);
  1273. start_ep_timer(ep);
  1274. send_flowc(ep, skb);
  1275. return 0;
  1276. }
  1277. static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
  1278. {
  1279. struct cpl_peer_close *hdr = cplhdr(skb);
  1280. struct c4iw_ep *ep;
  1281. struct c4iw_qp_attributes attrs;
  1282. unsigned long flags;
  1283. int disconnect = 1;
  1284. int release = 0;
  1285. int closing = 0;
  1286. struct tid_info *t = dev->rdev.lldi.tids;
  1287. unsigned int tid = GET_TID(hdr);
  1288. int start_timer = 0;
  1289. int stop_timer = 0;
  1290. ep = lookup_tid(t, tid);
  1291. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1292. dst_confirm(ep->dst);
  1293. spin_lock_irqsave(&ep->com.lock, flags);
  1294. switch (ep->com.state) {
  1295. case MPA_REQ_WAIT:
  1296. __state_set(&ep->com, CLOSING);
  1297. break;
  1298. case MPA_REQ_SENT:
  1299. __state_set(&ep->com, CLOSING);
  1300. connect_reply_upcall(ep, -ECONNRESET);
  1301. break;
  1302. case MPA_REQ_RCVD:
  1303. /*
  1304. * We're gonna mark this puppy DEAD, but keep
  1305. * the reference on it until the ULP accepts or
  1306. * rejects the CR. Also wake up anyone waiting
  1307. * in rdma connection migration (see c4iw_accept_cr()).
  1308. */
  1309. __state_set(&ep->com, CLOSING);
  1310. ep->com.rpl_done = 1;
  1311. ep->com.rpl_err = -ECONNRESET;
  1312. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1313. wake_up(&ep->com.waitq);
  1314. break;
  1315. case MPA_REP_SENT:
  1316. __state_set(&ep->com, CLOSING);
  1317. ep->com.rpl_done = 1;
  1318. ep->com.rpl_err = -ECONNRESET;
  1319. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1320. wake_up(&ep->com.waitq);
  1321. break;
  1322. case FPDU_MODE:
  1323. start_timer = 1;
  1324. __state_set(&ep->com, CLOSING);
  1325. closing = 1;
  1326. peer_close_upcall(ep);
  1327. break;
  1328. case ABORTING:
  1329. disconnect = 0;
  1330. break;
  1331. case CLOSING:
  1332. __state_set(&ep->com, MORIBUND);
  1333. disconnect = 0;
  1334. break;
  1335. case MORIBUND:
  1336. stop_timer = 1;
  1337. if (ep->com.cm_id && ep->com.qp) {
  1338. attrs.next_state = C4IW_QP_STATE_IDLE;
  1339. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1340. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1341. }
  1342. close_complete_upcall(ep);
  1343. __state_set(&ep->com, DEAD);
  1344. release = 1;
  1345. disconnect = 0;
  1346. break;
  1347. case DEAD:
  1348. disconnect = 0;
  1349. break;
  1350. default:
  1351. BUG_ON(1);
  1352. }
  1353. spin_unlock_irqrestore(&ep->com.lock, flags);
  1354. if (closing) {
  1355. attrs.next_state = C4IW_QP_STATE_CLOSING;
  1356. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1357. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1358. }
  1359. if (start_timer)
  1360. start_ep_timer(ep);
  1361. if (stop_timer)
  1362. stop_ep_timer(ep);
  1363. if (disconnect)
  1364. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1365. if (release)
  1366. release_ep_resources(ep);
  1367. return 0;
  1368. }
  1369. /*
  1370. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  1371. */
  1372. static int is_neg_adv_abort(unsigned int status)
  1373. {
  1374. return status == CPL_ERR_RTX_NEG_ADVICE ||
  1375. status == CPL_ERR_PERSIST_NEG_ADVICE;
  1376. }
  1377. static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
  1378. {
  1379. struct cpl_abort_req_rss *req = cplhdr(skb);
  1380. struct c4iw_ep *ep;
  1381. struct cpl_abort_rpl *rpl;
  1382. struct sk_buff *rpl_skb;
  1383. struct c4iw_qp_attributes attrs;
  1384. int ret;
  1385. int release = 0;
  1386. unsigned long flags;
  1387. struct tid_info *t = dev->rdev.lldi.tids;
  1388. unsigned int tid = GET_TID(req);
  1389. int stop_timer = 0;
  1390. ep = lookup_tid(t, tid);
  1391. if (is_neg_adv_abort(req->status)) {
  1392. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  1393. ep->hwtid);
  1394. return 0;
  1395. }
  1396. spin_lock_irqsave(&ep->com.lock, flags);
  1397. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  1398. ep->com.state);
  1399. switch (ep->com.state) {
  1400. case CONNECTING:
  1401. break;
  1402. case MPA_REQ_WAIT:
  1403. stop_timer = 1;
  1404. break;
  1405. case MPA_REQ_SENT:
  1406. stop_timer = 1;
  1407. connect_reply_upcall(ep, -ECONNRESET);
  1408. break;
  1409. case MPA_REP_SENT:
  1410. ep->com.rpl_done = 1;
  1411. ep->com.rpl_err = -ECONNRESET;
  1412. PDBG("waking up ep %p\n", ep);
  1413. wake_up(&ep->com.waitq);
  1414. break;
  1415. case MPA_REQ_RCVD:
  1416. /*
  1417. * We're gonna mark this puppy DEAD, but keep
  1418. * the reference on it until the ULP accepts or
  1419. * rejects the CR. Also wake up anyone waiting
  1420. * in rdma connection migration (see c4iw_accept_cr()).
  1421. */
  1422. ep->com.rpl_done = 1;
  1423. ep->com.rpl_err = -ECONNRESET;
  1424. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1425. wake_up(&ep->com.waitq);
  1426. break;
  1427. case MORIBUND:
  1428. case CLOSING:
  1429. stop_timer = 1;
  1430. /*FALLTHROUGH*/
  1431. case FPDU_MODE:
  1432. if (ep->com.cm_id && ep->com.qp) {
  1433. attrs.next_state = C4IW_QP_STATE_ERROR;
  1434. ret = c4iw_modify_qp(ep->com.qp->rhp,
  1435. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  1436. &attrs, 1);
  1437. if (ret)
  1438. printk(KERN_ERR MOD
  1439. "%s - qp <- error failed!\n",
  1440. __func__);
  1441. }
  1442. peer_abort_upcall(ep);
  1443. break;
  1444. case ABORTING:
  1445. break;
  1446. case DEAD:
  1447. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1448. spin_unlock_irqrestore(&ep->com.lock, flags);
  1449. return 0;
  1450. default:
  1451. BUG_ON(1);
  1452. break;
  1453. }
  1454. dst_confirm(ep->dst);
  1455. if (ep->com.state != ABORTING) {
  1456. __state_set(&ep->com, DEAD);
  1457. release = 1;
  1458. }
  1459. spin_unlock_irqrestore(&ep->com.lock, flags);
  1460. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1461. if (!rpl_skb) {
  1462. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  1463. __func__);
  1464. release = 1;
  1465. goto out;
  1466. }
  1467. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  1468. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  1469. INIT_TP_WR(rpl, ep->hwtid);
  1470. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  1471. rpl->cmd = CPL_ABORT_NO_RST;
  1472. c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
  1473. out:
  1474. if (stop_timer)
  1475. stop_ep_timer(ep);
  1476. if (release)
  1477. release_ep_resources(ep);
  1478. return 0;
  1479. }
  1480. static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1481. {
  1482. struct c4iw_ep *ep;
  1483. struct c4iw_qp_attributes attrs;
  1484. struct cpl_close_con_rpl *rpl = cplhdr(skb);
  1485. unsigned long flags;
  1486. int release = 0;
  1487. struct tid_info *t = dev->rdev.lldi.tids;
  1488. unsigned int tid = GET_TID(rpl);
  1489. int stop_timer = 0;
  1490. ep = lookup_tid(t, tid);
  1491. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1492. BUG_ON(!ep);
  1493. /* The cm_id may be null if we failed to connect */
  1494. spin_lock_irqsave(&ep->com.lock, flags);
  1495. switch (ep->com.state) {
  1496. case CLOSING:
  1497. __state_set(&ep->com, MORIBUND);
  1498. break;
  1499. case MORIBUND:
  1500. stop_timer = 1;
  1501. if ((ep->com.cm_id) && (ep->com.qp)) {
  1502. attrs.next_state = C4IW_QP_STATE_IDLE;
  1503. c4iw_modify_qp(ep->com.qp->rhp,
  1504. ep->com.qp,
  1505. C4IW_QP_ATTR_NEXT_STATE,
  1506. &attrs, 1);
  1507. }
  1508. close_complete_upcall(ep);
  1509. __state_set(&ep->com, DEAD);
  1510. release = 1;
  1511. break;
  1512. case ABORTING:
  1513. case DEAD:
  1514. break;
  1515. default:
  1516. BUG_ON(1);
  1517. break;
  1518. }
  1519. spin_unlock_irqrestore(&ep->com.lock, flags);
  1520. if (stop_timer)
  1521. stop_ep_timer(ep);
  1522. if (release)
  1523. release_ep_resources(ep);
  1524. return 0;
  1525. }
  1526. static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
  1527. {
  1528. struct c4iw_ep *ep;
  1529. struct cpl_rdma_terminate *term = cplhdr(skb);
  1530. struct tid_info *t = dev->rdev.lldi.tids;
  1531. unsigned int tid = GET_TID(term);
  1532. ep = lookup_tid(t, tid);
  1533. if (state_read(&ep->com) != FPDU_MODE)
  1534. return 0;
  1535. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1536. skb_pull(skb, sizeof *term);
  1537. PDBG("%s saving %d bytes of term msg\n", __func__, skb->len);
  1538. skb_copy_from_linear_data(skb, ep->com.qp->attr.terminate_buffer,
  1539. skb->len);
  1540. ep->com.qp->attr.terminate_msg_len = skb->len;
  1541. ep->com.qp->attr.is_terminate_local = 0;
  1542. return 0;
  1543. }
  1544. /*
  1545. * Upcall from the adapter indicating data has been transmitted.
  1546. * For us its just the single MPA request or reply. We can now free
  1547. * the skb holding the mpa message.
  1548. */
  1549. static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
  1550. {
  1551. struct c4iw_ep *ep;
  1552. struct cpl_fw4_ack *hdr = cplhdr(skb);
  1553. u8 credits = hdr->credits;
  1554. unsigned int tid = GET_TID(hdr);
  1555. struct tid_info *t = dev->rdev.lldi.tids;
  1556. ep = lookup_tid(t, tid);
  1557. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  1558. if (credits == 0) {
  1559. PDBG(KERN_ERR "%s 0 credit ack ep %p tid %u state %u\n",
  1560. __func__, ep, ep->hwtid, state_read(&ep->com));
  1561. return 0;
  1562. }
  1563. dst_confirm(ep->dst);
  1564. if (ep->mpa_skb) {
  1565. PDBG("%s last streaming msg ack ep %p tid %u state %u "
  1566. "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
  1567. state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
  1568. kfree_skb(ep->mpa_skb);
  1569. ep->mpa_skb = NULL;
  1570. }
  1571. return 0;
  1572. }
  1573. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  1574. {
  1575. int err;
  1576. struct c4iw_ep *ep = to_ep(cm_id);
  1577. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1578. if (state_read(&ep->com) == DEAD) {
  1579. c4iw_put_ep(&ep->com);
  1580. return -ECONNRESET;
  1581. }
  1582. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1583. if (mpa_rev == 0)
  1584. abort_connection(ep, NULL, GFP_KERNEL);
  1585. else {
  1586. err = send_mpa_reject(ep, pdata, pdata_len);
  1587. err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1588. }
  1589. c4iw_put_ep(&ep->com);
  1590. return 0;
  1591. }
  1592. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1593. {
  1594. int err;
  1595. struct c4iw_qp_attributes attrs;
  1596. enum c4iw_qp_attr_mask mask;
  1597. struct c4iw_ep *ep = to_ep(cm_id);
  1598. struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
  1599. struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
  1600. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1601. if (state_read(&ep->com) == DEAD) {
  1602. err = -ECONNRESET;
  1603. goto err;
  1604. }
  1605. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1606. BUG_ON(!qp);
  1607. if ((conn_param->ord > c4iw_max_read_depth) ||
  1608. (conn_param->ird > c4iw_max_read_depth)) {
  1609. abort_connection(ep, NULL, GFP_KERNEL);
  1610. err = -EINVAL;
  1611. goto err;
  1612. }
  1613. cm_id->add_ref(cm_id);
  1614. ep->com.cm_id = cm_id;
  1615. ep->com.qp = qp;
  1616. ep->ird = conn_param->ird;
  1617. ep->ord = conn_param->ord;
  1618. if (peer2peer && ep->ird == 0)
  1619. ep->ird = 1;
  1620. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  1621. /* bind QP to EP and move to RTS */
  1622. attrs.mpa_attr = ep->mpa_attr;
  1623. attrs.max_ird = ep->ird;
  1624. attrs.max_ord = ep->ord;
  1625. attrs.llp_stream_handle = ep;
  1626. attrs.next_state = C4IW_QP_STATE_RTS;
  1627. /* bind QP and TID with INIT_WR */
  1628. mask = C4IW_QP_ATTR_NEXT_STATE |
  1629. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  1630. C4IW_QP_ATTR_MPA_ATTR |
  1631. C4IW_QP_ATTR_MAX_IRD |
  1632. C4IW_QP_ATTR_MAX_ORD;
  1633. err = c4iw_modify_qp(ep->com.qp->rhp,
  1634. ep->com.qp, mask, &attrs, 1);
  1635. if (err)
  1636. goto err1;
  1637. err = send_mpa_reply(ep, conn_param->private_data,
  1638. conn_param->private_data_len);
  1639. if (err)
  1640. goto err1;
  1641. state_set(&ep->com, FPDU_MODE);
  1642. established_upcall(ep);
  1643. c4iw_put_ep(&ep->com);
  1644. return 0;
  1645. err1:
  1646. ep->com.cm_id = NULL;
  1647. ep->com.qp = NULL;
  1648. cm_id->rem_ref(cm_id);
  1649. err:
  1650. c4iw_put_ep(&ep->com);
  1651. return err;
  1652. }
  1653. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1654. {
  1655. int err = 0;
  1656. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  1657. struct c4iw_ep *ep;
  1658. struct rtable *rt;
  1659. struct net_device *pdev;
  1660. int step;
  1661. if ((conn_param->ord > c4iw_max_read_depth) ||
  1662. (conn_param->ird > c4iw_max_read_depth)) {
  1663. err = -EINVAL;
  1664. goto out;
  1665. }
  1666. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1667. if (!ep) {
  1668. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1669. err = -ENOMEM;
  1670. goto out;
  1671. }
  1672. init_timer(&ep->timer);
  1673. ep->plen = conn_param->private_data_len;
  1674. if (ep->plen)
  1675. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  1676. conn_param->private_data, ep->plen);
  1677. ep->ird = conn_param->ird;
  1678. ep->ord = conn_param->ord;
  1679. if (peer2peer && ep->ord == 0)
  1680. ep->ord = 1;
  1681. cm_id->add_ref(cm_id);
  1682. ep->com.dev = dev;
  1683. ep->com.cm_id = cm_id;
  1684. ep->com.qp = get_qhp(dev, conn_param->qpn);
  1685. BUG_ON(!ep->com.qp);
  1686. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  1687. ep->com.qp, cm_id);
  1688. /*
  1689. * Allocate an active TID to initiate a TCP connection.
  1690. */
  1691. ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
  1692. if (ep->atid == -1) {
  1693. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1694. err = -ENOMEM;
  1695. goto fail2;
  1696. }
  1697. PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
  1698. ntohl(cm_id->local_addr.sin_addr.s_addr),
  1699. ntohs(cm_id->local_addr.sin_port),
  1700. ntohl(cm_id->remote_addr.sin_addr.s_addr),
  1701. ntohs(cm_id->remote_addr.sin_port));
  1702. /* find a route */
  1703. rt = find_route(dev,
  1704. cm_id->local_addr.sin_addr.s_addr,
  1705. cm_id->remote_addr.sin_addr.s_addr,
  1706. cm_id->local_addr.sin_port,
  1707. cm_id->remote_addr.sin_port, 0);
  1708. if (!rt) {
  1709. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  1710. err = -EHOSTUNREACH;
  1711. goto fail3;
  1712. }
  1713. ep->dst = &rt->u.dst;
  1714. /* get a l2t entry */
  1715. if (ep->dst->neighbour->dev->flags & IFF_LOOPBACK) {
  1716. PDBG("%s LOOPBACK\n", __func__);
  1717. pdev = ip_dev_find(&init_net,
  1718. cm_id->remote_addr.sin_addr.s_addr);
  1719. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  1720. ep->dst->neighbour,
  1721. pdev, 0);
  1722. ep->mtu = pdev->mtu;
  1723. ep->tx_chan = cxgb4_port_chan(pdev);
  1724. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1725. step = ep->com.dev->rdev.lldi.ntxq /
  1726. ep->com.dev->rdev.lldi.nchan;
  1727. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1728. step = ep->com.dev->rdev.lldi.nrxq /
  1729. ep->com.dev->rdev.lldi.nchan;
  1730. ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
  1731. cxgb4_port_idx(pdev) * step];
  1732. dev_put(pdev);
  1733. } else {
  1734. ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
  1735. ep->dst->neighbour,
  1736. ep->dst->neighbour->dev, 0);
  1737. ep->mtu = dst_mtu(ep->dst);
  1738. ep->tx_chan = cxgb4_port_chan(ep->dst->neighbour->dev);
  1739. ep->smac_idx = (cxgb4_port_viid(ep->dst->neighbour->dev) &
  1740. 0x7F) << 1;
  1741. step = ep->com.dev->rdev.lldi.ntxq /
  1742. ep->com.dev->rdev.lldi.nchan;
  1743. ep->txq_idx = cxgb4_port_idx(ep->dst->neighbour->dev) * step;
  1744. step = ep->com.dev->rdev.lldi.nrxq /
  1745. ep->com.dev->rdev.lldi.nchan;
  1746. ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
  1747. cxgb4_port_idx(ep->dst->neighbour->dev) * step];
  1748. }
  1749. if (!ep->l2t) {
  1750. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  1751. err = -ENOMEM;
  1752. goto fail4;
  1753. }
  1754. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  1755. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  1756. ep->l2t->idx);
  1757. state_set(&ep->com, CONNECTING);
  1758. ep->tos = 0;
  1759. ep->com.local_addr = cm_id->local_addr;
  1760. ep->com.remote_addr = cm_id->remote_addr;
  1761. /* send connect request to rnic */
  1762. err = send_connect(ep);
  1763. if (!err)
  1764. goto out;
  1765. cxgb4_l2t_release(ep->l2t);
  1766. fail4:
  1767. dst_release(ep->dst);
  1768. fail3:
  1769. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  1770. fail2:
  1771. cm_id->rem_ref(cm_id);
  1772. c4iw_put_ep(&ep->com);
  1773. out:
  1774. return err;
  1775. }
  1776. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
  1777. {
  1778. int err = 0;
  1779. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  1780. struct c4iw_listen_ep *ep;
  1781. might_sleep();
  1782. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1783. if (!ep) {
  1784. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1785. err = -ENOMEM;
  1786. goto fail1;
  1787. }
  1788. PDBG("%s ep %p\n", __func__, ep);
  1789. cm_id->add_ref(cm_id);
  1790. ep->com.cm_id = cm_id;
  1791. ep->com.dev = dev;
  1792. ep->backlog = backlog;
  1793. ep->com.local_addr = cm_id->local_addr;
  1794. /*
  1795. * Allocate a server TID.
  1796. */
  1797. ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
  1798. if (ep->stid == -1) {
  1799. printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
  1800. err = -ENOMEM;
  1801. goto fail2;
  1802. }
  1803. state_set(&ep->com, LISTEN);
  1804. err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid,
  1805. ep->com.local_addr.sin_addr.s_addr,
  1806. ep->com.local_addr.sin_port,
  1807. ep->com.dev->rdev.lldi.rxq_ids[0]);
  1808. if (err)
  1809. goto fail3;
  1810. /* wait for pass_open_rpl */
  1811. wait_event(ep->com.waitq, ep->com.rpl_done);
  1812. err = ep->com.rpl_err;
  1813. if (!err) {
  1814. cm_id->provider_data = ep;
  1815. goto out;
  1816. }
  1817. fail3:
  1818. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  1819. fail2:
  1820. cm_id->rem_ref(cm_id);
  1821. c4iw_put_ep(&ep->com);
  1822. fail1:
  1823. out:
  1824. return err;
  1825. }
  1826. int c4iw_destroy_listen(struct iw_cm_id *cm_id)
  1827. {
  1828. int err;
  1829. struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
  1830. PDBG("%s ep %p\n", __func__, ep);
  1831. might_sleep();
  1832. state_set(&ep->com, DEAD);
  1833. ep->com.rpl_done = 0;
  1834. ep->com.rpl_err = 0;
  1835. err = listen_stop(ep);
  1836. if (err)
  1837. goto done;
  1838. wait_event(ep->com.waitq, ep->com.rpl_done);
  1839. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  1840. done:
  1841. err = ep->com.rpl_err;
  1842. cm_id->rem_ref(cm_id);
  1843. c4iw_put_ep(&ep->com);
  1844. return err;
  1845. }
  1846. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
  1847. {
  1848. int ret = 0;
  1849. unsigned long flags;
  1850. int close = 0;
  1851. int fatal = 0;
  1852. struct c4iw_rdev *rdev;
  1853. int start_timer = 0;
  1854. int stop_timer = 0;
  1855. spin_lock_irqsave(&ep->com.lock, flags);
  1856. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  1857. states[ep->com.state], abrupt);
  1858. rdev = &ep->com.dev->rdev;
  1859. if (c4iw_fatal_error(rdev)) {
  1860. fatal = 1;
  1861. close_complete_upcall(ep);
  1862. ep->com.state = DEAD;
  1863. }
  1864. switch (ep->com.state) {
  1865. case MPA_REQ_WAIT:
  1866. case MPA_REQ_SENT:
  1867. case MPA_REQ_RCVD:
  1868. case MPA_REP_SENT:
  1869. case FPDU_MODE:
  1870. close = 1;
  1871. if (abrupt)
  1872. ep->com.state = ABORTING;
  1873. else {
  1874. ep->com.state = CLOSING;
  1875. start_timer = 1;
  1876. }
  1877. set_bit(CLOSE_SENT, &ep->com.flags);
  1878. break;
  1879. case CLOSING:
  1880. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  1881. close = 1;
  1882. if (abrupt) {
  1883. stop_timer = 1;
  1884. ep->com.state = ABORTING;
  1885. } else
  1886. ep->com.state = MORIBUND;
  1887. }
  1888. break;
  1889. case MORIBUND:
  1890. case ABORTING:
  1891. case DEAD:
  1892. PDBG("%s ignoring disconnect ep %p state %u\n",
  1893. __func__, ep, ep->com.state);
  1894. break;
  1895. default:
  1896. BUG();
  1897. break;
  1898. }
  1899. spin_unlock_irqrestore(&ep->com.lock, flags);
  1900. if (start_timer)
  1901. start_ep_timer(ep);
  1902. if (stop_timer)
  1903. stop_ep_timer(ep);
  1904. if (close) {
  1905. if (abrupt)
  1906. ret = abort_connection(ep, NULL, gfp);
  1907. else
  1908. ret = send_halfclose(ep, gfp);
  1909. if (ret)
  1910. fatal = 1;
  1911. }
  1912. if (fatal)
  1913. release_ep_resources(ep);
  1914. return ret;
  1915. }
  1916. /*
  1917. * These are the real handlers that are called from a
  1918. * work queue.
  1919. */
  1920. static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
  1921. [CPL_ACT_ESTABLISH] = act_establish,
  1922. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  1923. [CPL_RX_DATA] = rx_data,
  1924. [CPL_ABORT_RPL_RSS] = abort_rpl,
  1925. [CPL_ABORT_RPL] = abort_rpl,
  1926. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  1927. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  1928. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  1929. [CPL_PASS_ESTABLISH] = pass_establish,
  1930. [CPL_PEER_CLOSE] = peer_close,
  1931. [CPL_ABORT_REQ_RSS] = peer_abort,
  1932. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  1933. [CPL_RDMA_TERMINATE] = terminate,
  1934. [CPL_FW4_ACK] = fw4_ack
  1935. };
  1936. static void process_timeout(struct c4iw_ep *ep)
  1937. {
  1938. struct c4iw_qp_attributes attrs;
  1939. int abort = 1;
  1940. spin_lock_irq(&ep->com.lock);
  1941. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  1942. ep->com.state);
  1943. switch (ep->com.state) {
  1944. case MPA_REQ_SENT:
  1945. __state_set(&ep->com, ABORTING);
  1946. connect_reply_upcall(ep, -ETIMEDOUT);
  1947. break;
  1948. case MPA_REQ_WAIT:
  1949. __state_set(&ep->com, ABORTING);
  1950. break;
  1951. case CLOSING:
  1952. case MORIBUND:
  1953. if (ep->com.cm_id && ep->com.qp) {
  1954. attrs.next_state = C4IW_QP_STATE_ERROR;
  1955. c4iw_modify_qp(ep->com.qp->rhp,
  1956. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  1957. &attrs, 1);
  1958. }
  1959. __state_set(&ep->com, ABORTING);
  1960. break;
  1961. default:
  1962. printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n",
  1963. __func__, ep, ep->hwtid, ep->com.state);
  1964. WARN_ON(1);
  1965. abort = 0;
  1966. }
  1967. spin_unlock_irq(&ep->com.lock);
  1968. if (abort)
  1969. abort_connection(ep, NULL, GFP_KERNEL);
  1970. c4iw_put_ep(&ep->com);
  1971. }
  1972. static void process_timedout_eps(void)
  1973. {
  1974. struct c4iw_ep *ep;
  1975. spin_lock_irq(&timeout_lock);
  1976. while (!list_empty(&timeout_list)) {
  1977. struct list_head *tmp;
  1978. tmp = timeout_list.next;
  1979. list_del(tmp);
  1980. spin_unlock_irq(&timeout_lock);
  1981. ep = list_entry(tmp, struct c4iw_ep, entry);
  1982. process_timeout(ep);
  1983. spin_lock_irq(&timeout_lock);
  1984. }
  1985. spin_unlock_irq(&timeout_lock);
  1986. }
  1987. static void process_work(struct work_struct *work)
  1988. {
  1989. struct sk_buff *skb = NULL;
  1990. struct c4iw_dev *dev;
  1991. struct cpl_act_establish *rpl;
  1992. unsigned int opcode;
  1993. int ret;
  1994. while ((skb = skb_dequeue(&rxq))) {
  1995. rpl = cplhdr(skb);
  1996. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  1997. opcode = rpl->ot.opcode;
  1998. BUG_ON(!work_handlers[opcode]);
  1999. ret = work_handlers[opcode](dev, skb);
  2000. if (!ret)
  2001. kfree_skb(skb);
  2002. }
  2003. process_timedout_eps();
  2004. }
  2005. static DECLARE_WORK(skb_work, process_work);
  2006. static void ep_timeout(unsigned long arg)
  2007. {
  2008. struct c4iw_ep *ep = (struct c4iw_ep *)arg;
  2009. spin_lock(&timeout_lock);
  2010. list_add_tail(&ep->entry, &timeout_list);
  2011. spin_unlock(&timeout_lock);
  2012. queue_work(workq, &skb_work);
  2013. }
  2014. /*
  2015. * All the CM events are handled on a work queue to have a safe context.
  2016. */
  2017. static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
  2018. {
  2019. /*
  2020. * Save dev in the skb->cb area.
  2021. */
  2022. *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
  2023. /*
  2024. * Queue the skb and schedule the worker thread.
  2025. */
  2026. skb_queue_tail(&rxq, skb);
  2027. queue_work(workq, &skb_work);
  2028. return 0;
  2029. }
  2030. static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2031. {
  2032. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  2033. if (rpl->status != CPL_ERR_NONE) {
  2034. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  2035. "for tid %u\n", rpl->status, GET_TID(rpl));
  2036. }
  2037. return 0;
  2038. }
  2039. static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  2040. {
  2041. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2042. struct c4iw_wr_wait *wr_waitp;
  2043. int ret;
  2044. PDBG("%s type %u\n", __func__, rpl->type);
  2045. switch (rpl->type) {
  2046. case 1:
  2047. ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
  2048. wr_waitp = (__force struct c4iw_wr_wait *)rpl->data[1];
  2049. PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
  2050. if (wr_waitp) {
  2051. wr_waitp->ret = ret;
  2052. wr_waitp->done = 1;
  2053. wake_up(&wr_waitp->wait);
  2054. }
  2055. break;
  2056. case 2:
  2057. c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
  2058. break;
  2059. default:
  2060. printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
  2061. rpl->type);
  2062. break;
  2063. }
  2064. return 0;
  2065. }
  2066. /*
  2067. * Most upcalls from the T4 Core go to sched() to
  2068. * schedule the processing on a work queue.
  2069. */
  2070. c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
  2071. [CPL_ACT_ESTABLISH] = sched,
  2072. [CPL_ACT_OPEN_RPL] = sched,
  2073. [CPL_RX_DATA] = sched,
  2074. [CPL_ABORT_RPL_RSS] = sched,
  2075. [CPL_ABORT_RPL] = sched,
  2076. [CPL_PASS_OPEN_RPL] = sched,
  2077. [CPL_CLOSE_LISTSRV_RPL] = sched,
  2078. [CPL_PASS_ACCEPT_REQ] = sched,
  2079. [CPL_PASS_ESTABLISH] = sched,
  2080. [CPL_PEER_CLOSE] = sched,
  2081. [CPL_CLOSE_CON_RPL] = sched,
  2082. [CPL_ABORT_REQ_RSS] = sched,
  2083. [CPL_RDMA_TERMINATE] = sched,
  2084. [CPL_FW4_ACK] = sched,
  2085. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  2086. [CPL_FW6_MSG] = fw6_msg
  2087. };
  2088. int __init c4iw_cm_init(void)
  2089. {
  2090. spin_lock_init(&timeout_lock);
  2091. skb_queue_head_init(&rxq);
  2092. workq = create_singlethread_workqueue("iw_cxgb4");
  2093. if (!workq)
  2094. return -ENOMEM;
  2095. return 0;
  2096. }
  2097. void __exit c4iw_cm_term(void)
  2098. {
  2099. WARN_ON(!list_empty(&timeout_list));
  2100. flush_workqueue(workq);
  2101. destroy_workqueue(workq);
  2102. }