ixgbe_main.c 187 KB

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