cm.c 70 KB

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