cxgb4_main.c 167 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 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 <asm/uaccess.h>
  65. #include "cxgb4.h"
  66. #include "t4_regs.h"
  67. #include "t4_values.h"
  68. #include "t4_msg.h"
  69. #include "t4fw_api.h"
  70. #include "t4fw_version.h"
  71. #include "cxgb4_dcb.h"
  72. #include "cxgb4_debugfs.h"
  73. #include "clip_tbl.h"
  74. #include "l2t.h"
  75. #ifdef DRV_VERSION
  76. #undef DRV_VERSION
  77. #endif
  78. #define DRV_VERSION "2.0.0-ko"
  79. #define DRV_DESC "Chelsio T4/T5 Network Driver"
  80. enum {
  81. MAX_TXQ_ENTRIES = 16384,
  82. MAX_CTRL_TXQ_ENTRIES = 1024,
  83. MAX_RSPQ_ENTRIES = 16384,
  84. MAX_RX_BUFFERS = 16384,
  85. MIN_TXQ_ENTRIES = 32,
  86. MIN_CTRL_TXQ_ENTRIES = 32,
  87. MIN_RSPQ_ENTRIES = 128,
  88. MIN_FL_ENTRIES = 16
  89. };
  90. /* Host shadow copy of ingress filter entry. This is in host native format
  91. * and doesn't match the ordering or bit order, etc. of the hardware of the
  92. * firmware command. The use of bit-field structure elements is purely to
  93. * remind ourselves of the field size limitations and save memory in the case
  94. * where the filter table is large.
  95. */
  96. struct filter_entry {
  97. /* Administrative fields for filter.
  98. */
  99. u32 valid:1; /* filter allocated and valid */
  100. u32 locked:1; /* filter is administratively locked */
  101. u32 pending:1; /* filter action is pending firmware reply */
  102. u32 smtidx:8; /* Source MAC Table index for smac */
  103. struct l2t_entry *l2t; /* Layer Two Table entry for dmac */
  104. /* The filter itself. Most of this is a straight copy of information
  105. * provided by the extended ioctl(). Some fields are translated to
  106. * internal forms -- for instance the Ingress Queue ID passed in from
  107. * the ioctl() is translated into the Absolute Ingress Queue ID.
  108. */
  109. struct ch_filter_specification fs;
  110. };
  111. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  112. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  113. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  114. /* Macros needed to support the PCI Device ID Table ...
  115. */
  116. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
  117. static const struct pci_device_id cxgb4_pci_tbl[] = {
  118. #define CH_PCI_DEVICE_ID_FUNCTION 0x4
  119. /* Include PCI Device IDs for both PF4 and PF0-3 so our PCI probe() routine is
  120. * called for both.
  121. */
  122. #define CH_PCI_DEVICE_ID_FUNCTION2 0x0
  123. #define CH_PCI_ID_TABLE_ENTRY(devid) \
  124. {PCI_VDEVICE(CHELSIO, (devid)), 4}
  125. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
  126. { 0, } \
  127. }
  128. #include "t4_pci_id_tbl.h"
  129. #define FW4_FNAME "cxgb4/t4fw.bin"
  130. #define FW5_FNAME "cxgb4/t5fw.bin"
  131. #define FW4_CFNAME "cxgb4/t4-config.txt"
  132. #define FW5_CFNAME "cxgb4/t5-config.txt"
  133. MODULE_DESCRIPTION(DRV_DESC);
  134. MODULE_AUTHOR("Chelsio Communications");
  135. MODULE_LICENSE("Dual BSD/GPL");
  136. MODULE_VERSION(DRV_VERSION);
  137. MODULE_DEVICE_TABLE(pci, cxgb4_pci_tbl);
  138. MODULE_FIRMWARE(FW4_FNAME);
  139. MODULE_FIRMWARE(FW5_FNAME);
  140. /*
  141. * Normally we're willing to become the firmware's Master PF but will be happy
  142. * if another PF has already become the Master and initialized the adapter.
  143. * Setting "force_init" will cause this driver to forcibly establish itself as
  144. * the Master PF and initialize the adapter.
  145. */
  146. static uint force_init;
  147. module_param(force_init, uint, 0644);
  148. MODULE_PARM_DESC(force_init, "Forcibly become Master PF and initialize adapter");
  149. /*
  150. * Normally if the firmware we connect to has Configuration File support, we
  151. * use that and only fall back to the old Driver-based initialization if the
  152. * Configuration File fails for some reason. If force_old_init is set, then
  153. * we'll always use the old Driver-based initialization sequence.
  154. */
  155. static uint force_old_init;
  156. module_param(force_old_init, uint, 0644);
  157. MODULE_PARM_DESC(force_old_init, "Force old initialization sequence, deprecated"
  158. " parameter");
  159. static int dflt_msg_enable = DFLT_MSG_ENABLE;
  160. module_param(dflt_msg_enable, int, 0644);
  161. MODULE_PARM_DESC(dflt_msg_enable, "Chelsio T4 default message enable bitmap");
  162. /*
  163. * The driver uses the best interrupt scheme available on a platform in the
  164. * order MSI-X, MSI, legacy INTx interrupts. This parameter determines which
  165. * of these schemes the driver may consider as follows:
  166. *
  167. * msi = 2: choose from among all three options
  168. * msi = 1: only consider MSI and INTx interrupts
  169. * msi = 0: force INTx interrupts
  170. */
  171. static int msi = 2;
  172. module_param(msi, int, 0644);
  173. MODULE_PARM_DESC(msi, "whether to use INTx (0), MSI (1) or MSI-X (2)");
  174. /*
  175. * Queue interrupt hold-off timer values. Queues default to the first of these
  176. * upon creation.
  177. */
  178. static unsigned int intr_holdoff[SGE_NTIMERS - 1] = { 5, 10, 20, 50, 100 };
  179. module_param_array(intr_holdoff, uint, NULL, 0644);
  180. MODULE_PARM_DESC(intr_holdoff, "values for queue interrupt hold-off timers "
  181. "0..4 in microseconds, deprecated parameter");
  182. static unsigned int intr_cnt[SGE_NCOUNTERS - 1] = { 4, 8, 16 };
  183. module_param_array(intr_cnt, uint, NULL, 0644);
  184. MODULE_PARM_DESC(intr_cnt,
  185. "thresholds 1..3 for queue interrupt packet counters, "
  186. "deprecated parameter");
  187. /*
  188. * Normally we tell the chip to deliver Ingress Packets into our DMA buffers
  189. * offset by 2 bytes in order to have the IP headers line up on 4-byte
  190. * boundaries. This is a requirement for many architectures which will throw
  191. * a machine check fault if an attempt is made to access one of the 4-byte IP
  192. * header fields on a non-4-byte boundary. And it's a major performance issue
  193. * even on some architectures which allow it like some implementations of the
  194. * x86 ISA. However, some architectures don't mind this and for some very
  195. * edge-case performance sensitive applications (like forwarding large volumes
  196. * of small packets), setting this DMA offset to 0 will decrease the number of
  197. * PCI-E Bus transfers enough to measurably affect performance.
  198. */
  199. static int rx_dma_offset = 2;
  200. static bool vf_acls;
  201. #ifdef CONFIG_PCI_IOV
  202. module_param(vf_acls, bool, 0644);
  203. MODULE_PARM_DESC(vf_acls, "if set enable virtualization L2 ACL enforcement, "
  204. "deprecated parameter");
  205. /* Configure the number of PCI-E Virtual Function which are to be instantiated
  206. * on SR-IOV Capable Physical Functions.
  207. */
  208. static unsigned int num_vf[NUM_OF_PF_WITH_SRIOV];
  209. module_param_array(num_vf, uint, NULL, 0644);
  210. MODULE_PARM_DESC(num_vf, "number of VFs for each of PFs 0-3");
  211. #endif
  212. /* TX Queue select used to determine what algorithm to use for selecting TX
  213. * queue. Select between the kernel provided function (select_queue=0) or user
  214. * cxgb_select_queue function (select_queue=1)
  215. *
  216. * Default: select_queue=0
  217. */
  218. static int select_queue;
  219. module_param(select_queue, int, 0644);
  220. MODULE_PARM_DESC(select_queue,
  221. "Select between kernel provided method of selecting or driver method of selecting TX queue. Default is kernel method.");
  222. static unsigned int tp_vlan_pri_map = HW_TPL_FR_MT_PR_IV_P_FC;
  223. module_param(tp_vlan_pri_map, uint, 0644);
  224. MODULE_PARM_DESC(tp_vlan_pri_map, "global compressed filter configuration, "
  225. "deprecated parameter");
  226. static struct dentry *cxgb4_debugfs_root;
  227. static LIST_HEAD(adapter_list);
  228. static DEFINE_MUTEX(uld_mutex);
  229. /* Adapter list to be accessed from atomic context */
  230. static LIST_HEAD(adap_rcu_list);
  231. static DEFINE_SPINLOCK(adap_rcu_lock);
  232. static struct cxgb4_uld_info ulds[CXGB4_ULD_MAX];
  233. static const char *uld_str[] = { "RDMA", "iSCSI" };
  234. static void link_report(struct net_device *dev)
  235. {
  236. if (!netif_carrier_ok(dev))
  237. netdev_info(dev, "link down\n");
  238. else {
  239. static const char *fc[] = { "no", "Rx", "Tx", "Tx/Rx" };
  240. const char *s = "10Mbps";
  241. const struct port_info *p = netdev_priv(dev);
  242. switch (p->link_cfg.speed) {
  243. case 10000:
  244. s = "10Gbps";
  245. break;
  246. case 1000:
  247. s = "1000Mbps";
  248. break;
  249. case 100:
  250. s = "100Mbps";
  251. break;
  252. case 40000:
  253. s = "40Gbps";
  254. break;
  255. }
  256. netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s,
  257. fc[p->link_cfg.fc]);
  258. }
  259. }
  260. #ifdef CONFIG_CHELSIO_T4_DCB
  261. /* Set up/tear down Data Center Bridging Priority mapping for a net device. */
  262. static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
  263. {
  264. struct port_info *pi = netdev_priv(dev);
  265. struct adapter *adap = pi->adapter;
  266. struct sge_eth_txq *txq = &adap->sge.ethtxq[pi->first_qset];
  267. int i;
  268. /* We use a simple mapping of Port TX Queue Index to DCB
  269. * Priority when we're enabling DCB.
  270. */
  271. for (i = 0; i < pi->nqsets; i++, txq++) {
  272. u32 name, value;
  273. int err;
  274. name = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  275. FW_PARAMS_PARAM_X_V(
  276. FW_PARAMS_PARAM_DMAQ_EQ_DCBPRIO_ETH) |
  277. FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
  278. value = enable ? i : 0xffffffff;
  279. /* Since we can be called while atomic (from "interrupt
  280. * level") we need to issue the Set Parameters Commannd
  281. * without sleeping (timeout < 0).
  282. */
  283. err = t4_set_params_nosleep(adap, adap->mbox, adap->fn, 0, 1,
  284. &name, &value);
  285. if (err)
  286. dev_err(adap->pdev_dev,
  287. "Can't %s DCB Priority on port %d, TX Queue %d: err=%d\n",
  288. enable ? "set" : "unset", pi->port_id, i, -err);
  289. else
  290. txq->dcb_prio = value;
  291. }
  292. }
  293. #endif /* CONFIG_CHELSIO_T4_DCB */
  294. void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
  295. {
  296. struct net_device *dev = adapter->port[port_id];
  297. /* Skip changes from disabled ports. */
  298. if (netif_running(dev) && link_stat != netif_carrier_ok(dev)) {
  299. if (link_stat)
  300. netif_carrier_on(dev);
  301. else {
  302. #ifdef CONFIG_CHELSIO_T4_DCB
  303. cxgb4_dcb_state_init(dev);
  304. dcb_tx_queue_prio_enable(dev, false);
  305. #endif /* CONFIG_CHELSIO_T4_DCB */
  306. netif_carrier_off(dev);
  307. }
  308. link_report(dev);
  309. }
  310. }
  311. void t4_os_portmod_changed(const struct adapter *adap, int port_id)
  312. {
  313. static const char *mod_str[] = {
  314. NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
  315. };
  316. const struct net_device *dev = adap->port[port_id];
  317. const struct port_info *pi = netdev_priv(dev);
  318. if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
  319. netdev_info(dev, "port module unplugged\n");
  320. else if (pi->mod_type < ARRAY_SIZE(mod_str))
  321. netdev_info(dev, "%s module inserted\n", mod_str[pi->mod_type]);
  322. }
  323. /*
  324. * Configure the exact and hash address filters to handle a port's multicast
  325. * and secondary unicast MAC addresses.
  326. */
  327. static int set_addr_filters(const struct net_device *dev, bool sleep)
  328. {
  329. u64 mhash = 0;
  330. u64 uhash = 0;
  331. bool free = true;
  332. u16 filt_idx[7];
  333. const u8 *addr[7];
  334. int ret, naddr = 0;
  335. const struct netdev_hw_addr *ha;
  336. int uc_cnt = netdev_uc_count(dev);
  337. int mc_cnt = netdev_mc_count(dev);
  338. const struct port_info *pi = netdev_priv(dev);
  339. unsigned int mb = pi->adapter->fn;
  340. /* first do the secondary unicast addresses */
  341. netdev_for_each_uc_addr(ha, dev) {
  342. addr[naddr++] = ha->addr;
  343. if (--uc_cnt == 0 || naddr >= ARRAY_SIZE(addr)) {
  344. ret = t4_alloc_mac_filt(pi->adapter, mb, pi->viid, free,
  345. naddr, addr, filt_idx, &uhash, sleep);
  346. if (ret < 0)
  347. return ret;
  348. free = false;
  349. naddr = 0;
  350. }
  351. }
  352. /* next set up the multicast addresses */
  353. netdev_for_each_mc_addr(ha, dev) {
  354. addr[naddr++] = ha->addr;
  355. if (--mc_cnt == 0 || naddr >= ARRAY_SIZE(addr)) {
  356. ret = t4_alloc_mac_filt(pi->adapter, mb, pi->viid, free,
  357. naddr, addr, filt_idx, &mhash, sleep);
  358. if (ret < 0)
  359. return ret;
  360. free = false;
  361. naddr = 0;
  362. }
  363. }
  364. return t4_set_addr_hash(pi->adapter, mb, pi->viid, uhash != 0,
  365. uhash | mhash, sleep);
  366. }
  367. int dbfifo_int_thresh = 10; /* 10 == 640 entry threshold */
  368. module_param(dbfifo_int_thresh, int, 0644);
  369. MODULE_PARM_DESC(dbfifo_int_thresh, "doorbell fifo interrupt threshold");
  370. /*
  371. * usecs to sleep while draining the dbfifo
  372. */
  373. static int dbfifo_drain_delay = 1000;
  374. module_param(dbfifo_drain_delay, int, 0644);
  375. MODULE_PARM_DESC(dbfifo_drain_delay,
  376. "usecs to sleep while draining the dbfifo");
  377. /*
  378. * Set Rx properties of a port, such as promiscruity, address filters, and MTU.
  379. * If @mtu is -1 it is left unchanged.
  380. */
  381. static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
  382. {
  383. int ret;
  384. struct port_info *pi = netdev_priv(dev);
  385. ret = set_addr_filters(dev, sleep_ok);
  386. if (ret == 0)
  387. ret = t4_set_rxmode(pi->adapter, pi->adapter->fn, pi->viid, mtu,
  388. (dev->flags & IFF_PROMISC) ? 1 : 0,
  389. (dev->flags & IFF_ALLMULTI) ? 1 : 0, 1, -1,
  390. sleep_ok);
  391. return ret;
  392. }
  393. /**
  394. * link_start - enable a port
  395. * @dev: the port to enable
  396. *
  397. * Performs the MAC and PHY actions needed to enable a port.
  398. */
  399. static int link_start(struct net_device *dev)
  400. {
  401. int ret;
  402. struct port_info *pi = netdev_priv(dev);
  403. unsigned int mb = pi->adapter->fn;
  404. /*
  405. * We do not set address filters and promiscuity here, the stack does
  406. * that step explicitly.
  407. */
  408. ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
  409. !!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
  410. if (ret == 0) {
  411. ret = t4_change_mac(pi->adapter, mb, pi->viid,
  412. pi->xact_addr_filt, dev->dev_addr, true,
  413. true);
  414. if (ret >= 0) {
  415. pi->xact_addr_filt = ret;
  416. ret = 0;
  417. }
  418. }
  419. if (ret == 0)
  420. ret = t4_link_start(pi->adapter, mb, pi->tx_chan,
  421. &pi->link_cfg);
  422. if (ret == 0) {
  423. local_bh_disable();
  424. ret = t4_enable_vi_params(pi->adapter, mb, pi->viid, true,
  425. true, CXGB4_DCB_ENABLED);
  426. local_bh_enable();
  427. }
  428. return ret;
  429. }
  430. int cxgb4_dcb_enabled(const struct net_device *dev)
  431. {
  432. #ifdef CONFIG_CHELSIO_T4_DCB
  433. struct port_info *pi = netdev_priv(dev);
  434. if (!pi->dcb.enabled)
  435. return 0;
  436. return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
  437. (pi->dcb.state == CXGB4_DCB_STATE_HOST));
  438. #else
  439. return 0;
  440. #endif
  441. }
  442. EXPORT_SYMBOL(cxgb4_dcb_enabled);
  443. #ifdef CONFIG_CHELSIO_T4_DCB
  444. /* Handle a Data Center Bridging update message from the firmware. */
  445. static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
  446. {
  447. int port = FW_PORT_CMD_PORTID_G(ntohl(pcmd->op_to_portid));
  448. struct net_device *dev = adap->port[port];
  449. int old_dcb_enabled = cxgb4_dcb_enabled(dev);
  450. int new_dcb_enabled;
  451. cxgb4_dcb_handle_fw_update(adap, pcmd);
  452. new_dcb_enabled = cxgb4_dcb_enabled(dev);
  453. /* If the DCB has become enabled or disabled on the port then we're
  454. * going to need to set up/tear down DCB Priority parameters for the
  455. * TX Queues associated with the port.
  456. */
  457. if (new_dcb_enabled != old_dcb_enabled)
  458. dcb_tx_queue_prio_enable(dev, new_dcb_enabled);
  459. }
  460. #endif /* CONFIG_CHELSIO_T4_DCB */
  461. /* Clear a filter and release any of its resources that we own. This also
  462. * clears the filter's "pending" status.
  463. */
  464. static void clear_filter(struct adapter *adap, struct filter_entry *f)
  465. {
  466. /* If the new or old filter have loopback rewriteing rules then we'll
  467. * need to free any existing Layer Two Table (L2T) entries of the old
  468. * filter rule. The firmware will handle freeing up any Source MAC
  469. * Table (SMT) entries used for rewriting Source MAC Addresses in
  470. * loopback rules.
  471. */
  472. if (f->l2t)
  473. cxgb4_l2t_release(f->l2t);
  474. /* The zeroing of the filter rule below clears the filter valid,
  475. * pending, locked flags, l2t pointer, etc. so it's all we need for
  476. * this operation.
  477. */
  478. memset(f, 0, sizeof(*f));
  479. }
  480. /* Handle a filter write/deletion reply.
  481. */
  482. static void filter_rpl(struct adapter *adap, const struct cpl_set_tcb_rpl *rpl)
  483. {
  484. unsigned int idx = GET_TID(rpl);
  485. unsigned int nidx = idx - adap->tids.ftid_base;
  486. unsigned int ret;
  487. struct filter_entry *f;
  488. if (idx >= adap->tids.ftid_base && nidx <
  489. (adap->tids.nftids + adap->tids.nsftids)) {
  490. idx = nidx;
  491. ret = TCB_COOKIE_G(rpl->cookie);
  492. f = &adap->tids.ftid_tab[idx];
  493. if (ret == FW_FILTER_WR_FLT_DELETED) {
  494. /* Clear the filter when we get confirmation from the
  495. * hardware that the filter has been deleted.
  496. */
  497. clear_filter(adap, f);
  498. } else if (ret == FW_FILTER_WR_SMT_TBL_FULL) {
  499. dev_err(adap->pdev_dev, "filter %u setup failed due to full SMT\n",
  500. idx);
  501. clear_filter(adap, f);
  502. } else if (ret == FW_FILTER_WR_FLT_ADDED) {
  503. f->smtidx = (be64_to_cpu(rpl->oldval) >> 24) & 0xff;
  504. f->pending = 0; /* asynchronous setup completed */
  505. f->valid = 1;
  506. } else {
  507. /* Something went wrong. Issue a warning about the
  508. * problem and clear everything out.
  509. */
  510. dev_err(adap->pdev_dev, "filter %u setup failed with error %u\n",
  511. idx, ret);
  512. clear_filter(adap, f);
  513. }
  514. }
  515. }
  516. /* Response queue handler for the FW event queue.
  517. */
  518. static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
  519. const struct pkt_gl *gl)
  520. {
  521. u8 opcode = ((const struct rss_header *)rsp)->opcode;
  522. rsp++; /* skip RSS header */
  523. /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
  524. */
  525. if (unlikely(opcode == CPL_FW4_MSG &&
  526. ((const struct cpl_fw4_msg *)rsp)->type == FW_TYPE_RSSCPL)) {
  527. rsp++;
  528. opcode = ((const struct rss_header *)rsp)->opcode;
  529. rsp++;
  530. if (opcode != CPL_SGE_EGR_UPDATE) {
  531. dev_err(q->adap->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
  532. , opcode);
  533. goto out;
  534. }
  535. }
  536. if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
  537. const struct cpl_sge_egr_update *p = (void *)rsp;
  538. unsigned int qid = EGR_QID_G(ntohl(p->opcode_qid));
  539. struct sge_txq *txq;
  540. txq = q->adap->sge.egr_map[qid - q->adap->sge.egr_start];
  541. txq->restarts++;
  542. if ((u8 *)txq < (u8 *)q->adap->sge.ofldtxq) {
  543. struct sge_eth_txq *eq;
  544. eq = container_of(txq, struct sge_eth_txq, q);
  545. netif_tx_wake_queue(eq->txq);
  546. } else {
  547. struct sge_ofld_txq *oq;
  548. oq = container_of(txq, struct sge_ofld_txq, q);
  549. tasklet_schedule(&oq->qresume_tsk);
  550. }
  551. } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
  552. const struct cpl_fw6_msg *p = (void *)rsp;
  553. #ifdef CONFIG_CHELSIO_T4_DCB
  554. const struct fw_port_cmd *pcmd = (const void *)p->data;
  555. unsigned int cmd = FW_CMD_OP_G(ntohl(pcmd->op_to_portid));
  556. unsigned int action =
  557. FW_PORT_CMD_ACTION_G(ntohl(pcmd->action_to_len16));
  558. if (cmd == FW_PORT_CMD &&
  559. action == FW_PORT_ACTION_GET_PORT_INFO) {
  560. int port = FW_PORT_CMD_PORTID_G(
  561. be32_to_cpu(pcmd->op_to_portid));
  562. struct net_device *dev = q->adap->port[port];
  563. int state_input = ((pcmd->u.info.dcbxdis_pkd &
  564. FW_PORT_CMD_DCBXDIS_F)
  565. ? CXGB4_DCB_INPUT_FW_DISABLED
  566. : CXGB4_DCB_INPUT_FW_ENABLED);
  567. cxgb4_dcb_state_fsm(dev, state_input);
  568. }
  569. if (cmd == FW_PORT_CMD &&
  570. action == FW_PORT_ACTION_L2_DCB_CFG)
  571. dcb_rpl(q->adap, pcmd);
  572. else
  573. #endif
  574. if (p->type == 0)
  575. t4_handle_fw_rpl(q->adap, p->data);
  576. } else if (opcode == CPL_L2T_WRITE_RPL) {
  577. const struct cpl_l2t_write_rpl *p = (void *)rsp;
  578. do_l2t_write_rpl(q->adap, p);
  579. } else if (opcode == CPL_SET_TCB_RPL) {
  580. const struct cpl_set_tcb_rpl *p = (void *)rsp;
  581. filter_rpl(q->adap, p);
  582. } else
  583. dev_err(q->adap->pdev_dev,
  584. "unexpected CPL %#x on FW event queue\n", opcode);
  585. out:
  586. return 0;
  587. }
  588. /**
  589. * uldrx_handler - response queue handler for ULD queues
  590. * @q: the response queue that received the packet
  591. * @rsp: the response queue descriptor holding the offload message
  592. * @gl: the gather list of packet fragments
  593. *
  594. * Deliver an ingress offload packet to a ULD. All processing is done by
  595. * the ULD, we just maintain statistics.
  596. */
  597. static int uldrx_handler(struct sge_rspq *q, const __be64 *rsp,
  598. const struct pkt_gl *gl)
  599. {
  600. struct sge_ofld_rxq *rxq = container_of(q, struct sge_ofld_rxq, rspq);
  601. /* FW can send CPLs encapsulated in a CPL_FW4_MSG.
  602. */
  603. if (((const struct rss_header *)rsp)->opcode == CPL_FW4_MSG &&
  604. ((const struct cpl_fw4_msg *)(rsp + 1))->type == FW_TYPE_RSSCPL)
  605. rsp += 2;
  606. if (ulds[q->uld].rx_handler(q->adap->uld_handle[q->uld], rsp, gl)) {
  607. rxq->stats.nomem++;
  608. return -1;
  609. }
  610. if (gl == NULL)
  611. rxq->stats.imm++;
  612. else if (gl == CXGB4_MSG_AN)
  613. rxq->stats.an++;
  614. else
  615. rxq->stats.pkts++;
  616. return 0;
  617. }
  618. static void disable_msi(struct adapter *adapter)
  619. {
  620. if (adapter->flags & USING_MSIX) {
  621. pci_disable_msix(adapter->pdev);
  622. adapter->flags &= ~USING_MSIX;
  623. } else if (adapter->flags & USING_MSI) {
  624. pci_disable_msi(adapter->pdev);
  625. adapter->flags &= ~USING_MSI;
  626. }
  627. }
  628. /*
  629. * Interrupt handler for non-data events used with MSI-X.
  630. */
  631. static irqreturn_t t4_nondata_intr(int irq, void *cookie)
  632. {
  633. struct adapter *adap = cookie;
  634. u32 v = t4_read_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A));
  635. if (v & PFSW_F) {
  636. adap->swintr = 1;
  637. t4_write_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A), v);
  638. }
  639. t4_slow_intr_handler(adap);
  640. return IRQ_HANDLED;
  641. }
  642. /*
  643. * Name the MSI-X interrupts.
  644. */
  645. static void name_msix_vecs(struct adapter *adap)
  646. {
  647. int i, j, msi_idx = 2, n = sizeof(adap->msix_info[0].desc);
  648. /* non-data interrupts */
  649. snprintf(adap->msix_info[0].desc, n, "%s", adap->port[0]->name);
  650. /* FW events */
  651. snprintf(adap->msix_info[1].desc, n, "%s-FWeventq",
  652. adap->port[0]->name);
  653. /* Ethernet queues */
  654. for_each_port(adap, j) {
  655. struct net_device *d = adap->port[j];
  656. const struct port_info *pi = netdev_priv(d);
  657. for (i = 0; i < pi->nqsets; i++, msi_idx++)
  658. snprintf(adap->msix_info[msi_idx].desc, n, "%s-Rx%d",
  659. d->name, i);
  660. }
  661. /* offload queues */
  662. for_each_ofldrxq(&adap->sge, i)
  663. snprintf(adap->msix_info[msi_idx++].desc, n, "%s-ofld%d",
  664. adap->port[0]->name, i);
  665. for_each_rdmarxq(&adap->sge, i)
  666. snprintf(adap->msix_info[msi_idx++].desc, n, "%s-rdma%d",
  667. adap->port[0]->name, i);
  668. for_each_rdmaciq(&adap->sge, i)
  669. snprintf(adap->msix_info[msi_idx++].desc, n, "%s-rdma-ciq%d",
  670. adap->port[0]->name, i);
  671. }
  672. static int request_msix_queue_irqs(struct adapter *adap)
  673. {
  674. struct sge *s = &adap->sge;
  675. int err, ethqidx, ofldqidx = 0, rdmaqidx = 0, rdmaciqqidx = 0;
  676. int msi_index = 2;
  677. err = request_irq(adap->msix_info[1].vec, t4_sge_intr_msix, 0,
  678. adap->msix_info[1].desc, &s->fw_evtq);
  679. if (err)
  680. return err;
  681. for_each_ethrxq(s, ethqidx) {
  682. err = request_irq(adap->msix_info[msi_index].vec,
  683. t4_sge_intr_msix, 0,
  684. adap->msix_info[msi_index].desc,
  685. &s->ethrxq[ethqidx].rspq);
  686. if (err)
  687. goto unwind;
  688. msi_index++;
  689. }
  690. for_each_ofldrxq(s, ofldqidx) {
  691. err = request_irq(adap->msix_info[msi_index].vec,
  692. t4_sge_intr_msix, 0,
  693. adap->msix_info[msi_index].desc,
  694. &s->ofldrxq[ofldqidx].rspq);
  695. if (err)
  696. goto unwind;
  697. msi_index++;
  698. }
  699. for_each_rdmarxq(s, rdmaqidx) {
  700. err = request_irq(adap->msix_info[msi_index].vec,
  701. t4_sge_intr_msix, 0,
  702. adap->msix_info[msi_index].desc,
  703. &s->rdmarxq[rdmaqidx].rspq);
  704. if (err)
  705. goto unwind;
  706. msi_index++;
  707. }
  708. for_each_rdmaciq(s, rdmaciqqidx) {
  709. err = request_irq(adap->msix_info[msi_index].vec,
  710. t4_sge_intr_msix, 0,
  711. adap->msix_info[msi_index].desc,
  712. &s->rdmaciq[rdmaciqqidx].rspq);
  713. if (err)
  714. goto unwind;
  715. msi_index++;
  716. }
  717. return 0;
  718. unwind:
  719. while (--rdmaciqqidx >= 0)
  720. free_irq(adap->msix_info[--msi_index].vec,
  721. &s->rdmaciq[rdmaciqqidx].rspq);
  722. while (--rdmaqidx >= 0)
  723. free_irq(adap->msix_info[--msi_index].vec,
  724. &s->rdmarxq[rdmaqidx].rspq);
  725. while (--ofldqidx >= 0)
  726. free_irq(adap->msix_info[--msi_index].vec,
  727. &s->ofldrxq[ofldqidx].rspq);
  728. while (--ethqidx >= 0)
  729. free_irq(adap->msix_info[--msi_index].vec,
  730. &s->ethrxq[ethqidx].rspq);
  731. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  732. return err;
  733. }
  734. static void free_msix_queue_irqs(struct adapter *adap)
  735. {
  736. int i, msi_index = 2;
  737. struct sge *s = &adap->sge;
  738. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  739. for_each_ethrxq(s, i)
  740. free_irq(adap->msix_info[msi_index++].vec, &s->ethrxq[i].rspq);
  741. for_each_ofldrxq(s, i)
  742. free_irq(adap->msix_info[msi_index++].vec, &s->ofldrxq[i].rspq);
  743. for_each_rdmarxq(s, i)
  744. free_irq(adap->msix_info[msi_index++].vec, &s->rdmarxq[i].rspq);
  745. for_each_rdmaciq(s, i)
  746. free_irq(adap->msix_info[msi_index++].vec, &s->rdmaciq[i].rspq);
  747. }
  748. /**
  749. * write_rss - write the RSS table for a given port
  750. * @pi: the port
  751. * @queues: array of queue indices for RSS
  752. *
  753. * Sets up the portion of the HW RSS table for the port's VI to distribute
  754. * packets to the Rx queues in @queues.
  755. */
  756. static int write_rss(const struct port_info *pi, const u16 *queues)
  757. {
  758. u16 *rss;
  759. int i, err;
  760. const struct sge_eth_rxq *q = &pi->adapter->sge.ethrxq[pi->first_qset];
  761. rss = kmalloc(pi->rss_size * sizeof(u16), GFP_KERNEL);
  762. if (!rss)
  763. return -ENOMEM;
  764. /* map the queue indices to queue ids */
  765. for (i = 0; i < pi->rss_size; i++, queues++)
  766. rss[i] = q[*queues].rspq.abs_id;
  767. err = t4_config_rss_range(pi->adapter, pi->adapter->fn, pi->viid, 0,
  768. pi->rss_size, rss, pi->rss_size);
  769. kfree(rss);
  770. return err;
  771. }
  772. /**
  773. * setup_rss - configure RSS
  774. * @adap: the adapter
  775. *
  776. * Sets up RSS for each port.
  777. */
  778. static int setup_rss(struct adapter *adap)
  779. {
  780. int i, err;
  781. for_each_port(adap, i) {
  782. const struct port_info *pi = adap2pinfo(adap, i);
  783. err = write_rss(pi, pi->rss);
  784. if (err)
  785. return err;
  786. }
  787. return 0;
  788. }
  789. /*
  790. * Return the channel of the ingress queue with the given qid.
  791. */
  792. static unsigned int rxq_to_chan(const struct sge *p, unsigned int qid)
  793. {
  794. qid -= p->ingr_start;
  795. return netdev2pinfo(p->ingr_map[qid]->netdev)->tx_chan;
  796. }
  797. /*
  798. * Wait until all NAPI handlers are descheduled.
  799. */
  800. static void quiesce_rx(struct adapter *adap)
  801. {
  802. int i;
  803. for (i = 0; i < ARRAY_SIZE(adap->sge.ingr_map); i++) {
  804. struct sge_rspq *q = adap->sge.ingr_map[i];
  805. if (q && q->handler) {
  806. napi_disable(&q->napi);
  807. local_bh_disable();
  808. while (!cxgb_poll_lock_napi(q))
  809. mdelay(1);
  810. local_bh_enable();
  811. }
  812. }
  813. }
  814. /*
  815. * Enable NAPI scheduling and interrupt generation for all Rx queues.
  816. */
  817. static void enable_rx(struct adapter *adap)
  818. {
  819. int i;
  820. for (i = 0; i < ARRAY_SIZE(adap->sge.ingr_map); i++) {
  821. struct sge_rspq *q = adap->sge.ingr_map[i];
  822. if (!q)
  823. continue;
  824. if (q->handler) {
  825. cxgb_busy_poll_init_lock(q);
  826. napi_enable(&q->napi);
  827. }
  828. /* 0-increment GTS to start the timer and enable interrupts */
  829. t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
  830. SEINTARM_V(q->intr_params) |
  831. INGRESSQID_V(q->cntxt_id));
  832. }
  833. }
  834. static int alloc_ofld_rxqs(struct adapter *adap, struct sge_ofld_rxq *q,
  835. unsigned int nq, unsigned int per_chan, int msi_idx,
  836. u16 *ids)
  837. {
  838. int i, err;
  839. for (i = 0; i < nq; i++, q++) {
  840. if (msi_idx > 0)
  841. msi_idx++;
  842. err = t4_sge_alloc_rxq(adap, &q->rspq, false,
  843. adap->port[i / per_chan],
  844. msi_idx, q->fl.size ? &q->fl : NULL,
  845. uldrx_handler);
  846. if (err)
  847. return err;
  848. memset(&q->stats, 0, sizeof(q->stats));
  849. if (ids)
  850. ids[i] = q->rspq.abs_id;
  851. }
  852. return 0;
  853. }
  854. /**
  855. * setup_sge_queues - configure SGE Tx/Rx/response queues
  856. * @adap: the adapter
  857. *
  858. * Determines how many sets of SGE queues to use and initializes them.
  859. * We support multiple queue sets per port if we have MSI-X, otherwise
  860. * just one queue set per port.
  861. */
  862. static int setup_sge_queues(struct adapter *adap)
  863. {
  864. int err, msi_idx, i, j;
  865. struct sge *s = &adap->sge;
  866. bitmap_zero(s->starving_fl, MAX_EGRQ);
  867. bitmap_zero(s->txq_maperr, MAX_EGRQ);
  868. if (adap->flags & USING_MSIX)
  869. msi_idx = 1; /* vector 0 is for non-queue interrupts */
  870. else {
  871. err = t4_sge_alloc_rxq(adap, &s->intrq, false, adap->port[0], 0,
  872. NULL, NULL);
  873. if (err)
  874. return err;
  875. msi_idx = -((int)s->intrq.abs_id + 1);
  876. }
  877. err = t4_sge_alloc_rxq(adap, &s->fw_evtq, true, adap->port[0],
  878. msi_idx, NULL, fwevtq_handler);
  879. if (err) {
  880. freeout: t4_free_sge_resources(adap);
  881. return err;
  882. }
  883. for_each_port(adap, i) {
  884. struct net_device *dev = adap->port[i];
  885. struct port_info *pi = netdev_priv(dev);
  886. struct sge_eth_rxq *q = &s->ethrxq[pi->first_qset];
  887. struct sge_eth_txq *t = &s->ethtxq[pi->first_qset];
  888. for (j = 0; j < pi->nqsets; j++, q++) {
  889. if (msi_idx > 0)
  890. msi_idx++;
  891. err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev,
  892. msi_idx, &q->fl,
  893. t4_ethrx_handler);
  894. if (err)
  895. goto freeout;
  896. q->rspq.idx = j;
  897. memset(&q->stats, 0, sizeof(q->stats));
  898. }
  899. for (j = 0; j < pi->nqsets; j++, t++) {
  900. err = t4_sge_alloc_eth_txq(adap, t, dev,
  901. netdev_get_tx_queue(dev, j),
  902. s->fw_evtq.cntxt_id);
  903. if (err)
  904. goto freeout;
  905. }
  906. }
  907. j = s->ofldqsets / adap->params.nports; /* ofld queues per channel */
  908. for_each_ofldrxq(s, i) {
  909. err = t4_sge_alloc_ofld_txq(adap, &s->ofldtxq[i],
  910. adap->port[i / j],
  911. s->fw_evtq.cntxt_id);
  912. if (err)
  913. goto freeout;
  914. }
  915. #define ALLOC_OFLD_RXQS(firstq, nq, per_chan, ids) do { \
  916. err = alloc_ofld_rxqs(adap, firstq, nq, per_chan, msi_idx, ids); \
  917. if (err) \
  918. goto freeout; \
  919. if (msi_idx > 0) \
  920. msi_idx += nq; \
  921. } while (0)
  922. ALLOC_OFLD_RXQS(s->ofldrxq, s->ofldqsets, j, s->ofld_rxq);
  923. ALLOC_OFLD_RXQS(s->rdmarxq, s->rdmaqs, 1, s->rdma_rxq);
  924. j = s->rdmaciqs / adap->params.nports; /* rdmaq queues per channel */
  925. ALLOC_OFLD_RXQS(s->rdmaciq, s->rdmaciqs, j, s->rdma_ciq);
  926. #undef ALLOC_OFLD_RXQS
  927. for_each_port(adap, i) {
  928. /*
  929. * Note that ->rdmarxq[i].rspq.cntxt_id below is 0 if we don't
  930. * have RDMA queues, and that's the right value.
  931. */
  932. err = t4_sge_alloc_ctrl_txq(adap, &s->ctrlq[i], adap->port[i],
  933. s->fw_evtq.cntxt_id,
  934. s->rdmarxq[i].rspq.cntxt_id);
  935. if (err)
  936. goto freeout;
  937. }
  938. t4_write_reg(adap, is_t4(adap->params.chip) ?
  939. MPS_TRC_RSS_CONTROL_A :
  940. MPS_T5_TRC_RSS_CONTROL_A,
  941. RSSCONTROL_V(netdev2pinfo(adap->port[0])->tx_chan) |
  942. QUEUENUMBER_V(s->ethrxq[0].rspq.abs_id));
  943. return 0;
  944. }
  945. /*
  946. * Allocate a chunk of memory using kmalloc or, if that fails, vmalloc.
  947. * The allocated memory is cleared.
  948. */
  949. void *t4_alloc_mem(size_t size)
  950. {
  951. void *p = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
  952. if (!p)
  953. p = vzalloc(size);
  954. return p;
  955. }
  956. /*
  957. * Free memory allocated through alloc_mem().
  958. */
  959. void t4_free_mem(void *addr)
  960. {
  961. if (is_vmalloc_addr(addr))
  962. vfree(addr);
  963. else
  964. kfree(addr);
  965. }
  966. /* Send a Work Request to write the filter at a specified index. We construct
  967. * a Firmware Filter Work Request to have the work done and put the indicated
  968. * filter into "pending" mode which will prevent any further actions against
  969. * it till we get a reply from the firmware on the completion status of the
  970. * request.
  971. */
  972. static int set_filter_wr(struct adapter *adapter, int fidx)
  973. {
  974. struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
  975. struct sk_buff *skb;
  976. struct fw_filter_wr *fwr;
  977. unsigned int ftid;
  978. /* If the new filter requires loopback Destination MAC and/or VLAN
  979. * rewriting then we need to allocate a Layer 2 Table (L2T) entry for
  980. * the filter.
  981. */
  982. if (f->fs.newdmac || f->fs.newvlan) {
  983. /* allocate L2T entry for new filter */
  984. f->l2t = t4_l2t_alloc_switching(adapter->l2t);
  985. if (f->l2t == NULL)
  986. return -EAGAIN;
  987. if (t4_l2t_set_switching(adapter, f->l2t, f->fs.vlan,
  988. f->fs.eport, f->fs.dmac)) {
  989. cxgb4_l2t_release(f->l2t);
  990. f->l2t = NULL;
  991. return -ENOMEM;
  992. }
  993. }
  994. ftid = adapter->tids.ftid_base + fidx;
  995. skb = alloc_skb(sizeof(*fwr), GFP_KERNEL | __GFP_NOFAIL);
  996. fwr = (struct fw_filter_wr *)__skb_put(skb, sizeof(*fwr));
  997. memset(fwr, 0, sizeof(*fwr));
  998. /* It would be nice to put most of the following in t4_hw.c but most
  999. * of the work is translating the cxgbtool ch_filter_specification
  1000. * into the Work Request and the definition of that structure is
  1001. * currently in cxgbtool.h which isn't appropriate to pull into the
  1002. * common code. We may eventually try to come up with a more neutral
  1003. * filter specification structure but for now it's easiest to simply
  1004. * put this fairly direct code in line ...
  1005. */
  1006. fwr->op_pkd = htonl(FW_WR_OP_V(FW_FILTER_WR));
  1007. fwr->len16_pkd = htonl(FW_WR_LEN16_V(sizeof(*fwr)/16));
  1008. fwr->tid_to_iq =
  1009. htonl(FW_FILTER_WR_TID_V(ftid) |
  1010. FW_FILTER_WR_RQTYPE_V(f->fs.type) |
  1011. FW_FILTER_WR_NOREPLY_V(0) |
  1012. FW_FILTER_WR_IQ_V(f->fs.iq));
  1013. fwr->del_filter_to_l2tix =
  1014. htonl(FW_FILTER_WR_RPTTID_V(f->fs.rpttid) |
  1015. FW_FILTER_WR_DROP_V(f->fs.action == FILTER_DROP) |
  1016. FW_FILTER_WR_DIRSTEER_V(f->fs.dirsteer) |
  1017. FW_FILTER_WR_MASKHASH_V(f->fs.maskhash) |
  1018. FW_FILTER_WR_DIRSTEERHASH_V(f->fs.dirsteerhash) |
  1019. FW_FILTER_WR_LPBK_V(f->fs.action == FILTER_SWITCH) |
  1020. FW_FILTER_WR_DMAC_V(f->fs.newdmac) |
  1021. FW_FILTER_WR_SMAC_V(f->fs.newsmac) |
  1022. FW_FILTER_WR_INSVLAN_V(f->fs.newvlan == VLAN_INSERT ||
  1023. f->fs.newvlan == VLAN_REWRITE) |
  1024. FW_FILTER_WR_RMVLAN_V(f->fs.newvlan == VLAN_REMOVE ||
  1025. f->fs.newvlan == VLAN_REWRITE) |
  1026. FW_FILTER_WR_HITCNTS_V(f->fs.hitcnts) |
  1027. FW_FILTER_WR_TXCHAN_V(f->fs.eport) |
  1028. FW_FILTER_WR_PRIO_V(f->fs.prio) |
  1029. FW_FILTER_WR_L2TIX_V(f->l2t ? f->l2t->idx : 0));
  1030. fwr->ethtype = htons(f->fs.val.ethtype);
  1031. fwr->ethtypem = htons(f->fs.mask.ethtype);
  1032. fwr->frag_to_ovlan_vldm =
  1033. (FW_FILTER_WR_FRAG_V(f->fs.val.frag) |
  1034. FW_FILTER_WR_FRAGM_V(f->fs.mask.frag) |
  1035. FW_FILTER_WR_IVLAN_VLD_V(f->fs.val.ivlan_vld) |
  1036. FW_FILTER_WR_OVLAN_VLD_V(f->fs.val.ovlan_vld) |
  1037. FW_FILTER_WR_IVLAN_VLDM_V(f->fs.mask.ivlan_vld) |
  1038. FW_FILTER_WR_OVLAN_VLDM_V(f->fs.mask.ovlan_vld));
  1039. fwr->smac_sel = 0;
  1040. fwr->rx_chan_rx_rpl_iq =
  1041. htons(FW_FILTER_WR_RX_CHAN_V(0) |
  1042. FW_FILTER_WR_RX_RPL_IQ_V(adapter->sge.fw_evtq.abs_id));
  1043. fwr->maci_to_matchtypem =
  1044. htonl(FW_FILTER_WR_MACI_V(f->fs.val.macidx) |
  1045. FW_FILTER_WR_MACIM_V(f->fs.mask.macidx) |
  1046. FW_FILTER_WR_FCOE_V(f->fs.val.fcoe) |
  1047. FW_FILTER_WR_FCOEM_V(f->fs.mask.fcoe) |
  1048. FW_FILTER_WR_PORT_V(f->fs.val.iport) |
  1049. FW_FILTER_WR_PORTM_V(f->fs.mask.iport) |
  1050. FW_FILTER_WR_MATCHTYPE_V(f->fs.val.matchtype) |
  1051. FW_FILTER_WR_MATCHTYPEM_V(f->fs.mask.matchtype));
  1052. fwr->ptcl = f->fs.val.proto;
  1053. fwr->ptclm = f->fs.mask.proto;
  1054. fwr->ttyp = f->fs.val.tos;
  1055. fwr->ttypm = f->fs.mask.tos;
  1056. fwr->ivlan = htons(f->fs.val.ivlan);
  1057. fwr->ivlanm = htons(f->fs.mask.ivlan);
  1058. fwr->ovlan = htons(f->fs.val.ovlan);
  1059. fwr->ovlanm = htons(f->fs.mask.ovlan);
  1060. memcpy(fwr->lip, f->fs.val.lip, sizeof(fwr->lip));
  1061. memcpy(fwr->lipm, f->fs.mask.lip, sizeof(fwr->lipm));
  1062. memcpy(fwr->fip, f->fs.val.fip, sizeof(fwr->fip));
  1063. memcpy(fwr->fipm, f->fs.mask.fip, sizeof(fwr->fipm));
  1064. fwr->lp = htons(f->fs.val.lport);
  1065. fwr->lpm = htons(f->fs.mask.lport);
  1066. fwr->fp = htons(f->fs.val.fport);
  1067. fwr->fpm = htons(f->fs.mask.fport);
  1068. if (f->fs.newsmac)
  1069. memcpy(fwr->sma, f->fs.smac, sizeof(fwr->sma));
  1070. /* Mark the filter as "pending" and ship off the Filter Work Request.
  1071. * When we get the Work Request Reply we'll clear the pending status.
  1072. */
  1073. f->pending = 1;
  1074. set_wr_txq(skb, CPL_PRIORITY_CONTROL, f->fs.val.iport & 0x3);
  1075. t4_ofld_send(adapter, skb);
  1076. return 0;
  1077. }
  1078. /* Delete the filter at a specified index.
  1079. */
  1080. static int del_filter_wr(struct adapter *adapter, int fidx)
  1081. {
  1082. struct filter_entry *f = &adapter->tids.ftid_tab[fidx];
  1083. struct sk_buff *skb;
  1084. struct fw_filter_wr *fwr;
  1085. unsigned int len, ftid;
  1086. len = sizeof(*fwr);
  1087. ftid = adapter->tids.ftid_base + fidx;
  1088. skb = alloc_skb(len, GFP_KERNEL | __GFP_NOFAIL);
  1089. fwr = (struct fw_filter_wr *)__skb_put(skb, len);
  1090. t4_mk_filtdelwr(ftid, fwr, adapter->sge.fw_evtq.abs_id);
  1091. /* Mark the filter as "pending" and ship off the Filter Work Request.
  1092. * When we get the Work Request Reply we'll clear the pending status.
  1093. */
  1094. f->pending = 1;
  1095. t4_mgmt_tx(adapter, skb);
  1096. return 0;
  1097. }
  1098. static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
  1099. void *accel_priv, select_queue_fallback_t fallback)
  1100. {
  1101. int txq;
  1102. #ifdef CONFIG_CHELSIO_T4_DCB
  1103. /* If a Data Center Bridging has been successfully negotiated on this
  1104. * link then we'll use the skb's priority to map it to a TX Queue.
  1105. * The skb's priority is determined via the VLAN Tag Priority Code
  1106. * Point field.
  1107. */
  1108. if (cxgb4_dcb_enabled(dev)) {
  1109. u16 vlan_tci;
  1110. int err;
  1111. err = vlan_get_tag(skb, &vlan_tci);
  1112. if (unlikely(err)) {
  1113. if (net_ratelimit())
  1114. netdev_warn(dev,
  1115. "TX Packet without VLAN Tag on DCB Link\n");
  1116. txq = 0;
  1117. } else {
  1118. txq = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  1119. }
  1120. return txq;
  1121. }
  1122. #endif /* CONFIG_CHELSIO_T4_DCB */
  1123. if (select_queue) {
  1124. txq = (skb_rx_queue_recorded(skb)
  1125. ? skb_get_rx_queue(skb)
  1126. : smp_processor_id());
  1127. while (unlikely(txq >= dev->real_num_tx_queues))
  1128. txq -= dev->real_num_tx_queues;
  1129. return txq;
  1130. }
  1131. return fallback(dev, skb) % dev->real_num_tx_queues;
  1132. }
  1133. static inline int is_offload(const struct adapter *adap)
  1134. {
  1135. return adap->params.offload;
  1136. }
  1137. /*
  1138. * Implementation of ethtool operations.
  1139. */
  1140. static u32 get_msglevel(struct net_device *dev)
  1141. {
  1142. return netdev2adap(dev)->msg_enable;
  1143. }
  1144. static void set_msglevel(struct net_device *dev, u32 val)
  1145. {
  1146. netdev2adap(dev)->msg_enable = val;
  1147. }
  1148. static char stats_strings[][ETH_GSTRING_LEN] = {
  1149. "TxOctetsOK ",
  1150. "TxFramesOK ",
  1151. "TxBroadcastFrames ",
  1152. "TxMulticastFrames ",
  1153. "TxUnicastFrames ",
  1154. "TxErrorFrames ",
  1155. "TxFrames64 ",
  1156. "TxFrames65To127 ",
  1157. "TxFrames128To255 ",
  1158. "TxFrames256To511 ",
  1159. "TxFrames512To1023 ",
  1160. "TxFrames1024To1518 ",
  1161. "TxFrames1519ToMax ",
  1162. "TxFramesDropped ",
  1163. "TxPauseFrames ",
  1164. "TxPPP0Frames ",
  1165. "TxPPP1Frames ",
  1166. "TxPPP2Frames ",
  1167. "TxPPP3Frames ",
  1168. "TxPPP4Frames ",
  1169. "TxPPP5Frames ",
  1170. "TxPPP6Frames ",
  1171. "TxPPP7Frames ",
  1172. "RxOctetsOK ",
  1173. "RxFramesOK ",
  1174. "RxBroadcastFrames ",
  1175. "RxMulticastFrames ",
  1176. "RxUnicastFrames ",
  1177. "RxFramesTooLong ",
  1178. "RxJabberErrors ",
  1179. "RxFCSErrors ",
  1180. "RxLengthErrors ",
  1181. "RxSymbolErrors ",
  1182. "RxRuntFrames ",
  1183. "RxFrames64 ",
  1184. "RxFrames65To127 ",
  1185. "RxFrames128To255 ",
  1186. "RxFrames256To511 ",
  1187. "RxFrames512To1023 ",
  1188. "RxFrames1024To1518 ",
  1189. "RxFrames1519ToMax ",
  1190. "RxPauseFrames ",
  1191. "RxPPP0Frames ",
  1192. "RxPPP1Frames ",
  1193. "RxPPP2Frames ",
  1194. "RxPPP3Frames ",
  1195. "RxPPP4Frames ",
  1196. "RxPPP5Frames ",
  1197. "RxPPP6Frames ",
  1198. "RxPPP7Frames ",
  1199. "RxBG0FramesDropped ",
  1200. "RxBG1FramesDropped ",
  1201. "RxBG2FramesDropped ",
  1202. "RxBG3FramesDropped ",
  1203. "RxBG0FramesTrunc ",
  1204. "RxBG1FramesTrunc ",
  1205. "RxBG2FramesTrunc ",
  1206. "RxBG3FramesTrunc ",
  1207. "TSO ",
  1208. "TxCsumOffload ",
  1209. "RxCsumGood ",
  1210. "VLANextractions ",
  1211. "VLANinsertions ",
  1212. "GROpackets ",
  1213. "GROmerged ",
  1214. "WriteCoalSuccess ",
  1215. "WriteCoalFail ",
  1216. };
  1217. static int get_sset_count(struct net_device *dev, int sset)
  1218. {
  1219. switch (sset) {
  1220. case ETH_SS_STATS:
  1221. return ARRAY_SIZE(stats_strings);
  1222. default:
  1223. return -EOPNOTSUPP;
  1224. }
  1225. }
  1226. #define T4_REGMAP_SIZE (160 * 1024)
  1227. #define T5_REGMAP_SIZE (332 * 1024)
  1228. static int get_regs_len(struct net_device *dev)
  1229. {
  1230. struct adapter *adap = netdev2adap(dev);
  1231. if (is_t4(adap->params.chip))
  1232. return T4_REGMAP_SIZE;
  1233. else
  1234. return T5_REGMAP_SIZE;
  1235. }
  1236. static int get_eeprom_len(struct net_device *dev)
  1237. {
  1238. return EEPROMSIZE;
  1239. }
  1240. static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1241. {
  1242. struct adapter *adapter = netdev2adap(dev);
  1243. u32 exprom_vers;
  1244. strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
  1245. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  1246. strlcpy(info->bus_info, pci_name(adapter->pdev),
  1247. sizeof(info->bus_info));
  1248. if (adapter->params.fw_vers)
  1249. snprintf(info->fw_version, sizeof(info->fw_version),
  1250. "%u.%u.%u.%u, TP %u.%u.%u.%u",
  1251. FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
  1252. FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
  1253. FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
  1254. FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers),
  1255. FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
  1256. FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
  1257. FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
  1258. FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
  1259. if (!t4_get_exprom_version(adapter, &exprom_vers))
  1260. snprintf(info->erom_version, sizeof(info->erom_version),
  1261. "%u.%u.%u.%u",
  1262. FW_HDR_FW_VER_MAJOR_G(exprom_vers),
  1263. FW_HDR_FW_VER_MINOR_G(exprom_vers),
  1264. FW_HDR_FW_VER_MICRO_G(exprom_vers),
  1265. FW_HDR_FW_VER_BUILD_G(exprom_vers));
  1266. }
  1267. static void get_strings(struct net_device *dev, u32 stringset, u8 *data)
  1268. {
  1269. if (stringset == ETH_SS_STATS)
  1270. memcpy(data, stats_strings, sizeof(stats_strings));
  1271. }
  1272. /*
  1273. * port stats maintained per queue of the port. They should be in the same
  1274. * order as in stats_strings above.
  1275. */
  1276. struct queue_port_stats {
  1277. u64 tso;
  1278. u64 tx_csum;
  1279. u64 rx_csum;
  1280. u64 vlan_ex;
  1281. u64 vlan_ins;
  1282. u64 gro_pkts;
  1283. u64 gro_merged;
  1284. };
  1285. static void collect_sge_port_stats(const struct adapter *adap,
  1286. const struct port_info *p, struct queue_port_stats *s)
  1287. {
  1288. int i;
  1289. const struct sge_eth_txq *tx = &adap->sge.ethtxq[p->first_qset];
  1290. const struct sge_eth_rxq *rx = &adap->sge.ethrxq[p->first_qset];
  1291. memset(s, 0, sizeof(*s));
  1292. for (i = 0; i < p->nqsets; i++, rx++, tx++) {
  1293. s->tso += tx->tso;
  1294. s->tx_csum += tx->tx_cso;
  1295. s->rx_csum += rx->stats.rx_cso;
  1296. s->vlan_ex += rx->stats.vlan_ex;
  1297. s->vlan_ins += tx->vlan_ins;
  1298. s->gro_pkts += rx->stats.lro_pkts;
  1299. s->gro_merged += rx->stats.lro_merged;
  1300. }
  1301. }
  1302. static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
  1303. u64 *data)
  1304. {
  1305. struct port_info *pi = netdev_priv(dev);
  1306. struct adapter *adapter = pi->adapter;
  1307. u32 val1, val2;
  1308. t4_get_port_stats(adapter, pi->tx_chan, (struct port_stats *)data);
  1309. data += sizeof(struct port_stats) / sizeof(u64);
  1310. collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
  1311. data += sizeof(struct queue_port_stats) / sizeof(u64);
  1312. if (!is_t4(adapter->params.chip)) {
  1313. t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7));
  1314. val1 = t4_read_reg(adapter, SGE_STAT_TOTAL_A);
  1315. val2 = t4_read_reg(adapter, SGE_STAT_MATCH_A);
  1316. *data = val1 - val2;
  1317. data++;
  1318. *data = val2;
  1319. data++;
  1320. } else {
  1321. memset(data, 0, 2 * sizeof(u64));
  1322. *data += 2;
  1323. }
  1324. }
  1325. /*
  1326. * Return a version number to identify the type of adapter. The scheme is:
  1327. * - bits 0..9: chip version
  1328. * - bits 10..15: chip revision
  1329. * - bits 16..23: register dump version
  1330. */
  1331. static inline unsigned int mk_adap_vers(const struct adapter *ap)
  1332. {
  1333. return CHELSIO_CHIP_VERSION(ap->params.chip) |
  1334. (CHELSIO_CHIP_RELEASE(ap->params.chip) << 10) | (1 << 16);
  1335. }
  1336. static void reg_block_dump(struct adapter *ap, void *buf, unsigned int start,
  1337. unsigned int end)
  1338. {
  1339. u32 *p = buf + start;
  1340. for ( ; start <= end; start += sizeof(u32))
  1341. *p++ = t4_read_reg(ap, start);
  1342. }
  1343. static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
  1344. void *buf)
  1345. {
  1346. static const unsigned int t4_reg_ranges[] = {
  1347. 0x1008, 0x1108,
  1348. 0x1180, 0x11b4,
  1349. 0x11fc, 0x123c,
  1350. 0x1300, 0x173c,
  1351. 0x1800, 0x18fc,
  1352. 0x3000, 0x30d8,
  1353. 0x30e0, 0x5924,
  1354. 0x5960, 0x59d4,
  1355. 0x5a00, 0x5af8,
  1356. 0x6000, 0x6098,
  1357. 0x6100, 0x6150,
  1358. 0x6200, 0x6208,
  1359. 0x6240, 0x6248,
  1360. 0x6280, 0x6338,
  1361. 0x6370, 0x638c,
  1362. 0x6400, 0x643c,
  1363. 0x6500, 0x6524,
  1364. 0x6a00, 0x6a38,
  1365. 0x6a60, 0x6a78,
  1366. 0x6b00, 0x6b84,
  1367. 0x6bf0, 0x6c84,
  1368. 0x6cf0, 0x6d84,
  1369. 0x6df0, 0x6e84,
  1370. 0x6ef0, 0x6f84,
  1371. 0x6ff0, 0x7084,
  1372. 0x70f0, 0x7184,
  1373. 0x71f0, 0x7284,
  1374. 0x72f0, 0x7384,
  1375. 0x73f0, 0x7450,
  1376. 0x7500, 0x7530,
  1377. 0x7600, 0x761c,
  1378. 0x7680, 0x76cc,
  1379. 0x7700, 0x7798,
  1380. 0x77c0, 0x77fc,
  1381. 0x7900, 0x79fc,
  1382. 0x7b00, 0x7c38,
  1383. 0x7d00, 0x7efc,
  1384. 0x8dc0, 0x8e1c,
  1385. 0x8e30, 0x8e78,
  1386. 0x8ea0, 0x8f6c,
  1387. 0x8fc0, 0x9074,
  1388. 0x90fc, 0x90fc,
  1389. 0x9400, 0x9458,
  1390. 0x9600, 0x96bc,
  1391. 0x9800, 0x9808,
  1392. 0x9820, 0x983c,
  1393. 0x9850, 0x9864,
  1394. 0x9c00, 0x9c6c,
  1395. 0x9c80, 0x9cec,
  1396. 0x9d00, 0x9d6c,
  1397. 0x9d80, 0x9dec,
  1398. 0x9e00, 0x9e6c,
  1399. 0x9e80, 0x9eec,
  1400. 0x9f00, 0x9f6c,
  1401. 0x9f80, 0x9fec,
  1402. 0xd004, 0xd03c,
  1403. 0xdfc0, 0xdfe0,
  1404. 0xe000, 0xea7c,
  1405. 0xf000, 0x11110,
  1406. 0x11118, 0x11190,
  1407. 0x19040, 0x1906c,
  1408. 0x19078, 0x19080,
  1409. 0x1908c, 0x19124,
  1410. 0x19150, 0x191b0,
  1411. 0x191d0, 0x191e8,
  1412. 0x19238, 0x1924c,
  1413. 0x193f8, 0x19474,
  1414. 0x19490, 0x194f8,
  1415. 0x19800, 0x19f30,
  1416. 0x1a000, 0x1a06c,
  1417. 0x1a0b0, 0x1a120,
  1418. 0x1a128, 0x1a138,
  1419. 0x1a190, 0x1a1c4,
  1420. 0x1a1fc, 0x1a1fc,
  1421. 0x1e040, 0x1e04c,
  1422. 0x1e284, 0x1e28c,
  1423. 0x1e2c0, 0x1e2c0,
  1424. 0x1e2e0, 0x1e2e0,
  1425. 0x1e300, 0x1e384,
  1426. 0x1e3c0, 0x1e3c8,
  1427. 0x1e440, 0x1e44c,
  1428. 0x1e684, 0x1e68c,
  1429. 0x1e6c0, 0x1e6c0,
  1430. 0x1e6e0, 0x1e6e0,
  1431. 0x1e700, 0x1e784,
  1432. 0x1e7c0, 0x1e7c8,
  1433. 0x1e840, 0x1e84c,
  1434. 0x1ea84, 0x1ea8c,
  1435. 0x1eac0, 0x1eac0,
  1436. 0x1eae0, 0x1eae0,
  1437. 0x1eb00, 0x1eb84,
  1438. 0x1ebc0, 0x1ebc8,
  1439. 0x1ec40, 0x1ec4c,
  1440. 0x1ee84, 0x1ee8c,
  1441. 0x1eec0, 0x1eec0,
  1442. 0x1eee0, 0x1eee0,
  1443. 0x1ef00, 0x1ef84,
  1444. 0x1efc0, 0x1efc8,
  1445. 0x1f040, 0x1f04c,
  1446. 0x1f284, 0x1f28c,
  1447. 0x1f2c0, 0x1f2c0,
  1448. 0x1f2e0, 0x1f2e0,
  1449. 0x1f300, 0x1f384,
  1450. 0x1f3c0, 0x1f3c8,
  1451. 0x1f440, 0x1f44c,
  1452. 0x1f684, 0x1f68c,
  1453. 0x1f6c0, 0x1f6c0,
  1454. 0x1f6e0, 0x1f6e0,
  1455. 0x1f700, 0x1f784,
  1456. 0x1f7c0, 0x1f7c8,
  1457. 0x1f840, 0x1f84c,
  1458. 0x1fa84, 0x1fa8c,
  1459. 0x1fac0, 0x1fac0,
  1460. 0x1fae0, 0x1fae0,
  1461. 0x1fb00, 0x1fb84,
  1462. 0x1fbc0, 0x1fbc8,
  1463. 0x1fc40, 0x1fc4c,
  1464. 0x1fe84, 0x1fe8c,
  1465. 0x1fec0, 0x1fec0,
  1466. 0x1fee0, 0x1fee0,
  1467. 0x1ff00, 0x1ff84,
  1468. 0x1ffc0, 0x1ffc8,
  1469. 0x20000, 0x2002c,
  1470. 0x20100, 0x2013c,
  1471. 0x20190, 0x201c8,
  1472. 0x20200, 0x20318,
  1473. 0x20400, 0x20528,
  1474. 0x20540, 0x20614,
  1475. 0x21000, 0x21040,
  1476. 0x2104c, 0x21060,
  1477. 0x210c0, 0x210ec,
  1478. 0x21200, 0x21268,
  1479. 0x21270, 0x21284,
  1480. 0x212fc, 0x21388,
  1481. 0x21400, 0x21404,
  1482. 0x21500, 0x21518,
  1483. 0x2152c, 0x2153c,
  1484. 0x21550, 0x21554,
  1485. 0x21600, 0x21600,
  1486. 0x21608, 0x21628,
  1487. 0x21630, 0x2163c,
  1488. 0x21700, 0x2171c,
  1489. 0x21780, 0x2178c,
  1490. 0x21800, 0x21c38,
  1491. 0x21c80, 0x21d7c,
  1492. 0x21e00, 0x21e04,
  1493. 0x22000, 0x2202c,
  1494. 0x22100, 0x2213c,
  1495. 0x22190, 0x221c8,
  1496. 0x22200, 0x22318,
  1497. 0x22400, 0x22528,
  1498. 0x22540, 0x22614,
  1499. 0x23000, 0x23040,
  1500. 0x2304c, 0x23060,
  1501. 0x230c0, 0x230ec,
  1502. 0x23200, 0x23268,
  1503. 0x23270, 0x23284,
  1504. 0x232fc, 0x23388,
  1505. 0x23400, 0x23404,
  1506. 0x23500, 0x23518,
  1507. 0x2352c, 0x2353c,
  1508. 0x23550, 0x23554,
  1509. 0x23600, 0x23600,
  1510. 0x23608, 0x23628,
  1511. 0x23630, 0x2363c,
  1512. 0x23700, 0x2371c,
  1513. 0x23780, 0x2378c,
  1514. 0x23800, 0x23c38,
  1515. 0x23c80, 0x23d7c,
  1516. 0x23e00, 0x23e04,
  1517. 0x24000, 0x2402c,
  1518. 0x24100, 0x2413c,
  1519. 0x24190, 0x241c8,
  1520. 0x24200, 0x24318,
  1521. 0x24400, 0x24528,
  1522. 0x24540, 0x24614,
  1523. 0x25000, 0x25040,
  1524. 0x2504c, 0x25060,
  1525. 0x250c0, 0x250ec,
  1526. 0x25200, 0x25268,
  1527. 0x25270, 0x25284,
  1528. 0x252fc, 0x25388,
  1529. 0x25400, 0x25404,
  1530. 0x25500, 0x25518,
  1531. 0x2552c, 0x2553c,
  1532. 0x25550, 0x25554,
  1533. 0x25600, 0x25600,
  1534. 0x25608, 0x25628,
  1535. 0x25630, 0x2563c,
  1536. 0x25700, 0x2571c,
  1537. 0x25780, 0x2578c,
  1538. 0x25800, 0x25c38,
  1539. 0x25c80, 0x25d7c,
  1540. 0x25e00, 0x25e04,
  1541. 0x26000, 0x2602c,
  1542. 0x26100, 0x2613c,
  1543. 0x26190, 0x261c8,
  1544. 0x26200, 0x26318,
  1545. 0x26400, 0x26528,
  1546. 0x26540, 0x26614,
  1547. 0x27000, 0x27040,
  1548. 0x2704c, 0x27060,
  1549. 0x270c0, 0x270ec,
  1550. 0x27200, 0x27268,
  1551. 0x27270, 0x27284,
  1552. 0x272fc, 0x27388,
  1553. 0x27400, 0x27404,
  1554. 0x27500, 0x27518,
  1555. 0x2752c, 0x2753c,
  1556. 0x27550, 0x27554,
  1557. 0x27600, 0x27600,
  1558. 0x27608, 0x27628,
  1559. 0x27630, 0x2763c,
  1560. 0x27700, 0x2771c,
  1561. 0x27780, 0x2778c,
  1562. 0x27800, 0x27c38,
  1563. 0x27c80, 0x27d7c,
  1564. 0x27e00, 0x27e04
  1565. };
  1566. static const unsigned int t5_reg_ranges[] = {
  1567. 0x1008, 0x1148,
  1568. 0x1180, 0x11b4,
  1569. 0x11fc, 0x123c,
  1570. 0x1280, 0x173c,
  1571. 0x1800, 0x18fc,
  1572. 0x3000, 0x3028,
  1573. 0x3060, 0x30d8,
  1574. 0x30e0, 0x30fc,
  1575. 0x3140, 0x357c,
  1576. 0x35a8, 0x35cc,
  1577. 0x35ec, 0x35ec,
  1578. 0x3600, 0x5624,
  1579. 0x56cc, 0x575c,
  1580. 0x580c, 0x5814,
  1581. 0x5890, 0x58bc,
  1582. 0x5940, 0x59dc,
  1583. 0x59fc, 0x5a18,
  1584. 0x5a60, 0x5a9c,
  1585. 0x5b9c, 0x5bfc,
  1586. 0x6000, 0x6040,
  1587. 0x6058, 0x614c,
  1588. 0x7700, 0x7798,
  1589. 0x77c0, 0x78fc,
  1590. 0x7b00, 0x7c54,
  1591. 0x7d00, 0x7efc,
  1592. 0x8dc0, 0x8de0,
  1593. 0x8df8, 0x8e84,
  1594. 0x8ea0, 0x8f84,
  1595. 0x8fc0, 0x90f8,
  1596. 0x9400, 0x9470,
  1597. 0x9600, 0x96f4,
  1598. 0x9800, 0x9808,
  1599. 0x9820, 0x983c,
  1600. 0x9850, 0x9864,
  1601. 0x9c00, 0x9c6c,
  1602. 0x9c80, 0x9cec,
  1603. 0x9d00, 0x9d6c,
  1604. 0x9d80, 0x9dec,
  1605. 0x9e00, 0x9e6c,
  1606. 0x9e80, 0x9eec,
  1607. 0x9f00, 0x9f6c,
  1608. 0x9f80, 0xa020,
  1609. 0xd004, 0xd03c,
  1610. 0xdfc0, 0xdfe0,
  1611. 0xe000, 0x11088,
  1612. 0x1109c, 0x11110,
  1613. 0x11118, 0x1117c,
  1614. 0x11190, 0x11204,
  1615. 0x19040, 0x1906c,
  1616. 0x19078, 0x19080,
  1617. 0x1908c, 0x19124,
  1618. 0x19150, 0x191b0,
  1619. 0x191d0, 0x191e8,
  1620. 0x19238, 0x19290,
  1621. 0x193f8, 0x19474,
  1622. 0x19490, 0x194cc,
  1623. 0x194f0, 0x194f8,
  1624. 0x19c00, 0x19c60,
  1625. 0x19c94, 0x19e10,
  1626. 0x19e50, 0x19f34,
  1627. 0x19f40, 0x19f50,
  1628. 0x19f90, 0x19fe4,
  1629. 0x1a000, 0x1a06c,
  1630. 0x1a0b0, 0x1a120,
  1631. 0x1a128, 0x1a138,
  1632. 0x1a190, 0x1a1c4,
  1633. 0x1a1fc, 0x1a1fc,
  1634. 0x1e008, 0x1e00c,
  1635. 0x1e040, 0x1e04c,
  1636. 0x1e284, 0x1e290,
  1637. 0x1e2c0, 0x1e2c0,
  1638. 0x1e2e0, 0x1e2e0,
  1639. 0x1e300, 0x1e384,
  1640. 0x1e3c0, 0x1e3c8,
  1641. 0x1e408, 0x1e40c,
  1642. 0x1e440, 0x1e44c,
  1643. 0x1e684, 0x1e690,
  1644. 0x1e6c0, 0x1e6c0,
  1645. 0x1e6e0, 0x1e6e0,
  1646. 0x1e700, 0x1e784,
  1647. 0x1e7c0, 0x1e7c8,
  1648. 0x1e808, 0x1e80c,
  1649. 0x1e840, 0x1e84c,
  1650. 0x1ea84, 0x1ea90,
  1651. 0x1eac0, 0x1eac0,
  1652. 0x1eae0, 0x1eae0,
  1653. 0x1eb00, 0x1eb84,
  1654. 0x1ebc0, 0x1ebc8,
  1655. 0x1ec08, 0x1ec0c,
  1656. 0x1ec40, 0x1ec4c,
  1657. 0x1ee84, 0x1ee90,
  1658. 0x1eec0, 0x1eec0,
  1659. 0x1eee0, 0x1eee0,
  1660. 0x1ef00, 0x1ef84,
  1661. 0x1efc0, 0x1efc8,
  1662. 0x1f008, 0x1f00c,
  1663. 0x1f040, 0x1f04c,
  1664. 0x1f284, 0x1f290,
  1665. 0x1f2c0, 0x1f2c0,
  1666. 0x1f2e0, 0x1f2e0,
  1667. 0x1f300, 0x1f384,
  1668. 0x1f3c0, 0x1f3c8,
  1669. 0x1f408, 0x1f40c,
  1670. 0x1f440, 0x1f44c,
  1671. 0x1f684, 0x1f690,
  1672. 0x1f6c0, 0x1f6c0,
  1673. 0x1f6e0, 0x1f6e0,
  1674. 0x1f700, 0x1f784,
  1675. 0x1f7c0, 0x1f7c8,
  1676. 0x1f808, 0x1f80c,
  1677. 0x1f840, 0x1f84c,
  1678. 0x1fa84, 0x1fa90,
  1679. 0x1fac0, 0x1fac0,
  1680. 0x1fae0, 0x1fae0,
  1681. 0x1fb00, 0x1fb84,
  1682. 0x1fbc0, 0x1fbc8,
  1683. 0x1fc08, 0x1fc0c,
  1684. 0x1fc40, 0x1fc4c,
  1685. 0x1fe84, 0x1fe90,
  1686. 0x1fec0, 0x1fec0,
  1687. 0x1fee0, 0x1fee0,
  1688. 0x1ff00, 0x1ff84,
  1689. 0x1ffc0, 0x1ffc8,
  1690. 0x30000, 0x30030,
  1691. 0x30100, 0x30144,
  1692. 0x30190, 0x301d0,
  1693. 0x30200, 0x30318,
  1694. 0x30400, 0x3052c,
  1695. 0x30540, 0x3061c,
  1696. 0x30800, 0x30834,
  1697. 0x308c0, 0x30908,
  1698. 0x30910, 0x309ac,
  1699. 0x30a00, 0x30a04,
  1700. 0x30a0c, 0x30a2c,
  1701. 0x30a44, 0x30a50,
  1702. 0x30a74, 0x30c24,
  1703. 0x30d08, 0x30d14,
  1704. 0x30d1c, 0x30d20,
  1705. 0x30d3c, 0x30d50,
  1706. 0x31200, 0x3120c,
  1707. 0x31220, 0x31220,
  1708. 0x31240, 0x31240,
  1709. 0x31600, 0x31600,
  1710. 0x31608, 0x3160c,
  1711. 0x31a00, 0x31a1c,
  1712. 0x31e04, 0x31e20,
  1713. 0x31e38, 0x31e3c,
  1714. 0x31e80, 0x31e80,
  1715. 0x31e88, 0x31ea8,
  1716. 0x31eb0, 0x31eb4,
  1717. 0x31ec8, 0x31ed4,
  1718. 0x31fb8, 0x32004,
  1719. 0x32208, 0x3223c,
  1720. 0x32600, 0x32630,
  1721. 0x32a00, 0x32abc,
  1722. 0x32b00, 0x32b70,
  1723. 0x33000, 0x33048,
  1724. 0x33060, 0x3309c,
  1725. 0x330f0, 0x33148,
  1726. 0x33160, 0x3319c,
  1727. 0x331f0, 0x332e4,
  1728. 0x332f8, 0x333e4,
  1729. 0x333f8, 0x33448,
  1730. 0x33460, 0x3349c,
  1731. 0x334f0, 0x33548,
  1732. 0x33560, 0x3359c,
  1733. 0x335f0, 0x336e4,
  1734. 0x336f8, 0x337e4,
  1735. 0x337f8, 0x337fc,
  1736. 0x33814, 0x33814,
  1737. 0x3382c, 0x3382c,
  1738. 0x33880, 0x3388c,
  1739. 0x338e8, 0x338ec,
  1740. 0x33900, 0x33948,
  1741. 0x33960, 0x3399c,
  1742. 0x339f0, 0x33ae4,
  1743. 0x33af8, 0x33b10,
  1744. 0x33b28, 0x33b28,
  1745. 0x33b3c, 0x33b50,
  1746. 0x33bf0, 0x33c10,
  1747. 0x33c28, 0x33c28,
  1748. 0x33c3c, 0x33c50,
  1749. 0x33cf0, 0x33cfc,
  1750. 0x34000, 0x34030,
  1751. 0x34100, 0x34144,
  1752. 0x34190, 0x341d0,
  1753. 0x34200, 0x34318,
  1754. 0x34400, 0x3452c,
  1755. 0x34540, 0x3461c,
  1756. 0x34800, 0x34834,
  1757. 0x348c0, 0x34908,
  1758. 0x34910, 0x349ac,
  1759. 0x34a00, 0x34a04,
  1760. 0x34a0c, 0x34a2c,
  1761. 0x34a44, 0x34a50,
  1762. 0x34a74, 0x34c24,
  1763. 0x34d08, 0x34d14,
  1764. 0x34d1c, 0x34d20,
  1765. 0x34d3c, 0x34d50,
  1766. 0x35200, 0x3520c,
  1767. 0x35220, 0x35220,
  1768. 0x35240, 0x35240,
  1769. 0x35600, 0x35600,
  1770. 0x35608, 0x3560c,
  1771. 0x35a00, 0x35a1c,
  1772. 0x35e04, 0x35e20,
  1773. 0x35e38, 0x35e3c,
  1774. 0x35e80, 0x35e80,
  1775. 0x35e88, 0x35ea8,
  1776. 0x35eb0, 0x35eb4,
  1777. 0x35ec8, 0x35ed4,
  1778. 0x35fb8, 0x36004,
  1779. 0x36208, 0x3623c,
  1780. 0x36600, 0x36630,
  1781. 0x36a00, 0x36abc,
  1782. 0x36b00, 0x36b70,
  1783. 0x37000, 0x37048,
  1784. 0x37060, 0x3709c,
  1785. 0x370f0, 0x37148,
  1786. 0x37160, 0x3719c,
  1787. 0x371f0, 0x372e4,
  1788. 0x372f8, 0x373e4,
  1789. 0x373f8, 0x37448,
  1790. 0x37460, 0x3749c,
  1791. 0x374f0, 0x37548,
  1792. 0x37560, 0x3759c,
  1793. 0x375f0, 0x376e4,
  1794. 0x376f8, 0x377e4,
  1795. 0x377f8, 0x377fc,
  1796. 0x37814, 0x37814,
  1797. 0x3782c, 0x3782c,
  1798. 0x37880, 0x3788c,
  1799. 0x378e8, 0x378ec,
  1800. 0x37900, 0x37948,
  1801. 0x37960, 0x3799c,
  1802. 0x379f0, 0x37ae4,
  1803. 0x37af8, 0x37b10,
  1804. 0x37b28, 0x37b28,
  1805. 0x37b3c, 0x37b50,
  1806. 0x37bf0, 0x37c10,
  1807. 0x37c28, 0x37c28,
  1808. 0x37c3c, 0x37c50,
  1809. 0x37cf0, 0x37cfc,
  1810. 0x38000, 0x38030,
  1811. 0x38100, 0x38144,
  1812. 0x38190, 0x381d0,
  1813. 0x38200, 0x38318,
  1814. 0x38400, 0x3852c,
  1815. 0x38540, 0x3861c,
  1816. 0x38800, 0x38834,
  1817. 0x388c0, 0x38908,
  1818. 0x38910, 0x389ac,
  1819. 0x38a00, 0x38a04,
  1820. 0x38a0c, 0x38a2c,
  1821. 0x38a44, 0x38a50,
  1822. 0x38a74, 0x38c24,
  1823. 0x38d08, 0x38d14,
  1824. 0x38d1c, 0x38d20,
  1825. 0x38d3c, 0x38d50,
  1826. 0x39200, 0x3920c,
  1827. 0x39220, 0x39220,
  1828. 0x39240, 0x39240,
  1829. 0x39600, 0x39600,
  1830. 0x39608, 0x3960c,
  1831. 0x39a00, 0x39a1c,
  1832. 0x39e04, 0x39e20,
  1833. 0x39e38, 0x39e3c,
  1834. 0x39e80, 0x39e80,
  1835. 0x39e88, 0x39ea8,
  1836. 0x39eb0, 0x39eb4,
  1837. 0x39ec8, 0x39ed4,
  1838. 0x39fb8, 0x3a004,
  1839. 0x3a208, 0x3a23c,
  1840. 0x3a600, 0x3a630,
  1841. 0x3aa00, 0x3aabc,
  1842. 0x3ab00, 0x3ab70,
  1843. 0x3b000, 0x3b048,
  1844. 0x3b060, 0x3b09c,
  1845. 0x3b0f0, 0x3b148,
  1846. 0x3b160, 0x3b19c,
  1847. 0x3b1f0, 0x3b2e4,
  1848. 0x3b2f8, 0x3b3e4,
  1849. 0x3b3f8, 0x3b448,
  1850. 0x3b460, 0x3b49c,
  1851. 0x3b4f0, 0x3b548,
  1852. 0x3b560, 0x3b59c,
  1853. 0x3b5f0, 0x3b6e4,
  1854. 0x3b6f8, 0x3b7e4,
  1855. 0x3b7f8, 0x3b7fc,
  1856. 0x3b814, 0x3b814,
  1857. 0x3b82c, 0x3b82c,
  1858. 0x3b880, 0x3b88c,
  1859. 0x3b8e8, 0x3b8ec,
  1860. 0x3b900, 0x3b948,
  1861. 0x3b960, 0x3b99c,
  1862. 0x3b9f0, 0x3bae4,
  1863. 0x3baf8, 0x3bb10,
  1864. 0x3bb28, 0x3bb28,
  1865. 0x3bb3c, 0x3bb50,
  1866. 0x3bbf0, 0x3bc10,
  1867. 0x3bc28, 0x3bc28,
  1868. 0x3bc3c, 0x3bc50,
  1869. 0x3bcf0, 0x3bcfc,
  1870. 0x3c000, 0x3c030,
  1871. 0x3c100, 0x3c144,
  1872. 0x3c190, 0x3c1d0,
  1873. 0x3c200, 0x3c318,
  1874. 0x3c400, 0x3c52c,
  1875. 0x3c540, 0x3c61c,
  1876. 0x3c800, 0x3c834,
  1877. 0x3c8c0, 0x3c908,
  1878. 0x3c910, 0x3c9ac,
  1879. 0x3ca00, 0x3ca04,
  1880. 0x3ca0c, 0x3ca2c,
  1881. 0x3ca44, 0x3ca50,
  1882. 0x3ca74, 0x3cc24,
  1883. 0x3cd08, 0x3cd14,
  1884. 0x3cd1c, 0x3cd20,
  1885. 0x3cd3c, 0x3cd50,
  1886. 0x3d200, 0x3d20c,
  1887. 0x3d220, 0x3d220,
  1888. 0x3d240, 0x3d240,
  1889. 0x3d600, 0x3d600,
  1890. 0x3d608, 0x3d60c,
  1891. 0x3da00, 0x3da1c,
  1892. 0x3de04, 0x3de20,
  1893. 0x3de38, 0x3de3c,
  1894. 0x3de80, 0x3de80,
  1895. 0x3de88, 0x3dea8,
  1896. 0x3deb0, 0x3deb4,
  1897. 0x3dec8, 0x3ded4,
  1898. 0x3dfb8, 0x3e004,
  1899. 0x3e208, 0x3e23c,
  1900. 0x3e600, 0x3e630,
  1901. 0x3ea00, 0x3eabc,
  1902. 0x3eb00, 0x3eb70,
  1903. 0x3f000, 0x3f048,
  1904. 0x3f060, 0x3f09c,
  1905. 0x3f0f0, 0x3f148,
  1906. 0x3f160, 0x3f19c,
  1907. 0x3f1f0, 0x3f2e4,
  1908. 0x3f2f8, 0x3f3e4,
  1909. 0x3f3f8, 0x3f448,
  1910. 0x3f460, 0x3f49c,
  1911. 0x3f4f0, 0x3f548,
  1912. 0x3f560, 0x3f59c,
  1913. 0x3f5f0, 0x3f6e4,
  1914. 0x3f6f8, 0x3f7e4,
  1915. 0x3f7f8, 0x3f7fc,
  1916. 0x3f814, 0x3f814,
  1917. 0x3f82c, 0x3f82c,
  1918. 0x3f880, 0x3f88c,
  1919. 0x3f8e8, 0x3f8ec,
  1920. 0x3f900, 0x3f948,
  1921. 0x3f960, 0x3f99c,
  1922. 0x3f9f0, 0x3fae4,
  1923. 0x3faf8, 0x3fb10,
  1924. 0x3fb28, 0x3fb28,
  1925. 0x3fb3c, 0x3fb50,
  1926. 0x3fbf0, 0x3fc10,
  1927. 0x3fc28, 0x3fc28,
  1928. 0x3fc3c, 0x3fc50,
  1929. 0x3fcf0, 0x3fcfc,
  1930. 0x40000, 0x4000c,
  1931. 0x40040, 0x40068,
  1932. 0x40080, 0x40144,
  1933. 0x40180, 0x4018c,
  1934. 0x40200, 0x40298,
  1935. 0x402ac, 0x4033c,
  1936. 0x403f8, 0x403fc,
  1937. 0x41304, 0x413c4,
  1938. 0x41400, 0x4141c,
  1939. 0x41480, 0x414d0,
  1940. 0x44000, 0x44078,
  1941. 0x440c0, 0x44278,
  1942. 0x442c0, 0x44478,
  1943. 0x444c0, 0x44678,
  1944. 0x446c0, 0x44878,
  1945. 0x448c0, 0x449fc,
  1946. 0x45000, 0x45068,
  1947. 0x45080, 0x45084,
  1948. 0x450a0, 0x450b0,
  1949. 0x45200, 0x45268,
  1950. 0x45280, 0x45284,
  1951. 0x452a0, 0x452b0,
  1952. 0x460c0, 0x460e4,
  1953. 0x47000, 0x4708c,
  1954. 0x47200, 0x47250,
  1955. 0x47400, 0x47420,
  1956. 0x47600, 0x47618,
  1957. 0x47800, 0x47814,
  1958. 0x48000, 0x4800c,
  1959. 0x48040, 0x48068,
  1960. 0x48080, 0x48144,
  1961. 0x48180, 0x4818c,
  1962. 0x48200, 0x48298,
  1963. 0x482ac, 0x4833c,
  1964. 0x483f8, 0x483fc,
  1965. 0x49304, 0x493c4,
  1966. 0x49400, 0x4941c,
  1967. 0x49480, 0x494d0,
  1968. 0x4c000, 0x4c078,
  1969. 0x4c0c0, 0x4c278,
  1970. 0x4c2c0, 0x4c478,
  1971. 0x4c4c0, 0x4c678,
  1972. 0x4c6c0, 0x4c878,
  1973. 0x4c8c0, 0x4c9fc,
  1974. 0x4d000, 0x4d068,
  1975. 0x4d080, 0x4d084,
  1976. 0x4d0a0, 0x4d0b0,
  1977. 0x4d200, 0x4d268,
  1978. 0x4d280, 0x4d284,
  1979. 0x4d2a0, 0x4d2b0,
  1980. 0x4e0c0, 0x4e0e4,
  1981. 0x4f000, 0x4f08c,
  1982. 0x4f200, 0x4f250,
  1983. 0x4f400, 0x4f420,
  1984. 0x4f600, 0x4f618,
  1985. 0x4f800, 0x4f814,
  1986. 0x50000, 0x500cc,
  1987. 0x50400, 0x50400,
  1988. 0x50800, 0x508cc,
  1989. 0x50c00, 0x50c00,
  1990. 0x51000, 0x5101c,
  1991. 0x51300, 0x51308,
  1992. };
  1993. int i;
  1994. struct adapter *ap = netdev2adap(dev);
  1995. static const unsigned int *reg_ranges;
  1996. int arr_size = 0, buf_size = 0;
  1997. if (is_t4(ap->params.chip)) {
  1998. reg_ranges = &t4_reg_ranges[0];
  1999. arr_size = ARRAY_SIZE(t4_reg_ranges);
  2000. buf_size = T4_REGMAP_SIZE;
  2001. } else {
  2002. reg_ranges = &t5_reg_ranges[0];
  2003. arr_size = ARRAY_SIZE(t5_reg_ranges);
  2004. buf_size = T5_REGMAP_SIZE;
  2005. }
  2006. regs->version = mk_adap_vers(ap);
  2007. memset(buf, 0, buf_size);
  2008. for (i = 0; i < arr_size; i += 2)
  2009. reg_block_dump(ap, buf, reg_ranges[i], reg_ranges[i + 1]);
  2010. }
  2011. static int restart_autoneg(struct net_device *dev)
  2012. {
  2013. struct port_info *p = netdev_priv(dev);
  2014. if (!netif_running(dev))
  2015. return -EAGAIN;
  2016. if (p->link_cfg.autoneg != AUTONEG_ENABLE)
  2017. return -EINVAL;
  2018. t4_restart_aneg(p->adapter, p->adapter->fn, p->tx_chan);
  2019. return 0;
  2020. }
  2021. static int identify_port(struct net_device *dev,
  2022. enum ethtool_phys_id_state state)
  2023. {
  2024. unsigned int val;
  2025. struct adapter *adap = netdev2adap(dev);
  2026. if (state == ETHTOOL_ID_ACTIVE)
  2027. val = 0xffff;
  2028. else if (state == ETHTOOL_ID_INACTIVE)
  2029. val = 0;
  2030. else
  2031. return -EINVAL;
  2032. return t4_identify_port(adap, adap->fn, netdev2pinfo(dev)->viid, val);
  2033. }
  2034. static unsigned int from_fw_linkcaps(enum fw_port_type type, unsigned int caps)
  2035. {
  2036. unsigned int v = 0;
  2037. if (type == FW_PORT_TYPE_BT_SGMII || type == FW_PORT_TYPE_BT_XFI ||
  2038. type == FW_PORT_TYPE_BT_XAUI) {
  2039. v |= SUPPORTED_TP;
  2040. if (caps & FW_PORT_CAP_SPEED_100M)
  2041. v |= SUPPORTED_100baseT_Full;
  2042. if (caps & FW_PORT_CAP_SPEED_1G)
  2043. v |= SUPPORTED_1000baseT_Full;
  2044. if (caps & FW_PORT_CAP_SPEED_10G)
  2045. v |= SUPPORTED_10000baseT_Full;
  2046. } else if (type == FW_PORT_TYPE_KX4 || type == FW_PORT_TYPE_KX) {
  2047. v |= SUPPORTED_Backplane;
  2048. if (caps & FW_PORT_CAP_SPEED_1G)
  2049. v |= SUPPORTED_1000baseKX_Full;
  2050. if (caps & FW_PORT_CAP_SPEED_10G)
  2051. v |= SUPPORTED_10000baseKX4_Full;
  2052. } else if (type == FW_PORT_TYPE_KR)
  2053. v |= SUPPORTED_Backplane | SUPPORTED_10000baseKR_Full;
  2054. else if (type == FW_PORT_TYPE_BP_AP)
  2055. v |= SUPPORTED_Backplane | SUPPORTED_10000baseR_FEC |
  2056. SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full;
  2057. else if (type == FW_PORT_TYPE_BP4_AP)
  2058. v |= SUPPORTED_Backplane | SUPPORTED_10000baseR_FEC |
  2059. SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full |
  2060. SUPPORTED_10000baseKX4_Full;
  2061. else if (type == FW_PORT_TYPE_FIBER_XFI ||
  2062. type == FW_PORT_TYPE_FIBER_XAUI ||
  2063. type == FW_PORT_TYPE_SFP ||
  2064. type == FW_PORT_TYPE_QSFP_10G ||
  2065. type == FW_PORT_TYPE_QSA) {
  2066. v |= SUPPORTED_FIBRE;
  2067. if (caps & FW_PORT_CAP_SPEED_1G)
  2068. v |= SUPPORTED_1000baseT_Full;
  2069. if (caps & FW_PORT_CAP_SPEED_10G)
  2070. v |= SUPPORTED_10000baseT_Full;
  2071. } else if (type == FW_PORT_TYPE_BP40_BA ||
  2072. type == FW_PORT_TYPE_QSFP) {
  2073. v |= SUPPORTED_40000baseSR4_Full;
  2074. v |= SUPPORTED_FIBRE;
  2075. }
  2076. if (caps & FW_PORT_CAP_ANEG)
  2077. v |= SUPPORTED_Autoneg;
  2078. return v;
  2079. }
  2080. static unsigned int to_fw_linkcaps(unsigned int caps)
  2081. {
  2082. unsigned int v = 0;
  2083. if (caps & ADVERTISED_100baseT_Full)
  2084. v |= FW_PORT_CAP_SPEED_100M;
  2085. if (caps & ADVERTISED_1000baseT_Full)
  2086. v |= FW_PORT_CAP_SPEED_1G;
  2087. if (caps & ADVERTISED_10000baseT_Full)
  2088. v |= FW_PORT_CAP_SPEED_10G;
  2089. if (caps & ADVERTISED_40000baseSR4_Full)
  2090. v |= FW_PORT_CAP_SPEED_40G;
  2091. return v;
  2092. }
  2093. static int get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2094. {
  2095. const struct port_info *p = netdev_priv(dev);
  2096. if (p->port_type == FW_PORT_TYPE_BT_SGMII ||
  2097. p->port_type == FW_PORT_TYPE_BT_XFI ||
  2098. p->port_type == FW_PORT_TYPE_BT_XAUI)
  2099. cmd->port = PORT_TP;
  2100. else if (p->port_type == FW_PORT_TYPE_FIBER_XFI ||
  2101. p->port_type == FW_PORT_TYPE_FIBER_XAUI)
  2102. cmd->port = PORT_FIBRE;
  2103. else if (p->port_type == FW_PORT_TYPE_SFP ||
  2104. p->port_type == FW_PORT_TYPE_QSFP_10G ||
  2105. p->port_type == FW_PORT_TYPE_QSA ||
  2106. p->port_type == FW_PORT_TYPE_QSFP) {
  2107. if (p->mod_type == FW_PORT_MOD_TYPE_LR ||
  2108. p->mod_type == FW_PORT_MOD_TYPE_SR ||
  2109. p->mod_type == FW_PORT_MOD_TYPE_ER ||
  2110. p->mod_type == FW_PORT_MOD_TYPE_LRM)
  2111. cmd->port = PORT_FIBRE;
  2112. else if (p->mod_type == FW_PORT_MOD_TYPE_TWINAX_PASSIVE ||
  2113. p->mod_type == FW_PORT_MOD_TYPE_TWINAX_ACTIVE)
  2114. cmd->port = PORT_DA;
  2115. else
  2116. cmd->port = PORT_OTHER;
  2117. } else
  2118. cmd->port = PORT_OTHER;
  2119. if (p->mdio_addr >= 0) {
  2120. cmd->phy_address = p->mdio_addr;
  2121. cmd->transceiver = XCVR_EXTERNAL;
  2122. cmd->mdio_support = p->port_type == FW_PORT_TYPE_BT_SGMII ?
  2123. MDIO_SUPPORTS_C22 : MDIO_SUPPORTS_C45;
  2124. } else {
  2125. cmd->phy_address = 0; /* not really, but no better option */
  2126. cmd->transceiver = XCVR_INTERNAL;
  2127. cmd->mdio_support = 0;
  2128. }
  2129. cmd->supported = from_fw_linkcaps(p->port_type, p->link_cfg.supported);
  2130. cmd->advertising = from_fw_linkcaps(p->port_type,
  2131. p->link_cfg.advertising);
  2132. ethtool_cmd_speed_set(cmd,
  2133. netif_carrier_ok(dev) ? p->link_cfg.speed : 0);
  2134. cmd->duplex = DUPLEX_FULL;
  2135. cmd->autoneg = p->link_cfg.autoneg;
  2136. cmd->maxtxpkt = 0;
  2137. cmd->maxrxpkt = 0;
  2138. return 0;
  2139. }
  2140. static unsigned int speed_to_caps(int speed)
  2141. {
  2142. if (speed == 100)
  2143. return FW_PORT_CAP_SPEED_100M;
  2144. if (speed == 1000)
  2145. return FW_PORT_CAP_SPEED_1G;
  2146. if (speed == 10000)
  2147. return FW_PORT_CAP_SPEED_10G;
  2148. if (speed == 40000)
  2149. return FW_PORT_CAP_SPEED_40G;
  2150. return 0;
  2151. }
  2152. static int set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  2153. {
  2154. unsigned int cap;
  2155. struct port_info *p = netdev_priv(dev);
  2156. struct link_config *lc = &p->link_cfg;
  2157. u32 speed = ethtool_cmd_speed(cmd);
  2158. if (cmd->duplex != DUPLEX_FULL) /* only full-duplex supported */
  2159. return -EINVAL;
  2160. if (!(lc->supported & FW_PORT_CAP_ANEG)) {
  2161. /*
  2162. * PHY offers a single speed. See if that's what's
  2163. * being requested.
  2164. */
  2165. if (cmd->autoneg == AUTONEG_DISABLE &&
  2166. (lc->supported & speed_to_caps(speed)))
  2167. return 0;
  2168. return -EINVAL;
  2169. }
  2170. if (cmd->autoneg == AUTONEG_DISABLE) {
  2171. cap = speed_to_caps(speed);
  2172. if (!(lc->supported & cap) ||
  2173. (speed == 1000) ||
  2174. (speed == 10000) ||
  2175. (speed == 40000))
  2176. return -EINVAL;
  2177. lc->requested_speed = cap;
  2178. lc->advertising = 0;
  2179. } else {
  2180. cap = to_fw_linkcaps(cmd->advertising);
  2181. if (!(lc->supported & cap))
  2182. return -EINVAL;
  2183. lc->requested_speed = 0;
  2184. lc->advertising = cap | FW_PORT_CAP_ANEG;
  2185. }
  2186. lc->autoneg = cmd->autoneg;
  2187. if (netif_running(dev))
  2188. return t4_link_start(p->adapter, p->adapter->fn, p->tx_chan,
  2189. lc);
  2190. return 0;
  2191. }
  2192. static void get_pauseparam(struct net_device *dev,
  2193. struct ethtool_pauseparam *epause)
  2194. {
  2195. struct port_info *p = netdev_priv(dev);
  2196. epause->autoneg = (p->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
  2197. epause->rx_pause = (p->link_cfg.fc & PAUSE_RX) != 0;
  2198. epause->tx_pause = (p->link_cfg.fc & PAUSE_TX) != 0;
  2199. }
  2200. static int set_pauseparam(struct net_device *dev,
  2201. struct ethtool_pauseparam *epause)
  2202. {
  2203. struct port_info *p = netdev_priv(dev);
  2204. struct link_config *lc = &p->link_cfg;
  2205. if (epause->autoneg == AUTONEG_DISABLE)
  2206. lc->requested_fc = 0;
  2207. else if (lc->supported & FW_PORT_CAP_ANEG)
  2208. lc->requested_fc = PAUSE_AUTONEG;
  2209. else
  2210. return -EINVAL;
  2211. if (epause->rx_pause)
  2212. lc->requested_fc |= PAUSE_RX;
  2213. if (epause->tx_pause)
  2214. lc->requested_fc |= PAUSE_TX;
  2215. if (netif_running(dev))
  2216. return t4_link_start(p->adapter, p->adapter->fn, p->tx_chan,
  2217. lc);
  2218. return 0;
  2219. }
  2220. static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  2221. {
  2222. const struct port_info *pi = netdev_priv(dev);
  2223. const struct sge *s = &pi->adapter->sge;
  2224. e->rx_max_pending = MAX_RX_BUFFERS;
  2225. e->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
  2226. e->rx_jumbo_max_pending = 0;
  2227. e->tx_max_pending = MAX_TXQ_ENTRIES;
  2228. e->rx_pending = s->ethrxq[pi->first_qset].fl.size - 8;
  2229. e->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
  2230. e->rx_jumbo_pending = 0;
  2231. e->tx_pending = s->ethtxq[pi->first_qset].q.size;
  2232. }
  2233. static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
  2234. {
  2235. int i;
  2236. const struct port_info *pi = netdev_priv(dev);
  2237. struct adapter *adapter = pi->adapter;
  2238. struct sge *s = &adapter->sge;
  2239. if (e->rx_pending > MAX_RX_BUFFERS || e->rx_jumbo_pending ||
  2240. e->tx_pending > MAX_TXQ_ENTRIES ||
  2241. e->rx_mini_pending > MAX_RSPQ_ENTRIES ||
  2242. e->rx_mini_pending < MIN_RSPQ_ENTRIES ||
  2243. e->rx_pending < MIN_FL_ENTRIES || e->tx_pending < MIN_TXQ_ENTRIES)
  2244. return -EINVAL;
  2245. if (adapter->flags & FULL_INIT_DONE)
  2246. return -EBUSY;
  2247. for (i = 0; i < pi->nqsets; ++i) {
  2248. s->ethtxq[pi->first_qset + i].q.size = e->tx_pending;
  2249. s->ethrxq[pi->first_qset + i].fl.size = e->rx_pending + 8;
  2250. s->ethrxq[pi->first_qset + i].rspq.size = e->rx_mini_pending;
  2251. }
  2252. return 0;
  2253. }
  2254. static int closest_timer(const struct sge *s, int time)
  2255. {
  2256. int i, delta, match = 0, min_delta = INT_MAX;
  2257. for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
  2258. delta = time - s->timer_val[i];
  2259. if (delta < 0)
  2260. delta = -delta;
  2261. if (delta < min_delta) {
  2262. min_delta = delta;
  2263. match = i;
  2264. }
  2265. }
  2266. return match;
  2267. }
  2268. static int closest_thres(const struct sge *s, int thres)
  2269. {
  2270. int i, delta, match = 0, min_delta = INT_MAX;
  2271. for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
  2272. delta = thres - s->counter_val[i];
  2273. if (delta < 0)
  2274. delta = -delta;
  2275. if (delta < min_delta) {
  2276. min_delta = delta;
  2277. match = i;
  2278. }
  2279. }
  2280. return match;
  2281. }
  2282. /*
  2283. * Return a queue's interrupt hold-off time in us. 0 means no timer.
  2284. */
  2285. unsigned int qtimer_val(const struct adapter *adap,
  2286. const struct sge_rspq *q)
  2287. {
  2288. unsigned int idx = q->intr_params >> 1;
  2289. return idx < SGE_NTIMERS ? adap->sge.timer_val[idx] : 0;
  2290. }
  2291. /**
  2292. * set_rspq_intr_params - set a queue's interrupt holdoff parameters
  2293. * @q: the Rx queue
  2294. * @us: the hold-off time in us, or 0 to disable timer
  2295. * @cnt: the hold-off packet count, or 0 to disable counter
  2296. *
  2297. * Sets an Rx queue's interrupt hold-off time and packet count. At least
  2298. * one of the two needs to be enabled for the queue to generate interrupts.
  2299. */
  2300. static int set_rspq_intr_params(struct sge_rspq *q,
  2301. unsigned int us, unsigned int cnt)
  2302. {
  2303. struct adapter *adap = q->adap;
  2304. if ((us | cnt) == 0)
  2305. cnt = 1;
  2306. if (cnt) {
  2307. int err;
  2308. u32 v, new_idx;
  2309. new_idx = closest_thres(&adap->sge, cnt);
  2310. if (q->desc && q->pktcnt_idx != new_idx) {
  2311. /* the queue has already been created, update it */
  2312. v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  2313. FW_PARAMS_PARAM_X_V(
  2314. FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
  2315. FW_PARAMS_PARAM_YZ_V(q->cntxt_id);
  2316. err = t4_set_params(adap, adap->fn, adap->fn, 0, 1, &v,
  2317. &new_idx);
  2318. if (err)
  2319. return err;
  2320. }
  2321. q->pktcnt_idx = new_idx;
  2322. }
  2323. us = us == 0 ? 6 : closest_timer(&adap->sge, us);
  2324. q->intr_params = QINTR_TIMER_IDX(us) | (cnt > 0 ? QINTR_CNT_EN : 0);
  2325. return 0;
  2326. }
  2327. /**
  2328. * set_rx_intr_params - set a net devices's RX interrupt holdoff paramete!
  2329. * @dev: the network device
  2330. * @us: the hold-off time in us, or 0 to disable timer
  2331. * @cnt: the hold-off packet count, or 0 to disable counter
  2332. *
  2333. * Set the RX interrupt hold-off parameters for a network device.
  2334. */
  2335. static int set_rx_intr_params(struct net_device *dev,
  2336. unsigned int us, unsigned int cnt)
  2337. {
  2338. int i, err;
  2339. struct port_info *pi = netdev_priv(dev);
  2340. struct adapter *adap = pi->adapter;
  2341. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  2342. for (i = 0; i < pi->nqsets; i++, q++) {
  2343. err = set_rspq_intr_params(&q->rspq, us, cnt);
  2344. if (err)
  2345. return err;
  2346. }
  2347. return 0;
  2348. }
  2349. static int set_adaptive_rx_setting(struct net_device *dev, int adaptive_rx)
  2350. {
  2351. int i;
  2352. struct port_info *pi = netdev_priv(dev);
  2353. struct adapter *adap = pi->adapter;
  2354. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  2355. for (i = 0; i < pi->nqsets; i++, q++)
  2356. q->rspq.adaptive_rx = adaptive_rx;
  2357. return 0;
  2358. }
  2359. static int get_adaptive_rx_setting(struct net_device *dev)
  2360. {
  2361. struct port_info *pi = netdev_priv(dev);
  2362. struct adapter *adap = pi->adapter;
  2363. struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
  2364. return q->rspq.adaptive_rx;
  2365. }
  2366. static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  2367. {
  2368. set_adaptive_rx_setting(dev, c->use_adaptive_rx_coalesce);
  2369. return set_rx_intr_params(dev, c->rx_coalesce_usecs,
  2370. c->rx_max_coalesced_frames);
  2371. }
  2372. static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
  2373. {
  2374. const struct port_info *pi = netdev_priv(dev);
  2375. const struct adapter *adap = pi->adapter;
  2376. const struct sge_rspq *rq = &adap->sge.ethrxq[pi->first_qset].rspq;
  2377. c->rx_coalesce_usecs = qtimer_val(adap, rq);
  2378. c->rx_max_coalesced_frames = (rq->intr_params & QINTR_CNT_EN) ?
  2379. adap->sge.counter_val[rq->pktcnt_idx] : 0;
  2380. c->use_adaptive_rx_coalesce = get_adaptive_rx_setting(dev);
  2381. return 0;
  2382. }
  2383. /**
  2384. * eeprom_ptov - translate a physical EEPROM address to virtual
  2385. * @phys_addr: the physical EEPROM address
  2386. * @fn: the PCI function number
  2387. * @sz: size of function-specific area
  2388. *
  2389. * Translate a physical EEPROM address to virtual. The first 1K is
  2390. * accessed through virtual addresses starting at 31K, the rest is
  2391. * accessed through virtual addresses starting at 0.
  2392. *
  2393. * The mapping is as follows:
  2394. * [0..1K) -> [31K..32K)
  2395. * [1K..1K+A) -> [31K-A..31K)
  2396. * [1K+A..ES) -> [0..ES-A-1K)
  2397. *
  2398. * where A = @fn * @sz, and ES = EEPROM size.
  2399. */
  2400. static int eeprom_ptov(unsigned int phys_addr, unsigned int fn, unsigned int sz)
  2401. {
  2402. fn *= sz;
  2403. if (phys_addr < 1024)
  2404. return phys_addr + (31 << 10);
  2405. if (phys_addr < 1024 + fn)
  2406. return 31744 - fn + phys_addr - 1024;
  2407. if (phys_addr < EEPROMSIZE)
  2408. return phys_addr - 1024 - fn;
  2409. return -EINVAL;
  2410. }
  2411. /*
  2412. * The next two routines implement eeprom read/write from physical addresses.
  2413. */
  2414. static int eeprom_rd_phys(struct adapter *adap, unsigned int phys_addr, u32 *v)
  2415. {
  2416. int vaddr = eeprom_ptov(phys_addr, adap->fn, EEPROMPFSIZE);
  2417. if (vaddr >= 0)
  2418. vaddr = pci_read_vpd(adap->pdev, vaddr, sizeof(u32), v);
  2419. return vaddr < 0 ? vaddr : 0;
  2420. }
  2421. static int eeprom_wr_phys(struct adapter *adap, unsigned int phys_addr, u32 v)
  2422. {
  2423. int vaddr = eeprom_ptov(phys_addr, adap->fn, EEPROMPFSIZE);
  2424. if (vaddr >= 0)
  2425. vaddr = pci_write_vpd(adap->pdev, vaddr, sizeof(u32), &v);
  2426. return vaddr < 0 ? vaddr : 0;
  2427. }
  2428. #define EEPROM_MAGIC 0x38E2F10C
  2429. static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
  2430. u8 *data)
  2431. {
  2432. int i, err = 0;
  2433. struct adapter *adapter = netdev2adap(dev);
  2434. u8 *buf = kmalloc(EEPROMSIZE, GFP_KERNEL);
  2435. if (!buf)
  2436. return -ENOMEM;
  2437. e->magic = EEPROM_MAGIC;
  2438. for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4)
  2439. err = eeprom_rd_phys(adapter, i, (u32 *)&buf[i]);
  2440. if (!err)
  2441. memcpy(data, buf + e->offset, e->len);
  2442. kfree(buf);
  2443. return err;
  2444. }
  2445. static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  2446. u8 *data)
  2447. {
  2448. u8 *buf;
  2449. int err = 0;
  2450. u32 aligned_offset, aligned_len, *p;
  2451. struct adapter *adapter = netdev2adap(dev);
  2452. if (eeprom->magic != EEPROM_MAGIC)
  2453. return -EINVAL;
  2454. aligned_offset = eeprom->offset & ~3;
  2455. aligned_len = (eeprom->len + (eeprom->offset & 3) + 3) & ~3;
  2456. if (adapter->fn > 0) {
  2457. u32 start = 1024 + adapter->fn * EEPROMPFSIZE;
  2458. if (aligned_offset < start ||
  2459. aligned_offset + aligned_len > start + EEPROMPFSIZE)
  2460. return -EPERM;
  2461. }
  2462. if (aligned_offset != eeprom->offset || aligned_len != eeprom->len) {
  2463. /*
  2464. * RMW possibly needed for first or last words.
  2465. */
  2466. buf = kmalloc(aligned_len, GFP_KERNEL);
  2467. if (!buf)
  2468. return -ENOMEM;
  2469. err = eeprom_rd_phys(adapter, aligned_offset, (u32 *)buf);
  2470. if (!err && aligned_len > 4)
  2471. err = eeprom_rd_phys(adapter,
  2472. aligned_offset + aligned_len - 4,
  2473. (u32 *)&buf[aligned_len - 4]);
  2474. if (err)
  2475. goto out;
  2476. memcpy(buf + (eeprom->offset & 3), data, eeprom->len);
  2477. } else
  2478. buf = data;
  2479. err = t4_seeprom_wp(adapter, false);
  2480. if (err)
  2481. goto out;
  2482. for (p = (u32 *)buf; !err && aligned_len; aligned_len -= 4, p++) {
  2483. err = eeprom_wr_phys(adapter, aligned_offset, *p);
  2484. aligned_offset += 4;
  2485. }
  2486. if (!err)
  2487. err = t4_seeprom_wp(adapter, true);
  2488. out:
  2489. if (buf != data)
  2490. kfree(buf);
  2491. return err;
  2492. }
  2493. static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
  2494. {
  2495. int ret;
  2496. const struct firmware *fw;
  2497. struct adapter *adap = netdev2adap(netdev);
  2498. unsigned int mbox = PCIE_FW_MASTER_M + 1;
  2499. ef->data[sizeof(ef->data) - 1] = '\0';
  2500. ret = request_firmware(&fw, ef->data, adap->pdev_dev);
  2501. if (ret < 0)
  2502. return ret;
  2503. /* If the adapter has been fully initialized then we'll go ahead and
  2504. * try to get the firmware's cooperation in upgrading to the new
  2505. * firmware image otherwise we'll try to do the entire job from the
  2506. * host ... and we always "force" the operation in this path.
  2507. */
  2508. if (adap->flags & FULL_INIT_DONE)
  2509. mbox = adap->mbox;
  2510. ret = t4_fw_upgrade(adap, mbox, fw->data, fw->size, 1);
  2511. release_firmware(fw);
  2512. if (!ret)
  2513. dev_info(adap->pdev_dev, "loaded firmware %s,"
  2514. " reload cxgb4 driver\n", ef->data);
  2515. return ret;
  2516. }
  2517. #define WOL_SUPPORTED (WAKE_BCAST | WAKE_MAGIC)
  2518. #define BCAST_CRC 0xa0ccc1a6
  2519. static void get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  2520. {
  2521. wol->supported = WAKE_BCAST | WAKE_MAGIC;
  2522. wol->wolopts = netdev2adap(dev)->wol;
  2523. memset(&wol->sopass, 0, sizeof(wol->sopass));
  2524. }
  2525. static int set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  2526. {
  2527. int err = 0;
  2528. struct port_info *pi = netdev_priv(dev);
  2529. if (wol->wolopts & ~WOL_SUPPORTED)
  2530. return -EINVAL;
  2531. t4_wol_magic_enable(pi->adapter, pi->tx_chan,
  2532. (wol->wolopts & WAKE_MAGIC) ? dev->dev_addr : NULL);
  2533. if (wol->wolopts & WAKE_BCAST) {
  2534. err = t4_wol_pat_enable(pi->adapter, pi->tx_chan, 0xfe, ~0ULL,
  2535. ~0ULL, 0, false);
  2536. if (!err)
  2537. err = t4_wol_pat_enable(pi->adapter, pi->tx_chan, 1,
  2538. ~6ULL, ~0ULL, BCAST_CRC, true);
  2539. } else
  2540. t4_wol_pat_enable(pi->adapter, pi->tx_chan, 0, 0, 0, 0, false);
  2541. return err;
  2542. }
  2543. static int cxgb_set_features(struct net_device *dev, netdev_features_t features)
  2544. {
  2545. const struct port_info *pi = netdev_priv(dev);
  2546. netdev_features_t changed = dev->features ^ features;
  2547. int err;
  2548. if (!(changed & NETIF_F_HW_VLAN_CTAG_RX))
  2549. return 0;
  2550. err = t4_set_rxmode(pi->adapter, pi->adapter->fn, pi->viid, -1,
  2551. -1, -1, -1,
  2552. !!(features & NETIF_F_HW_VLAN_CTAG_RX), true);
  2553. if (unlikely(err))
  2554. dev->features = features ^ NETIF_F_HW_VLAN_CTAG_RX;
  2555. return err;
  2556. }
  2557. static u32 get_rss_table_size(struct net_device *dev)
  2558. {
  2559. const struct port_info *pi = netdev_priv(dev);
  2560. return pi->rss_size;
  2561. }
  2562. static int get_rss_table(struct net_device *dev, u32 *p, u8 *key, u8 *hfunc)
  2563. {
  2564. const struct port_info *pi = netdev_priv(dev);
  2565. unsigned int n = pi->rss_size;
  2566. if (hfunc)
  2567. *hfunc = ETH_RSS_HASH_TOP;
  2568. if (!p)
  2569. return 0;
  2570. while (n--)
  2571. p[n] = pi->rss[n];
  2572. return 0;
  2573. }
  2574. static int set_rss_table(struct net_device *dev, const u32 *p, const u8 *key,
  2575. const u8 hfunc)
  2576. {
  2577. unsigned int i;
  2578. struct port_info *pi = netdev_priv(dev);
  2579. /* We require at least one supported parameter to be changed and no
  2580. * change in any of the unsupported parameters
  2581. */
  2582. if (key ||
  2583. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  2584. return -EOPNOTSUPP;
  2585. if (!p)
  2586. return 0;
  2587. for (i = 0; i < pi->rss_size; i++)
  2588. pi->rss[i] = p[i];
  2589. if (pi->adapter->flags & FULL_INIT_DONE)
  2590. return write_rss(pi, pi->rss);
  2591. return 0;
  2592. }
  2593. static int get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
  2594. u32 *rules)
  2595. {
  2596. const struct port_info *pi = netdev_priv(dev);
  2597. switch (info->cmd) {
  2598. case ETHTOOL_GRXFH: {
  2599. unsigned int v = pi->rss_mode;
  2600. info->data = 0;
  2601. switch (info->flow_type) {
  2602. case TCP_V4_FLOW:
  2603. if (v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F)
  2604. info->data = RXH_IP_SRC | RXH_IP_DST |
  2605. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2606. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  2607. info->data = RXH_IP_SRC | RXH_IP_DST;
  2608. break;
  2609. case UDP_V4_FLOW:
  2610. if ((v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F) &&
  2611. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  2612. info->data = RXH_IP_SRC | RXH_IP_DST |
  2613. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2614. else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  2615. info->data = RXH_IP_SRC | RXH_IP_DST;
  2616. break;
  2617. case SCTP_V4_FLOW:
  2618. case AH_ESP_V4_FLOW:
  2619. case IPV4_FLOW:
  2620. if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
  2621. info->data = RXH_IP_SRC | RXH_IP_DST;
  2622. break;
  2623. case TCP_V6_FLOW:
  2624. if (v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F)
  2625. info->data = RXH_IP_SRC | RXH_IP_DST |
  2626. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2627. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  2628. info->data = RXH_IP_SRC | RXH_IP_DST;
  2629. break;
  2630. case UDP_V6_FLOW:
  2631. if ((v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F) &&
  2632. (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
  2633. info->data = RXH_IP_SRC | RXH_IP_DST |
  2634. RXH_L4_B_0_1 | RXH_L4_B_2_3;
  2635. else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  2636. info->data = RXH_IP_SRC | RXH_IP_DST;
  2637. break;
  2638. case SCTP_V6_FLOW:
  2639. case AH_ESP_V6_FLOW:
  2640. case IPV6_FLOW:
  2641. if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
  2642. info->data = RXH_IP_SRC | RXH_IP_DST;
  2643. break;
  2644. }
  2645. return 0;
  2646. }
  2647. case ETHTOOL_GRXRINGS:
  2648. info->data = pi->nqsets;
  2649. return 0;
  2650. }
  2651. return -EOPNOTSUPP;
  2652. }
  2653. static const struct ethtool_ops cxgb_ethtool_ops = {
  2654. .get_settings = get_settings,
  2655. .set_settings = set_settings,
  2656. .get_drvinfo = get_drvinfo,
  2657. .get_msglevel = get_msglevel,
  2658. .set_msglevel = set_msglevel,
  2659. .get_ringparam = get_sge_param,
  2660. .set_ringparam = set_sge_param,
  2661. .get_coalesce = get_coalesce,
  2662. .set_coalesce = set_coalesce,
  2663. .get_eeprom_len = get_eeprom_len,
  2664. .get_eeprom = get_eeprom,
  2665. .set_eeprom = set_eeprom,
  2666. .get_pauseparam = get_pauseparam,
  2667. .set_pauseparam = set_pauseparam,
  2668. .get_link = ethtool_op_get_link,
  2669. .get_strings = get_strings,
  2670. .set_phys_id = identify_port,
  2671. .nway_reset = restart_autoneg,
  2672. .get_sset_count = get_sset_count,
  2673. .get_ethtool_stats = get_stats,
  2674. .get_regs_len = get_regs_len,
  2675. .get_regs = get_regs,
  2676. .get_wol = get_wol,
  2677. .set_wol = set_wol,
  2678. .get_rxnfc = get_rxnfc,
  2679. .get_rxfh_indir_size = get_rss_table_size,
  2680. .get_rxfh = get_rss_table,
  2681. .set_rxfh = set_rss_table,
  2682. .flash_device = set_flash,
  2683. };
  2684. static int setup_debugfs(struct adapter *adap)
  2685. {
  2686. if (IS_ERR_OR_NULL(adap->debugfs_root))
  2687. return -1;
  2688. #ifdef CONFIG_DEBUG_FS
  2689. t4_setup_debugfs(adap);
  2690. #endif
  2691. return 0;
  2692. }
  2693. /*
  2694. * upper-layer driver support
  2695. */
  2696. /*
  2697. * Allocate an active-open TID and set it to the supplied value.
  2698. */
  2699. int cxgb4_alloc_atid(struct tid_info *t, void *data)
  2700. {
  2701. int atid = -1;
  2702. spin_lock_bh(&t->atid_lock);
  2703. if (t->afree) {
  2704. union aopen_entry *p = t->afree;
  2705. atid = (p - t->atid_tab) + t->atid_base;
  2706. t->afree = p->next;
  2707. p->data = data;
  2708. t->atids_in_use++;
  2709. }
  2710. spin_unlock_bh(&t->atid_lock);
  2711. return atid;
  2712. }
  2713. EXPORT_SYMBOL(cxgb4_alloc_atid);
  2714. /*
  2715. * Release an active-open TID.
  2716. */
  2717. void cxgb4_free_atid(struct tid_info *t, unsigned int atid)
  2718. {
  2719. union aopen_entry *p = &t->atid_tab[atid - t->atid_base];
  2720. spin_lock_bh(&t->atid_lock);
  2721. p->next = t->afree;
  2722. t->afree = p;
  2723. t->atids_in_use--;
  2724. spin_unlock_bh(&t->atid_lock);
  2725. }
  2726. EXPORT_SYMBOL(cxgb4_free_atid);
  2727. /*
  2728. * Allocate a server TID and set it to the supplied value.
  2729. */
  2730. int cxgb4_alloc_stid(struct tid_info *t, int family, void *data)
  2731. {
  2732. int stid;
  2733. spin_lock_bh(&t->stid_lock);
  2734. if (family == PF_INET) {
  2735. stid = find_first_zero_bit(t->stid_bmap, t->nstids);
  2736. if (stid < t->nstids)
  2737. __set_bit(stid, t->stid_bmap);
  2738. else
  2739. stid = -1;
  2740. } else {
  2741. stid = bitmap_find_free_region(t->stid_bmap, t->nstids, 2);
  2742. if (stid < 0)
  2743. stid = -1;
  2744. }
  2745. if (stid >= 0) {
  2746. t->stid_tab[stid].data = data;
  2747. stid += t->stid_base;
  2748. /* IPv6 requires max of 520 bits or 16 cells in TCAM
  2749. * This is equivalent to 4 TIDs. With CLIP enabled it
  2750. * needs 2 TIDs.
  2751. */
  2752. if (family == PF_INET)
  2753. t->stids_in_use++;
  2754. else
  2755. t->stids_in_use += 4;
  2756. }
  2757. spin_unlock_bh(&t->stid_lock);
  2758. return stid;
  2759. }
  2760. EXPORT_SYMBOL(cxgb4_alloc_stid);
  2761. /* Allocate a server filter TID and set it to the supplied value.
  2762. */
  2763. int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data)
  2764. {
  2765. int stid;
  2766. spin_lock_bh(&t->stid_lock);
  2767. if (family == PF_INET) {
  2768. stid = find_next_zero_bit(t->stid_bmap,
  2769. t->nstids + t->nsftids, t->nstids);
  2770. if (stid < (t->nstids + t->nsftids))
  2771. __set_bit(stid, t->stid_bmap);
  2772. else
  2773. stid = -1;
  2774. } else {
  2775. stid = -1;
  2776. }
  2777. if (stid >= 0) {
  2778. t->stid_tab[stid].data = data;
  2779. stid -= t->nstids;
  2780. stid += t->sftid_base;
  2781. t->stids_in_use++;
  2782. }
  2783. spin_unlock_bh(&t->stid_lock);
  2784. return stid;
  2785. }
  2786. EXPORT_SYMBOL(cxgb4_alloc_sftid);
  2787. /* Release a server TID.
  2788. */
  2789. void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family)
  2790. {
  2791. /* Is it a server filter TID? */
  2792. if (t->nsftids && (stid >= t->sftid_base)) {
  2793. stid -= t->sftid_base;
  2794. stid += t->nstids;
  2795. } else {
  2796. stid -= t->stid_base;
  2797. }
  2798. spin_lock_bh(&t->stid_lock);
  2799. if (family == PF_INET)
  2800. __clear_bit(stid, t->stid_bmap);
  2801. else
  2802. bitmap_release_region(t->stid_bmap, stid, 2);
  2803. t->stid_tab[stid].data = NULL;
  2804. if (family == PF_INET)
  2805. t->stids_in_use--;
  2806. else
  2807. t->stids_in_use -= 4;
  2808. spin_unlock_bh(&t->stid_lock);
  2809. }
  2810. EXPORT_SYMBOL(cxgb4_free_stid);
  2811. /*
  2812. * Populate a TID_RELEASE WR. Caller must properly size the skb.
  2813. */
  2814. static void mk_tid_release(struct sk_buff *skb, unsigned int chan,
  2815. unsigned int tid)
  2816. {
  2817. struct cpl_tid_release *req;
  2818. set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
  2819. req = (struct cpl_tid_release *)__skb_put(skb, sizeof(*req));
  2820. INIT_TP_WR(req, tid);
  2821. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
  2822. }
  2823. /*
  2824. * Queue a TID release request and if necessary schedule a work queue to
  2825. * process it.
  2826. */
  2827. static void cxgb4_queue_tid_release(struct tid_info *t, unsigned int chan,
  2828. unsigned int tid)
  2829. {
  2830. void **p = &t->tid_tab[tid];
  2831. struct adapter *adap = container_of(t, struct adapter, tids);
  2832. spin_lock_bh(&adap->tid_release_lock);
  2833. *p = adap->tid_release_head;
  2834. /* Low 2 bits encode the Tx channel number */
  2835. adap->tid_release_head = (void **)((uintptr_t)p | chan);
  2836. if (!adap->tid_release_task_busy) {
  2837. adap->tid_release_task_busy = true;
  2838. queue_work(adap->workq, &adap->tid_release_task);
  2839. }
  2840. spin_unlock_bh(&adap->tid_release_lock);
  2841. }
  2842. /*
  2843. * Process the list of pending TID release requests.
  2844. */
  2845. static void process_tid_release_list(struct work_struct *work)
  2846. {
  2847. struct sk_buff *skb;
  2848. struct adapter *adap;
  2849. adap = container_of(work, struct adapter, tid_release_task);
  2850. spin_lock_bh(&adap->tid_release_lock);
  2851. while (adap->tid_release_head) {
  2852. void **p = adap->tid_release_head;
  2853. unsigned int chan = (uintptr_t)p & 3;
  2854. p = (void *)p - chan;
  2855. adap->tid_release_head = *p;
  2856. *p = NULL;
  2857. spin_unlock_bh(&adap->tid_release_lock);
  2858. while (!(skb = alloc_skb(sizeof(struct cpl_tid_release),
  2859. GFP_KERNEL)))
  2860. schedule_timeout_uninterruptible(1);
  2861. mk_tid_release(skb, chan, p - adap->tids.tid_tab);
  2862. t4_ofld_send(adap, skb);
  2863. spin_lock_bh(&adap->tid_release_lock);
  2864. }
  2865. adap->tid_release_task_busy = false;
  2866. spin_unlock_bh(&adap->tid_release_lock);
  2867. }
  2868. /*
  2869. * Release a TID and inform HW. If we are unable to allocate the release
  2870. * message we defer to a work queue.
  2871. */
  2872. void cxgb4_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid)
  2873. {
  2874. void *old;
  2875. struct sk_buff *skb;
  2876. struct adapter *adap = container_of(t, struct adapter, tids);
  2877. old = t->tid_tab[tid];
  2878. skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
  2879. if (likely(skb)) {
  2880. t->tid_tab[tid] = NULL;
  2881. mk_tid_release(skb, chan, tid);
  2882. t4_ofld_send(adap, skb);
  2883. } else
  2884. cxgb4_queue_tid_release(t, chan, tid);
  2885. if (old)
  2886. atomic_dec(&t->tids_in_use);
  2887. }
  2888. EXPORT_SYMBOL(cxgb4_remove_tid);
  2889. /*
  2890. * Allocate and initialize the TID tables. Returns 0 on success.
  2891. */
  2892. static int tid_init(struct tid_info *t)
  2893. {
  2894. size_t size;
  2895. unsigned int stid_bmap_size;
  2896. unsigned int natids = t->natids;
  2897. struct adapter *adap = container_of(t, struct adapter, tids);
  2898. stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
  2899. size = t->ntids * sizeof(*t->tid_tab) +
  2900. natids * sizeof(*t->atid_tab) +
  2901. t->nstids * sizeof(*t->stid_tab) +
  2902. t->nsftids * sizeof(*t->stid_tab) +
  2903. stid_bmap_size * sizeof(long) +
  2904. t->nftids * sizeof(*t->ftid_tab) +
  2905. t->nsftids * sizeof(*t->ftid_tab);
  2906. t->tid_tab = t4_alloc_mem(size);
  2907. if (!t->tid_tab)
  2908. return -ENOMEM;
  2909. t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
  2910. t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
  2911. t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
  2912. t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
  2913. spin_lock_init(&t->stid_lock);
  2914. spin_lock_init(&t->atid_lock);
  2915. t->stids_in_use = 0;
  2916. t->afree = NULL;
  2917. t->atids_in_use = 0;
  2918. atomic_set(&t->tids_in_use, 0);
  2919. /* Setup the free list for atid_tab and clear the stid bitmap. */
  2920. if (natids) {
  2921. while (--natids)
  2922. t->atid_tab[natids - 1].next = &t->atid_tab[natids];
  2923. t->afree = t->atid_tab;
  2924. }
  2925. bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
  2926. /* Reserve stid 0 for T4/T5 adapters */
  2927. if (!t->stid_base &&
  2928. (is_t4(adap->params.chip) || is_t5(adap->params.chip)))
  2929. __set_bit(0, t->stid_bmap);
  2930. return 0;
  2931. }
  2932. /**
  2933. * cxgb4_create_server - create an IP server
  2934. * @dev: the device
  2935. * @stid: the server TID
  2936. * @sip: local IP address to bind server to
  2937. * @sport: the server's TCP port
  2938. * @queue: queue to direct messages from this server to
  2939. *
  2940. * Create an IP server for the given port and address.
  2941. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  2942. */
  2943. int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
  2944. __be32 sip, __be16 sport, __be16 vlan,
  2945. unsigned int queue)
  2946. {
  2947. unsigned int chan;
  2948. struct sk_buff *skb;
  2949. struct adapter *adap;
  2950. struct cpl_pass_open_req *req;
  2951. int ret;
  2952. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  2953. if (!skb)
  2954. return -ENOMEM;
  2955. adap = netdev2adap(dev);
  2956. req = (struct cpl_pass_open_req *)__skb_put(skb, sizeof(*req));
  2957. INIT_TP_WR(req, 0);
  2958. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, stid));
  2959. req->local_port = sport;
  2960. req->peer_port = htons(0);
  2961. req->local_ip = sip;
  2962. req->peer_ip = htonl(0);
  2963. chan = rxq_to_chan(&adap->sge, queue);
  2964. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  2965. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  2966. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  2967. ret = t4_mgmt_tx(adap, skb);
  2968. return net_xmit_eval(ret);
  2969. }
  2970. EXPORT_SYMBOL(cxgb4_create_server);
  2971. /* cxgb4_create_server6 - create an IPv6 server
  2972. * @dev: the device
  2973. * @stid: the server TID
  2974. * @sip: local IPv6 address to bind server to
  2975. * @sport: the server's TCP port
  2976. * @queue: queue to direct messages from this server to
  2977. *
  2978. * Create an IPv6 server for the given port and address.
  2979. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  2980. */
  2981. int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
  2982. const struct in6_addr *sip, __be16 sport,
  2983. unsigned int queue)
  2984. {
  2985. unsigned int chan;
  2986. struct sk_buff *skb;
  2987. struct adapter *adap;
  2988. struct cpl_pass_open_req6 *req;
  2989. int ret;
  2990. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  2991. if (!skb)
  2992. return -ENOMEM;
  2993. adap = netdev2adap(dev);
  2994. req = (struct cpl_pass_open_req6 *)__skb_put(skb, sizeof(*req));
  2995. INIT_TP_WR(req, 0);
  2996. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ6, stid));
  2997. req->local_port = sport;
  2998. req->peer_port = htons(0);
  2999. req->local_ip_hi = *(__be64 *)(sip->s6_addr);
  3000. req->local_ip_lo = *(__be64 *)(sip->s6_addr + 8);
  3001. req->peer_ip_hi = cpu_to_be64(0);
  3002. req->peer_ip_lo = cpu_to_be64(0);
  3003. chan = rxq_to_chan(&adap->sge, queue);
  3004. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  3005. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  3006. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  3007. ret = t4_mgmt_tx(adap, skb);
  3008. return net_xmit_eval(ret);
  3009. }
  3010. EXPORT_SYMBOL(cxgb4_create_server6);
  3011. int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
  3012. unsigned int queue, bool ipv6)
  3013. {
  3014. struct sk_buff *skb;
  3015. struct adapter *adap;
  3016. struct cpl_close_listsvr_req *req;
  3017. int ret;
  3018. adap = netdev2adap(dev);
  3019. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  3020. if (!skb)
  3021. return -ENOMEM;
  3022. req = (struct cpl_close_listsvr_req *)__skb_put(skb, sizeof(*req));
  3023. INIT_TP_WR(req, 0);
  3024. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, stid));
  3025. req->reply_ctrl = htons(NO_REPLY_V(0) | (ipv6 ? LISTSVR_IPV6_V(1) :
  3026. LISTSVR_IPV6_V(0)) | QUEUENO_V(queue));
  3027. ret = t4_mgmt_tx(adap, skb);
  3028. return net_xmit_eval(ret);
  3029. }
  3030. EXPORT_SYMBOL(cxgb4_remove_server);
  3031. /**
  3032. * cxgb4_best_mtu - find the entry in the MTU table closest to an MTU
  3033. * @mtus: the HW MTU table
  3034. * @mtu: the target MTU
  3035. * @idx: index of selected entry in the MTU table
  3036. *
  3037. * Returns the index and the value in the HW MTU table that is closest to
  3038. * but does not exceed @mtu, unless @mtu is smaller than any value in the
  3039. * table, in which case that smallest available value is selected.
  3040. */
  3041. unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
  3042. unsigned int *idx)
  3043. {
  3044. unsigned int i = 0;
  3045. while (i < NMTUS - 1 && mtus[i + 1] <= mtu)
  3046. ++i;
  3047. if (idx)
  3048. *idx = i;
  3049. return mtus[i];
  3050. }
  3051. EXPORT_SYMBOL(cxgb4_best_mtu);
  3052. /**
  3053. * cxgb4_best_aligned_mtu - find best MTU, [hopefully] data size aligned
  3054. * @mtus: the HW MTU table
  3055. * @header_size: Header Size
  3056. * @data_size_max: maximum Data Segment Size
  3057. * @data_size_align: desired Data Segment Size Alignment (2^N)
  3058. * @mtu_idxp: HW MTU Table Index return value pointer (possibly NULL)
  3059. *
  3060. * Similar to cxgb4_best_mtu() but instead of searching the Hardware
  3061. * MTU Table based solely on a Maximum MTU parameter, we break that
  3062. * parameter up into a Header Size and Maximum Data Segment Size, and
  3063. * provide a desired Data Segment Size Alignment. If we find an MTU in
  3064. * the Hardware MTU Table which will result in a Data Segment Size with
  3065. * the requested alignment _and_ that MTU isn't "too far" from the
  3066. * closest MTU, then we'll return that rather than the closest MTU.
  3067. */
  3068. unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
  3069. unsigned short header_size,
  3070. unsigned short data_size_max,
  3071. unsigned short data_size_align,
  3072. unsigned int *mtu_idxp)
  3073. {
  3074. unsigned short max_mtu = header_size + data_size_max;
  3075. unsigned short data_size_align_mask = data_size_align - 1;
  3076. int mtu_idx, aligned_mtu_idx;
  3077. /* Scan the MTU Table till we find an MTU which is larger than our
  3078. * Maximum MTU or we reach the end of the table. Along the way,
  3079. * record the last MTU found, if any, which will result in a Data
  3080. * Segment Length matching the requested alignment.
  3081. */
  3082. for (mtu_idx = 0, aligned_mtu_idx = -1; mtu_idx < NMTUS; mtu_idx++) {
  3083. unsigned short data_size = mtus[mtu_idx] - header_size;
  3084. /* If this MTU minus the Header Size would result in a
  3085. * Data Segment Size of the desired alignment, remember it.
  3086. */
  3087. if ((data_size & data_size_align_mask) == 0)
  3088. aligned_mtu_idx = mtu_idx;
  3089. /* If we're not at the end of the Hardware MTU Table and the
  3090. * next element is larger than our Maximum MTU, drop out of
  3091. * the loop.
  3092. */
  3093. if (mtu_idx+1 < NMTUS && mtus[mtu_idx+1] > max_mtu)
  3094. break;
  3095. }
  3096. /* If we fell out of the loop because we ran to the end of the table,
  3097. * then we just have to use the last [largest] entry.
  3098. */
  3099. if (mtu_idx == NMTUS)
  3100. mtu_idx--;
  3101. /* If we found an MTU which resulted in the requested Data Segment
  3102. * Length alignment and that's "not far" from the largest MTU which is
  3103. * less than or equal to the maximum MTU, then use that.
  3104. */
  3105. if (aligned_mtu_idx >= 0 &&
  3106. mtu_idx - aligned_mtu_idx <= 1)
  3107. mtu_idx = aligned_mtu_idx;
  3108. /* If the caller has passed in an MTU Index pointer, pass the
  3109. * MTU Index back. Return the MTU value.
  3110. */
  3111. if (mtu_idxp)
  3112. *mtu_idxp = mtu_idx;
  3113. return mtus[mtu_idx];
  3114. }
  3115. EXPORT_SYMBOL(cxgb4_best_aligned_mtu);
  3116. /**
  3117. * cxgb4_port_chan - get the HW channel of a port
  3118. * @dev: the net device for the port
  3119. *
  3120. * Return the HW Tx channel of the given port.
  3121. */
  3122. unsigned int cxgb4_port_chan(const struct net_device *dev)
  3123. {
  3124. return netdev2pinfo(dev)->tx_chan;
  3125. }
  3126. EXPORT_SYMBOL(cxgb4_port_chan);
  3127. unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
  3128. {
  3129. struct adapter *adap = netdev2adap(dev);
  3130. u32 v1, v2, lp_count, hp_count;
  3131. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  3132. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  3133. if (is_t4(adap->params.chip)) {
  3134. lp_count = LP_COUNT_G(v1);
  3135. hp_count = HP_COUNT_G(v1);
  3136. } else {
  3137. lp_count = LP_COUNT_T5_G(v1);
  3138. hp_count = HP_COUNT_T5_G(v2);
  3139. }
  3140. return lpfifo ? lp_count : hp_count;
  3141. }
  3142. EXPORT_SYMBOL(cxgb4_dbfifo_count);
  3143. /**
  3144. * cxgb4_port_viid - get the VI id of a port
  3145. * @dev: the net device for the port
  3146. *
  3147. * Return the VI id of the given port.
  3148. */
  3149. unsigned int cxgb4_port_viid(const struct net_device *dev)
  3150. {
  3151. return netdev2pinfo(dev)->viid;
  3152. }
  3153. EXPORT_SYMBOL(cxgb4_port_viid);
  3154. /**
  3155. * cxgb4_port_idx - get the index of a port
  3156. * @dev: the net device for the port
  3157. *
  3158. * Return the index of the given port.
  3159. */
  3160. unsigned int cxgb4_port_idx(const struct net_device *dev)
  3161. {
  3162. return netdev2pinfo(dev)->port_id;
  3163. }
  3164. EXPORT_SYMBOL(cxgb4_port_idx);
  3165. void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
  3166. struct tp_tcp_stats *v6)
  3167. {
  3168. struct adapter *adap = pci_get_drvdata(pdev);
  3169. spin_lock(&adap->stats_lock);
  3170. t4_tp_get_tcp_stats(adap, v4, v6);
  3171. spin_unlock(&adap->stats_lock);
  3172. }
  3173. EXPORT_SYMBOL(cxgb4_get_tcp_stats);
  3174. void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
  3175. const unsigned int *pgsz_order)
  3176. {
  3177. struct adapter *adap = netdev2adap(dev);
  3178. t4_write_reg(adap, ULP_RX_ISCSI_TAGMASK_A, tag_mask);
  3179. t4_write_reg(adap, ULP_RX_ISCSI_PSZ_A, HPZ0_V(pgsz_order[0]) |
  3180. HPZ1_V(pgsz_order[1]) | HPZ2_V(pgsz_order[2]) |
  3181. HPZ3_V(pgsz_order[3]));
  3182. }
  3183. EXPORT_SYMBOL(cxgb4_iscsi_init);
  3184. int cxgb4_flush_eq_cache(struct net_device *dev)
  3185. {
  3186. struct adapter *adap = netdev2adap(dev);
  3187. int ret;
  3188. ret = t4_fwaddrspace_write(adap, adap->mbox,
  3189. 0xe1000000 + SGE_CTXT_CMD_A, 0x20000000);
  3190. return ret;
  3191. }
  3192. EXPORT_SYMBOL(cxgb4_flush_eq_cache);
  3193. static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
  3194. {
  3195. u32 addr = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A) + 24 * qid + 8;
  3196. __be64 indices;
  3197. int ret;
  3198. spin_lock(&adap->win0_lock);
  3199. ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
  3200. sizeof(indices), (__be32 *)&indices,
  3201. T4_MEMORY_READ);
  3202. spin_unlock(&adap->win0_lock);
  3203. if (!ret) {
  3204. *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
  3205. *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
  3206. }
  3207. return ret;
  3208. }
  3209. int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx,
  3210. u16 size)
  3211. {
  3212. struct adapter *adap = netdev2adap(dev);
  3213. u16 hw_pidx, hw_cidx;
  3214. int ret;
  3215. ret = read_eq_indices(adap, qid, &hw_pidx, &hw_cidx);
  3216. if (ret)
  3217. goto out;
  3218. if (pidx != hw_pidx) {
  3219. u16 delta;
  3220. u32 val;
  3221. if (pidx >= hw_pidx)
  3222. delta = pidx - hw_pidx;
  3223. else
  3224. delta = size - hw_pidx + pidx;
  3225. if (is_t4(adap->params.chip))
  3226. val = PIDX_V(delta);
  3227. else
  3228. val = PIDX_T5_V(delta);
  3229. wmb();
  3230. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  3231. QID_V(qid) | val);
  3232. }
  3233. out:
  3234. return ret;
  3235. }
  3236. EXPORT_SYMBOL(cxgb4_sync_txq_pidx);
  3237. void cxgb4_disable_db_coalescing(struct net_device *dev)
  3238. {
  3239. struct adapter *adap;
  3240. adap = netdev2adap(dev);
  3241. t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, NOCOALESCE_F,
  3242. NOCOALESCE_F);
  3243. }
  3244. EXPORT_SYMBOL(cxgb4_disable_db_coalescing);
  3245. void cxgb4_enable_db_coalescing(struct net_device *dev)
  3246. {
  3247. struct adapter *adap;
  3248. adap = netdev2adap(dev);
  3249. t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, NOCOALESCE_F, 0);
  3250. }
  3251. EXPORT_SYMBOL(cxgb4_enable_db_coalescing);
  3252. int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte)
  3253. {
  3254. struct adapter *adap;
  3255. u32 offset, memtype, memaddr;
  3256. u32 edc0_size, edc1_size, mc0_size, mc1_size, size;
  3257. u32 edc0_end, edc1_end, mc0_end, mc1_end;
  3258. int ret;
  3259. adap = netdev2adap(dev);
  3260. offset = ((stag >> 8) * 32) + adap->vres.stag.start;
  3261. /* Figure out where the offset lands in the Memory Type/Address scheme.
  3262. * This code assumes that the memory is laid out starting at offset 0
  3263. * with no breaks as: EDC0, EDC1, MC0, MC1. All cards have both EDC0
  3264. * and EDC1. Some cards will have neither MC0 nor MC1, most cards have
  3265. * MC0, and some have both MC0 and MC1.
  3266. */
  3267. size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
  3268. edc0_size = EDRAM0_SIZE_G(size) << 20;
  3269. size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
  3270. edc1_size = EDRAM1_SIZE_G(size) << 20;
  3271. size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
  3272. mc0_size = EXT_MEM0_SIZE_G(size) << 20;
  3273. edc0_end = edc0_size;
  3274. edc1_end = edc0_end + edc1_size;
  3275. mc0_end = edc1_end + mc0_size;
  3276. if (offset < edc0_end) {
  3277. memtype = MEM_EDC0;
  3278. memaddr = offset;
  3279. } else if (offset < edc1_end) {
  3280. memtype = MEM_EDC1;
  3281. memaddr = offset - edc0_end;
  3282. } else {
  3283. if (offset < mc0_end) {
  3284. memtype = MEM_MC0;
  3285. memaddr = offset - edc1_end;
  3286. } else if (is_t4(adap->params.chip)) {
  3287. /* T4 only has a single memory channel */
  3288. goto err;
  3289. } else {
  3290. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  3291. mc1_size = EXT_MEM1_SIZE_G(size) << 20;
  3292. mc1_end = mc0_end + mc1_size;
  3293. if (offset < mc1_end) {
  3294. memtype = MEM_MC1;
  3295. memaddr = offset - mc0_end;
  3296. } else {
  3297. /* offset beyond the end of any memory */
  3298. goto err;
  3299. }
  3300. }
  3301. }
  3302. spin_lock(&adap->win0_lock);
  3303. ret = t4_memory_rw(adap, 0, memtype, memaddr, 32, tpte, T4_MEMORY_READ);
  3304. spin_unlock(&adap->win0_lock);
  3305. return ret;
  3306. err:
  3307. dev_err(adap->pdev_dev, "stag %#x, offset %#x out of range\n",
  3308. stag, offset);
  3309. return -EINVAL;
  3310. }
  3311. EXPORT_SYMBOL(cxgb4_read_tpte);
  3312. u64 cxgb4_read_sge_timestamp(struct net_device *dev)
  3313. {
  3314. u32 hi, lo;
  3315. struct adapter *adap;
  3316. adap = netdev2adap(dev);
  3317. lo = t4_read_reg(adap, SGE_TIMESTAMP_LO_A);
  3318. hi = TSVAL_G(t4_read_reg(adap, SGE_TIMESTAMP_HI_A));
  3319. return ((u64)hi << 32) | (u64)lo;
  3320. }
  3321. EXPORT_SYMBOL(cxgb4_read_sge_timestamp);
  3322. int cxgb4_bar2_sge_qregs(struct net_device *dev,
  3323. unsigned int qid,
  3324. enum cxgb4_bar2_qtype qtype,
  3325. u64 *pbar2_qoffset,
  3326. unsigned int *pbar2_qid)
  3327. {
  3328. return cxgb4_t4_bar2_sge_qregs(netdev2adap(dev),
  3329. qid,
  3330. (qtype == CXGB4_BAR2_QTYPE_EGRESS
  3331. ? T4_BAR2_QTYPE_EGRESS
  3332. : T4_BAR2_QTYPE_INGRESS),
  3333. pbar2_qoffset,
  3334. pbar2_qid);
  3335. }
  3336. EXPORT_SYMBOL(cxgb4_bar2_sge_qregs);
  3337. static struct pci_driver cxgb4_driver;
  3338. static void check_neigh_update(struct neighbour *neigh)
  3339. {
  3340. const struct device *parent;
  3341. const struct net_device *netdev = neigh->dev;
  3342. if (netdev->priv_flags & IFF_802_1Q_VLAN)
  3343. netdev = vlan_dev_real_dev(netdev);
  3344. parent = netdev->dev.parent;
  3345. if (parent && parent->driver == &cxgb4_driver.driver)
  3346. t4_l2t_update(dev_get_drvdata(parent), neigh);
  3347. }
  3348. static int netevent_cb(struct notifier_block *nb, unsigned long event,
  3349. void *data)
  3350. {
  3351. switch (event) {
  3352. case NETEVENT_NEIGH_UPDATE:
  3353. check_neigh_update(data);
  3354. break;
  3355. case NETEVENT_REDIRECT:
  3356. default:
  3357. break;
  3358. }
  3359. return 0;
  3360. }
  3361. static bool netevent_registered;
  3362. static struct notifier_block cxgb4_netevent_nb = {
  3363. .notifier_call = netevent_cb
  3364. };
  3365. static void drain_db_fifo(struct adapter *adap, int usecs)
  3366. {
  3367. u32 v1, v2, lp_count, hp_count;
  3368. do {
  3369. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  3370. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  3371. if (is_t4(adap->params.chip)) {
  3372. lp_count = LP_COUNT_G(v1);
  3373. hp_count = HP_COUNT_G(v1);
  3374. } else {
  3375. lp_count = LP_COUNT_T5_G(v1);
  3376. hp_count = HP_COUNT_T5_G(v2);
  3377. }
  3378. if (lp_count == 0 && hp_count == 0)
  3379. break;
  3380. set_current_state(TASK_UNINTERRUPTIBLE);
  3381. schedule_timeout(usecs_to_jiffies(usecs));
  3382. } while (1);
  3383. }
  3384. static void disable_txq_db(struct sge_txq *q)
  3385. {
  3386. unsigned long flags;
  3387. spin_lock_irqsave(&q->db_lock, flags);
  3388. q->db_disabled = 1;
  3389. spin_unlock_irqrestore(&q->db_lock, flags);
  3390. }
  3391. static void enable_txq_db(struct adapter *adap, struct sge_txq *q)
  3392. {
  3393. spin_lock_irq(&q->db_lock);
  3394. if (q->db_pidx_inc) {
  3395. /* Make sure that all writes to the TX descriptors
  3396. * are committed before we tell HW about them.
  3397. */
  3398. wmb();
  3399. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  3400. QID_V(q->cntxt_id) | PIDX_V(q->db_pidx_inc));
  3401. q->db_pidx_inc = 0;
  3402. }
  3403. q->db_disabled = 0;
  3404. spin_unlock_irq(&q->db_lock);
  3405. }
  3406. static void disable_dbs(struct adapter *adap)
  3407. {
  3408. int i;
  3409. for_each_ethrxq(&adap->sge, i)
  3410. disable_txq_db(&adap->sge.ethtxq[i].q);
  3411. for_each_ofldrxq(&adap->sge, i)
  3412. disable_txq_db(&adap->sge.ofldtxq[i].q);
  3413. for_each_port(adap, i)
  3414. disable_txq_db(&adap->sge.ctrlq[i].q);
  3415. }
  3416. static void enable_dbs(struct adapter *adap)
  3417. {
  3418. int i;
  3419. for_each_ethrxq(&adap->sge, i)
  3420. enable_txq_db(adap, &adap->sge.ethtxq[i].q);
  3421. for_each_ofldrxq(&adap->sge, i)
  3422. enable_txq_db(adap, &adap->sge.ofldtxq[i].q);
  3423. for_each_port(adap, i)
  3424. enable_txq_db(adap, &adap->sge.ctrlq[i].q);
  3425. }
  3426. static void notify_rdma_uld(struct adapter *adap, enum cxgb4_control cmd)
  3427. {
  3428. if (adap->uld_handle[CXGB4_ULD_RDMA])
  3429. ulds[CXGB4_ULD_RDMA].control(adap->uld_handle[CXGB4_ULD_RDMA],
  3430. cmd);
  3431. }
  3432. static void process_db_full(struct work_struct *work)
  3433. {
  3434. struct adapter *adap;
  3435. adap = container_of(work, struct adapter, db_full_task);
  3436. drain_db_fifo(adap, dbfifo_drain_delay);
  3437. enable_dbs(adap);
  3438. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  3439. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  3440. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F,
  3441. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F);
  3442. }
  3443. static void sync_txq_pidx(struct adapter *adap, struct sge_txq *q)
  3444. {
  3445. u16 hw_pidx, hw_cidx;
  3446. int ret;
  3447. spin_lock_irq(&q->db_lock);
  3448. ret = read_eq_indices(adap, (u16)q->cntxt_id, &hw_pidx, &hw_cidx);
  3449. if (ret)
  3450. goto out;
  3451. if (q->db_pidx != hw_pidx) {
  3452. u16 delta;
  3453. u32 val;
  3454. if (q->db_pidx >= hw_pidx)
  3455. delta = q->db_pidx - hw_pidx;
  3456. else
  3457. delta = q->size - hw_pidx + q->db_pidx;
  3458. if (is_t4(adap->params.chip))
  3459. val = PIDX_V(delta);
  3460. else
  3461. val = PIDX_T5_V(delta);
  3462. wmb();
  3463. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  3464. QID_V(q->cntxt_id) | val);
  3465. }
  3466. out:
  3467. q->db_disabled = 0;
  3468. q->db_pidx_inc = 0;
  3469. spin_unlock_irq(&q->db_lock);
  3470. if (ret)
  3471. CH_WARN(adap, "DB drop recovery failed.\n");
  3472. }
  3473. static void recover_all_queues(struct adapter *adap)
  3474. {
  3475. int i;
  3476. for_each_ethrxq(&adap->sge, i)
  3477. sync_txq_pidx(adap, &adap->sge.ethtxq[i].q);
  3478. for_each_ofldrxq(&adap->sge, i)
  3479. sync_txq_pidx(adap, &adap->sge.ofldtxq[i].q);
  3480. for_each_port(adap, i)
  3481. sync_txq_pidx(adap, &adap->sge.ctrlq[i].q);
  3482. }
  3483. static void process_db_drop(struct work_struct *work)
  3484. {
  3485. struct adapter *adap;
  3486. adap = container_of(work, struct adapter, db_drop_task);
  3487. if (is_t4(adap->params.chip)) {
  3488. drain_db_fifo(adap, dbfifo_drain_delay);
  3489. notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
  3490. drain_db_fifo(adap, dbfifo_drain_delay);
  3491. recover_all_queues(adap);
  3492. drain_db_fifo(adap, dbfifo_drain_delay);
  3493. enable_dbs(adap);
  3494. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  3495. } else {
  3496. u32 dropped_db = t4_read_reg(adap, 0x010ac);
  3497. u16 qid = (dropped_db >> 15) & 0x1ffff;
  3498. u16 pidx_inc = dropped_db & 0x1fff;
  3499. u64 bar2_qoffset;
  3500. unsigned int bar2_qid;
  3501. int ret;
  3502. ret = cxgb4_t4_bar2_sge_qregs(adap, qid, T4_BAR2_QTYPE_EGRESS,
  3503. &bar2_qoffset, &bar2_qid);
  3504. if (ret)
  3505. dev_err(adap->pdev_dev, "doorbell drop recovery: "
  3506. "qid=%d, pidx_inc=%d\n", qid, pidx_inc);
  3507. else
  3508. writel(PIDX_T5_V(pidx_inc) | QID_V(bar2_qid),
  3509. adap->bar2 + bar2_qoffset + SGE_UDB_KDOORBELL);
  3510. /* Re-enable BAR2 WC */
  3511. t4_set_reg_field(adap, 0x10b0, 1<<15, 1<<15);
  3512. }
  3513. t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, DROPPED_DB_F, 0);
  3514. }
  3515. void t4_db_full(struct adapter *adap)
  3516. {
  3517. if (is_t4(adap->params.chip)) {
  3518. disable_dbs(adap);
  3519. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  3520. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  3521. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F, 0);
  3522. queue_work(adap->workq, &adap->db_full_task);
  3523. }
  3524. }
  3525. void t4_db_dropped(struct adapter *adap)
  3526. {
  3527. if (is_t4(adap->params.chip)) {
  3528. disable_dbs(adap);
  3529. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  3530. }
  3531. queue_work(adap->workq, &adap->db_drop_task);
  3532. }
  3533. static void uld_attach(struct adapter *adap, unsigned int uld)
  3534. {
  3535. void *handle;
  3536. struct cxgb4_lld_info lli;
  3537. unsigned short i;
  3538. lli.pdev = adap->pdev;
  3539. lli.pf = adap->fn;
  3540. lli.l2t = adap->l2t;
  3541. lli.tids = &adap->tids;
  3542. lli.ports = adap->port;
  3543. lli.vr = &adap->vres;
  3544. lli.mtus = adap->params.mtus;
  3545. if (uld == CXGB4_ULD_RDMA) {
  3546. lli.rxq_ids = adap->sge.rdma_rxq;
  3547. lli.ciq_ids = adap->sge.rdma_ciq;
  3548. lli.nrxq = adap->sge.rdmaqs;
  3549. lli.nciq = adap->sge.rdmaciqs;
  3550. } else if (uld == CXGB4_ULD_ISCSI) {
  3551. lli.rxq_ids = adap->sge.ofld_rxq;
  3552. lli.nrxq = adap->sge.ofldqsets;
  3553. }
  3554. lli.ntxq = adap->sge.ofldqsets;
  3555. lli.nchan = adap->params.nports;
  3556. lli.nports = adap->params.nports;
  3557. lli.wr_cred = adap->params.ofldq_wr_cred;
  3558. lli.adapter_type = adap->params.chip;
  3559. lli.iscsi_iolen = MAXRXDATA_G(t4_read_reg(adap, TP_PARA_REG2_A));
  3560. lli.cclk_ps = 1000000000 / adap->params.vpd.cclk;
  3561. lli.udb_density = 1 << adap->params.sge.eq_qpp;
  3562. lli.ucq_density = 1 << adap->params.sge.iq_qpp;
  3563. lli.filt_mode = adap->params.tp.vlan_pri_map;
  3564. /* MODQ_REQ_MAP sets queues 0-3 to chan 0-3 */
  3565. for (i = 0; i < NCHAN; i++)
  3566. lli.tx_modq[i] = i;
  3567. lli.gts_reg = adap->regs + MYPF_REG(SGE_PF_GTS_A);
  3568. lli.db_reg = adap->regs + MYPF_REG(SGE_PF_KDOORBELL_A);
  3569. lli.fw_vers = adap->params.fw_vers;
  3570. lli.dbfifo_int_thresh = dbfifo_int_thresh;
  3571. lli.sge_ingpadboundary = adap->sge.fl_align;
  3572. lli.sge_egrstatuspagesize = adap->sge.stat_len;
  3573. lli.sge_pktshift = adap->sge.pktshift;
  3574. lli.enable_fw_ofld_conn = adap->flags & FW_OFLD_CONN;
  3575. lli.max_ordird_qp = adap->params.max_ordird_qp;
  3576. lli.max_ird_adapter = adap->params.max_ird_adapter;
  3577. lli.ulptx_memwrite_dsgl = adap->params.ulptx_memwrite_dsgl;
  3578. handle = ulds[uld].add(&lli);
  3579. if (IS_ERR(handle)) {
  3580. dev_warn(adap->pdev_dev,
  3581. "could not attach to the %s driver, error %ld\n",
  3582. uld_str[uld], PTR_ERR(handle));
  3583. return;
  3584. }
  3585. adap->uld_handle[uld] = handle;
  3586. if (!netevent_registered) {
  3587. register_netevent_notifier(&cxgb4_netevent_nb);
  3588. netevent_registered = true;
  3589. }
  3590. if (adap->flags & FULL_INIT_DONE)
  3591. ulds[uld].state_change(handle, CXGB4_STATE_UP);
  3592. }
  3593. static void attach_ulds(struct adapter *adap)
  3594. {
  3595. unsigned int i;
  3596. spin_lock(&adap_rcu_lock);
  3597. list_add_tail_rcu(&adap->rcu_node, &adap_rcu_list);
  3598. spin_unlock(&adap_rcu_lock);
  3599. mutex_lock(&uld_mutex);
  3600. list_add_tail(&adap->list_node, &adapter_list);
  3601. for (i = 0; i < CXGB4_ULD_MAX; i++)
  3602. if (ulds[i].add)
  3603. uld_attach(adap, i);
  3604. mutex_unlock(&uld_mutex);
  3605. }
  3606. static void detach_ulds(struct adapter *adap)
  3607. {
  3608. unsigned int i;
  3609. mutex_lock(&uld_mutex);
  3610. list_del(&adap->list_node);
  3611. for (i = 0; i < CXGB4_ULD_MAX; i++)
  3612. if (adap->uld_handle[i]) {
  3613. ulds[i].state_change(adap->uld_handle[i],
  3614. CXGB4_STATE_DETACH);
  3615. adap->uld_handle[i] = NULL;
  3616. }
  3617. if (netevent_registered && list_empty(&adapter_list)) {
  3618. unregister_netevent_notifier(&cxgb4_netevent_nb);
  3619. netevent_registered = false;
  3620. }
  3621. mutex_unlock(&uld_mutex);
  3622. spin_lock(&adap_rcu_lock);
  3623. list_del_rcu(&adap->rcu_node);
  3624. spin_unlock(&adap_rcu_lock);
  3625. }
  3626. static void notify_ulds(struct adapter *adap, enum cxgb4_state new_state)
  3627. {
  3628. unsigned int i;
  3629. mutex_lock(&uld_mutex);
  3630. for (i = 0; i < CXGB4_ULD_MAX; i++)
  3631. if (adap->uld_handle[i])
  3632. ulds[i].state_change(adap->uld_handle[i], new_state);
  3633. mutex_unlock(&uld_mutex);
  3634. }
  3635. /**
  3636. * cxgb4_register_uld - register an upper-layer driver
  3637. * @type: the ULD type
  3638. * @p: the ULD methods
  3639. *
  3640. * Registers an upper-layer driver with this driver and notifies the ULD
  3641. * about any presently available devices that support its type. Returns
  3642. * %-EBUSY if a ULD of the same type is already registered.
  3643. */
  3644. int cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p)
  3645. {
  3646. int ret = 0;
  3647. struct adapter *adap;
  3648. if (type >= CXGB4_ULD_MAX)
  3649. return -EINVAL;
  3650. mutex_lock(&uld_mutex);
  3651. if (ulds[type].add) {
  3652. ret = -EBUSY;
  3653. goto out;
  3654. }
  3655. ulds[type] = *p;
  3656. list_for_each_entry(adap, &adapter_list, list_node)
  3657. uld_attach(adap, type);
  3658. out: mutex_unlock(&uld_mutex);
  3659. return ret;
  3660. }
  3661. EXPORT_SYMBOL(cxgb4_register_uld);
  3662. /**
  3663. * cxgb4_unregister_uld - unregister an upper-layer driver
  3664. * @type: the ULD type
  3665. *
  3666. * Unregisters an existing upper-layer driver.
  3667. */
  3668. int cxgb4_unregister_uld(enum cxgb4_uld type)
  3669. {
  3670. struct adapter *adap;
  3671. if (type >= CXGB4_ULD_MAX)
  3672. return -EINVAL;
  3673. mutex_lock(&uld_mutex);
  3674. list_for_each_entry(adap, &adapter_list, list_node)
  3675. adap->uld_handle[type] = NULL;
  3676. ulds[type].add = NULL;
  3677. mutex_unlock(&uld_mutex);
  3678. return 0;
  3679. }
  3680. EXPORT_SYMBOL(cxgb4_unregister_uld);
  3681. #if IS_ENABLED(CONFIG_IPV6)
  3682. static int cxgb4_inet6addr_handler(struct notifier_block *this,
  3683. unsigned long event, void *data)
  3684. {
  3685. struct inet6_ifaddr *ifa = data;
  3686. struct net_device *event_dev = ifa->idev->dev;
  3687. const struct device *parent = NULL;
  3688. #if IS_ENABLED(CONFIG_BONDING)
  3689. struct adapter *adap;
  3690. #endif
  3691. if (event_dev->priv_flags & IFF_802_1Q_VLAN)
  3692. event_dev = vlan_dev_real_dev(event_dev);
  3693. #if IS_ENABLED(CONFIG_BONDING)
  3694. if (event_dev->flags & IFF_MASTER) {
  3695. list_for_each_entry(adap, &adapter_list, list_node) {
  3696. switch (event) {
  3697. case NETDEV_UP:
  3698. cxgb4_clip_get(adap->port[0],
  3699. (const u32 *)ifa, 1);
  3700. break;
  3701. case NETDEV_DOWN:
  3702. cxgb4_clip_release(adap->port[0],
  3703. (const u32 *)ifa, 1);
  3704. break;
  3705. default:
  3706. break;
  3707. }
  3708. }
  3709. return NOTIFY_OK;
  3710. }
  3711. #endif
  3712. if (event_dev)
  3713. parent = event_dev->dev.parent;
  3714. if (parent && parent->driver == &cxgb4_driver.driver) {
  3715. switch (event) {
  3716. case NETDEV_UP:
  3717. cxgb4_clip_get(event_dev, (const u32 *)ifa, 1);
  3718. break;
  3719. case NETDEV_DOWN:
  3720. cxgb4_clip_release(event_dev, (const u32 *)ifa, 1);
  3721. break;
  3722. default:
  3723. break;
  3724. }
  3725. }
  3726. return NOTIFY_OK;
  3727. }
  3728. static bool inet6addr_registered;
  3729. static struct notifier_block cxgb4_inet6addr_notifier = {
  3730. .notifier_call = cxgb4_inet6addr_handler
  3731. };
  3732. static void update_clip(const struct adapter *adap)
  3733. {
  3734. int i;
  3735. struct net_device *dev;
  3736. int ret;
  3737. rcu_read_lock();
  3738. for (i = 0; i < MAX_NPORTS; i++) {
  3739. dev = adap->port[i];
  3740. ret = 0;
  3741. if (dev)
  3742. ret = cxgb4_update_root_dev_clip(dev);
  3743. if (ret < 0)
  3744. break;
  3745. }
  3746. rcu_read_unlock();
  3747. }
  3748. #endif /* IS_ENABLED(CONFIG_IPV6) */
  3749. /**
  3750. * cxgb_up - enable the adapter
  3751. * @adap: adapter being enabled
  3752. *
  3753. * Called when the first port is enabled, this function performs the
  3754. * actions necessary to make an adapter operational, such as completing
  3755. * the initialization of HW modules, and enabling interrupts.
  3756. *
  3757. * Must be called with the rtnl lock held.
  3758. */
  3759. static int cxgb_up(struct adapter *adap)
  3760. {
  3761. int err;
  3762. err = setup_sge_queues(adap);
  3763. if (err)
  3764. goto out;
  3765. err = setup_rss(adap);
  3766. if (err)
  3767. goto freeq;
  3768. if (adap->flags & USING_MSIX) {
  3769. name_msix_vecs(adap);
  3770. err = request_irq(adap->msix_info[0].vec, t4_nondata_intr, 0,
  3771. adap->msix_info[0].desc, adap);
  3772. if (err)
  3773. goto irq_err;
  3774. err = request_msix_queue_irqs(adap);
  3775. if (err) {
  3776. free_irq(adap->msix_info[0].vec, adap);
  3777. goto irq_err;
  3778. }
  3779. } else {
  3780. err = request_irq(adap->pdev->irq, t4_intr_handler(adap),
  3781. (adap->flags & USING_MSI) ? 0 : IRQF_SHARED,
  3782. adap->port[0]->name, adap);
  3783. if (err)
  3784. goto irq_err;
  3785. }
  3786. enable_rx(adap);
  3787. t4_sge_start(adap);
  3788. t4_intr_enable(adap);
  3789. adap->flags |= FULL_INIT_DONE;
  3790. notify_ulds(adap, CXGB4_STATE_UP);
  3791. #if IS_ENABLED(CONFIG_IPV6)
  3792. update_clip(adap);
  3793. #endif
  3794. out:
  3795. return err;
  3796. irq_err:
  3797. dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
  3798. freeq:
  3799. t4_free_sge_resources(adap);
  3800. goto out;
  3801. }
  3802. static void cxgb_down(struct adapter *adapter)
  3803. {
  3804. t4_intr_disable(adapter);
  3805. cancel_work_sync(&adapter->tid_release_task);
  3806. cancel_work_sync(&adapter->db_full_task);
  3807. cancel_work_sync(&adapter->db_drop_task);
  3808. adapter->tid_release_task_busy = false;
  3809. adapter->tid_release_head = NULL;
  3810. if (adapter->flags & USING_MSIX) {
  3811. free_msix_queue_irqs(adapter);
  3812. free_irq(adapter->msix_info[0].vec, adapter);
  3813. } else
  3814. free_irq(adapter->pdev->irq, adapter);
  3815. quiesce_rx(adapter);
  3816. t4_sge_stop(adapter);
  3817. t4_free_sge_resources(adapter);
  3818. adapter->flags &= ~FULL_INIT_DONE;
  3819. }
  3820. /*
  3821. * net_device operations
  3822. */
  3823. static int cxgb_open(struct net_device *dev)
  3824. {
  3825. int err;
  3826. struct port_info *pi = netdev_priv(dev);
  3827. struct adapter *adapter = pi->adapter;
  3828. netif_carrier_off(dev);
  3829. if (!(adapter->flags & FULL_INIT_DONE)) {
  3830. err = cxgb_up(adapter);
  3831. if (err < 0)
  3832. return err;
  3833. }
  3834. err = link_start(dev);
  3835. if (!err)
  3836. netif_tx_start_all_queues(dev);
  3837. return err;
  3838. }
  3839. static int cxgb_close(struct net_device *dev)
  3840. {
  3841. struct port_info *pi = netdev_priv(dev);
  3842. struct adapter *adapter = pi->adapter;
  3843. netif_tx_stop_all_queues(dev);
  3844. netif_carrier_off(dev);
  3845. return t4_enable_vi(adapter, adapter->fn, pi->viid, false, false);
  3846. }
  3847. /* Return an error number if the indicated filter isn't writable ...
  3848. */
  3849. static int writable_filter(struct filter_entry *f)
  3850. {
  3851. if (f->locked)
  3852. return -EPERM;
  3853. if (f->pending)
  3854. return -EBUSY;
  3855. return 0;
  3856. }
  3857. /* Delete the filter at the specified index (if valid). The checks for all
  3858. * the common problems with doing this like the filter being locked, currently
  3859. * pending in another operation, etc.
  3860. */
  3861. static int delete_filter(struct adapter *adapter, unsigned int fidx)
  3862. {
  3863. struct filter_entry *f;
  3864. int ret;
  3865. if (fidx >= adapter->tids.nftids + adapter->tids.nsftids)
  3866. return -EINVAL;
  3867. f = &adapter->tids.ftid_tab[fidx];
  3868. ret = writable_filter(f);
  3869. if (ret)
  3870. return ret;
  3871. if (f->valid)
  3872. return del_filter_wr(adapter, fidx);
  3873. return 0;
  3874. }
  3875. int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
  3876. __be32 sip, __be16 sport, __be16 vlan,
  3877. unsigned int queue, unsigned char port, unsigned char mask)
  3878. {
  3879. int ret;
  3880. struct filter_entry *f;
  3881. struct adapter *adap;
  3882. int i;
  3883. u8 *val;
  3884. adap = netdev2adap(dev);
  3885. /* Adjust stid to correct filter index */
  3886. stid -= adap->tids.sftid_base;
  3887. stid += adap->tids.nftids;
  3888. /* Check to make sure the filter requested is writable ...
  3889. */
  3890. f = &adap->tids.ftid_tab[stid];
  3891. ret = writable_filter(f);
  3892. if (ret)
  3893. return ret;
  3894. /* Clear out any old resources being used by the filter before
  3895. * we start constructing the new filter.
  3896. */
  3897. if (f->valid)
  3898. clear_filter(adap, f);
  3899. /* Clear out filter specifications */
  3900. memset(&f->fs, 0, sizeof(struct ch_filter_specification));
  3901. f->fs.val.lport = cpu_to_be16(sport);
  3902. f->fs.mask.lport = ~0;
  3903. val = (u8 *)&sip;
  3904. if ((val[0] | val[1] | val[2] | val[3]) != 0) {
  3905. for (i = 0; i < 4; i++) {
  3906. f->fs.val.lip[i] = val[i];
  3907. f->fs.mask.lip[i] = ~0;
  3908. }
  3909. if (adap->params.tp.vlan_pri_map & PORT_F) {
  3910. f->fs.val.iport = port;
  3911. f->fs.mask.iport = mask;
  3912. }
  3913. }
  3914. if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
  3915. f->fs.val.proto = IPPROTO_TCP;
  3916. f->fs.mask.proto = ~0;
  3917. }
  3918. f->fs.dirsteer = 1;
  3919. f->fs.iq = queue;
  3920. /* Mark filter as locked */
  3921. f->locked = 1;
  3922. f->fs.rpttid = 1;
  3923. ret = set_filter_wr(adap, stid);
  3924. if (ret) {
  3925. clear_filter(adap, f);
  3926. return ret;
  3927. }
  3928. return 0;
  3929. }
  3930. EXPORT_SYMBOL(cxgb4_create_server_filter);
  3931. int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
  3932. unsigned int queue, bool ipv6)
  3933. {
  3934. int ret;
  3935. struct filter_entry *f;
  3936. struct adapter *adap;
  3937. adap = netdev2adap(dev);
  3938. /* Adjust stid to correct filter index */
  3939. stid -= adap->tids.sftid_base;
  3940. stid += adap->tids.nftids;
  3941. f = &adap->tids.ftid_tab[stid];
  3942. /* Unlock the filter */
  3943. f->locked = 0;
  3944. ret = delete_filter(adap, stid);
  3945. if (ret)
  3946. return ret;
  3947. return 0;
  3948. }
  3949. EXPORT_SYMBOL(cxgb4_remove_server_filter);
  3950. static struct rtnl_link_stats64 *cxgb_get_stats(struct net_device *dev,
  3951. struct rtnl_link_stats64 *ns)
  3952. {
  3953. struct port_stats stats;
  3954. struct port_info *p = netdev_priv(dev);
  3955. struct adapter *adapter = p->adapter;
  3956. /* Block retrieving statistics during EEH error
  3957. * recovery. Otherwise, the recovery might fail
  3958. * and the PCI device will be removed permanently
  3959. */
  3960. spin_lock(&adapter->stats_lock);
  3961. if (!netif_device_present(dev)) {
  3962. spin_unlock(&adapter->stats_lock);
  3963. return ns;
  3964. }
  3965. t4_get_port_stats(adapter, p->tx_chan, &stats);
  3966. spin_unlock(&adapter->stats_lock);
  3967. ns->tx_bytes = stats.tx_octets;
  3968. ns->tx_packets = stats.tx_frames;
  3969. ns->rx_bytes = stats.rx_octets;
  3970. ns->rx_packets = stats.rx_frames;
  3971. ns->multicast = stats.rx_mcast_frames;
  3972. /* detailed rx_errors */
  3973. ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
  3974. stats.rx_runt;
  3975. ns->rx_over_errors = 0;
  3976. ns->rx_crc_errors = stats.rx_fcs_err;
  3977. ns->rx_frame_errors = stats.rx_symbol_err;
  3978. ns->rx_fifo_errors = stats.rx_ovflow0 + stats.rx_ovflow1 +
  3979. stats.rx_ovflow2 + stats.rx_ovflow3 +
  3980. stats.rx_trunc0 + stats.rx_trunc1 +
  3981. stats.rx_trunc2 + stats.rx_trunc3;
  3982. ns->rx_missed_errors = 0;
  3983. /* detailed tx_errors */
  3984. ns->tx_aborted_errors = 0;
  3985. ns->tx_carrier_errors = 0;
  3986. ns->tx_fifo_errors = 0;
  3987. ns->tx_heartbeat_errors = 0;
  3988. ns->tx_window_errors = 0;
  3989. ns->tx_errors = stats.tx_error_frames;
  3990. ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
  3991. ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
  3992. return ns;
  3993. }
  3994. static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  3995. {
  3996. unsigned int mbox;
  3997. int ret = 0, prtad, devad;
  3998. struct port_info *pi = netdev_priv(dev);
  3999. struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
  4000. switch (cmd) {
  4001. case SIOCGMIIPHY:
  4002. if (pi->mdio_addr < 0)
  4003. return -EOPNOTSUPP;
  4004. data->phy_id = pi->mdio_addr;
  4005. break;
  4006. case SIOCGMIIREG:
  4007. case SIOCSMIIREG:
  4008. if (mdio_phy_id_is_c45(data->phy_id)) {
  4009. prtad = mdio_phy_id_prtad(data->phy_id);
  4010. devad = mdio_phy_id_devad(data->phy_id);
  4011. } else if (data->phy_id < 32) {
  4012. prtad = data->phy_id;
  4013. devad = 0;
  4014. data->reg_num &= 0x1f;
  4015. } else
  4016. return -EINVAL;
  4017. mbox = pi->adapter->fn;
  4018. if (cmd == SIOCGMIIREG)
  4019. ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
  4020. data->reg_num, &data->val_out);
  4021. else
  4022. ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
  4023. data->reg_num, data->val_in);
  4024. break;
  4025. default:
  4026. return -EOPNOTSUPP;
  4027. }
  4028. return ret;
  4029. }
  4030. static void cxgb_set_rxmode(struct net_device *dev)
  4031. {
  4032. /* unfortunately we can't return errors to the stack */
  4033. set_rxmode(dev, -1, false);
  4034. }
  4035. static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
  4036. {
  4037. int ret;
  4038. struct port_info *pi = netdev_priv(dev);
  4039. if (new_mtu < 81 || new_mtu > MAX_MTU) /* accommodate SACK */
  4040. return -EINVAL;
  4041. ret = t4_set_rxmode(pi->adapter, pi->adapter->fn, pi->viid, new_mtu, -1,
  4042. -1, -1, -1, true);
  4043. if (!ret)
  4044. dev->mtu = new_mtu;
  4045. return ret;
  4046. }
  4047. static int cxgb_set_mac_addr(struct net_device *dev, void *p)
  4048. {
  4049. int ret;
  4050. struct sockaddr *addr = p;
  4051. struct port_info *pi = netdev_priv(dev);
  4052. if (!is_valid_ether_addr(addr->sa_data))
  4053. return -EADDRNOTAVAIL;
  4054. ret = t4_change_mac(pi->adapter, pi->adapter->fn, pi->viid,
  4055. pi->xact_addr_filt, addr->sa_data, true, true);
  4056. if (ret < 0)
  4057. return ret;
  4058. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4059. pi->xact_addr_filt = ret;
  4060. return 0;
  4061. }
  4062. #ifdef CONFIG_NET_POLL_CONTROLLER
  4063. static void cxgb_netpoll(struct net_device *dev)
  4064. {
  4065. struct port_info *pi = netdev_priv(dev);
  4066. struct adapter *adap = pi->adapter;
  4067. if (adap->flags & USING_MSIX) {
  4068. int i;
  4069. struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
  4070. for (i = pi->nqsets; i; i--, rx++)
  4071. t4_sge_intr_msix(0, &rx->rspq);
  4072. } else
  4073. t4_intr_handler(adap)(0, adap);
  4074. }
  4075. #endif
  4076. static const struct net_device_ops cxgb4_netdev_ops = {
  4077. .ndo_open = cxgb_open,
  4078. .ndo_stop = cxgb_close,
  4079. .ndo_start_xmit = t4_eth_xmit,
  4080. .ndo_select_queue = cxgb_select_queue,
  4081. .ndo_get_stats64 = cxgb_get_stats,
  4082. .ndo_set_rx_mode = cxgb_set_rxmode,
  4083. .ndo_set_mac_address = cxgb_set_mac_addr,
  4084. .ndo_set_features = cxgb_set_features,
  4085. .ndo_validate_addr = eth_validate_addr,
  4086. .ndo_do_ioctl = cxgb_ioctl,
  4087. .ndo_change_mtu = cxgb_change_mtu,
  4088. #ifdef CONFIG_NET_POLL_CONTROLLER
  4089. .ndo_poll_controller = cxgb_netpoll,
  4090. #endif
  4091. #ifdef CONFIG_NET_RX_BUSY_POLL
  4092. .ndo_busy_poll = cxgb_busy_poll,
  4093. #endif
  4094. };
  4095. void t4_fatal_err(struct adapter *adap)
  4096. {
  4097. t4_set_reg_field(adap, SGE_CONTROL_A, GLOBALENABLE_F, 0);
  4098. t4_intr_disable(adap);
  4099. dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
  4100. }
  4101. /* Return the specified PCI-E Configuration Space register from our Physical
  4102. * Function. We try first via a Firmware LDST Command since we prefer to let
  4103. * the firmware own all of these registers, but if that fails we go for it
  4104. * directly ourselves.
  4105. */
  4106. static u32 t4_read_pcie_cfg4(struct adapter *adap, int reg)
  4107. {
  4108. struct fw_ldst_cmd ldst_cmd;
  4109. u32 val;
  4110. int ret;
  4111. /* Construct and send the Firmware LDST Command to retrieve the
  4112. * specified PCI-E Configuration Space register.
  4113. */
  4114. memset(&ldst_cmd, 0, sizeof(ldst_cmd));
  4115. ldst_cmd.op_to_addrspace =
  4116. htonl(FW_CMD_OP_V(FW_LDST_CMD) |
  4117. FW_CMD_REQUEST_F |
  4118. FW_CMD_READ_F |
  4119. FW_LDST_CMD_ADDRSPACE_V(FW_LDST_ADDRSPC_FUNC_PCIE));
  4120. ldst_cmd.cycles_to_len16 = htonl(FW_LEN16(ldst_cmd));
  4121. ldst_cmd.u.pcie.select_naccess = FW_LDST_CMD_NACCESS_V(1);
  4122. ldst_cmd.u.pcie.ctrl_to_fn =
  4123. (FW_LDST_CMD_LC_F | FW_LDST_CMD_FN_V(adap->fn));
  4124. ldst_cmd.u.pcie.r = reg;
  4125. ret = t4_wr_mbox(adap, adap->mbox, &ldst_cmd, sizeof(ldst_cmd),
  4126. &ldst_cmd);
  4127. /* If the LDST Command suucceeded, exctract the returned register
  4128. * value. Otherwise read it directly ourself.
  4129. */
  4130. if (ret == 0)
  4131. val = ntohl(ldst_cmd.u.pcie.data[0]);
  4132. else
  4133. t4_hw_pci_read_cfg4(adap, reg, &val);
  4134. return val;
  4135. }
  4136. static void setup_memwin(struct adapter *adap)
  4137. {
  4138. u32 mem_win0_base, mem_win1_base, mem_win2_base, mem_win2_aperture;
  4139. if (is_t4(adap->params.chip)) {
  4140. u32 bar0;
  4141. /* Truncation intentional: we only read the bottom 32-bits of
  4142. * the 64-bit BAR0/BAR1 ... We use the hardware backdoor
  4143. * mechanism to read BAR0 instead of using
  4144. * pci_resource_start() because we could be operating from
  4145. * within a Virtual Machine which is trapping our accesses to
  4146. * our Configuration Space and we need to set up the PCI-E
  4147. * Memory Window decoders with the actual addresses which will
  4148. * be coming across the PCI-E link.
  4149. */
  4150. bar0 = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_0);
  4151. bar0 &= PCI_BASE_ADDRESS_MEM_MASK;
  4152. adap->t4_bar0 = bar0;
  4153. mem_win0_base = bar0 + MEMWIN0_BASE;
  4154. mem_win1_base = bar0 + MEMWIN1_BASE;
  4155. mem_win2_base = bar0 + MEMWIN2_BASE;
  4156. mem_win2_aperture = MEMWIN2_APERTURE;
  4157. } else {
  4158. /* For T5, only relative offset inside the PCIe BAR is passed */
  4159. mem_win0_base = MEMWIN0_BASE;
  4160. mem_win1_base = MEMWIN1_BASE;
  4161. mem_win2_base = MEMWIN2_BASE_T5;
  4162. mem_win2_aperture = MEMWIN2_APERTURE_T5;
  4163. }
  4164. t4_write_reg(adap, PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 0),
  4165. mem_win0_base | BIR_V(0) |
  4166. WINDOW_V(ilog2(MEMWIN0_APERTURE) - 10));
  4167. t4_write_reg(adap, PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 1),
  4168. mem_win1_base | BIR_V(0) |
  4169. WINDOW_V(ilog2(MEMWIN1_APERTURE) - 10));
  4170. t4_write_reg(adap, PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 2),
  4171. mem_win2_base | BIR_V(0) |
  4172. WINDOW_V(ilog2(mem_win2_aperture) - 10));
  4173. t4_read_reg(adap, PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 2));
  4174. }
  4175. static void setup_memwin_rdma(struct adapter *adap)
  4176. {
  4177. if (adap->vres.ocq.size) {
  4178. u32 start;
  4179. unsigned int sz_kb;
  4180. start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
  4181. start &= PCI_BASE_ADDRESS_MEM_MASK;
  4182. start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
  4183. sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
  4184. t4_write_reg(adap,
  4185. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
  4186. start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
  4187. t4_write_reg(adap,
  4188. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
  4189. adap->vres.ocq.start);
  4190. t4_read_reg(adap,
  4191. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
  4192. }
  4193. }
  4194. static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
  4195. {
  4196. u32 v;
  4197. int ret;
  4198. /* get device capabilities */
  4199. memset(c, 0, sizeof(*c));
  4200. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  4201. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  4202. c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
  4203. ret = t4_wr_mbox(adap, adap->fn, c, sizeof(*c), c);
  4204. if (ret < 0)
  4205. return ret;
  4206. /* select capabilities we'll be using */
  4207. if (c->niccaps & htons(FW_CAPS_CONFIG_NIC_VM)) {
  4208. if (!vf_acls)
  4209. c->niccaps ^= htons(FW_CAPS_CONFIG_NIC_VM);
  4210. else
  4211. c->niccaps = htons(FW_CAPS_CONFIG_NIC_VM);
  4212. } else if (vf_acls) {
  4213. dev_err(adap->pdev_dev, "virtualization ACLs not supported");
  4214. return ret;
  4215. }
  4216. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  4217. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  4218. ret = t4_wr_mbox(adap, adap->fn, c, sizeof(*c), NULL);
  4219. if (ret < 0)
  4220. return ret;
  4221. ret = t4_config_glbl_rss(adap, adap->fn,
  4222. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
  4223. FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
  4224. FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
  4225. if (ret < 0)
  4226. return ret;
  4227. ret = t4_cfg_pfvf(adap, adap->fn, adap->fn, 0, MAX_EGRQ, 64, MAX_INGQ,
  4228. 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF, FW_CMD_CAP_PF);
  4229. if (ret < 0)
  4230. return ret;
  4231. t4_sge_init(adap);
  4232. /* tweak some settings */
  4233. t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
  4234. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
  4235. t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
  4236. v = t4_read_reg(adap, TP_PIO_DATA_A);
  4237. t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
  4238. /* first 4 Tx modulation queues point to consecutive Tx channels */
  4239. adap->params.tp.tx_modq_map = 0xE4;
  4240. t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
  4241. TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
  4242. /* associate each Tx modulation queue with consecutive Tx channels */
  4243. v = 0x84218421;
  4244. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4245. &v, 1, TP_TX_SCHED_HDR_A);
  4246. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4247. &v, 1, TP_TX_SCHED_FIFO_A);
  4248. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  4249. &v, 1, TP_TX_SCHED_PCMD_A);
  4250. #define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
  4251. if (is_offload(adap)) {
  4252. t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
  4253. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  4254. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  4255. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  4256. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  4257. t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
  4258. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  4259. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  4260. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  4261. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  4262. }
  4263. /* get basic stuff going */
  4264. return t4_early_init(adap, adap->fn);
  4265. }
  4266. /*
  4267. * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
  4268. */
  4269. #define MAX_ATIDS 8192U
  4270. /*
  4271. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  4272. *
  4273. * If the firmware we're dealing with has Configuration File support, then
  4274. * we use that to perform all configuration
  4275. */
  4276. /*
  4277. * Tweak configuration based on module parameters, etc. Most of these have
  4278. * defaults assigned to them by Firmware Configuration Files (if we're using
  4279. * them) but need to be explicitly set if we're using hard-coded
  4280. * initialization. But even in the case of using Firmware Configuration
  4281. * Files, we'd like to expose the ability to change these via module
  4282. * parameters so these are essentially common tweaks/settings for
  4283. * Configuration Files and hard-coded initialization ...
  4284. */
  4285. static int adap_init0_tweaks(struct adapter *adapter)
  4286. {
  4287. /*
  4288. * Fix up various Host-Dependent Parameters like Page Size, Cache
  4289. * Line Size, etc. The firmware default is for a 4KB Page Size and
  4290. * 64B Cache Line Size ...
  4291. */
  4292. t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
  4293. /*
  4294. * Process module parameters which affect early initialization.
  4295. */
  4296. if (rx_dma_offset != 2 && rx_dma_offset != 0) {
  4297. dev_err(&adapter->pdev->dev,
  4298. "Ignoring illegal rx_dma_offset=%d, using 2\n",
  4299. rx_dma_offset);
  4300. rx_dma_offset = 2;
  4301. }
  4302. t4_set_reg_field(adapter, SGE_CONTROL_A,
  4303. PKTSHIFT_V(PKTSHIFT_M),
  4304. PKTSHIFT_V(rx_dma_offset));
  4305. /*
  4306. * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
  4307. * adds the pseudo header itself.
  4308. */
  4309. t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
  4310. CSUM_HAS_PSEUDO_HDR_F, 0);
  4311. return 0;
  4312. }
  4313. /*
  4314. * Attempt to initialize the adapter via a Firmware Configuration File.
  4315. */
  4316. static int adap_init0_config(struct adapter *adapter, int reset)
  4317. {
  4318. struct fw_caps_config_cmd caps_cmd;
  4319. const struct firmware *cf;
  4320. unsigned long mtype = 0, maddr = 0;
  4321. u32 finiver, finicsum, cfcsum;
  4322. int ret;
  4323. int config_issued = 0;
  4324. char *fw_config_file, fw_config_file_path[256];
  4325. char *config_name = NULL;
  4326. /*
  4327. * Reset device if necessary.
  4328. */
  4329. if (reset) {
  4330. ret = t4_fw_reset(adapter, adapter->mbox,
  4331. PIORSTMODE_F | PIORST_F);
  4332. if (ret < 0)
  4333. goto bye;
  4334. }
  4335. /*
  4336. * If we have a T4 configuration file under /lib/firmware/cxgb4/,
  4337. * then use that. Otherwise, use the configuration file stored
  4338. * in the adapter flash ...
  4339. */
  4340. switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
  4341. case CHELSIO_T4:
  4342. fw_config_file = FW4_CFNAME;
  4343. break;
  4344. case CHELSIO_T5:
  4345. fw_config_file = FW5_CFNAME;
  4346. break;
  4347. default:
  4348. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  4349. adapter->pdev->device);
  4350. ret = -EINVAL;
  4351. goto bye;
  4352. }
  4353. ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
  4354. if (ret < 0) {
  4355. config_name = "On FLASH";
  4356. mtype = FW_MEMTYPE_CF_FLASH;
  4357. maddr = t4_flash_cfg_addr(adapter);
  4358. } else {
  4359. u32 params[7], val[7];
  4360. sprintf(fw_config_file_path,
  4361. "/lib/firmware/%s", fw_config_file);
  4362. config_name = fw_config_file_path;
  4363. if (cf->size >= FLASH_CFG_MAX_SIZE)
  4364. ret = -ENOMEM;
  4365. else {
  4366. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  4367. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  4368. ret = t4_query_params(adapter, adapter->mbox,
  4369. adapter->fn, 0, 1, params, val);
  4370. if (ret == 0) {
  4371. /*
  4372. * For t4_memory_rw() below addresses and
  4373. * sizes have to be in terms of multiples of 4
  4374. * bytes. So, if the Configuration File isn't
  4375. * a multiple of 4 bytes in length we'll have
  4376. * to write that out separately since we can't
  4377. * guarantee that the bytes following the
  4378. * residual byte in the buffer returned by
  4379. * request_firmware() are zeroed out ...
  4380. */
  4381. size_t resid = cf->size & 0x3;
  4382. size_t size = cf->size & ~0x3;
  4383. __be32 *data = (__be32 *)cf->data;
  4384. mtype = FW_PARAMS_PARAM_Y_G(val[0]);
  4385. maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
  4386. spin_lock(&adapter->win0_lock);
  4387. ret = t4_memory_rw(adapter, 0, mtype, maddr,
  4388. size, data, T4_MEMORY_WRITE);
  4389. if (ret == 0 && resid != 0) {
  4390. union {
  4391. __be32 word;
  4392. char buf[4];
  4393. } last;
  4394. int i;
  4395. last.word = data[size >> 2];
  4396. for (i = resid; i < 4; i++)
  4397. last.buf[i] = 0;
  4398. ret = t4_memory_rw(adapter, 0, mtype,
  4399. maddr + size,
  4400. 4, &last.word,
  4401. T4_MEMORY_WRITE);
  4402. }
  4403. spin_unlock(&adapter->win0_lock);
  4404. }
  4405. }
  4406. release_firmware(cf);
  4407. if (ret)
  4408. goto bye;
  4409. }
  4410. /*
  4411. * Issue a Capability Configuration command to the firmware to get it
  4412. * to parse the Configuration File. We don't use t4_fw_config_file()
  4413. * because we want the ability to modify various features after we've
  4414. * processed the configuration file ...
  4415. */
  4416. memset(&caps_cmd, 0, sizeof(caps_cmd));
  4417. caps_cmd.op_to_write =
  4418. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  4419. FW_CMD_REQUEST_F |
  4420. FW_CMD_READ_F);
  4421. caps_cmd.cfvalid_to_len16 =
  4422. htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
  4423. FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
  4424. FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
  4425. FW_LEN16(caps_cmd));
  4426. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  4427. &caps_cmd);
  4428. /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
  4429. * Configuration File in FLASH), our last gasp effort is to use the
  4430. * Firmware Configuration File which is embedded in the firmware. A
  4431. * very few early versions of the firmware didn't have one embedded
  4432. * but we can ignore those.
  4433. */
  4434. if (ret == -ENOENT) {
  4435. memset(&caps_cmd, 0, sizeof(caps_cmd));
  4436. caps_cmd.op_to_write =
  4437. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  4438. FW_CMD_REQUEST_F |
  4439. FW_CMD_READ_F);
  4440. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  4441. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
  4442. sizeof(caps_cmd), &caps_cmd);
  4443. config_name = "Firmware Default";
  4444. }
  4445. config_issued = 1;
  4446. if (ret < 0)
  4447. goto bye;
  4448. finiver = ntohl(caps_cmd.finiver);
  4449. finicsum = ntohl(caps_cmd.finicsum);
  4450. cfcsum = ntohl(caps_cmd.cfcsum);
  4451. if (finicsum != cfcsum)
  4452. dev_warn(adapter->pdev_dev, "Configuration File checksum "\
  4453. "mismatch: [fini] csum=%#x, computed csum=%#x\n",
  4454. finicsum, cfcsum);
  4455. /*
  4456. * And now tell the firmware to use the configuration we just loaded.
  4457. */
  4458. caps_cmd.op_to_write =
  4459. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  4460. FW_CMD_REQUEST_F |
  4461. FW_CMD_WRITE_F);
  4462. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  4463. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  4464. NULL);
  4465. if (ret < 0)
  4466. goto bye;
  4467. /*
  4468. * Tweak configuration based on system architecture, module
  4469. * parameters, etc.
  4470. */
  4471. ret = adap_init0_tweaks(adapter);
  4472. if (ret < 0)
  4473. goto bye;
  4474. /*
  4475. * And finally tell the firmware to initialize itself using the
  4476. * parameters from the Configuration File.
  4477. */
  4478. ret = t4_fw_initialize(adapter, adapter->mbox);
  4479. if (ret < 0)
  4480. goto bye;
  4481. /* Emit Firmware Configuration File information and return
  4482. * successfully.
  4483. */
  4484. dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
  4485. "Configuration File \"%s\", version %#x, computed checksum %#x\n",
  4486. config_name, finiver, cfcsum);
  4487. return 0;
  4488. /*
  4489. * Something bad happened. Return the error ... (If the "error"
  4490. * is that there's no Configuration File on the adapter we don't
  4491. * want to issue a warning since this is fairly common.)
  4492. */
  4493. bye:
  4494. if (config_issued && ret != -ENOENT)
  4495. dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
  4496. config_name, -ret);
  4497. return ret;
  4498. }
  4499. static struct fw_info fw_info_array[] = {
  4500. {
  4501. .chip = CHELSIO_T4,
  4502. .fs_name = FW4_CFNAME,
  4503. .fw_mod_name = FW4_FNAME,
  4504. .fw_hdr = {
  4505. .chip = FW_HDR_CHIP_T4,
  4506. .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
  4507. .intfver_nic = FW_INTFVER(T4, NIC),
  4508. .intfver_vnic = FW_INTFVER(T4, VNIC),
  4509. .intfver_ri = FW_INTFVER(T4, RI),
  4510. .intfver_iscsi = FW_INTFVER(T4, ISCSI),
  4511. .intfver_fcoe = FW_INTFVER(T4, FCOE),
  4512. },
  4513. }, {
  4514. .chip = CHELSIO_T5,
  4515. .fs_name = FW5_CFNAME,
  4516. .fw_mod_name = FW5_FNAME,
  4517. .fw_hdr = {
  4518. .chip = FW_HDR_CHIP_T5,
  4519. .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
  4520. .intfver_nic = FW_INTFVER(T5, NIC),
  4521. .intfver_vnic = FW_INTFVER(T5, VNIC),
  4522. .intfver_ri = FW_INTFVER(T5, RI),
  4523. .intfver_iscsi = FW_INTFVER(T5, ISCSI),
  4524. .intfver_fcoe = FW_INTFVER(T5, FCOE),
  4525. },
  4526. }
  4527. };
  4528. static struct fw_info *find_fw_info(int chip)
  4529. {
  4530. int i;
  4531. for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
  4532. if (fw_info_array[i].chip == chip)
  4533. return &fw_info_array[i];
  4534. }
  4535. return NULL;
  4536. }
  4537. /*
  4538. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  4539. */
  4540. static int adap_init0(struct adapter *adap)
  4541. {
  4542. int ret;
  4543. u32 v, port_vec;
  4544. enum dev_state state;
  4545. u32 params[7], val[7];
  4546. struct fw_caps_config_cmd caps_cmd;
  4547. struct fw_devlog_cmd devlog_cmd;
  4548. u32 devlog_meminfo;
  4549. int reset = 1;
  4550. /* Contact FW, advertising Master capability */
  4551. ret = t4_fw_hello(adap, adap->mbox, adap->mbox, MASTER_MAY, &state);
  4552. if (ret < 0) {
  4553. dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
  4554. ret);
  4555. return ret;
  4556. }
  4557. if (ret == adap->mbox)
  4558. adap->flags |= MASTER_PF;
  4559. /*
  4560. * If we're the Master PF Driver and the device is uninitialized,
  4561. * then let's consider upgrading the firmware ... (We always want
  4562. * to check the firmware version number in order to A. get it for
  4563. * later reporting and B. to warn if the currently loaded firmware
  4564. * is excessively mismatched relative to the driver.)
  4565. */
  4566. t4_get_fw_version(adap, &adap->params.fw_vers);
  4567. t4_get_tp_version(adap, &adap->params.tp_vers);
  4568. if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
  4569. struct fw_info *fw_info;
  4570. struct fw_hdr *card_fw;
  4571. const struct firmware *fw;
  4572. const u8 *fw_data = NULL;
  4573. unsigned int fw_size = 0;
  4574. /* This is the firmware whose headers the driver was compiled
  4575. * against
  4576. */
  4577. fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
  4578. if (fw_info == NULL) {
  4579. dev_err(adap->pdev_dev,
  4580. "unable to get firmware info for chip %d.\n",
  4581. CHELSIO_CHIP_VERSION(adap->params.chip));
  4582. return -EINVAL;
  4583. }
  4584. /* allocate memory to read the header of the firmware on the
  4585. * card
  4586. */
  4587. card_fw = t4_alloc_mem(sizeof(*card_fw));
  4588. /* Get FW from from /lib/firmware/ */
  4589. ret = request_firmware(&fw, fw_info->fw_mod_name,
  4590. adap->pdev_dev);
  4591. if (ret < 0) {
  4592. dev_err(adap->pdev_dev,
  4593. "unable to load firmware image %s, error %d\n",
  4594. fw_info->fw_mod_name, ret);
  4595. } else {
  4596. fw_data = fw->data;
  4597. fw_size = fw->size;
  4598. }
  4599. /* upgrade FW logic */
  4600. ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
  4601. state, &reset);
  4602. /* Cleaning up */
  4603. release_firmware(fw);
  4604. t4_free_mem(card_fw);
  4605. if (ret < 0)
  4606. goto bye;
  4607. }
  4608. /*
  4609. * Grab VPD parameters. This should be done after we establish a
  4610. * connection to the firmware since some of the VPD parameters
  4611. * (notably the Core Clock frequency) are retrieved via requests to
  4612. * the firmware. On the other hand, we need these fairly early on
  4613. * so we do this right after getting ahold of the firmware.
  4614. */
  4615. ret = get_vpd_params(adap, &adap->params.vpd);
  4616. if (ret < 0)
  4617. goto bye;
  4618. /* Read firmware device log parameters. We really need to find a way
  4619. * to get these parameters initialized with some default values (which
  4620. * are likely to be correct) for the case where we either don't
  4621. * attache to the firmware or it's crashed when we probe the adapter.
  4622. * That way we'll still be able to perform early firmware startup
  4623. * debugging ... If the request to get the Firmware's Device Log
  4624. * parameters fails, we'll live so we don't make that a fatal error.
  4625. */
  4626. memset(&devlog_cmd, 0, sizeof(devlog_cmd));
  4627. devlog_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_DEVLOG_CMD) |
  4628. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  4629. devlog_cmd.retval_len16 = htonl(FW_LEN16(devlog_cmd));
  4630. ret = t4_wr_mbox(adap, adap->mbox, &devlog_cmd, sizeof(devlog_cmd),
  4631. &devlog_cmd);
  4632. if (ret == 0) {
  4633. devlog_meminfo =
  4634. ntohl(devlog_cmd.memtype_devlog_memaddr16_devlog);
  4635. adap->params.devlog.memtype =
  4636. FW_DEVLOG_CMD_MEMTYPE_DEVLOG_G(devlog_meminfo);
  4637. adap->params.devlog.start =
  4638. FW_DEVLOG_CMD_MEMADDR16_DEVLOG_G(devlog_meminfo) << 4;
  4639. adap->params.devlog.size = ntohl(devlog_cmd.memsize_devlog);
  4640. }
  4641. /*
  4642. * Find out what ports are available to us. Note that we need to do
  4643. * this before calling adap_init0_no_config() since it needs nports
  4644. * and portvec ...
  4645. */
  4646. v =
  4647. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  4648. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
  4649. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 1, &v, &port_vec);
  4650. if (ret < 0)
  4651. goto bye;
  4652. adap->params.nports = hweight32(port_vec);
  4653. adap->params.portvec = port_vec;
  4654. /* If the firmware is initialized already, emit a simply note to that
  4655. * effect. Otherwise, it's time to try initializing the adapter.
  4656. */
  4657. if (state == DEV_STATE_INIT) {
  4658. dev_info(adap->pdev_dev, "Coming up as %s: "\
  4659. "Adapter already initialized\n",
  4660. adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
  4661. } else {
  4662. dev_info(adap->pdev_dev, "Coming up as MASTER: "\
  4663. "Initializing adapter\n");
  4664. /* Find out whether we're dealing with a version of the
  4665. * firmware which has configuration file support.
  4666. */
  4667. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  4668. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  4669. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 1,
  4670. params, val);
  4671. /* If the firmware doesn't support Configuration Files,
  4672. * return an error.
  4673. */
  4674. if (ret < 0) {
  4675. dev_err(adap->pdev_dev, "firmware doesn't support "
  4676. "Firmware Configuration Files\n");
  4677. goto bye;
  4678. }
  4679. /* The firmware provides us with a memory buffer where we can
  4680. * load a Configuration File from the host if we want to
  4681. * override the Configuration File in flash.
  4682. */
  4683. ret = adap_init0_config(adap, reset);
  4684. if (ret == -ENOENT) {
  4685. dev_err(adap->pdev_dev, "no Configuration File "
  4686. "present on adapter.\n");
  4687. goto bye;
  4688. }
  4689. if (ret < 0) {
  4690. dev_err(adap->pdev_dev, "could not initialize "
  4691. "adapter, error %d\n", -ret);
  4692. goto bye;
  4693. }
  4694. }
  4695. /* Give the SGE code a chance to pull in anything that it needs ...
  4696. * Note that this must be called after we retrieve our VPD parameters
  4697. * in order to know how to convert core ticks to seconds, etc.
  4698. */
  4699. ret = t4_sge_init(adap);
  4700. if (ret < 0)
  4701. goto bye;
  4702. if (is_bypass_device(adap->pdev->device))
  4703. adap->params.bypass = 1;
  4704. /*
  4705. * Grab some of our basic fundamental operating parameters.
  4706. */
  4707. #define FW_PARAM_DEV(param) \
  4708. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
  4709. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
  4710. #define FW_PARAM_PFVF(param) \
  4711. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  4712. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
  4713. FW_PARAMS_PARAM_Y_V(0) | \
  4714. FW_PARAMS_PARAM_Z_V(0)
  4715. params[0] = FW_PARAM_PFVF(EQ_START);
  4716. params[1] = FW_PARAM_PFVF(L2T_START);
  4717. params[2] = FW_PARAM_PFVF(L2T_END);
  4718. params[3] = FW_PARAM_PFVF(FILTER_START);
  4719. params[4] = FW_PARAM_PFVF(FILTER_END);
  4720. params[5] = FW_PARAM_PFVF(IQFLINT_START);
  4721. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 6, params, val);
  4722. if (ret < 0)
  4723. goto bye;
  4724. adap->sge.egr_start = val[0];
  4725. adap->l2t_start = val[1];
  4726. adap->l2t_end = val[2];
  4727. adap->tids.ftid_base = val[3];
  4728. adap->tids.nftids = val[4] - val[3] + 1;
  4729. adap->sge.ingr_start = val[5];
  4730. params[0] = FW_PARAM_PFVF(CLIP_START);
  4731. params[1] = FW_PARAM_PFVF(CLIP_END);
  4732. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 2, params, val);
  4733. if (ret < 0)
  4734. goto bye;
  4735. adap->clipt_start = val[0];
  4736. adap->clipt_end = val[1];
  4737. /* query params related to active filter region */
  4738. params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
  4739. params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
  4740. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 2, params, val);
  4741. /* If Active filter size is set we enable establishing
  4742. * offload connection through firmware work request
  4743. */
  4744. if ((val[0] != val[1]) && (ret >= 0)) {
  4745. adap->flags |= FW_OFLD_CONN;
  4746. adap->tids.aftid_base = val[0];
  4747. adap->tids.aftid_end = val[1];
  4748. }
  4749. /* If we're running on newer firmware, let it know that we're
  4750. * prepared to deal with encapsulated CPL messages. Older
  4751. * firmware won't understand this and we'll just get
  4752. * unencapsulated messages ...
  4753. */
  4754. params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
  4755. val[0] = 1;
  4756. (void) t4_set_params(adap, adap->mbox, adap->fn, 0, 1, params, val);
  4757. /*
  4758. * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
  4759. * capability. Earlier versions of the firmware didn't have the
  4760. * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
  4761. * permission to use ULPTX MEMWRITE DSGL.
  4762. */
  4763. if (is_t4(adap->params.chip)) {
  4764. adap->params.ulptx_memwrite_dsgl = false;
  4765. } else {
  4766. params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
  4767. ret = t4_query_params(adap, adap->mbox, adap->fn, 0,
  4768. 1, params, val);
  4769. adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
  4770. }
  4771. /*
  4772. * Get device capabilities so we can determine what resources we need
  4773. * to manage.
  4774. */
  4775. memset(&caps_cmd, 0, sizeof(caps_cmd));
  4776. caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  4777. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  4778. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  4779. ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
  4780. &caps_cmd);
  4781. if (ret < 0)
  4782. goto bye;
  4783. if (caps_cmd.ofldcaps) {
  4784. /* query offload-related parameters */
  4785. params[0] = FW_PARAM_DEV(NTID);
  4786. params[1] = FW_PARAM_PFVF(SERVER_START);
  4787. params[2] = FW_PARAM_PFVF(SERVER_END);
  4788. params[3] = FW_PARAM_PFVF(TDDP_START);
  4789. params[4] = FW_PARAM_PFVF(TDDP_END);
  4790. params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
  4791. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 6,
  4792. params, val);
  4793. if (ret < 0)
  4794. goto bye;
  4795. adap->tids.ntids = val[0];
  4796. adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
  4797. adap->tids.stid_base = val[1];
  4798. adap->tids.nstids = val[2] - val[1] + 1;
  4799. /*
  4800. * Setup server filter region. Divide the available filter
  4801. * region into two parts. Regular filters get 1/3rd and server
  4802. * filters get 2/3rd part. This is only enabled if workarond
  4803. * path is enabled.
  4804. * 1. For regular filters.
  4805. * 2. Server filter: This are special filters which are used
  4806. * to redirect SYN packets to offload queue.
  4807. */
  4808. if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
  4809. adap->tids.sftid_base = adap->tids.ftid_base +
  4810. DIV_ROUND_UP(adap->tids.nftids, 3);
  4811. adap->tids.nsftids = adap->tids.nftids -
  4812. DIV_ROUND_UP(adap->tids.nftids, 3);
  4813. adap->tids.nftids = adap->tids.sftid_base -
  4814. adap->tids.ftid_base;
  4815. }
  4816. adap->vres.ddp.start = val[3];
  4817. adap->vres.ddp.size = val[4] - val[3] + 1;
  4818. adap->params.ofldq_wr_cred = val[5];
  4819. adap->params.offload = 1;
  4820. }
  4821. if (caps_cmd.rdmacaps) {
  4822. params[0] = FW_PARAM_PFVF(STAG_START);
  4823. params[1] = FW_PARAM_PFVF(STAG_END);
  4824. params[2] = FW_PARAM_PFVF(RQ_START);
  4825. params[3] = FW_PARAM_PFVF(RQ_END);
  4826. params[4] = FW_PARAM_PFVF(PBL_START);
  4827. params[5] = FW_PARAM_PFVF(PBL_END);
  4828. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 6,
  4829. params, val);
  4830. if (ret < 0)
  4831. goto bye;
  4832. adap->vres.stag.start = val[0];
  4833. adap->vres.stag.size = val[1] - val[0] + 1;
  4834. adap->vres.rq.start = val[2];
  4835. adap->vres.rq.size = val[3] - val[2] + 1;
  4836. adap->vres.pbl.start = val[4];
  4837. adap->vres.pbl.size = val[5] - val[4] + 1;
  4838. params[0] = FW_PARAM_PFVF(SQRQ_START);
  4839. params[1] = FW_PARAM_PFVF(SQRQ_END);
  4840. params[2] = FW_PARAM_PFVF(CQ_START);
  4841. params[3] = FW_PARAM_PFVF(CQ_END);
  4842. params[4] = FW_PARAM_PFVF(OCQ_START);
  4843. params[5] = FW_PARAM_PFVF(OCQ_END);
  4844. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 6, params,
  4845. val);
  4846. if (ret < 0)
  4847. goto bye;
  4848. adap->vres.qp.start = val[0];
  4849. adap->vres.qp.size = val[1] - val[0] + 1;
  4850. adap->vres.cq.start = val[2];
  4851. adap->vres.cq.size = val[3] - val[2] + 1;
  4852. adap->vres.ocq.start = val[4];
  4853. adap->vres.ocq.size = val[5] - val[4] + 1;
  4854. params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
  4855. params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
  4856. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 2, params,
  4857. val);
  4858. if (ret < 0) {
  4859. adap->params.max_ordird_qp = 8;
  4860. adap->params.max_ird_adapter = 32 * adap->tids.ntids;
  4861. ret = 0;
  4862. } else {
  4863. adap->params.max_ordird_qp = val[0];
  4864. adap->params.max_ird_adapter = val[1];
  4865. }
  4866. dev_info(adap->pdev_dev,
  4867. "max_ordird_qp %d max_ird_adapter %d\n",
  4868. adap->params.max_ordird_qp,
  4869. adap->params.max_ird_adapter);
  4870. }
  4871. if (caps_cmd.iscsicaps) {
  4872. params[0] = FW_PARAM_PFVF(ISCSI_START);
  4873. params[1] = FW_PARAM_PFVF(ISCSI_END);
  4874. ret = t4_query_params(adap, adap->mbox, adap->fn, 0, 2,
  4875. params, val);
  4876. if (ret < 0)
  4877. goto bye;
  4878. adap->vres.iscsi.start = val[0];
  4879. adap->vres.iscsi.size = val[1] - val[0] + 1;
  4880. }
  4881. #undef FW_PARAM_PFVF
  4882. #undef FW_PARAM_DEV
  4883. /* The MTU/MSS Table is initialized by now, so load their values. If
  4884. * we're initializing the adapter, then we'll make any modifications
  4885. * we want to the MTU/MSS Table and also initialize the congestion
  4886. * parameters.
  4887. */
  4888. t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
  4889. if (state != DEV_STATE_INIT) {
  4890. int i;
  4891. /* The default MTU Table contains values 1492 and 1500.
  4892. * However, for TCP, it's better to have two values which are
  4893. * a multiple of 8 +/- 4 bytes apart near this popular MTU.
  4894. * This allows us to have a TCP Data Payload which is a
  4895. * multiple of 8 regardless of what combination of TCP Options
  4896. * are in use (always a multiple of 4 bytes) which is
  4897. * important for performance reasons. For instance, if no
  4898. * options are in use, then we have a 20-byte IP header and a
  4899. * 20-byte TCP header. In this case, a 1500-byte MSS would
  4900. * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
  4901. * which is not a multiple of 8. So using an MSS of 1488 in
  4902. * this case results in a TCP Data Payload of 1448 bytes which
  4903. * is a multiple of 8. On the other hand, if 12-byte TCP Time
  4904. * Stamps have been negotiated, then an MTU of 1500 bytes
  4905. * results in a TCP Data Payload of 1448 bytes which, as
  4906. * above, is a multiple of 8 bytes ...
  4907. */
  4908. for (i = 0; i < NMTUS; i++)
  4909. if (adap->params.mtus[i] == 1492) {
  4910. adap->params.mtus[i] = 1488;
  4911. break;
  4912. }
  4913. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4914. adap->params.b_wnd);
  4915. }
  4916. t4_init_sge_params(adap);
  4917. t4_init_tp_params(adap);
  4918. adap->flags |= FW_OK;
  4919. return 0;
  4920. /*
  4921. * Something bad happened. If a command timed out or failed with EIO
  4922. * FW does not operate within its spec or something catastrophic
  4923. * happened to HW/FW, stop issuing commands.
  4924. */
  4925. bye:
  4926. if (ret != -ETIMEDOUT && ret != -EIO)
  4927. t4_fw_bye(adap, adap->mbox);
  4928. return ret;
  4929. }
  4930. /* EEH callbacks */
  4931. static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
  4932. pci_channel_state_t state)
  4933. {
  4934. int i;
  4935. struct adapter *adap = pci_get_drvdata(pdev);
  4936. if (!adap)
  4937. goto out;
  4938. rtnl_lock();
  4939. adap->flags &= ~FW_OK;
  4940. notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
  4941. spin_lock(&adap->stats_lock);
  4942. for_each_port(adap, i) {
  4943. struct net_device *dev = adap->port[i];
  4944. netif_device_detach(dev);
  4945. netif_carrier_off(dev);
  4946. }
  4947. spin_unlock(&adap->stats_lock);
  4948. if (adap->flags & FULL_INIT_DONE)
  4949. cxgb_down(adap);
  4950. rtnl_unlock();
  4951. if ((adap->flags & DEV_ENABLED)) {
  4952. pci_disable_device(pdev);
  4953. adap->flags &= ~DEV_ENABLED;
  4954. }
  4955. out: return state == pci_channel_io_perm_failure ?
  4956. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  4957. }
  4958. static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
  4959. {
  4960. int i, ret;
  4961. struct fw_caps_config_cmd c;
  4962. struct adapter *adap = pci_get_drvdata(pdev);
  4963. if (!adap) {
  4964. pci_restore_state(pdev);
  4965. pci_save_state(pdev);
  4966. return PCI_ERS_RESULT_RECOVERED;
  4967. }
  4968. if (!(adap->flags & DEV_ENABLED)) {
  4969. if (pci_enable_device(pdev)) {
  4970. dev_err(&pdev->dev, "Cannot reenable PCI "
  4971. "device after reset\n");
  4972. return PCI_ERS_RESULT_DISCONNECT;
  4973. }
  4974. adap->flags |= DEV_ENABLED;
  4975. }
  4976. pci_set_master(pdev);
  4977. pci_restore_state(pdev);
  4978. pci_save_state(pdev);
  4979. pci_cleanup_aer_uncorrect_error_status(pdev);
  4980. if (t4_wait_dev_ready(adap->regs) < 0)
  4981. return PCI_ERS_RESULT_DISCONNECT;
  4982. if (t4_fw_hello(adap, adap->fn, adap->fn, MASTER_MUST, NULL) < 0)
  4983. return PCI_ERS_RESULT_DISCONNECT;
  4984. adap->flags |= FW_OK;
  4985. if (adap_init1(adap, &c))
  4986. return PCI_ERS_RESULT_DISCONNECT;
  4987. for_each_port(adap, i) {
  4988. struct port_info *p = adap2pinfo(adap, i);
  4989. ret = t4_alloc_vi(adap, adap->fn, p->tx_chan, adap->fn, 0, 1,
  4990. NULL, NULL);
  4991. if (ret < 0)
  4992. return PCI_ERS_RESULT_DISCONNECT;
  4993. p->viid = ret;
  4994. p->xact_addr_filt = -1;
  4995. }
  4996. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  4997. adap->params.b_wnd);
  4998. setup_memwin(adap);
  4999. if (cxgb_up(adap))
  5000. return PCI_ERS_RESULT_DISCONNECT;
  5001. return PCI_ERS_RESULT_RECOVERED;
  5002. }
  5003. static void eeh_resume(struct pci_dev *pdev)
  5004. {
  5005. int i;
  5006. struct adapter *adap = pci_get_drvdata(pdev);
  5007. if (!adap)
  5008. return;
  5009. rtnl_lock();
  5010. for_each_port(adap, i) {
  5011. struct net_device *dev = adap->port[i];
  5012. if (netif_running(dev)) {
  5013. link_start(dev);
  5014. cxgb_set_rxmode(dev);
  5015. }
  5016. netif_device_attach(dev);
  5017. }
  5018. rtnl_unlock();
  5019. }
  5020. static const struct pci_error_handlers cxgb4_eeh = {
  5021. .error_detected = eeh_err_detected,
  5022. .slot_reset = eeh_slot_reset,
  5023. .resume = eeh_resume,
  5024. };
  5025. static inline bool is_x_10g_port(const struct link_config *lc)
  5026. {
  5027. return (lc->supported & FW_PORT_CAP_SPEED_10G) != 0 ||
  5028. (lc->supported & FW_PORT_CAP_SPEED_40G) != 0;
  5029. }
  5030. static inline void init_rspq(struct adapter *adap, struct sge_rspq *q,
  5031. unsigned int us, unsigned int cnt,
  5032. unsigned int size, unsigned int iqe_size)
  5033. {
  5034. q->adap = adap;
  5035. set_rspq_intr_params(q, us, cnt);
  5036. q->iqe_len = iqe_size;
  5037. q->size = size;
  5038. }
  5039. /*
  5040. * Perform default configuration of DMA queues depending on the number and type
  5041. * of ports we found and the number of available CPUs. Most settings can be
  5042. * modified by the admin prior to actual use.
  5043. */
  5044. static void cfg_queues(struct adapter *adap)
  5045. {
  5046. struct sge *s = &adap->sge;
  5047. int i, n10g = 0, qidx = 0;
  5048. #ifndef CONFIG_CHELSIO_T4_DCB
  5049. int q10g = 0;
  5050. #endif
  5051. int ciq_size;
  5052. for_each_port(adap, i)
  5053. n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
  5054. #ifdef CONFIG_CHELSIO_T4_DCB
  5055. /* For Data Center Bridging support we need to be able to support up
  5056. * to 8 Traffic Priorities; each of which will be assigned to its
  5057. * own TX Queue in order to prevent Head-Of-Line Blocking.
  5058. */
  5059. if (adap->params.nports * 8 > MAX_ETH_QSETS) {
  5060. dev_err(adap->pdev_dev, "MAX_ETH_QSETS=%d < %d!\n",
  5061. MAX_ETH_QSETS, adap->params.nports * 8);
  5062. BUG_ON(1);
  5063. }
  5064. for_each_port(adap, i) {
  5065. struct port_info *pi = adap2pinfo(adap, i);
  5066. pi->first_qset = qidx;
  5067. pi->nqsets = 8;
  5068. qidx += pi->nqsets;
  5069. }
  5070. #else /* !CONFIG_CHELSIO_T4_DCB */
  5071. /*
  5072. * We default to 1 queue per non-10G port and up to # of cores queues
  5073. * per 10G port.
  5074. */
  5075. if (n10g)
  5076. q10g = (MAX_ETH_QSETS - (adap->params.nports - n10g)) / n10g;
  5077. if (q10g > netif_get_num_default_rss_queues())
  5078. q10g = netif_get_num_default_rss_queues();
  5079. for_each_port(adap, i) {
  5080. struct port_info *pi = adap2pinfo(adap, i);
  5081. pi->first_qset = qidx;
  5082. pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
  5083. qidx += pi->nqsets;
  5084. }
  5085. #endif /* !CONFIG_CHELSIO_T4_DCB */
  5086. s->ethqsets = qidx;
  5087. s->max_ethqsets = qidx; /* MSI-X may lower it later */
  5088. if (is_offload(adap)) {
  5089. /*
  5090. * For offload we use 1 queue/channel if all ports are up to 1G,
  5091. * otherwise we divide all available queues amongst the channels
  5092. * capped by the number of available cores.
  5093. */
  5094. if (n10g) {
  5095. i = min_t(int, ARRAY_SIZE(s->ofldrxq),
  5096. num_online_cpus());
  5097. s->ofldqsets = roundup(i, adap->params.nports);
  5098. } else
  5099. s->ofldqsets = adap->params.nports;
  5100. /* For RDMA one Rx queue per channel suffices */
  5101. s->rdmaqs = adap->params.nports;
  5102. /* Try and allow at least 1 CIQ per cpu rounding down
  5103. * to the number of ports, with a minimum of 1 per port.
  5104. * A 2 port card in a 6 cpu system: 6 CIQs, 3 / port.
  5105. * A 4 port card in a 6 cpu system: 4 CIQs, 1 / port.
  5106. * A 4 port card in a 2 cpu system: 4 CIQs, 1 / port.
  5107. */
  5108. s->rdmaciqs = min_t(int, MAX_RDMA_CIQS, num_online_cpus());
  5109. s->rdmaciqs = (s->rdmaciqs / adap->params.nports) *
  5110. adap->params.nports;
  5111. s->rdmaciqs = max_t(int, s->rdmaciqs, adap->params.nports);
  5112. }
  5113. for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
  5114. struct sge_eth_rxq *r = &s->ethrxq[i];
  5115. init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
  5116. r->fl.size = 72;
  5117. }
  5118. for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
  5119. s->ethtxq[i].q.size = 1024;
  5120. for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
  5121. s->ctrlq[i].q.size = 512;
  5122. for (i = 0; i < ARRAY_SIZE(s->ofldtxq); i++)
  5123. s->ofldtxq[i].q.size = 1024;
  5124. for (i = 0; i < ARRAY_SIZE(s->ofldrxq); i++) {
  5125. struct sge_ofld_rxq *r = &s->ofldrxq[i];
  5126. init_rspq(adap, &r->rspq, 5, 1, 1024, 64);
  5127. r->rspq.uld = CXGB4_ULD_ISCSI;
  5128. r->fl.size = 72;
  5129. }
  5130. for (i = 0; i < ARRAY_SIZE(s->rdmarxq); i++) {
  5131. struct sge_ofld_rxq *r = &s->rdmarxq[i];
  5132. init_rspq(adap, &r->rspq, 5, 1, 511, 64);
  5133. r->rspq.uld = CXGB4_ULD_RDMA;
  5134. r->fl.size = 72;
  5135. }
  5136. ciq_size = 64 + adap->vres.cq.size + adap->tids.nftids;
  5137. if (ciq_size > SGE_MAX_IQ_SIZE) {
  5138. CH_WARN(adap, "CIQ size too small for available IQs\n");
  5139. ciq_size = SGE_MAX_IQ_SIZE;
  5140. }
  5141. for (i = 0; i < ARRAY_SIZE(s->rdmaciq); i++) {
  5142. struct sge_ofld_rxq *r = &s->rdmaciq[i];
  5143. init_rspq(adap, &r->rspq, 5, 1, ciq_size, 64);
  5144. r->rspq.uld = CXGB4_ULD_RDMA;
  5145. }
  5146. init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
  5147. init_rspq(adap, &s->intrq, 0, 1, 2 * MAX_INGQ, 64);
  5148. }
  5149. /*
  5150. * Reduce the number of Ethernet queues across all ports to at most n.
  5151. * n provides at least one queue per port.
  5152. */
  5153. static void reduce_ethqs(struct adapter *adap, int n)
  5154. {
  5155. int i;
  5156. struct port_info *pi;
  5157. while (n < adap->sge.ethqsets)
  5158. for_each_port(adap, i) {
  5159. pi = adap2pinfo(adap, i);
  5160. if (pi->nqsets > 1) {
  5161. pi->nqsets--;
  5162. adap->sge.ethqsets--;
  5163. if (adap->sge.ethqsets <= n)
  5164. break;
  5165. }
  5166. }
  5167. n = 0;
  5168. for_each_port(adap, i) {
  5169. pi = adap2pinfo(adap, i);
  5170. pi->first_qset = n;
  5171. n += pi->nqsets;
  5172. }
  5173. }
  5174. /* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
  5175. #define EXTRA_VECS 2
  5176. static int enable_msix(struct adapter *adap)
  5177. {
  5178. int ofld_need = 0;
  5179. int i, want, need, allocated;
  5180. struct sge *s = &adap->sge;
  5181. unsigned int nchan = adap->params.nports;
  5182. struct msix_entry *entries;
  5183. entries = kmalloc(sizeof(*entries) * (MAX_INGQ + 1),
  5184. GFP_KERNEL);
  5185. if (!entries)
  5186. return -ENOMEM;
  5187. for (i = 0; i < MAX_INGQ + 1; ++i)
  5188. entries[i].entry = i;
  5189. want = s->max_ethqsets + EXTRA_VECS;
  5190. if (is_offload(adap)) {
  5191. want += s->rdmaqs + s->rdmaciqs + s->ofldqsets;
  5192. /* need nchan for each possible ULD */
  5193. ofld_need = 3 * nchan;
  5194. }
  5195. #ifdef CONFIG_CHELSIO_T4_DCB
  5196. /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
  5197. * each port.
  5198. */
  5199. need = 8 * adap->params.nports + EXTRA_VECS + ofld_need;
  5200. #else
  5201. need = adap->params.nports + EXTRA_VECS + ofld_need;
  5202. #endif
  5203. allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
  5204. if (allocated < 0) {
  5205. dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
  5206. " not using MSI-X\n");
  5207. kfree(entries);
  5208. return allocated;
  5209. }
  5210. /* Distribute available vectors to the various queue groups.
  5211. * Every group gets its minimum requirement and NIC gets top
  5212. * priority for leftovers.
  5213. */
  5214. i = allocated - EXTRA_VECS - ofld_need;
  5215. if (i < s->max_ethqsets) {
  5216. s->max_ethqsets = i;
  5217. if (i < s->ethqsets)
  5218. reduce_ethqs(adap, i);
  5219. }
  5220. if (is_offload(adap)) {
  5221. if (allocated < want) {
  5222. s->rdmaqs = nchan;
  5223. s->rdmaciqs = nchan;
  5224. }
  5225. /* leftovers go to OFLD */
  5226. i = allocated - EXTRA_VECS - s->max_ethqsets -
  5227. s->rdmaqs - s->rdmaciqs;
  5228. s->ofldqsets = (i / nchan) * nchan; /* round down */
  5229. }
  5230. for (i = 0; i < allocated; ++i)
  5231. adap->msix_info[i].vec = entries[i].vector;
  5232. kfree(entries);
  5233. return 0;
  5234. }
  5235. #undef EXTRA_VECS
  5236. static int init_rss(struct adapter *adap)
  5237. {
  5238. unsigned int i, j;
  5239. for_each_port(adap, i) {
  5240. struct port_info *pi = adap2pinfo(adap, i);
  5241. pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
  5242. if (!pi->rss)
  5243. return -ENOMEM;
  5244. for (j = 0; j < pi->rss_size; j++)
  5245. pi->rss[j] = ethtool_rxfh_indir_default(j, pi->nqsets);
  5246. }
  5247. return 0;
  5248. }
  5249. static void print_port_info(const struct net_device *dev)
  5250. {
  5251. char buf[80];
  5252. char *bufp = buf;
  5253. const char *spd = "";
  5254. const struct port_info *pi = netdev_priv(dev);
  5255. const struct adapter *adap = pi->adapter;
  5256. if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_2_5GB)
  5257. spd = " 2.5 GT/s";
  5258. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_5_0GB)
  5259. spd = " 5 GT/s";
  5260. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_8_0GB)
  5261. spd = " 8 GT/s";
  5262. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100M)
  5263. bufp += sprintf(bufp, "100/");
  5264. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_1G)
  5265. bufp += sprintf(bufp, "1000/");
  5266. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
  5267. bufp += sprintf(bufp, "10G/");
  5268. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
  5269. bufp += sprintf(bufp, "40G/");
  5270. if (bufp != buf)
  5271. --bufp;
  5272. sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
  5273. netdev_info(dev, "Chelsio %s rev %d %s %sNIC PCIe x%d%s%s\n",
  5274. adap->params.vpd.id,
  5275. CHELSIO_CHIP_RELEASE(adap->params.chip), buf,
  5276. is_offload(adap) ? "R" : "", adap->params.pci.width, spd,
  5277. (adap->flags & USING_MSIX) ? " MSI-X" :
  5278. (adap->flags & USING_MSI) ? " MSI" : "");
  5279. netdev_info(dev, "S/N: %s, P/N: %s\n",
  5280. adap->params.vpd.sn, adap->params.vpd.pn);
  5281. }
  5282. static void enable_pcie_relaxed_ordering(struct pci_dev *dev)
  5283. {
  5284. pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
  5285. }
  5286. /*
  5287. * Free the following resources:
  5288. * - memory used for tables
  5289. * - MSI/MSI-X
  5290. * - net devices
  5291. * - resources FW is holding for us
  5292. */
  5293. static void free_some_resources(struct adapter *adapter)
  5294. {
  5295. unsigned int i;
  5296. t4_free_mem(adapter->l2t);
  5297. t4_free_mem(adapter->tids.tid_tab);
  5298. disable_msi(adapter);
  5299. for_each_port(adapter, i)
  5300. if (adapter->port[i]) {
  5301. kfree(adap2pinfo(adapter, i)->rss);
  5302. free_netdev(adapter->port[i]);
  5303. }
  5304. if (adapter->flags & FW_OK)
  5305. t4_fw_bye(adapter, adapter->fn);
  5306. }
  5307. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  5308. #define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
  5309. NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
  5310. #define SEGMENT_SIZE 128
  5311. static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  5312. {
  5313. int func, i, err, s_qpp, qpp, num_seg;
  5314. struct port_info *pi;
  5315. bool highdma = false;
  5316. struct adapter *adapter = NULL;
  5317. void __iomem *regs;
  5318. printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
  5319. err = pci_request_regions(pdev, KBUILD_MODNAME);
  5320. if (err) {
  5321. /* Just info, some other driver may have claimed the device. */
  5322. dev_info(&pdev->dev, "cannot obtain PCI resources\n");
  5323. return err;
  5324. }
  5325. err = pci_enable_device(pdev);
  5326. if (err) {
  5327. dev_err(&pdev->dev, "cannot enable PCI device\n");
  5328. goto out_release_regions;
  5329. }
  5330. regs = pci_ioremap_bar(pdev, 0);
  5331. if (!regs) {
  5332. dev_err(&pdev->dev, "cannot map device registers\n");
  5333. err = -ENOMEM;
  5334. goto out_disable_device;
  5335. }
  5336. err = t4_wait_dev_ready(regs);
  5337. if (err < 0)
  5338. goto out_unmap_bar0;
  5339. /* We control everything through one PF */
  5340. func = SOURCEPF_G(readl(regs + PL_WHOAMI_A));
  5341. if (func != ent->driver_data) {
  5342. iounmap(regs);
  5343. pci_disable_device(pdev);
  5344. pci_save_state(pdev); /* to restore SR-IOV later */
  5345. goto sriov;
  5346. }
  5347. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  5348. highdma = true;
  5349. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  5350. if (err) {
  5351. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
  5352. "coherent allocations\n");
  5353. goto out_unmap_bar0;
  5354. }
  5355. } else {
  5356. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  5357. if (err) {
  5358. dev_err(&pdev->dev, "no usable DMA configuration\n");
  5359. goto out_unmap_bar0;
  5360. }
  5361. }
  5362. pci_enable_pcie_error_reporting(pdev);
  5363. enable_pcie_relaxed_ordering(pdev);
  5364. pci_set_master(pdev);
  5365. pci_save_state(pdev);
  5366. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  5367. if (!adapter) {
  5368. err = -ENOMEM;
  5369. goto out_unmap_bar0;
  5370. }
  5371. adapter->workq = create_singlethread_workqueue("cxgb4");
  5372. if (!adapter->workq) {
  5373. err = -ENOMEM;
  5374. goto out_free_adapter;
  5375. }
  5376. /* PCI device has been enabled */
  5377. adapter->flags |= DEV_ENABLED;
  5378. adapter->regs = regs;
  5379. adapter->pdev = pdev;
  5380. adapter->pdev_dev = &pdev->dev;
  5381. adapter->mbox = func;
  5382. adapter->fn = func;
  5383. adapter->msg_enable = dflt_msg_enable;
  5384. memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
  5385. spin_lock_init(&adapter->stats_lock);
  5386. spin_lock_init(&adapter->tid_release_lock);
  5387. spin_lock_init(&adapter->win0_lock);
  5388. INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
  5389. INIT_WORK(&adapter->db_full_task, process_db_full);
  5390. INIT_WORK(&adapter->db_drop_task, process_db_drop);
  5391. err = t4_prep_adapter(adapter);
  5392. if (err)
  5393. goto out_free_adapter;
  5394. if (!is_t4(adapter->params.chip)) {
  5395. s_qpp = (QUEUESPERPAGEPF0_S +
  5396. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
  5397. adapter->fn);
  5398. qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
  5399. SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
  5400. num_seg = PAGE_SIZE / SEGMENT_SIZE;
  5401. /* Each segment size is 128B. Write coalescing is enabled only
  5402. * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
  5403. * queue is less no of segments that can be accommodated in
  5404. * a page size.
  5405. */
  5406. if (qpp > num_seg) {
  5407. dev_err(&pdev->dev,
  5408. "Incorrect number of egress queues per page\n");
  5409. err = -EINVAL;
  5410. goto out_free_adapter;
  5411. }
  5412. adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
  5413. pci_resource_len(pdev, 2));
  5414. if (!adapter->bar2) {
  5415. dev_err(&pdev->dev, "cannot map device bar2 region\n");
  5416. err = -ENOMEM;
  5417. goto out_free_adapter;
  5418. }
  5419. }
  5420. setup_memwin(adapter);
  5421. err = adap_init0(adapter);
  5422. setup_memwin_rdma(adapter);
  5423. if (err)
  5424. goto out_unmap_bar;
  5425. for_each_port(adapter, i) {
  5426. struct net_device *netdev;
  5427. netdev = alloc_etherdev_mq(sizeof(struct port_info),
  5428. MAX_ETH_QSETS);
  5429. if (!netdev) {
  5430. err = -ENOMEM;
  5431. goto out_free_dev;
  5432. }
  5433. SET_NETDEV_DEV(netdev, &pdev->dev);
  5434. adapter->port[i] = netdev;
  5435. pi = netdev_priv(netdev);
  5436. pi->adapter = adapter;
  5437. pi->xact_addr_filt = -1;
  5438. pi->port_id = i;
  5439. netdev->irq = pdev->irq;
  5440. netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
  5441. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  5442. NETIF_F_RXCSUM | NETIF_F_RXHASH |
  5443. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX;
  5444. if (highdma)
  5445. netdev->hw_features |= NETIF_F_HIGHDMA;
  5446. netdev->features |= netdev->hw_features;
  5447. netdev->vlan_features = netdev->features & VLAN_FEAT;
  5448. netdev->priv_flags |= IFF_UNICAST_FLT;
  5449. netdev->netdev_ops = &cxgb4_netdev_ops;
  5450. #ifdef CONFIG_CHELSIO_T4_DCB
  5451. netdev->dcbnl_ops = &cxgb4_dcb_ops;
  5452. cxgb4_dcb_state_init(netdev);
  5453. #endif
  5454. netdev->ethtool_ops = &cxgb_ethtool_ops;
  5455. }
  5456. pci_set_drvdata(pdev, adapter);
  5457. if (adapter->flags & FW_OK) {
  5458. err = t4_port_init(adapter, func, func, 0);
  5459. if (err)
  5460. goto out_free_dev;
  5461. }
  5462. /*
  5463. * Configure queues and allocate tables now, they can be needed as
  5464. * soon as the first register_netdev completes.
  5465. */
  5466. cfg_queues(adapter);
  5467. adapter->l2t = t4_init_l2t();
  5468. if (!adapter->l2t) {
  5469. /* We tolerate a lack of L2T, giving up some functionality */
  5470. dev_warn(&pdev->dev, "could not allocate L2T, continuing\n");
  5471. adapter->params.offload = 0;
  5472. }
  5473. #if IS_ENABLED(CONFIG_IPV6)
  5474. adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
  5475. adapter->clipt_end);
  5476. if (!adapter->clipt) {
  5477. /* We tolerate a lack of clip_table, giving up
  5478. * some functionality
  5479. */
  5480. dev_warn(&pdev->dev,
  5481. "could not allocate Clip table, continuing\n");
  5482. adapter->params.offload = 0;
  5483. }
  5484. #endif
  5485. if (is_offload(adapter) && tid_init(&adapter->tids) < 0) {
  5486. dev_warn(&pdev->dev, "could not allocate TID table, "
  5487. "continuing\n");
  5488. adapter->params.offload = 0;
  5489. }
  5490. /* See what interrupts we'll be using */
  5491. if (msi > 1 && enable_msix(adapter) == 0)
  5492. adapter->flags |= USING_MSIX;
  5493. else if (msi > 0 && pci_enable_msi(pdev) == 0)
  5494. adapter->flags |= USING_MSI;
  5495. err = init_rss(adapter);
  5496. if (err)
  5497. goto out_free_dev;
  5498. /*
  5499. * The card is now ready to go. If any errors occur during device
  5500. * registration we do not fail the whole card but rather proceed only
  5501. * with the ports we manage to register successfully. However we must
  5502. * register at least one net device.
  5503. */
  5504. for_each_port(adapter, i) {
  5505. pi = adap2pinfo(adapter, i);
  5506. netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
  5507. netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
  5508. err = register_netdev(adapter->port[i]);
  5509. if (err)
  5510. break;
  5511. adapter->chan_map[pi->tx_chan] = i;
  5512. print_port_info(adapter->port[i]);
  5513. }
  5514. if (i == 0) {
  5515. dev_err(&pdev->dev, "could not register any net devices\n");
  5516. goto out_free_dev;
  5517. }
  5518. if (err) {
  5519. dev_warn(&pdev->dev, "only %d net devices registered\n", i);
  5520. err = 0;
  5521. }
  5522. if (cxgb4_debugfs_root) {
  5523. adapter->debugfs_root = debugfs_create_dir(pci_name(pdev),
  5524. cxgb4_debugfs_root);
  5525. setup_debugfs(adapter);
  5526. }
  5527. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  5528. pdev->needs_freset = 1;
  5529. if (is_offload(adapter))
  5530. attach_ulds(adapter);
  5531. sriov:
  5532. #ifdef CONFIG_PCI_IOV
  5533. if (func < ARRAY_SIZE(num_vf) && num_vf[func] > 0)
  5534. if (pci_enable_sriov(pdev, num_vf[func]) == 0)
  5535. dev_info(&pdev->dev,
  5536. "instantiated %u virtual functions\n",
  5537. num_vf[func]);
  5538. #endif
  5539. return 0;
  5540. out_free_dev:
  5541. free_some_resources(adapter);
  5542. out_unmap_bar:
  5543. if (!is_t4(adapter->params.chip))
  5544. iounmap(adapter->bar2);
  5545. out_free_adapter:
  5546. if (adapter->workq)
  5547. destroy_workqueue(adapter->workq);
  5548. kfree(adapter);
  5549. out_unmap_bar0:
  5550. iounmap(regs);
  5551. out_disable_device:
  5552. pci_disable_pcie_error_reporting(pdev);
  5553. pci_disable_device(pdev);
  5554. out_release_regions:
  5555. pci_release_regions(pdev);
  5556. return err;
  5557. }
  5558. static void remove_one(struct pci_dev *pdev)
  5559. {
  5560. struct adapter *adapter = pci_get_drvdata(pdev);
  5561. #ifdef CONFIG_PCI_IOV
  5562. pci_disable_sriov(pdev);
  5563. #endif
  5564. if (adapter) {
  5565. int i;
  5566. /* Tear down per-adapter Work Queue first since it can contain
  5567. * references to our adapter data structure.
  5568. */
  5569. destroy_workqueue(adapter->workq);
  5570. if (is_offload(adapter))
  5571. detach_ulds(adapter);
  5572. for_each_port(adapter, i)
  5573. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  5574. unregister_netdev(adapter->port[i]);
  5575. debugfs_remove_recursive(adapter->debugfs_root);
  5576. /* If we allocated filters, free up state associated with any
  5577. * valid filters ...
  5578. */
  5579. if (adapter->tids.ftid_tab) {
  5580. struct filter_entry *f = &adapter->tids.ftid_tab[0];
  5581. for (i = 0; i < (adapter->tids.nftids +
  5582. adapter->tids.nsftids); i++, f++)
  5583. if (f->valid)
  5584. clear_filter(adapter, f);
  5585. }
  5586. if (adapter->flags & FULL_INIT_DONE)
  5587. cxgb_down(adapter);
  5588. free_some_resources(adapter);
  5589. #if IS_ENABLED(CONFIG_IPV6)
  5590. t4_cleanup_clip_tbl(adapter);
  5591. #endif
  5592. iounmap(adapter->regs);
  5593. if (!is_t4(adapter->params.chip))
  5594. iounmap(adapter->bar2);
  5595. pci_disable_pcie_error_reporting(pdev);
  5596. if ((adapter->flags & DEV_ENABLED)) {
  5597. pci_disable_device(pdev);
  5598. adapter->flags &= ~DEV_ENABLED;
  5599. }
  5600. pci_release_regions(pdev);
  5601. synchronize_rcu();
  5602. kfree(adapter);
  5603. } else
  5604. pci_release_regions(pdev);
  5605. }
  5606. static struct pci_driver cxgb4_driver = {
  5607. .name = KBUILD_MODNAME,
  5608. .id_table = cxgb4_pci_tbl,
  5609. .probe = init_one,
  5610. .remove = remove_one,
  5611. .shutdown = remove_one,
  5612. .err_handler = &cxgb4_eeh,
  5613. };
  5614. static int __init cxgb4_init_module(void)
  5615. {
  5616. int ret;
  5617. /* Debugfs support is optional, just warn if this fails */
  5618. cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  5619. if (!cxgb4_debugfs_root)
  5620. pr_warn("could not create debugfs entry, continuing\n");
  5621. ret = pci_register_driver(&cxgb4_driver);
  5622. if (ret < 0)
  5623. debugfs_remove(cxgb4_debugfs_root);
  5624. #if IS_ENABLED(CONFIG_IPV6)
  5625. if (!inet6addr_registered) {
  5626. register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5627. inet6addr_registered = true;
  5628. }
  5629. #endif
  5630. return ret;
  5631. }
  5632. static void __exit cxgb4_cleanup_module(void)
  5633. {
  5634. #if IS_ENABLED(CONFIG_IPV6)
  5635. if (inet6addr_registered) {
  5636. unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  5637. inet6addr_registered = false;
  5638. }
  5639. #endif
  5640. pci_unregister_driver(&cxgb4_driver);
  5641. debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
  5642. }
  5643. module_init(cxgb4_init_module);
  5644. module_exit(cxgb4_cleanup_module);