ixgbe_main.c 284 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2016 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include <linux/types.h>
  22. #include <linux/module.h>
  23. #include <linux/pci.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/string.h>
  27. #include <linux/in.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/ip.h>
  30. #include <linux/tcp.h>
  31. #include <linux/sctp.h>
  32. #include <linux/pkt_sched.h>
  33. #include <linux/ipv6.h>
  34. #include <linux/slab.h>
  35. #include <net/checksum.h>
  36. #include <net/ip6_checksum.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/if.h>
  40. #include <linux/if_vlan.h>
  41. #include <linux/if_macvlan.h>
  42. #include <linux/if_bridge.h>
  43. #include <linux/prefetch.h>
  44. #include <scsi/fc/fc_fcoe.h>
  45. #include <net/udp_tunnel.h>
  46. #include <net/pkt_cls.h>
  47. #include <net/tc_act/tc_gact.h>
  48. #include <net/tc_act/tc_mirred.h>
  49. #include <net/vxlan.h>
  50. #include "ixgbe.h"
  51. #include "ixgbe_common.h"
  52. #include "ixgbe_dcb_82599.h"
  53. #include "ixgbe_sriov.h"
  54. #include "ixgbe_model.h"
  55. char ixgbe_driver_name[] = "ixgbe";
  56. static const char ixgbe_driver_string[] =
  57. "Intel(R) 10 Gigabit PCI Express Network Driver";
  58. #ifdef IXGBE_FCOE
  59. char ixgbe_default_device_descr[] =
  60. "Intel(R) 10 Gigabit Network Connection";
  61. #else
  62. static char ixgbe_default_device_descr[] =
  63. "Intel(R) 10 Gigabit Network Connection";
  64. #endif
  65. #define DRV_VERSION "5.0.0-k"
  66. const char ixgbe_driver_version[] = DRV_VERSION;
  67. static const char ixgbe_copyright[] =
  68. "Copyright (c) 1999-2016 Intel Corporation.";
  69. static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter";
  70. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  71. [board_82598] = &ixgbe_82598_info,
  72. [board_82599] = &ixgbe_82599_info,
  73. [board_X540] = &ixgbe_X540_info,
  74. [board_X550] = &ixgbe_X550_info,
  75. [board_X550EM_x] = &ixgbe_X550EM_x_info,
  76. [board_x550em_a] = &ixgbe_x550em_a_info,
  77. [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
  78. };
  79. /* ixgbe_pci_tbl - PCI Device ID Table
  80. *
  81. * Wildcard entries (PCI_ANY_ID) should come last
  82. * Last entry must be all 0s
  83. *
  84. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  85. * Class, Class Mask, private data (not used) }
  86. */
  87. static const struct pci_device_id ixgbe_pci_tbl[] = {
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
  89. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
  91. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
  93. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
  95. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
  97. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
  99. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
  101. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
  102. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
  103. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
  104. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
  105. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
  106. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
  107. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
  108. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
  109. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
  110. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
  111. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
  112. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
  113. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
  114. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
  115. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
  116. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
  117. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
  118. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
  119. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
  120. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
  121. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
  122. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
  123. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
  124. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
  125. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
  126. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
  127. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
  128. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
  129. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
  130. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
  131. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
  132. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
  133. /* required last entry */
  134. {0, }
  135. };
  136. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  137. #ifdef CONFIG_IXGBE_DCA
  138. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  139. void *p);
  140. static struct notifier_block dca_notifier = {
  141. .notifier_call = ixgbe_notify_dca,
  142. .next = NULL,
  143. .priority = 0
  144. };
  145. #endif
  146. #ifdef CONFIG_PCI_IOV
  147. static unsigned int max_vfs;
  148. module_param(max_vfs, uint, 0);
  149. MODULE_PARM_DESC(max_vfs,
  150. "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
  151. #endif /* CONFIG_PCI_IOV */
  152. static unsigned int allow_unsupported_sfp;
  153. module_param(allow_unsupported_sfp, uint, 0);
  154. MODULE_PARM_DESC(allow_unsupported_sfp,
  155. "Allow unsupported and untested SFP+ modules on 82599-based adapters");
  156. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  157. static int debug = -1;
  158. module_param(debug, int, 0);
  159. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  160. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  161. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  162. MODULE_LICENSE("GPL");
  163. MODULE_VERSION(DRV_VERSION);
  164. static struct workqueue_struct *ixgbe_wq;
  165. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
  166. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
  167. static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
  168. u32 reg, u16 *value)
  169. {
  170. struct pci_dev *parent_dev;
  171. struct pci_bus *parent_bus;
  172. parent_bus = adapter->pdev->bus->parent;
  173. if (!parent_bus)
  174. return -1;
  175. parent_dev = parent_bus->self;
  176. if (!parent_dev)
  177. return -1;
  178. if (!pci_is_pcie(parent_dev))
  179. return -1;
  180. pcie_capability_read_word(parent_dev, reg, value);
  181. if (*value == IXGBE_FAILED_READ_CFG_WORD &&
  182. ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
  183. return -1;
  184. return 0;
  185. }
  186. static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
  187. {
  188. struct ixgbe_hw *hw = &adapter->hw;
  189. u16 link_status = 0;
  190. int err;
  191. hw->bus.type = ixgbe_bus_type_pci_express;
  192. /* Get the negotiated link width and speed from PCI config space of the
  193. * parent, as this device is behind a switch
  194. */
  195. err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
  196. /* assume caller will handle error case */
  197. if (err)
  198. return err;
  199. hw->bus.width = ixgbe_convert_bus_width(link_status);
  200. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  201. return 0;
  202. }
  203. /**
  204. * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
  205. * @hw: hw specific details
  206. *
  207. * This function is used by probe to determine whether a device's PCI-Express
  208. * bandwidth details should be gathered from the parent bus instead of from the
  209. * device. Used to ensure that various locations all have the correct device ID
  210. * checks.
  211. */
  212. static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
  213. {
  214. switch (hw->device_id) {
  215. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  216. case IXGBE_DEV_ID_82599_QSFP_SF_QP:
  217. return true;
  218. default:
  219. return false;
  220. }
  221. }
  222. static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
  223. int expected_gts)
  224. {
  225. struct ixgbe_hw *hw = &adapter->hw;
  226. int max_gts = 0;
  227. enum pci_bus_speed speed = PCI_SPEED_UNKNOWN;
  228. enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN;
  229. struct pci_dev *pdev;
  230. /* Some devices are not connected over PCIe and thus do not negotiate
  231. * speed. These devices do not have valid bus info, and thus any report
  232. * we generate may not be correct.
  233. */
  234. if (hw->bus.type == ixgbe_bus_type_internal)
  235. return;
  236. /* determine whether to use the parent device */
  237. if (ixgbe_pcie_from_parent(&adapter->hw))
  238. pdev = adapter->pdev->bus->parent->self;
  239. else
  240. pdev = adapter->pdev;
  241. if (pcie_get_minimum_link(pdev, &speed, &width) ||
  242. speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
  243. e_dev_warn("Unable to determine PCI Express bandwidth.\n");
  244. return;
  245. }
  246. switch (speed) {
  247. case PCIE_SPEED_2_5GT:
  248. /* 8b/10b encoding reduces max throughput by 20% */
  249. max_gts = 2 * width;
  250. break;
  251. case PCIE_SPEED_5_0GT:
  252. /* 8b/10b encoding reduces max throughput by 20% */
  253. max_gts = 4 * width;
  254. break;
  255. case PCIE_SPEED_8_0GT:
  256. /* 128b/130b encoding reduces throughput by less than 2% */
  257. max_gts = 8 * width;
  258. break;
  259. default:
  260. e_dev_warn("Unable to determine PCI Express bandwidth.\n");
  261. return;
  262. }
  263. e_dev_info("PCI Express bandwidth of %dGT/s available\n",
  264. max_gts);
  265. e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n",
  266. (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" :
  267. speed == PCIE_SPEED_5_0GT ? "5.0GT/s" :
  268. speed == PCIE_SPEED_2_5GT ? "2.5GT/s" :
  269. "Unknown"),
  270. width,
  271. (speed == PCIE_SPEED_2_5GT ? "20%" :
  272. speed == PCIE_SPEED_5_0GT ? "20%" :
  273. speed == PCIE_SPEED_8_0GT ? "<2%" :
  274. "Unknown"));
  275. if (max_gts < expected_gts) {
  276. e_dev_warn("This is not sufficient for optimal performance of this card.\n");
  277. e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n",
  278. expected_gts);
  279. e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n");
  280. }
  281. }
  282. static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
  283. {
  284. if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
  285. !test_bit(__IXGBE_REMOVING, &adapter->state) &&
  286. !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
  287. queue_work(ixgbe_wq, &adapter->service_task);
  288. }
  289. static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
  290. {
  291. struct ixgbe_adapter *adapter = hw->back;
  292. if (!hw->hw_addr)
  293. return;
  294. hw->hw_addr = NULL;
  295. e_dev_err("Adapter removed\n");
  296. if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  297. ixgbe_service_event_schedule(adapter);
  298. }
  299. static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
  300. {
  301. u32 value;
  302. /* The following check not only optimizes a bit by not
  303. * performing a read on the status register when the
  304. * register just read was a status register read that
  305. * returned IXGBE_FAILED_READ_REG. It also blocks any
  306. * potential recursion.
  307. */
  308. if (reg == IXGBE_STATUS) {
  309. ixgbe_remove_adapter(hw);
  310. return;
  311. }
  312. value = ixgbe_read_reg(hw, IXGBE_STATUS);
  313. if (value == IXGBE_FAILED_READ_REG)
  314. ixgbe_remove_adapter(hw);
  315. }
  316. /**
  317. * ixgbe_read_reg - Read from device register
  318. * @hw: hw specific details
  319. * @reg: offset of register to read
  320. *
  321. * Returns : value read or IXGBE_FAILED_READ_REG if removed
  322. *
  323. * This function is used to read device registers. It checks for device
  324. * removal by confirming any read that returns all ones by checking the
  325. * status register value for all ones. This function avoids reading from
  326. * the hardware if a removal was previously detected in which case it
  327. * returns IXGBE_FAILED_READ_REG (all ones).
  328. */
  329. u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
  330. {
  331. u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
  332. u32 value;
  333. if (ixgbe_removed(reg_addr))
  334. return IXGBE_FAILED_READ_REG;
  335. if (unlikely(hw->phy.nw_mng_if_sel &
  336. IXGBE_NW_MNG_IF_SEL_ENABLE_10_100M)) {
  337. struct ixgbe_adapter *adapter;
  338. int i;
  339. for (i = 0; i < 200; ++i) {
  340. value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
  341. if (likely(!value))
  342. goto writes_completed;
  343. if (value == IXGBE_FAILED_READ_REG) {
  344. ixgbe_remove_adapter(hw);
  345. return IXGBE_FAILED_READ_REG;
  346. }
  347. udelay(5);
  348. }
  349. adapter = hw->back;
  350. e_warn(hw, "register writes incomplete %08x\n", value);
  351. }
  352. writes_completed:
  353. value = readl(reg_addr + reg);
  354. if (unlikely(value == IXGBE_FAILED_READ_REG))
  355. ixgbe_check_remove(hw, reg);
  356. return value;
  357. }
  358. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
  359. {
  360. u16 value;
  361. pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
  362. if (value == IXGBE_FAILED_READ_CFG_WORD) {
  363. ixgbe_remove_adapter(hw);
  364. return true;
  365. }
  366. return false;
  367. }
  368. u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
  369. {
  370. struct ixgbe_adapter *adapter = hw->back;
  371. u16 value;
  372. if (ixgbe_removed(hw->hw_addr))
  373. return IXGBE_FAILED_READ_CFG_WORD;
  374. pci_read_config_word(adapter->pdev, reg, &value);
  375. if (value == IXGBE_FAILED_READ_CFG_WORD &&
  376. ixgbe_check_cfg_remove(hw, adapter->pdev))
  377. return IXGBE_FAILED_READ_CFG_WORD;
  378. return value;
  379. }
  380. #ifdef CONFIG_PCI_IOV
  381. static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
  382. {
  383. struct ixgbe_adapter *adapter = hw->back;
  384. u32 value;
  385. if (ixgbe_removed(hw->hw_addr))
  386. return IXGBE_FAILED_READ_CFG_DWORD;
  387. pci_read_config_dword(adapter->pdev, reg, &value);
  388. if (value == IXGBE_FAILED_READ_CFG_DWORD &&
  389. ixgbe_check_cfg_remove(hw, adapter->pdev))
  390. return IXGBE_FAILED_READ_CFG_DWORD;
  391. return value;
  392. }
  393. #endif /* CONFIG_PCI_IOV */
  394. void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
  395. {
  396. struct ixgbe_adapter *adapter = hw->back;
  397. if (ixgbe_removed(hw->hw_addr))
  398. return;
  399. pci_write_config_word(adapter->pdev, reg, value);
  400. }
  401. static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
  402. {
  403. BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
  404. /* flush memory to make sure state is correct before next watchdog */
  405. smp_mb__before_atomic();
  406. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  407. }
  408. struct ixgbe_reg_info {
  409. u32 ofs;
  410. char *name;
  411. };
  412. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  413. /* General Registers */
  414. {IXGBE_CTRL, "CTRL"},
  415. {IXGBE_STATUS, "STATUS"},
  416. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  417. /* Interrupt Registers */
  418. {IXGBE_EICR, "EICR"},
  419. /* RX Registers */
  420. {IXGBE_SRRCTL(0), "SRRCTL"},
  421. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  422. {IXGBE_RDLEN(0), "RDLEN"},
  423. {IXGBE_RDH(0), "RDH"},
  424. {IXGBE_RDT(0), "RDT"},
  425. {IXGBE_RXDCTL(0), "RXDCTL"},
  426. {IXGBE_RDBAL(0), "RDBAL"},
  427. {IXGBE_RDBAH(0), "RDBAH"},
  428. /* TX Registers */
  429. {IXGBE_TDBAL(0), "TDBAL"},
  430. {IXGBE_TDBAH(0), "TDBAH"},
  431. {IXGBE_TDLEN(0), "TDLEN"},
  432. {IXGBE_TDH(0), "TDH"},
  433. {IXGBE_TDT(0), "TDT"},
  434. {IXGBE_TXDCTL(0), "TXDCTL"},
  435. /* List Terminator */
  436. { .name = NULL }
  437. };
  438. /*
  439. * ixgbe_regdump - register printout routine
  440. */
  441. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  442. {
  443. int i = 0, j = 0;
  444. char rname[16];
  445. u32 regs[64];
  446. switch (reginfo->ofs) {
  447. case IXGBE_SRRCTL(0):
  448. for (i = 0; i < 64; i++)
  449. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  450. break;
  451. case IXGBE_DCA_RXCTRL(0):
  452. for (i = 0; i < 64; i++)
  453. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  454. break;
  455. case IXGBE_RDLEN(0):
  456. for (i = 0; i < 64; i++)
  457. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  458. break;
  459. case IXGBE_RDH(0):
  460. for (i = 0; i < 64; i++)
  461. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  462. break;
  463. case IXGBE_RDT(0):
  464. for (i = 0; i < 64; i++)
  465. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  466. break;
  467. case IXGBE_RXDCTL(0):
  468. for (i = 0; i < 64; i++)
  469. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  470. break;
  471. case IXGBE_RDBAL(0):
  472. for (i = 0; i < 64; i++)
  473. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  474. break;
  475. case IXGBE_RDBAH(0):
  476. for (i = 0; i < 64; i++)
  477. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  478. break;
  479. case IXGBE_TDBAL(0):
  480. for (i = 0; i < 64; i++)
  481. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  482. break;
  483. case IXGBE_TDBAH(0):
  484. for (i = 0; i < 64; i++)
  485. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  486. break;
  487. case IXGBE_TDLEN(0):
  488. for (i = 0; i < 64; i++)
  489. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  490. break;
  491. case IXGBE_TDH(0):
  492. for (i = 0; i < 64; i++)
  493. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  494. break;
  495. case IXGBE_TDT(0):
  496. for (i = 0; i < 64; i++)
  497. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  498. break;
  499. case IXGBE_TXDCTL(0):
  500. for (i = 0; i < 64; i++)
  501. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  502. break;
  503. default:
  504. pr_info("%-15s %08x\n", reginfo->name,
  505. IXGBE_READ_REG(hw, reginfo->ofs));
  506. return;
  507. }
  508. for (i = 0; i < 8; i++) {
  509. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
  510. pr_err("%-15s", rname);
  511. for (j = 0; j < 8; j++)
  512. pr_cont(" %08x", regs[i*8+j]);
  513. pr_cont("\n");
  514. }
  515. }
  516. /*
  517. * ixgbe_dump - Print registers, tx-rings and rx-rings
  518. */
  519. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  520. {
  521. struct net_device *netdev = adapter->netdev;
  522. struct ixgbe_hw *hw = &adapter->hw;
  523. struct ixgbe_reg_info *reginfo;
  524. int n = 0;
  525. struct ixgbe_ring *tx_ring;
  526. struct ixgbe_tx_buffer *tx_buffer;
  527. union ixgbe_adv_tx_desc *tx_desc;
  528. struct my_u0 { u64 a; u64 b; } *u0;
  529. struct ixgbe_ring *rx_ring;
  530. union ixgbe_adv_rx_desc *rx_desc;
  531. struct ixgbe_rx_buffer *rx_buffer_info;
  532. u32 staterr;
  533. int i = 0;
  534. if (!netif_msg_hw(adapter))
  535. return;
  536. /* Print netdevice Info */
  537. if (netdev) {
  538. dev_info(&adapter->pdev->dev, "Net device Info\n");
  539. pr_info("Device Name state "
  540. "trans_start\n");
  541. pr_info("%-15s %016lX %016lX\n",
  542. netdev->name,
  543. netdev->state,
  544. dev_trans_start(netdev));
  545. }
  546. /* Print Registers */
  547. dev_info(&adapter->pdev->dev, "Register Dump\n");
  548. pr_info(" Register Name Value\n");
  549. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  550. reginfo->name; reginfo++) {
  551. ixgbe_regdump(hw, reginfo);
  552. }
  553. /* Print TX Ring Summary */
  554. if (!netdev || !netif_running(netdev))
  555. return;
  556. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  557. pr_info(" %s %s %s %s\n",
  558. "Queue [NTU] [NTC] [bi(ntc)->dma ]",
  559. "leng", "ntw", "timestamp");
  560. for (n = 0; n < adapter->num_tx_queues; n++) {
  561. tx_ring = adapter->tx_ring[n];
  562. tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  563. pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
  564. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  565. (u64)dma_unmap_addr(tx_buffer, dma),
  566. dma_unmap_len(tx_buffer, len),
  567. tx_buffer->next_to_watch,
  568. (u64)tx_buffer->time_stamp);
  569. }
  570. /* Print TX Rings */
  571. if (!netif_msg_tx_done(adapter))
  572. goto rx_ring_summary;
  573. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  574. /* Transmit Descriptor Formats
  575. *
  576. * 82598 Advanced Transmit Descriptor
  577. * +--------------------------------------------------------------+
  578. * 0 | Buffer Address [63:0] |
  579. * +--------------------------------------------------------------+
  580. * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  581. * +--------------------------------------------------------------+
  582. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  583. *
  584. * 82598 Advanced Transmit Descriptor (Write-Back Format)
  585. * +--------------------------------------------------------------+
  586. * 0 | RSV [63:0] |
  587. * +--------------------------------------------------------------+
  588. * 8 | RSV | STA | NXTSEQ |
  589. * +--------------------------------------------------------------+
  590. * 63 36 35 32 31 0
  591. *
  592. * 82599+ Advanced Transmit Descriptor
  593. * +--------------------------------------------------------------+
  594. * 0 | Buffer Address [63:0] |
  595. * +--------------------------------------------------------------+
  596. * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
  597. * +--------------------------------------------------------------+
  598. * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
  599. *
  600. * 82599+ Advanced Transmit Descriptor (Write-Back Format)
  601. * +--------------------------------------------------------------+
  602. * 0 | RSV [63:0] |
  603. * +--------------------------------------------------------------+
  604. * 8 | RSV | STA | RSV |
  605. * +--------------------------------------------------------------+
  606. * 63 36 35 32 31 0
  607. */
  608. for (n = 0; n < adapter->num_tx_queues; n++) {
  609. tx_ring = adapter->tx_ring[n];
  610. pr_info("------------------------------------\n");
  611. pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  612. pr_info("------------------------------------\n");
  613. pr_info("%s%s %s %s %s %s\n",
  614. "T [desc] [address 63:0 ] ",
  615. "[PlPOIdStDDt Ln] [bi->dma ] ",
  616. "leng", "ntw", "timestamp", "bi->skb");
  617. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  618. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  619. tx_buffer = &tx_ring->tx_buffer_info[i];
  620. u0 = (struct my_u0 *)tx_desc;
  621. if (dma_unmap_len(tx_buffer, len) > 0) {
  622. pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
  623. i,
  624. le64_to_cpu(u0->a),
  625. le64_to_cpu(u0->b),
  626. (u64)dma_unmap_addr(tx_buffer, dma),
  627. dma_unmap_len(tx_buffer, len),
  628. tx_buffer->next_to_watch,
  629. (u64)tx_buffer->time_stamp,
  630. tx_buffer->skb);
  631. if (i == tx_ring->next_to_use &&
  632. i == tx_ring->next_to_clean)
  633. pr_cont(" NTC/U\n");
  634. else if (i == tx_ring->next_to_use)
  635. pr_cont(" NTU\n");
  636. else if (i == tx_ring->next_to_clean)
  637. pr_cont(" NTC\n");
  638. else
  639. pr_cont("\n");
  640. if (netif_msg_pktdata(adapter) &&
  641. tx_buffer->skb)
  642. print_hex_dump(KERN_INFO, "",
  643. DUMP_PREFIX_ADDRESS, 16, 1,
  644. tx_buffer->skb->data,
  645. dma_unmap_len(tx_buffer, len),
  646. true);
  647. }
  648. }
  649. }
  650. /* Print RX Rings Summary */
  651. rx_ring_summary:
  652. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  653. pr_info("Queue [NTU] [NTC]\n");
  654. for (n = 0; n < adapter->num_rx_queues; n++) {
  655. rx_ring = adapter->rx_ring[n];
  656. pr_info("%5d %5X %5X\n",
  657. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  658. }
  659. /* Print RX Rings */
  660. if (!netif_msg_rx_status(adapter))
  661. return;
  662. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  663. /* Receive Descriptor Formats
  664. *
  665. * 82598 Advanced Receive Descriptor (Read) Format
  666. * 63 1 0
  667. * +-----------------------------------------------------+
  668. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  669. * +----------------------------------------------+------+
  670. * 8 | Header Buffer Address [63:1] | DD |
  671. * +-----------------------------------------------------+
  672. *
  673. *
  674. * 82598 Advanced Receive Descriptor (Write-Back) Format
  675. *
  676. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  677. * +------------------------------------------------------+
  678. * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
  679. * | Packet | IP | | | | Type | Type |
  680. * | Checksum | Ident | | | | | |
  681. * +------------------------------------------------------+
  682. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  683. * +------------------------------------------------------+
  684. * 63 48 47 32 31 20 19 0
  685. *
  686. * 82599+ Advanced Receive Descriptor (Read) Format
  687. * 63 1 0
  688. * +-----------------------------------------------------+
  689. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  690. * +----------------------------------------------+------+
  691. * 8 | Header Buffer Address [63:1] | DD |
  692. * +-----------------------------------------------------+
  693. *
  694. *
  695. * 82599+ Advanced Receive Descriptor (Write-Back) Format
  696. *
  697. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  698. * +------------------------------------------------------+
  699. * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
  700. * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
  701. * |/ Flow Dir Flt ID | | | | | |
  702. * +------------------------------------------------------+
  703. * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
  704. * +------------------------------------------------------+
  705. * 63 48 47 32 31 20 19 0
  706. */
  707. for (n = 0; n < adapter->num_rx_queues; n++) {
  708. rx_ring = adapter->rx_ring[n];
  709. pr_info("------------------------------------\n");
  710. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  711. pr_info("------------------------------------\n");
  712. pr_info("%s%s%s",
  713. "R [desc] [ PktBuf A0] ",
  714. "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
  715. "<-- Adv Rx Read format\n");
  716. pr_info("%s%s%s",
  717. "RWB[desc] [PcsmIpSHl PtRs] ",
  718. "[vl er S cks ln] ---------------- [bi->skb ] ",
  719. "<-- Adv Rx Write-Back format\n");
  720. for (i = 0; i < rx_ring->count; i++) {
  721. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  722. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  723. u0 = (struct my_u0 *)rx_desc;
  724. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  725. if (staterr & IXGBE_RXD_STAT_DD) {
  726. /* Descriptor Done */
  727. pr_info("RWB[0x%03X] %016llX "
  728. "%016llX ---------------- %p", i,
  729. le64_to_cpu(u0->a),
  730. le64_to_cpu(u0->b),
  731. rx_buffer_info->skb);
  732. } else {
  733. pr_info("R [0x%03X] %016llX "
  734. "%016llX %016llX %p", i,
  735. le64_to_cpu(u0->a),
  736. le64_to_cpu(u0->b),
  737. (u64)rx_buffer_info->dma,
  738. rx_buffer_info->skb);
  739. if (netif_msg_pktdata(adapter) &&
  740. rx_buffer_info->dma) {
  741. print_hex_dump(KERN_INFO, "",
  742. DUMP_PREFIX_ADDRESS, 16, 1,
  743. page_address(rx_buffer_info->page) +
  744. rx_buffer_info->page_offset,
  745. ixgbe_rx_bufsz(rx_ring), true);
  746. }
  747. }
  748. if (i == rx_ring->next_to_use)
  749. pr_cont(" NTU\n");
  750. else if (i == rx_ring->next_to_clean)
  751. pr_cont(" NTC\n");
  752. else
  753. pr_cont("\n");
  754. }
  755. }
  756. }
  757. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  758. {
  759. u32 ctrl_ext;
  760. /* Let firmware take over control of h/w */
  761. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  762. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  763. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  764. }
  765. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  766. {
  767. u32 ctrl_ext;
  768. /* Let firmware know the driver has taken over */
  769. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  770. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  771. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  772. }
  773. /**
  774. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  775. * @adapter: pointer to adapter struct
  776. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  777. * @queue: queue to map the corresponding interrupt to
  778. * @msix_vector: the vector to map to the corresponding queue
  779. *
  780. */
  781. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  782. u8 queue, u8 msix_vector)
  783. {
  784. u32 ivar, index;
  785. struct ixgbe_hw *hw = &adapter->hw;
  786. switch (hw->mac.type) {
  787. case ixgbe_mac_82598EB:
  788. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  789. if (direction == -1)
  790. direction = 0;
  791. index = (((direction * 64) + queue) >> 2) & 0x1F;
  792. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  793. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  794. ivar |= (msix_vector << (8 * (queue & 0x3)));
  795. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  796. break;
  797. case ixgbe_mac_82599EB:
  798. case ixgbe_mac_X540:
  799. case ixgbe_mac_X550:
  800. case ixgbe_mac_X550EM_x:
  801. case ixgbe_mac_x550em_a:
  802. if (direction == -1) {
  803. /* other causes */
  804. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  805. index = ((queue & 1) * 8);
  806. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  807. ivar &= ~(0xFF << index);
  808. ivar |= (msix_vector << index);
  809. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  810. break;
  811. } else {
  812. /* tx or rx causes */
  813. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  814. index = ((16 * (queue & 1)) + (8 * direction));
  815. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  816. ivar &= ~(0xFF << index);
  817. ivar |= (msix_vector << index);
  818. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  819. break;
  820. }
  821. default:
  822. break;
  823. }
  824. }
  825. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  826. u64 qmask)
  827. {
  828. u32 mask;
  829. switch (adapter->hw.mac.type) {
  830. case ixgbe_mac_82598EB:
  831. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  832. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  833. break;
  834. case ixgbe_mac_82599EB:
  835. case ixgbe_mac_X540:
  836. case ixgbe_mac_X550:
  837. case ixgbe_mac_X550EM_x:
  838. case ixgbe_mac_x550em_a:
  839. mask = (qmask & 0xFFFFFFFF);
  840. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  841. mask = (qmask >> 32);
  842. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  843. break;
  844. default:
  845. break;
  846. }
  847. }
  848. static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
  849. {
  850. struct ixgbe_hw *hw = &adapter->hw;
  851. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  852. int i;
  853. u32 data;
  854. if ((hw->fc.current_mode != ixgbe_fc_full) &&
  855. (hw->fc.current_mode != ixgbe_fc_rx_pause))
  856. return;
  857. switch (hw->mac.type) {
  858. case ixgbe_mac_82598EB:
  859. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  860. break;
  861. default:
  862. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  863. }
  864. hwstats->lxoffrxc += data;
  865. /* refill credits (no tx hang) if we received xoff */
  866. if (!data)
  867. return;
  868. for (i = 0; i < adapter->num_tx_queues; i++)
  869. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  870. &adapter->tx_ring[i]->state);
  871. }
  872. static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
  873. {
  874. struct ixgbe_hw *hw = &adapter->hw;
  875. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  876. u32 xoff[8] = {0};
  877. u8 tc;
  878. int i;
  879. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  880. if (adapter->ixgbe_ieee_pfc)
  881. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  882. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
  883. ixgbe_update_xoff_rx_lfc(adapter);
  884. return;
  885. }
  886. /* update stats for each tc, only valid with PFC enabled */
  887. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  888. u32 pxoffrxc;
  889. switch (hw->mac.type) {
  890. case ixgbe_mac_82598EB:
  891. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  892. break;
  893. default:
  894. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  895. }
  896. hwstats->pxoffrxc[i] += pxoffrxc;
  897. /* Get the TC for given UP */
  898. tc = netdev_get_prio_tc_map(adapter->netdev, i);
  899. xoff[tc] += pxoffrxc;
  900. }
  901. /* disarm tx queues that have received xoff frames */
  902. for (i = 0; i < adapter->num_tx_queues; i++) {
  903. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  904. tc = tx_ring->dcb_tc;
  905. if (xoff[tc])
  906. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  907. }
  908. }
  909. static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
  910. {
  911. return ring->stats.packets;
  912. }
  913. static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
  914. {
  915. struct ixgbe_adapter *adapter;
  916. struct ixgbe_hw *hw;
  917. u32 head, tail;
  918. if (ring->l2_accel_priv)
  919. adapter = ring->l2_accel_priv->real_adapter;
  920. else
  921. adapter = netdev_priv(ring->netdev);
  922. hw = &adapter->hw;
  923. head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
  924. tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
  925. if (head != tail)
  926. return (head < tail) ?
  927. tail - head : (tail + ring->count - head);
  928. return 0;
  929. }
  930. static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
  931. {
  932. u32 tx_done = ixgbe_get_tx_completed(tx_ring);
  933. u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
  934. u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
  935. clear_check_for_tx_hang(tx_ring);
  936. /*
  937. * Check for a hung queue, but be thorough. This verifies
  938. * that a transmit has been completed since the previous
  939. * check AND there is at least one packet pending. The
  940. * ARMED bit is set to indicate a potential hang. The
  941. * bit is cleared if a pause frame is received to remove
  942. * false hang detection due to PFC or 802.3x frames. By
  943. * requiring this to fail twice we avoid races with
  944. * pfc clearing the ARMED bit and conditions where we
  945. * run the check_tx_hang logic with a transmit completion
  946. * pending but without time to complete it yet.
  947. */
  948. if (tx_done_old == tx_done && tx_pending)
  949. /* make sure it is true for two checks in a row */
  950. return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
  951. &tx_ring->state);
  952. /* update completed stats and continue */
  953. tx_ring->tx_stats.tx_done_old = tx_done;
  954. /* reset the countdown */
  955. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  956. return false;
  957. }
  958. /**
  959. * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
  960. * @adapter: driver private struct
  961. **/
  962. static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
  963. {
  964. /* Do the reset outside of interrupt context */
  965. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  966. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  967. e_warn(drv, "initiating reset due to tx timeout\n");
  968. ixgbe_service_event_schedule(adapter);
  969. }
  970. }
  971. /**
  972. * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
  973. **/
  974. static int ixgbe_tx_maxrate(struct net_device *netdev,
  975. int queue_index, u32 maxrate)
  976. {
  977. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  978. struct ixgbe_hw *hw = &adapter->hw;
  979. u32 bcnrc_val = ixgbe_link_mbps(adapter);
  980. if (!maxrate)
  981. return 0;
  982. /* Calculate the rate factor values to set */
  983. bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
  984. bcnrc_val /= maxrate;
  985. /* clear everything but the rate factor */
  986. bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
  987. IXGBE_RTTBCNRC_RF_DEC_MASK;
  988. /* enable the rate scheduler */
  989. bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
  990. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
  991. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
  992. return 0;
  993. }
  994. /**
  995. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  996. * @q_vector: structure containing interrupt and ring information
  997. * @tx_ring: tx ring to clean
  998. * @napi_budget: Used to determine if we are in netpoll
  999. **/
  1000. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  1001. struct ixgbe_ring *tx_ring, int napi_budget)
  1002. {
  1003. struct ixgbe_adapter *adapter = q_vector->adapter;
  1004. struct ixgbe_tx_buffer *tx_buffer;
  1005. union ixgbe_adv_tx_desc *tx_desc;
  1006. unsigned int total_bytes = 0, total_packets = 0;
  1007. unsigned int budget = q_vector->tx.work_limit;
  1008. unsigned int i = tx_ring->next_to_clean;
  1009. if (test_bit(__IXGBE_DOWN, &adapter->state))
  1010. return true;
  1011. tx_buffer = &tx_ring->tx_buffer_info[i];
  1012. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  1013. i -= tx_ring->count;
  1014. do {
  1015. union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
  1016. /* if next_to_watch is not set then there is no work pending */
  1017. if (!eop_desc)
  1018. break;
  1019. /* prevent any other reads prior to eop_desc */
  1020. read_barrier_depends();
  1021. /* if DD is not set pending work has not been completed */
  1022. if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
  1023. break;
  1024. /* clear next_to_watch to prevent false hangs */
  1025. tx_buffer->next_to_watch = NULL;
  1026. /* update the statistics for this packet */
  1027. total_bytes += tx_buffer->bytecount;
  1028. total_packets += tx_buffer->gso_segs;
  1029. /* free the skb */
  1030. napi_consume_skb(tx_buffer->skb, napi_budget);
  1031. /* unmap skb header data */
  1032. dma_unmap_single(tx_ring->dev,
  1033. dma_unmap_addr(tx_buffer, dma),
  1034. dma_unmap_len(tx_buffer, len),
  1035. DMA_TO_DEVICE);
  1036. /* clear tx_buffer data */
  1037. dma_unmap_len_set(tx_buffer, len, 0);
  1038. /* unmap remaining buffers */
  1039. while (tx_desc != eop_desc) {
  1040. tx_buffer++;
  1041. tx_desc++;
  1042. i++;
  1043. if (unlikely(!i)) {
  1044. i -= tx_ring->count;
  1045. tx_buffer = tx_ring->tx_buffer_info;
  1046. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1047. }
  1048. /* unmap any remaining paged data */
  1049. if (dma_unmap_len(tx_buffer, len)) {
  1050. dma_unmap_page(tx_ring->dev,
  1051. dma_unmap_addr(tx_buffer, dma),
  1052. dma_unmap_len(tx_buffer, len),
  1053. DMA_TO_DEVICE);
  1054. dma_unmap_len_set(tx_buffer, len, 0);
  1055. }
  1056. }
  1057. /* move us one more past the eop_desc for start of next pkt */
  1058. tx_buffer++;
  1059. tx_desc++;
  1060. i++;
  1061. if (unlikely(!i)) {
  1062. i -= tx_ring->count;
  1063. tx_buffer = tx_ring->tx_buffer_info;
  1064. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1065. }
  1066. /* issue prefetch for next Tx descriptor */
  1067. prefetch(tx_desc);
  1068. /* update budget accounting */
  1069. budget--;
  1070. } while (likely(budget));
  1071. i += tx_ring->count;
  1072. tx_ring->next_to_clean = i;
  1073. u64_stats_update_begin(&tx_ring->syncp);
  1074. tx_ring->stats.bytes += total_bytes;
  1075. tx_ring->stats.packets += total_packets;
  1076. u64_stats_update_end(&tx_ring->syncp);
  1077. q_vector->tx.total_bytes += total_bytes;
  1078. q_vector->tx.total_packets += total_packets;
  1079. if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
  1080. /* schedule immediate reset if we believe we hung */
  1081. struct ixgbe_hw *hw = &adapter->hw;
  1082. e_err(drv, "Detected Tx Unit Hang\n"
  1083. " Tx Queue <%d>\n"
  1084. " TDH, TDT <%x>, <%x>\n"
  1085. " next_to_use <%x>\n"
  1086. " next_to_clean <%x>\n"
  1087. "tx_buffer_info[next_to_clean]\n"
  1088. " time_stamp <%lx>\n"
  1089. " jiffies <%lx>\n",
  1090. tx_ring->queue_index,
  1091. IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
  1092. IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
  1093. tx_ring->next_to_use, i,
  1094. tx_ring->tx_buffer_info[i].time_stamp, jiffies);
  1095. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  1096. e_info(probe,
  1097. "tx hang %d detected on queue %d, resetting adapter\n",
  1098. adapter->tx_timeout_count + 1, tx_ring->queue_index);
  1099. /* schedule immediate reset if we believe we hung */
  1100. ixgbe_tx_timeout_reset(adapter);
  1101. /* the adapter is about to reset, no point in enabling stuff */
  1102. return true;
  1103. }
  1104. netdev_tx_completed_queue(txring_txq(tx_ring),
  1105. total_packets, total_bytes);
  1106. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  1107. if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
  1108. (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
  1109. /* Make sure that anybody stopping the queue after this
  1110. * sees the new next_to_clean.
  1111. */
  1112. smp_mb();
  1113. if (__netif_subqueue_stopped(tx_ring->netdev,
  1114. tx_ring->queue_index)
  1115. && !test_bit(__IXGBE_DOWN, &adapter->state)) {
  1116. netif_wake_subqueue(tx_ring->netdev,
  1117. tx_ring->queue_index);
  1118. ++tx_ring->tx_stats.restart_queue;
  1119. }
  1120. }
  1121. return !!budget;
  1122. }
  1123. #ifdef CONFIG_IXGBE_DCA
  1124. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  1125. struct ixgbe_ring *tx_ring,
  1126. int cpu)
  1127. {
  1128. struct ixgbe_hw *hw = &adapter->hw;
  1129. u32 txctrl = 0;
  1130. u16 reg_offset;
  1131. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1132. txctrl = dca3_get_tag(tx_ring->dev, cpu);
  1133. switch (hw->mac.type) {
  1134. case ixgbe_mac_82598EB:
  1135. reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
  1136. break;
  1137. case ixgbe_mac_82599EB:
  1138. case ixgbe_mac_X540:
  1139. reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
  1140. txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
  1141. break;
  1142. default:
  1143. /* for unknown hardware do not write register */
  1144. return;
  1145. }
  1146. /*
  1147. * We can enable relaxed ordering for reads, but not writes when
  1148. * DCA is enabled. This is due to a known issue in some chipsets
  1149. * which will cause the DCA tag to be cleared.
  1150. */
  1151. txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
  1152. IXGBE_DCA_TXCTRL_DATA_RRO_EN |
  1153. IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  1154. IXGBE_WRITE_REG(hw, reg_offset, txctrl);
  1155. }
  1156. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  1157. struct ixgbe_ring *rx_ring,
  1158. int cpu)
  1159. {
  1160. struct ixgbe_hw *hw = &adapter->hw;
  1161. u32 rxctrl = 0;
  1162. u8 reg_idx = rx_ring->reg_idx;
  1163. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1164. rxctrl = dca3_get_tag(rx_ring->dev, cpu);
  1165. switch (hw->mac.type) {
  1166. case ixgbe_mac_82599EB:
  1167. case ixgbe_mac_X540:
  1168. rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
  1169. break;
  1170. default:
  1171. break;
  1172. }
  1173. /*
  1174. * We can enable relaxed ordering for reads, but not writes when
  1175. * DCA is enabled. This is due to a known issue in some chipsets
  1176. * which will cause the DCA tag to be cleared.
  1177. */
  1178. rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
  1179. IXGBE_DCA_RXCTRL_DATA_DCA_EN |
  1180. IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  1181. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
  1182. }
  1183. static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
  1184. {
  1185. struct ixgbe_adapter *adapter = q_vector->adapter;
  1186. struct ixgbe_ring *ring;
  1187. int cpu = get_cpu();
  1188. if (q_vector->cpu == cpu)
  1189. goto out_no_update;
  1190. ixgbe_for_each_ring(ring, q_vector->tx)
  1191. ixgbe_update_tx_dca(adapter, ring, cpu);
  1192. ixgbe_for_each_ring(ring, q_vector->rx)
  1193. ixgbe_update_rx_dca(adapter, ring, cpu);
  1194. q_vector->cpu = cpu;
  1195. out_no_update:
  1196. put_cpu();
  1197. }
  1198. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  1199. {
  1200. int i;
  1201. /* always use CB2 mode, difference is masked in the CB driver */
  1202. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1203. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1204. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1205. else
  1206. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1207. IXGBE_DCA_CTRL_DCA_DISABLE);
  1208. for (i = 0; i < adapter->num_q_vectors; i++) {
  1209. adapter->q_vector[i]->cpu = -1;
  1210. ixgbe_update_dca(adapter->q_vector[i]);
  1211. }
  1212. }
  1213. static int __ixgbe_notify_dca(struct device *dev, void *data)
  1214. {
  1215. struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
  1216. unsigned long event = *(unsigned long *)data;
  1217. if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
  1218. return 0;
  1219. switch (event) {
  1220. case DCA_PROVIDER_ADD:
  1221. /* if we're already enabled, don't do it again */
  1222. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1223. break;
  1224. if (dca_add_requester(dev) == 0) {
  1225. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  1226. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1227. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1228. break;
  1229. }
  1230. /* Fall Through since DCA is disabled. */
  1231. case DCA_PROVIDER_REMOVE:
  1232. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  1233. dca_remove_requester(dev);
  1234. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  1235. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1236. IXGBE_DCA_CTRL_DCA_DISABLE);
  1237. }
  1238. break;
  1239. }
  1240. return 0;
  1241. }
  1242. #endif /* CONFIG_IXGBE_DCA */
  1243. #define IXGBE_RSS_L4_TYPES_MASK \
  1244. ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
  1245. (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
  1246. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
  1247. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
  1248. static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
  1249. union ixgbe_adv_rx_desc *rx_desc,
  1250. struct sk_buff *skb)
  1251. {
  1252. u16 rss_type;
  1253. if (!(ring->netdev->features & NETIF_F_RXHASH))
  1254. return;
  1255. rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
  1256. IXGBE_RXDADV_RSSTYPE_MASK;
  1257. if (!rss_type)
  1258. return;
  1259. skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
  1260. (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
  1261. PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
  1262. }
  1263. #ifdef IXGBE_FCOE
  1264. /**
  1265. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  1266. * @ring: structure containing ring specific data
  1267. * @rx_desc: advanced rx descriptor
  1268. *
  1269. * Returns : true if it is FCoE pkt
  1270. */
  1271. static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
  1272. union ixgbe_adv_rx_desc *rx_desc)
  1273. {
  1274. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1275. return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
  1276. ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
  1277. (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
  1278. IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
  1279. }
  1280. #endif /* IXGBE_FCOE */
  1281. /**
  1282. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  1283. * @ring: structure containing ring specific data
  1284. * @rx_desc: current Rx descriptor being processed
  1285. * @skb: skb currently being received and modified
  1286. **/
  1287. static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
  1288. union ixgbe_adv_rx_desc *rx_desc,
  1289. struct sk_buff *skb)
  1290. {
  1291. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1292. bool encap_pkt = false;
  1293. skb_checksum_none_assert(skb);
  1294. /* Rx csum disabled */
  1295. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  1296. return;
  1297. /* check for VXLAN and Geneve packets */
  1298. if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
  1299. encap_pkt = true;
  1300. skb->encapsulation = 1;
  1301. }
  1302. /* if IP and error */
  1303. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
  1304. ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
  1305. ring->rx_stats.csum_err++;
  1306. return;
  1307. }
  1308. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
  1309. return;
  1310. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
  1311. /*
  1312. * 82599 errata, UDP frames with a 0 checksum can be marked as
  1313. * checksum errors.
  1314. */
  1315. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
  1316. test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
  1317. return;
  1318. ring->rx_stats.csum_err++;
  1319. return;
  1320. }
  1321. /* It must be a TCP or UDP packet with a valid checksum */
  1322. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1323. if (encap_pkt) {
  1324. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
  1325. return;
  1326. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
  1327. skb->ip_summed = CHECKSUM_NONE;
  1328. return;
  1329. }
  1330. /* If we checked the outer header let the stack know */
  1331. skb->csum_level = 1;
  1332. }
  1333. }
  1334. static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
  1335. {
  1336. return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
  1337. }
  1338. static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
  1339. struct ixgbe_rx_buffer *bi)
  1340. {
  1341. struct page *page = bi->page;
  1342. dma_addr_t dma;
  1343. /* since we are recycling buffers we should seldom need to alloc */
  1344. if (likely(page))
  1345. return true;
  1346. /* alloc new page for storage */
  1347. page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
  1348. if (unlikely(!page)) {
  1349. rx_ring->rx_stats.alloc_rx_page_failed++;
  1350. return false;
  1351. }
  1352. /* map page for use */
  1353. dma = dma_map_page_attrs(rx_ring->dev, page, 0,
  1354. ixgbe_rx_pg_size(rx_ring),
  1355. DMA_FROM_DEVICE,
  1356. IXGBE_RX_DMA_ATTR);
  1357. /*
  1358. * if mapping failed free memory back to system since
  1359. * there isn't much point in holding memory we can't use
  1360. */
  1361. if (dma_mapping_error(rx_ring->dev, dma)) {
  1362. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1363. rx_ring->rx_stats.alloc_rx_page_failed++;
  1364. return false;
  1365. }
  1366. bi->dma = dma;
  1367. bi->page = page;
  1368. bi->page_offset = ixgbe_rx_offset(rx_ring);
  1369. bi->pagecnt_bias = 1;
  1370. return true;
  1371. }
  1372. /**
  1373. * ixgbe_alloc_rx_buffers - Replace used receive buffers
  1374. * @rx_ring: ring to place buffers on
  1375. * @cleaned_count: number of buffers to replace
  1376. **/
  1377. void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
  1378. {
  1379. union ixgbe_adv_rx_desc *rx_desc;
  1380. struct ixgbe_rx_buffer *bi;
  1381. u16 i = rx_ring->next_to_use;
  1382. u16 bufsz;
  1383. /* nothing to do */
  1384. if (!cleaned_count)
  1385. return;
  1386. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  1387. bi = &rx_ring->rx_buffer_info[i];
  1388. i -= rx_ring->count;
  1389. bufsz = ixgbe_rx_bufsz(rx_ring);
  1390. do {
  1391. if (!ixgbe_alloc_mapped_page(rx_ring, bi))
  1392. break;
  1393. /* sync the buffer for use by the device */
  1394. dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
  1395. bi->page_offset, bufsz,
  1396. DMA_FROM_DEVICE);
  1397. /*
  1398. * Refresh the desc even if buffer_addrs didn't change
  1399. * because each write-back erases this info.
  1400. */
  1401. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  1402. rx_desc++;
  1403. bi++;
  1404. i++;
  1405. if (unlikely(!i)) {
  1406. rx_desc = IXGBE_RX_DESC(rx_ring, 0);
  1407. bi = rx_ring->rx_buffer_info;
  1408. i -= rx_ring->count;
  1409. }
  1410. /* clear the length for the next_to_use descriptor */
  1411. rx_desc->wb.upper.length = 0;
  1412. cleaned_count--;
  1413. } while (cleaned_count);
  1414. i += rx_ring->count;
  1415. if (rx_ring->next_to_use != i) {
  1416. rx_ring->next_to_use = i;
  1417. /* update next to alloc since we have filled the ring */
  1418. rx_ring->next_to_alloc = i;
  1419. /* Force memory writes to complete before letting h/w
  1420. * know there are new descriptors to fetch. (Only
  1421. * applicable for weak-ordered memory model archs,
  1422. * such as IA-64).
  1423. */
  1424. wmb();
  1425. writel(i, rx_ring->tail);
  1426. }
  1427. }
  1428. static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
  1429. struct sk_buff *skb)
  1430. {
  1431. u16 hdr_len = skb_headlen(skb);
  1432. /* set gso_size to avoid messing up TCP MSS */
  1433. skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
  1434. IXGBE_CB(skb)->append_cnt);
  1435. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  1436. }
  1437. static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
  1438. struct sk_buff *skb)
  1439. {
  1440. /* if append_cnt is 0 then frame is not RSC */
  1441. if (!IXGBE_CB(skb)->append_cnt)
  1442. return;
  1443. rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
  1444. rx_ring->rx_stats.rsc_flush++;
  1445. ixgbe_set_rsc_gso_size(rx_ring, skb);
  1446. /* gso_size is computed using append_cnt so always clear it last */
  1447. IXGBE_CB(skb)->append_cnt = 0;
  1448. }
  1449. /**
  1450. * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
  1451. * @rx_ring: rx descriptor ring packet is being transacted on
  1452. * @rx_desc: pointer to the EOP Rx descriptor
  1453. * @skb: pointer to current skb being populated
  1454. *
  1455. * This function checks the ring, descriptor, and packet information in
  1456. * order to populate the hash, checksum, VLAN, timestamp, protocol, and
  1457. * other fields within the skb.
  1458. **/
  1459. static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
  1460. union ixgbe_adv_rx_desc *rx_desc,
  1461. struct sk_buff *skb)
  1462. {
  1463. struct net_device *dev = rx_ring->netdev;
  1464. u32 flags = rx_ring->q_vector->adapter->flags;
  1465. ixgbe_update_rsc_stats(rx_ring, skb);
  1466. ixgbe_rx_hash(rx_ring, rx_desc, skb);
  1467. ixgbe_rx_checksum(rx_ring, rx_desc, skb);
  1468. if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
  1469. ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
  1470. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
  1471. ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
  1472. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  1473. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  1474. }
  1475. skb_record_rx_queue(skb, rx_ring->queue_index);
  1476. skb->protocol = eth_type_trans(skb, dev);
  1477. }
  1478. static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
  1479. struct sk_buff *skb)
  1480. {
  1481. napi_gro_receive(&q_vector->napi, skb);
  1482. }
  1483. /**
  1484. * ixgbe_is_non_eop - process handling of non-EOP buffers
  1485. * @rx_ring: Rx ring being processed
  1486. * @rx_desc: Rx descriptor for current buffer
  1487. * @skb: Current socket buffer containing buffer in progress
  1488. *
  1489. * This function updates next to clean. If the buffer is an EOP buffer
  1490. * this function exits returning false, otherwise it will place the
  1491. * sk_buff in the next buffer to be chained and return true indicating
  1492. * that this is in fact a non-EOP buffer.
  1493. **/
  1494. static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
  1495. union ixgbe_adv_rx_desc *rx_desc,
  1496. struct sk_buff *skb)
  1497. {
  1498. u32 ntc = rx_ring->next_to_clean + 1;
  1499. /* fetch, update, and store next to clean */
  1500. ntc = (ntc < rx_ring->count) ? ntc : 0;
  1501. rx_ring->next_to_clean = ntc;
  1502. prefetch(IXGBE_RX_DESC(rx_ring, ntc));
  1503. /* update RSC append count if present */
  1504. if (ring_is_rsc_enabled(rx_ring)) {
  1505. __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
  1506. cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
  1507. if (unlikely(rsc_enabled)) {
  1508. u32 rsc_cnt = le32_to_cpu(rsc_enabled);
  1509. rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
  1510. IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
  1511. /* update ntc based on RSC value */
  1512. ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
  1513. ntc &= IXGBE_RXDADV_NEXTP_MASK;
  1514. ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
  1515. }
  1516. }
  1517. /* if we are the last buffer then there is nothing else to do */
  1518. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1519. return false;
  1520. /* place skb in next buffer to be received */
  1521. rx_ring->rx_buffer_info[ntc].skb = skb;
  1522. rx_ring->rx_stats.non_eop_descs++;
  1523. return true;
  1524. }
  1525. /**
  1526. * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
  1527. * @rx_ring: rx descriptor ring packet is being transacted on
  1528. * @skb: pointer to current skb being adjusted
  1529. *
  1530. * This function is an ixgbe specific version of __pskb_pull_tail. The
  1531. * main difference between this version and the original function is that
  1532. * this function can make several assumptions about the state of things
  1533. * that allow for significant optimizations versus the standard function.
  1534. * As a result we can do things like drop a frag and maintain an accurate
  1535. * truesize for the skb.
  1536. */
  1537. static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
  1538. struct sk_buff *skb)
  1539. {
  1540. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1541. unsigned char *va;
  1542. unsigned int pull_len;
  1543. /*
  1544. * it is valid to use page_address instead of kmap since we are
  1545. * working with pages allocated out of the lomem pool per
  1546. * alloc_page(GFP_ATOMIC)
  1547. */
  1548. va = skb_frag_address(frag);
  1549. /*
  1550. * we need the header to contain the greater of either ETH_HLEN or
  1551. * 60 bytes if the skb->len is less than 60 for skb_pad.
  1552. */
  1553. pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
  1554. /* align pull length to size of long to optimize memcpy performance */
  1555. skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
  1556. /* update all of the pointers */
  1557. skb_frag_size_sub(frag, pull_len);
  1558. frag->page_offset += pull_len;
  1559. skb->data_len -= pull_len;
  1560. skb->tail += pull_len;
  1561. }
  1562. /**
  1563. * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
  1564. * @rx_ring: rx descriptor ring packet is being transacted on
  1565. * @skb: pointer to current skb being updated
  1566. *
  1567. * This function provides a basic DMA sync up for the first fragment of an
  1568. * skb. The reason for doing this is that the first fragment cannot be
  1569. * unmapped until we have reached the end of packet descriptor for a buffer
  1570. * chain.
  1571. */
  1572. static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
  1573. struct sk_buff *skb)
  1574. {
  1575. /* if the page was released unmap it, else just sync our portion */
  1576. if (unlikely(IXGBE_CB(skb)->page_released)) {
  1577. dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
  1578. ixgbe_rx_pg_size(rx_ring),
  1579. DMA_FROM_DEVICE,
  1580. IXGBE_RX_DMA_ATTR);
  1581. } else {
  1582. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1583. dma_sync_single_range_for_cpu(rx_ring->dev,
  1584. IXGBE_CB(skb)->dma,
  1585. frag->page_offset,
  1586. skb_frag_size(frag),
  1587. DMA_FROM_DEVICE);
  1588. }
  1589. }
  1590. /**
  1591. * ixgbe_cleanup_headers - Correct corrupted or empty headers
  1592. * @rx_ring: rx descriptor ring packet is being transacted on
  1593. * @rx_desc: pointer to the EOP Rx descriptor
  1594. * @skb: pointer to current skb being fixed
  1595. *
  1596. * Check for corrupted packet headers caused by senders on the local L2
  1597. * embedded NIC switch not setting up their Tx Descriptors right. These
  1598. * should be very rare.
  1599. *
  1600. * Also address the case where we are pulling data in on pages only
  1601. * and as such no data is present in the skb header.
  1602. *
  1603. * In addition if skb is not at least 60 bytes we need to pad it so that
  1604. * it is large enough to qualify as a valid Ethernet frame.
  1605. *
  1606. * Returns true if an error was encountered and skb was freed.
  1607. **/
  1608. static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
  1609. union ixgbe_adv_rx_desc *rx_desc,
  1610. struct sk_buff *skb)
  1611. {
  1612. struct net_device *netdev = rx_ring->netdev;
  1613. /* verify that the packet does not have any known errors */
  1614. if (unlikely(ixgbe_test_staterr(rx_desc,
  1615. IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
  1616. !(netdev->features & NETIF_F_RXALL))) {
  1617. dev_kfree_skb_any(skb);
  1618. return true;
  1619. }
  1620. /* place header in linear portion of buffer */
  1621. if (!skb_headlen(skb))
  1622. ixgbe_pull_tail(rx_ring, skb);
  1623. #ifdef IXGBE_FCOE
  1624. /* do not attempt to pad FCoE Frames as this will disrupt DDP */
  1625. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
  1626. return false;
  1627. #endif
  1628. /* if eth_skb_pad returns an error the skb was freed */
  1629. if (eth_skb_pad(skb))
  1630. return true;
  1631. return false;
  1632. }
  1633. /**
  1634. * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
  1635. * @rx_ring: rx descriptor ring to store buffers on
  1636. * @old_buff: donor buffer to have page reused
  1637. *
  1638. * Synchronizes page for reuse by the adapter
  1639. **/
  1640. static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
  1641. struct ixgbe_rx_buffer *old_buff)
  1642. {
  1643. struct ixgbe_rx_buffer *new_buff;
  1644. u16 nta = rx_ring->next_to_alloc;
  1645. new_buff = &rx_ring->rx_buffer_info[nta];
  1646. /* update, and store next to alloc */
  1647. nta++;
  1648. rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
  1649. /* Transfer page from old buffer to new buffer.
  1650. * Move each member individually to avoid possible store
  1651. * forwarding stalls and unnecessary copy of skb.
  1652. */
  1653. new_buff->dma = old_buff->dma;
  1654. new_buff->page = old_buff->page;
  1655. new_buff->page_offset = old_buff->page_offset;
  1656. new_buff->pagecnt_bias = old_buff->pagecnt_bias;
  1657. }
  1658. static inline bool ixgbe_page_is_reserved(struct page *page)
  1659. {
  1660. return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
  1661. }
  1662. static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
  1663. {
  1664. unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
  1665. struct page *page = rx_buffer->page;
  1666. /* avoid re-using remote pages */
  1667. if (unlikely(ixgbe_page_is_reserved(page)))
  1668. return false;
  1669. #if (PAGE_SIZE < 8192)
  1670. /* if we are only owner of page we can reuse it */
  1671. if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
  1672. return false;
  1673. #else
  1674. /* The last offset is a bit aggressive in that we assume the
  1675. * worst case of FCoE being enabled and using a 3K buffer.
  1676. * However this should have minimal impact as the 1K extra is
  1677. * still less than one buffer in size.
  1678. */
  1679. #define IXGBE_LAST_OFFSET \
  1680. (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
  1681. if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
  1682. return false;
  1683. #endif
  1684. /* If we have drained the page fragment pool we need to update
  1685. * the pagecnt_bias and page count so that we fully restock the
  1686. * number of references the driver holds.
  1687. */
  1688. if (unlikely(!pagecnt_bias)) {
  1689. page_ref_add(page, USHRT_MAX);
  1690. rx_buffer->pagecnt_bias = USHRT_MAX;
  1691. }
  1692. return true;
  1693. }
  1694. /**
  1695. * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
  1696. * @rx_ring: rx descriptor ring to transact packets on
  1697. * @rx_buffer: buffer containing page to add
  1698. * @rx_desc: descriptor containing length of buffer written by hardware
  1699. * @skb: sk_buff to place the data into
  1700. *
  1701. * This function will add the data contained in rx_buffer->page to the skb.
  1702. * This is done either through a direct copy if the data in the buffer is
  1703. * less than the skb header size, otherwise it will just attach the page as
  1704. * a frag to the skb.
  1705. *
  1706. * The function will then update the page offset if necessary and return
  1707. * true if the buffer can be reused by the adapter.
  1708. **/
  1709. static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
  1710. struct ixgbe_rx_buffer *rx_buffer,
  1711. struct sk_buff *skb,
  1712. unsigned int size)
  1713. {
  1714. #if (PAGE_SIZE < 8192)
  1715. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1716. #else
  1717. unsigned int truesize = ring_uses_build_skb(rx_ring) ?
  1718. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
  1719. SKB_DATA_ALIGN(size);
  1720. #endif
  1721. skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
  1722. rx_buffer->page_offset, size, truesize);
  1723. #if (PAGE_SIZE < 8192)
  1724. rx_buffer->page_offset ^= truesize;
  1725. #else
  1726. rx_buffer->page_offset += truesize;
  1727. #endif
  1728. }
  1729. static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
  1730. union ixgbe_adv_rx_desc *rx_desc,
  1731. struct sk_buff **skb,
  1732. const unsigned int size)
  1733. {
  1734. struct ixgbe_rx_buffer *rx_buffer;
  1735. rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
  1736. prefetchw(rx_buffer->page);
  1737. *skb = rx_buffer->skb;
  1738. /* Delay unmapping of the first packet. It carries the header
  1739. * information, HW may still access the header after the writeback.
  1740. * Only unmap it when EOP is reached
  1741. */
  1742. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
  1743. if (!*skb)
  1744. goto skip_sync;
  1745. } else {
  1746. if (*skb)
  1747. ixgbe_dma_sync_frag(rx_ring, *skb);
  1748. }
  1749. /* we are reusing so sync this buffer for CPU use */
  1750. dma_sync_single_range_for_cpu(rx_ring->dev,
  1751. rx_buffer->dma,
  1752. rx_buffer->page_offset,
  1753. size,
  1754. DMA_FROM_DEVICE);
  1755. skip_sync:
  1756. rx_buffer->pagecnt_bias--;
  1757. return rx_buffer;
  1758. }
  1759. static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
  1760. struct ixgbe_rx_buffer *rx_buffer,
  1761. struct sk_buff *skb)
  1762. {
  1763. if (ixgbe_can_reuse_rx_page(rx_buffer)) {
  1764. /* hand second half of page back to the ring */
  1765. ixgbe_reuse_rx_page(rx_ring, rx_buffer);
  1766. } else {
  1767. if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
  1768. /* the page has been released from the ring */
  1769. IXGBE_CB(skb)->page_released = true;
  1770. } else {
  1771. /* we are not reusing the buffer so unmap it */
  1772. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  1773. ixgbe_rx_pg_size(rx_ring),
  1774. DMA_FROM_DEVICE,
  1775. IXGBE_RX_DMA_ATTR);
  1776. }
  1777. __page_frag_cache_drain(rx_buffer->page,
  1778. rx_buffer->pagecnt_bias);
  1779. }
  1780. /* clear contents of rx_buffer */
  1781. rx_buffer->page = NULL;
  1782. rx_buffer->skb = NULL;
  1783. }
  1784. static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
  1785. struct ixgbe_rx_buffer *rx_buffer,
  1786. union ixgbe_adv_rx_desc *rx_desc,
  1787. unsigned int size)
  1788. {
  1789. void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
  1790. #if (PAGE_SIZE < 8192)
  1791. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1792. #else
  1793. unsigned int truesize = SKB_DATA_ALIGN(size);
  1794. #endif
  1795. struct sk_buff *skb;
  1796. /* prefetch first cache line of first page */
  1797. prefetch(va);
  1798. #if L1_CACHE_BYTES < 128
  1799. prefetch(va + L1_CACHE_BYTES);
  1800. #endif
  1801. /* allocate a skb to store the frags */
  1802. skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
  1803. if (unlikely(!skb))
  1804. return NULL;
  1805. if (size > IXGBE_RX_HDR_SIZE) {
  1806. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1807. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1808. skb_add_rx_frag(skb, 0, rx_buffer->page,
  1809. rx_buffer->page_offset,
  1810. size, truesize);
  1811. #if (PAGE_SIZE < 8192)
  1812. rx_buffer->page_offset ^= truesize;
  1813. #else
  1814. rx_buffer->page_offset += truesize;
  1815. #endif
  1816. } else {
  1817. memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
  1818. rx_buffer->pagecnt_bias++;
  1819. }
  1820. return skb;
  1821. }
  1822. static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
  1823. struct ixgbe_rx_buffer *rx_buffer,
  1824. union ixgbe_adv_rx_desc *rx_desc,
  1825. unsigned int size)
  1826. {
  1827. void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
  1828. #if (PAGE_SIZE < 8192)
  1829. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1830. #else
  1831. unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
  1832. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size);
  1833. #endif
  1834. struct sk_buff *skb;
  1835. /* prefetch first cache line of first page */
  1836. prefetch(va);
  1837. #if L1_CACHE_BYTES < 128
  1838. prefetch(va + L1_CACHE_BYTES);
  1839. #endif
  1840. /* build an skb to around the page buffer */
  1841. skb = build_skb(va - IXGBE_SKB_PAD, truesize);
  1842. if (unlikely(!skb))
  1843. return NULL;
  1844. /* update pointers within the skb to store the data */
  1845. skb_reserve(skb, IXGBE_SKB_PAD);
  1846. __skb_put(skb, size);
  1847. /* record DMA address if this is the start of a chain of buffers */
  1848. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1849. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1850. /* update buffer offset */
  1851. #if (PAGE_SIZE < 8192)
  1852. rx_buffer->page_offset ^= truesize;
  1853. #else
  1854. rx_buffer->page_offset += truesize;
  1855. #endif
  1856. return skb;
  1857. }
  1858. /**
  1859. * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
  1860. * @q_vector: structure containing interrupt and ring information
  1861. * @rx_ring: rx descriptor ring to transact packets on
  1862. * @budget: Total limit on number of packets to process
  1863. *
  1864. * This function provides a "bounce buffer" approach to Rx interrupt
  1865. * processing. The advantage to this is that on systems that have
  1866. * expensive overhead for IOMMU access this provides a means of avoiding
  1867. * it by maintaining the mapping of the page to the syste.
  1868. *
  1869. * Returns amount of work completed
  1870. **/
  1871. static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1872. struct ixgbe_ring *rx_ring,
  1873. const int budget)
  1874. {
  1875. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1876. #ifdef IXGBE_FCOE
  1877. struct ixgbe_adapter *adapter = q_vector->adapter;
  1878. int ddp_bytes;
  1879. unsigned int mss = 0;
  1880. #endif /* IXGBE_FCOE */
  1881. u16 cleaned_count = ixgbe_desc_unused(rx_ring);
  1882. while (likely(total_rx_packets < budget)) {
  1883. union ixgbe_adv_rx_desc *rx_desc;
  1884. struct ixgbe_rx_buffer *rx_buffer;
  1885. struct sk_buff *skb;
  1886. unsigned int size;
  1887. /* return some buffers to hardware, one at a time is too slow */
  1888. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1889. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  1890. cleaned_count = 0;
  1891. }
  1892. rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
  1893. size = le16_to_cpu(rx_desc->wb.upper.length);
  1894. if (!size)
  1895. break;
  1896. /* This memory barrier is needed to keep us from reading
  1897. * any other fields out of the rx_desc until we know the
  1898. * descriptor has been written back
  1899. */
  1900. dma_rmb();
  1901. rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
  1902. /* retrieve a buffer from the ring */
  1903. if (skb)
  1904. ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
  1905. else if (ring_uses_build_skb(rx_ring))
  1906. skb = ixgbe_build_skb(rx_ring, rx_buffer,
  1907. rx_desc, size);
  1908. else
  1909. skb = ixgbe_construct_skb(rx_ring, rx_buffer,
  1910. rx_desc, size);
  1911. /* exit if we failed to retrieve a buffer */
  1912. if (!skb) {
  1913. rx_ring->rx_stats.alloc_rx_buff_failed++;
  1914. rx_buffer->pagecnt_bias++;
  1915. break;
  1916. }
  1917. ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
  1918. cleaned_count++;
  1919. /* place incomplete frames back on ring for completion */
  1920. if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
  1921. continue;
  1922. /* verify the packet layout is correct */
  1923. if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
  1924. continue;
  1925. /* probably a little skewed due to removing CRC */
  1926. total_rx_bytes += skb->len;
  1927. /* populate checksum, timestamp, VLAN, and protocol */
  1928. ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
  1929. #ifdef IXGBE_FCOE
  1930. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  1931. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
  1932. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  1933. /* include DDPed FCoE data */
  1934. if (ddp_bytes > 0) {
  1935. if (!mss) {
  1936. mss = rx_ring->netdev->mtu -
  1937. sizeof(struct fcoe_hdr) -
  1938. sizeof(struct fc_frame_header) -
  1939. sizeof(struct fcoe_crc_eof);
  1940. if (mss > 512)
  1941. mss &= ~511;
  1942. }
  1943. total_rx_bytes += ddp_bytes;
  1944. total_rx_packets += DIV_ROUND_UP(ddp_bytes,
  1945. mss);
  1946. }
  1947. if (!ddp_bytes) {
  1948. dev_kfree_skb_any(skb);
  1949. continue;
  1950. }
  1951. }
  1952. #endif /* IXGBE_FCOE */
  1953. ixgbe_rx_skb(q_vector, skb);
  1954. /* update budget accounting */
  1955. total_rx_packets++;
  1956. }
  1957. u64_stats_update_begin(&rx_ring->syncp);
  1958. rx_ring->stats.packets += total_rx_packets;
  1959. rx_ring->stats.bytes += total_rx_bytes;
  1960. u64_stats_update_end(&rx_ring->syncp);
  1961. q_vector->rx.total_packets += total_rx_packets;
  1962. q_vector->rx.total_bytes += total_rx_bytes;
  1963. return total_rx_packets;
  1964. }
  1965. /**
  1966. * ixgbe_configure_msix - Configure MSI-X hardware
  1967. * @adapter: board private structure
  1968. *
  1969. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  1970. * interrupts.
  1971. **/
  1972. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  1973. {
  1974. struct ixgbe_q_vector *q_vector;
  1975. int v_idx;
  1976. u32 mask;
  1977. /* Populate MSIX to EITR Select */
  1978. if (adapter->num_vfs > 32) {
  1979. u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
  1980. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  1981. }
  1982. /*
  1983. * Populate the IVAR table and set the ITR values to the
  1984. * corresponding register.
  1985. */
  1986. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  1987. struct ixgbe_ring *ring;
  1988. q_vector = adapter->q_vector[v_idx];
  1989. ixgbe_for_each_ring(ring, q_vector->rx)
  1990. ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  1991. ixgbe_for_each_ring(ring, q_vector->tx)
  1992. ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  1993. ixgbe_write_eitr(q_vector);
  1994. }
  1995. switch (adapter->hw.mac.type) {
  1996. case ixgbe_mac_82598EB:
  1997. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  1998. v_idx);
  1999. break;
  2000. case ixgbe_mac_82599EB:
  2001. case ixgbe_mac_X540:
  2002. case ixgbe_mac_X550:
  2003. case ixgbe_mac_X550EM_x:
  2004. case ixgbe_mac_x550em_a:
  2005. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  2006. break;
  2007. default:
  2008. break;
  2009. }
  2010. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  2011. /* set up to autoclear timer, and the vectors */
  2012. mask = IXGBE_EIMS_ENABLE_MASK;
  2013. mask &= ~(IXGBE_EIMS_OTHER |
  2014. IXGBE_EIMS_MAILBOX |
  2015. IXGBE_EIMS_LSC);
  2016. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  2017. }
  2018. enum latency_range {
  2019. lowest_latency = 0,
  2020. low_latency = 1,
  2021. bulk_latency = 2,
  2022. latency_invalid = 255
  2023. };
  2024. /**
  2025. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  2026. * @q_vector: structure containing interrupt and ring information
  2027. * @ring_container: structure containing ring performance data
  2028. *
  2029. * Stores a new ITR value based on packets and byte
  2030. * counts during the last interrupt. The advantage of per interrupt
  2031. * computation is faster updates and more accurate ITR for the current
  2032. * traffic pattern. Constants in this function were computed
  2033. * based on theoretical maximum wire speed and thresholds were set based
  2034. * on testing data as well as attempting to minimize response time
  2035. * while increasing bulk throughput.
  2036. * this functionality is controlled by the InterruptThrottleRate module
  2037. * parameter (see ixgbe_param.c)
  2038. **/
  2039. static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
  2040. struct ixgbe_ring_container *ring_container)
  2041. {
  2042. int bytes = ring_container->total_bytes;
  2043. int packets = ring_container->total_packets;
  2044. u32 timepassed_us;
  2045. u64 bytes_perint;
  2046. u8 itr_setting = ring_container->itr;
  2047. if (packets == 0)
  2048. return;
  2049. /* simple throttlerate management
  2050. * 0-10MB/s lowest (100000 ints/s)
  2051. * 10-20MB/s low (20000 ints/s)
  2052. * 20-1249MB/s bulk (12000 ints/s)
  2053. */
  2054. /* what was last interrupt timeslice? */
  2055. timepassed_us = q_vector->itr >> 2;
  2056. if (timepassed_us == 0)
  2057. return;
  2058. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  2059. switch (itr_setting) {
  2060. case lowest_latency:
  2061. if (bytes_perint > 10)
  2062. itr_setting = low_latency;
  2063. break;
  2064. case low_latency:
  2065. if (bytes_perint > 20)
  2066. itr_setting = bulk_latency;
  2067. else if (bytes_perint <= 10)
  2068. itr_setting = lowest_latency;
  2069. break;
  2070. case bulk_latency:
  2071. if (bytes_perint <= 20)
  2072. itr_setting = low_latency;
  2073. break;
  2074. }
  2075. /* clear work counters since we have the values we need */
  2076. ring_container->total_bytes = 0;
  2077. ring_container->total_packets = 0;
  2078. /* write updated itr to ring container */
  2079. ring_container->itr = itr_setting;
  2080. }
  2081. /**
  2082. * ixgbe_write_eitr - write EITR register in hardware specific way
  2083. * @q_vector: structure containing interrupt and ring information
  2084. *
  2085. * This function is made to be called by ethtool and by the driver
  2086. * when it needs to update EITR registers at runtime. Hardware
  2087. * specific quirks/differences are taken care of here.
  2088. */
  2089. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  2090. {
  2091. struct ixgbe_adapter *adapter = q_vector->adapter;
  2092. struct ixgbe_hw *hw = &adapter->hw;
  2093. int v_idx = q_vector->v_idx;
  2094. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  2095. switch (adapter->hw.mac.type) {
  2096. case ixgbe_mac_82598EB:
  2097. /* must write high and low 16 bits to reset counter */
  2098. itr_reg |= (itr_reg << 16);
  2099. break;
  2100. case ixgbe_mac_82599EB:
  2101. case ixgbe_mac_X540:
  2102. case ixgbe_mac_X550:
  2103. case ixgbe_mac_X550EM_x:
  2104. case ixgbe_mac_x550em_a:
  2105. /*
  2106. * set the WDIS bit to not clear the timer bits and cause an
  2107. * immediate assertion of the interrupt
  2108. */
  2109. itr_reg |= IXGBE_EITR_CNT_WDIS;
  2110. break;
  2111. default:
  2112. break;
  2113. }
  2114. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  2115. }
  2116. static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
  2117. {
  2118. u32 new_itr = q_vector->itr;
  2119. u8 current_itr;
  2120. ixgbe_update_itr(q_vector, &q_vector->tx);
  2121. ixgbe_update_itr(q_vector, &q_vector->rx);
  2122. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  2123. switch (current_itr) {
  2124. /* counts and packets in update_itr are dependent on these numbers */
  2125. case lowest_latency:
  2126. new_itr = IXGBE_100K_ITR;
  2127. break;
  2128. case low_latency:
  2129. new_itr = IXGBE_20K_ITR;
  2130. break;
  2131. case bulk_latency:
  2132. new_itr = IXGBE_12K_ITR;
  2133. break;
  2134. default:
  2135. break;
  2136. }
  2137. if (new_itr != q_vector->itr) {
  2138. /* do an exponential smoothing */
  2139. new_itr = (10 * new_itr * q_vector->itr) /
  2140. ((9 * new_itr) + q_vector->itr);
  2141. /* save the algorithm value here */
  2142. q_vector->itr = new_itr;
  2143. ixgbe_write_eitr(q_vector);
  2144. }
  2145. }
  2146. /**
  2147. * ixgbe_check_overtemp_subtask - check for over temperature
  2148. * @adapter: pointer to adapter
  2149. **/
  2150. static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
  2151. {
  2152. struct ixgbe_hw *hw = &adapter->hw;
  2153. u32 eicr = adapter->interrupt_event;
  2154. s32 rc;
  2155. if (test_bit(__IXGBE_DOWN, &adapter->state))
  2156. return;
  2157. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  2158. !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
  2159. return;
  2160. adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2161. switch (hw->device_id) {
  2162. case IXGBE_DEV_ID_82599_T3_LOM:
  2163. /*
  2164. * Since the warning interrupt is for both ports
  2165. * we don't have to check if:
  2166. * - This interrupt wasn't for our port.
  2167. * - We may have missed the interrupt so always have to
  2168. * check if we got a LSC
  2169. */
  2170. if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
  2171. !(eicr & IXGBE_EICR_LSC))
  2172. return;
  2173. if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
  2174. u32 speed;
  2175. bool link_up = false;
  2176. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2177. if (link_up)
  2178. return;
  2179. }
  2180. /* Check if this is not due to overtemp */
  2181. if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
  2182. return;
  2183. break;
  2184. case IXGBE_DEV_ID_X550EM_A_1G_T:
  2185. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  2186. rc = hw->phy.ops.check_overtemp(hw);
  2187. if (rc != IXGBE_ERR_OVERTEMP)
  2188. return;
  2189. break;
  2190. default:
  2191. if (adapter->hw.mac.type >= ixgbe_mac_X540)
  2192. return;
  2193. if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
  2194. return;
  2195. break;
  2196. }
  2197. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2198. adapter->interrupt_event = 0;
  2199. }
  2200. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  2201. {
  2202. struct ixgbe_hw *hw = &adapter->hw;
  2203. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  2204. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2205. e_crit(probe, "Fan has stopped, replace the adapter\n");
  2206. /* write to clear the interrupt */
  2207. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2208. }
  2209. }
  2210. static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2211. {
  2212. struct ixgbe_hw *hw = &adapter->hw;
  2213. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  2214. return;
  2215. switch (adapter->hw.mac.type) {
  2216. case ixgbe_mac_82599EB:
  2217. /*
  2218. * Need to check link state so complete overtemp check
  2219. * on service task
  2220. */
  2221. if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
  2222. (eicr & IXGBE_EICR_LSC)) &&
  2223. (!test_bit(__IXGBE_DOWN, &adapter->state))) {
  2224. adapter->interrupt_event = eicr;
  2225. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2226. ixgbe_service_event_schedule(adapter);
  2227. return;
  2228. }
  2229. return;
  2230. case ixgbe_mac_x550em_a:
  2231. if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
  2232. adapter->interrupt_event = eicr;
  2233. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2234. ixgbe_service_event_schedule(adapter);
  2235. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
  2236. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2237. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
  2238. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2239. }
  2240. return;
  2241. case ixgbe_mac_X550:
  2242. case ixgbe_mac_X540:
  2243. if (!(eicr & IXGBE_EICR_TS))
  2244. return;
  2245. break;
  2246. default:
  2247. return;
  2248. }
  2249. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2250. }
  2251. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2252. {
  2253. switch (hw->mac.type) {
  2254. case ixgbe_mac_82598EB:
  2255. if (hw->phy.type == ixgbe_phy_nl)
  2256. return true;
  2257. return false;
  2258. case ixgbe_mac_82599EB:
  2259. case ixgbe_mac_X550EM_x:
  2260. case ixgbe_mac_x550em_a:
  2261. switch (hw->mac.ops.get_media_type(hw)) {
  2262. case ixgbe_media_type_fiber:
  2263. case ixgbe_media_type_fiber_qsfp:
  2264. return true;
  2265. default:
  2266. return false;
  2267. }
  2268. default:
  2269. return false;
  2270. }
  2271. }
  2272. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2273. {
  2274. struct ixgbe_hw *hw = &adapter->hw;
  2275. u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
  2276. if (!ixgbe_is_sfp(hw))
  2277. return;
  2278. /* Later MAC's use different SDP */
  2279. if (hw->mac.type >= ixgbe_mac_X540)
  2280. eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
  2281. if (eicr & eicr_mask) {
  2282. /* Clear the interrupt */
  2283. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
  2284. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2285. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  2286. adapter->sfp_poll_time = 0;
  2287. ixgbe_service_event_schedule(adapter);
  2288. }
  2289. }
  2290. if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
  2291. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2292. /* Clear the interrupt */
  2293. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2294. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2295. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  2296. ixgbe_service_event_schedule(adapter);
  2297. }
  2298. }
  2299. }
  2300. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  2301. {
  2302. struct ixgbe_hw *hw = &adapter->hw;
  2303. adapter->lsc_int++;
  2304. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2305. adapter->link_check_timeout = jiffies;
  2306. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2307. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  2308. IXGBE_WRITE_FLUSH(hw);
  2309. ixgbe_service_event_schedule(adapter);
  2310. }
  2311. }
  2312. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  2313. u64 qmask)
  2314. {
  2315. u32 mask;
  2316. struct ixgbe_hw *hw = &adapter->hw;
  2317. switch (hw->mac.type) {
  2318. case ixgbe_mac_82598EB:
  2319. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2320. IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
  2321. break;
  2322. case ixgbe_mac_82599EB:
  2323. case ixgbe_mac_X540:
  2324. case ixgbe_mac_X550:
  2325. case ixgbe_mac_X550EM_x:
  2326. case ixgbe_mac_x550em_a:
  2327. mask = (qmask & 0xFFFFFFFF);
  2328. if (mask)
  2329. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  2330. mask = (qmask >> 32);
  2331. if (mask)
  2332. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  2333. break;
  2334. default:
  2335. break;
  2336. }
  2337. /* skip the flush */
  2338. }
  2339. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  2340. u64 qmask)
  2341. {
  2342. u32 mask;
  2343. struct ixgbe_hw *hw = &adapter->hw;
  2344. switch (hw->mac.type) {
  2345. case ixgbe_mac_82598EB:
  2346. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2347. IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
  2348. break;
  2349. case ixgbe_mac_82599EB:
  2350. case ixgbe_mac_X540:
  2351. case ixgbe_mac_X550:
  2352. case ixgbe_mac_X550EM_x:
  2353. case ixgbe_mac_x550em_a:
  2354. mask = (qmask & 0xFFFFFFFF);
  2355. if (mask)
  2356. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
  2357. mask = (qmask >> 32);
  2358. if (mask)
  2359. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
  2360. break;
  2361. default:
  2362. break;
  2363. }
  2364. /* skip the flush */
  2365. }
  2366. /**
  2367. * ixgbe_irq_enable - Enable default interrupt generation settings
  2368. * @adapter: board private structure
  2369. **/
  2370. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  2371. bool flush)
  2372. {
  2373. struct ixgbe_hw *hw = &adapter->hw;
  2374. u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  2375. /* don't reenable LSC while waiting for link */
  2376. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  2377. mask &= ~IXGBE_EIMS_LSC;
  2378. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  2379. switch (adapter->hw.mac.type) {
  2380. case ixgbe_mac_82599EB:
  2381. mask |= IXGBE_EIMS_GPI_SDP0(hw);
  2382. break;
  2383. case ixgbe_mac_X540:
  2384. case ixgbe_mac_X550:
  2385. case ixgbe_mac_X550EM_x:
  2386. case ixgbe_mac_x550em_a:
  2387. mask |= IXGBE_EIMS_TS;
  2388. break;
  2389. default:
  2390. break;
  2391. }
  2392. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  2393. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2394. switch (adapter->hw.mac.type) {
  2395. case ixgbe_mac_82599EB:
  2396. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2397. mask |= IXGBE_EIMS_GPI_SDP2(hw);
  2398. /* fall through */
  2399. case ixgbe_mac_X540:
  2400. case ixgbe_mac_X550:
  2401. case ixgbe_mac_X550EM_x:
  2402. case ixgbe_mac_x550em_a:
  2403. if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
  2404. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
  2405. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
  2406. mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
  2407. if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
  2408. mask |= IXGBE_EICR_GPI_SDP0_X540;
  2409. mask |= IXGBE_EIMS_ECC;
  2410. mask |= IXGBE_EIMS_MAILBOX;
  2411. break;
  2412. default:
  2413. break;
  2414. }
  2415. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
  2416. !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  2417. mask |= IXGBE_EIMS_FLOW_DIR;
  2418. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  2419. if (queues)
  2420. ixgbe_irq_enable_queues(adapter, ~0);
  2421. if (flush)
  2422. IXGBE_WRITE_FLUSH(&adapter->hw);
  2423. }
  2424. static irqreturn_t ixgbe_msix_other(int irq, void *data)
  2425. {
  2426. struct ixgbe_adapter *adapter = data;
  2427. struct ixgbe_hw *hw = &adapter->hw;
  2428. u32 eicr;
  2429. /*
  2430. * Workaround for Silicon errata. Use clear-by-write instead
  2431. * of clear-by-read. Reading with EICS will return the
  2432. * interrupt causes without clearing, which later be done
  2433. * with the write to EICR.
  2434. */
  2435. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  2436. /* The lower 16bits of the EICR register are for the queue interrupts
  2437. * which should be masked here in order to not accidentally clear them if
  2438. * the bits are high when ixgbe_msix_other is called. There is a race
  2439. * condition otherwise which results in possible performance loss
  2440. * especially if the ixgbe_msix_other interrupt is triggering
  2441. * consistently (as it would when PPS is turned on for the X540 device)
  2442. */
  2443. eicr &= 0xFFFF0000;
  2444. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  2445. if (eicr & IXGBE_EICR_LSC)
  2446. ixgbe_check_lsc(adapter);
  2447. if (eicr & IXGBE_EICR_MAILBOX)
  2448. ixgbe_msg_task(adapter);
  2449. switch (hw->mac.type) {
  2450. case ixgbe_mac_82599EB:
  2451. case ixgbe_mac_X540:
  2452. case ixgbe_mac_X550:
  2453. case ixgbe_mac_X550EM_x:
  2454. case ixgbe_mac_x550em_a:
  2455. if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
  2456. (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
  2457. adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
  2458. ixgbe_service_event_schedule(adapter);
  2459. IXGBE_WRITE_REG(hw, IXGBE_EICR,
  2460. IXGBE_EICR_GPI_SDP0_X540);
  2461. }
  2462. if (eicr & IXGBE_EICR_ECC) {
  2463. e_info(link, "Received ECC Err, initiating reset\n");
  2464. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2465. ixgbe_service_event_schedule(adapter);
  2466. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2467. }
  2468. /* Handle Flow Director Full threshold interrupt */
  2469. if (eicr & IXGBE_EICR_FLOW_DIR) {
  2470. int reinit_count = 0;
  2471. int i;
  2472. for (i = 0; i < adapter->num_tx_queues; i++) {
  2473. struct ixgbe_ring *ring = adapter->tx_ring[i];
  2474. if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
  2475. &ring->state))
  2476. reinit_count++;
  2477. }
  2478. if (reinit_count) {
  2479. /* no more flow director interrupts until after init */
  2480. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
  2481. adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  2482. ixgbe_service_event_schedule(adapter);
  2483. }
  2484. }
  2485. ixgbe_check_sfp_event(adapter, eicr);
  2486. ixgbe_check_overtemp_event(adapter, eicr);
  2487. break;
  2488. default:
  2489. break;
  2490. }
  2491. ixgbe_check_fan_failure(adapter, eicr);
  2492. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2493. ixgbe_ptp_check_pps_event(adapter);
  2494. /* re-enable the original interrupt state, no lsc, no queues */
  2495. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2496. ixgbe_irq_enable(adapter, false, false);
  2497. return IRQ_HANDLED;
  2498. }
  2499. static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
  2500. {
  2501. struct ixgbe_q_vector *q_vector = data;
  2502. /* EIAM disabled interrupts (on this vector) for us */
  2503. if (q_vector->rx.ring || q_vector->tx.ring)
  2504. napi_schedule_irqoff(&q_vector->napi);
  2505. return IRQ_HANDLED;
  2506. }
  2507. /**
  2508. * ixgbe_poll - NAPI Rx polling callback
  2509. * @napi: structure for representing this polling device
  2510. * @budget: how many packets driver is allowed to clean
  2511. *
  2512. * This function is used for legacy and MSI, NAPI mode
  2513. **/
  2514. int ixgbe_poll(struct napi_struct *napi, int budget)
  2515. {
  2516. struct ixgbe_q_vector *q_vector =
  2517. container_of(napi, struct ixgbe_q_vector, napi);
  2518. struct ixgbe_adapter *adapter = q_vector->adapter;
  2519. struct ixgbe_ring *ring;
  2520. int per_ring_budget, work_done = 0;
  2521. bool clean_complete = true;
  2522. #ifdef CONFIG_IXGBE_DCA
  2523. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  2524. ixgbe_update_dca(q_vector);
  2525. #endif
  2526. ixgbe_for_each_ring(ring, q_vector->tx) {
  2527. if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
  2528. clean_complete = false;
  2529. }
  2530. /* Exit if we are called by netpoll */
  2531. if (budget <= 0)
  2532. return budget;
  2533. /* attempt to distribute budget to each queue fairly, but don't allow
  2534. * the budget to go below 1 because we'll exit polling */
  2535. if (q_vector->rx.count > 1)
  2536. per_ring_budget = max(budget/q_vector->rx.count, 1);
  2537. else
  2538. per_ring_budget = budget;
  2539. ixgbe_for_each_ring(ring, q_vector->rx) {
  2540. int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
  2541. per_ring_budget);
  2542. work_done += cleaned;
  2543. if (cleaned >= per_ring_budget)
  2544. clean_complete = false;
  2545. }
  2546. /* If all work not completed, return budget and keep polling */
  2547. if (!clean_complete)
  2548. return budget;
  2549. /* all work done, exit the polling mode */
  2550. napi_complete_done(napi, work_done);
  2551. if (adapter->rx_itr_setting & 1)
  2552. ixgbe_set_itr(q_vector);
  2553. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2554. ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
  2555. return min(work_done, budget - 1);
  2556. }
  2557. /**
  2558. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  2559. * @adapter: board private structure
  2560. *
  2561. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  2562. * interrupts from the kernel.
  2563. **/
  2564. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  2565. {
  2566. struct net_device *netdev = adapter->netdev;
  2567. int vector, err;
  2568. int ri = 0, ti = 0;
  2569. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2570. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2571. struct msix_entry *entry = &adapter->msix_entries[vector];
  2572. if (q_vector->tx.ring && q_vector->rx.ring) {
  2573. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2574. "%s-%s-%d", netdev->name, "TxRx", ri++);
  2575. ti++;
  2576. } else if (q_vector->rx.ring) {
  2577. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2578. "%s-%s-%d", netdev->name, "rx", ri++);
  2579. } else if (q_vector->tx.ring) {
  2580. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2581. "%s-%s-%d", netdev->name, "tx", ti++);
  2582. } else {
  2583. /* skip this unused q_vector */
  2584. continue;
  2585. }
  2586. err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
  2587. q_vector->name, q_vector);
  2588. if (err) {
  2589. e_err(probe, "request_irq failed for MSIX interrupt "
  2590. "Error: %d\n", err);
  2591. goto free_queue_irqs;
  2592. }
  2593. /* If Flow Director is enabled, set interrupt affinity */
  2594. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2595. /* assign the mask for this irq */
  2596. irq_set_affinity_hint(entry->vector,
  2597. &q_vector->affinity_mask);
  2598. }
  2599. }
  2600. err = request_irq(adapter->msix_entries[vector].vector,
  2601. ixgbe_msix_other, 0, netdev->name, adapter);
  2602. if (err) {
  2603. e_err(probe, "request_irq for msix_other failed: %d\n", err);
  2604. goto free_queue_irqs;
  2605. }
  2606. return 0;
  2607. free_queue_irqs:
  2608. while (vector) {
  2609. vector--;
  2610. irq_set_affinity_hint(adapter->msix_entries[vector].vector,
  2611. NULL);
  2612. free_irq(adapter->msix_entries[vector].vector,
  2613. adapter->q_vector[vector]);
  2614. }
  2615. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2616. pci_disable_msix(adapter->pdev);
  2617. kfree(adapter->msix_entries);
  2618. adapter->msix_entries = NULL;
  2619. return err;
  2620. }
  2621. /**
  2622. * ixgbe_intr - legacy mode Interrupt Handler
  2623. * @irq: interrupt number
  2624. * @data: pointer to a network interface device structure
  2625. **/
  2626. static irqreturn_t ixgbe_intr(int irq, void *data)
  2627. {
  2628. struct ixgbe_adapter *adapter = data;
  2629. struct ixgbe_hw *hw = &adapter->hw;
  2630. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2631. u32 eicr;
  2632. /*
  2633. * Workaround for silicon errata #26 on 82598. Mask the interrupt
  2634. * before the read of EICR.
  2635. */
  2636. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2637. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2638. * therefore no explicit interrupt disable is necessary */
  2639. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2640. if (!eicr) {
  2641. /*
  2642. * shared interrupt alert!
  2643. * make sure interrupts are enabled because the read will
  2644. * have disabled interrupts due to EIAM
  2645. * finish the workaround of silicon errata on 82598. Unmask
  2646. * the interrupt that we masked before the EICR read.
  2647. */
  2648. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2649. ixgbe_irq_enable(adapter, true, true);
  2650. return IRQ_NONE; /* Not our interrupt */
  2651. }
  2652. if (eicr & IXGBE_EICR_LSC)
  2653. ixgbe_check_lsc(adapter);
  2654. switch (hw->mac.type) {
  2655. case ixgbe_mac_82599EB:
  2656. ixgbe_check_sfp_event(adapter, eicr);
  2657. /* Fall through */
  2658. case ixgbe_mac_X540:
  2659. case ixgbe_mac_X550:
  2660. case ixgbe_mac_X550EM_x:
  2661. case ixgbe_mac_x550em_a:
  2662. if (eicr & IXGBE_EICR_ECC) {
  2663. e_info(link, "Received ECC Err, initiating reset\n");
  2664. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2665. ixgbe_service_event_schedule(adapter);
  2666. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2667. }
  2668. ixgbe_check_overtemp_event(adapter, eicr);
  2669. break;
  2670. default:
  2671. break;
  2672. }
  2673. ixgbe_check_fan_failure(adapter, eicr);
  2674. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2675. ixgbe_ptp_check_pps_event(adapter);
  2676. /* would disable interrupts here but EIAM disabled it */
  2677. napi_schedule_irqoff(&q_vector->napi);
  2678. /*
  2679. * re-enable link(maybe) and non-queue interrupts, no flush.
  2680. * ixgbe_poll will re-enable the queue interrupts
  2681. */
  2682. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2683. ixgbe_irq_enable(adapter, false, false);
  2684. return IRQ_HANDLED;
  2685. }
  2686. /**
  2687. * ixgbe_request_irq - initialize interrupts
  2688. * @adapter: board private structure
  2689. *
  2690. * Attempts to configure interrupts using the best available
  2691. * capabilities of the hardware and kernel.
  2692. **/
  2693. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2694. {
  2695. struct net_device *netdev = adapter->netdev;
  2696. int err;
  2697. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2698. err = ixgbe_request_msix_irqs(adapter);
  2699. else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
  2700. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2701. netdev->name, adapter);
  2702. else
  2703. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2704. netdev->name, adapter);
  2705. if (err)
  2706. e_err(probe, "request_irq failed, Error %d\n", err);
  2707. return err;
  2708. }
  2709. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2710. {
  2711. int vector;
  2712. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  2713. free_irq(adapter->pdev->irq, adapter);
  2714. return;
  2715. }
  2716. if (!adapter->msix_entries)
  2717. return;
  2718. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2719. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2720. struct msix_entry *entry = &adapter->msix_entries[vector];
  2721. /* free only the irqs that were actually requested */
  2722. if (!q_vector->rx.ring && !q_vector->tx.ring)
  2723. continue;
  2724. /* clear the affinity_mask in the IRQ descriptor */
  2725. irq_set_affinity_hint(entry->vector, NULL);
  2726. free_irq(entry->vector, q_vector);
  2727. }
  2728. free_irq(adapter->msix_entries[vector].vector, adapter);
  2729. }
  2730. /**
  2731. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2732. * @adapter: board private structure
  2733. **/
  2734. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2735. {
  2736. switch (adapter->hw.mac.type) {
  2737. case ixgbe_mac_82598EB:
  2738. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2739. break;
  2740. case ixgbe_mac_82599EB:
  2741. case ixgbe_mac_X540:
  2742. case ixgbe_mac_X550:
  2743. case ixgbe_mac_X550EM_x:
  2744. case ixgbe_mac_x550em_a:
  2745. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2746. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2747. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2748. break;
  2749. default:
  2750. break;
  2751. }
  2752. IXGBE_WRITE_FLUSH(&adapter->hw);
  2753. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2754. int vector;
  2755. for (vector = 0; vector < adapter->num_q_vectors; vector++)
  2756. synchronize_irq(adapter->msix_entries[vector].vector);
  2757. synchronize_irq(adapter->msix_entries[vector++].vector);
  2758. } else {
  2759. synchronize_irq(adapter->pdev->irq);
  2760. }
  2761. }
  2762. /**
  2763. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2764. *
  2765. **/
  2766. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2767. {
  2768. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2769. ixgbe_write_eitr(q_vector);
  2770. ixgbe_set_ivar(adapter, 0, 0, 0);
  2771. ixgbe_set_ivar(adapter, 1, 0, 0);
  2772. e_info(hw, "Legacy interrupt IVAR setup done\n");
  2773. }
  2774. /**
  2775. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  2776. * @adapter: board private structure
  2777. * @ring: structure containing ring specific data
  2778. *
  2779. * Configure the Tx descriptor ring after a reset.
  2780. **/
  2781. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  2782. struct ixgbe_ring *ring)
  2783. {
  2784. struct ixgbe_hw *hw = &adapter->hw;
  2785. u64 tdba = ring->dma;
  2786. int wait_loop = 10;
  2787. u32 txdctl = IXGBE_TXDCTL_ENABLE;
  2788. u8 reg_idx = ring->reg_idx;
  2789. /* disable queue to avoid issues while updating state */
  2790. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
  2791. IXGBE_WRITE_FLUSH(hw);
  2792. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  2793. (tdba & DMA_BIT_MASK(32)));
  2794. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  2795. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  2796. ring->count * sizeof(union ixgbe_adv_tx_desc));
  2797. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  2798. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  2799. ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
  2800. /*
  2801. * set WTHRESH to encourage burst writeback, it should not be set
  2802. * higher than 1 when:
  2803. * - ITR is 0 as it could cause false TX hangs
  2804. * - ITR is set to > 100k int/sec and BQL is enabled
  2805. *
  2806. * In order to avoid issues WTHRESH + PTHRESH should always be equal
  2807. * to or less than the number of on chip descriptors, which is
  2808. * currently 40.
  2809. */
  2810. if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
  2811. txdctl |= 1u << 16; /* WTHRESH = 1 */
  2812. else
  2813. txdctl |= 8u << 16; /* WTHRESH = 8 */
  2814. /*
  2815. * Setting PTHRESH to 32 both improves performance
  2816. * and avoids a TX hang with DFP enabled
  2817. */
  2818. txdctl |= (1u << 8) | /* HTHRESH = 1 */
  2819. 32; /* PTHRESH = 32 */
  2820. /* reinitialize flowdirector state */
  2821. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2822. ring->atr_sample_rate = adapter->atr_sample_rate;
  2823. ring->atr_count = 0;
  2824. set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
  2825. } else {
  2826. ring->atr_sample_rate = 0;
  2827. }
  2828. /* initialize XPS */
  2829. if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
  2830. struct ixgbe_q_vector *q_vector = ring->q_vector;
  2831. if (q_vector)
  2832. netif_set_xps_queue(ring->netdev,
  2833. &q_vector->affinity_mask,
  2834. ring->queue_index);
  2835. }
  2836. clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
  2837. /* reinitialize tx_buffer_info */
  2838. memset(ring->tx_buffer_info, 0,
  2839. sizeof(struct ixgbe_tx_buffer) * ring->count);
  2840. /* enable queue */
  2841. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  2842. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  2843. if (hw->mac.type == ixgbe_mac_82598EB &&
  2844. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2845. return;
  2846. /* poll to verify queue is enabled */
  2847. do {
  2848. usleep_range(1000, 2000);
  2849. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  2850. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  2851. if (!wait_loop)
  2852. hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
  2853. }
  2854. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  2855. {
  2856. struct ixgbe_hw *hw = &adapter->hw;
  2857. u32 rttdcs, mtqc;
  2858. u8 tcs = netdev_get_num_tc(adapter->netdev);
  2859. if (hw->mac.type == ixgbe_mac_82598EB)
  2860. return;
  2861. /* disable the arbiter while setting MTQC */
  2862. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  2863. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  2864. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2865. /* set transmit pool layout */
  2866. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2867. mtqc = IXGBE_MTQC_VT_ENA;
  2868. if (tcs > 4)
  2869. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2870. else if (tcs > 1)
  2871. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2872. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  2873. IXGBE_82599_VMDQ_4Q_MASK)
  2874. mtqc |= IXGBE_MTQC_32VF;
  2875. else
  2876. mtqc |= IXGBE_MTQC_64VF;
  2877. } else {
  2878. if (tcs > 4)
  2879. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2880. else if (tcs > 1)
  2881. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2882. else
  2883. mtqc = IXGBE_MTQC_64Q_1PB;
  2884. }
  2885. IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
  2886. /* Enable Security TX Buffer IFG for multiple pb */
  2887. if (tcs) {
  2888. u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  2889. sectx |= IXGBE_SECTX_DCB;
  2890. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
  2891. }
  2892. /* re-enable the arbiter */
  2893. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  2894. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2895. }
  2896. /**
  2897. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  2898. * @adapter: board private structure
  2899. *
  2900. * Configure the Tx unit of the MAC after a reset.
  2901. **/
  2902. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  2903. {
  2904. struct ixgbe_hw *hw = &adapter->hw;
  2905. u32 dmatxctl;
  2906. u32 i;
  2907. ixgbe_setup_mtqc(adapter);
  2908. if (hw->mac.type != ixgbe_mac_82598EB) {
  2909. /* DMATXCTL.EN must be before Tx queues are enabled */
  2910. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  2911. dmatxctl |= IXGBE_DMATXCTL_TE;
  2912. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  2913. }
  2914. /* Setup the HW Tx Head and Tail descriptor pointers */
  2915. for (i = 0; i < adapter->num_tx_queues; i++)
  2916. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2917. }
  2918. static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
  2919. struct ixgbe_ring *ring)
  2920. {
  2921. struct ixgbe_hw *hw = &adapter->hw;
  2922. u8 reg_idx = ring->reg_idx;
  2923. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2924. srrctl |= IXGBE_SRRCTL_DROP_EN;
  2925. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2926. }
  2927. static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
  2928. struct ixgbe_ring *ring)
  2929. {
  2930. struct ixgbe_hw *hw = &adapter->hw;
  2931. u8 reg_idx = ring->reg_idx;
  2932. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2933. srrctl &= ~IXGBE_SRRCTL_DROP_EN;
  2934. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2935. }
  2936. #ifdef CONFIG_IXGBE_DCB
  2937. void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2938. #else
  2939. static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2940. #endif
  2941. {
  2942. int i;
  2943. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  2944. if (adapter->ixgbe_ieee_pfc)
  2945. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  2946. /*
  2947. * We should set the drop enable bit if:
  2948. * SR-IOV is enabled
  2949. * or
  2950. * Number of Rx queues > 1 and flow control is disabled
  2951. *
  2952. * This allows us to avoid head of line blocking for security
  2953. * and performance reasons.
  2954. */
  2955. if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
  2956. !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
  2957. for (i = 0; i < adapter->num_rx_queues; i++)
  2958. ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
  2959. } else {
  2960. for (i = 0; i < adapter->num_rx_queues; i++)
  2961. ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
  2962. }
  2963. }
  2964. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  2965. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  2966. struct ixgbe_ring *rx_ring)
  2967. {
  2968. struct ixgbe_hw *hw = &adapter->hw;
  2969. u32 srrctl;
  2970. u8 reg_idx = rx_ring->reg_idx;
  2971. if (hw->mac.type == ixgbe_mac_82598EB) {
  2972. u16 mask = adapter->ring_feature[RING_F_RSS].mask;
  2973. /*
  2974. * if VMDq is not active we must program one srrctl register
  2975. * per RSS queue since we have enabled RDRXCTL.MVMEN
  2976. */
  2977. reg_idx &= mask;
  2978. }
  2979. /* configure header buffer length, needed for RSC */
  2980. srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
  2981. /* configure the packet buffer length */
  2982. if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
  2983. srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2984. else
  2985. srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2986. /* configure descriptor type */
  2987. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  2988. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2989. }
  2990. /**
  2991. * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
  2992. * @adapter: device handle
  2993. *
  2994. * - 82598/82599/X540: 128
  2995. * - X550(non-SRIOV mode): 512
  2996. * - X550(SRIOV mode): 64
  2997. */
  2998. u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
  2999. {
  3000. if (adapter->hw.mac.type < ixgbe_mac_X550)
  3001. return 128;
  3002. else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3003. return 64;
  3004. else
  3005. return 512;
  3006. }
  3007. /**
  3008. * ixgbe_store_key - Write the RSS key to HW
  3009. * @adapter: device handle
  3010. *
  3011. * Write the RSS key stored in adapter.rss_key to HW.
  3012. */
  3013. void ixgbe_store_key(struct ixgbe_adapter *adapter)
  3014. {
  3015. struct ixgbe_hw *hw = &adapter->hw;
  3016. int i;
  3017. for (i = 0; i < 10; i++)
  3018. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
  3019. }
  3020. /**
  3021. * ixgbe_store_reta - Write the RETA table to HW
  3022. * @adapter: device handle
  3023. *
  3024. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3025. */
  3026. void ixgbe_store_reta(struct ixgbe_adapter *adapter)
  3027. {
  3028. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3029. struct ixgbe_hw *hw = &adapter->hw;
  3030. u32 reta = 0;
  3031. u32 indices_multi;
  3032. u8 *indir_tbl = adapter->rss_indir_tbl;
  3033. /* Fill out the redirection table as follows:
  3034. * - 82598: 8 bit wide entries containing pair of 4 bit RSS
  3035. * indices.
  3036. * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
  3037. * - X550: 8 bit wide entries containing 6 bit RSS index
  3038. */
  3039. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  3040. indices_multi = 0x11;
  3041. else
  3042. indices_multi = 0x1;
  3043. /* Write redirection table to HW */
  3044. for (i = 0; i < reta_entries; i++) {
  3045. reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
  3046. if ((i & 3) == 3) {
  3047. if (i < 128)
  3048. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  3049. else
  3050. IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
  3051. reta);
  3052. reta = 0;
  3053. }
  3054. }
  3055. }
  3056. /**
  3057. * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
  3058. * @adapter: device handle
  3059. *
  3060. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3061. */
  3062. static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
  3063. {
  3064. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3065. struct ixgbe_hw *hw = &adapter->hw;
  3066. u32 vfreta = 0;
  3067. unsigned int pf_pool = adapter->num_vfs;
  3068. /* Write redirection table to HW */
  3069. for (i = 0; i < reta_entries; i++) {
  3070. vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
  3071. if ((i & 3) == 3) {
  3072. IXGBE_WRITE_REG(hw, IXGBE_PFVFRETA(i >> 2, pf_pool),
  3073. vfreta);
  3074. vfreta = 0;
  3075. }
  3076. }
  3077. }
  3078. static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
  3079. {
  3080. u32 i, j;
  3081. u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3082. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3083. /* Program table for at least 4 queues w/ SR-IOV so that VFs can
  3084. * make full use of any rings they may have. We will use the
  3085. * PSRTYPE register to control how many rings we use within the PF.
  3086. */
  3087. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
  3088. rss_i = 4;
  3089. /* Fill out hash function seeds */
  3090. ixgbe_store_key(adapter);
  3091. /* Fill out redirection table */
  3092. memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
  3093. for (i = 0, j = 0; i < reta_entries; i++, j++) {
  3094. if (j == rss_i)
  3095. j = 0;
  3096. adapter->rss_indir_tbl[i] = j;
  3097. }
  3098. ixgbe_store_reta(adapter);
  3099. }
  3100. static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
  3101. {
  3102. struct ixgbe_hw *hw = &adapter->hw;
  3103. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3104. unsigned int pf_pool = adapter->num_vfs;
  3105. int i, j;
  3106. /* Fill out hash function seeds */
  3107. for (i = 0; i < 10; i++)
  3108. IXGBE_WRITE_REG(hw, IXGBE_PFVFRSSRK(i, pf_pool),
  3109. adapter->rss_key[i]);
  3110. /* Fill out the redirection table */
  3111. for (i = 0, j = 0; i < 64; i++, j++) {
  3112. if (j == rss_i)
  3113. j = 0;
  3114. adapter->rss_indir_tbl[i] = j;
  3115. }
  3116. ixgbe_store_vfreta(adapter);
  3117. }
  3118. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  3119. {
  3120. struct ixgbe_hw *hw = &adapter->hw;
  3121. u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
  3122. u32 rxcsum;
  3123. /* Disable indicating checksum in descriptor, enables RSS hash */
  3124. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  3125. rxcsum |= IXGBE_RXCSUM_PCSD;
  3126. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  3127. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3128. if (adapter->ring_feature[RING_F_RSS].mask)
  3129. mrqc = IXGBE_MRQC_RSSEN;
  3130. } else {
  3131. u8 tcs = netdev_get_num_tc(adapter->netdev);
  3132. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3133. if (tcs > 4)
  3134. mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
  3135. else if (tcs > 1)
  3136. mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
  3137. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3138. IXGBE_82599_VMDQ_4Q_MASK)
  3139. mrqc = IXGBE_MRQC_VMDQRSS32EN;
  3140. else
  3141. mrqc = IXGBE_MRQC_VMDQRSS64EN;
  3142. } else {
  3143. if (tcs > 4)
  3144. mrqc = IXGBE_MRQC_RTRSS8TCEN;
  3145. else if (tcs > 1)
  3146. mrqc = IXGBE_MRQC_RTRSS4TCEN;
  3147. else
  3148. mrqc = IXGBE_MRQC_RSSEN;
  3149. }
  3150. }
  3151. /* Perform hash on these packet types */
  3152. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
  3153. IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
  3154. IXGBE_MRQC_RSS_FIELD_IPV6 |
  3155. IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  3156. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
  3157. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
  3158. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
  3159. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  3160. netdev_rss_key_fill(adapter->rss_key, sizeof(adapter->rss_key));
  3161. if ((hw->mac.type >= ixgbe_mac_X550) &&
  3162. (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  3163. unsigned int pf_pool = adapter->num_vfs;
  3164. /* Enable VF RSS mode */
  3165. mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
  3166. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3167. /* Setup RSS through the VF registers */
  3168. ixgbe_setup_vfreta(adapter);
  3169. vfmrqc = IXGBE_MRQC_RSSEN;
  3170. vfmrqc |= rss_field;
  3171. IXGBE_WRITE_REG(hw, IXGBE_PFVFMRQC(pf_pool), vfmrqc);
  3172. } else {
  3173. ixgbe_setup_reta(adapter);
  3174. mrqc |= rss_field;
  3175. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3176. }
  3177. }
  3178. /**
  3179. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  3180. * @adapter: address of board private structure
  3181. * @index: index of ring to set
  3182. **/
  3183. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  3184. struct ixgbe_ring *ring)
  3185. {
  3186. struct ixgbe_hw *hw = &adapter->hw;
  3187. u32 rscctrl;
  3188. u8 reg_idx = ring->reg_idx;
  3189. if (!ring_is_rsc_enabled(ring))
  3190. return;
  3191. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  3192. rscctrl |= IXGBE_RSCCTL_RSCEN;
  3193. /*
  3194. * we must limit the number of descriptors so that the
  3195. * total size of max desc * buf_len is not greater
  3196. * than 65536
  3197. */
  3198. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  3199. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  3200. }
  3201. #define IXGBE_MAX_RX_DESC_POLL 10
  3202. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  3203. struct ixgbe_ring *ring)
  3204. {
  3205. struct ixgbe_hw *hw = &adapter->hw;
  3206. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3207. u32 rxdctl;
  3208. u8 reg_idx = ring->reg_idx;
  3209. if (ixgbe_removed(hw->hw_addr))
  3210. return;
  3211. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3212. if (hw->mac.type == ixgbe_mac_82598EB &&
  3213. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3214. return;
  3215. do {
  3216. usleep_range(1000, 2000);
  3217. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3218. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  3219. if (!wait_loop) {
  3220. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  3221. "the polling period\n", reg_idx);
  3222. }
  3223. }
  3224. void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
  3225. struct ixgbe_ring *ring)
  3226. {
  3227. struct ixgbe_hw *hw = &adapter->hw;
  3228. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3229. u32 rxdctl;
  3230. u8 reg_idx = ring->reg_idx;
  3231. if (ixgbe_removed(hw->hw_addr))
  3232. return;
  3233. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3234. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  3235. /* write value back with RXDCTL.ENABLE bit cleared */
  3236. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3237. if (hw->mac.type == ixgbe_mac_82598EB &&
  3238. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3239. return;
  3240. /* the hardware may take up to 100us to really disable the rx queue */
  3241. do {
  3242. udelay(10);
  3243. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3244. } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
  3245. if (!wait_loop) {
  3246. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
  3247. "the polling period\n", reg_idx);
  3248. }
  3249. }
  3250. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  3251. struct ixgbe_ring *ring)
  3252. {
  3253. struct ixgbe_hw *hw = &adapter->hw;
  3254. union ixgbe_adv_rx_desc *rx_desc;
  3255. u64 rdba = ring->dma;
  3256. u32 rxdctl;
  3257. u8 reg_idx = ring->reg_idx;
  3258. /* disable queue to avoid issues while updating state */
  3259. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3260. ixgbe_disable_rx_queue(adapter, ring);
  3261. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  3262. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  3263. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  3264. ring->count * sizeof(union ixgbe_adv_rx_desc));
  3265. /* Force flushing of IXGBE_RDLEN to prevent MDD */
  3266. IXGBE_WRITE_FLUSH(hw);
  3267. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  3268. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  3269. ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
  3270. ixgbe_configure_srrctl(adapter, ring);
  3271. ixgbe_configure_rscctl(adapter, ring);
  3272. if (hw->mac.type == ixgbe_mac_82598EB) {
  3273. /*
  3274. * enable cache line friendly hardware writes:
  3275. * PTHRESH=32 descriptors (half the internal cache),
  3276. * this also removes ugly rx_no_buffer_count increment
  3277. * HTHRESH=4 descriptors (to minimize latency on fetch)
  3278. * WTHRESH=8 burst writeback up to two cache lines
  3279. */
  3280. rxdctl &= ~0x3FFFFF;
  3281. rxdctl |= 0x080420;
  3282. #if (PAGE_SIZE < 8192)
  3283. } else {
  3284. rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
  3285. IXGBE_RXDCTL_RLPML_EN);
  3286. /* Limit the maximum frame size so we don't overrun the skb */
  3287. if (ring_uses_build_skb(ring) &&
  3288. !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
  3289. rxdctl |= IXGBE_MAX_FRAME_BUILD_SKB |
  3290. IXGBE_RXDCTL_RLPML_EN;
  3291. #endif
  3292. }
  3293. /* initialize rx_buffer_info */
  3294. memset(ring->rx_buffer_info, 0,
  3295. sizeof(struct ixgbe_rx_buffer) * ring->count);
  3296. /* initialize Rx descriptor 0 */
  3297. rx_desc = IXGBE_RX_DESC(ring, 0);
  3298. rx_desc->wb.upper.length = 0;
  3299. /* enable receive descriptor ring */
  3300. rxdctl |= IXGBE_RXDCTL_ENABLE;
  3301. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3302. ixgbe_rx_desc_queue_enable(adapter, ring);
  3303. ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
  3304. }
  3305. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  3306. {
  3307. struct ixgbe_hw *hw = &adapter->hw;
  3308. int rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3309. u16 pool;
  3310. /* PSRTYPE must be initialized in non 82598 adapters */
  3311. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  3312. IXGBE_PSRTYPE_UDPHDR |
  3313. IXGBE_PSRTYPE_IPV4HDR |
  3314. IXGBE_PSRTYPE_L2HDR |
  3315. IXGBE_PSRTYPE_IPV6HDR;
  3316. if (hw->mac.type == ixgbe_mac_82598EB)
  3317. return;
  3318. if (rss_i > 3)
  3319. psrtype |= 2u << 29;
  3320. else if (rss_i > 1)
  3321. psrtype |= 1u << 29;
  3322. for_each_set_bit(pool, &adapter->fwd_bitmask, 32)
  3323. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  3324. }
  3325. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  3326. {
  3327. struct ixgbe_hw *hw = &adapter->hw;
  3328. u32 reg_offset, vf_shift;
  3329. u32 gcr_ext, vmdctl;
  3330. int i;
  3331. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  3332. return;
  3333. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  3334. vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
  3335. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  3336. vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
  3337. vmdctl |= IXGBE_VT_CTL_REPLEN;
  3338. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  3339. vf_shift = VMDQ_P(0) % 32;
  3340. reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
  3341. /* Enable only the PF's pool for Tx/Rx */
  3342. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
  3343. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
  3344. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
  3345. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
  3346. if (adapter->bridge_mode == BRIDGE_MODE_VEB)
  3347. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  3348. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  3349. hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
  3350. /* clear VLAN promisc flag so VFTA will be updated if necessary */
  3351. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3352. /*
  3353. * Set up VF register offsets for selected VT Mode,
  3354. * i.e. 32 or 64 VFs for SR-IOV
  3355. */
  3356. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  3357. case IXGBE_82599_VMDQ_8Q_MASK:
  3358. gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
  3359. break;
  3360. case IXGBE_82599_VMDQ_4Q_MASK:
  3361. gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
  3362. break;
  3363. default:
  3364. gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
  3365. break;
  3366. }
  3367. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3368. for (i = 0; i < adapter->num_vfs; i++) {
  3369. /* configure spoof checking */
  3370. ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
  3371. adapter->vfinfo[i].spoofchk_enabled);
  3372. /* Enable/Disable RSS query feature */
  3373. ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
  3374. adapter->vfinfo[i].rss_query_enabled);
  3375. }
  3376. }
  3377. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  3378. {
  3379. struct ixgbe_hw *hw = &adapter->hw;
  3380. struct net_device *netdev = adapter->netdev;
  3381. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3382. struct ixgbe_ring *rx_ring;
  3383. int i;
  3384. u32 mhadd, hlreg0;
  3385. #ifdef IXGBE_FCOE
  3386. /* adjust max frame to be able to do baby jumbo for FCoE */
  3387. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  3388. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  3389. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3390. #endif /* IXGBE_FCOE */
  3391. /* adjust max frame to be at least the size of a standard frame */
  3392. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  3393. max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
  3394. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  3395. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  3396. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  3397. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  3398. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  3399. }
  3400. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3401. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  3402. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  3403. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3404. /*
  3405. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3406. * the Base and Length of the Rx Descriptor Ring
  3407. */
  3408. for (i = 0; i < adapter->num_rx_queues; i++) {
  3409. rx_ring = adapter->rx_ring[i];
  3410. clear_ring_rsc_enabled(rx_ring);
  3411. clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3412. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3413. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3414. set_ring_rsc_enabled(rx_ring);
  3415. if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
  3416. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3417. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3418. if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
  3419. continue;
  3420. set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3421. #if (PAGE_SIZE < 8192)
  3422. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3423. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3424. if ((max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)) ||
  3425. (max_frame > IXGBE_MAX_FRAME_BUILD_SKB))
  3426. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3427. #endif
  3428. }
  3429. }
  3430. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  3431. {
  3432. struct ixgbe_hw *hw = &adapter->hw;
  3433. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  3434. switch (hw->mac.type) {
  3435. case ixgbe_mac_82598EB:
  3436. /*
  3437. * For VMDq support of different descriptor types or
  3438. * buffer sizes through the use of multiple SRRCTL
  3439. * registers, RDRXCTL.MVMEN must be set to 1
  3440. *
  3441. * also, the manual doesn't mention it clearly but DCA hints
  3442. * will only use queue 0's tags unless this bit is set. Side
  3443. * effects of setting this bit are only that SRRCTL must be
  3444. * fully programmed [0..15]
  3445. */
  3446. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  3447. break;
  3448. case ixgbe_mac_X550:
  3449. case ixgbe_mac_X550EM_x:
  3450. case ixgbe_mac_x550em_a:
  3451. if (adapter->num_vfs)
  3452. rdrxctl |= IXGBE_RDRXCTL_PSP;
  3453. /* fall through for older HW */
  3454. case ixgbe_mac_82599EB:
  3455. case ixgbe_mac_X540:
  3456. /* Disable RSC for ACK packets */
  3457. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  3458. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  3459. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  3460. /* hardware requires some bits to be set by default */
  3461. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  3462. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  3463. break;
  3464. default:
  3465. /* We should do nothing since we don't know this hardware */
  3466. return;
  3467. }
  3468. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  3469. }
  3470. /**
  3471. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  3472. * @adapter: board private structure
  3473. *
  3474. * Configure the Rx unit of the MAC after a reset.
  3475. **/
  3476. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  3477. {
  3478. struct ixgbe_hw *hw = &adapter->hw;
  3479. int i;
  3480. u32 rxctrl, rfctl;
  3481. /* disable receives while setting up the descriptors */
  3482. hw->mac.ops.disable_rx(hw);
  3483. ixgbe_setup_psrtype(adapter);
  3484. ixgbe_setup_rdrxctl(adapter);
  3485. /* RSC Setup */
  3486. rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
  3487. rfctl &= ~IXGBE_RFCTL_RSC_DIS;
  3488. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  3489. rfctl |= IXGBE_RFCTL_RSC_DIS;
  3490. /* disable NFS filtering */
  3491. rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
  3492. IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
  3493. /* Program registers for the distribution of queues */
  3494. ixgbe_setup_mrqc(adapter);
  3495. /* set_rx_buffer_len must be called before ring initialization */
  3496. ixgbe_set_rx_buffer_len(adapter);
  3497. /*
  3498. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3499. * the Base and Length of the Rx Descriptor Ring
  3500. */
  3501. for (i = 0; i < adapter->num_rx_queues; i++)
  3502. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  3503. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3504. /* disable drop enable for 82598 parts */
  3505. if (hw->mac.type == ixgbe_mac_82598EB)
  3506. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  3507. /* enable all receives */
  3508. rxctrl |= IXGBE_RXCTRL_RXEN;
  3509. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  3510. }
  3511. static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
  3512. __be16 proto, u16 vid)
  3513. {
  3514. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3515. struct ixgbe_hw *hw = &adapter->hw;
  3516. /* add VID to filter table */
  3517. if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3518. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
  3519. set_bit(vid, adapter->active_vlans);
  3520. return 0;
  3521. }
  3522. static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
  3523. {
  3524. u32 vlvf;
  3525. int idx;
  3526. /* short cut the special case */
  3527. if (vlan == 0)
  3528. return 0;
  3529. /* Search for the vlan id in the VLVF entries */
  3530. for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
  3531. vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
  3532. if ((vlvf & VLAN_VID_MASK) == vlan)
  3533. break;
  3534. }
  3535. return idx;
  3536. }
  3537. void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
  3538. {
  3539. struct ixgbe_hw *hw = &adapter->hw;
  3540. u32 bits, word;
  3541. int idx;
  3542. idx = ixgbe_find_vlvf_entry(hw, vid);
  3543. if (!idx)
  3544. return;
  3545. /* See if any other pools are set for this VLAN filter
  3546. * entry other than the PF.
  3547. */
  3548. word = idx * 2 + (VMDQ_P(0) / 32);
  3549. bits = ~BIT(VMDQ_P(0) % 32);
  3550. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3551. /* Disable the filter so this falls into the default pool. */
  3552. if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
  3553. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3554. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
  3555. IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
  3556. }
  3557. }
  3558. static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
  3559. __be16 proto, u16 vid)
  3560. {
  3561. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3562. struct ixgbe_hw *hw = &adapter->hw;
  3563. /* remove VID from filter table */
  3564. if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3565. hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
  3566. clear_bit(vid, adapter->active_vlans);
  3567. return 0;
  3568. }
  3569. /**
  3570. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  3571. * @adapter: driver data
  3572. */
  3573. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  3574. {
  3575. struct ixgbe_hw *hw = &adapter->hw;
  3576. u32 vlnctrl;
  3577. int i, j;
  3578. switch (hw->mac.type) {
  3579. case ixgbe_mac_82598EB:
  3580. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3581. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  3582. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3583. break;
  3584. case ixgbe_mac_82599EB:
  3585. case ixgbe_mac_X540:
  3586. case ixgbe_mac_X550:
  3587. case ixgbe_mac_X550EM_x:
  3588. case ixgbe_mac_x550em_a:
  3589. for (i = 0; i < adapter->num_rx_queues; i++) {
  3590. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3591. if (ring->l2_accel_priv)
  3592. continue;
  3593. j = ring->reg_idx;
  3594. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3595. vlnctrl &= ~IXGBE_RXDCTL_VME;
  3596. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3597. }
  3598. break;
  3599. default:
  3600. break;
  3601. }
  3602. }
  3603. /**
  3604. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  3605. * @adapter: driver data
  3606. */
  3607. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  3608. {
  3609. struct ixgbe_hw *hw = &adapter->hw;
  3610. u32 vlnctrl;
  3611. int i, j;
  3612. switch (hw->mac.type) {
  3613. case ixgbe_mac_82598EB:
  3614. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3615. vlnctrl |= IXGBE_VLNCTRL_VME;
  3616. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3617. break;
  3618. case ixgbe_mac_82599EB:
  3619. case ixgbe_mac_X540:
  3620. case ixgbe_mac_X550:
  3621. case ixgbe_mac_X550EM_x:
  3622. case ixgbe_mac_x550em_a:
  3623. for (i = 0; i < adapter->num_rx_queues; i++) {
  3624. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3625. if (ring->l2_accel_priv)
  3626. continue;
  3627. j = ring->reg_idx;
  3628. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3629. vlnctrl |= IXGBE_RXDCTL_VME;
  3630. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3631. }
  3632. break;
  3633. default:
  3634. break;
  3635. }
  3636. }
  3637. static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
  3638. {
  3639. struct ixgbe_hw *hw = &adapter->hw;
  3640. u32 vlnctrl, i;
  3641. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3642. if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
  3643. /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
  3644. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3645. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3646. } else {
  3647. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  3648. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3649. return;
  3650. }
  3651. /* Nothing to do for 82598 */
  3652. if (hw->mac.type == ixgbe_mac_82598EB)
  3653. return;
  3654. /* We are already in VLAN promisc, nothing to do */
  3655. if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
  3656. return;
  3657. /* Set flag so we don't redo unnecessary work */
  3658. adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
  3659. /* Add PF to all active pools */
  3660. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3661. u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
  3662. u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
  3663. vlvfb |= BIT(VMDQ_P(0) % 32);
  3664. IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
  3665. }
  3666. /* Set all bits in the VLAN filter table array */
  3667. for (i = hw->mac.vft_size; i--;)
  3668. IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
  3669. }
  3670. #define VFTA_BLOCK_SIZE 8
  3671. static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
  3672. {
  3673. struct ixgbe_hw *hw = &adapter->hw;
  3674. u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
  3675. u32 vid_start = vfta_offset * 32;
  3676. u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
  3677. u32 i, vid, word, bits;
  3678. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3679. u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
  3680. /* pull VLAN ID from VLVF */
  3681. vid = vlvf & VLAN_VID_MASK;
  3682. /* only concern outselves with a certain range */
  3683. if (vid < vid_start || vid >= vid_end)
  3684. continue;
  3685. if (vlvf) {
  3686. /* record VLAN ID in VFTA */
  3687. vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
  3688. /* if PF is part of this then continue */
  3689. if (test_bit(vid, adapter->active_vlans))
  3690. continue;
  3691. }
  3692. /* remove PF from the pool */
  3693. word = i * 2 + VMDQ_P(0) / 32;
  3694. bits = ~BIT(VMDQ_P(0) % 32);
  3695. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3696. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
  3697. }
  3698. /* extract values from active_vlans and write back to VFTA */
  3699. for (i = VFTA_BLOCK_SIZE; i--;) {
  3700. vid = (vfta_offset + i) * 32;
  3701. word = vid / BITS_PER_LONG;
  3702. bits = vid % BITS_PER_LONG;
  3703. vfta[i] |= adapter->active_vlans[word] >> bits;
  3704. IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
  3705. }
  3706. }
  3707. static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
  3708. {
  3709. struct ixgbe_hw *hw = &adapter->hw;
  3710. u32 vlnctrl, i;
  3711. /* Set VLAN filtering to enabled */
  3712. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3713. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3714. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3715. if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
  3716. hw->mac.type == ixgbe_mac_82598EB)
  3717. return;
  3718. /* We are not in VLAN promisc, nothing to do */
  3719. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3720. return;
  3721. /* Set flag so we don't redo unnecessary work */
  3722. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3723. for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
  3724. ixgbe_scrub_vfta(adapter, i);
  3725. }
  3726. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  3727. {
  3728. u16 vid = 1;
  3729. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  3730. for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
  3731. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  3732. }
  3733. /**
  3734. * ixgbe_write_mc_addr_list - write multicast addresses to MTA
  3735. * @netdev: network interface device structure
  3736. *
  3737. * Writes multicast address list to the MTA hash table.
  3738. * Returns: -ENOMEM on failure
  3739. * 0 on no addresses written
  3740. * X on writing X addresses to MTA
  3741. **/
  3742. static int ixgbe_write_mc_addr_list(struct net_device *netdev)
  3743. {
  3744. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3745. struct ixgbe_hw *hw = &adapter->hw;
  3746. if (!netif_running(netdev))
  3747. return 0;
  3748. if (hw->mac.ops.update_mc_addr_list)
  3749. hw->mac.ops.update_mc_addr_list(hw, netdev);
  3750. else
  3751. return -ENOMEM;
  3752. #ifdef CONFIG_PCI_IOV
  3753. ixgbe_restore_vf_multicasts(adapter);
  3754. #endif
  3755. return netdev_mc_count(netdev);
  3756. }
  3757. #ifdef CONFIG_PCI_IOV
  3758. void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
  3759. {
  3760. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3761. struct ixgbe_hw *hw = &adapter->hw;
  3762. int i;
  3763. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3764. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  3765. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  3766. hw->mac.ops.set_rar(hw, i,
  3767. mac_table->addr,
  3768. mac_table->pool,
  3769. IXGBE_RAH_AV);
  3770. else
  3771. hw->mac.ops.clear_rar(hw, i);
  3772. }
  3773. }
  3774. #endif
  3775. static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
  3776. {
  3777. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3778. struct ixgbe_hw *hw = &adapter->hw;
  3779. int i;
  3780. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3781. if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
  3782. continue;
  3783. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  3784. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  3785. hw->mac.ops.set_rar(hw, i,
  3786. mac_table->addr,
  3787. mac_table->pool,
  3788. IXGBE_RAH_AV);
  3789. else
  3790. hw->mac.ops.clear_rar(hw, i);
  3791. }
  3792. }
  3793. static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
  3794. {
  3795. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3796. struct ixgbe_hw *hw = &adapter->hw;
  3797. int i;
  3798. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3799. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  3800. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  3801. }
  3802. ixgbe_sync_mac_table(adapter);
  3803. }
  3804. static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
  3805. {
  3806. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3807. struct ixgbe_hw *hw = &adapter->hw;
  3808. int i, count = 0;
  3809. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3810. /* do not count default RAR as available */
  3811. if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
  3812. continue;
  3813. /* only count unused and addresses that belong to us */
  3814. if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
  3815. if (mac_table->pool != pool)
  3816. continue;
  3817. }
  3818. count++;
  3819. }
  3820. return count;
  3821. }
  3822. /* this function destroys the first RAR entry */
  3823. static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
  3824. {
  3825. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3826. struct ixgbe_hw *hw = &adapter->hw;
  3827. memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
  3828. mac_table->pool = VMDQ_P(0);
  3829. mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
  3830. hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
  3831. IXGBE_RAH_AV);
  3832. }
  3833. int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
  3834. const u8 *addr, u16 pool)
  3835. {
  3836. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3837. struct ixgbe_hw *hw = &adapter->hw;
  3838. int i;
  3839. if (is_zero_ether_addr(addr))
  3840. return -EINVAL;
  3841. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3842. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  3843. continue;
  3844. ether_addr_copy(mac_table->addr, addr);
  3845. mac_table->pool = pool;
  3846. mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
  3847. IXGBE_MAC_STATE_IN_USE;
  3848. ixgbe_sync_mac_table(adapter);
  3849. return i;
  3850. }
  3851. return -ENOMEM;
  3852. }
  3853. int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
  3854. const u8 *addr, u16 pool)
  3855. {
  3856. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  3857. struct ixgbe_hw *hw = &adapter->hw;
  3858. int i;
  3859. if (is_zero_ether_addr(addr))
  3860. return -EINVAL;
  3861. /* search table for addr, if found clear IN_USE flag and sync */
  3862. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  3863. /* we can only delete an entry if it is in use */
  3864. if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
  3865. continue;
  3866. /* we only care about entries that belong to the given pool */
  3867. if (mac_table->pool != pool)
  3868. continue;
  3869. /* we only care about a specific MAC address */
  3870. if (!ether_addr_equal(addr, mac_table->addr))
  3871. continue;
  3872. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  3873. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  3874. ixgbe_sync_mac_table(adapter);
  3875. return 0;
  3876. }
  3877. return -ENOMEM;
  3878. }
  3879. /**
  3880. * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
  3881. * @netdev: network interface device structure
  3882. *
  3883. * Writes unicast address list to the RAR table.
  3884. * Returns: -ENOMEM on failure/insufficient address space
  3885. * 0 on no addresses written
  3886. * X on writing X addresses to the RAR table
  3887. **/
  3888. static int ixgbe_write_uc_addr_list(struct net_device *netdev, int vfn)
  3889. {
  3890. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3891. int count = 0;
  3892. /* return ENOMEM indicating insufficient memory for addresses */
  3893. if (netdev_uc_count(netdev) > ixgbe_available_rars(adapter, vfn))
  3894. return -ENOMEM;
  3895. if (!netdev_uc_empty(netdev)) {
  3896. struct netdev_hw_addr *ha;
  3897. netdev_for_each_uc_addr(ha, netdev) {
  3898. ixgbe_del_mac_filter(adapter, ha->addr, vfn);
  3899. ixgbe_add_mac_filter(adapter, ha->addr, vfn);
  3900. count++;
  3901. }
  3902. }
  3903. return count;
  3904. }
  3905. static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
  3906. {
  3907. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3908. int ret;
  3909. ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
  3910. return min_t(int, ret, 0);
  3911. }
  3912. static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
  3913. {
  3914. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3915. ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
  3916. return 0;
  3917. }
  3918. /**
  3919. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  3920. * @netdev: network interface device structure
  3921. *
  3922. * The set_rx_method entry point is called whenever the unicast/multicast
  3923. * address list or the network interface flags are updated. This routine is
  3924. * responsible for configuring the hardware for proper unicast, multicast and
  3925. * promiscuous mode.
  3926. **/
  3927. void ixgbe_set_rx_mode(struct net_device *netdev)
  3928. {
  3929. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3930. struct ixgbe_hw *hw = &adapter->hw;
  3931. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  3932. netdev_features_t features = netdev->features;
  3933. int count;
  3934. /* Check for Promiscuous and All Multicast modes */
  3935. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  3936. /* set all bits that we expect to always be set */
  3937. fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
  3938. fctrl |= IXGBE_FCTRL_BAM;
  3939. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  3940. fctrl |= IXGBE_FCTRL_PMCF;
  3941. /* clear the bits we are changing the status of */
  3942. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3943. if (netdev->flags & IFF_PROMISC) {
  3944. hw->addr_ctrl.user_set_promisc = true;
  3945. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3946. vmolr |= IXGBE_VMOLR_MPE;
  3947. features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  3948. } else {
  3949. if (netdev->flags & IFF_ALLMULTI) {
  3950. fctrl |= IXGBE_FCTRL_MPE;
  3951. vmolr |= IXGBE_VMOLR_MPE;
  3952. }
  3953. hw->addr_ctrl.user_set_promisc = false;
  3954. }
  3955. /*
  3956. * Write addresses to available RAR registers, if there is not
  3957. * sufficient space to store all the addresses then enable
  3958. * unicast promiscuous mode
  3959. */
  3960. if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
  3961. fctrl |= IXGBE_FCTRL_UPE;
  3962. vmolr |= IXGBE_VMOLR_ROPE;
  3963. }
  3964. /* Write addresses to the MTA, if the attempt fails
  3965. * then we should just turn on promiscuous mode so
  3966. * that we can at least receive multicast traffic
  3967. */
  3968. count = ixgbe_write_mc_addr_list(netdev);
  3969. if (count < 0) {
  3970. fctrl |= IXGBE_FCTRL_MPE;
  3971. vmolr |= IXGBE_VMOLR_MPE;
  3972. } else if (count) {
  3973. vmolr |= IXGBE_VMOLR_ROMPE;
  3974. }
  3975. if (hw->mac.type != ixgbe_mac_82598EB) {
  3976. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
  3977. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  3978. IXGBE_VMOLR_ROPE);
  3979. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
  3980. }
  3981. /* This is useful for sniffing bad packets. */
  3982. if (features & NETIF_F_RXALL) {
  3983. /* UPE and MPE will be handled by normal PROMISC logic
  3984. * in e1000e_set_rx_mode */
  3985. fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
  3986. IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
  3987. IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
  3988. fctrl &= ~(IXGBE_FCTRL_DPF);
  3989. /* NOTE: VLAN filtering is disabled by setting PROMISC */
  3990. }
  3991. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  3992. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  3993. ixgbe_vlan_strip_enable(adapter);
  3994. else
  3995. ixgbe_vlan_strip_disable(adapter);
  3996. if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
  3997. ixgbe_vlan_promisc_disable(adapter);
  3998. else
  3999. ixgbe_vlan_promisc_enable(adapter);
  4000. }
  4001. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  4002. {
  4003. int q_idx;
  4004. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4005. napi_enable(&adapter->q_vector[q_idx]->napi);
  4006. }
  4007. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  4008. {
  4009. int q_idx;
  4010. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4011. napi_disable(&adapter->q_vector[q_idx]->napi);
  4012. }
  4013. static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
  4014. {
  4015. struct ixgbe_hw *hw = &adapter->hw;
  4016. u32 vxlanctrl;
  4017. if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
  4018. IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
  4019. return;
  4020. vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) && ~mask;
  4021. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
  4022. if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
  4023. adapter->vxlan_port = 0;
  4024. if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
  4025. adapter->geneve_port = 0;
  4026. }
  4027. #ifdef CONFIG_IXGBE_DCB
  4028. /**
  4029. * ixgbe_configure_dcb - Configure DCB hardware
  4030. * @adapter: ixgbe adapter struct
  4031. *
  4032. * This is called by the driver on open to configure the DCB hardware.
  4033. * This is also called by the gennetlink interface when reconfiguring
  4034. * the DCB state.
  4035. */
  4036. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  4037. {
  4038. struct ixgbe_hw *hw = &adapter->hw;
  4039. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4040. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  4041. if (hw->mac.type == ixgbe_mac_82598EB)
  4042. netif_set_gso_max_size(adapter->netdev, 65536);
  4043. return;
  4044. }
  4045. if (hw->mac.type == ixgbe_mac_82598EB)
  4046. netif_set_gso_max_size(adapter->netdev, 32768);
  4047. #ifdef IXGBE_FCOE
  4048. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  4049. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  4050. #endif
  4051. /* reconfigure the hardware */
  4052. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
  4053. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4054. DCB_TX_CONFIG);
  4055. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4056. DCB_RX_CONFIG);
  4057. ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
  4058. } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
  4059. ixgbe_dcb_hw_ets(&adapter->hw,
  4060. adapter->ixgbe_ieee_ets,
  4061. max_frame);
  4062. ixgbe_dcb_hw_pfc_config(&adapter->hw,
  4063. adapter->ixgbe_ieee_pfc->pfc_en,
  4064. adapter->ixgbe_ieee_ets->prio_tc);
  4065. }
  4066. /* Enable RSS Hash per TC */
  4067. if (hw->mac.type != ixgbe_mac_82598EB) {
  4068. u32 msb = 0;
  4069. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
  4070. while (rss_i) {
  4071. msb++;
  4072. rss_i >>= 1;
  4073. }
  4074. /* write msb to all 8 TCs in one write */
  4075. IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
  4076. }
  4077. }
  4078. #endif
  4079. /* Additional bittime to account for IXGBE framing */
  4080. #define IXGBE_ETH_FRAMING 20
  4081. /**
  4082. * ixgbe_hpbthresh - calculate high water mark for flow control
  4083. *
  4084. * @adapter: board private structure to calculate for
  4085. * @pb: packet buffer to calculate
  4086. */
  4087. static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
  4088. {
  4089. struct ixgbe_hw *hw = &adapter->hw;
  4090. struct net_device *dev = adapter->netdev;
  4091. int link, tc, kb, marker;
  4092. u32 dv_id, rx_pba;
  4093. /* Calculate max LAN frame size */
  4094. tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
  4095. #ifdef IXGBE_FCOE
  4096. /* FCoE traffic class uses FCOE jumbo frames */
  4097. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4098. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4099. (pb == ixgbe_fcoe_get_tc(adapter)))
  4100. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4101. #endif
  4102. /* Calculate delay value for device */
  4103. switch (hw->mac.type) {
  4104. case ixgbe_mac_X540:
  4105. case ixgbe_mac_X550:
  4106. case ixgbe_mac_X550EM_x:
  4107. case ixgbe_mac_x550em_a:
  4108. dv_id = IXGBE_DV_X540(link, tc);
  4109. break;
  4110. default:
  4111. dv_id = IXGBE_DV(link, tc);
  4112. break;
  4113. }
  4114. /* Loopback switch introduces additional latency */
  4115. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4116. dv_id += IXGBE_B2BT(tc);
  4117. /* Delay value is calculated in bit times convert to KB */
  4118. kb = IXGBE_BT2KB(dv_id);
  4119. rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
  4120. marker = rx_pba - kb;
  4121. /* It is possible that the packet buffer is not large enough
  4122. * to provide required headroom. In this case throw an error
  4123. * to user and a do the best we can.
  4124. */
  4125. if (marker < 0) {
  4126. e_warn(drv, "Packet Buffer(%i) can not provide enough"
  4127. "headroom to support flow control."
  4128. "Decrease MTU or number of traffic classes\n", pb);
  4129. marker = tc + 1;
  4130. }
  4131. return marker;
  4132. }
  4133. /**
  4134. * ixgbe_lpbthresh - calculate low water mark for for flow control
  4135. *
  4136. * @adapter: board private structure to calculate for
  4137. * @pb: packet buffer to calculate
  4138. */
  4139. static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
  4140. {
  4141. struct ixgbe_hw *hw = &adapter->hw;
  4142. struct net_device *dev = adapter->netdev;
  4143. int tc;
  4144. u32 dv_id;
  4145. /* Calculate max LAN frame size */
  4146. tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4147. #ifdef IXGBE_FCOE
  4148. /* FCoE traffic class uses FCOE jumbo frames */
  4149. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4150. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4151. (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
  4152. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4153. #endif
  4154. /* Calculate delay value for device */
  4155. switch (hw->mac.type) {
  4156. case ixgbe_mac_X540:
  4157. case ixgbe_mac_X550:
  4158. case ixgbe_mac_X550EM_x:
  4159. case ixgbe_mac_x550em_a:
  4160. dv_id = IXGBE_LOW_DV_X540(tc);
  4161. break;
  4162. default:
  4163. dv_id = IXGBE_LOW_DV(tc);
  4164. break;
  4165. }
  4166. /* Delay value is calculated in bit times convert to KB */
  4167. return IXGBE_BT2KB(dv_id);
  4168. }
  4169. /*
  4170. * ixgbe_pbthresh_setup - calculate and setup high low water marks
  4171. */
  4172. static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
  4173. {
  4174. struct ixgbe_hw *hw = &adapter->hw;
  4175. int num_tc = netdev_get_num_tc(adapter->netdev);
  4176. int i;
  4177. if (!num_tc)
  4178. num_tc = 1;
  4179. for (i = 0; i < num_tc; i++) {
  4180. hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
  4181. hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
  4182. /* Low water marks must not be larger than high water marks */
  4183. if (hw->fc.low_water[i] > hw->fc.high_water[i])
  4184. hw->fc.low_water[i] = 0;
  4185. }
  4186. for (; i < MAX_TRAFFIC_CLASS; i++)
  4187. hw->fc.high_water[i] = 0;
  4188. }
  4189. static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
  4190. {
  4191. struct ixgbe_hw *hw = &adapter->hw;
  4192. int hdrm;
  4193. u8 tc = netdev_get_num_tc(adapter->netdev);
  4194. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  4195. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  4196. hdrm = 32 << adapter->fdir_pballoc;
  4197. else
  4198. hdrm = 0;
  4199. hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
  4200. ixgbe_pbthresh_setup(adapter);
  4201. }
  4202. static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
  4203. {
  4204. struct ixgbe_hw *hw = &adapter->hw;
  4205. struct hlist_node *node2;
  4206. struct ixgbe_fdir_filter *filter;
  4207. spin_lock(&adapter->fdir_perfect_lock);
  4208. if (!hlist_empty(&adapter->fdir_filter_list))
  4209. ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
  4210. hlist_for_each_entry_safe(filter, node2,
  4211. &adapter->fdir_filter_list, fdir_node) {
  4212. ixgbe_fdir_write_perfect_filter_82599(hw,
  4213. &filter->filter,
  4214. filter->sw_idx,
  4215. (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
  4216. IXGBE_FDIR_DROP_QUEUE :
  4217. adapter->rx_ring[filter->action]->reg_idx);
  4218. }
  4219. spin_unlock(&adapter->fdir_perfect_lock);
  4220. }
  4221. static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool,
  4222. struct ixgbe_adapter *adapter)
  4223. {
  4224. struct ixgbe_hw *hw = &adapter->hw;
  4225. u32 vmolr;
  4226. /* No unicast promiscuous support for VMDQ devices. */
  4227. vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool));
  4228. vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
  4229. /* clear the affected bit */
  4230. vmolr &= ~IXGBE_VMOLR_MPE;
  4231. if (dev->flags & IFF_ALLMULTI) {
  4232. vmolr |= IXGBE_VMOLR_MPE;
  4233. } else {
  4234. vmolr |= IXGBE_VMOLR_ROMPE;
  4235. hw->mac.ops.update_mc_addr_list(hw, dev);
  4236. }
  4237. ixgbe_write_uc_addr_list(adapter->netdev, pool);
  4238. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr);
  4239. }
  4240. static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter)
  4241. {
  4242. struct ixgbe_adapter *adapter = vadapter->real_adapter;
  4243. int rss_i = adapter->num_rx_queues_per_pool;
  4244. struct ixgbe_hw *hw = &adapter->hw;
  4245. u16 pool = vadapter->pool;
  4246. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  4247. IXGBE_PSRTYPE_UDPHDR |
  4248. IXGBE_PSRTYPE_IPV4HDR |
  4249. IXGBE_PSRTYPE_L2HDR |
  4250. IXGBE_PSRTYPE_IPV6HDR;
  4251. if (hw->mac.type == ixgbe_mac_82598EB)
  4252. return;
  4253. if (rss_i > 3)
  4254. psrtype |= 2u << 29;
  4255. else if (rss_i > 1)
  4256. psrtype |= 1u << 29;
  4257. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  4258. }
  4259. /**
  4260. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  4261. * @rx_ring: ring to free buffers from
  4262. **/
  4263. static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
  4264. {
  4265. u16 i = rx_ring->next_to_clean;
  4266. struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
  4267. /* Free all the Rx ring sk_buffs */
  4268. while (i != rx_ring->next_to_alloc) {
  4269. if (rx_buffer->skb) {
  4270. struct sk_buff *skb = rx_buffer->skb;
  4271. if (IXGBE_CB(skb)->page_released)
  4272. dma_unmap_page_attrs(rx_ring->dev,
  4273. IXGBE_CB(skb)->dma,
  4274. ixgbe_rx_pg_size(rx_ring),
  4275. DMA_FROM_DEVICE,
  4276. IXGBE_RX_DMA_ATTR);
  4277. dev_kfree_skb(skb);
  4278. }
  4279. /* Invalidate cache lines that may have been written to by
  4280. * device so that we avoid corrupting memory.
  4281. */
  4282. dma_sync_single_range_for_cpu(rx_ring->dev,
  4283. rx_buffer->dma,
  4284. rx_buffer->page_offset,
  4285. ixgbe_rx_bufsz(rx_ring),
  4286. DMA_FROM_DEVICE);
  4287. /* free resources associated with mapping */
  4288. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  4289. ixgbe_rx_pg_size(rx_ring),
  4290. DMA_FROM_DEVICE,
  4291. IXGBE_RX_DMA_ATTR);
  4292. __page_frag_cache_drain(rx_buffer->page,
  4293. rx_buffer->pagecnt_bias);
  4294. i++;
  4295. rx_buffer++;
  4296. if (i == rx_ring->count) {
  4297. i = 0;
  4298. rx_buffer = rx_ring->rx_buffer_info;
  4299. }
  4300. }
  4301. rx_ring->next_to_alloc = 0;
  4302. rx_ring->next_to_clean = 0;
  4303. rx_ring->next_to_use = 0;
  4304. }
  4305. static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter,
  4306. struct ixgbe_ring *rx_ring)
  4307. {
  4308. struct ixgbe_adapter *adapter = vadapter->real_adapter;
  4309. int index = rx_ring->queue_index + vadapter->rx_base_queue;
  4310. /* shutdown specific queue receive and wait for dma to settle */
  4311. ixgbe_disable_rx_queue(adapter, rx_ring);
  4312. usleep_range(10000, 20000);
  4313. ixgbe_irq_disable_queues(adapter, BIT_ULL(index));
  4314. ixgbe_clean_rx_ring(rx_ring);
  4315. rx_ring->l2_accel_priv = NULL;
  4316. }
  4317. static int ixgbe_fwd_ring_down(struct net_device *vdev,
  4318. struct ixgbe_fwd_adapter *accel)
  4319. {
  4320. struct ixgbe_adapter *adapter = accel->real_adapter;
  4321. unsigned int rxbase = accel->rx_base_queue;
  4322. unsigned int txbase = accel->tx_base_queue;
  4323. int i;
  4324. netif_tx_stop_all_queues(vdev);
  4325. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4326. ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
  4327. adapter->rx_ring[rxbase + i]->netdev = adapter->netdev;
  4328. }
  4329. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4330. adapter->tx_ring[txbase + i]->l2_accel_priv = NULL;
  4331. adapter->tx_ring[txbase + i]->netdev = adapter->netdev;
  4332. }
  4333. return 0;
  4334. }
  4335. static int ixgbe_fwd_ring_up(struct net_device *vdev,
  4336. struct ixgbe_fwd_adapter *accel)
  4337. {
  4338. struct ixgbe_adapter *adapter = accel->real_adapter;
  4339. unsigned int rxbase, txbase, queues;
  4340. int i, baseq, err = 0;
  4341. if (!test_bit(accel->pool, &adapter->fwd_bitmask))
  4342. return 0;
  4343. baseq = accel->pool * adapter->num_rx_queues_per_pool;
  4344. netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
  4345. accel->pool, adapter->num_rx_pools,
  4346. baseq, baseq + adapter->num_rx_queues_per_pool,
  4347. adapter->fwd_bitmask);
  4348. accel->netdev = vdev;
  4349. accel->rx_base_queue = rxbase = baseq;
  4350. accel->tx_base_queue = txbase = baseq;
  4351. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4352. ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]);
  4353. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4354. adapter->rx_ring[rxbase + i]->netdev = vdev;
  4355. adapter->rx_ring[rxbase + i]->l2_accel_priv = accel;
  4356. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]);
  4357. }
  4358. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  4359. adapter->tx_ring[txbase + i]->netdev = vdev;
  4360. adapter->tx_ring[txbase + i]->l2_accel_priv = accel;
  4361. }
  4362. queues = min_t(unsigned int,
  4363. adapter->num_rx_queues_per_pool, vdev->num_tx_queues);
  4364. err = netif_set_real_num_tx_queues(vdev, queues);
  4365. if (err)
  4366. goto fwd_queue_err;
  4367. err = netif_set_real_num_rx_queues(vdev, queues);
  4368. if (err)
  4369. goto fwd_queue_err;
  4370. if (is_valid_ether_addr(vdev->dev_addr))
  4371. ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool);
  4372. ixgbe_fwd_psrtype(accel);
  4373. ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter);
  4374. return err;
  4375. fwd_queue_err:
  4376. ixgbe_fwd_ring_down(vdev, accel);
  4377. return err;
  4378. }
  4379. static int ixgbe_upper_dev_walk(struct net_device *upper, void *data)
  4380. {
  4381. if (netif_is_macvlan(upper)) {
  4382. struct macvlan_dev *dfwd = netdev_priv(upper);
  4383. struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
  4384. if (dfwd->fwd_priv)
  4385. ixgbe_fwd_ring_up(upper, vadapter);
  4386. }
  4387. return 0;
  4388. }
  4389. static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
  4390. {
  4391. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  4392. ixgbe_upper_dev_walk, NULL);
  4393. }
  4394. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  4395. {
  4396. struct ixgbe_hw *hw = &adapter->hw;
  4397. ixgbe_configure_pb(adapter);
  4398. #ifdef CONFIG_IXGBE_DCB
  4399. ixgbe_configure_dcb(adapter);
  4400. #endif
  4401. /*
  4402. * We must restore virtualization before VLANs or else
  4403. * the VLVF registers will not be populated
  4404. */
  4405. ixgbe_configure_virtualization(adapter);
  4406. ixgbe_set_rx_mode(adapter->netdev);
  4407. ixgbe_restore_vlan(adapter);
  4408. switch (hw->mac.type) {
  4409. case ixgbe_mac_82599EB:
  4410. case ixgbe_mac_X540:
  4411. hw->mac.ops.disable_rx_buff(hw);
  4412. break;
  4413. default:
  4414. break;
  4415. }
  4416. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  4417. ixgbe_init_fdir_signature_82599(&adapter->hw,
  4418. adapter->fdir_pballoc);
  4419. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  4420. ixgbe_init_fdir_perfect_82599(&adapter->hw,
  4421. adapter->fdir_pballoc);
  4422. ixgbe_fdir_filter_restore(adapter);
  4423. }
  4424. switch (hw->mac.type) {
  4425. case ixgbe_mac_82599EB:
  4426. case ixgbe_mac_X540:
  4427. hw->mac.ops.enable_rx_buff(hw);
  4428. break;
  4429. default:
  4430. break;
  4431. }
  4432. #ifdef CONFIG_IXGBE_DCA
  4433. /* configure DCA */
  4434. if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
  4435. ixgbe_setup_dca(adapter);
  4436. #endif /* CONFIG_IXGBE_DCA */
  4437. #ifdef IXGBE_FCOE
  4438. /* configure FCoE L2 filters, redirection table, and Rx control */
  4439. ixgbe_configure_fcoe(adapter);
  4440. #endif /* IXGBE_FCOE */
  4441. ixgbe_configure_tx(adapter);
  4442. ixgbe_configure_rx(adapter);
  4443. ixgbe_configure_dfwd(adapter);
  4444. }
  4445. /**
  4446. * ixgbe_sfp_link_config - set up SFP+ link
  4447. * @adapter: pointer to private adapter struct
  4448. **/
  4449. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  4450. {
  4451. /*
  4452. * We are assuming the worst case scenario here, and that
  4453. * is that an SFP was inserted/removed after the reset
  4454. * but before SFP detection was enabled. As such the best
  4455. * solution is to just start searching as soon as we start
  4456. */
  4457. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  4458. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  4459. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  4460. adapter->sfp_poll_time = 0;
  4461. }
  4462. /**
  4463. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  4464. * @hw: pointer to private hardware struct
  4465. *
  4466. * Returns 0 on success, negative on failure
  4467. **/
  4468. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  4469. {
  4470. u32 speed;
  4471. bool autoneg, link_up = false;
  4472. int ret = IXGBE_ERR_LINK_SETUP;
  4473. if (hw->mac.ops.check_link)
  4474. ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
  4475. if (ret)
  4476. return ret;
  4477. speed = hw->phy.autoneg_advertised;
  4478. if ((!speed) && (hw->mac.ops.get_link_capabilities))
  4479. ret = hw->mac.ops.get_link_capabilities(hw, &speed,
  4480. &autoneg);
  4481. if (ret)
  4482. return ret;
  4483. if (hw->mac.ops.setup_link)
  4484. ret = hw->mac.ops.setup_link(hw, speed, link_up);
  4485. return ret;
  4486. }
  4487. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  4488. {
  4489. struct ixgbe_hw *hw = &adapter->hw;
  4490. u32 gpie = 0;
  4491. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4492. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  4493. IXGBE_GPIE_OCD;
  4494. gpie |= IXGBE_GPIE_EIAME;
  4495. /*
  4496. * use EIAM to auto-mask when MSI-X interrupt is asserted
  4497. * this saves a register write for every interrupt
  4498. */
  4499. switch (hw->mac.type) {
  4500. case ixgbe_mac_82598EB:
  4501. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4502. break;
  4503. case ixgbe_mac_82599EB:
  4504. case ixgbe_mac_X540:
  4505. case ixgbe_mac_X550:
  4506. case ixgbe_mac_X550EM_x:
  4507. case ixgbe_mac_x550em_a:
  4508. default:
  4509. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  4510. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  4511. break;
  4512. }
  4513. } else {
  4514. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  4515. * specifically only auto mask tx and rx interrupts */
  4516. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4517. }
  4518. /* XXX: to interrupt immediately for EICS writes, enable this */
  4519. /* gpie |= IXGBE_GPIE_EIMEN; */
  4520. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  4521. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  4522. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  4523. case IXGBE_82599_VMDQ_8Q_MASK:
  4524. gpie |= IXGBE_GPIE_VTMODE_16;
  4525. break;
  4526. case IXGBE_82599_VMDQ_4Q_MASK:
  4527. gpie |= IXGBE_GPIE_VTMODE_32;
  4528. break;
  4529. default:
  4530. gpie |= IXGBE_GPIE_VTMODE_64;
  4531. break;
  4532. }
  4533. }
  4534. /* Enable Thermal over heat sensor interrupt */
  4535. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  4536. switch (adapter->hw.mac.type) {
  4537. case ixgbe_mac_82599EB:
  4538. gpie |= IXGBE_SDP0_GPIEN_8259X;
  4539. break;
  4540. default:
  4541. break;
  4542. }
  4543. }
  4544. /* Enable fan failure interrupt */
  4545. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  4546. gpie |= IXGBE_SDP1_GPIEN(hw);
  4547. switch (hw->mac.type) {
  4548. case ixgbe_mac_82599EB:
  4549. gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
  4550. break;
  4551. case ixgbe_mac_X550EM_x:
  4552. case ixgbe_mac_x550em_a:
  4553. gpie |= IXGBE_SDP0_GPIEN_X540;
  4554. break;
  4555. default:
  4556. break;
  4557. }
  4558. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  4559. }
  4560. static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
  4561. {
  4562. struct ixgbe_hw *hw = &adapter->hw;
  4563. int err;
  4564. u32 ctrl_ext;
  4565. ixgbe_get_hw_control(adapter);
  4566. ixgbe_setup_gpie(adapter);
  4567. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4568. ixgbe_configure_msix(adapter);
  4569. else
  4570. ixgbe_configure_msi_and_legacy(adapter);
  4571. /* enable the optics for 82599 SFP+ fiber */
  4572. if (hw->mac.ops.enable_tx_laser)
  4573. hw->mac.ops.enable_tx_laser(hw);
  4574. if (hw->phy.ops.set_phy_power)
  4575. hw->phy.ops.set_phy_power(hw, true);
  4576. smp_mb__before_atomic();
  4577. clear_bit(__IXGBE_DOWN, &adapter->state);
  4578. ixgbe_napi_enable_all(adapter);
  4579. if (ixgbe_is_sfp(hw)) {
  4580. ixgbe_sfp_link_config(adapter);
  4581. } else {
  4582. err = ixgbe_non_sfp_link_config(hw);
  4583. if (err)
  4584. e_err(probe, "link_config FAILED %d\n", err);
  4585. }
  4586. /* clear any pending interrupts, may auto mask */
  4587. IXGBE_READ_REG(hw, IXGBE_EICR);
  4588. ixgbe_irq_enable(adapter, true, true);
  4589. /*
  4590. * If this adapter has a fan, check to see if we had a failure
  4591. * before we enabled the interrupt.
  4592. */
  4593. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  4594. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  4595. if (esdp & IXGBE_ESDP_SDP1)
  4596. e_crit(drv, "Fan has stopped, replace the adapter\n");
  4597. }
  4598. /* bring the link up in the watchdog, this could race with our first
  4599. * link up interrupt but shouldn't be a problem */
  4600. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4601. adapter->link_check_timeout = jiffies;
  4602. mod_timer(&adapter->service_timer, jiffies);
  4603. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  4604. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  4605. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  4606. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  4607. }
  4608. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  4609. {
  4610. WARN_ON(in_interrupt());
  4611. /* put off any impending NetWatchDogTimeout */
  4612. netif_trans_update(adapter->netdev);
  4613. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  4614. usleep_range(1000, 2000);
  4615. if (adapter->hw.phy.type == ixgbe_phy_fw)
  4616. ixgbe_watchdog_link_is_down(adapter);
  4617. ixgbe_down(adapter);
  4618. /*
  4619. * If SR-IOV enabled then wait a bit before bringing the adapter
  4620. * back up to give the VFs time to respond to the reset. The
  4621. * two second wait is based upon the watchdog timer cycle in
  4622. * the VF driver.
  4623. */
  4624. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4625. msleep(2000);
  4626. ixgbe_up(adapter);
  4627. clear_bit(__IXGBE_RESETTING, &adapter->state);
  4628. }
  4629. void ixgbe_up(struct ixgbe_adapter *adapter)
  4630. {
  4631. /* hardware has been reset, we need to reload some things */
  4632. ixgbe_configure(adapter);
  4633. ixgbe_up_complete(adapter);
  4634. }
  4635. void ixgbe_reset(struct ixgbe_adapter *adapter)
  4636. {
  4637. struct ixgbe_hw *hw = &adapter->hw;
  4638. struct net_device *netdev = adapter->netdev;
  4639. int err;
  4640. if (ixgbe_removed(hw->hw_addr))
  4641. return;
  4642. /* lock SFP init bit to prevent race conditions with the watchdog */
  4643. while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  4644. usleep_range(1000, 2000);
  4645. /* clear all SFP and link config related flags while holding SFP_INIT */
  4646. adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
  4647. IXGBE_FLAG2_SFP_NEEDS_RESET);
  4648. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  4649. err = hw->mac.ops.init_hw(hw);
  4650. switch (err) {
  4651. case 0:
  4652. case IXGBE_ERR_SFP_NOT_PRESENT:
  4653. case IXGBE_ERR_SFP_NOT_SUPPORTED:
  4654. break;
  4655. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  4656. e_dev_err("master disable timed out\n");
  4657. break;
  4658. case IXGBE_ERR_EEPROM_VERSION:
  4659. /* We are running on a pre-production device, log a warning */
  4660. e_dev_warn("This device is a pre-production adapter/LOM. "
  4661. "Please be aware there may be issues associated with "
  4662. "your hardware. If you are experiencing problems "
  4663. "please contact your Intel or hardware "
  4664. "representative who provided you with this "
  4665. "hardware.\n");
  4666. break;
  4667. default:
  4668. e_dev_err("Hardware Error: %d\n", err);
  4669. }
  4670. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  4671. /* flush entries out of MAC table */
  4672. ixgbe_flush_sw_mac_table(adapter);
  4673. __dev_uc_unsync(netdev, NULL);
  4674. /* do not flush user set addresses */
  4675. ixgbe_mac_set_default_filter(adapter);
  4676. /* update SAN MAC vmdq pool selection */
  4677. if (hw->mac.san_mac_rar_index)
  4678. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  4679. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  4680. ixgbe_ptp_reset(adapter);
  4681. if (hw->phy.ops.set_phy_power) {
  4682. if (!netif_running(adapter->netdev) && !adapter->wol)
  4683. hw->phy.ops.set_phy_power(hw, false);
  4684. else
  4685. hw->phy.ops.set_phy_power(hw, true);
  4686. }
  4687. }
  4688. /**
  4689. * ixgbe_clean_tx_ring - Free Tx Buffers
  4690. * @tx_ring: ring to be cleaned
  4691. **/
  4692. static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
  4693. {
  4694. u16 i = tx_ring->next_to_clean;
  4695. struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
  4696. while (i != tx_ring->next_to_use) {
  4697. union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
  4698. /* Free all the Tx ring sk_buffs */
  4699. dev_kfree_skb_any(tx_buffer->skb);
  4700. /* unmap skb header data */
  4701. dma_unmap_single(tx_ring->dev,
  4702. dma_unmap_addr(tx_buffer, dma),
  4703. dma_unmap_len(tx_buffer, len),
  4704. DMA_TO_DEVICE);
  4705. /* check for eop_desc to determine the end of the packet */
  4706. eop_desc = tx_buffer->next_to_watch;
  4707. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  4708. /* unmap remaining buffers */
  4709. while (tx_desc != eop_desc) {
  4710. tx_buffer++;
  4711. tx_desc++;
  4712. i++;
  4713. if (unlikely(i == tx_ring->count)) {
  4714. i = 0;
  4715. tx_buffer = tx_ring->tx_buffer_info;
  4716. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  4717. }
  4718. /* unmap any remaining paged data */
  4719. if (dma_unmap_len(tx_buffer, len))
  4720. dma_unmap_page(tx_ring->dev,
  4721. dma_unmap_addr(tx_buffer, dma),
  4722. dma_unmap_len(tx_buffer, len),
  4723. DMA_TO_DEVICE);
  4724. }
  4725. /* move us one more past the eop_desc for start of next pkt */
  4726. tx_buffer++;
  4727. i++;
  4728. if (unlikely(i == tx_ring->count)) {
  4729. i = 0;
  4730. tx_buffer = tx_ring->tx_buffer_info;
  4731. }
  4732. }
  4733. /* reset BQL for queue */
  4734. netdev_tx_reset_queue(txring_txq(tx_ring));
  4735. /* reset next_to_use and next_to_clean */
  4736. tx_ring->next_to_use = 0;
  4737. tx_ring->next_to_clean = 0;
  4738. }
  4739. /**
  4740. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  4741. * @adapter: board private structure
  4742. **/
  4743. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  4744. {
  4745. int i;
  4746. for (i = 0; i < adapter->num_rx_queues; i++)
  4747. ixgbe_clean_rx_ring(adapter->rx_ring[i]);
  4748. }
  4749. /**
  4750. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  4751. * @adapter: board private structure
  4752. **/
  4753. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  4754. {
  4755. int i;
  4756. for (i = 0; i < adapter->num_tx_queues; i++)
  4757. ixgbe_clean_tx_ring(adapter->tx_ring[i]);
  4758. }
  4759. static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
  4760. {
  4761. struct hlist_node *node2;
  4762. struct ixgbe_fdir_filter *filter;
  4763. spin_lock(&adapter->fdir_perfect_lock);
  4764. hlist_for_each_entry_safe(filter, node2,
  4765. &adapter->fdir_filter_list, fdir_node) {
  4766. hlist_del(&filter->fdir_node);
  4767. kfree(filter);
  4768. }
  4769. adapter->fdir_filter_count = 0;
  4770. spin_unlock(&adapter->fdir_perfect_lock);
  4771. }
  4772. static int ixgbe_disable_macvlan(struct net_device *upper, void *data)
  4773. {
  4774. if (netif_is_macvlan(upper)) {
  4775. struct macvlan_dev *vlan = netdev_priv(upper);
  4776. if (vlan->fwd_priv) {
  4777. netif_tx_stop_all_queues(upper);
  4778. netif_carrier_off(upper);
  4779. netif_tx_disable(upper);
  4780. }
  4781. }
  4782. return 0;
  4783. }
  4784. void ixgbe_down(struct ixgbe_adapter *adapter)
  4785. {
  4786. struct net_device *netdev = adapter->netdev;
  4787. struct ixgbe_hw *hw = &adapter->hw;
  4788. int i;
  4789. /* signal that we are down to the interrupt handler */
  4790. if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
  4791. return; /* do nothing if already down */
  4792. /* disable receives */
  4793. hw->mac.ops.disable_rx(hw);
  4794. /* disable all enabled rx queues */
  4795. for (i = 0; i < adapter->num_rx_queues; i++)
  4796. /* this call also flushes the previous write */
  4797. ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
  4798. usleep_range(10000, 20000);
  4799. netif_tx_stop_all_queues(netdev);
  4800. /* call carrier off first to avoid false dev_watchdog timeouts */
  4801. netif_carrier_off(netdev);
  4802. netif_tx_disable(netdev);
  4803. /* disable any upper devices */
  4804. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  4805. ixgbe_disable_macvlan, NULL);
  4806. ixgbe_irq_disable(adapter);
  4807. ixgbe_napi_disable_all(adapter);
  4808. clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  4809. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  4810. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4811. del_timer_sync(&adapter->service_timer);
  4812. if (adapter->num_vfs) {
  4813. /* Clear EITR Select mapping */
  4814. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  4815. /* Mark all the VFs as inactive */
  4816. for (i = 0 ; i < adapter->num_vfs; i++)
  4817. adapter->vfinfo[i].clear_to_send = false;
  4818. /* ping all the active vfs to let them know we are going down */
  4819. ixgbe_ping_all_vfs(adapter);
  4820. /* Disable all VFTE/VFRE TX/RX */
  4821. ixgbe_disable_tx_rx(adapter);
  4822. }
  4823. /* disable transmits in the hardware now that interrupts are off */
  4824. for (i = 0; i < adapter->num_tx_queues; i++) {
  4825. u8 reg_idx = adapter->tx_ring[i]->reg_idx;
  4826. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  4827. }
  4828. /* Disable the Tx DMA engine on 82599 and later MAC */
  4829. switch (hw->mac.type) {
  4830. case ixgbe_mac_82599EB:
  4831. case ixgbe_mac_X540:
  4832. case ixgbe_mac_X550:
  4833. case ixgbe_mac_X550EM_x:
  4834. case ixgbe_mac_x550em_a:
  4835. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  4836. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  4837. ~IXGBE_DMATXCTL_TE));
  4838. break;
  4839. default:
  4840. break;
  4841. }
  4842. if (!pci_channel_offline(adapter->pdev))
  4843. ixgbe_reset(adapter);
  4844. /* power down the optics for 82599 SFP+ fiber */
  4845. if (hw->mac.ops.disable_tx_laser)
  4846. hw->mac.ops.disable_tx_laser(hw);
  4847. ixgbe_clean_all_tx_rings(adapter);
  4848. ixgbe_clean_all_rx_rings(adapter);
  4849. }
  4850. /**
  4851. * ixgbe_eee_capable - helper function to determine EEE support on X550
  4852. * @adapter: board private structure
  4853. */
  4854. static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
  4855. {
  4856. struct ixgbe_hw *hw = &adapter->hw;
  4857. switch (hw->device_id) {
  4858. case IXGBE_DEV_ID_X550EM_A_1G_T:
  4859. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  4860. if (!hw->phy.eee_speeds_supported)
  4861. break;
  4862. adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
  4863. if (!hw->phy.eee_speeds_advertised)
  4864. break;
  4865. adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
  4866. break;
  4867. default:
  4868. adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
  4869. adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
  4870. break;
  4871. }
  4872. }
  4873. /**
  4874. * ixgbe_tx_timeout - Respond to a Tx Hang
  4875. * @netdev: network interface device structure
  4876. **/
  4877. static void ixgbe_tx_timeout(struct net_device *netdev)
  4878. {
  4879. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4880. /* Do the reset outside of interrupt context */
  4881. ixgbe_tx_timeout_reset(adapter);
  4882. }
  4883. #ifdef CONFIG_IXGBE_DCB
  4884. static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
  4885. {
  4886. struct ixgbe_hw *hw = &adapter->hw;
  4887. struct tc_configuration *tc;
  4888. int j;
  4889. switch (hw->mac.type) {
  4890. case ixgbe_mac_82598EB:
  4891. case ixgbe_mac_82599EB:
  4892. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  4893. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  4894. break;
  4895. case ixgbe_mac_X540:
  4896. case ixgbe_mac_X550:
  4897. adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
  4898. adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
  4899. break;
  4900. case ixgbe_mac_X550EM_x:
  4901. case ixgbe_mac_x550em_a:
  4902. default:
  4903. adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
  4904. adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
  4905. break;
  4906. }
  4907. /* Configure DCB traffic classes */
  4908. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  4909. tc = &adapter->dcb_cfg.tc_config[j];
  4910. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  4911. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  4912. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  4913. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  4914. tc->dcb_pfc = pfc_disabled;
  4915. }
  4916. /* Initialize default user to priority mapping, UPx->TC0 */
  4917. tc = &adapter->dcb_cfg.tc_config[0];
  4918. tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
  4919. tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
  4920. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  4921. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  4922. adapter->dcb_cfg.pfc_mode_enable = false;
  4923. adapter->dcb_set_bitmap = 0x00;
  4924. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  4925. adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
  4926. memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  4927. sizeof(adapter->temp_dcb_cfg));
  4928. }
  4929. #endif
  4930. /**
  4931. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  4932. * @adapter: board private structure to initialize
  4933. *
  4934. * ixgbe_sw_init initializes the Adapter private data structure.
  4935. * Fields are initialized based on PCI device information and
  4936. * OS network device settings (MTU size).
  4937. **/
  4938. static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
  4939. const struct ixgbe_info *ii)
  4940. {
  4941. struct ixgbe_hw *hw = &adapter->hw;
  4942. struct pci_dev *pdev = adapter->pdev;
  4943. unsigned int rss, fdir;
  4944. u32 fwsm;
  4945. int i;
  4946. /* PCI config space info */
  4947. hw->vendor_id = pdev->vendor;
  4948. hw->device_id = pdev->device;
  4949. hw->revision_id = pdev->revision;
  4950. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  4951. hw->subsystem_device_id = pdev->subsystem_device;
  4952. /* get_invariants needs the device IDs */
  4953. ii->get_invariants(hw);
  4954. /* Set common capability flags and settings */
  4955. rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
  4956. adapter->ring_feature[RING_F_RSS].limit = rss;
  4957. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  4958. adapter->max_q_vectors = MAX_Q_VECTORS_82599;
  4959. adapter->atr_sample_rate = 20;
  4960. fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
  4961. adapter->ring_feature[RING_F_FDIR].limit = fdir;
  4962. adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
  4963. #ifdef CONFIG_IXGBE_DCA
  4964. adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
  4965. #endif
  4966. #ifdef CONFIG_IXGBE_DCB
  4967. adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
  4968. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  4969. #endif
  4970. #ifdef IXGBE_FCOE
  4971. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  4972. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  4973. #ifdef CONFIG_IXGBE_DCB
  4974. /* Default traffic class to use for FCoE */
  4975. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  4976. #endif /* CONFIG_IXGBE_DCB */
  4977. #endif /* IXGBE_FCOE */
  4978. /* initialize static ixgbe jump table entries */
  4979. adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
  4980. GFP_KERNEL);
  4981. if (!adapter->jump_tables[0])
  4982. return -ENOMEM;
  4983. adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
  4984. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
  4985. adapter->jump_tables[i] = NULL;
  4986. adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
  4987. hw->mac.num_rar_entries,
  4988. GFP_ATOMIC);
  4989. if (!adapter->mac_table)
  4990. return -ENOMEM;
  4991. /* Set MAC specific capability flags and exceptions */
  4992. switch (hw->mac.type) {
  4993. case ixgbe_mac_82598EB:
  4994. adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
  4995. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  4996. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  4997. adapter->max_q_vectors = MAX_Q_VECTORS_82598;
  4998. adapter->ring_feature[RING_F_FDIR].limit = 0;
  4999. adapter->atr_sample_rate = 0;
  5000. adapter->fdir_pballoc = 0;
  5001. #ifdef IXGBE_FCOE
  5002. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5003. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5004. #ifdef CONFIG_IXGBE_DCB
  5005. adapter->fcoe.up = 0;
  5006. #endif /* IXGBE_DCB */
  5007. #endif /* IXGBE_FCOE */
  5008. break;
  5009. case ixgbe_mac_82599EB:
  5010. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  5011. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5012. break;
  5013. case ixgbe_mac_X540:
  5014. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  5015. if (fwsm & IXGBE_FWSM_TS_ENABLED)
  5016. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5017. break;
  5018. case ixgbe_mac_x550em_a:
  5019. adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
  5020. switch (hw->device_id) {
  5021. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5022. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5023. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5024. break;
  5025. default:
  5026. break;
  5027. }
  5028. /* fall through */
  5029. case ixgbe_mac_X550EM_x:
  5030. #ifdef CONFIG_IXGBE_DCB
  5031. adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
  5032. #endif
  5033. #ifdef IXGBE_FCOE
  5034. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5035. #ifdef CONFIG_IXGBE_DCB
  5036. adapter->fcoe.up = 0;
  5037. #endif /* IXGBE_DCB */
  5038. #endif /* IXGBE_FCOE */
  5039. /* Fall Through */
  5040. case ixgbe_mac_X550:
  5041. if (hw->mac.type == ixgbe_mac_X550)
  5042. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5043. #ifdef CONFIG_IXGBE_DCA
  5044. adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
  5045. #endif
  5046. adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
  5047. break;
  5048. default:
  5049. break;
  5050. }
  5051. #ifdef IXGBE_FCOE
  5052. /* FCoE support exists, always init the FCoE lock */
  5053. spin_lock_init(&adapter->fcoe.lock);
  5054. #endif
  5055. /* n-tuple support exists, always init our spinlock */
  5056. spin_lock_init(&adapter->fdir_perfect_lock);
  5057. #ifdef CONFIG_IXGBE_DCB
  5058. ixgbe_init_dcb(adapter);
  5059. #endif
  5060. /* default flow control settings */
  5061. hw->fc.requested_mode = ixgbe_fc_full;
  5062. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  5063. ixgbe_pbthresh_setup(adapter);
  5064. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  5065. hw->fc.send_xon = true;
  5066. hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
  5067. #ifdef CONFIG_PCI_IOV
  5068. if (max_vfs > 0)
  5069. e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
  5070. /* assign number of SR-IOV VFs */
  5071. if (hw->mac.type != ixgbe_mac_82598EB) {
  5072. if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
  5073. adapter->num_vfs = 0;
  5074. e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
  5075. } else {
  5076. adapter->num_vfs = max_vfs;
  5077. }
  5078. }
  5079. #endif /* CONFIG_PCI_IOV */
  5080. /* enable itr by default in dynamic mode */
  5081. adapter->rx_itr_setting = 1;
  5082. adapter->tx_itr_setting = 1;
  5083. /* set default ring sizes */
  5084. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  5085. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  5086. /* set default work limits */
  5087. adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
  5088. /* initialize eeprom parameters */
  5089. if (ixgbe_init_eeprom_params_generic(hw)) {
  5090. e_dev_err("EEPROM initialization failed\n");
  5091. return -EIO;
  5092. }
  5093. /* PF holds first pool slot */
  5094. set_bit(0, &adapter->fwd_bitmask);
  5095. set_bit(__IXGBE_DOWN, &adapter->state);
  5096. return 0;
  5097. }
  5098. /**
  5099. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  5100. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  5101. *
  5102. * Return 0 on success, negative on failure
  5103. **/
  5104. int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
  5105. {
  5106. struct device *dev = tx_ring->dev;
  5107. int orig_node = dev_to_node(dev);
  5108. int ring_node = -1;
  5109. int size;
  5110. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  5111. if (tx_ring->q_vector)
  5112. ring_node = tx_ring->q_vector->numa_node;
  5113. tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
  5114. if (!tx_ring->tx_buffer_info)
  5115. tx_ring->tx_buffer_info = vmalloc(size);
  5116. if (!tx_ring->tx_buffer_info)
  5117. goto err;
  5118. u64_stats_init(&tx_ring->syncp);
  5119. /* round up to nearest 4K */
  5120. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  5121. tx_ring->size = ALIGN(tx_ring->size, 4096);
  5122. set_dev_node(dev, ring_node);
  5123. tx_ring->desc = dma_alloc_coherent(dev,
  5124. tx_ring->size,
  5125. &tx_ring->dma,
  5126. GFP_KERNEL);
  5127. set_dev_node(dev, orig_node);
  5128. if (!tx_ring->desc)
  5129. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  5130. &tx_ring->dma, GFP_KERNEL);
  5131. if (!tx_ring->desc)
  5132. goto err;
  5133. tx_ring->next_to_use = 0;
  5134. tx_ring->next_to_clean = 0;
  5135. return 0;
  5136. err:
  5137. vfree(tx_ring->tx_buffer_info);
  5138. tx_ring->tx_buffer_info = NULL;
  5139. dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
  5140. return -ENOMEM;
  5141. }
  5142. /**
  5143. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  5144. * @adapter: board private structure
  5145. *
  5146. * If this function returns with an error, then it's possible one or
  5147. * more of the rings is populated (while the rest are not). It is the
  5148. * callers duty to clean those orphaned rings.
  5149. *
  5150. * Return 0 on success, negative on failure
  5151. **/
  5152. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  5153. {
  5154. int i, err = 0;
  5155. for (i = 0; i < adapter->num_tx_queues; i++) {
  5156. err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
  5157. if (!err)
  5158. continue;
  5159. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  5160. goto err_setup_tx;
  5161. }
  5162. return 0;
  5163. err_setup_tx:
  5164. /* rewind the index freeing the rings as we go */
  5165. while (i--)
  5166. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5167. return err;
  5168. }
  5169. /**
  5170. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  5171. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  5172. *
  5173. * Returns 0 on success, negative on failure
  5174. **/
  5175. int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
  5176. {
  5177. struct device *dev = rx_ring->dev;
  5178. int orig_node = dev_to_node(dev);
  5179. int ring_node = -1;
  5180. int size;
  5181. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  5182. if (rx_ring->q_vector)
  5183. ring_node = rx_ring->q_vector->numa_node;
  5184. rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
  5185. if (!rx_ring->rx_buffer_info)
  5186. rx_ring->rx_buffer_info = vmalloc(size);
  5187. if (!rx_ring->rx_buffer_info)
  5188. goto err;
  5189. u64_stats_init(&rx_ring->syncp);
  5190. /* Round up to nearest 4K */
  5191. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  5192. rx_ring->size = ALIGN(rx_ring->size, 4096);
  5193. set_dev_node(dev, ring_node);
  5194. rx_ring->desc = dma_alloc_coherent(dev,
  5195. rx_ring->size,
  5196. &rx_ring->dma,
  5197. GFP_KERNEL);
  5198. set_dev_node(dev, orig_node);
  5199. if (!rx_ring->desc)
  5200. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  5201. &rx_ring->dma, GFP_KERNEL);
  5202. if (!rx_ring->desc)
  5203. goto err;
  5204. rx_ring->next_to_clean = 0;
  5205. rx_ring->next_to_use = 0;
  5206. return 0;
  5207. err:
  5208. vfree(rx_ring->rx_buffer_info);
  5209. rx_ring->rx_buffer_info = NULL;
  5210. dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
  5211. return -ENOMEM;
  5212. }
  5213. /**
  5214. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  5215. * @adapter: board private structure
  5216. *
  5217. * If this function returns with an error, then it's possible one or
  5218. * more of the rings is populated (while the rest are not). It is the
  5219. * callers duty to clean those orphaned rings.
  5220. *
  5221. * Return 0 on success, negative on failure
  5222. **/
  5223. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  5224. {
  5225. int i, err = 0;
  5226. for (i = 0; i < adapter->num_rx_queues; i++) {
  5227. err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
  5228. if (!err)
  5229. continue;
  5230. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  5231. goto err_setup_rx;
  5232. }
  5233. #ifdef IXGBE_FCOE
  5234. err = ixgbe_setup_fcoe_ddp_resources(adapter);
  5235. if (!err)
  5236. #endif
  5237. return 0;
  5238. err_setup_rx:
  5239. /* rewind the index freeing the rings as we go */
  5240. while (i--)
  5241. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5242. return err;
  5243. }
  5244. /**
  5245. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  5246. * @tx_ring: Tx descriptor ring for a specific queue
  5247. *
  5248. * Free all transmit software resources
  5249. **/
  5250. void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
  5251. {
  5252. ixgbe_clean_tx_ring(tx_ring);
  5253. vfree(tx_ring->tx_buffer_info);
  5254. tx_ring->tx_buffer_info = NULL;
  5255. /* if not set, then don't free */
  5256. if (!tx_ring->desc)
  5257. return;
  5258. dma_free_coherent(tx_ring->dev, tx_ring->size,
  5259. tx_ring->desc, tx_ring->dma);
  5260. tx_ring->desc = NULL;
  5261. }
  5262. /**
  5263. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  5264. * @adapter: board private structure
  5265. *
  5266. * Free all transmit software resources
  5267. **/
  5268. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  5269. {
  5270. int i;
  5271. for (i = 0; i < adapter->num_tx_queues; i++)
  5272. if (adapter->tx_ring[i]->desc)
  5273. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5274. }
  5275. /**
  5276. * ixgbe_free_rx_resources - Free Rx Resources
  5277. * @rx_ring: ring to clean the resources from
  5278. *
  5279. * Free all receive software resources
  5280. **/
  5281. void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
  5282. {
  5283. ixgbe_clean_rx_ring(rx_ring);
  5284. vfree(rx_ring->rx_buffer_info);
  5285. rx_ring->rx_buffer_info = NULL;
  5286. /* if not set, then don't free */
  5287. if (!rx_ring->desc)
  5288. return;
  5289. dma_free_coherent(rx_ring->dev, rx_ring->size,
  5290. rx_ring->desc, rx_ring->dma);
  5291. rx_ring->desc = NULL;
  5292. }
  5293. /**
  5294. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  5295. * @adapter: board private structure
  5296. *
  5297. * Free all receive software resources
  5298. **/
  5299. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  5300. {
  5301. int i;
  5302. #ifdef IXGBE_FCOE
  5303. ixgbe_free_fcoe_ddp_resources(adapter);
  5304. #endif
  5305. for (i = 0; i < adapter->num_rx_queues; i++)
  5306. if (adapter->rx_ring[i]->desc)
  5307. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5308. }
  5309. /**
  5310. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  5311. * @netdev: network interface device structure
  5312. * @new_mtu: new value for maximum frame size
  5313. *
  5314. * Returns 0 on success, negative on failure
  5315. **/
  5316. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  5317. {
  5318. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5319. /*
  5320. * For 82599EB we cannot allow legacy VFs to enable their receive
  5321. * paths when MTU greater than 1500 is configured. So display a
  5322. * warning that legacy VFs will be disabled.
  5323. */
  5324. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
  5325. (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
  5326. (new_mtu > ETH_DATA_LEN))
  5327. e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
  5328. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  5329. /* must set new MTU before calling down or up */
  5330. netdev->mtu = new_mtu;
  5331. if (netif_running(netdev))
  5332. ixgbe_reinit_locked(adapter);
  5333. return 0;
  5334. }
  5335. /**
  5336. * ixgbe_open - Called when a network interface is made active
  5337. * @netdev: network interface device structure
  5338. *
  5339. * Returns 0 on success, negative value on failure
  5340. *
  5341. * The open entry point is called when a network interface is made
  5342. * active by the system (IFF_UP). At this point all resources needed
  5343. * for transmit and receive operations are allocated, the interrupt
  5344. * handler is registered with the OS, the watchdog timer is started,
  5345. * and the stack is notified that the interface is ready.
  5346. **/
  5347. int ixgbe_open(struct net_device *netdev)
  5348. {
  5349. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5350. struct ixgbe_hw *hw = &adapter->hw;
  5351. int err, queues;
  5352. /* disallow open during test */
  5353. if (test_bit(__IXGBE_TESTING, &adapter->state))
  5354. return -EBUSY;
  5355. netif_carrier_off(netdev);
  5356. /* allocate transmit descriptors */
  5357. err = ixgbe_setup_all_tx_resources(adapter);
  5358. if (err)
  5359. goto err_setup_tx;
  5360. /* allocate receive descriptors */
  5361. err = ixgbe_setup_all_rx_resources(adapter);
  5362. if (err)
  5363. goto err_setup_rx;
  5364. ixgbe_configure(adapter);
  5365. err = ixgbe_request_irq(adapter);
  5366. if (err)
  5367. goto err_req_irq;
  5368. /* Notify the stack of the actual queue counts. */
  5369. if (adapter->num_rx_pools > 1)
  5370. queues = adapter->num_rx_queues_per_pool;
  5371. else
  5372. queues = adapter->num_tx_queues;
  5373. err = netif_set_real_num_tx_queues(netdev, queues);
  5374. if (err)
  5375. goto err_set_queues;
  5376. if (adapter->num_rx_pools > 1 &&
  5377. adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES)
  5378. queues = IXGBE_MAX_L2A_QUEUES;
  5379. else
  5380. queues = adapter->num_rx_queues;
  5381. err = netif_set_real_num_rx_queues(netdev, queues);
  5382. if (err)
  5383. goto err_set_queues;
  5384. ixgbe_ptp_init(adapter);
  5385. ixgbe_up_complete(adapter);
  5386. ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
  5387. udp_tunnel_get_rx_info(netdev);
  5388. return 0;
  5389. err_set_queues:
  5390. ixgbe_free_irq(adapter);
  5391. err_req_irq:
  5392. ixgbe_free_all_rx_resources(adapter);
  5393. if (hw->phy.ops.set_phy_power && !adapter->wol)
  5394. hw->phy.ops.set_phy_power(&adapter->hw, false);
  5395. err_setup_rx:
  5396. ixgbe_free_all_tx_resources(adapter);
  5397. err_setup_tx:
  5398. ixgbe_reset(adapter);
  5399. return err;
  5400. }
  5401. static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
  5402. {
  5403. ixgbe_ptp_suspend(adapter);
  5404. if (adapter->hw.phy.ops.enter_lplu) {
  5405. adapter->hw.phy.reset_disable = true;
  5406. ixgbe_down(adapter);
  5407. adapter->hw.phy.ops.enter_lplu(&adapter->hw);
  5408. adapter->hw.phy.reset_disable = false;
  5409. } else {
  5410. ixgbe_down(adapter);
  5411. }
  5412. ixgbe_free_irq(adapter);
  5413. ixgbe_free_all_tx_resources(adapter);
  5414. ixgbe_free_all_rx_resources(adapter);
  5415. }
  5416. /**
  5417. * ixgbe_close - Disables a network interface
  5418. * @netdev: network interface device structure
  5419. *
  5420. * Returns 0, this is not allowed to fail
  5421. *
  5422. * The close entry point is called when an interface is de-activated
  5423. * by the OS. The hardware is still under the drivers control, but
  5424. * needs to be disabled. A global MAC reset is issued to stop the
  5425. * hardware, and all transmit and receive resources are freed.
  5426. **/
  5427. int ixgbe_close(struct net_device *netdev)
  5428. {
  5429. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5430. ixgbe_ptp_stop(adapter);
  5431. if (netif_device_present(netdev))
  5432. ixgbe_close_suspend(adapter);
  5433. ixgbe_fdir_filter_exit(adapter);
  5434. ixgbe_release_hw_control(adapter);
  5435. return 0;
  5436. }
  5437. #ifdef CONFIG_PM
  5438. static int ixgbe_resume(struct pci_dev *pdev)
  5439. {
  5440. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5441. struct net_device *netdev = adapter->netdev;
  5442. u32 err;
  5443. adapter->hw.hw_addr = adapter->io_addr;
  5444. pci_set_power_state(pdev, PCI_D0);
  5445. pci_restore_state(pdev);
  5446. /*
  5447. * pci_restore_state clears dev->state_saved so call
  5448. * pci_save_state to restore it.
  5449. */
  5450. pci_save_state(pdev);
  5451. err = pci_enable_device_mem(pdev);
  5452. if (err) {
  5453. e_dev_err("Cannot enable PCI device from suspend\n");
  5454. return err;
  5455. }
  5456. smp_mb__before_atomic();
  5457. clear_bit(__IXGBE_DISABLED, &adapter->state);
  5458. pci_set_master(pdev);
  5459. pci_wake_from_d3(pdev, false);
  5460. ixgbe_reset(adapter);
  5461. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5462. rtnl_lock();
  5463. err = ixgbe_init_interrupt_scheme(adapter);
  5464. if (!err && netif_running(netdev))
  5465. err = ixgbe_open(netdev);
  5466. if (!err)
  5467. netif_device_attach(netdev);
  5468. rtnl_unlock();
  5469. return err;
  5470. }
  5471. #endif /* CONFIG_PM */
  5472. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  5473. {
  5474. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5475. struct net_device *netdev = adapter->netdev;
  5476. struct ixgbe_hw *hw = &adapter->hw;
  5477. u32 ctrl, fctrl;
  5478. u32 wufc = adapter->wol;
  5479. #ifdef CONFIG_PM
  5480. int retval = 0;
  5481. #endif
  5482. rtnl_lock();
  5483. netif_device_detach(netdev);
  5484. if (netif_running(netdev))
  5485. ixgbe_close_suspend(adapter);
  5486. ixgbe_clear_interrupt_scheme(adapter);
  5487. rtnl_unlock();
  5488. #ifdef CONFIG_PM
  5489. retval = pci_save_state(pdev);
  5490. if (retval)
  5491. return retval;
  5492. #endif
  5493. if (hw->mac.ops.stop_link_on_d3)
  5494. hw->mac.ops.stop_link_on_d3(hw);
  5495. if (wufc) {
  5496. ixgbe_set_rx_mode(netdev);
  5497. /* enable the optics for 82599 SFP+ fiber as we can WoL */
  5498. if (hw->mac.ops.enable_tx_laser)
  5499. hw->mac.ops.enable_tx_laser(hw);
  5500. /* turn on all-multi mode if wake on multicast is enabled */
  5501. if (wufc & IXGBE_WUFC_MC) {
  5502. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5503. fctrl |= IXGBE_FCTRL_MPE;
  5504. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  5505. }
  5506. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  5507. ctrl |= IXGBE_CTRL_GIO_DIS;
  5508. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  5509. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  5510. } else {
  5511. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  5512. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  5513. }
  5514. switch (hw->mac.type) {
  5515. case ixgbe_mac_82598EB:
  5516. pci_wake_from_d3(pdev, false);
  5517. break;
  5518. case ixgbe_mac_82599EB:
  5519. case ixgbe_mac_X540:
  5520. case ixgbe_mac_X550:
  5521. case ixgbe_mac_X550EM_x:
  5522. case ixgbe_mac_x550em_a:
  5523. pci_wake_from_d3(pdev, !!wufc);
  5524. break;
  5525. default:
  5526. break;
  5527. }
  5528. *enable_wake = !!wufc;
  5529. if (hw->phy.ops.set_phy_power && !*enable_wake)
  5530. hw->phy.ops.set_phy_power(hw, false);
  5531. ixgbe_release_hw_control(adapter);
  5532. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  5533. pci_disable_device(pdev);
  5534. return 0;
  5535. }
  5536. #ifdef CONFIG_PM
  5537. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  5538. {
  5539. int retval;
  5540. bool wake;
  5541. retval = __ixgbe_shutdown(pdev, &wake);
  5542. if (retval)
  5543. return retval;
  5544. if (wake) {
  5545. pci_prepare_to_sleep(pdev);
  5546. } else {
  5547. pci_wake_from_d3(pdev, false);
  5548. pci_set_power_state(pdev, PCI_D3hot);
  5549. }
  5550. return 0;
  5551. }
  5552. #endif /* CONFIG_PM */
  5553. static void ixgbe_shutdown(struct pci_dev *pdev)
  5554. {
  5555. bool wake;
  5556. __ixgbe_shutdown(pdev, &wake);
  5557. if (system_state == SYSTEM_POWER_OFF) {
  5558. pci_wake_from_d3(pdev, wake);
  5559. pci_set_power_state(pdev, PCI_D3hot);
  5560. }
  5561. }
  5562. /**
  5563. * ixgbe_update_stats - Update the board statistics counters.
  5564. * @adapter: board private structure
  5565. **/
  5566. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  5567. {
  5568. struct net_device *netdev = adapter->netdev;
  5569. struct ixgbe_hw *hw = &adapter->hw;
  5570. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  5571. u64 total_mpc = 0;
  5572. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  5573. u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
  5574. u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
  5575. u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
  5576. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5577. test_bit(__IXGBE_RESETTING, &adapter->state))
  5578. return;
  5579. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  5580. u64 rsc_count = 0;
  5581. u64 rsc_flush = 0;
  5582. for (i = 0; i < adapter->num_rx_queues; i++) {
  5583. rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
  5584. rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
  5585. }
  5586. adapter->rsc_total_count = rsc_count;
  5587. adapter->rsc_total_flush = rsc_flush;
  5588. }
  5589. for (i = 0; i < adapter->num_rx_queues; i++) {
  5590. struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
  5591. non_eop_descs += rx_ring->rx_stats.non_eop_descs;
  5592. alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
  5593. alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
  5594. hw_csum_rx_error += rx_ring->rx_stats.csum_err;
  5595. bytes += rx_ring->stats.bytes;
  5596. packets += rx_ring->stats.packets;
  5597. }
  5598. adapter->non_eop_descs = non_eop_descs;
  5599. adapter->alloc_rx_page_failed = alloc_rx_page_failed;
  5600. adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
  5601. adapter->hw_csum_rx_error = hw_csum_rx_error;
  5602. netdev->stats.rx_bytes = bytes;
  5603. netdev->stats.rx_packets = packets;
  5604. bytes = 0;
  5605. packets = 0;
  5606. /* gather some stats to the adapter struct that are per queue */
  5607. for (i = 0; i < adapter->num_tx_queues; i++) {
  5608. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  5609. restart_queue += tx_ring->tx_stats.restart_queue;
  5610. tx_busy += tx_ring->tx_stats.tx_busy;
  5611. bytes += tx_ring->stats.bytes;
  5612. packets += tx_ring->stats.packets;
  5613. }
  5614. adapter->restart_queue = restart_queue;
  5615. adapter->tx_busy = tx_busy;
  5616. netdev->stats.tx_bytes = bytes;
  5617. netdev->stats.tx_packets = packets;
  5618. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  5619. /* 8 register reads */
  5620. for (i = 0; i < 8; i++) {
  5621. /* for packet buffers not used, the register should read 0 */
  5622. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  5623. missed_rx += mpc;
  5624. hwstats->mpc[i] += mpc;
  5625. total_mpc += hwstats->mpc[i];
  5626. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  5627. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  5628. switch (hw->mac.type) {
  5629. case ixgbe_mac_82598EB:
  5630. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  5631. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  5632. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  5633. hwstats->pxonrxc[i] +=
  5634. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  5635. break;
  5636. case ixgbe_mac_82599EB:
  5637. case ixgbe_mac_X540:
  5638. case ixgbe_mac_X550:
  5639. case ixgbe_mac_X550EM_x:
  5640. case ixgbe_mac_x550em_a:
  5641. hwstats->pxonrxc[i] +=
  5642. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  5643. break;
  5644. default:
  5645. break;
  5646. }
  5647. }
  5648. /*16 register reads */
  5649. for (i = 0; i < 16; i++) {
  5650. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  5651. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  5652. if ((hw->mac.type == ixgbe_mac_82599EB) ||
  5653. (hw->mac.type == ixgbe_mac_X540) ||
  5654. (hw->mac.type == ixgbe_mac_X550) ||
  5655. (hw->mac.type == ixgbe_mac_X550EM_x) ||
  5656. (hw->mac.type == ixgbe_mac_x550em_a)) {
  5657. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  5658. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
  5659. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  5660. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
  5661. }
  5662. }
  5663. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  5664. /* work around hardware counting issue */
  5665. hwstats->gprc -= missed_rx;
  5666. ixgbe_update_xoff_received(adapter);
  5667. /* 82598 hardware only has a 32 bit counter in the high register */
  5668. switch (hw->mac.type) {
  5669. case ixgbe_mac_82598EB:
  5670. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  5671. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  5672. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  5673. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  5674. break;
  5675. case ixgbe_mac_X540:
  5676. case ixgbe_mac_X550:
  5677. case ixgbe_mac_X550EM_x:
  5678. case ixgbe_mac_x550em_a:
  5679. /* OS2BMC stats are X540 and later */
  5680. hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
  5681. hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
  5682. hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
  5683. hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
  5684. case ixgbe_mac_82599EB:
  5685. for (i = 0; i < 16; i++)
  5686. adapter->hw_rx_no_dma_resources +=
  5687. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  5688. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  5689. IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
  5690. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  5691. IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
  5692. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  5693. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  5694. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  5695. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  5696. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  5697. #ifdef IXGBE_FCOE
  5698. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  5699. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  5700. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  5701. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  5702. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  5703. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  5704. /* Add up per cpu counters for total ddp aloc fail */
  5705. if (adapter->fcoe.ddp_pool) {
  5706. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  5707. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  5708. unsigned int cpu;
  5709. u64 noddp = 0, noddp_ext_buff = 0;
  5710. for_each_possible_cpu(cpu) {
  5711. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  5712. noddp += ddp_pool->noddp;
  5713. noddp_ext_buff += ddp_pool->noddp_ext_buff;
  5714. }
  5715. hwstats->fcoe_noddp = noddp;
  5716. hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
  5717. }
  5718. #endif /* IXGBE_FCOE */
  5719. break;
  5720. default:
  5721. break;
  5722. }
  5723. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  5724. hwstats->bprc += bprc;
  5725. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  5726. if (hw->mac.type == ixgbe_mac_82598EB)
  5727. hwstats->mprc -= bprc;
  5728. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  5729. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  5730. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  5731. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  5732. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  5733. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  5734. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  5735. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  5736. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  5737. hwstats->lxontxc += lxon;
  5738. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  5739. hwstats->lxofftxc += lxoff;
  5740. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  5741. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  5742. /*
  5743. * 82598 errata - tx of flow control packets is included in tx counters
  5744. */
  5745. xon_off_tot = lxon + lxoff;
  5746. hwstats->gptc -= xon_off_tot;
  5747. hwstats->mptc -= xon_off_tot;
  5748. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  5749. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  5750. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  5751. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  5752. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  5753. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  5754. hwstats->ptc64 -= xon_off_tot;
  5755. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  5756. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  5757. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  5758. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  5759. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  5760. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  5761. /* Fill out the OS statistics structure */
  5762. netdev->stats.multicast = hwstats->mprc;
  5763. /* Rx Errors */
  5764. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  5765. netdev->stats.rx_dropped = 0;
  5766. netdev->stats.rx_length_errors = hwstats->rlec;
  5767. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  5768. netdev->stats.rx_missed_errors = total_mpc;
  5769. }
  5770. /**
  5771. * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
  5772. * @adapter: pointer to the device adapter structure
  5773. **/
  5774. static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
  5775. {
  5776. struct ixgbe_hw *hw = &adapter->hw;
  5777. int i;
  5778. if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  5779. return;
  5780. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  5781. /* if interface is down do nothing */
  5782. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5783. return;
  5784. /* do nothing if we are not using signature filters */
  5785. if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
  5786. return;
  5787. adapter->fdir_overflow++;
  5788. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  5789. for (i = 0; i < adapter->num_tx_queues; i++)
  5790. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  5791. &(adapter->tx_ring[i]->state));
  5792. /* re-enable flow director interrupts */
  5793. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
  5794. } else {
  5795. e_err(probe, "failed to finish FDIR re-initialization, "
  5796. "ignored adding FDIR ATR filters\n");
  5797. }
  5798. }
  5799. /**
  5800. * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
  5801. * @adapter: pointer to the device adapter structure
  5802. *
  5803. * This function serves two purposes. First it strobes the interrupt lines
  5804. * in order to make certain interrupts are occurring. Secondly it sets the
  5805. * bits needed to check for TX hangs. As a result we should immediately
  5806. * determine if a hang has occurred.
  5807. */
  5808. static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
  5809. {
  5810. struct ixgbe_hw *hw = &adapter->hw;
  5811. u64 eics = 0;
  5812. int i;
  5813. /* If we're down, removing or resetting, just bail */
  5814. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5815. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  5816. test_bit(__IXGBE_RESETTING, &adapter->state))
  5817. return;
  5818. /* Force detection of hung controller */
  5819. if (netif_carrier_ok(adapter->netdev)) {
  5820. for (i = 0; i < adapter->num_tx_queues; i++)
  5821. set_check_for_tx_hang(adapter->tx_ring[i]);
  5822. }
  5823. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  5824. /*
  5825. * for legacy and MSI interrupts don't set any bits
  5826. * that are enabled for EIAM, because this operation
  5827. * would set *both* EIMS and EICS for any bit in EIAM
  5828. */
  5829. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  5830. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  5831. } else {
  5832. /* get one bit for every active tx/rx interrupt vector */
  5833. for (i = 0; i < adapter->num_q_vectors; i++) {
  5834. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  5835. if (qv->rx.ring || qv->tx.ring)
  5836. eics |= BIT_ULL(i);
  5837. }
  5838. }
  5839. /* Cause software interrupt to ensure rings are cleaned */
  5840. ixgbe_irq_rearm_queues(adapter, eics);
  5841. }
  5842. /**
  5843. * ixgbe_watchdog_update_link - update the link status
  5844. * @adapter: pointer to the device adapter structure
  5845. * @link_speed: pointer to a u32 to store the link_speed
  5846. **/
  5847. static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
  5848. {
  5849. struct ixgbe_hw *hw = &adapter->hw;
  5850. u32 link_speed = adapter->link_speed;
  5851. bool link_up = adapter->link_up;
  5852. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  5853. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  5854. return;
  5855. if (hw->mac.ops.check_link) {
  5856. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  5857. } else {
  5858. /* always assume link is up, if no check link function */
  5859. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  5860. link_up = true;
  5861. }
  5862. if (adapter->ixgbe_ieee_pfc)
  5863. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  5864. if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
  5865. hw->mac.ops.fc_enable(hw);
  5866. ixgbe_set_rx_drop_en(adapter);
  5867. }
  5868. if (link_up ||
  5869. time_after(jiffies, (adapter->link_check_timeout +
  5870. IXGBE_TRY_LINK_TIMEOUT))) {
  5871. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  5872. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  5873. IXGBE_WRITE_FLUSH(hw);
  5874. }
  5875. adapter->link_up = link_up;
  5876. adapter->link_speed = link_speed;
  5877. }
  5878. static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
  5879. {
  5880. #ifdef CONFIG_IXGBE_DCB
  5881. struct net_device *netdev = adapter->netdev;
  5882. struct dcb_app app = {
  5883. .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
  5884. .protocol = 0,
  5885. };
  5886. u8 up = 0;
  5887. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  5888. up = dcb_ieee_getapp_mask(netdev, &app);
  5889. adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
  5890. #endif
  5891. }
  5892. static int ixgbe_enable_macvlan(struct net_device *upper, void *data)
  5893. {
  5894. if (netif_is_macvlan(upper)) {
  5895. struct macvlan_dev *vlan = netdev_priv(upper);
  5896. if (vlan->fwd_priv)
  5897. netif_tx_wake_all_queues(upper);
  5898. }
  5899. return 0;
  5900. }
  5901. /**
  5902. * ixgbe_watchdog_link_is_up - update netif_carrier status and
  5903. * print link up message
  5904. * @adapter: pointer to the device adapter structure
  5905. **/
  5906. static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
  5907. {
  5908. struct net_device *netdev = adapter->netdev;
  5909. struct ixgbe_hw *hw = &adapter->hw;
  5910. u32 link_speed = adapter->link_speed;
  5911. const char *speed_str;
  5912. bool flow_rx, flow_tx;
  5913. /* only continue if link was previously down */
  5914. if (netif_carrier_ok(netdev))
  5915. return;
  5916. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  5917. switch (hw->mac.type) {
  5918. case ixgbe_mac_82598EB: {
  5919. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5920. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  5921. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  5922. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  5923. }
  5924. break;
  5925. case ixgbe_mac_X540:
  5926. case ixgbe_mac_X550:
  5927. case ixgbe_mac_X550EM_x:
  5928. case ixgbe_mac_x550em_a:
  5929. case ixgbe_mac_82599EB: {
  5930. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  5931. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  5932. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  5933. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  5934. }
  5935. break;
  5936. default:
  5937. flow_tx = false;
  5938. flow_rx = false;
  5939. break;
  5940. }
  5941. adapter->last_rx_ptp_check = jiffies;
  5942. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  5943. ixgbe_ptp_start_cyclecounter(adapter);
  5944. switch (link_speed) {
  5945. case IXGBE_LINK_SPEED_10GB_FULL:
  5946. speed_str = "10 Gbps";
  5947. break;
  5948. case IXGBE_LINK_SPEED_2_5GB_FULL:
  5949. speed_str = "2.5 Gbps";
  5950. break;
  5951. case IXGBE_LINK_SPEED_1GB_FULL:
  5952. speed_str = "1 Gbps";
  5953. break;
  5954. case IXGBE_LINK_SPEED_100_FULL:
  5955. speed_str = "100 Mbps";
  5956. break;
  5957. case IXGBE_LINK_SPEED_10_FULL:
  5958. speed_str = "10 Mbps";
  5959. break;
  5960. default:
  5961. speed_str = "unknown speed";
  5962. break;
  5963. }
  5964. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
  5965. ((flow_rx && flow_tx) ? "RX/TX" :
  5966. (flow_rx ? "RX" :
  5967. (flow_tx ? "TX" : "None"))));
  5968. netif_carrier_on(netdev);
  5969. ixgbe_check_vf_rate_limit(adapter);
  5970. /* enable transmits */
  5971. netif_tx_wake_all_queues(adapter->netdev);
  5972. /* enable any upper devices */
  5973. rtnl_lock();
  5974. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  5975. ixgbe_enable_macvlan, NULL);
  5976. rtnl_unlock();
  5977. /* update the default user priority for VFs */
  5978. ixgbe_update_default_up(adapter);
  5979. /* ping all the active vfs to let them know link has changed */
  5980. ixgbe_ping_all_vfs(adapter);
  5981. }
  5982. /**
  5983. * ixgbe_watchdog_link_is_down - update netif_carrier status and
  5984. * print link down message
  5985. * @adapter: pointer to the adapter structure
  5986. **/
  5987. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
  5988. {
  5989. struct net_device *netdev = adapter->netdev;
  5990. struct ixgbe_hw *hw = &adapter->hw;
  5991. adapter->link_up = false;
  5992. adapter->link_speed = 0;
  5993. /* only continue if link was up previously */
  5994. if (!netif_carrier_ok(netdev))
  5995. return;
  5996. /* poll for SFP+ cable when link is down */
  5997. if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
  5998. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  5999. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6000. ixgbe_ptp_start_cyclecounter(adapter);
  6001. e_info(drv, "NIC Link is Down\n");
  6002. netif_carrier_off(netdev);
  6003. /* ping all the active vfs to let them know link has changed */
  6004. ixgbe_ping_all_vfs(adapter);
  6005. }
  6006. static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
  6007. {
  6008. int i;
  6009. for (i = 0; i < adapter->num_tx_queues; i++) {
  6010. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  6011. if (tx_ring->next_to_use != tx_ring->next_to_clean)
  6012. return true;
  6013. }
  6014. return false;
  6015. }
  6016. static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
  6017. {
  6018. struct ixgbe_hw *hw = &adapter->hw;
  6019. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  6020. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  6021. int i, j;
  6022. if (!adapter->num_vfs)
  6023. return false;
  6024. /* resetting the PF is only needed for MAC before X550 */
  6025. if (hw->mac.type >= ixgbe_mac_X550)
  6026. return false;
  6027. for (i = 0; i < adapter->num_vfs; i++) {
  6028. for (j = 0; j < q_per_pool; j++) {
  6029. u32 h, t;
  6030. h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
  6031. t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
  6032. if (h != t)
  6033. return true;
  6034. }
  6035. }
  6036. return false;
  6037. }
  6038. /**
  6039. * ixgbe_watchdog_flush_tx - flush queues on link down
  6040. * @adapter: pointer to the device adapter structure
  6041. **/
  6042. static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
  6043. {
  6044. if (!netif_carrier_ok(adapter->netdev)) {
  6045. if (ixgbe_ring_tx_pending(adapter) ||
  6046. ixgbe_vf_tx_pending(adapter)) {
  6047. /* We've lost link, so the controller stops DMA,
  6048. * but we've got queued Tx work that's never going
  6049. * to get done, so reset controller to flush Tx.
  6050. * (Do the reset outside of interrupt context).
  6051. */
  6052. e_warn(drv, "initiating reset to clear Tx work after link loss\n");
  6053. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  6054. }
  6055. }
  6056. }
  6057. #ifdef CONFIG_PCI_IOV
  6058. static inline void ixgbe_issue_vf_flr(struct ixgbe_adapter *adapter,
  6059. struct pci_dev *vfdev)
  6060. {
  6061. if (!pci_wait_for_pending_transaction(vfdev))
  6062. e_dev_warn("Issuing VFLR with pending transactions\n");
  6063. e_dev_err("Issuing VFLR for VF %s\n", pci_name(vfdev));
  6064. pcie_capability_set_word(vfdev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
  6065. msleep(100);
  6066. }
  6067. static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
  6068. {
  6069. struct ixgbe_hw *hw = &adapter->hw;
  6070. struct pci_dev *pdev = adapter->pdev;
  6071. unsigned int vf;
  6072. u32 gpc;
  6073. if (!(netif_carrier_ok(adapter->netdev)))
  6074. return;
  6075. gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
  6076. if (gpc) /* If incrementing then no need for the check below */
  6077. return;
  6078. /* Check to see if a bad DMA write target from an errant or
  6079. * malicious VF has caused a PCIe error. If so then we can
  6080. * issue a VFLR to the offending VF(s) and then resume without
  6081. * requesting a full slot reset.
  6082. */
  6083. if (!pdev)
  6084. return;
  6085. /* check status reg for all VFs owned by this PF */
  6086. for (vf = 0; vf < adapter->num_vfs; ++vf) {
  6087. struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
  6088. u16 status_reg;
  6089. if (!vfdev)
  6090. continue;
  6091. pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
  6092. if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
  6093. status_reg & PCI_STATUS_REC_MASTER_ABORT)
  6094. ixgbe_issue_vf_flr(adapter, vfdev);
  6095. }
  6096. }
  6097. static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
  6098. {
  6099. u32 ssvpc;
  6100. /* Do not perform spoof check for 82598 or if not in IOV mode */
  6101. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  6102. adapter->num_vfs == 0)
  6103. return;
  6104. ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
  6105. /*
  6106. * ssvpc register is cleared on read, if zero then no
  6107. * spoofed packets in the last interval.
  6108. */
  6109. if (!ssvpc)
  6110. return;
  6111. e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
  6112. }
  6113. #else
  6114. static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
  6115. {
  6116. }
  6117. static void
  6118. ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
  6119. {
  6120. }
  6121. #endif /* CONFIG_PCI_IOV */
  6122. /**
  6123. * ixgbe_watchdog_subtask - check and bring link up
  6124. * @adapter: pointer to the device adapter structure
  6125. **/
  6126. static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
  6127. {
  6128. /* if interface is down, removing or resetting, do nothing */
  6129. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6130. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6131. test_bit(__IXGBE_RESETTING, &adapter->state))
  6132. return;
  6133. ixgbe_watchdog_update_link(adapter);
  6134. if (adapter->link_up)
  6135. ixgbe_watchdog_link_is_up(adapter);
  6136. else
  6137. ixgbe_watchdog_link_is_down(adapter);
  6138. ixgbe_check_for_bad_vf(adapter);
  6139. ixgbe_spoof_check(adapter);
  6140. ixgbe_update_stats(adapter);
  6141. ixgbe_watchdog_flush_tx(adapter);
  6142. }
  6143. /**
  6144. * ixgbe_sfp_detection_subtask - poll for SFP+ cable
  6145. * @adapter: the ixgbe adapter structure
  6146. **/
  6147. static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
  6148. {
  6149. struct ixgbe_hw *hw = &adapter->hw;
  6150. s32 err;
  6151. /* not searching for SFP so there is nothing to do here */
  6152. if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
  6153. !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6154. return;
  6155. if (adapter->sfp_poll_time &&
  6156. time_after(adapter->sfp_poll_time, jiffies))
  6157. return; /* If not yet time to poll for SFP */
  6158. /* someone else is in init, wait until next service event */
  6159. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6160. return;
  6161. adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
  6162. err = hw->phy.ops.identify_sfp(hw);
  6163. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6164. goto sfp_out;
  6165. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  6166. /* If no cable is present, then we need to reset
  6167. * the next time we find a good cable. */
  6168. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  6169. }
  6170. /* exit on error */
  6171. if (err)
  6172. goto sfp_out;
  6173. /* exit if reset not needed */
  6174. if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6175. goto sfp_out;
  6176. adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
  6177. /*
  6178. * A module may be identified correctly, but the EEPROM may not have
  6179. * support for that module. setup_sfp() will fail in that case, so
  6180. * we should not allow that module to load.
  6181. */
  6182. if (hw->mac.type == ixgbe_mac_82598EB)
  6183. err = hw->phy.ops.reset(hw);
  6184. else
  6185. err = hw->mac.ops.setup_sfp(hw);
  6186. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6187. goto sfp_out;
  6188. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  6189. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  6190. sfp_out:
  6191. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6192. if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
  6193. (adapter->netdev->reg_state == NETREG_REGISTERED)) {
  6194. e_dev_err("failed to initialize because an unsupported "
  6195. "SFP+ module type was detected.\n");
  6196. e_dev_err("Reload the driver after installing a "
  6197. "supported module.\n");
  6198. unregister_netdev(adapter->netdev);
  6199. }
  6200. }
  6201. /**
  6202. * ixgbe_sfp_link_config_subtask - set up link SFP after module install
  6203. * @adapter: the ixgbe adapter structure
  6204. **/
  6205. static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
  6206. {
  6207. struct ixgbe_hw *hw = &adapter->hw;
  6208. u32 speed;
  6209. bool autoneg = false;
  6210. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
  6211. return;
  6212. /* someone else is in init, wait until next service event */
  6213. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6214. return;
  6215. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  6216. speed = hw->phy.autoneg_advertised;
  6217. if ((!speed) && (hw->mac.ops.get_link_capabilities)) {
  6218. hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
  6219. /* setup the highest link when no autoneg */
  6220. if (!autoneg) {
  6221. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  6222. speed = IXGBE_LINK_SPEED_10GB_FULL;
  6223. }
  6224. }
  6225. if (hw->mac.ops.setup_link)
  6226. hw->mac.ops.setup_link(hw, speed, true);
  6227. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  6228. adapter->link_check_timeout = jiffies;
  6229. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6230. }
  6231. /**
  6232. * ixgbe_service_timer - Timer Call-back
  6233. * @data: pointer to adapter cast into an unsigned long
  6234. **/
  6235. static void ixgbe_service_timer(unsigned long data)
  6236. {
  6237. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  6238. unsigned long next_event_offset;
  6239. /* poll faster when waiting for link */
  6240. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  6241. next_event_offset = HZ / 10;
  6242. else
  6243. next_event_offset = HZ * 2;
  6244. /* Reset the timer */
  6245. mod_timer(&adapter->service_timer, next_event_offset + jiffies);
  6246. ixgbe_service_event_schedule(adapter);
  6247. }
  6248. static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
  6249. {
  6250. struct ixgbe_hw *hw = &adapter->hw;
  6251. u32 status;
  6252. if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
  6253. return;
  6254. adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
  6255. if (!hw->phy.ops.handle_lasi)
  6256. return;
  6257. status = hw->phy.ops.handle_lasi(&adapter->hw);
  6258. if (status != IXGBE_ERR_OVERTEMP)
  6259. return;
  6260. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  6261. }
  6262. static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
  6263. {
  6264. if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
  6265. return;
  6266. /* If we're already down, removing or resetting, just bail */
  6267. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6268. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6269. test_bit(__IXGBE_RESETTING, &adapter->state))
  6270. return;
  6271. ixgbe_dump(adapter);
  6272. netdev_err(adapter->netdev, "Reset adapter\n");
  6273. adapter->tx_timeout_count++;
  6274. rtnl_lock();
  6275. ixgbe_reinit_locked(adapter);
  6276. rtnl_unlock();
  6277. }
  6278. /**
  6279. * ixgbe_service_task - manages and runs subtasks
  6280. * @work: pointer to work_struct containing our data
  6281. **/
  6282. static void ixgbe_service_task(struct work_struct *work)
  6283. {
  6284. struct ixgbe_adapter *adapter = container_of(work,
  6285. struct ixgbe_adapter,
  6286. service_task);
  6287. if (ixgbe_removed(adapter->hw.hw_addr)) {
  6288. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  6289. rtnl_lock();
  6290. ixgbe_down(adapter);
  6291. rtnl_unlock();
  6292. }
  6293. ixgbe_service_event_complete(adapter);
  6294. return;
  6295. }
  6296. if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
  6297. rtnl_lock();
  6298. adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  6299. udp_tunnel_get_rx_info(adapter->netdev);
  6300. rtnl_unlock();
  6301. }
  6302. ixgbe_reset_subtask(adapter);
  6303. ixgbe_phy_interrupt_subtask(adapter);
  6304. ixgbe_sfp_detection_subtask(adapter);
  6305. ixgbe_sfp_link_config_subtask(adapter);
  6306. ixgbe_check_overtemp_subtask(adapter);
  6307. ixgbe_watchdog_subtask(adapter);
  6308. ixgbe_fdir_reinit_subtask(adapter);
  6309. ixgbe_check_hang_subtask(adapter);
  6310. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
  6311. ixgbe_ptp_overflow_check(adapter);
  6312. ixgbe_ptp_rx_hang(adapter);
  6313. }
  6314. ixgbe_service_event_complete(adapter);
  6315. }
  6316. static int ixgbe_tso(struct ixgbe_ring *tx_ring,
  6317. struct ixgbe_tx_buffer *first,
  6318. u8 *hdr_len)
  6319. {
  6320. u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
  6321. struct sk_buff *skb = first->skb;
  6322. union {
  6323. struct iphdr *v4;
  6324. struct ipv6hdr *v6;
  6325. unsigned char *hdr;
  6326. } ip;
  6327. union {
  6328. struct tcphdr *tcp;
  6329. unsigned char *hdr;
  6330. } l4;
  6331. u32 paylen, l4_offset;
  6332. int err;
  6333. if (skb->ip_summed != CHECKSUM_PARTIAL)
  6334. return 0;
  6335. if (!skb_is_gso(skb))
  6336. return 0;
  6337. err = skb_cow_head(skb, 0);
  6338. if (err < 0)
  6339. return err;
  6340. ip.hdr = skb_network_header(skb);
  6341. l4.hdr = skb_checksum_start(skb);
  6342. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  6343. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6344. /* initialize outer IP header fields */
  6345. if (ip.v4->version == 4) {
  6346. unsigned char *csum_start = skb_checksum_start(skb);
  6347. unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
  6348. /* IP header will have to cancel out any data that
  6349. * is not a part of the outer IP header
  6350. */
  6351. ip.v4->check = csum_fold(csum_partial(trans_start,
  6352. csum_start - trans_start,
  6353. 0));
  6354. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  6355. ip.v4->tot_len = 0;
  6356. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6357. IXGBE_TX_FLAGS_CSUM |
  6358. IXGBE_TX_FLAGS_IPV4;
  6359. } else {
  6360. ip.v6->payload_len = 0;
  6361. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6362. IXGBE_TX_FLAGS_CSUM;
  6363. }
  6364. /* determine offset of inner transport header */
  6365. l4_offset = l4.hdr - skb->data;
  6366. /* compute length of segmentation header */
  6367. *hdr_len = (l4.tcp->doff * 4) + l4_offset;
  6368. /* remove payload length from inner checksum */
  6369. paylen = skb->len - l4_offset;
  6370. csum_replace_by_diff(&l4.tcp->check, htonl(paylen));
  6371. /* update gso size and bytecount with header size */
  6372. first->gso_segs = skb_shinfo(skb)->gso_segs;
  6373. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  6374. /* mss_l4len_id: use 0 as index for TSO */
  6375. mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
  6376. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  6377. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  6378. vlan_macip_lens = l4.hdr - ip.hdr;
  6379. vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6380. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6381. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
  6382. mss_l4len_idx);
  6383. return 1;
  6384. }
  6385. static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
  6386. {
  6387. unsigned int offset = 0;
  6388. ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
  6389. return offset == skb_checksum_start_offset(skb);
  6390. }
  6391. static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
  6392. struct ixgbe_tx_buffer *first)
  6393. {
  6394. struct sk_buff *skb = first->skb;
  6395. u32 vlan_macip_lens = 0;
  6396. u32 type_tucmd = 0;
  6397. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  6398. csum_failed:
  6399. if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
  6400. IXGBE_TX_FLAGS_CC)))
  6401. return;
  6402. goto no_csum;
  6403. }
  6404. switch (skb->csum_offset) {
  6405. case offsetof(struct tcphdr, check):
  6406. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6407. /* fall through */
  6408. case offsetof(struct udphdr, check):
  6409. break;
  6410. case offsetof(struct sctphdr, checksum):
  6411. /* validate that this is actually an SCTP request */
  6412. if (((first->protocol == htons(ETH_P_IP)) &&
  6413. (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
  6414. ((first->protocol == htons(ETH_P_IPV6)) &&
  6415. ixgbe_ipv6_csum_is_sctp(skb))) {
  6416. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  6417. break;
  6418. }
  6419. /* fall through */
  6420. default:
  6421. skb_checksum_help(skb);
  6422. goto csum_failed;
  6423. }
  6424. /* update TX checksum flag */
  6425. first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
  6426. vlan_macip_lens = skb_checksum_start_offset(skb) -
  6427. skb_network_offset(skb);
  6428. no_csum:
  6429. /* vlan_macip_lens: MACLEN, VLAN tag */
  6430. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6431. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6432. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, 0);
  6433. }
  6434. #define IXGBE_SET_FLAG(_input, _flag, _result) \
  6435. ((_flag <= _result) ? \
  6436. ((u32)(_input & _flag) * (_result / _flag)) : \
  6437. ((u32)(_input & _flag) / (_flag / _result)))
  6438. static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
  6439. {
  6440. /* set type for advanced descriptor with frame checksum insertion */
  6441. u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  6442. IXGBE_ADVTXD_DCMD_DEXT |
  6443. IXGBE_ADVTXD_DCMD_IFCS;
  6444. /* set HW vlan bit if vlan is present */
  6445. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
  6446. IXGBE_ADVTXD_DCMD_VLE);
  6447. /* set segmentation enable bits for TSO/FSO */
  6448. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
  6449. IXGBE_ADVTXD_DCMD_TSE);
  6450. /* set timestamp bit if present */
  6451. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
  6452. IXGBE_ADVTXD_MAC_TSTAMP);
  6453. /* insert frame checksum */
  6454. cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
  6455. return cmd_type;
  6456. }
  6457. static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
  6458. u32 tx_flags, unsigned int paylen)
  6459. {
  6460. u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
  6461. /* enable L4 checksum for TSO and TX checksum offload */
  6462. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6463. IXGBE_TX_FLAGS_CSUM,
  6464. IXGBE_ADVTXD_POPTS_TXSM);
  6465. /* enble IPv4 checksum for TSO */
  6466. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6467. IXGBE_TX_FLAGS_IPV4,
  6468. IXGBE_ADVTXD_POPTS_IXSM);
  6469. /*
  6470. * Check Context must be set if Tx switch is enabled, which it
  6471. * always is for case where virtual functions are running
  6472. */
  6473. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6474. IXGBE_TX_FLAGS_CC,
  6475. IXGBE_ADVTXD_CC);
  6476. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  6477. }
  6478. static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6479. {
  6480. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6481. /* Herbert's original patch had:
  6482. * smp_mb__after_netif_stop_queue();
  6483. * but since that doesn't exist yet, just open code it.
  6484. */
  6485. smp_mb();
  6486. /* We need to check again in a case another CPU has just
  6487. * made room available.
  6488. */
  6489. if (likely(ixgbe_desc_unused(tx_ring) < size))
  6490. return -EBUSY;
  6491. /* A reprieve! - use start_queue because it doesn't call schedule */
  6492. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6493. ++tx_ring->tx_stats.restart_queue;
  6494. return 0;
  6495. }
  6496. static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6497. {
  6498. if (likely(ixgbe_desc_unused(tx_ring) >= size))
  6499. return 0;
  6500. return __ixgbe_maybe_stop_tx(tx_ring, size);
  6501. }
  6502. #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
  6503. IXGBE_TXD_CMD_RS)
  6504. static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
  6505. struct ixgbe_tx_buffer *first,
  6506. const u8 hdr_len)
  6507. {
  6508. struct sk_buff *skb = first->skb;
  6509. struct ixgbe_tx_buffer *tx_buffer;
  6510. union ixgbe_adv_tx_desc *tx_desc;
  6511. struct skb_frag_struct *frag;
  6512. dma_addr_t dma;
  6513. unsigned int data_len, size;
  6514. u32 tx_flags = first->tx_flags;
  6515. u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
  6516. u16 i = tx_ring->next_to_use;
  6517. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  6518. ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
  6519. size = skb_headlen(skb);
  6520. data_len = skb->data_len;
  6521. #ifdef IXGBE_FCOE
  6522. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  6523. if (data_len < sizeof(struct fcoe_crc_eof)) {
  6524. size -= sizeof(struct fcoe_crc_eof) - data_len;
  6525. data_len = 0;
  6526. } else {
  6527. data_len -= sizeof(struct fcoe_crc_eof);
  6528. }
  6529. }
  6530. #endif
  6531. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  6532. tx_buffer = first;
  6533. for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
  6534. if (dma_mapping_error(tx_ring->dev, dma))
  6535. goto dma_error;
  6536. /* record length, and DMA address */
  6537. dma_unmap_len_set(tx_buffer, len, size);
  6538. dma_unmap_addr_set(tx_buffer, dma, dma);
  6539. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6540. while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
  6541. tx_desc->read.cmd_type_len =
  6542. cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
  6543. i++;
  6544. tx_desc++;
  6545. if (i == tx_ring->count) {
  6546. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6547. i = 0;
  6548. }
  6549. tx_desc->read.olinfo_status = 0;
  6550. dma += IXGBE_MAX_DATA_PER_TXD;
  6551. size -= IXGBE_MAX_DATA_PER_TXD;
  6552. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6553. }
  6554. if (likely(!data_len))
  6555. break;
  6556. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
  6557. i++;
  6558. tx_desc++;
  6559. if (i == tx_ring->count) {
  6560. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6561. i = 0;
  6562. }
  6563. tx_desc->read.olinfo_status = 0;
  6564. #ifdef IXGBE_FCOE
  6565. size = min_t(unsigned int, data_len, skb_frag_size(frag));
  6566. #else
  6567. size = skb_frag_size(frag);
  6568. #endif
  6569. data_len -= size;
  6570. dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
  6571. DMA_TO_DEVICE);
  6572. tx_buffer = &tx_ring->tx_buffer_info[i];
  6573. }
  6574. /* write last descriptor with RS and EOP bits */
  6575. cmd_type |= size | IXGBE_TXD_CMD;
  6576. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  6577. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  6578. /* set the timestamp */
  6579. first->time_stamp = jiffies;
  6580. /*
  6581. * Force memory writes to complete before letting h/w know there
  6582. * are new descriptors to fetch. (Only applicable for weak-ordered
  6583. * memory model archs, such as IA-64).
  6584. *
  6585. * We also need this memory barrier to make certain all of the
  6586. * status bits have been updated before next_to_watch is written.
  6587. */
  6588. wmb();
  6589. /* set next_to_watch value indicating a packet is present */
  6590. first->next_to_watch = tx_desc;
  6591. i++;
  6592. if (i == tx_ring->count)
  6593. i = 0;
  6594. tx_ring->next_to_use = i;
  6595. ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
  6596. if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
  6597. writel(i, tx_ring->tail);
  6598. /* we need this if more than one processor can write to our tail
  6599. * at a time, it synchronizes IO on IA64/Altix systems
  6600. */
  6601. mmiowb();
  6602. }
  6603. return;
  6604. dma_error:
  6605. dev_err(tx_ring->dev, "TX DMA map failed\n");
  6606. tx_buffer = &tx_ring->tx_buffer_info[i];
  6607. /* clear dma mappings for failed tx_buffer_info map */
  6608. while (tx_buffer != first) {
  6609. if (dma_unmap_len(tx_buffer, len))
  6610. dma_unmap_page(tx_ring->dev,
  6611. dma_unmap_addr(tx_buffer, dma),
  6612. dma_unmap_len(tx_buffer, len),
  6613. DMA_TO_DEVICE);
  6614. dma_unmap_len_set(tx_buffer, len, 0);
  6615. if (i--)
  6616. i += tx_ring->count;
  6617. tx_buffer = &tx_ring->tx_buffer_info[i];
  6618. }
  6619. if (dma_unmap_len(tx_buffer, len))
  6620. dma_unmap_single(tx_ring->dev,
  6621. dma_unmap_addr(tx_buffer, dma),
  6622. dma_unmap_len(tx_buffer, len),
  6623. DMA_TO_DEVICE);
  6624. dma_unmap_len_set(tx_buffer, len, 0);
  6625. dev_kfree_skb_any(first->skb);
  6626. first->skb = NULL;
  6627. tx_ring->next_to_use = i;
  6628. }
  6629. static void ixgbe_atr(struct ixgbe_ring *ring,
  6630. struct ixgbe_tx_buffer *first)
  6631. {
  6632. struct ixgbe_q_vector *q_vector = ring->q_vector;
  6633. union ixgbe_atr_hash_dword input = { .dword = 0 };
  6634. union ixgbe_atr_hash_dword common = { .dword = 0 };
  6635. union {
  6636. unsigned char *network;
  6637. struct iphdr *ipv4;
  6638. struct ipv6hdr *ipv6;
  6639. } hdr;
  6640. struct tcphdr *th;
  6641. unsigned int hlen;
  6642. struct sk_buff *skb;
  6643. __be16 vlan_id;
  6644. int l4_proto;
  6645. /* if ring doesn't have a interrupt vector, cannot perform ATR */
  6646. if (!q_vector)
  6647. return;
  6648. /* do nothing if sampling is disabled */
  6649. if (!ring->atr_sample_rate)
  6650. return;
  6651. ring->atr_count++;
  6652. /* currently only IPv4/IPv6 with TCP is supported */
  6653. if ((first->protocol != htons(ETH_P_IP)) &&
  6654. (first->protocol != htons(ETH_P_IPV6)))
  6655. return;
  6656. /* snag network header to get L4 type and address */
  6657. skb = first->skb;
  6658. hdr.network = skb_network_header(skb);
  6659. if (unlikely(hdr.network <= skb->data))
  6660. return;
  6661. if (skb->encapsulation &&
  6662. first->protocol == htons(ETH_P_IP) &&
  6663. hdr.ipv4->protocol == IPPROTO_UDP) {
  6664. struct ixgbe_adapter *adapter = q_vector->adapter;
  6665. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  6666. VXLAN_HEADROOM))
  6667. return;
  6668. /* verify the port is recognized as VXLAN */
  6669. if (adapter->vxlan_port &&
  6670. udp_hdr(skb)->dest == adapter->vxlan_port)
  6671. hdr.network = skb_inner_network_header(skb);
  6672. if (adapter->geneve_port &&
  6673. udp_hdr(skb)->dest == adapter->geneve_port)
  6674. hdr.network = skb_inner_network_header(skb);
  6675. }
  6676. /* Make sure we have at least [minimum IPv4 header + TCP]
  6677. * or [IPv6 header] bytes
  6678. */
  6679. if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
  6680. return;
  6681. /* Currently only IPv4/IPv6 with TCP is supported */
  6682. switch (hdr.ipv4->version) {
  6683. case IPVERSION:
  6684. /* access ihl as u8 to avoid unaligned access on ia64 */
  6685. hlen = (hdr.network[0] & 0x0F) << 2;
  6686. l4_proto = hdr.ipv4->protocol;
  6687. break;
  6688. case 6:
  6689. hlen = hdr.network - skb->data;
  6690. l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
  6691. hlen -= hdr.network - skb->data;
  6692. break;
  6693. default:
  6694. return;
  6695. }
  6696. if (l4_proto != IPPROTO_TCP)
  6697. return;
  6698. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  6699. hlen + sizeof(struct tcphdr)))
  6700. return;
  6701. th = (struct tcphdr *)(hdr.network + hlen);
  6702. /* skip this packet since the socket is closing */
  6703. if (th->fin)
  6704. return;
  6705. /* sample on all syn packets or once every atr sample count */
  6706. if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
  6707. return;
  6708. /* reset sample count */
  6709. ring->atr_count = 0;
  6710. vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
  6711. /*
  6712. * src and dst are inverted, think how the receiver sees them
  6713. *
  6714. * The input is broken into two sections, a non-compressed section
  6715. * containing vm_pool, vlan_id, and flow_type. The rest of the data
  6716. * is XORed together and stored in the compressed dword.
  6717. */
  6718. input.formatted.vlan_id = vlan_id;
  6719. /*
  6720. * since src port and flex bytes occupy the same word XOR them together
  6721. * and write the value to source port portion of compressed dword
  6722. */
  6723. if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
  6724. common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
  6725. else
  6726. common.port.src ^= th->dest ^ first->protocol;
  6727. common.port.dst ^= th->source;
  6728. switch (hdr.ipv4->version) {
  6729. case IPVERSION:
  6730. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  6731. common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
  6732. break;
  6733. case 6:
  6734. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
  6735. common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
  6736. hdr.ipv6->saddr.s6_addr32[1] ^
  6737. hdr.ipv6->saddr.s6_addr32[2] ^
  6738. hdr.ipv6->saddr.s6_addr32[3] ^
  6739. hdr.ipv6->daddr.s6_addr32[0] ^
  6740. hdr.ipv6->daddr.s6_addr32[1] ^
  6741. hdr.ipv6->daddr.s6_addr32[2] ^
  6742. hdr.ipv6->daddr.s6_addr32[3];
  6743. break;
  6744. default:
  6745. break;
  6746. }
  6747. if (hdr.network != skb_network_header(skb))
  6748. input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
  6749. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  6750. ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
  6751. input, common, ring->queue_index);
  6752. }
  6753. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
  6754. void *accel_priv, select_queue_fallback_t fallback)
  6755. {
  6756. struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
  6757. #ifdef IXGBE_FCOE
  6758. struct ixgbe_adapter *adapter;
  6759. struct ixgbe_ring_feature *f;
  6760. int txq;
  6761. #endif
  6762. if (fwd_adapter)
  6763. return skb->queue_mapping + fwd_adapter->tx_base_queue;
  6764. #ifdef IXGBE_FCOE
  6765. /*
  6766. * only execute the code below if protocol is FCoE
  6767. * or FIP and we have FCoE enabled on the adapter
  6768. */
  6769. switch (vlan_get_protocol(skb)) {
  6770. case htons(ETH_P_FCOE):
  6771. case htons(ETH_P_FIP):
  6772. adapter = netdev_priv(dev);
  6773. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  6774. break;
  6775. default:
  6776. return fallback(dev, skb);
  6777. }
  6778. f = &adapter->ring_feature[RING_F_FCOE];
  6779. txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
  6780. smp_processor_id();
  6781. while (txq >= f->indices)
  6782. txq -= f->indices;
  6783. return txq + f->offset;
  6784. #else
  6785. return fallback(dev, skb);
  6786. #endif
  6787. }
  6788. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
  6789. struct ixgbe_adapter *adapter,
  6790. struct ixgbe_ring *tx_ring)
  6791. {
  6792. struct ixgbe_tx_buffer *first;
  6793. int tso;
  6794. u32 tx_flags = 0;
  6795. unsigned short f;
  6796. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  6797. __be16 protocol = skb->protocol;
  6798. u8 hdr_len = 0;
  6799. /*
  6800. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  6801. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  6802. * + 2 desc gap to keep tail from touching head,
  6803. * + 1 desc for context descriptor,
  6804. * otherwise try next time
  6805. */
  6806. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  6807. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  6808. if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
  6809. tx_ring->tx_stats.tx_busy++;
  6810. return NETDEV_TX_BUSY;
  6811. }
  6812. /* record the location of the first descriptor for this packet */
  6813. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  6814. first->skb = skb;
  6815. first->bytecount = skb->len;
  6816. first->gso_segs = 1;
  6817. /* if we have a HW VLAN tag being added default to the HW one */
  6818. if (skb_vlan_tag_present(skb)) {
  6819. tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
  6820. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  6821. /* else if it is a SW VLAN check the next protocol and store the tag */
  6822. } else if (protocol == htons(ETH_P_8021Q)) {
  6823. struct vlan_hdr *vhdr, _vhdr;
  6824. vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
  6825. if (!vhdr)
  6826. goto out_drop;
  6827. tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
  6828. IXGBE_TX_FLAGS_VLAN_SHIFT;
  6829. tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
  6830. }
  6831. protocol = vlan_get_protocol(skb);
  6832. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  6833. adapter->ptp_clock &&
  6834. !test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
  6835. &adapter->state)) {
  6836. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  6837. tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
  6838. /* schedule check for Tx timestamp */
  6839. adapter->ptp_tx_skb = skb_get(skb);
  6840. adapter->ptp_tx_start = jiffies;
  6841. schedule_work(&adapter->ptp_tx_work);
  6842. }
  6843. skb_tx_timestamp(skb);
  6844. #ifdef CONFIG_PCI_IOV
  6845. /*
  6846. * Use the l2switch_enable flag - would be false if the DMA
  6847. * Tx switch had been disabled.
  6848. */
  6849. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6850. tx_flags |= IXGBE_TX_FLAGS_CC;
  6851. #endif
  6852. /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
  6853. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  6854. ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
  6855. (skb->priority != TC_PRIO_CONTROL))) {
  6856. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  6857. tx_flags |= (skb->priority & 0x7) <<
  6858. IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
  6859. if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
  6860. struct vlan_ethhdr *vhdr;
  6861. if (skb_cow_head(skb, 0))
  6862. goto out_drop;
  6863. vhdr = (struct vlan_ethhdr *)skb->data;
  6864. vhdr->h_vlan_TCI = htons(tx_flags >>
  6865. IXGBE_TX_FLAGS_VLAN_SHIFT);
  6866. } else {
  6867. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  6868. }
  6869. }
  6870. /* record initial flags and protocol */
  6871. first->tx_flags = tx_flags;
  6872. first->protocol = protocol;
  6873. #ifdef IXGBE_FCOE
  6874. /* setup tx offload for FCoE */
  6875. if ((protocol == htons(ETH_P_FCOE)) &&
  6876. (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
  6877. tso = ixgbe_fso(tx_ring, first, &hdr_len);
  6878. if (tso < 0)
  6879. goto out_drop;
  6880. goto xmit_fcoe;
  6881. }
  6882. #endif /* IXGBE_FCOE */
  6883. tso = ixgbe_tso(tx_ring, first, &hdr_len);
  6884. if (tso < 0)
  6885. goto out_drop;
  6886. else if (!tso)
  6887. ixgbe_tx_csum(tx_ring, first);
  6888. /* add the ATR filter if ATR is on */
  6889. if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
  6890. ixgbe_atr(tx_ring, first);
  6891. #ifdef IXGBE_FCOE
  6892. xmit_fcoe:
  6893. #endif /* IXGBE_FCOE */
  6894. ixgbe_tx_map(tx_ring, first, hdr_len);
  6895. return NETDEV_TX_OK;
  6896. out_drop:
  6897. dev_kfree_skb_any(first->skb);
  6898. first->skb = NULL;
  6899. return NETDEV_TX_OK;
  6900. }
  6901. static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
  6902. struct net_device *netdev,
  6903. struct ixgbe_ring *ring)
  6904. {
  6905. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6906. struct ixgbe_ring *tx_ring;
  6907. /*
  6908. * The minimum packet size for olinfo paylen is 17 so pad the skb
  6909. * in order to meet this minimum size requirement.
  6910. */
  6911. if (skb_put_padto(skb, 17))
  6912. return NETDEV_TX_OK;
  6913. tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
  6914. return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
  6915. }
  6916. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  6917. struct net_device *netdev)
  6918. {
  6919. return __ixgbe_xmit_frame(skb, netdev, NULL);
  6920. }
  6921. /**
  6922. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  6923. * @netdev: network interface device structure
  6924. * @p: pointer to an address structure
  6925. *
  6926. * Returns 0 on success, negative on failure
  6927. **/
  6928. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  6929. {
  6930. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6931. struct ixgbe_hw *hw = &adapter->hw;
  6932. struct sockaddr *addr = p;
  6933. if (!is_valid_ether_addr(addr->sa_data))
  6934. return -EADDRNOTAVAIL;
  6935. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  6936. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  6937. ixgbe_mac_set_default_filter(adapter);
  6938. return 0;
  6939. }
  6940. static int
  6941. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  6942. {
  6943. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6944. struct ixgbe_hw *hw = &adapter->hw;
  6945. u16 value;
  6946. int rc;
  6947. if (prtad != hw->phy.mdio.prtad)
  6948. return -EINVAL;
  6949. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  6950. if (!rc)
  6951. rc = value;
  6952. return rc;
  6953. }
  6954. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  6955. u16 addr, u16 value)
  6956. {
  6957. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6958. struct ixgbe_hw *hw = &adapter->hw;
  6959. if (prtad != hw->phy.mdio.prtad)
  6960. return -EINVAL;
  6961. return hw->phy.ops.write_reg(hw, addr, devad, value);
  6962. }
  6963. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  6964. {
  6965. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6966. switch (cmd) {
  6967. case SIOCSHWTSTAMP:
  6968. return ixgbe_ptp_set_ts_config(adapter, req);
  6969. case SIOCGHWTSTAMP:
  6970. return ixgbe_ptp_get_ts_config(adapter, req);
  6971. default:
  6972. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  6973. }
  6974. }
  6975. /**
  6976. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  6977. * netdev->dev_addrs
  6978. * @netdev: network interface device structure
  6979. *
  6980. * Returns non-zero on failure
  6981. **/
  6982. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  6983. {
  6984. int err = 0;
  6985. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6986. struct ixgbe_hw *hw = &adapter->hw;
  6987. if (is_valid_ether_addr(hw->mac.san_addr)) {
  6988. rtnl_lock();
  6989. err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
  6990. rtnl_unlock();
  6991. /* update SAN MAC vmdq pool selection */
  6992. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  6993. }
  6994. return err;
  6995. }
  6996. /**
  6997. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  6998. * netdev->dev_addrs
  6999. * @netdev: network interface device structure
  7000. *
  7001. * Returns non-zero on failure
  7002. **/
  7003. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  7004. {
  7005. int err = 0;
  7006. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7007. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  7008. if (is_valid_ether_addr(mac->san_addr)) {
  7009. rtnl_lock();
  7010. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  7011. rtnl_unlock();
  7012. }
  7013. return err;
  7014. }
  7015. #ifdef CONFIG_NET_POLL_CONTROLLER
  7016. /*
  7017. * Polling 'interrupt' - used by things like netconsole to send skbs
  7018. * without having to re-enable interrupts. It's not called while
  7019. * the interrupt routine is executing.
  7020. */
  7021. static void ixgbe_netpoll(struct net_device *netdev)
  7022. {
  7023. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7024. int i;
  7025. /* if interface is down do nothing */
  7026. if (test_bit(__IXGBE_DOWN, &adapter->state))
  7027. return;
  7028. /* loop through and schedule all active queues */
  7029. for (i = 0; i < adapter->num_q_vectors; i++)
  7030. ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
  7031. }
  7032. #endif
  7033. static void ixgbe_get_stats64(struct net_device *netdev,
  7034. struct rtnl_link_stats64 *stats)
  7035. {
  7036. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7037. int i;
  7038. rcu_read_lock();
  7039. for (i = 0; i < adapter->num_rx_queues; i++) {
  7040. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
  7041. u64 bytes, packets;
  7042. unsigned int start;
  7043. if (ring) {
  7044. do {
  7045. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7046. packets = ring->stats.packets;
  7047. bytes = ring->stats.bytes;
  7048. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7049. stats->rx_packets += packets;
  7050. stats->rx_bytes += bytes;
  7051. }
  7052. }
  7053. for (i = 0; i < adapter->num_tx_queues; i++) {
  7054. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
  7055. u64 bytes, packets;
  7056. unsigned int start;
  7057. if (ring) {
  7058. do {
  7059. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7060. packets = ring->stats.packets;
  7061. bytes = ring->stats.bytes;
  7062. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7063. stats->tx_packets += packets;
  7064. stats->tx_bytes += bytes;
  7065. }
  7066. }
  7067. rcu_read_unlock();
  7068. /* following stats updated by ixgbe_watchdog_task() */
  7069. stats->multicast = netdev->stats.multicast;
  7070. stats->rx_errors = netdev->stats.rx_errors;
  7071. stats->rx_length_errors = netdev->stats.rx_length_errors;
  7072. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  7073. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  7074. }
  7075. #ifdef CONFIG_IXGBE_DCB
  7076. /**
  7077. * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
  7078. * @adapter: pointer to ixgbe_adapter
  7079. * @tc: number of traffic classes currently enabled
  7080. *
  7081. * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
  7082. * 802.1Q priority maps to a packet buffer that exists.
  7083. */
  7084. static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
  7085. {
  7086. struct ixgbe_hw *hw = &adapter->hw;
  7087. u32 reg, rsave;
  7088. int i;
  7089. /* 82598 have a static priority to TC mapping that can not
  7090. * be changed so no validation is needed.
  7091. */
  7092. if (hw->mac.type == ixgbe_mac_82598EB)
  7093. return;
  7094. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  7095. rsave = reg;
  7096. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  7097. u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
  7098. /* If up2tc is out of bounds default to zero */
  7099. if (up2tc > tc)
  7100. reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
  7101. }
  7102. if (reg != rsave)
  7103. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  7104. return;
  7105. }
  7106. /**
  7107. * ixgbe_set_prio_tc_map - Configure netdev prio tc map
  7108. * @adapter: Pointer to adapter struct
  7109. *
  7110. * Populate the netdev user priority to tc map
  7111. */
  7112. static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
  7113. {
  7114. struct net_device *dev = adapter->netdev;
  7115. struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
  7116. struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
  7117. u8 prio;
  7118. for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
  7119. u8 tc = 0;
  7120. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
  7121. tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
  7122. else if (ets)
  7123. tc = ets->prio_tc[prio];
  7124. netdev_set_prio_tc_map(dev, prio, tc);
  7125. }
  7126. }
  7127. #endif /* CONFIG_IXGBE_DCB */
  7128. /**
  7129. * ixgbe_setup_tc - configure net_device for multiple traffic classes
  7130. *
  7131. * @netdev: net device to configure
  7132. * @tc: number of traffic classes to enable
  7133. */
  7134. int ixgbe_setup_tc(struct net_device *dev, u8 tc)
  7135. {
  7136. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7137. struct ixgbe_hw *hw = &adapter->hw;
  7138. bool pools;
  7139. /* Hardware supports up to 8 traffic classes */
  7140. if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
  7141. return -EINVAL;
  7142. if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
  7143. return -EINVAL;
  7144. pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
  7145. if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS)
  7146. return -EBUSY;
  7147. /* Hardware has to reinitialize queues and interrupts to
  7148. * match packet buffer alignment. Unfortunately, the
  7149. * hardware is not flexible enough to do this dynamically.
  7150. */
  7151. if (netif_running(dev))
  7152. ixgbe_close(dev);
  7153. else
  7154. ixgbe_reset(adapter);
  7155. ixgbe_clear_interrupt_scheme(adapter);
  7156. #ifdef CONFIG_IXGBE_DCB
  7157. if (tc) {
  7158. netdev_set_num_tc(dev, tc);
  7159. ixgbe_set_prio_tc_map(adapter);
  7160. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  7161. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  7162. adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
  7163. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  7164. }
  7165. } else {
  7166. netdev_reset_tc(dev);
  7167. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  7168. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  7169. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  7170. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  7171. adapter->dcb_cfg.pfc_mode_enable = false;
  7172. }
  7173. ixgbe_validate_rtr(adapter, tc);
  7174. #endif /* CONFIG_IXGBE_DCB */
  7175. ixgbe_init_interrupt_scheme(adapter);
  7176. if (netif_running(dev))
  7177. return ixgbe_open(dev);
  7178. return 0;
  7179. }
  7180. static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
  7181. struct tc_cls_u32_offload *cls)
  7182. {
  7183. u32 hdl = cls->knode.handle;
  7184. u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
  7185. u32 loc = cls->knode.handle & 0xfffff;
  7186. int err = 0, i, j;
  7187. struct ixgbe_jump_table *jump = NULL;
  7188. if (loc > IXGBE_MAX_HW_ENTRIES)
  7189. return -EINVAL;
  7190. if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
  7191. return -EINVAL;
  7192. /* Clear this filter in the link data it is associated with */
  7193. if (uhtid != 0x800) {
  7194. jump = adapter->jump_tables[uhtid];
  7195. if (!jump)
  7196. return -EINVAL;
  7197. if (!test_bit(loc - 1, jump->child_loc_map))
  7198. return -EINVAL;
  7199. clear_bit(loc - 1, jump->child_loc_map);
  7200. }
  7201. /* Check if the filter being deleted is a link */
  7202. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7203. jump = adapter->jump_tables[i];
  7204. if (jump && jump->link_hdl == hdl) {
  7205. /* Delete filters in the hardware in the child hash
  7206. * table associated with this link
  7207. */
  7208. for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
  7209. if (!test_bit(j, jump->child_loc_map))
  7210. continue;
  7211. spin_lock(&adapter->fdir_perfect_lock);
  7212. err = ixgbe_update_ethtool_fdir_entry(adapter,
  7213. NULL,
  7214. j + 1);
  7215. spin_unlock(&adapter->fdir_perfect_lock);
  7216. clear_bit(j, jump->child_loc_map);
  7217. }
  7218. /* Remove resources for this link */
  7219. kfree(jump->input);
  7220. kfree(jump->mask);
  7221. kfree(jump);
  7222. adapter->jump_tables[i] = NULL;
  7223. return err;
  7224. }
  7225. }
  7226. spin_lock(&adapter->fdir_perfect_lock);
  7227. err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
  7228. spin_unlock(&adapter->fdir_perfect_lock);
  7229. return err;
  7230. }
  7231. static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
  7232. __be16 protocol,
  7233. struct tc_cls_u32_offload *cls)
  7234. {
  7235. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7236. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7237. return -EINVAL;
  7238. /* This ixgbe devices do not support hash tables at the moment
  7239. * so abort when given hash tables.
  7240. */
  7241. if (cls->hnode.divisor > 0)
  7242. return -EINVAL;
  7243. set_bit(uhtid - 1, &adapter->tables);
  7244. return 0;
  7245. }
  7246. static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
  7247. struct tc_cls_u32_offload *cls)
  7248. {
  7249. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7250. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7251. return -EINVAL;
  7252. clear_bit(uhtid - 1, &adapter->tables);
  7253. return 0;
  7254. }
  7255. #ifdef CONFIG_NET_CLS_ACT
  7256. struct upper_walk_data {
  7257. struct ixgbe_adapter *adapter;
  7258. u64 action;
  7259. int ifindex;
  7260. u8 queue;
  7261. };
  7262. static int get_macvlan_queue(struct net_device *upper, void *_data)
  7263. {
  7264. if (netif_is_macvlan(upper)) {
  7265. struct macvlan_dev *dfwd = netdev_priv(upper);
  7266. struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv;
  7267. struct upper_walk_data *data = _data;
  7268. struct ixgbe_adapter *adapter = data->adapter;
  7269. int ifindex = data->ifindex;
  7270. if (vadapter && vadapter->netdev->ifindex == ifindex) {
  7271. data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
  7272. data->action = data->queue;
  7273. return 1;
  7274. }
  7275. }
  7276. return 0;
  7277. }
  7278. static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
  7279. u8 *queue, u64 *action)
  7280. {
  7281. unsigned int num_vfs = adapter->num_vfs, vf;
  7282. struct upper_walk_data data;
  7283. struct net_device *upper;
  7284. /* redirect to a SRIOV VF */
  7285. for (vf = 0; vf < num_vfs; ++vf) {
  7286. upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
  7287. if (upper->ifindex == ifindex) {
  7288. if (adapter->num_rx_pools > 1)
  7289. *queue = vf * 2;
  7290. else
  7291. *queue = vf * adapter->num_rx_queues_per_pool;
  7292. *action = vf + 1;
  7293. *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
  7294. return 0;
  7295. }
  7296. }
  7297. /* redirect to a offloaded macvlan netdev */
  7298. data.adapter = adapter;
  7299. data.ifindex = ifindex;
  7300. data.action = 0;
  7301. data.queue = 0;
  7302. if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
  7303. get_macvlan_queue, &data)) {
  7304. *action = data.action;
  7305. *queue = data.queue;
  7306. return 0;
  7307. }
  7308. return -EINVAL;
  7309. }
  7310. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7311. struct tcf_exts *exts, u64 *action, u8 *queue)
  7312. {
  7313. const struct tc_action *a;
  7314. LIST_HEAD(actions);
  7315. int err;
  7316. if (tc_no_actions(exts))
  7317. return -EINVAL;
  7318. tcf_exts_to_list(exts, &actions);
  7319. list_for_each_entry(a, &actions, list) {
  7320. /* Drop action */
  7321. if (is_tcf_gact_shot(a)) {
  7322. *action = IXGBE_FDIR_DROP_QUEUE;
  7323. *queue = IXGBE_FDIR_DROP_QUEUE;
  7324. return 0;
  7325. }
  7326. /* Redirect to a VF or a offloaded macvlan */
  7327. if (is_tcf_mirred_egress_redirect(a)) {
  7328. int ifindex = tcf_mirred_ifindex(a);
  7329. err = handle_redirect_action(adapter, ifindex, queue,
  7330. action);
  7331. if (err == 0)
  7332. return err;
  7333. }
  7334. }
  7335. return -EINVAL;
  7336. }
  7337. #else
  7338. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7339. struct tcf_exts *exts, u64 *action, u8 *queue)
  7340. {
  7341. return -EINVAL;
  7342. }
  7343. #endif /* CONFIG_NET_CLS_ACT */
  7344. static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
  7345. union ixgbe_atr_input *mask,
  7346. struct tc_cls_u32_offload *cls,
  7347. struct ixgbe_mat_field *field_ptr,
  7348. struct ixgbe_nexthdr *nexthdr)
  7349. {
  7350. int i, j, off;
  7351. __be32 val, m;
  7352. bool found_entry = false, found_jump_field = false;
  7353. for (i = 0; i < cls->knode.sel->nkeys; i++) {
  7354. off = cls->knode.sel->keys[i].off;
  7355. val = cls->knode.sel->keys[i].val;
  7356. m = cls->knode.sel->keys[i].mask;
  7357. for (j = 0; field_ptr[j].val; j++) {
  7358. if (field_ptr[j].off == off) {
  7359. field_ptr[j].val(input, mask, val, m);
  7360. input->filter.formatted.flow_type |=
  7361. field_ptr[j].type;
  7362. found_entry = true;
  7363. break;
  7364. }
  7365. }
  7366. if (nexthdr) {
  7367. if (nexthdr->off == cls->knode.sel->keys[i].off &&
  7368. nexthdr->val == cls->knode.sel->keys[i].val &&
  7369. nexthdr->mask == cls->knode.sel->keys[i].mask)
  7370. found_jump_field = true;
  7371. else
  7372. continue;
  7373. }
  7374. }
  7375. if (nexthdr && !found_jump_field)
  7376. return -EINVAL;
  7377. if (!found_entry)
  7378. return 0;
  7379. mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
  7380. IXGBE_ATR_L4TYPE_MASK;
  7381. if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
  7382. mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
  7383. return 0;
  7384. }
  7385. static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  7386. __be16 protocol,
  7387. struct tc_cls_u32_offload *cls)
  7388. {
  7389. u32 loc = cls->knode.handle & 0xfffff;
  7390. struct ixgbe_hw *hw = &adapter->hw;
  7391. struct ixgbe_mat_field *field_ptr;
  7392. struct ixgbe_fdir_filter *input = NULL;
  7393. union ixgbe_atr_input *mask = NULL;
  7394. struct ixgbe_jump_table *jump = NULL;
  7395. int i, err = -EINVAL;
  7396. u8 queue;
  7397. u32 uhtid, link_uhtid;
  7398. uhtid = TC_U32_USERHTID(cls->knode.handle);
  7399. link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
  7400. /* At the moment cls_u32 jumps to network layer and skips past
  7401. * L2 headers. The canonical method to match L2 frames is to use
  7402. * negative values. However this is error prone at best but really
  7403. * just broken because there is no way to "know" what sort of hdr
  7404. * is in front of the network layer. Fix cls_u32 to support L2
  7405. * headers when needed.
  7406. */
  7407. if (protocol != htons(ETH_P_IP))
  7408. return err;
  7409. if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
  7410. e_err(drv, "Location out of range\n");
  7411. return err;
  7412. }
  7413. /* cls u32 is a graph starting at root node 0x800. The driver tracks
  7414. * links and also the fields used to advance the parser across each
  7415. * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
  7416. * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
  7417. * To add support for new nodes update ixgbe_model.h parse structures
  7418. * this function _should_ be generic try not to hardcode values here.
  7419. */
  7420. if (uhtid == 0x800) {
  7421. field_ptr = (adapter->jump_tables[0])->mat;
  7422. } else {
  7423. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7424. return err;
  7425. if (!adapter->jump_tables[uhtid])
  7426. return err;
  7427. field_ptr = (adapter->jump_tables[uhtid])->mat;
  7428. }
  7429. if (!field_ptr)
  7430. return err;
  7431. /* At this point we know the field_ptr is valid and need to either
  7432. * build cls_u32 link or attach filter. Because adding a link to
  7433. * a handle that does not exist is invalid and the same for adding
  7434. * rules to handles that don't exist.
  7435. */
  7436. if (link_uhtid) {
  7437. struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
  7438. if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
  7439. return err;
  7440. if (!test_bit(link_uhtid - 1, &adapter->tables))
  7441. return err;
  7442. /* Multiple filters as links to the same hash table are not
  7443. * supported. To add a new filter with the same next header
  7444. * but different match/jump conditions, create a new hash table
  7445. * and link to it.
  7446. */
  7447. if (adapter->jump_tables[link_uhtid] &&
  7448. (adapter->jump_tables[link_uhtid])->link_hdl) {
  7449. e_err(drv, "Link filter exists for link: %x\n",
  7450. link_uhtid);
  7451. return err;
  7452. }
  7453. for (i = 0; nexthdr[i].jump; i++) {
  7454. if (nexthdr[i].o != cls->knode.sel->offoff ||
  7455. nexthdr[i].s != cls->knode.sel->offshift ||
  7456. nexthdr[i].m != cls->knode.sel->offmask)
  7457. return err;
  7458. jump = kzalloc(sizeof(*jump), GFP_KERNEL);
  7459. if (!jump)
  7460. return -ENOMEM;
  7461. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7462. if (!input) {
  7463. err = -ENOMEM;
  7464. goto free_jump;
  7465. }
  7466. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7467. if (!mask) {
  7468. err = -ENOMEM;
  7469. goto free_input;
  7470. }
  7471. jump->input = input;
  7472. jump->mask = mask;
  7473. jump->link_hdl = cls->knode.handle;
  7474. err = ixgbe_clsu32_build_input(input, mask, cls,
  7475. field_ptr, &nexthdr[i]);
  7476. if (!err) {
  7477. jump->mat = nexthdr[i].jump;
  7478. adapter->jump_tables[link_uhtid] = jump;
  7479. break;
  7480. }
  7481. }
  7482. return 0;
  7483. }
  7484. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7485. if (!input)
  7486. return -ENOMEM;
  7487. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7488. if (!mask) {
  7489. err = -ENOMEM;
  7490. goto free_input;
  7491. }
  7492. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
  7493. if ((adapter->jump_tables[uhtid])->input)
  7494. memcpy(input, (adapter->jump_tables[uhtid])->input,
  7495. sizeof(*input));
  7496. if ((adapter->jump_tables[uhtid])->mask)
  7497. memcpy(mask, (adapter->jump_tables[uhtid])->mask,
  7498. sizeof(*mask));
  7499. /* Lookup in all child hash tables if this location is already
  7500. * filled with a filter
  7501. */
  7502. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7503. struct ixgbe_jump_table *link = adapter->jump_tables[i];
  7504. if (link && (test_bit(loc - 1, link->child_loc_map))) {
  7505. e_err(drv, "Filter exists in location: %x\n",
  7506. loc);
  7507. err = -EINVAL;
  7508. goto err_out;
  7509. }
  7510. }
  7511. }
  7512. err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
  7513. if (err)
  7514. goto err_out;
  7515. err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
  7516. &queue);
  7517. if (err < 0)
  7518. goto err_out;
  7519. input->sw_idx = loc;
  7520. spin_lock(&adapter->fdir_perfect_lock);
  7521. if (hlist_empty(&adapter->fdir_filter_list)) {
  7522. memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
  7523. err = ixgbe_fdir_set_input_mask_82599(hw, mask);
  7524. if (err)
  7525. goto err_out_w_lock;
  7526. } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
  7527. err = -EINVAL;
  7528. goto err_out_w_lock;
  7529. }
  7530. ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
  7531. err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
  7532. input->sw_idx, queue);
  7533. if (!err)
  7534. ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
  7535. spin_unlock(&adapter->fdir_perfect_lock);
  7536. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
  7537. set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
  7538. kfree(mask);
  7539. return err;
  7540. err_out_w_lock:
  7541. spin_unlock(&adapter->fdir_perfect_lock);
  7542. err_out:
  7543. kfree(mask);
  7544. free_input:
  7545. kfree(input);
  7546. free_jump:
  7547. kfree(jump);
  7548. return err;
  7549. }
  7550. static int __ixgbe_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
  7551. struct tc_to_netdev *tc)
  7552. {
  7553. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7554. if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
  7555. tc->type == TC_SETUP_CLSU32) {
  7556. switch (tc->cls_u32->command) {
  7557. case TC_CLSU32_NEW_KNODE:
  7558. case TC_CLSU32_REPLACE_KNODE:
  7559. return ixgbe_configure_clsu32(adapter,
  7560. proto, tc->cls_u32);
  7561. case TC_CLSU32_DELETE_KNODE:
  7562. return ixgbe_delete_clsu32(adapter, tc->cls_u32);
  7563. case TC_CLSU32_NEW_HNODE:
  7564. case TC_CLSU32_REPLACE_HNODE:
  7565. return ixgbe_configure_clsu32_add_hnode(adapter, proto,
  7566. tc->cls_u32);
  7567. case TC_CLSU32_DELETE_HNODE:
  7568. return ixgbe_configure_clsu32_del_hnode(adapter,
  7569. tc->cls_u32);
  7570. default:
  7571. return -EINVAL;
  7572. }
  7573. }
  7574. if (tc->type != TC_SETUP_MQPRIO)
  7575. return -EINVAL;
  7576. tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  7577. return ixgbe_setup_tc(dev, tc->mqprio->num_tc);
  7578. }
  7579. #ifdef CONFIG_PCI_IOV
  7580. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
  7581. {
  7582. struct net_device *netdev = adapter->netdev;
  7583. rtnl_lock();
  7584. ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
  7585. rtnl_unlock();
  7586. }
  7587. #endif
  7588. void ixgbe_do_reset(struct net_device *netdev)
  7589. {
  7590. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7591. if (netif_running(netdev))
  7592. ixgbe_reinit_locked(adapter);
  7593. else
  7594. ixgbe_reset(adapter);
  7595. }
  7596. static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
  7597. netdev_features_t features)
  7598. {
  7599. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7600. /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
  7601. if (!(features & NETIF_F_RXCSUM))
  7602. features &= ~NETIF_F_LRO;
  7603. /* Turn off LRO if not RSC capable */
  7604. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  7605. features &= ~NETIF_F_LRO;
  7606. return features;
  7607. }
  7608. static int ixgbe_set_features(struct net_device *netdev,
  7609. netdev_features_t features)
  7610. {
  7611. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7612. netdev_features_t changed = netdev->features ^ features;
  7613. bool need_reset = false;
  7614. /* Make sure RSC matches LRO, reset if change */
  7615. if (!(features & NETIF_F_LRO)) {
  7616. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  7617. need_reset = true;
  7618. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  7619. } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  7620. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  7621. if (adapter->rx_itr_setting == 1 ||
  7622. adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
  7623. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  7624. need_reset = true;
  7625. } else if ((changed ^ features) & NETIF_F_LRO) {
  7626. e_info(probe, "rx-usecs set too low, "
  7627. "disabling RSC\n");
  7628. }
  7629. }
  7630. /*
  7631. * Check if Flow Director n-tuple support or hw_tc support was
  7632. * enabled or disabled. If the state changed, we need to reset.
  7633. */
  7634. if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
  7635. /* turn off ATR, enable perfect filters and reset */
  7636. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  7637. need_reset = true;
  7638. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  7639. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  7640. } else {
  7641. /* turn off perfect filters, enable ATR and reset */
  7642. if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  7643. need_reset = true;
  7644. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  7645. /* We cannot enable ATR if SR-IOV is enabled */
  7646. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
  7647. /* We cannot enable ATR if we have 2 or more tcs */
  7648. (netdev_get_num_tc(netdev) > 1) ||
  7649. /* We cannot enable ATR if RSS is disabled */
  7650. (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
  7651. /* A sample rate of 0 indicates ATR disabled */
  7652. (!adapter->atr_sample_rate))
  7653. ; /* do nothing not supported */
  7654. else /* otherwise supported and set the flag */
  7655. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  7656. }
  7657. if (changed & NETIF_F_RXALL)
  7658. need_reset = true;
  7659. netdev->features = features;
  7660. if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
  7661. if (features & NETIF_F_RXCSUM) {
  7662. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  7663. } else {
  7664. u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  7665. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  7666. }
  7667. }
  7668. if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
  7669. if (features & NETIF_F_RXCSUM) {
  7670. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  7671. } else {
  7672. u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  7673. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  7674. }
  7675. }
  7676. if (need_reset)
  7677. ixgbe_do_reset(netdev);
  7678. else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
  7679. NETIF_F_HW_VLAN_CTAG_FILTER))
  7680. ixgbe_set_rx_mode(netdev);
  7681. return 0;
  7682. }
  7683. /**
  7684. * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
  7685. * @dev: The port's netdev
  7686. * @ti: Tunnel endpoint information
  7687. **/
  7688. static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
  7689. struct udp_tunnel_info *ti)
  7690. {
  7691. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7692. struct ixgbe_hw *hw = &adapter->hw;
  7693. __be16 port = ti->port;
  7694. u32 port_shift = 0;
  7695. u32 reg;
  7696. if (ti->sa_family != AF_INET)
  7697. return;
  7698. switch (ti->type) {
  7699. case UDP_TUNNEL_TYPE_VXLAN:
  7700. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  7701. return;
  7702. if (adapter->vxlan_port == port)
  7703. return;
  7704. if (adapter->vxlan_port) {
  7705. netdev_info(dev,
  7706. "VXLAN port %d set, not adding port %d\n",
  7707. ntohs(adapter->vxlan_port),
  7708. ntohs(port));
  7709. return;
  7710. }
  7711. adapter->vxlan_port = port;
  7712. break;
  7713. case UDP_TUNNEL_TYPE_GENEVE:
  7714. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7715. return;
  7716. if (adapter->geneve_port == port)
  7717. return;
  7718. if (adapter->geneve_port) {
  7719. netdev_info(dev,
  7720. "GENEVE port %d set, not adding port %d\n",
  7721. ntohs(adapter->geneve_port),
  7722. ntohs(port));
  7723. return;
  7724. }
  7725. port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
  7726. adapter->geneve_port = port;
  7727. break;
  7728. default:
  7729. return;
  7730. }
  7731. reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
  7732. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
  7733. }
  7734. /**
  7735. * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
  7736. * @dev: The port's netdev
  7737. * @ti: Tunnel endpoint information
  7738. **/
  7739. static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
  7740. struct udp_tunnel_info *ti)
  7741. {
  7742. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7743. u32 port_mask;
  7744. if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
  7745. ti->type != UDP_TUNNEL_TYPE_GENEVE)
  7746. return;
  7747. if (ti->sa_family != AF_INET)
  7748. return;
  7749. switch (ti->type) {
  7750. case UDP_TUNNEL_TYPE_VXLAN:
  7751. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  7752. return;
  7753. if (adapter->vxlan_port != ti->port) {
  7754. netdev_info(dev, "VXLAN port %d not found\n",
  7755. ntohs(ti->port));
  7756. return;
  7757. }
  7758. port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  7759. break;
  7760. case UDP_TUNNEL_TYPE_GENEVE:
  7761. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7762. return;
  7763. if (adapter->geneve_port != ti->port) {
  7764. netdev_info(dev, "GENEVE port %d not found\n",
  7765. ntohs(ti->port));
  7766. return;
  7767. }
  7768. port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  7769. break;
  7770. default:
  7771. return;
  7772. }
  7773. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  7774. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  7775. }
  7776. static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  7777. struct net_device *dev,
  7778. const unsigned char *addr, u16 vid,
  7779. u16 flags)
  7780. {
  7781. /* guarantee we can provide a unique filter for the unicast address */
  7782. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
  7783. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7784. u16 pool = VMDQ_P(0);
  7785. if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
  7786. return -ENOMEM;
  7787. }
  7788. return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
  7789. }
  7790. /**
  7791. * ixgbe_configure_bridge_mode - set various bridge modes
  7792. * @adapter - the private structure
  7793. * @mode - requested bridge mode
  7794. *
  7795. * Configure some settings require for various bridge modes.
  7796. **/
  7797. static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
  7798. __u16 mode)
  7799. {
  7800. struct ixgbe_hw *hw = &adapter->hw;
  7801. unsigned int p, num_pools;
  7802. u32 vmdctl;
  7803. switch (mode) {
  7804. case BRIDGE_MODE_VEPA:
  7805. /* disable Tx loopback, rely on switch hairpin mode */
  7806. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
  7807. /* must enable Rx switching replication to allow multicast
  7808. * packet reception on all VFs, and to enable source address
  7809. * pruning.
  7810. */
  7811. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  7812. vmdctl |= IXGBE_VT_CTL_REPLEN;
  7813. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  7814. /* enable Rx source address pruning. Note, this requires
  7815. * replication to be enabled or else it does nothing.
  7816. */
  7817. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  7818. for (p = 0; p < num_pools; p++) {
  7819. if (hw->mac.ops.set_source_address_pruning)
  7820. hw->mac.ops.set_source_address_pruning(hw,
  7821. true,
  7822. p);
  7823. }
  7824. break;
  7825. case BRIDGE_MODE_VEB:
  7826. /* enable Tx loopback for internal VF/PF communication */
  7827. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
  7828. IXGBE_PFDTXGSWC_VT_LBEN);
  7829. /* disable Rx switching replication unless we have SR-IOV
  7830. * virtual functions
  7831. */
  7832. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  7833. if (!adapter->num_vfs)
  7834. vmdctl &= ~IXGBE_VT_CTL_REPLEN;
  7835. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  7836. /* disable Rx source address pruning, since we don't expect to
  7837. * be receiving external loopback of our transmitted frames.
  7838. */
  7839. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  7840. for (p = 0; p < num_pools; p++) {
  7841. if (hw->mac.ops.set_source_address_pruning)
  7842. hw->mac.ops.set_source_address_pruning(hw,
  7843. false,
  7844. p);
  7845. }
  7846. break;
  7847. default:
  7848. return -EINVAL;
  7849. }
  7850. adapter->bridge_mode = mode;
  7851. e_info(drv, "enabling bridge mode: %s\n",
  7852. mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  7853. return 0;
  7854. }
  7855. static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
  7856. struct nlmsghdr *nlh, u16 flags)
  7857. {
  7858. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7859. struct nlattr *attr, *br_spec;
  7860. int rem;
  7861. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  7862. return -EOPNOTSUPP;
  7863. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  7864. if (!br_spec)
  7865. return -EINVAL;
  7866. nla_for_each_nested(attr, br_spec, rem) {
  7867. int status;
  7868. __u16 mode;
  7869. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  7870. continue;
  7871. if (nla_len(attr) < sizeof(mode))
  7872. return -EINVAL;
  7873. mode = nla_get_u16(attr);
  7874. status = ixgbe_configure_bridge_mode(adapter, mode);
  7875. if (status)
  7876. return status;
  7877. break;
  7878. }
  7879. return 0;
  7880. }
  7881. static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  7882. struct net_device *dev,
  7883. u32 filter_mask, int nlflags)
  7884. {
  7885. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7886. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  7887. return 0;
  7888. return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
  7889. adapter->bridge_mode, 0, 0, nlflags,
  7890. filter_mask, NULL);
  7891. }
  7892. static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
  7893. {
  7894. struct ixgbe_fwd_adapter *fwd_adapter = NULL;
  7895. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  7896. int used_pools = adapter->num_vfs + adapter->num_rx_pools;
  7897. unsigned int limit;
  7898. int pool, err;
  7899. /* Hardware has a limited number of available pools. Each VF, and the
  7900. * PF require a pool. Check to ensure we don't attempt to use more
  7901. * then the available number of pools.
  7902. */
  7903. if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
  7904. return ERR_PTR(-EINVAL);
  7905. #ifdef CONFIG_RPS
  7906. if (vdev->num_rx_queues != vdev->num_tx_queues) {
  7907. netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n",
  7908. vdev->name);
  7909. return ERR_PTR(-EINVAL);
  7910. }
  7911. #endif
  7912. /* Check for hardware restriction on number of rx/tx queues */
  7913. if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES ||
  7914. vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) {
  7915. netdev_info(pdev,
  7916. "%s: Supports RX/TX Queue counts 1,2, and 4\n",
  7917. pdev->name);
  7918. return ERR_PTR(-EINVAL);
  7919. }
  7920. if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  7921. adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) ||
  7922. (adapter->num_rx_pools > IXGBE_MAX_MACVLANS))
  7923. return ERR_PTR(-EBUSY);
  7924. fwd_adapter = kzalloc(sizeof(*fwd_adapter), GFP_KERNEL);
  7925. if (!fwd_adapter)
  7926. return ERR_PTR(-ENOMEM);
  7927. pool = find_first_zero_bit(&adapter->fwd_bitmask, 32);
  7928. adapter->num_rx_pools++;
  7929. set_bit(pool, &adapter->fwd_bitmask);
  7930. limit = find_last_bit(&adapter->fwd_bitmask, 32);
  7931. /* Enable VMDq flag so device will be set in VM mode */
  7932. adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED;
  7933. adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
  7934. adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues;
  7935. /* Force reinit of ring allocation with VMDQ enabled */
  7936. err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
  7937. if (err)
  7938. goto fwd_add_err;
  7939. fwd_adapter->pool = pool;
  7940. fwd_adapter->real_adapter = adapter;
  7941. if (netif_running(pdev)) {
  7942. err = ixgbe_fwd_ring_up(vdev, fwd_adapter);
  7943. if (err)
  7944. goto fwd_add_err;
  7945. netif_tx_start_all_queues(vdev);
  7946. }
  7947. return fwd_adapter;
  7948. fwd_add_err:
  7949. /* unwind counter and free adapter struct */
  7950. netdev_info(pdev,
  7951. "%s: dfwd hardware acceleration failed\n", vdev->name);
  7952. clear_bit(pool, &adapter->fwd_bitmask);
  7953. adapter->num_rx_pools--;
  7954. kfree(fwd_adapter);
  7955. return ERR_PTR(err);
  7956. }
  7957. static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
  7958. {
  7959. struct ixgbe_fwd_adapter *fwd_adapter = priv;
  7960. struct ixgbe_adapter *adapter = fwd_adapter->real_adapter;
  7961. unsigned int limit;
  7962. clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask);
  7963. adapter->num_rx_pools--;
  7964. limit = find_last_bit(&adapter->fwd_bitmask, 32);
  7965. adapter->ring_feature[RING_F_VMDQ].limit = limit + 1;
  7966. ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter);
  7967. ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev));
  7968. netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n",
  7969. fwd_adapter->pool, adapter->num_rx_pools,
  7970. fwd_adapter->rx_base_queue,
  7971. fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool,
  7972. adapter->fwd_bitmask);
  7973. kfree(fwd_adapter);
  7974. }
  7975. #define IXGBE_MAX_MAC_HDR_LEN 127
  7976. #define IXGBE_MAX_NETWORK_HDR_LEN 511
  7977. static netdev_features_t
  7978. ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
  7979. netdev_features_t features)
  7980. {
  7981. unsigned int network_hdr_len, mac_hdr_len;
  7982. /* Make certain the headers can be described by a context descriptor */
  7983. mac_hdr_len = skb_network_header(skb) - skb->data;
  7984. if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
  7985. return features & ~(NETIF_F_HW_CSUM |
  7986. NETIF_F_SCTP_CRC |
  7987. NETIF_F_HW_VLAN_CTAG_TX |
  7988. NETIF_F_TSO |
  7989. NETIF_F_TSO6);
  7990. network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
  7991. if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
  7992. return features & ~(NETIF_F_HW_CSUM |
  7993. NETIF_F_SCTP_CRC |
  7994. NETIF_F_TSO |
  7995. NETIF_F_TSO6);
  7996. /* We can only support IPV4 TSO in tunnels if we can mangle the
  7997. * inner IP ID field, so strip TSO if MANGLEID is not supported.
  7998. */
  7999. if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID))
  8000. features &= ~NETIF_F_TSO;
  8001. return features;
  8002. }
  8003. static const struct net_device_ops ixgbe_netdev_ops = {
  8004. .ndo_open = ixgbe_open,
  8005. .ndo_stop = ixgbe_close,
  8006. .ndo_start_xmit = ixgbe_xmit_frame,
  8007. .ndo_select_queue = ixgbe_select_queue,
  8008. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  8009. .ndo_validate_addr = eth_validate_addr,
  8010. .ndo_set_mac_address = ixgbe_set_mac,
  8011. .ndo_change_mtu = ixgbe_change_mtu,
  8012. .ndo_tx_timeout = ixgbe_tx_timeout,
  8013. .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
  8014. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  8015. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  8016. .ndo_do_ioctl = ixgbe_ioctl,
  8017. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  8018. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  8019. .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
  8020. .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
  8021. .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
  8022. .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
  8023. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  8024. .ndo_get_stats64 = ixgbe_get_stats64,
  8025. .ndo_setup_tc = __ixgbe_setup_tc,
  8026. #ifdef CONFIG_NET_POLL_CONTROLLER
  8027. .ndo_poll_controller = ixgbe_netpoll,
  8028. #endif
  8029. #ifdef IXGBE_FCOE
  8030. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  8031. .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
  8032. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  8033. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  8034. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  8035. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  8036. .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
  8037. #endif /* IXGBE_FCOE */
  8038. .ndo_set_features = ixgbe_set_features,
  8039. .ndo_fix_features = ixgbe_fix_features,
  8040. .ndo_fdb_add = ixgbe_ndo_fdb_add,
  8041. .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
  8042. .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
  8043. .ndo_dfwd_add_station = ixgbe_fwd_add,
  8044. .ndo_dfwd_del_station = ixgbe_fwd_del,
  8045. .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
  8046. .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
  8047. .ndo_features_check = ixgbe_features_check,
  8048. };
  8049. /**
  8050. * ixgbe_enumerate_functions - Get the number of ports this device has
  8051. * @adapter: adapter structure
  8052. *
  8053. * This function enumerates the phsyical functions co-located on a single slot,
  8054. * in order to determine how many ports a device has. This is most useful in
  8055. * determining the required GT/s of PCIe bandwidth necessary for optimal
  8056. * performance.
  8057. **/
  8058. static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
  8059. {
  8060. struct pci_dev *entry, *pdev = adapter->pdev;
  8061. int physfns = 0;
  8062. /* Some cards can not use the generic count PCIe functions method,
  8063. * because they are behind a parent switch, so we hardcode these with
  8064. * the correct number of functions.
  8065. */
  8066. if (ixgbe_pcie_from_parent(&adapter->hw))
  8067. physfns = 4;
  8068. list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
  8069. /* don't count virtual functions */
  8070. if (entry->is_virtfn)
  8071. continue;
  8072. /* When the devices on the bus don't all match our device ID,
  8073. * we can't reliably determine the correct number of
  8074. * functions. This can occur if a function has been direct
  8075. * attached to a virtual machine using VT-d, for example. In
  8076. * this case, simply return -1 to indicate this.
  8077. */
  8078. if ((entry->vendor != pdev->vendor) ||
  8079. (entry->device != pdev->device))
  8080. return -1;
  8081. physfns++;
  8082. }
  8083. return physfns;
  8084. }
  8085. /**
  8086. * ixgbe_wol_supported - Check whether device supports WoL
  8087. * @adapter: the adapter private structure
  8088. * @device_id: the device ID
  8089. * @subdev_id: the subsystem device ID
  8090. *
  8091. * This function is used by probe and ethtool to determine
  8092. * which devices have WoL support
  8093. *
  8094. **/
  8095. bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  8096. u16 subdevice_id)
  8097. {
  8098. struct ixgbe_hw *hw = &adapter->hw;
  8099. u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
  8100. /* WOL not supported on 82598 */
  8101. if (hw->mac.type == ixgbe_mac_82598EB)
  8102. return false;
  8103. /* check eeprom to see if WOL is enabled for X540 and newer */
  8104. if (hw->mac.type >= ixgbe_mac_X540) {
  8105. if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
  8106. ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
  8107. (hw->bus.func == 0)))
  8108. return true;
  8109. }
  8110. /* WOL is determined based on device IDs for 82599 MACs */
  8111. switch (device_id) {
  8112. case IXGBE_DEV_ID_82599_SFP:
  8113. /* Only these subdevices could supports WOL */
  8114. switch (subdevice_id) {
  8115. case IXGBE_SUBDEV_ID_82599_560FLR:
  8116. case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
  8117. case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
  8118. case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
  8119. /* only support first port */
  8120. if (hw->bus.func != 0)
  8121. break;
  8122. case IXGBE_SUBDEV_ID_82599_SP_560FLR:
  8123. case IXGBE_SUBDEV_ID_82599_SFP:
  8124. case IXGBE_SUBDEV_ID_82599_RNDC:
  8125. case IXGBE_SUBDEV_ID_82599_ECNA_DP:
  8126. case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
  8127. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
  8128. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
  8129. return true;
  8130. }
  8131. break;
  8132. case IXGBE_DEV_ID_82599EN_SFP:
  8133. /* Only these subdevices support WOL */
  8134. switch (subdevice_id) {
  8135. case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
  8136. return true;
  8137. }
  8138. break;
  8139. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  8140. /* All except this subdevice support WOL */
  8141. if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
  8142. return true;
  8143. break;
  8144. case IXGBE_DEV_ID_82599_KX4:
  8145. return true;
  8146. default:
  8147. break;
  8148. }
  8149. return false;
  8150. }
  8151. /**
  8152. * ixgbe_probe - Device Initialization Routine
  8153. * @pdev: PCI device information struct
  8154. * @ent: entry in ixgbe_pci_tbl
  8155. *
  8156. * Returns 0 on success, negative on failure
  8157. *
  8158. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  8159. * The OS initialization, configuring of the adapter private structure,
  8160. * and a hardware reset occur.
  8161. **/
  8162. static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  8163. {
  8164. struct net_device *netdev;
  8165. struct ixgbe_adapter *adapter = NULL;
  8166. struct ixgbe_hw *hw;
  8167. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  8168. int i, err, pci_using_dac, expected_gts;
  8169. unsigned int indices = MAX_TX_QUEUES;
  8170. u8 part_str[IXGBE_PBANUM_LENGTH];
  8171. bool disable_dev = false;
  8172. #ifdef IXGBE_FCOE
  8173. u16 device_caps;
  8174. #endif
  8175. u32 eec;
  8176. /* Catch broken hardware that put the wrong VF device ID in
  8177. * the PCIe SR-IOV capability.
  8178. */
  8179. if (pdev->is_virtfn) {
  8180. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  8181. pci_name(pdev), pdev->vendor, pdev->device);
  8182. return -EINVAL;
  8183. }
  8184. err = pci_enable_device_mem(pdev);
  8185. if (err)
  8186. return err;
  8187. if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
  8188. pci_using_dac = 1;
  8189. } else {
  8190. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  8191. if (err) {
  8192. dev_err(&pdev->dev,
  8193. "No usable DMA configuration, aborting\n");
  8194. goto err_dma;
  8195. }
  8196. pci_using_dac = 0;
  8197. }
  8198. err = pci_request_mem_regions(pdev, ixgbe_driver_name);
  8199. if (err) {
  8200. dev_err(&pdev->dev,
  8201. "pci_request_selected_regions failed 0x%x\n", err);
  8202. goto err_pci_reg;
  8203. }
  8204. pci_enable_pcie_error_reporting(pdev);
  8205. pci_set_master(pdev);
  8206. pci_save_state(pdev);
  8207. if (ii->mac == ixgbe_mac_82598EB) {
  8208. #ifdef CONFIG_IXGBE_DCB
  8209. /* 8 TC w/ 4 queues per TC */
  8210. indices = 4 * MAX_TRAFFIC_CLASS;
  8211. #else
  8212. indices = IXGBE_MAX_RSS_INDICES;
  8213. #endif
  8214. }
  8215. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  8216. if (!netdev) {
  8217. err = -ENOMEM;
  8218. goto err_alloc_etherdev;
  8219. }
  8220. SET_NETDEV_DEV(netdev, &pdev->dev);
  8221. adapter = netdev_priv(netdev);
  8222. adapter->netdev = netdev;
  8223. adapter->pdev = pdev;
  8224. hw = &adapter->hw;
  8225. hw->back = adapter;
  8226. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  8227. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  8228. pci_resource_len(pdev, 0));
  8229. adapter->io_addr = hw->hw_addr;
  8230. if (!hw->hw_addr) {
  8231. err = -EIO;
  8232. goto err_ioremap;
  8233. }
  8234. netdev->netdev_ops = &ixgbe_netdev_ops;
  8235. ixgbe_set_ethtool_ops(netdev);
  8236. netdev->watchdog_timeo = 5 * HZ;
  8237. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  8238. /* Setup hw api */
  8239. hw->mac.ops = *ii->mac_ops;
  8240. hw->mac.type = ii->mac;
  8241. hw->mvals = ii->mvals;
  8242. if (ii->link_ops)
  8243. hw->link.ops = *ii->link_ops;
  8244. /* EEPROM */
  8245. hw->eeprom.ops = *ii->eeprom_ops;
  8246. eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
  8247. if (ixgbe_removed(hw->hw_addr)) {
  8248. err = -EIO;
  8249. goto err_ioremap;
  8250. }
  8251. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  8252. if (!(eec & BIT(8)))
  8253. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  8254. /* PHY */
  8255. hw->phy.ops = *ii->phy_ops;
  8256. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  8257. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  8258. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  8259. hw->phy.mdio.mmds = 0;
  8260. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8261. hw->phy.mdio.dev = netdev;
  8262. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  8263. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  8264. /* setup the private structure */
  8265. err = ixgbe_sw_init(adapter, ii);
  8266. if (err)
  8267. goto err_sw_init;
  8268. /* Make sure the SWFW semaphore is in a valid state */
  8269. if (hw->mac.ops.init_swfw_sync)
  8270. hw->mac.ops.init_swfw_sync(hw);
  8271. /* Make it possible the adapter to be woken up via WOL */
  8272. switch (adapter->hw.mac.type) {
  8273. case ixgbe_mac_82599EB:
  8274. case ixgbe_mac_X540:
  8275. case ixgbe_mac_X550:
  8276. case ixgbe_mac_X550EM_x:
  8277. case ixgbe_mac_x550em_a:
  8278. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  8279. break;
  8280. default:
  8281. break;
  8282. }
  8283. /*
  8284. * If there is a fan on this device and it has failed log the
  8285. * failure.
  8286. */
  8287. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  8288. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  8289. if (esdp & IXGBE_ESDP_SDP1)
  8290. e_crit(probe, "Fan has stopped, replace the adapter\n");
  8291. }
  8292. if (allow_unsupported_sfp)
  8293. hw->allow_unsupported_sfp = allow_unsupported_sfp;
  8294. /* reset_hw fills in the perm_addr as well */
  8295. hw->phy.reset_if_overtemp = true;
  8296. err = hw->mac.ops.reset_hw(hw);
  8297. hw->phy.reset_if_overtemp = false;
  8298. ixgbe_set_eee_capable(adapter);
  8299. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  8300. err = 0;
  8301. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  8302. e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
  8303. e_dev_err("Reload the driver after installing a supported module.\n");
  8304. goto err_sw_init;
  8305. } else if (err) {
  8306. e_dev_err("HW Init failed: %d\n", err);
  8307. goto err_sw_init;
  8308. }
  8309. #ifdef CONFIG_PCI_IOV
  8310. /* SR-IOV not supported on the 82598 */
  8311. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  8312. goto skip_sriov;
  8313. /* Mailbox */
  8314. ixgbe_init_mbx_params_pf(hw);
  8315. hw->mbx.ops = ii->mbx_ops;
  8316. pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
  8317. ixgbe_enable_sriov(adapter);
  8318. skip_sriov:
  8319. #endif
  8320. netdev->features = NETIF_F_SG |
  8321. NETIF_F_TSO |
  8322. NETIF_F_TSO6 |
  8323. NETIF_F_RXHASH |
  8324. NETIF_F_RXCSUM |
  8325. NETIF_F_HW_CSUM;
  8326. #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
  8327. NETIF_F_GSO_GRE_CSUM | \
  8328. NETIF_F_GSO_IPXIP4 | \
  8329. NETIF_F_GSO_IPXIP6 | \
  8330. NETIF_F_GSO_UDP_TUNNEL | \
  8331. NETIF_F_GSO_UDP_TUNNEL_CSUM)
  8332. netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
  8333. netdev->features |= NETIF_F_GSO_PARTIAL |
  8334. IXGBE_GSO_PARTIAL_FEATURES;
  8335. if (hw->mac.type >= ixgbe_mac_82599EB)
  8336. netdev->features |= NETIF_F_SCTP_CRC;
  8337. /* copy netdev features into list of user selectable features */
  8338. netdev->hw_features |= netdev->features |
  8339. NETIF_F_HW_VLAN_CTAG_FILTER |
  8340. NETIF_F_HW_VLAN_CTAG_RX |
  8341. NETIF_F_HW_VLAN_CTAG_TX |
  8342. NETIF_F_RXALL |
  8343. NETIF_F_HW_L2FW_DOFFLOAD;
  8344. if (hw->mac.type >= ixgbe_mac_82599EB)
  8345. netdev->hw_features |= NETIF_F_NTUPLE |
  8346. NETIF_F_HW_TC;
  8347. if (pci_using_dac)
  8348. netdev->features |= NETIF_F_HIGHDMA;
  8349. netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
  8350. netdev->hw_enc_features |= netdev->vlan_features;
  8351. netdev->mpls_features |= NETIF_F_HW_CSUM;
  8352. /* set this bit last since it cannot be part of vlan_features */
  8353. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
  8354. NETIF_F_HW_VLAN_CTAG_RX |
  8355. NETIF_F_HW_VLAN_CTAG_TX;
  8356. netdev->priv_flags |= IFF_UNICAST_FLT;
  8357. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8358. /* MTU range: 68 - 9710 */
  8359. netdev->min_mtu = ETH_MIN_MTU;
  8360. netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
  8361. #ifdef CONFIG_IXGBE_DCB
  8362. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  8363. netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
  8364. #endif
  8365. #ifdef IXGBE_FCOE
  8366. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  8367. unsigned int fcoe_l;
  8368. if (hw->mac.ops.get_device_caps) {
  8369. hw->mac.ops.get_device_caps(hw, &device_caps);
  8370. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  8371. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  8372. }
  8373. fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
  8374. adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
  8375. netdev->features |= NETIF_F_FSO |
  8376. NETIF_F_FCOE_CRC;
  8377. netdev->vlan_features |= NETIF_F_FSO |
  8378. NETIF_F_FCOE_CRC |
  8379. NETIF_F_FCOE_MTU;
  8380. }
  8381. #endif /* IXGBE_FCOE */
  8382. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  8383. netdev->hw_features |= NETIF_F_LRO;
  8384. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  8385. netdev->features |= NETIF_F_LRO;
  8386. /* make sure the EEPROM is good */
  8387. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  8388. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  8389. err = -EIO;
  8390. goto err_sw_init;
  8391. }
  8392. eth_platform_get_mac_address(&adapter->pdev->dev,
  8393. adapter->hw.mac.perm_addr);
  8394. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  8395. if (!is_valid_ether_addr(netdev->dev_addr)) {
  8396. e_dev_err("invalid MAC address\n");
  8397. err = -EIO;
  8398. goto err_sw_init;
  8399. }
  8400. /* Set hw->mac.addr to permanent MAC address */
  8401. ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
  8402. ixgbe_mac_set_default_filter(adapter);
  8403. setup_timer(&adapter->service_timer, &ixgbe_service_timer,
  8404. (unsigned long) adapter);
  8405. if (ixgbe_removed(hw->hw_addr)) {
  8406. err = -EIO;
  8407. goto err_sw_init;
  8408. }
  8409. INIT_WORK(&adapter->service_task, ixgbe_service_task);
  8410. set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
  8411. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  8412. err = ixgbe_init_interrupt_scheme(adapter);
  8413. if (err)
  8414. goto err_sw_init;
  8415. /* WOL not supported for all devices */
  8416. adapter->wol = 0;
  8417. hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
  8418. hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
  8419. pdev->subsystem_device);
  8420. if (hw->wol_enabled)
  8421. adapter->wol = IXGBE_WUFC_MAG;
  8422. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  8423. /* save off EEPROM version number */
  8424. hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
  8425. hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
  8426. /* pick up the PCI bus settings for reporting later */
  8427. if (ixgbe_pcie_from_parent(hw))
  8428. ixgbe_get_parent_bus_info(adapter);
  8429. else
  8430. hw->mac.ops.get_bus_info(hw);
  8431. /* calculate the expected PCIe bandwidth required for optimal
  8432. * performance. Note that some older parts will never have enough
  8433. * bandwidth due to being older generation PCIe parts. We clamp these
  8434. * parts to ensure no warning is displayed if it can't be fixed.
  8435. */
  8436. switch (hw->mac.type) {
  8437. case ixgbe_mac_82598EB:
  8438. expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
  8439. break;
  8440. default:
  8441. expected_gts = ixgbe_enumerate_functions(adapter) * 10;
  8442. break;
  8443. }
  8444. /* don't check link if we failed to enumerate functions */
  8445. if (expected_gts > 0)
  8446. ixgbe_check_minimum_link(adapter, expected_gts);
  8447. err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
  8448. if (err)
  8449. strlcpy(part_str, "Unknown", sizeof(part_str));
  8450. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  8451. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
  8452. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  8453. part_str);
  8454. else
  8455. e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
  8456. hw->mac.type, hw->phy.type, part_str);
  8457. e_dev_info("%pM\n", netdev->dev_addr);
  8458. /* reset the hardware with the new settings */
  8459. err = hw->mac.ops.start_hw(hw);
  8460. if (err == IXGBE_ERR_EEPROM_VERSION) {
  8461. /* We are running on a pre-production device, log a warning */
  8462. e_dev_warn("This device is a pre-production adapter/LOM. "
  8463. "Please be aware there may be issues associated "
  8464. "with your hardware. If you are experiencing "
  8465. "problems please contact your Intel or hardware "
  8466. "representative who provided you with this "
  8467. "hardware.\n");
  8468. }
  8469. strcpy(netdev->name, "eth%d");
  8470. err = register_netdev(netdev);
  8471. if (err)
  8472. goto err_register;
  8473. pci_set_drvdata(pdev, adapter);
  8474. /* power down the optics for 82599 SFP+ fiber */
  8475. if (hw->mac.ops.disable_tx_laser)
  8476. hw->mac.ops.disable_tx_laser(hw);
  8477. /* carrier off reporting is important to ethtool even BEFORE open */
  8478. netif_carrier_off(netdev);
  8479. #ifdef CONFIG_IXGBE_DCA
  8480. if (dca_add_requester(&pdev->dev) == 0) {
  8481. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  8482. ixgbe_setup_dca(adapter);
  8483. }
  8484. #endif
  8485. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  8486. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  8487. for (i = 0; i < adapter->num_vfs; i++)
  8488. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  8489. }
  8490. /* firmware requires driver version to be 0xFFFFFFFF
  8491. * since os does not support feature
  8492. */
  8493. if (hw->mac.ops.set_fw_drv_ver)
  8494. hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
  8495. sizeof(ixgbe_driver_version) - 1,
  8496. ixgbe_driver_version);
  8497. /* add san mac addr to netdev */
  8498. ixgbe_add_sanmac_netdev(netdev);
  8499. e_dev_info("%s\n", ixgbe_default_device_descr);
  8500. #ifdef CONFIG_IXGBE_HWMON
  8501. if (ixgbe_sysfs_init(adapter))
  8502. e_err(probe, "failed to allocate sysfs resources\n");
  8503. #endif /* CONFIG_IXGBE_HWMON */
  8504. ixgbe_dbg_adapter_init(adapter);
  8505. /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
  8506. if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
  8507. hw->mac.ops.setup_link(hw,
  8508. IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
  8509. true);
  8510. return 0;
  8511. err_register:
  8512. ixgbe_release_hw_control(adapter);
  8513. ixgbe_clear_interrupt_scheme(adapter);
  8514. err_sw_init:
  8515. ixgbe_disable_sriov(adapter);
  8516. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  8517. iounmap(adapter->io_addr);
  8518. kfree(adapter->jump_tables[0]);
  8519. kfree(adapter->mac_table);
  8520. err_ioremap:
  8521. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  8522. free_netdev(netdev);
  8523. err_alloc_etherdev:
  8524. pci_release_mem_regions(pdev);
  8525. err_pci_reg:
  8526. err_dma:
  8527. if (!adapter || disable_dev)
  8528. pci_disable_device(pdev);
  8529. return err;
  8530. }
  8531. /**
  8532. * ixgbe_remove - Device Removal Routine
  8533. * @pdev: PCI device information struct
  8534. *
  8535. * ixgbe_remove is called by the PCI subsystem to alert the driver
  8536. * that it should release a PCI device. The could be caused by a
  8537. * Hot-Plug event, or because the driver is going to be removed from
  8538. * memory.
  8539. **/
  8540. static void ixgbe_remove(struct pci_dev *pdev)
  8541. {
  8542. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8543. struct net_device *netdev;
  8544. bool disable_dev;
  8545. int i;
  8546. /* if !adapter then we already cleaned up in probe */
  8547. if (!adapter)
  8548. return;
  8549. netdev = adapter->netdev;
  8550. ixgbe_dbg_adapter_exit(adapter);
  8551. set_bit(__IXGBE_REMOVING, &adapter->state);
  8552. cancel_work_sync(&adapter->service_task);
  8553. #ifdef CONFIG_IXGBE_DCA
  8554. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  8555. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  8556. dca_remove_requester(&pdev->dev);
  8557. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  8558. IXGBE_DCA_CTRL_DCA_DISABLE);
  8559. }
  8560. #endif
  8561. #ifdef CONFIG_IXGBE_HWMON
  8562. ixgbe_sysfs_exit(adapter);
  8563. #endif /* CONFIG_IXGBE_HWMON */
  8564. /* remove the added san mac */
  8565. ixgbe_del_sanmac_netdev(netdev);
  8566. #ifdef CONFIG_PCI_IOV
  8567. ixgbe_disable_sriov(adapter);
  8568. #endif
  8569. if (netdev->reg_state == NETREG_REGISTERED)
  8570. unregister_netdev(netdev);
  8571. ixgbe_clear_interrupt_scheme(adapter);
  8572. ixgbe_release_hw_control(adapter);
  8573. #ifdef CONFIG_DCB
  8574. kfree(adapter->ixgbe_ieee_pfc);
  8575. kfree(adapter->ixgbe_ieee_ets);
  8576. #endif
  8577. iounmap(adapter->io_addr);
  8578. pci_release_mem_regions(pdev);
  8579. e_dev_info("complete\n");
  8580. for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
  8581. if (adapter->jump_tables[i]) {
  8582. kfree(adapter->jump_tables[i]->input);
  8583. kfree(adapter->jump_tables[i]->mask);
  8584. }
  8585. kfree(adapter->jump_tables[i]);
  8586. }
  8587. kfree(adapter->mac_table);
  8588. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  8589. free_netdev(netdev);
  8590. pci_disable_pcie_error_reporting(pdev);
  8591. if (disable_dev)
  8592. pci_disable_device(pdev);
  8593. }
  8594. /**
  8595. * ixgbe_io_error_detected - called when PCI error is detected
  8596. * @pdev: Pointer to PCI device
  8597. * @state: The current pci connection state
  8598. *
  8599. * This function is called after a PCI bus error affecting
  8600. * this device has been detected.
  8601. */
  8602. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  8603. pci_channel_state_t state)
  8604. {
  8605. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8606. struct net_device *netdev = adapter->netdev;
  8607. #ifdef CONFIG_PCI_IOV
  8608. struct ixgbe_hw *hw = &adapter->hw;
  8609. struct pci_dev *bdev, *vfdev;
  8610. u32 dw0, dw1, dw2, dw3;
  8611. int vf, pos;
  8612. u16 req_id, pf_func;
  8613. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  8614. adapter->num_vfs == 0)
  8615. goto skip_bad_vf_detection;
  8616. bdev = pdev->bus->self;
  8617. while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
  8618. bdev = bdev->bus->self;
  8619. if (!bdev)
  8620. goto skip_bad_vf_detection;
  8621. pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
  8622. if (!pos)
  8623. goto skip_bad_vf_detection;
  8624. dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
  8625. dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
  8626. dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
  8627. dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
  8628. if (ixgbe_removed(hw->hw_addr))
  8629. goto skip_bad_vf_detection;
  8630. req_id = dw1 >> 16;
  8631. /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
  8632. if (!(req_id & 0x0080))
  8633. goto skip_bad_vf_detection;
  8634. pf_func = req_id & 0x01;
  8635. if ((pf_func & 1) == (pdev->devfn & 1)) {
  8636. unsigned int device_id;
  8637. vf = (req_id & 0x7F) >> 1;
  8638. e_dev_err("VF %d has caused a PCIe error\n", vf);
  8639. e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
  8640. "%8.8x\tdw3: %8.8x\n",
  8641. dw0, dw1, dw2, dw3);
  8642. switch (adapter->hw.mac.type) {
  8643. case ixgbe_mac_82599EB:
  8644. device_id = IXGBE_82599_VF_DEVICE_ID;
  8645. break;
  8646. case ixgbe_mac_X540:
  8647. device_id = IXGBE_X540_VF_DEVICE_ID;
  8648. break;
  8649. case ixgbe_mac_X550:
  8650. device_id = IXGBE_DEV_ID_X550_VF;
  8651. break;
  8652. case ixgbe_mac_X550EM_x:
  8653. device_id = IXGBE_DEV_ID_X550EM_X_VF;
  8654. break;
  8655. case ixgbe_mac_x550em_a:
  8656. device_id = IXGBE_DEV_ID_X550EM_A_VF;
  8657. break;
  8658. default:
  8659. device_id = 0;
  8660. break;
  8661. }
  8662. /* Find the pci device of the offending VF */
  8663. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
  8664. while (vfdev) {
  8665. if (vfdev->devfn == (req_id & 0xFF))
  8666. break;
  8667. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  8668. device_id, vfdev);
  8669. }
  8670. /*
  8671. * There's a slim chance the VF could have been hot plugged,
  8672. * so if it is no longer present we don't need to issue the
  8673. * VFLR. Just clean up the AER in that case.
  8674. */
  8675. if (vfdev) {
  8676. ixgbe_issue_vf_flr(adapter, vfdev);
  8677. /* Free device reference count */
  8678. pci_dev_put(vfdev);
  8679. }
  8680. pci_cleanup_aer_uncorrect_error_status(pdev);
  8681. }
  8682. /*
  8683. * Even though the error may have occurred on the other port
  8684. * we still need to increment the vf error reference count for
  8685. * both ports because the I/O resume function will be called
  8686. * for both of them.
  8687. */
  8688. adapter->vferr_refcount++;
  8689. return PCI_ERS_RESULT_RECOVERED;
  8690. skip_bad_vf_detection:
  8691. #endif /* CONFIG_PCI_IOV */
  8692. if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  8693. return PCI_ERS_RESULT_DISCONNECT;
  8694. rtnl_lock();
  8695. netif_device_detach(netdev);
  8696. if (state == pci_channel_io_perm_failure) {
  8697. rtnl_unlock();
  8698. return PCI_ERS_RESULT_DISCONNECT;
  8699. }
  8700. if (netif_running(netdev))
  8701. ixgbe_close_suspend(adapter);
  8702. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  8703. pci_disable_device(pdev);
  8704. rtnl_unlock();
  8705. /* Request a slot reset. */
  8706. return PCI_ERS_RESULT_NEED_RESET;
  8707. }
  8708. /**
  8709. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  8710. * @pdev: Pointer to PCI device
  8711. *
  8712. * Restart the card from scratch, as if from a cold-boot.
  8713. */
  8714. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  8715. {
  8716. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8717. pci_ers_result_t result;
  8718. int err;
  8719. if (pci_enable_device_mem(pdev)) {
  8720. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  8721. result = PCI_ERS_RESULT_DISCONNECT;
  8722. } else {
  8723. smp_mb__before_atomic();
  8724. clear_bit(__IXGBE_DISABLED, &adapter->state);
  8725. adapter->hw.hw_addr = adapter->io_addr;
  8726. pci_set_master(pdev);
  8727. pci_restore_state(pdev);
  8728. pci_save_state(pdev);
  8729. pci_wake_from_d3(pdev, false);
  8730. ixgbe_reset(adapter);
  8731. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  8732. result = PCI_ERS_RESULT_RECOVERED;
  8733. }
  8734. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  8735. if (err) {
  8736. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  8737. "failed 0x%0x\n", err);
  8738. /* non-fatal, continue */
  8739. }
  8740. return result;
  8741. }
  8742. /**
  8743. * ixgbe_io_resume - called when traffic can start flowing again.
  8744. * @pdev: Pointer to PCI device
  8745. *
  8746. * This callback is called when the error recovery driver tells us that
  8747. * its OK to resume normal operation.
  8748. */
  8749. static void ixgbe_io_resume(struct pci_dev *pdev)
  8750. {
  8751. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  8752. struct net_device *netdev = adapter->netdev;
  8753. #ifdef CONFIG_PCI_IOV
  8754. if (adapter->vferr_refcount) {
  8755. e_info(drv, "Resuming after VF err\n");
  8756. adapter->vferr_refcount--;
  8757. return;
  8758. }
  8759. #endif
  8760. rtnl_lock();
  8761. if (netif_running(netdev))
  8762. ixgbe_open(netdev);
  8763. netif_device_attach(netdev);
  8764. rtnl_unlock();
  8765. }
  8766. static const struct pci_error_handlers ixgbe_err_handler = {
  8767. .error_detected = ixgbe_io_error_detected,
  8768. .slot_reset = ixgbe_io_slot_reset,
  8769. .resume = ixgbe_io_resume,
  8770. };
  8771. static struct pci_driver ixgbe_driver = {
  8772. .name = ixgbe_driver_name,
  8773. .id_table = ixgbe_pci_tbl,
  8774. .probe = ixgbe_probe,
  8775. .remove = ixgbe_remove,
  8776. #ifdef CONFIG_PM
  8777. .suspend = ixgbe_suspend,
  8778. .resume = ixgbe_resume,
  8779. #endif
  8780. .shutdown = ixgbe_shutdown,
  8781. .sriov_configure = ixgbe_pci_sriov_configure,
  8782. .err_handler = &ixgbe_err_handler
  8783. };
  8784. /**
  8785. * ixgbe_init_module - Driver Registration Routine
  8786. *
  8787. * ixgbe_init_module is the first routine called when the driver is
  8788. * loaded. All it does is register with the PCI subsystem.
  8789. **/
  8790. static int __init ixgbe_init_module(void)
  8791. {
  8792. int ret;
  8793. pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
  8794. pr_info("%s\n", ixgbe_copyright);
  8795. ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
  8796. if (!ixgbe_wq) {
  8797. pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
  8798. return -ENOMEM;
  8799. }
  8800. ixgbe_dbg_init();
  8801. ret = pci_register_driver(&ixgbe_driver);
  8802. if (ret) {
  8803. destroy_workqueue(ixgbe_wq);
  8804. ixgbe_dbg_exit();
  8805. return ret;
  8806. }
  8807. #ifdef CONFIG_IXGBE_DCA
  8808. dca_register_notify(&dca_notifier);
  8809. #endif
  8810. return 0;
  8811. }
  8812. module_init(ixgbe_init_module);
  8813. /**
  8814. * ixgbe_exit_module - Driver Exit Cleanup Routine
  8815. *
  8816. * ixgbe_exit_module is called just before the driver is removed
  8817. * from memory.
  8818. **/
  8819. static void __exit ixgbe_exit_module(void)
  8820. {
  8821. #ifdef CONFIG_IXGBE_DCA
  8822. dca_unregister_notify(&dca_notifier);
  8823. #endif
  8824. pci_unregister_driver(&ixgbe_driver);
  8825. ixgbe_dbg_exit();
  8826. if (ixgbe_wq) {
  8827. destroy_workqueue(ixgbe_wq);
  8828. ixgbe_wq = NULL;
  8829. }
  8830. }
  8831. #ifdef CONFIG_IXGBE_DCA
  8832. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  8833. void *p)
  8834. {
  8835. int ret_val;
  8836. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  8837. __ixgbe_notify_dca);
  8838. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  8839. }
  8840. #endif /* CONFIG_IXGBE_DCA */
  8841. module_exit(ixgbe_exit_module);
  8842. /* ixgbe_main.c */