cm.c 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674
  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 <linux/if_vlan.h>
  42. #include <net/neighbour.h>
  43. #include <net/netevent.h>
  44. #include <net/route.h>
  45. #include <net/tcp.h>
  46. #include <net/ip6_route.h>
  47. #include <net/addrconf.h>
  48. #include "iw_cxgb4.h"
  49. static char *states[] = {
  50. "idle",
  51. "listen",
  52. "connecting",
  53. "mpa_wait_req",
  54. "mpa_req_sent",
  55. "mpa_req_rcvd",
  56. "mpa_rep_sent",
  57. "fpdu_mode",
  58. "aborting",
  59. "closing",
  60. "moribund",
  61. "dead",
  62. NULL,
  63. };
  64. static int nocong;
  65. module_param(nocong, int, 0644);
  66. MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
  67. static int enable_ecn;
  68. module_param(enable_ecn, int, 0644);
  69. MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
  70. static int dack_mode = 1;
  71. module_param(dack_mode, int, 0644);
  72. MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
  73. int c4iw_max_read_depth = 8;
  74. module_param(c4iw_max_read_depth, int, 0644);
  75. MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
  76. static int enable_tcp_timestamps;
  77. module_param(enable_tcp_timestamps, int, 0644);
  78. MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
  79. static int enable_tcp_sack;
  80. module_param(enable_tcp_sack, int, 0644);
  81. MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
  82. static int enable_tcp_window_scaling = 1;
  83. module_param(enable_tcp_window_scaling, int, 0644);
  84. MODULE_PARM_DESC(enable_tcp_window_scaling,
  85. "Enable tcp window scaling (default=1)");
  86. int c4iw_debug;
  87. module_param(c4iw_debug, int, 0644);
  88. MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
  89. static int peer2peer;
  90. module_param(peer2peer, int, 0644);
  91. MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
  92. static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
  93. module_param(p2p_type, int, 0644);
  94. MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
  95. "1=RDMA_READ 0=RDMA_WRITE (default 1)");
  96. static int ep_timeout_secs = 60;
  97. module_param(ep_timeout_secs, int, 0644);
  98. MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
  99. "in seconds (default=60)");
  100. static int mpa_rev = 1;
  101. module_param(mpa_rev, int, 0644);
  102. MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
  103. "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
  104. " compliant (default=1)");
  105. static int markers_enabled;
  106. module_param(markers_enabled, int, 0644);
  107. MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
  108. static int crc_enabled = 1;
  109. module_param(crc_enabled, int, 0644);
  110. MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
  111. static int rcv_win = 256 * 1024;
  112. module_param(rcv_win, int, 0644);
  113. MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
  114. static int snd_win = 128 * 1024;
  115. module_param(snd_win, int, 0644);
  116. MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
  117. static struct workqueue_struct *workq;
  118. static struct sk_buff_head rxq;
  119. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
  120. static void ep_timeout(unsigned long arg);
  121. static void connect_reply_upcall(struct c4iw_ep *ep, int status);
  122. static LIST_HEAD(timeout_list);
  123. static spinlock_t timeout_lock;
  124. static void deref_qp(struct c4iw_ep *ep)
  125. {
  126. c4iw_qp_rem_ref(&ep->com.qp->ibqp);
  127. clear_bit(QP_REFERENCED, &ep->com.flags);
  128. }
  129. static void ref_qp(struct c4iw_ep *ep)
  130. {
  131. set_bit(QP_REFERENCED, &ep->com.flags);
  132. c4iw_qp_add_ref(&ep->com.qp->ibqp);
  133. }
  134. static void start_ep_timer(struct c4iw_ep *ep)
  135. {
  136. PDBG("%s ep %p\n", __func__, ep);
  137. if (timer_pending(&ep->timer)) {
  138. pr_err("%s timer already started! ep %p\n",
  139. __func__, ep);
  140. return;
  141. }
  142. clear_bit(TIMEOUT, &ep->com.flags);
  143. c4iw_get_ep(&ep->com);
  144. ep->timer.expires = jiffies + ep_timeout_secs * HZ;
  145. ep->timer.data = (unsigned long)ep;
  146. ep->timer.function = ep_timeout;
  147. add_timer(&ep->timer);
  148. }
  149. static void stop_ep_timer(struct c4iw_ep *ep)
  150. {
  151. PDBG("%s ep %p stopping\n", __func__, ep);
  152. del_timer_sync(&ep->timer);
  153. if (!test_and_set_bit(TIMEOUT, &ep->com.flags))
  154. c4iw_put_ep(&ep->com);
  155. }
  156. static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
  157. struct l2t_entry *l2e)
  158. {
  159. int error = 0;
  160. if (c4iw_fatal_error(rdev)) {
  161. kfree_skb(skb);
  162. PDBG("%s - device in error state - dropping\n", __func__);
  163. return -EIO;
  164. }
  165. error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
  166. if (error < 0)
  167. kfree_skb(skb);
  168. return error < 0 ? error : 0;
  169. }
  170. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
  171. {
  172. int error = 0;
  173. if (c4iw_fatal_error(rdev)) {
  174. kfree_skb(skb);
  175. PDBG("%s - device in error state - dropping\n", __func__);
  176. return -EIO;
  177. }
  178. error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
  179. if (error < 0)
  180. kfree_skb(skb);
  181. return error < 0 ? error : 0;
  182. }
  183. static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
  184. {
  185. struct cpl_tid_release *req;
  186. skb = get_skb(skb, sizeof *req, GFP_KERNEL);
  187. if (!skb)
  188. return;
  189. req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
  190. INIT_TP_WR(req, hwtid);
  191. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
  192. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  193. c4iw_ofld_send(rdev, skb);
  194. return;
  195. }
  196. static void set_emss(struct c4iw_ep *ep, u16 opt)
  197. {
  198. ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
  199. ep->mss = ep->emss;
  200. if (GET_TCPOPT_TSTAMP(opt))
  201. ep->emss -= 12;
  202. if (ep->emss < 128)
  203. ep->emss = 128;
  204. PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
  205. ep->mss, ep->emss);
  206. }
  207. static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
  208. {
  209. enum c4iw_ep_state state;
  210. mutex_lock(&epc->mutex);
  211. state = epc->state;
  212. mutex_unlock(&epc->mutex);
  213. return state;
  214. }
  215. static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  216. {
  217. epc->state = new;
  218. }
  219. static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  220. {
  221. mutex_lock(&epc->mutex);
  222. PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
  223. __state_set(epc, new);
  224. mutex_unlock(&epc->mutex);
  225. return;
  226. }
  227. static void *alloc_ep(int size, gfp_t gfp)
  228. {
  229. struct c4iw_ep_common *epc;
  230. epc = kzalloc(size, gfp);
  231. if (epc) {
  232. kref_init(&epc->kref);
  233. mutex_init(&epc->mutex);
  234. c4iw_init_wr_wait(&epc->wr_wait);
  235. }
  236. PDBG("%s alloc ep %p\n", __func__, epc);
  237. return epc;
  238. }
  239. void _c4iw_free_ep(struct kref *kref)
  240. {
  241. struct c4iw_ep *ep;
  242. ep = container_of(kref, struct c4iw_ep, com.kref);
  243. PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
  244. if (test_bit(QP_REFERENCED, &ep->com.flags))
  245. deref_qp(ep);
  246. if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
  247. remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
  248. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  249. dst_release(ep->dst);
  250. cxgb4_l2t_release(ep->l2t);
  251. }
  252. kfree(ep);
  253. }
  254. static void release_ep_resources(struct c4iw_ep *ep)
  255. {
  256. set_bit(RELEASE_RESOURCES, &ep->com.flags);
  257. c4iw_put_ep(&ep->com);
  258. }
  259. static int status2errno(int status)
  260. {
  261. switch (status) {
  262. case CPL_ERR_NONE:
  263. return 0;
  264. case CPL_ERR_CONN_RESET:
  265. return -ECONNRESET;
  266. case CPL_ERR_ARP_MISS:
  267. return -EHOSTUNREACH;
  268. case CPL_ERR_CONN_TIMEDOUT:
  269. return -ETIMEDOUT;
  270. case CPL_ERR_TCAM_FULL:
  271. return -ENOMEM;
  272. case CPL_ERR_CONN_EXIST:
  273. return -EADDRINUSE;
  274. default:
  275. return -EIO;
  276. }
  277. }
  278. /*
  279. * Try and reuse skbs already allocated...
  280. */
  281. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
  282. {
  283. if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
  284. skb_trim(skb, 0);
  285. skb_get(skb);
  286. skb_reset_transport_header(skb);
  287. } else {
  288. skb = alloc_skb(len, gfp);
  289. }
  290. t4_set_arp_err_handler(skb, NULL, NULL);
  291. return skb;
  292. }
  293. static struct net_device *get_real_dev(struct net_device *egress_dev)
  294. {
  295. struct net_device *phys_dev = egress_dev;
  296. if (egress_dev->priv_flags & IFF_802_1Q_VLAN)
  297. phys_dev = vlan_dev_real_dev(egress_dev);
  298. return phys_dev;
  299. }
  300. static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
  301. {
  302. int i;
  303. egress_dev = get_real_dev(egress_dev);
  304. for (i = 0; i < dev->rdev.lldi.nports; i++)
  305. if (dev->rdev.lldi.ports[i] == egress_dev)
  306. return 1;
  307. return 0;
  308. }
  309. static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
  310. __u8 *peer_ip, __be16 local_port,
  311. __be16 peer_port, u8 tos,
  312. __u32 sin6_scope_id)
  313. {
  314. struct dst_entry *dst = NULL;
  315. if (IS_ENABLED(CONFIG_IPV6)) {
  316. struct flowi6 fl6;
  317. memset(&fl6, 0, sizeof(fl6));
  318. memcpy(&fl6.daddr, peer_ip, 16);
  319. memcpy(&fl6.saddr, local_ip, 16);
  320. if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
  321. fl6.flowi6_oif = sin6_scope_id;
  322. dst = ip6_route_output(&init_net, NULL, &fl6);
  323. if (!dst)
  324. goto out;
  325. if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
  326. !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
  327. dst_release(dst);
  328. dst = NULL;
  329. }
  330. }
  331. out:
  332. return dst;
  333. }
  334. static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
  335. __be32 peer_ip, __be16 local_port,
  336. __be16 peer_port, u8 tos)
  337. {
  338. struct rtable *rt;
  339. struct flowi4 fl4;
  340. struct neighbour *n;
  341. rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
  342. peer_port, local_port, IPPROTO_TCP,
  343. tos, 0);
  344. if (IS_ERR(rt))
  345. return NULL;
  346. n = dst_neigh_lookup(&rt->dst, &peer_ip);
  347. if (!n)
  348. return NULL;
  349. if (!our_interface(dev, n->dev)) {
  350. dst_release(&rt->dst);
  351. return NULL;
  352. }
  353. neigh_release(n);
  354. return &rt->dst;
  355. }
  356. static void arp_failure_discard(void *handle, struct sk_buff *skb)
  357. {
  358. PDBG("%s c4iw_dev %p\n", __func__, handle);
  359. kfree_skb(skb);
  360. }
  361. /*
  362. * Handle an ARP failure for an active open.
  363. */
  364. static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
  365. {
  366. printk(KERN_ERR MOD "ARP failure duing connect\n");
  367. kfree_skb(skb);
  368. }
  369. /*
  370. * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
  371. * and send it along.
  372. */
  373. static void abort_arp_failure(void *handle, struct sk_buff *skb)
  374. {
  375. struct c4iw_rdev *rdev = handle;
  376. struct cpl_abort_req *req = cplhdr(skb);
  377. PDBG("%s rdev %p\n", __func__, rdev);
  378. req->cmd = CPL_ABORT_NO_RST;
  379. c4iw_ofld_send(rdev, skb);
  380. }
  381. static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
  382. {
  383. unsigned int flowclen = 80;
  384. struct fw_flowc_wr *flowc;
  385. int i;
  386. skb = get_skb(skb, flowclen, GFP_KERNEL);
  387. flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
  388. flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
  389. FW_FLOWC_WR_NPARAMS(8));
  390. flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
  391. 16)) | FW_WR_FLOWID(ep->hwtid));
  392. flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
  393. flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
  394. flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
  395. flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
  396. flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
  397. flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
  398. flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
  399. flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
  400. flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
  401. flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
  402. flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
  403. flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
  404. flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
  405. flowc->mnemval[6].val = cpu_to_be32(snd_win);
  406. flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
  407. flowc->mnemval[7].val = cpu_to_be32(ep->emss);
  408. /* Pad WR to 16 byte boundary */
  409. flowc->mnemval[8].mnemonic = 0;
  410. flowc->mnemval[8].val = 0;
  411. for (i = 0; i < 9; i++) {
  412. flowc->mnemval[i].r4[0] = 0;
  413. flowc->mnemval[i].r4[1] = 0;
  414. flowc->mnemval[i].r4[2] = 0;
  415. }
  416. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  417. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  418. }
  419. static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
  420. {
  421. struct cpl_close_con_req *req;
  422. struct sk_buff *skb;
  423. int wrlen = roundup(sizeof *req, 16);
  424. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  425. skb = get_skb(NULL, wrlen, gfp);
  426. if (!skb) {
  427. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  428. return -ENOMEM;
  429. }
  430. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  431. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  432. req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
  433. memset(req, 0, wrlen);
  434. INIT_TP_WR(req, ep->hwtid);
  435. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
  436. ep->hwtid));
  437. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  438. }
  439. static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  440. {
  441. struct cpl_abort_req *req;
  442. int wrlen = roundup(sizeof *req, 16);
  443. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  444. skb = get_skb(skb, wrlen, gfp);
  445. if (!skb) {
  446. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  447. __func__);
  448. return -ENOMEM;
  449. }
  450. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  451. t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
  452. req = (struct cpl_abort_req *) skb_put(skb, wrlen);
  453. memset(req, 0, wrlen);
  454. INIT_TP_WR(req, ep->hwtid);
  455. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
  456. req->cmd = CPL_ABORT_SEND_RST;
  457. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  458. }
  459. #define VLAN_NONE 0xfff
  460. #define FILTER_SEL_VLAN_NONE 0xffff
  461. #define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
  462. #define FILTER_SEL_WIDTH_VIN_P_FC \
  463. (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
  464. #define FILTER_SEL_WIDTH_TAG_P_FC \
  465. (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
  466. #define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
  467. static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
  468. struct l2t_entry *l2t)
  469. {
  470. unsigned int ntuple = 0;
  471. u32 viid;
  472. switch (dev->rdev.lldi.filt_mode) {
  473. /* default filter mode */
  474. case HW_TPL_FR_MT_PR_IV_P_FC:
  475. if (l2t->vlan == VLAN_NONE)
  476. ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
  477. else {
  478. ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
  479. ntuple |= 1 << FILTER_SEL_WIDTH_TAG_P_FC;
  480. }
  481. ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
  482. FILTER_SEL_WIDTH_VLD_TAG_P_FC;
  483. break;
  484. case HW_TPL_FR_MT_PR_OV_P_FC: {
  485. viid = cxgb4_port_viid(l2t->neigh->dev);
  486. ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
  487. ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
  488. ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
  489. ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
  490. FILTER_SEL_WIDTH_VLD_TAG_P_FC;
  491. break;
  492. }
  493. default:
  494. break;
  495. }
  496. return ntuple;
  497. }
  498. static int send_connect(struct c4iw_ep *ep)
  499. {
  500. struct cpl_act_open_req *req;
  501. struct cpl_t5_act_open_req *t5_req;
  502. struct cpl_act_open_req6 *req6;
  503. struct cpl_t5_act_open_req6 *t5_req6;
  504. struct sk_buff *skb;
  505. u64 opt0;
  506. u32 opt2;
  507. unsigned int mtu_idx;
  508. int wscale;
  509. int wrlen;
  510. int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
  511. sizeof(struct cpl_act_open_req) :
  512. sizeof(struct cpl_t5_act_open_req);
  513. int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
  514. sizeof(struct cpl_act_open_req6) :
  515. sizeof(struct cpl_t5_act_open_req6);
  516. struct sockaddr_in *la = (struct sockaddr_in *)&ep->com.local_addr;
  517. struct sockaddr_in *ra = (struct sockaddr_in *)&ep->com.remote_addr;
  518. struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  519. struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
  520. wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
  521. roundup(sizev4, 16) :
  522. roundup(sizev6, 16);
  523. PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
  524. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  525. if (!skb) {
  526. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  527. __func__);
  528. return -ENOMEM;
  529. }
  530. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  531. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  532. wscale = compute_wscale(rcv_win);
  533. opt0 = (nocong ? NO_CONG(1) : 0) |
  534. KEEP_ALIVE(1) |
  535. DELACK(1) |
  536. WND_SCALE(wscale) |
  537. MSS_IDX(mtu_idx) |
  538. L2T_IDX(ep->l2t->idx) |
  539. TX_CHAN(ep->tx_chan) |
  540. SMAC_SEL(ep->smac_idx) |
  541. DSCP(ep->tos) |
  542. ULP_MODE(ULP_MODE_TCPDDP) |
  543. RCV_BUFSIZ(rcv_win>>10);
  544. opt2 = RX_CHANNEL(0) |
  545. CCTRL_ECN(enable_ecn) |
  546. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  547. if (enable_tcp_timestamps)
  548. opt2 |= TSTAMPS_EN(1);
  549. if (enable_tcp_sack)
  550. opt2 |= SACK_EN(1);
  551. if (wscale && enable_tcp_window_scaling)
  552. opt2 |= WND_SCALE_EN(1);
  553. t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
  554. if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
  555. if (ep->com.remote_addr.ss_family == AF_INET) {
  556. req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
  557. INIT_TP_WR(req, 0);
  558. OPCODE_TID(req) = cpu_to_be32(
  559. MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  560. ((ep->rss_qid << 14) | ep->atid)));
  561. req->local_port = la->sin_port;
  562. req->peer_port = ra->sin_port;
  563. req->local_ip = la->sin_addr.s_addr;
  564. req->peer_ip = ra->sin_addr.s_addr;
  565. req->opt0 = cpu_to_be64(opt0);
  566. req->params = cpu_to_be32(select_ntuple(ep->com.dev,
  567. ep->dst, ep->l2t));
  568. req->opt2 = cpu_to_be32(opt2);
  569. } else {
  570. req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
  571. INIT_TP_WR(req6, 0);
  572. OPCODE_TID(req6) = cpu_to_be32(
  573. MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
  574. ((ep->rss_qid<<14)|ep->atid)));
  575. req6->local_port = la6->sin6_port;
  576. req6->peer_port = ra6->sin6_port;
  577. req6->local_ip_hi = *((__be64 *)
  578. (la6->sin6_addr.s6_addr));
  579. req6->local_ip_lo = *((__be64 *)
  580. (la6->sin6_addr.s6_addr + 8));
  581. req6->peer_ip_hi = *((__be64 *)
  582. (ra6->sin6_addr.s6_addr));
  583. req6->peer_ip_lo = *((__be64 *)
  584. (ra6->sin6_addr.s6_addr + 8));
  585. req6->opt0 = cpu_to_be64(opt0);
  586. req6->params = cpu_to_be32(
  587. select_ntuple(ep->com.dev, ep->dst,
  588. ep->l2t));
  589. req6->opt2 = cpu_to_be32(opt2);
  590. }
  591. } else {
  592. if (ep->com.remote_addr.ss_family == AF_INET) {
  593. t5_req = (struct cpl_t5_act_open_req *)
  594. skb_put(skb, wrlen);
  595. INIT_TP_WR(t5_req, 0);
  596. OPCODE_TID(t5_req) = cpu_to_be32(
  597. MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  598. ((ep->rss_qid << 14) | ep->atid)));
  599. t5_req->local_port = la->sin_port;
  600. t5_req->peer_port = ra->sin_port;
  601. t5_req->local_ip = la->sin_addr.s_addr;
  602. t5_req->peer_ip = ra->sin_addr.s_addr;
  603. t5_req->opt0 = cpu_to_be64(opt0);
  604. t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
  605. select_ntuple(ep->com.dev,
  606. ep->dst, ep->l2t)));
  607. t5_req->opt2 = cpu_to_be32(opt2);
  608. } else {
  609. t5_req6 = (struct cpl_t5_act_open_req6 *)
  610. skb_put(skb, wrlen);
  611. INIT_TP_WR(t5_req6, 0);
  612. OPCODE_TID(t5_req6) = cpu_to_be32(
  613. MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
  614. ((ep->rss_qid<<14)|ep->atid)));
  615. t5_req6->local_port = la6->sin6_port;
  616. t5_req6->peer_port = ra6->sin6_port;
  617. t5_req6->local_ip_hi = *((__be64 *)
  618. (la6->sin6_addr.s6_addr));
  619. t5_req6->local_ip_lo = *((__be64 *)
  620. (la6->sin6_addr.s6_addr + 8));
  621. t5_req6->peer_ip_hi = *((__be64 *)
  622. (ra6->sin6_addr.s6_addr));
  623. t5_req6->peer_ip_lo = *((__be64 *)
  624. (ra6->sin6_addr.s6_addr + 8));
  625. t5_req6->opt0 = cpu_to_be64(opt0);
  626. t5_req6->params = (__force __be64)cpu_to_be32(
  627. select_ntuple(ep->com.dev, ep->dst, ep->l2t));
  628. t5_req6->opt2 = cpu_to_be32(opt2);
  629. }
  630. }
  631. set_bit(ACT_OPEN_REQ, &ep->com.history);
  632. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  633. }
  634. static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
  635. u8 mpa_rev_to_use)
  636. {
  637. int mpalen, wrlen;
  638. struct fw_ofld_tx_data_wr *req;
  639. struct mpa_message *mpa;
  640. struct mpa_v2_conn_params mpa_v2_params;
  641. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  642. BUG_ON(skb_cloned(skb));
  643. mpalen = sizeof(*mpa) + ep->plen;
  644. if (mpa_rev_to_use == 2)
  645. mpalen += sizeof(struct mpa_v2_conn_params);
  646. wrlen = roundup(mpalen + sizeof *req, 16);
  647. skb = get_skb(skb, wrlen, GFP_KERNEL);
  648. if (!skb) {
  649. connect_reply_upcall(ep, -ENOMEM);
  650. return;
  651. }
  652. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  653. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  654. memset(req, 0, wrlen);
  655. req->op_to_immdlen = cpu_to_be32(
  656. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  657. FW_WR_COMPL(1) |
  658. FW_WR_IMMDLEN(mpalen));
  659. req->flowid_len16 = cpu_to_be32(
  660. FW_WR_FLOWID(ep->hwtid) |
  661. FW_WR_LEN16(wrlen >> 4));
  662. req->plen = cpu_to_be32(mpalen);
  663. req->tunnel_to_proxy = cpu_to_be32(
  664. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  665. FW_OFLD_TX_DATA_WR_SHOVE(1));
  666. mpa = (struct mpa_message *)(req + 1);
  667. memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
  668. mpa->flags = (crc_enabled ? MPA_CRC : 0) |
  669. (markers_enabled ? MPA_MARKERS : 0) |
  670. (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
  671. mpa->private_data_size = htons(ep->plen);
  672. mpa->revision = mpa_rev_to_use;
  673. if (mpa_rev_to_use == 1) {
  674. ep->tried_with_mpa_v1 = 1;
  675. ep->retry_with_mpa_v1 = 0;
  676. }
  677. if (mpa_rev_to_use == 2) {
  678. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  679. sizeof (struct mpa_v2_conn_params));
  680. mpa_v2_params.ird = htons((u16)ep->ird);
  681. mpa_v2_params.ord = htons((u16)ep->ord);
  682. if (peer2peer) {
  683. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  684. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  685. mpa_v2_params.ord |=
  686. htons(MPA_V2_RDMA_WRITE_RTR);
  687. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  688. mpa_v2_params.ord |=
  689. htons(MPA_V2_RDMA_READ_RTR);
  690. }
  691. memcpy(mpa->private_data, &mpa_v2_params,
  692. sizeof(struct mpa_v2_conn_params));
  693. if (ep->plen)
  694. memcpy(mpa->private_data +
  695. sizeof(struct mpa_v2_conn_params),
  696. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  697. } else
  698. if (ep->plen)
  699. memcpy(mpa->private_data,
  700. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  701. /*
  702. * Reference the mpa skb. This ensures the data area
  703. * will remain in memory until the hw acks the tx.
  704. * Function fw4_ack() will deref it.
  705. */
  706. skb_get(skb);
  707. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  708. BUG_ON(ep->mpa_skb);
  709. ep->mpa_skb = skb;
  710. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  711. start_ep_timer(ep);
  712. state_set(&ep->com, MPA_REQ_SENT);
  713. ep->mpa_attr.initiator = 1;
  714. return;
  715. }
  716. static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
  717. {
  718. int mpalen, wrlen;
  719. struct fw_ofld_tx_data_wr *req;
  720. struct mpa_message *mpa;
  721. struct sk_buff *skb;
  722. struct mpa_v2_conn_params mpa_v2_params;
  723. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  724. mpalen = sizeof(*mpa) + plen;
  725. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  726. mpalen += sizeof(struct mpa_v2_conn_params);
  727. wrlen = roundup(mpalen + sizeof *req, 16);
  728. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  729. if (!skb) {
  730. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  731. return -ENOMEM;
  732. }
  733. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  734. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  735. memset(req, 0, wrlen);
  736. req->op_to_immdlen = cpu_to_be32(
  737. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  738. FW_WR_COMPL(1) |
  739. FW_WR_IMMDLEN(mpalen));
  740. req->flowid_len16 = cpu_to_be32(
  741. FW_WR_FLOWID(ep->hwtid) |
  742. FW_WR_LEN16(wrlen >> 4));
  743. req->plen = cpu_to_be32(mpalen);
  744. req->tunnel_to_proxy = cpu_to_be32(
  745. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  746. FW_OFLD_TX_DATA_WR_SHOVE(1));
  747. mpa = (struct mpa_message *)(req + 1);
  748. memset(mpa, 0, sizeof(*mpa));
  749. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  750. mpa->flags = MPA_REJECT;
  751. mpa->revision = ep->mpa_attr.version;
  752. mpa->private_data_size = htons(plen);
  753. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  754. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  755. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  756. sizeof (struct mpa_v2_conn_params));
  757. mpa_v2_params.ird = htons(((u16)ep->ird) |
  758. (peer2peer ? MPA_V2_PEER2PEER_MODEL :
  759. 0));
  760. mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
  761. (p2p_type ==
  762. FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
  763. MPA_V2_RDMA_WRITE_RTR : p2p_type ==
  764. FW_RI_INIT_P2PTYPE_READ_REQ ?
  765. MPA_V2_RDMA_READ_RTR : 0) : 0));
  766. memcpy(mpa->private_data, &mpa_v2_params,
  767. sizeof(struct mpa_v2_conn_params));
  768. if (ep->plen)
  769. memcpy(mpa->private_data +
  770. sizeof(struct mpa_v2_conn_params), pdata, plen);
  771. } else
  772. if (plen)
  773. memcpy(mpa->private_data, pdata, plen);
  774. /*
  775. * Reference the mpa skb again. This ensures the data area
  776. * will remain in memory until the hw acks the tx.
  777. * Function fw4_ack() will deref it.
  778. */
  779. skb_get(skb);
  780. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  781. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  782. BUG_ON(ep->mpa_skb);
  783. ep->mpa_skb = skb;
  784. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  785. }
  786. static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
  787. {
  788. int mpalen, wrlen;
  789. struct fw_ofld_tx_data_wr *req;
  790. struct mpa_message *mpa;
  791. struct sk_buff *skb;
  792. struct mpa_v2_conn_params mpa_v2_params;
  793. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  794. mpalen = sizeof(*mpa) + plen;
  795. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  796. mpalen += sizeof(struct mpa_v2_conn_params);
  797. wrlen = roundup(mpalen + sizeof *req, 16);
  798. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  799. if (!skb) {
  800. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  801. return -ENOMEM;
  802. }
  803. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  804. req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
  805. memset(req, 0, wrlen);
  806. req->op_to_immdlen = cpu_to_be32(
  807. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  808. FW_WR_COMPL(1) |
  809. FW_WR_IMMDLEN(mpalen));
  810. req->flowid_len16 = cpu_to_be32(
  811. FW_WR_FLOWID(ep->hwtid) |
  812. FW_WR_LEN16(wrlen >> 4));
  813. req->plen = cpu_to_be32(mpalen);
  814. req->tunnel_to_proxy = cpu_to_be32(
  815. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  816. FW_OFLD_TX_DATA_WR_SHOVE(1));
  817. mpa = (struct mpa_message *)(req + 1);
  818. memset(mpa, 0, sizeof(*mpa));
  819. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  820. mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
  821. (markers_enabled ? MPA_MARKERS : 0);
  822. mpa->revision = ep->mpa_attr.version;
  823. mpa->private_data_size = htons(plen);
  824. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  825. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  826. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  827. sizeof (struct mpa_v2_conn_params));
  828. mpa_v2_params.ird = htons((u16)ep->ird);
  829. mpa_v2_params.ord = htons((u16)ep->ord);
  830. if (peer2peer && (ep->mpa_attr.p2p_type !=
  831. FW_RI_INIT_P2PTYPE_DISABLED)) {
  832. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  833. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  834. mpa_v2_params.ord |=
  835. htons(MPA_V2_RDMA_WRITE_RTR);
  836. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  837. mpa_v2_params.ord |=
  838. htons(MPA_V2_RDMA_READ_RTR);
  839. }
  840. memcpy(mpa->private_data, &mpa_v2_params,
  841. sizeof(struct mpa_v2_conn_params));
  842. if (ep->plen)
  843. memcpy(mpa->private_data +
  844. sizeof(struct mpa_v2_conn_params), pdata, plen);
  845. } else
  846. if (plen)
  847. memcpy(mpa->private_data, pdata, plen);
  848. /*
  849. * Reference the mpa skb. This ensures the data area
  850. * will remain in memory until the hw acks the tx.
  851. * Function fw4_ack() will deref it.
  852. */
  853. skb_get(skb);
  854. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  855. ep->mpa_skb = skb;
  856. state_set(&ep->com, MPA_REP_SENT);
  857. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  858. }
  859. static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  860. {
  861. struct c4iw_ep *ep;
  862. struct cpl_act_establish *req = cplhdr(skb);
  863. unsigned int tid = GET_TID(req);
  864. unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
  865. struct tid_info *t = dev->rdev.lldi.tids;
  866. ep = lookup_atid(t, atid);
  867. PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
  868. be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
  869. dst_confirm(ep->dst);
  870. /* setup the hwtid for this connection */
  871. ep->hwtid = tid;
  872. cxgb4_insert_tid(t, ep, tid);
  873. insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
  874. ep->snd_seq = be32_to_cpu(req->snd_isn);
  875. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  876. set_emss(ep, ntohs(req->tcp_opt));
  877. /* dealloc the atid */
  878. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
  879. cxgb4_free_atid(t, atid);
  880. set_bit(ACT_ESTAB, &ep->com.history);
  881. /* start MPA negotiation */
  882. send_flowc(ep, NULL);
  883. if (ep->retry_with_mpa_v1)
  884. send_mpa_req(ep, skb, 1);
  885. else
  886. send_mpa_req(ep, skb, mpa_rev);
  887. return 0;
  888. }
  889. static void close_complete_upcall(struct c4iw_ep *ep)
  890. {
  891. struct iw_cm_event event;
  892. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  893. memset(&event, 0, sizeof(event));
  894. event.event = IW_CM_EVENT_CLOSE;
  895. if (ep->com.cm_id) {
  896. PDBG("close complete delivered ep %p cm_id %p tid %u\n",
  897. ep, ep->com.cm_id, ep->hwtid);
  898. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  899. ep->com.cm_id->rem_ref(ep->com.cm_id);
  900. ep->com.cm_id = NULL;
  901. set_bit(CLOSE_UPCALL, &ep->com.history);
  902. }
  903. }
  904. static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  905. {
  906. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  907. close_complete_upcall(ep);
  908. state_set(&ep->com, ABORTING);
  909. set_bit(ABORT_CONN, &ep->com.history);
  910. return send_abort(ep, skb, gfp);
  911. }
  912. static void peer_close_upcall(struct c4iw_ep *ep)
  913. {
  914. struct iw_cm_event event;
  915. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  916. memset(&event, 0, sizeof(event));
  917. event.event = IW_CM_EVENT_DISCONNECT;
  918. if (ep->com.cm_id) {
  919. PDBG("peer close delivered ep %p cm_id %p tid %u\n",
  920. ep, ep->com.cm_id, ep->hwtid);
  921. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  922. set_bit(DISCONN_UPCALL, &ep->com.history);
  923. }
  924. }
  925. static void peer_abort_upcall(struct c4iw_ep *ep)
  926. {
  927. struct iw_cm_event event;
  928. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  929. memset(&event, 0, sizeof(event));
  930. event.event = IW_CM_EVENT_CLOSE;
  931. event.status = -ECONNRESET;
  932. if (ep->com.cm_id) {
  933. PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
  934. ep->com.cm_id, ep->hwtid);
  935. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  936. ep->com.cm_id->rem_ref(ep->com.cm_id);
  937. ep->com.cm_id = NULL;
  938. set_bit(ABORT_UPCALL, &ep->com.history);
  939. }
  940. }
  941. static void connect_reply_upcall(struct c4iw_ep *ep, int status)
  942. {
  943. struct iw_cm_event event;
  944. PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
  945. memset(&event, 0, sizeof(event));
  946. event.event = IW_CM_EVENT_CONNECT_REPLY;
  947. event.status = status;
  948. memcpy(&event.local_addr, &ep->com.local_addr,
  949. sizeof(ep->com.local_addr));
  950. memcpy(&event.remote_addr, &ep->com.remote_addr,
  951. sizeof(ep->com.remote_addr));
  952. if ((status == 0) || (status == -ECONNREFUSED)) {
  953. if (!ep->tried_with_mpa_v1) {
  954. /* this means MPA_v2 is used */
  955. event.private_data_len = ep->plen -
  956. sizeof(struct mpa_v2_conn_params);
  957. event.private_data = ep->mpa_pkt +
  958. sizeof(struct mpa_message) +
  959. sizeof(struct mpa_v2_conn_params);
  960. } else {
  961. /* this means MPA_v1 is used */
  962. event.private_data_len = ep->plen;
  963. event.private_data = ep->mpa_pkt +
  964. sizeof(struct mpa_message);
  965. }
  966. }
  967. PDBG("%s ep %p tid %u status %d\n", __func__, ep,
  968. ep->hwtid, status);
  969. set_bit(CONN_RPL_UPCALL, &ep->com.history);
  970. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  971. if (status < 0) {
  972. ep->com.cm_id->rem_ref(ep->com.cm_id);
  973. ep->com.cm_id = NULL;
  974. }
  975. }
  976. static void connect_request_upcall(struct c4iw_ep *ep)
  977. {
  978. struct iw_cm_event event;
  979. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  980. memset(&event, 0, sizeof(event));
  981. event.event = IW_CM_EVENT_CONNECT_REQUEST;
  982. memcpy(&event.local_addr, &ep->com.local_addr,
  983. sizeof(ep->com.local_addr));
  984. memcpy(&event.remote_addr, &ep->com.remote_addr,
  985. sizeof(ep->com.remote_addr));
  986. event.provider_data = ep;
  987. if (!ep->tried_with_mpa_v1) {
  988. /* this means MPA_v2 is used */
  989. event.ord = ep->ord;
  990. event.ird = ep->ird;
  991. event.private_data_len = ep->plen -
  992. sizeof(struct mpa_v2_conn_params);
  993. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
  994. sizeof(struct mpa_v2_conn_params);
  995. } else {
  996. /* this means MPA_v1 is used. Send max supported */
  997. event.ord = c4iw_max_read_depth;
  998. event.ird = c4iw_max_read_depth;
  999. event.private_data_len = ep->plen;
  1000. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  1001. }
  1002. if (state_read(&ep->parent_ep->com) != DEAD) {
  1003. c4iw_get_ep(&ep->com);
  1004. ep->parent_ep->com.cm_id->event_handler(
  1005. ep->parent_ep->com.cm_id,
  1006. &event);
  1007. }
  1008. set_bit(CONNREQ_UPCALL, &ep->com.history);
  1009. c4iw_put_ep(&ep->parent_ep->com);
  1010. ep->parent_ep = NULL;
  1011. }
  1012. static void established_upcall(struct c4iw_ep *ep)
  1013. {
  1014. struct iw_cm_event event;
  1015. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1016. memset(&event, 0, sizeof(event));
  1017. event.event = IW_CM_EVENT_ESTABLISHED;
  1018. event.ird = ep->ird;
  1019. event.ord = ep->ord;
  1020. if (ep->com.cm_id) {
  1021. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1022. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  1023. set_bit(ESTAB_UPCALL, &ep->com.history);
  1024. }
  1025. }
  1026. static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
  1027. {
  1028. struct cpl_rx_data_ack *req;
  1029. struct sk_buff *skb;
  1030. int wrlen = roundup(sizeof *req, 16);
  1031. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  1032. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  1033. if (!skb) {
  1034. printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
  1035. return 0;
  1036. }
  1037. req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
  1038. memset(req, 0, wrlen);
  1039. INIT_TP_WR(req, ep->hwtid);
  1040. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
  1041. ep->hwtid));
  1042. req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
  1043. F_RX_DACK_CHANGE |
  1044. V_RX_DACK_MODE(dack_mode));
  1045. set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
  1046. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  1047. return credits;
  1048. }
  1049. static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
  1050. {
  1051. struct mpa_message *mpa;
  1052. struct mpa_v2_conn_params *mpa_v2_params;
  1053. u16 plen;
  1054. u16 resp_ird, resp_ord;
  1055. u8 rtr_mismatch = 0, insuff_ird = 0;
  1056. struct c4iw_qp_attributes attrs;
  1057. enum c4iw_qp_attr_mask mask;
  1058. int err;
  1059. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1060. /*
  1061. * Stop mpa timer. If it expired, then the state has
  1062. * changed and we bail since ep_timeout already aborted
  1063. * the connection.
  1064. */
  1065. stop_ep_timer(ep);
  1066. if (state_read(&ep->com) != MPA_REQ_SENT)
  1067. return;
  1068. /*
  1069. * If we get more than the supported amount of private data
  1070. * then we must fail this connection.
  1071. */
  1072. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  1073. err = -EINVAL;
  1074. goto err;
  1075. }
  1076. /*
  1077. * copy the new data into our accumulation buffer.
  1078. */
  1079. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  1080. skb->len);
  1081. ep->mpa_pkt_len += skb->len;
  1082. /*
  1083. * if we don't even have the mpa message, then bail.
  1084. */
  1085. if (ep->mpa_pkt_len < sizeof(*mpa))
  1086. return;
  1087. mpa = (struct mpa_message *) ep->mpa_pkt;
  1088. /* Validate MPA header. */
  1089. if (mpa->revision > mpa_rev) {
  1090. printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
  1091. " Received = %d\n", __func__, mpa_rev, mpa->revision);
  1092. err = -EPROTO;
  1093. goto err;
  1094. }
  1095. if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
  1096. err = -EPROTO;
  1097. goto err;
  1098. }
  1099. plen = ntohs(mpa->private_data_size);
  1100. /*
  1101. * Fail if there's too much private data.
  1102. */
  1103. if (plen > MPA_MAX_PRIVATE_DATA) {
  1104. err = -EPROTO;
  1105. goto err;
  1106. }
  1107. /*
  1108. * If plen does not account for pkt size
  1109. */
  1110. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  1111. err = -EPROTO;
  1112. goto err;
  1113. }
  1114. ep->plen = (u8) plen;
  1115. /*
  1116. * If we don't have all the pdata yet, then bail.
  1117. * We'll continue process when more data arrives.
  1118. */
  1119. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  1120. return;
  1121. if (mpa->flags & MPA_REJECT) {
  1122. err = -ECONNREFUSED;
  1123. goto err;
  1124. }
  1125. /*
  1126. * If we get here we have accumulated the entire mpa
  1127. * start reply message including private data. And
  1128. * the MPA header is valid.
  1129. */
  1130. state_set(&ep->com, FPDU_MODE);
  1131. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  1132. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  1133. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  1134. ep->mpa_attr.version = mpa->revision;
  1135. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1136. if (mpa->revision == 2) {
  1137. ep->mpa_attr.enhanced_rdma_conn =
  1138. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  1139. if (ep->mpa_attr.enhanced_rdma_conn) {
  1140. mpa_v2_params = (struct mpa_v2_conn_params *)
  1141. (ep->mpa_pkt + sizeof(*mpa));
  1142. resp_ird = ntohs(mpa_v2_params->ird) &
  1143. MPA_V2_IRD_ORD_MASK;
  1144. resp_ord = ntohs(mpa_v2_params->ord) &
  1145. MPA_V2_IRD_ORD_MASK;
  1146. /*
  1147. * This is a double-check. Ideally, below checks are
  1148. * not required since ird/ord stuff has been taken
  1149. * care of in c4iw_accept_cr
  1150. */
  1151. if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
  1152. err = -ENOMEM;
  1153. ep->ird = resp_ord;
  1154. ep->ord = resp_ird;
  1155. insuff_ird = 1;
  1156. }
  1157. if (ntohs(mpa_v2_params->ird) &
  1158. MPA_V2_PEER2PEER_MODEL) {
  1159. if (ntohs(mpa_v2_params->ord) &
  1160. MPA_V2_RDMA_WRITE_RTR)
  1161. ep->mpa_attr.p2p_type =
  1162. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  1163. else if (ntohs(mpa_v2_params->ord) &
  1164. MPA_V2_RDMA_READ_RTR)
  1165. ep->mpa_attr.p2p_type =
  1166. FW_RI_INIT_P2PTYPE_READ_REQ;
  1167. }
  1168. }
  1169. } else if (mpa->revision == 1)
  1170. if (peer2peer)
  1171. ep->mpa_attr.p2p_type = p2p_type;
  1172. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  1173. "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
  1174. "%d\n", __func__, ep->mpa_attr.crc_enabled,
  1175. ep->mpa_attr.recv_marker_enabled,
  1176. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  1177. ep->mpa_attr.p2p_type, p2p_type);
  1178. /*
  1179. * If responder's RTR does not match with that of initiator, assign
  1180. * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
  1181. * generated when moving QP to RTS state.
  1182. * A TERM message will be sent after QP has moved to RTS state
  1183. */
  1184. if ((ep->mpa_attr.version == 2) && peer2peer &&
  1185. (ep->mpa_attr.p2p_type != p2p_type)) {
  1186. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1187. rtr_mismatch = 1;
  1188. }
  1189. attrs.mpa_attr = ep->mpa_attr;
  1190. attrs.max_ird = ep->ird;
  1191. attrs.max_ord = ep->ord;
  1192. attrs.llp_stream_handle = ep;
  1193. attrs.next_state = C4IW_QP_STATE_RTS;
  1194. mask = C4IW_QP_ATTR_NEXT_STATE |
  1195. C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
  1196. C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
  1197. /* bind QP and TID with INIT_WR */
  1198. err = c4iw_modify_qp(ep->com.qp->rhp,
  1199. ep->com.qp, mask, &attrs, 1);
  1200. if (err)
  1201. goto err;
  1202. /*
  1203. * If responder's RTR requirement did not match with what initiator
  1204. * supports, generate TERM message
  1205. */
  1206. if (rtr_mismatch) {
  1207. printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
  1208. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1209. attrs.ecode = MPA_NOMATCH_RTR;
  1210. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1211. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1212. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1213. err = -ENOMEM;
  1214. goto out;
  1215. }
  1216. /*
  1217. * Generate TERM if initiator IRD is not sufficient for responder
  1218. * provided ORD. Currently, we do the same behaviour even when
  1219. * responder provided IRD is also not sufficient as regards to
  1220. * initiator ORD.
  1221. */
  1222. if (insuff_ird) {
  1223. printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
  1224. __func__);
  1225. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1226. attrs.ecode = MPA_INSUFF_IRD;
  1227. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1228. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1229. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1230. err = -ENOMEM;
  1231. goto out;
  1232. }
  1233. goto out;
  1234. err:
  1235. state_set(&ep->com, ABORTING);
  1236. send_abort(ep, skb, GFP_KERNEL);
  1237. out:
  1238. connect_reply_upcall(ep, err);
  1239. return;
  1240. }
  1241. static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
  1242. {
  1243. struct mpa_message *mpa;
  1244. struct mpa_v2_conn_params *mpa_v2_params;
  1245. u16 plen;
  1246. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1247. if (state_read(&ep->com) != MPA_REQ_WAIT)
  1248. return;
  1249. /*
  1250. * If we get more than the supported amount of private data
  1251. * then we must fail this connection.
  1252. */
  1253. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  1254. stop_ep_timer(ep);
  1255. abort_connection(ep, skb, GFP_KERNEL);
  1256. return;
  1257. }
  1258. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  1259. /*
  1260. * Copy the new data into our accumulation buffer.
  1261. */
  1262. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  1263. skb->len);
  1264. ep->mpa_pkt_len += skb->len;
  1265. /*
  1266. * If we don't even have the mpa message, then bail.
  1267. * We'll continue process when more data arrives.
  1268. */
  1269. if (ep->mpa_pkt_len < sizeof(*mpa))
  1270. return;
  1271. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  1272. stop_ep_timer(ep);
  1273. mpa = (struct mpa_message *) ep->mpa_pkt;
  1274. /*
  1275. * Validate MPA Header.
  1276. */
  1277. if (mpa->revision > mpa_rev) {
  1278. printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
  1279. " Received = %d\n", __func__, mpa_rev, mpa->revision);
  1280. stop_ep_timer(ep);
  1281. abort_connection(ep, skb, GFP_KERNEL);
  1282. return;
  1283. }
  1284. if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
  1285. stop_ep_timer(ep);
  1286. abort_connection(ep, skb, GFP_KERNEL);
  1287. return;
  1288. }
  1289. plen = ntohs(mpa->private_data_size);
  1290. /*
  1291. * Fail if there's too much private data.
  1292. */
  1293. if (plen > MPA_MAX_PRIVATE_DATA) {
  1294. stop_ep_timer(ep);
  1295. abort_connection(ep, skb, GFP_KERNEL);
  1296. return;
  1297. }
  1298. /*
  1299. * If plen does not account for pkt size
  1300. */
  1301. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  1302. stop_ep_timer(ep);
  1303. abort_connection(ep, skb, GFP_KERNEL);
  1304. return;
  1305. }
  1306. ep->plen = (u8) plen;
  1307. /*
  1308. * If we don't have all the pdata yet, then bail.
  1309. */
  1310. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  1311. return;
  1312. /*
  1313. * If we get here we have accumulated the entire mpa
  1314. * start reply message including private data.
  1315. */
  1316. ep->mpa_attr.initiator = 0;
  1317. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  1318. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  1319. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  1320. ep->mpa_attr.version = mpa->revision;
  1321. if (mpa->revision == 1)
  1322. ep->tried_with_mpa_v1 = 1;
  1323. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1324. if (mpa->revision == 2) {
  1325. ep->mpa_attr.enhanced_rdma_conn =
  1326. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  1327. if (ep->mpa_attr.enhanced_rdma_conn) {
  1328. mpa_v2_params = (struct mpa_v2_conn_params *)
  1329. (ep->mpa_pkt + sizeof(*mpa));
  1330. ep->ird = ntohs(mpa_v2_params->ird) &
  1331. MPA_V2_IRD_ORD_MASK;
  1332. ep->ord = ntohs(mpa_v2_params->ord) &
  1333. MPA_V2_IRD_ORD_MASK;
  1334. if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
  1335. if (peer2peer) {
  1336. if (ntohs(mpa_v2_params->ord) &
  1337. MPA_V2_RDMA_WRITE_RTR)
  1338. ep->mpa_attr.p2p_type =
  1339. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  1340. else if (ntohs(mpa_v2_params->ord) &
  1341. MPA_V2_RDMA_READ_RTR)
  1342. ep->mpa_attr.p2p_type =
  1343. FW_RI_INIT_P2PTYPE_READ_REQ;
  1344. }
  1345. }
  1346. } else if (mpa->revision == 1)
  1347. if (peer2peer)
  1348. ep->mpa_attr.p2p_type = p2p_type;
  1349. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  1350. "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
  1351. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  1352. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  1353. ep->mpa_attr.p2p_type);
  1354. state_set(&ep->com, MPA_REQ_RCVD);
  1355. /* drive upcall */
  1356. connect_request_upcall(ep);
  1357. return;
  1358. }
  1359. static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
  1360. {
  1361. struct c4iw_ep *ep;
  1362. struct cpl_rx_data *hdr = cplhdr(skb);
  1363. unsigned int dlen = ntohs(hdr->len);
  1364. unsigned int tid = GET_TID(hdr);
  1365. struct tid_info *t = dev->rdev.lldi.tids;
  1366. __u8 status = hdr->status;
  1367. ep = lookup_tid(t, tid);
  1368. PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
  1369. skb_pull(skb, sizeof(*hdr));
  1370. skb_trim(skb, dlen);
  1371. /* update RX credits */
  1372. update_rx_credits(ep, dlen);
  1373. switch (state_read(&ep->com)) {
  1374. case MPA_REQ_SENT:
  1375. ep->rcv_seq += dlen;
  1376. process_mpa_reply(ep, skb);
  1377. break;
  1378. case MPA_REQ_WAIT:
  1379. ep->rcv_seq += dlen;
  1380. process_mpa_request(ep, skb);
  1381. break;
  1382. case FPDU_MODE: {
  1383. struct c4iw_qp_attributes attrs;
  1384. BUG_ON(!ep->com.qp);
  1385. if (status)
  1386. pr_err("%s Unexpected streaming data." \
  1387. " qpid %u ep %p state %d tid %u status %d\n",
  1388. __func__, ep->com.qp->wq.sq.qid, ep,
  1389. state_read(&ep->com), ep->hwtid, status);
  1390. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1391. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1392. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1393. break;
  1394. }
  1395. default:
  1396. break;
  1397. }
  1398. return 0;
  1399. }
  1400. static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1401. {
  1402. struct c4iw_ep *ep;
  1403. struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
  1404. int release = 0;
  1405. unsigned int tid = GET_TID(rpl);
  1406. struct tid_info *t = dev->rdev.lldi.tids;
  1407. ep = lookup_tid(t, tid);
  1408. if (!ep) {
  1409. printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
  1410. return 0;
  1411. }
  1412. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1413. mutex_lock(&ep->com.mutex);
  1414. switch (ep->com.state) {
  1415. case ABORTING:
  1416. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1417. __state_set(&ep->com, DEAD);
  1418. release = 1;
  1419. break;
  1420. default:
  1421. printk(KERN_ERR "%s ep %p state %d\n",
  1422. __func__, ep, ep->com.state);
  1423. break;
  1424. }
  1425. mutex_unlock(&ep->com.mutex);
  1426. if (release)
  1427. release_ep_resources(ep);
  1428. return 0;
  1429. }
  1430. static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
  1431. {
  1432. struct sk_buff *skb;
  1433. struct fw_ofld_connection_wr *req;
  1434. unsigned int mtu_idx;
  1435. int wscale;
  1436. struct sockaddr_in *sin;
  1437. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1438. req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
  1439. memset(req, 0, sizeof(*req));
  1440. req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
  1441. req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
  1442. req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
  1443. ep->l2t));
  1444. sin = (struct sockaddr_in *)&ep->com.local_addr;
  1445. req->le.lport = sin->sin_port;
  1446. req->le.u.ipv4.lip = sin->sin_addr.s_addr;
  1447. sin = (struct sockaddr_in *)&ep->com.remote_addr;
  1448. req->le.pport = sin->sin_port;
  1449. req->le.u.ipv4.pip = sin->sin_addr.s_addr;
  1450. req->tcb.t_state_to_astid =
  1451. htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
  1452. V_FW_OFLD_CONNECTION_WR_ASTID(atid));
  1453. req->tcb.cplrxdataack_cplpassacceptrpl =
  1454. htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
  1455. req->tcb.tx_max = (__force __be32) jiffies;
  1456. req->tcb.rcv_adv = htons(1);
  1457. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1458. wscale = compute_wscale(rcv_win);
  1459. req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
  1460. (nocong ? NO_CONG(1) : 0) |
  1461. KEEP_ALIVE(1) |
  1462. DELACK(1) |
  1463. WND_SCALE(wscale) |
  1464. MSS_IDX(mtu_idx) |
  1465. L2T_IDX(ep->l2t->idx) |
  1466. TX_CHAN(ep->tx_chan) |
  1467. SMAC_SEL(ep->smac_idx) |
  1468. DSCP(ep->tos) |
  1469. ULP_MODE(ULP_MODE_TCPDDP) |
  1470. RCV_BUFSIZ(rcv_win >> 10));
  1471. req->tcb.opt2 = (__force __be32) (PACE(1) |
  1472. TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
  1473. RX_CHANNEL(0) |
  1474. CCTRL_ECN(enable_ecn) |
  1475. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
  1476. if (enable_tcp_timestamps)
  1477. req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
  1478. if (enable_tcp_sack)
  1479. req->tcb.opt2 |= (__force __be32) SACK_EN(1);
  1480. if (wscale && enable_tcp_window_scaling)
  1481. req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
  1482. req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
  1483. req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
  1484. set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
  1485. set_bit(ACT_OFLD_CONN, &ep->com.history);
  1486. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1487. }
  1488. /*
  1489. * Return whether a failed active open has allocated a TID
  1490. */
  1491. static inline int act_open_has_tid(int status)
  1492. {
  1493. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1494. status != CPL_ERR_ARP_MISS;
  1495. }
  1496. #define ACT_OPEN_RETRY_COUNT 2
  1497. static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
  1498. struct dst_entry *dst, struct c4iw_dev *cdev,
  1499. bool clear_mpa_v1)
  1500. {
  1501. struct neighbour *n;
  1502. int err, step;
  1503. struct net_device *pdev;
  1504. n = dst_neigh_lookup(dst, peer_ip);
  1505. if (!n)
  1506. return -ENODEV;
  1507. rcu_read_lock();
  1508. err = -ENOMEM;
  1509. if (n->dev->flags & IFF_LOOPBACK) {
  1510. if (iptype == 4)
  1511. pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
  1512. else if (IS_ENABLED(CONFIG_IPV6))
  1513. for_each_netdev(&init_net, pdev) {
  1514. if (ipv6_chk_addr(&init_net,
  1515. (struct in6_addr *)peer_ip,
  1516. pdev, 1))
  1517. break;
  1518. }
  1519. else
  1520. pdev = NULL;
  1521. if (!pdev) {
  1522. err = -ENODEV;
  1523. goto out;
  1524. }
  1525. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1526. n, pdev, 0);
  1527. if (!ep->l2t)
  1528. goto out;
  1529. ep->mtu = pdev->mtu;
  1530. ep->tx_chan = cxgb4_port_chan(pdev);
  1531. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1532. step = cdev->rdev.lldi.ntxq /
  1533. cdev->rdev.lldi.nchan;
  1534. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1535. step = cdev->rdev.lldi.nrxq /
  1536. cdev->rdev.lldi.nchan;
  1537. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  1538. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1539. cxgb4_port_idx(pdev) * step];
  1540. dev_put(pdev);
  1541. } else {
  1542. pdev = get_real_dev(n->dev);
  1543. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1544. n, pdev, 0);
  1545. if (!ep->l2t)
  1546. goto out;
  1547. ep->mtu = dst_mtu(dst);
  1548. ep->tx_chan = cxgb4_port_chan(n->dev);
  1549. ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
  1550. step = cdev->rdev.lldi.ntxq /
  1551. cdev->rdev.lldi.nchan;
  1552. ep->txq_idx = cxgb4_port_idx(n->dev) * step;
  1553. ep->ctrlq_idx = cxgb4_port_idx(n->dev);
  1554. step = cdev->rdev.lldi.nrxq /
  1555. cdev->rdev.lldi.nchan;
  1556. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1557. cxgb4_port_idx(n->dev) * step];
  1558. if (clear_mpa_v1) {
  1559. ep->retry_with_mpa_v1 = 0;
  1560. ep->tried_with_mpa_v1 = 0;
  1561. }
  1562. }
  1563. err = 0;
  1564. out:
  1565. rcu_read_unlock();
  1566. neigh_release(n);
  1567. return err;
  1568. }
  1569. static int c4iw_reconnect(struct c4iw_ep *ep)
  1570. {
  1571. int err = 0;
  1572. struct sockaddr_in *laddr = (struct sockaddr_in *)
  1573. &ep->com.cm_id->local_addr;
  1574. struct sockaddr_in *raddr = (struct sockaddr_in *)
  1575. &ep->com.cm_id->remote_addr;
  1576. struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
  1577. &ep->com.cm_id->local_addr;
  1578. struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
  1579. &ep->com.cm_id->remote_addr;
  1580. int iptype;
  1581. __u8 *ra;
  1582. PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
  1583. init_timer(&ep->timer);
  1584. /*
  1585. * Allocate an active TID to initiate a TCP connection.
  1586. */
  1587. ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
  1588. if (ep->atid == -1) {
  1589. pr_err("%s - cannot alloc atid.\n", __func__);
  1590. err = -ENOMEM;
  1591. goto fail2;
  1592. }
  1593. insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
  1594. /* find a route */
  1595. if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
  1596. ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
  1597. raddr->sin_addr.s_addr, laddr->sin_port,
  1598. raddr->sin_port, 0);
  1599. iptype = 4;
  1600. ra = (__u8 *)&raddr->sin_addr;
  1601. } else {
  1602. ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
  1603. raddr6->sin6_addr.s6_addr,
  1604. laddr6->sin6_port, raddr6->sin6_port, 0,
  1605. raddr6->sin6_scope_id);
  1606. iptype = 6;
  1607. ra = (__u8 *)&raddr6->sin6_addr;
  1608. }
  1609. if (!ep->dst) {
  1610. pr_err("%s - cannot find route.\n", __func__);
  1611. err = -EHOSTUNREACH;
  1612. goto fail3;
  1613. }
  1614. err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
  1615. if (err) {
  1616. pr_err("%s - cannot alloc l2e.\n", __func__);
  1617. goto fail4;
  1618. }
  1619. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  1620. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  1621. ep->l2t->idx);
  1622. state_set(&ep->com, CONNECTING);
  1623. ep->tos = 0;
  1624. /* send connect request to rnic */
  1625. err = send_connect(ep);
  1626. if (!err)
  1627. goto out;
  1628. cxgb4_l2t_release(ep->l2t);
  1629. fail4:
  1630. dst_release(ep->dst);
  1631. fail3:
  1632. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  1633. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  1634. fail2:
  1635. /*
  1636. * remember to send notification to upper layer.
  1637. * We are in here so the upper layer is not aware that this is
  1638. * re-connect attempt and so, upper layer is still waiting for
  1639. * response of 1st connect request.
  1640. */
  1641. connect_reply_upcall(ep, -ECONNRESET);
  1642. c4iw_put_ep(&ep->com);
  1643. out:
  1644. return err;
  1645. }
  1646. static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1647. {
  1648. struct c4iw_ep *ep;
  1649. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1650. unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
  1651. ntohl(rpl->atid_status)));
  1652. struct tid_info *t = dev->rdev.lldi.tids;
  1653. int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
  1654. struct sockaddr_in *la;
  1655. struct sockaddr_in *ra;
  1656. struct sockaddr_in6 *la6;
  1657. struct sockaddr_in6 *ra6;
  1658. ep = lookup_atid(t, atid);
  1659. la = (struct sockaddr_in *)&ep->com.local_addr;
  1660. ra = (struct sockaddr_in *)&ep->com.remote_addr;
  1661. la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  1662. ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
  1663. PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
  1664. status, status2errno(status));
  1665. if (status == CPL_ERR_RTX_NEG_ADVICE) {
  1666. printk(KERN_WARNING MOD "Connection problems for atid %u\n",
  1667. atid);
  1668. return 0;
  1669. }
  1670. set_bit(ACT_OPEN_RPL, &ep->com.history);
  1671. /*
  1672. * Log interesting failures.
  1673. */
  1674. switch (status) {
  1675. case CPL_ERR_CONN_RESET:
  1676. case CPL_ERR_CONN_TIMEDOUT:
  1677. break;
  1678. case CPL_ERR_TCAM_FULL:
  1679. mutex_lock(&dev->rdev.stats.lock);
  1680. dev->rdev.stats.tcam_full++;
  1681. mutex_unlock(&dev->rdev.stats.lock);
  1682. if (ep->com.local_addr.ss_family == AF_INET &&
  1683. dev->rdev.lldi.enable_fw_ofld_conn) {
  1684. send_fw_act_open_req(ep,
  1685. GET_TID_TID(GET_AOPEN_ATID(
  1686. ntohl(rpl->atid_status))));
  1687. return 0;
  1688. }
  1689. break;
  1690. case CPL_ERR_CONN_EXIST:
  1691. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  1692. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  1693. remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
  1694. atid);
  1695. cxgb4_free_atid(t, atid);
  1696. dst_release(ep->dst);
  1697. cxgb4_l2t_release(ep->l2t);
  1698. c4iw_reconnect(ep);
  1699. return 0;
  1700. }
  1701. break;
  1702. default:
  1703. if (ep->com.local_addr.ss_family == AF_INET) {
  1704. pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
  1705. atid, status, status2errno(status),
  1706. &la->sin_addr.s_addr, ntohs(la->sin_port),
  1707. &ra->sin_addr.s_addr, ntohs(ra->sin_port));
  1708. } else {
  1709. pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
  1710. atid, status, status2errno(status),
  1711. la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
  1712. ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
  1713. }
  1714. break;
  1715. }
  1716. connect_reply_upcall(ep, status2errno(status));
  1717. state_set(&ep->com, DEAD);
  1718. if (status && act_open_has_tid(status))
  1719. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
  1720. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
  1721. cxgb4_free_atid(t, atid);
  1722. dst_release(ep->dst);
  1723. cxgb4_l2t_release(ep->l2t);
  1724. c4iw_put_ep(&ep->com);
  1725. return 0;
  1726. }
  1727. static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1728. {
  1729. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1730. struct tid_info *t = dev->rdev.lldi.tids;
  1731. unsigned int stid = GET_TID(rpl);
  1732. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1733. if (!ep) {
  1734. PDBG("%s stid %d lookup failure!\n", __func__, stid);
  1735. goto out;
  1736. }
  1737. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1738. rpl->status, status2errno(rpl->status));
  1739. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1740. out:
  1741. return 0;
  1742. }
  1743. static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1744. {
  1745. struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
  1746. struct tid_info *t = dev->rdev.lldi.tids;
  1747. unsigned int stid = GET_TID(rpl);
  1748. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1749. PDBG("%s ep %p\n", __func__, ep);
  1750. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1751. return 0;
  1752. }
  1753. static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
  1754. struct cpl_pass_accept_req *req)
  1755. {
  1756. struct cpl_pass_accept_rpl *rpl;
  1757. unsigned int mtu_idx;
  1758. u64 opt0;
  1759. u32 opt2;
  1760. int wscale;
  1761. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1762. BUG_ON(skb_cloned(skb));
  1763. skb_trim(skb, sizeof(*rpl));
  1764. skb_get(skb);
  1765. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1766. wscale = compute_wscale(rcv_win);
  1767. opt0 = (nocong ? NO_CONG(1) : 0) |
  1768. KEEP_ALIVE(1) |
  1769. DELACK(1) |
  1770. WND_SCALE(wscale) |
  1771. MSS_IDX(mtu_idx) |
  1772. L2T_IDX(ep->l2t->idx) |
  1773. TX_CHAN(ep->tx_chan) |
  1774. SMAC_SEL(ep->smac_idx) |
  1775. DSCP(ep->tos >> 2) |
  1776. ULP_MODE(ULP_MODE_TCPDDP) |
  1777. RCV_BUFSIZ(rcv_win>>10);
  1778. opt2 = RX_CHANNEL(0) |
  1779. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  1780. if (enable_tcp_timestamps && req->tcpopt.tstamp)
  1781. opt2 |= TSTAMPS_EN(1);
  1782. if (enable_tcp_sack && req->tcpopt.sack)
  1783. opt2 |= SACK_EN(1);
  1784. if (wscale && enable_tcp_window_scaling)
  1785. opt2 |= WND_SCALE_EN(1);
  1786. if (enable_ecn) {
  1787. const struct tcphdr *tcph;
  1788. u32 hlen = ntohl(req->hdr_len);
  1789. tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
  1790. G_IP_HDR_LEN(hlen);
  1791. if (tcph->ece && tcph->cwr)
  1792. opt2 |= CCTRL_ECN(1);
  1793. }
  1794. rpl = cplhdr(skb);
  1795. INIT_TP_WR(rpl, ep->hwtid);
  1796. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1797. ep->hwtid));
  1798. rpl->opt0 = cpu_to_be64(opt0);
  1799. rpl->opt2 = cpu_to_be32(opt2);
  1800. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  1801. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  1802. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1803. return;
  1804. }
  1805. static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
  1806. {
  1807. PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
  1808. BUG_ON(skb_cloned(skb));
  1809. skb_trim(skb, sizeof(struct cpl_tid_release));
  1810. skb_get(skb);
  1811. release_tid(&dev->rdev, hwtid, skb);
  1812. return;
  1813. }
  1814. static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
  1815. __u8 *local_ip, __u8 *peer_ip,
  1816. __be16 *local_port, __be16 *peer_port)
  1817. {
  1818. int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
  1819. int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
  1820. struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
  1821. struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
  1822. struct tcphdr *tcp = (struct tcphdr *)
  1823. ((u8 *)(req + 1) + eth_len + ip_len);
  1824. if (ip->version == 4) {
  1825. PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
  1826. ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
  1827. ntohs(tcp->dest));
  1828. *iptype = 4;
  1829. memcpy(peer_ip, &ip->saddr, 4);
  1830. memcpy(local_ip, &ip->daddr, 4);
  1831. } else {
  1832. PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
  1833. ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
  1834. ntohs(tcp->dest));
  1835. *iptype = 6;
  1836. memcpy(peer_ip, ip6->saddr.s6_addr, 16);
  1837. memcpy(local_ip, ip6->daddr.s6_addr, 16);
  1838. }
  1839. *peer_port = tcp->source;
  1840. *local_port = tcp->dest;
  1841. return;
  1842. }
  1843. static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
  1844. {
  1845. struct c4iw_ep *child_ep = NULL, *parent_ep;
  1846. struct cpl_pass_accept_req *req = cplhdr(skb);
  1847. unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
  1848. struct tid_info *t = dev->rdev.lldi.tids;
  1849. unsigned int hwtid = GET_TID(req);
  1850. struct dst_entry *dst;
  1851. __u8 local_ip[16], peer_ip[16];
  1852. __be16 local_port, peer_port;
  1853. int err;
  1854. u16 peer_mss = ntohs(req->tcpopt.mss);
  1855. int iptype;
  1856. parent_ep = lookup_stid(t, stid);
  1857. if (!parent_ep) {
  1858. PDBG("%s connect request on invalid stid %d\n", __func__, stid);
  1859. goto reject;
  1860. }
  1861. if (state_read(&parent_ep->com) != LISTEN) {
  1862. printk(KERN_ERR "%s - listening ep not in LISTEN\n",
  1863. __func__);
  1864. goto reject;
  1865. }
  1866. get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
  1867. /* Find output route */
  1868. if (iptype == 4) {
  1869. PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
  1870. , __func__, parent_ep, hwtid,
  1871. local_ip, peer_ip, ntohs(local_port),
  1872. ntohs(peer_port), peer_mss);
  1873. dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
  1874. local_port, peer_port,
  1875. GET_POPEN_TOS(ntohl(req->tos_stid)));
  1876. } else {
  1877. PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
  1878. , __func__, parent_ep, hwtid,
  1879. local_ip, peer_ip, ntohs(local_port),
  1880. ntohs(peer_port), peer_mss);
  1881. dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
  1882. PASS_OPEN_TOS(ntohl(req->tos_stid)),
  1883. ((struct sockaddr_in6 *)
  1884. &parent_ep->com.local_addr)->sin6_scope_id);
  1885. }
  1886. if (!dst) {
  1887. printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
  1888. __func__);
  1889. goto reject;
  1890. }
  1891. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1892. if (!child_ep) {
  1893. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1894. __func__);
  1895. dst_release(dst);
  1896. goto reject;
  1897. }
  1898. err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
  1899. if (err) {
  1900. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1901. __func__);
  1902. dst_release(dst);
  1903. kfree(child_ep);
  1904. goto reject;
  1905. }
  1906. if (peer_mss && child_ep->mtu > (peer_mss + 40))
  1907. child_ep->mtu = peer_mss + 40;
  1908. state_set(&child_ep->com, CONNECTING);
  1909. child_ep->com.dev = dev;
  1910. child_ep->com.cm_id = NULL;
  1911. if (iptype == 4) {
  1912. struct sockaddr_in *sin = (struct sockaddr_in *)
  1913. &child_ep->com.local_addr;
  1914. sin->sin_family = PF_INET;
  1915. sin->sin_port = local_port;
  1916. sin->sin_addr.s_addr = *(__be32 *)local_ip;
  1917. sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
  1918. sin->sin_family = PF_INET;
  1919. sin->sin_port = peer_port;
  1920. sin->sin_addr.s_addr = *(__be32 *)peer_ip;
  1921. } else {
  1922. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
  1923. &child_ep->com.local_addr;
  1924. sin6->sin6_family = PF_INET6;
  1925. sin6->sin6_port = local_port;
  1926. memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
  1927. sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
  1928. sin6->sin6_family = PF_INET6;
  1929. sin6->sin6_port = peer_port;
  1930. memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
  1931. }
  1932. c4iw_get_ep(&parent_ep->com);
  1933. child_ep->parent_ep = parent_ep;
  1934. child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
  1935. child_ep->dst = dst;
  1936. child_ep->hwtid = hwtid;
  1937. PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
  1938. child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
  1939. init_timer(&child_ep->timer);
  1940. cxgb4_insert_tid(t, child_ep, hwtid);
  1941. insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
  1942. accept_cr(child_ep, skb, req);
  1943. set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
  1944. goto out;
  1945. reject:
  1946. reject_cr(dev, hwtid, skb);
  1947. out:
  1948. return 0;
  1949. }
  1950. static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  1951. {
  1952. struct c4iw_ep *ep;
  1953. struct cpl_pass_establish *req = cplhdr(skb);
  1954. struct tid_info *t = dev->rdev.lldi.tids;
  1955. unsigned int tid = GET_TID(req);
  1956. ep = lookup_tid(t, tid);
  1957. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1958. ep->snd_seq = be32_to_cpu(req->snd_isn);
  1959. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  1960. PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
  1961. ntohs(req->tcp_opt));
  1962. set_emss(ep, ntohs(req->tcp_opt));
  1963. dst_confirm(ep->dst);
  1964. state_set(&ep->com, MPA_REQ_WAIT);
  1965. start_ep_timer(ep);
  1966. send_flowc(ep, skb);
  1967. set_bit(PASS_ESTAB, &ep->com.history);
  1968. return 0;
  1969. }
  1970. static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
  1971. {
  1972. struct cpl_peer_close *hdr = cplhdr(skb);
  1973. struct c4iw_ep *ep;
  1974. struct c4iw_qp_attributes attrs;
  1975. int disconnect = 1;
  1976. int release = 0;
  1977. struct tid_info *t = dev->rdev.lldi.tids;
  1978. unsigned int tid = GET_TID(hdr);
  1979. int ret;
  1980. ep = lookup_tid(t, tid);
  1981. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1982. dst_confirm(ep->dst);
  1983. set_bit(PEER_CLOSE, &ep->com.history);
  1984. mutex_lock(&ep->com.mutex);
  1985. switch (ep->com.state) {
  1986. case MPA_REQ_WAIT:
  1987. __state_set(&ep->com, CLOSING);
  1988. break;
  1989. case MPA_REQ_SENT:
  1990. __state_set(&ep->com, CLOSING);
  1991. connect_reply_upcall(ep, -ECONNRESET);
  1992. break;
  1993. case MPA_REQ_RCVD:
  1994. /*
  1995. * We're gonna mark this puppy DEAD, but keep
  1996. * the reference on it until the ULP accepts or
  1997. * rejects the CR. Also wake up anyone waiting
  1998. * in rdma connection migration (see c4iw_accept_cr()).
  1999. */
  2000. __state_set(&ep->com, CLOSING);
  2001. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  2002. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2003. break;
  2004. case MPA_REP_SENT:
  2005. __state_set(&ep->com, CLOSING);
  2006. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  2007. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2008. break;
  2009. case FPDU_MODE:
  2010. start_ep_timer(ep);
  2011. __state_set(&ep->com, CLOSING);
  2012. attrs.next_state = C4IW_QP_STATE_CLOSING;
  2013. ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2014. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2015. if (ret != -ECONNRESET) {
  2016. peer_close_upcall(ep);
  2017. disconnect = 1;
  2018. }
  2019. break;
  2020. case ABORTING:
  2021. disconnect = 0;
  2022. break;
  2023. case CLOSING:
  2024. __state_set(&ep->com, MORIBUND);
  2025. disconnect = 0;
  2026. break;
  2027. case MORIBUND:
  2028. stop_ep_timer(ep);
  2029. if (ep->com.cm_id && ep->com.qp) {
  2030. attrs.next_state = C4IW_QP_STATE_IDLE;
  2031. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2032. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2033. }
  2034. close_complete_upcall(ep);
  2035. __state_set(&ep->com, DEAD);
  2036. release = 1;
  2037. disconnect = 0;
  2038. break;
  2039. case DEAD:
  2040. disconnect = 0;
  2041. break;
  2042. default:
  2043. BUG_ON(1);
  2044. }
  2045. mutex_unlock(&ep->com.mutex);
  2046. if (disconnect)
  2047. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  2048. if (release)
  2049. release_ep_resources(ep);
  2050. return 0;
  2051. }
  2052. /*
  2053. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  2054. */
  2055. static int is_neg_adv_abort(unsigned int status)
  2056. {
  2057. return status == CPL_ERR_RTX_NEG_ADVICE ||
  2058. status == CPL_ERR_PERSIST_NEG_ADVICE;
  2059. }
  2060. static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
  2061. {
  2062. struct cpl_abort_req_rss *req = cplhdr(skb);
  2063. struct c4iw_ep *ep;
  2064. struct cpl_abort_rpl *rpl;
  2065. struct sk_buff *rpl_skb;
  2066. struct c4iw_qp_attributes attrs;
  2067. int ret;
  2068. int release = 0;
  2069. struct tid_info *t = dev->rdev.lldi.tids;
  2070. unsigned int tid = GET_TID(req);
  2071. ep = lookup_tid(t, tid);
  2072. if (is_neg_adv_abort(req->status)) {
  2073. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  2074. ep->hwtid);
  2075. return 0;
  2076. }
  2077. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  2078. ep->com.state);
  2079. set_bit(PEER_ABORT, &ep->com.history);
  2080. /*
  2081. * Wake up any threads in rdma_init() or rdma_fini().
  2082. * However, this is not needed if com state is just
  2083. * MPA_REQ_SENT
  2084. */
  2085. if (ep->com.state != MPA_REQ_SENT)
  2086. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2087. mutex_lock(&ep->com.mutex);
  2088. switch (ep->com.state) {
  2089. case CONNECTING:
  2090. break;
  2091. case MPA_REQ_WAIT:
  2092. stop_ep_timer(ep);
  2093. break;
  2094. case MPA_REQ_SENT:
  2095. stop_ep_timer(ep);
  2096. if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
  2097. connect_reply_upcall(ep, -ECONNRESET);
  2098. else {
  2099. /*
  2100. * we just don't send notification upwards because we
  2101. * want to retry with mpa_v1 without upper layers even
  2102. * knowing it.
  2103. *
  2104. * do some housekeeping so as to re-initiate the
  2105. * connection
  2106. */
  2107. PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
  2108. mpa_rev);
  2109. ep->retry_with_mpa_v1 = 1;
  2110. }
  2111. break;
  2112. case MPA_REP_SENT:
  2113. break;
  2114. case MPA_REQ_RCVD:
  2115. break;
  2116. case MORIBUND:
  2117. case CLOSING:
  2118. stop_ep_timer(ep);
  2119. /*FALLTHROUGH*/
  2120. case FPDU_MODE:
  2121. if (ep->com.cm_id && ep->com.qp) {
  2122. attrs.next_state = C4IW_QP_STATE_ERROR;
  2123. ret = c4iw_modify_qp(ep->com.qp->rhp,
  2124. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  2125. &attrs, 1);
  2126. if (ret)
  2127. printk(KERN_ERR MOD
  2128. "%s - qp <- error failed!\n",
  2129. __func__);
  2130. }
  2131. peer_abort_upcall(ep);
  2132. break;
  2133. case ABORTING:
  2134. break;
  2135. case DEAD:
  2136. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  2137. mutex_unlock(&ep->com.mutex);
  2138. return 0;
  2139. default:
  2140. BUG_ON(1);
  2141. break;
  2142. }
  2143. dst_confirm(ep->dst);
  2144. if (ep->com.state != ABORTING) {
  2145. __state_set(&ep->com, DEAD);
  2146. /* we don't release if we want to retry with mpa_v1 */
  2147. if (!ep->retry_with_mpa_v1)
  2148. release = 1;
  2149. }
  2150. mutex_unlock(&ep->com.mutex);
  2151. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  2152. if (!rpl_skb) {
  2153. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  2154. __func__);
  2155. release = 1;
  2156. goto out;
  2157. }
  2158. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  2159. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  2160. INIT_TP_WR(rpl, ep->hwtid);
  2161. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  2162. rpl->cmd = CPL_ABORT_NO_RST;
  2163. c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
  2164. out:
  2165. if (release)
  2166. release_ep_resources(ep);
  2167. else if (ep->retry_with_mpa_v1) {
  2168. remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
  2169. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  2170. dst_release(ep->dst);
  2171. cxgb4_l2t_release(ep->l2t);
  2172. c4iw_reconnect(ep);
  2173. }
  2174. return 0;
  2175. }
  2176. static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2177. {
  2178. struct c4iw_ep *ep;
  2179. struct c4iw_qp_attributes attrs;
  2180. struct cpl_close_con_rpl *rpl = cplhdr(skb);
  2181. int release = 0;
  2182. struct tid_info *t = dev->rdev.lldi.tids;
  2183. unsigned int tid = GET_TID(rpl);
  2184. ep = lookup_tid(t, tid);
  2185. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2186. BUG_ON(!ep);
  2187. /* The cm_id may be null if we failed to connect */
  2188. mutex_lock(&ep->com.mutex);
  2189. switch (ep->com.state) {
  2190. case CLOSING:
  2191. __state_set(&ep->com, MORIBUND);
  2192. break;
  2193. case MORIBUND:
  2194. stop_ep_timer(ep);
  2195. if ((ep->com.cm_id) && (ep->com.qp)) {
  2196. attrs.next_state = C4IW_QP_STATE_IDLE;
  2197. c4iw_modify_qp(ep->com.qp->rhp,
  2198. ep->com.qp,
  2199. C4IW_QP_ATTR_NEXT_STATE,
  2200. &attrs, 1);
  2201. }
  2202. close_complete_upcall(ep);
  2203. __state_set(&ep->com, DEAD);
  2204. release = 1;
  2205. break;
  2206. case ABORTING:
  2207. case DEAD:
  2208. break;
  2209. default:
  2210. BUG_ON(1);
  2211. break;
  2212. }
  2213. mutex_unlock(&ep->com.mutex);
  2214. if (release)
  2215. release_ep_resources(ep);
  2216. return 0;
  2217. }
  2218. static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
  2219. {
  2220. struct cpl_rdma_terminate *rpl = cplhdr(skb);
  2221. struct tid_info *t = dev->rdev.lldi.tids;
  2222. unsigned int tid = GET_TID(rpl);
  2223. struct c4iw_ep *ep;
  2224. struct c4iw_qp_attributes attrs;
  2225. ep = lookup_tid(t, tid);
  2226. BUG_ON(!ep);
  2227. if (ep && ep->com.qp) {
  2228. printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
  2229. ep->com.qp->wq.sq.qid);
  2230. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  2231. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2232. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2233. } else
  2234. printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
  2235. return 0;
  2236. }
  2237. /*
  2238. * Upcall from the adapter indicating data has been transmitted.
  2239. * For us its just the single MPA request or reply. We can now free
  2240. * the skb holding the mpa message.
  2241. */
  2242. static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
  2243. {
  2244. struct c4iw_ep *ep;
  2245. struct cpl_fw4_ack *hdr = cplhdr(skb);
  2246. u8 credits = hdr->credits;
  2247. unsigned int tid = GET_TID(hdr);
  2248. struct tid_info *t = dev->rdev.lldi.tids;
  2249. ep = lookup_tid(t, tid);
  2250. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  2251. if (credits == 0) {
  2252. PDBG("%s 0 credit ack ep %p tid %u state %u\n",
  2253. __func__, ep, ep->hwtid, state_read(&ep->com));
  2254. return 0;
  2255. }
  2256. dst_confirm(ep->dst);
  2257. if (ep->mpa_skb) {
  2258. PDBG("%s last streaming msg ack ep %p tid %u state %u "
  2259. "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
  2260. state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
  2261. kfree_skb(ep->mpa_skb);
  2262. ep->mpa_skb = NULL;
  2263. }
  2264. return 0;
  2265. }
  2266. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  2267. {
  2268. int err;
  2269. struct c4iw_ep *ep = to_ep(cm_id);
  2270. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2271. if (state_read(&ep->com) == DEAD) {
  2272. c4iw_put_ep(&ep->com);
  2273. return -ECONNRESET;
  2274. }
  2275. set_bit(ULP_REJECT, &ep->com.history);
  2276. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  2277. if (mpa_rev == 0)
  2278. abort_connection(ep, NULL, GFP_KERNEL);
  2279. else {
  2280. err = send_mpa_reject(ep, pdata, pdata_len);
  2281. err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  2282. }
  2283. c4iw_put_ep(&ep->com);
  2284. return 0;
  2285. }
  2286. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2287. {
  2288. int err;
  2289. struct c4iw_qp_attributes attrs;
  2290. enum c4iw_qp_attr_mask mask;
  2291. struct c4iw_ep *ep = to_ep(cm_id);
  2292. struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
  2293. struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
  2294. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2295. if (state_read(&ep->com) == DEAD) {
  2296. err = -ECONNRESET;
  2297. goto err;
  2298. }
  2299. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  2300. BUG_ON(!qp);
  2301. set_bit(ULP_ACCEPT, &ep->com.history);
  2302. if ((conn_param->ord > c4iw_max_read_depth) ||
  2303. (conn_param->ird > c4iw_max_read_depth)) {
  2304. abort_connection(ep, NULL, GFP_KERNEL);
  2305. err = -EINVAL;
  2306. goto err;
  2307. }
  2308. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  2309. if (conn_param->ord > ep->ird) {
  2310. ep->ird = conn_param->ird;
  2311. ep->ord = conn_param->ord;
  2312. send_mpa_reject(ep, conn_param->private_data,
  2313. conn_param->private_data_len);
  2314. abort_connection(ep, NULL, GFP_KERNEL);
  2315. err = -ENOMEM;
  2316. goto err;
  2317. }
  2318. if (conn_param->ird > ep->ord) {
  2319. if (!ep->ord)
  2320. conn_param->ird = 1;
  2321. else {
  2322. abort_connection(ep, NULL, GFP_KERNEL);
  2323. err = -ENOMEM;
  2324. goto err;
  2325. }
  2326. }
  2327. }
  2328. ep->ird = conn_param->ird;
  2329. ep->ord = conn_param->ord;
  2330. if (ep->mpa_attr.version != 2)
  2331. if (peer2peer && ep->ird == 0)
  2332. ep->ird = 1;
  2333. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  2334. cm_id->add_ref(cm_id);
  2335. ep->com.cm_id = cm_id;
  2336. ep->com.qp = qp;
  2337. ref_qp(ep);
  2338. /* bind QP to EP and move to RTS */
  2339. attrs.mpa_attr = ep->mpa_attr;
  2340. attrs.max_ird = ep->ird;
  2341. attrs.max_ord = ep->ord;
  2342. attrs.llp_stream_handle = ep;
  2343. attrs.next_state = C4IW_QP_STATE_RTS;
  2344. /* bind QP and TID with INIT_WR */
  2345. mask = C4IW_QP_ATTR_NEXT_STATE |
  2346. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  2347. C4IW_QP_ATTR_MPA_ATTR |
  2348. C4IW_QP_ATTR_MAX_IRD |
  2349. C4IW_QP_ATTR_MAX_ORD;
  2350. err = c4iw_modify_qp(ep->com.qp->rhp,
  2351. ep->com.qp, mask, &attrs, 1);
  2352. if (err)
  2353. goto err1;
  2354. err = send_mpa_reply(ep, conn_param->private_data,
  2355. conn_param->private_data_len);
  2356. if (err)
  2357. goto err1;
  2358. state_set(&ep->com, FPDU_MODE);
  2359. established_upcall(ep);
  2360. c4iw_put_ep(&ep->com);
  2361. return 0;
  2362. err1:
  2363. ep->com.cm_id = NULL;
  2364. cm_id->rem_ref(cm_id);
  2365. err:
  2366. c4iw_put_ep(&ep->com);
  2367. return err;
  2368. }
  2369. static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
  2370. {
  2371. struct in_device *ind;
  2372. int found = 0;
  2373. struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
  2374. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
  2375. ind = in_dev_get(dev->rdev.lldi.ports[0]);
  2376. if (!ind)
  2377. return -EADDRNOTAVAIL;
  2378. for_primary_ifa(ind) {
  2379. laddr->sin_addr.s_addr = ifa->ifa_address;
  2380. raddr->sin_addr.s_addr = ifa->ifa_address;
  2381. found = 1;
  2382. break;
  2383. }
  2384. endfor_ifa(ind);
  2385. in_dev_put(ind);
  2386. return found ? 0 : -EADDRNOTAVAIL;
  2387. }
  2388. static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
  2389. unsigned char banned_flags)
  2390. {
  2391. struct inet6_dev *idev;
  2392. int err = -EADDRNOTAVAIL;
  2393. rcu_read_lock();
  2394. idev = __in6_dev_get(dev);
  2395. if (idev != NULL) {
  2396. struct inet6_ifaddr *ifp;
  2397. read_lock_bh(&idev->lock);
  2398. list_for_each_entry(ifp, &idev->addr_list, if_list) {
  2399. if (ifp->scope == IFA_LINK &&
  2400. !(ifp->flags & banned_flags)) {
  2401. memcpy(addr, &ifp->addr, 16);
  2402. err = 0;
  2403. break;
  2404. }
  2405. }
  2406. read_unlock_bh(&idev->lock);
  2407. }
  2408. rcu_read_unlock();
  2409. return err;
  2410. }
  2411. static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
  2412. {
  2413. struct in6_addr uninitialized_var(addr);
  2414. struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
  2415. struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
  2416. if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
  2417. memcpy(la6->sin6_addr.s6_addr, &addr, 16);
  2418. memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
  2419. return 0;
  2420. }
  2421. return -EADDRNOTAVAIL;
  2422. }
  2423. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2424. {
  2425. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2426. struct c4iw_ep *ep;
  2427. int err = 0;
  2428. struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
  2429. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
  2430. struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr;
  2431. struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
  2432. &cm_id->remote_addr;
  2433. __u8 *ra;
  2434. int iptype;
  2435. if ((conn_param->ord > c4iw_max_read_depth) ||
  2436. (conn_param->ird > c4iw_max_read_depth)) {
  2437. err = -EINVAL;
  2438. goto out;
  2439. }
  2440. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2441. if (!ep) {
  2442. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2443. err = -ENOMEM;
  2444. goto out;
  2445. }
  2446. init_timer(&ep->timer);
  2447. ep->plen = conn_param->private_data_len;
  2448. if (ep->plen)
  2449. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  2450. conn_param->private_data, ep->plen);
  2451. ep->ird = conn_param->ird;
  2452. ep->ord = conn_param->ord;
  2453. if (peer2peer && ep->ord == 0)
  2454. ep->ord = 1;
  2455. cm_id->add_ref(cm_id);
  2456. ep->com.dev = dev;
  2457. ep->com.cm_id = cm_id;
  2458. ep->com.qp = get_qhp(dev, conn_param->qpn);
  2459. if (!ep->com.qp) {
  2460. PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
  2461. err = -EINVAL;
  2462. goto fail2;
  2463. }
  2464. ref_qp(ep);
  2465. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  2466. ep->com.qp, cm_id);
  2467. /*
  2468. * Allocate an active TID to initiate a TCP connection.
  2469. */
  2470. ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
  2471. if (ep->atid == -1) {
  2472. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  2473. err = -ENOMEM;
  2474. goto fail2;
  2475. }
  2476. insert_handle(dev, &dev->atid_idr, ep, ep->atid);
  2477. if (cm_id->remote_addr.ss_family == AF_INET) {
  2478. iptype = 4;
  2479. ra = (__u8 *)&raddr->sin_addr;
  2480. /*
  2481. * Handle loopback requests to INADDR_ANY.
  2482. */
  2483. if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
  2484. err = pick_local_ipaddrs(dev, cm_id);
  2485. if (err)
  2486. goto fail2;
  2487. }
  2488. /* find a route */
  2489. PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
  2490. __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
  2491. ra, ntohs(raddr->sin_port));
  2492. ep->dst = find_route(dev, laddr->sin_addr.s_addr,
  2493. raddr->sin_addr.s_addr, laddr->sin_port,
  2494. raddr->sin_port, 0);
  2495. } else {
  2496. iptype = 6;
  2497. ra = (__u8 *)&raddr6->sin6_addr;
  2498. /*
  2499. * Handle loopback requests to INADDR_ANY.
  2500. */
  2501. if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
  2502. err = pick_local_ip6addrs(dev, cm_id);
  2503. if (err)
  2504. goto fail2;
  2505. }
  2506. /* find a route */
  2507. PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
  2508. __func__, laddr6->sin6_addr.s6_addr,
  2509. ntohs(laddr6->sin6_port),
  2510. raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
  2511. ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
  2512. raddr6->sin6_addr.s6_addr,
  2513. laddr6->sin6_port, raddr6->sin6_port, 0,
  2514. raddr6->sin6_scope_id);
  2515. }
  2516. if (!ep->dst) {
  2517. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  2518. err = -EHOSTUNREACH;
  2519. goto fail3;
  2520. }
  2521. err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
  2522. if (err) {
  2523. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  2524. goto fail4;
  2525. }
  2526. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  2527. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  2528. ep->l2t->idx);
  2529. state_set(&ep->com, CONNECTING);
  2530. ep->tos = 0;
  2531. memcpy(&ep->com.local_addr, &cm_id->local_addr,
  2532. sizeof(ep->com.local_addr));
  2533. memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
  2534. sizeof(ep->com.remote_addr));
  2535. /* send connect request to rnic */
  2536. err = send_connect(ep);
  2537. if (!err)
  2538. goto out;
  2539. cxgb4_l2t_release(ep->l2t);
  2540. fail4:
  2541. dst_release(ep->dst);
  2542. fail3:
  2543. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  2544. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  2545. fail2:
  2546. cm_id->rem_ref(cm_id);
  2547. c4iw_put_ep(&ep->com);
  2548. out:
  2549. return err;
  2550. }
  2551. static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
  2552. {
  2553. int err;
  2554. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  2555. c4iw_init_wr_wait(&ep->com.wr_wait);
  2556. err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
  2557. ep->stid, &sin6->sin6_addr,
  2558. sin6->sin6_port,
  2559. ep->com.dev->rdev.lldi.rxq_ids[0]);
  2560. if (!err)
  2561. err = c4iw_wait_for_reply(&ep->com.dev->rdev,
  2562. &ep->com.wr_wait,
  2563. 0, 0, __func__);
  2564. if (err)
  2565. pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
  2566. err, ep->stid,
  2567. sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
  2568. return err;
  2569. }
  2570. static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
  2571. {
  2572. int err;
  2573. struct sockaddr_in *sin = (struct sockaddr_in *)&ep->com.local_addr;
  2574. if (dev->rdev.lldi.enable_fw_ofld_conn) {
  2575. do {
  2576. err = cxgb4_create_server_filter(
  2577. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2578. sin->sin_addr.s_addr, sin->sin_port, 0,
  2579. ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
  2580. if (err == -EBUSY) {
  2581. set_current_state(TASK_UNINTERRUPTIBLE);
  2582. schedule_timeout(usecs_to_jiffies(100));
  2583. }
  2584. } while (err == -EBUSY);
  2585. } else {
  2586. c4iw_init_wr_wait(&ep->com.wr_wait);
  2587. err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
  2588. ep->stid, sin->sin_addr.s_addr, sin->sin_port,
  2589. 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
  2590. if (!err)
  2591. err = c4iw_wait_for_reply(&ep->com.dev->rdev,
  2592. &ep->com.wr_wait,
  2593. 0, 0, __func__);
  2594. }
  2595. if (err)
  2596. pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
  2597. , err, ep->stid,
  2598. &sin->sin_addr, ntohs(sin->sin_port));
  2599. return err;
  2600. }
  2601. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
  2602. {
  2603. int err = 0;
  2604. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2605. struct c4iw_listen_ep *ep;
  2606. might_sleep();
  2607. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2608. if (!ep) {
  2609. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2610. err = -ENOMEM;
  2611. goto fail1;
  2612. }
  2613. PDBG("%s ep %p\n", __func__, ep);
  2614. cm_id->add_ref(cm_id);
  2615. ep->com.cm_id = cm_id;
  2616. ep->com.dev = dev;
  2617. ep->backlog = backlog;
  2618. memcpy(&ep->com.local_addr, &cm_id->local_addr,
  2619. sizeof(ep->com.local_addr));
  2620. /*
  2621. * Allocate a server TID.
  2622. */
  2623. if (dev->rdev.lldi.enable_fw_ofld_conn)
  2624. ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
  2625. cm_id->local_addr.ss_family, ep);
  2626. else
  2627. ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
  2628. cm_id->local_addr.ss_family, ep);
  2629. if (ep->stid == -1) {
  2630. printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
  2631. err = -ENOMEM;
  2632. goto fail2;
  2633. }
  2634. insert_handle(dev, &dev->stid_idr, ep, ep->stid);
  2635. state_set(&ep->com, LISTEN);
  2636. if (ep->com.local_addr.ss_family == AF_INET)
  2637. err = create_server4(dev, ep);
  2638. else
  2639. err = create_server6(dev, ep);
  2640. if (!err) {
  2641. cm_id->provider_data = ep;
  2642. goto out;
  2643. }
  2644. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
  2645. ep->com.local_addr.ss_family);
  2646. fail2:
  2647. cm_id->rem_ref(cm_id);
  2648. c4iw_put_ep(&ep->com);
  2649. fail1:
  2650. out:
  2651. return err;
  2652. }
  2653. int c4iw_destroy_listen(struct iw_cm_id *cm_id)
  2654. {
  2655. int err;
  2656. struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
  2657. PDBG("%s ep %p\n", __func__, ep);
  2658. might_sleep();
  2659. state_set(&ep->com, DEAD);
  2660. if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
  2661. ep->com.local_addr.ss_family == AF_INET) {
  2662. err = cxgb4_remove_server_filter(
  2663. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2664. ep->com.dev->rdev.lldi.rxq_ids[0], 0);
  2665. } else {
  2666. c4iw_init_wr_wait(&ep->com.wr_wait);
  2667. err = cxgb4_remove_server(
  2668. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2669. ep->com.dev->rdev.lldi.rxq_ids[0], 0);
  2670. if (err)
  2671. goto done;
  2672. err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
  2673. 0, 0, __func__);
  2674. }
  2675. remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
  2676. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
  2677. ep->com.local_addr.ss_family);
  2678. done:
  2679. cm_id->rem_ref(cm_id);
  2680. c4iw_put_ep(&ep->com);
  2681. return err;
  2682. }
  2683. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
  2684. {
  2685. int ret = 0;
  2686. int close = 0;
  2687. int fatal = 0;
  2688. struct c4iw_rdev *rdev;
  2689. mutex_lock(&ep->com.mutex);
  2690. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  2691. states[ep->com.state], abrupt);
  2692. rdev = &ep->com.dev->rdev;
  2693. if (c4iw_fatal_error(rdev)) {
  2694. fatal = 1;
  2695. close_complete_upcall(ep);
  2696. ep->com.state = DEAD;
  2697. }
  2698. switch (ep->com.state) {
  2699. case MPA_REQ_WAIT:
  2700. case MPA_REQ_SENT:
  2701. case MPA_REQ_RCVD:
  2702. case MPA_REP_SENT:
  2703. case FPDU_MODE:
  2704. close = 1;
  2705. if (abrupt)
  2706. ep->com.state = ABORTING;
  2707. else {
  2708. ep->com.state = CLOSING;
  2709. start_ep_timer(ep);
  2710. }
  2711. set_bit(CLOSE_SENT, &ep->com.flags);
  2712. break;
  2713. case CLOSING:
  2714. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  2715. close = 1;
  2716. if (abrupt) {
  2717. stop_ep_timer(ep);
  2718. ep->com.state = ABORTING;
  2719. } else
  2720. ep->com.state = MORIBUND;
  2721. }
  2722. break;
  2723. case MORIBUND:
  2724. case ABORTING:
  2725. case DEAD:
  2726. PDBG("%s ignoring disconnect ep %p state %u\n",
  2727. __func__, ep, ep->com.state);
  2728. break;
  2729. default:
  2730. BUG();
  2731. break;
  2732. }
  2733. if (close) {
  2734. if (abrupt) {
  2735. set_bit(EP_DISC_ABORT, &ep->com.history);
  2736. close_complete_upcall(ep);
  2737. ret = send_abort(ep, NULL, gfp);
  2738. } else {
  2739. set_bit(EP_DISC_CLOSE, &ep->com.history);
  2740. ret = send_halfclose(ep, gfp);
  2741. }
  2742. if (ret)
  2743. fatal = 1;
  2744. }
  2745. mutex_unlock(&ep->com.mutex);
  2746. if (fatal)
  2747. release_ep_resources(ep);
  2748. return ret;
  2749. }
  2750. static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  2751. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  2752. {
  2753. struct c4iw_ep *ep;
  2754. int atid = be32_to_cpu(req->tid);
  2755. ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
  2756. (__force u32) req->tid);
  2757. if (!ep)
  2758. return;
  2759. switch (req->retval) {
  2760. case FW_ENOMEM:
  2761. set_bit(ACT_RETRY_NOMEM, &ep->com.history);
  2762. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  2763. send_fw_act_open_req(ep, atid);
  2764. return;
  2765. }
  2766. case FW_EADDRINUSE:
  2767. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  2768. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  2769. send_fw_act_open_req(ep, atid);
  2770. return;
  2771. }
  2772. break;
  2773. default:
  2774. pr_info("%s unexpected ofld conn wr retval %d\n",
  2775. __func__, req->retval);
  2776. break;
  2777. }
  2778. pr_err("active ofld_connect_wr failure %d atid %d\n",
  2779. req->retval, atid);
  2780. mutex_lock(&dev->rdev.stats.lock);
  2781. dev->rdev.stats.act_ofld_conn_fails++;
  2782. mutex_unlock(&dev->rdev.stats.lock);
  2783. connect_reply_upcall(ep, status2errno(req->retval));
  2784. state_set(&ep->com, DEAD);
  2785. remove_handle(dev, &dev->atid_idr, atid);
  2786. cxgb4_free_atid(dev->rdev.lldi.tids, atid);
  2787. dst_release(ep->dst);
  2788. cxgb4_l2t_release(ep->l2t);
  2789. c4iw_put_ep(&ep->com);
  2790. }
  2791. static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  2792. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  2793. {
  2794. struct sk_buff *rpl_skb;
  2795. struct cpl_pass_accept_req *cpl;
  2796. int ret;
  2797. rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
  2798. BUG_ON(!rpl_skb);
  2799. if (req->retval) {
  2800. PDBG("%s passive open failure %d\n", __func__, req->retval);
  2801. mutex_lock(&dev->rdev.stats.lock);
  2802. dev->rdev.stats.pas_ofld_conn_fails++;
  2803. mutex_unlock(&dev->rdev.stats.lock);
  2804. kfree_skb(rpl_skb);
  2805. } else {
  2806. cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
  2807. OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
  2808. (__force u32) htonl(
  2809. (__force u32) req->tid)));
  2810. ret = pass_accept_req(dev, rpl_skb);
  2811. if (!ret)
  2812. kfree_skb(rpl_skb);
  2813. }
  2814. return;
  2815. }
  2816. static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  2817. {
  2818. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2819. struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
  2820. switch (rpl->type) {
  2821. case FW6_TYPE_CQE:
  2822. c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
  2823. break;
  2824. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  2825. req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
  2826. switch (req->t_state) {
  2827. case TCP_SYN_SENT:
  2828. active_ofld_conn_reply(dev, skb, req);
  2829. break;
  2830. case TCP_SYN_RECV:
  2831. passive_ofld_conn_reply(dev, skb, req);
  2832. break;
  2833. default:
  2834. pr_err("%s unexpected ofld conn wr state %d\n",
  2835. __func__, req->t_state);
  2836. break;
  2837. }
  2838. break;
  2839. }
  2840. return 0;
  2841. }
  2842. static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
  2843. {
  2844. u32 l2info;
  2845. u16 vlantag, len, hdr_len, eth_hdr_len;
  2846. u8 intf;
  2847. struct cpl_rx_pkt *cpl = cplhdr(skb);
  2848. struct cpl_pass_accept_req *req;
  2849. struct tcp_options_received tmp_opt;
  2850. struct c4iw_dev *dev;
  2851. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  2852. /* Store values from cpl_rx_pkt in temporary location. */
  2853. vlantag = (__force u16) cpl->vlan;
  2854. len = (__force u16) cpl->len;
  2855. l2info = (__force u32) cpl->l2info;
  2856. hdr_len = (__force u16) cpl->hdr_len;
  2857. intf = cpl->iff;
  2858. __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
  2859. /*
  2860. * We need to parse the TCP options from SYN packet.
  2861. * to generate cpl_pass_accept_req.
  2862. */
  2863. memset(&tmp_opt, 0, sizeof(tmp_opt));
  2864. tcp_clear_options(&tmp_opt);
  2865. tcp_parse_options(skb, &tmp_opt, 0, NULL);
  2866. req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
  2867. memset(req, 0, sizeof(*req));
  2868. req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
  2869. V_SYN_MAC_IDX(G_RX_MACIDX(
  2870. (__force int) htonl(l2info))) |
  2871. F_SYN_XACT_MATCH);
  2872. eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
  2873. G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
  2874. G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
  2875. req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
  2876. (__force int) htonl(l2info))) |
  2877. V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
  2878. (__force int) htons(hdr_len))) |
  2879. V_IP_HDR_LEN(G_RX_IPHDR_LEN(
  2880. (__force int) htons(hdr_len))) |
  2881. V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
  2882. req->vlan = (__force __be16) vlantag;
  2883. req->len = (__force __be16) len;
  2884. req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
  2885. PASS_OPEN_TOS(tos));
  2886. req->tcpopt.mss = htons(tmp_opt.mss_clamp);
  2887. if (tmp_opt.wscale_ok)
  2888. req->tcpopt.wsf = tmp_opt.snd_wscale;
  2889. req->tcpopt.tstamp = tmp_opt.saw_tstamp;
  2890. if (tmp_opt.sack_ok)
  2891. req->tcpopt.sack = 1;
  2892. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
  2893. return;
  2894. }
  2895. static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
  2896. __be32 laddr, __be16 lport,
  2897. __be32 raddr, __be16 rport,
  2898. u32 rcv_isn, u32 filter, u16 window,
  2899. u32 rss_qid, u8 port_id)
  2900. {
  2901. struct sk_buff *req_skb;
  2902. struct fw_ofld_connection_wr *req;
  2903. struct cpl_pass_accept_req *cpl = cplhdr(skb);
  2904. req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
  2905. req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
  2906. memset(req, 0, sizeof(*req));
  2907. req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
  2908. req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
  2909. req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
  2910. req->le.filter = (__force __be32) filter;
  2911. req->le.lport = lport;
  2912. req->le.pport = rport;
  2913. req->le.u.ipv4.lip = laddr;
  2914. req->le.u.ipv4.pip = raddr;
  2915. req->tcb.rcv_nxt = htonl(rcv_isn + 1);
  2916. req->tcb.rcv_adv = htons(window);
  2917. req->tcb.t_state_to_astid =
  2918. htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
  2919. V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
  2920. V_FW_OFLD_CONNECTION_WR_ASTID(
  2921. GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
  2922. /*
  2923. * We store the qid in opt2 which will be used by the firmware
  2924. * to send us the wr response.
  2925. */
  2926. req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
  2927. /*
  2928. * We initialize the MSS index in TCB to 0xF.
  2929. * So that when driver sends cpl_pass_accept_rpl
  2930. * TCB picks up the correct value. If this was 0
  2931. * TP will ignore any value > 0 for MSS index.
  2932. */
  2933. req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
  2934. req->cookie = (unsigned long)skb;
  2935. set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
  2936. cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
  2937. }
  2938. /*
  2939. * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
  2940. * messages when a filter is being used instead of server to
  2941. * redirect a syn packet. When packets hit filter they are redirected
  2942. * to the offload queue and driver tries to establish the connection
  2943. * using firmware work request.
  2944. */
  2945. static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
  2946. {
  2947. int stid;
  2948. unsigned int filter;
  2949. struct ethhdr *eh = NULL;
  2950. struct vlan_ethhdr *vlan_eh = NULL;
  2951. struct iphdr *iph;
  2952. struct tcphdr *tcph;
  2953. struct rss_header *rss = (void *)skb->data;
  2954. struct cpl_rx_pkt *cpl = (void *)skb->data;
  2955. struct cpl_pass_accept_req *req = (void *)(rss + 1);
  2956. struct l2t_entry *e;
  2957. struct dst_entry *dst;
  2958. struct c4iw_ep *lep;
  2959. u16 window;
  2960. struct port_info *pi;
  2961. struct net_device *pdev;
  2962. u16 rss_qid, eth_hdr_len;
  2963. int step;
  2964. u32 tx_chan;
  2965. struct neighbour *neigh;
  2966. /* Drop all non-SYN packets */
  2967. if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
  2968. goto reject;
  2969. /*
  2970. * Drop all packets which did not hit the filter.
  2971. * Unlikely to happen.
  2972. */
  2973. if (!(rss->filter_hit && rss->filter_tid))
  2974. goto reject;
  2975. /*
  2976. * Calculate the server tid from filter hit index from cpl_rx_pkt.
  2977. */
  2978. stid = (__force int) cpu_to_be32((__force u32) rss->hash_val)
  2979. - dev->rdev.lldi.tids->sftid_base
  2980. + dev->rdev.lldi.tids->nstids;
  2981. lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
  2982. if (!lep) {
  2983. PDBG("%s connect request on invalid stid %d\n", __func__, stid);
  2984. goto reject;
  2985. }
  2986. eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
  2987. G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
  2988. G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
  2989. if (eth_hdr_len == ETH_HLEN) {
  2990. eh = (struct ethhdr *)(req + 1);
  2991. iph = (struct iphdr *)(eh + 1);
  2992. } else {
  2993. vlan_eh = (struct vlan_ethhdr *)(req + 1);
  2994. iph = (struct iphdr *)(vlan_eh + 1);
  2995. skb->vlan_tci = ntohs(cpl->vlan);
  2996. }
  2997. if (iph->version != 0x4)
  2998. goto reject;
  2999. tcph = (struct tcphdr *)(iph + 1);
  3000. skb_set_network_header(skb, (void *)iph - (void *)rss);
  3001. skb_set_transport_header(skb, (void *)tcph - (void *)rss);
  3002. skb_get(skb);
  3003. PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
  3004. ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
  3005. ntohs(tcph->source), iph->tos);
  3006. dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
  3007. iph->tos);
  3008. if (!dst) {
  3009. pr_err("%s - failed to find dst entry!\n",
  3010. __func__);
  3011. goto reject;
  3012. }
  3013. neigh = dst_neigh_lookup_skb(dst, skb);
  3014. if (!neigh) {
  3015. pr_err("%s - failed to allocate neigh!\n",
  3016. __func__);
  3017. goto free_dst;
  3018. }
  3019. if (neigh->dev->flags & IFF_LOOPBACK) {
  3020. pdev = ip_dev_find(&init_net, iph->daddr);
  3021. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  3022. pdev, 0);
  3023. pi = (struct port_info *)netdev_priv(pdev);
  3024. tx_chan = cxgb4_port_chan(pdev);
  3025. dev_put(pdev);
  3026. } else {
  3027. pdev = get_real_dev(neigh->dev);
  3028. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  3029. pdev, 0);
  3030. pi = (struct port_info *)netdev_priv(pdev);
  3031. tx_chan = cxgb4_port_chan(pdev);
  3032. }
  3033. if (!e) {
  3034. pr_err("%s - failed to allocate l2t entry!\n",
  3035. __func__);
  3036. goto free_dst;
  3037. }
  3038. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  3039. rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
  3040. window = (__force u16) htons((__force u16)tcph->window);
  3041. /* Calcuate filter portion for LE region. */
  3042. filter = (__force unsigned int) cpu_to_be32(select_ntuple(dev, dst, e));
  3043. /*
  3044. * Synthesize the cpl_pass_accept_req. We have everything except the
  3045. * TID. Once firmware sends a reply with TID we update the TID field
  3046. * in cpl and pass it through the regular cpl_pass_accept_req path.
  3047. */
  3048. build_cpl_pass_accept_req(skb, stid, iph->tos);
  3049. send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
  3050. tcph->source, ntohl(tcph->seq), filter, window,
  3051. rss_qid, pi->port_id);
  3052. cxgb4_l2t_release(e);
  3053. free_dst:
  3054. dst_release(dst);
  3055. reject:
  3056. return 0;
  3057. }
  3058. /*
  3059. * These are the real handlers that are called from a
  3060. * work queue.
  3061. */
  3062. static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
  3063. [CPL_ACT_ESTABLISH] = act_establish,
  3064. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  3065. [CPL_RX_DATA] = rx_data,
  3066. [CPL_ABORT_RPL_RSS] = abort_rpl,
  3067. [CPL_ABORT_RPL] = abort_rpl,
  3068. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  3069. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  3070. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  3071. [CPL_PASS_ESTABLISH] = pass_establish,
  3072. [CPL_PEER_CLOSE] = peer_close,
  3073. [CPL_ABORT_REQ_RSS] = peer_abort,
  3074. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  3075. [CPL_RDMA_TERMINATE] = terminate,
  3076. [CPL_FW4_ACK] = fw4_ack,
  3077. [CPL_FW6_MSG] = deferred_fw6_msg,
  3078. [CPL_RX_PKT] = rx_pkt
  3079. };
  3080. static void process_timeout(struct c4iw_ep *ep)
  3081. {
  3082. struct c4iw_qp_attributes attrs;
  3083. int abort = 1;
  3084. mutex_lock(&ep->com.mutex);
  3085. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  3086. ep->com.state);
  3087. set_bit(TIMEDOUT, &ep->com.history);
  3088. switch (ep->com.state) {
  3089. case MPA_REQ_SENT:
  3090. __state_set(&ep->com, ABORTING);
  3091. connect_reply_upcall(ep, -ETIMEDOUT);
  3092. break;
  3093. case MPA_REQ_WAIT:
  3094. __state_set(&ep->com, ABORTING);
  3095. break;
  3096. case CLOSING:
  3097. case MORIBUND:
  3098. if (ep->com.cm_id && ep->com.qp) {
  3099. attrs.next_state = C4IW_QP_STATE_ERROR;
  3100. c4iw_modify_qp(ep->com.qp->rhp,
  3101. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  3102. &attrs, 1);
  3103. }
  3104. __state_set(&ep->com, ABORTING);
  3105. break;
  3106. default:
  3107. WARN(1, "%s unexpected state ep %p tid %u state %u\n",
  3108. __func__, ep, ep->hwtid, ep->com.state);
  3109. abort = 0;
  3110. }
  3111. mutex_unlock(&ep->com.mutex);
  3112. if (abort)
  3113. abort_connection(ep, NULL, GFP_KERNEL);
  3114. c4iw_put_ep(&ep->com);
  3115. }
  3116. static void process_timedout_eps(void)
  3117. {
  3118. struct c4iw_ep *ep;
  3119. spin_lock_irq(&timeout_lock);
  3120. while (!list_empty(&timeout_list)) {
  3121. struct list_head *tmp;
  3122. tmp = timeout_list.next;
  3123. list_del(tmp);
  3124. spin_unlock_irq(&timeout_lock);
  3125. ep = list_entry(tmp, struct c4iw_ep, entry);
  3126. process_timeout(ep);
  3127. spin_lock_irq(&timeout_lock);
  3128. }
  3129. spin_unlock_irq(&timeout_lock);
  3130. }
  3131. static void process_work(struct work_struct *work)
  3132. {
  3133. struct sk_buff *skb = NULL;
  3134. struct c4iw_dev *dev;
  3135. struct cpl_act_establish *rpl;
  3136. unsigned int opcode;
  3137. int ret;
  3138. while ((skb = skb_dequeue(&rxq))) {
  3139. rpl = cplhdr(skb);
  3140. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  3141. opcode = rpl->ot.opcode;
  3142. BUG_ON(!work_handlers[opcode]);
  3143. ret = work_handlers[opcode](dev, skb);
  3144. if (!ret)
  3145. kfree_skb(skb);
  3146. }
  3147. process_timedout_eps();
  3148. }
  3149. static DECLARE_WORK(skb_work, process_work);
  3150. static void ep_timeout(unsigned long arg)
  3151. {
  3152. struct c4iw_ep *ep = (struct c4iw_ep *)arg;
  3153. int kickit = 0;
  3154. spin_lock(&timeout_lock);
  3155. if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
  3156. list_add_tail(&ep->entry, &timeout_list);
  3157. kickit = 1;
  3158. }
  3159. spin_unlock(&timeout_lock);
  3160. if (kickit)
  3161. queue_work(workq, &skb_work);
  3162. }
  3163. /*
  3164. * All the CM events are handled on a work queue to have a safe context.
  3165. */
  3166. static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
  3167. {
  3168. /*
  3169. * Save dev in the skb->cb area.
  3170. */
  3171. *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
  3172. /*
  3173. * Queue the skb and schedule the worker thread.
  3174. */
  3175. skb_queue_tail(&rxq, skb);
  3176. queue_work(workq, &skb_work);
  3177. return 0;
  3178. }
  3179. static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  3180. {
  3181. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  3182. if (rpl->status != CPL_ERR_NONE) {
  3183. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  3184. "for tid %u\n", rpl->status, GET_TID(rpl));
  3185. }
  3186. kfree_skb(skb);
  3187. return 0;
  3188. }
  3189. static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  3190. {
  3191. struct cpl_fw6_msg *rpl = cplhdr(skb);
  3192. struct c4iw_wr_wait *wr_waitp;
  3193. int ret;
  3194. PDBG("%s type %u\n", __func__, rpl->type);
  3195. switch (rpl->type) {
  3196. case FW6_TYPE_WR_RPL:
  3197. ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
  3198. wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
  3199. PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
  3200. if (wr_waitp)
  3201. c4iw_wake_up(wr_waitp, ret ? -ret : 0);
  3202. kfree_skb(skb);
  3203. break;
  3204. case FW6_TYPE_CQE:
  3205. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  3206. sched(dev, skb);
  3207. break;
  3208. default:
  3209. printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
  3210. rpl->type);
  3211. kfree_skb(skb);
  3212. break;
  3213. }
  3214. return 0;
  3215. }
  3216. static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
  3217. {
  3218. struct cpl_abort_req_rss *req = cplhdr(skb);
  3219. struct c4iw_ep *ep;
  3220. struct tid_info *t = dev->rdev.lldi.tids;
  3221. unsigned int tid = GET_TID(req);
  3222. ep = lookup_tid(t, tid);
  3223. if (!ep) {
  3224. printk(KERN_WARNING MOD
  3225. "Abort on non-existent endpoint, tid %d\n", tid);
  3226. kfree_skb(skb);
  3227. return 0;
  3228. }
  3229. if (is_neg_adv_abort(req->status)) {
  3230. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  3231. ep->hwtid);
  3232. kfree_skb(skb);
  3233. return 0;
  3234. }
  3235. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  3236. ep->com.state);
  3237. /*
  3238. * Wake up any threads in rdma_init() or rdma_fini().
  3239. * However, if we are on MPAv2 and want to retry with MPAv1
  3240. * then, don't wake up yet.
  3241. */
  3242. if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
  3243. if (ep->com.state != MPA_REQ_SENT)
  3244. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  3245. } else
  3246. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  3247. sched(dev, skb);
  3248. return 0;
  3249. }
  3250. /*
  3251. * Most upcalls from the T4 Core go to sched() to
  3252. * schedule the processing on a work queue.
  3253. */
  3254. c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
  3255. [CPL_ACT_ESTABLISH] = sched,
  3256. [CPL_ACT_OPEN_RPL] = sched,
  3257. [CPL_RX_DATA] = sched,
  3258. [CPL_ABORT_RPL_RSS] = sched,
  3259. [CPL_ABORT_RPL] = sched,
  3260. [CPL_PASS_OPEN_RPL] = sched,
  3261. [CPL_CLOSE_LISTSRV_RPL] = sched,
  3262. [CPL_PASS_ACCEPT_REQ] = sched,
  3263. [CPL_PASS_ESTABLISH] = sched,
  3264. [CPL_PEER_CLOSE] = sched,
  3265. [CPL_CLOSE_CON_RPL] = sched,
  3266. [CPL_ABORT_REQ_RSS] = peer_abort_intr,
  3267. [CPL_RDMA_TERMINATE] = sched,
  3268. [CPL_FW4_ACK] = sched,
  3269. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  3270. [CPL_FW6_MSG] = fw6_msg,
  3271. [CPL_RX_PKT] = sched
  3272. };
  3273. int __init c4iw_cm_init(void)
  3274. {
  3275. spin_lock_init(&timeout_lock);
  3276. skb_queue_head_init(&rxq);
  3277. workq = create_singlethread_workqueue("iw_cxgb4");
  3278. if (!workq)
  3279. return -ENOMEM;
  3280. return 0;
  3281. }
  3282. void __exit c4iw_cm_term(void)
  3283. {
  3284. WARN_ON(!list_empty(&timeout_list));
  3285. flush_workqueue(workq);
  3286. destroy_workqueue(workq);
  3287. }