cm.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747
  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. if (!ep) {
  1195. printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
  1196. return 0;
  1197. }
  1198. mutex_lock(&ep->com.mutex);
  1199. switch (ep->com.state) {
  1200. case ABORTING:
  1201. __state_set(&ep->com, DEAD);
  1202. release = 1;
  1203. break;
  1204. default:
  1205. printk(KERN_ERR "%s ep %p state %d\n",
  1206. __func__, ep, ep->com.state);
  1207. break;
  1208. }
  1209. mutex_unlock(&ep->com.mutex);
  1210. if (release)
  1211. release_ep_resources(ep);
  1212. return 0;
  1213. }
  1214. /*
  1215. * Return whether a failed active open has allocated a TID
  1216. */
  1217. static inline int act_open_has_tid(int status)
  1218. {
  1219. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1220. status != CPL_ERR_ARP_MISS;
  1221. }
  1222. static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1223. {
  1224. struct c4iw_ep *ep;
  1225. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1226. unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
  1227. ntohl(rpl->atid_status)));
  1228. struct tid_info *t = dev->rdev.lldi.tids;
  1229. int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
  1230. ep = lookup_atid(t, atid);
  1231. PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
  1232. status, status2errno(status));
  1233. if (status == CPL_ERR_RTX_NEG_ADVICE) {
  1234. printk(KERN_WARNING MOD "Connection problems for atid %u\n",
  1235. atid);
  1236. return 0;
  1237. }
  1238. /*
  1239. * Log interesting failures.
  1240. */
  1241. switch (status) {
  1242. case CPL_ERR_CONN_RESET:
  1243. case CPL_ERR_CONN_TIMEDOUT:
  1244. break;
  1245. default:
  1246. printk(KERN_INFO MOD "Active open failure - "
  1247. "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
  1248. atid, status, status2errno(status),
  1249. &ep->com.local_addr.sin_addr.s_addr,
  1250. ntohs(ep->com.local_addr.sin_port),
  1251. &ep->com.remote_addr.sin_addr.s_addr,
  1252. ntohs(ep->com.remote_addr.sin_port));
  1253. break;
  1254. }
  1255. connect_reply_upcall(ep, status2errno(status));
  1256. state_set(&ep->com, DEAD);
  1257. if (status && act_open_has_tid(status))
  1258. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
  1259. cxgb4_free_atid(t, atid);
  1260. dst_release(ep->dst);
  1261. cxgb4_l2t_release(ep->l2t);
  1262. c4iw_put_ep(&ep->com);
  1263. return 0;
  1264. }
  1265. static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1266. {
  1267. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1268. struct tid_info *t = dev->rdev.lldi.tids;
  1269. unsigned int stid = GET_TID(rpl);
  1270. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1271. if (!ep) {
  1272. printk(KERN_ERR MOD "stid %d lookup failure!\n", stid);
  1273. return 0;
  1274. }
  1275. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1276. rpl->status, status2errno(rpl->status));
  1277. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1278. return 0;
  1279. }
  1280. static int listen_stop(struct c4iw_listen_ep *ep)
  1281. {
  1282. struct sk_buff *skb;
  1283. struct cpl_close_listsvr_req *req;
  1284. PDBG("%s ep %p\n", __func__, ep);
  1285. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1286. if (!skb) {
  1287. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  1288. return -ENOMEM;
  1289. }
  1290. req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
  1291. INIT_TP_WR(req, 0);
  1292. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
  1293. ep->stid));
  1294. req->reply_ctrl = cpu_to_be16(
  1295. QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
  1296. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  1297. return c4iw_ofld_send(&ep->com.dev->rdev, skb);
  1298. }
  1299. static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1300. {
  1301. struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
  1302. struct tid_info *t = dev->rdev.lldi.tids;
  1303. unsigned int stid = GET_TID(rpl);
  1304. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1305. PDBG("%s ep %p\n", __func__, ep);
  1306. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1307. return 0;
  1308. }
  1309. static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
  1310. struct cpl_pass_accept_req *req)
  1311. {
  1312. struct cpl_pass_accept_rpl *rpl;
  1313. unsigned int mtu_idx;
  1314. u64 opt0;
  1315. u32 opt2;
  1316. int wscale;
  1317. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1318. BUG_ON(skb_cloned(skb));
  1319. skb_trim(skb, sizeof(*rpl));
  1320. skb_get(skb);
  1321. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1322. wscale = compute_wscale(rcv_win);
  1323. opt0 = KEEP_ALIVE(1) |
  1324. DELACK(1) |
  1325. WND_SCALE(wscale) |
  1326. MSS_IDX(mtu_idx) |
  1327. L2T_IDX(ep->l2t->idx) |
  1328. TX_CHAN(ep->tx_chan) |
  1329. SMAC_SEL(ep->smac_idx) |
  1330. DSCP(ep->tos) |
  1331. ULP_MODE(ULP_MODE_TCPDDP) |
  1332. RCV_BUFSIZ(rcv_win>>10);
  1333. opt2 = RX_CHANNEL(0) |
  1334. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  1335. if (enable_tcp_timestamps && req->tcpopt.tstamp)
  1336. opt2 |= TSTAMPS_EN(1);
  1337. if (enable_tcp_sack && req->tcpopt.sack)
  1338. opt2 |= SACK_EN(1);
  1339. if (wscale && enable_tcp_window_scaling)
  1340. opt2 |= WND_SCALE_EN(1);
  1341. rpl = cplhdr(skb);
  1342. INIT_TP_WR(rpl, ep->hwtid);
  1343. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1344. ep->hwtid));
  1345. rpl->opt0 = cpu_to_be64(opt0);
  1346. rpl->opt2 = cpu_to_be32(opt2);
  1347. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  1348. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1349. return;
  1350. }
  1351. static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
  1352. struct sk_buff *skb)
  1353. {
  1354. PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
  1355. peer_ip);
  1356. BUG_ON(skb_cloned(skb));
  1357. skb_trim(skb, sizeof(struct cpl_tid_release));
  1358. skb_get(skb);
  1359. release_tid(&dev->rdev, hwtid, skb);
  1360. return;
  1361. }
  1362. static void get_4tuple(struct cpl_pass_accept_req *req,
  1363. __be32 *local_ip, __be32 *peer_ip,
  1364. __be16 *local_port, __be16 *peer_port)
  1365. {
  1366. int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
  1367. int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
  1368. struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
  1369. struct tcphdr *tcp = (struct tcphdr *)
  1370. ((u8 *)(req + 1) + eth_len + ip_len);
  1371. PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
  1372. ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
  1373. ntohs(tcp->dest));
  1374. *peer_ip = ip->saddr;
  1375. *local_ip = ip->daddr;
  1376. *peer_port = tcp->source;
  1377. *local_port = tcp->dest;
  1378. return;
  1379. }
  1380. static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
  1381. struct c4iw_dev *cdev, bool clear_mpa_v1)
  1382. {
  1383. struct neighbour *n;
  1384. int err, step;
  1385. n = dst_neigh_lookup(dst, &peer_ip);
  1386. if (!n)
  1387. return -ENODEV;
  1388. rcu_read_lock();
  1389. err = -ENOMEM;
  1390. if (n->dev->flags & IFF_LOOPBACK) {
  1391. struct net_device *pdev;
  1392. pdev = ip_dev_find(&init_net, peer_ip);
  1393. if (!pdev) {
  1394. err = -ENODEV;
  1395. goto out;
  1396. }
  1397. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1398. n, pdev, 0);
  1399. if (!ep->l2t)
  1400. goto out;
  1401. ep->mtu = pdev->mtu;
  1402. ep->tx_chan = cxgb4_port_chan(pdev);
  1403. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1404. step = cdev->rdev.lldi.ntxq /
  1405. cdev->rdev.lldi.nchan;
  1406. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1407. step = cdev->rdev.lldi.nrxq /
  1408. cdev->rdev.lldi.nchan;
  1409. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  1410. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1411. cxgb4_port_idx(pdev) * step];
  1412. dev_put(pdev);
  1413. } else {
  1414. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1415. n, n->dev, 0);
  1416. if (!ep->l2t)
  1417. goto out;
  1418. ep->mtu = dst_mtu(dst);
  1419. ep->tx_chan = cxgb4_port_chan(n->dev);
  1420. ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
  1421. step = cdev->rdev.lldi.ntxq /
  1422. cdev->rdev.lldi.nchan;
  1423. ep->txq_idx = cxgb4_port_idx(n->dev) * step;
  1424. ep->ctrlq_idx = cxgb4_port_idx(n->dev);
  1425. step = cdev->rdev.lldi.nrxq /
  1426. cdev->rdev.lldi.nchan;
  1427. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1428. cxgb4_port_idx(n->dev) * step];
  1429. if (clear_mpa_v1) {
  1430. ep->retry_with_mpa_v1 = 0;
  1431. ep->tried_with_mpa_v1 = 0;
  1432. }
  1433. }
  1434. err = 0;
  1435. out:
  1436. rcu_read_unlock();
  1437. neigh_release(n);
  1438. return err;
  1439. }
  1440. static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
  1441. {
  1442. struct c4iw_ep *child_ep, *parent_ep;
  1443. struct cpl_pass_accept_req *req = cplhdr(skb);
  1444. unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
  1445. struct tid_info *t = dev->rdev.lldi.tids;
  1446. unsigned int hwtid = GET_TID(req);
  1447. struct dst_entry *dst;
  1448. struct rtable *rt;
  1449. __be32 local_ip, peer_ip;
  1450. __be16 local_port, peer_port;
  1451. int err;
  1452. parent_ep = lookup_stid(t, stid);
  1453. PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
  1454. get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
  1455. if (state_read(&parent_ep->com) != LISTEN) {
  1456. printk(KERN_ERR "%s - listening ep not in LISTEN\n",
  1457. __func__);
  1458. goto reject;
  1459. }
  1460. /* Find output route */
  1461. rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
  1462. GET_POPEN_TOS(ntohl(req->tos_stid)));
  1463. if (!rt) {
  1464. printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
  1465. __func__);
  1466. goto reject;
  1467. }
  1468. dst = &rt->dst;
  1469. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1470. if (!child_ep) {
  1471. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1472. __func__);
  1473. dst_release(dst);
  1474. goto reject;
  1475. }
  1476. err = import_ep(child_ep, peer_ip, dst, dev, false);
  1477. if (err) {
  1478. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1479. __func__);
  1480. dst_release(dst);
  1481. kfree(child_ep);
  1482. goto reject;
  1483. }
  1484. state_set(&child_ep->com, CONNECTING);
  1485. child_ep->com.dev = dev;
  1486. child_ep->com.cm_id = NULL;
  1487. child_ep->com.local_addr.sin_family = PF_INET;
  1488. child_ep->com.local_addr.sin_port = local_port;
  1489. child_ep->com.local_addr.sin_addr.s_addr = local_ip;
  1490. child_ep->com.remote_addr.sin_family = PF_INET;
  1491. child_ep->com.remote_addr.sin_port = peer_port;
  1492. child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
  1493. c4iw_get_ep(&parent_ep->com);
  1494. child_ep->parent_ep = parent_ep;
  1495. child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
  1496. child_ep->dst = dst;
  1497. child_ep->hwtid = hwtid;
  1498. PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
  1499. child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
  1500. init_timer(&child_ep->timer);
  1501. cxgb4_insert_tid(t, child_ep, hwtid);
  1502. accept_cr(child_ep, peer_ip, skb, req);
  1503. goto out;
  1504. reject:
  1505. reject_cr(dev, hwtid, peer_ip, skb);
  1506. out:
  1507. return 0;
  1508. }
  1509. static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  1510. {
  1511. struct c4iw_ep *ep;
  1512. struct cpl_pass_establish *req = cplhdr(skb);
  1513. struct tid_info *t = dev->rdev.lldi.tids;
  1514. unsigned int tid = GET_TID(req);
  1515. ep = lookup_tid(t, tid);
  1516. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1517. ep->snd_seq = be32_to_cpu(req->snd_isn);
  1518. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  1519. set_emss(ep, ntohs(req->tcp_opt));
  1520. dst_confirm(ep->dst);
  1521. state_set(&ep->com, MPA_REQ_WAIT);
  1522. start_ep_timer(ep);
  1523. send_flowc(ep, skb);
  1524. return 0;
  1525. }
  1526. static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
  1527. {
  1528. struct cpl_peer_close *hdr = cplhdr(skb);
  1529. struct c4iw_ep *ep;
  1530. struct c4iw_qp_attributes attrs;
  1531. int disconnect = 1;
  1532. int release = 0;
  1533. struct tid_info *t = dev->rdev.lldi.tids;
  1534. unsigned int tid = GET_TID(hdr);
  1535. int ret;
  1536. ep = lookup_tid(t, tid);
  1537. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1538. dst_confirm(ep->dst);
  1539. mutex_lock(&ep->com.mutex);
  1540. switch (ep->com.state) {
  1541. case MPA_REQ_WAIT:
  1542. __state_set(&ep->com, CLOSING);
  1543. break;
  1544. case MPA_REQ_SENT:
  1545. __state_set(&ep->com, CLOSING);
  1546. connect_reply_upcall(ep, -ECONNRESET);
  1547. break;
  1548. case MPA_REQ_RCVD:
  1549. /*
  1550. * We're gonna mark this puppy DEAD, but keep
  1551. * the reference on it until the ULP accepts or
  1552. * rejects the CR. Also wake up anyone waiting
  1553. * in rdma connection migration (see c4iw_accept_cr()).
  1554. */
  1555. __state_set(&ep->com, CLOSING);
  1556. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1557. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1558. break;
  1559. case MPA_REP_SENT:
  1560. __state_set(&ep->com, CLOSING);
  1561. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1562. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1563. break;
  1564. case FPDU_MODE:
  1565. start_ep_timer(ep);
  1566. __state_set(&ep->com, CLOSING);
  1567. attrs.next_state = C4IW_QP_STATE_CLOSING;
  1568. ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1569. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1570. if (ret != -ECONNRESET) {
  1571. peer_close_upcall(ep);
  1572. disconnect = 1;
  1573. }
  1574. break;
  1575. case ABORTING:
  1576. disconnect = 0;
  1577. break;
  1578. case CLOSING:
  1579. __state_set(&ep->com, MORIBUND);
  1580. disconnect = 0;
  1581. break;
  1582. case MORIBUND:
  1583. stop_ep_timer(ep);
  1584. if (ep->com.cm_id && ep->com.qp) {
  1585. attrs.next_state = C4IW_QP_STATE_IDLE;
  1586. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1587. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1588. }
  1589. close_complete_upcall(ep);
  1590. __state_set(&ep->com, DEAD);
  1591. release = 1;
  1592. disconnect = 0;
  1593. break;
  1594. case DEAD:
  1595. disconnect = 0;
  1596. break;
  1597. default:
  1598. BUG_ON(1);
  1599. }
  1600. mutex_unlock(&ep->com.mutex);
  1601. if (disconnect)
  1602. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1603. if (release)
  1604. release_ep_resources(ep);
  1605. return 0;
  1606. }
  1607. /*
  1608. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  1609. */
  1610. static int is_neg_adv_abort(unsigned int status)
  1611. {
  1612. return status == CPL_ERR_RTX_NEG_ADVICE ||
  1613. status == CPL_ERR_PERSIST_NEG_ADVICE;
  1614. }
  1615. static int c4iw_reconnect(struct c4iw_ep *ep)
  1616. {
  1617. struct rtable *rt;
  1618. int err = 0;
  1619. PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
  1620. init_timer(&ep->timer);
  1621. /*
  1622. * Allocate an active TID to initiate a TCP connection.
  1623. */
  1624. ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
  1625. if (ep->atid == -1) {
  1626. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  1627. err = -ENOMEM;
  1628. goto fail2;
  1629. }
  1630. /* find a route */
  1631. rt = find_route(ep->com.dev,
  1632. ep->com.cm_id->local_addr.sin_addr.s_addr,
  1633. ep->com.cm_id->remote_addr.sin_addr.s_addr,
  1634. ep->com.cm_id->local_addr.sin_port,
  1635. ep->com.cm_id->remote_addr.sin_port, 0);
  1636. if (!rt) {
  1637. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  1638. err = -EHOSTUNREACH;
  1639. goto fail3;
  1640. }
  1641. ep->dst = &rt->dst;
  1642. err = import_ep(ep, ep->com.cm_id->remote_addr.sin_addr.s_addr,
  1643. ep->dst, ep->com.dev, false);
  1644. if (err) {
  1645. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  1646. goto fail4;
  1647. }
  1648. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  1649. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  1650. ep->l2t->idx);
  1651. state_set(&ep->com, CONNECTING);
  1652. ep->tos = 0;
  1653. /* send connect request to rnic */
  1654. err = send_connect(ep);
  1655. if (!err)
  1656. goto out;
  1657. cxgb4_l2t_release(ep->l2t);
  1658. fail4:
  1659. dst_release(ep->dst);
  1660. fail3:
  1661. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  1662. fail2:
  1663. /*
  1664. * remember to send notification to upper layer.
  1665. * We are in here so the upper layer is not aware that this is
  1666. * re-connect attempt and so, upper layer is still waiting for
  1667. * response of 1st connect request.
  1668. */
  1669. connect_reply_upcall(ep, -ECONNRESET);
  1670. c4iw_put_ep(&ep->com);
  1671. out:
  1672. return err;
  1673. }
  1674. static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
  1675. {
  1676. struct cpl_abort_req_rss *req = cplhdr(skb);
  1677. struct c4iw_ep *ep;
  1678. struct cpl_abort_rpl *rpl;
  1679. struct sk_buff *rpl_skb;
  1680. struct c4iw_qp_attributes attrs;
  1681. int ret;
  1682. int release = 0;
  1683. struct tid_info *t = dev->rdev.lldi.tids;
  1684. unsigned int tid = GET_TID(req);
  1685. ep = lookup_tid(t, tid);
  1686. if (is_neg_adv_abort(req->status)) {
  1687. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  1688. ep->hwtid);
  1689. return 0;
  1690. }
  1691. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  1692. ep->com.state);
  1693. /*
  1694. * Wake up any threads in rdma_init() or rdma_fini().
  1695. * However, this is not needed if com state is just
  1696. * MPA_REQ_SENT
  1697. */
  1698. if (ep->com.state != MPA_REQ_SENT)
  1699. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1700. mutex_lock(&ep->com.mutex);
  1701. switch (ep->com.state) {
  1702. case CONNECTING:
  1703. break;
  1704. case MPA_REQ_WAIT:
  1705. stop_ep_timer(ep);
  1706. break;
  1707. case MPA_REQ_SENT:
  1708. stop_ep_timer(ep);
  1709. if (mpa_rev == 2 && ep->tried_with_mpa_v1)
  1710. connect_reply_upcall(ep, -ECONNRESET);
  1711. else {
  1712. /*
  1713. * we just don't send notification upwards because we
  1714. * want to retry with mpa_v1 without upper layers even
  1715. * knowing it.
  1716. *
  1717. * do some housekeeping so as to re-initiate the
  1718. * connection
  1719. */
  1720. PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
  1721. mpa_rev);
  1722. ep->retry_with_mpa_v1 = 1;
  1723. }
  1724. break;
  1725. case MPA_REP_SENT:
  1726. break;
  1727. case MPA_REQ_RCVD:
  1728. break;
  1729. case MORIBUND:
  1730. case CLOSING:
  1731. stop_ep_timer(ep);
  1732. /*FALLTHROUGH*/
  1733. case FPDU_MODE:
  1734. if (ep->com.cm_id && ep->com.qp) {
  1735. attrs.next_state = C4IW_QP_STATE_ERROR;
  1736. ret = c4iw_modify_qp(ep->com.qp->rhp,
  1737. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  1738. &attrs, 1);
  1739. if (ret)
  1740. printk(KERN_ERR MOD
  1741. "%s - qp <- error failed!\n",
  1742. __func__);
  1743. }
  1744. peer_abort_upcall(ep);
  1745. break;
  1746. case ABORTING:
  1747. break;
  1748. case DEAD:
  1749. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  1750. mutex_unlock(&ep->com.mutex);
  1751. return 0;
  1752. default:
  1753. BUG_ON(1);
  1754. break;
  1755. }
  1756. dst_confirm(ep->dst);
  1757. if (ep->com.state != ABORTING) {
  1758. __state_set(&ep->com, DEAD);
  1759. /* we don't release if we want to retry with mpa_v1 */
  1760. if (!ep->retry_with_mpa_v1)
  1761. release = 1;
  1762. }
  1763. mutex_unlock(&ep->com.mutex);
  1764. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  1765. if (!rpl_skb) {
  1766. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  1767. __func__);
  1768. release = 1;
  1769. goto out;
  1770. }
  1771. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  1772. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  1773. INIT_TP_WR(rpl, ep->hwtid);
  1774. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  1775. rpl->cmd = CPL_ABORT_NO_RST;
  1776. c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
  1777. out:
  1778. if (release)
  1779. release_ep_resources(ep);
  1780. /* retry with mpa-v1 */
  1781. if (ep && ep->retry_with_mpa_v1) {
  1782. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  1783. dst_release(ep->dst);
  1784. cxgb4_l2t_release(ep->l2t);
  1785. c4iw_reconnect(ep);
  1786. }
  1787. return 0;
  1788. }
  1789. static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1790. {
  1791. struct c4iw_ep *ep;
  1792. struct c4iw_qp_attributes attrs;
  1793. struct cpl_close_con_rpl *rpl = cplhdr(skb);
  1794. int release = 0;
  1795. struct tid_info *t = dev->rdev.lldi.tids;
  1796. unsigned int tid = GET_TID(rpl);
  1797. ep = lookup_tid(t, tid);
  1798. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1799. BUG_ON(!ep);
  1800. /* The cm_id may be null if we failed to connect */
  1801. mutex_lock(&ep->com.mutex);
  1802. switch (ep->com.state) {
  1803. case CLOSING:
  1804. __state_set(&ep->com, MORIBUND);
  1805. break;
  1806. case MORIBUND:
  1807. stop_ep_timer(ep);
  1808. if ((ep->com.cm_id) && (ep->com.qp)) {
  1809. attrs.next_state = C4IW_QP_STATE_IDLE;
  1810. c4iw_modify_qp(ep->com.qp->rhp,
  1811. ep->com.qp,
  1812. C4IW_QP_ATTR_NEXT_STATE,
  1813. &attrs, 1);
  1814. }
  1815. close_complete_upcall(ep);
  1816. __state_set(&ep->com, DEAD);
  1817. release = 1;
  1818. break;
  1819. case ABORTING:
  1820. case DEAD:
  1821. break;
  1822. default:
  1823. BUG_ON(1);
  1824. break;
  1825. }
  1826. mutex_unlock(&ep->com.mutex);
  1827. if (release)
  1828. release_ep_resources(ep);
  1829. return 0;
  1830. }
  1831. static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
  1832. {
  1833. struct cpl_rdma_terminate *rpl = cplhdr(skb);
  1834. struct tid_info *t = dev->rdev.lldi.tids;
  1835. unsigned int tid = GET_TID(rpl);
  1836. struct c4iw_ep *ep;
  1837. struct c4iw_qp_attributes attrs;
  1838. ep = lookup_tid(t, tid);
  1839. BUG_ON(!ep);
  1840. if (ep && ep->com.qp) {
  1841. printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
  1842. ep->com.qp->wq.sq.qid);
  1843. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1844. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1845. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1846. } else
  1847. printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
  1848. return 0;
  1849. }
  1850. /*
  1851. * Upcall from the adapter indicating data has been transmitted.
  1852. * For us its just the single MPA request or reply. We can now free
  1853. * the skb holding the mpa message.
  1854. */
  1855. static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
  1856. {
  1857. struct c4iw_ep *ep;
  1858. struct cpl_fw4_ack *hdr = cplhdr(skb);
  1859. u8 credits = hdr->credits;
  1860. unsigned int tid = GET_TID(hdr);
  1861. struct tid_info *t = dev->rdev.lldi.tids;
  1862. ep = lookup_tid(t, tid);
  1863. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  1864. if (credits == 0) {
  1865. PDBG("%s 0 credit ack ep %p tid %u state %u\n",
  1866. __func__, ep, ep->hwtid, state_read(&ep->com));
  1867. return 0;
  1868. }
  1869. dst_confirm(ep->dst);
  1870. if (ep->mpa_skb) {
  1871. PDBG("%s last streaming msg ack ep %p tid %u state %u "
  1872. "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
  1873. state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
  1874. kfree_skb(ep->mpa_skb);
  1875. ep->mpa_skb = NULL;
  1876. }
  1877. return 0;
  1878. }
  1879. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  1880. {
  1881. int err;
  1882. struct c4iw_ep *ep = to_ep(cm_id);
  1883. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1884. if (state_read(&ep->com) == DEAD) {
  1885. c4iw_put_ep(&ep->com);
  1886. return -ECONNRESET;
  1887. }
  1888. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1889. if (mpa_rev == 0)
  1890. abort_connection(ep, NULL, GFP_KERNEL);
  1891. else {
  1892. err = send_mpa_reject(ep, pdata, pdata_len);
  1893. err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  1894. }
  1895. c4iw_put_ep(&ep->com);
  1896. return 0;
  1897. }
  1898. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1899. {
  1900. int err;
  1901. struct c4iw_qp_attributes attrs;
  1902. enum c4iw_qp_attr_mask mask;
  1903. struct c4iw_ep *ep = to_ep(cm_id);
  1904. struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
  1905. struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
  1906. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1907. if (state_read(&ep->com) == DEAD) {
  1908. err = -ECONNRESET;
  1909. goto err;
  1910. }
  1911. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  1912. BUG_ON(!qp);
  1913. if ((conn_param->ord > c4iw_max_read_depth) ||
  1914. (conn_param->ird > c4iw_max_read_depth)) {
  1915. abort_connection(ep, NULL, GFP_KERNEL);
  1916. err = -EINVAL;
  1917. goto err;
  1918. }
  1919. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  1920. if (conn_param->ord > ep->ird) {
  1921. ep->ird = conn_param->ird;
  1922. ep->ord = conn_param->ord;
  1923. send_mpa_reject(ep, conn_param->private_data,
  1924. conn_param->private_data_len);
  1925. abort_connection(ep, NULL, GFP_KERNEL);
  1926. err = -ENOMEM;
  1927. goto err;
  1928. }
  1929. if (conn_param->ird > ep->ord) {
  1930. if (!ep->ord)
  1931. conn_param->ird = 1;
  1932. else {
  1933. abort_connection(ep, NULL, GFP_KERNEL);
  1934. err = -ENOMEM;
  1935. goto err;
  1936. }
  1937. }
  1938. }
  1939. ep->ird = conn_param->ird;
  1940. ep->ord = conn_param->ord;
  1941. if (ep->mpa_attr.version != 2)
  1942. if (peer2peer && ep->ird == 0)
  1943. ep->ird = 1;
  1944. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  1945. cm_id->add_ref(cm_id);
  1946. ep->com.cm_id = cm_id;
  1947. ep->com.qp = qp;
  1948. /* bind QP to EP and move to RTS */
  1949. attrs.mpa_attr = ep->mpa_attr;
  1950. attrs.max_ird = ep->ird;
  1951. attrs.max_ord = ep->ord;
  1952. attrs.llp_stream_handle = ep;
  1953. attrs.next_state = C4IW_QP_STATE_RTS;
  1954. /* bind QP and TID with INIT_WR */
  1955. mask = C4IW_QP_ATTR_NEXT_STATE |
  1956. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  1957. C4IW_QP_ATTR_MPA_ATTR |
  1958. C4IW_QP_ATTR_MAX_IRD |
  1959. C4IW_QP_ATTR_MAX_ORD;
  1960. err = c4iw_modify_qp(ep->com.qp->rhp,
  1961. ep->com.qp, mask, &attrs, 1);
  1962. if (err)
  1963. goto err1;
  1964. err = send_mpa_reply(ep, conn_param->private_data,
  1965. conn_param->private_data_len);
  1966. if (err)
  1967. goto err1;
  1968. state_set(&ep->com, FPDU_MODE);
  1969. established_upcall(ep);
  1970. c4iw_put_ep(&ep->com);
  1971. return 0;
  1972. err1:
  1973. ep->com.cm_id = NULL;
  1974. ep->com.qp = NULL;
  1975. cm_id->rem_ref(cm_id);
  1976. err:
  1977. c4iw_put_ep(&ep->com);
  1978. return err;
  1979. }
  1980. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  1981. {
  1982. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  1983. struct c4iw_ep *ep;
  1984. struct rtable *rt;
  1985. int err = 0;
  1986. if ((conn_param->ord > c4iw_max_read_depth) ||
  1987. (conn_param->ird > c4iw_max_read_depth)) {
  1988. err = -EINVAL;
  1989. goto out;
  1990. }
  1991. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  1992. if (!ep) {
  1993. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  1994. err = -ENOMEM;
  1995. goto out;
  1996. }
  1997. init_timer(&ep->timer);
  1998. ep->plen = conn_param->private_data_len;
  1999. if (ep->plen)
  2000. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  2001. conn_param->private_data, ep->plen);
  2002. ep->ird = conn_param->ird;
  2003. ep->ord = conn_param->ord;
  2004. if (peer2peer && ep->ord == 0)
  2005. ep->ord = 1;
  2006. cm_id->add_ref(cm_id);
  2007. ep->com.dev = dev;
  2008. ep->com.cm_id = cm_id;
  2009. ep->com.qp = get_qhp(dev, conn_param->qpn);
  2010. BUG_ON(!ep->com.qp);
  2011. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  2012. ep->com.qp, cm_id);
  2013. /*
  2014. * Allocate an active TID to initiate a TCP connection.
  2015. */
  2016. ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
  2017. if (ep->atid == -1) {
  2018. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  2019. err = -ENOMEM;
  2020. goto fail2;
  2021. }
  2022. PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
  2023. ntohl(cm_id->local_addr.sin_addr.s_addr),
  2024. ntohs(cm_id->local_addr.sin_port),
  2025. ntohl(cm_id->remote_addr.sin_addr.s_addr),
  2026. ntohs(cm_id->remote_addr.sin_port));
  2027. /* find a route */
  2028. rt = find_route(dev,
  2029. cm_id->local_addr.sin_addr.s_addr,
  2030. cm_id->remote_addr.sin_addr.s_addr,
  2031. cm_id->local_addr.sin_port,
  2032. cm_id->remote_addr.sin_port, 0);
  2033. if (!rt) {
  2034. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  2035. err = -EHOSTUNREACH;
  2036. goto fail3;
  2037. }
  2038. ep->dst = &rt->dst;
  2039. err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
  2040. ep->dst, ep->com.dev, true);
  2041. if (err) {
  2042. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  2043. goto fail4;
  2044. }
  2045. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  2046. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  2047. ep->l2t->idx);
  2048. state_set(&ep->com, CONNECTING);
  2049. ep->tos = 0;
  2050. ep->com.local_addr = cm_id->local_addr;
  2051. ep->com.remote_addr = cm_id->remote_addr;
  2052. /* send connect request to rnic */
  2053. err = send_connect(ep);
  2054. if (!err)
  2055. goto out;
  2056. cxgb4_l2t_release(ep->l2t);
  2057. fail4:
  2058. dst_release(ep->dst);
  2059. fail3:
  2060. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  2061. fail2:
  2062. cm_id->rem_ref(cm_id);
  2063. c4iw_put_ep(&ep->com);
  2064. out:
  2065. return err;
  2066. }
  2067. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
  2068. {
  2069. int err = 0;
  2070. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2071. struct c4iw_listen_ep *ep;
  2072. might_sleep();
  2073. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2074. if (!ep) {
  2075. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2076. err = -ENOMEM;
  2077. goto fail1;
  2078. }
  2079. PDBG("%s ep %p\n", __func__, ep);
  2080. cm_id->add_ref(cm_id);
  2081. ep->com.cm_id = cm_id;
  2082. ep->com.dev = dev;
  2083. ep->backlog = backlog;
  2084. ep->com.local_addr = cm_id->local_addr;
  2085. /*
  2086. * Allocate a server TID.
  2087. */
  2088. ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
  2089. if (ep->stid == -1) {
  2090. printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
  2091. err = -ENOMEM;
  2092. goto fail2;
  2093. }
  2094. state_set(&ep->com, LISTEN);
  2095. c4iw_init_wr_wait(&ep->com.wr_wait);
  2096. err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2097. ep->com.local_addr.sin_addr.s_addr,
  2098. ep->com.local_addr.sin_port,
  2099. ep->com.dev->rdev.lldi.rxq_ids[0]);
  2100. if (err)
  2101. goto fail3;
  2102. /* wait for pass_open_rpl */
  2103. err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
  2104. __func__);
  2105. if (!err) {
  2106. cm_id->provider_data = ep;
  2107. goto out;
  2108. }
  2109. fail3:
  2110. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  2111. fail2:
  2112. cm_id->rem_ref(cm_id);
  2113. c4iw_put_ep(&ep->com);
  2114. fail1:
  2115. out:
  2116. return err;
  2117. }
  2118. int c4iw_destroy_listen(struct iw_cm_id *cm_id)
  2119. {
  2120. int err;
  2121. struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
  2122. PDBG("%s ep %p\n", __func__, ep);
  2123. might_sleep();
  2124. state_set(&ep->com, DEAD);
  2125. c4iw_init_wr_wait(&ep->com.wr_wait);
  2126. err = listen_stop(ep);
  2127. if (err)
  2128. goto done;
  2129. err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
  2130. __func__);
  2131. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
  2132. done:
  2133. cm_id->rem_ref(cm_id);
  2134. c4iw_put_ep(&ep->com);
  2135. return err;
  2136. }
  2137. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
  2138. {
  2139. int ret = 0;
  2140. int close = 0;
  2141. int fatal = 0;
  2142. struct c4iw_rdev *rdev;
  2143. mutex_lock(&ep->com.mutex);
  2144. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  2145. states[ep->com.state], abrupt);
  2146. rdev = &ep->com.dev->rdev;
  2147. if (c4iw_fatal_error(rdev)) {
  2148. fatal = 1;
  2149. close_complete_upcall(ep);
  2150. ep->com.state = DEAD;
  2151. }
  2152. switch (ep->com.state) {
  2153. case MPA_REQ_WAIT:
  2154. case MPA_REQ_SENT:
  2155. case MPA_REQ_RCVD:
  2156. case MPA_REP_SENT:
  2157. case FPDU_MODE:
  2158. close = 1;
  2159. if (abrupt)
  2160. ep->com.state = ABORTING;
  2161. else {
  2162. ep->com.state = CLOSING;
  2163. start_ep_timer(ep);
  2164. }
  2165. set_bit(CLOSE_SENT, &ep->com.flags);
  2166. break;
  2167. case CLOSING:
  2168. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  2169. close = 1;
  2170. if (abrupt) {
  2171. stop_ep_timer(ep);
  2172. ep->com.state = ABORTING;
  2173. } else
  2174. ep->com.state = MORIBUND;
  2175. }
  2176. break;
  2177. case MORIBUND:
  2178. case ABORTING:
  2179. case DEAD:
  2180. PDBG("%s ignoring disconnect ep %p state %u\n",
  2181. __func__, ep, ep->com.state);
  2182. break;
  2183. default:
  2184. BUG();
  2185. break;
  2186. }
  2187. if (close) {
  2188. if (abrupt) {
  2189. close_complete_upcall(ep);
  2190. ret = send_abort(ep, NULL, gfp);
  2191. } else
  2192. ret = send_halfclose(ep, gfp);
  2193. if (ret)
  2194. fatal = 1;
  2195. }
  2196. mutex_unlock(&ep->com.mutex);
  2197. if (fatal)
  2198. release_ep_resources(ep);
  2199. return ret;
  2200. }
  2201. static int async_event(struct c4iw_dev *dev, struct sk_buff *skb)
  2202. {
  2203. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2204. c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
  2205. return 0;
  2206. }
  2207. /*
  2208. * These are the real handlers that are called from a
  2209. * work queue.
  2210. */
  2211. static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
  2212. [CPL_ACT_ESTABLISH] = act_establish,
  2213. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  2214. [CPL_RX_DATA] = rx_data,
  2215. [CPL_ABORT_RPL_RSS] = abort_rpl,
  2216. [CPL_ABORT_RPL] = abort_rpl,
  2217. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  2218. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  2219. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  2220. [CPL_PASS_ESTABLISH] = pass_establish,
  2221. [CPL_PEER_CLOSE] = peer_close,
  2222. [CPL_ABORT_REQ_RSS] = peer_abort,
  2223. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  2224. [CPL_RDMA_TERMINATE] = terminate,
  2225. [CPL_FW4_ACK] = fw4_ack,
  2226. [CPL_FW6_MSG] = async_event
  2227. };
  2228. static void process_timeout(struct c4iw_ep *ep)
  2229. {
  2230. struct c4iw_qp_attributes attrs;
  2231. int abort = 1;
  2232. mutex_lock(&ep->com.mutex);
  2233. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  2234. ep->com.state);
  2235. switch (ep->com.state) {
  2236. case MPA_REQ_SENT:
  2237. __state_set(&ep->com, ABORTING);
  2238. connect_reply_upcall(ep, -ETIMEDOUT);
  2239. break;
  2240. case MPA_REQ_WAIT:
  2241. __state_set(&ep->com, ABORTING);
  2242. break;
  2243. case CLOSING:
  2244. case MORIBUND:
  2245. if (ep->com.cm_id && ep->com.qp) {
  2246. attrs.next_state = C4IW_QP_STATE_ERROR;
  2247. c4iw_modify_qp(ep->com.qp->rhp,
  2248. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  2249. &attrs, 1);
  2250. }
  2251. __state_set(&ep->com, ABORTING);
  2252. break;
  2253. default:
  2254. printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n",
  2255. __func__, ep, ep->hwtid, ep->com.state);
  2256. WARN_ON(1);
  2257. abort = 0;
  2258. }
  2259. mutex_unlock(&ep->com.mutex);
  2260. if (abort)
  2261. abort_connection(ep, NULL, GFP_KERNEL);
  2262. c4iw_put_ep(&ep->com);
  2263. }
  2264. static void process_timedout_eps(void)
  2265. {
  2266. struct c4iw_ep *ep;
  2267. spin_lock_irq(&timeout_lock);
  2268. while (!list_empty(&timeout_list)) {
  2269. struct list_head *tmp;
  2270. tmp = timeout_list.next;
  2271. list_del(tmp);
  2272. spin_unlock_irq(&timeout_lock);
  2273. ep = list_entry(tmp, struct c4iw_ep, entry);
  2274. process_timeout(ep);
  2275. spin_lock_irq(&timeout_lock);
  2276. }
  2277. spin_unlock_irq(&timeout_lock);
  2278. }
  2279. static void process_work(struct work_struct *work)
  2280. {
  2281. struct sk_buff *skb = NULL;
  2282. struct c4iw_dev *dev;
  2283. struct cpl_act_establish *rpl;
  2284. unsigned int opcode;
  2285. int ret;
  2286. while ((skb = skb_dequeue(&rxq))) {
  2287. rpl = cplhdr(skb);
  2288. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  2289. opcode = rpl->ot.opcode;
  2290. BUG_ON(!work_handlers[opcode]);
  2291. ret = work_handlers[opcode](dev, skb);
  2292. if (!ret)
  2293. kfree_skb(skb);
  2294. }
  2295. process_timedout_eps();
  2296. }
  2297. static DECLARE_WORK(skb_work, process_work);
  2298. static void ep_timeout(unsigned long arg)
  2299. {
  2300. struct c4iw_ep *ep = (struct c4iw_ep *)arg;
  2301. spin_lock(&timeout_lock);
  2302. list_add_tail(&ep->entry, &timeout_list);
  2303. spin_unlock(&timeout_lock);
  2304. queue_work(workq, &skb_work);
  2305. }
  2306. /*
  2307. * All the CM events are handled on a work queue to have a safe context.
  2308. */
  2309. static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
  2310. {
  2311. /*
  2312. * Save dev in the skb->cb area.
  2313. */
  2314. *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
  2315. /*
  2316. * Queue the skb and schedule the worker thread.
  2317. */
  2318. skb_queue_tail(&rxq, skb);
  2319. queue_work(workq, &skb_work);
  2320. return 0;
  2321. }
  2322. static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2323. {
  2324. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  2325. if (rpl->status != CPL_ERR_NONE) {
  2326. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  2327. "for tid %u\n", rpl->status, GET_TID(rpl));
  2328. }
  2329. kfree_skb(skb);
  2330. return 0;
  2331. }
  2332. static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  2333. {
  2334. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2335. struct c4iw_wr_wait *wr_waitp;
  2336. int ret;
  2337. PDBG("%s type %u\n", __func__, rpl->type);
  2338. switch (rpl->type) {
  2339. case 1:
  2340. ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
  2341. wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
  2342. PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
  2343. if (wr_waitp)
  2344. c4iw_wake_up(wr_waitp, ret ? -ret : 0);
  2345. kfree_skb(skb);
  2346. break;
  2347. case 2:
  2348. sched(dev, skb);
  2349. break;
  2350. default:
  2351. printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
  2352. rpl->type);
  2353. kfree_skb(skb);
  2354. break;
  2355. }
  2356. return 0;
  2357. }
  2358. static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
  2359. {
  2360. struct cpl_abort_req_rss *req = cplhdr(skb);
  2361. struct c4iw_ep *ep;
  2362. struct tid_info *t = dev->rdev.lldi.tids;
  2363. unsigned int tid = GET_TID(req);
  2364. ep = lookup_tid(t, tid);
  2365. if (!ep) {
  2366. printk(KERN_WARNING MOD
  2367. "Abort on non-existent endpoint, tid %d\n", tid);
  2368. kfree_skb(skb);
  2369. return 0;
  2370. }
  2371. if (is_neg_adv_abort(req->status)) {
  2372. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  2373. ep->hwtid);
  2374. kfree_skb(skb);
  2375. return 0;
  2376. }
  2377. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  2378. ep->com.state);
  2379. /*
  2380. * Wake up any threads in rdma_init() or rdma_fini().
  2381. */
  2382. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2383. sched(dev, skb);
  2384. return 0;
  2385. }
  2386. /*
  2387. * Most upcalls from the T4 Core go to sched() to
  2388. * schedule the processing on a work queue.
  2389. */
  2390. c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
  2391. [CPL_ACT_ESTABLISH] = sched,
  2392. [CPL_ACT_OPEN_RPL] = sched,
  2393. [CPL_RX_DATA] = sched,
  2394. [CPL_ABORT_RPL_RSS] = sched,
  2395. [CPL_ABORT_RPL] = sched,
  2396. [CPL_PASS_OPEN_RPL] = sched,
  2397. [CPL_CLOSE_LISTSRV_RPL] = sched,
  2398. [CPL_PASS_ACCEPT_REQ] = sched,
  2399. [CPL_PASS_ESTABLISH] = sched,
  2400. [CPL_PEER_CLOSE] = sched,
  2401. [CPL_CLOSE_CON_RPL] = sched,
  2402. [CPL_ABORT_REQ_RSS] = peer_abort_intr,
  2403. [CPL_RDMA_TERMINATE] = sched,
  2404. [CPL_FW4_ACK] = sched,
  2405. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  2406. [CPL_FW6_MSG] = fw6_msg
  2407. };
  2408. int __init c4iw_cm_init(void)
  2409. {
  2410. spin_lock_init(&timeout_lock);
  2411. skb_queue_head_init(&rxq);
  2412. workq = create_singlethread_workqueue("iw_cxgb4");
  2413. if (!workq)
  2414. return -ENOMEM;
  2415. return 0;
  2416. }
  2417. void __exit c4iw_cm_term(void)
  2418. {
  2419. WARN_ON(!list_empty(&timeout_list));
  2420. flush_workqueue(workq);
  2421. destroy_workqueue(workq);
  2422. }