ixgbe_main.c 205 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2010 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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/types.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/string.h>
  26. #include <linux/in.h>
  27. #include <linux/ip.h>
  28. #include <linux/tcp.h>
  29. #include <linux/pkt_sched.h>
  30. #include <linux/ipv6.h>
  31. #include <linux/slab.h>
  32. #include <net/checksum.h>
  33. #include <net/ip6_checksum.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if_vlan.h>
  36. #include <scsi/fc/fc_fcoe.h>
  37. #include "ixgbe.h"
  38. #include "ixgbe_common.h"
  39. #include "ixgbe_dcb_82599.h"
  40. #include "ixgbe_sriov.h"
  41. char ixgbe_driver_name[] = "ixgbe";
  42. static const char ixgbe_driver_string[] =
  43. "Intel(R) 10 Gigabit PCI Express Network Driver";
  44. #define DRV_VERSION "2.0.84-k2"
  45. const char ixgbe_driver_version[] = DRV_VERSION;
  46. static char ixgbe_copyright[] = "Copyright (c) 1999-2010 Intel Corporation.";
  47. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  48. [board_82598] = &ixgbe_82598_info,
  49. [board_82599] = &ixgbe_82599_info,
  50. };
  51. /* ixgbe_pci_tbl - PCI Device ID Table
  52. *
  53. * Wildcard entries (PCI_ANY_ID) should come last
  54. * Last entry must be all 0s
  55. *
  56. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  57. * Class, Class Mask, private data (not used) }
  58. */
  59. static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
  60. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
  61. board_82598 },
  62. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
  63. board_82598 },
  64. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
  65. board_82598 },
  66. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
  67. board_82598 },
  68. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
  69. board_82598 },
  70. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
  71. board_82598 },
  72. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
  73. board_82598 },
  74. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
  75. board_82598 },
  76. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
  77. board_82598 },
  78. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
  79. board_82598 },
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
  81. board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
  83. board_82598 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
  85. board_82599 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
  87. board_82599 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
  89. board_82599 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
  91. board_82599 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
  93. board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
  95. board_82599 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
  97. board_82599 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
  99. board_82599 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
  101. board_82599 },
  102. /* required last entry */
  103. {0, }
  104. };
  105. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  106. #ifdef CONFIG_IXGBE_DCA
  107. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  108. void *p);
  109. static struct notifier_block dca_notifier = {
  110. .notifier_call = ixgbe_notify_dca,
  111. .next = NULL,
  112. .priority = 0
  113. };
  114. #endif
  115. #ifdef CONFIG_PCI_IOV
  116. static unsigned int max_vfs;
  117. module_param(max_vfs, uint, 0);
  118. MODULE_PARM_DESC(max_vfs,
  119. "Maximum number of virtual functions to allocate per physical function");
  120. #endif /* CONFIG_PCI_IOV */
  121. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  122. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  123. MODULE_LICENSE("GPL");
  124. MODULE_VERSION(DRV_VERSION);
  125. #define DEFAULT_DEBUG_LEVEL_SHIFT 3
  126. static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
  127. {
  128. struct ixgbe_hw *hw = &adapter->hw;
  129. u32 gcr;
  130. u32 gpie;
  131. u32 vmdctl;
  132. #ifdef CONFIG_PCI_IOV
  133. /* disable iov and allow time for transactions to clear */
  134. pci_disable_sriov(adapter->pdev);
  135. #endif
  136. /* turn off device IOV mode */
  137. gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  138. gcr &= ~(IXGBE_GCR_EXT_SRIOV);
  139. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
  140. gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
  141. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  142. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  143. /* set default pool back to 0 */
  144. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  145. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  146. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  147. /* take a breather then clean up driver data */
  148. msleep(100);
  149. kfree(adapter->vfinfo);
  150. adapter->vfinfo = NULL;
  151. adapter->num_vfs = 0;
  152. adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
  153. }
  154. struct ixgbe_reg_info {
  155. u32 ofs;
  156. char *name;
  157. };
  158. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  159. /* General Registers */
  160. {IXGBE_CTRL, "CTRL"},
  161. {IXGBE_STATUS, "STATUS"},
  162. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  163. /* Interrupt Registers */
  164. {IXGBE_EICR, "EICR"},
  165. /* RX Registers */
  166. {IXGBE_SRRCTL(0), "SRRCTL"},
  167. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  168. {IXGBE_RDLEN(0), "RDLEN"},
  169. {IXGBE_RDH(0), "RDH"},
  170. {IXGBE_RDT(0), "RDT"},
  171. {IXGBE_RXDCTL(0), "RXDCTL"},
  172. {IXGBE_RDBAL(0), "RDBAL"},
  173. {IXGBE_RDBAH(0), "RDBAH"},
  174. /* TX Registers */
  175. {IXGBE_TDBAL(0), "TDBAL"},
  176. {IXGBE_TDBAH(0), "TDBAH"},
  177. {IXGBE_TDLEN(0), "TDLEN"},
  178. {IXGBE_TDH(0), "TDH"},
  179. {IXGBE_TDT(0), "TDT"},
  180. {IXGBE_TXDCTL(0), "TXDCTL"},
  181. /* List Terminator */
  182. {}
  183. };
  184. /*
  185. * ixgbe_regdump - register printout routine
  186. */
  187. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  188. {
  189. int i = 0, j = 0;
  190. char rname[16];
  191. u32 regs[64];
  192. switch (reginfo->ofs) {
  193. case IXGBE_SRRCTL(0):
  194. for (i = 0; i < 64; i++)
  195. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  196. break;
  197. case IXGBE_DCA_RXCTRL(0):
  198. for (i = 0; i < 64; i++)
  199. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  200. break;
  201. case IXGBE_RDLEN(0):
  202. for (i = 0; i < 64; i++)
  203. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  204. break;
  205. case IXGBE_RDH(0):
  206. for (i = 0; i < 64; i++)
  207. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  208. break;
  209. case IXGBE_RDT(0):
  210. for (i = 0; i < 64; i++)
  211. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  212. break;
  213. case IXGBE_RXDCTL(0):
  214. for (i = 0; i < 64; i++)
  215. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  216. break;
  217. case IXGBE_RDBAL(0):
  218. for (i = 0; i < 64; i++)
  219. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  220. break;
  221. case IXGBE_RDBAH(0):
  222. for (i = 0; i < 64; i++)
  223. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  224. break;
  225. case IXGBE_TDBAL(0):
  226. for (i = 0; i < 64; i++)
  227. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  228. break;
  229. case IXGBE_TDBAH(0):
  230. for (i = 0; i < 64; i++)
  231. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  232. break;
  233. case IXGBE_TDLEN(0):
  234. for (i = 0; i < 64; i++)
  235. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  236. break;
  237. case IXGBE_TDH(0):
  238. for (i = 0; i < 64; i++)
  239. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  240. break;
  241. case IXGBE_TDT(0):
  242. for (i = 0; i < 64; i++)
  243. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  244. break;
  245. case IXGBE_TXDCTL(0):
  246. for (i = 0; i < 64; i++)
  247. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  248. break;
  249. default:
  250. pr_info("%-15s %08x\n", reginfo->name,
  251. IXGBE_READ_REG(hw, reginfo->ofs));
  252. return;
  253. }
  254. for (i = 0; i < 8; i++) {
  255. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
  256. pr_err("%-15s", rname);
  257. for (j = 0; j < 8; j++)
  258. pr_cont(" %08x", regs[i*8+j]);
  259. pr_cont("\n");
  260. }
  261. }
  262. /*
  263. * ixgbe_dump - Print registers, tx-rings and rx-rings
  264. */
  265. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  266. {
  267. struct net_device *netdev = adapter->netdev;
  268. struct ixgbe_hw *hw = &adapter->hw;
  269. struct ixgbe_reg_info *reginfo;
  270. int n = 0;
  271. struct ixgbe_ring *tx_ring;
  272. struct ixgbe_tx_buffer *tx_buffer_info;
  273. union ixgbe_adv_tx_desc *tx_desc;
  274. struct my_u0 { u64 a; u64 b; } *u0;
  275. struct ixgbe_ring *rx_ring;
  276. union ixgbe_adv_rx_desc *rx_desc;
  277. struct ixgbe_rx_buffer *rx_buffer_info;
  278. u32 staterr;
  279. int i = 0;
  280. if (!netif_msg_hw(adapter))
  281. return;
  282. /* Print netdevice Info */
  283. if (netdev) {
  284. dev_info(&adapter->pdev->dev, "Net device Info\n");
  285. pr_info("Device Name state "
  286. "trans_start last_rx\n");
  287. pr_info("%-15s %016lX %016lX %016lX\n",
  288. netdev->name,
  289. netdev->state,
  290. netdev->trans_start,
  291. netdev->last_rx);
  292. }
  293. /* Print Registers */
  294. dev_info(&adapter->pdev->dev, "Register Dump\n");
  295. pr_info(" Register Name Value\n");
  296. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  297. reginfo->name; reginfo++) {
  298. ixgbe_regdump(hw, reginfo);
  299. }
  300. /* Print TX Ring Summary */
  301. if (!netdev || !netif_running(netdev))
  302. goto exit;
  303. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  304. pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
  305. for (n = 0; n < adapter->num_tx_queues; n++) {
  306. tx_ring = adapter->tx_ring[n];
  307. tx_buffer_info =
  308. &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  309. pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
  310. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  311. (u64)tx_buffer_info->dma,
  312. tx_buffer_info->length,
  313. tx_buffer_info->next_to_watch,
  314. (u64)tx_buffer_info->time_stamp);
  315. }
  316. /* Print TX Rings */
  317. if (!netif_msg_tx_done(adapter))
  318. goto rx_ring_summary;
  319. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  320. /* Transmit Descriptor Formats
  321. *
  322. * Advanced Transmit Descriptor
  323. * +--------------------------------------------------------------+
  324. * 0 | Buffer Address [63:0] |
  325. * +--------------------------------------------------------------+
  326. * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  327. * +--------------------------------------------------------------+
  328. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  329. */
  330. for (n = 0; n < adapter->num_tx_queues; n++) {
  331. tx_ring = adapter->tx_ring[n];
  332. pr_info("------------------------------------\n");
  333. pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  334. pr_info("------------------------------------\n");
  335. pr_info("T [desc] [address 63:0 ] "
  336. "[PlPOIdStDDt Ln] [bi->dma ] "
  337. "leng ntw timestamp bi->skb\n");
  338. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  339. tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
  340. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  341. u0 = (struct my_u0 *)tx_desc;
  342. pr_info("T [0x%03X] %016llX %016llX %016llX"
  343. " %04X %3X %016llX %p", i,
  344. le64_to_cpu(u0->a),
  345. le64_to_cpu(u0->b),
  346. (u64)tx_buffer_info->dma,
  347. tx_buffer_info->length,
  348. tx_buffer_info->next_to_watch,
  349. (u64)tx_buffer_info->time_stamp,
  350. tx_buffer_info->skb);
  351. if (i == tx_ring->next_to_use &&
  352. i == tx_ring->next_to_clean)
  353. pr_cont(" NTC/U\n");
  354. else if (i == tx_ring->next_to_use)
  355. pr_cont(" NTU\n");
  356. else if (i == tx_ring->next_to_clean)
  357. pr_cont(" NTC\n");
  358. else
  359. pr_cont("\n");
  360. if (netif_msg_pktdata(adapter) &&
  361. tx_buffer_info->dma != 0)
  362. print_hex_dump(KERN_INFO, "",
  363. DUMP_PREFIX_ADDRESS, 16, 1,
  364. phys_to_virt(tx_buffer_info->dma),
  365. tx_buffer_info->length, true);
  366. }
  367. }
  368. /* Print RX Rings Summary */
  369. rx_ring_summary:
  370. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  371. pr_info("Queue [NTU] [NTC]\n");
  372. for (n = 0; n < adapter->num_rx_queues; n++) {
  373. rx_ring = adapter->rx_ring[n];
  374. pr_info("%5d %5X %5X\n",
  375. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  376. }
  377. /* Print RX Rings */
  378. if (!netif_msg_rx_status(adapter))
  379. goto exit;
  380. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  381. /* Advanced Receive Descriptor (Read) Format
  382. * 63 1 0
  383. * +-----------------------------------------------------+
  384. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  385. * +----------------------------------------------+------+
  386. * 8 | Header Buffer Address [63:1] | DD |
  387. * +-----------------------------------------------------+
  388. *
  389. *
  390. * Advanced Receive Descriptor (Write-Back) Format
  391. *
  392. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  393. * +------------------------------------------------------+
  394. * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
  395. * | Checksum Ident | | | | Type | Type |
  396. * +------------------------------------------------------+
  397. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  398. * +------------------------------------------------------+
  399. * 63 48 47 32 31 20 19 0
  400. */
  401. for (n = 0; n < adapter->num_rx_queues; n++) {
  402. rx_ring = adapter->rx_ring[n];
  403. pr_info("------------------------------------\n");
  404. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  405. pr_info("------------------------------------\n");
  406. pr_info("R [desc] [ PktBuf A0] "
  407. "[ HeadBuf DD] [bi->dma ] [bi->skb] "
  408. "<-- Adv Rx Read format\n");
  409. pr_info("RWB[desc] [PcsmIpSHl PtRs] "
  410. "[vl er S cks ln] ---------------- [bi->skb] "
  411. "<-- Adv Rx Write-Back format\n");
  412. for (i = 0; i < rx_ring->count; i++) {
  413. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  414. rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
  415. u0 = (struct my_u0 *)rx_desc;
  416. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  417. if (staterr & IXGBE_RXD_STAT_DD) {
  418. /* Descriptor Done */
  419. pr_info("RWB[0x%03X] %016llX "
  420. "%016llX ---------------- %p", i,
  421. le64_to_cpu(u0->a),
  422. le64_to_cpu(u0->b),
  423. rx_buffer_info->skb);
  424. } else {
  425. pr_info("R [0x%03X] %016llX "
  426. "%016llX %016llX %p", i,
  427. le64_to_cpu(u0->a),
  428. le64_to_cpu(u0->b),
  429. (u64)rx_buffer_info->dma,
  430. rx_buffer_info->skb);
  431. if (netif_msg_pktdata(adapter)) {
  432. print_hex_dump(KERN_INFO, "",
  433. DUMP_PREFIX_ADDRESS, 16, 1,
  434. phys_to_virt(rx_buffer_info->dma),
  435. rx_ring->rx_buf_len, true);
  436. if (rx_ring->rx_buf_len
  437. < IXGBE_RXBUFFER_2048)
  438. print_hex_dump(KERN_INFO, "",
  439. DUMP_PREFIX_ADDRESS, 16, 1,
  440. phys_to_virt(
  441. rx_buffer_info->page_dma +
  442. rx_buffer_info->page_offset
  443. ),
  444. PAGE_SIZE/2, true);
  445. }
  446. }
  447. if (i == rx_ring->next_to_use)
  448. pr_cont(" NTU\n");
  449. else if (i == rx_ring->next_to_clean)
  450. pr_cont(" NTC\n");
  451. else
  452. pr_cont("\n");
  453. }
  454. }
  455. exit:
  456. return;
  457. }
  458. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  459. {
  460. u32 ctrl_ext;
  461. /* Let firmware take over control of h/w */
  462. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  463. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  464. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  465. }
  466. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  467. {
  468. u32 ctrl_ext;
  469. /* Let firmware know the driver has taken over */
  470. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  471. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  472. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  473. }
  474. /*
  475. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  476. * @adapter: pointer to adapter struct
  477. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  478. * @queue: queue to map the corresponding interrupt to
  479. * @msix_vector: the vector to map to the corresponding queue
  480. *
  481. */
  482. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  483. u8 queue, u8 msix_vector)
  484. {
  485. u32 ivar, index;
  486. struct ixgbe_hw *hw = &adapter->hw;
  487. switch (hw->mac.type) {
  488. case ixgbe_mac_82598EB:
  489. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  490. if (direction == -1)
  491. direction = 0;
  492. index = (((direction * 64) + queue) >> 2) & 0x1F;
  493. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  494. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  495. ivar |= (msix_vector << (8 * (queue & 0x3)));
  496. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  497. break;
  498. case ixgbe_mac_82599EB:
  499. if (direction == -1) {
  500. /* other causes */
  501. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  502. index = ((queue & 1) * 8);
  503. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  504. ivar &= ~(0xFF << index);
  505. ivar |= (msix_vector << index);
  506. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  507. break;
  508. } else {
  509. /* tx or rx causes */
  510. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  511. index = ((16 * (queue & 1)) + (8 * direction));
  512. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  513. ivar &= ~(0xFF << index);
  514. ivar |= (msix_vector << index);
  515. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  516. break;
  517. }
  518. default:
  519. break;
  520. }
  521. }
  522. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  523. u64 qmask)
  524. {
  525. u32 mask;
  526. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  527. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  528. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  529. } else {
  530. mask = (qmask & 0xFFFFFFFF);
  531. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  532. mask = (qmask >> 32);
  533. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  534. }
  535. }
  536. void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter,
  537. struct ixgbe_tx_buffer
  538. *tx_buffer_info)
  539. {
  540. if (tx_buffer_info->dma) {
  541. if (tx_buffer_info->mapped_as_page)
  542. dma_unmap_page(&adapter->pdev->dev,
  543. tx_buffer_info->dma,
  544. tx_buffer_info->length,
  545. DMA_TO_DEVICE);
  546. else
  547. dma_unmap_single(&adapter->pdev->dev,
  548. tx_buffer_info->dma,
  549. tx_buffer_info->length,
  550. DMA_TO_DEVICE);
  551. tx_buffer_info->dma = 0;
  552. }
  553. if (tx_buffer_info->skb) {
  554. dev_kfree_skb_any(tx_buffer_info->skb);
  555. tx_buffer_info->skb = NULL;
  556. }
  557. tx_buffer_info->time_stamp = 0;
  558. /* tx_buffer_info must be completely set up in the transmit path */
  559. }
  560. /**
  561. * ixgbe_tx_xon_state - check the tx ring xon state
  562. * @adapter: the ixgbe adapter
  563. * @tx_ring: the corresponding tx_ring
  564. *
  565. * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the
  566. * corresponding TC of this tx_ring when checking TFCS.
  567. *
  568. * Returns : true if in xon state (currently not paused)
  569. */
  570. static inline bool ixgbe_tx_xon_state(struct ixgbe_adapter *adapter,
  571. struct ixgbe_ring *tx_ring)
  572. {
  573. u32 txoff = IXGBE_TFCS_TXOFF;
  574. #ifdef CONFIG_IXGBE_DCB
  575. if (adapter->dcb_cfg.pfc_mode_enable) {
  576. int tc;
  577. int reg_idx = tx_ring->reg_idx;
  578. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  579. switch (adapter->hw.mac.type) {
  580. case ixgbe_mac_82598EB:
  581. tc = reg_idx >> 2;
  582. txoff = IXGBE_TFCS_TXOFF0;
  583. break;
  584. case ixgbe_mac_82599EB:
  585. tc = 0;
  586. txoff = IXGBE_TFCS_TXOFF;
  587. if (dcb_i == 8) {
  588. /* TC0, TC1 */
  589. tc = reg_idx >> 5;
  590. if (tc == 2) /* TC2, TC3 */
  591. tc += (reg_idx - 64) >> 4;
  592. else if (tc == 3) /* TC4, TC5, TC6, TC7 */
  593. tc += 1 + ((reg_idx - 96) >> 3);
  594. } else if (dcb_i == 4) {
  595. /* TC0, TC1 */
  596. tc = reg_idx >> 6;
  597. if (tc == 1) {
  598. tc += (reg_idx - 64) >> 5;
  599. if (tc == 2) /* TC2, TC3 */
  600. tc += (reg_idx - 96) >> 4;
  601. }
  602. }
  603. break;
  604. default:
  605. tc = 0;
  606. }
  607. txoff <<= tc;
  608. }
  609. #endif
  610. return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff;
  611. }
  612. static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter,
  613. struct ixgbe_ring *tx_ring,
  614. unsigned int eop)
  615. {
  616. struct ixgbe_hw *hw = &adapter->hw;
  617. /* Detect a transmit hang in hardware, this serializes the
  618. * check with the clearing of time_stamp and movement of eop */
  619. adapter->detect_tx_hung = false;
  620. if (tx_ring->tx_buffer_info[eop].time_stamp &&
  621. time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) &&
  622. ixgbe_tx_xon_state(adapter, tx_ring)) {
  623. /* detected Tx unit hang */
  624. union ixgbe_adv_tx_desc *tx_desc;
  625. tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
  626. e_err(drv, "Detected Tx Unit Hang\n"
  627. " Tx Queue <%d>\n"
  628. " TDH, TDT <%x>, <%x>\n"
  629. " next_to_use <%x>\n"
  630. " next_to_clean <%x>\n"
  631. "tx_buffer_info[next_to_clean]\n"
  632. " time_stamp <%lx>\n"
  633. " jiffies <%lx>\n",
  634. tx_ring->queue_index,
  635. IXGBE_READ_REG(hw, tx_ring->head),
  636. IXGBE_READ_REG(hw, tx_ring->tail),
  637. tx_ring->next_to_use, eop,
  638. tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
  639. return true;
  640. }
  641. return false;
  642. }
  643. #define IXGBE_MAX_TXD_PWR 14
  644. #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
  645. /* Tx Descriptors needed, worst case */
  646. #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
  647. (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
  648. #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
  649. MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
  650. static void ixgbe_tx_timeout(struct net_device *netdev);
  651. /**
  652. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  653. * @q_vector: structure containing interrupt and ring information
  654. * @tx_ring: tx ring to clean
  655. **/
  656. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  657. struct ixgbe_ring *tx_ring)
  658. {
  659. struct ixgbe_adapter *adapter = q_vector->adapter;
  660. struct net_device *netdev = adapter->netdev;
  661. union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
  662. struct ixgbe_tx_buffer *tx_buffer_info;
  663. unsigned int i, eop, count = 0;
  664. unsigned int total_bytes = 0, total_packets = 0;
  665. i = tx_ring->next_to_clean;
  666. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  667. eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
  668. while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
  669. (count < tx_ring->work_limit)) {
  670. bool cleaned = false;
  671. rmb(); /* read buffer_info after eop_desc */
  672. for ( ; !cleaned; count++) {
  673. struct sk_buff *skb;
  674. tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
  675. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  676. cleaned = (i == eop);
  677. skb = tx_buffer_info->skb;
  678. if (cleaned && skb) {
  679. unsigned int segs, bytecount;
  680. unsigned int hlen = skb_headlen(skb);
  681. /* gso_segs is currently only valid for tcp */
  682. segs = skb_shinfo(skb)->gso_segs ?: 1;
  683. #ifdef IXGBE_FCOE
  684. /* adjust for FCoE Sequence Offload */
  685. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  686. && skb_is_gso(skb)
  687. && vlan_get_protocol(skb) ==
  688. htons(ETH_P_FCOE)) {
  689. hlen = skb_transport_offset(skb) +
  690. sizeof(struct fc_frame_header) +
  691. sizeof(struct fcoe_crc_eof);
  692. segs = DIV_ROUND_UP(skb->len - hlen,
  693. skb_shinfo(skb)->gso_size);
  694. }
  695. #endif /* IXGBE_FCOE */
  696. /* multiply data chunks by size of headers */
  697. bytecount = ((segs - 1) * hlen) + skb->len;
  698. total_packets += segs;
  699. total_bytes += bytecount;
  700. }
  701. ixgbe_unmap_and_free_tx_resource(adapter,
  702. tx_buffer_info);
  703. tx_desc->wb.status = 0;
  704. i++;
  705. if (i == tx_ring->count)
  706. i = 0;
  707. }
  708. eop = tx_ring->tx_buffer_info[i].next_to_watch;
  709. eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
  710. }
  711. tx_ring->next_to_clean = i;
  712. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  713. if (unlikely(count && netif_carrier_ok(netdev) &&
  714. (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
  715. /* Make sure that anybody stopping the queue after this
  716. * sees the new next_to_clean.
  717. */
  718. smp_mb();
  719. if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
  720. !test_bit(__IXGBE_DOWN, &adapter->state)) {
  721. netif_wake_subqueue(netdev, tx_ring->queue_index);
  722. ++tx_ring->restart_queue;
  723. }
  724. }
  725. if (adapter->detect_tx_hung) {
  726. if (ixgbe_check_tx_hang(adapter, tx_ring, i)) {
  727. /* schedule immediate reset if we believe we hung */
  728. e_info(probe, "tx hang %d detected, resetting "
  729. "adapter\n", adapter->tx_timeout_count + 1);
  730. ixgbe_tx_timeout(adapter->netdev);
  731. }
  732. }
  733. /* re-arm the interrupt */
  734. if (count >= tx_ring->work_limit)
  735. ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx));
  736. tx_ring->total_bytes += total_bytes;
  737. tx_ring->total_packets += total_packets;
  738. u64_stats_update_begin(&tx_ring->syncp);
  739. tx_ring->stats.packets += total_packets;
  740. tx_ring->stats.bytes += total_bytes;
  741. u64_stats_update_end(&tx_ring->syncp);
  742. return count < tx_ring->work_limit;
  743. }
  744. #ifdef CONFIG_IXGBE_DCA
  745. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  746. struct ixgbe_ring *rx_ring)
  747. {
  748. u32 rxctrl;
  749. int cpu = get_cpu();
  750. int q = rx_ring->reg_idx;
  751. if (rx_ring->cpu != cpu) {
  752. rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q));
  753. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  754. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
  755. rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  756. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  757. rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
  758. rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  759. IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
  760. }
  761. rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  762. rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
  763. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
  764. rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
  765. IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
  766. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl);
  767. rx_ring->cpu = cpu;
  768. }
  769. put_cpu();
  770. }
  771. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  772. struct ixgbe_ring *tx_ring)
  773. {
  774. u32 txctrl;
  775. int cpu = get_cpu();
  776. int q = tx_ring->reg_idx;
  777. struct ixgbe_hw *hw = &adapter->hw;
  778. if (tx_ring->cpu != cpu) {
  779. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  780. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q));
  781. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
  782. txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  783. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  784. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl);
  785. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  786. txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q));
  787. txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
  788. txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
  789. IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
  790. txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  791. IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl);
  792. }
  793. tx_ring->cpu = cpu;
  794. }
  795. put_cpu();
  796. }
  797. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  798. {
  799. int i;
  800. if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
  801. return;
  802. /* always use CB2 mode, difference is masked in the CB driver */
  803. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
  804. for (i = 0; i < adapter->num_tx_queues; i++) {
  805. adapter->tx_ring[i]->cpu = -1;
  806. ixgbe_update_tx_dca(adapter, adapter->tx_ring[i]);
  807. }
  808. for (i = 0; i < adapter->num_rx_queues; i++) {
  809. adapter->rx_ring[i]->cpu = -1;
  810. ixgbe_update_rx_dca(adapter, adapter->rx_ring[i]);
  811. }
  812. }
  813. static int __ixgbe_notify_dca(struct device *dev, void *data)
  814. {
  815. struct net_device *netdev = dev_get_drvdata(dev);
  816. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  817. unsigned long event = *(unsigned long *)data;
  818. switch (event) {
  819. case DCA_PROVIDER_ADD:
  820. /* if we're already enabled, don't do it again */
  821. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  822. break;
  823. if (dca_add_requester(dev) == 0) {
  824. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  825. ixgbe_setup_dca(adapter);
  826. break;
  827. }
  828. /* Fall Through since DCA is disabled. */
  829. case DCA_PROVIDER_REMOVE:
  830. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  831. dca_remove_requester(dev);
  832. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  833. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  834. }
  835. break;
  836. }
  837. return 0;
  838. }
  839. #endif /* CONFIG_IXGBE_DCA */
  840. /**
  841. * ixgbe_receive_skb - Send a completed packet up the stack
  842. * @adapter: board private structure
  843. * @skb: packet to send up
  844. * @status: hardware indication of status of receive
  845. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  846. * @rx_desc: rx descriptor
  847. **/
  848. static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
  849. struct sk_buff *skb, u8 status,
  850. struct ixgbe_ring *ring,
  851. union ixgbe_adv_rx_desc *rx_desc)
  852. {
  853. struct ixgbe_adapter *adapter = q_vector->adapter;
  854. struct napi_struct *napi = &q_vector->napi;
  855. bool is_vlan = (status & IXGBE_RXD_STAT_VP);
  856. u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
  857. if (is_vlan && (tag & VLAN_VID_MASK))
  858. __vlan_hwaccel_put_tag(skb, tag);
  859. if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
  860. napi_gro_receive(napi, skb);
  861. else
  862. netif_rx(skb);
  863. }
  864. /**
  865. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  866. * @adapter: address of board private structure
  867. * @status_err: hardware indication of status of receive
  868. * @skb: skb currently being received and modified
  869. **/
  870. static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
  871. union ixgbe_adv_rx_desc *rx_desc,
  872. struct sk_buff *skb)
  873. {
  874. u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
  875. skb_checksum_none_assert(skb);
  876. /* Rx csum disabled */
  877. if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
  878. return;
  879. /* if IP and error */
  880. if ((status_err & IXGBE_RXD_STAT_IPCS) &&
  881. (status_err & IXGBE_RXDADV_ERR_IPE)) {
  882. adapter->hw_csum_rx_error++;
  883. return;
  884. }
  885. if (!(status_err & IXGBE_RXD_STAT_L4CS))
  886. return;
  887. if (status_err & IXGBE_RXDADV_ERR_TCPE) {
  888. u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  889. /*
  890. * 82599 errata, UDP frames with a 0 checksum can be marked as
  891. * checksum errors.
  892. */
  893. if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
  894. (adapter->hw.mac.type == ixgbe_mac_82599EB))
  895. return;
  896. adapter->hw_csum_rx_error++;
  897. return;
  898. }
  899. /* It must be a TCP or UDP packet with a valid checksum */
  900. skb->ip_summed = CHECKSUM_UNNECESSARY;
  901. }
  902. static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw,
  903. struct ixgbe_ring *rx_ring, u32 val)
  904. {
  905. /*
  906. * Force memory writes to complete before letting h/w
  907. * know there are new descriptors to fetch. (Only
  908. * applicable for weak-ordered memory model archs,
  909. * such as IA-64).
  910. */
  911. wmb();
  912. IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val);
  913. }
  914. /**
  915. * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
  916. * @adapter: address of board private structure
  917. **/
  918. void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter,
  919. struct ixgbe_ring *rx_ring,
  920. int cleaned_count)
  921. {
  922. struct net_device *netdev = adapter->netdev;
  923. struct pci_dev *pdev = adapter->pdev;
  924. union ixgbe_adv_rx_desc *rx_desc;
  925. struct ixgbe_rx_buffer *bi;
  926. unsigned int i;
  927. unsigned int bufsz = rx_ring->rx_buf_len;
  928. i = rx_ring->next_to_use;
  929. bi = &rx_ring->rx_buffer_info[i];
  930. while (cleaned_count--) {
  931. rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
  932. if (!bi->page_dma &&
  933. (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) {
  934. if (!bi->page) {
  935. bi->page = netdev_alloc_page(netdev);
  936. if (!bi->page) {
  937. adapter->alloc_rx_page_failed++;
  938. goto no_buffers;
  939. }
  940. bi->page_offset = 0;
  941. } else {
  942. /* use a half page if we're re-using */
  943. bi->page_offset ^= (PAGE_SIZE / 2);
  944. }
  945. bi->page_dma = dma_map_page(&pdev->dev, bi->page,
  946. bi->page_offset,
  947. (PAGE_SIZE / 2),
  948. DMA_FROM_DEVICE);
  949. }
  950. if (!bi->skb) {
  951. struct sk_buff *skb = netdev_alloc_skb_ip_align(netdev,
  952. bufsz);
  953. bi->skb = skb;
  954. if (!skb) {
  955. adapter->alloc_rx_buff_failed++;
  956. goto no_buffers;
  957. }
  958. /* initialize queue mapping */
  959. skb_record_rx_queue(skb, rx_ring->queue_index);
  960. }
  961. if (!bi->dma) {
  962. bi->dma = dma_map_single(&pdev->dev,
  963. bi->skb->data,
  964. rx_ring->rx_buf_len,
  965. DMA_FROM_DEVICE);
  966. }
  967. /* Refresh the desc even if buffer_addrs didn't change because
  968. * each write-back erases this info. */
  969. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  970. rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
  971. rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
  972. } else {
  973. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
  974. rx_desc->read.hdr_addr = 0;
  975. }
  976. i++;
  977. if (i == rx_ring->count)
  978. i = 0;
  979. bi = &rx_ring->rx_buffer_info[i];
  980. }
  981. no_buffers:
  982. if (rx_ring->next_to_use != i) {
  983. rx_ring->next_to_use = i;
  984. if (i-- == 0)
  985. i = (rx_ring->count - 1);
  986. ixgbe_release_rx_desc(&adapter->hw, rx_ring, i);
  987. }
  988. }
  989. static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc)
  990. {
  991. return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info;
  992. }
  993. static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc)
  994. {
  995. return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  996. }
  997. static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc)
  998. {
  999. return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
  1000. IXGBE_RXDADV_RSCCNT_MASK) >>
  1001. IXGBE_RXDADV_RSCCNT_SHIFT;
  1002. }
  1003. /**
  1004. * ixgbe_transform_rsc_queue - change rsc queue into a full packet
  1005. * @skb: pointer to the last skb in the rsc queue
  1006. * @count: pointer to number of packets coalesced in this context
  1007. *
  1008. * This function changes a queue full of hw rsc buffers into a completed
  1009. * packet. It uses the ->prev pointers to find the first packet and then
  1010. * turns it into the frag list owner.
  1011. **/
  1012. static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb,
  1013. u64 *count)
  1014. {
  1015. unsigned int frag_list_size = 0;
  1016. while (skb->prev) {
  1017. struct sk_buff *prev = skb->prev;
  1018. frag_list_size += skb->len;
  1019. skb->prev = NULL;
  1020. skb = prev;
  1021. *count += 1;
  1022. }
  1023. skb_shinfo(skb)->frag_list = skb->next;
  1024. skb->next = NULL;
  1025. skb->len += frag_list_size;
  1026. skb->data_len += frag_list_size;
  1027. skb->truesize += frag_list_size;
  1028. return skb;
  1029. }
  1030. struct ixgbe_rsc_cb {
  1031. dma_addr_t dma;
  1032. bool delay_unmap;
  1033. };
  1034. #define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb)
  1035. static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1036. struct ixgbe_ring *rx_ring,
  1037. int *work_done, int work_to_do)
  1038. {
  1039. struct ixgbe_adapter *adapter = q_vector->adapter;
  1040. struct pci_dev *pdev = adapter->pdev;
  1041. union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
  1042. struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
  1043. struct sk_buff *skb;
  1044. unsigned int i, rsc_count = 0;
  1045. u32 len, staterr;
  1046. u16 hdr_info;
  1047. bool cleaned = false;
  1048. int cleaned_count = 0;
  1049. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1050. #ifdef IXGBE_FCOE
  1051. int ddp_bytes = 0;
  1052. #endif /* IXGBE_FCOE */
  1053. i = rx_ring->next_to_clean;
  1054. rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
  1055. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1056. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  1057. while (staterr & IXGBE_RXD_STAT_DD) {
  1058. u32 upper_len = 0;
  1059. if (*work_done >= work_to_do)
  1060. break;
  1061. (*work_done)++;
  1062. rmb(); /* read descriptor and rx_buffer_info after status DD */
  1063. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1064. hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc));
  1065. len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
  1066. IXGBE_RXDADV_HDRBUFLEN_SHIFT;
  1067. upper_len = le16_to_cpu(rx_desc->wb.upper.length);
  1068. if ((len > IXGBE_RX_HDR_SIZE) ||
  1069. (upper_len && !(hdr_info & IXGBE_RXDADV_SPH)))
  1070. len = IXGBE_RX_HDR_SIZE;
  1071. } else {
  1072. len = le16_to_cpu(rx_desc->wb.upper.length);
  1073. }
  1074. cleaned = true;
  1075. skb = rx_buffer_info->skb;
  1076. prefetch(skb->data);
  1077. rx_buffer_info->skb = NULL;
  1078. if (rx_buffer_info->dma) {
  1079. if ((adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
  1080. (!(staterr & IXGBE_RXD_STAT_EOP)) &&
  1081. (!(skb->prev))) {
  1082. /*
  1083. * When HWRSC is enabled, delay unmapping
  1084. * of the first packet. It carries the
  1085. * header information, HW may still
  1086. * access the header after the writeback.
  1087. * Only unmap it when EOP is reached
  1088. */
  1089. IXGBE_RSC_CB(skb)->delay_unmap = true;
  1090. IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
  1091. } else {
  1092. dma_unmap_single(&pdev->dev,
  1093. rx_buffer_info->dma,
  1094. rx_ring->rx_buf_len,
  1095. DMA_FROM_DEVICE);
  1096. }
  1097. rx_buffer_info->dma = 0;
  1098. skb_put(skb, len);
  1099. }
  1100. if (upper_len) {
  1101. dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma,
  1102. PAGE_SIZE / 2, DMA_FROM_DEVICE);
  1103. rx_buffer_info->page_dma = 0;
  1104. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  1105. rx_buffer_info->page,
  1106. rx_buffer_info->page_offset,
  1107. upper_len);
  1108. if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) ||
  1109. (page_count(rx_buffer_info->page) != 1))
  1110. rx_buffer_info->page = NULL;
  1111. else
  1112. get_page(rx_buffer_info->page);
  1113. skb->len += upper_len;
  1114. skb->data_len += upper_len;
  1115. skb->truesize += upper_len;
  1116. }
  1117. i++;
  1118. if (i == rx_ring->count)
  1119. i = 0;
  1120. next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
  1121. prefetch(next_rxd);
  1122. cleaned_count++;
  1123. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  1124. rsc_count = ixgbe_get_rsc_count(rx_desc);
  1125. if (rsc_count) {
  1126. u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
  1127. IXGBE_RXDADV_NEXTP_SHIFT;
  1128. next_buffer = &rx_ring->rx_buffer_info[nextp];
  1129. } else {
  1130. next_buffer = &rx_ring->rx_buffer_info[i];
  1131. }
  1132. if (staterr & IXGBE_RXD_STAT_EOP) {
  1133. if (skb->prev)
  1134. skb = ixgbe_transform_rsc_queue(skb,
  1135. &(rx_ring->rsc_count));
  1136. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  1137. if (IXGBE_RSC_CB(skb)->delay_unmap) {
  1138. dma_unmap_single(&pdev->dev,
  1139. IXGBE_RSC_CB(skb)->dma,
  1140. rx_ring->rx_buf_len,
  1141. DMA_FROM_DEVICE);
  1142. IXGBE_RSC_CB(skb)->dma = 0;
  1143. IXGBE_RSC_CB(skb)->delay_unmap = false;
  1144. }
  1145. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)
  1146. rx_ring->rsc_count +=
  1147. skb_shinfo(skb)->nr_frags;
  1148. else
  1149. rx_ring->rsc_count++;
  1150. rx_ring->rsc_flush++;
  1151. }
  1152. u64_stats_update_begin(&rx_ring->syncp);
  1153. rx_ring->stats.packets++;
  1154. rx_ring->stats.bytes += skb->len;
  1155. u64_stats_update_end(&rx_ring->syncp);
  1156. } else {
  1157. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  1158. rx_buffer_info->skb = next_buffer->skb;
  1159. rx_buffer_info->dma = next_buffer->dma;
  1160. next_buffer->skb = skb;
  1161. next_buffer->dma = 0;
  1162. } else {
  1163. skb->next = next_buffer->skb;
  1164. skb->next->prev = skb;
  1165. }
  1166. rx_ring->non_eop_descs++;
  1167. goto next_desc;
  1168. }
  1169. if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
  1170. dev_kfree_skb_irq(skb);
  1171. goto next_desc;
  1172. }
  1173. ixgbe_rx_checksum(adapter, rx_desc, skb);
  1174. /* probably a little skewed due to removing CRC */
  1175. total_rx_bytes += skb->len;
  1176. total_rx_packets++;
  1177. skb->protocol = eth_type_trans(skb, adapter->netdev);
  1178. #ifdef IXGBE_FCOE
  1179. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  1180. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  1181. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  1182. if (!ddp_bytes)
  1183. goto next_desc;
  1184. }
  1185. #endif /* IXGBE_FCOE */
  1186. ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
  1187. next_desc:
  1188. rx_desc->wb.upper.status_error = 0;
  1189. /* return some buffers to hardware, one at a time is too slow */
  1190. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1191. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  1192. cleaned_count = 0;
  1193. }
  1194. /* use prefetched values */
  1195. rx_desc = next_rxd;
  1196. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  1197. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1198. }
  1199. rx_ring->next_to_clean = i;
  1200. cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
  1201. if (cleaned_count)
  1202. ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count);
  1203. #ifdef IXGBE_FCOE
  1204. /* include DDPed FCoE data */
  1205. if (ddp_bytes > 0) {
  1206. unsigned int mss;
  1207. mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) -
  1208. sizeof(struct fc_frame_header) -
  1209. sizeof(struct fcoe_crc_eof);
  1210. if (mss > 512)
  1211. mss &= ~511;
  1212. total_rx_bytes += ddp_bytes;
  1213. total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
  1214. }
  1215. #endif /* IXGBE_FCOE */
  1216. rx_ring->total_packets += total_rx_packets;
  1217. rx_ring->total_bytes += total_rx_bytes;
  1218. return cleaned;
  1219. }
  1220. static int ixgbe_clean_rxonly(struct napi_struct *, int);
  1221. /**
  1222. * ixgbe_configure_msix - Configure MSI-X hardware
  1223. * @adapter: board private structure
  1224. *
  1225. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  1226. * interrupts.
  1227. **/
  1228. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  1229. {
  1230. struct ixgbe_q_vector *q_vector;
  1231. int i, j, q_vectors, v_idx, r_idx;
  1232. u32 mask;
  1233. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1234. /*
  1235. * Populate the IVAR table and set the ITR values to the
  1236. * corresponding register.
  1237. */
  1238. for (v_idx = 0; v_idx < q_vectors; v_idx++) {
  1239. q_vector = adapter->q_vector[v_idx];
  1240. /* XXX for_each_set_bit(...) */
  1241. r_idx = find_first_bit(q_vector->rxr_idx,
  1242. adapter->num_rx_queues);
  1243. for (i = 0; i < q_vector->rxr_count; i++) {
  1244. j = adapter->rx_ring[r_idx]->reg_idx;
  1245. ixgbe_set_ivar(adapter, 0, j, v_idx);
  1246. r_idx = find_next_bit(q_vector->rxr_idx,
  1247. adapter->num_rx_queues,
  1248. r_idx + 1);
  1249. }
  1250. r_idx = find_first_bit(q_vector->txr_idx,
  1251. adapter->num_tx_queues);
  1252. for (i = 0; i < q_vector->txr_count; i++) {
  1253. j = adapter->tx_ring[r_idx]->reg_idx;
  1254. ixgbe_set_ivar(adapter, 1, j, v_idx);
  1255. r_idx = find_next_bit(q_vector->txr_idx,
  1256. adapter->num_tx_queues,
  1257. r_idx + 1);
  1258. }
  1259. if (q_vector->txr_count && !q_vector->rxr_count)
  1260. /* tx only */
  1261. q_vector->eitr = adapter->tx_eitr_param;
  1262. else if (q_vector->rxr_count)
  1263. /* rx or mixed */
  1264. q_vector->eitr = adapter->rx_eitr_param;
  1265. ixgbe_write_eitr(q_vector);
  1266. /* If Flow Director is enabled, set interrupt affinity */
  1267. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  1268. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
  1269. /*
  1270. * Allocate the affinity_hint cpumask, assign the mask
  1271. * for this vector, and set our affinity_hint for
  1272. * this irq.
  1273. */
  1274. if (!alloc_cpumask_var(&q_vector->affinity_mask,
  1275. GFP_KERNEL))
  1276. return;
  1277. cpumask_set_cpu(v_idx, q_vector->affinity_mask);
  1278. irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
  1279. q_vector->affinity_mask);
  1280. }
  1281. }
  1282. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  1283. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  1284. v_idx);
  1285. else if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  1286. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  1287. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  1288. /* set up to autoclear timer, and the vectors */
  1289. mask = IXGBE_EIMS_ENABLE_MASK;
  1290. if (adapter->num_vfs)
  1291. mask &= ~(IXGBE_EIMS_OTHER |
  1292. IXGBE_EIMS_MAILBOX |
  1293. IXGBE_EIMS_LSC);
  1294. else
  1295. mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
  1296. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  1297. }
  1298. enum latency_range {
  1299. lowest_latency = 0,
  1300. low_latency = 1,
  1301. bulk_latency = 2,
  1302. latency_invalid = 255
  1303. };
  1304. /**
  1305. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  1306. * @adapter: pointer to adapter
  1307. * @eitr: eitr setting (ints per sec) to give last timeslice
  1308. * @itr_setting: current throttle rate in ints/second
  1309. * @packets: the number of packets during this measurement interval
  1310. * @bytes: the number of bytes during this measurement interval
  1311. *
  1312. * Stores a new ITR value based on packets and byte
  1313. * counts during the last interrupt. The advantage of per interrupt
  1314. * computation is faster updates and more accurate ITR for the current
  1315. * traffic pattern. Constants in this function were computed
  1316. * based on theoretical maximum wire speed and thresholds were set based
  1317. * on testing data as well as attempting to minimize response time
  1318. * while increasing bulk throughput.
  1319. * this functionality is controlled by the InterruptThrottleRate module
  1320. * parameter (see ixgbe_param.c)
  1321. **/
  1322. static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
  1323. u32 eitr, u8 itr_setting,
  1324. int packets, int bytes)
  1325. {
  1326. unsigned int retval = itr_setting;
  1327. u32 timepassed_us;
  1328. u64 bytes_perint;
  1329. if (packets == 0)
  1330. goto update_itr_done;
  1331. /* simple throttlerate management
  1332. * 0-20MB/s lowest (100000 ints/s)
  1333. * 20-100MB/s low (20000 ints/s)
  1334. * 100-1249MB/s bulk (8000 ints/s)
  1335. */
  1336. /* what was last interrupt timeslice? */
  1337. timepassed_us = 1000000/eitr;
  1338. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  1339. switch (itr_setting) {
  1340. case lowest_latency:
  1341. if (bytes_perint > adapter->eitr_low)
  1342. retval = low_latency;
  1343. break;
  1344. case low_latency:
  1345. if (bytes_perint > adapter->eitr_high)
  1346. retval = bulk_latency;
  1347. else if (bytes_perint <= adapter->eitr_low)
  1348. retval = lowest_latency;
  1349. break;
  1350. case bulk_latency:
  1351. if (bytes_perint <= adapter->eitr_high)
  1352. retval = low_latency;
  1353. break;
  1354. }
  1355. update_itr_done:
  1356. return retval;
  1357. }
  1358. /**
  1359. * ixgbe_write_eitr - write EITR register in hardware specific way
  1360. * @q_vector: structure containing interrupt and ring information
  1361. *
  1362. * This function is made to be called by ethtool and by the driver
  1363. * when it needs to update EITR registers at runtime. Hardware
  1364. * specific quirks/differences are taken care of here.
  1365. */
  1366. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  1367. {
  1368. struct ixgbe_adapter *adapter = q_vector->adapter;
  1369. struct ixgbe_hw *hw = &adapter->hw;
  1370. int v_idx = q_vector->v_idx;
  1371. u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
  1372. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1373. /* must write high and low 16 bits to reset counter */
  1374. itr_reg |= (itr_reg << 16);
  1375. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  1376. /*
  1377. * 82599 can support a value of zero, so allow it for
  1378. * max interrupt rate, but there is an errata where it can
  1379. * not be zero with RSC
  1380. */
  1381. if (itr_reg == 8 &&
  1382. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  1383. itr_reg = 0;
  1384. /*
  1385. * set the WDIS bit to not clear the timer bits and cause an
  1386. * immediate assertion of the interrupt
  1387. */
  1388. itr_reg |= IXGBE_EITR_CNT_WDIS;
  1389. }
  1390. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  1391. }
  1392. static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
  1393. {
  1394. struct ixgbe_adapter *adapter = q_vector->adapter;
  1395. u32 new_itr;
  1396. u8 current_itr, ret_itr;
  1397. int i, r_idx;
  1398. struct ixgbe_ring *rx_ring, *tx_ring;
  1399. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1400. for (i = 0; i < q_vector->txr_count; i++) {
  1401. tx_ring = adapter->tx_ring[r_idx];
  1402. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  1403. q_vector->tx_itr,
  1404. tx_ring->total_packets,
  1405. tx_ring->total_bytes);
  1406. /* if the result for this queue would decrease interrupt
  1407. * rate for this vector then use that result */
  1408. q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
  1409. q_vector->tx_itr - 1 : ret_itr);
  1410. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1411. r_idx + 1);
  1412. }
  1413. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1414. for (i = 0; i < q_vector->rxr_count; i++) {
  1415. rx_ring = adapter->rx_ring[r_idx];
  1416. ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
  1417. q_vector->rx_itr,
  1418. rx_ring->total_packets,
  1419. rx_ring->total_bytes);
  1420. /* if the result for this queue would decrease interrupt
  1421. * rate for this vector then use that result */
  1422. q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
  1423. q_vector->rx_itr - 1 : ret_itr);
  1424. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1425. r_idx + 1);
  1426. }
  1427. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1428. switch (current_itr) {
  1429. /* counts and packets in update_itr are dependent on these numbers */
  1430. case lowest_latency:
  1431. new_itr = 100000;
  1432. break;
  1433. case low_latency:
  1434. new_itr = 20000; /* aka hwitr = ~200 */
  1435. break;
  1436. case bulk_latency:
  1437. default:
  1438. new_itr = 8000;
  1439. break;
  1440. }
  1441. if (new_itr != q_vector->eitr) {
  1442. /* do an exponential smoothing */
  1443. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1444. /* save the algorithm value here, not the smoothed one */
  1445. q_vector->eitr = new_itr;
  1446. ixgbe_write_eitr(q_vector);
  1447. }
  1448. }
  1449. /**
  1450. * ixgbe_check_overtemp_task - worker thread to check over tempurature
  1451. * @work: pointer to work_struct containing our data
  1452. **/
  1453. static void ixgbe_check_overtemp_task(struct work_struct *work)
  1454. {
  1455. struct ixgbe_adapter *adapter = container_of(work,
  1456. struct ixgbe_adapter,
  1457. check_overtemp_task);
  1458. struct ixgbe_hw *hw = &adapter->hw;
  1459. u32 eicr = adapter->interrupt_event;
  1460. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  1461. return;
  1462. switch (hw->device_id) {
  1463. case IXGBE_DEV_ID_82599_T3_LOM: {
  1464. u32 autoneg;
  1465. bool link_up = false;
  1466. if (hw->mac.ops.check_link)
  1467. hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
  1468. if (((eicr & IXGBE_EICR_GPI_SDP0) && (!link_up)) ||
  1469. (eicr & IXGBE_EICR_LSC))
  1470. /* Check if this is due to overtemp */
  1471. if (hw->phy.ops.check_overtemp(hw) == IXGBE_ERR_OVERTEMP)
  1472. break;
  1473. return;
  1474. }
  1475. default:
  1476. if (!(eicr & IXGBE_EICR_GPI_SDP0))
  1477. return;
  1478. break;
  1479. }
  1480. e_crit(drv,
  1481. "Network adapter has been stopped because it has over heated. "
  1482. "Restart the computer. If the problem persists, "
  1483. "power off the system and replace the adapter\n");
  1484. /* write to clear the interrupt */
  1485. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0);
  1486. }
  1487. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  1488. {
  1489. struct ixgbe_hw *hw = &adapter->hw;
  1490. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  1491. (eicr & IXGBE_EICR_GPI_SDP1)) {
  1492. e_crit(probe, "Fan has stopped, replace the adapter\n");
  1493. /* write to clear the interrupt */
  1494. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1495. }
  1496. }
  1497. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  1498. {
  1499. struct ixgbe_hw *hw = &adapter->hw;
  1500. if (eicr & IXGBE_EICR_GPI_SDP1) {
  1501. /* Clear the interrupt */
  1502. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1503. schedule_work(&adapter->multispeed_fiber_task);
  1504. } else if (eicr & IXGBE_EICR_GPI_SDP2) {
  1505. /* Clear the interrupt */
  1506. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
  1507. schedule_work(&adapter->sfp_config_module_task);
  1508. } else {
  1509. /* Interrupt isn't for us... */
  1510. return;
  1511. }
  1512. }
  1513. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  1514. {
  1515. struct ixgbe_hw *hw = &adapter->hw;
  1516. adapter->lsc_int++;
  1517. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  1518. adapter->link_check_timeout = jiffies;
  1519. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  1520. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  1521. IXGBE_WRITE_FLUSH(hw);
  1522. schedule_work(&adapter->watchdog_task);
  1523. }
  1524. }
  1525. static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
  1526. {
  1527. struct net_device *netdev = data;
  1528. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  1529. struct ixgbe_hw *hw = &adapter->hw;
  1530. u32 eicr;
  1531. /*
  1532. * Workaround for Silicon errata. Use clear-by-write instead
  1533. * of clear-by-read. Reading with EICS will return the
  1534. * interrupt causes without clearing, which later be done
  1535. * with the write to EICR.
  1536. */
  1537. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  1538. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  1539. if (eicr & IXGBE_EICR_LSC)
  1540. ixgbe_check_lsc(adapter);
  1541. if (eicr & IXGBE_EICR_MAILBOX)
  1542. ixgbe_msg_task(adapter);
  1543. if (hw->mac.type == ixgbe_mac_82598EB)
  1544. ixgbe_check_fan_failure(adapter, eicr);
  1545. if (hw->mac.type == ixgbe_mac_82599EB) {
  1546. ixgbe_check_sfp_event(adapter, eicr);
  1547. adapter->interrupt_event = eicr;
  1548. if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  1549. ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)))
  1550. schedule_work(&adapter->check_overtemp_task);
  1551. /* Handle Flow Director Full threshold interrupt */
  1552. if (eicr & IXGBE_EICR_FLOW_DIR) {
  1553. int i;
  1554. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
  1555. /* Disable transmits before FDIR Re-initialization */
  1556. netif_tx_stop_all_queues(netdev);
  1557. for (i = 0; i < adapter->num_tx_queues; i++) {
  1558. struct ixgbe_ring *tx_ring =
  1559. adapter->tx_ring[i];
  1560. if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE,
  1561. &tx_ring->reinit_state))
  1562. schedule_work(&adapter->fdir_reinit_task);
  1563. }
  1564. }
  1565. }
  1566. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1567. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
  1568. return IRQ_HANDLED;
  1569. }
  1570. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  1571. u64 qmask)
  1572. {
  1573. u32 mask;
  1574. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1575. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1576. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1577. } else {
  1578. mask = (qmask & 0xFFFFFFFF);
  1579. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask);
  1580. mask = (qmask >> 32);
  1581. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask);
  1582. }
  1583. /* skip the flush */
  1584. }
  1585. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  1586. u64 qmask)
  1587. {
  1588. u32 mask;
  1589. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  1590. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  1591. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask);
  1592. } else {
  1593. mask = (qmask & 0xFFFFFFFF);
  1594. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask);
  1595. mask = (qmask >> 32);
  1596. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask);
  1597. }
  1598. /* skip the flush */
  1599. }
  1600. static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
  1601. {
  1602. struct ixgbe_q_vector *q_vector = data;
  1603. struct ixgbe_adapter *adapter = q_vector->adapter;
  1604. struct ixgbe_ring *tx_ring;
  1605. int i, r_idx;
  1606. if (!q_vector->txr_count)
  1607. return IRQ_HANDLED;
  1608. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1609. for (i = 0; i < q_vector->txr_count; i++) {
  1610. tx_ring = adapter->tx_ring[r_idx];
  1611. tx_ring->total_bytes = 0;
  1612. tx_ring->total_packets = 0;
  1613. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1614. r_idx + 1);
  1615. }
  1616. /* EIAM disabled interrupts (on this vector) for us */
  1617. napi_schedule(&q_vector->napi);
  1618. return IRQ_HANDLED;
  1619. }
  1620. /**
  1621. * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
  1622. * @irq: unused
  1623. * @data: pointer to our q_vector struct for this interrupt vector
  1624. **/
  1625. static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
  1626. {
  1627. struct ixgbe_q_vector *q_vector = data;
  1628. struct ixgbe_adapter *adapter = q_vector->adapter;
  1629. struct ixgbe_ring *rx_ring;
  1630. int r_idx;
  1631. int i;
  1632. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1633. for (i = 0; i < q_vector->rxr_count; i++) {
  1634. rx_ring = adapter->rx_ring[r_idx];
  1635. rx_ring->total_bytes = 0;
  1636. rx_ring->total_packets = 0;
  1637. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1638. r_idx + 1);
  1639. }
  1640. if (!q_vector->rxr_count)
  1641. return IRQ_HANDLED;
  1642. /* disable interrupts on this vector only */
  1643. /* EIAM disabled interrupts (on this vector) for us */
  1644. napi_schedule(&q_vector->napi);
  1645. return IRQ_HANDLED;
  1646. }
  1647. static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
  1648. {
  1649. struct ixgbe_q_vector *q_vector = data;
  1650. struct ixgbe_adapter *adapter = q_vector->adapter;
  1651. struct ixgbe_ring *ring;
  1652. int r_idx;
  1653. int i;
  1654. if (!q_vector->txr_count && !q_vector->rxr_count)
  1655. return IRQ_HANDLED;
  1656. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1657. for (i = 0; i < q_vector->txr_count; i++) {
  1658. ring = adapter->tx_ring[r_idx];
  1659. ring->total_bytes = 0;
  1660. ring->total_packets = 0;
  1661. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1662. r_idx + 1);
  1663. }
  1664. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1665. for (i = 0; i < q_vector->rxr_count; i++) {
  1666. ring = adapter->rx_ring[r_idx];
  1667. ring->total_bytes = 0;
  1668. ring->total_packets = 0;
  1669. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1670. r_idx + 1);
  1671. }
  1672. /* EIAM disabled interrupts (on this vector) for us */
  1673. napi_schedule(&q_vector->napi);
  1674. return IRQ_HANDLED;
  1675. }
  1676. /**
  1677. * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
  1678. * @napi: napi struct with our devices info in it
  1679. * @budget: amount of work driver is allowed to do this pass, in packets
  1680. *
  1681. * This function is optimized for cleaning one queue only on a single
  1682. * q_vector!!!
  1683. **/
  1684. static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
  1685. {
  1686. struct ixgbe_q_vector *q_vector =
  1687. container_of(napi, struct ixgbe_q_vector, napi);
  1688. struct ixgbe_adapter *adapter = q_vector->adapter;
  1689. struct ixgbe_ring *rx_ring = NULL;
  1690. int work_done = 0;
  1691. long r_idx;
  1692. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1693. rx_ring = adapter->rx_ring[r_idx];
  1694. #ifdef CONFIG_IXGBE_DCA
  1695. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1696. ixgbe_update_rx_dca(adapter, rx_ring);
  1697. #endif
  1698. ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
  1699. /* If all Rx work done, exit the polling mode */
  1700. if (work_done < budget) {
  1701. napi_complete(napi);
  1702. if (adapter->rx_itr_setting & 1)
  1703. ixgbe_set_itr_msix(q_vector);
  1704. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1705. ixgbe_irq_enable_queues(adapter,
  1706. ((u64)1 << q_vector->v_idx));
  1707. }
  1708. return work_done;
  1709. }
  1710. /**
  1711. * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
  1712. * @napi: napi struct with our devices info in it
  1713. * @budget: amount of work driver is allowed to do this pass, in packets
  1714. *
  1715. * This function will clean more than one rx queue associated with a
  1716. * q_vector.
  1717. **/
  1718. static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
  1719. {
  1720. struct ixgbe_q_vector *q_vector =
  1721. container_of(napi, struct ixgbe_q_vector, napi);
  1722. struct ixgbe_adapter *adapter = q_vector->adapter;
  1723. struct ixgbe_ring *ring = NULL;
  1724. int work_done = 0, i;
  1725. long r_idx;
  1726. bool tx_clean_complete = true;
  1727. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1728. for (i = 0; i < q_vector->txr_count; i++) {
  1729. ring = adapter->tx_ring[r_idx];
  1730. #ifdef CONFIG_IXGBE_DCA
  1731. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1732. ixgbe_update_tx_dca(adapter, ring);
  1733. #endif
  1734. tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
  1735. r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
  1736. r_idx + 1);
  1737. }
  1738. /* attempt to distribute budget to each queue fairly, but don't allow
  1739. * the budget to go below 1 because we'll exit polling */
  1740. budget /= (q_vector->rxr_count ?: 1);
  1741. budget = max(budget, 1);
  1742. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1743. for (i = 0; i < q_vector->rxr_count; i++) {
  1744. ring = adapter->rx_ring[r_idx];
  1745. #ifdef CONFIG_IXGBE_DCA
  1746. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1747. ixgbe_update_rx_dca(adapter, ring);
  1748. #endif
  1749. ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
  1750. r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
  1751. r_idx + 1);
  1752. }
  1753. r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
  1754. ring = adapter->rx_ring[r_idx];
  1755. /* If all Rx work done, exit the polling mode */
  1756. if (work_done < budget) {
  1757. napi_complete(napi);
  1758. if (adapter->rx_itr_setting & 1)
  1759. ixgbe_set_itr_msix(q_vector);
  1760. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1761. ixgbe_irq_enable_queues(adapter,
  1762. ((u64)1 << q_vector->v_idx));
  1763. return 0;
  1764. }
  1765. return work_done;
  1766. }
  1767. /**
  1768. * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
  1769. * @napi: napi struct with our devices info in it
  1770. * @budget: amount of work driver is allowed to do this pass, in packets
  1771. *
  1772. * This function is optimized for cleaning one queue only on a single
  1773. * q_vector!!!
  1774. **/
  1775. static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
  1776. {
  1777. struct ixgbe_q_vector *q_vector =
  1778. container_of(napi, struct ixgbe_q_vector, napi);
  1779. struct ixgbe_adapter *adapter = q_vector->adapter;
  1780. struct ixgbe_ring *tx_ring = NULL;
  1781. int work_done = 0;
  1782. long r_idx;
  1783. r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
  1784. tx_ring = adapter->tx_ring[r_idx];
  1785. #ifdef CONFIG_IXGBE_DCA
  1786. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1787. ixgbe_update_tx_dca(adapter, tx_ring);
  1788. #endif
  1789. if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
  1790. work_done = budget;
  1791. /* If all Tx work done, exit the polling mode */
  1792. if (work_done < budget) {
  1793. napi_complete(napi);
  1794. if (adapter->tx_itr_setting & 1)
  1795. ixgbe_set_itr_msix(q_vector);
  1796. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  1797. ixgbe_irq_enable_queues(adapter,
  1798. ((u64)1 << q_vector->v_idx));
  1799. }
  1800. return work_done;
  1801. }
  1802. static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
  1803. int r_idx)
  1804. {
  1805. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1806. set_bit(r_idx, q_vector->rxr_idx);
  1807. q_vector->rxr_count++;
  1808. }
  1809. static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
  1810. int t_idx)
  1811. {
  1812. struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
  1813. set_bit(t_idx, q_vector->txr_idx);
  1814. q_vector->txr_count++;
  1815. }
  1816. /**
  1817. * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
  1818. * @adapter: board private structure to initialize
  1819. * @vectors: allotted vector count for descriptor rings
  1820. *
  1821. * This function maps descriptor rings to the queue-specific vectors
  1822. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  1823. * one vector per ring/queue, but on a constrained vector budget, we
  1824. * group the rings as "efficiently" as possible. You would add new
  1825. * mapping configurations in here.
  1826. **/
  1827. static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter,
  1828. int vectors)
  1829. {
  1830. int v_start = 0;
  1831. int rxr_idx = 0, txr_idx = 0;
  1832. int rxr_remaining = adapter->num_rx_queues;
  1833. int txr_remaining = adapter->num_tx_queues;
  1834. int i, j;
  1835. int rqpv, tqpv;
  1836. int err = 0;
  1837. /* No mapping required if MSI-X is disabled. */
  1838. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  1839. goto out;
  1840. /*
  1841. * The ideal configuration...
  1842. * We have enough vectors to map one per queue.
  1843. */
  1844. if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
  1845. for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
  1846. map_vector_to_rxq(adapter, v_start, rxr_idx);
  1847. for (; txr_idx < txr_remaining; v_start++, txr_idx++)
  1848. map_vector_to_txq(adapter, v_start, txr_idx);
  1849. goto out;
  1850. }
  1851. /*
  1852. * If we don't have enough vectors for a 1-to-1
  1853. * mapping, we'll have to group them so there are
  1854. * multiple queues per vector.
  1855. */
  1856. /* Re-adjusting *qpv takes care of the remainder. */
  1857. for (i = v_start; i < vectors; i++) {
  1858. rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i);
  1859. for (j = 0; j < rqpv; j++) {
  1860. map_vector_to_rxq(adapter, i, rxr_idx);
  1861. rxr_idx++;
  1862. rxr_remaining--;
  1863. }
  1864. }
  1865. for (i = v_start; i < vectors; i++) {
  1866. tqpv = DIV_ROUND_UP(txr_remaining, vectors - i);
  1867. for (j = 0; j < tqpv; j++) {
  1868. map_vector_to_txq(adapter, i, txr_idx);
  1869. txr_idx++;
  1870. txr_remaining--;
  1871. }
  1872. }
  1873. out:
  1874. return err;
  1875. }
  1876. /**
  1877. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  1878. * @adapter: board private structure
  1879. *
  1880. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  1881. * interrupts from the kernel.
  1882. **/
  1883. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  1884. {
  1885. struct net_device *netdev = adapter->netdev;
  1886. irqreturn_t (*handler)(int, void *);
  1887. int i, vector, q_vectors, err;
  1888. int ri = 0, ti = 0;
  1889. /* Decrement for Other and TCP Timer vectors */
  1890. q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  1891. /* Map the Tx/Rx rings to the vectors we were allotted. */
  1892. err = ixgbe_map_rings_to_vectors(adapter, q_vectors);
  1893. if (err)
  1894. goto out;
  1895. #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \
  1896. (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \
  1897. &ixgbe_msix_clean_many)
  1898. for (vector = 0; vector < q_vectors; vector++) {
  1899. handler = SET_HANDLER(adapter->q_vector[vector]);
  1900. if (handler == &ixgbe_msix_clean_rx) {
  1901. sprintf(adapter->name[vector], "%s-%s-%d",
  1902. netdev->name, "rx", ri++);
  1903. } else if (handler == &ixgbe_msix_clean_tx) {
  1904. sprintf(adapter->name[vector], "%s-%s-%d",
  1905. netdev->name, "tx", ti++);
  1906. } else
  1907. sprintf(adapter->name[vector], "%s-%s-%d",
  1908. netdev->name, "TxRx", vector);
  1909. err = request_irq(adapter->msix_entries[vector].vector,
  1910. handler, 0, adapter->name[vector],
  1911. adapter->q_vector[vector]);
  1912. if (err) {
  1913. e_err(probe, "request_irq failed for MSIX interrupt "
  1914. "Error: %d\n", err);
  1915. goto free_queue_irqs;
  1916. }
  1917. }
  1918. sprintf(adapter->name[vector], "%s:lsc", netdev->name);
  1919. err = request_irq(adapter->msix_entries[vector].vector,
  1920. ixgbe_msix_lsc, 0, adapter->name[vector], netdev);
  1921. if (err) {
  1922. e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
  1923. goto free_queue_irqs;
  1924. }
  1925. return 0;
  1926. free_queue_irqs:
  1927. for (i = vector - 1; i >= 0; i--)
  1928. free_irq(adapter->msix_entries[--vector].vector,
  1929. adapter->q_vector[i]);
  1930. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  1931. pci_disable_msix(adapter->pdev);
  1932. kfree(adapter->msix_entries);
  1933. adapter->msix_entries = NULL;
  1934. out:
  1935. return err;
  1936. }
  1937. static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
  1938. {
  1939. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  1940. u8 current_itr;
  1941. u32 new_itr = q_vector->eitr;
  1942. struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
  1943. struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
  1944. q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
  1945. q_vector->tx_itr,
  1946. tx_ring->total_packets,
  1947. tx_ring->total_bytes);
  1948. q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
  1949. q_vector->rx_itr,
  1950. rx_ring->total_packets,
  1951. rx_ring->total_bytes);
  1952. current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
  1953. switch (current_itr) {
  1954. /* counts and packets in update_itr are dependent on these numbers */
  1955. case lowest_latency:
  1956. new_itr = 100000;
  1957. break;
  1958. case low_latency:
  1959. new_itr = 20000; /* aka hwitr = ~200 */
  1960. break;
  1961. case bulk_latency:
  1962. new_itr = 8000;
  1963. break;
  1964. default:
  1965. break;
  1966. }
  1967. if (new_itr != q_vector->eitr) {
  1968. /* do an exponential smoothing */
  1969. new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100);
  1970. /* save the algorithm value here, not the smoothed one */
  1971. q_vector->eitr = new_itr;
  1972. ixgbe_write_eitr(q_vector);
  1973. }
  1974. }
  1975. /**
  1976. * ixgbe_irq_enable - Enable default interrupt generation settings
  1977. * @adapter: board private structure
  1978. **/
  1979. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  1980. bool flush)
  1981. {
  1982. u32 mask;
  1983. mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  1984. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  1985. mask |= IXGBE_EIMS_GPI_SDP0;
  1986. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  1987. mask |= IXGBE_EIMS_GPI_SDP1;
  1988. if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  1989. mask |= IXGBE_EIMS_ECC;
  1990. mask |= IXGBE_EIMS_GPI_SDP1;
  1991. mask |= IXGBE_EIMS_GPI_SDP2;
  1992. if (adapter->num_vfs)
  1993. mask |= IXGBE_EIMS_MAILBOX;
  1994. }
  1995. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  1996. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  1997. mask |= IXGBE_EIMS_FLOW_DIR;
  1998. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  1999. if (queues)
  2000. ixgbe_irq_enable_queues(adapter, ~0);
  2001. if (flush)
  2002. IXGBE_WRITE_FLUSH(&adapter->hw);
  2003. if (adapter->num_vfs > 32) {
  2004. u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
  2005. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  2006. }
  2007. }
  2008. /**
  2009. * ixgbe_intr - legacy mode Interrupt Handler
  2010. * @irq: interrupt number
  2011. * @data: pointer to a network interface device structure
  2012. **/
  2013. static irqreturn_t ixgbe_intr(int irq, void *data)
  2014. {
  2015. struct net_device *netdev = data;
  2016. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2017. struct ixgbe_hw *hw = &adapter->hw;
  2018. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2019. u32 eicr;
  2020. /*
  2021. * Workaround for silicon errata on 82598. Mask the interrupts
  2022. * before the read of EICR.
  2023. */
  2024. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2025. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2026. * therefore no explict interrupt disable is necessary */
  2027. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2028. if (!eicr) {
  2029. /*
  2030. * shared interrupt alert!
  2031. * make sure interrupts are enabled because the read will
  2032. * have disabled interrupts due to EIAM
  2033. * finish the workaround of silicon errata on 82598. Unmask
  2034. * the interrupt that we masked before the EICR read.
  2035. */
  2036. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2037. ixgbe_irq_enable(adapter, true, true);
  2038. return IRQ_NONE; /* Not our interrupt */
  2039. }
  2040. if (eicr & IXGBE_EICR_LSC)
  2041. ixgbe_check_lsc(adapter);
  2042. if (hw->mac.type == ixgbe_mac_82599EB)
  2043. ixgbe_check_sfp_event(adapter, eicr);
  2044. ixgbe_check_fan_failure(adapter, eicr);
  2045. if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  2046. ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)))
  2047. schedule_work(&adapter->check_overtemp_task);
  2048. if (napi_schedule_prep(&(q_vector->napi))) {
  2049. adapter->tx_ring[0]->total_packets = 0;
  2050. adapter->tx_ring[0]->total_bytes = 0;
  2051. adapter->rx_ring[0]->total_packets = 0;
  2052. adapter->rx_ring[0]->total_bytes = 0;
  2053. /* would disable interrupts here but EIAM disabled it */
  2054. __napi_schedule(&(q_vector->napi));
  2055. }
  2056. /*
  2057. * re-enable link(maybe) and non-queue interrupts, no flush.
  2058. * ixgbe_poll will re-enable the queue interrupts
  2059. */
  2060. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2061. ixgbe_irq_enable(adapter, false, false);
  2062. return IRQ_HANDLED;
  2063. }
  2064. static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
  2065. {
  2066. int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2067. for (i = 0; i < q_vectors; i++) {
  2068. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  2069. bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
  2070. bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
  2071. q_vector->rxr_count = 0;
  2072. q_vector->txr_count = 0;
  2073. }
  2074. }
  2075. /**
  2076. * ixgbe_request_irq - initialize interrupts
  2077. * @adapter: board private structure
  2078. *
  2079. * Attempts to configure interrupts using the best available
  2080. * capabilities of the hardware and kernel.
  2081. **/
  2082. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2083. {
  2084. struct net_device *netdev = adapter->netdev;
  2085. int err;
  2086. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2087. err = ixgbe_request_msix_irqs(adapter);
  2088. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  2089. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2090. netdev->name, netdev);
  2091. } else {
  2092. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2093. netdev->name, netdev);
  2094. }
  2095. if (err)
  2096. e_err(probe, "request_irq failed, Error %d\n", err);
  2097. return err;
  2098. }
  2099. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2100. {
  2101. struct net_device *netdev = adapter->netdev;
  2102. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2103. int i, q_vectors;
  2104. q_vectors = adapter->num_msix_vectors;
  2105. i = q_vectors - 1;
  2106. free_irq(adapter->msix_entries[i].vector, netdev);
  2107. i--;
  2108. for (; i >= 0; i--) {
  2109. free_irq(adapter->msix_entries[i].vector,
  2110. adapter->q_vector[i]);
  2111. }
  2112. ixgbe_reset_q_vectors(adapter);
  2113. } else {
  2114. free_irq(adapter->pdev->irq, netdev);
  2115. }
  2116. }
  2117. /**
  2118. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2119. * @adapter: board private structure
  2120. **/
  2121. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2122. {
  2123. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2124. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2125. } else {
  2126. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2127. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2128. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2129. if (adapter->num_vfs > 32)
  2130. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  2131. }
  2132. IXGBE_WRITE_FLUSH(&adapter->hw);
  2133. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2134. int i;
  2135. for (i = 0; i < adapter->num_msix_vectors; i++)
  2136. synchronize_irq(adapter->msix_entries[i].vector);
  2137. } else {
  2138. synchronize_irq(adapter->pdev->irq);
  2139. }
  2140. }
  2141. /**
  2142. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2143. *
  2144. **/
  2145. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2146. {
  2147. struct ixgbe_hw *hw = &adapter->hw;
  2148. IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
  2149. EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
  2150. ixgbe_set_ivar(adapter, 0, 0, 0);
  2151. ixgbe_set_ivar(adapter, 1, 0, 0);
  2152. map_vector_to_rxq(adapter, 0, 0);
  2153. map_vector_to_txq(adapter, 0, 0);
  2154. e_info(hw, "Legacy interrupt IVAR setup done\n");
  2155. }
  2156. /**
  2157. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  2158. * @adapter: board private structure
  2159. * @ring: structure containing ring specific data
  2160. *
  2161. * Configure the Tx descriptor ring after a reset.
  2162. **/
  2163. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  2164. struct ixgbe_ring *ring)
  2165. {
  2166. struct ixgbe_hw *hw = &adapter->hw;
  2167. u64 tdba = ring->dma;
  2168. int wait_loop = 10;
  2169. u32 txdctl;
  2170. u16 reg_idx = ring->reg_idx;
  2171. /* disable queue to avoid issues while updating state */
  2172. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  2173. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
  2174. txdctl & ~IXGBE_TXDCTL_ENABLE);
  2175. IXGBE_WRITE_FLUSH(hw);
  2176. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  2177. (tdba & DMA_BIT_MASK(32)));
  2178. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  2179. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  2180. ring->count * sizeof(union ixgbe_adv_tx_desc));
  2181. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  2182. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  2183. ring->head = IXGBE_TDH(reg_idx);
  2184. ring->tail = IXGBE_TDT(reg_idx);
  2185. /* configure fetching thresholds */
  2186. if (adapter->rx_itr_setting == 0) {
  2187. /* cannot set wthresh when itr==0 */
  2188. txdctl &= ~0x007F0000;
  2189. } else {
  2190. /* enable WTHRESH=8 descriptors, to encourage burst writeback */
  2191. txdctl |= (8 << 16);
  2192. }
  2193. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  2194. /* PThresh workaround for Tx hang with DFP enabled. */
  2195. txdctl |= 32;
  2196. }
  2197. /* reinitialize flowdirector state */
  2198. set_bit(__IXGBE_FDIR_INIT_DONE, &ring->reinit_state);
  2199. /* enable queue */
  2200. txdctl |= IXGBE_TXDCTL_ENABLE;
  2201. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  2202. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  2203. if (hw->mac.type == ixgbe_mac_82598EB &&
  2204. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2205. return;
  2206. /* poll to verify queue is enabled */
  2207. do {
  2208. msleep(1);
  2209. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  2210. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  2211. if (!wait_loop)
  2212. e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
  2213. }
  2214. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  2215. {
  2216. struct ixgbe_hw *hw = &adapter->hw;
  2217. u32 rttdcs;
  2218. u32 mask;
  2219. if (hw->mac.type == ixgbe_mac_82598EB)
  2220. return;
  2221. /* disable the arbiter while setting MTQC */
  2222. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  2223. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  2224. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2225. /* set transmit pool layout */
  2226. mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
  2227. switch (adapter->flags & mask) {
  2228. case (IXGBE_FLAG_SRIOV_ENABLED):
  2229. IXGBE_WRITE_REG(hw, IXGBE_MTQC,
  2230. (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
  2231. break;
  2232. case (IXGBE_FLAG_DCB_ENABLED):
  2233. /* We enable 8 traffic classes, DCB only */
  2234. IXGBE_WRITE_REG(hw, IXGBE_MTQC,
  2235. (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
  2236. break;
  2237. default:
  2238. IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
  2239. break;
  2240. }
  2241. /* re-enable the arbiter */
  2242. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  2243. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2244. }
  2245. /**
  2246. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  2247. * @adapter: board private structure
  2248. *
  2249. * Configure the Tx unit of the MAC after a reset.
  2250. **/
  2251. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  2252. {
  2253. struct ixgbe_hw *hw = &adapter->hw;
  2254. u32 dmatxctl;
  2255. u32 i;
  2256. ixgbe_setup_mtqc(adapter);
  2257. if (hw->mac.type != ixgbe_mac_82598EB) {
  2258. /* DMATXCTL.EN must be before Tx queues are enabled */
  2259. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  2260. dmatxctl |= IXGBE_DMATXCTL_TE;
  2261. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  2262. }
  2263. /* Setup the HW Tx Head and Tail descriptor pointers */
  2264. for (i = 0; i < adapter->num_tx_queues; i++)
  2265. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2266. }
  2267. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  2268. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  2269. struct ixgbe_ring *rx_ring)
  2270. {
  2271. u32 srrctl;
  2272. int index;
  2273. struct ixgbe_ring_feature *feature = adapter->ring_feature;
  2274. index = rx_ring->reg_idx;
  2275. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2276. unsigned long mask;
  2277. mask = (unsigned long) feature[RING_F_RSS].mask;
  2278. index = index & mask;
  2279. }
  2280. srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index));
  2281. srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
  2282. srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
  2283. if (adapter->num_vfs)
  2284. srrctl |= IXGBE_SRRCTL_DROP_EN;
  2285. srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
  2286. IXGBE_SRRCTL_BSIZEHDR_MASK;
  2287. if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  2288. #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
  2289. srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2290. #else
  2291. srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2292. #endif
  2293. srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  2294. } else {
  2295. srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
  2296. IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2297. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  2298. }
  2299. IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl);
  2300. }
  2301. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  2302. {
  2303. struct ixgbe_hw *hw = &adapter->hw;
  2304. static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
  2305. 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
  2306. 0x6A3E67EA, 0x14364D17, 0x3BED200D};
  2307. u32 mrqc = 0, reta = 0;
  2308. u32 rxcsum;
  2309. int i, j;
  2310. int mask;
  2311. /* Fill out hash function seeds */
  2312. for (i = 0; i < 10; i++)
  2313. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
  2314. /* Fill out redirection table */
  2315. for (i = 0, j = 0; i < 128; i++, j++) {
  2316. if (j == adapter->ring_feature[RING_F_RSS].indices)
  2317. j = 0;
  2318. /* reta = 4-byte sliding window of
  2319. * 0x00..(indices-1)(indices-1)00..etc. */
  2320. reta = (reta << 8) | (j * 0x11);
  2321. if ((i & 3) == 3)
  2322. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  2323. }
  2324. /* Disable indicating checksum in descriptor, enables RSS hash */
  2325. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  2326. rxcsum |= IXGBE_RXCSUM_PCSD;
  2327. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  2328. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  2329. mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED;
  2330. else
  2331. mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
  2332. #ifdef CONFIG_IXGBE_DCB
  2333. | IXGBE_FLAG_DCB_ENABLED
  2334. #endif
  2335. | IXGBE_FLAG_SRIOV_ENABLED
  2336. );
  2337. switch (mask) {
  2338. case (IXGBE_FLAG_RSS_ENABLED):
  2339. mrqc = IXGBE_MRQC_RSSEN;
  2340. break;
  2341. case (IXGBE_FLAG_SRIOV_ENABLED):
  2342. mrqc = IXGBE_MRQC_VMDQEN;
  2343. break;
  2344. #ifdef CONFIG_IXGBE_DCB
  2345. case (IXGBE_FLAG_DCB_ENABLED):
  2346. mrqc = IXGBE_MRQC_RT8TCEN;
  2347. break;
  2348. #endif /* CONFIG_IXGBE_DCB */
  2349. default:
  2350. break;
  2351. }
  2352. /* Perform hash on these packet types */
  2353. mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
  2354. | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
  2355. | IXGBE_MRQC_RSS_FIELD_IPV6
  2356. | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  2357. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  2358. }
  2359. /**
  2360. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  2361. * @adapter: address of board private structure
  2362. * @index: index of ring to set
  2363. **/
  2364. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  2365. struct ixgbe_ring *ring)
  2366. {
  2367. struct ixgbe_hw *hw = &adapter->hw;
  2368. u32 rscctrl;
  2369. int rx_buf_len;
  2370. u16 reg_idx = ring->reg_idx;
  2371. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  2372. return;
  2373. rx_buf_len = ring->rx_buf_len;
  2374. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  2375. rscctrl |= IXGBE_RSCCTL_RSCEN;
  2376. /*
  2377. * we must limit the number of descriptors so that the
  2378. * total size of max desc * buf_len is not greater
  2379. * than 65535
  2380. */
  2381. if (ring->flags & IXGBE_RING_RX_PS_ENABLED) {
  2382. #if (MAX_SKB_FRAGS > 16)
  2383. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  2384. #elif (MAX_SKB_FRAGS > 8)
  2385. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  2386. #elif (MAX_SKB_FRAGS > 4)
  2387. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  2388. #else
  2389. rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
  2390. #endif
  2391. } else {
  2392. if (rx_buf_len < IXGBE_RXBUFFER_4096)
  2393. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  2394. else if (rx_buf_len < IXGBE_RXBUFFER_8192)
  2395. rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
  2396. else
  2397. rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
  2398. }
  2399. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  2400. }
  2401. /**
  2402. * ixgbe_set_uta - Set unicast filter table address
  2403. * @adapter: board private structure
  2404. *
  2405. * The unicast table address is a register array of 32-bit registers.
  2406. * The table is meant to be used in a way similar to how the MTA is used
  2407. * however due to certain limitations in the hardware it is necessary to
  2408. * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
  2409. * enable bit to allow vlan tag stripping when promiscuous mode is enabled
  2410. **/
  2411. static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
  2412. {
  2413. struct ixgbe_hw *hw = &adapter->hw;
  2414. int i;
  2415. /* The UTA table only exists on 82599 hardware and newer */
  2416. if (hw->mac.type < ixgbe_mac_82599EB)
  2417. return;
  2418. /* we only need to do this if VMDq is enabled */
  2419. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  2420. return;
  2421. for (i = 0; i < 128; i++)
  2422. IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
  2423. }
  2424. #define IXGBE_MAX_RX_DESC_POLL 10
  2425. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  2426. struct ixgbe_ring *ring)
  2427. {
  2428. struct ixgbe_hw *hw = &adapter->hw;
  2429. int reg_idx = ring->reg_idx;
  2430. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  2431. u32 rxdctl;
  2432. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  2433. if (hw->mac.type == ixgbe_mac_82598EB &&
  2434. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2435. return;
  2436. do {
  2437. msleep(1);
  2438. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  2439. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  2440. if (!wait_loop) {
  2441. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  2442. "the polling period\n", reg_idx);
  2443. }
  2444. }
  2445. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  2446. struct ixgbe_ring *ring)
  2447. {
  2448. struct ixgbe_hw *hw = &adapter->hw;
  2449. u64 rdba = ring->dma;
  2450. u32 rxdctl;
  2451. u16 reg_idx = ring->reg_idx;
  2452. /* disable queue to avoid issues while updating state */
  2453. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  2454. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx),
  2455. rxdctl & ~IXGBE_RXDCTL_ENABLE);
  2456. IXGBE_WRITE_FLUSH(hw);
  2457. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  2458. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  2459. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  2460. ring->count * sizeof(union ixgbe_adv_rx_desc));
  2461. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  2462. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  2463. ring->head = IXGBE_RDH(reg_idx);
  2464. ring->tail = IXGBE_RDT(reg_idx);
  2465. ixgbe_configure_srrctl(adapter, ring);
  2466. ixgbe_configure_rscctl(adapter, ring);
  2467. if (hw->mac.type == ixgbe_mac_82598EB) {
  2468. /*
  2469. * enable cache line friendly hardware writes:
  2470. * PTHRESH=32 descriptors (half the internal cache),
  2471. * this also removes ugly rx_no_buffer_count increment
  2472. * HTHRESH=4 descriptors (to minimize latency on fetch)
  2473. * WTHRESH=8 burst writeback up to two cache lines
  2474. */
  2475. rxdctl &= ~0x3FFFFF;
  2476. rxdctl |= 0x080420;
  2477. }
  2478. /* enable receive descriptor ring */
  2479. rxdctl |= IXGBE_RXDCTL_ENABLE;
  2480. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  2481. ixgbe_rx_desc_queue_enable(adapter, ring);
  2482. ixgbe_alloc_rx_buffers(adapter, ring, IXGBE_DESC_UNUSED(ring));
  2483. }
  2484. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  2485. {
  2486. struct ixgbe_hw *hw = &adapter->hw;
  2487. int p;
  2488. /* PSRTYPE must be initialized in non 82598 adapters */
  2489. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  2490. IXGBE_PSRTYPE_UDPHDR |
  2491. IXGBE_PSRTYPE_IPV4HDR |
  2492. IXGBE_PSRTYPE_L2HDR |
  2493. IXGBE_PSRTYPE_IPV6HDR;
  2494. if (hw->mac.type == ixgbe_mac_82598EB)
  2495. return;
  2496. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
  2497. psrtype |= (adapter->num_rx_queues_per_pool << 29);
  2498. for (p = 0; p < adapter->num_rx_pools; p++)
  2499. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
  2500. psrtype);
  2501. }
  2502. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  2503. {
  2504. struct ixgbe_hw *hw = &adapter->hw;
  2505. u32 gcr_ext;
  2506. u32 vt_reg_bits;
  2507. u32 reg_offset, vf_shift;
  2508. u32 vmdctl;
  2509. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  2510. return;
  2511. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  2512. vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
  2513. vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
  2514. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
  2515. vf_shift = adapter->num_vfs % 32;
  2516. reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
  2517. /* Enable only the PF's pool for Tx/Rx */
  2518. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
  2519. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
  2520. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
  2521. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
  2522. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  2523. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  2524. hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
  2525. /*
  2526. * Set up VF register offsets for selected VT Mode,
  2527. * i.e. 32 or 64 VFs for SR-IOV
  2528. */
  2529. gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
  2530. gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
  2531. gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
  2532. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  2533. /* enable Tx loopback for VF/PF communication */
  2534. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  2535. }
  2536. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  2537. {
  2538. struct ixgbe_hw *hw = &adapter->hw;
  2539. struct net_device *netdev = adapter->netdev;
  2540. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2541. int rx_buf_len;
  2542. struct ixgbe_ring *rx_ring;
  2543. int i;
  2544. u32 mhadd, hlreg0;
  2545. /* Decide whether to use packet split mode or not */
  2546. /* Do not use packet split if we're in SR-IOV Mode */
  2547. if (!adapter->num_vfs)
  2548. adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
  2549. /* Set the RX buffer length according to the mode */
  2550. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
  2551. rx_buf_len = IXGBE_RX_HDR_SIZE;
  2552. } else {
  2553. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
  2554. (netdev->mtu <= ETH_DATA_LEN))
  2555. rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  2556. else
  2557. rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
  2558. }
  2559. #ifdef IXGBE_FCOE
  2560. /* adjust max frame to be able to do baby jumbo for FCoE */
  2561. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  2562. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  2563. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2564. #endif /* IXGBE_FCOE */
  2565. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  2566. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  2567. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  2568. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  2569. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  2570. }
  2571. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  2572. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  2573. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  2574. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  2575. /*
  2576. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2577. * the Base and Length of the Rx Descriptor Ring
  2578. */
  2579. for (i = 0; i < adapter->num_rx_queues; i++) {
  2580. rx_ring = adapter->rx_ring[i];
  2581. rx_ring->rx_buf_len = rx_buf_len;
  2582. if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
  2583. rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED;
  2584. else
  2585. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  2586. #ifdef IXGBE_FCOE
  2587. if (netdev->features & NETIF_F_FCOE_MTU) {
  2588. struct ixgbe_ring_feature *f;
  2589. f = &adapter->ring_feature[RING_F_FCOE];
  2590. if ((i >= f->mask) && (i < f->mask + f->indices)) {
  2591. rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED;
  2592. if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
  2593. rx_ring->rx_buf_len =
  2594. IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2595. }
  2596. }
  2597. #endif /* IXGBE_FCOE */
  2598. }
  2599. }
  2600. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  2601. {
  2602. struct ixgbe_hw *hw = &adapter->hw;
  2603. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  2604. switch (hw->mac.type) {
  2605. case ixgbe_mac_82598EB:
  2606. /*
  2607. * For VMDq support of different descriptor types or
  2608. * buffer sizes through the use of multiple SRRCTL
  2609. * registers, RDRXCTL.MVMEN must be set to 1
  2610. *
  2611. * also, the manual doesn't mention it clearly but DCA hints
  2612. * will only use queue 0's tags unless this bit is set. Side
  2613. * effects of setting this bit are only that SRRCTL must be
  2614. * fully programmed [0..15]
  2615. */
  2616. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  2617. break;
  2618. case ixgbe_mac_82599EB:
  2619. /* Disable RSC for ACK packets */
  2620. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  2621. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  2622. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  2623. /* hardware requires some bits to be set by default */
  2624. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  2625. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  2626. break;
  2627. default:
  2628. /* We should do nothing since we don't know this hardware */
  2629. return;
  2630. }
  2631. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  2632. }
  2633. /**
  2634. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  2635. * @adapter: board private structure
  2636. *
  2637. * Configure the Rx unit of the MAC after a reset.
  2638. **/
  2639. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  2640. {
  2641. struct ixgbe_hw *hw = &adapter->hw;
  2642. int i;
  2643. u32 rxctrl;
  2644. /* disable receives while setting up the descriptors */
  2645. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2646. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  2647. ixgbe_setup_psrtype(adapter);
  2648. ixgbe_setup_rdrxctl(adapter);
  2649. /* Program registers for the distribution of queues */
  2650. ixgbe_setup_mrqc(adapter);
  2651. ixgbe_set_uta(adapter);
  2652. /* set_rx_buffer_len must be called before ring initialization */
  2653. ixgbe_set_rx_buffer_len(adapter);
  2654. /*
  2655. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2656. * the Base and Length of the Rx Descriptor Ring
  2657. */
  2658. for (i = 0; i < adapter->num_rx_queues; i++)
  2659. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  2660. /* disable drop enable for 82598 parts */
  2661. if (hw->mac.type == ixgbe_mac_82598EB)
  2662. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  2663. /* enable all receives */
  2664. rxctrl |= IXGBE_RXCTRL_RXEN;
  2665. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  2666. }
  2667. static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  2668. {
  2669. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2670. struct ixgbe_hw *hw = &adapter->hw;
  2671. int pool_ndx = adapter->num_vfs;
  2672. /* add VID to filter table */
  2673. hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
  2674. set_bit(vid, adapter->active_vlans);
  2675. }
  2676. static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  2677. {
  2678. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2679. struct ixgbe_hw *hw = &adapter->hw;
  2680. int pool_ndx = adapter->num_vfs;
  2681. /* remove VID from filter table */
  2682. hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
  2683. clear_bit(vid, adapter->active_vlans);
  2684. }
  2685. /**
  2686. * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
  2687. * @adapter: driver data
  2688. */
  2689. static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
  2690. {
  2691. struct ixgbe_hw *hw = &adapter->hw;
  2692. u32 vlnctrl;
  2693. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2694. vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
  2695. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2696. }
  2697. /**
  2698. * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
  2699. * @adapter: driver data
  2700. */
  2701. static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
  2702. {
  2703. struct ixgbe_hw *hw = &adapter->hw;
  2704. u32 vlnctrl;
  2705. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2706. vlnctrl |= IXGBE_VLNCTRL_VFE;
  2707. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  2708. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2709. }
  2710. /**
  2711. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  2712. * @adapter: driver data
  2713. */
  2714. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  2715. {
  2716. struct ixgbe_hw *hw = &adapter->hw;
  2717. u32 vlnctrl;
  2718. int i, j;
  2719. switch (hw->mac.type) {
  2720. case ixgbe_mac_82598EB:
  2721. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2722. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  2723. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2724. break;
  2725. case ixgbe_mac_82599EB:
  2726. for (i = 0; i < adapter->num_rx_queues; i++) {
  2727. j = adapter->rx_ring[i]->reg_idx;
  2728. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2729. vlnctrl &= ~IXGBE_RXDCTL_VME;
  2730. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  2731. }
  2732. break;
  2733. default:
  2734. break;
  2735. }
  2736. }
  2737. /**
  2738. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  2739. * @adapter: driver data
  2740. */
  2741. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  2742. {
  2743. struct ixgbe_hw *hw = &adapter->hw;
  2744. u32 vlnctrl;
  2745. int i, j;
  2746. switch (hw->mac.type) {
  2747. case ixgbe_mac_82598EB:
  2748. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  2749. vlnctrl |= IXGBE_VLNCTRL_VME;
  2750. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  2751. break;
  2752. case ixgbe_mac_82599EB:
  2753. for (i = 0; i < adapter->num_rx_queues; i++) {
  2754. j = adapter->rx_ring[i]->reg_idx;
  2755. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  2756. vlnctrl |= IXGBE_RXDCTL_VME;
  2757. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  2758. }
  2759. break;
  2760. default:
  2761. break;
  2762. }
  2763. }
  2764. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  2765. {
  2766. u16 vid;
  2767. ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
  2768. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  2769. ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
  2770. }
  2771. /**
  2772. * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
  2773. * @netdev: network interface device structure
  2774. *
  2775. * Writes unicast address list to the RAR table.
  2776. * Returns: -ENOMEM on failure/insufficient address space
  2777. * 0 on no addresses written
  2778. * X on writing X addresses to the RAR table
  2779. **/
  2780. static int ixgbe_write_uc_addr_list(struct net_device *netdev)
  2781. {
  2782. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2783. struct ixgbe_hw *hw = &adapter->hw;
  2784. unsigned int vfn = adapter->num_vfs;
  2785. unsigned int rar_entries = hw->mac.num_rar_entries - (vfn + 1);
  2786. int count = 0;
  2787. /* return ENOMEM indicating insufficient memory for addresses */
  2788. if (netdev_uc_count(netdev) > rar_entries)
  2789. return -ENOMEM;
  2790. if (!netdev_uc_empty(netdev) && rar_entries) {
  2791. struct netdev_hw_addr *ha;
  2792. /* return error if we do not support writing to RAR table */
  2793. if (!hw->mac.ops.set_rar)
  2794. return -ENOMEM;
  2795. netdev_for_each_uc_addr(ha, netdev) {
  2796. if (!rar_entries)
  2797. break;
  2798. hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
  2799. vfn, IXGBE_RAH_AV);
  2800. count++;
  2801. }
  2802. }
  2803. /* write the addresses in reverse order to avoid write combining */
  2804. for (; rar_entries > 0 ; rar_entries--)
  2805. hw->mac.ops.clear_rar(hw, rar_entries);
  2806. return count;
  2807. }
  2808. /**
  2809. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  2810. * @netdev: network interface device structure
  2811. *
  2812. * The set_rx_method entry point is called whenever the unicast/multicast
  2813. * address list or the network interface flags are updated. This routine is
  2814. * responsible for configuring the hardware for proper unicast, multicast and
  2815. * promiscuous mode.
  2816. **/
  2817. void ixgbe_set_rx_mode(struct net_device *netdev)
  2818. {
  2819. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2820. struct ixgbe_hw *hw = &adapter->hw;
  2821. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  2822. int count;
  2823. /* Check for Promiscuous and All Multicast modes */
  2824. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  2825. /* set all bits that we expect to always be set */
  2826. fctrl |= IXGBE_FCTRL_BAM;
  2827. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  2828. fctrl |= IXGBE_FCTRL_PMCF;
  2829. /* clear the bits we are changing the status of */
  2830. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2831. if (netdev->flags & IFF_PROMISC) {
  2832. hw->addr_ctrl.user_set_promisc = true;
  2833. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  2834. vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
  2835. /* don't hardware filter vlans in promisc mode */
  2836. ixgbe_vlan_filter_disable(adapter);
  2837. } else {
  2838. if (netdev->flags & IFF_ALLMULTI) {
  2839. fctrl |= IXGBE_FCTRL_MPE;
  2840. vmolr |= IXGBE_VMOLR_MPE;
  2841. } else {
  2842. /*
  2843. * Write addresses to the MTA, if the attempt fails
  2844. * then we should just turn on promiscous mode so
  2845. * that we can at least receive multicast traffic
  2846. */
  2847. hw->mac.ops.update_mc_addr_list(hw, netdev);
  2848. vmolr |= IXGBE_VMOLR_ROMPE;
  2849. }
  2850. ixgbe_vlan_filter_enable(adapter);
  2851. hw->addr_ctrl.user_set_promisc = false;
  2852. /*
  2853. * Write addresses to available RAR registers, if there is not
  2854. * sufficient space to store all the addresses then enable
  2855. * unicast promiscous mode
  2856. */
  2857. count = ixgbe_write_uc_addr_list(netdev);
  2858. if (count < 0) {
  2859. fctrl |= IXGBE_FCTRL_UPE;
  2860. vmolr |= IXGBE_VMOLR_ROPE;
  2861. }
  2862. }
  2863. if (adapter->num_vfs) {
  2864. ixgbe_restore_vf_multicasts(adapter);
  2865. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
  2866. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  2867. IXGBE_VMOLR_ROPE);
  2868. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
  2869. }
  2870. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  2871. if (netdev->features & NETIF_F_HW_VLAN_RX)
  2872. ixgbe_vlan_strip_enable(adapter);
  2873. else
  2874. ixgbe_vlan_strip_disable(adapter);
  2875. }
  2876. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  2877. {
  2878. int q_idx;
  2879. struct ixgbe_q_vector *q_vector;
  2880. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2881. /* legacy and MSI only use one vector */
  2882. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2883. q_vectors = 1;
  2884. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2885. struct napi_struct *napi;
  2886. q_vector = adapter->q_vector[q_idx];
  2887. napi = &q_vector->napi;
  2888. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2889. if (!q_vector->rxr_count || !q_vector->txr_count) {
  2890. if (q_vector->txr_count == 1)
  2891. napi->poll = &ixgbe_clean_txonly;
  2892. else if (q_vector->rxr_count == 1)
  2893. napi->poll = &ixgbe_clean_rxonly;
  2894. }
  2895. }
  2896. napi_enable(napi);
  2897. }
  2898. }
  2899. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  2900. {
  2901. int q_idx;
  2902. struct ixgbe_q_vector *q_vector;
  2903. int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  2904. /* legacy and MSI only use one vector */
  2905. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  2906. q_vectors = 1;
  2907. for (q_idx = 0; q_idx < q_vectors; q_idx++) {
  2908. q_vector = adapter->q_vector[q_idx];
  2909. napi_disable(&q_vector->napi);
  2910. }
  2911. }
  2912. #ifdef CONFIG_IXGBE_DCB
  2913. /*
  2914. * ixgbe_configure_dcb - Configure DCB hardware
  2915. * @adapter: ixgbe adapter struct
  2916. *
  2917. * This is called by the driver on open to configure the DCB hardware.
  2918. * This is also called by the gennetlink interface when reconfiguring
  2919. * the DCB state.
  2920. */
  2921. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  2922. {
  2923. struct ixgbe_hw *hw = &adapter->hw;
  2924. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2925. u32 txdctl;
  2926. int i, j;
  2927. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  2928. if (hw->mac.type == ixgbe_mac_82598EB)
  2929. netif_set_gso_max_size(adapter->netdev, 65536);
  2930. return;
  2931. }
  2932. if (hw->mac.type == ixgbe_mac_82598EB)
  2933. netif_set_gso_max_size(adapter->netdev, 32768);
  2934. #ifdef CONFIG_FCOE
  2935. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  2936. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  2937. #endif
  2938. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  2939. DCB_TX_CONFIG);
  2940. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  2941. DCB_RX_CONFIG);
  2942. /* reconfigure the hardware */
  2943. ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg);
  2944. for (i = 0; i < adapter->num_tx_queues; i++) {
  2945. j = adapter->tx_ring[i]->reg_idx;
  2946. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  2947. /* PThresh workaround for Tx hang with DFP enabled. */
  2948. txdctl |= 32;
  2949. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl);
  2950. }
  2951. /* Enable VLAN tag insert/strip */
  2952. adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
  2953. hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
  2954. }
  2955. #endif
  2956. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  2957. {
  2958. struct net_device *netdev = adapter->netdev;
  2959. struct ixgbe_hw *hw = &adapter->hw;
  2960. int i;
  2961. #ifdef CONFIG_IXGBE_DCB
  2962. ixgbe_configure_dcb(adapter);
  2963. #endif
  2964. ixgbe_set_rx_mode(netdev);
  2965. ixgbe_restore_vlan(adapter);
  2966. #ifdef IXGBE_FCOE
  2967. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  2968. ixgbe_configure_fcoe(adapter);
  2969. #endif /* IXGBE_FCOE */
  2970. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2971. for (i = 0; i < adapter->num_tx_queues; i++)
  2972. adapter->tx_ring[i]->atr_sample_rate =
  2973. adapter->atr_sample_rate;
  2974. ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
  2975. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  2976. ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
  2977. }
  2978. ixgbe_configure_virtualization(adapter);
  2979. ixgbe_configure_tx(adapter);
  2980. ixgbe_configure_rx(adapter);
  2981. }
  2982. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2983. {
  2984. switch (hw->phy.type) {
  2985. case ixgbe_phy_sfp_avago:
  2986. case ixgbe_phy_sfp_ftl:
  2987. case ixgbe_phy_sfp_intel:
  2988. case ixgbe_phy_sfp_unknown:
  2989. case ixgbe_phy_sfp_passive_tyco:
  2990. case ixgbe_phy_sfp_passive_unknown:
  2991. case ixgbe_phy_sfp_active_unknown:
  2992. case ixgbe_phy_sfp_ftl_active:
  2993. return true;
  2994. default:
  2995. return false;
  2996. }
  2997. }
  2998. /**
  2999. * ixgbe_sfp_link_config - set up SFP+ link
  3000. * @adapter: pointer to private adapter struct
  3001. **/
  3002. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  3003. {
  3004. struct ixgbe_hw *hw = &adapter->hw;
  3005. if (hw->phy.multispeed_fiber) {
  3006. /*
  3007. * In multispeed fiber setups, the device may not have
  3008. * had a physical connection when the driver loaded.
  3009. * If that's the case, the initial link configuration
  3010. * couldn't get the MAC into 10G or 1G mode, so we'll
  3011. * never have a link status change interrupt fire.
  3012. * We need to try and force an autonegotiation
  3013. * session, then bring up link.
  3014. */
  3015. hw->mac.ops.setup_sfp(hw);
  3016. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  3017. schedule_work(&adapter->multispeed_fiber_task);
  3018. } else {
  3019. /*
  3020. * Direct Attach Cu and non-multispeed fiber modules
  3021. * still need to be configured properly prior to
  3022. * attempting link.
  3023. */
  3024. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
  3025. schedule_work(&adapter->sfp_config_module_task);
  3026. }
  3027. }
  3028. /**
  3029. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  3030. * @hw: pointer to private hardware struct
  3031. *
  3032. * Returns 0 on success, negative on failure
  3033. **/
  3034. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  3035. {
  3036. u32 autoneg;
  3037. bool negotiation, link_up = false;
  3038. u32 ret = IXGBE_ERR_LINK_SETUP;
  3039. if (hw->mac.ops.check_link)
  3040. ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
  3041. if (ret)
  3042. goto link_cfg_out;
  3043. if (hw->mac.ops.get_link_capabilities)
  3044. ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
  3045. &negotiation);
  3046. if (ret)
  3047. goto link_cfg_out;
  3048. if (hw->mac.ops.setup_link)
  3049. ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
  3050. link_cfg_out:
  3051. return ret;
  3052. }
  3053. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  3054. {
  3055. struct ixgbe_hw *hw = &adapter->hw;
  3056. u32 gpie = 0;
  3057. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3058. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  3059. IXGBE_GPIE_OCD;
  3060. gpie |= IXGBE_GPIE_EIAME;
  3061. /*
  3062. * use EIAM to auto-mask when MSI-X interrupt is asserted
  3063. * this saves a register write for every interrupt
  3064. */
  3065. switch (hw->mac.type) {
  3066. case ixgbe_mac_82598EB:
  3067. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  3068. break;
  3069. default:
  3070. case ixgbe_mac_82599EB:
  3071. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  3072. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  3073. break;
  3074. }
  3075. } else {
  3076. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  3077. * specifically only auto mask tx and rx interrupts */
  3078. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  3079. }
  3080. /* XXX: to interrupt immediately for EICS writes, enable this */
  3081. /* gpie |= IXGBE_GPIE_EIMEN; */
  3082. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3083. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  3084. gpie |= IXGBE_GPIE_VTMODE_64;
  3085. }
  3086. /* Enable fan failure interrupt */
  3087. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  3088. gpie |= IXGBE_SDP1_GPIEN;
  3089. if (hw->mac.type == ixgbe_mac_82599EB)
  3090. gpie |= IXGBE_SDP1_GPIEN;
  3091. gpie |= IXGBE_SDP2_GPIEN;
  3092. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  3093. }
  3094. static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
  3095. {
  3096. struct ixgbe_hw *hw = &adapter->hw;
  3097. int err;
  3098. u32 ctrl_ext;
  3099. ixgbe_get_hw_control(adapter);
  3100. ixgbe_setup_gpie(adapter);
  3101. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3102. ixgbe_configure_msix(adapter);
  3103. else
  3104. ixgbe_configure_msi_and_legacy(adapter);
  3105. /* enable the optics */
  3106. if (hw->phy.multispeed_fiber)
  3107. hw->mac.ops.enable_tx_laser(hw);
  3108. clear_bit(__IXGBE_DOWN, &adapter->state);
  3109. ixgbe_napi_enable_all(adapter);
  3110. /* clear any pending interrupts, may auto mask */
  3111. IXGBE_READ_REG(hw, IXGBE_EICR);
  3112. ixgbe_irq_enable(adapter, true, true);
  3113. /*
  3114. * If this adapter has a fan, check to see if we had a failure
  3115. * before we enabled the interrupt.
  3116. */
  3117. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  3118. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  3119. if (esdp & IXGBE_ESDP_SDP1)
  3120. e_crit(drv, "Fan has stopped, replace the adapter\n");
  3121. }
  3122. /*
  3123. * For hot-pluggable SFP+ devices, a new SFP+ module may have
  3124. * arrived before interrupts were enabled but after probe. Such
  3125. * devices wouldn't have their type identified yet. We need to
  3126. * kick off the SFP+ module setup first, then try to bring up link.
  3127. * If we're not hot-pluggable SFP+, we just need to configure link
  3128. * and bring it up.
  3129. */
  3130. if (hw->phy.type == ixgbe_phy_unknown) {
  3131. err = hw->phy.ops.identify(hw);
  3132. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  3133. /*
  3134. * Take the device down and schedule the sfp tasklet
  3135. * which will unregister_netdev and log it.
  3136. */
  3137. ixgbe_down(adapter);
  3138. schedule_work(&adapter->sfp_config_module_task);
  3139. return err;
  3140. }
  3141. }
  3142. if (ixgbe_is_sfp(hw)) {
  3143. ixgbe_sfp_link_config(adapter);
  3144. } else {
  3145. err = ixgbe_non_sfp_link_config(hw);
  3146. if (err)
  3147. e_err(probe, "link_config FAILED %d\n", err);
  3148. }
  3149. /* enable transmits */
  3150. netif_tx_start_all_queues(adapter->netdev);
  3151. /* bring the link up in the watchdog, this could race with our first
  3152. * link up interrupt but shouldn't be a problem */
  3153. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  3154. adapter->link_check_timeout = jiffies;
  3155. mod_timer(&adapter->watchdog_timer, jiffies);
  3156. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  3157. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  3158. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  3159. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  3160. return 0;
  3161. }
  3162. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  3163. {
  3164. WARN_ON(in_interrupt());
  3165. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  3166. msleep(1);
  3167. ixgbe_down(adapter);
  3168. /*
  3169. * If SR-IOV enabled then wait a bit before bringing the adapter
  3170. * back up to give the VFs time to respond to the reset. The
  3171. * two second wait is based upon the watchdog timer cycle in
  3172. * the VF driver.
  3173. */
  3174. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3175. msleep(2000);
  3176. ixgbe_up(adapter);
  3177. clear_bit(__IXGBE_RESETTING, &adapter->state);
  3178. }
  3179. int ixgbe_up(struct ixgbe_adapter *adapter)
  3180. {
  3181. /* hardware has been reset, we need to reload some things */
  3182. ixgbe_configure(adapter);
  3183. return ixgbe_up_complete(adapter);
  3184. }
  3185. void ixgbe_reset(struct ixgbe_adapter *adapter)
  3186. {
  3187. struct ixgbe_hw *hw = &adapter->hw;
  3188. int err;
  3189. err = hw->mac.ops.init_hw(hw);
  3190. switch (err) {
  3191. case 0:
  3192. case IXGBE_ERR_SFP_NOT_PRESENT:
  3193. break;
  3194. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  3195. e_dev_err("master disable timed out\n");
  3196. break;
  3197. case IXGBE_ERR_EEPROM_VERSION:
  3198. /* We are running on a pre-production device, log a warning */
  3199. e_dev_warn("This device is a pre-production adapter/LOM. "
  3200. "Please be aware there may be issuesassociated with "
  3201. "your hardware. If you are experiencing problems "
  3202. "please contact your Intel or hardware "
  3203. "representative who provided you with this "
  3204. "hardware.\n");
  3205. break;
  3206. default:
  3207. e_dev_err("Hardware Error: %d\n", err);
  3208. }
  3209. /* reprogram the RAR[0] in case user changed it. */
  3210. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
  3211. IXGBE_RAH_AV);
  3212. }
  3213. /**
  3214. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  3215. * @adapter: board private structure
  3216. * @rx_ring: ring to free buffers from
  3217. **/
  3218. static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter,
  3219. struct ixgbe_ring *rx_ring)
  3220. {
  3221. struct pci_dev *pdev = adapter->pdev;
  3222. unsigned long size;
  3223. unsigned int i;
  3224. /* ring already cleared, nothing to do */
  3225. if (!rx_ring->rx_buffer_info)
  3226. return;
  3227. /* Free all the Rx ring sk_buffs */
  3228. for (i = 0; i < rx_ring->count; i++) {
  3229. struct ixgbe_rx_buffer *rx_buffer_info;
  3230. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  3231. if (rx_buffer_info->dma) {
  3232. dma_unmap_single(&pdev->dev, rx_buffer_info->dma,
  3233. rx_ring->rx_buf_len,
  3234. DMA_FROM_DEVICE);
  3235. rx_buffer_info->dma = 0;
  3236. }
  3237. if (rx_buffer_info->skb) {
  3238. struct sk_buff *skb = rx_buffer_info->skb;
  3239. rx_buffer_info->skb = NULL;
  3240. do {
  3241. struct sk_buff *this = skb;
  3242. if (IXGBE_RSC_CB(this)->delay_unmap) {
  3243. dma_unmap_single(&pdev->dev,
  3244. IXGBE_RSC_CB(this)->dma,
  3245. rx_ring->rx_buf_len,
  3246. DMA_FROM_DEVICE);
  3247. IXGBE_RSC_CB(this)->dma = 0;
  3248. IXGBE_RSC_CB(skb)->delay_unmap = false;
  3249. }
  3250. skb = skb->prev;
  3251. dev_kfree_skb(this);
  3252. } while (skb);
  3253. }
  3254. if (!rx_buffer_info->page)
  3255. continue;
  3256. if (rx_buffer_info->page_dma) {
  3257. dma_unmap_page(&pdev->dev, rx_buffer_info->page_dma,
  3258. PAGE_SIZE / 2, DMA_FROM_DEVICE);
  3259. rx_buffer_info->page_dma = 0;
  3260. }
  3261. put_page(rx_buffer_info->page);
  3262. rx_buffer_info->page = NULL;
  3263. rx_buffer_info->page_offset = 0;
  3264. }
  3265. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  3266. memset(rx_ring->rx_buffer_info, 0, size);
  3267. /* Zero out the descriptor ring */
  3268. memset(rx_ring->desc, 0, rx_ring->size);
  3269. rx_ring->next_to_clean = 0;
  3270. rx_ring->next_to_use = 0;
  3271. if (rx_ring->head)
  3272. writel(0, adapter->hw.hw_addr + rx_ring->head);
  3273. if (rx_ring->tail)
  3274. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  3275. }
  3276. /**
  3277. * ixgbe_clean_tx_ring - Free Tx Buffers
  3278. * @adapter: board private structure
  3279. * @tx_ring: ring to be cleaned
  3280. **/
  3281. static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter,
  3282. struct ixgbe_ring *tx_ring)
  3283. {
  3284. struct ixgbe_tx_buffer *tx_buffer_info;
  3285. unsigned long size;
  3286. unsigned int i;
  3287. /* ring already cleared, nothing to do */
  3288. if (!tx_ring->tx_buffer_info)
  3289. return;
  3290. /* Free all the Tx ring sk_buffs */
  3291. for (i = 0; i < tx_ring->count; i++) {
  3292. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  3293. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  3294. }
  3295. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  3296. memset(tx_ring->tx_buffer_info, 0, size);
  3297. /* Zero out the descriptor ring */
  3298. memset(tx_ring->desc, 0, tx_ring->size);
  3299. tx_ring->next_to_use = 0;
  3300. tx_ring->next_to_clean = 0;
  3301. if (tx_ring->head)
  3302. writel(0, adapter->hw.hw_addr + tx_ring->head);
  3303. if (tx_ring->tail)
  3304. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  3305. }
  3306. /**
  3307. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  3308. * @adapter: board private structure
  3309. **/
  3310. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  3311. {
  3312. int i;
  3313. for (i = 0; i < adapter->num_rx_queues; i++)
  3314. ixgbe_clean_rx_ring(adapter, adapter->rx_ring[i]);
  3315. }
  3316. /**
  3317. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  3318. * @adapter: board private structure
  3319. **/
  3320. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  3321. {
  3322. int i;
  3323. for (i = 0; i < adapter->num_tx_queues; i++)
  3324. ixgbe_clean_tx_ring(adapter, adapter->tx_ring[i]);
  3325. }
  3326. void ixgbe_down(struct ixgbe_adapter *adapter)
  3327. {
  3328. struct net_device *netdev = adapter->netdev;
  3329. struct ixgbe_hw *hw = &adapter->hw;
  3330. u32 rxctrl;
  3331. u32 txdctl;
  3332. int i, j;
  3333. int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  3334. /* signal that we are down to the interrupt handler */
  3335. set_bit(__IXGBE_DOWN, &adapter->state);
  3336. /* disable receive for all VFs and wait one second */
  3337. if (adapter->num_vfs) {
  3338. /* ping all the active vfs to let them know we are going down */
  3339. ixgbe_ping_all_vfs(adapter);
  3340. /* Disable all VFTE/VFRE TX/RX */
  3341. ixgbe_disable_tx_rx(adapter);
  3342. /* Mark all the VFs as inactive */
  3343. for (i = 0 ; i < adapter->num_vfs; i++)
  3344. adapter->vfinfo[i].clear_to_send = 0;
  3345. }
  3346. /* disable receives */
  3347. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3348. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  3349. IXGBE_WRITE_FLUSH(hw);
  3350. msleep(10);
  3351. netif_tx_stop_all_queues(netdev);
  3352. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  3353. del_timer_sync(&adapter->sfp_timer);
  3354. del_timer_sync(&adapter->watchdog_timer);
  3355. cancel_work_sync(&adapter->watchdog_task);
  3356. netif_carrier_off(netdev);
  3357. netif_tx_disable(netdev);
  3358. ixgbe_irq_disable(adapter);
  3359. ixgbe_napi_disable_all(adapter);
  3360. /* Cleanup the affinity_hint CPU mask memory and callback */
  3361. for (i = 0; i < num_q_vectors; i++) {
  3362. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  3363. /* clear the affinity_mask in the IRQ descriptor */
  3364. irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
  3365. /* release the CPU mask memory */
  3366. free_cpumask_var(q_vector->affinity_mask);
  3367. }
  3368. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  3369. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  3370. cancel_work_sync(&adapter->fdir_reinit_task);
  3371. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  3372. cancel_work_sync(&adapter->check_overtemp_task);
  3373. /* disable transmits in the hardware now that interrupts are off */
  3374. for (i = 0; i < adapter->num_tx_queues; i++) {
  3375. j = adapter->tx_ring[i]->reg_idx;
  3376. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j));
  3377. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j),
  3378. (txdctl & ~IXGBE_TXDCTL_ENABLE));
  3379. }
  3380. /* Disable the Tx DMA engine on 82599 */
  3381. if (hw->mac.type == ixgbe_mac_82599EB)
  3382. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  3383. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  3384. ~IXGBE_DMATXCTL_TE));
  3385. /* power down the optics */
  3386. if (hw->phy.multispeed_fiber)
  3387. hw->mac.ops.disable_tx_laser(hw);
  3388. /* clear n-tuple filters that are cached */
  3389. ethtool_ntuple_flush(netdev);
  3390. if (!pci_channel_offline(adapter->pdev))
  3391. ixgbe_reset(adapter);
  3392. ixgbe_clean_all_tx_rings(adapter);
  3393. ixgbe_clean_all_rx_rings(adapter);
  3394. #ifdef CONFIG_IXGBE_DCA
  3395. /* since we reset the hardware DCA settings were cleared */
  3396. ixgbe_setup_dca(adapter);
  3397. #endif
  3398. }
  3399. /**
  3400. * ixgbe_poll - NAPI Rx polling callback
  3401. * @napi: structure for representing this polling device
  3402. * @budget: how many packets driver is allowed to clean
  3403. *
  3404. * This function is used for legacy and MSI, NAPI mode
  3405. **/
  3406. static int ixgbe_poll(struct napi_struct *napi, int budget)
  3407. {
  3408. struct ixgbe_q_vector *q_vector =
  3409. container_of(napi, struct ixgbe_q_vector, napi);
  3410. struct ixgbe_adapter *adapter = q_vector->adapter;
  3411. int tx_clean_complete, work_done = 0;
  3412. #ifdef CONFIG_IXGBE_DCA
  3413. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  3414. ixgbe_update_tx_dca(adapter, adapter->tx_ring[0]);
  3415. ixgbe_update_rx_dca(adapter, adapter->rx_ring[0]);
  3416. }
  3417. #endif
  3418. tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
  3419. ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
  3420. if (!tx_clean_complete)
  3421. work_done = budget;
  3422. /* If budget not fully consumed, exit the polling mode */
  3423. if (work_done < budget) {
  3424. napi_complete(napi);
  3425. if (adapter->rx_itr_setting & 1)
  3426. ixgbe_set_itr(adapter);
  3427. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  3428. ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
  3429. }
  3430. return work_done;
  3431. }
  3432. /**
  3433. * ixgbe_tx_timeout - Respond to a Tx Hang
  3434. * @netdev: network interface device structure
  3435. **/
  3436. static void ixgbe_tx_timeout(struct net_device *netdev)
  3437. {
  3438. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3439. /* Do the reset outside of interrupt context */
  3440. schedule_work(&adapter->reset_task);
  3441. }
  3442. static void ixgbe_reset_task(struct work_struct *work)
  3443. {
  3444. struct ixgbe_adapter *adapter;
  3445. adapter = container_of(work, struct ixgbe_adapter, reset_task);
  3446. /* If we're already down or resetting, just bail */
  3447. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  3448. test_bit(__IXGBE_RESETTING, &adapter->state))
  3449. return;
  3450. adapter->tx_timeout_count++;
  3451. ixgbe_dump(adapter);
  3452. netdev_err(adapter->netdev, "Reset adapter\n");
  3453. ixgbe_reinit_locked(adapter);
  3454. }
  3455. #ifdef CONFIG_IXGBE_DCB
  3456. static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
  3457. {
  3458. bool ret = false;
  3459. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
  3460. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
  3461. return ret;
  3462. f->mask = 0x7 << 3;
  3463. adapter->num_rx_queues = f->indices;
  3464. adapter->num_tx_queues = f->indices;
  3465. ret = true;
  3466. return ret;
  3467. }
  3468. #endif
  3469. /**
  3470. * ixgbe_set_rss_queues: Allocate queues for RSS
  3471. * @adapter: board private structure to initialize
  3472. *
  3473. * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
  3474. * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
  3475. *
  3476. **/
  3477. static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
  3478. {
  3479. bool ret = false;
  3480. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
  3481. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3482. f->mask = 0xF;
  3483. adapter->num_rx_queues = f->indices;
  3484. adapter->num_tx_queues = f->indices;
  3485. ret = true;
  3486. } else {
  3487. ret = false;
  3488. }
  3489. return ret;
  3490. }
  3491. /**
  3492. * ixgbe_set_fdir_queues: Allocate queues for Flow Director
  3493. * @adapter: board private structure to initialize
  3494. *
  3495. * Flow Director is an advanced Rx filter, attempting to get Rx flows back
  3496. * to the original CPU that initiated the Tx session. This runs in addition
  3497. * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
  3498. * Rx load across CPUs using RSS.
  3499. *
  3500. **/
  3501. static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
  3502. {
  3503. bool ret = false;
  3504. struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
  3505. f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
  3506. f_fdir->mask = 0;
  3507. /* Flow Director must have RSS enabled */
  3508. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  3509. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  3510. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
  3511. adapter->num_tx_queues = f_fdir->indices;
  3512. adapter->num_rx_queues = f_fdir->indices;
  3513. ret = true;
  3514. } else {
  3515. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3516. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3517. }
  3518. return ret;
  3519. }
  3520. #ifdef IXGBE_FCOE
  3521. /**
  3522. * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
  3523. * @adapter: board private structure to initialize
  3524. *
  3525. * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
  3526. * The ring feature mask is not used as a mask for FCoE, as it can take any 8
  3527. * rx queues out of the max number of rx queues, instead, it is used as the
  3528. * index of the first rx queue used by FCoE.
  3529. *
  3530. **/
  3531. static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
  3532. {
  3533. bool ret = false;
  3534. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  3535. f->indices = min((int)num_online_cpus(), f->indices);
  3536. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  3537. adapter->num_rx_queues = 1;
  3538. adapter->num_tx_queues = 1;
  3539. #ifdef CONFIG_IXGBE_DCB
  3540. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3541. e_info(probe, "FCoE enabled with DCB\n");
  3542. ixgbe_set_dcb_queues(adapter);
  3543. }
  3544. #endif
  3545. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3546. e_info(probe, "FCoE enabled with RSS\n");
  3547. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3548. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  3549. ixgbe_set_fdir_queues(adapter);
  3550. else
  3551. ixgbe_set_rss_queues(adapter);
  3552. }
  3553. /* adding FCoE rx rings to the end */
  3554. f->mask = adapter->num_rx_queues;
  3555. adapter->num_rx_queues += f->indices;
  3556. adapter->num_tx_queues += f->indices;
  3557. ret = true;
  3558. }
  3559. return ret;
  3560. }
  3561. #endif /* IXGBE_FCOE */
  3562. /**
  3563. * ixgbe_set_sriov_queues: Allocate queues for IOV use
  3564. * @adapter: board private structure to initialize
  3565. *
  3566. * IOV doesn't actually use anything, so just NAK the
  3567. * request for now and let the other queue routines
  3568. * figure out what to do.
  3569. */
  3570. static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
  3571. {
  3572. return false;
  3573. }
  3574. /*
  3575. * ixgbe_set_num_queues: Allocate queues for device, feature dependant
  3576. * @adapter: board private structure to initialize
  3577. *
  3578. * This is the top level queue allocation routine. The order here is very
  3579. * important, starting with the "most" number of features turned on at once,
  3580. * and ending with the smallest set of features. This way large combinations
  3581. * can be allocated if they're turned on, and smaller combinations are the
  3582. * fallthrough conditions.
  3583. *
  3584. **/
  3585. static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
  3586. {
  3587. /* Start with base case */
  3588. adapter->num_rx_queues = 1;
  3589. adapter->num_tx_queues = 1;
  3590. adapter->num_rx_pools = adapter->num_rx_queues;
  3591. adapter->num_rx_queues_per_pool = 1;
  3592. if (ixgbe_set_sriov_queues(adapter))
  3593. goto done;
  3594. #ifdef IXGBE_FCOE
  3595. if (ixgbe_set_fcoe_queues(adapter))
  3596. goto done;
  3597. #endif /* IXGBE_FCOE */
  3598. #ifdef CONFIG_IXGBE_DCB
  3599. if (ixgbe_set_dcb_queues(adapter))
  3600. goto done;
  3601. #endif
  3602. if (ixgbe_set_fdir_queues(adapter))
  3603. goto done;
  3604. if (ixgbe_set_rss_queues(adapter))
  3605. goto done;
  3606. /* fallback to base case */
  3607. adapter->num_rx_queues = 1;
  3608. adapter->num_tx_queues = 1;
  3609. done:
  3610. /* Notify the stack of the (possibly) reduced queue counts. */
  3611. netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
  3612. return netif_set_real_num_rx_queues(adapter->netdev,
  3613. adapter->num_rx_queues);
  3614. }
  3615. static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
  3616. int vectors)
  3617. {
  3618. int err, vector_threshold;
  3619. /* We'll want at least 3 (vector_threshold):
  3620. * 1) TxQ[0] Cleanup
  3621. * 2) RxQ[0] Cleanup
  3622. * 3) Other (Link Status Change, etc.)
  3623. * 4) TCP Timer (optional)
  3624. */
  3625. vector_threshold = MIN_MSIX_COUNT;
  3626. /* The more we get, the more we will assign to Tx/Rx Cleanup
  3627. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  3628. * Right now, we simply care about how many we'll get; we'll
  3629. * set them up later while requesting irq's.
  3630. */
  3631. while (vectors >= vector_threshold) {
  3632. err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
  3633. vectors);
  3634. if (!err) /* Success in acquiring all requested vectors. */
  3635. break;
  3636. else if (err < 0)
  3637. vectors = 0; /* Nasty failure, quit now */
  3638. else /* err == number of vectors we should try again with */
  3639. vectors = err;
  3640. }
  3641. if (vectors < vector_threshold) {
  3642. /* Can't allocate enough MSI-X interrupts? Oh well.
  3643. * This just means we'll go with either a single MSI
  3644. * vector or fall back to legacy interrupts.
  3645. */
  3646. netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
  3647. "Unable to allocate MSI-X interrupts\n");
  3648. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  3649. kfree(adapter->msix_entries);
  3650. adapter->msix_entries = NULL;
  3651. } else {
  3652. adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
  3653. /*
  3654. * Adjust for only the vectors we'll use, which is minimum
  3655. * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
  3656. * vectors we were allocated.
  3657. */
  3658. adapter->num_msix_vectors = min(vectors,
  3659. adapter->max_msix_q_vectors + NON_Q_VECTORS);
  3660. }
  3661. }
  3662. /**
  3663. * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
  3664. * @adapter: board private structure to initialize
  3665. *
  3666. * Cache the descriptor ring offsets for RSS to the assigned rings.
  3667. *
  3668. **/
  3669. static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
  3670. {
  3671. int i;
  3672. bool ret = false;
  3673. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3674. for (i = 0; i < adapter->num_rx_queues; i++)
  3675. adapter->rx_ring[i]->reg_idx = i;
  3676. for (i = 0; i < adapter->num_tx_queues; i++)
  3677. adapter->tx_ring[i]->reg_idx = i;
  3678. ret = true;
  3679. } else {
  3680. ret = false;
  3681. }
  3682. return ret;
  3683. }
  3684. #ifdef CONFIG_IXGBE_DCB
  3685. /**
  3686. * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
  3687. * @adapter: board private structure to initialize
  3688. *
  3689. * Cache the descriptor ring offsets for DCB to the assigned rings.
  3690. *
  3691. **/
  3692. static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
  3693. {
  3694. int i;
  3695. bool ret = false;
  3696. int dcb_i = adapter->ring_feature[RING_F_DCB].indices;
  3697. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3698. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3699. /* the number of queues is assumed to be symmetric */
  3700. for (i = 0; i < dcb_i; i++) {
  3701. adapter->rx_ring[i]->reg_idx = i << 3;
  3702. adapter->tx_ring[i]->reg_idx = i << 2;
  3703. }
  3704. ret = true;
  3705. } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) {
  3706. if (dcb_i == 8) {
  3707. /*
  3708. * Tx TC0 starts at: descriptor queue 0
  3709. * Tx TC1 starts at: descriptor queue 32
  3710. * Tx TC2 starts at: descriptor queue 64
  3711. * Tx TC3 starts at: descriptor queue 80
  3712. * Tx TC4 starts at: descriptor queue 96
  3713. * Tx TC5 starts at: descriptor queue 104
  3714. * Tx TC6 starts at: descriptor queue 112
  3715. * Tx TC7 starts at: descriptor queue 120
  3716. *
  3717. * Rx TC0-TC7 are offset by 16 queues each
  3718. */
  3719. for (i = 0; i < 3; i++) {
  3720. adapter->tx_ring[i]->reg_idx = i << 5;
  3721. adapter->rx_ring[i]->reg_idx = i << 4;
  3722. }
  3723. for ( ; i < 5; i++) {
  3724. adapter->tx_ring[i]->reg_idx =
  3725. ((i + 2) << 4);
  3726. adapter->rx_ring[i]->reg_idx = i << 4;
  3727. }
  3728. for ( ; i < dcb_i; i++) {
  3729. adapter->tx_ring[i]->reg_idx =
  3730. ((i + 8) << 3);
  3731. adapter->rx_ring[i]->reg_idx = i << 4;
  3732. }
  3733. ret = true;
  3734. } else if (dcb_i == 4) {
  3735. /*
  3736. * Tx TC0 starts at: descriptor queue 0
  3737. * Tx TC1 starts at: descriptor queue 64
  3738. * Tx TC2 starts at: descriptor queue 96
  3739. * Tx TC3 starts at: descriptor queue 112
  3740. *
  3741. * Rx TC0-TC3 are offset by 32 queues each
  3742. */
  3743. adapter->tx_ring[0]->reg_idx = 0;
  3744. adapter->tx_ring[1]->reg_idx = 64;
  3745. adapter->tx_ring[2]->reg_idx = 96;
  3746. adapter->tx_ring[3]->reg_idx = 112;
  3747. for (i = 0 ; i < dcb_i; i++)
  3748. adapter->rx_ring[i]->reg_idx = i << 5;
  3749. ret = true;
  3750. } else {
  3751. ret = false;
  3752. }
  3753. } else {
  3754. ret = false;
  3755. }
  3756. } else {
  3757. ret = false;
  3758. }
  3759. return ret;
  3760. }
  3761. #endif
  3762. /**
  3763. * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
  3764. * @adapter: board private structure to initialize
  3765. *
  3766. * Cache the descriptor ring offsets for Flow Director to the assigned rings.
  3767. *
  3768. **/
  3769. static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
  3770. {
  3771. int i;
  3772. bool ret = false;
  3773. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
  3774. ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3775. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
  3776. for (i = 0; i < adapter->num_rx_queues; i++)
  3777. adapter->rx_ring[i]->reg_idx = i;
  3778. for (i = 0; i < adapter->num_tx_queues; i++)
  3779. adapter->tx_ring[i]->reg_idx = i;
  3780. ret = true;
  3781. }
  3782. return ret;
  3783. }
  3784. #ifdef IXGBE_FCOE
  3785. /**
  3786. * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
  3787. * @adapter: board private structure to initialize
  3788. *
  3789. * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
  3790. *
  3791. */
  3792. static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
  3793. {
  3794. int i, fcoe_rx_i = 0, fcoe_tx_i = 0;
  3795. bool ret = false;
  3796. struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
  3797. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  3798. #ifdef CONFIG_IXGBE_DCB
  3799. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  3800. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  3801. ixgbe_cache_ring_dcb(adapter);
  3802. /* find out queues in TC for FCoE */
  3803. fcoe_rx_i = adapter->rx_ring[fcoe->tc]->reg_idx + 1;
  3804. fcoe_tx_i = adapter->tx_ring[fcoe->tc]->reg_idx + 1;
  3805. /*
  3806. * In 82599, the number of Tx queues for each traffic
  3807. * class for both 8-TC and 4-TC modes are:
  3808. * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7
  3809. * 8 TCs: 32 32 16 16 8 8 8 8
  3810. * 4 TCs: 64 64 32 32
  3811. * We have max 8 queues for FCoE, where 8 the is
  3812. * FCoE redirection table size. If TC for FCoE is
  3813. * less than or equal to TC3, we have enough queues
  3814. * to add max of 8 queues for FCoE, so we start FCoE
  3815. * tx descriptor from the next one, i.e., reg_idx + 1.
  3816. * If TC for FCoE is above TC3, implying 8 TC mode,
  3817. * and we need 8 for FCoE, we have to take all queues
  3818. * in that traffic class for FCoE.
  3819. */
  3820. if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3))
  3821. fcoe_tx_i--;
  3822. }
  3823. #endif /* CONFIG_IXGBE_DCB */
  3824. if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
  3825. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
  3826. (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  3827. ixgbe_cache_ring_fdir(adapter);
  3828. else
  3829. ixgbe_cache_ring_rss(adapter);
  3830. fcoe_rx_i = f->mask;
  3831. fcoe_tx_i = f->mask;
  3832. }
  3833. for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
  3834. adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
  3835. adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
  3836. }
  3837. ret = true;
  3838. }
  3839. return ret;
  3840. }
  3841. #endif /* IXGBE_FCOE */
  3842. /**
  3843. * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
  3844. * @adapter: board private structure to initialize
  3845. *
  3846. * SR-IOV doesn't use any descriptor rings but changes the default if
  3847. * no other mapping is used.
  3848. *
  3849. */
  3850. static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
  3851. {
  3852. adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
  3853. adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
  3854. if (adapter->num_vfs)
  3855. return true;
  3856. else
  3857. return false;
  3858. }
  3859. /**
  3860. * ixgbe_cache_ring_register - Descriptor ring to register mapping
  3861. * @adapter: board private structure to initialize
  3862. *
  3863. * Once we know the feature-set enabled for the device, we'll cache
  3864. * the register offset the descriptor ring is assigned to.
  3865. *
  3866. * Note, the order the various feature calls is important. It must start with
  3867. * the "most" features enabled at the same time, then trickle down to the
  3868. * least amount of features turned on at once.
  3869. **/
  3870. static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
  3871. {
  3872. /* start with default case */
  3873. adapter->rx_ring[0]->reg_idx = 0;
  3874. adapter->tx_ring[0]->reg_idx = 0;
  3875. if (ixgbe_cache_ring_sriov(adapter))
  3876. return;
  3877. #ifdef IXGBE_FCOE
  3878. if (ixgbe_cache_ring_fcoe(adapter))
  3879. return;
  3880. #endif /* IXGBE_FCOE */
  3881. #ifdef CONFIG_IXGBE_DCB
  3882. if (ixgbe_cache_ring_dcb(adapter))
  3883. return;
  3884. #endif
  3885. if (ixgbe_cache_ring_fdir(adapter))
  3886. return;
  3887. if (ixgbe_cache_ring_rss(adapter))
  3888. return;
  3889. }
  3890. /**
  3891. * ixgbe_alloc_queues - Allocate memory for all rings
  3892. * @adapter: board private structure to initialize
  3893. *
  3894. * We allocate one ring per queue at run-time since we don't know the
  3895. * number of queues at compile-time. The polling_netdev array is
  3896. * intended for Multiqueue, but should work fine with a single queue.
  3897. **/
  3898. static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
  3899. {
  3900. int i;
  3901. int orig_node = adapter->node;
  3902. for (i = 0; i < adapter->num_tx_queues; i++) {
  3903. struct ixgbe_ring *ring = adapter->tx_ring[i];
  3904. if (orig_node == -1) {
  3905. int cur_node = next_online_node(adapter->node);
  3906. if (cur_node == MAX_NUMNODES)
  3907. cur_node = first_online_node;
  3908. adapter->node = cur_node;
  3909. }
  3910. ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL,
  3911. adapter->node);
  3912. if (!ring)
  3913. ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL);
  3914. if (!ring)
  3915. goto err_tx_ring_allocation;
  3916. ring->count = adapter->tx_ring_count;
  3917. ring->queue_index = i;
  3918. ring->numa_node = adapter->node;
  3919. adapter->tx_ring[i] = ring;
  3920. }
  3921. /* Restore the adapter's original node */
  3922. adapter->node = orig_node;
  3923. for (i = 0; i < adapter->num_rx_queues; i++) {
  3924. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3925. if (orig_node == -1) {
  3926. int cur_node = next_online_node(adapter->node);
  3927. if (cur_node == MAX_NUMNODES)
  3928. cur_node = first_online_node;
  3929. adapter->node = cur_node;
  3930. }
  3931. ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL,
  3932. adapter->node);
  3933. if (!ring)
  3934. ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL);
  3935. if (!ring)
  3936. goto err_rx_ring_allocation;
  3937. ring->count = adapter->rx_ring_count;
  3938. ring->queue_index = i;
  3939. ring->numa_node = adapter->node;
  3940. adapter->rx_ring[i] = ring;
  3941. }
  3942. /* Restore the adapter's original node */
  3943. adapter->node = orig_node;
  3944. ixgbe_cache_ring_register(adapter);
  3945. return 0;
  3946. err_rx_ring_allocation:
  3947. for (i = 0; i < adapter->num_tx_queues; i++)
  3948. kfree(adapter->tx_ring[i]);
  3949. err_tx_ring_allocation:
  3950. return -ENOMEM;
  3951. }
  3952. /**
  3953. * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
  3954. * @adapter: board private structure to initialize
  3955. *
  3956. * Attempt to configure the interrupts using the best available
  3957. * capabilities of the hardware and the kernel.
  3958. **/
  3959. static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
  3960. {
  3961. struct ixgbe_hw *hw = &adapter->hw;
  3962. int err = 0;
  3963. int vector, v_budget;
  3964. /*
  3965. * It's easy to be greedy for MSI-X vectors, but it really
  3966. * doesn't do us much good if we have a lot more vectors
  3967. * than CPU's. So let's be conservative and only ask for
  3968. * (roughly) the same number of vectors as there are CPU's.
  3969. */
  3970. v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
  3971. (int)num_online_cpus()) + NON_Q_VECTORS;
  3972. /*
  3973. * At the same time, hardware can only support a maximum of
  3974. * hw.mac->max_msix_vectors vectors. With features
  3975. * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
  3976. * descriptor queues supported by our device. Thus, we cap it off in
  3977. * those rare cases where the cpu count also exceeds our vector limit.
  3978. */
  3979. v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
  3980. /* A failure in MSI-X entry allocation isn't fatal, but it does
  3981. * mean we disable MSI-X capabilities of the adapter. */
  3982. adapter->msix_entries = kcalloc(v_budget,
  3983. sizeof(struct msix_entry), GFP_KERNEL);
  3984. if (adapter->msix_entries) {
  3985. for (vector = 0; vector < v_budget; vector++)
  3986. adapter->msix_entries[vector].entry = vector;
  3987. ixgbe_acquire_msix_vectors(adapter, v_budget);
  3988. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3989. goto out;
  3990. }
  3991. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  3992. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  3993. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  3994. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  3995. adapter->atr_sample_rate = 0;
  3996. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3997. ixgbe_disable_sriov(adapter);
  3998. err = ixgbe_set_num_queues(adapter);
  3999. if (err)
  4000. return err;
  4001. err = pci_enable_msi(adapter->pdev);
  4002. if (!err) {
  4003. adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
  4004. } else {
  4005. netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
  4006. "Unable to allocate MSI interrupt, "
  4007. "falling back to legacy. Error: %d\n", err);
  4008. /* reset err */
  4009. err = 0;
  4010. }
  4011. out:
  4012. return err;
  4013. }
  4014. /**
  4015. * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
  4016. * @adapter: board private structure to initialize
  4017. *
  4018. * We allocate one q_vector per queue interrupt. If allocation fails we
  4019. * return -ENOMEM.
  4020. **/
  4021. static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
  4022. {
  4023. int q_idx, num_q_vectors;
  4024. struct ixgbe_q_vector *q_vector;
  4025. int napi_vectors;
  4026. int (*poll)(struct napi_struct *, int);
  4027. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4028. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  4029. napi_vectors = adapter->num_rx_queues;
  4030. poll = &ixgbe_clean_rxtx_many;
  4031. } else {
  4032. num_q_vectors = 1;
  4033. napi_vectors = 1;
  4034. poll = &ixgbe_poll;
  4035. }
  4036. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  4037. q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
  4038. GFP_KERNEL, adapter->node);
  4039. if (!q_vector)
  4040. q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
  4041. GFP_KERNEL);
  4042. if (!q_vector)
  4043. goto err_out;
  4044. q_vector->adapter = adapter;
  4045. if (q_vector->txr_count && !q_vector->rxr_count)
  4046. q_vector->eitr = adapter->tx_eitr_param;
  4047. else
  4048. q_vector->eitr = adapter->rx_eitr_param;
  4049. q_vector->v_idx = q_idx;
  4050. netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
  4051. adapter->q_vector[q_idx] = q_vector;
  4052. }
  4053. return 0;
  4054. err_out:
  4055. while (q_idx) {
  4056. q_idx--;
  4057. q_vector = adapter->q_vector[q_idx];
  4058. netif_napi_del(&q_vector->napi);
  4059. kfree(q_vector);
  4060. adapter->q_vector[q_idx] = NULL;
  4061. }
  4062. return -ENOMEM;
  4063. }
  4064. /**
  4065. * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
  4066. * @adapter: board private structure to initialize
  4067. *
  4068. * This function frees the memory allocated to the q_vectors. In addition if
  4069. * NAPI is enabled it will delete any references to the NAPI struct prior
  4070. * to freeing the q_vector.
  4071. **/
  4072. static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
  4073. {
  4074. int q_idx, num_q_vectors;
  4075. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4076. num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  4077. else
  4078. num_q_vectors = 1;
  4079. for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
  4080. struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
  4081. adapter->q_vector[q_idx] = NULL;
  4082. netif_napi_del(&q_vector->napi);
  4083. kfree(q_vector);
  4084. }
  4085. }
  4086. static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
  4087. {
  4088. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4089. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  4090. pci_disable_msix(adapter->pdev);
  4091. kfree(adapter->msix_entries);
  4092. adapter->msix_entries = NULL;
  4093. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  4094. adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
  4095. pci_disable_msi(adapter->pdev);
  4096. }
  4097. }
  4098. /**
  4099. * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
  4100. * @adapter: board private structure to initialize
  4101. *
  4102. * We determine which interrupt scheme to use based on...
  4103. * - Kernel support (MSI, MSI-X)
  4104. * - which can be user-defined (via MODULE_PARAM)
  4105. * - Hardware queue count (num_*_queues)
  4106. * - defined by miscellaneous hardware support/features (RSS, etc.)
  4107. **/
  4108. int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
  4109. {
  4110. int err;
  4111. /* Number of supported queues */
  4112. err = ixgbe_set_num_queues(adapter);
  4113. if (err)
  4114. return err;
  4115. err = ixgbe_set_interrupt_capability(adapter);
  4116. if (err) {
  4117. e_dev_err("Unable to setup interrupt capabilities\n");
  4118. goto err_set_interrupt;
  4119. }
  4120. err = ixgbe_alloc_q_vectors(adapter);
  4121. if (err) {
  4122. e_dev_err("Unable to allocate memory for queue vectors\n");
  4123. goto err_alloc_q_vectors;
  4124. }
  4125. err = ixgbe_alloc_queues(adapter);
  4126. if (err) {
  4127. e_dev_err("Unable to allocate memory for queues\n");
  4128. goto err_alloc_queues;
  4129. }
  4130. e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
  4131. (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
  4132. adapter->num_rx_queues, adapter->num_tx_queues);
  4133. set_bit(__IXGBE_DOWN, &adapter->state);
  4134. return 0;
  4135. err_alloc_queues:
  4136. ixgbe_free_q_vectors(adapter);
  4137. err_alloc_q_vectors:
  4138. ixgbe_reset_interrupt_capability(adapter);
  4139. err_set_interrupt:
  4140. return err;
  4141. }
  4142. static void ring_free_rcu(struct rcu_head *head)
  4143. {
  4144. kfree(container_of(head, struct ixgbe_ring, rcu));
  4145. }
  4146. /**
  4147. * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
  4148. * @adapter: board private structure to clear interrupt scheme on
  4149. *
  4150. * We go through and clear interrupt specific resources and reset the structure
  4151. * to pre-load conditions
  4152. **/
  4153. void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
  4154. {
  4155. int i;
  4156. for (i = 0; i < adapter->num_tx_queues; i++) {
  4157. kfree(adapter->tx_ring[i]);
  4158. adapter->tx_ring[i] = NULL;
  4159. }
  4160. for (i = 0; i < adapter->num_rx_queues; i++) {
  4161. struct ixgbe_ring *ring = adapter->rx_ring[i];
  4162. /* ixgbe_get_stats64() might access this ring, we must wait
  4163. * a grace period before freeing it.
  4164. */
  4165. call_rcu(&ring->rcu, ring_free_rcu);
  4166. adapter->rx_ring[i] = NULL;
  4167. }
  4168. ixgbe_free_q_vectors(adapter);
  4169. ixgbe_reset_interrupt_capability(adapter);
  4170. }
  4171. /**
  4172. * ixgbe_sfp_timer - worker thread to find a missing module
  4173. * @data: pointer to our adapter struct
  4174. **/
  4175. static void ixgbe_sfp_timer(unsigned long data)
  4176. {
  4177. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  4178. /*
  4179. * Do the sfp_timer outside of interrupt context due to the
  4180. * delays that sfp+ detection requires
  4181. */
  4182. schedule_work(&adapter->sfp_task);
  4183. }
  4184. /**
  4185. * ixgbe_sfp_task - worker thread to find a missing module
  4186. * @work: pointer to work_struct containing our data
  4187. **/
  4188. static void ixgbe_sfp_task(struct work_struct *work)
  4189. {
  4190. struct ixgbe_adapter *adapter = container_of(work,
  4191. struct ixgbe_adapter,
  4192. sfp_task);
  4193. struct ixgbe_hw *hw = &adapter->hw;
  4194. if ((hw->phy.type == ixgbe_phy_nl) &&
  4195. (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
  4196. s32 ret = hw->phy.ops.identify_sfp(hw);
  4197. if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
  4198. goto reschedule;
  4199. ret = hw->phy.ops.reset(hw);
  4200. if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  4201. e_dev_err("failed to initialize because an unsupported "
  4202. "SFP+ module type was detected.\n");
  4203. e_dev_err("Reload the driver after installing a "
  4204. "supported module.\n");
  4205. unregister_netdev(adapter->netdev);
  4206. } else {
  4207. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  4208. }
  4209. /* don't need this routine any more */
  4210. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  4211. }
  4212. return;
  4213. reschedule:
  4214. if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
  4215. mod_timer(&adapter->sfp_timer,
  4216. round_jiffies(jiffies + (2 * HZ)));
  4217. }
  4218. /**
  4219. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  4220. * @adapter: board private structure to initialize
  4221. *
  4222. * ixgbe_sw_init initializes the Adapter private data structure.
  4223. * Fields are initialized based on PCI device information and
  4224. * OS network device settings (MTU size).
  4225. **/
  4226. static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
  4227. {
  4228. struct ixgbe_hw *hw = &adapter->hw;
  4229. struct pci_dev *pdev = adapter->pdev;
  4230. struct net_device *dev = adapter->netdev;
  4231. unsigned int rss;
  4232. #ifdef CONFIG_IXGBE_DCB
  4233. int j;
  4234. struct tc_configuration *tc;
  4235. #endif
  4236. int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4237. /* PCI config space info */
  4238. hw->vendor_id = pdev->vendor;
  4239. hw->device_id = pdev->device;
  4240. hw->revision_id = pdev->revision;
  4241. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  4242. hw->subsystem_device_id = pdev->subsystem_device;
  4243. /* Set capability flags */
  4244. rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
  4245. adapter->ring_feature[RING_F_RSS].indices = rss;
  4246. adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
  4247. adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
  4248. if (hw->mac.type == ixgbe_mac_82598EB) {
  4249. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  4250. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  4251. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
  4252. } else if (hw->mac.type == ixgbe_mac_82599EB) {
  4253. adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
  4254. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  4255. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  4256. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  4257. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  4258. if (dev->features & NETIF_F_NTUPLE) {
  4259. /* Flow Director perfect filter enabled */
  4260. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  4261. adapter->atr_sample_rate = 0;
  4262. spin_lock_init(&adapter->fdir_perfect_lock);
  4263. } else {
  4264. /* Flow Director hash filters enabled */
  4265. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  4266. adapter->atr_sample_rate = 20;
  4267. }
  4268. adapter->ring_feature[RING_F_FDIR].indices =
  4269. IXGBE_MAX_FDIR_INDICES;
  4270. adapter->fdir_pballoc = 0;
  4271. #ifdef IXGBE_FCOE
  4272. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  4273. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  4274. adapter->ring_feature[RING_F_FCOE].indices = 0;
  4275. #ifdef CONFIG_IXGBE_DCB
  4276. /* Default traffic class to use for FCoE */
  4277. adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
  4278. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  4279. #endif
  4280. #endif /* IXGBE_FCOE */
  4281. }
  4282. #ifdef CONFIG_IXGBE_DCB
  4283. /* Configure DCB traffic classes */
  4284. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  4285. tc = &adapter->dcb_cfg.tc_config[j];
  4286. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  4287. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  4288. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  4289. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  4290. tc->dcb_pfc = pfc_disabled;
  4291. }
  4292. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  4293. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  4294. adapter->dcb_cfg.rx_pba_cfg = pba_equal;
  4295. adapter->dcb_cfg.pfc_mode_enable = false;
  4296. adapter->dcb_cfg.round_robin_enable = false;
  4297. adapter->dcb_set_bitmap = 0x00;
  4298. ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
  4299. adapter->ring_feature[RING_F_DCB].indices);
  4300. #endif
  4301. /* default flow control settings */
  4302. hw->fc.requested_mode = ixgbe_fc_full;
  4303. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  4304. #ifdef CONFIG_DCB
  4305. adapter->last_lfc_mode = hw->fc.current_mode;
  4306. #endif
  4307. hw->fc.high_water = FC_HIGH_WATER(max_frame);
  4308. hw->fc.low_water = FC_LOW_WATER(max_frame);
  4309. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  4310. hw->fc.send_xon = true;
  4311. hw->fc.disable_fc_autoneg = false;
  4312. /* enable itr by default in dynamic mode */
  4313. adapter->rx_itr_setting = 1;
  4314. adapter->rx_eitr_param = 20000;
  4315. adapter->tx_itr_setting = 1;
  4316. adapter->tx_eitr_param = 10000;
  4317. /* set defaults for eitr in MegaBytes */
  4318. adapter->eitr_low = 10;
  4319. adapter->eitr_high = 20;
  4320. /* set default ring sizes */
  4321. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  4322. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  4323. /* initialize eeprom parameters */
  4324. if (ixgbe_init_eeprom_params_generic(hw)) {
  4325. e_dev_err("EEPROM initialization failed\n");
  4326. return -EIO;
  4327. }
  4328. /* enable rx csum by default */
  4329. adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
  4330. /* get assigned NUMA node */
  4331. adapter->node = dev_to_node(&pdev->dev);
  4332. set_bit(__IXGBE_DOWN, &adapter->state);
  4333. return 0;
  4334. }
  4335. /**
  4336. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  4337. * @adapter: board private structure
  4338. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  4339. *
  4340. * Return 0 on success, negative on failure
  4341. **/
  4342. int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter,
  4343. struct ixgbe_ring *tx_ring)
  4344. {
  4345. struct pci_dev *pdev = adapter->pdev;
  4346. int size;
  4347. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  4348. tx_ring->tx_buffer_info = vmalloc_node(size, tx_ring->numa_node);
  4349. if (!tx_ring->tx_buffer_info)
  4350. tx_ring->tx_buffer_info = vmalloc(size);
  4351. if (!tx_ring->tx_buffer_info)
  4352. goto err;
  4353. memset(tx_ring->tx_buffer_info, 0, size);
  4354. /* round up to nearest 4K */
  4355. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  4356. tx_ring->size = ALIGN(tx_ring->size, 4096);
  4357. tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
  4358. &tx_ring->dma, GFP_KERNEL);
  4359. if (!tx_ring->desc)
  4360. goto err;
  4361. tx_ring->next_to_use = 0;
  4362. tx_ring->next_to_clean = 0;
  4363. tx_ring->work_limit = tx_ring->count;
  4364. return 0;
  4365. err:
  4366. vfree(tx_ring->tx_buffer_info);
  4367. tx_ring->tx_buffer_info = NULL;
  4368. e_err(probe, "Unable to allocate memory for the Tx descriptor ring\n");
  4369. return -ENOMEM;
  4370. }
  4371. /**
  4372. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  4373. * @adapter: board private structure
  4374. *
  4375. * If this function returns with an error, then it's possible one or
  4376. * more of the rings is populated (while the rest are not). It is the
  4377. * callers duty to clean those orphaned rings.
  4378. *
  4379. * Return 0 on success, negative on failure
  4380. **/
  4381. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  4382. {
  4383. int i, err = 0;
  4384. for (i = 0; i < adapter->num_tx_queues; i++) {
  4385. err = ixgbe_setup_tx_resources(adapter, adapter->tx_ring[i]);
  4386. if (!err)
  4387. continue;
  4388. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  4389. break;
  4390. }
  4391. return err;
  4392. }
  4393. /**
  4394. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  4395. * @adapter: board private structure
  4396. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  4397. *
  4398. * Returns 0 on success, negative on failure
  4399. **/
  4400. int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
  4401. struct ixgbe_ring *rx_ring)
  4402. {
  4403. struct pci_dev *pdev = adapter->pdev;
  4404. int size;
  4405. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  4406. rx_ring->rx_buffer_info = vmalloc_node(size, adapter->node);
  4407. if (!rx_ring->rx_buffer_info)
  4408. rx_ring->rx_buffer_info = vmalloc(size);
  4409. if (!rx_ring->rx_buffer_info) {
  4410. e_err(probe, "vmalloc allocation failed for the Rx "
  4411. "descriptor ring\n");
  4412. goto alloc_failed;
  4413. }
  4414. memset(rx_ring->rx_buffer_info, 0, size);
  4415. /* Round up to nearest 4K */
  4416. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  4417. rx_ring->size = ALIGN(rx_ring->size, 4096);
  4418. rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
  4419. &rx_ring->dma, GFP_KERNEL);
  4420. if (!rx_ring->desc) {
  4421. e_err(probe, "Memory allocation failed for the Rx "
  4422. "descriptor ring\n");
  4423. vfree(rx_ring->rx_buffer_info);
  4424. goto alloc_failed;
  4425. }
  4426. rx_ring->next_to_clean = 0;
  4427. rx_ring->next_to_use = 0;
  4428. return 0;
  4429. alloc_failed:
  4430. return -ENOMEM;
  4431. }
  4432. /**
  4433. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  4434. * @adapter: board private structure
  4435. *
  4436. * If this function returns with an error, then it's possible one or
  4437. * more of the rings is populated (while the rest are not). It is the
  4438. * callers duty to clean those orphaned rings.
  4439. *
  4440. * Return 0 on success, negative on failure
  4441. **/
  4442. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  4443. {
  4444. int i, err = 0;
  4445. for (i = 0; i < adapter->num_rx_queues; i++) {
  4446. err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
  4447. if (!err)
  4448. continue;
  4449. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  4450. break;
  4451. }
  4452. return err;
  4453. }
  4454. /**
  4455. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  4456. * @adapter: board private structure
  4457. * @tx_ring: Tx descriptor ring for a specific queue
  4458. *
  4459. * Free all transmit software resources
  4460. **/
  4461. void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter,
  4462. struct ixgbe_ring *tx_ring)
  4463. {
  4464. struct pci_dev *pdev = adapter->pdev;
  4465. ixgbe_clean_tx_ring(adapter, tx_ring);
  4466. vfree(tx_ring->tx_buffer_info);
  4467. tx_ring->tx_buffer_info = NULL;
  4468. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  4469. tx_ring->dma);
  4470. tx_ring->desc = NULL;
  4471. }
  4472. /**
  4473. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  4474. * @adapter: board private structure
  4475. *
  4476. * Free all transmit software resources
  4477. **/
  4478. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  4479. {
  4480. int i;
  4481. for (i = 0; i < adapter->num_tx_queues; i++)
  4482. if (adapter->tx_ring[i]->desc)
  4483. ixgbe_free_tx_resources(adapter, adapter->tx_ring[i]);
  4484. }
  4485. /**
  4486. * ixgbe_free_rx_resources - Free Rx Resources
  4487. * @adapter: board private structure
  4488. * @rx_ring: ring to clean the resources from
  4489. *
  4490. * Free all receive software resources
  4491. **/
  4492. void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter,
  4493. struct ixgbe_ring *rx_ring)
  4494. {
  4495. struct pci_dev *pdev = adapter->pdev;
  4496. ixgbe_clean_rx_ring(adapter, rx_ring);
  4497. vfree(rx_ring->rx_buffer_info);
  4498. rx_ring->rx_buffer_info = NULL;
  4499. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  4500. rx_ring->dma);
  4501. rx_ring->desc = NULL;
  4502. }
  4503. /**
  4504. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  4505. * @adapter: board private structure
  4506. *
  4507. * Free all receive software resources
  4508. **/
  4509. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  4510. {
  4511. int i;
  4512. for (i = 0; i < adapter->num_rx_queues; i++)
  4513. if (adapter->rx_ring[i]->desc)
  4514. ixgbe_free_rx_resources(adapter, adapter->rx_ring[i]);
  4515. }
  4516. /**
  4517. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  4518. * @netdev: network interface device structure
  4519. * @new_mtu: new value for maximum frame size
  4520. *
  4521. * Returns 0 on success, negative on failure
  4522. **/
  4523. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  4524. {
  4525. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4526. struct ixgbe_hw *hw = &adapter->hw;
  4527. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  4528. /* MTU < 68 is an error and causes problems on some kernels */
  4529. if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
  4530. return -EINVAL;
  4531. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  4532. /* must set new MTU before calling down or up */
  4533. netdev->mtu = new_mtu;
  4534. hw->fc.high_water = FC_HIGH_WATER(max_frame);
  4535. hw->fc.low_water = FC_LOW_WATER(max_frame);
  4536. if (netif_running(netdev))
  4537. ixgbe_reinit_locked(adapter);
  4538. return 0;
  4539. }
  4540. /**
  4541. * ixgbe_open - Called when a network interface is made active
  4542. * @netdev: network interface device structure
  4543. *
  4544. * Returns 0 on success, negative value on failure
  4545. *
  4546. * The open entry point is called when a network interface is made
  4547. * active by the system (IFF_UP). At this point all resources needed
  4548. * for transmit and receive operations are allocated, the interrupt
  4549. * handler is registered with the OS, the watchdog timer is started,
  4550. * and the stack is notified that the interface is ready.
  4551. **/
  4552. static int ixgbe_open(struct net_device *netdev)
  4553. {
  4554. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4555. int err;
  4556. /* disallow open during test */
  4557. if (test_bit(__IXGBE_TESTING, &adapter->state))
  4558. return -EBUSY;
  4559. netif_carrier_off(netdev);
  4560. /* allocate transmit descriptors */
  4561. err = ixgbe_setup_all_tx_resources(adapter);
  4562. if (err)
  4563. goto err_setup_tx;
  4564. /* allocate receive descriptors */
  4565. err = ixgbe_setup_all_rx_resources(adapter);
  4566. if (err)
  4567. goto err_setup_rx;
  4568. ixgbe_configure(adapter);
  4569. err = ixgbe_request_irq(adapter);
  4570. if (err)
  4571. goto err_req_irq;
  4572. err = ixgbe_up_complete(adapter);
  4573. if (err)
  4574. goto err_up;
  4575. netif_tx_start_all_queues(netdev);
  4576. return 0;
  4577. err_up:
  4578. ixgbe_release_hw_control(adapter);
  4579. ixgbe_free_irq(adapter);
  4580. err_req_irq:
  4581. err_setup_rx:
  4582. ixgbe_free_all_rx_resources(adapter);
  4583. err_setup_tx:
  4584. ixgbe_free_all_tx_resources(adapter);
  4585. ixgbe_reset(adapter);
  4586. return err;
  4587. }
  4588. /**
  4589. * ixgbe_close - Disables a network interface
  4590. * @netdev: network interface device structure
  4591. *
  4592. * Returns 0, this is not allowed to fail
  4593. *
  4594. * The close entry point is called when an interface is de-activated
  4595. * by the OS. The hardware is still under the drivers control, but
  4596. * needs to be disabled. A global MAC reset is issued to stop the
  4597. * hardware, and all transmit and receive resources are freed.
  4598. **/
  4599. static int ixgbe_close(struct net_device *netdev)
  4600. {
  4601. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4602. ixgbe_down(adapter);
  4603. ixgbe_free_irq(adapter);
  4604. ixgbe_free_all_tx_resources(adapter);
  4605. ixgbe_free_all_rx_resources(adapter);
  4606. ixgbe_release_hw_control(adapter);
  4607. return 0;
  4608. }
  4609. #ifdef CONFIG_PM
  4610. static int ixgbe_resume(struct pci_dev *pdev)
  4611. {
  4612. struct net_device *netdev = pci_get_drvdata(pdev);
  4613. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4614. u32 err;
  4615. pci_set_power_state(pdev, PCI_D0);
  4616. pci_restore_state(pdev);
  4617. /*
  4618. * pci_restore_state clears dev->state_saved so call
  4619. * pci_save_state to restore it.
  4620. */
  4621. pci_save_state(pdev);
  4622. err = pci_enable_device_mem(pdev);
  4623. if (err) {
  4624. e_dev_err("Cannot enable PCI device from suspend\n");
  4625. return err;
  4626. }
  4627. pci_set_master(pdev);
  4628. pci_wake_from_d3(pdev, false);
  4629. err = ixgbe_init_interrupt_scheme(adapter);
  4630. if (err) {
  4631. e_dev_err("Cannot initialize interrupts for device\n");
  4632. return err;
  4633. }
  4634. ixgbe_reset(adapter);
  4635. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  4636. if (netif_running(netdev)) {
  4637. err = ixgbe_open(adapter->netdev);
  4638. if (err)
  4639. return err;
  4640. }
  4641. netif_device_attach(netdev);
  4642. return 0;
  4643. }
  4644. #endif /* CONFIG_PM */
  4645. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  4646. {
  4647. struct net_device *netdev = pci_get_drvdata(pdev);
  4648. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4649. struct ixgbe_hw *hw = &adapter->hw;
  4650. u32 ctrl, fctrl;
  4651. u32 wufc = adapter->wol;
  4652. #ifdef CONFIG_PM
  4653. int retval = 0;
  4654. #endif
  4655. netif_device_detach(netdev);
  4656. if (netif_running(netdev)) {
  4657. ixgbe_down(adapter);
  4658. ixgbe_free_irq(adapter);
  4659. ixgbe_free_all_tx_resources(adapter);
  4660. ixgbe_free_all_rx_resources(adapter);
  4661. }
  4662. #ifdef CONFIG_PM
  4663. retval = pci_save_state(pdev);
  4664. if (retval)
  4665. return retval;
  4666. #endif
  4667. if (wufc) {
  4668. ixgbe_set_rx_mode(netdev);
  4669. /* turn on all-multi mode if wake on multicast is enabled */
  4670. if (wufc & IXGBE_WUFC_MC) {
  4671. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4672. fctrl |= IXGBE_FCTRL_MPE;
  4673. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  4674. }
  4675. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  4676. ctrl |= IXGBE_CTRL_GIO_DIS;
  4677. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  4678. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  4679. } else {
  4680. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  4681. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  4682. }
  4683. if (wufc && hw->mac.type == ixgbe_mac_82599EB)
  4684. pci_wake_from_d3(pdev, true);
  4685. else
  4686. pci_wake_from_d3(pdev, false);
  4687. *enable_wake = !!wufc;
  4688. ixgbe_clear_interrupt_scheme(adapter);
  4689. ixgbe_release_hw_control(adapter);
  4690. pci_disable_device(pdev);
  4691. return 0;
  4692. }
  4693. #ifdef CONFIG_PM
  4694. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  4695. {
  4696. int retval;
  4697. bool wake;
  4698. retval = __ixgbe_shutdown(pdev, &wake);
  4699. if (retval)
  4700. return retval;
  4701. if (wake) {
  4702. pci_prepare_to_sleep(pdev);
  4703. } else {
  4704. pci_wake_from_d3(pdev, false);
  4705. pci_set_power_state(pdev, PCI_D3hot);
  4706. }
  4707. return 0;
  4708. }
  4709. #endif /* CONFIG_PM */
  4710. static void ixgbe_shutdown(struct pci_dev *pdev)
  4711. {
  4712. bool wake;
  4713. __ixgbe_shutdown(pdev, &wake);
  4714. if (system_state == SYSTEM_POWER_OFF) {
  4715. pci_wake_from_d3(pdev, wake);
  4716. pci_set_power_state(pdev, PCI_D3hot);
  4717. }
  4718. }
  4719. /**
  4720. * ixgbe_update_stats - Update the board statistics counters.
  4721. * @adapter: board private structure
  4722. **/
  4723. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  4724. {
  4725. struct net_device *netdev = adapter->netdev;
  4726. struct ixgbe_hw *hw = &adapter->hw;
  4727. u64 total_mpc = 0;
  4728. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  4729. u64 non_eop_descs = 0, restart_queue = 0;
  4730. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  4731. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  4732. test_bit(__IXGBE_RESETTING, &adapter->state))
  4733. return;
  4734. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  4735. u64 rsc_count = 0;
  4736. u64 rsc_flush = 0;
  4737. for (i = 0; i < 16; i++)
  4738. adapter->hw_rx_no_dma_resources +=
  4739. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  4740. for (i = 0; i < adapter->num_rx_queues; i++) {
  4741. rsc_count += adapter->rx_ring[i]->rsc_count;
  4742. rsc_flush += adapter->rx_ring[i]->rsc_flush;
  4743. }
  4744. adapter->rsc_total_count = rsc_count;
  4745. adapter->rsc_total_flush = rsc_flush;
  4746. }
  4747. /* gather some stats to the adapter struct that are per queue */
  4748. for (i = 0; i < adapter->num_tx_queues; i++)
  4749. restart_queue += adapter->tx_ring[i]->restart_queue;
  4750. adapter->restart_queue = restart_queue;
  4751. for (i = 0; i < adapter->num_rx_queues; i++)
  4752. non_eop_descs += adapter->rx_ring[i]->non_eop_descs;
  4753. adapter->non_eop_descs = non_eop_descs;
  4754. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  4755. for (i = 0; i < 8; i++) {
  4756. /* for packet buffers not used, the register should read 0 */
  4757. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  4758. missed_rx += mpc;
  4759. hwstats->mpc[i] += mpc;
  4760. total_mpc += hwstats->mpc[i];
  4761. if (hw->mac.type == ixgbe_mac_82598EB)
  4762. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  4763. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  4764. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  4765. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  4766. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  4767. if (hw->mac.type == ixgbe_mac_82599EB) {
  4768. hwstats->pxonrxc[i] +=
  4769. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  4770. hwstats->pxoffrxc[i] +=
  4771. IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  4772. hwstats->qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  4773. } else {
  4774. hwstats->pxonrxc[i] +=
  4775. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  4776. hwstats->pxoffrxc[i] +=
  4777. IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  4778. }
  4779. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  4780. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  4781. }
  4782. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  4783. /* work around hardware counting issue */
  4784. hwstats->gprc -= missed_rx;
  4785. /* 82598 hardware only has a 32 bit counter in the high register */
  4786. if (hw->mac.type == ixgbe_mac_82599EB) {
  4787. u64 tmp;
  4788. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  4789. tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF;
  4790. /* 4 high bits of GORC */
  4791. hwstats->gorc += (tmp << 32);
  4792. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  4793. tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF;
  4794. /* 4 high bits of GOTC */
  4795. hwstats->gotc += (tmp << 32);
  4796. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  4797. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  4798. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  4799. hwstats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  4800. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  4801. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  4802. #ifdef IXGBE_FCOE
  4803. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  4804. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  4805. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  4806. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  4807. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  4808. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  4809. #endif /* IXGBE_FCOE */
  4810. } else {
  4811. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  4812. hwstats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  4813. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  4814. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  4815. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  4816. }
  4817. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  4818. hwstats->bprc += bprc;
  4819. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  4820. if (hw->mac.type == ixgbe_mac_82598EB)
  4821. hwstats->mprc -= bprc;
  4822. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  4823. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  4824. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  4825. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  4826. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  4827. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  4828. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  4829. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  4830. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  4831. hwstats->lxontxc += lxon;
  4832. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  4833. hwstats->lxofftxc += lxoff;
  4834. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4835. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  4836. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  4837. /*
  4838. * 82598 errata - tx of flow control packets is included in tx counters
  4839. */
  4840. xon_off_tot = lxon + lxoff;
  4841. hwstats->gptc -= xon_off_tot;
  4842. hwstats->mptc -= xon_off_tot;
  4843. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  4844. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4845. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  4846. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  4847. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  4848. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  4849. hwstats->ptc64 -= xon_off_tot;
  4850. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  4851. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  4852. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  4853. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  4854. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  4855. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  4856. /* Fill out the OS statistics structure */
  4857. netdev->stats.multicast = hwstats->mprc;
  4858. /* Rx Errors */
  4859. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  4860. netdev->stats.rx_dropped = 0;
  4861. netdev->stats.rx_length_errors = hwstats->rlec;
  4862. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  4863. netdev->stats.rx_missed_errors = total_mpc;
  4864. }
  4865. /**
  4866. * ixgbe_watchdog - Timer Call-back
  4867. * @data: pointer to adapter cast into an unsigned long
  4868. **/
  4869. static void ixgbe_watchdog(unsigned long data)
  4870. {
  4871. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  4872. struct ixgbe_hw *hw = &adapter->hw;
  4873. u64 eics = 0;
  4874. int i;
  4875. /*
  4876. * Do the watchdog outside of interrupt context due to the lovely
  4877. * delays that some of the newer hardware requires
  4878. */
  4879. if (test_bit(__IXGBE_DOWN, &adapter->state))
  4880. goto watchdog_short_circuit;
  4881. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  4882. /*
  4883. * for legacy and MSI interrupts don't set any bits
  4884. * that are enabled for EIAM, because this operation
  4885. * would set *both* EIMS and EICS for any bit in EIAM
  4886. */
  4887. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  4888. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  4889. goto watchdog_reschedule;
  4890. }
  4891. /* get one bit for every active tx/rx interrupt vector */
  4892. for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
  4893. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  4894. if (qv->rxr_count || qv->txr_count)
  4895. eics |= ((u64)1 << i);
  4896. }
  4897. /* Cause software interrupt to ensure rx rings are cleaned */
  4898. ixgbe_irq_rearm_queues(adapter, eics);
  4899. watchdog_reschedule:
  4900. /* Reset the timer */
  4901. mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
  4902. watchdog_short_circuit:
  4903. schedule_work(&adapter->watchdog_task);
  4904. }
  4905. /**
  4906. * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
  4907. * @work: pointer to work_struct containing our data
  4908. **/
  4909. static void ixgbe_multispeed_fiber_task(struct work_struct *work)
  4910. {
  4911. struct ixgbe_adapter *adapter = container_of(work,
  4912. struct ixgbe_adapter,
  4913. multispeed_fiber_task);
  4914. struct ixgbe_hw *hw = &adapter->hw;
  4915. u32 autoneg;
  4916. bool negotiation;
  4917. adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
  4918. autoneg = hw->phy.autoneg_advertised;
  4919. if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
  4920. hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
  4921. hw->mac.autotry_restart = false;
  4922. if (hw->mac.ops.setup_link)
  4923. hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
  4924. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4925. adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
  4926. }
  4927. /**
  4928. * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
  4929. * @work: pointer to work_struct containing our data
  4930. **/
  4931. static void ixgbe_sfp_config_module_task(struct work_struct *work)
  4932. {
  4933. struct ixgbe_adapter *adapter = container_of(work,
  4934. struct ixgbe_adapter,
  4935. sfp_config_module_task);
  4936. struct ixgbe_hw *hw = &adapter->hw;
  4937. u32 err;
  4938. adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
  4939. /* Time for electrical oscillations to settle down */
  4940. msleep(100);
  4941. err = hw->phy.ops.identify_sfp(hw);
  4942. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  4943. e_dev_err("failed to initialize because an unsupported SFP+ "
  4944. "module type was detected.\n");
  4945. e_dev_err("Reload the driver after installing a supported "
  4946. "module.\n");
  4947. unregister_netdev(adapter->netdev);
  4948. return;
  4949. }
  4950. hw->mac.ops.setup_sfp(hw);
  4951. if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
  4952. /* This will also work for DA Twinax connections */
  4953. schedule_work(&adapter->multispeed_fiber_task);
  4954. adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
  4955. }
  4956. /**
  4957. * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
  4958. * @work: pointer to work_struct containing our data
  4959. **/
  4960. static void ixgbe_fdir_reinit_task(struct work_struct *work)
  4961. {
  4962. struct ixgbe_adapter *adapter = container_of(work,
  4963. struct ixgbe_adapter,
  4964. fdir_reinit_task);
  4965. struct ixgbe_hw *hw = &adapter->hw;
  4966. int i;
  4967. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  4968. for (i = 0; i < adapter->num_tx_queues; i++)
  4969. set_bit(__IXGBE_FDIR_INIT_DONE,
  4970. &(adapter->tx_ring[i]->reinit_state));
  4971. } else {
  4972. e_err(probe, "failed to finish FDIR re-initialization, "
  4973. "ignored adding FDIR ATR filters\n");
  4974. }
  4975. /* Done FDIR Re-initialization, enable transmits */
  4976. netif_tx_start_all_queues(adapter->netdev);
  4977. }
  4978. static DEFINE_MUTEX(ixgbe_watchdog_lock);
  4979. /**
  4980. * ixgbe_watchdog_task - worker thread to bring link up
  4981. * @work: pointer to work_struct containing our data
  4982. **/
  4983. static void ixgbe_watchdog_task(struct work_struct *work)
  4984. {
  4985. struct ixgbe_adapter *adapter = container_of(work,
  4986. struct ixgbe_adapter,
  4987. watchdog_task);
  4988. struct net_device *netdev = adapter->netdev;
  4989. struct ixgbe_hw *hw = &adapter->hw;
  4990. u32 link_speed;
  4991. bool link_up;
  4992. int i;
  4993. struct ixgbe_ring *tx_ring;
  4994. int some_tx_pending = 0;
  4995. mutex_lock(&ixgbe_watchdog_lock);
  4996. link_up = adapter->link_up;
  4997. link_speed = adapter->link_speed;
  4998. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
  4999. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  5000. if (link_up) {
  5001. #ifdef CONFIG_DCB
  5002. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5003. for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
  5004. hw->mac.ops.fc_enable(hw, i);
  5005. } else {
  5006. hw->mac.ops.fc_enable(hw, 0);
  5007. }
  5008. #else
  5009. hw->mac.ops.fc_enable(hw, 0);
  5010. #endif
  5011. }
  5012. if (link_up ||
  5013. time_after(jiffies, (adapter->link_check_timeout +
  5014. IXGBE_TRY_LINK_TIMEOUT))) {
  5015. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  5016. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  5017. }
  5018. adapter->link_up = link_up;
  5019. adapter->link_speed = link_speed;
  5020. }
  5021. if (link_up) {
  5022. if (!netif_carrier_ok(netdev)) {
  5023. bool flow_rx, flow_tx;
  5024. if (hw->mac.type == ixgbe_mac_82599EB) {
  5025. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  5026. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  5027. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  5028. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  5029. } else {
  5030. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5031. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  5032. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  5033. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  5034. }
  5035. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
  5036. (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
  5037. "10 Gbps" :
  5038. (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
  5039. "1 Gbps" : "unknown speed")),
  5040. ((flow_rx && flow_tx) ? "RX/TX" :
  5041. (flow_rx ? "RX" :
  5042. (flow_tx ? "TX" : "None"))));
  5043. netif_carrier_on(netdev);
  5044. } else {
  5045. /* Force detection of hung controller */
  5046. adapter->detect_tx_hung = true;
  5047. }
  5048. } else {
  5049. adapter->link_up = false;
  5050. adapter->link_speed = 0;
  5051. if (netif_carrier_ok(netdev)) {
  5052. e_info(drv, "NIC Link is Down\n");
  5053. netif_carrier_off(netdev);
  5054. }
  5055. }
  5056. if (!netif_carrier_ok(netdev)) {
  5057. for (i = 0; i < adapter->num_tx_queues; i++) {
  5058. tx_ring = adapter->tx_ring[i];
  5059. if (tx_ring->next_to_use != tx_ring->next_to_clean) {
  5060. some_tx_pending = 1;
  5061. break;
  5062. }
  5063. }
  5064. if (some_tx_pending) {
  5065. /* We've lost link, so the controller stops DMA,
  5066. * but we've got queued Tx work that's never going
  5067. * to get done, so reset controller to flush Tx.
  5068. * (Do the reset outside of interrupt context).
  5069. */
  5070. schedule_work(&adapter->reset_task);
  5071. }
  5072. }
  5073. ixgbe_update_stats(adapter);
  5074. mutex_unlock(&ixgbe_watchdog_lock);
  5075. }
  5076. static int ixgbe_tso(struct ixgbe_adapter *adapter,
  5077. struct ixgbe_ring *tx_ring, struct sk_buff *skb,
  5078. u32 tx_flags, u8 *hdr_len, __be16 protocol)
  5079. {
  5080. struct ixgbe_adv_tx_context_desc *context_desc;
  5081. unsigned int i;
  5082. int err;
  5083. struct ixgbe_tx_buffer *tx_buffer_info;
  5084. u32 vlan_macip_lens = 0, type_tucmd_mlhl;
  5085. u32 mss_l4len_idx, l4len;
  5086. if (skb_is_gso(skb)) {
  5087. if (skb_header_cloned(skb)) {
  5088. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  5089. if (err)
  5090. return err;
  5091. }
  5092. l4len = tcp_hdrlen(skb);
  5093. *hdr_len += l4len;
  5094. if (protocol == htons(ETH_P_IP)) {
  5095. struct iphdr *iph = ip_hdr(skb);
  5096. iph->tot_len = 0;
  5097. iph->check = 0;
  5098. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  5099. iph->daddr, 0,
  5100. IPPROTO_TCP,
  5101. 0);
  5102. } else if (skb_is_gso_v6(skb)) {
  5103. ipv6_hdr(skb)->payload_len = 0;
  5104. tcp_hdr(skb)->check =
  5105. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  5106. &ipv6_hdr(skb)->daddr,
  5107. 0, IPPROTO_TCP, 0);
  5108. }
  5109. i = tx_ring->next_to_use;
  5110. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5111. context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
  5112. /* VLAN MACLEN IPLEN */
  5113. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  5114. vlan_macip_lens |=
  5115. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  5116. vlan_macip_lens |= ((skb_network_offset(skb)) <<
  5117. IXGBE_ADVTXD_MACLEN_SHIFT);
  5118. *hdr_len += skb_network_offset(skb);
  5119. vlan_macip_lens |=
  5120. (skb_transport_header(skb) - skb_network_header(skb));
  5121. *hdr_len +=
  5122. (skb_transport_header(skb) - skb_network_header(skb));
  5123. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  5124. context_desc->seqnum_seed = 0;
  5125. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  5126. type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
  5127. IXGBE_ADVTXD_DTYP_CTXT);
  5128. if (protocol == htons(ETH_P_IP))
  5129. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
  5130. type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5131. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  5132. /* MSS L4LEN IDX */
  5133. mss_l4len_idx =
  5134. (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
  5135. mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
  5136. /* use index 1 for TSO */
  5137. mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  5138. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  5139. tx_buffer_info->time_stamp = jiffies;
  5140. tx_buffer_info->next_to_watch = i;
  5141. i++;
  5142. if (i == tx_ring->count)
  5143. i = 0;
  5144. tx_ring->next_to_use = i;
  5145. return true;
  5146. }
  5147. return false;
  5148. }
  5149. static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
  5150. __be16 protocol)
  5151. {
  5152. u32 rtn = 0;
  5153. switch (protocol) {
  5154. case cpu_to_be16(ETH_P_IP):
  5155. rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
  5156. switch (ip_hdr(skb)->protocol) {
  5157. case IPPROTO_TCP:
  5158. rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5159. break;
  5160. case IPPROTO_SCTP:
  5161. rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  5162. break;
  5163. }
  5164. break;
  5165. case cpu_to_be16(ETH_P_IPV6):
  5166. /* XXX what about other V6 headers?? */
  5167. switch (ipv6_hdr(skb)->nexthdr) {
  5168. case IPPROTO_TCP:
  5169. rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5170. break;
  5171. case IPPROTO_SCTP:
  5172. rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  5173. break;
  5174. }
  5175. break;
  5176. default:
  5177. if (unlikely(net_ratelimit()))
  5178. e_warn(probe, "partial checksum but proto=%x!\n",
  5179. protocol);
  5180. break;
  5181. }
  5182. return rtn;
  5183. }
  5184. static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
  5185. struct ixgbe_ring *tx_ring,
  5186. struct sk_buff *skb, u32 tx_flags,
  5187. __be16 protocol)
  5188. {
  5189. struct ixgbe_adv_tx_context_desc *context_desc;
  5190. unsigned int i;
  5191. struct ixgbe_tx_buffer *tx_buffer_info;
  5192. u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
  5193. if (skb->ip_summed == CHECKSUM_PARTIAL ||
  5194. (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
  5195. i = tx_ring->next_to_use;
  5196. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5197. context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
  5198. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  5199. vlan_macip_lens |=
  5200. (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
  5201. vlan_macip_lens |= (skb_network_offset(skb) <<
  5202. IXGBE_ADVTXD_MACLEN_SHIFT);
  5203. if (skb->ip_summed == CHECKSUM_PARTIAL)
  5204. vlan_macip_lens |= (skb_transport_header(skb) -
  5205. skb_network_header(skb));
  5206. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  5207. context_desc->seqnum_seed = 0;
  5208. type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
  5209. IXGBE_ADVTXD_DTYP_CTXT);
  5210. if (skb->ip_summed == CHECKSUM_PARTIAL)
  5211. type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
  5212. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
  5213. /* use index zero for tx checksum offload */
  5214. context_desc->mss_l4len_idx = 0;
  5215. tx_buffer_info->time_stamp = jiffies;
  5216. tx_buffer_info->next_to_watch = i;
  5217. i++;
  5218. if (i == tx_ring->count)
  5219. i = 0;
  5220. tx_ring->next_to_use = i;
  5221. return true;
  5222. }
  5223. return false;
  5224. }
  5225. static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
  5226. struct ixgbe_ring *tx_ring,
  5227. struct sk_buff *skb, u32 tx_flags,
  5228. unsigned int first)
  5229. {
  5230. struct pci_dev *pdev = adapter->pdev;
  5231. struct ixgbe_tx_buffer *tx_buffer_info;
  5232. unsigned int len;
  5233. unsigned int total = skb->len;
  5234. unsigned int offset = 0, size, count = 0, i;
  5235. unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
  5236. unsigned int f;
  5237. i = tx_ring->next_to_use;
  5238. if (tx_flags & IXGBE_TX_FLAGS_FCOE)
  5239. /* excluding fcoe_crc_eof for FCoE */
  5240. total -= sizeof(struct fcoe_crc_eof);
  5241. len = min(skb_headlen(skb), total);
  5242. while (len) {
  5243. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5244. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  5245. tx_buffer_info->length = size;
  5246. tx_buffer_info->mapped_as_page = false;
  5247. tx_buffer_info->dma = dma_map_single(&pdev->dev,
  5248. skb->data + offset,
  5249. size, DMA_TO_DEVICE);
  5250. if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma))
  5251. goto dma_error;
  5252. tx_buffer_info->time_stamp = jiffies;
  5253. tx_buffer_info->next_to_watch = i;
  5254. len -= size;
  5255. total -= size;
  5256. offset += size;
  5257. count++;
  5258. if (len) {
  5259. i++;
  5260. if (i == tx_ring->count)
  5261. i = 0;
  5262. }
  5263. }
  5264. for (f = 0; f < nr_frags; f++) {
  5265. struct skb_frag_struct *frag;
  5266. frag = &skb_shinfo(skb)->frags[f];
  5267. len = min((unsigned int)frag->size, total);
  5268. offset = frag->page_offset;
  5269. while (len) {
  5270. i++;
  5271. if (i == tx_ring->count)
  5272. i = 0;
  5273. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5274. size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
  5275. tx_buffer_info->length = size;
  5276. tx_buffer_info->dma = dma_map_page(&adapter->pdev->dev,
  5277. frag->page,
  5278. offset, size,
  5279. DMA_TO_DEVICE);
  5280. tx_buffer_info->mapped_as_page = true;
  5281. if (dma_mapping_error(&pdev->dev, tx_buffer_info->dma))
  5282. goto dma_error;
  5283. tx_buffer_info->time_stamp = jiffies;
  5284. tx_buffer_info->next_to_watch = i;
  5285. len -= size;
  5286. total -= size;
  5287. offset += size;
  5288. count++;
  5289. }
  5290. if (total == 0)
  5291. break;
  5292. }
  5293. tx_ring->tx_buffer_info[i].skb = skb;
  5294. tx_ring->tx_buffer_info[first].next_to_watch = i;
  5295. return count;
  5296. dma_error:
  5297. e_dev_err("TX DMA map failed\n");
  5298. /* clear timestamp and dma mappings for failed tx_buffer_info map */
  5299. tx_buffer_info->dma = 0;
  5300. tx_buffer_info->time_stamp = 0;
  5301. tx_buffer_info->next_to_watch = 0;
  5302. if (count)
  5303. count--;
  5304. /* clear timestamp and dma mappings for remaining portion of packet */
  5305. while (count--) {
  5306. if (i == 0)
  5307. i += tx_ring->count;
  5308. i--;
  5309. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5310. ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info);
  5311. }
  5312. return 0;
  5313. }
  5314. static void ixgbe_tx_queue(struct ixgbe_adapter *adapter,
  5315. struct ixgbe_ring *tx_ring,
  5316. int tx_flags, int count, u32 paylen, u8 hdr_len)
  5317. {
  5318. union ixgbe_adv_tx_desc *tx_desc = NULL;
  5319. struct ixgbe_tx_buffer *tx_buffer_info;
  5320. u32 olinfo_status = 0, cmd_type_len = 0;
  5321. unsigned int i;
  5322. u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
  5323. cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
  5324. cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
  5325. if (tx_flags & IXGBE_TX_FLAGS_VLAN)
  5326. cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
  5327. if (tx_flags & IXGBE_TX_FLAGS_TSO) {
  5328. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  5329. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  5330. IXGBE_ADVTXD_POPTS_SHIFT;
  5331. /* use index 1 context for tso */
  5332. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  5333. if (tx_flags & IXGBE_TX_FLAGS_IPV4)
  5334. olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
  5335. IXGBE_ADVTXD_POPTS_SHIFT;
  5336. } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
  5337. olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
  5338. IXGBE_ADVTXD_POPTS_SHIFT;
  5339. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  5340. olinfo_status |= IXGBE_ADVTXD_CC;
  5341. olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
  5342. if (tx_flags & IXGBE_TX_FLAGS_FSO)
  5343. cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
  5344. }
  5345. olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
  5346. i = tx_ring->next_to_use;
  5347. while (count--) {
  5348. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  5349. tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
  5350. tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
  5351. tx_desc->read.cmd_type_len =
  5352. cpu_to_le32(cmd_type_len | tx_buffer_info->length);
  5353. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  5354. i++;
  5355. if (i == tx_ring->count)
  5356. i = 0;
  5357. }
  5358. tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
  5359. /*
  5360. * Force memory writes to complete before letting h/w
  5361. * know there are new descriptors to fetch. (Only
  5362. * applicable for weak-ordered memory model archs,
  5363. * such as IA-64).
  5364. */
  5365. wmb();
  5366. tx_ring->next_to_use = i;
  5367. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  5368. }
  5369. static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb,
  5370. int queue, u32 tx_flags, __be16 protocol)
  5371. {
  5372. struct ixgbe_atr_input atr_input;
  5373. struct tcphdr *th;
  5374. struct iphdr *iph = ip_hdr(skb);
  5375. struct ethhdr *eth = (struct ethhdr *)skb->data;
  5376. u16 vlan_id, src_port, dst_port, flex_bytes;
  5377. u32 src_ipv4_addr, dst_ipv4_addr;
  5378. u8 l4type = 0;
  5379. /* Right now, we support IPv4 only */
  5380. if (protocol != htons(ETH_P_IP))
  5381. return;
  5382. /* check if we're UDP or TCP */
  5383. if (iph->protocol == IPPROTO_TCP) {
  5384. th = tcp_hdr(skb);
  5385. src_port = th->source;
  5386. dst_port = th->dest;
  5387. l4type |= IXGBE_ATR_L4TYPE_TCP;
  5388. /* l4type IPv4 type is 0, no need to assign */
  5389. } else {
  5390. /* Unsupported L4 header, just bail here */
  5391. return;
  5392. }
  5393. memset(&atr_input, 0, sizeof(struct ixgbe_atr_input));
  5394. vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >>
  5395. IXGBE_TX_FLAGS_VLAN_SHIFT;
  5396. src_ipv4_addr = iph->saddr;
  5397. dst_ipv4_addr = iph->daddr;
  5398. flex_bytes = eth->h_proto;
  5399. ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id);
  5400. ixgbe_atr_set_src_port_82599(&atr_input, dst_port);
  5401. ixgbe_atr_set_dst_port_82599(&atr_input, src_port);
  5402. ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes);
  5403. ixgbe_atr_set_l4type_82599(&atr_input, l4type);
  5404. /* src and dst are inverted, think how the receiver sees them */
  5405. ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr);
  5406. ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr);
  5407. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  5408. ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue);
  5409. }
  5410. static int __ixgbe_maybe_stop_tx(struct net_device *netdev,
  5411. struct ixgbe_ring *tx_ring, int size)
  5412. {
  5413. netif_stop_subqueue(netdev, tx_ring->queue_index);
  5414. /* Herbert's original patch had:
  5415. * smp_mb__after_netif_stop_queue();
  5416. * but since that doesn't exist yet, just open code it. */
  5417. smp_mb();
  5418. /* We need to check again in a case another CPU has just
  5419. * made room available. */
  5420. if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
  5421. return -EBUSY;
  5422. /* A reprieve! - use start_queue because it doesn't call schedule */
  5423. netif_start_subqueue(netdev, tx_ring->queue_index);
  5424. ++tx_ring->restart_queue;
  5425. return 0;
  5426. }
  5427. static int ixgbe_maybe_stop_tx(struct net_device *netdev,
  5428. struct ixgbe_ring *tx_ring, int size)
  5429. {
  5430. if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
  5431. return 0;
  5432. return __ixgbe_maybe_stop_tx(netdev, tx_ring, size);
  5433. }
  5434. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
  5435. {
  5436. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5437. int txq = smp_processor_id();
  5438. #ifdef IXGBE_FCOE
  5439. __be16 protocol;
  5440. protocol = vlan_get_protocol(skb);
  5441. if ((protocol == htons(ETH_P_FCOE)) ||
  5442. (protocol == htons(ETH_P_FIP))) {
  5443. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  5444. txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
  5445. txq += adapter->ring_feature[RING_F_FCOE].mask;
  5446. return txq;
  5447. #ifdef CONFIG_IXGBE_DCB
  5448. } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5449. txq = adapter->fcoe.up;
  5450. return txq;
  5451. #endif
  5452. }
  5453. }
  5454. #endif
  5455. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  5456. while (unlikely(txq >= dev->real_num_tx_queues))
  5457. txq -= dev->real_num_tx_queues;
  5458. return txq;
  5459. }
  5460. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5461. if (skb->priority == TC_PRIO_CONTROL)
  5462. txq = adapter->ring_feature[RING_F_DCB].indices-1;
  5463. else
  5464. txq = (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK)
  5465. >> 13;
  5466. return txq;
  5467. }
  5468. return skb_tx_hash(dev, skb);
  5469. }
  5470. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, struct net_device *netdev,
  5471. struct ixgbe_adapter *adapter,
  5472. struct ixgbe_ring *tx_ring)
  5473. {
  5474. struct netdev_queue *txq;
  5475. unsigned int first;
  5476. unsigned int tx_flags = 0;
  5477. u8 hdr_len = 0;
  5478. int tso;
  5479. int count = 0;
  5480. unsigned int f;
  5481. __be16 protocol;
  5482. protocol = vlan_get_protocol(skb);
  5483. if (vlan_tx_tag_present(skb)) {
  5484. tx_flags |= vlan_tx_tag_get(skb);
  5485. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5486. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  5487. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  5488. }
  5489. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  5490. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  5491. } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
  5492. skb->priority != TC_PRIO_CONTROL) {
  5493. tx_flags |= ((skb->queue_mapping & 0x7) << 13);
  5494. tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
  5495. tx_flags |= IXGBE_TX_FLAGS_VLAN;
  5496. }
  5497. #ifdef IXGBE_FCOE
  5498. /* for FCoE with DCB, we force the priority to what
  5499. * was specified by the switch */
  5500. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
  5501. (protocol == htons(ETH_P_FCOE) ||
  5502. protocol == htons(ETH_P_FIP))) {
  5503. #ifdef CONFIG_IXGBE_DCB
  5504. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
  5505. tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK
  5506. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  5507. tx_flags |= ((adapter->fcoe.up << 13)
  5508. << IXGBE_TX_FLAGS_VLAN_SHIFT);
  5509. }
  5510. #endif
  5511. /* flag for FCoE offloads */
  5512. if (protocol == htons(ETH_P_FCOE))
  5513. tx_flags |= IXGBE_TX_FLAGS_FCOE;
  5514. }
  5515. #endif
  5516. /* four things can cause us to need a context descriptor */
  5517. if (skb_is_gso(skb) ||
  5518. (skb->ip_summed == CHECKSUM_PARTIAL) ||
  5519. (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
  5520. (tx_flags & IXGBE_TX_FLAGS_FCOE))
  5521. count++;
  5522. count += TXD_USE_COUNT(skb_headlen(skb));
  5523. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  5524. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  5525. if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) {
  5526. adapter->tx_busy++;
  5527. return NETDEV_TX_BUSY;
  5528. }
  5529. first = tx_ring->next_to_use;
  5530. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  5531. #ifdef IXGBE_FCOE
  5532. /* setup tx offload for FCoE */
  5533. tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
  5534. if (tso < 0) {
  5535. dev_kfree_skb_any(skb);
  5536. return NETDEV_TX_OK;
  5537. }
  5538. if (tso)
  5539. tx_flags |= IXGBE_TX_FLAGS_FSO;
  5540. #endif /* IXGBE_FCOE */
  5541. } else {
  5542. if (protocol == htons(ETH_P_IP))
  5543. tx_flags |= IXGBE_TX_FLAGS_IPV4;
  5544. tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
  5545. protocol);
  5546. if (tso < 0) {
  5547. dev_kfree_skb_any(skb);
  5548. return NETDEV_TX_OK;
  5549. }
  5550. if (tso)
  5551. tx_flags |= IXGBE_TX_FLAGS_TSO;
  5552. else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
  5553. protocol) &&
  5554. (skb->ip_summed == CHECKSUM_PARTIAL))
  5555. tx_flags |= IXGBE_TX_FLAGS_CSUM;
  5556. }
  5557. count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first);
  5558. if (count) {
  5559. /* add the ATR filter if ATR is on */
  5560. if (tx_ring->atr_sample_rate) {
  5561. ++tx_ring->atr_count;
  5562. if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) &&
  5563. test_bit(__IXGBE_FDIR_INIT_DONE,
  5564. &tx_ring->reinit_state)) {
  5565. ixgbe_atr(adapter, skb, tx_ring->queue_index,
  5566. tx_flags, protocol);
  5567. tx_ring->atr_count = 0;
  5568. }
  5569. }
  5570. txq = netdev_get_tx_queue(netdev, tx_ring->queue_index);
  5571. txq->tx_bytes += skb->len;
  5572. txq->tx_packets++;
  5573. ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len,
  5574. hdr_len);
  5575. ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED);
  5576. } else {
  5577. dev_kfree_skb_any(skb);
  5578. tx_ring->tx_buffer_info[first].time_stamp = 0;
  5579. tx_ring->next_to_use = first;
  5580. }
  5581. return NETDEV_TX_OK;
  5582. }
  5583. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  5584. {
  5585. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5586. struct ixgbe_ring *tx_ring;
  5587. tx_ring = adapter->tx_ring[skb->queue_mapping];
  5588. return ixgbe_xmit_frame_ring(skb, netdev, adapter, tx_ring);
  5589. }
  5590. /**
  5591. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  5592. * @netdev: network interface device structure
  5593. * @p: pointer to an address structure
  5594. *
  5595. * Returns 0 on success, negative on failure
  5596. **/
  5597. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  5598. {
  5599. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5600. struct ixgbe_hw *hw = &adapter->hw;
  5601. struct sockaddr *addr = p;
  5602. if (!is_valid_ether_addr(addr->sa_data))
  5603. return -EADDRNOTAVAIL;
  5604. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  5605. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  5606. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
  5607. IXGBE_RAH_AV);
  5608. return 0;
  5609. }
  5610. static int
  5611. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  5612. {
  5613. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5614. struct ixgbe_hw *hw = &adapter->hw;
  5615. u16 value;
  5616. int rc;
  5617. if (prtad != hw->phy.mdio.prtad)
  5618. return -EINVAL;
  5619. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  5620. if (!rc)
  5621. rc = value;
  5622. return rc;
  5623. }
  5624. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  5625. u16 addr, u16 value)
  5626. {
  5627. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5628. struct ixgbe_hw *hw = &adapter->hw;
  5629. if (prtad != hw->phy.mdio.prtad)
  5630. return -EINVAL;
  5631. return hw->phy.ops.write_reg(hw, addr, devad, value);
  5632. }
  5633. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  5634. {
  5635. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5636. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  5637. }
  5638. /**
  5639. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  5640. * netdev->dev_addrs
  5641. * @netdev: network interface device structure
  5642. *
  5643. * Returns non-zero on failure
  5644. **/
  5645. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  5646. {
  5647. int err = 0;
  5648. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5649. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  5650. if (is_valid_ether_addr(mac->san_addr)) {
  5651. rtnl_lock();
  5652. err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  5653. rtnl_unlock();
  5654. }
  5655. return err;
  5656. }
  5657. /**
  5658. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  5659. * netdev->dev_addrs
  5660. * @netdev: network interface device structure
  5661. *
  5662. * Returns non-zero on failure
  5663. **/
  5664. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  5665. {
  5666. int err = 0;
  5667. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5668. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  5669. if (is_valid_ether_addr(mac->san_addr)) {
  5670. rtnl_lock();
  5671. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  5672. rtnl_unlock();
  5673. }
  5674. return err;
  5675. }
  5676. #ifdef CONFIG_NET_POLL_CONTROLLER
  5677. /*
  5678. * Polling 'interrupt' - used by things like netconsole to send skbs
  5679. * without having to re-enable interrupts. It's not called while
  5680. * the interrupt routine is executing.
  5681. */
  5682. static void ixgbe_netpoll(struct net_device *netdev)
  5683. {
  5684. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5685. int i;
  5686. /* if interface is down do nothing */
  5687. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5688. return;
  5689. adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
  5690. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  5691. int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
  5692. for (i = 0; i < num_q_vectors; i++) {
  5693. struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
  5694. ixgbe_msix_clean_many(0, q_vector);
  5695. }
  5696. } else {
  5697. ixgbe_intr(adapter->pdev->irq, netdev);
  5698. }
  5699. adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
  5700. }
  5701. #endif
  5702. static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
  5703. struct rtnl_link_stats64 *stats)
  5704. {
  5705. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5706. int i;
  5707. /* accurate rx/tx bytes/packets stats */
  5708. dev_txq_stats_fold(netdev, stats);
  5709. rcu_read_lock();
  5710. for (i = 0; i < adapter->num_rx_queues; i++) {
  5711. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
  5712. u64 bytes, packets;
  5713. unsigned int start;
  5714. if (ring) {
  5715. do {
  5716. start = u64_stats_fetch_begin_bh(&ring->syncp);
  5717. packets = ring->stats.packets;
  5718. bytes = ring->stats.bytes;
  5719. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  5720. stats->rx_packets += packets;
  5721. stats->rx_bytes += bytes;
  5722. }
  5723. }
  5724. rcu_read_unlock();
  5725. /* following stats updated by ixgbe_watchdog_task() */
  5726. stats->multicast = netdev->stats.multicast;
  5727. stats->rx_errors = netdev->stats.rx_errors;
  5728. stats->rx_length_errors = netdev->stats.rx_length_errors;
  5729. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  5730. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  5731. return stats;
  5732. }
  5733. static const struct net_device_ops ixgbe_netdev_ops = {
  5734. .ndo_open = ixgbe_open,
  5735. .ndo_stop = ixgbe_close,
  5736. .ndo_start_xmit = ixgbe_xmit_frame,
  5737. .ndo_select_queue = ixgbe_select_queue,
  5738. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  5739. .ndo_set_multicast_list = ixgbe_set_rx_mode,
  5740. .ndo_validate_addr = eth_validate_addr,
  5741. .ndo_set_mac_address = ixgbe_set_mac,
  5742. .ndo_change_mtu = ixgbe_change_mtu,
  5743. .ndo_tx_timeout = ixgbe_tx_timeout,
  5744. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  5745. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  5746. .ndo_do_ioctl = ixgbe_ioctl,
  5747. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  5748. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  5749. .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
  5750. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  5751. .ndo_get_stats64 = ixgbe_get_stats64,
  5752. #ifdef CONFIG_NET_POLL_CONTROLLER
  5753. .ndo_poll_controller = ixgbe_netpoll,
  5754. #endif
  5755. #ifdef IXGBE_FCOE
  5756. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  5757. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  5758. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  5759. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  5760. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  5761. #endif /* IXGBE_FCOE */
  5762. };
  5763. static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
  5764. const struct ixgbe_info *ii)
  5765. {
  5766. #ifdef CONFIG_PCI_IOV
  5767. struct ixgbe_hw *hw = &adapter->hw;
  5768. int err;
  5769. if (hw->mac.type != ixgbe_mac_82599EB || !max_vfs)
  5770. return;
  5771. /* The 82599 supports up to 64 VFs per physical function
  5772. * but this implementation limits allocation to 63 so that
  5773. * basic networking resources are still available to the
  5774. * physical function
  5775. */
  5776. adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
  5777. adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
  5778. err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
  5779. if (err) {
  5780. e_err(probe, "Failed to enable PCI sriov: %d\n", err);
  5781. goto err_novfs;
  5782. }
  5783. /* If call to enable VFs succeeded then allocate memory
  5784. * for per VF control structures.
  5785. */
  5786. adapter->vfinfo =
  5787. kcalloc(adapter->num_vfs,
  5788. sizeof(struct vf_data_storage), GFP_KERNEL);
  5789. if (adapter->vfinfo) {
  5790. /* Now that we're sure SR-IOV is enabled
  5791. * and memory allocated set up the mailbox parameters
  5792. */
  5793. ixgbe_init_mbx_params_pf(hw);
  5794. memcpy(&hw->mbx.ops, ii->mbx_ops,
  5795. sizeof(hw->mbx.ops));
  5796. /* Disable RSC when in SR-IOV mode */
  5797. adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
  5798. IXGBE_FLAG2_RSC_ENABLED);
  5799. return;
  5800. }
  5801. /* Oh oh */
  5802. e_err(probe, "Unable to allocate memory for VF Data Storage - "
  5803. "SRIOV disabled\n");
  5804. pci_disable_sriov(adapter->pdev);
  5805. err_novfs:
  5806. adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
  5807. adapter->num_vfs = 0;
  5808. #endif /* CONFIG_PCI_IOV */
  5809. }
  5810. /**
  5811. * ixgbe_probe - Device Initialization Routine
  5812. * @pdev: PCI device information struct
  5813. * @ent: entry in ixgbe_pci_tbl
  5814. *
  5815. * Returns 0 on success, negative on failure
  5816. *
  5817. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  5818. * The OS initialization, configuring of the adapter private structure,
  5819. * and a hardware reset occur.
  5820. **/
  5821. static int __devinit ixgbe_probe(struct pci_dev *pdev,
  5822. const struct pci_device_id *ent)
  5823. {
  5824. struct net_device *netdev;
  5825. struct ixgbe_adapter *adapter = NULL;
  5826. struct ixgbe_hw *hw;
  5827. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  5828. static int cards_found;
  5829. int i, err, pci_using_dac;
  5830. unsigned int indices = num_possible_cpus();
  5831. #ifdef IXGBE_FCOE
  5832. u16 device_caps;
  5833. #endif
  5834. u32 part_num, eec;
  5835. /* Catch broken hardware that put the wrong VF device ID in
  5836. * the PCIe SR-IOV capability.
  5837. */
  5838. if (pdev->is_virtfn) {
  5839. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  5840. pci_name(pdev), pdev->vendor, pdev->device);
  5841. return -EINVAL;
  5842. }
  5843. err = pci_enable_device_mem(pdev);
  5844. if (err)
  5845. return err;
  5846. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
  5847. !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  5848. pci_using_dac = 1;
  5849. } else {
  5850. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  5851. if (err) {
  5852. err = dma_set_coherent_mask(&pdev->dev,
  5853. DMA_BIT_MASK(32));
  5854. if (err) {
  5855. dev_err(&pdev->dev,
  5856. "No usable DMA configuration, aborting\n");
  5857. goto err_dma;
  5858. }
  5859. }
  5860. pci_using_dac = 0;
  5861. }
  5862. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  5863. IORESOURCE_MEM), ixgbe_driver_name);
  5864. if (err) {
  5865. dev_err(&pdev->dev,
  5866. "pci_request_selected_regions failed 0x%x\n", err);
  5867. goto err_pci_reg;
  5868. }
  5869. pci_enable_pcie_error_reporting(pdev);
  5870. pci_set_master(pdev);
  5871. pci_save_state(pdev);
  5872. if (ii->mac == ixgbe_mac_82598EB)
  5873. indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
  5874. else
  5875. indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
  5876. indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
  5877. #ifdef IXGBE_FCOE
  5878. indices += min_t(unsigned int, num_possible_cpus(),
  5879. IXGBE_MAX_FCOE_INDICES);
  5880. #endif
  5881. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  5882. if (!netdev) {
  5883. err = -ENOMEM;
  5884. goto err_alloc_etherdev;
  5885. }
  5886. SET_NETDEV_DEV(netdev, &pdev->dev);
  5887. pci_set_drvdata(pdev, netdev);
  5888. adapter = netdev_priv(netdev);
  5889. adapter->netdev = netdev;
  5890. adapter->pdev = pdev;
  5891. hw = &adapter->hw;
  5892. hw->back = adapter;
  5893. adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
  5894. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  5895. pci_resource_len(pdev, 0));
  5896. if (!hw->hw_addr) {
  5897. err = -EIO;
  5898. goto err_ioremap;
  5899. }
  5900. for (i = 1; i <= 5; i++) {
  5901. if (pci_resource_len(pdev, i) == 0)
  5902. continue;
  5903. }
  5904. netdev->netdev_ops = &ixgbe_netdev_ops;
  5905. ixgbe_set_ethtool_ops(netdev);
  5906. netdev->watchdog_timeo = 5 * HZ;
  5907. strcpy(netdev->name, pci_name(pdev));
  5908. adapter->bd_number = cards_found;
  5909. /* Setup hw api */
  5910. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  5911. hw->mac.type = ii->mac;
  5912. /* EEPROM */
  5913. memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
  5914. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  5915. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  5916. if (!(eec & (1 << 8)))
  5917. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  5918. /* PHY */
  5919. memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
  5920. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  5921. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  5922. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  5923. hw->phy.mdio.mmds = 0;
  5924. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  5925. hw->phy.mdio.dev = netdev;
  5926. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  5927. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  5928. /* set up this timer and work struct before calling get_invariants
  5929. * which might start the timer
  5930. */
  5931. init_timer(&adapter->sfp_timer);
  5932. adapter->sfp_timer.function = ixgbe_sfp_timer;
  5933. adapter->sfp_timer.data = (unsigned long) adapter;
  5934. INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
  5935. /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
  5936. INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
  5937. /* a new SFP+ module arrival, called from GPI SDP2 context */
  5938. INIT_WORK(&adapter->sfp_config_module_task,
  5939. ixgbe_sfp_config_module_task);
  5940. ii->get_invariants(hw);
  5941. /* setup the private structure */
  5942. err = ixgbe_sw_init(adapter);
  5943. if (err)
  5944. goto err_sw_init;
  5945. /* Make it possible the adapter to be woken up via WOL */
  5946. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  5947. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5948. /*
  5949. * If there is a fan on this device and it has failed log the
  5950. * failure.
  5951. */
  5952. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  5953. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  5954. if (esdp & IXGBE_ESDP_SDP1)
  5955. e_crit(probe, "Fan has stopped, replace the adapter\n");
  5956. }
  5957. /* reset_hw fills in the perm_addr as well */
  5958. hw->phy.reset_if_overtemp = true;
  5959. err = hw->mac.ops.reset_hw(hw);
  5960. hw->phy.reset_if_overtemp = false;
  5961. if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
  5962. hw->mac.type == ixgbe_mac_82598EB) {
  5963. /*
  5964. * Start a kernel thread to watch for a module to arrive.
  5965. * Only do this for 82598, since 82599 will generate
  5966. * interrupts on module arrival.
  5967. */
  5968. set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  5969. mod_timer(&adapter->sfp_timer,
  5970. round_jiffies(jiffies + (2 * HZ)));
  5971. err = 0;
  5972. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  5973. e_dev_err("failed to initialize because an unsupported SFP+ "
  5974. "module type was detected.\n");
  5975. e_dev_err("Reload the driver after installing a supported "
  5976. "module.\n");
  5977. goto err_sw_init;
  5978. } else if (err) {
  5979. e_dev_err("HW Init failed: %d\n", err);
  5980. goto err_sw_init;
  5981. }
  5982. ixgbe_probe_vf(adapter, ii);
  5983. netdev->features = NETIF_F_SG |
  5984. NETIF_F_IP_CSUM |
  5985. NETIF_F_HW_VLAN_TX |
  5986. NETIF_F_HW_VLAN_RX |
  5987. NETIF_F_HW_VLAN_FILTER;
  5988. netdev->features |= NETIF_F_IPV6_CSUM;
  5989. netdev->features |= NETIF_F_TSO;
  5990. netdev->features |= NETIF_F_TSO6;
  5991. netdev->features |= NETIF_F_GRO;
  5992. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  5993. netdev->features |= NETIF_F_SCTP_CSUM;
  5994. netdev->vlan_features |= NETIF_F_TSO;
  5995. netdev->vlan_features |= NETIF_F_TSO6;
  5996. netdev->vlan_features |= NETIF_F_IP_CSUM;
  5997. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  5998. netdev->vlan_features |= NETIF_F_SG;
  5999. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6000. adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
  6001. IXGBE_FLAG_DCB_ENABLED);
  6002. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  6003. adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
  6004. #ifdef CONFIG_IXGBE_DCB
  6005. netdev->dcbnl_ops = &dcbnl_ops;
  6006. #endif
  6007. #ifdef IXGBE_FCOE
  6008. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  6009. if (hw->mac.ops.get_device_caps) {
  6010. hw->mac.ops.get_device_caps(hw, &device_caps);
  6011. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  6012. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  6013. }
  6014. }
  6015. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  6016. netdev->vlan_features |= NETIF_F_FCOE_CRC;
  6017. netdev->vlan_features |= NETIF_F_FSO;
  6018. netdev->vlan_features |= NETIF_F_FCOE_MTU;
  6019. }
  6020. #endif /* IXGBE_FCOE */
  6021. if (pci_using_dac) {
  6022. netdev->features |= NETIF_F_HIGHDMA;
  6023. netdev->vlan_features |= NETIF_F_HIGHDMA;
  6024. }
  6025. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  6026. netdev->features |= NETIF_F_LRO;
  6027. /* make sure the EEPROM is good */
  6028. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  6029. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  6030. err = -EIO;
  6031. goto err_eeprom;
  6032. }
  6033. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  6034. memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
  6035. if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
  6036. e_dev_err("invalid MAC address\n");
  6037. err = -EIO;
  6038. goto err_eeprom;
  6039. }
  6040. /* power down the optics */
  6041. if (hw->phy.multispeed_fiber)
  6042. hw->mac.ops.disable_tx_laser(hw);
  6043. init_timer(&adapter->watchdog_timer);
  6044. adapter->watchdog_timer.function = ixgbe_watchdog;
  6045. adapter->watchdog_timer.data = (unsigned long)adapter;
  6046. INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
  6047. INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
  6048. err = ixgbe_init_interrupt_scheme(adapter);
  6049. if (err)
  6050. goto err_sw_init;
  6051. switch (pdev->device) {
  6052. case IXGBE_DEV_ID_82599_KX4:
  6053. adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
  6054. IXGBE_WUFC_MC | IXGBE_WUFC_BC);
  6055. break;
  6056. default:
  6057. adapter->wol = 0;
  6058. break;
  6059. }
  6060. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  6061. /* pick up the PCI bus settings for reporting later */
  6062. hw->mac.ops.get_bus_info(hw);
  6063. /* print bus type/speed/width info */
  6064. e_dev_info("(PCI Express:%s:%s) %pM\n",
  6065. (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0Gb/s" :
  6066. hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5Gb/s" :
  6067. "Unknown"),
  6068. (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
  6069. hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
  6070. hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
  6071. "Unknown"),
  6072. netdev->dev_addr);
  6073. ixgbe_read_pba_num_generic(hw, &part_num);
  6074. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  6075. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, "
  6076. "PBA No: %06x-%03x\n",
  6077. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  6078. (part_num >> 8), (part_num & 0xff));
  6079. else
  6080. e_dev_info("MAC: %d, PHY: %d, PBA No: %06x-%03x\n",
  6081. hw->mac.type, hw->phy.type,
  6082. (part_num >> 8), (part_num & 0xff));
  6083. if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
  6084. e_dev_warn("PCI-Express bandwidth available for this card is "
  6085. "not sufficient for optimal performance.\n");
  6086. e_dev_warn("For optimal performance a x8 PCI-Express slot "
  6087. "is required.\n");
  6088. }
  6089. /* save off EEPROM version number */
  6090. hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
  6091. /* reset the hardware with the new settings */
  6092. err = hw->mac.ops.start_hw(hw);
  6093. if (err == IXGBE_ERR_EEPROM_VERSION) {
  6094. /* We are running on a pre-production device, log a warning */
  6095. e_dev_warn("This device is a pre-production adapter/LOM. "
  6096. "Please be aware there may be issues associated "
  6097. "with your hardware. If you are experiencing "
  6098. "problems please contact your Intel or hardware "
  6099. "representative who provided you with this "
  6100. "hardware.\n");
  6101. }
  6102. strcpy(netdev->name, "eth%d");
  6103. err = register_netdev(netdev);
  6104. if (err)
  6105. goto err_register;
  6106. /* carrier off reporting is important to ethtool even BEFORE open */
  6107. netif_carrier_off(netdev);
  6108. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  6109. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  6110. INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
  6111. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  6112. INIT_WORK(&adapter->check_overtemp_task,
  6113. ixgbe_check_overtemp_task);
  6114. #ifdef CONFIG_IXGBE_DCA
  6115. if (dca_add_requester(&pdev->dev) == 0) {
  6116. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  6117. ixgbe_setup_dca(adapter);
  6118. }
  6119. #endif
  6120. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  6121. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  6122. for (i = 0; i < adapter->num_vfs; i++)
  6123. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  6124. }
  6125. /* add san mac addr to netdev */
  6126. ixgbe_add_sanmac_netdev(netdev);
  6127. e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
  6128. cards_found++;
  6129. return 0;
  6130. err_register:
  6131. ixgbe_release_hw_control(adapter);
  6132. ixgbe_clear_interrupt_scheme(adapter);
  6133. err_sw_init:
  6134. err_eeprom:
  6135. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6136. ixgbe_disable_sriov(adapter);
  6137. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  6138. del_timer_sync(&adapter->sfp_timer);
  6139. cancel_work_sync(&adapter->sfp_task);
  6140. cancel_work_sync(&adapter->multispeed_fiber_task);
  6141. cancel_work_sync(&adapter->sfp_config_module_task);
  6142. iounmap(hw->hw_addr);
  6143. err_ioremap:
  6144. free_netdev(netdev);
  6145. err_alloc_etherdev:
  6146. pci_release_selected_regions(pdev,
  6147. pci_select_bars(pdev, IORESOURCE_MEM));
  6148. err_pci_reg:
  6149. err_dma:
  6150. pci_disable_device(pdev);
  6151. return err;
  6152. }
  6153. /**
  6154. * ixgbe_remove - Device Removal Routine
  6155. * @pdev: PCI device information struct
  6156. *
  6157. * ixgbe_remove is called by the PCI subsystem to alert the driver
  6158. * that it should release a PCI device. The could be caused by a
  6159. * Hot-Plug event, or because the driver is going to be removed from
  6160. * memory.
  6161. **/
  6162. static void __devexit ixgbe_remove(struct pci_dev *pdev)
  6163. {
  6164. struct net_device *netdev = pci_get_drvdata(pdev);
  6165. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6166. set_bit(__IXGBE_DOWN, &adapter->state);
  6167. /* clear the module not found bit to make sure the worker won't
  6168. * reschedule
  6169. */
  6170. clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
  6171. del_timer_sync(&adapter->watchdog_timer);
  6172. del_timer_sync(&adapter->sfp_timer);
  6173. cancel_work_sync(&adapter->watchdog_task);
  6174. cancel_work_sync(&adapter->sfp_task);
  6175. cancel_work_sync(&adapter->multispeed_fiber_task);
  6176. cancel_work_sync(&adapter->sfp_config_module_task);
  6177. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  6178. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  6179. cancel_work_sync(&adapter->fdir_reinit_task);
  6180. flush_scheduled_work();
  6181. #ifdef CONFIG_IXGBE_DCA
  6182. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  6183. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  6184. dca_remove_requester(&pdev->dev);
  6185. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  6186. }
  6187. #endif
  6188. #ifdef IXGBE_FCOE
  6189. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  6190. ixgbe_cleanup_fcoe(adapter);
  6191. #endif /* IXGBE_FCOE */
  6192. /* remove the added san mac */
  6193. ixgbe_del_sanmac_netdev(netdev);
  6194. if (netdev->reg_state == NETREG_REGISTERED)
  6195. unregister_netdev(netdev);
  6196. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  6197. ixgbe_disable_sriov(adapter);
  6198. ixgbe_clear_interrupt_scheme(adapter);
  6199. ixgbe_release_hw_control(adapter);
  6200. iounmap(adapter->hw.hw_addr);
  6201. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  6202. IORESOURCE_MEM));
  6203. e_dev_info("complete\n");
  6204. free_netdev(netdev);
  6205. pci_disable_pcie_error_reporting(pdev);
  6206. pci_disable_device(pdev);
  6207. }
  6208. /**
  6209. * ixgbe_io_error_detected - called when PCI error is detected
  6210. * @pdev: Pointer to PCI device
  6211. * @state: The current pci connection state
  6212. *
  6213. * This function is called after a PCI bus error affecting
  6214. * this device has been detected.
  6215. */
  6216. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  6217. pci_channel_state_t state)
  6218. {
  6219. struct net_device *netdev = pci_get_drvdata(pdev);
  6220. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6221. netif_device_detach(netdev);
  6222. if (state == pci_channel_io_perm_failure)
  6223. return PCI_ERS_RESULT_DISCONNECT;
  6224. if (netif_running(netdev))
  6225. ixgbe_down(adapter);
  6226. pci_disable_device(pdev);
  6227. /* Request a slot reset. */
  6228. return PCI_ERS_RESULT_NEED_RESET;
  6229. }
  6230. /**
  6231. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  6232. * @pdev: Pointer to PCI device
  6233. *
  6234. * Restart the card from scratch, as if from a cold-boot.
  6235. */
  6236. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  6237. {
  6238. struct net_device *netdev = pci_get_drvdata(pdev);
  6239. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6240. pci_ers_result_t result;
  6241. int err;
  6242. if (pci_enable_device_mem(pdev)) {
  6243. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  6244. result = PCI_ERS_RESULT_DISCONNECT;
  6245. } else {
  6246. pci_set_master(pdev);
  6247. pci_restore_state(pdev);
  6248. pci_save_state(pdev);
  6249. pci_wake_from_d3(pdev, false);
  6250. ixgbe_reset(adapter);
  6251. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  6252. result = PCI_ERS_RESULT_RECOVERED;
  6253. }
  6254. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  6255. if (err) {
  6256. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  6257. "failed 0x%0x\n", err);
  6258. /* non-fatal, continue */
  6259. }
  6260. return result;
  6261. }
  6262. /**
  6263. * ixgbe_io_resume - called when traffic can start flowing again.
  6264. * @pdev: Pointer to PCI device
  6265. *
  6266. * This callback is called when the error recovery driver tells us that
  6267. * its OK to resume normal operation.
  6268. */
  6269. static void ixgbe_io_resume(struct pci_dev *pdev)
  6270. {
  6271. struct net_device *netdev = pci_get_drvdata(pdev);
  6272. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  6273. if (netif_running(netdev)) {
  6274. if (ixgbe_up(adapter)) {
  6275. e_info(probe, "ixgbe_up failed after reset\n");
  6276. return;
  6277. }
  6278. }
  6279. netif_device_attach(netdev);
  6280. }
  6281. static struct pci_error_handlers ixgbe_err_handler = {
  6282. .error_detected = ixgbe_io_error_detected,
  6283. .slot_reset = ixgbe_io_slot_reset,
  6284. .resume = ixgbe_io_resume,
  6285. };
  6286. static struct pci_driver ixgbe_driver = {
  6287. .name = ixgbe_driver_name,
  6288. .id_table = ixgbe_pci_tbl,
  6289. .probe = ixgbe_probe,
  6290. .remove = __devexit_p(ixgbe_remove),
  6291. #ifdef CONFIG_PM
  6292. .suspend = ixgbe_suspend,
  6293. .resume = ixgbe_resume,
  6294. #endif
  6295. .shutdown = ixgbe_shutdown,
  6296. .err_handler = &ixgbe_err_handler
  6297. };
  6298. /**
  6299. * ixgbe_init_module - Driver Registration Routine
  6300. *
  6301. * ixgbe_init_module is the first routine called when the driver is
  6302. * loaded. All it does is register with the PCI subsystem.
  6303. **/
  6304. static int __init ixgbe_init_module(void)
  6305. {
  6306. int ret;
  6307. pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
  6308. pr_info("%s\n", ixgbe_copyright);
  6309. #ifdef CONFIG_IXGBE_DCA
  6310. dca_register_notify(&dca_notifier);
  6311. #endif
  6312. ret = pci_register_driver(&ixgbe_driver);
  6313. return ret;
  6314. }
  6315. module_init(ixgbe_init_module);
  6316. /**
  6317. * ixgbe_exit_module - Driver Exit Cleanup Routine
  6318. *
  6319. * ixgbe_exit_module is called just before the driver is removed
  6320. * from memory.
  6321. **/
  6322. static void __exit ixgbe_exit_module(void)
  6323. {
  6324. #ifdef CONFIG_IXGBE_DCA
  6325. dca_unregister_notify(&dca_notifier);
  6326. #endif
  6327. pci_unregister_driver(&ixgbe_driver);
  6328. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  6329. }
  6330. #ifdef CONFIG_IXGBE_DCA
  6331. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  6332. void *p)
  6333. {
  6334. int ret_val;
  6335. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  6336. __ixgbe_notify_dca);
  6337. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  6338. }
  6339. #endif /* CONFIG_IXGBE_DCA */
  6340. /**
  6341. * ixgbe_get_hw_dev return device
  6342. * used by hardware layer to print debugging information
  6343. **/
  6344. struct net_device *ixgbe_get_hw_dev(struct ixgbe_hw *hw)
  6345. {
  6346. struct ixgbe_adapter *adapter = hw->back;
  6347. return adapter->netdev;
  6348. }
  6349. module_exit(ixgbe_exit_module);
  6350. /* ixgbe_main.c */