cm.c 108 KB

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