ixgbe_main.c 174 KB

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