cm.c 114 KB

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