igb_main.c 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-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/module.h>
  21. #include <linux/types.h>
  22. #include <linux/init.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/pagemap.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/ipv6.h>
  27. #include <net/checksum.h>
  28. #include <net/ip6_checksum.h>
  29. #include <linux/net_tstamp.h>
  30. #include <linux/mii.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/if_vlan.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/delay.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/if_ether.h>
  38. #include <linux/aer.h>
  39. #ifdef CONFIG_IGB_DCA
  40. #include <linux/dca.h>
  41. #endif
  42. #include "igb.h"
  43. #define DRV_VERSION "1.3.16-k2"
  44. char igb_driver_name[] = "igb";
  45. char igb_driver_version[] = DRV_VERSION;
  46. static const char igb_driver_string[] =
  47. "Intel(R) Gigabit Ethernet Network Driver";
  48. static const char igb_copyright[] = "Copyright (c) 2007-2009 Intel Corporation.";
  49. static const struct e1000_info *igb_info_tbl[] = {
  50. [board_82575] = &e1000_82575_info,
  51. };
  52. static struct pci_device_id igb_pci_tbl[] = {
  53. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
  54. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
  55. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
  56. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
  57. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
  58. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
  59. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
  60. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
  61. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
  62. /* required last entry */
  63. {0, }
  64. };
  65. MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
  66. void igb_reset(struct igb_adapter *);
  67. static int igb_setup_all_tx_resources(struct igb_adapter *);
  68. static int igb_setup_all_rx_resources(struct igb_adapter *);
  69. static void igb_free_all_tx_resources(struct igb_adapter *);
  70. static void igb_free_all_rx_resources(struct igb_adapter *);
  71. void igb_update_stats(struct igb_adapter *);
  72. static int igb_probe(struct pci_dev *, const struct pci_device_id *);
  73. static void __devexit igb_remove(struct pci_dev *pdev);
  74. static int igb_sw_init(struct igb_adapter *);
  75. static int igb_open(struct net_device *);
  76. static int igb_close(struct net_device *);
  77. static void igb_configure_tx(struct igb_adapter *);
  78. static void igb_configure_rx(struct igb_adapter *);
  79. static void igb_setup_rctl(struct igb_adapter *);
  80. static void igb_clean_all_tx_rings(struct igb_adapter *);
  81. static void igb_clean_all_rx_rings(struct igb_adapter *);
  82. static void igb_clean_tx_ring(struct igb_ring *);
  83. static void igb_clean_rx_ring(struct igb_ring *);
  84. static void igb_set_rx_mode(struct net_device *);
  85. static void igb_update_phy_info(unsigned long);
  86. static void igb_watchdog(unsigned long);
  87. static void igb_watchdog_task(struct work_struct *);
  88. static netdev_tx_t igb_xmit_frame_ring_adv(struct sk_buff *,
  89. struct net_device *,
  90. struct igb_ring *);
  91. static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb,
  92. struct net_device *);
  93. static struct net_device_stats *igb_get_stats(struct net_device *);
  94. static int igb_change_mtu(struct net_device *, int);
  95. static int igb_set_mac(struct net_device *, void *);
  96. static irqreturn_t igb_intr(int irq, void *);
  97. static irqreturn_t igb_intr_msi(int irq, void *);
  98. static irqreturn_t igb_msix_other(int irq, void *);
  99. static irqreturn_t igb_msix_rx(int irq, void *);
  100. static irqreturn_t igb_msix_tx(int irq, void *);
  101. #ifdef CONFIG_IGB_DCA
  102. static void igb_update_rx_dca(struct igb_ring *);
  103. static void igb_update_tx_dca(struct igb_ring *);
  104. static void igb_setup_dca(struct igb_adapter *);
  105. #endif /* CONFIG_IGB_DCA */
  106. static bool igb_clean_tx_irq(struct igb_ring *);
  107. static int igb_poll(struct napi_struct *, int);
  108. static bool igb_clean_rx_irq_adv(struct igb_ring *, int *, int);
  109. static void igb_alloc_rx_buffers_adv(struct igb_ring *, int);
  110. static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
  111. static void igb_tx_timeout(struct net_device *);
  112. static void igb_reset_task(struct work_struct *);
  113. static void igb_vlan_rx_register(struct net_device *, struct vlan_group *);
  114. static void igb_vlan_rx_add_vid(struct net_device *, u16);
  115. static void igb_vlan_rx_kill_vid(struct net_device *, u16);
  116. static void igb_restore_vlan(struct igb_adapter *);
  117. static void igb_ping_all_vfs(struct igb_adapter *);
  118. static void igb_msg_task(struct igb_adapter *);
  119. static int igb_rcv_msg_from_vf(struct igb_adapter *, u32);
  120. static inline void igb_set_rah_pool(struct e1000_hw *, int , int);
  121. static void igb_vmm_control(struct igb_adapter *);
  122. static int igb_set_vf_mac(struct igb_adapter *adapter, int, unsigned char *);
  123. static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
  124. static inline void igb_set_vmolr(struct e1000_hw *hw, int vfn)
  125. {
  126. u32 reg_data;
  127. reg_data = rd32(E1000_VMOLR(vfn));
  128. reg_data |= E1000_VMOLR_BAM | /* Accept broadcast */
  129. E1000_VMOLR_ROPE | /* Accept packets matched in UTA */
  130. E1000_VMOLR_ROMPE | /* Accept packets matched in MTA */
  131. E1000_VMOLR_AUPE | /* Accept untagged packets */
  132. E1000_VMOLR_STRVLAN; /* Strip vlan tags */
  133. wr32(E1000_VMOLR(vfn), reg_data);
  134. }
  135. static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
  136. int vfn)
  137. {
  138. struct e1000_hw *hw = &adapter->hw;
  139. u32 vmolr;
  140. /* if it isn't the PF check to see if VFs are enabled and
  141. * increase the size to support vlan tags */
  142. if (vfn < adapter->vfs_allocated_count &&
  143. adapter->vf_data[vfn].vlans_enabled)
  144. size += VLAN_TAG_SIZE;
  145. vmolr = rd32(E1000_VMOLR(vfn));
  146. vmolr &= ~E1000_VMOLR_RLPML_MASK;
  147. vmolr |= size | E1000_VMOLR_LPE;
  148. wr32(E1000_VMOLR(vfn), vmolr);
  149. return 0;
  150. }
  151. static inline void igb_set_rah_pool(struct e1000_hw *hw, int pool, int entry)
  152. {
  153. u32 reg_data;
  154. reg_data = rd32(E1000_RAH(entry));
  155. reg_data &= ~E1000_RAH_POOL_MASK;
  156. reg_data |= E1000_RAH_POOL_1 << pool;;
  157. wr32(E1000_RAH(entry), reg_data);
  158. }
  159. #ifdef CONFIG_PM
  160. static int igb_suspend(struct pci_dev *, pm_message_t);
  161. static int igb_resume(struct pci_dev *);
  162. #endif
  163. static void igb_shutdown(struct pci_dev *);
  164. #ifdef CONFIG_IGB_DCA
  165. static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
  166. static struct notifier_block dca_notifier = {
  167. .notifier_call = igb_notify_dca,
  168. .next = NULL,
  169. .priority = 0
  170. };
  171. #endif
  172. #ifdef CONFIG_NET_POLL_CONTROLLER
  173. /* for netdump / net console */
  174. static void igb_netpoll(struct net_device *);
  175. #endif
  176. #ifdef CONFIG_PCI_IOV
  177. static unsigned int max_vfs = 0;
  178. module_param(max_vfs, uint, 0);
  179. MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
  180. "per physical function");
  181. #endif /* CONFIG_PCI_IOV */
  182. static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
  183. pci_channel_state_t);
  184. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
  185. static void igb_io_resume(struct pci_dev *);
  186. static struct pci_error_handlers igb_err_handler = {
  187. .error_detected = igb_io_error_detected,
  188. .slot_reset = igb_io_slot_reset,
  189. .resume = igb_io_resume,
  190. };
  191. static struct pci_driver igb_driver = {
  192. .name = igb_driver_name,
  193. .id_table = igb_pci_tbl,
  194. .probe = igb_probe,
  195. .remove = __devexit_p(igb_remove),
  196. #ifdef CONFIG_PM
  197. /* Power Managment Hooks */
  198. .suspend = igb_suspend,
  199. .resume = igb_resume,
  200. #endif
  201. .shutdown = igb_shutdown,
  202. .err_handler = &igb_err_handler
  203. };
  204. static int global_quad_port_a; /* global quad port a indication */
  205. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  206. MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
  207. MODULE_LICENSE("GPL");
  208. MODULE_VERSION(DRV_VERSION);
  209. /**
  210. * Scale the NIC clock cycle by a large factor so that
  211. * relatively small clock corrections can be added or
  212. * substracted at each clock tick. The drawbacks of a
  213. * large factor are a) that the clock register overflows
  214. * more quickly (not such a big deal) and b) that the
  215. * increment per tick has to fit into 24 bits.
  216. *
  217. * Note that
  218. * TIMINCA = IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS *
  219. * IGB_TSYNC_SCALE
  220. * TIMINCA += TIMINCA * adjustment [ppm] / 1e9
  221. *
  222. * The base scale factor is intentionally a power of two
  223. * so that the division in %struct timecounter can be done with
  224. * a shift.
  225. */
  226. #define IGB_TSYNC_SHIFT (19)
  227. #define IGB_TSYNC_SCALE (1<<IGB_TSYNC_SHIFT)
  228. /**
  229. * The duration of one clock cycle of the NIC.
  230. *
  231. * @todo This hard-coded value is part of the specification and might change
  232. * in future hardware revisions. Add revision check.
  233. */
  234. #define IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS 16
  235. #if (IGB_TSYNC_SCALE * IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS) >= (1<<24)
  236. # error IGB_TSYNC_SCALE and/or IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS are too large to fit into TIMINCA
  237. #endif
  238. /**
  239. * igb_read_clock - read raw cycle counter (to be used by time counter)
  240. */
  241. static cycle_t igb_read_clock(const struct cyclecounter *tc)
  242. {
  243. struct igb_adapter *adapter =
  244. container_of(tc, struct igb_adapter, cycles);
  245. struct e1000_hw *hw = &adapter->hw;
  246. u64 stamp;
  247. stamp = rd32(E1000_SYSTIML);
  248. stamp |= (u64)rd32(E1000_SYSTIMH) << 32ULL;
  249. return stamp;
  250. }
  251. #ifdef DEBUG
  252. /**
  253. * igb_get_hw_dev_name - return device name string
  254. * used by hardware layer to print debugging information
  255. **/
  256. char *igb_get_hw_dev_name(struct e1000_hw *hw)
  257. {
  258. struct igb_adapter *adapter = hw->back;
  259. return adapter->netdev->name;
  260. }
  261. /**
  262. * igb_get_time_str - format current NIC and system time as string
  263. */
  264. static char *igb_get_time_str(struct igb_adapter *adapter,
  265. char buffer[160])
  266. {
  267. cycle_t hw = adapter->cycles.read(&adapter->cycles);
  268. struct timespec nic = ns_to_timespec(timecounter_read(&adapter->clock));
  269. struct timespec sys;
  270. struct timespec delta;
  271. getnstimeofday(&sys);
  272. delta = timespec_sub(nic, sys);
  273. sprintf(buffer,
  274. "HW %llu, NIC %ld.%09lus, SYS %ld.%09lus, NIC-SYS %lds + %09luns",
  275. hw,
  276. (long)nic.tv_sec, nic.tv_nsec,
  277. (long)sys.tv_sec, sys.tv_nsec,
  278. (long)delta.tv_sec, delta.tv_nsec);
  279. return buffer;
  280. }
  281. #endif
  282. /**
  283. * igb_desc_unused - calculate if we have unused descriptors
  284. **/
  285. static int igb_desc_unused(struct igb_ring *ring)
  286. {
  287. if (ring->next_to_clean > ring->next_to_use)
  288. return ring->next_to_clean - ring->next_to_use - 1;
  289. return ring->count + ring->next_to_clean - ring->next_to_use - 1;
  290. }
  291. /**
  292. * igb_init_module - Driver Registration Routine
  293. *
  294. * igb_init_module is the first routine called when the driver is
  295. * loaded. All it does is register with the PCI subsystem.
  296. **/
  297. static int __init igb_init_module(void)
  298. {
  299. int ret;
  300. printk(KERN_INFO "%s - version %s\n",
  301. igb_driver_string, igb_driver_version);
  302. printk(KERN_INFO "%s\n", igb_copyright);
  303. global_quad_port_a = 0;
  304. #ifdef CONFIG_IGB_DCA
  305. dca_register_notify(&dca_notifier);
  306. #endif
  307. ret = pci_register_driver(&igb_driver);
  308. return ret;
  309. }
  310. module_init(igb_init_module);
  311. /**
  312. * igb_exit_module - Driver Exit Cleanup Routine
  313. *
  314. * igb_exit_module is called just before the driver is removed
  315. * from memory.
  316. **/
  317. static void __exit igb_exit_module(void)
  318. {
  319. #ifdef CONFIG_IGB_DCA
  320. dca_unregister_notify(&dca_notifier);
  321. #endif
  322. pci_unregister_driver(&igb_driver);
  323. }
  324. module_exit(igb_exit_module);
  325. #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
  326. /**
  327. * igb_cache_ring_register - Descriptor ring to register mapping
  328. * @adapter: board private structure to initialize
  329. *
  330. * Once we know the feature-set enabled for the device, we'll cache
  331. * the register offset the descriptor ring is assigned to.
  332. **/
  333. static void igb_cache_ring_register(struct igb_adapter *adapter)
  334. {
  335. int i;
  336. unsigned int rbase_offset = adapter->vfs_allocated_count;
  337. switch (adapter->hw.mac.type) {
  338. case e1000_82576:
  339. /* The queues are allocated for virtualization such that VF 0
  340. * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
  341. * In order to avoid collision we start at the first free queue
  342. * and continue consuming queues in the same sequence
  343. */
  344. for (i = 0; i < adapter->num_rx_queues; i++)
  345. adapter->rx_ring[i].reg_idx = rbase_offset +
  346. Q_IDX_82576(i);
  347. for (i = 0; i < adapter->num_tx_queues; i++)
  348. adapter->tx_ring[i].reg_idx = rbase_offset +
  349. Q_IDX_82576(i);
  350. break;
  351. case e1000_82575:
  352. default:
  353. for (i = 0; i < adapter->num_rx_queues; i++)
  354. adapter->rx_ring[i].reg_idx = i;
  355. for (i = 0; i < adapter->num_tx_queues; i++)
  356. adapter->tx_ring[i].reg_idx = i;
  357. break;
  358. }
  359. }
  360. /**
  361. * igb_alloc_queues - Allocate memory for all rings
  362. * @adapter: board private structure to initialize
  363. *
  364. * We allocate one ring per queue at run-time since we don't know the
  365. * number of queues at compile-time.
  366. **/
  367. static int igb_alloc_queues(struct igb_adapter *adapter)
  368. {
  369. int i;
  370. adapter->tx_ring = kcalloc(adapter->num_tx_queues,
  371. sizeof(struct igb_ring), GFP_KERNEL);
  372. if (!adapter->tx_ring)
  373. return -ENOMEM;
  374. adapter->rx_ring = kcalloc(adapter->num_rx_queues,
  375. sizeof(struct igb_ring), GFP_KERNEL);
  376. if (!adapter->rx_ring) {
  377. kfree(adapter->tx_ring);
  378. return -ENOMEM;
  379. }
  380. adapter->rx_ring->buddy = adapter->tx_ring;
  381. for (i = 0; i < adapter->num_tx_queues; i++) {
  382. struct igb_ring *ring = &(adapter->tx_ring[i]);
  383. ring->count = adapter->tx_ring_count;
  384. ring->adapter = adapter;
  385. ring->queue_index = i;
  386. }
  387. for (i = 0; i < adapter->num_rx_queues; i++) {
  388. struct igb_ring *ring = &(adapter->rx_ring[i]);
  389. ring->count = adapter->rx_ring_count;
  390. ring->adapter = adapter;
  391. ring->queue_index = i;
  392. ring->itr_register = E1000_ITR;
  393. /* set a default napi handler for each rx_ring */
  394. netif_napi_add(adapter->netdev, &ring->napi, igb_poll, 64);
  395. }
  396. igb_cache_ring_register(adapter);
  397. return 0;
  398. }
  399. static void igb_free_queues(struct igb_adapter *adapter)
  400. {
  401. int i;
  402. for (i = 0; i < adapter->num_rx_queues; i++)
  403. netif_napi_del(&adapter->rx_ring[i].napi);
  404. adapter->num_rx_queues = 0;
  405. adapter->num_tx_queues = 0;
  406. kfree(adapter->tx_ring);
  407. kfree(adapter->rx_ring);
  408. }
  409. #define IGB_N0_QUEUE -1
  410. static void igb_assign_vector(struct igb_adapter *adapter, int rx_queue,
  411. int tx_queue, int msix_vector)
  412. {
  413. u32 msixbm = 0;
  414. struct e1000_hw *hw = &adapter->hw;
  415. u32 ivar, index;
  416. switch (hw->mac.type) {
  417. case e1000_82575:
  418. /* The 82575 assigns vectors using a bitmask, which matches the
  419. bitmask for the EICR/EIMS/EIMC registers. To assign one
  420. or more queues to a vector, we write the appropriate bits
  421. into the MSIXBM register for that vector. */
  422. if (rx_queue > IGB_N0_QUEUE) {
  423. msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
  424. adapter->rx_ring[rx_queue].eims_value = msixbm;
  425. }
  426. if (tx_queue > IGB_N0_QUEUE) {
  427. msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
  428. adapter->tx_ring[tx_queue].eims_value =
  429. E1000_EICR_TX_QUEUE0 << tx_queue;
  430. }
  431. array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
  432. break;
  433. case e1000_82576:
  434. /* 82576 uses a table-based method for assigning vectors.
  435. Each queue has a single entry in the table to which we write
  436. a vector number along with a "valid" bit. Sadly, the layout
  437. of the table is somewhat counterintuitive. */
  438. if (rx_queue > IGB_N0_QUEUE) {
  439. index = (rx_queue >> 1) + adapter->vfs_allocated_count;
  440. ivar = array_rd32(E1000_IVAR0, index);
  441. if (rx_queue & 0x1) {
  442. /* vector goes into third byte of register */
  443. ivar = ivar & 0xFF00FFFF;
  444. ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
  445. } else {
  446. /* vector goes into low byte of register */
  447. ivar = ivar & 0xFFFFFF00;
  448. ivar |= msix_vector | E1000_IVAR_VALID;
  449. }
  450. adapter->rx_ring[rx_queue].eims_value= 1 << msix_vector;
  451. array_wr32(E1000_IVAR0, index, ivar);
  452. }
  453. if (tx_queue > IGB_N0_QUEUE) {
  454. index = (tx_queue >> 1) + adapter->vfs_allocated_count;
  455. ivar = array_rd32(E1000_IVAR0, index);
  456. if (tx_queue & 0x1) {
  457. /* vector goes into high byte of register */
  458. ivar = ivar & 0x00FFFFFF;
  459. ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
  460. } else {
  461. /* vector goes into second byte of register */
  462. ivar = ivar & 0xFFFF00FF;
  463. ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
  464. }
  465. adapter->tx_ring[tx_queue].eims_value= 1 << msix_vector;
  466. array_wr32(E1000_IVAR0, index, ivar);
  467. }
  468. break;
  469. default:
  470. BUG();
  471. break;
  472. }
  473. }
  474. /**
  475. * igb_configure_msix - Configure MSI-X hardware
  476. *
  477. * igb_configure_msix sets up the hardware to properly
  478. * generate MSI-X interrupts.
  479. **/
  480. static void igb_configure_msix(struct igb_adapter *adapter)
  481. {
  482. u32 tmp;
  483. int i, vector = 0;
  484. struct e1000_hw *hw = &adapter->hw;
  485. adapter->eims_enable_mask = 0;
  486. if (hw->mac.type == e1000_82576)
  487. /* Turn on MSI-X capability first, or our settings
  488. * won't stick. And it will take days to debug. */
  489. wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
  490. E1000_GPIE_PBA | E1000_GPIE_EIAME |
  491. E1000_GPIE_NSICR);
  492. for (i = 0; i < adapter->num_tx_queues; i++) {
  493. struct igb_ring *tx_ring = &adapter->tx_ring[i];
  494. igb_assign_vector(adapter, IGB_N0_QUEUE, i, vector++);
  495. adapter->eims_enable_mask |= tx_ring->eims_value;
  496. if (tx_ring->itr_val)
  497. writel(tx_ring->itr_val,
  498. hw->hw_addr + tx_ring->itr_register);
  499. else
  500. writel(1, hw->hw_addr + tx_ring->itr_register);
  501. }
  502. for (i = 0; i < adapter->num_rx_queues; i++) {
  503. struct igb_ring *rx_ring = &adapter->rx_ring[i];
  504. rx_ring->buddy = NULL;
  505. igb_assign_vector(adapter, i, IGB_N0_QUEUE, vector++);
  506. adapter->eims_enable_mask |= rx_ring->eims_value;
  507. if (rx_ring->itr_val)
  508. writel(rx_ring->itr_val,
  509. hw->hw_addr + rx_ring->itr_register);
  510. else
  511. writel(1, hw->hw_addr + rx_ring->itr_register);
  512. }
  513. /* set vector for other causes, i.e. link changes */
  514. switch (hw->mac.type) {
  515. case e1000_82575:
  516. array_wr32(E1000_MSIXBM(0), vector++,
  517. E1000_EIMS_OTHER);
  518. tmp = rd32(E1000_CTRL_EXT);
  519. /* enable MSI-X PBA support*/
  520. tmp |= E1000_CTRL_EXT_PBA_CLR;
  521. /* Auto-Mask interrupts upon ICR read. */
  522. tmp |= E1000_CTRL_EXT_EIAME;
  523. tmp |= E1000_CTRL_EXT_IRCA;
  524. wr32(E1000_CTRL_EXT, tmp);
  525. adapter->eims_enable_mask |= E1000_EIMS_OTHER;
  526. adapter->eims_other = E1000_EIMS_OTHER;
  527. break;
  528. case e1000_82576:
  529. tmp = (vector++ | E1000_IVAR_VALID) << 8;
  530. wr32(E1000_IVAR_MISC, tmp);
  531. adapter->eims_enable_mask = (1 << (vector)) - 1;
  532. adapter->eims_other = 1 << (vector - 1);
  533. break;
  534. default:
  535. /* do nothing, since nothing else supports MSI-X */
  536. break;
  537. } /* switch (hw->mac.type) */
  538. wrfl();
  539. }
  540. /**
  541. * igb_request_msix - Initialize MSI-X interrupts
  542. *
  543. * igb_request_msix allocates MSI-X vectors and requests interrupts from the
  544. * kernel.
  545. **/
  546. static int igb_request_msix(struct igb_adapter *adapter)
  547. {
  548. struct net_device *netdev = adapter->netdev;
  549. int i, err = 0, vector = 0;
  550. vector = 0;
  551. for (i = 0; i < adapter->num_tx_queues; i++) {
  552. struct igb_ring *ring = &(adapter->tx_ring[i]);
  553. sprintf(ring->name, "%s-tx-%d", netdev->name, i);
  554. err = request_irq(adapter->msix_entries[vector].vector,
  555. &igb_msix_tx, 0, ring->name,
  556. &(adapter->tx_ring[i]));
  557. if (err)
  558. goto out;
  559. ring->itr_register = E1000_EITR(0) + (vector << 2);
  560. ring->itr_val = 976; /* ~4000 ints/sec */
  561. vector++;
  562. }
  563. for (i = 0; i < adapter->num_rx_queues; i++) {
  564. struct igb_ring *ring = &(adapter->rx_ring[i]);
  565. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  566. sprintf(ring->name, "%s-rx-%d", netdev->name, i);
  567. else
  568. memcpy(ring->name, netdev->name, IFNAMSIZ);
  569. err = request_irq(adapter->msix_entries[vector].vector,
  570. &igb_msix_rx, 0, ring->name,
  571. &(adapter->rx_ring[i]));
  572. if (err)
  573. goto out;
  574. ring->itr_register = E1000_EITR(0) + (vector << 2);
  575. ring->itr_val = adapter->itr;
  576. vector++;
  577. }
  578. err = request_irq(adapter->msix_entries[vector].vector,
  579. &igb_msix_other, 0, netdev->name, netdev);
  580. if (err)
  581. goto out;
  582. igb_configure_msix(adapter);
  583. return 0;
  584. out:
  585. return err;
  586. }
  587. static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
  588. {
  589. if (adapter->msix_entries) {
  590. pci_disable_msix(adapter->pdev);
  591. kfree(adapter->msix_entries);
  592. adapter->msix_entries = NULL;
  593. } else if (adapter->flags & IGB_FLAG_HAS_MSI)
  594. pci_disable_msi(adapter->pdev);
  595. return;
  596. }
  597. /**
  598. * igb_set_interrupt_capability - set MSI or MSI-X if supported
  599. *
  600. * Attempt to configure interrupts using the best available
  601. * capabilities of the hardware and kernel.
  602. **/
  603. static void igb_set_interrupt_capability(struct igb_adapter *adapter)
  604. {
  605. int err;
  606. int numvecs, i;
  607. /* Number of supported queues. */
  608. /* Having more queues than CPUs doesn't make sense. */
  609. adapter->num_rx_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus());
  610. adapter->num_tx_queues = min_t(u32, IGB_MAX_TX_QUEUES, num_online_cpus());
  611. numvecs = adapter->num_tx_queues + adapter->num_rx_queues + 1;
  612. adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
  613. GFP_KERNEL);
  614. if (!adapter->msix_entries)
  615. goto msi_only;
  616. for (i = 0; i < numvecs; i++)
  617. adapter->msix_entries[i].entry = i;
  618. err = pci_enable_msix(adapter->pdev,
  619. adapter->msix_entries,
  620. numvecs);
  621. if (err == 0)
  622. goto out;
  623. igb_reset_interrupt_capability(adapter);
  624. /* If we can't do MSI-X, try MSI */
  625. msi_only:
  626. #ifdef CONFIG_PCI_IOV
  627. /* disable SR-IOV for non MSI-X configurations */
  628. if (adapter->vf_data) {
  629. struct e1000_hw *hw = &adapter->hw;
  630. /* disable iov and allow time for transactions to clear */
  631. pci_disable_sriov(adapter->pdev);
  632. msleep(500);
  633. kfree(adapter->vf_data);
  634. adapter->vf_data = NULL;
  635. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  636. msleep(100);
  637. dev_info(&adapter->pdev->dev, "IOV Disabled\n");
  638. }
  639. #endif
  640. adapter->num_rx_queues = 1;
  641. adapter->num_tx_queues = 1;
  642. if (!pci_enable_msi(adapter->pdev))
  643. adapter->flags |= IGB_FLAG_HAS_MSI;
  644. out:
  645. /* Notify the stack of the (possibly) reduced Tx Queue count. */
  646. adapter->netdev->real_num_tx_queues = adapter->num_tx_queues;
  647. return;
  648. }
  649. /**
  650. * igb_request_irq - initialize interrupts
  651. *
  652. * Attempts to configure interrupts using the best available
  653. * capabilities of the hardware and kernel.
  654. **/
  655. static int igb_request_irq(struct igb_adapter *adapter)
  656. {
  657. struct net_device *netdev = adapter->netdev;
  658. struct e1000_hw *hw = &adapter->hw;
  659. int err = 0;
  660. if (adapter->msix_entries) {
  661. err = igb_request_msix(adapter);
  662. if (!err)
  663. goto request_done;
  664. /* fall back to MSI */
  665. igb_reset_interrupt_capability(adapter);
  666. if (!pci_enable_msi(adapter->pdev))
  667. adapter->flags |= IGB_FLAG_HAS_MSI;
  668. igb_free_all_tx_resources(adapter);
  669. igb_free_all_rx_resources(adapter);
  670. adapter->num_rx_queues = 1;
  671. igb_alloc_queues(adapter);
  672. } else {
  673. switch (hw->mac.type) {
  674. case e1000_82575:
  675. wr32(E1000_MSIXBM(0),
  676. (E1000_EICR_RX_QUEUE0 | E1000_EIMS_OTHER));
  677. break;
  678. case e1000_82576:
  679. wr32(E1000_IVAR0, E1000_IVAR_VALID);
  680. break;
  681. default:
  682. break;
  683. }
  684. }
  685. if (adapter->flags & IGB_FLAG_HAS_MSI) {
  686. err = request_irq(adapter->pdev->irq, &igb_intr_msi, 0,
  687. netdev->name, netdev);
  688. if (!err)
  689. goto request_done;
  690. /* fall back to legacy interrupts */
  691. igb_reset_interrupt_capability(adapter);
  692. adapter->flags &= ~IGB_FLAG_HAS_MSI;
  693. }
  694. err = request_irq(adapter->pdev->irq, &igb_intr, IRQF_SHARED,
  695. netdev->name, netdev);
  696. if (err)
  697. dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n",
  698. err);
  699. request_done:
  700. return err;
  701. }
  702. static void igb_free_irq(struct igb_adapter *adapter)
  703. {
  704. struct net_device *netdev = adapter->netdev;
  705. if (adapter->msix_entries) {
  706. int vector = 0, i;
  707. for (i = 0; i < adapter->num_tx_queues; i++)
  708. free_irq(adapter->msix_entries[vector++].vector,
  709. &(adapter->tx_ring[i]));
  710. for (i = 0; i < adapter->num_rx_queues; i++)
  711. free_irq(adapter->msix_entries[vector++].vector,
  712. &(adapter->rx_ring[i]));
  713. free_irq(adapter->msix_entries[vector++].vector, netdev);
  714. return;
  715. }
  716. free_irq(adapter->pdev->irq, netdev);
  717. }
  718. /**
  719. * igb_irq_disable - Mask off interrupt generation on the NIC
  720. * @adapter: board private structure
  721. **/
  722. static void igb_irq_disable(struct igb_adapter *adapter)
  723. {
  724. struct e1000_hw *hw = &adapter->hw;
  725. if (adapter->msix_entries) {
  726. u32 regval = rd32(E1000_EIAM);
  727. wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
  728. wr32(E1000_EIMC, adapter->eims_enable_mask);
  729. regval = rd32(E1000_EIAC);
  730. wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
  731. }
  732. wr32(E1000_IAM, 0);
  733. wr32(E1000_IMC, ~0);
  734. wrfl();
  735. synchronize_irq(adapter->pdev->irq);
  736. }
  737. /**
  738. * igb_irq_enable - Enable default interrupt generation settings
  739. * @adapter: board private structure
  740. **/
  741. static void igb_irq_enable(struct igb_adapter *adapter)
  742. {
  743. struct e1000_hw *hw = &adapter->hw;
  744. if (adapter->msix_entries) {
  745. u32 regval = rd32(E1000_EIAC);
  746. wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
  747. regval = rd32(E1000_EIAM);
  748. wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
  749. wr32(E1000_EIMS, adapter->eims_enable_mask);
  750. if (adapter->vfs_allocated_count)
  751. wr32(E1000_MBVFIMR, 0xFF);
  752. wr32(E1000_IMS, (E1000_IMS_LSC | E1000_IMS_VMMB |
  753. E1000_IMS_DOUTSYNC));
  754. } else {
  755. wr32(E1000_IMS, IMS_ENABLE_MASK);
  756. wr32(E1000_IAM, IMS_ENABLE_MASK);
  757. }
  758. }
  759. static void igb_update_mng_vlan(struct igb_adapter *adapter)
  760. {
  761. struct net_device *netdev = adapter->netdev;
  762. u16 vid = adapter->hw.mng_cookie.vlan_id;
  763. u16 old_vid = adapter->mng_vlan_id;
  764. if (adapter->vlgrp) {
  765. if (!vlan_group_get_device(adapter->vlgrp, vid)) {
  766. if (adapter->hw.mng_cookie.status &
  767. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  768. igb_vlan_rx_add_vid(netdev, vid);
  769. adapter->mng_vlan_id = vid;
  770. } else
  771. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  772. if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
  773. (vid != old_vid) &&
  774. !vlan_group_get_device(adapter->vlgrp, old_vid))
  775. igb_vlan_rx_kill_vid(netdev, old_vid);
  776. } else
  777. adapter->mng_vlan_id = vid;
  778. }
  779. }
  780. /**
  781. * igb_release_hw_control - release control of the h/w to f/w
  782. * @adapter: address of board private structure
  783. *
  784. * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
  785. * For ASF and Pass Through versions of f/w this means that the
  786. * driver is no longer loaded.
  787. *
  788. **/
  789. static void igb_release_hw_control(struct igb_adapter *adapter)
  790. {
  791. struct e1000_hw *hw = &adapter->hw;
  792. u32 ctrl_ext;
  793. /* Let firmware take over control of h/w */
  794. ctrl_ext = rd32(E1000_CTRL_EXT);
  795. wr32(E1000_CTRL_EXT,
  796. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  797. }
  798. /**
  799. * igb_get_hw_control - get control of the h/w from f/w
  800. * @adapter: address of board private structure
  801. *
  802. * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
  803. * For ASF and Pass Through versions of f/w this means that
  804. * the driver is loaded.
  805. *
  806. **/
  807. static void igb_get_hw_control(struct igb_adapter *adapter)
  808. {
  809. struct e1000_hw *hw = &adapter->hw;
  810. u32 ctrl_ext;
  811. /* Let firmware know the driver has taken over */
  812. ctrl_ext = rd32(E1000_CTRL_EXT);
  813. wr32(E1000_CTRL_EXT,
  814. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  815. }
  816. /**
  817. * igb_configure - configure the hardware for RX and TX
  818. * @adapter: private board structure
  819. **/
  820. static void igb_configure(struct igb_adapter *adapter)
  821. {
  822. struct net_device *netdev = adapter->netdev;
  823. int i;
  824. igb_get_hw_control(adapter);
  825. igb_set_rx_mode(netdev);
  826. igb_restore_vlan(adapter);
  827. igb_configure_tx(adapter);
  828. igb_setup_rctl(adapter);
  829. igb_configure_rx(adapter);
  830. igb_rx_fifo_flush_82575(&adapter->hw);
  831. /* call igb_desc_unused which always leaves
  832. * at least 1 descriptor unused to make sure
  833. * next_to_use != next_to_clean */
  834. for (i = 0; i < adapter->num_rx_queues; i++) {
  835. struct igb_ring *ring = &adapter->rx_ring[i];
  836. igb_alloc_rx_buffers_adv(ring, igb_desc_unused(ring));
  837. }
  838. adapter->tx_queue_len = netdev->tx_queue_len;
  839. }
  840. /**
  841. * igb_up - Open the interface and prepare it to handle traffic
  842. * @adapter: board private structure
  843. **/
  844. int igb_up(struct igb_adapter *adapter)
  845. {
  846. struct e1000_hw *hw = &adapter->hw;
  847. int i;
  848. /* hardware has been reset, we need to reload some things */
  849. igb_configure(adapter);
  850. clear_bit(__IGB_DOWN, &adapter->state);
  851. for (i = 0; i < adapter->num_rx_queues; i++)
  852. napi_enable(&adapter->rx_ring[i].napi);
  853. if (adapter->msix_entries)
  854. igb_configure_msix(adapter);
  855. igb_vmm_control(adapter);
  856. igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0);
  857. igb_set_vmolr(hw, adapter->vfs_allocated_count);
  858. /* Clear any pending interrupts. */
  859. rd32(E1000_ICR);
  860. igb_irq_enable(adapter);
  861. netif_tx_start_all_queues(adapter->netdev);
  862. /* Fire a link change interrupt to start the watchdog. */
  863. wr32(E1000_ICS, E1000_ICS_LSC);
  864. return 0;
  865. }
  866. void igb_down(struct igb_adapter *adapter)
  867. {
  868. struct e1000_hw *hw = &adapter->hw;
  869. struct net_device *netdev = adapter->netdev;
  870. u32 tctl, rctl;
  871. int i;
  872. /* signal that we're down so the interrupt handler does not
  873. * reschedule our watchdog timer */
  874. set_bit(__IGB_DOWN, &adapter->state);
  875. /* disable receives in the hardware */
  876. rctl = rd32(E1000_RCTL);
  877. wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
  878. /* flush and sleep below */
  879. netif_tx_stop_all_queues(netdev);
  880. /* disable transmits in the hardware */
  881. tctl = rd32(E1000_TCTL);
  882. tctl &= ~E1000_TCTL_EN;
  883. wr32(E1000_TCTL, tctl);
  884. /* flush both disables and wait for them to finish */
  885. wrfl();
  886. msleep(10);
  887. for (i = 0; i < adapter->num_rx_queues; i++)
  888. napi_disable(&adapter->rx_ring[i].napi);
  889. igb_irq_disable(adapter);
  890. del_timer_sync(&adapter->watchdog_timer);
  891. del_timer_sync(&adapter->phy_info_timer);
  892. netdev->tx_queue_len = adapter->tx_queue_len;
  893. netif_carrier_off(netdev);
  894. /* record the stats before reset*/
  895. igb_update_stats(adapter);
  896. adapter->link_speed = 0;
  897. adapter->link_duplex = 0;
  898. if (!pci_channel_offline(adapter->pdev))
  899. igb_reset(adapter);
  900. igb_clean_all_tx_rings(adapter);
  901. igb_clean_all_rx_rings(adapter);
  902. #ifdef CONFIG_IGB_DCA
  903. /* since we reset the hardware DCA settings were cleared */
  904. igb_setup_dca(adapter);
  905. #endif
  906. }
  907. void igb_reinit_locked(struct igb_adapter *adapter)
  908. {
  909. WARN_ON(in_interrupt());
  910. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  911. msleep(1);
  912. igb_down(adapter);
  913. igb_up(adapter);
  914. clear_bit(__IGB_RESETTING, &adapter->state);
  915. }
  916. void igb_reset(struct igb_adapter *adapter)
  917. {
  918. struct e1000_hw *hw = &adapter->hw;
  919. struct e1000_mac_info *mac = &hw->mac;
  920. struct e1000_fc_info *fc = &hw->fc;
  921. u32 pba = 0, tx_space, min_tx_space, min_rx_space;
  922. u16 hwm;
  923. /* Repartition Pba for greater than 9k mtu
  924. * To take effect CTRL.RST is required.
  925. */
  926. switch (mac->type) {
  927. case e1000_82576:
  928. pba = E1000_PBA_64K;
  929. break;
  930. case e1000_82575:
  931. default:
  932. pba = E1000_PBA_34K;
  933. break;
  934. }
  935. if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
  936. (mac->type < e1000_82576)) {
  937. /* adjust PBA for jumbo frames */
  938. wr32(E1000_PBA, pba);
  939. /* To maintain wire speed transmits, the Tx FIFO should be
  940. * large enough to accommodate two full transmit packets,
  941. * rounded up to the next 1KB and expressed in KB. Likewise,
  942. * the Rx FIFO should be large enough to accommodate at least
  943. * one full receive packet and is similarly rounded up and
  944. * expressed in KB. */
  945. pba = rd32(E1000_PBA);
  946. /* upper 16 bits has Tx packet buffer allocation size in KB */
  947. tx_space = pba >> 16;
  948. /* lower 16 bits has Rx packet buffer allocation size in KB */
  949. pba &= 0xffff;
  950. /* the tx fifo also stores 16 bytes of information about the tx
  951. * but don't include ethernet FCS because hardware appends it */
  952. min_tx_space = (adapter->max_frame_size +
  953. sizeof(union e1000_adv_tx_desc) -
  954. ETH_FCS_LEN) * 2;
  955. min_tx_space = ALIGN(min_tx_space, 1024);
  956. min_tx_space >>= 10;
  957. /* software strips receive CRC, so leave room for it */
  958. min_rx_space = adapter->max_frame_size;
  959. min_rx_space = ALIGN(min_rx_space, 1024);
  960. min_rx_space >>= 10;
  961. /* If current Tx allocation is less than the min Tx FIFO size,
  962. * and the min Tx FIFO size is less than the current Rx FIFO
  963. * allocation, take space away from current Rx allocation */
  964. if (tx_space < min_tx_space &&
  965. ((min_tx_space - tx_space) < pba)) {
  966. pba = pba - (min_tx_space - tx_space);
  967. /* if short on rx space, rx wins and must trump tx
  968. * adjustment */
  969. if (pba < min_rx_space)
  970. pba = min_rx_space;
  971. }
  972. wr32(E1000_PBA, pba);
  973. }
  974. /* flow control settings */
  975. /* The high water mark must be low enough to fit one full frame
  976. * (or the size used for early receive) above it in the Rx FIFO.
  977. * Set it to the lower of:
  978. * - 90% of the Rx FIFO size, or
  979. * - the full Rx FIFO size minus one full frame */
  980. hwm = min(((pba << 10) * 9 / 10),
  981. ((pba << 10) - 2 * adapter->max_frame_size));
  982. if (mac->type < e1000_82576) {
  983. fc->high_water = hwm & 0xFFF8; /* 8-byte granularity */
  984. fc->low_water = fc->high_water - 8;
  985. } else {
  986. fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
  987. fc->low_water = fc->high_water - 16;
  988. }
  989. fc->pause_time = 0xFFFF;
  990. fc->send_xon = 1;
  991. fc->current_mode = fc->requested_mode;
  992. /* disable receive for all VFs and wait one second */
  993. if (adapter->vfs_allocated_count) {
  994. int i;
  995. for (i = 0 ; i < adapter->vfs_allocated_count; i++)
  996. adapter->vf_data[i].clear_to_send = false;
  997. /* ping all the active vfs to let them know we are going down */
  998. igb_ping_all_vfs(adapter);
  999. /* disable transmits and receives */
  1000. wr32(E1000_VFRE, 0);
  1001. wr32(E1000_VFTE, 0);
  1002. }
  1003. /* Allow time for pending master requests to run */
  1004. adapter->hw.mac.ops.reset_hw(&adapter->hw);
  1005. wr32(E1000_WUC, 0);
  1006. if (adapter->hw.mac.ops.init_hw(&adapter->hw))
  1007. dev_err(&adapter->pdev->dev, "Hardware Error\n");
  1008. igb_update_mng_vlan(adapter);
  1009. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  1010. wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
  1011. igb_reset_adaptive(&adapter->hw);
  1012. igb_get_phy_info(&adapter->hw);
  1013. }
  1014. static const struct net_device_ops igb_netdev_ops = {
  1015. .ndo_open = igb_open,
  1016. .ndo_stop = igb_close,
  1017. .ndo_start_xmit = igb_xmit_frame_adv,
  1018. .ndo_get_stats = igb_get_stats,
  1019. .ndo_set_rx_mode = igb_set_rx_mode,
  1020. .ndo_set_multicast_list = igb_set_rx_mode,
  1021. .ndo_set_mac_address = igb_set_mac,
  1022. .ndo_change_mtu = igb_change_mtu,
  1023. .ndo_do_ioctl = igb_ioctl,
  1024. .ndo_tx_timeout = igb_tx_timeout,
  1025. .ndo_validate_addr = eth_validate_addr,
  1026. .ndo_vlan_rx_register = igb_vlan_rx_register,
  1027. .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
  1028. .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
  1029. #ifdef CONFIG_NET_POLL_CONTROLLER
  1030. .ndo_poll_controller = igb_netpoll,
  1031. #endif
  1032. };
  1033. /**
  1034. * igb_probe - Device Initialization Routine
  1035. * @pdev: PCI device information struct
  1036. * @ent: entry in igb_pci_tbl
  1037. *
  1038. * Returns 0 on success, negative on failure
  1039. *
  1040. * igb_probe initializes an adapter identified by a pci_dev structure.
  1041. * The OS initialization, configuring of the adapter private structure,
  1042. * and a hardware reset occur.
  1043. **/
  1044. static int __devinit igb_probe(struct pci_dev *pdev,
  1045. const struct pci_device_id *ent)
  1046. {
  1047. struct net_device *netdev;
  1048. struct igb_adapter *adapter;
  1049. struct e1000_hw *hw;
  1050. const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
  1051. unsigned long mmio_start, mmio_len;
  1052. int err, pci_using_dac;
  1053. u16 eeprom_data = 0;
  1054. u16 eeprom_apme_mask = IGB_EEPROM_APME;
  1055. u32 part_num;
  1056. err = pci_enable_device_mem(pdev);
  1057. if (err)
  1058. return err;
  1059. pci_using_dac = 0;
  1060. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  1061. if (!err) {
  1062. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  1063. if (!err)
  1064. pci_using_dac = 1;
  1065. } else {
  1066. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  1067. if (err) {
  1068. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  1069. if (err) {
  1070. dev_err(&pdev->dev, "No usable DMA "
  1071. "configuration, aborting\n");
  1072. goto err_dma;
  1073. }
  1074. }
  1075. }
  1076. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  1077. IORESOURCE_MEM),
  1078. igb_driver_name);
  1079. if (err)
  1080. goto err_pci_reg;
  1081. pci_enable_pcie_error_reporting(pdev);
  1082. pci_set_master(pdev);
  1083. pci_save_state(pdev);
  1084. err = -ENOMEM;
  1085. netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
  1086. IGB_ABS_MAX_TX_QUEUES);
  1087. if (!netdev)
  1088. goto err_alloc_etherdev;
  1089. SET_NETDEV_DEV(netdev, &pdev->dev);
  1090. pci_set_drvdata(pdev, netdev);
  1091. adapter = netdev_priv(netdev);
  1092. adapter->netdev = netdev;
  1093. adapter->pdev = pdev;
  1094. hw = &adapter->hw;
  1095. hw->back = adapter;
  1096. adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  1097. mmio_start = pci_resource_start(pdev, 0);
  1098. mmio_len = pci_resource_len(pdev, 0);
  1099. err = -EIO;
  1100. hw->hw_addr = ioremap(mmio_start, mmio_len);
  1101. if (!hw->hw_addr)
  1102. goto err_ioremap;
  1103. netdev->netdev_ops = &igb_netdev_ops;
  1104. igb_set_ethtool_ops(netdev);
  1105. netdev->watchdog_timeo = 5 * HZ;
  1106. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  1107. netdev->mem_start = mmio_start;
  1108. netdev->mem_end = mmio_start + mmio_len;
  1109. /* PCI config space info */
  1110. hw->vendor_id = pdev->vendor;
  1111. hw->device_id = pdev->device;
  1112. hw->revision_id = pdev->revision;
  1113. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1114. hw->subsystem_device_id = pdev->subsystem_device;
  1115. /* setup the private structure */
  1116. hw->back = adapter;
  1117. /* Copy the default MAC, PHY and NVM function pointers */
  1118. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  1119. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  1120. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  1121. /* Initialize skew-specific constants */
  1122. err = ei->get_invariants(hw);
  1123. if (err)
  1124. goto err_sw_init;
  1125. #ifdef CONFIG_PCI_IOV
  1126. /* since iov functionality isn't critical to base device function we
  1127. * can accept failure. If it fails we don't allow iov to be enabled */
  1128. if (hw->mac.type == e1000_82576) {
  1129. /* 82576 supports a maximum of 7 VFs in addition to the PF */
  1130. unsigned int num_vfs = (max_vfs > 7) ? 7 : max_vfs;
  1131. int i;
  1132. unsigned char mac_addr[ETH_ALEN];
  1133. if (num_vfs) {
  1134. adapter->vf_data = kcalloc(num_vfs,
  1135. sizeof(struct vf_data_storage),
  1136. GFP_KERNEL);
  1137. if (!adapter->vf_data) {
  1138. dev_err(&pdev->dev,
  1139. "Could not allocate VF private data - "
  1140. "IOV enable failed\n");
  1141. } else {
  1142. err = pci_enable_sriov(pdev, num_vfs);
  1143. if (!err) {
  1144. adapter->vfs_allocated_count = num_vfs;
  1145. dev_info(&pdev->dev,
  1146. "%d vfs allocated\n",
  1147. num_vfs);
  1148. for (i = 0;
  1149. i < adapter->vfs_allocated_count;
  1150. i++) {
  1151. random_ether_addr(mac_addr);
  1152. igb_set_vf_mac(adapter, i,
  1153. mac_addr);
  1154. }
  1155. } else {
  1156. kfree(adapter->vf_data);
  1157. adapter->vf_data = NULL;
  1158. }
  1159. }
  1160. }
  1161. }
  1162. #endif
  1163. /* setup the private structure */
  1164. err = igb_sw_init(adapter);
  1165. if (err)
  1166. goto err_sw_init;
  1167. igb_get_bus_info_pcie(hw);
  1168. /* set flags */
  1169. switch (hw->mac.type) {
  1170. case e1000_82575:
  1171. adapter->flags |= IGB_FLAG_NEED_CTX_IDX;
  1172. break;
  1173. case e1000_82576:
  1174. default:
  1175. break;
  1176. }
  1177. hw->phy.autoneg_wait_to_complete = false;
  1178. hw->mac.adaptive_ifs = true;
  1179. /* Copper options */
  1180. if (hw->phy.media_type == e1000_media_type_copper) {
  1181. hw->phy.mdix = AUTO_ALL_MODES;
  1182. hw->phy.disable_polarity_correction = false;
  1183. hw->phy.ms_type = e1000_ms_hw_default;
  1184. }
  1185. if (igb_check_reset_block(hw))
  1186. dev_info(&pdev->dev,
  1187. "PHY reset is blocked due to SOL/IDER session.\n");
  1188. netdev->features = NETIF_F_SG |
  1189. NETIF_F_IP_CSUM |
  1190. NETIF_F_HW_VLAN_TX |
  1191. NETIF_F_HW_VLAN_RX |
  1192. NETIF_F_HW_VLAN_FILTER;
  1193. netdev->features |= NETIF_F_IPV6_CSUM;
  1194. netdev->features |= NETIF_F_TSO;
  1195. netdev->features |= NETIF_F_TSO6;
  1196. netdev->features |= NETIF_F_GRO;
  1197. netdev->vlan_features |= NETIF_F_TSO;
  1198. netdev->vlan_features |= NETIF_F_TSO6;
  1199. netdev->vlan_features |= NETIF_F_IP_CSUM;
  1200. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  1201. netdev->vlan_features |= NETIF_F_SG;
  1202. if (pci_using_dac)
  1203. netdev->features |= NETIF_F_HIGHDMA;
  1204. if (adapter->hw.mac.type == e1000_82576)
  1205. netdev->features |= NETIF_F_SCTP_CSUM;
  1206. adapter->en_mng_pt = igb_enable_mng_pass_thru(&adapter->hw);
  1207. /* before reading the NVM, reset the controller to put the device in a
  1208. * known good starting state */
  1209. hw->mac.ops.reset_hw(hw);
  1210. /* make sure the NVM is good */
  1211. if (igb_validate_nvm_checksum(hw) < 0) {
  1212. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  1213. err = -EIO;
  1214. goto err_eeprom;
  1215. }
  1216. /* copy the MAC address out of the NVM */
  1217. if (hw->mac.ops.read_mac_addr(hw))
  1218. dev_err(&pdev->dev, "NVM Read Error\n");
  1219. memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
  1220. memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
  1221. if (!is_valid_ether_addr(netdev->perm_addr)) {
  1222. dev_err(&pdev->dev, "Invalid MAC Address\n");
  1223. err = -EIO;
  1224. goto err_eeprom;
  1225. }
  1226. setup_timer(&adapter->watchdog_timer, &igb_watchdog,
  1227. (unsigned long) adapter);
  1228. setup_timer(&adapter->phy_info_timer, &igb_update_phy_info,
  1229. (unsigned long) adapter);
  1230. INIT_WORK(&adapter->reset_task, igb_reset_task);
  1231. INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
  1232. /* Initialize link properties that are user-changeable */
  1233. adapter->fc_autoneg = true;
  1234. hw->mac.autoneg = true;
  1235. hw->phy.autoneg_advertised = 0x2f;
  1236. hw->fc.requested_mode = e1000_fc_default;
  1237. hw->fc.current_mode = e1000_fc_default;
  1238. adapter->itr_setting = IGB_DEFAULT_ITR;
  1239. adapter->itr = IGB_START_ITR;
  1240. igb_validate_mdi_setting(hw);
  1241. /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
  1242. * enable the ACPI Magic Packet filter
  1243. */
  1244. if (hw->bus.func == 0)
  1245. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  1246. else if (hw->bus.func == 1)
  1247. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  1248. if (eeprom_data & eeprom_apme_mask)
  1249. adapter->eeprom_wol |= E1000_WUFC_MAG;
  1250. /* now that we have the eeprom settings, apply the special cases where
  1251. * the eeprom may be wrong or the board simply won't support wake on
  1252. * lan on a particular port */
  1253. switch (pdev->device) {
  1254. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  1255. adapter->eeprom_wol = 0;
  1256. break;
  1257. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  1258. case E1000_DEV_ID_82576_FIBER:
  1259. case E1000_DEV_ID_82576_SERDES:
  1260. /* Wake events only supported on port A for dual fiber
  1261. * regardless of eeprom setting */
  1262. if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
  1263. adapter->eeprom_wol = 0;
  1264. break;
  1265. case E1000_DEV_ID_82576_QUAD_COPPER:
  1266. /* if quad port adapter, disable WoL on all but port A */
  1267. if (global_quad_port_a != 0)
  1268. adapter->eeprom_wol = 0;
  1269. else
  1270. adapter->flags |= IGB_FLAG_QUAD_PORT_A;
  1271. /* Reset for multiple quad port adapters */
  1272. if (++global_quad_port_a == 4)
  1273. global_quad_port_a = 0;
  1274. break;
  1275. }
  1276. /* initialize the wol settings based on the eeprom settings */
  1277. adapter->wol = adapter->eeprom_wol;
  1278. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1279. /* reset the hardware with the new settings */
  1280. igb_reset(adapter);
  1281. /* let the f/w know that the h/w is now under the control of the
  1282. * driver. */
  1283. igb_get_hw_control(adapter);
  1284. strcpy(netdev->name, "eth%d");
  1285. err = register_netdev(netdev);
  1286. if (err)
  1287. goto err_register;
  1288. /* carrier off reporting is important to ethtool even BEFORE open */
  1289. netif_carrier_off(netdev);
  1290. #ifdef CONFIG_IGB_DCA
  1291. if (dca_add_requester(&pdev->dev) == 0) {
  1292. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  1293. dev_info(&pdev->dev, "DCA enabled\n");
  1294. igb_setup_dca(adapter);
  1295. }
  1296. #endif
  1297. /*
  1298. * Initialize hardware timer: we keep it running just in case
  1299. * that some program needs it later on.
  1300. */
  1301. memset(&adapter->cycles, 0, sizeof(adapter->cycles));
  1302. adapter->cycles.read = igb_read_clock;
  1303. adapter->cycles.mask = CLOCKSOURCE_MASK(64);
  1304. adapter->cycles.mult = 1;
  1305. adapter->cycles.shift = IGB_TSYNC_SHIFT;
  1306. wr32(E1000_TIMINCA,
  1307. (1<<24) |
  1308. IGB_TSYNC_CYCLE_TIME_IN_NANOSECONDS * IGB_TSYNC_SCALE);
  1309. #if 0
  1310. /*
  1311. * Avoid rollover while we initialize by resetting the time counter.
  1312. */
  1313. wr32(E1000_SYSTIML, 0x00000000);
  1314. wr32(E1000_SYSTIMH, 0x00000000);
  1315. #else
  1316. /*
  1317. * Set registers so that rollover occurs soon to test this.
  1318. */
  1319. wr32(E1000_SYSTIML, 0x00000000);
  1320. wr32(E1000_SYSTIMH, 0xFF800000);
  1321. #endif
  1322. wrfl();
  1323. timecounter_init(&adapter->clock,
  1324. &adapter->cycles,
  1325. ktime_to_ns(ktime_get_real()));
  1326. /*
  1327. * Synchronize our NIC clock against system wall clock. NIC
  1328. * time stamp reading requires ~3us per sample, each sample
  1329. * was pretty stable even under load => only require 10
  1330. * samples for each offset comparison.
  1331. */
  1332. memset(&adapter->compare, 0, sizeof(adapter->compare));
  1333. adapter->compare.source = &adapter->clock;
  1334. adapter->compare.target = ktime_get_real;
  1335. adapter->compare.num_samples = 10;
  1336. timecompare_update(&adapter->compare, 0);
  1337. #ifdef DEBUG
  1338. {
  1339. char buffer[160];
  1340. printk(KERN_DEBUG
  1341. "igb: %s: hw %p initialized timer\n",
  1342. igb_get_time_str(adapter, buffer),
  1343. &adapter->hw);
  1344. }
  1345. #endif
  1346. dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
  1347. /* print bus type/speed/width info */
  1348. dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
  1349. netdev->name,
  1350. ((hw->bus.speed == e1000_bus_speed_2500)
  1351. ? "2.5Gb/s" : "unknown"),
  1352. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  1353. (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
  1354. (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
  1355. "unknown"),
  1356. netdev->dev_addr);
  1357. igb_read_part_num(hw, &part_num);
  1358. dev_info(&pdev->dev, "%s: PBA No: %06x-%03x\n", netdev->name,
  1359. (part_num >> 8), (part_num & 0xff));
  1360. dev_info(&pdev->dev,
  1361. "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
  1362. adapter->msix_entries ? "MSI-X" :
  1363. (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
  1364. adapter->num_rx_queues, adapter->num_tx_queues);
  1365. return 0;
  1366. err_register:
  1367. igb_release_hw_control(adapter);
  1368. err_eeprom:
  1369. if (!igb_check_reset_block(hw))
  1370. igb_reset_phy(hw);
  1371. if (hw->flash_address)
  1372. iounmap(hw->flash_address);
  1373. igb_free_queues(adapter);
  1374. err_sw_init:
  1375. iounmap(hw->hw_addr);
  1376. err_ioremap:
  1377. free_netdev(netdev);
  1378. err_alloc_etherdev:
  1379. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  1380. IORESOURCE_MEM));
  1381. err_pci_reg:
  1382. err_dma:
  1383. pci_disable_device(pdev);
  1384. return err;
  1385. }
  1386. /**
  1387. * igb_remove - Device Removal Routine
  1388. * @pdev: PCI device information struct
  1389. *
  1390. * igb_remove is called by the PCI subsystem to alert the driver
  1391. * that it should release a PCI device. The could be caused by a
  1392. * Hot-Plug event, or because the driver is going to be removed from
  1393. * memory.
  1394. **/
  1395. static void __devexit igb_remove(struct pci_dev *pdev)
  1396. {
  1397. struct net_device *netdev = pci_get_drvdata(pdev);
  1398. struct igb_adapter *adapter = netdev_priv(netdev);
  1399. struct e1000_hw *hw = &adapter->hw;
  1400. /* flush_scheduled work may reschedule our watchdog task, so
  1401. * explicitly disable watchdog tasks from being rescheduled */
  1402. set_bit(__IGB_DOWN, &adapter->state);
  1403. del_timer_sync(&adapter->watchdog_timer);
  1404. del_timer_sync(&adapter->phy_info_timer);
  1405. flush_scheduled_work();
  1406. #ifdef CONFIG_IGB_DCA
  1407. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  1408. dev_info(&pdev->dev, "DCA disabled\n");
  1409. dca_remove_requester(&pdev->dev);
  1410. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  1411. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  1412. }
  1413. #endif
  1414. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  1415. * would have already happened in close and is redundant. */
  1416. igb_release_hw_control(adapter);
  1417. unregister_netdev(netdev);
  1418. if (!igb_check_reset_block(&adapter->hw))
  1419. igb_reset_phy(&adapter->hw);
  1420. igb_reset_interrupt_capability(adapter);
  1421. igb_free_queues(adapter);
  1422. #ifdef CONFIG_PCI_IOV
  1423. /* reclaim resources allocated to VFs */
  1424. if (adapter->vf_data) {
  1425. /* disable iov and allow time for transactions to clear */
  1426. pci_disable_sriov(pdev);
  1427. msleep(500);
  1428. kfree(adapter->vf_data);
  1429. adapter->vf_data = NULL;
  1430. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  1431. msleep(100);
  1432. dev_info(&pdev->dev, "IOV Disabled\n");
  1433. }
  1434. #endif
  1435. iounmap(hw->hw_addr);
  1436. if (hw->flash_address)
  1437. iounmap(hw->flash_address);
  1438. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  1439. IORESOURCE_MEM));
  1440. free_netdev(netdev);
  1441. pci_disable_pcie_error_reporting(pdev);
  1442. pci_disable_device(pdev);
  1443. }
  1444. /**
  1445. * igb_sw_init - Initialize general software structures (struct igb_adapter)
  1446. * @adapter: board private structure to initialize
  1447. *
  1448. * igb_sw_init initializes the Adapter private data structure.
  1449. * Fields are initialized based on PCI device information and
  1450. * OS network device settings (MTU size).
  1451. **/
  1452. static int __devinit igb_sw_init(struct igb_adapter *adapter)
  1453. {
  1454. struct e1000_hw *hw = &adapter->hw;
  1455. struct net_device *netdev = adapter->netdev;
  1456. struct pci_dev *pdev = adapter->pdev;
  1457. pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
  1458. adapter->tx_ring_count = IGB_DEFAULT_TXD;
  1459. adapter->rx_ring_count = IGB_DEFAULT_RXD;
  1460. adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  1461. adapter->rx_ps_hdr_size = 0; /* disable packet split */
  1462. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  1463. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  1464. /* This call may decrease the number of queues depending on
  1465. * interrupt mode. */
  1466. igb_set_interrupt_capability(adapter);
  1467. if (igb_alloc_queues(adapter)) {
  1468. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  1469. return -ENOMEM;
  1470. }
  1471. /* Explicitly disable IRQ since the NIC can be in any state. */
  1472. igb_irq_disable(adapter);
  1473. set_bit(__IGB_DOWN, &adapter->state);
  1474. return 0;
  1475. }
  1476. /**
  1477. * igb_open - Called when a network interface is made active
  1478. * @netdev: network interface device structure
  1479. *
  1480. * Returns 0 on success, negative value on failure
  1481. *
  1482. * The open entry point is called when a network interface is made
  1483. * active by the system (IFF_UP). At this point all resources needed
  1484. * for transmit and receive operations are allocated, the interrupt
  1485. * handler is registered with the OS, the watchdog timer is started,
  1486. * and the stack is notified that the interface is ready.
  1487. **/
  1488. static int igb_open(struct net_device *netdev)
  1489. {
  1490. struct igb_adapter *adapter = netdev_priv(netdev);
  1491. struct e1000_hw *hw = &adapter->hw;
  1492. int err;
  1493. int i;
  1494. /* disallow open during test */
  1495. if (test_bit(__IGB_TESTING, &adapter->state))
  1496. return -EBUSY;
  1497. netif_carrier_off(netdev);
  1498. /* allocate transmit descriptors */
  1499. err = igb_setup_all_tx_resources(adapter);
  1500. if (err)
  1501. goto err_setup_tx;
  1502. /* allocate receive descriptors */
  1503. err = igb_setup_all_rx_resources(adapter);
  1504. if (err)
  1505. goto err_setup_rx;
  1506. /* e1000_power_up_phy(adapter); */
  1507. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  1508. if ((adapter->hw.mng_cookie.status &
  1509. E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
  1510. igb_update_mng_vlan(adapter);
  1511. /* before we allocate an interrupt, we must be ready to handle it.
  1512. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  1513. * as soon as we call pci_request_irq, so we have to setup our
  1514. * clean_rx handler before we do so. */
  1515. igb_configure(adapter);
  1516. igb_vmm_control(adapter);
  1517. igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0);
  1518. igb_set_vmolr(hw, adapter->vfs_allocated_count);
  1519. err = igb_request_irq(adapter);
  1520. if (err)
  1521. goto err_req_irq;
  1522. /* From here on the code is the same as igb_up() */
  1523. clear_bit(__IGB_DOWN, &adapter->state);
  1524. for (i = 0; i < adapter->num_rx_queues; i++)
  1525. napi_enable(&adapter->rx_ring[i].napi);
  1526. /* Clear any pending interrupts. */
  1527. rd32(E1000_ICR);
  1528. igb_irq_enable(adapter);
  1529. netif_tx_start_all_queues(netdev);
  1530. /* Fire a link status change interrupt to start the watchdog. */
  1531. wr32(E1000_ICS, E1000_ICS_LSC);
  1532. return 0;
  1533. err_req_irq:
  1534. igb_release_hw_control(adapter);
  1535. /* e1000_power_down_phy(adapter); */
  1536. igb_free_all_rx_resources(adapter);
  1537. err_setup_rx:
  1538. igb_free_all_tx_resources(adapter);
  1539. err_setup_tx:
  1540. igb_reset(adapter);
  1541. return err;
  1542. }
  1543. /**
  1544. * igb_close - Disables a network interface
  1545. * @netdev: network interface device structure
  1546. *
  1547. * Returns 0, this is not allowed to fail
  1548. *
  1549. * The close entry point is called when an interface is de-activated
  1550. * by the OS. The hardware is still under the driver's control, but
  1551. * needs to be disabled. A global MAC reset is issued to stop the
  1552. * hardware, and all transmit and receive resources are freed.
  1553. **/
  1554. static int igb_close(struct net_device *netdev)
  1555. {
  1556. struct igb_adapter *adapter = netdev_priv(netdev);
  1557. WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
  1558. igb_down(adapter);
  1559. igb_free_irq(adapter);
  1560. igb_free_all_tx_resources(adapter);
  1561. igb_free_all_rx_resources(adapter);
  1562. /* kill manageability vlan ID if supported, but not if a vlan with
  1563. * the same ID is registered on the host OS (let 8021q kill it) */
  1564. if ((adapter->hw.mng_cookie.status &
  1565. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  1566. !(adapter->vlgrp &&
  1567. vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id)))
  1568. igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  1569. return 0;
  1570. }
  1571. /**
  1572. * igb_setup_tx_resources - allocate Tx resources (Descriptors)
  1573. * @adapter: board private structure
  1574. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  1575. *
  1576. * Return 0 on success, negative on failure
  1577. **/
  1578. int igb_setup_tx_resources(struct igb_adapter *adapter,
  1579. struct igb_ring *tx_ring)
  1580. {
  1581. struct pci_dev *pdev = adapter->pdev;
  1582. int size;
  1583. size = sizeof(struct igb_buffer) * tx_ring->count;
  1584. tx_ring->buffer_info = vmalloc(size);
  1585. if (!tx_ring->buffer_info)
  1586. goto err;
  1587. memset(tx_ring->buffer_info, 0, size);
  1588. /* round up to nearest 4K */
  1589. tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
  1590. tx_ring->size = ALIGN(tx_ring->size, 4096);
  1591. tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size,
  1592. &tx_ring->dma);
  1593. if (!tx_ring->desc)
  1594. goto err;
  1595. tx_ring->adapter = adapter;
  1596. tx_ring->next_to_use = 0;
  1597. tx_ring->next_to_clean = 0;
  1598. return 0;
  1599. err:
  1600. vfree(tx_ring->buffer_info);
  1601. dev_err(&adapter->pdev->dev,
  1602. "Unable to allocate memory for the transmit descriptor ring\n");
  1603. return -ENOMEM;
  1604. }
  1605. /**
  1606. * igb_setup_all_tx_resources - wrapper to allocate Tx resources
  1607. * (Descriptors) for all queues
  1608. * @adapter: board private structure
  1609. *
  1610. * Return 0 on success, negative on failure
  1611. **/
  1612. static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
  1613. {
  1614. int i, err = 0;
  1615. int r_idx;
  1616. for (i = 0; i < adapter->num_tx_queues; i++) {
  1617. err = igb_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  1618. if (err) {
  1619. dev_err(&adapter->pdev->dev,
  1620. "Allocation for Tx Queue %u failed\n", i);
  1621. for (i--; i >= 0; i--)
  1622. igb_free_tx_resources(&adapter->tx_ring[i]);
  1623. break;
  1624. }
  1625. }
  1626. for (i = 0; i < IGB_MAX_TX_QUEUES; i++) {
  1627. r_idx = i % adapter->num_tx_queues;
  1628. adapter->multi_tx_table[i] = &adapter->tx_ring[r_idx];
  1629. }
  1630. return err;
  1631. }
  1632. /**
  1633. * igb_configure_tx - Configure transmit Unit after Reset
  1634. * @adapter: board private structure
  1635. *
  1636. * Configure the Tx unit of the MAC after a reset.
  1637. **/
  1638. static void igb_configure_tx(struct igb_adapter *adapter)
  1639. {
  1640. u64 tdba;
  1641. struct e1000_hw *hw = &adapter->hw;
  1642. u32 tctl;
  1643. u32 txdctl, txctrl;
  1644. int i, j;
  1645. for (i = 0; i < adapter->num_tx_queues; i++) {
  1646. struct igb_ring *ring = &adapter->tx_ring[i];
  1647. j = ring->reg_idx;
  1648. wr32(E1000_TDLEN(j),
  1649. ring->count * sizeof(union e1000_adv_tx_desc));
  1650. tdba = ring->dma;
  1651. wr32(E1000_TDBAL(j),
  1652. tdba & 0x00000000ffffffffULL);
  1653. wr32(E1000_TDBAH(j), tdba >> 32);
  1654. ring->head = E1000_TDH(j);
  1655. ring->tail = E1000_TDT(j);
  1656. writel(0, hw->hw_addr + ring->tail);
  1657. writel(0, hw->hw_addr + ring->head);
  1658. txdctl = rd32(E1000_TXDCTL(j));
  1659. txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
  1660. wr32(E1000_TXDCTL(j), txdctl);
  1661. /* Turn off Relaxed Ordering on head write-backs. The
  1662. * writebacks MUST be delivered in order or it will
  1663. * completely screw up our bookeeping.
  1664. */
  1665. txctrl = rd32(E1000_DCA_TXCTRL(j));
  1666. txctrl &= ~E1000_DCA_TXCTRL_TX_WB_RO_EN;
  1667. wr32(E1000_DCA_TXCTRL(j), txctrl);
  1668. }
  1669. /* disable queue 0 to prevent tail bump w/o re-configuration */
  1670. if (adapter->vfs_allocated_count)
  1671. wr32(E1000_TXDCTL(0), 0);
  1672. /* Program the Transmit Control Register */
  1673. tctl = rd32(E1000_TCTL);
  1674. tctl &= ~E1000_TCTL_CT;
  1675. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  1676. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  1677. igb_config_collision_dist(hw);
  1678. /* Setup Transmit Descriptor Settings for eop descriptor */
  1679. adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS;
  1680. /* Enable transmits */
  1681. tctl |= E1000_TCTL_EN;
  1682. wr32(E1000_TCTL, tctl);
  1683. }
  1684. /**
  1685. * igb_setup_rx_resources - allocate Rx resources (Descriptors)
  1686. * @adapter: board private structure
  1687. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  1688. *
  1689. * Returns 0 on success, negative on failure
  1690. **/
  1691. int igb_setup_rx_resources(struct igb_adapter *adapter,
  1692. struct igb_ring *rx_ring)
  1693. {
  1694. struct pci_dev *pdev = adapter->pdev;
  1695. int size, desc_len;
  1696. size = sizeof(struct igb_buffer) * rx_ring->count;
  1697. rx_ring->buffer_info = vmalloc(size);
  1698. if (!rx_ring->buffer_info)
  1699. goto err;
  1700. memset(rx_ring->buffer_info, 0, size);
  1701. desc_len = sizeof(union e1000_adv_rx_desc);
  1702. /* Round up to nearest 4K */
  1703. rx_ring->size = rx_ring->count * desc_len;
  1704. rx_ring->size = ALIGN(rx_ring->size, 4096);
  1705. rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size,
  1706. &rx_ring->dma);
  1707. if (!rx_ring->desc)
  1708. goto err;
  1709. rx_ring->next_to_clean = 0;
  1710. rx_ring->next_to_use = 0;
  1711. rx_ring->adapter = adapter;
  1712. return 0;
  1713. err:
  1714. vfree(rx_ring->buffer_info);
  1715. dev_err(&adapter->pdev->dev, "Unable to allocate memory for "
  1716. "the receive descriptor ring\n");
  1717. return -ENOMEM;
  1718. }
  1719. /**
  1720. * igb_setup_all_rx_resources - wrapper to allocate Rx resources
  1721. * (Descriptors) for all queues
  1722. * @adapter: board private structure
  1723. *
  1724. * Return 0 on success, negative on failure
  1725. **/
  1726. static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
  1727. {
  1728. int i, err = 0;
  1729. for (i = 0; i < adapter->num_rx_queues; i++) {
  1730. err = igb_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  1731. if (err) {
  1732. dev_err(&adapter->pdev->dev,
  1733. "Allocation for Rx Queue %u failed\n", i);
  1734. for (i--; i >= 0; i--)
  1735. igb_free_rx_resources(&adapter->rx_ring[i]);
  1736. break;
  1737. }
  1738. }
  1739. return err;
  1740. }
  1741. /**
  1742. * igb_setup_rctl - configure the receive control registers
  1743. * @adapter: Board private structure
  1744. **/
  1745. static void igb_setup_rctl(struct igb_adapter *adapter)
  1746. {
  1747. struct e1000_hw *hw = &adapter->hw;
  1748. u32 rctl;
  1749. u32 srrctl = 0;
  1750. int i;
  1751. rctl = rd32(E1000_RCTL);
  1752. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  1753. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  1754. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
  1755. (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  1756. /*
  1757. * enable stripping of CRC. It's unlikely this will break BMC
  1758. * redirection as it did with e1000. Newer features require
  1759. * that the HW strips the CRC.
  1760. */
  1761. rctl |= E1000_RCTL_SECRC;
  1762. /*
  1763. * disable store bad packets and clear size bits.
  1764. */
  1765. rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
  1766. /* enable LPE when to prevent packets larger than max_frame_size */
  1767. rctl |= E1000_RCTL_LPE;
  1768. /* Setup buffer sizes */
  1769. switch (adapter->rx_buffer_len) {
  1770. case IGB_RXBUFFER_256:
  1771. rctl |= E1000_RCTL_SZ_256;
  1772. break;
  1773. case IGB_RXBUFFER_512:
  1774. rctl |= E1000_RCTL_SZ_512;
  1775. break;
  1776. default:
  1777. srrctl = ALIGN(adapter->rx_buffer_len, 1024)
  1778. >> E1000_SRRCTL_BSIZEPKT_SHIFT;
  1779. break;
  1780. }
  1781. /* 82575 and greater support packet-split where the protocol
  1782. * header is placed in skb->data and the packet data is
  1783. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  1784. * In the case of a non-split, skb->data is linearly filled,
  1785. * followed by the page buffers. Therefore, skb->data is
  1786. * sized to hold the largest protocol header.
  1787. */
  1788. /* allocations using alloc_page take too long for regular MTU
  1789. * so only enable packet split for jumbo frames */
  1790. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  1791. adapter->rx_ps_hdr_size = IGB_RXBUFFER_128;
  1792. srrctl |= adapter->rx_ps_hdr_size <<
  1793. E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
  1794. srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  1795. } else {
  1796. adapter->rx_ps_hdr_size = 0;
  1797. srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
  1798. }
  1799. /* Attention!!! For SR-IOV PF driver operations you must enable
  1800. * queue drop for all VF and PF queues to prevent head of line blocking
  1801. * if an un-trusted VF does not provide descriptors to hardware.
  1802. */
  1803. if (adapter->vfs_allocated_count) {
  1804. u32 vmolr;
  1805. /* set all queue drop enable bits */
  1806. wr32(E1000_QDE, ALL_QUEUES);
  1807. srrctl |= E1000_SRRCTL_DROP_EN;
  1808. /* disable queue 0 to prevent tail write w/o re-config */
  1809. wr32(E1000_RXDCTL(0), 0);
  1810. vmolr = rd32(E1000_VMOLR(adapter->vfs_allocated_count));
  1811. if (rctl & E1000_RCTL_LPE)
  1812. vmolr |= E1000_VMOLR_LPE;
  1813. if (adapter->num_rx_queues > 1)
  1814. vmolr |= E1000_VMOLR_RSSE;
  1815. wr32(E1000_VMOLR(adapter->vfs_allocated_count), vmolr);
  1816. }
  1817. for (i = 0; i < adapter->num_rx_queues; i++) {
  1818. int j = adapter->rx_ring[i].reg_idx;
  1819. wr32(E1000_SRRCTL(j), srrctl);
  1820. }
  1821. wr32(E1000_RCTL, rctl);
  1822. }
  1823. /**
  1824. * igb_rlpml_set - set maximum receive packet size
  1825. * @adapter: board private structure
  1826. *
  1827. * Configure maximum receivable packet size.
  1828. **/
  1829. static void igb_rlpml_set(struct igb_adapter *adapter)
  1830. {
  1831. u32 max_frame_size = adapter->max_frame_size;
  1832. struct e1000_hw *hw = &adapter->hw;
  1833. u16 pf_id = adapter->vfs_allocated_count;
  1834. if (adapter->vlgrp)
  1835. max_frame_size += VLAN_TAG_SIZE;
  1836. /* if vfs are enabled we set RLPML to the largest possible request
  1837. * size and set the VMOLR RLPML to the size we need */
  1838. if (pf_id) {
  1839. igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
  1840. max_frame_size = MAX_STD_JUMBO_FRAME_SIZE + VLAN_TAG_SIZE;
  1841. }
  1842. wr32(E1000_RLPML, max_frame_size);
  1843. }
  1844. /**
  1845. * igb_configure_vt_default_pool - Configure VT default pool
  1846. * @adapter: board private structure
  1847. *
  1848. * Configure the default pool
  1849. **/
  1850. static void igb_configure_vt_default_pool(struct igb_adapter *adapter)
  1851. {
  1852. struct e1000_hw *hw = &adapter->hw;
  1853. u16 pf_id = adapter->vfs_allocated_count;
  1854. u32 vtctl;
  1855. /* not in sr-iov mode - do nothing */
  1856. if (!pf_id)
  1857. return;
  1858. vtctl = rd32(E1000_VT_CTL);
  1859. vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
  1860. E1000_VT_CTL_DISABLE_DEF_POOL);
  1861. vtctl |= pf_id << E1000_VT_CTL_DEFAULT_POOL_SHIFT;
  1862. wr32(E1000_VT_CTL, vtctl);
  1863. }
  1864. /**
  1865. * igb_configure_rx - Configure receive Unit after Reset
  1866. * @adapter: board private structure
  1867. *
  1868. * Configure the Rx unit of the MAC after a reset.
  1869. **/
  1870. static void igb_configure_rx(struct igb_adapter *adapter)
  1871. {
  1872. u64 rdba;
  1873. struct e1000_hw *hw = &adapter->hw;
  1874. u32 rctl, rxcsum;
  1875. u32 rxdctl;
  1876. int i;
  1877. /* disable receives while setting up the descriptors */
  1878. rctl = rd32(E1000_RCTL);
  1879. wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
  1880. wrfl();
  1881. mdelay(10);
  1882. if (adapter->itr_setting > 3)
  1883. wr32(E1000_ITR, adapter->itr);
  1884. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  1885. * the Base and Length of the Rx Descriptor Ring */
  1886. for (i = 0; i < adapter->num_rx_queues; i++) {
  1887. struct igb_ring *ring = &adapter->rx_ring[i];
  1888. int j = ring->reg_idx;
  1889. rdba = ring->dma;
  1890. wr32(E1000_RDBAL(j),
  1891. rdba & 0x00000000ffffffffULL);
  1892. wr32(E1000_RDBAH(j), rdba >> 32);
  1893. wr32(E1000_RDLEN(j),
  1894. ring->count * sizeof(union e1000_adv_rx_desc));
  1895. ring->head = E1000_RDH(j);
  1896. ring->tail = E1000_RDT(j);
  1897. writel(0, hw->hw_addr + ring->tail);
  1898. writel(0, hw->hw_addr + ring->head);
  1899. rxdctl = rd32(E1000_RXDCTL(j));
  1900. rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
  1901. rxdctl &= 0xFFF00000;
  1902. rxdctl |= IGB_RX_PTHRESH;
  1903. rxdctl |= IGB_RX_HTHRESH << 8;
  1904. rxdctl |= IGB_RX_WTHRESH << 16;
  1905. wr32(E1000_RXDCTL(j), rxdctl);
  1906. }
  1907. if (adapter->num_rx_queues > 1) {
  1908. u32 random[10];
  1909. u32 mrqc;
  1910. u32 j, shift;
  1911. union e1000_reta {
  1912. u32 dword;
  1913. u8 bytes[4];
  1914. } reta;
  1915. get_random_bytes(&random[0], 40);
  1916. if (hw->mac.type >= e1000_82576)
  1917. shift = 0;
  1918. else
  1919. shift = 6;
  1920. for (j = 0; j < (32 * 4); j++) {
  1921. reta.bytes[j & 3] =
  1922. adapter->rx_ring[(j % adapter->num_rx_queues)].reg_idx << shift;
  1923. if ((j & 3) == 3)
  1924. writel(reta.dword,
  1925. hw->hw_addr + E1000_RETA(0) + (j & ~3));
  1926. }
  1927. if (adapter->vfs_allocated_count)
  1928. mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
  1929. else
  1930. mrqc = E1000_MRQC_ENABLE_RSS_4Q;
  1931. /* Fill out hash function seeds */
  1932. for (j = 0; j < 10; j++)
  1933. array_wr32(E1000_RSSRK(0), j, random[j]);
  1934. mrqc |= (E1000_MRQC_RSS_FIELD_IPV4 |
  1935. E1000_MRQC_RSS_FIELD_IPV4_TCP);
  1936. mrqc |= (E1000_MRQC_RSS_FIELD_IPV6 |
  1937. E1000_MRQC_RSS_FIELD_IPV6_TCP);
  1938. mrqc |= (E1000_MRQC_RSS_FIELD_IPV4_UDP |
  1939. E1000_MRQC_RSS_FIELD_IPV6_UDP);
  1940. mrqc |= (E1000_MRQC_RSS_FIELD_IPV6_UDP_EX |
  1941. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
  1942. wr32(E1000_MRQC, mrqc);
  1943. } else if (adapter->vfs_allocated_count) {
  1944. /* Enable multi-queue for sr-iov */
  1945. wr32(E1000_MRQC, E1000_MRQC_ENABLE_VMDQ);
  1946. }
  1947. /* Enable Receive Checksum Offload for TCP and UDP */
  1948. rxcsum = rd32(E1000_RXCSUM);
  1949. /* Disable raw packet checksumming */
  1950. rxcsum |= E1000_RXCSUM_PCSD;
  1951. if (adapter->hw.mac.type == e1000_82576)
  1952. /* Enable Receive Checksum Offload for SCTP */
  1953. rxcsum |= E1000_RXCSUM_CRCOFL;
  1954. /* Don't need to set TUOFL or IPOFL, they default to 1 */
  1955. wr32(E1000_RXCSUM, rxcsum);
  1956. /* Set the default pool for the PF's first queue */
  1957. igb_configure_vt_default_pool(adapter);
  1958. igb_rlpml_set(adapter);
  1959. /* Enable Receives */
  1960. wr32(E1000_RCTL, rctl);
  1961. }
  1962. /**
  1963. * igb_free_tx_resources - Free Tx Resources per Queue
  1964. * @tx_ring: Tx descriptor ring for a specific queue
  1965. *
  1966. * Free all transmit software resources
  1967. **/
  1968. void igb_free_tx_resources(struct igb_ring *tx_ring)
  1969. {
  1970. struct pci_dev *pdev = tx_ring->adapter->pdev;
  1971. igb_clean_tx_ring(tx_ring);
  1972. vfree(tx_ring->buffer_info);
  1973. tx_ring->buffer_info = NULL;
  1974. pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
  1975. tx_ring->desc = NULL;
  1976. }
  1977. /**
  1978. * igb_free_all_tx_resources - Free Tx Resources for All Queues
  1979. * @adapter: board private structure
  1980. *
  1981. * Free all transmit software resources
  1982. **/
  1983. static void igb_free_all_tx_resources(struct igb_adapter *adapter)
  1984. {
  1985. int i;
  1986. for (i = 0; i < adapter->num_tx_queues; i++)
  1987. igb_free_tx_resources(&adapter->tx_ring[i]);
  1988. }
  1989. static void igb_unmap_and_free_tx_resource(struct igb_adapter *adapter,
  1990. struct igb_buffer *buffer_info)
  1991. {
  1992. buffer_info->dma = 0;
  1993. if (buffer_info->skb) {
  1994. skb_dma_unmap(&adapter->pdev->dev, buffer_info->skb,
  1995. DMA_TO_DEVICE);
  1996. dev_kfree_skb_any(buffer_info->skb);
  1997. buffer_info->skb = NULL;
  1998. }
  1999. buffer_info->time_stamp = 0;
  2000. /* buffer_info must be completely set up in the transmit path */
  2001. }
  2002. /**
  2003. * igb_clean_tx_ring - Free Tx Buffers
  2004. * @tx_ring: ring to be cleaned
  2005. **/
  2006. static void igb_clean_tx_ring(struct igb_ring *tx_ring)
  2007. {
  2008. struct igb_adapter *adapter = tx_ring->adapter;
  2009. struct igb_buffer *buffer_info;
  2010. unsigned long size;
  2011. unsigned int i;
  2012. if (!tx_ring->buffer_info)
  2013. return;
  2014. /* Free all the Tx ring sk_buffs */
  2015. for (i = 0; i < tx_ring->count; i++) {
  2016. buffer_info = &tx_ring->buffer_info[i];
  2017. igb_unmap_and_free_tx_resource(adapter, buffer_info);
  2018. }
  2019. size = sizeof(struct igb_buffer) * tx_ring->count;
  2020. memset(tx_ring->buffer_info, 0, size);
  2021. /* Zero out the descriptor ring */
  2022. memset(tx_ring->desc, 0, tx_ring->size);
  2023. tx_ring->next_to_use = 0;
  2024. tx_ring->next_to_clean = 0;
  2025. writel(0, adapter->hw.hw_addr + tx_ring->head);
  2026. writel(0, adapter->hw.hw_addr + tx_ring->tail);
  2027. }
  2028. /**
  2029. * igb_clean_all_tx_rings - Free Tx Buffers for all queues
  2030. * @adapter: board private structure
  2031. **/
  2032. static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
  2033. {
  2034. int i;
  2035. for (i = 0; i < adapter->num_tx_queues; i++)
  2036. igb_clean_tx_ring(&adapter->tx_ring[i]);
  2037. }
  2038. /**
  2039. * igb_free_rx_resources - Free Rx Resources
  2040. * @rx_ring: ring to clean the resources from
  2041. *
  2042. * Free all receive software resources
  2043. **/
  2044. void igb_free_rx_resources(struct igb_ring *rx_ring)
  2045. {
  2046. struct pci_dev *pdev = rx_ring->adapter->pdev;
  2047. igb_clean_rx_ring(rx_ring);
  2048. vfree(rx_ring->buffer_info);
  2049. rx_ring->buffer_info = NULL;
  2050. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  2051. rx_ring->desc = NULL;
  2052. }
  2053. /**
  2054. * igb_free_all_rx_resources - Free Rx Resources for All Queues
  2055. * @adapter: board private structure
  2056. *
  2057. * Free all receive software resources
  2058. **/
  2059. static void igb_free_all_rx_resources(struct igb_adapter *adapter)
  2060. {
  2061. int i;
  2062. for (i = 0; i < adapter->num_rx_queues; i++)
  2063. igb_free_rx_resources(&adapter->rx_ring[i]);
  2064. }
  2065. /**
  2066. * igb_clean_rx_ring - Free Rx Buffers per Queue
  2067. * @rx_ring: ring to free buffers from
  2068. **/
  2069. static void igb_clean_rx_ring(struct igb_ring *rx_ring)
  2070. {
  2071. struct igb_adapter *adapter = rx_ring->adapter;
  2072. struct igb_buffer *buffer_info;
  2073. struct pci_dev *pdev = adapter->pdev;
  2074. unsigned long size;
  2075. unsigned int i;
  2076. if (!rx_ring->buffer_info)
  2077. return;
  2078. /* Free all the Rx ring sk_buffs */
  2079. for (i = 0; i < rx_ring->count; i++) {
  2080. buffer_info = &rx_ring->buffer_info[i];
  2081. if (buffer_info->dma) {
  2082. if (adapter->rx_ps_hdr_size)
  2083. pci_unmap_single(pdev, buffer_info->dma,
  2084. adapter->rx_ps_hdr_size,
  2085. PCI_DMA_FROMDEVICE);
  2086. else
  2087. pci_unmap_single(pdev, buffer_info->dma,
  2088. adapter->rx_buffer_len,
  2089. PCI_DMA_FROMDEVICE);
  2090. buffer_info->dma = 0;
  2091. }
  2092. if (buffer_info->skb) {
  2093. dev_kfree_skb(buffer_info->skb);
  2094. buffer_info->skb = NULL;
  2095. }
  2096. if (buffer_info->page) {
  2097. if (buffer_info->page_dma)
  2098. pci_unmap_page(pdev, buffer_info->page_dma,
  2099. PAGE_SIZE / 2,
  2100. PCI_DMA_FROMDEVICE);
  2101. put_page(buffer_info->page);
  2102. buffer_info->page = NULL;
  2103. buffer_info->page_dma = 0;
  2104. buffer_info->page_offset = 0;
  2105. }
  2106. }
  2107. size = sizeof(struct igb_buffer) * rx_ring->count;
  2108. memset(rx_ring->buffer_info, 0, size);
  2109. /* Zero out the descriptor ring */
  2110. memset(rx_ring->desc, 0, rx_ring->size);
  2111. rx_ring->next_to_clean = 0;
  2112. rx_ring->next_to_use = 0;
  2113. writel(0, adapter->hw.hw_addr + rx_ring->head);
  2114. writel(0, adapter->hw.hw_addr + rx_ring->tail);
  2115. }
  2116. /**
  2117. * igb_clean_all_rx_rings - Free Rx Buffers for all queues
  2118. * @adapter: board private structure
  2119. **/
  2120. static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
  2121. {
  2122. int i;
  2123. for (i = 0; i < adapter->num_rx_queues; i++)
  2124. igb_clean_rx_ring(&adapter->rx_ring[i]);
  2125. }
  2126. /**
  2127. * igb_set_mac - Change the Ethernet Address of the NIC
  2128. * @netdev: network interface device structure
  2129. * @p: pointer to an address structure
  2130. *
  2131. * Returns 0 on success, negative on failure
  2132. **/
  2133. static int igb_set_mac(struct net_device *netdev, void *p)
  2134. {
  2135. struct igb_adapter *adapter = netdev_priv(netdev);
  2136. struct e1000_hw *hw = &adapter->hw;
  2137. struct sockaddr *addr = p;
  2138. if (!is_valid_ether_addr(addr->sa_data))
  2139. return -EADDRNOTAVAIL;
  2140. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2141. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  2142. igb_rar_set(hw, hw->mac.addr, 0);
  2143. igb_set_rah_pool(hw, adapter->vfs_allocated_count, 0);
  2144. return 0;
  2145. }
  2146. /**
  2147. * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
  2148. * @netdev: network interface device structure
  2149. *
  2150. * The set_rx_mode entry point is called whenever the unicast or multicast
  2151. * address lists or the network interface flags are updated. This routine is
  2152. * responsible for configuring the hardware for proper unicast, multicast,
  2153. * promiscuous mode, and all-multi behavior.
  2154. **/
  2155. static void igb_set_rx_mode(struct net_device *netdev)
  2156. {
  2157. struct igb_adapter *adapter = netdev_priv(netdev);
  2158. struct e1000_hw *hw = &adapter->hw;
  2159. unsigned int rar_entries = hw->mac.rar_entry_count -
  2160. (adapter->vfs_allocated_count + 1);
  2161. struct dev_mc_list *mc_ptr = netdev->mc_list;
  2162. u8 *mta_list = NULL;
  2163. u32 rctl;
  2164. int i;
  2165. /* Check for Promiscuous and All Multicast modes */
  2166. rctl = rd32(E1000_RCTL);
  2167. if (netdev->flags & IFF_PROMISC) {
  2168. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  2169. rctl &= ~E1000_RCTL_VFE;
  2170. } else {
  2171. if (netdev->flags & IFF_ALLMULTI)
  2172. rctl |= E1000_RCTL_MPE;
  2173. else
  2174. rctl &= ~E1000_RCTL_MPE;
  2175. if (netdev->uc.count > rar_entries)
  2176. rctl |= E1000_RCTL_UPE;
  2177. else
  2178. rctl &= ~E1000_RCTL_UPE;
  2179. rctl |= E1000_RCTL_VFE;
  2180. }
  2181. wr32(E1000_RCTL, rctl);
  2182. if (netdev->uc.count && rar_entries) {
  2183. struct netdev_hw_addr *ha;
  2184. list_for_each_entry(ha, &netdev->uc.list, list) {
  2185. if (!rar_entries)
  2186. break;
  2187. igb_rar_set(hw, ha->addr, rar_entries);
  2188. igb_set_rah_pool(hw, adapter->vfs_allocated_count,
  2189. rar_entries);
  2190. rar_entries--;
  2191. }
  2192. }
  2193. /* write the addresses in reverse order to avoid write combining */
  2194. for (; rar_entries > 0 ; rar_entries--) {
  2195. wr32(E1000_RAH(rar_entries), 0);
  2196. wr32(E1000_RAL(rar_entries), 0);
  2197. }
  2198. wrfl();
  2199. if (!netdev->mc_count) {
  2200. /* nothing to program, so clear mc list */
  2201. igb_update_mc_addr_list(hw, NULL, 0);
  2202. igb_restore_vf_multicasts(adapter);
  2203. return;
  2204. }
  2205. mta_list = kzalloc(netdev->mc_count * 6, GFP_ATOMIC);
  2206. if (!mta_list) {
  2207. dev_err(&adapter->pdev->dev,
  2208. "failed to allocate multicast filter list\n");
  2209. return;
  2210. }
  2211. /* The shared function expects a packed array of only addresses. */
  2212. for (i = 0; i < netdev->mc_count; i++) {
  2213. if (!mc_ptr)
  2214. break;
  2215. memcpy(mta_list + (i*ETH_ALEN), mc_ptr->dmi_addr, ETH_ALEN);
  2216. mc_ptr = mc_ptr->next;
  2217. }
  2218. igb_update_mc_addr_list(hw, mta_list, i);
  2219. kfree(mta_list);
  2220. igb_restore_vf_multicasts(adapter);
  2221. }
  2222. /* Need to wait a few seconds after link up to get diagnostic information from
  2223. * the phy */
  2224. static void igb_update_phy_info(unsigned long data)
  2225. {
  2226. struct igb_adapter *adapter = (struct igb_adapter *) data;
  2227. igb_get_phy_info(&adapter->hw);
  2228. }
  2229. /**
  2230. * igb_has_link - check shared code for link and determine up/down
  2231. * @adapter: pointer to driver private info
  2232. **/
  2233. static bool igb_has_link(struct igb_adapter *adapter)
  2234. {
  2235. struct e1000_hw *hw = &adapter->hw;
  2236. bool link_active = false;
  2237. s32 ret_val = 0;
  2238. /* get_link_status is set on LSC (link status) interrupt or
  2239. * rx sequence error interrupt. get_link_status will stay
  2240. * false until the e1000_check_for_link establishes link
  2241. * for copper adapters ONLY
  2242. */
  2243. switch (hw->phy.media_type) {
  2244. case e1000_media_type_copper:
  2245. if (hw->mac.get_link_status) {
  2246. ret_val = hw->mac.ops.check_for_link(hw);
  2247. link_active = !hw->mac.get_link_status;
  2248. } else {
  2249. link_active = true;
  2250. }
  2251. break;
  2252. case e1000_media_type_internal_serdes:
  2253. ret_val = hw->mac.ops.check_for_link(hw);
  2254. link_active = hw->mac.serdes_has_link;
  2255. break;
  2256. default:
  2257. case e1000_media_type_unknown:
  2258. break;
  2259. }
  2260. return link_active;
  2261. }
  2262. /**
  2263. * igb_watchdog - Timer Call-back
  2264. * @data: pointer to adapter cast into an unsigned long
  2265. **/
  2266. static void igb_watchdog(unsigned long data)
  2267. {
  2268. struct igb_adapter *adapter = (struct igb_adapter *)data;
  2269. /* Do the rest outside of interrupt context */
  2270. schedule_work(&adapter->watchdog_task);
  2271. }
  2272. static void igb_watchdog_task(struct work_struct *work)
  2273. {
  2274. struct igb_adapter *adapter = container_of(work,
  2275. struct igb_adapter, watchdog_task);
  2276. struct e1000_hw *hw = &adapter->hw;
  2277. struct net_device *netdev = adapter->netdev;
  2278. struct igb_ring *tx_ring = adapter->tx_ring;
  2279. u32 link;
  2280. u32 eics = 0;
  2281. int i;
  2282. link = igb_has_link(adapter);
  2283. if ((netif_carrier_ok(netdev)) && link)
  2284. goto link_up;
  2285. if (link) {
  2286. if (!netif_carrier_ok(netdev)) {
  2287. u32 ctrl;
  2288. hw->mac.ops.get_speed_and_duplex(&adapter->hw,
  2289. &adapter->link_speed,
  2290. &adapter->link_duplex);
  2291. ctrl = rd32(E1000_CTRL);
  2292. /* Links status message must follow this format */
  2293. printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
  2294. "Flow Control: %s\n",
  2295. netdev->name,
  2296. adapter->link_speed,
  2297. adapter->link_duplex == FULL_DUPLEX ?
  2298. "Full Duplex" : "Half Duplex",
  2299. ((ctrl & E1000_CTRL_TFCE) && (ctrl &
  2300. E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
  2301. E1000_CTRL_RFCE) ? "RX" : ((ctrl &
  2302. E1000_CTRL_TFCE) ? "TX" : "None")));
  2303. /* tweak tx_queue_len according to speed/duplex and
  2304. * adjust the timeout factor */
  2305. netdev->tx_queue_len = adapter->tx_queue_len;
  2306. adapter->tx_timeout_factor = 1;
  2307. switch (adapter->link_speed) {
  2308. case SPEED_10:
  2309. netdev->tx_queue_len = 10;
  2310. adapter->tx_timeout_factor = 14;
  2311. break;
  2312. case SPEED_100:
  2313. netdev->tx_queue_len = 100;
  2314. /* maybe add some timeout factor ? */
  2315. break;
  2316. }
  2317. netif_carrier_on(netdev);
  2318. igb_ping_all_vfs(adapter);
  2319. /* link state has changed, schedule phy info update */
  2320. if (!test_bit(__IGB_DOWN, &adapter->state))
  2321. mod_timer(&adapter->phy_info_timer,
  2322. round_jiffies(jiffies + 2 * HZ));
  2323. }
  2324. } else {
  2325. if (netif_carrier_ok(netdev)) {
  2326. adapter->link_speed = 0;
  2327. adapter->link_duplex = 0;
  2328. /* Links status message must follow this format */
  2329. printk(KERN_INFO "igb: %s NIC Link is Down\n",
  2330. netdev->name);
  2331. netif_carrier_off(netdev);
  2332. igb_ping_all_vfs(adapter);
  2333. /* link state has changed, schedule phy info update */
  2334. if (!test_bit(__IGB_DOWN, &adapter->state))
  2335. mod_timer(&adapter->phy_info_timer,
  2336. round_jiffies(jiffies + 2 * HZ));
  2337. }
  2338. }
  2339. link_up:
  2340. igb_update_stats(adapter);
  2341. hw->mac.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  2342. adapter->tpt_old = adapter->stats.tpt;
  2343. hw->mac.collision_delta = adapter->stats.colc - adapter->colc_old;
  2344. adapter->colc_old = adapter->stats.colc;
  2345. adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
  2346. adapter->gorc_old = adapter->stats.gorc;
  2347. adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
  2348. adapter->gotc_old = adapter->stats.gotc;
  2349. igb_update_adaptive(&adapter->hw);
  2350. if (!netif_carrier_ok(netdev)) {
  2351. if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
  2352. /* We've lost link, so the controller stops DMA,
  2353. * but we've got queued Tx work that's never going
  2354. * to get done, so reset controller to flush Tx.
  2355. * (Do the reset outside of interrupt context). */
  2356. adapter->tx_timeout_count++;
  2357. schedule_work(&adapter->reset_task);
  2358. /* return immediately since reset is imminent */
  2359. return;
  2360. }
  2361. }
  2362. /* Cause software interrupt to ensure rx ring is cleaned */
  2363. if (adapter->msix_entries) {
  2364. for (i = 0; i < adapter->num_rx_queues; i++)
  2365. eics |= adapter->rx_ring[i].eims_value;
  2366. wr32(E1000_EICS, eics);
  2367. } else {
  2368. wr32(E1000_ICS, E1000_ICS_RXDMT0);
  2369. }
  2370. /* Force detection of hung controller every watchdog period */
  2371. tx_ring->detect_tx_hung = true;
  2372. /* Reset the timer */
  2373. if (!test_bit(__IGB_DOWN, &adapter->state))
  2374. mod_timer(&adapter->watchdog_timer,
  2375. round_jiffies(jiffies + 2 * HZ));
  2376. }
  2377. enum latency_range {
  2378. lowest_latency = 0,
  2379. low_latency = 1,
  2380. bulk_latency = 2,
  2381. latency_invalid = 255
  2382. };
  2383. /**
  2384. * igb_update_ring_itr - update the dynamic ITR value based on packet size
  2385. *
  2386. * Stores a new ITR value based on strictly on packet size. This
  2387. * algorithm is less sophisticated than that used in igb_update_itr,
  2388. * due to the difficulty of synchronizing statistics across multiple
  2389. * receive rings. The divisors and thresholds used by this fuction
  2390. * were determined based on theoretical maximum wire speed and testing
  2391. * data, in order to minimize response time while increasing bulk
  2392. * throughput.
  2393. * This functionality is controlled by the InterruptThrottleRate module
  2394. * parameter (see igb_param.c)
  2395. * NOTE: This function is called only when operating in a multiqueue
  2396. * receive environment.
  2397. * @rx_ring: pointer to ring
  2398. **/
  2399. static void igb_update_ring_itr(struct igb_ring *rx_ring)
  2400. {
  2401. int new_val = rx_ring->itr_val;
  2402. int avg_wire_size = 0;
  2403. struct igb_adapter *adapter = rx_ring->adapter;
  2404. if (!rx_ring->total_packets)
  2405. goto clear_counts; /* no packets, so don't do anything */
  2406. /* For non-gigabit speeds, just fix the interrupt rate at 4000
  2407. * ints/sec - ITR timer value of 120 ticks.
  2408. */
  2409. if (adapter->link_speed != SPEED_1000) {
  2410. new_val = 120;
  2411. goto set_itr_val;
  2412. }
  2413. avg_wire_size = rx_ring->total_bytes / rx_ring->total_packets;
  2414. /* Add 24 bytes to size to account for CRC, preamble, and gap */
  2415. avg_wire_size += 24;
  2416. /* Don't starve jumbo frames */
  2417. avg_wire_size = min(avg_wire_size, 3000);
  2418. /* Give a little boost to mid-size frames */
  2419. if ((avg_wire_size > 300) && (avg_wire_size < 1200))
  2420. new_val = avg_wire_size / 3;
  2421. else
  2422. new_val = avg_wire_size / 2;
  2423. set_itr_val:
  2424. if (new_val != rx_ring->itr_val) {
  2425. rx_ring->itr_val = new_val;
  2426. rx_ring->set_itr = 1;
  2427. }
  2428. clear_counts:
  2429. rx_ring->total_bytes = 0;
  2430. rx_ring->total_packets = 0;
  2431. }
  2432. /**
  2433. * igb_update_itr - update the dynamic ITR value based on statistics
  2434. * Stores a new ITR value based on packets and byte
  2435. * counts during the last interrupt. The advantage of per interrupt
  2436. * computation is faster updates and more accurate ITR for the current
  2437. * traffic pattern. Constants in this function were computed
  2438. * based on theoretical maximum wire speed and thresholds were set based
  2439. * on testing data as well as attempting to minimize response time
  2440. * while increasing bulk throughput.
  2441. * this functionality is controlled by the InterruptThrottleRate module
  2442. * parameter (see igb_param.c)
  2443. * NOTE: These calculations are only valid when operating in a single-
  2444. * queue environment.
  2445. * @adapter: pointer to adapter
  2446. * @itr_setting: current adapter->itr
  2447. * @packets: the number of packets during this measurement interval
  2448. * @bytes: the number of bytes during this measurement interval
  2449. **/
  2450. static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
  2451. int packets, int bytes)
  2452. {
  2453. unsigned int retval = itr_setting;
  2454. if (packets == 0)
  2455. goto update_itr_done;
  2456. switch (itr_setting) {
  2457. case lowest_latency:
  2458. /* handle TSO and jumbo frames */
  2459. if (bytes/packets > 8000)
  2460. retval = bulk_latency;
  2461. else if ((packets < 5) && (bytes > 512))
  2462. retval = low_latency;
  2463. break;
  2464. case low_latency: /* 50 usec aka 20000 ints/s */
  2465. if (bytes > 10000) {
  2466. /* this if handles the TSO accounting */
  2467. if (bytes/packets > 8000) {
  2468. retval = bulk_latency;
  2469. } else if ((packets < 10) || ((bytes/packets) > 1200)) {
  2470. retval = bulk_latency;
  2471. } else if ((packets > 35)) {
  2472. retval = lowest_latency;
  2473. }
  2474. } else if (bytes/packets > 2000) {
  2475. retval = bulk_latency;
  2476. } else if (packets <= 2 && bytes < 512) {
  2477. retval = lowest_latency;
  2478. }
  2479. break;
  2480. case bulk_latency: /* 250 usec aka 4000 ints/s */
  2481. if (bytes > 25000) {
  2482. if (packets > 35)
  2483. retval = low_latency;
  2484. } else if (bytes < 1500) {
  2485. retval = low_latency;
  2486. }
  2487. break;
  2488. }
  2489. update_itr_done:
  2490. return retval;
  2491. }
  2492. static void igb_set_itr(struct igb_adapter *adapter)
  2493. {
  2494. u16 current_itr;
  2495. u32 new_itr = adapter->itr;
  2496. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  2497. if (adapter->link_speed != SPEED_1000) {
  2498. current_itr = 0;
  2499. new_itr = 4000;
  2500. goto set_itr_now;
  2501. }
  2502. adapter->rx_itr = igb_update_itr(adapter,
  2503. adapter->rx_itr,
  2504. adapter->rx_ring->total_packets,
  2505. adapter->rx_ring->total_bytes);
  2506. if (adapter->rx_ring->buddy) {
  2507. adapter->tx_itr = igb_update_itr(adapter,
  2508. adapter->tx_itr,
  2509. adapter->tx_ring->total_packets,
  2510. adapter->tx_ring->total_bytes);
  2511. current_itr = max(adapter->rx_itr, adapter->tx_itr);
  2512. } else {
  2513. current_itr = adapter->rx_itr;
  2514. }
  2515. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2516. if (adapter->itr_setting == 3 && current_itr == lowest_latency)
  2517. current_itr = low_latency;
  2518. switch (current_itr) {
  2519. /* counts and packets in update_itr are dependent on these numbers */
  2520. case lowest_latency:
  2521. new_itr = 56; /* aka 70,000 ints/sec */
  2522. break;
  2523. case low_latency:
  2524. new_itr = 196; /* aka 20,000 ints/sec */
  2525. break;
  2526. case bulk_latency:
  2527. new_itr = 980; /* aka 4,000 ints/sec */
  2528. break;
  2529. default:
  2530. break;
  2531. }
  2532. set_itr_now:
  2533. adapter->rx_ring->total_bytes = 0;
  2534. adapter->rx_ring->total_packets = 0;
  2535. if (adapter->rx_ring->buddy) {
  2536. adapter->rx_ring->buddy->total_bytes = 0;
  2537. adapter->rx_ring->buddy->total_packets = 0;
  2538. }
  2539. if (new_itr != adapter->itr) {
  2540. /* this attempts to bias the interrupt rate towards Bulk
  2541. * by adding intermediate steps when interrupt rate is
  2542. * increasing */
  2543. new_itr = new_itr > adapter->itr ?
  2544. max((new_itr * adapter->itr) /
  2545. (new_itr + (adapter->itr >> 2)), new_itr) :
  2546. new_itr;
  2547. /* Don't write the value here; it resets the adapter's
  2548. * internal timer, and causes us to delay far longer than
  2549. * we should between interrupts. Instead, we write the ITR
  2550. * value at the beginning of the next interrupt so the timing
  2551. * ends up being correct.
  2552. */
  2553. adapter->itr = new_itr;
  2554. adapter->rx_ring->itr_val = new_itr;
  2555. adapter->rx_ring->set_itr = 1;
  2556. }
  2557. return;
  2558. }
  2559. #define IGB_TX_FLAGS_CSUM 0x00000001
  2560. #define IGB_TX_FLAGS_VLAN 0x00000002
  2561. #define IGB_TX_FLAGS_TSO 0x00000004
  2562. #define IGB_TX_FLAGS_IPV4 0x00000008
  2563. #define IGB_TX_FLAGS_TSTAMP 0x00000010
  2564. #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
  2565. #define IGB_TX_FLAGS_VLAN_SHIFT 16
  2566. static inline int igb_tso_adv(struct igb_adapter *adapter,
  2567. struct igb_ring *tx_ring,
  2568. struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
  2569. {
  2570. struct e1000_adv_tx_context_desc *context_desc;
  2571. unsigned int i;
  2572. int err;
  2573. struct igb_buffer *buffer_info;
  2574. u32 info = 0, tu_cmd = 0;
  2575. u32 mss_l4len_idx, l4len;
  2576. *hdr_len = 0;
  2577. if (skb_header_cloned(skb)) {
  2578. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  2579. if (err)
  2580. return err;
  2581. }
  2582. l4len = tcp_hdrlen(skb);
  2583. *hdr_len += l4len;
  2584. if (skb->protocol == htons(ETH_P_IP)) {
  2585. struct iphdr *iph = ip_hdr(skb);
  2586. iph->tot_len = 0;
  2587. iph->check = 0;
  2588. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  2589. iph->daddr, 0,
  2590. IPPROTO_TCP,
  2591. 0);
  2592. } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) {
  2593. ipv6_hdr(skb)->payload_len = 0;
  2594. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  2595. &ipv6_hdr(skb)->daddr,
  2596. 0, IPPROTO_TCP, 0);
  2597. }
  2598. i = tx_ring->next_to_use;
  2599. buffer_info = &tx_ring->buffer_info[i];
  2600. context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
  2601. /* VLAN MACLEN IPLEN */
  2602. if (tx_flags & IGB_TX_FLAGS_VLAN)
  2603. info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
  2604. info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
  2605. *hdr_len += skb_network_offset(skb);
  2606. info |= skb_network_header_len(skb);
  2607. *hdr_len += skb_network_header_len(skb);
  2608. context_desc->vlan_macip_lens = cpu_to_le32(info);
  2609. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  2610. tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
  2611. if (skb->protocol == htons(ETH_P_IP))
  2612. tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
  2613. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  2614. context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
  2615. /* MSS L4LEN IDX */
  2616. mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
  2617. mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
  2618. /* For 82575, context index must be unique per ring. */
  2619. if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
  2620. mss_l4len_idx |= tx_ring->queue_index << 4;
  2621. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  2622. context_desc->seqnum_seed = 0;
  2623. buffer_info->time_stamp = jiffies;
  2624. buffer_info->next_to_watch = i;
  2625. buffer_info->dma = 0;
  2626. i++;
  2627. if (i == tx_ring->count)
  2628. i = 0;
  2629. tx_ring->next_to_use = i;
  2630. return true;
  2631. }
  2632. static inline bool igb_tx_csum_adv(struct igb_adapter *adapter,
  2633. struct igb_ring *tx_ring,
  2634. struct sk_buff *skb, u32 tx_flags)
  2635. {
  2636. struct e1000_adv_tx_context_desc *context_desc;
  2637. unsigned int i;
  2638. struct igb_buffer *buffer_info;
  2639. u32 info = 0, tu_cmd = 0;
  2640. if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
  2641. (tx_flags & IGB_TX_FLAGS_VLAN)) {
  2642. i = tx_ring->next_to_use;
  2643. buffer_info = &tx_ring->buffer_info[i];
  2644. context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
  2645. if (tx_flags & IGB_TX_FLAGS_VLAN)
  2646. info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
  2647. info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
  2648. if (skb->ip_summed == CHECKSUM_PARTIAL)
  2649. info |= skb_network_header_len(skb);
  2650. context_desc->vlan_macip_lens = cpu_to_le32(info);
  2651. tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
  2652. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2653. __be16 protocol;
  2654. if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
  2655. const struct vlan_ethhdr *vhdr =
  2656. (const struct vlan_ethhdr*)skb->data;
  2657. protocol = vhdr->h_vlan_encapsulated_proto;
  2658. } else {
  2659. protocol = skb->protocol;
  2660. }
  2661. switch (protocol) {
  2662. case cpu_to_be16(ETH_P_IP):
  2663. tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
  2664. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  2665. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  2666. else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
  2667. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
  2668. break;
  2669. case cpu_to_be16(ETH_P_IPV6):
  2670. /* XXX what about other V6 headers?? */
  2671. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  2672. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  2673. else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
  2674. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
  2675. break;
  2676. default:
  2677. if (unlikely(net_ratelimit()))
  2678. dev_warn(&adapter->pdev->dev,
  2679. "partial checksum but proto=%x!\n",
  2680. skb->protocol);
  2681. break;
  2682. }
  2683. }
  2684. context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
  2685. context_desc->seqnum_seed = 0;
  2686. if (adapter->flags & IGB_FLAG_NEED_CTX_IDX)
  2687. context_desc->mss_l4len_idx =
  2688. cpu_to_le32(tx_ring->queue_index << 4);
  2689. else
  2690. context_desc->mss_l4len_idx = 0;
  2691. buffer_info->time_stamp = jiffies;
  2692. buffer_info->next_to_watch = i;
  2693. buffer_info->dma = 0;
  2694. i++;
  2695. if (i == tx_ring->count)
  2696. i = 0;
  2697. tx_ring->next_to_use = i;
  2698. return true;
  2699. }
  2700. return false;
  2701. }
  2702. #define IGB_MAX_TXD_PWR 16
  2703. #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
  2704. static inline int igb_tx_map_adv(struct igb_adapter *adapter,
  2705. struct igb_ring *tx_ring, struct sk_buff *skb,
  2706. unsigned int first)
  2707. {
  2708. struct igb_buffer *buffer_info;
  2709. unsigned int len = skb_headlen(skb);
  2710. unsigned int count = 0, i;
  2711. unsigned int f;
  2712. dma_addr_t *map;
  2713. i = tx_ring->next_to_use;
  2714. if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) {
  2715. dev_err(&adapter->pdev->dev, "TX DMA map failed\n");
  2716. return 0;
  2717. }
  2718. map = skb_shinfo(skb)->dma_maps;
  2719. buffer_info = &tx_ring->buffer_info[i];
  2720. BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
  2721. buffer_info->length = len;
  2722. /* set time_stamp *before* dma to help avoid a possible race */
  2723. buffer_info->time_stamp = jiffies;
  2724. buffer_info->next_to_watch = i;
  2725. buffer_info->dma = skb_shinfo(skb)->dma_head;
  2726. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
  2727. struct skb_frag_struct *frag;
  2728. i++;
  2729. if (i == tx_ring->count)
  2730. i = 0;
  2731. frag = &skb_shinfo(skb)->frags[f];
  2732. len = frag->size;
  2733. buffer_info = &tx_ring->buffer_info[i];
  2734. BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
  2735. buffer_info->length = len;
  2736. buffer_info->time_stamp = jiffies;
  2737. buffer_info->next_to_watch = i;
  2738. buffer_info->dma = map[count];
  2739. count++;
  2740. }
  2741. tx_ring->buffer_info[i].skb = skb;
  2742. tx_ring->buffer_info[first].next_to_watch = i;
  2743. return count + 1;
  2744. }
  2745. static inline void igb_tx_queue_adv(struct igb_adapter *adapter,
  2746. struct igb_ring *tx_ring,
  2747. int tx_flags, int count, u32 paylen,
  2748. u8 hdr_len)
  2749. {
  2750. union e1000_adv_tx_desc *tx_desc = NULL;
  2751. struct igb_buffer *buffer_info;
  2752. u32 olinfo_status = 0, cmd_type_len;
  2753. unsigned int i;
  2754. cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
  2755. E1000_ADVTXD_DCMD_DEXT);
  2756. if (tx_flags & IGB_TX_FLAGS_VLAN)
  2757. cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
  2758. if (tx_flags & IGB_TX_FLAGS_TSTAMP)
  2759. cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
  2760. if (tx_flags & IGB_TX_FLAGS_TSO) {
  2761. cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
  2762. /* insert tcp checksum */
  2763. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  2764. /* insert ip checksum */
  2765. if (tx_flags & IGB_TX_FLAGS_IPV4)
  2766. olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
  2767. } else if (tx_flags & IGB_TX_FLAGS_CSUM) {
  2768. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  2769. }
  2770. if ((adapter->flags & IGB_FLAG_NEED_CTX_IDX) &&
  2771. (tx_flags & (IGB_TX_FLAGS_CSUM | IGB_TX_FLAGS_TSO |
  2772. IGB_TX_FLAGS_VLAN)))
  2773. olinfo_status |= tx_ring->queue_index << 4;
  2774. olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
  2775. i = tx_ring->next_to_use;
  2776. while (count--) {
  2777. buffer_info = &tx_ring->buffer_info[i];
  2778. tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
  2779. tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  2780. tx_desc->read.cmd_type_len =
  2781. cpu_to_le32(cmd_type_len | buffer_info->length);
  2782. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  2783. i++;
  2784. if (i == tx_ring->count)
  2785. i = 0;
  2786. }
  2787. tx_desc->read.cmd_type_len |= cpu_to_le32(adapter->txd_cmd);
  2788. /* Force memory writes to complete before letting h/w
  2789. * know there are new descriptors to fetch. (Only
  2790. * applicable for weak-ordered memory model archs,
  2791. * such as IA-64). */
  2792. wmb();
  2793. tx_ring->next_to_use = i;
  2794. writel(i, adapter->hw.hw_addr + tx_ring->tail);
  2795. /* we need this if more than one processor can write to our tail
  2796. * at a time, it syncronizes IO on IA64/Altix systems */
  2797. mmiowb();
  2798. }
  2799. static int __igb_maybe_stop_tx(struct net_device *netdev,
  2800. struct igb_ring *tx_ring, int size)
  2801. {
  2802. struct igb_adapter *adapter = netdev_priv(netdev);
  2803. netif_stop_subqueue(netdev, tx_ring->queue_index);
  2804. /* Herbert's original patch had:
  2805. * smp_mb__after_netif_stop_queue();
  2806. * but since that doesn't exist yet, just open code it. */
  2807. smp_mb();
  2808. /* We need to check again in a case another CPU has just
  2809. * made room available. */
  2810. if (igb_desc_unused(tx_ring) < size)
  2811. return -EBUSY;
  2812. /* A reprieve! */
  2813. netif_wake_subqueue(netdev, tx_ring->queue_index);
  2814. ++adapter->restart_queue;
  2815. return 0;
  2816. }
  2817. static int igb_maybe_stop_tx(struct net_device *netdev,
  2818. struct igb_ring *tx_ring, int size)
  2819. {
  2820. if (igb_desc_unused(tx_ring) >= size)
  2821. return 0;
  2822. return __igb_maybe_stop_tx(netdev, tx_ring, size);
  2823. }
  2824. static netdev_tx_t igb_xmit_frame_ring_adv(struct sk_buff *skb,
  2825. struct net_device *netdev,
  2826. struct igb_ring *tx_ring)
  2827. {
  2828. struct igb_adapter *adapter = netdev_priv(netdev);
  2829. unsigned int first;
  2830. unsigned int tx_flags = 0;
  2831. u8 hdr_len = 0;
  2832. int count = 0;
  2833. int tso = 0;
  2834. union skb_shared_tx *shtx;
  2835. if (test_bit(__IGB_DOWN, &adapter->state)) {
  2836. dev_kfree_skb_any(skb);
  2837. return NETDEV_TX_OK;
  2838. }
  2839. if (skb->len <= 0) {
  2840. dev_kfree_skb_any(skb);
  2841. return NETDEV_TX_OK;
  2842. }
  2843. /* need: 1 descriptor per page,
  2844. * + 2 desc gap to keep tail from touching head,
  2845. * + 1 desc for skb->data,
  2846. * + 1 desc for context descriptor,
  2847. * otherwise try next time */
  2848. if (igb_maybe_stop_tx(netdev, tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
  2849. /* this is a hard error */
  2850. return NETDEV_TX_BUSY;
  2851. }
  2852. /*
  2853. * TODO: check that there currently is no other packet with
  2854. * time stamping in the queue
  2855. *
  2856. * When doing time stamping, keep the connection to the socket
  2857. * a while longer: it is still needed by skb_hwtstamp_tx(),
  2858. * called either in igb_tx_hwtstamp() or by our caller when
  2859. * doing software time stamping.
  2860. */
  2861. shtx = skb_tx(skb);
  2862. if (unlikely(shtx->hardware)) {
  2863. shtx->in_progress = 1;
  2864. tx_flags |= IGB_TX_FLAGS_TSTAMP;
  2865. }
  2866. if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
  2867. tx_flags |= IGB_TX_FLAGS_VLAN;
  2868. tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
  2869. }
  2870. if (skb->protocol == htons(ETH_P_IP))
  2871. tx_flags |= IGB_TX_FLAGS_IPV4;
  2872. first = tx_ring->next_to_use;
  2873. tso = skb_is_gso(skb) ? igb_tso_adv(adapter, tx_ring, skb, tx_flags,
  2874. &hdr_len) : 0;
  2875. if (tso < 0) {
  2876. dev_kfree_skb_any(skb);
  2877. return NETDEV_TX_OK;
  2878. }
  2879. if (tso)
  2880. tx_flags |= IGB_TX_FLAGS_TSO;
  2881. else if (igb_tx_csum_adv(adapter, tx_ring, skb, tx_flags) &&
  2882. (skb->ip_summed == CHECKSUM_PARTIAL))
  2883. tx_flags |= IGB_TX_FLAGS_CSUM;
  2884. /*
  2885. * count reflects descriptors mapped, if 0 then mapping error
  2886. * has occured and we need to rewind the descriptor queue
  2887. */
  2888. count = igb_tx_map_adv(adapter, tx_ring, skb, first);
  2889. if (count) {
  2890. igb_tx_queue_adv(adapter, tx_ring, tx_flags, count,
  2891. skb->len, hdr_len);
  2892. /* Make sure there is space in the ring for the next send. */
  2893. igb_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 4);
  2894. } else {
  2895. dev_kfree_skb_any(skb);
  2896. tx_ring->buffer_info[first].time_stamp = 0;
  2897. tx_ring->next_to_use = first;
  2898. }
  2899. return NETDEV_TX_OK;
  2900. }
  2901. static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb,
  2902. struct net_device *netdev)
  2903. {
  2904. struct igb_adapter *adapter = netdev_priv(netdev);
  2905. struct igb_ring *tx_ring;
  2906. int r_idx = 0;
  2907. r_idx = skb->queue_mapping & (IGB_ABS_MAX_TX_QUEUES - 1);
  2908. tx_ring = adapter->multi_tx_table[r_idx];
  2909. /* This goes back to the question of how to logically map a tx queue
  2910. * to a flow. Right now, performance is impacted slightly negatively
  2911. * if using multiple tx queues. If the stack breaks away from a
  2912. * single qdisc implementation, we can look at this again. */
  2913. return igb_xmit_frame_ring_adv(skb, netdev, tx_ring);
  2914. }
  2915. /**
  2916. * igb_tx_timeout - Respond to a Tx Hang
  2917. * @netdev: network interface device structure
  2918. **/
  2919. static void igb_tx_timeout(struct net_device *netdev)
  2920. {
  2921. struct igb_adapter *adapter = netdev_priv(netdev);
  2922. struct e1000_hw *hw = &adapter->hw;
  2923. /* Do the reset outside of interrupt context */
  2924. adapter->tx_timeout_count++;
  2925. schedule_work(&adapter->reset_task);
  2926. wr32(E1000_EICS,
  2927. (adapter->eims_enable_mask & ~adapter->eims_other));
  2928. }
  2929. static void igb_reset_task(struct work_struct *work)
  2930. {
  2931. struct igb_adapter *adapter;
  2932. adapter = container_of(work, struct igb_adapter, reset_task);
  2933. igb_reinit_locked(adapter);
  2934. }
  2935. /**
  2936. * igb_get_stats - Get System Network Statistics
  2937. * @netdev: network interface device structure
  2938. *
  2939. * Returns the address of the device statistics structure.
  2940. * The statistics are actually updated from the timer callback.
  2941. **/
  2942. static struct net_device_stats *igb_get_stats(struct net_device *netdev)
  2943. {
  2944. struct igb_adapter *adapter = netdev_priv(netdev);
  2945. /* only return the current stats */
  2946. return &adapter->net_stats;
  2947. }
  2948. /**
  2949. * igb_change_mtu - Change the Maximum Transfer Unit
  2950. * @netdev: network interface device structure
  2951. * @new_mtu: new value for maximum frame size
  2952. *
  2953. * Returns 0 on success, negative on failure
  2954. **/
  2955. static int igb_change_mtu(struct net_device *netdev, int new_mtu)
  2956. {
  2957. struct igb_adapter *adapter = netdev_priv(netdev);
  2958. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  2959. if ((max_frame < ETH_ZLEN + ETH_FCS_LEN) ||
  2960. (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  2961. dev_err(&adapter->pdev->dev, "Invalid MTU setting\n");
  2962. return -EINVAL;
  2963. }
  2964. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  2965. dev_err(&adapter->pdev->dev, "MTU > 9216 not supported.\n");
  2966. return -EINVAL;
  2967. }
  2968. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  2969. msleep(1);
  2970. /* igb_down has a dependency on max_frame_size */
  2971. adapter->max_frame_size = max_frame;
  2972. if (netif_running(netdev))
  2973. igb_down(adapter);
  2974. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  2975. * means we reserve 2 more, this pushes us to allocate from the next
  2976. * larger slab size.
  2977. * i.e. RXBUFFER_2048 --> size-4096 slab
  2978. */
  2979. if (max_frame <= IGB_RXBUFFER_256)
  2980. adapter->rx_buffer_len = IGB_RXBUFFER_256;
  2981. else if (max_frame <= IGB_RXBUFFER_512)
  2982. adapter->rx_buffer_len = IGB_RXBUFFER_512;
  2983. else if (max_frame <= IGB_RXBUFFER_1024)
  2984. adapter->rx_buffer_len = IGB_RXBUFFER_1024;
  2985. else if (max_frame <= IGB_RXBUFFER_2048)
  2986. adapter->rx_buffer_len = IGB_RXBUFFER_2048;
  2987. else
  2988. #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
  2989. adapter->rx_buffer_len = IGB_RXBUFFER_16384;
  2990. #else
  2991. adapter->rx_buffer_len = PAGE_SIZE / 2;
  2992. #endif
  2993. /* if sr-iov is enabled we need to force buffer size to 1K or larger */
  2994. if (adapter->vfs_allocated_count &&
  2995. (adapter->rx_buffer_len < IGB_RXBUFFER_1024))
  2996. adapter->rx_buffer_len = IGB_RXBUFFER_1024;
  2997. /* adjust allocation if LPE protects us, and we aren't using SBP */
  2998. if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN) ||
  2999. (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE))
  3000. adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  3001. dev_info(&adapter->pdev->dev, "changing MTU from %d to %d\n",
  3002. netdev->mtu, new_mtu);
  3003. netdev->mtu = new_mtu;
  3004. if (netif_running(netdev))
  3005. igb_up(adapter);
  3006. else
  3007. igb_reset(adapter);
  3008. clear_bit(__IGB_RESETTING, &adapter->state);
  3009. return 0;
  3010. }
  3011. /**
  3012. * igb_update_stats - Update the board statistics counters
  3013. * @adapter: board private structure
  3014. **/
  3015. void igb_update_stats(struct igb_adapter *adapter)
  3016. {
  3017. struct e1000_hw *hw = &adapter->hw;
  3018. struct pci_dev *pdev = adapter->pdev;
  3019. u16 phy_tmp;
  3020. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  3021. /*
  3022. * Prevent stats update while adapter is being reset, or if the pci
  3023. * connection is down.
  3024. */
  3025. if (adapter->link_speed == 0)
  3026. return;
  3027. if (pci_channel_offline(pdev))
  3028. return;
  3029. adapter->stats.crcerrs += rd32(E1000_CRCERRS);
  3030. adapter->stats.gprc += rd32(E1000_GPRC);
  3031. adapter->stats.gorc += rd32(E1000_GORCL);
  3032. rd32(E1000_GORCH); /* clear GORCL */
  3033. adapter->stats.bprc += rd32(E1000_BPRC);
  3034. adapter->stats.mprc += rd32(E1000_MPRC);
  3035. adapter->stats.roc += rd32(E1000_ROC);
  3036. adapter->stats.prc64 += rd32(E1000_PRC64);
  3037. adapter->stats.prc127 += rd32(E1000_PRC127);
  3038. adapter->stats.prc255 += rd32(E1000_PRC255);
  3039. adapter->stats.prc511 += rd32(E1000_PRC511);
  3040. adapter->stats.prc1023 += rd32(E1000_PRC1023);
  3041. adapter->stats.prc1522 += rd32(E1000_PRC1522);
  3042. adapter->stats.symerrs += rd32(E1000_SYMERRS);
  3043. adapter->stats.sec += rd32(E1000_SEC);
  3044. adapter->stats.mpc += rd32(E1000_MPC);
  3045. adapter->stats.scc += rd32(E1000_SCC);
  3046. adapter->stats.ecol += rd32(E1000_ECOL);
  3047. adapter->stats.mcc += rd32(E1000_MCC);
  3048. adapter->stats.latecol += rd32(E1000_LATECOL);
  3049. adapter->stats.dc += rd32(E1000_DC);
  3050. adapter->stats.rlec += rd32(E1000_RLEC);
  3051. adapter->stats.xonrxc += rd32(E1000_XONRXC);
  3052. adapter->stats.xontxc += rd32(E1000_XONTXC);
  3053. adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
  3054. adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
  3055. adapter->stats.fcruc += rd32(E1000_FCRUC);
  3056. adapter->stats.gptc += rd32(E1000_GPTC);
  3057. adapter->stats.gotc += rd32(E1000_GOTCL);
  3058. rd32(E1000_GOTCH); /* clear GOTCL */
  3059. adapter->stats.rnbc += rd32(E1000_RNBC);
  3060. adapter->stats.ruc += rd32(E1000_RUC);
  3061. adapter->stats.rfc += rd32(E1000_RFC);
  3062. adapter->stats.rjc += rd32(E1000_RJC);
  3063. adapter->stats.tor += rd32(E1000_TORH);
  3064. adapter->stats.tot += rd32(E1000_TOTH);
  3065. adapter->stats.tpr += rd32(E1000_TPR);
  3066. adapter->stats.ptc64 += rd32(E1000_PTC64);
  3067. adapter->stats.ptc127 += rd32(E1000_PTC127);
  3068. adapter->stats.ptc255 += rd32(E1000_PTC255);
  3069. adapter->stats.ptc511 += rd32(E1000_PTC511);
  3070. adapter->stats.ptc1023 += rd32(E1000_PTC1023);
  3071. adapter->stats.ptc1522 += rd32(E1000_PTC1522);
  3072. adapter->stats.mptc += rd32(E1000_MPTC);
  3073. adapter->stats.bptc += rd32(E1000_BPTC);
  3074. /* used for adaptive IFS */
  3075. hw->mac.tx_packet_delta = rd32(E1000_TPT);
  3076. adapter->stats.tpt += hw->mac.tx_packet_delta;
  3077. hw->mac.collision_delta = rd32(E1000_COLC);
  3078. adapter->stats.colc += hw->mac.collision_delta;
  3079. adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
  3080. adapter->stats.rxerrc += rd32(E1000_RXERRC);
  3081. adapter->stats.tncrs += rd32(E1000_TNCRS);
  3082. adapter->stats.tsctc += rd32(E1000_TSCTC);
  3083. adapter->stats.tsctfc += rd32(E1000_TSCTFC);
  3084. adapter->stats.iac += rd32(E1000_IAC);
  3085. adapter->stats.icrxoc += rd32(E1000_ICRXOC);
  3086. adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
  3087. adapter->stats.icrxatc += rd32(E1000_ICRXATC);
  3088. adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
  3089. adapter->stats.ictxatc += rd32(E1000_ICTXATC);
  3090. adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
  3091. adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
  3092. adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
  3093. /* Fill out the OS statistics structure */
  3094. adapter->net_stats.multicast = adapter->stats.mprc;
  3095. adapter->net_stats.collisions = adapter->stats.colc;
  3096. /* Rx Errors */
  3097. if (hw->mac.type != e1000_82575) {
  3098. u32 rqdpc_tmp;
  3099. u64 rqdpc_total = 0;
  3100. int i;
  3101. /* Read out drops stats per RX queue. Notice RQDPC (Receive
  3102. * Queue Drop Packet Count) stats only gets incremented, if
  3103. * the DROP_EN but it set (in the SRRCTL register for that
  3104. * queue). If DROP_EN bit is NOT set, then the some what
  3105. * equivalent count is stored in RNBC (not per queue basis).
  3106. * Also note the drop count is due to lack of available
  3107. * descriptors.
  3108. */
  3109. for (i = 0; i < adapter->num_rx_queues; i++) {
  3110. rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0xFFF;
  3111. adapter->rx_ring[i].rx_stats.drops += rqdpc_tmp;
  3112. rqdpc_total += adapter->rx_ring[i].rx_stats.drops;
  3113. }
  3114. adapter->net_stats.rx_fifo_errors = rqdpc_total;
  3115. }
  3116. /* Note RNBC (Receive No Buffers Count) is an not an exact
  3117. * drop count as the hardware FIFO might save the day. Thats
  3118. * one of the reason for saving it in rx_fifo_errors, as its
  3119. * potentially not a true drop.
  3120. */
  3121. adapter->net_stats.rx_fifo_errors += adapter->stats.rnbc;
  3122. /* RLEC on some newer hardware can be incorrect so build
  3123. * our own version based on RUC and ROC */
  3124. adapter->net_stats.rx_errors = adapter->stats.rxerrc +
  3125. adapter->stats.crcerrs + adapter->stats.algnerrc +
  3126. adapter->stats.ruc + adapter->stats.roc +
  3127. adapter->stats.cexterr;
  3128. adapter->net_stats.rx_length_errors = adapter->stats.ruc +
  3129. adapter->stats.roc;
  3130. adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
  3131. adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
  3132. adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
  3133. /* Tx Errors */
  3134. adapter->net_stats.tx_errors = adapter->stats.ecol +
  3135. adapter->stats.latecol;
  3136. adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
  3137. adapter->net_stats.tx_window_errors = adapter->stats.latecol;
  3138. adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
  3139. /* Tx Dropped needs to be maintained elsewhere */
  3140. /* Phy Stats */
  3141. if (hw->phy.media_type == e1000_media_type_copper) {
  3142. if ((adapter->link_speed == SPEED_1000) &&
  3143. (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
  3144. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  3145. adapter->phy_stats.idle_errors += phy_tmp;
  3146. }
  3147. }
  3148. /* Management Stats */
  3149. adapter->stats.mgptc += rd32(E1000_MGTPTC);
  3150. adapter->stats.mgprc += rd32(E1000_MGTPRC);
  3151. adapter->stats.mgpdc += rd32(E1000_MGTPDC);
  3152. }
  3153. static irqreturn_t igb_msix_other(int irq, void *data)
  3154. {
  3155. struct net_device *netdev = data;
  3156. struct igb_adapter *adapter = netdev_priv(netdev);
  3157. struct e1000_hw *hw = &adapter->hw;
  3158. u32 icr = rd32(E1000_ICR);
  3159. /* reading ICR causes bit 31 of EICR to be cleared */
  3160. if(icr & E1000_ICR_DOUTSYNC) {
  3161. /* HW is reporting DMA is out of sync */
  3162. adapter->stats.doosync++;
  3163. }
  3164. /* Check for a mailbox event */
  3165. if (icr & E1000_ICR_VMMB)
  3166. igb_msg_task(adapter);
  3167. if (icr & E1000_ICR_LSC) {
  3168. hw->mac.get_link_status = 1;
  3169. /* guard against interrupt when we're going down */
  3170. if (!test_bit(__IGB_DOWN, &adapter->state))
  3171. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  3172. }
  3173. wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC | E1000_IMS_VMMB);
  3174. wr32(E1000_EIMS, adapter->eims_other);
  3175. return IRQ_HANDLED;
  3176. }
  3177. static irqreturn_t igb_msix_tx(int irq, void *data)
  3178. {
  3179. struct igb_ring *tx_ring = data;
  3180. struct igb_adapter *adapter = tx_ring->adapter;
  3181. struct e1000_hw *hw = &adapter->hw;
  3182. #ifdef CONFIG_IGB_DCA
  3183. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  3184. igb_update_tx_dca(tx_ring);
  3185. #endif
  3186. tx_ring->total_bytes = 0;
  3187. tx_ring->total_packets = 0;
  3188. /* auto mask will automatically reenable the interrupt when we write
  3189. * EICS */
  3190. if (!igb_clean_tx_irq(tx_ring))
  3191. /* Ring was not completely cleaned, so fire another interrupt */
  3192. wr32(E1000_EICS, tx_ring->eims_value);
  3193. else
  3194. wr32(E1000_EIMS, tx_ring->eims_value);
  3195. return IRQ_HANDLED;
  3196. }
  3197. static void igb_write_itr(struct igb_ring *ring)
  3198. {
  3199. struct e1000_hw *hw = &ring->adapter->hw;
  3200. if ((ring->adapter->itr_setting & 3) && ring->set_itr) {
  3201. switch (hw->mac.type) {
  3202. case e1000_82576:
  3203. wr32(ring->itr_register, ring->itr_val |
  3204. 0x80000000);
  3205. break;
  3206. default:
  3207. wr32(ring->itr_register, ring->itr_val |
  3208. (ring->itr_val << 16));
  3209. break;
  3210. }
  3211. ring->set_itr = 0;
  3212. }
  3213. }
  3214. static irqreturn_t igb_msix_rx(int irq, void *data)
  3215. {
  3216. struct igb_ring *rx_ring = data;
  3217. /* Write the ITR value calculated at the end of the
  3218. * previous interrupt.
  3219. */
  3220. igb_write_itr(rx_ring);
  3221. if (napi_schedule_prep(&rx_ring->napi))
  3222. __napi_schedule(&rx_ring->napi);
  3223. #ifdef CONFIG_IGB_DCA
  3224. if (rx_ring->adapter->flags & IGB_FLAG_DCA_ENABLED)
  3225. igb_update_rx_dca(rx_ring);
  3226. #endif
  3227. return IRQ_HANDLED;
  3228. }
  3229. #ifdef CONFIG_IGB_DCA
  3230. static void igb_update_rx_dca(struct igb_ring *rx_ring)
  3231. {
  3232. u32 dca_rxctrl;
  3233. struct igb_adapter *adapter = rx_ring->adapter;
  3234. struct e1000_hw *hw = &adapter->hw;
  3235. int cpu = get_cpu();
  3236. int q = rx_ring->reg_idx;
  3237. if (rx_ring->cpu != cpu) {
  3238. dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
  3239. if (hw->mac.type == e1000_82576) {
  3240. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
  3241. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  3242. E1000_DCA_RXCTRL_CPUID_SHIFT;
  3243. } else {
  3244. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
  3245. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  3246. }
  3247. dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
  3248. dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
  3249. dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
  3250. wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
  3251. rx_ring->cpu = cpu;
  3252. }
  3253. put_cpu();
  3254. }
  3255. static void igb_update_tx_dca(struct igb_ring *tx_ring)
  3256. {
  3257. u32 dca_txctrl;
  3258. struct igb_adapter *adapter = tx_ring->adapter;
  3259. struct e1000_hw *hw = &adapter->hw;
  3260. int cpu = get_cpu();
  3261. int q = tx_ring->reg_idx;
  3262. if (tx_ring->cpu != cpu) {
  3263. dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
  3264. if (hw->mac.type == e1000_82576) {
  3265. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
  3266. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  3267. E1000_DCA_TXCTRL_CPUID_SHIFT;
  3268. } else {
  3269. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
  3270. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  3271. }
  3272. dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
  3273. wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
  3274. tx_ring->cpu = cpu;
  3275. }
  3276. put_cpu();
  3277. }
  3278. static void igb_setup_dca(struct igb_adapter *adapter)
  3279. {
  3280. struct e1000_hw *hw = &adapter->hw;
  3281. int i;
  3282. if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
  3283. return;
  3284. /* Always use CB2 mode, difference is masked in the CB driver. */
  3285. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
  3286. for (i = 0; i < adapter->num_tx_queues; i++) {
  3287. adapter->tx_ring[i].cpu = -1;
  3288. igb_update_tx_dca(&adapter->tx_ring[i]);
  3289. }
  3290. for (i = 0; i < adapter->num_rx_queues; i++) {
  3291. adapter->rx_ring[i].cpu = -1;
  3292. igb_update_rx_dca(&adapter->rx_ring[i]);
  3293. }
  3294. }
  3295. static int __igb_notify_dca(struct device *dev, void *data)
  3296. {
  3297. struct net_device *netdev = dev_get_drvdata(dev);
  3298. struct igb_adapter *adapter = netdev_priv(netdev);
  3299. struct e1000_hw *hw = &adapter->hw;
  3300. unsigned long event = *(unsigned long *)data;
  3301. switch (event) {
  3302. case DCA_PROVIDER_ADD:
  3303. /* if already enabled, don't do it again */
  3304. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  3305. break;
  3306. /* Always use CB2 mode, difference is masked
  3307. * in the CB driver. */
  3308. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
  3309. if (dca_add_requester(dev) == 0) {
  3310. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  3311. dev_info(&adapter->pdev->dev, "DCA enabled\n");
  3312. igb_setup_dca(adapter);
  3313. break;
  3314. }
  3315. /* Fall Through since DCA is disabled. */
  3316. case DCA_PROVIDER_REMOVE:
  3317. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  3318. /* without this a class_device is left
  3319. * hanging around in the sysfs model */
  3320. dca_remove_requester(dev);
  3321. dev_info(&adapter->pdev->dev, "DCA disabled\n");
  3322. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  3323. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  3324. }
  3325. break;
  3326. }
  3327. return 0;
  3328. }
  3329. static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
  3330. void *p)
  3331. {
  3332. int ret_val;
  3333. ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
  3334. __igb_notify_dca);
  3335. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  3336. }
  3337. #endif /* CONFIG_IGB_DCA */
  3338. static void igb_ping_all_vfs(struct igb_adapter *adapter)
  3339. {
  3340. struct e1000_hw *hw = &adapter->hw;
  3341. u32 ping;
  3342. int i;
  3343. for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
  3344. ping = E1000_PF_CONTROL_MSG;
  3345. if (adapter->vf_data[i].clear_to_send)
  3346. ping |= E1000_VT_MSGTYPE_CTS;
  3347. igb_write_mbx(hw, &ping, 1, i);
  3348. }
  3349. }
  3350. static int igb_set_vf_multicasts(struct igb_adapter *adapter,
  3351. u32 *msgbuf, u32 vf)
  3352. {
  3353. int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  3354. u16 *hash_list = (u16 *)&msgbuf[1];
  3355. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  3356. int i;
  3357. /* only up to 30 hash values supported */
  3358. if (n > 30)
  3359. n = 30;
  3360. /* salt away the number of multi cast addresses assigned
  3361. * to this VF for later use to restore when the PF multi cast
  3362. * list changes
  3363. */
  3364. vf_data->num_vf_mc_hashes = n;
  3365. /* VFs are limited to using the MTA hash table for their multicast
  3366. * addresses */
  3367. for (i = 0; i < n; i++)
  3368. vf_data->vf_mc_hashes[i] = hash_list[i];
  3369. /* Flush and reset the mta with the new values */
  3370. igb_set_rx_mode(adapter->netdev);
  3371. return 0;
  3372. }
  3373. static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
  3374. {
  3375. struct e1000_hw *hw = &adapter->hw;
  3376. struct vf_data_storage *vf_data;
  3377. int i, j;
  3378. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  3379. vf_data = &adapter->vf_data[i];
  3380. for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
  3381. igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
  3382. }
  3383. }
  3384. static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
  3385. {
  3386. struct e1000_hw *hw = &adapter->hw;
  3387. u32 pool_mask, reg, vid;
  3388. int i;
  3389. pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  3390. /* Find the vlan filter for this id */
  3391. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  3392. reg = rd32(E1000_VLVF(i));
  3393. /* remove the vf from the pool */
  3394. reg &= ~pool_mask;
  3395. /* if pool is empty then remove entry from vfta */
  3396. if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
  3397. (reg & E1000_VLVF_VLANID_ENABLE)) {
  3398. reg = 0;
  3399. vid = reg & E1000_VLVF_VLANID_MASK;
  3400. igb_vfta_set(hw, vid, false);
  3401. }
  3402. wr32(E1000_VLVF(i), reg);
  3403. }
  3404. adapter->vf_data[vf].vlans_enabled = 0;
  3405. }
  3406. static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
  3407. {
  3408. struct e1000_hw *hw = &adapter->hw;
  3409. u32 reg, i;
  3410. /* It is an error to call this function when VFs are not enabled */
  3411. if (!adapter->vfs_allocated_count)
  3412. return -1;
  3413. /* Find the vlan filter for this id */
  3414. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  3415. reg = rd32(E1000_VLVF(i));
  3416. if ((reg & E1000_VLVF_VLANID_ENABLE) &&
  3417. vid == (reg & E1000_VLVF_VLANID_MASK))
  3418. break;
  3419. }
  3420. if (add) {
  3421. if (i == E1000_VLVF_ARRAY_SIZE) {
  3422. /* Did not find a matching VLAN ID entry that was
  3423. * enabled. Search for a free filter entry, i.e.
  3424. * one without the enable bit set
  3425. */
  3426. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  3427. reg = rd32(E1000_VLVF(i));
  3428. if (!(reg & E1000_VLVF_VLANID_ENABLE))
  3429. break;
  3430. }
  3431. }
  3432. if (i < E1000_VLVF_ARRAY_SIZE) {
  3433. /* Found an enabled/available entry */
  3434. reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  3435. /* if !enabled we need to set this up in vfta */
  3436. if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
  3437. /* add VID to filter table, if bit already set
  3438. * PF must have added it outside of table */
  3439. if (igb_vfta_set(hw, vid, true))
  3440. reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT +
  3441. adapter->vfs_allocated_count);
  3442. reg |= E1000_VLVF_VLANID_ENABLE;
  3443. }
  3444. reg &= ~E1000_VLVF_VLANID_MASK;
  3445. reg |= vid;
  3446. wr32(E1000_VLVF(i), reg);
  3447. /* do not modify RLPML for PF devices */
  3448. if (vf >= adapter->vfs_allocated_count)
  3449. return 0;
  3450. if (!adapter->vf_data[vf].vlans_enabled) {
  3451. u32 size;
  3452. reg = rd32(E1000_VMOLR(vf));
  3453. size = reg & E1000_VMOLR_RLPML_MASK;
  3454. size += 4;
  3455. reg &= ~E1000_VMOLR_RLPML_MASK;
  3456. reg |= size;
  3457. wr32(E1000_VMOLR(vf), reg);
  3458. }
  3459. adapter->vf_data[vf].vlans_enabled++;
  3460. return 0;
  3461. }
  3462. } else {
  3463. if (i < E1000_VLVF_ARRAY_SIZE) {
  3464. /* remove vf from the pool */
  3465. reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
  3466. /* if pool is empty then remove entry from vfta */
  3467. if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
  3468. reg = 0;
  3469. igb_vfta_set(hw, vid, false);
  3470. }
  3471. wr32(E1000_VLVF(i), reg);
  3472. /* do not modify RLPML for PF devices */
  3473. if (vf >= adapter->vfs_allocated_count)
  3474. return 0;
  3475. adapter->vf_data[vf].vlans_enabled--;
  3476. if (!adapter->vf_data[vf].vlans_enabled) {
  3477. u32 size;
  3478. reg = rd32(E1000_VMOLR(vf));
  3479. size = reg & E1000_VMOLR_RLPML_MASK;
  3480. size -= 4;
  3481. reg &= ~E1000_VMOLR_RLPML_MASK;
  3482. reg |= size;
  3483. wr32(E1000_VMOLR(vf), reg);
  3484. }
  3485. return 0;
  3486. }
  3487. }
  3488. return -1;
  3489. }
  3490. static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
  3491. {
  3492. int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  3493. int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
  3494. return igb_vlvf_set(adapter, vid, add, vf);
  3495. }
  3496. static inline void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
  3497. {
  3498. struct e1000_hw *hw = &adapter->hw;
  3499. /* disable mailbox functionality for vf */
  3500. adapter->vf_data[vf].clear_to_send = false;
  3501. /* reset offloads to defaults */
  3502. igb_set_vmolr(hw, vf);
  3503. /* reset vlans for device */
  3504. igb_clear_vf_vfta(adapter, vf);
  3505. /* reset multicast table array for vf */
  3506. adapter->vf_data[vf].num_vf_mc_hashes = 0;
  3507. /* Flush and reset the mta with the new values */
  3508. igb_set_rx_mode(adapter->netdev);
  3509. }
  3510. static inline void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
  3511. {
  3512. struct e1000_hw *hw = &adapter->hw;
  3513. unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
  3514. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  3515. u32 reg, msgbuf[3];
  3516. u8 *addr = (u8 *)(&msgbuf[1]);
  3517. /* process all the same items cleared in a function level reset */
  3518. igb_vf_reset_event(adapter, vf);
  3519. /* set vf mac address */
  3520. igb_rar_set(hw, vf_mac, rar_entry);
  3521. igb_set_rah_pool(hw, vf, rar_entry);
  3522. /* enable transmit and receive for vf */
  3523. reg = rd32(E1000_VFTE);
  3524. wr32(E1000_VFTE, reg | (1 << vf));
  3525. reg = rd32(E1000_VFRE);
  3526. wr32(E1000_VFRE, reg | (1 << vf));
  3527. /* enable mailbox functionality for vf */
  3528. adapter->vf_data[vf].clear_to_send = true;
  3529. /* reply to reset with ack and vf mac address */
  3530. msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
  3531. memcpy(addr, vf_mac, 6);
  3532. igb_write_mbx(hw, msgbuf, 3, vf);
  3533. }
  3534. static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
  3535. {
  3536. unsigned char *addr = (char *)&msg[1];
  3537. int err = -1;
  3538. if (is_valid_ether_addr(addr))
  3539. err = igb_set_vf_mac(adapter, vf, addr);
  3540. return err;
  3541. }
  3542. static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
  3543. {
  3544. struct e1000_hw *hw = &adapter->hw;
  3545. u32 msg = E1000_VT_MSGTYPE_NACK;
  3546. /* if device isn't clear to send it shouldn't be reading either */
  3547. if (!adapter->vf_data[vf].clear_to_send)
  3548. igb_write_mbx(hw, &msg, 1, vf);
  3549. }
  3550. static void igb_msg_task(struct igb_adapter *adapter)
  3551. {
  3552. struct e1000_hw *hw = &adapter->hw;
  3553. u32 vf;
  3554. for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
  3555. /* process any reset requests */
  3556. if (!igb_check_for_rst(hw, vf)) {
  3557. adapter->vf_data[vf].clear_to_send = false;
  3558. igb_vf_reset_event(adapter, vf);
  3559. }
  3560. /* process any messages pending */
  3561. if (!igb_check_for_msg(hw, vf))
  3562. igb_rcv_msg_from_vf(adapter, vf);
  3563. /* process any acks */
  3564. if (!igb_check_for_ack(hw, vf))
  3565. igb_rcv_ack_from_vf(adapter, vf);
  3566. }
  3567. }
  3568. static int igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
  3569. {
  3570. u32 mbx_size = E1000_VFMAILBOX_SIZE;
  3571. u32 msgbuf[mbx_size];
  3572. struct e1000_hw *hw = &adapter->hw;
  3573. s32 retval;
  3574. retval = igb_read_mbx(hw, msgbuf, mbx_size, vf);
  3575. if (retval)
  3576. dev_err(&adapter->pdev->dev,
  3577. "Error receiving message from VF\n");
  3578. /* this is a message we already processed, do nothing */
  3579. if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
  3580. return retval;
  3581. /*
  3582. * until the vf completes a reset it should not be
  3583. * allowed to start any configuration.
  3584. */
  3585. if (msgbuf[0] == E1000_VF_RESET) {
  3586. igb_vf_reset_msg(adapter, vf);
  3587. return retval;
  3588. }
  3589. if (!adapter->vf_data[vf].clear_to_send) {
  3590. msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
  3591. igb_write_mbx(hw, msgbuf, 1, vf);
  3592. return retval;
  3593. }
  3594. switch ((msgbuf[0] & 0xFFFF)) {
  3595. case E1000_VF_SET_MAC_ADDR:
  3596. retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
  3597. break;
  3598. case E1000_VF_SET_MULTICAST:
  3599. retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
  3600. break;
  3601. case E1000_VF_SET_LPE:
  3602. retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
  3603. break;
  3604. case E1000_VF_SET_VLAN:
  3605. retval = igb_set_vf_vlan(adapter, msgbuf, vf);
  3606. break;
  3607. default:
  3608. dev_err(&adapter->pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
  3609. retval = -1;
  3610. break;
  3611. }
  3612. /* notify the VF of the results of what it sent us */
  3613. if (retval)
  3614. msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
  3615. else
  3616. msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
  3617. msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
  3618. igb_write_mbx(hw, msgbuf, 1, vf);
  3619. return retval;
  3620. }
  3621. /**
  3622. * igb_intr_msi - Interrupt Handler
  3623. * @irq: interrupt number
  3624. * @data: pointer to a network interface device structure
  3625. **/
  3626. static irqreturn_t igb_intr_msi(int irq, void *data)
  3627. {
  3628. struct net_device *netdev = data;
  3629. struct igb_adapter *adapter = netdev_priv(netdev);
  3630. struct e1000_hw *hw = &adapter->hw;
  3631. /* read ICR disables interrupts using IAM */
  3632. u32 icr = rd32(E1000_ICR);
  3633. igb_write_itr(adapter->rx_ring);
  3634. if(icr & E1000_ICR_DOUTSYNC) {
  3635. /* HW is reporting DMA is out of sync */
  3636. adapter->stats.doosync++;
  3637. }
  3638. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  3639. hw->mac.get_link_status = 1;
  3640. if (!test_bit(__IGB_DOWN, &adapter->state))
  3641. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  3642. }
  3643. napi_schedule(&adapter->rx_ring[0].napi);
  3644. return IRQ_HANDLED;
  3645. }
  3646. /**
  3647. * igb_intr - Legacy Interrupt Handler
  3648. * @irq: interrupt number
  3649. * @data: pointer to a network interface device structure
  3650. **/
  3651. static irqreturn_t igb_intr(int irq, void *data)
  3652. {
  3653. struct net_device *netdev = data;
  3654. struct igb_adapter *adapter = netdev_priv(netdev);
  3655. struct e1000_hw *hw = &adapter->hw;
  3656. /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
  3657. * need for the IMC write */
  3658. u32 icr = rd32(E1000_ICR);
  3659. if (!icr)
  3660. return IRQ_NONE; /* Not our interrupt */
  3661. igb_write_itr(adapter->rx_ring);
  3662. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  3663. * not set, then the adapter didn't send an interrupt */
  3664. if (!(icr & E1000_ICR_INT_ASSERTED))
  3665. return IRQ_NONE;
  3666. if(icr & E1000_ICR_DOUTSYNC) {
  3667. /* HW is reporting DMA is out of sync */
  3668. adapter->stats.doosync++;
  3669. }
  3670. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  3671. hw->mac.get_link_status = 1;
  3672. /* guard against interrupt when we're going down */
  3673. if (!test_bit(__IGB_DOWN, &adapter->state))
  3674. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  3675. }
  3676. napi_schedule(&adapter->rx_ring[0].napi);
  3677. return IRQ_HANDLED;
  3678. }
  3679. static inline void igb_rx_irq_enable(struct igb_ring *rx_ring)
  3680. {
  3681. struct igb_adapter *adapter = rx_ring->adapter;
  3682. struct e1000_hw *hw = &adapter->hw;
  3683. if (adapter->itr_setting & 3) {
  3684. if (adapter->num_rx_queues == 1)
  3685. igb_set_itr(adapter);
  3686. else
  3687. igb_update_ring_itr(rx_ring);
  3688. }
  3689. if (!test_bit(__IGB_DOWN, &adapter->state)) {
  3690. if (adapter->msix_entries)
  3691. wr32(E1000_EIMS, rx_ring->eims_value);
  3692. else
  3693. igb_irq_enable(adapter);
  3694. }
  3695. }
  3696. /**
  3697. * igb_poll - NAPI Rx polling callback
  3698. * @napi: napi polling structure
  3699. * @budget: count of how many packets we should handle
  3700. **/
  3701. static int igb_poll(struct napi_struct *napi, int budget)
  3702. {
  3703. struct igb_ring *rx_ring = container_of(napi, struct igb_ring, napi);
  3704. int work_done = 0;
  3705. #ifdef CONFIG_IGB_DCA
  3706. if (rx_ring->adapter->flags & IGB_FLAG_DCA_ENABLED)
  3707. igb_update_rx_dca(rx_ring);
  3708. #endif
  3709. igb_clean_rx_irq_adv(rx_ring, &work_done, budget);
  3710. if (rx_ring->buddy) {
  3711. #ifdef CONFIG_IGB_DCA
  3712. if (rx_ring->adapter->flags & IGB_FLAG_DCA_ENABLED)
  3713. igb_update_tx_dca(rx_ring->buddy);
  3714. #endif
  3715. if (!igb_clean_tx_irq(rx_ring->buddy))
  3716. work_done = budget;
  3717. }
  3718. /* If not enough Rx work done, exit the polling mode */
  3719. if (work_done < budget) {
  3720. napi_complete(napi);
  3721. igb_rx_irq_enable(rx_ring);
  3722. }
  3723. return work_done;
  3724. }
  3725. /**
  3726. * igb_hwtstamp - utility function which checks for TX time stamp
  3727. * @adapter: board private structure
  3728. * @skb: packet that was just sent
  3729. *
  3730. * If we were asked to do hardware stamping and such a time stamp is
  3731. * available, then it must have been for this skb here because we only
  3732. * allow only one such packet into the queue.
  3733. */
  3734. static void igb_tx_hwtstamp(struct igb_adapter *adapter, struct sk_buff *skb)
  3735. {
  3736. union skb_shared_tx *shtx = skb_tx(skb);
  3737. struct e1000_hw *hw = &adapter->hw;
  3738. if (unlikely(shtx->hardware)) {
  3739. u32 valid = rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID;
  3740. if (valid) {
  3741. u64 regval = rd32(E1000_TXSTMPL);
  3742. u64 ns;
  3743. struct skb_shared_hwtstamps shhwtstamps;
  3744. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  3745. regval |= (u64)rd32(E1000_TXSTMPH) << 32;
  3746. ns = timecounter_cyc2time(&adapter->clock,
  3747. regval);
  3748. timecompare_update(&adapter->compare, ns);
  3749. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  3750. shhwtstamps.syststamp =
  3751. timecompare_transform(&adapter->compare, ns);
  3752. skb_tstamp_tx(skb, &shhwtstamps);
  3753. }
  3754. }
  3755. }
  3756. /**
  3757. * igb_clean_tx_irq - Reclaim resources after transmit completes
  3758. * @adapter: board private structure
  3759. * returns true if ring is completely cleaned
  3760. **/
  3761. static bool igb_clean_tx_irq(struct igb_ring *tx_ring)
  3762. {
  3763. struct igb_adapter *adapter = tx_ring->adapter;
  3764. struct net_device *netdev = adapter->netdev;
  3765. struct e1000_hw *hw = &adapter->hw;
  3766. struct igb_buffer *buffer_info;
  3767. struct sk_buff *skb;
  3768. union e1000_adv_tx_desc *tx_desc, *eop_desc;
  3769. unsigned int total_bytes = 0, total_packets = 0;
  3770. unsigned int i, eop, count = 0;
  3771. bool cleaned = false;
  3772. i = tx_ring->next_to_clean;
  3773. eop = tx_ring->buffer_info[i].next_to_watch;
  3774. eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
  3775. while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
  3776. (count < tx_ring->count)) {
  3777. for (cleaned = false; !cleaned; count++) {
  3778. tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
  3779. buffer_info = &tx_ring->buffer_info[i];
  3780. cleaned = (i == eop);
  3781. skb = buffer_info->skb;
  3782. if (skb) {
  3783. unsigned int segs, bytecount;
  3784. /* gso_segs is currently only valid for tcp */
  3785. segs = skb_shinfo(skb)->gso_segs ?: 1;
  3786. /* multiply data chunks by size of headers */
  3787. bytecount = ((segs - 1) * skb_headlen(skb)) +
  3788. skb->len;
  3789. total_packets += segs;
  3790. total_bytes += bytecount;
  3791. igb_tx_hwtstamp(adapter, skb);
  3792. }
  3793. igb_unmap_and_free_tx_resource(adapter, buffer_info);
  3794. tx_desc->wb.status = 0;
  3795. i++;
  3796. if (i == tx_ring->count)
  3797. i = 0;
  3798. }
  3799. eop = tx_ring->buffer_info[i].next_to_watch;
  3800. eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
  3801. }
  3802. tx_ring->next_to_clean = i;
  3803. if (unlikely(count &&
  3804. netif_carrier_ok(netdev) &&
  3805. igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
  3806. /* Make sure that anybody stopping the queue after this
  3807. * sees the new next_to_clean.
  3808. */
  3809. smp_mb();
  3810. if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
  3811. !(test_bit(__IGB_DOWN, &adapter->state))) {
  3812. netif_wake_subqueue(netdev, tx_ring->queue_index);
  3813. ++adapter->restart_queue;
  3814. }
  3815. }
  3816. if (tx_ring->detect_tx_hung) {
  3817. /* Detect a transmit hang in hardware, this serializes the
  3818. * check with the clearing of time_stamp and movement of i */
  3819. tx_ring->detect_tx_hung = false;
  3820. if (tx_ring->buffer_info[i].time_stamp &&
  3821. time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
  3822. (adapter->tx_timeout_factor * HZ))
  3823. && !(rd32(E1000_STATUS) &
  3824. E1000_STATUS_TXOFF)) {
  3825. /* detected Tx unit hang */
  3826. dev_err(&adapter->pdev->dev,
  3827. "Detected Tx Unit Hang\n"
  3828. " Tx Queue <%d>\n"
  3829. " TDH <%x>\n"
  3830. " TDT <%x>\n"
  3831. " next_to_use <%x>\n"
  3832. " next_to_clean <%x>\n"
  3833. "buffer_info[next_to_clean]\n"
  3834. " time_stamp <%lx>\n"
  3835. " next_to_watch <%x>\n"
  3836. " jiffies <%lx>\n"
  3837. " desc.status <%x>\n",
  3838. tx_ring->queue_index,
  3839. readl(adapter->hw.hw_addr + tx_ring->head),
  3840. readl(adapter->hw.hw_addr + tx_ring->tail),
  3841. tx_ring->next_to_use,
  3842. tx_ring->next_to_clean,
  3843. tx_ring->buffer_info[i].time_stamp,
  3844. eop,
  3845. jiffies,
  3846. eop_desc->wb.status);
  3847. netif_stop_subqueue(netdev, tx_ring->queue_index);
  3848. }
  3849. }
  3850. tx_ring->total_bytes += total_bytes;
  3851. tx_ring->total_packets += total_packets;
  3852. tx_ring->tx_stats.bytes += total_bytes;
  3853. tx_ring->tx_stats.packets += total_packets;
  3854. adapter->net_stats.tx_bytes += total_bytes;
  3855. adapter->net_stats.tx_packets += total_packets;
  3856. return (count < tx_ring->count);
  3857. }
  3858. /**
  3859. * igb_receive_skb - helper function to handle rx indications
  3860. * @ring: pointer to receive ring receving this packet
  3861. * @status: descriptor status field as written by hardware
  3862. * @rx_desc: receive descriptor containing vlan and type information.
  3863. * @skb: pointer to sk_buff to be indicated to stack
  3864. **/
  3865. static void igb_receive_skb(struct igb_ring *ring, u8 status,
  3866. union e1000_adv_rx_desc * rx_desc,
  3867. struct sk_buff *skb)
  3868. {
  3869. struct igb_adapter * adapter = ring->adapter;
  3870. bool vlan_extracted = (adapter->vlgrp && (status & E1000_RXD_STAT_VP));
  3871. skb_record_rx_queue(skb, ring->queue_index);
  3872. if (vlan_extracted)
  3873. vlan_gro_receive(&ring->napi, adapter->vlgrp,
  3874. le16_to_cpu(rx_desc->wb.upper.vlan),
  3875. skb);
  3876. else
  3877. napi_gro_receive(&ring->napi, skb);
  3878. }
  3879. static inline void igb_rx_checksum_adv(struct igb_adapter *adapter,
  3880. u32 status_err, struct sk_buff *skb)
  3881. {
  3882. skb->ip_summed = CHECKSUM_NONE;
  3883. /* Ignore Checksum bit is set or checksum is disabled through ethtool */
  3884. if ((status_err & E1000_RXD_STAT_IXSM) ||
  3885. (adapter->flags & IGB_FLAG_RX_CSUM_DISABLED))
  3886. return;
  3887. /* TCP/UDP checksum error bit is set */
  3888. if (status_err &
  3889. (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
  3890. /*
  3891. * work around errata with sctp packets where the TCPE aka
  3892. * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
  3893. * packets, (aka let the stack check the crc32c)
  3894. */
  3895. if (!((adapter->hw.mac.type == e1000_82576) &&
  3896. (skb->len == 60)))
  3897. adapter->hw_csum_err++;
  3898. /* let the stack verify checksum errors */
  3899. return;
  3900. }
  3901. /* It must be a TCP or UDP packet with a valid checksum */
  3902. if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
  3903. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3904. dev_dbg(&adapter->pdev->dev, "cksum success: bits %08X\n", status_err);
  3905. adapter->hw_csum_good++;
  3906. }
  3907. static inline u16 igb_get_hlen(struct igb_adapter *adapter,
  3908. union e1000_adv_rx_desc *rx_desc)
  3909. {
  3910. /* HW will not DMA in data larger than the given buffer, even if it
  3911. * parses the (NFS, of course) header to be larger. In that case, it
  3912. * fills the header buffer and spills the rest into the page.
  3913. */
  3914. u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
  3915. E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
  3916. if (hlen > adapter->rx_ps_hdr_size)
  3917. hlen = adapter->rx_ps_hdr_size;
  3918. return hlen;
  3919. }
  3920. static bool igb_clean_rx_irq_adv(struct igb_ring *rx_ring,
  3921. int *work_done, int budget)
  3922. {
  3923. struct igb_adapter *adapter = rx_ring->adapter;
  3924. struct net_device *netdev = adapter->netdev;
  3925. struct e1000_hw *hw = &adapter->hw;
  3926. struct pci_dev *pdev = adapter->pdev;
  3927. union e1000_adv_rx_desc *rx_desc , *next_rxd;
  3928. struct igb_buffer *buffer_info , *next_buffer;
  3929. struct sk_buff *skb;
  3930. bool cleaned = false;
  3931. int cleaned_count = 0;
  3932. unsigned int total_bytes = 0, total_packets = 0;
  3933. unsigned int i;
  3934. u32 staterr;
  3935. u16 length;
  3936. i = rx_ring->next_to_clean;
  3937. buffer_info = &rx_ring->buffer_info[i];
  3938. rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
  3939. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  3940. while (staterr & E1000_RXD_STAT_DD) {
  3941. if (*work_done >= budget)
  3942. break;
  3943. (*work_done)++;
  3944. skb = buffer_info->skb;
  3945. prefetch(skb->data - NET_IP_ALIGN);
  3946. buffer_info->skb = NULL;
  3947. i++;
  3948. if (i == rx_ring->count)
  3949. i = 0;
  3950. next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
  3951. prefetch(next_rxd);
  3952. next_buffer = &rx_ring->buffer_info[i];
  3953. length = le16_to_cpu(rx_desc->wb.upper.length);
  3954. cleaned = true;
  3955. cleaned_count++;
  3956. /* this is the fast path for the non-packet split case */
  3957. if (!adapter->rx_ps_hdr_size) {
  3958. pci_unmap_single(pdev, buffer_info->dma,
  3959. adapter->rx_buffer_len,
  3960. PCI_DMA_FROMDEVICE);
  3961. buffer_info->dma = 0;
  3962. skb_put(skb, length);
  3963. goto send_up;
  3964. }
  3965. if (buffer_info->dma) {
  3966. u16 hlen = igb_get_hlen(adapter, rx_desc);
  3967. pci_unmap_single(pdev, buffer_info->dma,
  3968. adapter->rx_ps_hdr_size,
  3969. PCI_DMA_FROMDEVICE);
  3970. buffer_info->dma = 0;
  3971. skb_put(skb, hlen);
  3972. }
  3973. if (length) {
  3974. pci_unmap_page(pdev, buffer_info->page_dma,
  3975. PAGE_SIZE / 2, PCI_DMA_FROMDEVICE);
  3976. buffer_info->page_dma = 0;
  3977. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags++,
  3978. buffer_info->page,
  3979. buffer_info->page_offset,
  3980. length);
  3981. if ((adapter->rx_buffer_len > (PAGE_SIZE / 2)) ||
  3982. (page_count(buffer_info->page) != 1))
  3983. buffer_info->page = NULL;
  3984. else
  3985. get_page(buffer_info->page);
  3986. skb->len += length;
  3987. skb->data_len += length;
  3988. skb->truesize += length;
  3989. }
  3990. if (!(staterr & E1000_RXD_STAT_EOP)) {
  3991. buffer_info->skb = next_buffer->skb;
  3992. buffer_info->dma = next_buffer->dma;
  3993. next_buffer->skb = skb;
  3994. next_buffer->dma = 0;
  3995. goto next_desc;
  3996. }
  3997. send_up:
  3998. /*
  3999. * If this bit is set, then the RX registers contain
  4000. * the time stamp. No other packet will be time
  4001. * stamped until we read these registers, so read the
  4002. * registers to make them available again. Because
  4003. * only one packet can be time stamped at a time, we
  4004. * know that the register values must belong to this
  4005. * one here and therefore we don't need to compare
  4006. * any of the additional attributes stored for it.
  4007. *
  4008. * If nothing went wrong, then it should have a
  4009. * skb_shared_tx that we can turn into a
  4010. * skb_shared_hwtstamps.
  4011. *
  4012. * TODO: can time stamping be triggered (thus locking
  4013. * the registers) without the packet reaching this point
  4014. * here? In that case RX time stamping would get stuck.
  4015. *
  4016. * TODO: in "time stamp all packets" mode this bit is
  4017. * not set. Need a global flag for this mode and then
  4018. * always read the registers. Cannot be done without
  4019. * a race condition.
  4020. */
  4021. if (unlikely(staterr & E1000_RXD_STAT_TS)) {
  4022. u64 regval;
  4023. u64 ns;
  4024. struct skb_shared_hwtstamps *shhwtstamps =
  4025. skb_hwtstamps(skb);
  4026. WARN(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID),
  4027. "igb: no RX time stamp available for time stamped packet");
  4028. regval = rd32(E1000_RXSTMPL);
  4029. regval |= (u64)rd32(E1000_RXSTMPH) << 32;
  4030. ns = timecounter_cyc2time(&adapter->clock, regval);
  4031. timecompare_update(&adapter->compare, ns);
  4032. memset(shhwtstamps, 0, sizeof(*shhwtstamps));
  4033. shhwtstamps->hwtstamp = ns_to_ktime(ns);
  4034. shhwtstamps->syststamp =
  4035. timecompare_transform(&adapter->compare, ns);
  4036. }
  4037. if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
  4038. dev_kfree_skb_irq(skb);
  4039. goto next_desc;
  4040. }
  4041. total_bytes += skb->len;
  4042. total_packets++;
  4043. igb_rx_checksum_adv(adapter, staterr, skb);
  4044. skb->protocol = eth_type_trans(skb, netdev);
  4045. igb_receive_skb(rx_ring, staterr, rx_desc, skb);
  4046. next_desc:
  4047. rx_desc->wb.upper.status_error = 0;
  4048. /* return some buffers to hardware, one at a time is too slow */
  4049. if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
  4050. igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
  4051. cleaned_count = 0;
  4052. }
  4053. /* use prefetched values */
  4054. rx_desc = next_rxd;
  4055. buffer_info = next_buffer;
  4056. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  4057. }
  4058. rx_ring->next_to_clean = i;
  4059. cleaned_count = igb_desc_unused(rx_ring);
  4060. if (cleaned_count)
  4061. igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
  4062. rx_ring->total_packets += total_packets;
  4063. rx_ring->total_bytes += total_bytes;
  4064. rx_ring->rx_stats.packets += total_packets;
  4065. rx_ring->rx_stats.bytes += total_bytes;
  4066. adapter->net_stats.rx_bytes += total_bytes;
  4067. adapter->net_stats.rx_packets += total_packets;
  4068. return cleaned;
  4069. }
  4070. /**
  4071. * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
  4072. * @adapter: address of board private structure
  4073. **/
  4074. static void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring,
  4075. int cleaned_count)
  4076. {
  4077. struct igb_adapter *adapter = rx_ring->adapter;
  4078. struct net_device *netdev = adapter->netdev;
  4079. struct pci_dev *pdev = adapter->pdev;
  4080. union e1000_adv_rx_desc *rx_desc;
  4081. struct igb_buffer *buffer_info;
  4082. struct sk_buff *skb;
  4083. unsigned int i;
  4084. int bufsz;
  4085. i = rx_ring->next_to_use;
  4086. buffer_info = &rx_ring->buffer_info[i];
  4087. if (adapter->rx_ps_hdr_size)
  4088. bufsz = adapter->rx_ps_hdr_size;
  4089. else
  4090. bufsz = adapter->rx_buffer_len;
  4091. while (cleaned_count--) {
  4092. rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
  4093. if (adapter->rx_ps_hdr_size && !buffer_info->page_dma) {
  4094. if (!buffer_info->page) {
  4095. buffer_info->page = alloc_page(GFP_ATOMIC);
  4096. if (!buffer_info->page) {
  4097. adapter->alloc_rx_buff_failed++;
  4098. goto no_buffers;
  4099. }
  4100. buffer_info->page_offset = 0;
  4101. } else {
  4102. buffer_info->page_offset ^= PAGE_SIZE / 2;
  4103. }
  4104. buffer_info->page_dma =
  4105. pci_map_page(pdev, buffer_info->page,
  4106. buffer_info->page_offset,
  4107. PAGE_SIZE / 2,
  4108. PCI_DMA_FROMDEVICE);
  4109. }
  4110. if (!buffer_info->skb) {
  4111. skb = netdev_alloc_skb(netdev, bufsz + NET_IP_ALIGN);
  4112. if (!skb) {
  4113. adapter->alloc_rx_buff_failed++;
  4114. goto no_buffers;
  4115. }
  4116. /* Make buffer alignment 2 beyond a 16 byte boundary
  4117. * this will result in a 16 byte aligned IP header after
  4118. * the 14 byte MAC header is removed
  4119. */
  4120. skb_reserve(skb, NET_IP_ALIGN);
  4121. buffer_info->skb = skb;
  4122. buffer_info->dma = pci_map_single(pdev, skb->data,
  4123. bufsz,
  4124. PCI_DMA_FROMDEVICE);
  4125. }
  4126. /* Refresh the desc even if buffer_addrs didn't change because
  4127. * each write-back erases this info. */
  4128. if (adapter->rx_ps_hdr_size) {
  4129. rx_desc->read.pkt_addr =
  4130. cpu_to_le64(buffer_info->page_dma);
  4131. rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
  4132. } else {
  4133. rx_desc->read.pkt_addr =
  4134. cpu_to_le64(buffer_info->dma);
  4135. rx_desc->read.hdr_addr = 0;
  4136. }
  4137. i++;
  4138. if (i == rx_ring->count)
  4139. i = 0;
  4140. buffer_info = &rx_ring->buffer_info[i];
  4141. }
  4142. no_buffers:
  4143. if (rx_ring->next_to_use != i) {
  4144. rx_ring->next_to_use = i;
  4145. if (i == 0)
  4146. i = (rx_ring->count - 1);
  4147. else
  4148. i--;
  4149. /* Force memory writes to complete before letting h/w
  4150. * know there are new descriptors to fetch. (Only
  4151. * applicable for weak-ordered memory model archs,
  4152. * such as IA-64). */
  4153. wmb();
  4154. writel(i, adapter->hw.hw_addr + rx_ring->tail);
  4155. }
  4156. }
  4157. /**
  4158. * igb_mii_ioctl -
  4159. * @netdev:
  4160. * @ifreq:
  4161. * @cmd:
  4162. **/
  4163. static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  4164. {
  4165. struct igb_adapter *adapter = netdev_priv(netdev);
  4166. struct mii_ioctl_data *data = if_mii(ifr);
  4167. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  4168. return -EOPNOTSUPP;
  4169. switch (cmd) {
  4170. case SIOCGMIIPHY:
  4171. data->phy_id = adapter->hw.phy.addr;
  4172. break;
  4173. case SIOCGMIIREG:
  4174. if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
  4175. &data->val_out))
  4176. return -EIO;
  4177. break;
  4178. case SIOCSMIIREG:
  4179. default:
  4180. return -EOPNOTSUPP;
  4181. }
  4182. return 0;
  4183. }
  4184. /**
  4185. * igb_hwtstamp_ioctl - control hardware time stamping
  4186. * @netdev:
  4187. * @ifreq:
  4188. * @cmd:
  4189. *
  4190. * Outgoing time stamping can be enabled and disabled. Play nice and
  4191. * disable it when requested, although it shouldn't case any overhead
  4192. * when no packet needs it. At most one packet in the queue may be
  4193. * marked for time stamping, otherwise it would be impossible to tell
  4194. * for sure to which packet the hardware time stamp belongs.
  4195. *
  4196. * Incoming time stamping has to be configured via the hardware
  4197. * filters. Not all combinations are supported, in particular event
  4198. * type has to be specified. Matching the kind of event packet is
  4199. * not supported, with the exception of "all V2 events regardless of
  4200. * level 2 or 4".
  4201. *
  4202. **/
  4203. static int igb_hwtstamp_ioctl(struct net_device *netdev,
  4204. struct ifreq *ifr, int cmd)
  4205. {
  4206. struct igb_adapter *adapter = netdev_priv(netdev);
  4207. struct e1000_hw *hw = &adapter->hw;
  4208. struct hwtstamp_config config;
  4209. u32 tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED;
  4210. u32 tsync_rx_ctl_bit = E1000_TSYNCRXCTL_ENABLED;
  4211. u32 tsync_rx_ctl_type = 0;
  4212. u32 tsync_rx_cfg = 0;
  4213. int is_l4 = 0;
  4214. int is_l2 = 0;
  4215. short port = 319; /* PTP */
  4216. u32 regval;
  4217. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  4218. return -EFAULT;
  4219. /* reserved for future extensions */
  4220. if (config.flags)
  4221. return -EINVAL;
  4222. switch (config.tx_type) {
  4223. case HWTSTAMP_TX_OFF:
  4224. tsync_tx_ctl_bit = 0;
  4225. break;
  4226. case HWTSTAMP_TX_ON:
  4227. tsync_tx_ctl_bit = E1000_TSYNCTXCTL_ENABLED;
  4228. break;
  4229. default:
  4230. return -ERANGE;
  4231. }
  4232. switch (config.rx_filter) {
  4233. case HWTSTAMP_FILTER_NONE:
  4234. tsync_rx_ctl_bit = 0;
  4235. break;
  4236. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  4237. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  4238. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  4239. case HWTSTAMP_FILTER_ALL:
  4240. /*
  4241. * register TSYNCRXCFG must be set, therefore it is not
  4242. * possible to time stamp both Sync and Delay_Req messages
  4243. * => fall back to time stamping all packets
  4244. */
  4245. tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_ALL;
  4246. config.rx_filter = HWTSTAMP_FILTER_ALL;
  4247. break;
  4248. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  4249. tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1;
  4250. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
  4251. is_l4 = 1;
  4252. break;
  4253. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  4254. tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L4_V1;
  4255. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
  4256. is_l4 = 1;
  4257. break;
  4258. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  4259. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  4260. tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  4261. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
  4262. is_l2 = 1;
  4263. is_l4 = 1;
  4264. config.rx_filter = HWTSTAMP_FILTER_SOME;
  4265. break;
  4266. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  4267. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  4268. tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  4269. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
  4270. is_l2 = 1;
  4271. is_l4 = 1;
  4272. config.rx_filter = HWTSTAMP_FILTER_SOME;
  4273. break;
  4274. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  4275. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  4276. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  4277. tsync_rx_ctl_type = E1000_TSYNCRXCTL_TYPE_EVENT_V2;
  4278. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  4279. is_l2 = 1;
  4280. break;
  4281. default:
  4282. return -ERANGE;
  4283. }
  4284. /* enable/disable TX */
  4285. regval = rd32(E1000_TSYNCTXCTL);
  4286. regval = (regval & ~E1000_TSYNCTXCTL_ENABLED) | tsync_tx_ctl_bit;
  4287. wr32(E1000_TSYNCTXCTL, regval);
  4288. /* enable/disable RX, define which PTP packets are time stamped */
  4289. regval = rd32(E1000_TSYNCRXCTL);
  4290. regval = (regval & ~E1000_TSYNCRXCTL_ENABLED) | tsync_rx_ctl_bit;
  4291. regval = (regval & ~0xE) | tsync_rx_ctl_type;
  4292. wr32(E1000_TSYNCRXCTL, regval);
  4293. wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
  4294. /*
  4295. * Ethertype Filter Queue Filter[0][15:0] = 0x88F7
  4296. * (Ethertype to filter on)
  4297. * Ethertype Filter Queue Filter[0][26] = 0x1 (Enable filter)
  4298. * Ethertype Filter Queue Filter[0][30] = 0x1 (Enable Timestamping)
  4299. */
  4300. wr32(E1000_ETQF0, is_l2 ? 0x440088f7 : 0);
  4301. /* L4 Queue Filter[0]: only filter by source and destination port */
  4302. wr32(E1000_SPQF0, htons(port));
  4303. wr32(E1000_IMIREXT(0), is_l4 ?
  4304. ((1<<12) | (1<<19) /* bypass size and control flags */) : 0);
  4305. wr32(E1000_IMIR(0), is_l4 ?
  4306. (htons(port)
  4307. | (0<<16) /* immediate interrupt disabled */
  4308. | 0 /* (1<<17) bit cleared: do not bypass
  4309. destination port check */)
  4310. : 0);
  4311. wr32(E1000_FTQF0, is_l4 ?
  4312. (0x11 /* UDP */
  4313. | (1<<15) /* VF not compared */
  4314. | (1<<27) /* Enable Timestamping */
  4315. | (7<<28) /* only source port filter enabled,
  4316. source/target address and protocol
  4317. masked */)
  4318. : ((1<<15) | (15<<28) /* all mask bits set = filter not
  4319. enabled */));
  4320. wrfl();
  4321. adapter->hwtstamp_config = config;
  4322. /* clear TX/RX time stamp registers, just to be sure */
  4323. regval = rd32(E1000_TXSTMPH);
  4324. regval = rd32(E1000_RXSTMPH);
  4325. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  4326. -EFAULT : 0;
  4327. }
  4328. /**
  4329. * igb_ioctl -
  4330. * @netdev:
  4331. * @ifreq:
  4332. * @cmd:
  4333. **/
  4334. static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  4335. {
  4336. switch (cmd) {
  4337. case SIOCGMIIPHY:
  4338. case SIOCGMIIREG:
  4339. case SIOCSMIIREG:
  4340. return igb_mii_ioctl(netdev, ifr, cmd);
  4341. case SIOCSHWTSTAMP:
  4342. return igb_hwtstamp_ioctl(netdev, ifr, cmd);
  4343. default:
  4344. return -EOPNOTSUPP;
  4345. }
  4346. }
  4347. s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  4348. {
  4349. struct igb_adapter *adapter = hw->back;
  4350. u16 cap_offset;
  4351. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  4352. if (!cap_offset)
  4353. return -E1000_ERR_CONFIG;
  4354. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  4355. return 0;
  4356. }
  4357. s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  4358. {
  4359. struct igb_adapter *adapter = hw->back;
  4360. u16 cap_offset;
  4361. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  4362. if (!cap_offset)
  4363. return -E1000_ERR_CONFIG;
  4364. pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
  4365. return 0;
  4366. }
  4367. static void igb_vlan_rx_register(struct net_device *netdev,
  4368. struct vlan_group *grp)
  4369. {
  4370. struct igb_adapter *adapter = netdev_priv(netdev);
  4371. struct e1000_hw *hw = &adapter->hw;
  4372. u32 ctrl, rctl;
  4373. igb_irq_disable(adapter);
  4374. adapter->vlgrp = grp;
  4375. if (grp) {
  4376. /* enable VLAN tag insert/strip */
  4377. ctrl = rd32(E1000_CTRL);
  4378. ctrl |= E1000_CTRL_VME;
  4379. wr32(E1000_CTRL, ctrl);
  4380. /* enable VLAN receive filtering */
  4381. rctl = rd32(E1000_RCTL);
  4382. rctl &= ~E1000_RCTL_CFIEN;
  4383. wr32(E1000_RCTL, rctl);
  4384. igb_update_mng_vlan(adapter);
  4385. } else {
  4386. /* disable VLAN tag insert/strip */
  4387. ctrl = rd32(E1000_CTRL);
  4388. ctrl &= ~E1000_CTRL_VME;
  4389. wr32(E1000_CTRL, ctrl);
  4390. if (adapter->mng_vlan_id != (u16)IGB_MNG_VLAN_NONE) {
  4391. igb_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  4392. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  4393. }
  4394. }
  4395. igb_rlpml_set(adapter);
  4396. if (!test_bit(__IGB_DOWN, &adapter->state))
  4397. igb_irq_enable(adapter);
  4398. }
  4399. static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  4400. {
  4401. struct igb_adapter *adapter = netdev_priv(netdev);
  4402. struct e1000_hw *hw = &adapter->hw;
  4403. int pf_id = adapter->vfs_allocated_count;
  4404. if ((hw->mng_cookie.status &
  4405. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  4406. (vid == adapter->mng_vlan_id))
  4407. return;
  4408. /* add vid to vlvf if sr-iov is enabled,
  4409. * if that fails add directly to filter table */
  4410. if (igb_vlvf_set(adapter, vid, true, pf_id))
  4411. igb_vfta_set(hw, vid, true);
  4412. }
  4413. static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  4414. {
  4415. struct igb_adapter *adapter = netdev_priv(netdev);
  4416. struct e1000_hw *hw = &adapter->hw;
  4417. int pf_id = adapter->vfs_allocated_count;
  4418. igb_irq_disable(adapter);
  4419. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  4420. if (!test_bit(__IGB_DOWN, &adapter->state))
  4421. igb_irq_enable(adapter);
  4422. if ((adapter->hw.mng_cookie.status &
  4423. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  4424. (vid == adapter->mng_vlan_id)) {
  4425. /* release control to f/w */
  4426. igb_release_hw_control(adapter);
  4427. return;
  4428. }
  4429. /* remove vid from vlvf if sr-iov is enabled,
  4430. * if not in vlvf remove from vfta */
  4431. if (igb_vlvf_set(adapter, vid, false, pf_id))
  4432. igb_vfta_set(hw, vid, false);
  4433. }
  4434. static void igb_restore_vlan(struct igb_adapter *adapter)
  4435. {
  4436. igb_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  4437. if (adapter->vlgrp) {
  4438. u16 vid;
  4439. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  4440. if (!vlan_group_get_device(adapter->vlgrp, vid))
  4441. continue;
  4442. igb_vlan_rx_add_vid(adapter->netdev, vid);
  4443. }
  4444. }
  4445. }
  4446. int igb_set_spd_dplx(struct igb_adapter *adapter, u16 spddplx)
  4447. {
  4448. struct e1000_mac_info *mac = &adapter->hw.mac;
  4449. mac->autoneg = 0;
  4450. switch (spddplx) {
  4451. case SPEED_10 + DUPLEX_HALF:
  4452. mac->forced_speed_duplex = ADVERTISE_10_HALF;
  4453. break;
  4454. case SPEED_10 + DUPLEX_FULL:
  4455. mac->forced_speed_duplex = ADVERTISE_10_FULL;
  4456. break;
  4457. case SPEED_100 + DUPLEX_HALF:
  4458. mac->forced_speed_duplex = ADVERTISE_100_HALF;
  4459. break;
  4460. case SPEED_100 + DUPLEX_FULL:
  4461. mac->forced_speed_duplex = ADVERTISE_100_FULL;
  4462. break;
  4463. case SPEED_1000 + DUPLEX_FULL:
  4464. mac->autoneg = 1;
  4465. adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
  4466. break;
  4467. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  4468. default:
  4469. dev_err(&adapter->pdev->dev,
  4470. "Unsupported Speed/Duplex configuration\n");
  4471. return -EINVAL;
  4472. }
  4473. return 0;
  4474. }
  4475. static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake)
  4476. {
  4477. struct net_device *netdev = pci_get_drvdata(pdev);
  4478. struct igb_adapter *adapter = netdev_priv(netdev);
  4479. struct e1000_hw *hw = &adapter->hw;
  4480. u32 ctrl, rctl, status;
  4481. u32 wufc = adapter->wol;
  4482. #ifdef CONFIG_PM
  4483. int retval = 0;
  4484. #endif
  4485. netif_device_detach(netdev);
  4486. if (netif_running(netdev))
  4487. igb_close(netdev);
  4488. igb_reset_interrupt_capability(adapter);
  4489. igb_free_queues(adapter);
  4490. #ifdef CONFIG_PM
  4491. retval = pci_save_state(pdev);
  4492. if (retval)
  4493. return retval;
  4494. #endif
  4495. status = rd32(E1000_STATUS);
  4496. if (status & E1000_STATUS_LU)
  4497. wufc &= ~E1000_WUFC_LNKC;
  4498. if (wufc) {
  4499. igb_setup_rctl(adapter);
  4500. igb_set_rx_mode(netdev);
  4501. /* turn on all-multi mode if wake on multicast is enabled */
  4502. if (wufc & E1000_WUFC_MC) {
  4503. rctl = rd32(E1000_RCTL);
  4504. rctl |= E1000_RCTL_MPE;
  4505. wr32(E1000_RCTL, rctl);
  4506. }
  4507. ctrl = rd32(E1000_CTRL);
  4508. /* advertise wake from D3Cold */
  4509. #define E1000_CTRL_ADVD3WUC 0x00100000
  4510. /* phy power management enable */
  4511. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  4512. ctrl |= E1000_CTRL_ADVD3WUC;
  4513. wr32(E1000_CTRL, ctrl);
  4514. /* Allow time for pending master requests to run */
  4515. igb_disable_pcie_master(&adapter->hw);
  4516. wr32(E1000_WUC, E1000_WUC_PME_EN);
  4517. wr32(E1000_WUFC, wufc);
  4518. } else {
  4519. wr32(E1000_WUC, 0);
  4520. wr32(E1000_WUFC, 0);
  4521. }
  4522. *enable_wake = wufc || adapter->en_mng_pt;
  4523. if (!*enable_wake)
  4524. igb_shutdown_serdes_link_82575(hw);
  4525. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  4526. * would have already happened in close and is redundant. */
  4527. igb_release_hw_control(adapter);
  4528. pci_disable_device(pdev);
  4529. return 0;
  4530. }
  4531. #ifdef CONFIG_PM
  4532. static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
  4533. {
  4534. int retval;
  4535. bool wake;
  4536. retval = __igb_shutdown(pdev, &wake);
  4537. if (retval)
  4538. return retval;
  4539. if (wake) {
  4540. pci_prepare_to_sleep(pdev);
  4541. } else {
  4542. pci_wake_from_d3(pdev, false);
  4543. pci_set_power_state(pdev, PCI_D3hot);
  4544. }
  4545. return 0;
  4546. }
  4547. static int igb_resume(struct pci_dev *pdev)
  4548. {
  4549. struct net_device *netdev = pci_get_drvdata(pdev);
  4550. struct igb_adapter *adapter = netdev_priv(netdev);
  4551. struct e1000_hw *hw = &adapter->hw;
  4552. u32 err;
  4553. pci_set_power_state(pdev, PCI_D0);
  4554. pci_restore_state(pdev);
  4555. err = pci_enable_device_mem(pdev);
  4556. if (err) {
  4557. dev_err(&pdev->dev,
  4558. "igb: Cannot enable PCI device from suspend\n");
  4559. return err;
  4560. }
  4561. pci_set_master(pdev);
  4562. pci_enable_wake(pdev, PCI_D3hot, 0);
  4563. pci_enable_wake(pdev, PCI_D3cold, 0);
  4564. igb_set_interrupt_capability(adapter);
  4565. if (igb_alloc_queues(adapter)) {
  4566. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  4567. return -ENOMEM;
  4568. }
  4569. /* e1000_power_up_phy(adapter); */
  4570. igb_reset(adapter);
  4571. /* let the f/w know that the h/w is now under the control of the
  4572. * driver. */
  4573. igb_get_hw_control(adapter);
  4574. wr32(E1000_WUS, ~0);
  4575. if (netif_running(netdev)) {
  4576. err = igb_open(netdev);
  4577. if (err)
  4578. return err;
  4579. }
  4580. netif_device_attach(netdev);
  4581. return 0;
  4582. }
  4583. #endif
  4584. static void igb_shutdown(struct pci_dev *pdev)
  4585. {
  4586. bool wake;
  4587. __igb_shutdown(pdev, &wake);
  4588. if (system_state == SYSTEM_POWER_OFF) {
  4589. pci_wake_from_d3(pdev, wake);
  4590. pci_set_power_state(pdev, PCI_D3hot);
  4591. }
  4592. }
  4593. #ifdef CONFIG_NET_POLL_CONTROLLER
  4594. /*
  4595. * Polling 'interrupt' - used by things like netconsole to send skbs
  4596. * without having to re-enable interrupts. It's not called while
  4597. * the interrupt routine is executing.
  4598. */
  4599. static void igb_netpoll(struct net_device *netdev)
  4600. {
  4601. struct igb_adapter *adapter = netdev_priv(netdev);
  4602. struct e1000_hw *hw = &adapter->hw;
  4603. int i;
  4604. if (!adapter->msix_entries) {
  4605. igb_irq_disable(adapter);
  4606. napi_schedule(&adapter->rx_ring[0].napi);
  4607. return;
  4608. }
  4609. for (i = 0; i < adapter->num_tx_queues; i++) {
  4610. struct igb_ring *tx_ring = &adapter->tx_ring[i];
  4611. wr32(E1000_EIMC, tx_ring->eims_value);
  4612. igb_clean_tx_irq(tx_ring);
  4613. wr32(E1000_EIMS, tx_ring->eims_value);
  4614. }
  4615. for (i = 0; i < adapter->num_rx_queues; i++) {
  4616. struct igb_ring *rx_ring = &adapter->rx_ring[i];
  4617. wr32(E1000_EIMC, rx_ring->eims_value);
  4618. napi_schedule(&rx_ring->napi);
  4619. }
  4620. }
  4621. #endif /* CONFIG_NET_POLL_CONTROLLER */
  4622. /**
  4623. * igb_io_error_detected - called when PCI error is detected
  4624. * @pdev: Pointer to PCI device
  4625. * @state: The current pci connection state
  4626. *
  4627. * This function is called after a PCI bus error affecting
  4628. * this device has been detected.
  4629. */
  4630. static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
  4631. pci_channel_state_t state)
  4632. {
  4633. struct net_device *netdev = pci_get_drvdata(pdev);
  4634. struct igb_adapter *adapter = netdev_priv(netdev);
  4635. netif_device_detach(netdev);
  4636. if (state == pci_channel_io_perm_failure)
  4637. return PCI_ERS_RESULT_DISCONNECT;
  4638. if (netif_running(netdev))
  4639. igb_down(adapter);
  4640. pci_disable_device(pdev);
  4641. /* Request a slot slot reset. */
  4642. return PCI_ERS_RESULT_NEED_RESET;
  4643. }
  4644. /**
  4645. * igb_io_slot_reset - called after the pci bus has been reset.
  4646. * @pdev: Pointer to PCI device
  4647. *
  4648. * Restart the card from scratch, as if from a cold-boot. Implementation
  4649. * resembles the first-half of the igb_resume routine.
  4650. */
  4651. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
  4652. {
  4653. struct net_device *netdev = pci_get_drvdata(pdev);
  4654. struct igb_adapter *adapter = netdev_priv(netdev);
  4655. struct e1000_hw *hw = &adapter->hw;
  4656. pci_ers_result_t result;
  4657. int err;
  4658. if (pci_enable_device_mem(pdev)) {
  4659. dev_err(&pdev->dev,
  4660. "Cannot re-enable PCI device after reset.\n");
  4661. result = PCI_ERS_RESULT_DISCONNECT;
  4662. } else {
  4663. pci_set_master(pdev);
  4664. pci_restore_state(pdev);
  4665. pci_enable_wake(pdev, PCI_D3hot, 0);
  4666. pci_enable_wake(pdev, PCI_D3cold, 0);
  4667. igb_reset(adapter);
  4668. wr32(E1000_WUS, ~0);
  4669. result = PCI_ERS_RESULT_RECOVERED;
  4670. }
  4671. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  4672. if (err) {
  4673. dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
  4674. "failed 0x%0x\n", err);
  4675. /* non-fatal, continue */
  4676. }
  4677. return result;
  4678. }
  4679. /**
  4680. * igb_io_resume - called when traffic can start flowing again.
  4681. * @pdev: Pointer to PCI device
  4682. *
  4683. * This callback is called when the error recovery driver tells us that
  4684. * its OK to resume normal operation. Implementation resembles the
  4685. * second-half of the igb_resume routine.
  4686. */
  4687. static void igb_io_resume(struct pci_dev *pdev)
  4688. {
  4689. struct net_device *netdev = pci_get_drvdata(pdev);
  4690. struct igb_adapter *adapter = netdev_priv(netdev);
  4691. if (netif_running(netdev)) {
  4692. if (igb_up(adapter)) {
  4693. dev_err(&pdev->dev, "igb_up failed after reset\n");
  4694. return;
  4695. }
  4696. }
  4697. netif_device_attach(netdev);
  4698. /* let the f/w know that the h/w is now under the control of the
  4699. * driver. */
  4700. igb_get_hw_control(adapter);
  4701. }
  4702. static int igb_set_vf_mac(struct igb_adapter *adapter,
  4703. int vf, unsigned char *mac_addr)
  4704. {
  4705. struct e1000_hw *hw = &adapter->hw;
  4706. /* VF MAC addresses start at end of receive addresses and moves
  4707. * torwards the first, as a result a collision should not be possible */
  4708. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  4709. memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
  4710. igb_rar_set(hw, mac_addr, rar_entry);
  4711. igb_set_rah_pool(hw, vf, rar_entry);
  4712. return 0;
  4713. }
  4714. static void igb_vmm_control(struct igb_adapter *adapter)
  4715. {
  4716. struct e1000_hw *hw = &adapter->hw;
  4717. u32 reg_data;
  4718. if (!adapter->vfs_allocated_count)
  4719. return;
  4720. /* VF's need PF reset indication before they
  4721. * can send/receive mail */
  4722. reg_data = rd32(E1000_CTRL_EXT);
  4723. reg_data |= E1000_CTRL_EXT_PFRSTD;
  4724. wr32(E1000_CTRL_EXT, reg_data);
  4725. igb_vmdq_set_loopback_pf(hw, true);
  4726. igb_vmdq_set_replication_pf(hw, true);
  4727. }
  4728. /* igb_main.c */