ixgbe_main.c 261 KB

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