ixgbe_main.c 172 KB

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