cxgb4_main.c 160 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  35. #include <linux/bitmap.h>
  36. #include <linux/crc32.h>
  37. #include <linux/ctype.h>
  38. #include <linux/debugfs.h>
  39. #include <linux/err.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/firmware.h>
  42. #include <linux/if.h>
  43. #include <linux/if_vlan.h>
  44. #include <linux/init.h>
  45. #include <linux/log2.h>
  46. #include <linux/mdio.h>
  47. #include <linux/module.h>
  48. #include <linux/moduleparam.h>
  49. #include <linux/mutex.h>
  50. #include <linux/netdevice.h>
  51. #include <linux/pci.h>
  52. #include <linux/aer.h>
  53. #include <linux/rtnetlink.h>
  54. #include <linux/sched.h>
  55. #include <linux/seq_file.h>
  56. #include <linux/sockios.h>
  57. #include <linux/vmalloc.h>
  58. #include <linux/workqueue.h>
  59. #include <net/neighbour.h>
  60. #include <net/netevent.h>
  61. #include <net/addrconf.h>
  62. #include <net/bonding.h>
  63. #include <net/addrconf.h>
  64. #include <linux/uaccess.h>
  65. #include <linux/crash_dump.h>
  66. #include <net/udp_tunnel.h>
  67. #include "cxgb4.h"
  68. #include "cxgb4_filter.h"
  69. #include "t4_regs.h"
  70. #include "t4_values.h"
  71. #include "t4_msg.h"
  72. #include "t4fw_api.h"
  73. #include "t4fw_version.h"
  74. #include "cxgb4_dcb.h"
  75. #include "srq.h"
  76. #include "cxgb4_debugfs.h"
  77. #include "clip_tbl.h"
  78. #include "l2t.h"
  79. #include "smt.h"
  80. #include "sched.h"
  81. #include "cxgb4_tc_u32.h"
  82. #include "cxgb4_tc_flower.h"
  83. #include "cxgb4_ptp.h"
  84. #include "cxgb4_cudbg.h"
  85. char cxgb4_driver_name[] = KBUILD_MODNAME;
  86. #ifdef DRV_VERSION
  87. #undef DRV_VERSION
  88. #endif
  89. #define DRV_VERSION "2.0.0-ko"
  90. const char cxgb4_driver_version[] = DRV_VERSION;
  91. #define DRV_DESC "Chelsio T4/T5/T6 Network Driver"
  92. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  93. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  94. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  95. /* Macros needed to support the PCI Device ID Table ...
  96. */
  97. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
  98. static const struct pci_device_id cxgb4_pci_tbl[] = {
  99. #define CXGB4_UNIFIED_PF 0x4
  100. #define CH_PCI_DEVICE_ID_FUNCTION CXGB4_UNIFIED_PF
  101. /* Include PCI Device IDs for both PF4 and PF0-3 so our PCI probe() routine is
  102. * called for both.
  103. */
  104. #define CH_PCI_DEVICE_ID_FUNCTION2 0x0
  105. #define CH_PCI_ID_TABLE_ENTRY(devid) \
  106. {PCI_VDEVICE(CHELSIO, (devid)), CXGB4_UNIFIED_PF}
  107. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
  108. { 0, } \
  109. }
  110. #include "t4_pci_id_tbl.h"
  111. #define FW4_FNAME "cxgb4/t4fw.bin"
  112. #define FW5_FNAME "cxgb4/t5fw.bin"
  113. #define FW6_FNAME "cxgb4/t6fw.bin"
  114. #define FW4_CFNAME "cxgb4/t4-config.txt"
  115. #define FW5_CFNAME "cxgb4/t5-config.txt"
  116. #define FW6_CFNAME "cxgb4/t6-config.txt"
  117. #define PHY_AQ1202_FIRMWARE "cxgb4/aq1202_fw.cld"
  118. #define PHY_BCM84834_FIRMWARE "cxgb4/bcm8483.bin"
  119. #define PHY_AQ1202_DEVICEID 0x4409
  120. #define PHY_BCM84834_DEVICEID 0x4486
  121. MODULE_DESCRIPTION(DRV_DESC);
  122. MODULE_AUTHOR("Chelsio Communications");
  123. MODULE_LICENSE("Dual BSD/GPL");
  124. MODULE_VERSION(DRV_VERSION);
  125. MODULE_DEVICE_TABLE(pci, cxgb4_pci_tbl);
  126. MODULE_FIRMWARE(FW4_FNAME);
  127. MODULE_FIRMWARE(FW5_FNAME);
  128. MODULE_FIRMWARE(FW6_FNAME);
  129. /*
  130. * The driver uses the best interrupt scheme available on a platform in the
  131. * order MSI-X, MSI, legacy INTx interrupts. This parameter determines which
  132. * of these schemes the driver may consider as follows:
  133. *
  134. * msi = 2: choose from among all three options
  135. * msi = 1: only consider MSI and INTx interrupts
  136. * msi = 0: force INTx interrupts
  137. */
  138. static int msi = 2;
  139. module_param(msi, int, 0644);
  140. MODULE_PARM_DESC(msi, "whether to use INTx (0), MSI (1) or MSI-X (2)");
  141. /*
  142. * Normally we tell the chip to deliver Ingress Packets into our DMA buffers
  143. * offset by 2 bytes in order to have the IP headers line up on 4-byte
  144. * boundaries. This is a requirement for many architectures which will throw
  145. * a machine check fault if an attempt is made to access one of the 4-byte IP
  146. * header fields on a non-4-byte boundary. And it's a major performance issue
  147. * even on some architectures which allow it like some implementations of the
  148. * x86 ISA. However, some architectures don't mind this and for some very
  149. * edge-case performance sensitive applications (like forwarding large volumes
  150. * of small packets), setting this DMA offset to 0 will decrease the number of
  151. * PCI-E Bus transfers enough to measurably affect performance.
  152. */
  153. static int rx_dma_offset = 2;
  154. /* TX Queue select used to determine what algorithm to use for selecting TX
  155. * queue. Select between the kernel provided function (select_queue=0) or user
  156. * cxgb_select_queue function (select_queue=1)
  157. *
  158. * Default: select_queue=0
  159. */
  160. static int select_queue;
  161. module_param(select_queue, int, 0644);
  162. MODULE_PARM_DESC(select_queue,
  163. "Select between kernel provided method of selecting or driver method of selecting TX queue. Default is kernel method.");
  164. static struct dentry *cxgb4_debugfs_root;
  165. LIST_HEAD(adapter_list);
  166. DEFINE_MUTEX(uld_mutex);
  167. static void link_report(struct net_device *dev)
  168. {
  169. if (!netif_carrier_ok(dev))
  170. netdev_info(dev, "link down\n");
  171. else {
  172. static const char *fc[] = { "no", "Rx", "Tx", "Tx/Rx" };
  173. const char *s;
  174. const struct port_info *p = netdev_priv(dev);
  175. switch (p->link_cfg.speed) {
  176. case 100:
  177. s = "100Mbps";
  178. break;
  179. case 1000:
  180. s = "1Gbps";
  181. break;
  182. case 10000:
  183. s = "10Gbps";
  184. break;
  185. case 25000:
  186. s = "25Gbps";
  187. break;
  188. case 40000:
  189. s = "40Gbps";
  190. break;
  191. case 50000:
  192. s = "50Gbps";
  193. break;
  194. case 100000:
  195. s = "100Gbps";
  196. break;
  197. default:
  198. pr_info("%s: unsupported speed: %d\n",
  199. dev->name, p->link_cfg.speed);
  200. return;
  201. }
  202. netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s,
  203. fc[p->link_cfg.fc]);
  204. }
  205. }
  206. #ifdef CONFIG_CHELSIO_T4_DCB
  207. /* Set up/tear down Data Center Bridging Priority mapping for a net device. */
  208. static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
  209. {
  210. struct port_info *pi = netdev_priv(dev);
  211. struct adapter *adap = pi->adapter;
  212. struct sge_eth_txq *txq = &adap->sge.ethtxq[pi->first_qset];
  213. int i;
  214. /* We use a simple mapping of Port TX Queue Index to DCB
  215. * Priority when we're enabling DCB.
  216. */
  217. for (i = 0; i < pi->nqsets; i++, txq++) {
  218. u32 name, value;
  219. int err;
  220. name = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  221. FW_PARAMS_PARAM_X_V(
  222. FW_PARAMS_PARAM_DMAQ_EQ_DCBPRIO_ETH) |
  223. FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
  224. value = enable ? i : 0xffffffff;
  225. /* Since we can be called while atomic (from "interrupt
  226. * level") we need to issue the Set Parameters Commannd
  227. * without sleeping (timeout < 0).
  228. */
  229. err = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
  230. &name, &value,
  231. -FW_CMD_MAX_TIMEOUT);
  232. if (err)
  233. dev_err(adap->pdev_dev,
  234. "Can't %s DCB Priority on port %d, TX Queue %d: err=%d\n",
  235. enable ? "set" : "unset", pi->port_id, i, -err);
  236. else
  237. txq->dcb_prio = value;
  238. }
  239. }
  240. static int cxgb4_dcb_enabled(const struct net_device *dev)
  241. {
  242. struct port_info *pi = netdev_priv(dev);
  243. if (!pi->dcb.enabled)
  244. return 0;
  245. return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
  246. (pi->dcb.state == CXGB4_DCB_STATE_HOST));
  247. }
  248. #endif /* CONFIG_CHELSIO_T4_DCB */
  249. void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
  250. {
  251. struct net_device *dev = adapter->port[port_id];
  252. /* Skip changes from disabled ports. */
  253. if (netif_running(dev) && link_stat != netif_carrier_ok(dev)) {
  254. if (link_stat)
  255. netif_carrier_on(dev);
  256. else {
  257. #ifdef CONFIG_CHELSIO_T4_DCB
  258. if (cxgb4_dcb_enabled(dev)) {
  259. cxgb4_dcb_reset(dev);
  260. dcb_tx_queue_prio_enable(dev, false);
  261. }
  262. #endif /* CONFIG_CHELSIO_T4_DCB */
  263. netif_carrier_off(dev);
  264. }
  265. link_report(dev);
  266. }
  267. }
  268. void t4_os_portmod_changed(const struct adapter *adap, int port_id)
  269. {
  270. static const char *mod_str[] = {
  271. NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
  272. };
  273. const struct net_device *dev = adap->port[port_id];
  274. const struct port_info *pi = netdev_priv(dev);
  275. if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
  276. netdev_info(dev, "port module unplugged\n");
  277. else if (pi->mod_type < ARRAY_SIZE(mod_str))
  278. netdev_info(dev, "%s module inserted\n", mod_str[pi->mod_type]);
  279. else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
  280. netdev_info(dev, "%s: unsupported port module inserted\n",
  281. dev->name);
  282. else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
  283. netdev_info(dev, "%s: unknown port module inserted\n",
  284. dev->name);
  285. else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
  286. netdev_info(dev, "%s: transceiver module error\n", dev->name);
  287. else
  288. netdev_info(dev, "%s: unknown module type %d inserted\n",
  289. dev->name, pi->mod_type);
  290. }
  291. int dbfifo_int_thresh = 10; /* 10 == 640 entry threshold */
  292. module_param(dbfifo_int_thresh, int, 0644);
  293. MODULE_PARM_DESC(dbfifo_int_thresh, "doorbell fifo interrupt threshold");
  294. /*
  295. * usecs to sleep while draining the dbfifo
  296. */
  297. static int dbfifo_drain_delay = 1000;
  298. module_param(dbfifo_drain_delay, int, 0644);
  299. MODULE_PARM_DESC(dbfifo_drain_delay,
  300. "usecs to sleep while draining the dbfifo");
  301. static inline int cxgb4_set_addr_hash(struct port_info *pi)
  302. {
  303. struct adapter *adap = pi->adapter;
  304. u64 vec = 0;
  305. bool ucast = false;
  306. struct hash_mac_addr *entry;
  307. /* Calculate the hash vector for the updated list and program it */
  308. list_for_each_entry(entry, &adap->mac_hlist, list) {
  309. ucast |= is_unicast_ether_addr(entry->addr);
  310. vec |= (1ULL << hash_mac_addr(entry->addr));
  311. }
  312. return t4_set_addr_hash(adap, adap->mbox, pi->viid, ucast,
  313. vec, false);
  314. }
  315. static int cxgb4_mac_sync(struct net_device *netdev, const u8 *mac_addr)
  316. {
  317. struct port_info *pi = netdev_priv(netdev);
  318. struct adapter *adap = pi->adapter;
  319. int ret;
  320. u64 mhash = 0;
  321. u64 uhash = 0;
  322. bool free = false;
  323. bool ucast = is_unicast_ether_addr(mac_addr);
  324. const u8 *maclist[1] = {mac_addr};
  325. struct hash_mac_addr *new_entry;
  326. ret = t4_alloc_mac_filt(adap, adap->mbox, pi->viid, free, 1, maclist,
  327. NULL, ucast ? &uhash : &mhash, false);
  328. if (ret < 0)
  329. goto out;
  330. /* if hash != 0, then add the addr to hash addr list
  331. * so on the end we will calculate the hash for the
  332. * list and program it
  333. */
  334. if (uhash || mhash) {
  335. new_entry = kzalloc(sizeof(*new_entry), GFP_ATOMIC);
  336. if (!new_entry)
  337. return -ENOMEM;
  338. ether_addr_copy(new_entry->addr, mac_addr);
  339. list_add_tail(&new_entry->list, &adap->mac_hlist);
  340. ret = cxgb4_set_addr_hash(pi);
  341. }
  342. out:
  343. return ret < 0 ? ret : 0;
  344. }
  345. static int cxgb4_mac_unsync(struct net_device *netdev, const u8 *mac_addr)
  346. {
  347. struct port_info *pi = netdev_priv(netdev);
  348. struct adapter *adap = pi->adapter;
  349. int ret;
  350. const u8 *maclist[1] = {mac_addr};
  351. struct hash_mac_addr *entry, *tmp;
  352. /* If the MAC address to be removed is in the hash addr
  353. * list, delete it from the list and update hash vector
  354. */
  355. list_for_each_entry_safe(entry, tmp, &adap->mac_hlist, list) {
  356. if (ether_addr_equal(entry->addr, mac_addr)) {
  357. list_del(&entry->list);
  358. kfree(entry);
  359. return cxgb4_set_addr_hash(pi);
  360. }
  361. }
  362. ret = t4_free_mac_filt(adap, adap->mbox, pi->viid, 1, maclist, false);
  363. return ret < 0 ? -EINVAL : 0;
  364. }
  365. /*
  366. * Set Rx properties of a port, such as promiscruity, address filters, and MTU.
  367. * If @mtu is -1 it is left unchanged.
  368. */
  369. static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
  370. {
  371. struct port_info *pi = netdev_priv(dev);
  372. struct adapter *adapter = pi->adapter;
  373. __dev_uc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  374. __dev_mc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  375. return t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu,
  376. (dev->flags & IFF_PROMISC) ? 1 : 0,
  377. (dev->flags & IFF_ALLMULTI) ? 1 : 0, 1, -1,
  378. sleep_ok);
  379. }
  380. /**
  381. * link_start - enable a port
  382. * @dev: the port to enable
  383. *
  384. * Performs the MAC and PHY actions needed to enable a port.
  385. */
  386. static int link_start(struct net_device *dev)
  387. {
  388. int ret;
  389. struct port_info *pi = netdev_priv(dev);
  390. unsigned int mb = pi->adapter->pf;
  391. /*
  392. * We do not set address filters and promiscuity here, the stack does
  393. * that step explicitly.
  394. */
  395. ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
  396. !!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
  397. if (ret == 0) {
  398. ret = t4_change_mac(pi->adapter, mb, pi->viid,
  399. pi->xact_addr_filt, dev->dev_addr, true,
  400. true);
  401. if (ret >= 0) {
  402. pi->xact_addr_filt = ret;
  403. ret = 0;
  404. }
  405. }
  406. if (ret == 0)
  407. ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
  408. &pi->link_cfg);
  409. if (ret == 0) {
  410. local_bh_disable();
  411. ret = t4_enable_vi_params(pi->adapter, mb, pi->viid, true,
  412. true, CXGB4_DCB_ENABLED);
  413. local_bh_enable();
  414. }
  415. return ret;
  416. }
  417. #ifdef CONFIG_CHELSIO_T4_DCB
  418. /* Handle a Data Center Bridging update message from the firmware. */
  419. static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
  420. {
  421. int port = FW_PORT_CMD_PORTID_G(ntohl(pcmd->op_to_portid));
  422. struct net_device *dev = adap->port[adap->chan_map[port]];
  423. int old_dcb_enabled = cxgb4_dcb_enabled(dev);
  424. int new_dcb_enabled;
  425. cxgb4_dcb_handle_fw_update(adap, pcmd);
  426. new_dcb_enabled = cxgb4_dcb_enabled(dev);
  427. /* If the DCB has become enabled or disabled on the port then we're
  428. * going to need to set up/tear down DCB Priority parameters for the
  429. * TX Queues associated with the port.
  430. */
  431. if (new_dcb_enabled != old_dcb_enabled)
  432. dcb_tx_queue_prio_enable(dev, new_dcb_enabled);
  433. }
  434. #endif /* CONFIG_CHELSIO_T4_DCB */
  435. /* Response queue handler for the FW event queue.
  436. */
  437. static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
  438. const struct pkt_gl *gl)
  439. {
  440. u8 opcode = ((const struct rss_header *)rsp)->opcode;
  441. rsp++; /* skip RSS header */
  442. /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
  443. */
  444. if (unlikely(opcode == CPL_FW4_MSG &&
  445. ((const struct cpl_fw4_msg *)rsp)->type == FW_TYPE_RSSCPL)) {
  446. rsp++;
  447. opcode = ((const struct rss_header *)rsp)->opcode;
  448. rsp++;
  449. if (opcode != CPL_SGE_EGR_UPDATE) {
  450. dev_err(q->adap->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
  451. , opcode);
  452. goto out;
  453. }
  454. }
  455. if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
  456. const struct cpl_sge_egr_update *p = (void *)rsp;
  457. unsigned int qid = EGR_QID_G(ntohl(p->opcode_qid));
  458. struct sge_txq *txq;
  459. txq = q->adap->sge.egr_map[qid - q->adap->sge.egr_start];
  460. txq->restarts++;
  461. if (txq->q_type == CXGB4_TXQ_ETH) {
  462. struct sge_eth_txq *eq;
  463. eq = container_of(txq, struct sge_eth_txq, q);
  464. netif_tx_wake_queue(eq->txq);
  465. } else {
  466. struct sge_uld_txq *oq;
  467. oq = container_of(txq, struct sge_uld_txq, q);
  468. tasklet_schedule(&oq->qresume_tsk);
  469. }
  470. } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
  471. const struct cpl_fw6_msg *p = (void *)rsp;
  472. #ifdef CONFIG_CHELSIO_T4_DCB
  473. const struct fw_port_cmd *pcmd = (const void *)p->data;
  474. unsigned int cmd = FW_CMD_OP_G(ntohl(pcmd->op_to_portid));
  475. unsigned int action =
  476. FW_PORT_CMD_ACTION_G(ntohl(pcmd->action_to_len16));
  477. if (cmd == FW_PORT_CMD &&
  478. (action == FW_PORT_ACTION_GET_PORT_INFO ||
  479. action == FW_PORT_ACTION_GET_PORT_INFO32)) {
  480. int port = FW_PORT_CMD_PORTID_G(
  481. be32_to_cpu(pcmd->op_to_portid));
  482. struct net_device *dev;
  483. int dcbxdis, state_input;
  484. dev = q->adap->port[q->adap->chan_map[port]];
  485. dcbxdis = (action == FW_PORT_ACTION_GET_PORT_INFO
  486. ? !!(pcmd->u.info.dcbxdis_pkd &
  487. FW_PORT_CMD_DCBXDIS_F)
  488. : !!(pcmd->u.info32.lstatus32_to_cbllen32 &
  489. FW_PORT_CMD_DCBXDIS32_F));
  490. state_input = (dcbxdis
  491. ? CXGB4_DCB_INPUT_FW_DISABLED
  492. : CXGB4_DCB_INPUT_FW_ENABLED);
  493. cxgb4_dcb_state_fsm(dev, state_input);
  494. }
  495. if (cmd == FW_PORT_CMD &&
  496. action == FW_PORT_ACTION_L2_DCB_CFG)
  497. dcb_rpl(q->adap, pcmd);
  498. else
  499. #endif
  500. if (p->type == 0)
  501. t4_handle_fw_rpl(q->adap, p->data);
  502. } else if (opcode == CPL_L2T_WRITE_RPL) {
  503. const struct cpl_l2t_write_rpl *p = (void *)rsp;
  504. do_l2t_write_rpl(q->adap, p);
  505. } else if (opcode == CPL_SMT_WRITE_RPL) {
  506. const struct cpl_smt_write_rpl *p = (void *)rsp;
  507. do_smt_write_rpl(q->adap, p);
  508. } else if (opcode == CPL_SET_TCB_RPL) {
  509. const struct cpl_set_tcb_rpl *p = (void *)rsp;
  510. filter_rpl(q->adap, p);
  511. } else if (opcode == CPL_ACT_OPEN_RPL) {
  512. const struct cpl_act_open_rpl *p = (void *)rsp;
  513. hash_filter_rpl(q->adap, p);
  514. } else if (opcode == CPL_ABORT_RPL_RSS) {
  515. const struct cpl_abort_rpl_rss *p = (void *)rsp;
  516. hash_del_filter_rpl(q->adap, p);
  517. } else if (opcode == CPL_SRQ_TABLE_RPL) {
  518. const struct cpl_srq_table_rpl *p = (void *)rsp;
  519. do_srq_table_rpl(q->adap, p);
  520. } else
  521. dev_err(q->adap->pdev_dev,
  522. "unexpected CPL %#x on FW event queue\n", opcode);
  523. out:
  524. return 0;
  525. }
  526. static void disable_msi(struct adapter *adapter)
  527. {
  528. if (adapter->flags & USING_MSIX) {
  529. pci_disable_msix(adapter->pdev);
  530. adapter->flags &= ~USING_MSIX;
  531. } else if (adapter->flags & USING_MSI) {
  532. pci_disable_msi(adapter->pdev);
  533. adapter->flags &= ~USING_MSI;
  534. }
  535. }
  536. /*
  537. * Interrupt handler for non-data events used with MSI-X.
  538. */
  539. static irqreturn_t t4_nondata_intr(int irq, void *cookie)
  540. {
  541. struct adapter *adap = cookie;
  542. u32 v = t4_read_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A));
  543. if (v & PFSW_F) {
  544. adap->swintr = 1;
  545. t4_write_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A), v);
  546. }
  547. if (adap->flags & MASTER_PF)
  548. t4_slow_intr_handler(adap);
  549. return IRQ_HANDLED;
  550. }
  551. /*
  552. * Name the MSI-X interrupts.
  553. */
  554. static void name_msix_vecs(struct adapter *adap)
  555. {
  556. int i, j, msi_idx = 2, n = sizeof(adap->msix_info[0].desc);
  557. /* non-data interrupts */
  558. snprintf(adap->msix_info[0].desc, n, "%s", adap->port[0]->name);
  559. /* FW events */
  560. snprintf(adap->msix_info[1].desc, n, "%s-FWeventq",
  561. adap->port[0]->name);
  562. /* Ethernet queues */
  563. for_each_port(adap, j) {
  564. struct net_device *d = adap->port[j];
  565. const struct port_info *pi = netdev_priv(d);
  566. for (i = 0; i < pi->nqsets; i++, msi_idx++)
  567. snprintf(adap->msix_info[msi_idx].desc, n, "%s-Rx%d",
  568. d->name, i);
  569. }
  570. }
  571. static int request_msix_queue_irqs(struct adapter *adap)
  572. {
  573. struct sge *s = &adap->sge;
  574. int err, ethqidx;
  575. int msi_index = 2;
  576. err = request_irq(adap->msix_info[1].vec, t4_sge_intr_msix, 0,
  577. adap->msix_info[1].desc, &s->fw_evtq);
  578. if (err)
  579. return err;
  580. for_each_ethrxq(s, ethqidx) {
  581. err = request_irq(adap->msix_info[msi_index].vec,
  582. t4_sge_intr_msix, 0,
  583. adap->msix_info[msi_index].desc,
  584. &s->ethrxq[ethqidx].rspq);
  585. if (err)
  586. goto unwind;
  587. msi_index++;
  588. }
  589. return 0;
  590. unwind:
  591. while (--ethqidx >= 0)
  592. free_irq(adap->msix_info[--msi_index].vec,
  593. &s->ethrxq[ethqidx].rspq);
  594. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  595. return err;
  596. }
  597. static void free_msix_queue_irqs(struct adapter *adap)
  598. {
  599. int i, msi_index = 2;
  600. struct sge *s = &adap->sge;
  601. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  602. for_each_ethrxq(s, i)
  603. free_irq(adap->msix_info[msi_index++].vec, &s->ethrxq[i].rspq);
  604. }
  605. /**
  606. * cxgb4_write_rss - write the RSS table for a given port
  607. * @pi: the port
  608. * @queues: array of queue indices for RSS
  609. *
  610. * Sets up the portion of the HW RSS table for the port's VI to distribute
  611. * packets to the Rx queues in @queues.
  612. * Should never be called before setting up sge eth rx queues
  613. */
  614. int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
  615. {
  616. u16 *rss;
  617. int i, err;
  618. struct adapter *adapter = pi->adapter;
  619. const struct sge_eth_rxq *rxq;
  620. rxq = &adapter->sge.ethrxq[pi->first_qset];
  621. rss = kmalloc(pi->rss_size * sizeof(u16), GFP_KERNEL);
  622. if (!rss)
  623. return -ENOMEM;
  624. /* map the queue indices to queue ids */
  625. for (i = 0; i < pi->rss_size; i++, queues++)
  626. rss[i] = rxq[*queues].rspq.abs_id;
  627. err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
  628. pi->rss_size, rss, pi->rss_size);
  629. /* If Tunnel All Lookup isn't specified in the global RSS
  630. * Configuration, then we need to specify a default Ingress
  631. * Queue for any ingress packets which aren't hashed. We'll
  632. * use our first ingress queue ...
  633. */
  634. if (!err)
  635. err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
  636. FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F |
  637. FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F |
  638. FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F |
  639. FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F |
  640. FW_RSS_VI_CONFIG_CMD_UDPEN_F,
  641. rss[0]);
  642. kfree(rss);
  643. return err;
  644. }
  645. /**
  646. * setup_rss - configure RSS
  647. * @adap: the adapter
  648. *
  649. * Sets up RSS for each port.
  650. */
  651. static int setup_rss(struct adapter *adap)
  652. {
  653. int i, j, err;
  654. for_each_port(adap, i) {
  655. const struct port_info *pi = adap2pinfo(adap, i);
  656. /* Fill default values with equal distribution */
  657. for (j = 0; j < pi->rss_size; j++)
  658. pi->rss[j] = j % pi->nqsets;
  659. err = cxgb4_write_rss(pi, pi->rss);
  660. if (err)
  661. return err;
  662. }
  663. return 0;
  664. }
  665. /*
  666. * Return the channel of the ingress queue with the given qid.
  667. */
  668. static unsigned int rxq_to_chan(const struct sge *p, unsigned int qid)
  669. {
  670. qid -= p->ingr_start;
  671. return netdev2pinfo(p->ingr_map[qid]->netdev)->tx_chan;
  672. }
  673. /*
  674. * Wait until all NAPI handlers are descheduled.
  675. */
  676. static void quiesce_rx(struct adapter *adap)
  677. {
  678. int i;
  679. for (i = 0; i < adap->sge.ingr_sz; i++) {
  680. struct sge_rspq *q = adap->sge.ingr_map[i];
  681. if (q && q->handler)
  682. napi_disable(&q->napi);
  683. }
  684. }
  685. /* Disable interrupt and napi handler */
  686. static void disable_interrupts(struct adapter *adap)
  687. {
  688. if (adap->flags & FULL_INIT_DONE) {
  689. t4_intr_disable(adap);
  690. if (adap->flags & USING_MSIX) {
  691. free_msix_queue_irqs(adap);
  692. free_irq(adap->msix_info[0].vec, adap);
  693. } else {
  694. free_irq(adap->pdev->irq, adap);
  695. }
  696. quiesce_rx(adap);
  697. }
  698. }
  699. /*
  700. * Enable NAPI scheduling and interrupt generation for all Rx queues.
  701. */
  702. static void enable_rx(struct adapter *adap)
  703. {
  704. int i;
  705. for (i = 0; i < adap->sge.ingr_sz; i++) {
  706. struct sge_rspq *q = adap->sge.ingr_map[i];
  707. if (!q)
  708. continue;
  709. if (q->handler)
  710. napi_enable(&q->napi);
  711. /* 0-increment GTS to start the timer and enable interrupts */
  712. t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
  713. SEINTARM_V(q->intr_params) |
  714. INGRESSQID_V(q->cntxt_id));
  715. }
  716. }
  717. static int setup_fw_sge_queues(struct adapter *adap)
  718. {
  719. struct sge *s = &adap->sge;
  720. int err = 0;
  721. bitmap_zero(s->starving_fl, s->egr_sz);
  722. bitmap_zero(s->txq_maperr, s->egr_sz);
  723. if (adap->flags & USING_MSIX)
  724. adap->msi_idx = 1; /* vector 0 is for non-queue interrupts */
  725. else {
  726. err = t4_sge_alloc_rxq(adap, &s->intrq, false, adap->port[0], 0,
  727. NULL, NULL, NULL, -1);
  728. if (err)
  729. return err;
  730. adap->msi_idx = -((int)s->intrq.abs_id + 1);
  731. }
  732. err = t4_sge_alloc_rxq(adap, &s->fw_evtq, true, adap->port[0],
  733. adap->msi_idx, NULL, fwevtq_handler, NULL, -1);
  734. return err;
  735. }
  736. /**
  737. * setup_sge_queues - configure SGE Tx/Rx/response queues
  738. * @adap: the adapter
  739. *
  740. * Determines how many sets of SGE queues to use and initializes them.
  741. * We support multiple queue sets per port if we have MSI-X, otherwise
  742. * just one queue set per port.
  743. */
  744. static int setup_sge_queues(struct adapter *adap)
  745. {
  746. int err, i, j;
  747. struct sge *s = &adap->sge;
  748. struct sge_uld_rxq_info *rxq_info = NULL;
  749. unsigned int cmplqid = 0;
  750. if (is_uld(adap))
  751. rxq_info = s->uld_rxq_info[CXGB4_ULD_RDMA];
  752. for_each_port(adap, i) {
  753. struct net_device *dev = adap->port[i];
  754. struct port_info *pi = netdev_priv(dev);
  755. struct sge_eth_rxq *q = &s->ethrxq[pi->first_qset];
  756. struct sge_eth_txq *t = &s->ethtxq[pi->first_qset];
  757. for (j = 0; j < pi->nqsets; j++, q++) {
  758. if (adap->msi_idx > 0)
  759. adap->msi_idx++;
  760. err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev,
  761. adap->msi_idx, &q->fl,
  762. t4_ethrx_handler,
  763. NULL,
  764. t4_get_tp_ch_map(adap,
  765. pi->tx_chan));
  766. if (err)
  767. goto freeout;
  768. q->rspq.idx = j;
  769. memset(&q->stats, 0, sizeof(q->stats));
  770. }
  771. for (j = 0; j < pi->nqsets; j++, t++) {
  772. err = t4_sge_alloc_eth_txq(adap, t, dev,
  773. netdev_get_tx_queue(dev, j),
  774. s->fw_evtq.cntxt_id);
  775. if (err)
  776. goto freeout;
  777. }
  778. }
  779. for_each_port(adap, i) {
  780. /* Note that cmplqid below is 0 if we don't
  781. * have RDMA queues, and that's the right value.
  782. */
  783. if (rxq_info)
  784. cmplqid = rxq_info->uldrxq[i].rspq.cntxt_id;
  785. err = t4_sge_alloc_ctrl_txq(adap, &s->ctrlq[i], adap->port[i],
  786. s->fw_evtq.cntxt_id, cmplqid);
  787. if (err)
  788. goto freeout;
  789. }
  790. if (!is_t4(adap->params.chip)) {
  791. err = t4_sge_alloc_eth_txq(adap, &s->ptptxq, adap->port[0],
  792. netdev_get_tx_queue(adap->port[0], 0)
  793. , s->fw_evtq.cntxt_id);
  794. if (err)
  795. goto freeout;
  796. }
  797. t4_write_reg(adap, is_t4(adap->params.chip) ?
  798. MPS_TRC_RSS_CONTROL_A :
  799. MPS_T5_TRC_RSS_CONTROL_A,
  800. RSSCONTROL_V(netdev2pinfo(adap->port[0])->tx_chan) |
  801. QUEUENUMBER_V(s->ethrxq[0].rspq.abs_id));
  802. return 0;
  803. freeout:
  804. t4_free_sge_resources(adap);
  805. return err;
  806. }
  807. static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
  808. void *accel_priv, select_queue_fallback_t fallback)
  809. {
  810. int txq;
  811. #ifdef CONFIG_CHELSIO_T4_DCB
  812. /* If a Data Center Bridging has been successfully negotiated on this
  813. * link then we'll use the skb's priority to map it to a TX Queue.
  814. * The skb's priority is determined via the VLAN Tag Priority Code
  815. * Point field.
  816. */
  817. if (cxgb4_dcb_enabled(dev) && !is_kdump_kernel()) {
  818. u16 vlan_tci;
  819. int err;
  820. err = vlan_get_tag(skb, &vlan_tci);
  821. if (unlikely(err)) {
  822. if (net_ratelimit())
  823. netdev_warn(dev,
  824. "TX Packet without VLAN Tag on DCB Link\n");
  825. txq = 0;
  826. } else {
  827. txq = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  828. #ifdef CONFIG_CHELSIO_T4_FCOE
  829. if (skb->protocol == htons(ETH_P_FCOE))
  830. txq = skb->priority & 0x7;
  831. #endif /* CONFIG_CHELSIO_T4_FCOE */
  832. }
  833. return txq;
  834. }
  835. #endif /* CONFIG_CHELSIO_T4_DCB */
  836. if (select_queue) {
  837. txq = (skb_rx_queue_recorded(skb)
  838. ? skb_get_rx_queue(skb)
  839. : smp_processor_id());
  840. while (unlikely(txq >= dev->real_num_tx_queues))
  841. txq -= dev->real_num_tx_queues;
  842. return txq;
  843. }
  844. return fallback(dev, skb) % dev->real_num_tx_queues;
  845. }
  846. static int closest_timer(const struct sge *s, int time)
  847. {
  848. int i, delta, match = 0, min_delta = INT_MAX;
  849. for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
  850. delta = time - s->timer_val[i];
  851. if (delta < 0)
  852. delta = -delta;
  853. if (delta < min_delta) {
  854. min_delta = delta;
  855. match = i;
  856. }
  857. }
  858. return match;
  859. }
  860. static int closest_thres(const struct sge *s, int thres)
  861. {
  862. int i, delta, match = 0, min_delta = INT_MAX;
  863. for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
  864. delta = thres - s->counter_val[i];
  865. if (delta < 0)
  866. delta = -delta;
  867. if (delta < min_delta) {
  868. min_delta = delta;
  869. match = i;
  870. }
  871. }
  872. return match;
  873. }
  874. /**
  875. * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
  876. * @q: the Rx queue
  877. * @us: the hold-off time in us, or 0 to disable timer
  878. * @cnt: the hold-off packet count, or 0 to disable counter
  879. *
  880. * Sets an Rx queue's interrupt hold-off time and packet count. At least
  881. * one of the two needs to be enabled for the queue to generate interrupts.
  882. */
  883. int cxgb4_set_rspq_intr_params(struct sge_rspq *q,
  884. unsigned int us, unsigned int cnt)
  885. {
  886. struct adapter *adap = q->adap;
  887. if ((us | cnt) == 0)
  888. cnt = 1;
  889. if (cnt) {
  890. int err;
  891. u32 v, new_idx;
  892. new_idx = closest_thres(&adap->sge, cnt);
  893. if (q->desc && q->pktcnt_idx != new_idx) {
  894. /* the queue has already been created, update it */
  895. v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  896. FW_PARAMS_PARAM_X_V(
  897. FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
  898. FW_PARAMS_PARAM_YZ_V(q->cntxt_id);
  899. err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
  900. &v, &new_idx);
  901. if (err)
  902. return err;
  903. }
  904. q->pktcnt_idx = new_idx;
  905. }
  906. us = us == 0 ? 6 : closest_timer(&adap->sge, us);
  907. q->intr_params = QINTR_TIMER_IDX_V(us) | QINTR_CNT_EN_V(cnt > 0);
  908. return 0;
  909. }
  910. static int cxgb_set_features(struct net_device *dev, netdev_features_t features)
  911. {
  912. const struct port_info *pi = netdev_priv(dev);
  913. netdev_features_t changed = dev->features ^ features;
  914. int err;
  915. if (!(changed & NETIF_F_HW_VLAN_CTAG_RX))
  916. return 0;
  917. err = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, -1,
  918. -1, -1, -1,
  919. !!(features & NETIF_F_HW_VLAN_CTAG_RX), true);
  920. if (unlikely(err))
  921. dev->features = features ^ NETIF_F_HW_VLAN_CTAG_RX;
  922. return err;
  923. }
  924. static int setup_debugfs(struct adapter *adap)
  925. {
  926. if (IS_ERR_OR_NULL(adap->debugfs_root))
  927. return -1;
  928. #ifdef CONFIG_DEBUG_FS
  929. t4_setup_debugfs(adap);
  930. #endif
  931. return 0;
  932. }
  933. /*
  934. * upper-layer driver support
  935. */
  936. /*
  937. * Allocate an active-open TID and set it to the supplied value.
  938. */
  939. int cxgb4_alloc_atid(struct tid_info *t, void *data)
  940. {
  941. int atid = -1;
  942. spin_lock_bh(&t->atid_lock);
  943. if (t->afree) {
  944. union aopen_entry *p = t->afree;
  945. atid = (p - t->atid_tab) + t->atid_base;
  946. t->afree = p->next;
  947. p->data = data;
  948. t->atids_in_use++;
  949. }
  950. spin_unlock_bh(&t->atid_lock);
  951. return atid;
  952. }
  953. EXPORT_SYMBOL(cxgb4_alloc_atid);
  954. /*
  955. * Release an active-open TID.
  956. */
  957. void cxgb4_free_atid(struct tid_info *t, unsigned int atid)
  958. {
  959. union aopen_entry *p = &t->atid_tab[atid - t->atid_base];
  960. spin_lock_bh(&t->atid_lock);
  961. p->next = t->afree;
  962. t->afree = p;
  963. t->atids_in_use--;
  964. spin_unlock_bh(&t->atid_lock);
  965. }
  966. EXPORT_SYMBOL(cxgb4_free_atid);
  967. /*
  968. * Allocate a server TID and set it to the supplied value.
  969. */
  970. int cxgb4_alloc_stid(struct tid_info *t, int family, void *data)
  971. {
  972. int stid;
  973. spin_lock_bh(&t->stid_lock);
  974. if (family == PF_INET) {
  975. stid = find_first_zero_bit(t->stid_bmap, t->nstids);
  976. if (stid < t->nstids)
  977. __set_bit(stid, t->stid_bmap);
  978. else
  979. stid = -1;
  980. } else {
  981. stid = bitmap_find_free_region(t->stid_bmap, t->nstids, 1);
  982. if (stid < 0)
  983. stid = -1;
  984. }
  985. if (stid >= 0) {
  986. t->stid_tab[stid].data = data;
  987. stid += t->stid_base;
  988. /* IPv6 requires max of 520 bits or 16 cells in TCAM
  989. * This is equivalent to 4 TIDs. With CLIP enabled it
  990. * needs 2 TIDs.
  991. */
  992. if (family == PF_INET6) {
  993. t->stids_in_use += 2;
  994. t->v6_stids_in_use += 2;
  995. } else {
  996. t->stids_in_use++;
  997. }
  998. }
  999. spin_unlock_bh(&t->stid_lock);
  1000. return stid;
  1001. }
  1002. EXPORT_SYMBOL(cxgb4_alloc_stid);
  1003. /* Allocate a server filter TID and set it to the supplied value.
  1004. */
  1005. int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data)
  1006. {
  1007. int stid;
  1008. spin_lock_bh(&t->stid_lock);
  1009. if (family == PF_INET) {
  1010. stid = find_next_zero_bit(t->stid_bmap,
  1011. t->nstids + t->nsftids, t->nstids);
  1012. if (stid < (t->nstids + t->nsftids))
  1013. __set_bit(stid, t->stid_bmap);
  1014. else
  1015. stid = -1;
  1016. } else {
  1017. stid = -1;
  1018. }
  1019. if (stid >= 0) {
  1020. t->stid_tab[stid].data = data;
  1021. stid -= t->nstids;
  1022. stid += t->sftid_base;
  1023. t->sftids_in_use++;
  1024. }
  1025. spin_unlock_bh(&t->stid_lock);
  1026. return stid;
  1027. }
  1028. EXPORT_SYMBOL(cxgb4_alloc_sftid);
  1029. /* Release a server TID.
  1030. */
  1031. void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family)
  1032. {
  1033. /* Is it a server filter TID? */
  1034. if (t->nsftids && (stid >= t->sftid_base)) {
  1035. stid -= t->sftid_base;
  1036. stid += t->nstids;
  1037. } else {
  1038. stid -= t->stid_base;
  1039. }
  1040. spin_lock_bh(&t->stid_lock);
  1041. if (family == PF_INET)
  1042. __clear_bit(stid, t->stid_bmap);
  1043. else
  1044. bitmap_release_region(t->stid_bmap, stid, 1);
  1045. t->stid_tab[stid].data = NULL;
  1046. if (stid < t->nstids) {
  1047. if (family == PF_INET6) {
  1048. t->stids_in_use -= 2;
  1049. t->v6_stids_in_use -= 2;
  1050. } else {
  1051. t->stids_in_use--;
  1052. }
  1053. } else {
  1054. t->sftids_in_use--;
  1055. }
  1056. spin_unlock_bh(&t->stid_lock);
  1057. }
  1058. EXPORT_SYMBOL(cxgb4_free_stid);
  1059. /*
  1060. * Populate a TID_RELEASE WR. Caller must properly size the skb.
  1061. */
  1062. static void mk_tid_release(struct sk_buff *skb, unsigned int chan,
  1063. unsigned int tid)
  1064. {
  1065. struct cpl_tid_release *req;
  1066. set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
  1067. req = __skb_put(skb, sizeof(*req));
  1068. INIT_TP_WR(req, tid);
  1069. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
  1070. }
  1071. /*
  1072. * Queue a TID release request and if necessary schedule a work queue to
  1073. * process it.
  1074. */
  1075. static void cxgb4_queue_tid_release(struct tid_info *t, unsigned int chan,
  1076. unsigned int tid)
  1077. {
  1078. void **p = &t->tid_tab[tid];
  1079. struct adapter *adap = container_of(t, struct adapter, tids);
  1080. spin_lock_bh(&adap->tid_release_lock);
  1081. *p = adap->tid_release_head;
  1082. /* Low 2 bits encode the Tx channel number */
  1083. adap->tid_release_head = (void **)((uintptr_t)p | chan);
  1084. if (!adap->tid_release_task_busy) {
  1085. adap->tid_release_task_busy = true;
  1086. queue_work(adap->workq, &adap->tid_release_task);
  1087. }
  1088. spin_unlock_bh(&adap->tid_release_lock);
  1089. }
  1090. /*
  1091. * Process the list of pending TID release requests.
  1092. */
  1093. static void process_tid_release_list(struct work_struct *work)
  1094. {
  1095. struct sk_buff *skb;
  1096. struct adapter *adap;
  1097. adap = container_of(work, struct adapter, tid_release_task);
  1098. spin_lock_bh(&adap->tid_release_lock);
  1099. while (adap->tid_release_head) {
  1100. void **p = adap->tid_release_head;
  1101. unsigned int chan = (uintptr_t)p & 3;
  1102. p = (void *)p - chan;
  1103. adap->tid_release_head = *p;
  1104. *p = NULL;
  1105. spin_unlock_bh(&adap->tid_release_lock);
  1106. while (!(skb = alloc_skb(sizeof(struct cpl_tid_release),
  1107. GFP_KERNEL)))
  1108. schedule_timeout_uninterruptible(1);
  1109. mk_tid_release(skb, chan, p - adap->tids.tid_tab);
  1110. t4_ofld_send(adap, skb);
  1111. spin_lock_bh(&adap->tid_release_lock);
  1112. }
  1113. adap->tid_release_task_busy = false;
  1114. spin_unlock_bh(&adap->tid_release_lock);
  1115. }
  1116. /*
  1117. * Release a TID and inform HW. If we are unable to allocate the release
  1118. * message we defer to a work queue.
  1119. */
  1120. void cxgb4_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid,
  1121. unsigned short family)
  1122. {
  1123. struct sk_buff *skb;
  1124. struct adapter *adap = container_of(t, struct adapter, tids);
  1125. WARN_ON(tid >= t->ntids);
  1126. if (t->tid_tab[tid]) {
  1127. t->tid_tab[tid] = NULL;
  1128. atomic_dec(&t->conns_in_use);
  1129. if (t->hash_base && (tid >= t->hash_base)) {
  1130. if (family == AF_INET6)
  1131. atomic_sub(2, &t->hash_tids_in_use);
  1132. else
  1133. atomic_dec(&t->hash_tids_in_use);
  1134. } else {
  1135. if (family == AF_INET6)
  1136. atomic_sub(2, &t->tids_in_use);
  1137. else
  1138. atomic_dec(&t->tids_in_use);
  1139. }
  1140. }
  1141. skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
  1142. if (likely(skb)) {
  1143. mk_tid_release(skb, chan, tid);
  1144. t4_ofld_send(adap, skb);
  1145. } else
  1146. cxgb4_queue_tid_release(t, chan, tid);
  1147. }
  1148. EXPORT_SYMBOL(cxgb4_remove_tid);
  1149. /*
  1150. * Allocate and initialize the TID tables. Returns 0 on success.
  1151. */
  1152. static int tid_init(struct tid_info *t)
  1153. {
  1154. struct adapter *adap = container_of(t, struct adapter, tids);
  1155. unsigned int max_ftids = t->nftids + t->nsftids;
  1156. unsigned int natids = t->natids;
  1157. unsigned int stid_bmap_size;
  1158. unsigned int ftid_bmap_size;
  1159. size_t size;
  1160. stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
  1161. ftid_bmap_size = BITS_TO_LONGS(t->nftids);
  1162. size = t->ntids * sizeof(*t->tid_tab) +
  1163. natids * sizeof(*t->atid_tab) +
  1164. t->nstids * sizeof(*t->stid_tab) +
  1165. t->nsftids * sizeof(*t->stid_tab) +
  1166. stid_bmap_size * sizeof(long) +
  1167. max_ftids * sizeof(*t->ftid_tab) +
  1168. ftid_bmap_size * sizeof(long);
  1169. t->tid_tab = kvzalloc(size, GFP_KERNEL);
  1170. if (!t->tid_tab)
  1171. return -ENOMEM;
  1172. t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
  1173. t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
  1174. t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
  1175. t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
  1176. t->ftid_bmap = (unsigned long *)&t->ftid_tab[max_ftids];
  1177. spin_lock_init(&t->stid_lock);
  1178. spin_lock_init(&t->atid_lock);
  1179. spin_lock_init(&t->ftid_lock);
  1180. t->stids_in_use = 0;
  1181. t->v6_stids_in_use = 0;
  1182. t->sftids_in_use = 0;
  1183. t->afree = NULL;
  1184. t->atids_in_use = 0;
  1185. atomic_set(&t->tids_in_use, 0);
  1186. atomic_set(&t->conns_in_use, 0);
  1187. atomic_set(&t->hash_tids_in_use, 0);
  1188. /* Setup the free list for atid_tab and clear the stid bitmap. */
  1189. if (natids) {
  1190. while (--natids)
  1191. t->atid_tab[natids - 1].next = &t->atid_tab[natids];
  1192. t->afree = t->atid_tab;
  1193. }
  1194. if (is_offload(adap)) {
  1195. bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
  1196. /* Reserve stid 0 for T4/T5 adapters */
  1197. if (!t->stid_base &&
  1198. CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1199. __set_bit(0, t->stid_bmap);
  1200. }
  1201. bitmap_zero(t->ftid_bmap, t->nftids);
  1202. return 0;
  1203. }
  1204. /**
  1205. * cxgb4_create_server - create an IP server
  1206. * @dev: the device
  1207. * @stid: the server TID
  1208. * @sip: local IP address to bind server to
  1209. * @sport: the server's TCP port
  1210. * @queue: queue to direct messages from this server to
  1211. *
  1212. * Create an IP server for the given port and address.
  1213. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1214. */
  1215. int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
  1216. __be32 sip, __be16 sport, __be16 vlan,
  1217. unsigned int queue)
  1218. {
  1219. unsigned int chan;
  1220. struct sk_buff *skb;
  1221. struct adapter *adap;
  1222. struct cpl_pass_open_req *req;
  1223. int ret;
  1224. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1225. if (!skb)
  1226. return -ENOMEM;
  1227. adap = netdev2adap(dev);
  1228. req = __skb_put(skb, sizeof(*req));
  1229. INIT_TP_WR(req, 0);
  1230. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, stid));
  1231. req->local_port = sport;
  1232. req->peer_port = htons(0);
  1233. req->local_ip = sip;
  1234. req->peer_ip = htonl(0);
  1235. chan = rxq_to_chan(&adap->sge, queue);
  1236. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1237. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1238. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1239. ret = t4_mgmt_tx(adap, skb);
  1240. return net_xmit_eval(ret);
  1241. }
  1242. EXPORT_SYMBOL(cxgb4_create_server);
  1243. /* cxgb4_create_server6 - create an IPv6 server
  1244. * @dev: the device
  1245. * @stid: the server TID
  1246. * @sip: local IPv6 address to bind server to
  1247. * @sport: the server's TCP port
  1248. * @queue: queue to direct messages from this server to
  1249. *
  1250. * Create an IPv6 server for the given port and address.
  1251. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1252. */
  1253. int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
  1254. const struct in6_addr *sip, __be16 sport,
  1255. unsigned int queue)
  1256. {
  1257. unsigned int chan;
  1258. struct sk_buff *skb;
  1259. struct adapter *adap;
  1260. struct cpl_pass_open_req6 *req;
  1261. int ret;
  1262. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1263. if (!skb)
  1264. return -ENOMEM;
  1265. adap = netdev2adap(dev);
  1266. req = __skb_put(skb, sizeof(*req));
  1267. INIT_TP_WR(req, 0);
  1268. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ6, stid));
  1269. req->local_port = sport;
  1270. req->peer_port = htons(0);
  1271. req->local_ip_hi = *(__be64 *)(sip->s6_addr);
  1272. req->local_ip_lo = *(__be64 *)(sip->s6_addr + 8);
  1273. req->peer_ip_hi = cpu_to_be64(0);
  1274. req->peer_ip_lo = cpu_to_be64(0);
  1275. chan = rxq_to_chan(&adap->sge, queue);
  1276. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1277. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1278. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1279. ret = t4_mgmt_tx(adap, skb);
  1280. return net_xmit_eval(ret);
  1281. }
  1282. EXPORT_SYMBOL(cxgb4_create_server6);
  1283. int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
  1284. unsigned int queue, bool ipv6)
  1285. {
  1286. struct sk_buff *skb;
  1287. struct adapter *adap;
  1288. struct cpl_close_listsvr_req *req;
  1289. int ret;
  1290. adap = netdev2adap(dev);
  1291. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1292. if (!skb)
  1293. return -ENOMEM;
  1294. req = __skb_put(skb, sizeof(*req));
  1295. INIT_TP_WR(req, 0);
  1296. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, stid));
  1297. req->reply_ctrl = htons(NO_REPLY_V(0) | (ipv6 ? LISTSVR_IPV6_V(1) :
  1298. LISTSVR_IPV6_V(0)) | QUEUENO_V(queue));
  1299. ret = t4_mgmt_tx(adap, skb);
  1300. return net_xmit_eval(ret);
  1301. }
  1302. EXPORT_SYMBOL(cxgb4_remove_server);
  1303. /**
  1304. * cxgb4_best_mtu - find the entry in the MTU table closest to an MTU
  1305. * @mtus: the HW MTU table
  1306. * @mtu: the target MTU
  1307. * @idx: index of selected entry in the MTU table
  1308. *
  1309. * Returns the index and the value in the HW MTU table that is closest to
  1310. * but does not exceed @mtu, unless @mtu is smaller than any value in the
  1311. * table, in which case that smallest available value is selected.
  1312. */
  1313. unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
  1314. unsigned int *idx)
  1315. {
  1316. unsigned int i = 0;
  1317. while (i < NMTUS - 1 && mtus[i + 1] <= mtu)
  1318. ++i;
  1319. if (idx)
  1320. *idx = i;
  1321. return mtus[i];
  1322. }
  1323. EXPORT_SYMBOL(cxgb4_best_mtu);
  1324. /**
  1325. * cxgb4_best_aligned_mtu - find best MTU, [hopefully] data size aligned
  1326. * @mtus: the HW MTU table
  1327. * @header_size: Header Size
  1328. * @data_size_max: maximum Data Segment Size
  1329. * @data_size_align: desired Data Segment Size Alignment (2^N)
  1330. * @mtu_idxp: HW MTU Table Index return value pointer (possibly NULL)
  1331. *
  1332. * Similar to cxgb4_best_mtu() but instead of searching the Hardware
  1333. * MTU Table based solely on a Maximum MTU parameter, we break that
  1334. * parameter up into a Header Size and Maximum Data Segment Size, and
  1335. * provide a desired Data Segment Size Alignment. If we find an MTU in
  1336. * the Hardware MTU Table which will result in a Data Segment Size with
  1337. * the requested alignment _and_ that MTU isn't "too far" from the
  1338. * closest MTU, then we'll return that rather than the closest MTU.
  1339. */
  1340. unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
  1341. unsigned short header_size,
  1342. unsigned short data_size_max,
  1343. unsigned short data_size_align,
  1344. unsigned int *mtu_idxp)
  1345. {
  1346. unsigned short max_mtu = header_size + data_size_max;
  1347. unsigned short data_size_align_mask = data_size_align - 1;
  1348. int mtu_idx, aligned_mtu_idx;
  1349. /* Scan the MTU Table till we find an MTU which is larger than our
  1350. * Maximum MTU or we reach the end of the table. Along the way,
  1351. * record the last MTU found, if any, which will result in a Data
  1352. * Segment Length matching the requested alignment.
  1353. */
  1354. for (mtu_idx = 0, aligned_mtu_idx = -1; mtu_idx < NMTUS; mtu_idx++) {
  1355. unsigned short data_size = mtus[mtu_idx] - header_size;
  1356. /* If this MTU minus the Header Size would result in a
  1357. * Data Segment Size of the desired alignment, remember it.
  1358. */
  1359. if ((data_size & data_size_align_mask) == 0)
  1360. aligned_mtu_idx = mtu_idx;
  1361. /* If we're not at the end of the Hardware MTU Table and the
  1362. * next element is larger than our Maximum MTU, drop out of
  1363. * the loop.
  1364. */
  1365. if (mtu_idx+1 < NMTUS && mtus[mtu_idx+1] > max_mtu)
  1366. break;
  1367. }
  1368. /* If we fell out of the loop because we ran to the end of the table,
  1369. * then we just have to use the last [largest] entry.
  1370. */
  1371. if (mtu_idx == NMTUS)
  1372. mtu_idx--;
  1373. /* If we found an MTU which resulted in the requested Data Segment
  1374. * Length alignment and that's "not far" from the largest MTU which is
  1375. * less than or equal to the maximum MTU, then use that.
  1376. */
  1377. if (aligned_mtu_idx >= 0 &&
  1378. mtu_idx - aligned_mtu_idx <= 1)
  1379. mtu_idx = aligned_mtu_idx;
  1380. /* If the caller has passed in an MTU Index pointer, pass the
  1381. * MTU Index back. Return the MTU value.
  1382. */
  1383. if (mtu_idxp)
  1384. *mtu_idxp = mtu_idx;
  1385. return mtus[mtu_idx];
  1386. }
  1387. EXPORT_SYMBOL(cxgb4_best_aligned_mtu);
  1388. /**
  1389. * cxgb4_tp_smt_idx - Get the Source Mac Table index for this VI
  1390. * @chip: chip type
  1391. * @viid: VI id of the given port
  1392. *
  1393. * Return the SMT index for this VI.
  1394. */
  1395. unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid)
  1396. {
  1397. /* In T4/T5, SMT contains 256 SMAC entries organized in
  1398. * 128 rows of 2 entries each.
  1399. * In T6, SMT contains 256 SMAC entries in 256 rows.
  1400. * TODO: The below code needs to be updated when we add support
  1401. * for 256 VFs.
  1402. */
  1403. if (CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5)
  1404. return ((viid & 0x7f) << 1);
  1405. else
  1406. return (viid & 0x7f);
  1407. }
  1408. EXPORT_SYMBOL(cxgb4_tp_smt_idx);
  1409. /**
  1410. * cxgb4_port_chan - get the HW channel of a port
  1411. * @dev: the net device for the port
  1412. *
  1413. * Return the HW Tx channel of the given port.
  1414. */
  1415. unsigned int cxgb4_port_chan(const struct net_device *dev)
  1416. {
  1417. return netdev2pinfo(dev)->tx_chan;
  1418. }
  1419. EXPORT_SYMBOL(cxgb4_port_chan);
  1420. unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
  1421. {
  1422. struct adapter *adap = netdev2adap(dev);
  1423. u32 v1, v2, lp_count, hp_count;
  1424. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  1425. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  1426. if (is_t4(adap->params.chip)) {
  1427. lp_count = LP_COUNT_G(v1);
  1428. hp_count = HP_COUNT_G(v1);
  1429. } else {
  1430. lp_count = LP_COUNT_T5_G(v1);
  1431. hp_count = HP_COUNT_T5_G(v2);
  1432. }
  1433. return lpfifo ? lp_count : hp_count;
  1434. }
  1435. EXPORT_SYMBOL(cxgb4_dbfifo_count);
  1436. /**
  1437. * cxgb4_port_viid - get the VI id of a port
  1438. * @dev: the net device for the port
  1439. *
  1440. * Return the VI id of the given port.
  1441. */
  1442. unsigned int cxgb4_port_viid(const struct net_device *dev)
  1443. {
  1444. return netdev2pinfo(dev)->viid;
  1445. }
  1446. EXPORT_SYMBOL(cxgb4_port_viid);
  1447. /**
  1448. * cxgb4_port_idx - get the index of a port
  1449. * @dev: the net device for the port
  1450. *
  1451. * Return the index of the given port.
  1452. */
  1453. unsigned int cxgb4_port_idx(const struct net_device *dev)
  1454. {
  1455. return netdev2pinfo(dev)->port_id;
  1456. }
  1457. EXPORT_SYMBOL(cxgb4_port_idx);
  1458. void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
  1459. struct tp_tcp_stats *v6)
  1460. {
  1461. struct adapter *adap = pci_get_drvdata(pdev);
  1462. spin_lock(&adap->stats_lock);
  1463. t4_tp_get_tcp_stats(adap, v4, v6, false);
  1464. spin_unlock(&adap->stats_lock);
  1465. }
  1466. EXPORT_SYMBOL(cxgb4_get_tcp_stats);
  1467. void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
  1468. const unsigned int *pgsz_order)
  1469. {
  1470. struct adapter *adap = netdev2adap(dev);
  1471. t4_write_reg(adap, ULP_RX_ISCSI_TAGMASK_A, tag_mask);
  1472. t4_write_reg(adap, ULP_RX_ISCSI_PSZ_A, HPZ0_V(pgsz_order[0]) |
  1473. HPZ1_V(pgsz_order[1]) | HPZ2_V(pgsz_order[2]) |
  1474. HPZ3_V(pgsz_order[3]));
  1475. }
  1476. EXPORT_SYMBOL(cxgb4_iscsi_init);
  1477. int cxgb4_flush_eq_cache(struct net_device *dev)
  1478. {
  1479. struct adapter *adap = netdev2adap(dev);
  1480. return t4_sge_ctxt_flush(adap, adap->mbox, CTXT_EGRESS);
  1481. }
  1482. EXPORT_SYMBOL(cxgb4_flush_eq_cache);
  1483. static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
  1484. {
  1485. u32 addr = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A) + 24 * qid + 8;
  1486. __be64 indices;
  1487. int ret;
  1488. spin_lock(&adap->win0_lock);
  1489. ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
  1490. sizeof(indices), (__be32 *)&indices,
  1491. T4_MEMORY_READ);
  1492. spin_unlock(&adap->win0_lock);
  1493. if (!ret) {
  1494. *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
  1495. *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
  1496. }
  1497. return ret;
  1498. }
  1499. int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx,
  1500. u16 size)
  1501. {
  1502. struct adapter *adap = netdev2adap(dev);
  1503. u16 hw_pidx, hw_cidx;
  1504. int ret;
  1505. ret = read_eq_indices(adap, qid, &hw_pidx, &hw_cidx);
  1506. if (ret)
  1507. goto out;
  1508. if (pidx != hw_pidx) {
  1509. u16 delta;
  1510. u32 val;
  1511. if (pidx >= hw_pidx)
  1512. delta = pidx - hw_pidx;
  1513. else
  1514. delta = size - hw_pidx + pidx;
  1515. if (is_t4(adap->params.chip))
  1516. val = PIDX_V(delta);
  1517. else
  1518. val = PIDX_T5_V(delta);
  1519. wmb();
  1520. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1521. QID_V(qid) | val);
  1522. }
  1523. out:
  1524. return ret;
  1525. }
  1526. EXPORT_SYMBOL(cxgb4_sync_txq_pidx);
  1527. int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte)
  1528. {
  1529. u32 edc0_size, edc1_size, mc0_size, mc1_size, size;
  1530. u32 edc0_end, edc1_end, mc0_end, mc1_end;
  1531. u32 offset, memtype, memaddr;
  1532. struct adapter *adap;
  1533. u32 hma_size = 0;
  1534. int ret;
  1535. adap = netdev2adap(dev);
  1536. offset = ((stag >> 8) * 32) + adap->vres.stag.start;
  1537. /* Figure out where the offset lands in the Memory Type/Address scheme.
  1538. * This code assumes that the memory is laid out starting at offset 0
  1539. * with no breaks as: EDC0, EDC1, MC0, MC1. All cards have both EDC0
  1540. * and EDC1. Some cards will have neither MC0 nor MC1, most cards have
  1541. * MC0, and some have both MC0 and MC1.
  1542. */
  1543. size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
  1544. edc0_size = EDRAM0_SIZE_G(size) << 20;
  1545. size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
  1546. edc1_size = EDRAM1_SIZE_G(size) << 20;
  1547. size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
  1548. mc0_size = EXT_MEM0_SIZE_G(size) << 20;
  1549. if (t4_read_reg(adap, MA_TARGET_MEM_ENABLE_A) & HMA_MUX_F) {
  1550. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  1551. hma_size = EXT_MEM1_SIZE_G(size) << 20;
  1552. }
  1553. edc0_end = edc0_size;
  1554. edc1_end = edc0_end + edc1_size;
  1555. mc0_end = edc1_end + mc0_size;
  1556. if (offset < edc0_end) {
  1557. memtype = MEM_EDC0;
  1558. memaddr = offset;
  1559. } else if (offset < edc1_end) {
  1560. memtype = MEM_EDC1;
  1561. memaddr = offset - edc0_end;
  1562. } else {
  1563. if (hma_size && (offset < (edc1_end + hma_size))) {
  1564. memtype = MEM_HMA;
  1565. memaddr = offset - edc1_end;
  1566. } else if (offset < mc0_end) {
  1567. memtype = MEM_MC0;
  1568. memaddr = offset - edc1_end;
  1569. } else if (is_t5(adap->params.chip)) {
  1570. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  1571. mc1_size = EXT_MEM1_SIZE_G(size) << 20;
  1572. mc1_end = mc0_end + mc1_size;
  1573. if (offset < mc1_end) {
  1574. memtype = MEM_MC1;
  1575. memaddr = offset - mc0_end;
  1576. } else {
  1577. /* offset beyond the end of any memory */
  1578. goto err;
  1579. }
  1580. } else {
  1581. /* T4/T6 only has a single memory channel */
  1582. goto err;
  1583. }
  1584. }
  1585. spin_lock(&adap->win0_lock);
  1586. ret = t4_memory_rw(adap, 0, memtype, memaddr, 32, tpte, T4_MEMORY_READ);
  1587. spin_unlock(&adap->win0_lock);
  1588. return ret;
  1589. err:
  1590. dev_err(adap->pdev_dev, "stag %#x, offset %#x out of range\n",
  1591. stag, offset);
  1592. return -EINVAL;
  1593. }
  1594. EXPORT_SYMBOL(cxgb4_read_tpte);
  1595. u64 cxgb4_read_sge_timestamp(struct net_device *dev)
  1596. {
  1597. u32 hi, lo;
  1598. struct adapter *adap;
  1599. adap = netdev2adap(dev);
  1600. lo = t4_read_reg(adap, SGE_TIMESTAMP_LO_A);
  1601. hi = TSVAL_G(t4_read_reg(adap, SGE_TIMESTAMP_HI_A));
  1602. return ((u64)hi << 32) | (u64)lo;
  1603. }
  1604. EXPORT_SYMBOL(cxgb4_read_sge_timestamp);
  1605. int cxgb4_bar2_sge_qregs(struct net_device *dev,
  1606. unsigned int qid,
  1607. enum cxgb4_bar2_qtype qtype,
  1608. int user,
  1609. u64 *pbar2_qoffset,
  1610. unsigned int *pbar2_qid)
  1611. {
  1612. return t4_bar2_sge_qregs(netdev2adap(dev),
  1613. qid,
  1614. (qtype == CXGB4_BAR2_QTYPE_EGRESS
  1615. ? T4_BAR2_QTYPE_EGRESS
  1616. : T4_BAR2_QTYPE_INGRESS),
  1617. user,
  1618. pbar2_qoffset,
  1619. pbar2_qid);
  1620. }
  1621. EXPORT_SYMBOL(cxgb4_bar2_sge_qregs);
  1622. static struct pci_driver cxgb4_driver;
  1623. static void check_neigh_update(struct neighbour *neigh)
  1624. {
  1625. const struct device *parent;
  1626. const struct net_device *netdev = neigh->dev;
  1627. if (is_vlan_dev(netdev))
  1628. netdev = vlan_dev_real_dev(netdev);
  1629. parent = netdev->dev.parent;
  1630. if (parent && parent->driver == &cxgb4_driver.driver)
  1631. t4_l2t_update(dev_get_drvdata(parent), neigh);
  1632. }
  1633. static int netevent_cb(struct notifier_block *nb, unsigned long event,
  1634. void *data)
  1635. {
  1636. switch (event) {
  1637. case NETEVENT_NEIGH_UPDATE:
  1638. check_neigh_update(data);
  1639. break;
  1640. case NETEVENT_REDIRECT:
  1641. default:
  1642. break;
  1643. }
  1644. return 0;
  1645. }
  1646. static bool netevent_registered;
  1647. static struct notifier_block cxgb4_netevent_nb = {
  1648. .notifier_call = netevent_cb
  1649. };
  1650. static void drain_db_fifo(struct adapter *adap, int usecs)
  1651. {
  1652. u32 v1, v2, lp_count, hp_count;
  1653. do {
  1654. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  1655. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  1656. if (is_t4(adap->params.chip)) {
  1657. lp_count = LP_COUNT_G(v1);
  1658. hp_count = HP_COUNT_G(v1);
  1659. } else {
  1660. lp_count = LP_COUNT_T5_G(v1);
  1661. hp_count = HP_COUNT_T5_G(v2);
  1662. }
  1663. if (lp_count == 0 && hp_count == 0)
  1664. break;
  1665. set_current_state(TASK_UNINTERRUPTIBLE);
  1666. schedule_timeout(usecs_to_jiffies(usecs));
  1667. } while (1);
  1668. }
  1669. static void disable_txq_db(struct sge_txq *q)
  1670. {
  1671. unsigned long flags;
  1672. spin_lock_irqsave(&q->db_lock, flags);
  1673. q->db_disabled = 1;
  1674. spin_unlock_irqrestore(&q->db_lock, flags);
  1675. }
  1676. static void enable_txq_db(struct adapter *adap, struct sge_txq *q)
  1677. {
  1678. spin_lock_irq(&q->db_lock);
  1679. if (q->db_pidx_inc) {
  1680. /* Make sure that all writes to the TX descriptors
  1681. * are committed before we tell HW about them.
  1682. */
  1683. wmb();
  1684. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1685. QID_V(q->cntxt_id) | PIDX_V(q->db_pidx_inc));
  1686. q->db_pidx_inc = 0;
  1687. }
  1688. q->db_disabled = 0;
  1689. spin_unlock_irq(&q->db_lock);
  1690. }
  1691. static void disable_dbs(struct adapter *adap)
  1692. {
  1693. int i;
  1694. for_each_ethrxq(&adap->sge, i)
  1695. disable_txq_db(&adap->sge.ethtxq[i].q);
  1696. if (is_offload(adap)) {
  1697. struct sge_uld_txq_info *txq_info =
  1698. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1699. if (txq_info) {
  1700. for_each_ofldtxq(&adap->sge, i) {
  1701. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1702. disable_txq_db(&txq->q);
  1703. }
  1704. }
  1705. }
  1706. for_each_port(adap, i)
  1707. disable_txq_db(&adap->sge.ctrlq[i].q);
  1708. }
  1709. static void enable_dbs(struct adapter *adap)
  1710. {
  1711. int i;
  1712. for_each_ethrxq(&adap->sge, i)
  1713. enable_txq_db(adap, &adap->sge.ethtxq[i].q);
  1714. if (is_offload(adap)) {
  1715. struct sge_uld_txq_info *txq_info =
  1716. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1717. if (txq_info) {
  1718. for_each_ofldtxq(&adap->sge, i) {
  1719. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1720. enable_txq_db(adap, &txq->q);
  1721. }
  1722. }
  1723. }
  1724. for_each_port(adap, i)
  1725. enable_txq_db(adap, &adap->sge.ctrlq[i].q);
  1726. }
  1727. static void notify_rdma_uld(struct adapter *adap, enum cxgb4_control cmd)
  1728. {
  1729. enum cxgb4_uld type = CXGB4_ULD_RDMA;
  1730. if (adap->uld && adap->uld[type].handle)
  1731. adap->uld[type].control(adap->uld[type].handle, cmd);
  1732. }
  1733. static void process_db_full(struct work_struct *work)
  1734. {
  1735. struct adapter *adap;
  1736. adap = container_of(work, struct adapter, db_full_task);
  1737. drain_db_fifo(adap, dbfifo_drain_delay);
  1738. enable_dbs(adap);
  1739. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  1740. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1741. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1742. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F,
  1743. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F);
  1744. else
  1745. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1746. DBFIFO_LP_INT_F, DBFIFO_LP_INT_F);
  1747. }
  1748. static void sync_txq_pidx(struct adapter *adap, struct sge_txq *q)
  1749. {
  1750. u16 hw_pidx, hw_cidx;
  1751. int ret;
  1752. spin_lock_irq(&q->db_lock);
  1753. ret = read_eq_indices(adap, (u16)q->cntxt_id, &hw_pidx, &hw_cidx);
  1754. if (ret)
  1755. goto out;
  1756. if (q->db_pidx != hw_pidx) {
  1757. u16 delta;
  1758. u32 val;
  1759. if (q->db_pidx >= hw_pidx)
  1760. delta = q->db_pidx - hw_pidx;
  1761. else
  1762. delta = q->size - hw_pidx + q->db_pidx;
  1763. if (is_t4(adap->params.chip))
  1764. val = PIDX_V(delta);
  1765. else
  1766. val = PIDX_T5_V(delta);
  1767. wmb();
  1768. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1769. QID_V(q->cntxt_id) | val);
  1770. }
  1771. out:
  1772. q->db_disabled = 0;
  1773. q->db_pidx_inc = 0;
  1774. spin_unlock_irq(&q->db_lock);
  1775. if (ret)
  1776. CH_WARN(adap, "DB drop recovery failed.\n");
  1777. }
  1778. static void recover_all_queues(struct adapter *adap)
  1779. {
  1780. int i;
  1781. for_each_ethrxq(&adap->sge, i)
  1782. sync_txq_pidx(adap, &adap->sge.ethtxq[i].q);
  1783. if (is_offload(adap)) {
  1784. struct sge_uld_txq_info *txq_info =
  1785. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1786. if (txq_info) {
  1787. for_each_ofldtxq(&adap->sge, i) {
  1788. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1789. sync_txq_pidx(adap, &txq->q);
  1790. }
  1791. }
  1792. }
  1793. for_each_port(adap, i)
  1794. sync_txq_pidx(adap, &adap->sge.ctrlq[i].q);
  1795. }
  1796. static void process_db_drop(struct work_struct *work)
  1797. {
  1798. struct adapter *adap;
  1799. adap = container_of(work, struct adapter, db_drop_task);
  1800. if (is_t4(adap->params.chip)) {
  1801. drain_db_fifo(adap, dbfifo_drain_delay);
  1802. notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
  1803. drain_db_fifo(adap, dbfifo_drain_delay);
  1804. recover_all_queues(adap);
  1805. drain_db_fifo(adap, dbfifo_drain_delay);
  1806. enable_dbs(adap);
  1807. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  1808. } else if (is_t5(adap->params.chip)) {
  1809. u32 dropped_db = t4_read_reg(adap, 0x010ac);
  1810. u16 qid = (dropped_db >> 15) & 0x1ffff;
  1811. u16 pidx_inc = dropped_db & 0x1fff;
  1812. u64 bar2_qoffset;
  1813. unsigned int bar2_qid;
  1814. int ret;
  1815. ret = t4_bar2_sge_qregs(adap, qid, T4_BAR2_QTYPE_EGRESS,
  1816. 0, &bar2_qoffset, &bar2_qid);
  1817. if (ret)
  1818. dev_err(adap->pdev_dev, "doorbell drop recovery: "
  1819. "qid=%d, pidx_inc=%d\n", qid, pidx_inc);
  1820. else
  1821. writel(PIDX_T5_V(pidx_inc) | QID_V(bar2_qid),
  1822. adap->bar2 + bar2_qoffset + SGE_UDB_KDOORBELL);
  1823. /* Re-enable BAR2 WC */
  1824. t4_set_reg_field(adap, 0x10b0, 1<<15, 1<<15);
  1825. }
  1826. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1827. t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, DROPPED_DB_F, 0);
  1828. }
  1829. void t4_db_full(struct adapter *adap)
  1830. {
  1831. if (is_t4(adap->params.chip)) {
  1832. disable_dbs(adap);
  1833. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  1834. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1835. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F, 0);
  1836. queue_work(adap->workq, &adap->db_full_task);
  1837. }
  1838. }
  1839. void t4_db_dropped(struct adapter *adap)
  1840. {
  1841. if (is_t4(adap->params.chip)) {
  1842. disable_dbs(adap);
  1843. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  1844. }
  1845. queue_work(adap->workq, &adap->db_drop_task);
  1846. }
  1847. void t4_register_netevent_notifier(void)
  1848. {
  1849. if (!netevent_registered) {
  1850. register_netevent_notifier(&cxgb4_netevent_nb);
  1851. netevent_registered = true;
  1852. }
  1853. }
  1854. static void detach_ulds(struct adapter *adap)
  1855. {
  1856. unsigned int i;
  1857. mutex_lock(&uld_mutex);
  1858. list_del(&adap->list_node);
  1859. for (i = 0; i < CXGB4_ULD_MAX; i++)
  1860. if (adap->uld && adap->uld[i].handle)
  1861. adap->uld[i].state_change(adap->uld[i].handle,
  1862. CXGB4_STATE_DETACH);
  1863. if (netevent_registered && list_empty(&adapter_list)) {
  1864. unregister_netevent_notifier(&cxgb4_netevent_nb);
  1865. netevent_registered = false;
  1866. }
  1867. mutex_unlock(&uld_mutex);
  1868. }
  1869. static void notify_ulds(struct adapter *adap, enum cxgb4_state new_state)
  1870. {
  1871. unsigned int i;
  1872. mutex_lock(&uld_mutex);
  1873. for (i = 0; i < CXGB4_ULD_MAX; i++)
  1874. if (adap->uld && adap->uld[i].handle)
  1875. adap->uld[i].state_change(adap->uld[i].handle,
  1876. new_state);
  1877. mutex_unlock(&uld_mutex);
  1878. }
  1879. #if IS_ENABLED(CONFIG_IPV6)
  1880. static int cxgb4_inet6addr_handler(struct notifier_block *this,
  1881. unsigned long event, void *data)
  1882. {
  1883. struct inet6_ifaddr *ifa = data;
  1884. struct net_device *event_dev = ifa->idev->dev;
  1885. const struct device *parent = NULL;
  1886. #if IS_ENABLED(CONFIG_BONDING)
  1887. struct adapter *adap;
  1888. #endif
  1889. if (is_vlan_dev(event_dev))
  1890. event_dev = vlan_dev_real_dev(event_dev);
  1891. #if IS_ENABLED(CONFIG_BONDING)
  1892. if (event_dev->flags & IFF_MASTER) {
  1893. list_for_each_entry(adap, &adapter_list, list_node) {
  1894. switch (event) {
  1895. case NETDEV_UP:
  1896. cxgb4_clip_get(adap->port[0],
  1897. (const u32 *)ifa, 1);
  1898. break;
  1899. case NETDEV_DOWN:
  1900. cxgb4_clip_release(adap->port[0],
  1901. (const u32 *)ifa, 1);
  1902. break;
  1903. default:
  1904. break;
  1905. }
  1906. }
  1907. return NOTIFY_OK;
  1908. }
  1909. #endif
  1910. if (event_dev)
  1911. parent = event_dev->dev.parent;
  1912. if (parent && parent->driver == &cxgb4_driver.driver) {
  1913. switch (event) {
  1914. case NETDEV_UP:
  1915. cxgb4_clip_get(event_dev, (const u32 *)ifa, 1);
  1916. break;
  1917. case NETDEV_DOWN:
  1918. cxgb4_clip_release(event_dev, (const u32 *)ifa, 1);
  1919. break;
  1920. default:
  1921. break;
  1922. }
  1923. }
  1924. return NOTIFY_OK;
  1925. }
  1926. static bool inet6addr_registered;
  1927. static struct notifier_block cxgb4_inet6addr_notifier = {
  1928. .notifier_call = cxgb4_inet6addr_handler
  1929. };
  1930. static void update_clip(const struct adapter *adap)
  1931. {
  1932. int i;
  1933. struct net_device *dev;
  1934. int ret;
  1935. rcu_read_lock();
  1936. for (i = 0; i < MAX_NPORTS; i++) {
  1937. dev = adap->port[i];
  1938. ret = 0;
  1939. if (dev)
  1940. ret = cxgb4_update_root_dev_clip(dev);
  1941. if (ret < 0)
  1942. break;
  1943. }
  1944. rcu_read_unlock();
  1945. }
  1946. #endif /* IS_ENABLED(CONFIG_IPV6) */
  1947. /**
  1948. * cxgb_up - enable the adapter
  1949. * @adap: adapter being enabled
  1950. *
  1951. * Called when the first port is enabled, this function performs the
  1952. * actions necessary to make an adapter operational, such as completing
  1953. * the initialization of HW modules, and enabling interrupts.
  1954. *
  1955. * Must be called with the rtnl lock held.
  1956. */
  1957. static int cxgb_up(struct adapter *adap)
  1958. {
  1959. int err;
  1960. mutex_lock(&uld_mutex);
  1961. err = setup_sge_queues(adap);
  1962. if (err)
  1963. goto rel_lock;
  1964. err = setup_rss(adap);
  1965. if (err)
  1966. goto freeq;
  1967. if (adap->flags & USING_MSIX) {
  1968. name_msix_vecs(adap);
  1969. err = request_irq(adap->msix_info[0].vec, t4_nondata_intr, 0,
  1970. adap->msix_info[0].desc, adap);
  1971. if (err)
  1972. goto irq_err;
  1973. err = request_msix_queue_irqs(adap);
  1974. if (err) {
  1975. free_irq(adap->msix_info[0].vec, adap);
  1976. goto irq_err;
  1977. }
  1978. } else {
  1979. err = request_irq(adap->pdev->irq, t4_intr_handler(adap),
  1980. (adap->flags & USING_MSI) ? 0 : IRQF_SHARED,
  1981. adap->port[0]->name, adap);
  1982. if (err)
  1983. goto irq_err;
  1984. }
  1985. enable_rx(adap);
  1986. t4_sge_start(adap);
  1987. t4_intr_enable(adap);
  1988. adap->flags |= FULL_INIT_DONE;
  1989. mutex_unlock(&uld_mutex);
  1990. notify_ulds(adap, CXGB4_STATE_UP);
  1991. #if IS_ENABLED(CONFIG_IPV6)
  1992. update_clip(adap);
  1993. #endif
  1994. /* Initialize hash mac addr list*/
  1995. INIT_LIST_HEAD(&adap->mac_hlist);
  1996. return err;
  1997. irq_err:
  1998. dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
  1999. freeq:
  2000. t4_free_sge_resources(adap);
  2001. rel_lock:
  2002. mutex_unlock(&uld_mutex);
  2003. return err;
  2004. }
  2005. static void cxgb_down(struct adapter *adapter)
  2006. {
  2007. cancel_work_sync(&adapter->tid_release_task);
  2008. cancel_work_sync(&adapter->db_full_task);
  2009. cancel_work_sync(&adapter->db_drop_task);
  2010. adapter->tid_release_task_busy = false;
  2011. adapter->tid_release_head = NULL;
  2012. t4_sge_stop(adapter);
  2013. t4_free_sge_resources(adapter);
  2014. adapter->flags &= ~FULL_INIT_DONE;
  2015. }
  2016. /*
  2017. * net_device operations
  2018. */
  2019. static int cxgb_open(struct net_device *dev)
  2020. {
  2021. int err;
  2022. struct port_info *pi = netdev_priv(dev);
  2023. struct adapter *adapter = pi->adapter;
  2024. netif_carrier_off(dev);
  2025. if (!(adapter->flags & FULL_INIT_DONE)) {
  2026. err = cxgb_up(adapter);
  2027. if (err < 0)
  2028. return err;
  2029. }
  2030. /* It's possible that the basic port information could have
  2031. * changed since we first read it.
  2032. */
  2033. err = t4_update_port_info(pi);
  2034. if (err < 0)
  2035. return err;
  2036. err = link_start(dev);
  2037. if (!err)
  2038. netif_tx_start_all_queues(dev);
  2039. return err;
  2040. }
  2041. static int cxgb_close(struct net_device *dev)
  2042. {
  2043. struct port_info *pi = netdev_priv(dev);
  2044. struct adapter *adapter = pi->adapter;
  2045. int ret;
  2046. netif_tx_stop_all_queues(dev);
  2047. netif_carrier_off(dev);
  2048. ret = t4_enable_vi(adapter, adapter->pf, pi->viid, false, false);
  2049. #ifdef CONFIG_CHELSIO_T4_DCB
  2050. cxgb4_dcb_reset(dev);
  2051. dcb_tx_queue_prio_enable(dev, false);
  2052. #endif
  2053. return ret;
  2054. }
  2055. int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
  2056. __be32 sip, __be16 sport, __be16 vlan,
  2057. unsigned int queue, unsigned char port, unsigned char mask)
  2058. {
  2059. int ret;
  2060. struct filter_entry *f;
  2061. struct adapter *adap;
  2062. int i;
  2063. u8 *val;
  2064. adap = netdev2adap(dev);
  2065. /* Adjust stid to correct filter index */
  2066. stid -= adap->tids.sftid_base;
  2067. stid += adap->tids.nftids;
  2068. /* Check to make sure the filter requested is writable ...
  2069. */
  2070. f = &adap->tids.ftid_tab[stid];
  2071. ret = writable_filter(f);
  2072. if (ret)
  2073. return ret;
  2074. /* Clear out any old resources being used by the filter before
  2075. * we start constructing the new filter.
  2076. */
  2077. if (f->valid)
  2078. clear_filter(adap, f);
  2079. /* Clear out filter specifications */
  2080. memset(&f->fs, 0, sizeof(struct ch_filter_specification));
  2081. f->fs.val.lport = cpu_to_be16(sport);
  2082. f->fs.mask.lport = ~0;
  2083. val = (u8 *)&sip;
  2084. if ((val[0] | val[1] | val[2] | val[3]) != 0) {
  2085. for (i = 0; i < 4; i++) {
  2086. f->fs.val.lip[i] = val[i];
  2087. f->fs.mask.lip[i] = ~0;
  2088. }
  2089. if (adap->params.tp.vlan_pri_map & PORT_F) {
  2090. f->fs.val.iport = port;
  2091. f->fs.mask.iport = mask;
  2092. }
  2093. }
  2094. if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
  2095. f->fs.val.proto = IPPROTO_TCP;
  2096. f->fs.mask.proto = ~0;
  2097. }
  2098. f->fs.dirsteer = 1;
  2099. f->fs.iq = queue;
  2100. /* Mark filter as locked */
  2101. f->locked = 1;
  2102. f->fs.rpttid = 1;
  2103. /* Save the actual tid. We need this to get the corresponding
  2104. * filter entry structure in filter_rpl.
  2105. */
  2106. f->tid = stid + adap->tids.ftid_base;
  2107. ret = set_filter_wr(adap, stid);
  2108. if (ret) {
  2109. clear_filter(adap, f);
  2110. return ret;
  2111. }
  2112. return 0;
  2113. }
  2114. EXPORT_SYMBOL(cxgb4_create_server_filter);
  2115. int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
  2116. unsigned int queue, bool ipv6)
  2117. {
  2118. struct filter_entry *f;
  2119. struct adapter *adap;
  2120. adap = netdev2adap(dev);
  2121. /* Adjust stid to correct filter index */
  2122. stid -= adap->tids.sftid_base;
  2123. stid += adap->tids.nftids;
  2124. f = &adap->tids.ftid_tab[stid];
  2125. /* Unlock the filter */
  2126. f->locked = 0;
  2127. return delete_filter(adap, stid);
  2128. }
  2129. EXPORT_SYMBOL(cxgb4_remove_server_filter);
  2130. static void cxgb_get_stats(struct net_device *dev,
  2131. struct rtnl_link_stats64 *ns)
  2132. {
  2133. struct port_stats stats;
  2134. struct port_info *p = netdev_priv(dev);
  2135. struct adapter *adapter = p->adapter;
  2136. /* Block retrieving statistics during EEH error
  2137. * recovery. Otherwise, the recovery might fail
  2138. * and the PCI device will be removed permanently
  2139. */
  2140. spin_lock(&adapter->stats_lock);
  2141. if (!netif_device_present(dev)) {
  2142. spin_unlock(&adapter->stats_lock);
  2143. return;
  2144. }
  2145. t4_get_port_stats_offset(adapter, p->tx_chan, &stats,
  2146. &p->stats_base);
  2147. spin_unlock(&adapter->stats_lock);
  2148. ns->tx_bytes = stats.tx_octets;
  2149. ns->tx_packets = stats.tx_frames;
  2150. ns->rx_bytes = stats.rx_octets;
  2151. ns->rx_packets = stats.rx_frames;
  2152. ns->multicast = stats.rx_mcast_frames;
  2153. /* detailed rx_errors */
  2154. ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
  2155. stats.rx_runt;
  2156. ns->rx_over_errors = 0;
  2157. ns->rx_crc_errors = stats.rx_fcs_err;
  2158. ns->rx_frame_errors = stats.rx_symbol_err;
  2159. ns->rx_dropped = stats.rx_ovflow0 + stats.rx_ovflow1 +
  2160. stats.rx_ovflow2 + stats.rx_ovflow3 +
  2161. stats.rx_trunc0 + stats.rx_trunc1 +
  2162. stats.rx_trunc2 + stats.rx_trunc3;
  2163. ns->rx_missed_errors = 0;
  2164. /* detailed tx_errors */
  2165. ns->tx_aborted_errors = 0;
  2166. ns->tx_carrier_errors = 0;
  2167. ns->tx_fifo_errors = 0;
  2168. ns->tx_heartbeat_errors = 0;
  2169. ns->tx_window_errors = 0;
  2170. ns->tx_errors = stats.tx_error_frames;
  2171. ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
  2172. ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
  2173. }
  2174. static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  2175. {
  2176. unsigned int mbox;
  2177. int ret = 0, prtad, devad;
  2178. struct port_info *pi = netdev_priv(dev);
  2179. struct adapter *adapter = pi->adapter;
  2180. struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
  2181. switch (cmd) {
  2182. case SIOCGMIIPHY:
  2183. if (pi->mdio_addr < 0)
  2184. return -EOPNOTSUPP;
  2185. data->phy_id = pi->mdio_addr;
  2186. break;
  2187. case SIOCGMIIREG:
  2188. case SIOCSMIIREG:
  2189. if (mdio_phy_id_is_c45(data->phy_id)) {
  2190. prtad = mdio_phy_id_prtad(data->phy_id);
  2191. devad = mdio_phy_id_devad(data->phy_id);
  2192. } else if (data->phy_id < 32) {
  2193. prtad = data->phy_id;
  2194. devad = 0;
  2195. data->reg_num &= 0x1f;
  2196. } else
  2197. return -EINVAL;
  2198. mbox = pi->adapter->pf;
  2199. if (cmd == SIOCGMIIREG)
  2200. ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
  2201. data->reg_num, &data->val_out);
  2202. else
  2203. ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
  2204. data->reg_num, data->val_in);
  2205. break;
  2206. case SIOCGHWTSTAMP:
  2207. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2208. sizeof(pi->tstamp_config)) ?
  2209. -EFAULT : 0;
  2210. case SIOCSHWTSTAMP:
  2211. if (copy_from_user(&pi->tstamp_config, req->ifr_data,
  2212. sizeof(pi->tstamp_config)))
  2213. return -EFAULT;
  2214. if (!is_t4(adapter->params.chip)) {
  2215. switch (pi->tstamp_config.tx_type) {
  2216. case HWTSTAMP_TX_OFF:
  2217. case HWTSTAMP_TX_ON:
  2218. break;
  2219. default:
  2220. return -ERANGE;
  2221. }
  2222. switch (pi->tstamp_config.rx_filter) {
  2223. case HWTSTAMP_FILTER_NONE:
  2224. pi->rxtstamp = false;
  2225. break;
  2226. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  2227. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  2228. cxgb4_ptprx_timestamping(pi, pi->port_id,
  2229. PTP_TS_L4);
  2230. break;
  2231. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  2232. cxgb4_ptprx_timestamping(pi, pi->port_id,
  2233. PTP_TS_L2_L4);
  2234. break;
  2235. case HWTSTAMP_FILTER_ALL:
  2236. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  2237. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  2238. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  2239. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  2240. pi->rxtstamp = true;
  2241. break;
  2242. default:
  2243. pi->tstamp_config.rx_filter =
  2244. HWTSTAMP_FILTER_NONE;
  2245. return -ERANGE;
  2246. }
  2247. if ((pi->tstamp_config.tx_type == HWTSTAMP_TX_OFF) &&
  2248. (pi->tstamp_config.rx_filter ==
  2249. HWTSTAMP_FILTER_NONE)) {
  2250. if (cxgb4_ptp_txtype(adapter, pi->port_id) >= 0)
  2251. pi->ptp_enable = false;
  2252. }
  2253. if (pi->tstamp_config.rx_filter !=
  2254. HWTSTAMP_FILTER_NONE) {
  2255. if (cxgb4_ptp_redirect_rx_packet(adapter,
  2256. pi) >= 0)
  2257. pi->ptp_enable = true;
  2258. }
  2259. } else {
  2260. /* For T4 Adapters */
  2261. switch (pi->tstamp_config.rx_filter) {
  2262. case HWTSTAMP_FILTER_NONE:
  2263. pi->rxtstamp = false;
  2264. break;
  2265. case HWTSTAMP_FILTER_ALL:
  2266. pi->rxtstamp = true;
  2267. break;
  2268. default:
  2269. pi->tstamp_config.rx_filter =
  2270. HWTSTAMP_FILTER_NONE;
  2271. return -ERANGE;
  2272. }
  2273. }
  2274. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2275. sizeof(pi->tstamp_config)) ?
  2276. -EFAULT : 0;
  2277. default:
  2278. return -EOPNOTSUPP;
  2279. }
  2280. return ret;
  2281. }
  2282. static void cxgb_set_rxmode(struct net_device *dev)
  2283. {
  2284. /* unfortunately we can't return errors to the stack */
  2285. set_rxmode(dev, -1, false);
  2286. }
  2287. static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
  2288. {
  2289. int ret;
  2290. struct port_info *pi = netdev_priv(dev);
  2291. ret = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, new_mtu, -1,
  2292. -1, -1, -1, true);
  2293. if (!ret)
  2294. dev->mtu = new_mtu;
  2295. return ret;
  2296. }
  2297. #ifdef CONFIG_PCI_IOV
  2298. static int cxgb4_mgmt_open(struct net_device *dev)
  2299. {
  2300. /* Turn carrier off since we don't have to transmit anything on this
  2301. * interface.
  2302. */
  2303. netif_carrier_off(dev);
  2304. return 0;
  2305. }
  2306. /* Fill MAC address that will be assigned by the FW */
  2307. static void cxgb4_mgmt_fill_vf_station_mac_addr(struct adapter *adap)
  2308. {
  2309. u8 hw_addr[ETH_ALEN], macaddr[ETH_ALEN];
  2310. unsigned int i, vf, nvfs;
  2311. u16 a, b;
  2312. int err;
  2313. u8 *na;
  2314. adap->params.pci.vpd_cap_addr = pci_find_capability(adap->pdev,
  2315. PCI_CAP_ID_VPD);
  2316. err = t4_get_raw_vpd_params(adap, &adap->params.vpd);
  2317. if (err)
  2318. return;
  2319. na = adap->params.vpd.na;
  2320. for (i = 0; i < ETH_ALEN; i++)
  2321. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  2322. hex2val(na[2 * i + 1]));
  2323. a = (hw_addr[0] << 8) | hw_addr[1];
  2324. b = (hw_addr[1] << 8) | hw_addr[2];
  2325. a ^= b;
  2326. a |= 0x0200; /* locally assigned Ethernet MAC address */
  2327. a &= ~0x0100; /* not a multicast Ethernet MAC address */
  2328. macaddr[0] = a >> 8;
  2329. macaddr[1] = a & 0xff;
  2330. for (i = 2; i < 5; i++)
  2331. macaddr[i] = hw_addr[i + 1];
  2332. for (vf = 0, nvfs = pci_sriov_get_totalvfs(adap->pdev);
  2333. vf < nvfs; vf++) {
  2334. macaddr[5] = adap->pf * 16 + vf;
  2335. ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, macaddr);
  2336. }
  2337. }
  2338. static int cxgb4_mgmt_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
  2339. {
  2340. struct port_info *pi = netdev_priv(dev);
  2341. struct adapter *adap = pi->adapter;
  2342. int ret;
  2343. /* verify MAC addr is valid */
  2344. if (!is_valid_ether_addr(mac)) {
  2345. dev_err(pi->adapter->pdev_dev,
  2346. "Invalid Ethernet address %pM for VF %d\n",
  2347. mac, vf);
  2348. return -EINVAL;
  2349. }
  2350. dev_info(pi->adapter->pdev_dev,
  2351. "Setting MAC %pM on VF %d\n", mac, vf);
  2352. ret = t4_set_vf_mac_acl(adap, vf + 1, 1, mac);
  2353. if (!ret)
  2354. ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, mac);
  2355. return ret;
  2356. }
  2357. static int cxgb4_mgmt_get_vf_config(struct net_device *dev,
  2358. int vf, struct ifla_vf_info *ivi)
  2359. {
  2360. struct port_info *pi = netdev_priv(dev);
  2361. struct adapter *adap = pi->adapter;
  2362. struct vf_info *vfinfo;
  2363. if (vf >= adap->num_vfs)
  2364. return -EINVAL;
  2365. vfinfo = &adap->vfinfo[vf];
  2366. ivi->vf = vf;
  2367. ivi->max_tx_rate = vfinfo->tx_rate;
  2368. ivi->min_tx_rate = 0;
  2369. ether_addr_copy(ivi->mac, vfinfo->vf_mac_addr);
  2370. ivi->vlan = vfinfo->vlan;
  2371. return 0;
  2372. }
  2373. static int cxgb4_mgmt_get_phys_port_id(struct net_device *dev,
  2374. struct netdev_phys_item_id *ppid)
  2375. {
  2376. struct port_info *pi = netdev_priv(dev);
  2377. unsigned int phy_port_id;
  2378. phy_port_id = pi->adapter->adap_idx * 10 + pi->port_id;
  2379. ppid->id_len = sizeof(phy_port_id);
  2380. memcpy(ppid->id, &phy_port_id, ppid->id_len);
  2381. return 0;
  2382. }
  2383. static int cxgb4_mgmt_set_vf_rate(struct net_device *dev, int vf,
  2384. int min_tx_rate, int max_tx_rate)
  2385. {
  2386. struct port_info *pi = netdev_priv(dev);
  2387. struct adapter *adap = pi->adapter;
  2388. unsigned int link_ok, speed, mtu;
  2389. u32 fw_pfvf, fw_class;
  2390. int class_id = vf;
  2391. int ret;
  2392. u16 pktsize;
  2393. if (vf >= adap->num_vfs)
  2394. return -EINVAL;
  2395. if (min_tx_rate) {
  2396. dev_err(adap->pdev_dev,
  2397. "Min tx rate (%d) (> 0) for VF %d is Invalid.\n",
  2398. min_tx_rate, vf);
  2399. return -EINVAL;
  2400. }
  2401. ret = t4_get_link_params(pi, &link_ok, &speed, &mtu);
  2402. if (ret != FW_SUCCESS) {
  2403. dev_err(adap->pdev_dev,
  2404. "Failed to get link information for VF %d\n", vf);
  2405. return -EINVAL;
  2406. }
  2407. if (!link_ok) {
  2408. dev_err(adap->pdev_dev, "Link down for VF %d\n", vf);
  2409. return -EINVAL;
  2410. }
  2411. if (max_tx_rate > speed) {
  2412. dev_err(adap->pdev_dev,
  2413. "Max tx rate %d for VF %d can't be > link-speed %u",
  2414. max_tx_rate, vf, speed);
  2415. return -EINVAL;
  2416. }
  2417. pktsize = mtu;
  2418. /* subtract ethhdr size and 4 bytes crc since, f/w appends it */
  2419. pktsize = pktsize - sizeof(struct ethhdr) - 4;
  2420. /* subtract ipv4 hdr size, tcp hdr size to get typical IPv4 MSS size */
  2421. pktsize = pktsize - sizeof(struct iphdr) - sizeof(struct tcphdr);
  2422. /* configure Traffic Class for rate-limiting */
  2423. ret = t4_sched_params(adap, SCHED_CLASS_TYPE_PACKET,
  2424. SCHED_CLASS_LEVEL_CL_RL,
  2425. SCHED_CLASS_MODE_CLASS,
  2426. SCHED_CLASS_RATEUNIT_BITS,
  2427. SCHED_CLASS_RATEMODE_ABS,
  2428. pi->tx_chan, class_id, 0,
  2429. max_tx_rate * 1000, 0, pktsize);
  2430. if (ret) {
  2431. dev_err(adap->pdev_dev, "Err %d for Traffic Class config\n",
  2432. ret);
  2433. return -EINVAL;
  2434. }
  2435. dev_info(adap->pdev_dev,
  2436. "Class %d with MSS %u configured with rate %u\n",
  2437. class_id, pktsize, max_tx_rate);
  2438. /* bind VF to configured Traffic Class */
  2439. fw_pfvf = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) |
  2440. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_SCHEDCLASS_ETH));
  2441. fw_class = class_id;
  2442. ret = t4_set_params(adap, adap->mbox, adap->pf, vf + 1, 1, &fw_pfvf,
  2443. &fw_class);
  2444. if (ret) {
  2445. dev_err(adap->pdev_dev,
  2446. "Err %d in binding VF %d to Traffic Class %d\n",
  2447. ret, vf, class_id);
  2448. return -EINVAL;
  2449. }
  2450. dev_info(adap->pdev_dev, "PF %d VF %d is bound to Class %d\n",
  2451. adap->pf, vf, class_id);
  2452. adap->vfinfo[vf].tx_rate = max_tx_rate;
  2453. return 0;
  2454. }
  2455. static int cxgb4_mgmt_set_vf_vlan(struct net_device *dev, int vf,
  2456. u16 vlan, u8 qos, __be16 vlan_proto)
  2457. {
  2458. struct port_info *pi = netdev_priv(dev);
  2459. struct adapter *adap = pi->adapter;
  2460. int ret;
  2461. if (vf >= adap->num_vfs || vlan > 4095 || qos > 7)
  2462. return -EINVAL;
  2463. if (vlan_proto != htons(ETH_P_8021Q) || qos != 0)
  2464. return -EPROTONOSUPPORT;
  2465. ret = t4_set_vlan_acl(adap, adap->mbox, vf + 1, vlan);
  2466. if (!ret) {
  2467. adap->vfinfo[vf].vlan = vlan;
  2468. return 0;
  2469. }
  2470. dev_err(adap->pdev_dev, "Err %d %s VLAN ACL for PF/VF %d/%d\n",
  2471. ret, (vlan ? "setting" : "clearing"), adap->pf, vf);
  2472. return ret;
  2473. }
  2474. #endif /* CONFIG_PCI_IOV */
  2475. static int cxgb_set_mac_addr(struct net_device *dev, void *p)
  2476. {
  2477. int ret;
  2478. struct sockaddr *addr = p;
  2479. struct port_info *pi = netdev_priv(dev);
  2480. if (!is_valid_ether_addr(addr->sa_data))
  2481. return -EADDRNOTAVAIL;
  2482. ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
  2483. pi->xact_addr_filt, addr->sa_data, true, true);
  2484. if (ret < 0)
  2485. return ret;
  2486. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2487. pi->xact_addr_filt = ret;
  2488. return 0;
  2489. }
  2490. #ifdef CONFIG_NET_POLL_CONTROLLER
  2491. static void cxgb_netpoll(struct net_device *dev)
  2492. {
  2493. struct port_info *pi = netdev_priv(dev);
  2494. struct adapter *adap = pi->adapter;
  2495. if (adap->flags & USING_MSIX) {
  2496. int i;
  2497. struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
  2498. for (i = pi->nqsets; i; i--, rx++)
  2499. t4_sge_intr_msix(0, &rx->rspq);
  2500. } else
  2501. t4_intr_handler(adap)(0, adap);
  2502. }
  2503. #endif
  2504. static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
  2505. {
  2506. struct port_info *pi = netdev_priv(dev);
  2507. struct adapter *adap = pi->adapter;
  2508. struct sched_class *e;
  2509. struct ch_sched_params p;
  2510. struct ch_sched_queue qe;
  2511. u32 req_rate;
  2512. int err = 0;
  2513. if (!can_sched(dev))
  2514. return -ENOTSUPP;
  2515. if (index < 0 || index > pi->nqsets - 1)
  2516. return -EINVAL;
  2517. if (!(adap->flags & FULL_INIT_DONE)) {
  2518. dev_err(adap->pdev_dev,
  2519. "Failed to rate limit on queue %d. Link Down?\n",
  2520. index);
  2521. return -EINVAL;
  2522. }
  2523. /* Convert from Mbps to Kbps */
  2524. req_rate = rate << 10;
  2525. /* Max rate is 100 Gbps */
  2526. if (req_rate >= SCHED_MAX_RATE_KBPS) {
  2527. dev_err(adap->pdev_dev,
  2528. "Invalid rate %u Mbps, Max rate is %u Mbps\n",
  2529. rate, SCHED_MAX_RATE_KBPS >> 10);
  2530. return -ERANGE;
  2531. }
  2532. /* First unbind the queue from any existing class */
  2533. memset(&qe, 0, sizeof(qe));
  2534. qe.queue = index;
  2535. qe.class = SCHED_CLS_NONE;
  2536. err = cxgb4_sched_class_unbind(dev, (void *)(&qe), SCHED_QUEUE);
  2537. if (err) {
  2538. dev_err(adap->pdev_dev,
  2539. "Unbinding Queue %d on port %d fail. Err: %d\n",
  2540. index, pi->port_id, err);
  2541. return err;
  2542. }
  2543. /* Queue already unbound */
  2544. if (!req_rate)
  2545. return 0;
  2546. /* Fetch any available unused or matching scheduling class */
  2547. memset(&p, 0, sizeof(p));
  2548. p.type = SCHED_CLASS_TYPE_PACKET;
  2549. p.u.params.level = SCHED_CLASS_LEVEL_CL_RL;
  2550. p.u.params.mode = SCHED_CLASS_MODE_CLASS;
  2551. p.u.params.rateunit = SCHED_CLASS_RATEUNIT_BITS;
  2552. p.u.params.ratemode = SCHED_CLASS_RATEMODE_ABS;
  2553. p.u.params.channel = pi->tx_chan;
  2554. p.u.params.class = SCHED_CLS_NONE;
  2555. p.u.params.minrate = 0;
  2556. p.u.params.maxrate = req_rate;
  2557. p.u.params.weight = 0;
  2558. p.u.params.pktsize = dev->mtu;
  2559. e = cxgb4_sched_class_alloc(dev, &p);
  2560. if (!e)
  2561. return -ENOMEM;
  2562. /* Bind the queue to a scheduling class */
  2563. memset(&qe, 0, sizeof(qe));
  2564. qe.queue = index;
  2565. qe.class = e->idx;
  2566. err = cxgb4_sched_class_bind(dev, (void *)(&qe), SCHED_QUEUE);
  2567. if (err)
  2568. dev_err(adap->pdev_dev,
  2569. "Queue rate limiting failed. Err: %d\n", err);
  2570. return err;
  2571. }
  2572. static int cxgb_setup_tc_flower(struct net_device *dev,
  2573. struct tc_cls_flower_offload *cls_flower)
  2574. {
  2575. switch (cls_flower->command) {
  2576. case TC_CLSFLOWER_REPLACE:
  2577. return cxgb4_tc_flower_replace(dev, cls_flower);
  2578. case TC_CLSFLOWER_DESTROY:
  2579. return cxgb4_tc_flower_destroy(dev, cls_flower);
  2580. case TC_CLSFLOWER_STATS:
  2581. return cxgb4_tc_flower_stats(dev, cls_flower);
  2582. default:
  2583. return -EOPNOTSUPP;
  2584. }
  2585. }
  2586. static int cxgb_setup_tc_cls_u32(struct net_device *dev,
  2587. struct tc_cls_u32_offload *cls_u32)
  2588. {
  2589. switch (cls_u32->command) {
  2590. case TC_CLSU32_NEW_KNODE:
  2591. case TC_CLSU32_REPLACE_KNODE:
  2592. return cxgb4_config_knode(dev, cls_u32);
  2593. case TC_CLSU32_DELETE_KNODE:
  2594. return cxgb4_delete_knode(dev, cls_u32);
  2595. default:
  2596. return -EOPNOTSUPP;
  2597. }
  2598. }
  2599. static int cxgb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  2600. void *cb_priv)
  2601. {
  2602. struct net_device *dev = cb_priv;
  2603. struct port_info *pi = netdev2pinfo(dev);
  2604. struct adapter *adap = netdev2adap(dev);
  2605. if (!(adap->flags & FULL_INIT_DONE)) {
  2606. dev_err(adap->pdev_dev,
  2607. "Failed to setup tc on port %d. Link Down?\n",
  2608. pi->port_id);
  2609. return -EINVAL;
  2610. }
  2611. if (!tc_cls_can_offload_and_chain0(dev, type_data))
  2612. return -EOPNOTSUPP;
  2613. switch (type) {
  2614. case TC_SETUP_CLSU32:
  2615. return cxgb_setup_tc_cls_u32(dev, type_data);
  2616. case TC_SETUP_CLSFLOWER:
  2617. return cxgb_setup_tc_flower(dev, type_data);
  2618. default:
  2619. return -EOPNOTSUPP;
  2620. }
  2621. }
  2622. static int cxgb_setup_tc_block(struct net_device *dev,
  2623. struct tc_block_offload *f)
  2624. {
  2625. struct port_info *pi = netdev2pinfo(dev);
  2626. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  2627. return -EOPNOTSUPP;
  2628. switch (f->command) {
  2629. case TC_BLOCK_BIND:
  2630. return tcf_block_cb_register(f->block, cxgb_setup_tc_block_cb,
  2631. pi, dev);
  2632. case TC_BLOCK_UNBIND:
  2633. tcf_block_cb_unregister(f->block, cxgb_setup_tc_block_cb, pi);
  2634. return 0;
  2635. default:
  2636. return -EOPNOTSUPP;
  2637. }
  2638. }
  2639. static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
  2640. void *type_data)
  2641. {
  2642. switch (type) {
  2643. case TC_SETUP_BLOCK:
  2644. return cxgb_setup_tc_block(dev, type_data);
  2645. default:
  2646. return -EOPNOTSUPP;
  2647. }
  2648. }
  2649. static void cxgb_del_udp_tunnel(struct net_device *netdev,
  2650. struct udp_tunnel_info *ti)
  2651. {
  2652. struct port_info *pi = netdev_priv(netdev);
  2653. struct adapter *adapter = pi->adapter;
  2654. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
  2655. u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
  2656. int ret = 0, i;
  2657. if (chip_ver < CHELSIO_T6)
  2658. return;
  2659. switch (ti->type) {
  2660. case UDP_TUNNEL_TYPE_VXLAN:
  2661. if (!adapter->vxlan_port_cnt ||
  2662. adapter->vxlan_port != ti->port)
  2663. return; /* Invalid VxLAN destination port */
  2664. adapter->vxlan_port_cnt--;
  2665. if (adapter->vxlan_port_cnt)
  2666. return;
  2667. adapter->vxlan_port = 0;
  2668. t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A, 0);
  2669. break;
  2670. case UDP_TUNNEL_TYPE_GENEVE:
  2671. if (!adapter->geneve_port_cnt ||
  2672. adapter->geneve_port != ti->port)
  2673. return; /* Invalid GENEVE destination port */
  2674. adapter->geneve_port_cnt--;
  2675. if (adapter->geneve_port_cnt)
  2676. return;
  2677. adapter->geneve_port = 0;
  2678. t4_write_reg(adapter, MPS_RX_GENEVE_TYPE_A, 0);
  2679. default:
  2680. return;
  2681. }
  2682. /* Matchall mac entries can be deleted only after all tunnel ports
  2683. * are brought down or removed.
  2684. */
  2685. if (!adapter->rawf_cnt)
  2686. return;
  2687. for_each_port(adapter, i) {
  2688. pi = adap2pinfo(adapter, i);
  2689. ret = t4_free_raw_mac_filt(adapter, pi->viid,
  2690. match_all_mac, match_all_mac,
  2691. adapter->rawf_start +
  2692. pi->port_id,
  2693. 1, pi->port_id, true);
  2694. if (ret < 0) {
  2695. netdev_info(netdev, "Failed to free mac filter entry, for port %d\n",
  2696. i);
  2697. return;
  2698. }
  2699. atomic_dec(&adapter->mps_encap[adapter->rawf_start +
  2700. pi->port_id].refcnt);
  2701. }
  2702. }
  2703. static void cxgb_add_udp_tunnel(struct net_device *netdev,
  2704. struct udp_tunnel_info *ti)
  2705. {
  2706. struct port_info *pi = netdev_priv(netdev);
  2707. struct adapter *adapter = pi->adapter;
  2708. unsigned int chip_ver = CHELSIO_CHIP_VERSION(adapter->params.chip);
  2709. u8 match_all_mac[] = { 0, 0, 0, 0, 0, 0 };
  2710. int i, ret;
  2711. if (chip_ver < CHELSIO_T6 || !adapter->rawf_cnt)
  2712. return;
  2713. switch (ti->type) {
  2714. case UDP_TUNNEL_TYPE_VXLAN:
  2715. /* Callback for adding vxlan port can be called with the same
  2716. * port for both IPv4 and IPv6. We should not disable the
  2717. * offloading when the same port for both protocols is added
  2718. * and later one of them is removed.
  2719. */
  2720. if (adapter->vxlan_port_cnt &&
  2721. adapter->vxlan_port == ti->port) {
  2722. adapter->vxlan_port_cnt++;
  2723. return;
  2724. }
  2725. /* We will support only one VxLAN port */
  2726. if (adapter->vxlan_port_cnt) {
  2727. netdev_info(netdev, "UDP port %d already offloaded, not adding port %d\n",
  2728. be16_to_cpu(adapter->vxlan_port),
  2729. be16_to_cpu(ti->port));
  2730. return;
  2731. }
  2732. adapter->vxlan_port = ti->port;
  2733. adapter->vxlan_port_cnt = 1;
  2734. t4_write_reg(adapter, MPS_RX_VXLAN_TYPE_A,
  2735. VXLAN_V(be16_to_cpu(ti->port)) | VXLAN_EN_F);
  2736. break;
  2737. case UDP_TUNNEL_TYPE_GENEVE:
  2738. if (adapter->geneve_port_cnt &&
  2739. adapter->geneve_port == ti->port) {
  2740. adapter->geneve_port_cnt++;
  2741. return;
  2742. }
  2743. /* We will support only one GENEVE port */
  2744. if (adapter->geneve_port_cnt) {
  2745. netdev_info(netdev, "UDP port %d already offloaded, not adding port %d\n",
  2746. be16_to_cpu(adapter->geneve_port),
  2747. be16_to_cpu(ti->port));
  2748. return;
  2749. }
  2750. adapter->geneve_port = ti->port;
  2751. adapter->geneve_port_cnt = 1;
  2752. t4_write_reg(adapter, MPS_RX_GENEVE_TYPE_A,
  2753. GENEVE_V(be16_to_cpu(ti->port)) | GENEVE_EN_F);
  2754. default:
  2755. return;
  2756. }
  2757. /* Create a 'match all' mac filter entry for inner mac,
  2758. * if raw mac interface is supported. Once the linux kernel provides
  2759. * driver entry points for adding/deleting the inner mac addresses,
  2760. * we will remove this 'match all' entry and fallback to adding
  2761. * exact match filters.
  2762. */
  2763. for_each_port(adapter, i) {
  2764. pi = adap2pinfo(adapter, i);
  2765. ret = t4_alloc_raw_mac_filt(adapter, pi->viid,
  2766. match_all_mac,
  2767. match_all_mac,
  2768. adapter->rawf_start +
  2769. pi->port_id,
  2770. 1, pi->port_id, true);
  2771. if (ret < 0) {
  2772. netdev_info(netdev, "Failed to allocate a mac filter entry, not adding port %d\n",
  2773. be16_to_cpu(ti->port));
  2774. cxgb_del_udp_tunnel(netdev, ti);
  2775. return;
  2776. }
  2777. atomic_inc(&adapter->mps_encap[ret].refcnt);
  2778. }
  2779. }
  2780. static netdev_features_t cxgb_features_check(struct sk_buff *skb,
  2781. struct net_device *dev,
  2782. netdev_features_t features)
  2783. {
  2784. struct port_info *pi = netdev_priv(dev);
  2785. struct adapter *adapter = pi->adapter;
  2786. if (CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
  2787. return features;
  2788. /* Check if hw supports offload for this packet */
  2789. if (!skb->encapsulation || cxgb_encap_offload_supported(skb))
  2790. return features;
  2791. /* Offload is not supported for this encapsulated packet */
  2792. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  2793. }
  2794. static netdev_features_t cxgb_fix_features(struct net_device *dev,
  2795. netdev_features_t features)
  2796. {
  2797. /* Disable GRO, if RX_CSUM is disabled */
  2798. if (!(features & NETIF_F_RXCSUM))
  2799. features &= ~NETIF_F_GRO;
  2800. return features;
  2801. }
  2802. static const struct net_device_ops cxgb4_netdev_ops = {
  2803. .ndo_open = cxgb_open,
  2804. .ndo_stop = cxgb_close,
  2805. .ndo_start_xmit = t4_eth_xmit,
  2806. .ndo_select_queue = cxgb_select_queue,
  2807. .ndo_get_stats64 = cxgb_get_stats,
  2808. .ndo_set_rx_mode = cxgb_set_rxmode,
  2809. .ndo_set_mac_address = cxgb_set_mac_addr,
  2810. .ndo_set_features = cxgb_set_features,
  2811. .ndo_validate_addr = eth_validate_addr,
  2812. .ndo_do_ioctl = cxgb_ioctl,
  2813. .ndo_change_mtu = cxgb_change_mtu,
  2814. #ifdef CONFIG_NET_POLL_CONTROLLER
  2815. .ndo_poll_controller = cxgb_netpoll,
  2816. #endif
  2817. #ifdef CONFIG_CHELSIO_T4_FCOE
  2818. .ndo_fcoe_enable = cxgb_fcoe_enable,
  2819. .ndo_fcoe_disable = cxgb_fcoe_disable,
  2820. #endif /* CONFIG_CHELSIO_T4_FCOE */
  2821. .ndo_set_tx_maxrate = cxgb_set_tx_maxrate,
  2822. .ndo_setup_tc = cxgb_setup_tc,
  2823. .ndo_udp_tunnel_add = cxgb_add_udp_tunnel,
  2824. .ndo_udp_tunnel_del = cxgb_del_udp_tunnel,
  2825. .ndo_features_check = cxgb_features_check,
  2826. .ndo_fix_features = cxgb_fix_features,
  2827. };
  2828. #ifdef CONFIG_PCI_IOV
  2829. static const struct net_device_ops cxgb4_mgmt_netdev_ops = {
  2830. .ndo_open = cxgb4_mgmt_open,
  2831. .ndo_set_vf_mac = cxgb4_mgmt_set_vf_mac,
  2832. .ndo_get_vf_config = cxgb4_mgmt_get_vf_config,
  2833. .ndo_set_vf_rate = cxgb4_mgmt_set_vf_rate,
  2834. .ndo_get_phys_port_id = cxgb4_mgmt_get_phys_port_id,
  2835. .ndo_set_vf_vlan = cxgb4_mgmt_set_vf_vlan,
  2836. };
  2837. #endif
  2838. static void cxgb4_mgmt_get_drvinfo(struct net_device *dev,
  2839. struct ethtool_drvinfo *info)
  2840. {
  2841. struct adapter *adapter = netdev2adap(dev);
  2842. strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
  2843. strlcpy(info->version, cxgb4_driver_version,
  2844. sizeof(info->version));
  2845. strlcpy(info->bus_info, pci_name(adapter->pdev),
  2846. sizeof(info->bus_info));
  2847. }
  2848. static const struct ethtool_ops cxgb4_mgmt_ethtool_ops = {
  2849. .get_drvinfo = cxgb4_mgmt_get_drvinfo,
  2850. };
  2851. static void notify_fatal_err(struct work_struct *work)
  2852. {
  2853. struct adapter *adap;
  2854. adap = container_of(work, struct adapter, fatal_err_notify_task);
  2855. notify_ulds(adap, CXGB4_STATE_FATAL_ERROR);
  2856. }
  2857. void t4_fatal_err(struct adapter *adap)
  2858. {
  2859. int port;
  2860. if (pci_channel_offline(adap->pdev))
  2861. return;
  2862. /* Disable the SGE since ULDs are going to free resources that
  2863. * could be exposed to the adapter. RDMA MWs for example...
  2864. */
  2865. t4_shutdown_adapter(adap);
  2866. for_each_port(adap, port) {
  2867. struct net_device *dev = adap->port[port];
  2868. /* If we get here in very early initialization the network
  2869. * devices may not have been set up yet.
  2870. */
  2871. if (!dev)
  2872. continue;
  2873. netif_tx_stop_all_queues(dev);
  2874. netif_carrier_off(dev);
  2875. }
  2876. dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
  2877. queue_work(adap->workq, &adap->fatal_err_notify_task);
  2878. }
  2879. static void setup_memwin(struct adapter *adap)
  2880. {
  2881. u32 nic_win_base = t4_get_util_window(adap);
  2882. t4_setup_memwin(adap, nic_win_base, MEMWIN_NIC);
  2883. }
  2884. static void setup_memwin_rdma(struct adapter *adap)
  2885. {
  2886. if (adap->vres.ocq.size) {
  2887. u32 start;
  2888. unsigned int sz_kb;
  2889. start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
  2890. start &= PCI_BASE_ADDRESS_MEM_MASK;
  2891. start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
  2892. sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
  2893. t4_write_reg(adap,
  2894. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
  2895. start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
  2896. t4_write_reg(adap,
  2897. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
  2898. adap->vres.ocq.start);
  2899. t4_read_reg(adap,
  2900. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
  2901. }
  2902. }
  2903. /* HMA Definitions */
  2904. /* The maximum number of address that can be send in a single FW cmd */
  2905. #define HMA_MAX_ADDR_IN_CMD 5
  2906. #define HMA_PAGE_SIZE PAGE_SIZE
  2907. #define HMA_MAX_NO_FW_ADDRESS (16 << 10) /* FW supports 16K addresses */
  2908. #define HMA_PAGE_ORDER \
  2909. ((HMA_PAGE_SIZE < HMA_MAX_NO_FW_ADDRESS) ? \
  2910. ilog2(HMA_MAX_NO_FW_ADDRESS / HMA_PAGE_SIZE) : 0)
  2911. /* The minimum and maximum possible HMA sizes that can be specified in the FW
  2912. * configuration(in units of MB).
  2913. */
  2914. #define HMA_MIN_TOTAL_SIZE 1
  2915. #define HMA_MAX_TOTAL_SIZE \
  2916. (((HMA_PAGE_SIZE << HMA_PAGE_ORDER) * \
  2917. HMA_MAX_NO_FW_ADDRESS) >> 20)
  2918. static void adap_free_hma_mem(struct adapter *adapter)
  2919. {
  2920. struct scatterlist *iter;
  2921. struct page *page;
  2922. int i;
  2923. if (!adapter->hma.sgt)
  2924. return;
  2925. if (adapter->hma.flags & HMA_DMA_MAPPED_FLAG) {
  2926. dma_unmap_sg(adapter->pdev_dev, adapter->hma.sgt->sgl,
  2927. adapter->hma.sgt->nents, PCI_DMA_BIDIRECTIONAL);
  2928. adapter->hma.flags &= ~HMA_DMA_MAPPED_FLAG;
  2929. }
  2930. for_each_sg(adapter->hma.sgt->sgl, iter,
  2931. adapter->hma.sgt->orig_nents, i) {
  2932. page = sg_page(iter);
  2933. if (page)
  2934. __free_pages(page, HMA_PAGE_ORDER);
  2935. }
  2936. kfree(adapter->hma.phy_addr);
  2937. sg_free_table(adapter->hma.sgt);
  2938. kfree(adapter->hma.sgt);
  2939. adapter->hma.sgt = NULL;
  2940. }
  2941. static int adap_config_hma(struct adapter *adapter)
  2942. {
  2943. struct scatterlist *sgl, *iter;
  2944. struct sg_table *sgt;
  2945. struct page *newpage;
  2946. unsigned int i, j, k;
  2947. u32 param, hma_size;
  2948. unsigned int ncmds;
  2949. size_t page_size;
  2950. u32 page_order;
  2951. int node, ret;
  2952. /* HMA is supported only for T6+ cards.
  2953. * Avoid initializing HMA in kdump kernels.
  2954. */
  2955. if (is_kdump_kernel() ||
  2956. CHELSIO_CHIP_VERSION(adapter->params.chip) < CHELSIO_T6)
  2957. return 0;
  2958. /* Get the HMA region size required by fw */
  2959. param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  2960. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_HMA_SIZE));
  2961. ret = t4_query_params(adapter, adapter->mbox, adapter->pf, 0,
  2962. 1, &param, &hma_size);
  2963. /* An error means card has its own memory or HMA is not supported by
  2964. * the firmware. Return without any errors.
  2965. */
  2966. if (ret || !hma_size)
  2967. return 0;
  2968. if (hma_size < HMA_MIN_TOTAL_SIZE ||
  2969. hma_size > HMA_MAX_TOTAL_SIZE) {
  2970. dev_err(adapter->pdev_dev,
  2971. "HMA size %uMB beyond bounds(%u-%lu)MB\n",
  2972. hma_size, HMA_MIN_TOTAL_SIZE, HMA_MAX_TOTAL_SIZE);
  2973. return -EINVAL;
  2974. }
  2975. page_size = HMA_PAGE_SIZE;
  2976. page_order = HMA_PAGE_ORDER;
  2977. adapter->hma.sgt = kzalloc(sizeof(*adapter->hma.sgt), GFP_KERNEL);
  2978. if (unlikely(!adapter->hma.sgt)) {
  2979. dev_err(adapter->pdev_dev, "HMA SG table allocation failed\n");
  2980. return -ENOMEM;
  2981. }
  2982. sgt = adapter->hma.sgt;
  2983. /* FW returned value will be in MB's
  2984. */
  2985. sgt->orig_nents = (hma_size << 20) / (page_size << page_order);
  2986. if (sg_alloc_table(sgt, sgt->orig_nents, GFP_KERNEL)) {
  2987. dev_err(adapter->pdev_dev, "HMA SGL allocation failed\n");
  2988. kfree(adapter->hma.sgt);
  2989. adapter->hma.sgt = NULL;
  2990. return -ENOMEM;
  2991. }
  2992. sgl = adapter->hma.sgt->sgl;
  2993. node = dev_to_node(adapter->pdev_dev);
  2994. for_each_sg(sgl, iter, sgt->orig_nents, i) {
  2995. newpage = alloc_pages_node(node, __GFP_NOWARN | GFP_KERNEL,
  2996. page_order);
  2997. if (!newpage) {
  2998. dev_err(adapter->pdev_dev,
  2999. "Not enough memory for HMA page allocation\n");
  3000. ret = -ENOMEM;
  3001. goto free_hma;
  3002. }
  3003. sg_set_page(iter, newpage, page_size << page_order, 0);
  3004. }
  3005. sgt->nents = dma_map_sg(adapter->pdev_dev, sgl, sgt->orig_nents,
  3006. DMA_BIDIRECTIONAL);
  3007. if (!sgt->nents) {
  3008. dev_err(adapter->pdev_dev,
  3009. "Not enough memory for HMA DMA mapping");
  3010. ret = -ENOMEM;
  3011. goto free_hma;
  3012. }
  3013. adapter->hma.flags |= HMA_DMA_MAPPED_FLAG;
  3014. adapter->hma.phy_addr = kcalloc(sgt->nents, sizeof(dma_addr_t),
  3015. GFP_KERNEL);
  3016. if (unlikely(!adapter->hma.phy_addr))
  3017. goto free_hma;
  3018. for_each_sg(sgl, iter, sgt->nents, i) {
  3019. newpage = sg_page(iter);
  3020. adapter->hma.phy_addr[i] = sg_dma_address(iter);
  3021. }
  3022. ncmds = DIV_ROUND_UP(sgt->nents, HMA_MAX_ADDR_IN_CMD);
  3023. /* Pass on the addresses to firmware */
  3024. for (i = 0, k = 0; i < ncmds; i++, k += HMA_MAX_ADDR_IN_CMD) {
  3025. struct fw_hma_cmd hma_cmd;
  3026. u8 naddr = HMA_MAX_ADDR_IN_CMD;
  3027. u8 soc = 0, eoc = 0;
  3028. u8 hma_mode = 1; /* Presently we support only Page table mode */
  3029. soc = (i == 0) ? 1 : 0;
  3030. eoc = (i == ncmds - 1) ? 1 : 0;
  3031. /* For last cmd, set naddr corresponding to remaining
  3032. * addresses
  3033. */
  3034. if (i == ncmds - 1) {
  3035. naddr = sgt->nents % HMA_MAX_ADDR_IN_CMD;
  3036. naddr = naddr ? naddr : HMA_MAX_ADDR_IN_CMD;
  3037. }
  3038. memset(&hma_cmd, 0, sizeof(hma_cmd));
  3039. hma_cmd.op_pkd = htonl(FW_CMD_OP_V(FW_HMA_CMD) |
  3040. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  3041. hma_cmd.retval_len16 = htonl(FW_LEN16(hma_cmd));
  3042. hma_cmd.mode_to_pcie_params =
  3043. htonl(FW_HMA_CMD_MODE_V(hma_mode) |
  3044. FW_HMA_CMD_SOC_V(soc) | FW_HMA_CMD_EOC_V(eoc));
  3045. /* HMA cmd size specified in MB's */
  3046. hma_cmd.naddr_size =
  3047. htonl(FW_HMA_CMD_SIZE_V(hma_size) |
  3048. FW_HMA_CMD_NADDR_V(naddr));
  3049. /* Total Page size specified in units of 4K */
  3050. hma_cmd.addr_size_pkd =
  3051. htonl(FW_HMA_CMD_ADDR_SIZE_V
  3052. ((page_size << page_order) >> 12));
  3053. /* Fill the 5 addresses */
  3054. for (j = 0; j < naddr; j++) {
  3055. hma_cmd.phy_address[j] =
  3056. cpu_to_be64(adapter->hma.phy_addr[j + k]);
  3057. }
  3058. ret = t4_wr_mbox(adapter, adapter->mbox, &hma_cmd,
  3059. sizeof(hma_cmd), &hma_cmd);
  3060. if (ret) {
  3061. dev_err(adapter->pdev_dev,
  3062. "HMA FW command failed with err %d\n", ret);
  3063. goto free_hma;
  3064. }
  3065. }
  3066. if (!ret)
  3067. dev_info(adapter->pdev_dev,
  3068. "Reserved %uMB host memory for HMA\n", hma_size);
  3069. return ret;
  3070. free_hma:
  3071. adap_free_hma_mem(adapter);
  3072. return ret;
  3073. }
  3074. static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
  3075. {
  3076. u32 v;
  3077. int ret;
  3078. /* get device capabilities */
  3079. memset(c, 0, sizeof(*c));
  3080. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3081. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3082. c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
  3083. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), c);
  3084. if (ret < 0)
  3085. return ret;
  3086. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3087. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  3088. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), NULL);
  3089. if (ret < 0)
  3090. return ret;
  3091. ret = t4_config_glbl_rss(adap, adap->pf,
  3092. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
  3093. FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
  3094. FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
  3095. if (ret < 0)
  3096. return ret;
  3097. ret = t4_cfg_pfvf(adap, adap->mbox, adap->pf, 0, adap->sge.egr_sz, 64,
  3098. MAX_INGQ, 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF,
  3099. FW_CMD_CAP_PF);
  3100. if (ret < 0)
  3101. return ret;
  3102. t4_sge_init(adap);
  3103. /* tweak some settings */
  3104. t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
  3105. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
  3106. t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
  3107. v = t4_read_reg(adap, TP_PIO_DATA_A);
  3108. t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
  3109. /* first 4 Tx modulation queues point to consecutive Tx channels */
  3110. adap->params.tp.tx_modq_map = 0xE4;
  3111. t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
  3112. TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
  3113. /* associate each Tx modulation queue with consecutive Tx channels */
  3114. v = 0x84218421;
  3115. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3116. &v, 1, TP_TX_SCHED_HDR_A);
  3117. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3118. &v, 1, TP_TX_SCHED_FIFO_A);
  3119. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  3120. &v, 1, TP_TX_SCHED_PCMD_A);
  3121. #define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
  3122. if (is_offload(adap)) {
  3123. t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
  3124. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3125. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3126. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3127. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  3128. t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
  3129. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3130. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3131. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  3132. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  3133. }
  3134. /* get basic stuff going */
  3135. return t4_early_init(adap, adap->pf);
  3136. }
  3137. /*
  3138. * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
  3139. */
  3140. #define MAX_ATIDS 8192U
  3141. /*
  3142. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  3143. *
  3144. * If the firmware we're dealing with has Configuration File support, then
  3145. * we use that to perform all configuration
  3146. */
  3147. /*
  3148. * Tweak configuration based on module parameters, etc. Most of these have
  3149. * defaults assigned to them by Firmware Configuration Files (if we're using
  3150. * them) but need to be explicitly set if we're using hard-coded
  3151. * initialization. But even in the case of using Firmware Configuration
  3152. * Files, we'd like to expose the ability to change these via module
  3153. * parameters so these are essentially common tweaks/settings for
  3154. * Configuration Files and hard-coded initialization ...
  3155. */
  3156. static int adap_init0_tweaks(struct adapter *adapter)
  3157. {
  3158. /*
  3159. * Fix up various Host-Dependent Parameters like Page Size, Cache
  3160. * Line Size, etc. The firmware default is for a 4KB Page Size and
  3161. * 64B Cache Line Size ...
  3162. */
  3163. t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
  3164. /*
  3165. * Process module parameters which affect early initialization.
  3166. */
  3167. if (rx_dma_offset != 2 && rx_dma_offset != 0) {
  3168. dev_err(&adapter->pdev->dev,
  3169. "Ignoring illegal rx_dma_offset=%d, using 2\n",
  3170. rx_dma_offset);
  3171. rx_dma_offset = 2;
  3172. }
  3173. t4_set_reg_field(adapter, SGE_CONTROL_A,
  3174. PKTSHIFT_V(PKTSHIFT_M),
  3175. PKTSHIFT_V(rx_dma_offset));
  3176. /*
  3177. * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
  3178. * adds the pseudo header itself.
  3179. */
  3180. t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
  3181. CSUM_HAS_PSEUDO_HDR_F, 0);
  3182. return 0;
  3183. }
  3184. /* 10Gb/s-BT PHY Support. chip-external 10Gb/s-BT PHYs are complex chips
  3185. * unto themselves and they contain their own firmware to perform their
  3186. * tasks ...
  3187. */
  3188. static int phy_aq1202_version(const u8 *phy_fw_data,
  3189. size_t phy_fw_size)
  3190. {
  3191. int offset;
  3192. /* At offset 0x8 you're looking for the primary image's
  3193. * starting offset which is 3 Bytes wide
  3194. *
  3195. * At offset 0xa of the primary image, you look for the offset
  3196. * of the DRAM segment which is 3 Bytes wide.
  3197. *
  3198. * The FW version is at offset 0x27e of the DRAM and is 2 Bytes
  3199. * wide
  3200. */
  3201. #define be16(__p) (((__p)[0] << 8) | (__p)[1])
  3202. #define le16(__p) ((__p)[0] | ((__p)[1] << 8))
  3203. #define le24(__p) (le16(__p) | ((__p)[2] << 16))
  3204. offset = le24(phy_fw_data + 0x8) << 12;
  3205. offset = le24(phy_fw_data + offset + 0xa);
  3206. return be16(phy_fw_data + offset + 0x27e);
  3207. #undef be16
  3208. #undef le16
  3209. #undef le24
  3210. }
  3211. static struct info_10gbt_phy_fw {
  3212. unsigned int phy_fw_id; /* PCI Device ID */
  3213. char *phy_fw_file; /* /lib/firmware/ PHY Firmware file */
  3214. int (*phy_fw_version)(const u8 *phy_fw_data, size_t phy_fw_size);
  3215. int phy_flash; /* Has FLASH for PHY Firmware */
  3216. } phy_info_array[] = {
  3217. {
  3218. PHY_AQ1202_DEVICEID,
  3219. PHY_AQ1202_FIRMWARE,
  3220. phy_aq1202_version,
  3221. 1,
  3222. },
  3223. {
  3224. PHY_BCM84834_DEVICEID,
  3225. PHY_BCM84834_FIRMWARE,
  3226. NULL,
  3227. 0,
  3228. },
  3229. { 0, NULL, NULL },
  3230. };
  3231. static struct info_10gbt_phy_fw *find_phy_info(int devid)
  3232. {
  3233. int i;
  3234. for (i = 0; i < ARRAY_SIZE(phy_info_array); i++) {
  3235. if (phy_info_array[i].phy_fw_id == devid)
  3236. return &phy_info_array[i];
  3237. }
  3238. return NULL;
  3239. }
  3240. /* Handle updating of chip-external 10Gb/s-BT PHY firmware. This needs to
  3241. * happen after the FW_RESET_CMD but before the FW_INITIALIZE_CMD. On error
  3242. * we return a negative error number. If we transfer new firmware we return 1
  3243. * (from t4_load_phy_fw()). If we don't do anything we return 0.
  3244. */
  3245. static int adap_init0_phy(struct adapter *adap)
  3246. {
  3247. const struct firmware *phyf;
  3248. int ret;
  3249. struct info_10gbt_phy_fw *phy_info;
  3250. /* Use the device ID to determine which PHY file to flash.
  3251. */
  3252. phy_info = find_phy_info(adap->pdev->device);
  3253. if (!phy_info) {
  3254. dev_warn(adap->pdev_dev,
  3255. "No PHY Firmware file found for this PHY\n");
  3256. return -EOPNOTSUPP;
  3257. }
  3258. /* If we have a T4 PHY firmware file under /lib/firmware/cxgb4/, then
  3259. * use that. The adapter firmware provides us with a memory buffer
  3260. * where we can load a PHY firmware file from the host if we want to
  3261. * override the PHY firmware File in flash.
  3262. */
  3263. ret = request_firmware_direct(&phyf, phy_info->phy_fw_file,
  3264. adap->pdev_dev);
  3265. if (ret < 0) {
  3266. /* For adapters without FLASH attached to PHY for their
  3267. * firmware, it's obviously a fatal error if we can't get the
  3268. * firmware to the adapter. For adapters with PHY firmware
  3269. * FLASH storage, it's worth a warning if we can't find the
  3270. * PHY Firmware but we'll neuter the error ...
  3271. */
  3272. dev_err(adap->pdev_dev, "unable to find PHY Firmware image "
  3273. "/lib/firmware/%s, error %d\n",
  3274. phy_info->phy_fw_file, -ret);
  3275. if (phy_info->phy_flash) {
  3276. int cur_phy_fw_ver = 0;
  3277. t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  3278. dev_warn(adap->pdev_dev, "continuing with, on-adapter "
  3279. "FLASH copy, version %#x\n", cur_phy_fw_ver);
  3280. ret = 0;
  3281. }
  3282. return ret;
  3283. }
  3284. /* Load PHY Firmware onto adapter.
  3285. */
  3286. ret = t4_load_phy_fw(adap, MEMWIN_NIC, &adap->win0_lock,
  3287. phy_info->phy_fw_version,
  3288. (u8 *)phyf->data, phyf->size);
  3289. if (ret < 0)
  3290. dev_err(adap->pdev_dev, "PHY Firmware transfer error %d\n",
  3291. -ret);
  3292. else if (ret > 0) {
  3293. int new_phy_fw_ver = 0;
  3294. if (phy_info->phy_fw_version)
  3295. new_phy_fw_ver = phy_info->phy_fw_version(phyf->data,
  3296. phyf->size);
  3297. dev_info(adap->pdev_dev, "Successfully transferred PHY "
  3298. "Firmware /lib/firmware/%s, version %#x\n",
  3299. phy_info->phy_fw_file, new_phy_fw_ver);
  3300. }
  3301. release_firmware(phyf);
  3302. return ret;
  3303. }
  3304. /*
  3305. * Attempt to initialize the adapter via a Firmware Configuration File.
  3306. */
  3307. static int adap_init0_config(struct adapter *adapter, int reset)
  3308. {
  3309. struct fw_caps_config_cmd caps_cmd;
  3310. const struct firmware *cf;
  3311. unsigned long mtype = 0, maddr = 0;
  3312. u32 finiver, finicsum, cfcsum;
  3313. int ret;
  3314. int config_issued = 0;
  3315. char *fw_config_file, fw_config_file_path[256];
  3316. char *config_name = NULL;
  3317. /*
  3318. * Reset device if necessary.
  3319. */
  3320. if (reset) {
  3321. ret = t4_fw_reset(adapter, adapter->mbox,
  3322. PIORSTMODE_F | PIORST_F);
  3323. if (ret < 0)
  3324. goto bye;
  3325. }
  3326. /* If this is a 10Gb/s-BT adapter make sure the chip-external
  3327. * 10Gb/s-BT PHYs have up-to-date firmware. Note that this step needs
  3328. * to be performed after any global adapter RESET above since some
  3329. * PHYs only have local RAM copies of the PHY firmware.
  3330. */
  3331. if (is_10gbt_device(adapter->pdev->device)) {
  3332. ret = adap_init0_phy(adapter);
  3333. if (ret < 0)
  3334. goto bye;
  3335. }
  3336. /*
  3337. * If we have a T4 configuration file under /lib/firmware/cxgb4/,
  3338. * then use that. Otherwise, use the configuration file stored
  3339. * in the adapter flash ...
  3340. */
  3341. switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
  3342. case CHELSIO_T4:
  3343. fw_config_file = FW4_CFNAME;
  3344. break;
  3345. case CHELSIO_T5:
  3346. fw_config_file = FW5_CFNAME;
  3347. break;
  3348. case CHELSIO_T6:
  3349. fw_config_file = FW6_CFNAME;
  3350. break;
  3351. default:
  3352. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  3353. adapter->pdev->device);
  3354. ret = -EINVAL;
  3355. goto bye;
  3356. }
  3357. ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
  3358. if (ret < 0) {
  3359. config_name = "On FLASH";
  3360. mtype = FW_MEMTYPE_CF_FLASH;
  3361. maddr = t4_flash_cfg_addr(adapter);
  3362. } else {
  3363. u32 params[7], val[7];
  3364. sprintf(fw_config_file_path,
  3365. "/lib/firmware/%s", fw_config_file);
  3366. config_name = fw_config_file_path;
  3367. if (cf->size >= FLASH_CFG_MAX_SIZE)
  3368. ret = -ENOMEM;
  3369. else {
  3370. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3371. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3372. ret = t4_query_params(adapter, adapter->mbox,
  3373. adapter->pf, 0, 1, params, val);
  3374. if (ret == 0) {
  3375. /*
  3376. * For t4_memory_rw() below addresses and
  3377. * sizes have to be in terms of multiples of 4
  3378. * bytes. So, if the Configuration File isn't
  3379. * a multiple of 4 bytes in length we'll have
  3380. * to write that out separately since we can't
  3381. * guarantee that the bytes following the
  3382. * residual byte in the buffer returned by
  3383. * request_firmware() are zeroed out ...
  3384. */
  3385. size_t resid = cf->size & 0x3;
  3386. size_t size = cf->size & ~0x3;
  3387. __be32 *data = (__be32 *)cf->data;
  3388. mtype = FW_PARAMS_PARAM_Y_G(val[0]);
  3389. maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
  3390. spin_lock(&adapter->win0_lock);
  3391. ret = t4_memory_rw(adapter, 0, mtype, maddr,
  3392. size, data, T4_MEMORY_WRITE);
  3393. if (ret == 0 && resid != 0) {
  3394. union {
  3395. __be32 word;
  3396. char buf[4];
  3397. } last;
  3398. int i;
  3399. last.word = data[size >> 2];
  3400. for (i = resid; i < 4; i++)
  3401. last.buf[i] = 0;
  3402. ret = t4_memory_rw(adapter, 0, mtype,
  3403. maddr + size,
  3404. 4, &last.word,
  3405. T4_MEMORY_WRITE);
  3406. }
  3407. spin_unlock(&adapter->win0_lock);
  3408. }
  3409. }
  3410. release_firmware(cf);
  3411. if (ret)
  3412. goto bye;
  3413. }
  3414. /*
  3415. * Issue a Capability Configuration command to the firmware to get it
  3416. * to parse the Configuration File. We don't use t4_fw_config_file()
  3417. * because we want the ability to modify various features after we've
  3418. * processed the configuration file ...
  3419. */
  3420. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3421. caps_cmd.op_to_write =
  3422. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3423. FW_CMD_REQUEST_F |
  3424. FW_CMD_READ_F);
  3425. caps_cmd.cfvalid_to_len16 =
  3426. htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
  3427. FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
  3428. FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
  3429. FW_LEN16(caps_cmd));
  3430. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3431. &caps_cmd);
  3432. /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
  3433. * Configuration File in FLASH), our last gasp effort is to use the
  3434. * Firmware Configuration File which is embedded in the firmware. A
  3435. * very few early versions of the firmware didn't have one embedded
  3436. * but we can ignore those.
  3437. */
  3438. if (ret == -ENOENT) {
  3439. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3440. caps_cmd.op_to_write =
  3441. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3442. FW_CMD_REQUEST_F |
  3443. FW_CMD_READ_F);
  3444. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3445. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
  3446. sizeof(caps_cmd), &caps_cmd);
  3447. config_name = "Firmware Default";
  3448. }
  3449. config_issued = 1;
  3450. if (ret < 0)
  3451. goto bye;
  3452. finiver = ntohl(caps_cmd.finiver);
  3453. finicsum = ntohl(caps_cmd.finicsum);
  3454. cfcsum = ntohl(caps_cmd.cfcsum);
  3455. if (finicsum != cfcsum)
  3456. dev_warn(adapter->pdev_dev, "Configuration File checksum "\
  3457. "mismatch: [fini] csum=%#x, computed csum=%#x\n",
  3458. finicsum, cfcsum);
  3459. /*
  3460. * And now tell the firmware to use the configuration we just loaded.
  3461. */
  3462. caps_cmd.op_to_write =
  3463. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3464. FW_CMD_REQUEST_F |
  3465. FW_CMD_WRITE_F);
  3466. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3467. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  3468. NULL);
  3469. if (ret < 0)
  3470. goto bye;
  3471. /*
  3472. * Tweak configuration based on system architecture, module
  3473. * parameters, etc.
  3474. */
  3475. ret = adap_init0_tweaks(adapter);
  3476. if (ret < 0)
  3477. goto bye;
  3478. /* We will proceed even if HMA init fails. */
  3479. ret = adap_config_hma(adapter);
  3480. if (ret)
  3481. dev_err(adapter->pdev_dev,
  3482. "HMA configuration failed with error %d\n", ret);
  3483. /*
  3484. * And finally tell the firmware to initialize itself using the
  3485. * parameters from the Configuration File.
  3486. */
  3487. ret = t4_fw_initialize(adapter, adapter->mbox);
  3488. if (ret < 0)
  3489. goto bye;
  3490. /* Emit Firmware Configuration File information and return
  3491. * successfully.
  3492. */
  3493. dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
  3494. "Configuration File \"%s\", version %#x, computed checksum %#x\n",
  3495. config_name, finiver, cfcsum);
  3496. return 0;
  3497. /*
  3498. * Something bad happened. Return the error ... (If the "error"
  3499. * is that there's no Configuration File on the adapter we don't
  3500. * want to issue a warning since this is fairly common.)
  3501. */
  3502. bye:
  3503. if (config_issued && ret != -ENOENT)
  3504. dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
  3505. config_name, -ret);
  3506. return ret;
  3507. }
  3508. static struct fw_info fw_info_array[] = {
  3509. {
  3510. .chip = CHELSIO_T4,
  3511. .fs_name = FW4_CFNAME,
  3512. .fw_mod_name = FW4_FNAME,
  3513. .fw_hdr = {
  3514. .chip = FW_HDR_CHIP_T4,
  3515. .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
  3516. .intfver_nic = FW_INTFVER(T4, NIC),
  3517. .intfver_vnic = FW_INTFVER(T4, VNIC),
  3518. .intfver_ri = FW_INTFVER(T4, RI),
  3519. .intfver_iscsi = FW_INTFVER(T4, ISCSI),
  3520. .intfver_fcoe = FW_INTFVER(T4, FCOE),
  3521. },
  3522. }, {
  3523. .chip = CHELSIO_T5,
  3524. .fs_name = FW5_CFNAME,
  3525. .fw_mod_name = FW5_FNAME,
  3526. .fw_hdr = {
  3527. .chip = FW_HDR_CHIP_T5,
  3528. .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
  3529. .intfver_nic = FW_INTFVER(T5, NIC),
  3530. .intfver_vnic = FW_INTFVER(T5, VNIC),
  3531. .intfver_ri = FW_INTFVER(T5, RI),
  3532. .intfver_iscsi = FW_INTFVER(T5, ISCSI),
  3533. .intfver_fcoe = FW_INTFVER(T5, FCOE),
  3534. },
  3535. }, {
  3536. .chip = CHELSIO_T6,
  3537. .fs_name = FW6_CFNAME,
  3538. .fw_mod_name = FW6_FNAME,
  3539. .fw_hdr = {
  3540. .chip = FW_HDR_CHIP_T6,
  3541. .fw_ver = __cpu_to_be32(FW_VERSION(T6)),
  3542. .intfver_nic = FW_INTFVER(T6, NIC),
  3543. .intfver_vnic = FW_INTFVER(T6, VNIC),
  3544. .intfver_ofld = FW_INTFVER(T6, OFLD),
  3545. .intfver_ri = FW_INTFVER(T6, RI),
  3546. .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
  3547. .intfver_iscsi = FW_INTFVER(T6, ISCSI),
  3548. .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
  3549. .intfver_fcoe = FW_INTFVER(T6, FCOE),
  3550. },
  3551. }
  3552. };
  3553. static struct fw_info *find_fw_info(int chip)
  3554. {
  3555. int i;
  3556. for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
  3557. if (fw_info_array[i].chip == chip)
  3558. return &fw_info_array[i];
  3559. }
  3560. return NULL;
  3561. }
  3562. /*
  3563. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  3564. */
  3565. static int adap_init0(struct adapter *adap)
  3566. {
  3567. int ret;
  3568. u32 v, port_vec;
  3569. enum dev_state state;
  3570. u32 params[7], val[7];
  3571. struct fw_caps_config_cmd caps_cmd;
  3572. int reset = 1;
  3573. /* Grab Firmware Device Log parameters as early as possible so we have
  3574. * access to it for debugging, etc.
  3575. */
  3576. ret = t4_init_devlog_params(adap);
  3577. if (ret < 0)
  3578. return ret;
  3579. /* Contact FW, advertising Master capability */
  3580. ret = t4_fw_hello(adap, adap->mbox, adap->mbox,
  3581. is_kdump_kernel() ? MASTER_MUST : MASTER_MAY, &state);
  3582. if (ret < 0) {
  3583. dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
  3584. ret);
  3585. return ret;
  3586. }
  3587. if (ret == adap->mbox)
  3588. adap->flags |= MASTER_PF;
  3589. /*
  3590. * If we're the Master PF Driver and the device is uninitialized,
  3591. * then let's consider upgrading the firmware ... (We always want
  3592. * to check the firmware version number in order to A. get it for
  3593. * later reporting and B. to warn if the currently loaded firmware
  3594. * is excessively mismatched relative to the driver.)
  3595. */
  3596. t4_get_version_info(adap);
  3597. ret = t4_check_fw_version(adap);
  3598. /* If firmware is too old (not supported by driver) force an update. */
  3599. if (ret)
  3600. state = DEV_STATE_UNINIT;
  3601. if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
  3602. struct fw_info *fw_info;
  3603. struct fw_hdr *card_fw;
  3604. const struct firmware *fw;
  3605. const u8 *fw_data = NULL;
  3606. unsigned int fw_size = 0;
  3607. /* This is the firmware whose headers the driver was compiled
  3608. * against
  3609. */
  3610. fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
  3611. if (fw_info == NULL) {
  3612. dev_err(adap->pdev_dev,
  3613. "unable to get firmware info for chip %d.\n",
  3614. CHELSIO_CHIP_VERSION(adap->params.chip));
  3615. return -EINVAL;
  3616. }
  3617. /* allocate memory to read the header of the firmware on the
  3618. * card
  3619. */
  3620. card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL);
  3621. /* Get FW from from /lib/firmware/ */
  3622. ret = request_firmware(&fw, fw_info->fw_mod_name,
  3623. adap->pdev_dev);
  3624. if (ret < 0) {
  3625. dev_err(adap->pdev_dev,
  3626. "unable to load firmware image %s, error %d\n",
  3627. fw_info->fw_mod_name, ret);
  3628. } else {
  3629. fw_data = fw->data;
  3630. fw_size = fw->size;
  3631. }
  3632. /* upgrade FW logic */
  3633. ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
  3634. state, &reset);
  3635. /* Cleaning up */
  3636. release_firmware(fw);
  3637. kvfree(card_fw);
  3638. if (ret < 0)
  3639. goto bye;
  3640. }
  3641. /*
  3642. * Grab VPD parameters. This should be done after we establish a
  3643. * connection to the firmware since some of the VPD parameters
  3644. * (notably the Core Clock frequency) are retrieved via requests to
  3645. * the firmware. On the other hand, we need these fairly early on
  3646. * so we do this right after getting ahold of the firmware.
  3647. */
  3648. ret = t4_get_vpd_params(adap, &adap->params.vpd);
  3649. if (ret < 0)
  3650. goto bye;
  3651. /*
  3652. * Find out what ports are available to us. Note that we need to do
  3653. * this before calling adap_init0_no_config() since it needs nports
  3654. * and portvec ...
  3655. */
  3656. v =
  3657. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3658. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
  3659. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
  3660. if (ret < 0)
  3661. goto bye;
  3662. adap->params.nports = hweight32(port_vec);
  3663. adap->params.portvec = port_vec;
  3664. /* If the firmware is initialized already, emit a simply note to that
  3665. * effect. Otherwise, it's time to try initializing the adapter.
  3666. */
  3667. if (state == DEV_STATE_INIT) {
  3668. ret = adap_config_hma(adap);
  3669. if (ret)
  3670. dev_err(adap->pdev_dev,
  3671. "HMA configuration failed with error %d\n",
  3672. ret);
  3673. dev_info(adap->pdev_dev, "Coming up as %s: "\
  3674. "Adapter already initialized\n",
  3675. adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
  3676. } else {
  3677. dev_info(adap->pdev_dev, "Coming up as MASTER: "\
  3678. "Initializing adapter\n");
  3679. /* Find out whether we're dealing with a version of the
  3680. * firmware which has configuration file support.
  3681. */
  3682. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3683. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3684. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
  3685. params, val);
  3686. /* If the firmware doesn't support Configuration Files,
  3687. * return an error.
  3688. */
  3689. if (ret < 0) {
  3690. dev_err(adap->pdev_dev, "firmware doesn't support "
  3691. "Firmware Configuration Files\n");
  3692. goto bye;
  3693. }
  3694. /* The firmware provides us with a memory buffer where we can
  3695. * load a Configuration File from the host if we want to
  3696. * override the Configuration File in flash.
  3697. */
  3698. ret = adap_init0_config(adap, reset);
  3699. if (ret == -ENOENT) {
  3700. dev_err(adap->pdev_dev, "no Configuration File "
  3701. "present on adapter.\n");
  3702. goto bye;
  3703. }
  3704. if (ret < 0) {
  3705. dev_err(adap->pdev_dev, "could not initialize "
  3706. "adapter, error %d\n", -ret);
  3707. goto bye;
  3708. }
  3709. }
  3710. /* Give the SGE code a chance to pull in anything that it needs ...
  3711. * Note that this must be called after we retrieve our VPD parameters
  3712. * in order to know how to convert core ticks to seconds, etc.
  3713. */
  3714. ret = t4_sge_init(adap);
  3715. if (ret < 0)
  3716. goto bye;
  3717. if (is_bypass_device(adap->pdev->device))
  3718. adap->params.bypass = 1;
  3719. /*
  3720. * Grab some of our basic fundamental operating parameters.
  3721. */
  3722. #define FW_PARAM_DEV(param) \
  3723. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
  3724. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
  3725. #define FW_PARAM_PFVF(param) \
  3726. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  3727. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
  3728. FW_PARAMS_PARAM_Y_V(0) | \
  3729. FW_PARAMS_PARAM_Z_V(0)
  3730. params[0] = FW_PARAM_PFVF(EQ_START);
  3731. params[1] = FW_PARAM_PFVF(L2T_START);
  3732. params[2] = FW_PARAM_PFVF(L2T_END);
  3733. params[3] = FW_PARAM_PFVF(FILTER_START);
  3734. params[4] = FW_PARAM_PFVF(FILTER_END);
  3735. params[5] = FW_PARAM_PFVF(IQFLINT_START);
  3736. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params, val);
  3737. if (ret < 0)
  3738. goto bye;
  3739. adap->sge.egr_start = val[0];
  3740. adap->l2t_start = val[1];
  3741. adap->l2t_end = val[2];
  3742. adap->tids.ftid_base = val[3];
  3743. adap->tids.nftids = val[4] - val[3] + 1;
  3744. adap->sge.ingr_start = val[5];
  3745. /* qids (ingress/egress) returned from firmware can be anywhere
  3746. * in the range from EQ(IQFLINT)_START to EQ(IQFLINT)_END.
  3747. * Hence driver needs to allocate memory for this range to
  3748. * store the queue info. Get the highest IQFLINT/EQ index returned
  3749. * in FW_EQ_*_CMD.alloc command.
  3750. */
  3751. params[0] = FW_PARAM_PFVF(EQ_END);
  3752. params[1] = FW_PARAM_PFVF(IQFLINT_END);
  3753. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3754. if (ret < 0)
  3755. goto bye;
  3756. adap->sge.egr_sz = val[0] - adap->sge.egr_start + 1;
  3757. adap->sge.ingr_sz = val[1] - adap->sge.ingr_start + 1;
  3758. adap->sge.egr_map = kcalloc(adap->sge.egr_sz,
  3759. sizeof(*adap->sge.egr_map), GFP_KERNEL);
  3760. if (!adap->sge.egr_map) {
  3761. ret = -ENOMEM;
  3762. goto bye;
  3763. }
  3764. adap->sge.ingr_map = kcalloc(adap->sge.ingr_sz,
  3765. sizeof(*adap->sge.ingr_map), GFP_KERNEL);
  3766. if (!adap->sge.ingr_map) {
  3767. ret = -ENOMEM;
  3768. goto bye;
  3769. }
  3770. /* Allocate the memory for the vaious egress queue bitmaps
  3771. * ie starving_fl, txq_maperr and blocked_fl.
  3772. */
  3773. adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3774. sizeof(long), GFP_KERNEL);
  3775. if (!adap->sge.starving_fl) {
  3776. ret = -ENOMEM;
  3777. goto bye;
  3778. }
  3779. adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3780. sizeof(long), GFP_KERNEL);
  3781. if (!adap->sge.txq_maperr) {
  3782. ret = -ENOMEM;
  3783. goto bye;
  3784. }
  3785. #ifdef CONFIG_DEBUG_FS
  3786. adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3787. sizeof(long), GFP_KERNEL);
  3788. if (!adap->sge.blocked_fl) {
  3789. ret = -ENOMEM;
  3790. goto bye;
  3791. }
  3792. #endif
  3793. params[0] = FW_PARAM_PFVF(CLIP_START);
  3794. params[1] = FW_PARAM_PFVF(CLIP_END);
  3795. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3796. if (ret < 0)
  3797. goto bye;
  3798. adap->clipt_start = val[0];
  3799. adap->clipt_end = val[1];
  3800. /* We don't yet have a PARAMs calls to retrieve the number of Traffic
  3801. * Classes supported by the hardware/firmware so we hard code it here
  3802. * for now.
  3803. */
  3804. adap->params.nsched_cls = is_t4(adap->params.chip) ? 15 : 16;
  3805. /* query params related to active filter region */
  3806. params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
  3807. params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
  3808. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3809. /* If Active filter size is set we enable establishing
  3810. * offload connection through firmware work request
  3811. */
  3812. if ((val[0] != val[1]) && (ret >= 0)) {
  3813. adap->flags |= FW_OFLD_CONN;
  3814. adap->tids.aftid_base = val[0];
  3815. adap->tids.aftid_end = val[1];
  3816. }
  3817. /* If we're running on newer firmware, let it know that we're
  3818. * prepared to deal with encapsulated CPL messages. Older
  3819. * firmware won't understand this and we'll just get
  3820. * unencapsulated messages ...
  3821. */
  3822. params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
  3823. val[0] = 1;
  3824. (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
  3825. /*
  3826. * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
  3827. * capability. Earlier versions of the firmware didn't have the
  3828. * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
  3829. * permission to use ULPTX MEMWRITE DSGL.
  3830. */
  3831. if (is_t4(adap->params.chip)) {
  3832. adap->params.ulptx_memwrite_dsgl = false;
  3833. } else {
  3834. params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
  3835. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3836. 1, params, val);
  3837. adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
  3838. }
  3839. /* See if FW supports FW_RI_FR_NSMR_TPTE_WR work request */
  3840. params[0] = FW_PARAM_DEV(RI_FR_NSMR_TPTE_WR);
  3841. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3842. 1, params, val);
  3843. adap->params.fr_nsmr_tpte_wr_support = (ret == 0 && val[0] != 0);
  3844. /* See if FW supports FW_FILTER2 work request */
  3845. if (is_t4(adap->params.chip)) {
  3846. adap->params.filter2_wr_support = 0;
  3847. } else {
  3848. params[0] = FW_PARAM_DEV(FILTER2_WR);
  3849. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3850. 1, params, val);
  3851. adap->params.filter2_wr_support = (ret == 0 && val[0] != 0);
  3852. }
  3853. /*
  3854. * Get device capabilities so we can determine what resources we need
  3855. * to manage.
  3856. */
  3857. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3858. caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3859. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3860. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3861. ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
  3862. &caps_cmd);
  3863. if (ret < 0)
  3864. goto bye;
  3865. if (caps_cmd.ofldcaps ||
  3866. (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER))) {
  3867. /* query offload-related parameters */
  3868. params[0] = FW_PARAM_DEV(NTID);
  3869. params[1] = FW_PARAM_PFVF(SERVER_START);
  3870. params[2] = FW_PARAM_PFVF(SERVER_END);
  3871. params[3] = FW_PARAM_PFVF(TDDP_START);
  3872. params[4] = FW_PARAM_PFVF(TDDP_END);
  3873. params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
  3874. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3875. params, val);
  3876. if (ret < 0)
  3877. goto bye;
  3878. adap->tids.ntids = val[0];
  3879. adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
  3880. adap->tids.stid_base = val[1];
  3881. adap->tids.nstids = val[2] - val[1] + 1;
  3882. /*
  3883. * Setup server filter region. Divide the available filter
  3884. * region into two parts. Regular filters get 1/3rd and server
  3885. * filters get 2/3rd part. This is only enabled if workarond
  3886. * path is enabled.
  3887. * 1. For regular filters.
  3888. * 2. Server filter: This are special filters which are used
  3889. * to redirect SYN packets to offload queue.
  3890. */
  3891. if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
  3892. adap->tids.sftid_base = adap->tids.ftid_base +
  3893. DIV_ROUND_UP(adap->tids.nftids, 3);
  3894. adap->tids.nsftids = adap->tids.nftids -
  3895. DIV_ROUND_UP(adap->tids.nftids, 3);
  3896. adap->tids.nftids = adap->tids.sftid_base -
  3897. adap->tids.ftid_base;
  3898. }
  3899. adap->vres.ddp.start = val[3];
  3900. adap->vres.ddp.size = val[4] - val[3] + 1;
  3901. adap->params.ofldq_wr_cred = val[5];
  3902. if (caps_cmd.niccaps & htons(FW_CAPS_CONFIG_NIC_HASHFILTER)) {
  3903. ret = init_hash_filter(adap);
  3904. if (ret < 0)
  3905. goto bye;
  3906. } else {
  3907. adap->params.offload = 1;
  3908. adap->num_ofld_uld += 1;
  3909. }
  3910. }
  3911. if (caps_cmd.rdmacaps) {
  3912. params[0] = FW_PARAM_PFVF(STAG_START);
  3913. params[1] = FW_PARAM_PFVF(STAG_END);
  3914. params[2] = FW_PARAM_PFVF(RQ_START);
  3915. params[3] = FW_PARAM_PFVF(RQ_END);
  3916. params[4] = FW_PARAM_PFVF(PBL_START);
  3917. params[5] = FW_PARAM_PFVF(PBL_END);
  3918. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3919. params, val);
  3920. if (ret < 0)
  3921. goto bye;
  3922. adap->vres.stag.start = val[0];
  3923. adap->vres.stag.size = val[1] - val[0] + 1;
  3924. adap->vres.rq.start = val[2];
  3925. adap->vres.rq.size = val[3] - val[2] + 1;
  3926. adap->vres.pbl.start = val[4];
  3927. adap->vres.pbl.size = val[5] - val[4] + 1;
  3928. params[0] = FW_PARAM_PFVF(SRQ_START);
  3929. params[1] = FW_PARAM_PFVF(SRQ_END);
  3930. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3931. params, val);
  3932. if (!ret) {
  3933. adap->vres.srq.start = val[0];
  3934. adap->vres.srq.size = val[1] - val[0] + 1;
  3935. }
  3936. if (adap->vres.srq.size) {
  3937. adap->srq = t4_init_srq(adap->vres.srq.size);
  3938. if (!adap->srq)
  3939. dev_warn(&adap->pdev->dev, "could not allocate SRQ, continuing\n");
  3940. }
  3941. params[0] = FW_PARAM_PFVF(SQRQ_START);
  3942. params[1] = FW_PARAM_PFVF(SQRQ_END);
  3943. params[2] = FW_PARAM_PFVF(CQ_START);
  3944. params[3] = FW_PARAM_PFVF(CQ_END);
  3945. params[4] = FW_PARAM_PFVF(OCQ_START);
  3946. params[5] = FW_PARAM_PFVF(OCQ_END);
  3947. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params,
  3948. val);
  3949. if (ret < 0)
  3950. goto bye;
  3951. adap->vres.qp.start = val[0];
  3952. adap->vres.qp.size = val[1] - val[0] + 1;
  3953. adap->vres.cq.start = val[2];
  3954. adap->vres.cq.size = val[3] - val[2] + 1;
  3955. adap->vres.ocq.start = val[4];
  3956. adap->vres.ocq.size = val[5] - val[4] + 1;
  3957. params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
  3958. params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
  3959. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params,
  3960. val);
  3961. if (ret < 0) {
  3962. adap->params.max_ordird_qp = 8;
  3963. adap->params.max_ird_adapter = 32 * adap->tids.ntids;
  3964. ret = 0;
  3965. } else {
  3966. adap->params.max_ordird_qp = val[0];
  3967. adap->params.max_ird_adapter = val[1];
  3968. }
  3969. dev_info(adap->pdev_dev,
  3970. "max_ordird_qp %d max_ird_adapter %d\n",
  3971. adap->params.max_ordird_qp,
  3972. adap->params.max_ird_adapter);
  3973. /* Enable write_with_immediate if FW supports it */
  3974. params[0] = FW_PARAM_DEV(RDMA_WRITE_WITH_IMM);
  3975. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, params,
  3976. val);
  3977. adap->params.write_w_imm_support = (ret == 0 && val[0] != 0);
  3978. /* Enable write_cmpl if FW supports it */
  3979. params[0] = FW_PARAM_DEV(RI_WRITE_CMPL_WR);
  3980. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, params,
  3981. val);
  3982. adap->params.write_cmpl_support = (ret == 0 && val[0] != 0);
  3983. adap->num_ofld_uld += 2;
  3984. }
  3985. if (caps_cmd.iscsicaps) {
  3986. params[0] = FW_PARAM_PFVF(ISCSI_START);
  3987. params[1] = FW_PARAM_PFVF(ISCSI_END);
  3988. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3989. params, val);
  3990. if (ret < 0)
  3991. goto bye;
  3992. adap->vres.iscsi.start = val[0];
  3993. adap->vres.iscsi.size = val[1] - val[0] + 1;
  3994. /* LIO target and cxgb4i initiaitor */
  3995. adap->num_ofld_uld += 2;
  3996. }
  3997. if (caps_cmd.cryptocaps) {
  3998. if (ntohs(caps_cmd.cryptocaps) &
  3999. FW_CAPS_CONFIG_CRYPTO_LOOKASIDE) {
  4000. params[0] = FW_PARAM_PFVF(NCRYPTO_LOOKASIDE);
  4001. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  4002. 2, params, val);
  4003. if (ret < 0) {
  4004. if (ret != -EINVAL)
  4005. goto bye;
  4006. } else {
  4007. adap->vres.ncrypto_fc = val[0];
  4008. }
  4009. adap->num_ofld_uld += 1;
  4010. }
  4011. if (ntohs(caps_cmd.cryptocaps) &
  4012. FW_CAPS_CONFIG_TLS_INLINE) {
  4013. params[0] = FW_PARAM_PFVF(TLS_START);
  4014. params[1] = FW_PARAM_PFVF(TLS_END);
  4015. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  4016. 2, params, val);
  4017. if (ret < 0)
  4018. goto bye;
  4019. adap->vres.key.start = val[0];
  4020. adap->vres.key.size = val[1] - val[0] + 1;
  4021. adap->num_uld += 1;
  4022. }
  4023. adap->params.crypto = ntohs(caps_cmd.cryptocaps);
  4024. }
  4025. #undef FW_PARAM_PFVF
  4026. #undef FW_PARAM_DEV
  4027. /* The MTU/MSS Table is initialized by now, so load their values. If
  4028. * we're initializing the adapter, then we'll make any modifications
  4029. * we want to the MTU/MSS Table and also initialize the congestion
  4030. * parameters.
  4031. */
  4032. t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
  4033. if (state != DEV_STATE_INIT) {
  4034. int i;
  4035. /* The default MTU Table contains values 1492 and 1500.
  4036. * However, for TCP, it's better to have two values which are
  4037. * a multiple of 8 +/- 4 bytes apart near this popular MTU.
  4038. * This allows us to have a TCP Data Payload which is a
  4039. * multiple of 8 regardless of what combination of TCP Options
  4040. * are in use (always a multiple of 4 bytes) which is
  4041. * important for performance reasons. For instance, if no
  4042. * options are in use, then we have a 20-byte IP header and a
  4043. * 20-byte TCP header. In this case, a 1500-byte MSS would
  4044. * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
  4045. * which is not a multiple of 8. So using an MSS of 1488 in
  4046. * this case results in a TCP Data Payload of 1448 bytes which
  4047. * is a multiple of 8. On the other hand, if 12-byte TCP Time
  4048. * Stamps have been negotiated, then an MTU of 1500 bytes
  4049. * results in a TCP Data Payload of 1448 bytes which, as
  4050. * above, is a multiple of 8 bytes ...
  4051. */
  4052. for (i = 0; i < NMTUS; i++)
  4053. if (adap->params.mtus[i] == 1492) {
  4054. adap->params.mtus[i] = 1488;
  4055. break;
  4056. }
  4057. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4058. adap->params.b_wnd);
  4059. }
  4060. t4_init_sge_params(adap);
  4061. adap->flags |= FW_OK;
  4062. t4_init_tp_params(adap, true);
  4063. return 0;
  4064. /*
  4065. * Something bad happened. If a command timed out or failed with EIO
  4066. * FW does not operate within its spec or something catastrophic
  4067. * happened to HW/FW, stop issuing commands.
  4068. */
  4069. bye:
  4070. adap_free_hma_mem(adap);
  4071. kfree(adap->sge.egr_map);
  4072. kfree(adap->sge.ingr_map);
  4073. kfree(adap->sge.starving_fl);
  4074. kfree(adap->sge.txq_maperr);
  4075. #ifdef CONFIG_DEBUG_FS
  4076. kfree(adap->sge.blocked_fl);
  4077. #endif
  4078. if (ret != -ETIMEDOUT && ret != -EIO)
  4079. t4_fw_bye(adap, adap->mbox);
  4080. return ret;
  4081. }
  4082. /* EEH callbacks */
  4083. static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
  4084. pci_channel_state_t state)
  4085. {
  4086. int i;
  4087. struct adapter *adap = pci_get_drvdata(pdev);
  4088. if (!adap)
  4089. goto out;
  4090. rtnl_lock();
  4091. adap->flags &= ~FW_OK;
  4092. notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
  4093. spin_lock(&adap->stats_lock);
  4094. for_each_port(adap, i) {
  4095. struct net_device *dev = adap->port[i];
  4096. if (dev) {
  4097. netif_device_detach(dev);
  4098. netif_carrier_off(dev);
  4099. }
  4100. }
  4101. spin_unlock(&adap->stats_lock);
  4102. disable_interrupts(adap);
  4103. if (adap->flags & FULL_INIT_DONE)
  4104. cxgb_down(adap);
  4105. rtnl_unlock();
  4106. if ((adap->flags & DEV_ENABLED)) {
  4107. pci_disable_device(pdev);
  4108. adap->flags &= ~DEV_ENABLED;
  4109. }
  4110. out: return state == pci_channel_io_perm_failure ?
  4111. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  4112. }
  4113. static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
  4114. {
  4115. int i, ret;
  4116. struct fw_caps_config_cmd c;
  4117. struct adapter *adap = pci_get_drvdata(pdev);
  4118. if (!adap) {
  4119. pci_restore_state(pdev);
  4120. pci_save_state(pdev);
  4121. return PCI_ERS_RESULT_RECOVERED;
  4122. }
  4123. if (!(adap->flags & DEV_ENABLED)) {
  4124. if (pci_enable_device(pdev)) {
  4125. dev_err(&pdev->dev, "Cannot reenable PCI "
  4126. "device after reset\n");
  4127. return PCI_ERS_RESULT_DISCONNECT;
  4128. }
  4129. adap->flags |= DEV_ENABLED;
  4130. }
  4131. pci_set_master(pdev);
  4132. pci_restore_state(pdev);
  4133. pci_save_state(pdev);
  4134. pci_cleanup_aer_uncorrect_error_status(pdev);
  4135. if (t4_wait_dev_ready(adap->regs) < 0)
  4136. return PCI_ERS_RESULT_DISCONNECT;
  4137. if (t4_fw_hello(adap, adap->mbox, adap->pf, MASTER_MUST, NULL) < 0)
  4138. return PCI_ERS_RESULT_DISCONNECT;
  4139. adap->flags |= FW_OK;
  4140. if (adap_init1(adap, &c))
  4141. return PCI_ERS_RESULT_DISCONNECT;
  4142. for_each_port(adap, i) {
  4143. struct port_info *p = adap2pinfo(adap, i);
  4144. ret = t4_alloc_vi(adap, adap->mbox, p->tx_chan, adap->pf, 0, 1,
  4145. NULL, NULL);
  4146. if (ret < 0)
  4147. return PCI_ERS_RESULT_DISCONNECT;
  4148. p->viid = ret;
  4149. p->xact_addr_filt = -1;
  4150. }
  4151. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4152. adap->params.b_wnd);
  4153. setup_memwin(adap);
  4154. if (cxgb_up(adap))
  4155. return PCI_ERS_RESULT_DISCONNECT;
  4156. return PCI_ERS_RESULT_RECOVERED;
  4157. }
  4158. static void eeh_resume(struct pci_dev *pdev)
  4159. {
  4160. int i;
  4161. struct adapter *adap = pci_get_drvdata(pdev);
  4162. if (!adap)
  4163. return;
  4164. rtnl_lock();
  4165. for_each_port(adap, i) {
  4166. struct net_device *dev = adap->port[i];
  4167. if (dev) {
  4168. if (netif_running(dev)) {
  4169. link_start(dev);
  4170. cxgb_set_rxmode(dev);
  4171. }
  4172. netif_device_attach(dev);
  4173. }
  4174. }
  4175. rtnl_unlock();
  4176. }
  4177. static const struct pci_error_handlers cxgb4_eeh = {
  4178. .error_detected = eeh_err_detected,
  4179. .slot_reset = eeh_slot_reset,
  4180. .resume = eeh_resume,
  4181. };
  4182. /* Return true if the Link Configuration supports "High Speeds" (those greater
  4183. * than 1Gb/s).
  4184. */
  4185. static inline bool is_x_10g_port(const struct link_config *lc)
  4186. {
  4187. unsigned int speeds, high_speeds;
  4188. speeds = FW_PORT_CAP32_SPEED_V(FW_PORT_CAP32_SPEED_G(lc->pcaps));
  4189. high_speeds = speeds &
  4190. ~(FW_PORT_CAP32_SPEED_100M | FW_PORT_CAP32_SPEED_1G);
  4191. return high_speeds != 0;
  4192. }
  4193. /*
  4194. * Perform default configuration of DMA queues depending on the number and type
  4195. * of ports we found and the number of available CPUs. Most settings can be
  4196. * modified by the admin prior to actual use.
  4197. */
  4198. static void cfg_queues(struct adapter *adap)
  4199. {
  4200. struct sge *s = &adap->sge;
  4201. int i = 0, n10g = 0, qidx = 0;
  4202. #ifndef CONFIG_CHELSIO_T4_DCB
  4203. int q10g = 0;
  4204. #endif
  4205. /* Reduce memory usage in kdump environment, disable all offload.
  4206. */
  4207. if (is_kdump_kernel() || (is_uld(adap) && t4_uld_mem_alloc(adap))) {
  4208. adap->params.offload = 0;
  4209. adap->params.crypto = 0;
  4210. }
  4211. n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
  4212. #ifdef CONFIG_CHELSIO_T4_DCB
  4213. /* For Data Center Bridging support we need to be able to support up
  4214. * to 8 Traffic Priorities; each of which will be assigned to its
  4215. * own TX Queue in order to prevent Head-Of-Line Blocking.
  4216. */
  4217. if (adap->params.nports * 8 > MAX_ETH_QSETS) {
  4218. dev_err(adap->pdev_dev, "MAX_ETH_QSETS=%d < %d!\n",
  4219. MAX_ETH_QSETS, adap->params.nports * 8);
  4220. BUG_ON(1);
  4221. }
  4222. for_each_port(adap, i) {
  4223. struct port_info *pi = adap2pinfo(adap, i);
  4224. pi->first_qset = qidx;
  4225. pi->nqsets = is_kdump_kernel() ? 1 : 8;
  4226. qidx += pi->nqsets;
  4227. }
  4228. #else /* !CONFIG_CHELSIO_T4_DCB */
  4229. /*
  4230. * We default to 1 queue per non-10G port and up to # of cores queues
  4231. * per 10G port.
  4232. */
  4233. if (n10g)
  4234. q10g = (MAX_ETH_QSETS - (adap->params.nports - n10g)) / n10g;
  4235. if (q10g > netif_get_num_default_rss_queues())
  4236. q10g = netif_get_num_default_rss_queues();
  4237. if (is_kdump_kernel())
  4238. q10g = 1;
  4239. for_each_port(adap, i) {
  4240. struct port_info *pi = adap2pinfo(adap, i);
  4241. pi->first_qset = qidx;
  4242. pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
  4243. qidx += pi->nqsets;
  4244. }
  4245. #endif /* !CONFIG_CHELSIO_T4_DCB */
  4246. s->ethqsets = qidx;
  4247. s->max_ethqsets = qidx; /* MSI-X may lower it later */
  4248. if (is_uld(adap)) {
  4249. /*
  4250. * For offload we use 1 queue/channel if all ports are up to 1G,
  4251. * otherwise we divide all available queues amongst the channels
  4252. * capped by the number of available cores.
  4253. */
  4254. if (n10g) {
  4255. i = min_t(int, MAX_OFLD_QSETS, num_online_cpus());
  4256. s->ofldqsets = roundup(i, adap->params.nports);
  4257. } else {
  4258. s->ofldqsets = adap->params.nports;
  4259. }
  4260. }
  4261. for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
  4262. struct sge_eth_rxq *r = &s->ethrxq[i];
  4263. init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
  4264. r->fl.size = 72;
  4265. }
  4266. for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
  4267. s->ethtxq[i].q.size = 1024;
  4268. for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
  4269. s->ctrlq[i].q.size = 512;
  4270. if (!is_t4(adap->params.chip))
  4271. s->ptptxq.q.size = 8;
  4272. init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
  4273. init_rspq(adap, &s->intrq, 0, 1, 512, 64);
  4274. }
  4275. /*
  4276. * Reduce the number of Ethernet queues across all ports to at most n.
  4277. * n provides at least one queue per port.
  4278. */
  4279. static void reduce_ethqs(struct adapter *adap, int n)
  4280. {
  4281. int i;
  4282. struct port_info *pi;
  4283. while (n < adap->sge.ethqsets)
  4284. for_each_port(adap, i) {
  4285. pi = adap2pinfo(adap, i);
  4286. if (pi->nqsets > 1) {
  4287. pi->nqsets--;
  4288. adap->sge.ethqsets--;
  4289. if (adap->sge.ethqsets <= n)
  4290. break;
  4291. }
  4292. }
  4293. n = 0;
  4294. for_each_port(adap, i) {
  4295. pi = adap2pinfo(adap, i);
  4296. pi->first_qset = n;
  4297. n += pi->nqsets;
  4298. }
  4299. }
  4300. static int get_msix_info(struct adapter *adap)
  4301. {
  4302. struct uld_msix_info *msix_info;
  4303. unsigned int max_ingq = 0;
  4304. if (is_offload(adap))
  4305. max_ingq += MAX_OFLD_QSETS * adap->num_ofld_uld;
  4306. if (is_pci_uld(adap))
  4307. max_ingq += MAX_OFLD_QSETS * adap->num_uld;
  4308. if (!max_ingq)
  4309. goto out;
  4310. msix_info = kcalloc(max_ingq, sizeof(*msix_info), GFP_KERNEL);
  4311. if (!msix_info)
  4312. return -ENOMEM;
  4313. adap->msix_bmap_ulds.msix_bmap = kcalloc(BITS_TO_LONGS(max_ingq),
  4314. sizeof(long), GFP_KERNEL);
  4315. if (!adap->msix_bmap_ulds.msix_bmap) {
  4316. kfree(msix_info);
  4317. return -ENOMEM;
  4318. }
  4319. spin_lock_init(&adap->msix_bmap_ulds.lock);
  4320. adap->msix_info_ulds = msix_info;
  4321. out:
  4322. return 0;
  4323. }
  4324. static void free_msix_info(struct adapter *adap)
  4325. {
  4326. if (!(adap->num_uld && adap->num_ofld_uld))
  4327. return;
  4328. kfree(adap->msix_info_ulds);
  4329. kfree(adap->msix_bmap_ulds.msix_bmap);
  4330. }
  4331. /* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
  4332. #define EXTRA_VECS 2
  4333. static int enable_msix(struct adapter *adap)
  4334. {
  4335. int ofld_need = 0, uld_need = 0;
  4336. int i, j, want, need, allocated;
  4337. struct sge *s = &adap->sge;
  4338. unsigned int nchan = adap->params.nports;
  4339. struct msix_entry *entries;
  4340. int max_ingq = MAX_INGQ;
  4341. if (is_pci_uld(adap))
  4342. max_ingq += (MAX_OFLD_QSETS * adap->num_uld);
  4343. if (is_offload(adap))
  4344. max_ingq += (MAX_OFLD_QSETS * adap->num_ofld_uld);
  4345. entries = kmalloc(sizeof(*entries) * (max_ingq + 1),
  4346. GFP_KERNEL);
  4347. if (!entries)
  4348. return -ENOMEM;
  4349. /* map for msix */
  4350. if (get_msix_info(adap)) {
  4351. adap->params.offload = 0;
  4352. adap->params.crypto = 0;
  4353. }
  4354. for (i = 0; i < max_ingq + 1; ++i)
  4355. entries[i].entry = i;
  4356. want = s->max_ethqsets + EXTRA_VECS;
  4357. if (is_offload(adap)) {
  4358. want += adap->num_ofld_uld * s->ofldqsets;
  4359. ofld_need = adap->num_ofld_uld * nchan;
  4360. }
  4361. if (is_pci_uld(adap)) {
  4362. want += adap->num_uld * s->ofldqsets;
  4363. uld_need = adap->num_uld * nchan;
  4364. }
  4365. #ifdef CONFIG_CHELSIO_T4_DCB
  4366. /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
  4367. * each port.
  4368. */
  4369. need = 8 * adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  4370. #else
  4371. need = adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  4372. #endif
  4373. allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
  4374. if (allocated < 0) {
  4375. dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
  4376. " not using MSI-X\n");
  4377. kfree(entries);
  4378. return allocated;
  4379. }
  4380. /* Distribute available vectors to the various queue groups.
  4381. * Every group gets its minimum requirement and NIC gets top
  4382. * priority for leftovers.
  4383. */
  4384. i = allocated - EXTRA_VECS - ofld_need - uld_need;
  4385. if (i < s->max_ethqsets) {
  4386. s->max_ethqsets = i;
  4387. if (i < s->ethqsets)
  4388. reduce_ethqs(adap, i);
  4389. }
  4390. if (is_uld(adap)) {
  4391. if (allocated < want)
  4392. s->nqs_per_uld = nchan;
  4393. else
  4394. s->nqs_per_uld = s->ofldqsets;
  4395. }
  4396. for (i = 0; i < (s->max_ethqsets + EXTRA_VECS); ++i)
  4397. adap->msix_info[i].vec = entries[i].vector;
  4398. if (is_uld(adap)) {
  4399. for (j = 0 ; i < allocated; ++i, j++) {
  4400. adap->msix_info_ulds[j].vec = entries[i].vector;
  4401. adap->msix_info_ulds[j].idx = i;
  4402. }
  4403. adap->msix_bmap_ulds.mapsize = j;
  4404. }
  4405. dev_info(adap->pdev_dev, "%d MSI-X vectors allocated, "
  4406. "nic %d per uld %d\n",
  4407. allocated, s->max_ethqsets, s->nqs_per_uld);
  4408. kfree(entries);
  4409. return 0;
  4410. }
  4411. #undef EXTRA_VECS
  4412. static int init_rss(struct adapter *adap)
  4413. {
  4414. unsigned int i;
  4415. int err;
  4416. err = t4_init_rss_mode(adap, adap->mbox);
  4417. if (err)
  4418. return err;
  4419. for_each_port(adap, i) {
  4420. struct port_info *pi = adap2pinfo(adap, i);
  4421. pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
  4422. if (!pi->rss)
  4423. return -ENOMEM;
  4424. }
  4425. return 0;
  4426. }
  4427. static int cxgb4_get_pcie_dev_link_caps(struct adapter *adap,
  4428. enum pci_bus_speed *speed,
  4429. enum pcie_link_width *width)
  4430. {
  4431. u32 lnkcap1, lnkcap2;
  4432. int err1, err2;
  4433. #define PCIE_MLW_CAP_SHIFT 4 /* start of MLW mask in link capabilities */
  4434. *speed = PCI_SPEED_UNKNOWN;
  4435. *width = PCIE_LNK_WIDTH_UNKNOWN;
  4436. err1 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP,
  4437. &lnkcap1);
  4438. err2 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP2,
  4439. &lnkcap2);
  4440. if (!err2 && lnkcap2) { /* PCIe r3.0-compliant */
  4441. if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
  4442. *speed = PCIE_SPEED_8_0GT;
  4443. else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
  4444. *speed = PCIE_SPEED_5_0GT;
  4445. else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
  4446. *speed = PCIE_SPEED_2_5GT;
  4447. }
  4448. if (!err1) {
  4449. *width = (lnkcap1 & PCI_EXP_LNKCAP_MLW) >> PCIE_MLW_CAP_SHIFT;
  4450. if (!lnkcap2) { /* pre-r3.0 */
  4451. if (lnkcap1 & PCI_EXP_LNKCAP_SLS_5_0GB)
  4452. *speed = PCIE_SPEED_5_0GT;
  4453. else if (lnkcap1 & PCI_EXP_LNKCAP_SLS_2_5GB)
  4454. *speed = PCIE_SPEED_2_5GT;
  4455. }
  4456. }
  4457. if (*speed == PCI_SPEED_UNKNOWN || *width == PCIE_LNK_WIDTH_UNKNOWN)
  4458. return err1 ? err1 : err2 ? err2 : -EINVAL;
  4459. return 0;
  4460. }
  4461. static void cxgb4_check_pcie_caps(struct adapter *adap)
  4462. {
  4463. enum pcie_link_width width, width_cap;
  4464. enum pci_bus_speed speed, speed_cap;
  4465. #define PCIE_SPEED_STR(speed) \
  4466. (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : \
  4467. speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : \
  4468. speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : \
  4469. "Unknown")
  4470. if (cxgb4_get_pcie_dev_link_caps(adap, &speed_cap, &width_cap)) {
  4471. dev_warn(adap->pdev_dev,
  4472. "Unable to determine PCIe device BW capabilities\n");
  4473. return;
  4474. }
  4475. if (pcie_get_minimum_link(adap->pdev, &speed, &width) ||
  4476. speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
  4477. dev_warn(adap->pdev_dev,
  4478. "Unable to determine PCI Express bandwidth.\n");
  4479. return;
  4480. }
  4481. dev_info(adap->pdev_dev, "PCIe link speed is %s, device supports %s\n",
  4482. PCIE_SPEED_STR(speed), PCIE_SPEED_STR(speed_cap));
  4483. dev_info(adap->pdev_dev, "PCIe link width is x%d, device supports x%d\n",
  4484. width, width_cap);
  4485. if (speed < speed_cap || width < width_cap)
  4486. dev_info(adap->pdev_dev,
  4487. "A slot with more lanes and/or higher speed is "
  4488. "suggested for optimal performance.\n");
  4489. }
  4490. /* Dump basic information about the adapter */
  4491. static void print_adapter_info(struct adapter *adapter)
  4492. {
  4493. /* Hardware/Firmware/etc. Version/Revision IDs */
  4494. t4_dump_version_info(adapter);
  4495. /* Software/Hardware configuration */
  4496. dev_info(adapter->pdev_dev, "Configuration: %sNIC %s, %s capable\n",
  4497. is_offload(adapter) ? "R" : "",
  4498. ((adapter->flags & USING_MSIX) ? "MSI-X" :
  4499. (adapter->flags & USING_MSI) ? "MSI" : ""),
  4500. is_offload(adapter) ? "Offload" : "non-Offload");
  4501. }
  4502. static void print_port_info(const struct net_device *dev)
  4503. {
  4504. char buf[80];
  4505. char *bufp = buf;
  4506. const char *spd = "";
  4507. const struct port_info *pi = netdev_priv(dev);
  4508. const struct adapter *adap = pi->adapter;
  4509. if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_2_5GB)
  4510. spd = " 2.5 GT/s";
  4511. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_5_0GB)
  4512. spd = " 5 GT/s";
  4513. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_8_0GB)
  4514. spd = " 8 GT/s";
  4515. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100M)
  4516. bufp += sprintf(bufp, "100M/");
  4517. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_1G)
  4518. bufp += sprintf(bufp, "1G/");
  4519. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_10G)
  4520. bufp += sprintf(bufp, "10G/");
  4521. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_25G)
  4522. bufp += sprintf(bufp, "25G/");
  4523. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_40G)
  4524. bufp += sprintf(bufp, "40G/");
  4525. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_50G)
  4526. bufp += sprintf(bufp, "50G/");
  4527. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_100G)
  4528. bufp += sprintf(bufp, "100G/");
  4529. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_200G)
  4530. bufp += sprintf(bufp, "200G/");
  4531. if (pi->link_cfg.pcaps & FW_PORT_CAP32_SPEED_400G)
  4532. bufp += sprintf(bufp, "400G/");
  4533. if (bufp != buf)
  4534. --bufp;
  4535. sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
  4536. netdev_info(dev, "%s: Chelsio %s (%s) %s\n",
  4537. dev->name, adap->params.vpd.id, adap->name, buf);
  4538. }
  4539. /*
  4540. * Free the following resources:
  4541. * - memory used for tables
  4542. * - MSI/MSI-X
  4543. * - net devices
  4544. * - resources FW is holding for us
  4545. */
  4546. static void free_some_resources(struct adapter *adapter)
  4547. {
  4548. unsigned int i;
  4549. kvfree(adapter->smt);
  4550. kvfree(adapter->l2t);
  4551. kvfree(adapter->srq);
  4552. t4_cleanup_sched(adapter);
  4553. kvfree(adapter->tids.tid_tab);
  4554. cxgb4_cleanup_tc_flower(adapter);
  4555. cxgb4_cleanup_tc_u32(adapter);
  4556. kfree(adapter->sge.egr_map);
  4557. kfree(adapter->sge.ingr_map);
  4558. kfree(adapter->sge.starving_fl);
  4559. kfree(adapter->sge.txq_maperr);
  4560. #ifdef CONFIG_DEBUG_FS
  4561. kfree(adapter->sge.blocked_fl);
  4562. #endif
  4563. disable_msi(adapter);
  4564. for_each_port(adapter, i)
  4565. if (adapter->port[i]) {
  4566. struct port_info *pi = adap2pinfo(adapter, i);
  4567. if (pi->viid != 0)
  4568. t4_free_vi(adapter, adapter->mbox, adapter->pf,
  4569. 0, pi->viid);
  4570. kfree(adap2pinfo(adapter, i)->rss);
  4571. free_netdev(adapter->port[i]);
  4572. }
  4573. if (adapter->flags & FW_OK)
  4574. t4_fw_bye(adapter, adapter->pf);
  4575. }
  4576. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  4577. #define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
  4578. NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
  4579. #define SEGMENT_SIZE 128
  4580. static int get_chip_type(struct pci_dev *pdev, u32 pl_rev)
  4581. {
  4582. u16 device_id;
  4583. /* Retrieve adapter's device ID */
  4584. pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
  4585. switch (device_id >> 12) {
  4586. case CHELSIO_T4:
  4587. return CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  4588. case CHELSIO_T5:
  4589. return CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  4590. case CHELSIO_T6:
  4591. return CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
  4592. default:
  4593. dev_err(&pdev->dev, "Device %d is not supported\n",
  4594. device_id);
  4595. }
  4596. return -EINVAL;
  4597. }
  4598. #ifdef CONFIG_PCI_IOV
  4599. static void cxgb4_mgmt_setup(struct net_device *dev)
  4600. {
  4601. dev->type = ARPHRD_NONE;
  4602. dev->mtu = 0;
  4603. dev->hard_header_len = 0;
  4604. dev->addr_len = 0;
  4605. dev->tx_queue_len = 0;
  4606. dev->flags |= IFF_NOARP;
  4607. dev->priv_flags |= IFF_NO_QUEUE;
  4608. /* Initialize the device structure. */
  4609. dev->netdev_ops = &cxgb4_mgmt_netdev_ops;
  4610. dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
  4611. }
  4612. static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
  4613. {
  4614. struct adapter *adap = pci_get_drvdata(pdev);
  4615. int err = 0;
  4616. int current_vfs = pci_num_vf(pdev);
  4617. u32 pcie_fw;
  4618. pcie_fw = readl(adap->regs + PCIE_FW_A);
  4619. /* Check if cxgb4 is the MASTER and fw is initialized */
  4620. if (num_vfs &&
  4621. (!(pcie_fw & PCIE_FW_INIT_F) ||
  4622. !(pcie_fw & PCIE_FW_MASTER_VLD_F) ||
  4623. PCIE_FW_MASTER_G(pcie_fw) != CXGB4_UNIFIED_PF)) {
  4624. dev_warn(&pdev->dev,
  4625. "cxgb4 driver needs to be MASTER to support SRIOV\n");
  4626. return -EOPNOTSUPP;
  4627. }
  4628. /* If any of the VF's is already assigned to Guest OS, then
  4629. * SRIOV for the same cannot be modified
  4630. */
  4631. if (current_vfs && pci_vfs_assigned(pdev)) {
  4632. dev_err(&pdev->dev,
  4633. "Cannot modify SR-IOV while VFs are assigned\n");
  4634. return current_vfs;
  4635. }
  4636. /* Note that the upper-level code ensures that we're never called with
  4637. * a non-zero "num_vfs" when we already have VFs instantiated. But
  4638. * it never hurts to code defensively.
  4639. */
  4640. if (num_vfs != 0 && current_vfs != 0)
  4641. return -EBUSY;
  4642. /* Nothing to do for no change. */
  4643. if (num_vfs == current_vfs)
  4644. return num_vfs;
  4645. /* Disable SRIOV when zero is passed. */
  4646. if (!num_vfs) {
  4647. pci_disable_sriov(pdev);
  4648. /* free VF Management Interface */
  4649. unregister_netdev(adap->port[0]);
  4650. free_netdev(adap->port[0]);
  4651. adap->port[0] = NULL;
  4652. /* free VF resources */
  4653. adap->num_vfs = 0;
  4654. kfree(adap->vfinfo);
  4655. adap->vfinfo = NULL;
  4656. return 0;
  4657. }
  4658. if (!current_vfs) {
  4659. struct fw_pfvf_cmd port_cmd, port_rpl;
  4660. struct net_device *netdev;
  4661. unsigned int pmask, port;
  4662. struct pci_dev *pbridge;
  4663. struct port_info *pi;
  4664. char name[IFNAMSIZ];
  4665. u32 devcap2;
  4666. u16 flags;
  4667. int pos;
  4668. /* If we want to instantiate Virtual Functions, then our
  4669. * parent bridge's PCI-E needs to support Alternative Routing
  4670. * ID (ARI) because our VFs will show up at function offset 8
  4671. * and above.
  4672. */
  4673. pbridge = pdev->bus->self;
  4674. pos = pci_find_capability(pbridge, PCI_CAP_ID_EXP);
  4675. pci_read_config_word(pbridge, pos + PCI_EXP_FLAGS, &flags);
  4676. pci_read_config_dword(pbridge, pos + PCI_EXP_DEVCAP2, &devcap2);
  4677. if ((flags & PCI_EXP_FLAGS_VERS) < 2 ||
  4678. !(devcap2 & PCI_EXP_DEVCAP2_ARI)) {
  4679. /* Our parent bridge does not support ARI so issue a
  4680. * warning and skip instantiating the VFs. They
  4681. * won't be reachable.
  4682. */
  4683. dev_warn(&pdev->dev, "Parent bridge %02x:%02x.%x doesn't support ARI; can't instantiate Virtual Functions\n",
  4684. pbridge->bus->number, PCI_SLOT(pbridge->devfn),
  4685. PCI_FUNC(pbridge->devfn));
  4686. return -ENOTSUPP;
  4687. }
  4688. memset(&port_cmd, 0, sizeof(port_cmd));
  4689. port_cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_PFVF_CMD) |
  4690. FW_CMD_REQUEST_F |
  4691. FW_CMD_READ_F |
  4692. FW_PFVF_CMD_PFN_V(adap->pf) |
  4693. FW_PFVF_CMD_VFN_V(0));
  4694. port_cmd.retval_len16 = cpu_to_be32(FW_LEN16(port_cmd));
  4695. err = t4_wr_mbox(adap, adap->mbox, &port_cmd, sizeof(port_cmd),
  4696. &port_rpl);
  4697. if (err)
  4698. return err;
  4699. pmask = FW_PFVF_CMD_PMASK_G(be32_to_cpu(port_rpl.type_to_neq));
  4700. port = ffs(pmask) - 1;
  4701. /* Allocate VF Management Interface. */
  4702. snprintf(name, IFNAMSIZ, "mgmtpf%d,%d", adap->adap_idx,
  4703. adap->pf);
  4704. netdev = alloc_netdev(sizeof(struct port_info),
  4705. name, NET_NAME_UNKNOWN, cxgb4_mgmt_setup);
  4706. if (!netdev)
  4707. return -ENOMEM;
  4708. pi = netdev_priv(netdev);
  4709. pi->adapter = adap;
  4710. pi->lport = port;
  4711. pi->tx_chan = port;
  4712. SET_NETDEV_DEV(netdev, &pdev->dev);
  4713. adap->port[0] = netdev;
  4714. pi->port_id = 0;
  4715. err = register_netdev(adap->port[0]);
  4716. if (err) {
  4717. pr_info("Unable to register VF mgmt netdev %s\n", name);
  4718. free_netdev(adap->port[0]);
  4719. adap->port[0] = NULL;
  4720. return err;
  4721. }
  4722. /* Allocate and set up VF Information. */
  4723. adap->vfinfo = kcalloc(pci_sriov_get_totalvfs(pdev),
  4724. sizeof(struct vf_info), GFP_KERNEL);
  4725. if (!adap->vfinfo) {
  4726. unregister_netdev(adap->port[0]);
  4727. free_netdev(adap->port[0]);
  4728. adap->port[0] = NULL;
  4729. return -ENOMEM;
  4730. }
  4731. cxgb4_mgmt_fill_vf_station_mac_addr(adap);
  4732. }
  4733. /* Instantiate the requested number of VFs. */
  4734. err = pci_enable_sriov(pdev, num_vfs);
  4735. if (err) {
  4736. pr_info("Unable to instantiate %d VFs\n", num_vfs);
  4737. if (!current_vfs) {
  4738. unregister_netdev(adap->port[0]);
  4739. free_netdev(adap->port[0]);
  4740. adap->port[0] = NULL;
  4741. kfree(adap->vfinfo);
  4742. adap->vfinfo = NULL;
  4743. }
  4744. return err;
  4745. }
  4746. adap->num_vfs = num_vfs;
  4747. return num_vfs;
  4748. }
  4749. #endif /* CONFIG_PCI_IOV */
  4750. static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4751. {
  4752. int func, i, err, s_qpp, qpp, num_seg;
  4753. struct port_info *pi;
  4754. bool highdma = false;
  4755. struct adapter *adapter = NULL;
  4756. struct net_device *netdev;
  4757. void __iomem *regs;
  4758. u32 whoami, pl_rev;
  4759. enum chip_type chip;
  4760. static int adap_idx = 1;
  4761. printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
  4762. err = pci_request_regions(pdev, KBUILD_MODNAME);
  4763. if (err) {
  4764. /* Just info, some other driver may have claimed the device. */
  4765. dev_info(&pdev->dev, "cannot obtain PCI resources\n");
  4766. return err;
  4767. }
  4768. err = pci_enable_device(pdev);
  4769. if (err) {
  4770. dev_err(&pdev->dev, "cannot enable PCI device\n");
  4771. goto out_release_regions;
  4772. }
  4773. regs = pci_ioremap_bar(pdev, 0);
  4774. if (!regs) {
  4775. dev_err(&pdev->dev, "cannot map device registers\n");
  4776. err = -ENOMEM;
  4777. goto out_disable_device;
  4778. }
  4779. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  4780. if (!adapter) {
  4781. err = -ENOMEM;
  4782. goto out_unmap_bar0;
  4783. }
  4784. adapter->regs = regs;
  4785. err = t4_wait_dev_ready(regs);
  4786. if (err < 0)
  4787. goto out_free_adapter;
  4788. /* We control everything through one PF */
  4789. whoami = readl(regs + PL_WHOAMI_A);
  4790. pl_rev = REV_G(readl(regs + PL_REV_A));
  4791. chip = get_chip_type(pdev, pl_rev);
  4792. func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
  4793. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4794. adapter->pdev = pdev;
  4795. adapter->pdev_dev = &pdev->dev;
  4796. adapter->name = pci_name(pdev);
  4797. adapter->mbox = func;
  4798. adapter->pf = func;
  4799. adapter->params.chip = chip;
  4800. adapter->adap_idx = adap_idx;
  4801. adapter->msg_enable = DFLT_MSG_ENABLE;
  4802. adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
  4803. (sizeof(struct mbox_cmd) *
  4804. T4_OS_LOG_MBOX_CMDS),
  4805. GFP_KERNEL);
  4806. if (!adapter->mbox_log) {
  4807. err = -ENOMEM;
  4808. goto out_free_adapter;
  4809. }
  4810. spin_lock_init(&adapter->mbox_lock);
  4811. INIT_LIST_HEAD(&adapter->mlist.list);
  4812. pci_set_drvdata(pdev, adapter);
  4813. if (func != ent->driver_data) {
  4814. pci_disable_device(pdev);
  4815. pci_save_state(pdev); /* to restore SR-IOV later */
  4816. return 0;
  4817. }
  4818. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  4819. highdma = true;
  4820. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  4821. if (err) {
  4822. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
  4823. "coherent allocations\n");
  4824. goto out_free_adapter;
  4825. }
  4826. } else {
  4827. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4828. if (err) {
  4829. dev_err(&pdev->dev, "no usable DMA configuration\n");
  4830. goto out_free_adapter;
  4831. }
  4832. }
  4833. pci_enable_pcie_error_reporting(pdev);
  4834. pci_set_master(pdev);
  4835. pci_save_state(pdev);
  4836. adap_idx++;
  4837. adapter->workq = create_singlethread_workqueue("cxgb4");
  4838. if (!adapter->workq) {
  4839. err = -ENOMEM;
  4840. goto out_free_adapter;
  4841. }
  4842. adapter->mbox_log->size = T4_OS_LOG_MBOX_CMDS;
  4843. /* PCI device has been enabled */
  4844. adapter->flags |= DEV_ENABLED;
  4845. memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
  4846. /* If possible, we use PCIe Relaxed Ordering Attribute to deliver
  4847. * Ingress Packet Data to Free List Buffers in order to allow for
  4848. * chipset performance optimizations between the Root Complex and
  4849. * Memory Controllers. (Messages to the associated Ingress Queue
  4850. * notifying new Packet Placement in the Free Lists Buffers will be
  4851. * send without the Relaxed Ordering Attribute thus guaranteeing that
  4852. * all preceding PCIe Transaction Layer Packets will be processed
  4853. * first.) But some Root Complexes have various issues with Upstream
  4854. * Transaction Layer Packets with the Relaxed Ordering Attribute set.
  4855. * The PCIe devices which under the Root Complexes will be cleared the
  4856. * Relaxed Ordering bit in the configuration space, So we check our
  4857. * PCIe configuration space to see if it's flagged with advice against
  4858. * using Relaxed Ordering.
  4859. */
  4860. if (!pcie_relaxed_ordering_enabled(pdev))
  4861. adapter->flags |= ROOT_NO_RELAXED_ORDERING;
  4862. spin_lock_init(&adapter->stats_lock);
  4863. spin_lock_init(&adapter->tid_release_lock);
  4864. spin_lock_init(&adapter->win0_lock);
  4865. INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
  4866. INIT_WORK(&adapter->db_full_task, process_db_full);
  4867. INIT_WORK(&adapter->db_drop_task, process_db_drop);
  4868. INIT_WORK(&adapter->fatal_err_notify_task, notify_fatal_err);
  4869. err = t4_prep_adapter(adapter);
  4870. if (err)
  4871. goto out_free_adapter;
  4872. if (!is_t4(adapter->params.chip)) {
  4873. s_qpp = (QUEUESPERPAGEPF0_S +
  4874. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
  4875. adapter->pf);
  4876. qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
  4877. SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
  4878. num_seg = PAGE_SIZE / SEGMENT_SIZE;
  4879. /* Each segment size is 128B. Write coalescing is enabled only
  4880. * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
  4881. * queue is less no of segments that can be accommodated in
  4882. * a page size.
  4883. */
  4884. if (qpp > num_seg) {
  4885. dev_err(&pdev->dev,
  4886. "Incorrect number of egress queues per page\n");
  4887. err = -EINVAL;
  4888. goto out_free_adapter;
  4889. }
  4890. adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
  4891. pci_resource_len(pdev, 2));
  4892. if (!adapter->bar2) {
  4893. dev_err(&pdev->dev, "cannot map device bar2 region\n");
  4894. err = -ENOMEM;
  4895. goto out_free_adapter;
  4896. }
  4897. }
  4898. setup_memwin(adapter);
  4899. err = adap_init0(adapter);
  4900. #ifdef CONFIG_DEBUG_FS
  4901. bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
  4902. #endif
  4903. setup_memwin_rdma(adapter);
  4904. if (err)
  4905. goto out_unmap_bar;
  4906. /* configure SGE_STAT_CFG_A to read WC stats */
  4907. if (!is_t4(adapter->params.chip))
  4908. t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7) |
  4909. (is_t5(adapter->params.chip) ? STATMODE_V(0) :
  4910. T6_STATMODE_V(0)));
  4911. for_each_port(adapter, i) {
  4912. netdev = alloc_etherdev_mq(sizeof(struct port_info),
  4913. MAX_ETH_QSETS);
  4914. if (!netdev) {
  4915. err = -ENOMEM;
  4916. goto out_free_dev;
  4917. }
  4918. SET_NETDEV_DEV(netdev, &pdev->dev);
  4919. adapter->port[i] = netdev;
  4920. pi = netdev_priv(netdev);
  4921. pi->adapter = adapter;
  4922. pi->xact_addr_filt = -1;
  4923. pi->port_id = i;
  4924. netdev->irq = pdev->irq;
  4925. netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
  4926. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  4927. NETIF_F_RXCSUM | NETIF_F_RXHASH |
  4928. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
  4929. NETIF_F_HW_TC;
  4930. if (CHELSIO_CHIP_VERSION(chip) > CHELSIO_T5)
  4931. netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
  4932. if (highdma)
  4933. netdev->hw_features |= NETIF_F_HIGHDMA;
  4934. netdev->features |= netdev->hw_features;
  4935. netdev->vlan_features = netdev->features & VLAN_FEAT;
  4936. netdev->priv_flags |= IFF_UNICAST_FLT;
  4937. /* MTU range: 81 - 9600 */
  4938. netdev->min_mtu = 81; /* accommodate SACK */
  4939. netdev->max_mtu = MAX_MTU;
  4940. netdev->netdev_ops = &cxgb4_netdev_ops;
  4941. #ifdef CONFIG_CHELSIO_T4_DCB
  4942. netdev->dcbnl_ops = &cxgb4_dcb_ops;
  4943. cxgb4_dcb_state_init(netdev);
  4944. #endif
  4945. cxgb4_set_ethtool_ops(netdev);
  4946. }
  4947. cxgb4_init_ethtool_dump(adapter);
  4948. pci_set_drvdata(pdev, adapter);
  4949. if (adapter->flags & FW_OK) {
  4950. err = t4_port_init(adapter, func, func, 0);
  4951. if (err)
  4952. goto out_free_dev;
  4953. } else if (adapter->params.nports == 1) {
  4954. /* If we don't have a connection to the firmware -- possibly
  4955. * because of an error -- grab the raw VPD parameters so we
  4956. * can set the proper MAC Address on the debug network
  4957. * interface that we've created.
  4958. */
  4959. u8 hw_addr[ETH_ALEN];
  4960. u8 *na = adapter->params.vpd.na;
  4961. err = t4_get_raw_vpd_params(adapter, &adapter->params.vpd);
  4962. if (!err) {
  4963. for (i = 0; i < ETH_ALEN; i++)
  4964. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  4965. hex2val(na[2 * i + 1]));
  4966. t4_set_hw_addr(adapter, 0, hw_addr);
  4967. }
  4968. }
  4969. /* Configure queues and allocate tables now, they can be needed as
  4970. * soon as the first register_netdev completes.
  4971. */
  4972. cfg_queues(adapter);
  4973. adapter->smt = t4_init_smt();
  4974. if (!adapter->smt) {
  4975. /* We tolerate a lack of SMT, giving up some functionality */
  4976. dev_warn(&pdev->dev, "could not allocate SMT, continuing\n");
  4977. }
  4978. adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end);
  4979. if (!adapter->l2t) {
  4980. /* We tolerate a lack of L2T, giving up some functionality */
  4981. dev_warn(&pdev->dev, "could not allocate L2T, continuing\n");
  4982. adapter->params.offload = 0;
  4983. }
  4984. #if IS_ENABLED(CONFIG_IPV6)
  4985. if ((CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) &&
  4986. (!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
  4987. /* CLIP functionality is not present in hardware,
  4988. * hence disable all offload features
  4989. */
  4990. dev_warn(&pdev->dev,
  4991. "CLIP not enabled in hardware, continuing\n");
  4992. adapter->params.offload = 0;
  4993. } else {
  4994. adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
  4995. adapter->clipt_end);
  4996. if (!adapter->clipt) {
  4997. /* We tolerate a lack of clip_table, giving up
  4998. * some functionality
  4999. */
  5000. dev_warn(&pdev->dev,
  5001. "could not allocate Clip table, continuing\n");
  5002. adapter->params.offload = 0;
  5003. }
  5004. }
  5005. #endif
  5006. for_each_port(adapter, i) {
  5007. pi = adap2pinfo(adapter, i);
  5008. pi->sched_tbl = t4_init_sched(adapter->params.nsched_cls);
  5009. if (!pi->sched_tbl)
  5010. dev_warn(&pdev->dev,
  5011. "could not activate scheduling on port %d\n",
  5012. i);
  5013. }
  5014. if (tid_init(&adapter->tids) < 0) {
  5015. dev_warn(&pdev->dev, "could not allocate TID table, "
  5016. "continuing\n");
  5017. adapter->params.offload = 0;
  5018. } else {
  5019. adapter->tc_u32 = cxgb4_init_tc_u32(adapter);
  5020. if (!adapter->tc_u32)
  5021. dev_warn(&pdev->dev,
  5022. "could not offload tc u32, continuing\n");
  5023. if (cxgb4_init_tc_flower(adapter))
  5024. dev_warn(&pdev->dev,
  5025. "could not offload tc flower, continuing\n");
  5026. }
  5027. if (is_offload(adapter) || is_hashfilter(adapter)) {
  5028. if (t4_read_reg(adapter, LE_DB_CONFIG_A) & HASHEN_F) {
  5029. u32 hash_base, hash_reg;
  5030. if (chip <= CHELSIO_T5) {
  5031. hash_reg = LE_DB_TID_HASHBASE_A;
  5032. hash_base = t4_read_reg(adapter, hash_reg);
  5033. adapter->tids.hash_base = hash_base / 4;
  5034. } else {
  5035. hash_reg = T6_LE_DB_HASH_TID_BASE_A;
  5036. hash_base = t4_read_reg(adapter, hash_reg);
  5037. adapter->tids.hash_base = hash_base;
  5038. }
  5039. }
  5040. }
  5041. /* See what interrupts we'll be using */
  5042. if (msi > 1 && enable_msix(adapter) == 0)
  5043. adapter->flags |= USING_MSIX;
  5044. else if (msi > 0 && pci_enable_msi(pdev) == 0) {
  5045. adapter->flags |= USING_MSI;
  5046. if (msi > 1)
  5047. free_msix_info(adapter);
  5048. }
  5049. /* check for PCI Express bandwidth capabiltites */
  5050. cxgb4_check_pcie_caps(adapter);
  5051. err = init_rss(adapter);
  5052. if (err)
  5053. goto out_free_dev;
  5054. err = setup_fw_sge_queues(adapter);
  5055. if (err) {
  5056. dev_err(adapter->pdev_dev,
  5057. "FW sge queue allocation failed, err %d", err);
  5058. goto out_free_dev;
  5059. }
  5060. /*
  5061. * The card is now ready to go. If any errors occur during device
  5062. * registration we do not fail the whole card but rather proceed only
  5063. * with the ports we manage to register successfully. However we must
  5064. * register at least one net device.
  5065. */
  5066. for_each_port(adapter, i) {
  5067. pi = adap2pinfo(adapter, i);
  5068. adapter->port[i]->dev_port = pi->lport;
  5069. netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
  5070. netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
  5071. netif_carrier_off(adapter->port[i]);
  5072. err = register_netdev(adapter->port[i]);
  5073. if (err)
  5074. break;
  5075. adapter->chan_map[pi->tx_chan] = i;
  5076. print_port_info(adapter->port[i]);
  5077. }
  5078. if (i == 0) {
  5079. dev_err(&pdev->dev, "could not register any net devices\n");
  5080. goto out_free_dev;
  5081. }
  5082. if (err) {
  5083. dev_warn(&pdev->dev, "only %d net devices registered\n", i);
  5084. err = 0;
  5085. }
  5086. if (cxgb4_debugfs_root) {
  5087. adapter->debugfs_root = debugfs_create_dir(pci_name(pdev),
  5088. cxgb4_debugfs_root);
  5089. setup_debugfs(adapter);
  5090. }
  5091. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  5092. pdev->needs_freset = 1;
  5093. if (is_uld(adapter)) {
  5094. mutex_lock(&uld_mutex);
  5095. list_add_tail(&adapter->list_node, &adapter_list);
  5096. mutex_unlock(&uld_mutex);
  5097. }
  5098. if (!is_t4(adapter->params.chip))
  5099. cxgb4_ptp_init(adapter);
  5100. print_adapter_info(adapter);
  5101. return 0;
  5102. out_free_dev:
  5103. t4_free_sge_resources(adapter);
  5104. free_some_resources(adapter);
  5105. if (adapter->flags & USING_MSIX)
  5106. free_msix_info(adapter);
  5107. if (adapter->num_uld || adapter->num_ofld_uld)
  5108. t4_uld_mem_free(adapter);
  5109. out_unmap_bar:
  5110. if (!is_t4(adapter->params.chip))
  5111. iounmap(adapter->bar2);
  5112. out_free_adapter:
  5113. if (adapter->workq)
  5114. destroy_workqueue(adapter->workq);
  5115. kfree(adapter->mbox_log);
  5116. kfree(adapter);
  5117. out_unmap_bar0:
  5118. iounmap(regs);
  5119. out_disable_device:
  5120. pci_disable_pcie_error_reporting(pdev);
  5121. pci_disable_device(pdev);
  5122. out_release_regions:
  5123. pci_release_regions(pdev);
  5124. return err;
  5125. }
  5126. static void remove_one(struct pci_dev *pdev)
  5127. {
  5128. struct adapter *adapter = pci_get_drvdata(pdev);
  5129. if (!adapter) {
  5130. pci_release_regions(pdev);
  5131. return;
  5132. }
  5133. adapter->flags |= SHUTTING_DOWN;
  5134. if (adapter->pf == 4) {
  5135. int i;
  5136. /* Tear down per-adapter Work Queue first since it can contain
  5137. * references to our adapter data structure.
  5138. */
  5139. destroy_workqueue(adapter->workq);
  5140. if (is_uld(adapter)) {
  5141. detach_ulds(adapter);
  5142. t4_uld_clean_up(adapter);
  5143. }
  5144. adap_free_hma_mem(adapter);
  5145. disable_interrupts(adapter);
  5146. for_each_port(adapter, i)
  5147. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  5148. unregister_netdev(adapter->port[i]);
  5149. debugfs_remove_recursive(adapter->debugfs_root);
  5150. if (!is_t4(adapter->params.chip))
  5151. cxgb4_ptp_stop(adapter);
  5152. /* If we allocated filters, free up state associated with any
  5153. * valid filters ...
  5154. */
  5155. clear_all_filters(adapter);
  5156. if (adapter->flags & FULL_INIT_DONE)
  5157. cxgb_down(adapter);
  5158. if (adapter->flags & USING_MSIX)
  5159. free_msix_info(adapter);
  5160. if (adapter->num_uld || adapter->num_ofld_uld)
  5161. t4_uld_mem_free(adapter);
  5162. free_some_resources(adapter);
  5163. #if IS_ENABLED(CONFIG_IPV6)
  5164. t4_cleanup_clip_tbl(adapter);
  5165. #endif
  5166. if (!is_t4(adapter->params.chip))
  5167. iounmap(adapter->bar2);
  5168. }
  5169. #ifdef CONFIG_PCI_IOV
  5170. else {
  5171. cxgb4_iov_configure(adapter->pdev, 0);
  5172. }
  5173. #endif
  5174. iounmap(adapter->regs);
  5175. pci_disable_pcie_error_reporting(pdev);
  5176. if ((adapter->flags & DEV_ENABLED)) {
  5177. pci_disable_device(pdev);
  5178. adapter->flags &= ~DEV_ENABLED;
  5179. }
  5180. pci_release_regions(pdev);
  5181. kfree(adapter->mbox_log);
  5182. synchronize_rcu();
  5183. kfree(adapter);
  5184. }
  5185. /* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
  5186. * delivery. This is essentially a stripped down version of the PCI remove()
  5187. * function where we do the minimal amount of work necessary to shutdown any
  5188. * further activity.
  5189. */
  5190. static void shutdown_one(struct pci_dev *pdev)
  5191. {
  5192. struct adapter *adapter = pci_get_drvdata(pdev);
  5193. /* As with remove_one() above (see extended comment), we only want do
  5194. * do cleanup on PCI Devices which went all the way through init_one()
  5195. * ...
  5196. */
  5197. if (!adapter) {
  5198. pci_release_regions(pdev);
  5199. return;
  5200. }
  5201. adapter->flags |= SHUTTING_DOWN;
  5202. if (adapter->pf == 4) {
  5203. int i;
  5204. for_each_port(adapter, i)
  5205. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  5206. cxgb_close(adapter->port[i]);
  5207. if (is_uld(adapter)) {
  5208. detach_ulds(adapter);
  5209. t4_uld_clean_up(adapter);
  5210. }
  5211. disable_interrupts(adapter);
  5212. disable_msi(adapter);
  5213. t4_sge_stop(adapter);
  5214. if (adapter->flags & FW_OK)
  5215. t4_fw_bye(adapter, adapter->mbox);
  5216. }
  5217. }
  5218. static struct pci_driver cxgb4_driver = {
  5219. .name = KBUILD_MODNAME,
  5220. .id_table = cxgb4_pci_tbl,
  5221. .probe = init_one,
  5222. .remove = remove_one,
  5223. .shutdown = shutdown_one,
  5224. #ifdef CONFIG_PCI_IOV
  5225. .sriov_configure = cxgb4_iov_configure,
  5226. #endif
  5227. .err_handler = &cxgb4_eeh,
  5228. };
  5229. static int __init cxgb4_init_module(void)
  5230. {
  5231. int ret;
  5232. /* Debugfs support is optional, just warn if this fails */
  5233. cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  5234. if (!cxgb4_debugfs_root)
  5235. pr_warn("could not create debugfs entry, continuing\n");
  5236. ret = pci_register_driver(&cxgb4_driver);
  5237. if (ret < 0)
  5238. debugfs_remove(cxgb4_debugfs_root);
  5239. #if IS_ENABLED(CONFIG_IPV6)
  5240. if (!inet6addr_registered) {
  5241. register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5242. inet6addr_registered = true;
  5243. }
  5244. #endif
  5245. return ret;
  5246. }
  5247. static void __exit cxgb4_cleanup_module(void)
  5248. {
  5249. #if IS_ENABLED(CONFIG_IPV6)
  5250. if (inet6addr_registered) {
  5251. unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5252. inet6addr_registered = false;
  5253. }
  5254. #endif
  5255. pci_unregister_driver(&cxgb4_driver);
  5256. debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
  5257. }
  5258. module_init(cxgb4_init_module);
  5259. module_exit(cxgb4_cleanup_module);