ixgbe_main.c 170 KB

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