e1000_main.c 152 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332
  1. /*******************************************************************************
  2. Intel PRO/1000 Linux driver
  3. Copyright(c) 1999 - 2006 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. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "e1000.h"
  22. #include <net/ip6_checksum.h>
  23. char e1000_driver_name[] = "e1000";
  24. static char e1000_driver_string[] = "Intel(R) PRO/1000 Network Driver";
  25. #ifndef CONFIG_E1000_NAPI
  26. #define DRIVERNAPI
  27. #else
  28. #define DRIVERNAPI "-NAPI"
  29. #endif
  30. #define DRV_VERSION "7.3.20-k2"DRIVERNAPI
  31. char e1000_driver_version[] = DRV_VERSION;
  32. static char e1000_copyright[] = "Copyright (c) 1999-2006 Intel Corporation.";
  33. /* e1000_pci_tbl - PCI Device ID Table
  34. *
  35. * Last entry must be all 0s
  36. *
  37. * Macro expands to...
  38. * {PCI_DEVICE(PCI_VENDOR_ID_INTEL, device_id)}
  39. */
  40. static struct pci_device_id e1000_pci_tbl[] = {
  41. INTEL_E1000_ETHERNET_DEVICE(0x1000),
  42. INTEL_E1000_ETHERNET_DEVICE(0x1001),
  43. INTEL_E1000_ETHERNET_DEVICE(0x1004),
  44. INTEL_E1000_ETHERNET_DEVICE(0x1008),
  45. INTEL_E1000_ETHERNET_DEVICE(0x1009),
  46. INTEL_E1000_ETHERNET_DEVICE(0x100C),
  47. INTEL_E1000_ETHERNET_DEVICE(0x100D),
  48. INTEL_E1000_ETHERNET_DEVICE(0x100E),
  49. INTEL_E1000_ETHERNET_DEVICE(0x100F),
  50. INTEL_E1000_ETHERNET_DEVICE(0x1010),
  51. INTEL_E1000_ETHERNET_DEVICE(0x1011),
  52. INTEL_E1000_ETHERNET_DEVICE(0x1012),
  53. INTEL_E1000_ETHERNET_DEVICE(0x1013),
  54. INTEL_E1000_ETHERNET_DEVICE(0x1014),
  55. INTEL_E1000_ETHERNET_DEVICE(0x1015),
  56. INTEL_E1000_ETHERNET_DEVICE(0x1016),
  57. INTEL_E1000_ETHERNET_DEVICE(0x1017),
  58. INTEL_E1000_ETHERNET_DEVICE(0x1018),
  59. INTEL_E1000_ETHERNET_DEVICE(0x1019),
  60. INTEL_E1000_ETHERNET_DEVICE(0x101A),
  61. INTEL_E1000_ETHERNET_DEVICE(0x101D),
  62. INTEL_E1000_ETHERNET_DEVICE(0x101E),
  63. INTEL_E1000_ETHERNET_DEVICE(0x1026),
  64. INTEL_E1000_ETHERNET_DEVICE(0x1027),
  65. INTEL_E1000_ETHERNET_DEVICE(0x1028),
  66. INTEL_E1000_ETHERNET_DEVICE(0x1049),
  67. INTEL_E1000_ETHERNET_DEVICE(0x104A),
  68. INTEL_E1000_ETHERNET_DEVICE(0x104B),
  69. INTEL_E1000_ETHERNET_DEVICE(0x104C),
  70. INTEL_E1000_ETHERNET_DEVICE(0x104D),
  71. INTEL_E1000_ETHERNET_DEVICE(0x105E),
  72. INTEL_E1000_ETHERNET_DEVICE(0x105F),
  73. INTEL_E1000_ETHERNET_DEVICE(0x1060),
  74. INTEL_E1000_ETHERNET_DEVICE(0x1075),
  75. INTEL_E1000_ETHERNET_DEVICE(0x1076),
  76. INTEL_E1000_ETHERNET_DEVICE(0x1077),
  77. INTEL_E1000_ETHERNET_DEVICE(0x1078),
  78. INTEL_E1000_ETHERNET_DEVICE(0x1079),
  79. INTEL_E1000_ETHERNET_DEVICE(0x107A),
  80. INTEL_E1000_ETHERNET_DEVICE(0x107B),
  81. INTEL_E1000_ETHERNET_DEVICE(0x107C),
  82. INTEL_E1000_ETHERNET_DEVICE(0x107D),
  83. INTEL_E1000_ETHERNET_DEVICE(0x107E),
  84. INTEL_E1000_ETHERNET_DEVICE(0x107F),
  85. INTEL_E1000_ETHERNET_DEVICE(0x108A),
  86. INTEL_E1000_ETHERNET_DEVICE(0x108B),
  87. INTEL_E1000_ETHERNET_DEVICE(0x108C),
  88. INTEL_E1000_ETHERNET_DEVICE(0x1096),
  89. INTEL_E1000_ETHERNET_DEVICE(0x1098),
  90. INTEL_E1000_ETHERNET_DEVICE(0x1099),
  91. INTEL_E1000_ETHERNET_DEVICE(0x109A),
  92. INTEL_E1000_ETHERNET_DEVICE(0x10A4),
  93. INTEL_E1000_ETHERNET_DEVICE(0x10A5),
  94. INTEL_E1000_ETHERNET_DEVICE(0x10B5),
  95. INTEL_E1000_ETHERNET_DEVICE(0x10B9),
  96. INTEL_E1000_ETHERNET_DEVICE(0x10BA),
  97. INTEL_E1000_ETHERNET_DEVICE(0x10BB),
  98. INTEL_E1000_ETHERNET_DEVICE(0x10BC),
  99. INTEL_E1000_ETHERNET_DEVICE(0x10C4),
  100. INTEL_E1000_ETHERNET_DEVICE(0x10C5),
  101. INTEL_E1000_ETHERNET_DEVICE(0x10D5),
  102. INTEL_E1000_ETHERNET_DEVICE(0x10D9),
  103. INTEL_E1000_ETHERNET_DEVICE(0x10DA),
  104. /* required last entry */
  105. {0,}
  106. };
  107. MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  108. int e1000_up(struct e1000_adapter *adapter);
  109. void e1000_down(struct e1000_adapter *adapter);
  110. void e1000_reinit_locked(struct e1000_adapter *adapter);
  111. void e1000_reset(struct e1000_adapter *adapter);
  112. int e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx);
  113. int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
  114. int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
  115. void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
  116. void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
  117. static int e1000_setup_tx_resources(struct e1000_adapter *adapter,
  118. struct e1000_tx_ring *txdr);
  119. static int e1000_setup_rx_resources(struct e1000_adapter *adapter,
  120. struct e1000_rx_ring *rxdr);
  121. static void e1000_free_tx_resources(struct e1000_adapter *adapter,
  122. struct e1000_tx_ring *tx_ring);
  123. static void e1000_free_rx_resources(struct e1000_adapter *adapter,
  124. struct e1000_rx_ring *rx_ring);
  125. void e1000_update_stats(struct e1000_adapter *adapter);
  126. static int e1000_init_module(void);
  127. static void e1000_exit_module(void);
  128. static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  129. static void __devexit e1000_remove(struct pci_dev *pdev);
  130. static int e1000_alloc_queues(struct e1000_adapter *adapter);
  131. static int e1000_sw_init(struct e1000_adapter *adapter);
  132. static int e1000_open(struct net_device *netdev);
  133. static int e1000_close(struct net_device *netdev);
  134. static void e1000_configure_tx(struct e1000_adapter *adapter);
  135. static void e1000_configure_rx(struct e1000_adapter *adapter);
  136. static void e1000_setup_rctl(struct e1000_adapter *adapter);
  137. static void e1000_clean_all_tx_rings(struct e1000_adapter *adapter);
  138. static void e1000_clean_all_rx_rings(struct e1000_adapter *adapter);
  139. static void e1000_clean_tx_ring(struct e1000_adapter *adapter,
  140. struct e1000_tx_ring *tx_ring);
  141. static void e1000_clean_rx_ring(struct e1000_adapter *adapter,
  142. struct e1000_rx_ring *rx_ring);
  143. static void e1000_set_multi(struct net_device *netdev);
  144. static void e1000_update_phy_info(unsigned long data);
  145. static void e1000_watchdog(unsigned long data);
  146. static void e1000_82547_tx_fifo_stall(unsigned long data);
  147. static int e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev);
  148. static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
  149. static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
  150. static int e1000_set_mac(struct net_device *netdev, void *p);
  151. static irqreturn_t e1000_intr(int irq, void *data);
  152. static irqreturn_t e1000_intr_msi(int irq, void *data);
  153. static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
  154. struct e1000_tx_ring *tx_ring);
  155. #ifdef CONFIG_E1000_NAPI
  156. static int e1000_clean(struct napi_struct *napi, int budget);
  157. static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
  158. struct e1000_rx_ring *rx_ring,
  159. int *work_done, int work_to_do);
  160. static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  161. struct e1000_rx_ring *rx_ring,
  162. int *work_done, int work_to_do);
  163. #else
  164. static boolean_t e1000_clean_rx_irq(struct e1000_adapter *adapter,
  165. struct e1000_rx_ring *rx_ring);
  166. static boolean_t e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  167. struct e1000_rx_ring *rx_ring);
  168. #endif
  169. static void e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
  170. struct e1000_rx_ring *rx_ring,
  171. int cleaned_count);
  172. static void e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
  173. struct e1000_rx_ring *rx_ring,
  174. int cleaned_count);
  175. static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
  176. static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  177. int cmd);
  178. void e1000_set_ethtool_ops(struct net_device *netdev);
  179. static void e1000_enter_82542_rst(struct e1000_adapter *adapter);
  180. static void e1000_leave_82542_rst(struct e1000_adapter *adapter);
  181. static void e1000_tx_timeout(struct net_device *dev);
  182. static void e1000_reset_task(struct work_struct *work);
  183. static void e1000_smartspeed(struct e1000_adapter *adapter);
  184. static int e1000_82547_fifo_workaround(struct e1000_adapter *adapter,
  185. struct sk_buff *skb);
  186. static void e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
  187. static void e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
  188. static void e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
  189. static void e1000_restore_vlan(struct e1000_adapter *adapter);
  190. static int e1000_suspend(struct pci_dev *pdev, pm_message_t state);
  191. #ifdef CONFIG_PM
  192. static int e1000_resume(struct pci_dev *pdev);
  193. #endif
  194. static void e1000_shutdown(struct pci_dev *pdev);
  195. #ifdef CONFIG_NET_POLL_CONTROLLER
  196. /* for netdump / net console */
  197. static void e1000_netpoll (struct net_device *netdev);
  198. #endif
  199. extern void e1000_check_options(struct e1000_adapter *adapter);
  200. #define COPYBREAK_DEFAULT 256
  201. static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
  202. module_param(copybreak, uint, 0644);
  203. MODULE_PARM_DESC(copybreak,
  204. "Maximum size of packet that is copied to a new buffer on receive");
  205. static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
  206. pci_channel_state_t state);
  207. static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
  208. static void e1000_io_resume(struct pci_dev *pdev);
  209. static struct pci_error_handlers e1000_err_handler = {
  210. .error_detected = e1000_io_error_detected,
  211. .slot_reset = e1000_io_slot_reset,
  212. .resume = e1000_io_resume,
  213. };
  214. static struct pci_driver e1000_driver = {
  215. .name = e1000_driver_name,
  216. .id_table = e1000_pci_tbl,
  217. .probe = e1000_probe,
  218. .remove = __devexit_p(e1000_remove),
  219. #ifdef CONFIG_PM
  220. /* Power Managment Hooks */
  221. .suspend = e1000_suspend,
  222. .resume = e1000_resume,
  223. #endif
  224. .shutdown = e1000_shutdown,
  225. .err_handler = &e1000_err_handler
  226. };
  227. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  228. MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  229. MODULE_LICENSE("GPL");
  230. MODULE_VERSION(DRV_VERSION);
  231. static int debug = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  232. module_param(debug, int, 0);
  233. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  234. /**
  235. * e1000_init_module - Driver Registration Routine
  236. *
  237. * e1000_init_module is the first routine called when the driver is
  238. * loaded. All it does is register with the PCI subsystem.
  239. **/
  240. static int __init
  241. e1000_init_module(void)
  242. {
  243. int ret;
  244. printk(KERN_INFO "%s - version %s\n",
  245. e1000_driver_string, e1000_driver_version);
  246. printk(KERN_INFO "%s\n", e1000_copyright);
  247. ret = pci_register_driver(&e1000_driver);
  248. if (copybreak != COPYBREAK_DEFAULT) {
  249. if (copybreak == 0)
  250. printk(KERN_INFO "e1000: copybreak disabled\n");
  251. else
  252. printk(KERN_INFO "e1000: copybreak enabled for "
  253. "packets <= %u bytes\n", copybreak);
  254. }
  255. return ret;
  256. }
  257. module_init(e1000_init_module);
  258. /**
  259. * e1000_exit_module - Driver Exit Cleanup Routine
  260. *
  261. * e1000_exit_module is called just before the driver is removed
  262. * from memory.
  263. **/
  264. static void __exit
  265. e1000_exit_module(void)
  266. {
  267. pci_unregister_driver(&e1000_driver);
  268. }
  269. module_exit(e1000_exit_module);
  270. static int e1000_request_irq(struct e1000_adapter *adapter)
  271. {
  272. struct net_device *netdev = adapter->netdev;
  273. void (*handler) = &e1000_intr;
  274. int irq_flags = IRQF_SHARED;
  275. int err;
  276. if (adapter->hw.mac_type >= e1000_82571) {
  277. adapter->have_msi = !pci_enable_msi(adapter->pdev);
  278. if (adapter->have_msi) {
  279. handler = &e1000_intr_msi;
  280. irq_flags = 0;
  281. }
  282. }
  283. err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
  284. netdev);
  285. if (err) {
  286. if (adapter->have_msi)
  287. pci_disable_msi(adapter->pdev);
  288. DPRINTK(PROBE, ERR,
  289. "Unable to allocate interrupt Error: %d\n", err);
  290. }
  291. return err;
  292. }
  293. static void e1000_free_irq(struct e1000_adapter *adapter)
  294. {
  295. struct net_device *netdev = adapter->netdev;
  296. free_irq(adapter->pdev->irq, netdev);
  297. if (adapter->have_msi)
  298. pci_disable_msi(adapter->pdev);
  299. }
  300. /**
  301. * e1000_irq_disable - Mask off interrupt generation on the NIC
  302. * @adapter: board private structure
  303. **/
  304. static void
  305. e1000_irq_disable(struct e1000_adapter *adapter)
  306. {
  307. atomic_inc(&adapter->irq_sem);
  308. E1000_WRITE_REG(&adapter->hw, IMC, ~0);
  309. E1000_WRITE_FLUSH(&adapter->hw);
  310. synchronize_irq(adapter->pdev->irq);
  311. }
  312. /**
  313. * e1000_irq_enable - Enable default interrupt generation settings
  314. * @adapter: board private structure
  315. **/
  316. static void
  317. e1000_irq_enable(struct e1000_adapter *adapter)
  318. {
  319. if (likely(atomic_dec_and_test(&adapter->irq_sem))) {
  320. E1000_WRITE_REG(&adapter->hw, IMS, IMS_ENABLE_MASK);
  321. E1000_WRITE_FLUSH(&adapter->hw);
  322. }
  323. }
  324. static void
  325. e1000_update_mng_vlan(struct e1000_adapter *adapter)
  326. {
  327. struct net_device *netdev = adapter->netdev;
  328. uint16_t vid = adapter->hw.mng_cookie.vlan_id;
  329. uint16_t old_vid = adapter->mng_vlan_id;
  330. if (adapter->vlgrp) {
  331. if (!vlan_group_get_device(adapter->vlgrp, vid)) {
  332. if (adapter->hw.mng_cookie.status &
  333. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) {
  334. e1000_vlan_rx_add_vid(netdev, vid);
  335. adapter->mng_vlan_id = vid;
  336. } else
  337. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  338. if ((old_vid != (uint16_t)E1000_MNG_VLAN_NONE) &&
  339. (vid != old_vid) &&
  340. !vlan_group_get_device(adapter->vlgrp, old_vid))
  341. e1000_vlan_rx_kill_vid(netdev, old_vid);
  342. } else
  343. adapter->mng_vlan_id = vid;
  344. }
  345. }
  346. /**
  347. * e1000_release_hw_control - release control of the h/w to f/w
  348. * @adapter: address of board private structure
  349. *
  350. * e1000_release_hw_control resets {CTRL_EXT|FWSM}:DRV_LOAD bit.
  351. * For ASF and Pass Through versions of f/w this means that the
  352. * driver is no longer loaded. For AMT version (only with 82573) i
  353. * of the f/w this means that the network i/f is closed.
  354. *
  355. **/
  356. static void
  357. e1000_release_hw_control(struct e1000_adapter *adapter)
  358. {
  359. uint32_t ctrl_ext;
  360. uint32_t swsm;
  361. /* Let firmware taken over control of h/w */
  362. switch (adapter->hw.mac_type) {
  363. case e1000_82573:
  364. swsm = E1000_READ_REG(&adapter->hw, SWSM);
  365. E1000_WRITE_REG(&adapter->hw, SWSM,
  366. swsm & ~E1000_SWSM_DRV_LOAD);
  367. break;
  368. case e1000_82571:
  369. case e1000_82572:
  370. case e1000_80003es2lan:
  371. case e1000_ich8lan:
  372. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  373. E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
  374. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  375. break;
  376. default:
  377. break;
  378. }
  379. }
  380. /**
  381. * e1000_get_hw_control - get control of the h/w from f/w
  382. * @adapter: address of board private structure
  383. *
  384. * e1000_get_hw_control sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
  385. * For ASF and Pass Through versions of f/w this means that
  386. * the driver is loaded. For AMT version (only with 82573)
  387. * of the f/w this means that the network i/f is open.
  388. *
  389. **/
  390. static void
  391. e1000_get_hw_control(struct e1000_adapter *adapter)
  392. {
  393. uint32_t ctrl_ext;
  394. uint32_t swsm;
  395. /* Let firmware know the driver has taken over */
  396. switch (adapter->hw.mac_type) {
  397. case e1000_82573:
  398. swsm = E1000_READ_REG(&adapter->hw, SWSM);
  399. E1000_WRITE_REG(&adapter->hw, SWSM,
  400. swsm | E1000_SWSM_DRV_LOAD);
  401. break;
  402. case e1000_82571:
  403. case e1000_82572:
  404. case e1000_80003es2lan:
  405. case e1000_ich8lan:
  406. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  407. E1000_WRITE_REG(&adapter->hw, CTRL_EXT,
  408. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  409. break;
  410. default:
  411. break;
  412. }
  413. }
  414. static void
  415. e1000_init_manageability(struct e1000_adapter *adapter)
  416. {
  417. if (adapter->en_mng_pt) {
  418. uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
  419. /* disable hardware interception of ARP */
  420. manc &= ~(E1000_MANC_ARP_EN);
  421. /* enable receiving management packets to the host */
  422. /* this will probably generate destination unreachable messages
  423. * from the host OS, but the packets will be handled on SMBUS */
  424. if (adapter->hw.has_manc2h) {
  425. uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
  426. manc |= E1000_MANC_EN_MNG2HOST;
  427. #define E1000_MNG2HOST_PORT_623 (1 << 5)
  428. #define E1000_MNG2HOST_PORT_664 (1 << 6)
  429. manc2h |= E1000_MNG2HOST_PORT_623;
  430. manc2h |= E1000_MNG2HOST_PORT_664;
  431. E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
  432. }
  433. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  434. }
  435. }
  436. static void
  437. e1000_release_manageability(struct e1000_adapter *adapter)
  438. {
  439. if (adapter->en_mng_pt) {
  440. uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
  441. /* re-enable hardware interception of ARP */
  442. manc |= E1000_MANC_ARP_EN;
  443. if (adapter->hw.has_manc2h)
  444. manc &= ~E1000_MANC_EN_MNG2HOST;
  445. /* don't explicitly have to mess with MANC2H since
  446. * MANC has an enable disable that gates MANC2H */
  447. E1000_WRITE_REG(&adapter->hw, MANC, manc);
  448. }
  449. }
  450. /**
  451. * e1000_configure - configure the hardware for RX and TX
  452. * @adapter = private board structure
  453. **/
  454. static void e1000_configure(struct e1000_adapter *adapter)
  455. {
  456. struct net_device *netdev = adapter->netdev;
  457. int i;
  458. e1000_set_multi(netdev);
  459. e1000_restore_vlan(adapter);
  460. e1000_init_manageability(adapter);
  461. e1000_configure_tx(adapter);
  462. e1000_setup_rctl(adapter);
  463. e1000_configure_rx(adapter);
  464. /* call E1000_DESC_UNUSED which always leaves
  465. * at least 1 descriptor unused to make sure
  466. * next_to_use != next_to_clean */
  467. for (i = 0; i < adapter->num_rx_queues; i++) {
  468. struct e1000_rx_ring *ring = &adapter->rx_ring[i];
  469. adapter->alloc_rx_buf(adapter, ring,
  470. E1000_DESC_UNUSED(ring));
  471. }
  472. adapter->tx_queue_len = netdev->tx_queue_len;
  473. }
  474. int e1000_up(struct e1000_adapter *adapter)
  475. {
  476. /* hardware has been reset, we need to reload some things */
  477. e1000_configure(adapter);
  478. clear_bit(__E1000_DOWN, &adapter->flags);
  479. #ifdef CONFIG_E1000_NAPI
  480. napi_enable(&adapter->napi);
  481. #endif
  482. e1000_irq_enable(adapter);
  483. /* fire a link change interrupt to start the watchdog */
  484. E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
  485. return 0;
  486. }
  487. /**
  488. * e1000_power_up_phy - restore link in case the phy was powered down
  489. * @adapter: address of board private structure
  490. *
  491. * The phy may be powered down to save power and turn off link when the
  492. * driver is unloaded and wake on lan is not enabled (among others)
  493. * *** this routine MUST be followed by a call to e1000_reset ***
  494. *
  495. **/
  496. void e1000_power_up_phy(struct e1000_adapter *adapter)
  497. {
  498. uint16_t mii_reg = 0;
  499. /* Just clear the power down bit to wake the phy back up */
  500. if (adapter->hw.media_type == e1000_media_type_copper) {
  501. /* according to the manual, the phy will retain its
  502. * settings across a power-down/up cycle */
  503. e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
  504. mii_reg &= ~MII_CR_POWER_DOWN;
  505. e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
  506. }
  507. }
  508. static void e1000_power_down_phy(struct e1000_adapter *adapter)
  509. {
  510. /* Power down the PHY so no link is implied when interface is down *
  511. * The PHY cannot be powered down if any of the following is TRUE *
  512. * (a) WoL is enabled
  513. * (b) AMT is active
  514. * (c) SoL/IDER session is active */
  515. if (!adapter->wol && adapter->hw.mac_type >= e1000_82540 &&
  516. adapter->hw.media_type == e1000_media_type_copper) {
  517. uint16_t mii_reg = 0;
  518. switch (adapter->hw.mac_type) {
  519. case e1000_82540:
  520. case e1000_82545:
  521. case e1000_82545_rev_3:
  522. case e1000_82546:
  523. case e1000_82546_rev_3:
  524. case e1000_82541:
  525. case e1000_82541_rev_2:
  526. case e1000_82547:
  527. case e1000_82547_rev_2:
  528. if (E1000_READ_REG(&adapter->hw, MANC) &
  529. E1000_MANC_SMBUS_EN)
  530. goto out;
  531. break;
  532. case e1000_82571:
  533. case e1000_82572:
  534. case e1000_82573:
  535. case e1000_80003es2lan:
  536. case e1000_ich8lan:
  537. if (e1000_check_mng_mode(&adapter->hw) ||
  538. e1000_check_phy_reset_block(&adapter->hw))
  539. goto out;
  540. break;
  541. default:
  542. goto out;
  543. }
  544. e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &mii_reg);
  545. mii_reg |= MII_CR_POWER_DOWN;
  546. e1000_write_phy_reg(&adapter->hw, PHY_CTRL, mii_reg);
  547. mdelay(1);
  548. }
  549. out:
  550. return;
  551. }
  552. void
  553. e1000_down(struct e1000_adapter *adapter)
  554. {
  555. struct net_device *netdev = adapter->netdev;
  556. /* signal that we're down so the interrupt handler does not
  557. * reschedule our watchdog timer */
  558. set_bit(__E1000_DOWN, &adapter->flags);
  559. #ifdef CONFIG_E1000_NAPI
  560. napi_disable(&adapter->napi);
  561. #endif
  562. e1000_irq_disable(adapter);
  563. del_timer_sync(&adapter->tx_fifo_stall_timer);
  564. del_timer_sync(&adapter->watchdog_timer);
  565. del_timer_sync(&adapter->phy_info_timer);
  566. netdev->tx_queue_len = adapter->tx_queue_len;
  567. adapter->link_speed = 0;
  568. adapter->link_duplex = 0;
  569. netif_carrier_off(netdev);
  570. netif_stop_queue(netdev);
  571. e1000_reset(adapter);
  572. e1000_clean_all_tx_rings(adapter);
  573. e1000_clean_all_rx_rings(adapter);
  574. }
  575. void
  576. e1000_reinit_locked(struct e1000_adapter *adapter)
  577. {
  578. WARN_ON(in_interrupt());
  579. while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
  580. msleep(1);
  581. e1000_down(adapter);
  582. e1000_up(adapter);
  583. clear_bit(__E1000_RESETTING, &adapter->flags);
  584. }
  585. void
  586. e1000_reset(struct e1000_adapter *adapter)
  587. {
  588. uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
  589. uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
  590. boolean_t legacy_pba_adjust = FALSE;
  591. /* Repartition Pba for greater than 9k mtu
  592. * To take effect CTRL.RST is required.
  593. */
  594. switch (adapter->hw.mac_type) {
  595. case e1000_82542_rev2_0:
  596. case e1000_82542_rev2_1:
  597. case e1000_82543:
  598. case e1000_82544:
  599. case e1000_82540:
  600. case e1000_82541:
  601. case e1000_82541_rev_2:
  602. legacy_pba_adjust = TRUE;
  603. pba = E1000_PBA_48K;
  604. break;
  605. case e1000_82545:
  606. case e1000_82545_rev_3:
  607. case e1000_82546:
  608. case e1000_82546_rev_3:
  609. pba = E1000_PBA_48K;
  610. break;
  611. case e1000_82547:
  612. case e1000_82547_rev_2:
  613. legacy_pba_adjust = TRUE;
  614. pba = E1000_PBA_30K;
  615. break;
  616. case e1000_82571:
  617. case e1000_82572:
  618. case e1000_80003es2lan:
  619. pba = E1000_PBA_38K;
  620. break;
  621. case e1000_82573:
  622. pba = E1000_PBA_20K;
  623. break;
  624. case e1000_ich8lan:
  625. pba = E1000_PBA_8K;
  626. case e1000_undefined:
  627. case e1000_num_macs:
  628. break;
  629. }
  630. if (legacy_pba_adjust == TRUE) {
  631. if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
  632. pba -= 8; /* allocate more FIFO for Tx */
  633. if (adapter->hw.mac_type == e1000_82547) {
  634. adapter->tx_fifo_head = 0;
  635. adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
  636. adapter->tx_fifo_size =
  637. (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
  638. atomic_set(&adapter->tx_fifo_stall, 0);
  639. }
  640. } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
  641. /* adjust PBA for jumbo frames */
  642. E1000_WRITE_REG(&adapter->hw, PBA, pba);
  643. /* To maintain wire speed transmits, the Tx FIFO should be
  644. * large enough to accomodate two full transmit packets,
  645. * rounded up to the next 1KB and expressed in KB. Likewise,
  646. * the Rx FIFO should be large enough to accomodate at least
  647. * one full receive packet and is similarly rounded up and
  648. * expressed in KB. */
  649. pba = E1000_READ_REG(&adapter->hw, PBA);
  650. /* upper 16 bits has Tx packet buffer allocation size in KB */
  651. tx_space = pba >> 16;
  652. /* lower 16 bits has Rx packet buffer allocation size in KB */
  653. pba &= 0xffff;
  654. /* don't include ethernet FCS because hardware appends/strips */
  655. min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
  656. VLAN_TAG_SIZE;
  657. min_tx_space = min_rx_space;
  658. min_tx_space *= 2;
  659. min_tx_space = ALIGN(min_tx_space, 1024);
  660. min_tx_space >>= 10;
  661. min_rx_space = ALIGN(min_rx_space, 1024);
  662. min_rx_space >>= 10;
  663. /* If current Tx allocation is less than the min Tx FIFO size,
  664. * and the min Tx FIFO size is less than the current Rx FIFO
  665. * allocation, take space away from current Rx allocation */
  666. if (tx_space < min_tx_space &&
  667. ((min_tx_space - tx_space) < pba)) {
  668. pba = pba - (min_tx_space - tx_space);
  669. /* PCI/PCIx hardware has PBA alignment constraints */
  670. switch (adapter->hw.mac_type) {
  671. case e1000_82545 ... e1000_82546_rev_3:
  672. pba &= ~(E1000_PBA_8K - 1);
  673. break;
  674. default:
  675. break;
  676. }
  677. /* if short on rx space, rx wins and must trump tx
  678. * adjustment or use Early Receive if available */
  679. if (pba < min_rx_space) {
  680. switch (adapter->hw.mac_type) {
  681. case e1000_82573:
  682. /* ERT enabled in e1000_configure_rx */
  683. break;
  684. default:
  685. pba = min_rx_space;
  686. break;
  687. }
  688. }
  689. }
  690. }
  691. E1000_WRITE_REG(&adapter->hw, PBA, pba);
  692. /* flow control settings */
  693. /* Set the FC high water mark to 90% of the FIFO size.
  694. * Required to clear last 3 LSB */
  695. fc_high_water_mark = ((pba * 9216)/10) & 0xFFF8;
  696. /* We can't use 90% on small FIFOs because the remainder
  697. * would be less than 1 full frame. In this case, we size
  698. * it to allow at least a full frame above the high water
  699. * mark. */
  700. if (pba < E1000_PBA_16K)
  701. fc_high_water_mark = (pba * 1024) - 1600;
  702. adapter->hw.fc_high_water = fc_high_water_mark;
  703. adapter->hw.fc_low_water = fc_high_water_mark - 8;
  704. if (adapter->hw.mac_type == e1000_80003es2lan)
  705. adapter->hw.fc_pause_time = 0xFFFF;
  706. else
  707. adapter->hw.fc_pause_time = E1000_FC_PAUSE_TIME;
  708. adapter->hw.fc_send_xon = 1;
  709. adapter->hw.fc = adapter->hw.original_fc;
  710. /* Allow time for pending master requests to run */
  711. e1000_reset_hw(&adapter->hw);
  712. if (adapter->hw.mac_type >= e1000_82544)
  713. E1000_WRITE_REG(&adapter->hw, WUC, 0);
  714. if (e1000_init_hw(&adapter->hw))
  715. DPRINTK(PROBE, ERR, "Hardware Error\n");
  716. e1000_update_mng_vlan(adapter);
  717. /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
  718. if (adapter->hw.mac_type >= e1000_82544 &&
  719. adapter->hw.mac_type <= e1000_82547_rev_2 &&
  720. adapter->hw.autoneg == 1 &&
  721. adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
  722. uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  723. /* clear phy power management bit if we are in gig only mode,
  724. * which if enabled will attempt negotiation to 100Mb, which
  725. * can cause a loss of link at power off or driver unload */
  726. ctrl &= ~E1000_CTRL_SWDPIN3;
  727. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  728. }
  729. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  730. E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
  731. e1000_reset_adaptive(&adapter->hw);
  732. e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
  733. if (!adapter->smart_power_down &&
  734. (adapter->hw.mac_type == e1000_82571 ||
  735. adapter->hw.mac_type == e1000_82572)) {
  736. uint16_t phy_data = 0;
  737. /* speed up time to link by disabling smart power down, ignore
  738. * the return value of this function because there is nothing
  739. * different we would do if it failed */
  740. e1000_read_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
  741. &phy_data);
  742. phy_data &= ~IGP02E1000_PM_SPD;
  743. e1000_write_phy_reg(&adapter->hw, IGP02E1000_PHY_POWER_MGMT,
  744. phy_data);
  745. }
  746. e1000_release_manageability(adapter);
  747. }
  748. /**
  749. * e1000_probe - Device Initialization Routine
  750. * @pdev: PCI device information struct
  751. * @ent: entry in e1000_pci_tbl
  752. *
  753. * Returns 0 on success, negative on failure
  754. *
  755. * e1000_probe initializes an adapter identified by a pci_dev structure.
  756. * The OS initialization, configuring of the adapter private structure,
  757. * and a hardware reset occur.
  758. **/
  759. static int __devinit
  760. e1000_probe(struct pci_dev *pdev,
  761. const struct pci_device_id *ent)
  762. {
  763. struct net_device *netdev;
  764. struct e1000_adapter *adapter;
  765. unsigned long mmio_start, mmio_len;
  766. unsigned long flash_start, flash_len;
  767. static int cards_found = 0;
  768. static int global_quad_port_a = 0; /* global ksp3 port a indication */
  769. int i, err, pci_using_dac;
  770. uint16_t eeprom_data = 0;
  771. uint16_t eeprom_apme_mask = E1000_EEPROM_APME;
  772. DECLARE_MAC_BUF(mac);
  773. if ((err = pci_enable_device(pdev)))
  774. return err;
  775. if (!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
  776. !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
  777. pci_using_dac = 1;
  778. } else {
  779. if ((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) &&
  780. (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
  781. E1000_ERR("No usable DMA configuration, aborting\n");
  782. goto err_dma;
  783. }
  784. pci_using_dac = 0;
  785. }
  786. if ((err = pci_request_regions(pdev, e1000_driver_name)))
  787. goto err_pci_reg;
  788. pci_set_master(pdev);
  789. err = -ENOMEM;
  790. netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  791. if (!netdev)
  792. goto err_alloc_etherdev;
  793. SET_NETDEV_DEV(netdev, &pdev->dev);
  794. pci_set_drvdata(pdev, netdev);
  795. adapter = netdev_priv(netdev);
  796. adapter->netdev = netdev;
  797. adapter->pdev = pdev;
  798. adapter->hw.back = adapter;
  799. adapter->msg_enable = (1 << debug) - 1;
  800. mmio_start = pci_resource_start(pdev, BAR_0);
  801. mmio_len = pci_resource_len(pdev, BAR_0);
  802. err = -EIO;
  803. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  804. if (!adapter->hw.hw_addr)
  805. goto err_ioremap;
  806. for (i = BAR_1; i <= BAR_5; i++) {
  807. if (pci_resource_len(pdev, i) == 0)
  808. continue;
  809. if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
  810. adapter->hw.io_base = pci_resource_start(pdev, i);
  811. break;
  812. }
  813. }
  814. netdev->open = &e1000_open;
  815. netdev->stop = &e1000_close;
  816. netdev->hard_start_xmit = &e1000_xmit_frame;
  817. netdev->get_stats = &e1000_get_stats;
  818. netdev->set_multicast_list = &e1000_set_multi;
  819. netdev->set_mac_address = &e1000_set_mac;
  820. netdev->change_mtu = &e1000_change_mtu;
  821. netdev->do_ioctl = &e1000_ioctl;
  822. e1000_set_ethtool_ops(netdev);
  823. netdev->tx_timeout = &e1000_tx_timeout;
  824. netdev->watchdog_timeo = 5 * HZ;
  825. #ifdef CONFIG_E1000_NAPI
  826. netif_napi_add(netdev, &adapter->napi, e1000_clean, 64);
  827. #endif
  828. netdev->vlan_rx_register = e1000_vlan_rx_register;
  829. netdev->vlan_rx_add_vid = e1000_vlan_rx_add_vid;
  830. netdev->vlan_rx_kill_vid = e1000_vlan_rx_kill_vid;
  831. #ifdef CONFIG_NET_POLL_CONTROLLER
  832. netdev->poll_controller = e1000_netpoll;
  833. #endif
  834. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  835. netdev->mem_start = mmio_start;
  836. netdev->mem_end = mmio_start + mmio_len;
  837. netdev->base_addr = adapter->hw.io_base;
  838. adapter->bd_number = cards_found;
  839. /* setup the private structure */
  840. if ((err = e1000_sw_init(adapter)))
  841. goto err_sw_init;
  842. err = -EIO;
  843. /* Flash BAR mapping must happen after e1000_sw_init
  844. * because it depends on mac_type */
  845. if ((adapter->hw.mac_type == e1000_ich8lan) &&
  846. (pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
  847. flash_start = pci_resource_start(pdev, 1);
  848. flash_len = pci_resource_len(pdev, 1);
  849. adapter->hw.flash_address = ioremap(flash_start, flash_len);
  850. if (!adapter->hw.flash_address)
  851. goto err_flashmap;
  852. }
  853. if (e1000_check_phy_reset_block(&adapter->hw))
  854. DPRINTK(PROBE, INFO, "PHY reset is blocked due to SOL/IDER session.\n");
  855. if (adapter->hw.mac_type >= e1000_82543) {
  856. netdev->features = NETIF_F_SG |
  857. NETIF_F_HW_CSUM |
  858. NETIF_F_HW_VLAN_TX |
  859. NETIF_F_HW_VLAN_RX |
  860. NETIF_F_HW_VLAN_FILTER;
  861. if (adapter->hw.mac_type == e1000_ich8lan)
  862. netdev->features &= ~NETIF_F_HW_VLAN_FILTER;
  863. }
  864. if ((adapter->hw.mac_type >= e1000_82544) &&
  865. (adapter->hw.mac_type != e1000_82547))
  866. netdev->features |= NETIF_F_TSO;
  867. if (adapter->hw.mac_type > e1000_82547_rev_2)
  868. netdev->features |= NETIF_F_TSO6;
  869. if (pci_using_dac)
  870. netdev->features |= NETIF_F_HIGHDMA;
  871. netdev->features |= NETIF_F_LLTX;
  872. adapter->en_mng_pt = e1000_enable_mng_pass_thru(&adapter->hw);
  873. /* initialize eeprom parameters */
  874. if (e1000_init_eeprom_params(&adapter->hw)) {
  875. E1000_ERR("EEPROM initialization failed\n");
  876. goto err_eeprom;
  877. }
  878. /* before reading the EEPROM, reset the controller to
  879. * put the device in a known good starting state */
  880. e1000_reset_hw(&adapter->hw);
  881. /* make sure the EEPROM is good */
  882. if (e1000_validate_eeprom_checksum(&adapter->hw) < 0) {
  883. DPRINTK(PROBE, ERR, "The EEPROM Checksum Is Not Valid\n");
  884. goto err_eeprom;
  885. }
  886. /* copy the MAC address out of the EEPROM */
  887. if (e1000_read_mac_addr(&adapter->hw))
  888. DPRINTK(PROBE, ERR, "EEPROM Read Error\n");
  889. memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
  890. memcpy(netdev->perm_addr, adapter->hw.mac_addr, netdev->addr_len);
  891. if (!is_valid_ether_addr(netdev->perm_addr)) {
  892. DPRINTK(PROBE, ERR, "Invalid MAC Address\n");
  893. goto err_eeprom;
  894. }
  895. e1000_get_bus_info(&adapter->hw);
  896. init_timer(&adapter->tx_fifo_stall_timer);
  897. adapter->tx_fifo_stall_timer.function = &e1000_82547_tx_fifo_stall;
  898. adapter->tx_fifo_stall_timer.data = (unsigned long) adapter;
  899. init_timer(&adapter->watchdog_timer);
  900. adapter->watchdog_timer.function = &e1000_watchdog;
  901. adapter->watchdog_timer.data = (unsigned long) adapter;
  902. init_timer(&adapter->phy_info_timer);
  903. adapter->phy_info_timer.function = &e1000_update_phy_info;
  904. adapter->phy_info_timer.data = (unsigned long) adapter;
  905. INIT_WORK(&adapter->reset_task, e1000_reset_task);
  906. e1000_check_options(adapter);
  907. /* Initial Wake on LAN setting
  908. * If APM wake is enabled in the EEPROM,
  909. * enable the ACPI Magic Packet filter
  910. */
  911. switch (adapter->hw.mac_type) {
  912. case e1000_82542_rev2_0:
  913. case e1000_82542_rev2_1:
  914. case e1000_82543:
  915. break;
  916. case e1000_82544:
  917. e1000_read_eeprom(&adapter->hw,
  918. EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
  919. eeprom_apme_mask = E1000_EEPROM_82544_APM;
  920. break;
  921. case e1000_ich8lan:
  922. e1000_read_eeprom(&adapter->hw,
  923. EEPROM_INIT_CONTROL1_REG, 1, &eeprom_data);
  924. eeprom_apme_mask = E1000_EEPROM_ICH8_APME;
  925. break;
  926. case e1000_82546:
  927. case e1000_82546_rev_3:
  928. case e1000_82571:
  929. case e1000_80003es2lan:
  930. if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1){
  931. e1000_read_eeprom(&adapter->hw,
  932. EEPROM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  933. break;
  934. }
  935. /* Fall Through */
  936. default:
  937. e1000_read_eeprom(&adapter->hw,
  938. EEPROM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  939. break;
  940. }
  941. if (eeprom_data & eeprom_apme_mask)
  942. adapter->eeprom_wol |= E1000_WUFC_MAG;
  943. /* now that we have the eeprom settings, apply the special cases
  944. * where the eeprom may be wrong or the board simply won't support
  945. * wake on lan on a particular port */
  946. switch (pdev->device) {
  947. case E1000_DEV_ID_82546GB_PCIE:
  948. adapter->eeprom_wol = 0;
  949. break;
  950. case E1000_DEV_ID_82546EB_FIBER:
  951. case E1000_DEV_ID_82546GB_FIBER:
  952. case E1000_DEV_ID_82571EB_FIBER:
  953. /* Wake events only supported on port A for dual fiber
  954. * regardless of eeprom setting */
  955. if (E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_FUNC_1)
  956. adapter->eeprom_wol = 0;
  957. break;
  958. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  959. case E1000_DEV_ID_82571EB_QUAD_COPPER:
  960. case E1000_DEV_ID_82571EB_QUAD_FIBER:
  961. case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
  962. case E1000_DEV_ID_82571PT_QUAD_COPPER:
  963. /* if quad port adapter, disable WoL on all but port A */
  964. if (global_quad_port_a != 0)
  965. adapter->eeprom_wol = 0;
  966. else
  967. adapter->quad_port_a = 1;
  968. /* Reset for multiple quad port adapters */
  969. if (++global_quad_port_a == 4)
  970. global_quad_port_a = 0;
  971. break;
  972. }
  973. /* initialize the wol settings based on the eeprom settings */
  974. adapter->wol = adapter->eeprom_wol;
  975. /* print bus type/speed/width info */
  976. {
  977. struct e1000_hw *hw = &adapter->hw;
  978. DPRINTK(PROBE, INFO, "(PCI%s:%s:%s) ",
  979. ((hw->bus_type == e1000_bus_type_pcix) ? "-X" :
  980. (hw->bus_type == e1000_bus_type_pci_express ? " Express":"")),
  981. ((hw->bus_speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
  982. (hw->bus_speed == e1000_bus_speed_133) ? "133MHz" :
  983. (hw->bus_speed == e1000_bus_speed_120) ? "120MHz" :
  984. (hw->bus_speed == e1000_bus_speed_100) ? "100MHz" :
  985. (hw->bus_speed == e1000_bus_speed_66) ? "66MHz" : "33MHz"),
  986. ((hw->bus_width == e1000_bus_width_64) ? "64-bit" :
  987. (hw->bus_width == e1000_bus_width_pciex_4) ? "Width x4" :
  988. (hw->bus_width == e1000_bus_width_pciex_1) ? "Width x1" :
  989. "32-bit"));
  990. }
  991. printk("%s\n", print_mac(mac, netdev->dev_addr));
  992. /* reset the hardware with the new settings */
  993. e1000_reset(adapter);
  994. /* If the controller is 82573 and f/w is AMT, do not set
  995. * DRV_LOAD until the interface is up. For all other cases,
  996. * let the f/w know that the h/w is now under the control
  997. * of the driver. */
  998. if (adapter->hw.mac_type != e1000_82573 ||
  999. !e1000_check_mng_mode(&adapter->hw))
  1000. e1000_get_hw_control(adapter);
  1001. /* tell the stack to leave us alone until e1000_open() is called */
  1002. netif_carrier_off(netdev);
  1003. netif_stop_queue(netdev);
  1004. strcpy(netdev->name, "eth%d");
  1005. if ((err = register_netdev(netdev)))
  1006. goto err_register;
  1007. DPRINTK(PROBE, INFO, "Intel(R) PRO/1000 Network Connection\n");
  1008. cards_found++;
  1009. return 0;
  1010. err_register:
  1011. e1000_release_hw_control(adapter);
  1012. err_eeprom:
  1013. if (!e1000_check_phy_reset_block(&adapter->hw))
  1014. e1000_phy_hw_reset(&adapter->hw);
  1015. if (adapter->hw.flash_address)
  1016. iounmap(adapter->hw.flash_address);
  1017. err_flashmap:
  1018. #ifdef CONFIG_E1000_NAPI
  1019. for (i = 0; i < adapter->num_rx_queues; i++)
  1020. dev_put(&adapter->polling_netdev[i]);
  1021. #endif
  1022. kfree(adapter->tx_ring);
  1023. kfree(adapter->rx_ring);
  1024. #ifdef CONFIG_E1000_NAPI
  1025. kfree(adapter->polling_netdev);
  1026. #endif
  1027. err_sw_init:
  1028. iounmap(adapter->hw.hw_addr);
  1029. err_ioremap:
  1030. free_netdev(netdev);
  1031. err_alloc_etherdev:
  1032. pci_release_regions(pdev);
  1033. err_pci_reg:
  1034. err_dma:
  1035. pci_disable_device(pdev);
  1036. return err;
  1037. }
  1038. /**
  1039. * e1000_remove - Device Removal Routine
  1040. * @pdev: PCI device information struct
  1041. *
  1042. * e1000_remove is called by the PCI subsystem to alert the driver
  1043. * that it should release a PCI device. The could be caused by a
  1044. * Hot-Plug event, or because the driver is going to be removed from
  1045. * memory.
  1046. **/
  1047. static void __devexit
  1048. e1000_remove(struct pci_dev *pdev)
  1049. {
  1050. struct net_device *netdev = pci_get_drvdata(pdev);
  1051. struct e1000_adapter *adapter = netdev_priv(netdev);
  1052. #ifdef CONFIG_E1000_NAPI
  1053. int i;
  1054. #endif
  1055. cancel_work_sync(&adapter->reset_task);
  1056. e1000_release_manageability(adapter);
  1057. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  1058. * would have already happened in close and is redundant. */
  1059. e1000_release_hw_control(adapter);
  1060. #ifdef CONFIG_E1000_NAPI
  1061. for (i = 0; i < adapter->num_rx_queues; i++)
  1062. dev_put(&adapter->polling_netdev[i]);
  1063. #endif
  1064. unregister_netdev(netdev);
  1065. if (!e1000_check_phy_reset_block(&adapter->hw))
  1066. e1000_phy_hw_reset(&adapter->hw);
  1067. kfree(adapter->tx_ring);
  1068. kfree(adapter->rx_ring);
  1069. #ifdef CONFIG_E1000_NAPI
  1070. kfree(adapter->polling_netdev);
  1071. #endif
  1072. iounmap(adapter->hw.hw_addr);
  1073. if (adapter->hw.flash_address)
  1074. iounmap(adapter->hw.flash_address);
  1075. pci_release_regions(pdev);
  1076. free_netdev(netdev);
  1077. pci_disable_device(pdev);
  1078. }
  1079. /**
  1080. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  1081. * @adapter: board private structure to initialize
  1082. *
  1083. * e1000_sw_init initializes the Adapter private data structure.
  1084. * Fields are initialized based on PCI device information and
  1085. * OS network device settings (MTU size).
  1086. **/
  1087. static int __devinit
  1088. e1000_sw_init(struct e1000_adapter *adapter)
  1089. {
  1090. struct e1000_hw *hw = &adapter->hw;
  1091. struct net_device *netdev = adapter->netdev;
  1092. struct pci_dev *pdev = adapter->pdev;
  1093. #ifdef CONFIG_E1000_NAPI
  1094. int i;
  1095. #endif
  1096. /* PCI config space info */
  1097. hw->vendor_id = pdev->vendor;
  1098. hw->device_id = pdev->device;
  1099. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1100. hw->subsystem_id = pdev->subsystem_device;
  1101. hw->revision_id = pdev->revision;
  1102. pci_read_config_word(pdev, PCI_COMMAND, &hw->pci_cmd_word);
  1103. adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  1104. adapter->rx_ps_bsize0 = E1000_RXBUFFER_128;
  1105. hw->max_frame_size = netdev->mtu +
  1106. ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  1107. hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
  1108. /* identify the MAC */
  1109. if (e1000_set_mac_type(hw)) {
  1110. DPRINTK(PROBE, ERR, "Unknown MAC Type\n");
  1111. return -EIO;
  1112. }
  1113. switch (hw->mac_type) {
  1114. default:
  1115. break;
  1116. case e1000_82541:
  1117. case e1000_82547:
  1118. case e1000_82541_rev_2:
  1119. case e1000_82547_rev_2:
  1120. hw->phy_init_script = 1;
  1121. break;
  1122. }
  1123. e1000_set_media_type(hw);
  1124. hw->wait_autoneg_complete = FALSE;
  1125. hw->tbi_compatibility_en = TRUE;
  1126. hw->adaptive_ifs = TRUE;
  1127. /* Copper options */
  1128. if (hw->media_type == e1000_media_type_copper) {
  1129. hw->mdix = AUTO_ALL_MODES;
  1130. hw->disable_polarity_correction = FALSE;
  1131. hw->master_slave = E1000_MASTER_SLAVE;
  1132. }
  1133. adapter->num_tx_queues = 1;
  1134. adapter->num_rx_queues = 1;
  1135. if (e1000_alloc_queues(adapter)) {
  1136. DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n");
  1137. return -ENOMEM;
  1138. }
  1139. #ifdef CONFIG_E1000_NAPI
  1140. for (i = 0; i < adapter->num_rx_queues; i++) {
  1141. adapter->polling_netdev[i].priv = adapter;
  1142. dev_hold(&adapter->polling_netdev[i]);
  1143. set_bit(__LINK_STATE_START, &adapter->polling_netdev[i].state);
  1144. }
  1145. spin_lock_init(&adapter->tx_queue_lock);
  1146. #endif
  1147. /* Explicitly disable IRQ since the NIC can be in any state. */
  1148. atomic_set(&adapter->irq_sem, 0);
  1149. e1000_irq_disable(adapter);
  1150. spin_lock_init(&adapter->stats_lock);
  1151. set_bit(__E1000_DOWN, &adapter->flags);
  1152. return 0;
  1153. }
  1154. /**
  1155. * e1000_alloc_queues - Allocate memory for all rings
  1156. * @adapter: board private structure to initialize
  1157. *
  1158. * We allocate one ring per queue at run-time since we don't know the
  1159. * number of queues at compile-time. The polling_netdev array is
  1160. * intended for Multiqueue, but should work fine with a single queue.
  1161. **/
  1162. static int __devinit
  1163. e1000_alloc_queues(struct e1000_adapter *adapter)
  1164. {
  1165. adapter->tx_ring = kcalloc(adapter->num_tx_queues,
  1166. sizeof(struct e1000_tx_ring), GFP_KERNEL);
  1167. if (!adapter->tx_ring)
  1168. return -ENOMEM;
  1169. adapter->rx_ring = kcalloc(adapter->num_rx_queues,
  1170. sizeof(struct e1000_rx_ring), GFP_KERNEL);
  1171. if (!adapter->rx_ring) {
  1172. kfree(adapter->tx_ring);
  1173. return -ENOMEM;
  1174. }
  1175. #ifdef CONFIG_E1000_NAPI
  1176. adapter->polling_netdev = kcalloc(adapter->num_rx_queues,
  1177. sizeof(struct net_device),
  1178. GFP_KERNEL);
  1179. if (!adapter->polling_netdev) {
  1180. kfree(adapter->tx_ring);
  1181. kfree(adapter->rx_ring);
  1182. return -ENOMEM;
  1183. }
  1184. #endif
  1185. return E1000_SUCCESS;
  1186. }
  1187. /**
  1188. * e1000_open - Called when a network interface is made active
  1189. * @netdev: network interface device structure
  1190. *
  1191. * Returns 0 on success, negative value on failure
  1192. *
  1193. * The open entry point is called when a network interface is made
  1194. * active by the system (IFF_UP). At this point all resources needed
  1195. * for transmit and receive operations are allocated, the interrupt
  1196. * handler is registered with the OS, the watchdog timer is started,
  1197. * and the stack is notified that the interface is ready.
  1198. **/
  1199. static int
  1200. e1000_open(struct net_device *netdev)
  1201. {
  1202. struct e1000_adapter *adapter = netdev_priv(netdev);
  1203. int err;
  1204. /* disallow open during test */
  1205. if (test_bit(__E1000_TESTING, &adapter->flags))
  1206. return -EBUSY;
  1207. /* allocate transmit descriptors */
  1208. err = e1000_setup_all_tx_resources(adapter);
  1209. if (err)
  1210. goto err_setup_tx;
  1211. /* allocate receive descriptors */
  1212. err = e1000_setup_all_rx_resources(adapter);
  1213. if (err)
  1214. goto err_setup_rx;
  1215. e1000_power_up_phy(adapter);
  1216. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  1217. if ((adapter->hw.mng_cookie.status &
  1218. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) {
  1219. e1000_update_mng_vlan(adapter);
  1220. }
  1221. /* If AMT is enabled, let the firmware know that the network
  1222. * interface is now open */
  1223. if (adapter->hw.mac_type == e1000_82573 &&
  1224. e1000_check_mng_mode(&adapter->hw))
  1225. e1000_get_hw_control(adapter);
  1226. /* before we allocate an interrupt, we must be ready to handle it.
  1227. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  1228. * as soon as we call pci_request_irq, so we have to setup our
  1229. * clean_rx handler before we do so. */
  1230. e1000_configure(adapter);
  1231. err = e1000_request_irq(adapter);
  1232. if (err)
  1233. goto err_req_irq;
  1234. /* From here on the code is the same as e1000_up() */
  1235. clear_bit(__E1000_DOWN, &adapter->flags);
  1236. #ifdef CONFIG_E1000_NAPI
  1237. napi_enable(&adapter->napi);
  1238. #endif
  1239. e1000_irq_enable(adapter);
  1240. /* fire a link status change interrupt to start the watchdog */
  1241. E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
  1242. return E1000_SUCCESS;
  1243. err_req_irq:
  1244. e1000_release_hw_control(adapter);
  1245. e1000_power_down_phy(adapter);
  1246. e1000_free_all_rx_resources(adapter);
  1247. err_setup_rx:
  1248. e1000_free_all_tx_resources(adapter);
  1249. err_setup_tx:
  1250. e1000_reset(adapter);
  1251. return err;
  1252. }
  1253. /**
  1254. * e1000_close - Disables a network interface
  1255. * @netdev: network interface device structure
  1256. *
  1257. * Returns 0, this is not allowed to fail
  1258. *
  1259. * The close entry point is called when an interface is de-activated
  1260. * by the OS. The hardware is still under the drivers control, but
  1261. * needs to be disabled. A global MAC reset is issued to stop the
  1262. * hardware, and all transmit and receive resources are freed.
  1263. **/
  1264. static int
  1265. e1000_close(struct net_device *netdev)
  1266. {
  1267. struct e1000_adapter *adapter = netdev_priv(netdev);
  1268. WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
  1269. e1000_down(adapter);
  1270. e1000_power_down_phy(adapter);
  1271. e1000_free_irq(adapter);
  1272. e1000_free_all_tx_resources(adapter);
  1273. e1000_free_all_rx_resources(adapter);
  1274. /* kill manageability vlan ID if supported, but not if a vlan with
  1275. * the same ID is registered on the host OS (let 8021q kill it) */
  1276. if ((adapter->hw.mng_cookie.status &
  1277. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
  1278. !(adapter->vlgrp &&
  1279. vlan_group_get_device(adapter->vlgrp, adapter->mng_vlan_id))) {
  1280. e1000_vlan_rx_kill_vid(netdev, adapter->mng_vlan_id);
  1281. }
  1282. /* If AMT is enabled, let the firmware know that the network
  1283. * interface is now closed */
  1284. if (adapter->hw.mac_type == e1000_82573 &&
  1285. e1000_check_mng_mode(&adapter->hw))
  1286. e1000_release_hw_control(adapter);
  1287. return 0;
  1288. }
  1289. /**
  1290. * e1000_check_64k_bound - check that memory doesn't cross 64kB boundary
  1291. * @adapter: address of board private structure
  1292. * @start: address of beginning of memory
  1293. * @len: length of memory
  1294. **/
  1295. static boolean_t
  1296. e1000_check_64k_bound(struct e1000_adapter *adapter,
  1297. void *start, unsigned long len)
  1298. {
  1299. unsigned long begin = (unsigned long) start;
  1300. unsigned long end = begin + len;
  1301. /* First rev 82545 and 82546 need to not allow any memory
  1302. * write location to cross 64k boundary due to errata 23 */
  1303. if (adapter->hw.mac_type == e1000_82545 ||
  1304. adapter->hw.mac_type == e1000_82546) {
  1305. return ((begin ^ (end - 1)) >> 16) != 0 ? FALSE : TRUE;
  1306. }
  1307. return TRUE;
  1308. }
  1309. /**
  1310. * e1000_setup_tx_resources - allocate Tx resources (Descriptors)
  1311. * @adapter: board private structure
  1312. * @txdr: tx descriptor ring (for a specific queue) to setup
  1313. *
  1314. * Return 0 on success, negative on failure
  1315. **/
  1316. static int
  1317. e1000_setup_tx_resources(struct e1000_adapter *adapter,
  1318. struct e1000_tx_ring *txdr)
  1319. {
  1320. struct pci_dev *pdev = adapter->pdev;
  1321. int size;
  1322. size = sizeof(struct e1000_buffer) * txdr->count;
  1323. txdr->buffer_info = vmalloc(size);
  1324. if (!txdr->buffer_info) {
  1325. DPRINTK(PROBE, ERR,
  1326. "Unable to allocate memory for the transmit descriptor ring\n");
  1327. return -ENOMEM;
  1328. }
  1329. memset(txdr->buffer_info, 0, size);
  1330. /* round up to nearest 4K */
  1331. txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
  1332. txdr->size = ALIGN(txdr->size, 4096);
  1333. txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  1334. if (!txdr->desc) {
  1335. setup_tx_desc_die:
  1336. vfree(txdr->buffer_info);
  1337. DPRINTK(PROBE, ERR,
  1338. "Unable to allocate memory for the transmit descriptor ring\n");
  1339. return -ENOMEM;
  1340. }
  1341. /* Fix for errata 23, can't cross 64kB boundary */
  1342. if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
  1343. void *olddesc = txdr->desc;
  1344. dma_addr_t olddma = txdr->dma;
  1345. DPRINTK(TX_ERR, ERR, "txdr align check failed: %u bytes "
  1346. "at %p\n", txdr->size, txdr->desc);
  1347. /* Try again, without freeing the previous */
  1348. txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
  1349. /* Failed allocation, critical failure */
  1350. if (!txdr->desc) {
  1351. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1352. goto setup_tx_desc_die;
  1353. }
  1354. if (!e1000_check_64k_bound(adapter, txdr->desc, txdr->size)) {
  1355. /* give up */
  1356. pci_free_consistent(pdev, txdr->size, txdr->desc,
  1357. txdr->dma);
  1358. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1359. DPRINTK(PROBE, ERR,
  1360. "Unable to allocate aligned memory "
  1361. "for the transmit descriptor ring\n");
  1362. vfree(txdr->buffer_info);
  1363. return -ENOMEM;
  1364. } else {
  1365. /* Free old allocation, new allocation was successful */
  1366. pci_free_consistent(pdev, txdr->size, olddesc, olddma);
  1367. }
  1368. }
  1369. memset(txdr->desc, 0, txdr->size);
  1370. txdr->next_to_use = 0;
  1371. txdr->next_to_clean = 0;
  1372. spin_lock_init(&txdr->tx_lock);
  1373. return 0;
  1374. }
  1375. /**
  1376. * e1000_setup_all_tx_resources - wrapper to allocate Tx resources
  1377. * (Descriptors) for all queues
  1378. * @adapter: board private structure
  1379. *
  1380. * Return 0 on success, negative on failure
  1381. **/
  1382. int
  1383. e1000_setup_all_tx_resources(struct e1000_adapter *adapter)
  1384. {
  1385. int i, err = 0;
  1386. for (i = 0; i < adapter->num_tx_queues; i++) {
  1387. err = e1000_setup_tx_resources(adapter, &adapter->tx_ring[i]);
  1388. if (err) {
  1389. DPRINTK(PROBE, ERR,
  1390. "Allocation for Tx Queue %u failed\n", i);
  1391. for (i-- ; i >= 0; i--)
  1392. e1000_free_tx_resources(adapter,
  1393. &adapter->tx_ring[i]);
  1394. break;
  1395. }
  1396. }
  1397. return err;
  1398. }
  1399. /**
  1400. * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  1401. * @adapter: board private structure
  1402. *
  1403. * Configure the Tx unit of the MAC after a reset.
  1404. **/
  1405. static void
  1406. e1000_configure_tx(struct e1000_adapter *adapter)
  1407. {
  1408. uint64_t tdba;
  1409. struct e1000_hw *hw = &adapter->hw;
  1410. uint32_t tdlen, tctl, tipg, tarc;
  1411. uint32_t ipgr1, ipgr2;
  1412. /* Setup the HW Tx Head and Tail descriptor pointers */
  1413. switch (adapter->num_tx_queues) {
  1414. case 1:
  1415. default:
  1416. tdba = adapter->tx_ring[0].dma;
  1417. tdlen = adapter->tx_ring[0].count *
  1418. sizeof(struct e1000_tx_desc);
  1419. E1000_WRITE_REG(hw, TDLEN, tdlen);
  1420. E1000_WRITE_REG(hw, TDBAH, (tdba >> 32));
  1421. E1000_WRITE_REG(hw, TDBAL, (tdba & 0x00000000ffffffffULL));
  1422. E1000_WRITE_REG(hw, TDT, 0);
  1423. E1000_WRITE_REG(hw, TDH, 0);
  1424. adapter->tx_ring[0].tdh = ((hw->mac_type >= e1000_82543) ? E1000_TDH : E1000_82542_TDH);
  1425. adapter->tx_ring[0].tdt = ((hw->mac_type >= e1000_82543) ? E1000_TDT : E1000_82542_TDT);
  1426. break;
  1427. }
  1428. /* Set the default values for the Tx Inter Packet Gap timer */
  1429. if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
  1430. (hw->media_type == e1000_media_type_fiber ||
  1431. hw->media_type == e1000_media_type_internal_serdes))
  1432. tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
  1433. else
  1434. tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
  1435. switch (hw->mac_type) {
  1436. case e1000_82542_rev2_0:
  1437. case e1000_82542_rev2_1:
  1438. tipg = DEFAULT_82542_TIPG_IPGT;
  1439. ipgr1 = DEFAULT_82542_TIPG_IPGR1;
  1440. ipgr2 = DEFAULT_82542_TIPG_IPGR2;
  1441. break;
  1442. case e1000_80003es2lan:
  1443. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  1444. ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
  1445. break;
  1446. default:
  1447. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  1448. ipgr2 = DEFAULT_82543_TIPG_IPGR2;
  1449. break;
  1450. }
  1451. tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
  1452. tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
  1453. E1000_WRITE_REG(hw, TIPG, tipg);
  1454. /* Set the Tx Interrupt Delay register */
  1455. E1000_WRITE_REG(hw, TIDV, adapter->tx_int_delay);
  1456. if (hw->mac_type >= e1000_82540)
  1457. E1000_WRITE_REG(hw, TADV, adapter->tx_abs_int_delay);
  1458. /* Program the Transmit Control Register */
  1459. tctl = E1000_READ_REG(hw, TCTL);
  1460. tctl &= ~E1000_TCTL_CT;
  1461. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  1462. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  1463. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
  1464. tarc = E1000_READ_REG(hw, TARC0);
  1465. /* set the speed mode bit, we'll clear it if we're not at
  1466. * gigabit link later */
  1467. tarc |= (1 << 21);
  1468. E1000_WRITE_REG(hw, TARC0, tarc);
  1469. } else if (hw->mac_type == e1000_80003es2lan) {
  1470. tarc = E1000_READ_REG(hw, TARC0);
  1471. tarc |= 1;
  1472. E1000_WRITE_REG(hw, TARC0, tarc);
  1473. tarc = E1000_READ_REG(hw, TARC1);
  1474. tarc |= 1;
  1475. E1000_WRITE_REG(hw, TARC1, tarc);
  1476. }
  1477. e1000_config_collision_dist(hw);
  1478. /* Setup Transmit Descriptor Settings for eop descriptor */
  1479. adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
  1480. /* only set IDE if we are delaying interrupts using the timers */
  1481. if (adapter->tx_int_delay)
  1482. adapter->txd_cmd |= E1000_TXD_CMD_IDE;
  1483. if (hw->mac_type < e1000_82543)
  1484. adapter->txd_cmd |= E1000_TXD_CMD_RPS;
  1485. else
  1486. adapter->txd_cmd |= E1000_TXD_CMD_RS;
  1487. /* Cache if we're 82544 running in PCI-X because we'll
  1488. * need this to apply a workaround later in the send path. */
  1489. if (hw->mac_type == e1000_82544 &&
  1490. hw->bus_type == e1000_bus_type_pcix)
  1491. adapter->pcix_82544 = 1;
  1492. E1000_WRITE_REG(hw, TCTL, tctl);
  1493. }
  1494. /**
  1495. * e1000_setup_rx_resources - allocate Rx resources (Descriptors)
  1496. * @adapter: board private structure
  1497. * @rxdr: rx descriptor ring (for a specific queue) to setup
  1498. *
  1499. * Returns 0 on success, negative on failure
  1500. **/
  1501. static int
  1502. e1000_setup_rx_resources(struct e1000_adapter *adapter,
  1503. struct e1000_rx_ring *rxdr)
  1504. {
  1505. struct pci_dev *pdev = adapter->pdev;
  1506. int size, desc_len;
  1507. size = sizeof(struct e1000_buffer) * rxdr->count;
  1508. rxdr->buffer_info = vmalloc(size);
  1509. if (!rxdr->buffer_info) {
  1510. DPRINTK(PROBE, ERR,
  1511. "Unable to allocate memory for the receive descriptor ring\n");
  1512. return -ENOMEM;
  1513. }
  1514. memset(rxdr->buffer_info, 0, size);
  1515. rxdr->ps_page = kcalloc(rxdr->count, sizeof(struct e1000_ps_page),
  1516. GFP_KERNEL);
  1517. if (!rxdr->ps_page) {
  1518. vfree(rxdr->buffer_info);
  1519. DPRINTK(PROBE, ERR,
  1520. "Unable to allocate memory for the receive descriptor ring\n");
  1521. return -ENOMEM;
  1522. }
  1523. rxdr->ps_page_dma = kcalloc(rxdr->count,
  1524. sizeof(struct e1000_ps_page_dma),
  1525. GFP_KERNEL);
  1526. if (!rxdr->ps_page_dma) {
  1527. vfree(rxdr->buffer_info);
  1528. kfree(rxdr->ps_page);
  1529. DPRINTK(PROBE, ERR,
  1530. "Unable to allocate memory for the receive descriptor ring\n");
  1531. return -ENOMEM;
  1532. }
  1533. if (adapter->hw.mac_type <= e1000_82547_rev_2)
  1534. desc_len = sizeof(struct e1000_rx_desc);
  1535. else
  1536. desc_len = sizeof(union e1000_rx_desc_packet_split);
  1537. /* Round up to nearest 4K */
  1538. rxdr->size = rxdr->count * desc_len;
  1539. rxdr->size = ALIGN(rxdr->size, 4096);
  1540. rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  1541. if (!rxdr->desc) {
  1542. DPRINTK(PROBE, ERR,
  1543. "Unable to allocate memory for the receive descriptor ring\n");
  1544. setup_rx_desc_die:
  1545. vfree(rxdr->buffer_info);
  1546. kfree(rxdr->ps_page);
  1547. kfree(rxdr->ps_page_dma);
  1548. return -ENOMEM;
  1549. }
  1550. /* Fix for errata 23, can't cross 64kB boundary */
  1551. if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
  1552. void *olddesc = rxdr->desc;
  1553. dma_addr_t olddma = rxdr->dma;
  1554. DPRINTK(RX_ERR, ERR, "rxdr align check failed: %u bytes "
  1555. "at %p\n", rxdr->size, rxdr->desc);
  1556. /* Try again, without freeing the previous */
  1557. rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
  1558. /* Failed allocation, critical failure */
  1559. if (!rxdr->desc) {
  1560. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1561. DPRINTK(PROBE, ERR,
  1562. "Unable to allocate memory "
  1563. "for the receive descriptor ring\n");
  1564. goto setup_rx_desc_die;
  1565. }
  1566. if (!e1000_check_64k_bound(adapter, rxdr->desc, rxdr->size)) {
  1567. /* give up */
  1568. pci_free_consistent(pdev, rxdr->size, rxdr->desc,
  1569. rxdr->dma);
  1570. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1571. DPRINTK(PROBE, ERR,
  1572. "Unable to allocate aligned memory "
  1573. "for the receive descriptor ring\n");
  1574. goto setup_rx_desc_die;
  1575. } else {
  1576. /* Free old allocation, new allocation was successful */
  1577. pci_free_consistent(pdev, rxdr->size, olddesc, olddma);
  1578. }
  1579. }
  1580. memset(rxdr->desc, 0, rxdr->size);
  1581. rxdr->next_to_clean = 0;
  1582. rxdr->next_to_use = 0;
  1583. return 0;
  1584. }
  1585. /**
  1586. * e1000_setup_all_rx_resources - wrapper to allocate Rx resources
  1587. * (Descriptors) for all queues
  1588. * @adapter: board private structure
  1589. *
  1590. * Return 0 on success, negative on failure
  1591. **/
  1592. int
  1593. e1000_setup_all_rx_resources(struct e1000_adapter *adapter)
  1594. {
  1595. int i, err = 0;
  1596. for (i = 0; i < adapter->num_rx_queues; i++) {
  1597. err = e1000_setup_rx_resources(adapter, &adapter->rx_ring[i]);
  1598. if (err) {
  1599. DPRINTK(PROBE, ERR,
  1600. "Allocation for Rx Queue %u failed\n", i);
  1601. for (i-- ; i >= 0; i--)
  1602. e1000_free_rx_resources(adapter,
  1603. &adapter->rx_ring[i]);
  1604. break;
  1605. }
  1606. }
  1607. return err;
  1608. }
  1609. /**
  1610. * e1000_setup_rctl - configure the receive control registers
  1611. * @adapter: Board private structure
  1612. **/
  1613. #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
  1614. (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
  1615. static void
  1616. e1000_setup_rctl(struct e1000_adapter *adapter)
  1617. {
  1618. uint32_t rctl, rfctl;
  1619. uint32_t psrctl = 0;
  1620. #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
  1621. uint32_t pages = 0;
  1622. #endif
  1623. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1624. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  1625. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  1626. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  1627. (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
  1628. if (adapter->hw.tbi_compatibility_on == 1)
  1629. rctl |= E1000_RCTL_SBP;
  1630. else
  1631. rctl &= ~E1000_RCTL_SBP;
  1632. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  1633. rctl &= ~E1000_RCTL_LPE;
  1634. else
  1635. rctl |= E1000_RCTL_LPE;
  1636. /* Setup buffer sizes */
  1637. rctl &= ~E1000_RCTL_SZ_4096;
  1638. rctl |= E1000_RCTL_BSEX;
  1639. switch (adapter->rx_buffer_len) {
  1640. case E1000_RXBUFFER_256:
  1641. rctl |= E1000_RCTL_SZ_256;
  1642. rctl &= ~E1000_RCTL_BSEX;
  1643. break;
  1644. case E1000_RXBUFFER_512:
  1645. rctl |= E1000_RCTL_SZ_512;
  1646. rctl &= ~E1000_RCTL_BSEX;
  1647. break;
  1648. case E1000_RXBUFFER_1024:
  1649. rctl |= E1000_RCTL_SZ_1024;
  1650. rctl &= ~E1000_RCTL_BSEX;
  1651. break;
  1652. case E1000_RXBUFFER_2048:
  1653. default:
  1654. rctl |= E1000_RCTL_SZ_2048;
  1655. rctl &= ~E1000_RCTL_BSEX;
  1656. break;
  1657. case E1000_RXBUFFER_4096:
  1658. rctl |= E1000_RCTL_SZ_4096;
  1659. break;
  1660. case E1000_RXBUFFER_8192:
  1661. rctl |= E1000_RCTL_SZ_8192;
  1662. break;
  1663. case E1000_RXBUFFER_16384:
  1664. rctl |= E1000_RCTL_SZ_16384;
  1665. break;
  1666. }
  1667. #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
  1668. /* 82571 and greater support packet-split where the protocol
  1669. * header is placed in skb->data and the packet data is
  1670. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  1671. * In the case of a non-split, skb->data is linearly filled,
  1672. * followed by the page buffers. Therefore, skb->data is
  1673. * sized to hold the largest protocol header.
  1674. */
  1675. /* allocations using alloc_page take too long for regular MTU
  1676. * so only enable packet split for jumbo frames */
  1677. pages = PAGE_USE_COUNT(adapter->netdev->mtu);
  1678. if ((adapter->hw.mac_type >= e1000_82571) && (pages <= 3) &&
  1679. PAGE_SIZE <= 16384 && (rctl & E1000_RCTL_LPE))
  1680. adapter->rx_ps_pages = pages;
  1681. else
  1682. adapter->rx_ps_pages = 0;
  1683. #endif
  1684. if (adapter->rx_ps_pages) {
  1685. /* Configure extra packet-split registers */
  1686. rfctl = E1000_READ_REG(&adapter->hw, RFCTL);
  1687. rfctl |= E1000_RFCTL_EXTEN;
  1688. /* disable packet split support for IPv6 extension headers,
  1689. * because some malformed IPv6 headers can hang the RX */
  1690. rfctl |= (E1000_RFCTL_IPV6_EX_DIS |
  1691. E1000_RFCTL_NEW_IPV6_EXT_DIS);
  1692. E1000_WRITE_REG(&adapter->hw, RFCTL, rfctl);
  1693. rctl |= E1000_RCTL_DTYP_PS;
  1694. psrctl |= adapter->rx_ps_bsize0 >>
  1695. E1000_PSRCTL_BSIZE0_SHIFT;
  1696. switch (adapter->rx_ps_pages) {
  1697. case 3:
  1698. psrctl |= PAGE_SIZE <<
  1699. E1000_PSRCTL_BSIZE3_SHIFT;
  1700. case 2:
  1701. psrctl |= PAGE_SIZE <<
  1702. E1000_PSRCTL_BSIZE2_SHIFT;
  1703. case 1:
  1704. psrctl |= PAGE_SIZE >>
  1705. E1000_PSRCTL_BSIZE1_SHIFT;
  1706. break;
  1707. }
  1708. E1000_WRITE_REG(&adapter->hw, PSRCTL, psrctl);
  1709. }
  1710. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1711. }
  1712. /**
  1713. * e1000_configure_rx - Configure 8254x Receive Unit after Reset
  1714. * @adapter: board private structure
  1715. *
  1716. * Configure the Rx unit of the MAC after a reset.
  1717. **/
  1718. static void
  1719. e1000_configure_rx(struct e1000_adapter *adapter)
  1720. {
  1721. uint64_t rdba;
  1722. struct e1000_hw *hw = &adapter->hw;
  1723. uint32_t rdlen, rctl, rxcsum, ctrl_ext;
  1724. if (adapter->rx_ps_pages) {
  1725. /* this is a 32 byte descriptor */
  1726. rdlen = adapter->rx_ring[0].count *
  1727. sizeof(union e1000_rx_desc_packet_split);
  1728. adapter->clean_rx = e1000_clean_rx_irq_ps;
  1729. adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
  1730. } else {
  1731. rdlen = adapter->rx_ring[0].count *
  1732. sizeof(struct e1000_rx_desc);
  1733. adapter->clean_rx = e1000_clean_rx_irq;
  1734. adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
  1735. }
  1736. /* disable receives while setting up the descriptors */
  1737. rctl = E1000_READ_REG(hw, RCTL);
  1738. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  1739. /* set the Receive Delay Timer Register */
  1740. E1000_WRITE_REG(hw, RDTR, adapter->rx_int_delay);
  1741. if (hw->mac_type >= e1000_82540) {
  1742. E1000_WRITE_REG(hw, RADV, adapter->rx_abs_int_delay);
  1743. if (adapter->itr_setting != 0)
  1744. E1000_WRITE_REG(hw, ITR,
  1745. 1000000000 / (adapter->itr * 256));
  1746. }
  1747. if (hw->mac_type >= e1000_82571) {
  1748. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1749. /* Reset delay timers after every interrupt */
  1750. ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
  1751. #ifdef CONFIG_E1000_NAPI
  1752. /* Auto-Mask interrupts upon ICR access */
  1753. ctrl_ext |= E1000_CTRL_EXT_IAME;
  1754. E1000_WRITE_REG(hw, IAM, 0xffffffff);
  1755. #endif
  1756. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1757. E1000_WRITE_FLUSH(hw);
  1758. }
  1759. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  1760. * the Base and Length of the Rx Descriptor Ring */
  1761. switch (adapter->num_rx_queues) {
  1762. case 1:
  1763. default:
  1764. rdba = adapter->rx_ring[0].dma;
  1765. E1000_WRITE_REG(hw, RDLEN, rdlen);
  1766. E1000_WRITE_REG(hw, RDBAH, (rdba >> 32));
  1767. E1000_WRITE_REG(hw, RDBAL, (rdba & 0x00000000ffffffffULL));
  1768. E1000_WRITE_REG(hw, RDT, 0);
  1769. E1000_WRITE_REG(hw, RDH, 0);
  1770. adapter->rx_ring[0].rdh = ((hw->mac_type >= e1000_82543) ? E1000_RDH : E1000_82542_RDH);
  1771. adapter->rx_ring[0].rdt = ((hw->mac_type >= e1000_82543) ? E1000_RDT : E1000_82542_RDT);
  1772. break;
  1773. }
  1774. /* Enable 82543 Receive Checksum Offload for TCP and UDP */
  1775. if (hw->mac_type >= e1000_82543) {
  1776. rxcsum = E1000_READ_REG(hw, RXCSUM);
  1777. if (adapter->rx_csum == TRUE) {
  1778. rxcsum |= E1000_RXCSUM_TUOFL;
  1779. /* Enable 82571 IPv4 payload checksum for UDP fragments
  1780. * Must be used in conjunction with packet-split. */
  1781. if ((hw->mac_type >= e1000_82571) &&
  1782. (adapter->rx_ps_pages)) {
  1783. rxcsum |= E1000_RXCSUM_IPPCSE;
  1784. }
  1785. } else {
  1786. rxcsum &= ~E1000_RXCSUM_TUOFL;
  1787. /* don't need to clear IPPCSE as it defaults to 0 */
  1788. }
  1789. E1000_WRITE_REG(hw, RXCSUM, rxcsum);
  1790. }
  1791. /* enable early receives on 82573, only takes effect if using > 2048
  1792. * byte total frame size. for example only for jumbo frames */
  1793. #define E1000_ERT_2048 0x100
  1794. if (hw->mac_type == e1000_82573)
  1795. E1000_WRITE_REG(hw, ERT, E1000_ERT_2048);
  1796. /* Enable Receives */
  1797. E1000_WRITE_REG(hw, RCTL, rctl);
  1798. }
  1799. /**
  1800. * e1000_free_tx_resources - Free Tx Resources per Queue
  1801. * @adapter: board private structure
  1802. * @tx_ring: Tx descriptor ring for a specific queue
  1803. *
  1804. * Free all transmit software resources
  1805. **/
  1806. static void
  1807. e1000_free_tx_resources(struct e1000_adapter *adapter,
  1808. struct e1000_tx_ring *tx_ring)
  1809. {
  1810. struct pci_dev *pdev = adapter->pdev;
  1811. e1000_clean_tx_ring(adapter, tx_ring);
  1812. vfree(tx_ring->buffer_info);
  1813. tx_ring->buffer_info = NULL;
  1814. pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma);
  1815. tx_ring->desc = NULL;
  1816. }
  1817. /**
  1818. * e1000_free_all_tx_resources - Free Tx Resources for All Queues
  1819. * @adapter: board private structure
  1820. *
  1821. * Free all transmit software resources
  1822. **/
  1823. void
  1824. e1000_free_all_tx_resources(struct e1000_adapter *adapter)
  1825. {
  1826. int i;
  1827. for (i = 0; i < adapter->num_tx_queues; i++)
  1828. e1000_free_tx_resources(adapter, &adapter->tx_ring[i]);
  1829. }
  1830. static void
  1831. e1000_unmap_and_free_tx_resource(struct e1000_adapter *adapter,
  1832. struct e1000_buffer *buffer_info)
  1833. {
  1834. if (buffer_info->dma) {
  1835. pci_unmap_page(adapter->pdev,
  1836. buffer_info->dma,
  1837. buffer_info->length,
  1838. PCI_DMA_TODEVICE);
  1839. buffer_info->dma = 0;
  1840. }
  1841. if (buffer_info->skb) {
  1842. dev_kfree_skb_any(buffer_info->skb);
  1843. buffer_info->skb = NULL;
  1844. }
  1845. /* buffer_info must be completely set up in the transmit path */
  1846. }
  1847. /**
  1848. * e1000_clean_tx_ring - Free Tx Buffers
  1849. * @adapter: board private structure
  1850. * @tx_ring: ring to be cleaned
  1851. **/
  1852. static void
  1853. e1000_clean_tx_ring(struct e1000_adapter *adapter,
  1854. struct e1000_tx_ring *tx_ring)
  1855. {
  1856. struct e1000_buffer *buffer_info;
  1857. unsigned long size;
  1858. unsigned int i;
  1859. /* Free all the Tx ring sk_buffs */
  1860. for (i = 0; i < tx_ring->count; i++) {
  1861. buffer_info = &tx_ring->buffer_info[i];
  1862. e1000_unmap_and_free_tx_resource(adapter, buffer_info);
  1863. }
  1864. size = sizeof(struct e1000_buffer) * tx_ring->count;
  1865. memset(tx_ring->buffer_info, 0, size);
  1866. /* Zero out the descriptor ring */
  1867. memset(tx_ring->desc, 0, tx_ring->size);
  1868. tx_ring->next_to_use = 0;
  1869. tx_ring->next_to_clean = 0;
  1870. tx_ring->last_tx_tso = 0;
  1871. writel(0, adapter->hw.hw_addr + tx_ring->tdh);
  1872. writel(0, adapter->hw.hw_addr + tx_ring->tdt);
  1873. }
  1874. /**
  1875. * e1000_clean_all_tx_rings - Free Tx Buffers for all queues
  1876. * @adapter: board private structure
  1877. **/
  1878. static void
  1879. e1000_clean_all_tx_rings(struct e1000_adapter *adapter)
  1880. {
  1881. int i;
  1882. for (i = 0; i < adapter->num_tx_queues; i++)
  1883. e1000_clean_tx_ring(adapter, &adapter->tx_ring[i]);
  1884. }
  1885. /**
  1886. * e1000_free_rx_resources - Free Rx Resources
  1887. * @adapter: board private structure
  1888. * @rx_ring: ring to clean the resources from
  1889. *
  1890. * Free all receive software resources
  1891. **/
  1892. static void
  1893. e1000_free_rx_resources(struct e1000_adapter *adapter,
  1894. struct e1000_rx_ring *rx_ring)
  1895. {
  1896. struct pci_dev *pdev = adapter->pdev;
  1897. e1000_clean_rx_ring(adapter, rx_ring);
  1898. vfree(rx_ring->buffer_info);
  1899. rx_ring->buffer_info = NULL;
  1900. kfree(rx_ring->ps_page);
  1901. rx_ring->ps_page = NULL;
  1902. kfree(rx_ring->ps_page_dma);
  1903. rx_ring->ps_page_dma = NULL;
  1904. pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma);
  1905. rx_ring->desc = NULL;
  1906. }
  1907. /**
  1908. * e1000_free_all_rx_resources - Free Rx Resources for All Queues
  1909. * @adapter: board private structure
  1910. *
  1911. * Free all receive software resources
  1912. **/
  1913. void
  1914. e1000_free_all_rx_resources(struct e1000_adapter *adapter)
  1915. {
  1916. int i;
  1917. for (i = 0; i < adapter->num_rx_queues; i++)
  1918. e1000_free_rx_resources(adapter, &adapter->rx_ring[i]);
  1919. }
  1920. /**
  1921. * e1000_clean_rx_ring - Free Rx Buffers per Queue
  1922. * @adapter: board private structure
  1923. * @rx_ring: ring to free buffers from
  1924. **/
  1925. static void
  1926. e1000_clean_rx_ring(struct e1000_adapter *adapter,
  1927. struct e1000_rx_ring *rx_ring)
  1928. {
  1929. struct e1000_buffer *buffer_info;
  1930. struct e1000_ps_page *ps_page;
  1931. struct e1000_ps_page_dma *ps_page_dma;
  1932. struct pci_dev *pdev = adapter->pdev;
  1933. unsigned long size;
  1934. unsigned int i, j;
  1935. /* Free all the Rx ring sk_buffs */
  1936. for (i = 0; i < rx_ring->count; i++) {
  1937. buffer_info = &rx_ring->buffer_info[i];
  1938. if (buffer_info->skb) {
  1939. pci_unmap_single(pdev,
  1940. buffer_info->dma,
  1941. buffer_info->length,
  1942. PCI_DMA_FROMDEVICE);
  1943. dev_kfree_skb(buffer_info->skb);
  1944. buffer_info->skb = NULL;
  1945. }
  1946. ps_page = &rx_ring->ps_page[i];
  1947. ps_page_dma = &rx_ring->ps_page_dma[i];
  1948. for (j = 0; j < adapter->rx_ps_pages; j++) {
  1949. if (!ps_page->ps_page[j]) break;
  1950. pci_unmap_page(pdev,
  1951. ps_page_dma->ps_page_dma[j],
  1952. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  1953. ps_page_dma->ps_page_dma[j] = 0;
  1954. put_page(ps_page->ps_page[j]);
  1955. ps_page->ps_page[j] = NULL;
  1956. }
  1957. }
  1958. size = sizeof(struct e1000_buffer) * rx_ring->count;
  1959. memset(rx_ring->buffer_info, 0, size);
  1960. size = sizeof(struct e1000_ps_page) * rx_ring->count;
  1961. memset(rx_ring->ps_page, 0, size);
  1962. size = sizeof(struct e1000_ps_page_dma) * rx_ring->count;
  1963. memset(rx_ring->ps_page_dma, 0, size);
  1964. /* Zero out the descriptor ring */
  1965. memset(rx_ring->desc, 0, rx_ring->size);
  1966. rx_ring->next_to_clean = 0;
  1967. rx_ring->next_to_use = 0;
  1968. writel(0, adapter->hw.hw_addr + rx_ring->rdh);
  1969. writel(0, adapter->hw.hw_addr + rx_ring->rdt);
  1970. }
  1971. /**
  1972. * e1000_clean_all_rx_rings - Free Rx Buffers for all queues
  1973. * @adapter: board private structure
  1974. **/
  1975. static void
  1976. e1000_clean_all_rx_rings(struct e1000_adapter *adapter)
  1977. {
  1978. int i;
  1979. for (i = 0; i < adapter->num_rx_queues; i++)
  1980. e1000_clean_rx_ring(adapter, &adapter->rx_ring[i]);
  1981. }
  1982. /* The 82542 2.0 (revision 2) needs to have the receive unit in reset
  1983. * and memory write and invalidate disabled for certain operations
  1984. */
  1985. static void
  1986. e1000_enter_82542_rst(struct e1000_adapter *adapter)
  1987. {
  1988. struct net_device *netdev = adapter->netdev;
  1989. uint32_t rctl;
  1990. e1000_pci_clear_mwi(&adapter->hw);
  1991. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  1992. rctl |= E1000_RCTL_RST;
  1993. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  1994. E1000_WRITE_FLUSH(&adapter->hw);
  1995. mdelay(5);
  1996. if (netif_running(netdev))
  1997. e1000_clean_all_rx_rings(adapter);
  1998. }
  1999. static void
  2000. e1000_leave_82542_rst(struct e1000_adapter *adapter)
  2001. {
  2002. struct net_device *netdev = adapter->netdev;
  2003. uint32_t rctl;
  2004. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  2005. rctl &= ~E1000_RCTL_RST;
  2006. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  2007. E1000_WRITE_FLUSH(&adapter->hw);
  2008. mdelay(5);
  2009. if (adapter->hw.pci_cmd_word & PCI_COMMAND_INVALIDATE)
  2010. e1000_pci_set_mwi(&adapter->hw);
  2011. if (netif_running(netdev)) {
  2012. /* No need to loop, because 82542 supports only 1 queue */
  2013. struct e1000_rx_ring *ring = &adapter->rx_ring[0];
  2014. e1000_configure_rx(adapter);
  2015. adapter->alloc_rx_buf(adapter, ring, E1000_DESC_UNUSED(ring));
  2016. }
  2017. }
  2018. /**
  2019. * e1000_set_mac - Change the Ethernet Address of the NIC
  2020. * @netdev: network interface device structure
  2021. * @p: pointer to an address structure
  2022. *
  2023. * Returns 0 on success, negative on failure
  2024. **/
  2025. static int
  2026. e1000_set_mac(struct net_device *netdev, void *p)
  2027. {
  2028. struct e1000_adapter *adapter = netdev_priv(netdev);
  2029. struct sockaddr *addr = p;
  2030. if (!is_valid_ether_addr(addr->sa_data))
  2031. return -EADDRNOTAVAIL;
  2032. /* 82542 2.0 needs to be in reset to write receive address registers */
  2033. if (adapter->hw.mac_type == e1000_82542_rev2_0)
  2034. e1000_enter_82542_rst(adapter);
  2035. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2036. memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
  2037. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
  2038. /* With 82571 controllers, LAA may be overwritten (with the default)
  2039. * due to controller reset from the other port. */
  2040. if (adapter->hw.mac_type == e1000_82571) {
  2041. /* activate the work around */
  2042. adapter->hw.laa_is_present = 1;
  2043. /* Hold a copy of the LAA in RAR[14] This is done so that
  2044. * between the time RAR[0] gets clobbered and the time it
  2045. * gets fixed (in e1000_watchdog), the actual LAA is in one
  2046. * of the RARs and no incoming packets directed to this port
  2047. * are dropped. Eventaully the LAA will be in RAR[0] and
  2048. * RAR[14] */
  2049. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr,
  2050. E1000_RAR_ENTRIES - 1);
  2051. }
  2052. if (adapter->hw.mac_type == e1000_82542_rev2_0)
  2053. e1000_leave_82542_rst(adapter);
  2054. return 0;
  2055. }
  2056. /**
  2057. * e1000_set_multi - Multicast and Promiscuous mode set
  2058. * @netdev: network interface device structure
  2059. *
  2060. * The set_multi entry point is called whenever the multicast address
  2061. * list or the network interface flags are updated. This routine is
  2062. * responsible for configuring the hardware for proper multicast,
  2063. * promiscuous mode, and all-multi behavior.
  2064. **/
  2065. static void
  2066. e1000_set_multi(struct net_device *netdev)
  2067. {
  2068. struct e1000_adapter *adapter = netdev_priv(netdev);
  2069. struct e1000_hw *hw = &adapter->hw;
  2070. struct dev_mc_list *mc_ptr;
  2071. uint32_t rctl;
  2072. uint32_t hash_value;
  2073. int i, rar_entries = E1000_RAR_ENTRIES;
  2074. int mta_reg_count = (hw->mac_type == e1000_ich8lan) ?
  2075. E1000_NUM_MTA_REGISTERS_ICH8LAN :
  2076. E1000_NUM_MTA_REGISTERS;
  2077. if (adapter->hw.mac_type == e1000_ich8lan)
  2078. rar_entries = E1000_RAR_ENTRIES_ICH8LAN;
  2079. /* reserve RAR[14] for LAA over-write work-around */
  2080. if (adapter->hw.mac_type == e1000_82571)
  2081. rar_entries--;
  2082. /* Check for Promiscuous and All Multicast modes */
  2083. rctl = E1000_READ_REG(hw, RCTL);
  2084. if (netdev->flags & IFF_PROMISC) {
  2085. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  2086. } else if (netdev->flags & IFF_ALLMULTI) {
  2087. rctl |= E1000_RCTL_MPE;
  2088. rctl &= ~E1000_RCTL_UPE;
  2089. } else {
  2090. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
  2091. }
  2092. E1000_WRITE_REG(hw, RCTL, rctl);
  2093. /* 82542 2.0 needs to be in reset to write receive address registers */
  2094. if (hw->mac_type == e1000_82542_rev2_0)
  2095. e1000_enter_82542_rst(adapter);
  2096. /* load the first 14 multicast address into the exact filters 1-14
  2097. * RAR 0 is used for the station MAC adddress
  2098. * if there are not 14 addresses, go ahead and clear the filters
  2099. * -- with 82571 controllers only 0-13 entries are filled here
  2100. */
  2101. mc_ptr = netdev->mc_list;
  2102. for (i = 1; i < rar_entries; i++) {
  2103. if (mc_ptr) {
  2104. e1000_rar_set(hw, mc_ptr->dmi_addr, i);
  2105. mc_ptr = mc_ptr->next;
  2106. } else {
  2107. E1000_WRITE_REG_ARRAY(hw, RA, i << 1, 0);
  2108. E1000_WRITE_FLUSH(hw);
  2109. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1) + 1, 0);
  2110. E1000_WRITE_FLUSH(hw);
  2111. }
  2112. }
  2113. /* clear the old settings from the multicast hash table */
  2114. for (i = 0; i < mta_reg_count; i++) {
  2115. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  2116. E1000_WRITE_FLUSH(hw);
  2117. }
  2118. /* load any remaining addresses into the hash table */
  2119. for (; mc_ptr; mc_ptr = mc_ptr->next) {
  2120. hash_value = e1000_hash_mc_addr(hw, mc_ptr->dmi_addr);
  2121. e1000_mta_set(hw, hash_value);
  2122. }
  2123. if (hw->mac_type == e1000_82542_rev2_0)
  2124. e1000_leave_82542_rst(adapter);
  2125. }
  2126. /* Need to wait a few seconds after link up to get diagnostic information from
  2127. * the phy */
  2128. static void
  2129. e1000_update_phy_info(unsigned long data)
  2130. {
  2131. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  2132. e1000_phy_get_info(&adapter->hw, &adapter->phy_info);
  2133. }
  2134. /**
  2135. * e1000_82547_tx_fifo_stall - Timer Call-back
  2136. * @data: pointer to adapter cast into an unsigned long
  2137. **/
  2138. static void
  2139. e1000_82547_tx_fifo_stall(unsigned long data)
  2140. {
  2141. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  2142. struct net_device *netdev = adapter->netdev;
  2143. uint32_t tctl;
  2144. if (atomic_read(&adapter->tx_fifo_stall)) {
  2145. if ((E1000_READ_REG(&adapter->hw, TDT) ==
  2146. E1000_READ_REG(&adapter->hw, TDH)) &&
  2147. (E1000_READ_REG(&adapter->hw, TDFT) ==
  2148. E1000_READ_REG(&adapter->hw, TDFH)) &&
  2149. (E1000_READ_REG(&adapter->hw, TDFTS) ==
  2150. E1000_READ_REG(&adapter->hw, TDFHS))) {
  2151. tctl = E1000_READ_REG(&adapter->hw, TCTL);
  2152. E1000_WRITE_REG(&adapter->hw, TCTL,
  2153. tctl & ~E1000_TCTL_EN);
  2154. E1000_WRITE_REG(&adapter->hw, TDFT,
  2155. adapter->tx_head_addr);
  2156. E1000_WRITE_REG(&adapter->hw, TDFH,
  2157. adapter->tx_head_addr);
  2158. E1000_WRITE_REG(&adapter->hw, TDFTS,
  2159. adapter->tx_head_addr);
  2160. E1000_WRITE_REG(&adapter->hw, TDFHS,
  2161. adapter->tx_head_addr);
  2162. E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
  2163. E1000_WRITE_FLUSH(&adapter->hw);
  2164. adapter->tx_fifo_head = 0;
  2165. atomic_set(&adapter->tx_fifo_stall, 0);
  2166. netif_wake_queue(netdev);
  2167. } else {
  2168. mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
  2169. }
  2170. }
  2171. }
  2172. /**
  2173. * e1000_watchdog - Timer Call-back
  2174. * @data: pointer to adapter cast into an unsigned long
  2175. **/
  2176. static void
  2177. e1000_watchdog(unsigned long data)
  2178. {
  2179. struct e1000_adapter *adapter = (struct e1000_adapter *) data;
  2180. struct net_device *netdev = adapter->netdev;
  2181. struct e1000_tx_ring *txdr = adapter->tx_ring;
  2182. uint32_t link, tctl;
  2183. int32_t ret_val;
  2184. ret_val = e1000_check_for_link(&adapter->hw);
  2185. if ((ret_val == E1000_ERR_PHY) &&
  2186. (adapter->hw.phy_type == e1000_phy_igp_3) &&
  2187. (E1000_READ_REG(&adapter->hw, CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
  2188. /* See e1000_kumeran_lock_loss_workaround() */
  2189. DPRINTK(LINK, INFO,
  2190. "Gigabit has been disabled, downgrading speed\n");
  2191. }
  2192. if (adapter->hw.mac_type == e1000_82573) {
  2193. e1000_enable_tx_pkt_filtering(&adapter->hw);
  2194. if (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id)
  2195. e1000_update_mng_vlan(adapter);
  2196. }
  2197. if ((adapter->hw.media_type == e1000_media_type_internal_serdes) &&
  2198. !(E1000_READ_REG(&adapter->hw, TXCW) & E1000_TXCW_ANE))
  2199. link = !adapter->hw.serdes_link_down;
  2200. else
  2201. link = E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU;
  2202. if (link) {
  2203. if (!netif_carrier_ok(netdev)) {
  2204. uint32_t ctrl;
  2205. boolean_t txb2b = 1;
  2206. e1000_get_speed_and_duplex(&adapter->hw,
  2207. &adapter->link_speed,
  2208. &adapter->link_duplex);
  2209. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  2210. DPRINTK(LINK, INFO, "NIC Link is Up %d Mbps %s, "
  2211. "Flow Control: %s\n",
  2212. adapter->link_speed,
  2213. adapter->link_duplex == FULL_DUPLEX ?
  2214. "Full Duplex" : "Half Duplex",
  2215. ((ctrl & E1000_CTRL_TFCE) && (ctrl &
  2216. E1000_CTRL_RFCE)) ? "RX/TX" : ((ctrl &
  2217. E1000_CTRL_RFCE) ? "RX" : ((ctrl &
  2218. E1000_CTRL_TFCE) ? "TX" : "None" )));
  2219. /* tweak tx_queue_len according to speed/duplex
  2220. * and adjust the timeout factor */
  2221. netdev->tx_queue_len = adapter->tx_queue_len;
  2222. adapter->tx_timeout_factor = 1;
  2223. switch (adapter->link_speed) {
  2224. case SPEED_10:
  2225. txb2b = 0;
  2226. netdev->tx_queue_len = 10;
  2227. adapter->tx_timeout_factor = 8;
  2228. break;
  2229. case SPEED_100:
  2230. txb2b = 0;
  2231. netdev->tx_queue_len = 100;
  2232. /* maybe add some timeout factor ? */
  2233. break;
  2234. }
  2235. if ((adapter->hw.mac_type == e1000_82571 ||
  2236. adapter->hw.mac_type == e1000_82572) &&
  2237. txb2b == 0) {
  2238. uint32_t tarc0;
  2239. tarc0 = E1000_READ_REG(&adapter->hw, TARC0);
  2240. tarc0 &= ~(1 << 21);
  2241. E1000_WRITE_REG(&adapter->hw, TARC0, tarc0);
  2242. }
  2243. /* disable TSO for pcie and 10/100 speeds, to avoid
  2244. * some hardware issues */
  2245. if (!adapter->tso_force &&
  2246. adapter->hw.bus_type == e1000_bus_type_pci_express){
  2247. switch (adapter->link_speed) {
  2248. case SPEED_10:
  2249. case SPEED_100:
  2250. DPRINTK(PROBE,INFO,
  2251. "10/100 speed: disabling TSO\n");
  2252. netdev->features &= ~NETIF_F_TSO;
  2253. netdev->features &= ~NETIF_F_TSO6;
  2254. break;
  2255. case SPEED_1000:
  2256. netdev->features |= NETIF_F_TSO;
  2257. netdev->features |= NETIF_F_TSO6;
  2258. break;
  2259. default:
  2260. /* oops */
  2261. break;
  2262. }
  2263. }
  2264. /* enable transmits in the hardware, need to do this
  2265. * after setting TARC0 */
  2266. tctl = E1000_READ_REG(&adapter->hw, TCTL);
  2267. tctl |= E1000_TCTL_EN;
  2268. E1000_WRITE_REG(&adapter->hw, TCTL, tctl);
  2269. netif_carrier_on(netdev);
  2270. netif_wake_queue(netdev);
  2271. mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
  2272. adapter->smartspeed = 0;
  2273. } else {
  2274. /* make sure the receive unit is started */
  2275. if (adapter->hw.rx_needs_kicking) {
  2276. struct e1000_hw *hw = &adapter->hw;
  2277. uint32_t rctl = E1000_READ_REG(hw, RCTL);
  2278. E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
  2279. }
  2280. }
  2281. } else {
  2282. if (netif_carrier_ok(netdev)) {
  2283. adapter->link_speed = 0;
  2284. adapter->link_duplex = 0;
  2285. DPRINTK(LINK, INFO, "NIC Link is Down\n");
  2286. netif_carrier_off(netdev);
  2287. netif_stop_queue(netdev);
  2288. mod_timer(&adapter->phy_info_timer, round_jiffies(jiffies + 2 * HZ));
  2289. /* 80003ES2LAN workaround--
  2290. * For packet buffer work-around on link down event;
  2291. * disable receives in the ISR and
  2292. * reset device here in the watchdog
  2293. */
  2294. if (adapter->hw.mac_type == e1000_80003es2lan)
  2295. /* reset device */
  2296. schedule_work(&adapter->reset_task);
  2297. }
  2298. e1000_smartspeed(adapter);
  2299. }
  2300. e1000_update_stats(adapter);
  2301. adapter->hw.tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  2302. adapter->tpt_old = adapter->stats.tpt;
  2303. adapter->hw.collision_delta = adapter->stats.colc - adapter->colc_old;
  2304. adapter->colc_old = adapter->stats.colc;
  2305. adapter->gorcl = adapter->stats.gorcl - adapter->gorcl_old;
  2306. adapter->gorcl_old = adapter->stats.gorcl;
  2307. adapter->gotcl = adapter->stats.gotcl - adapter->gotcl_old;
  2308. adapter->gotcl_old = adapter->stats.gotcl;
  2309. e1000_update_adaptive(&adapter->hw);
  2310. if (!netif_carrier_ok(netdev)) {
  2311. if (E1000_DESC_UNUSED(txdr) + 1 < txdr->count) {
  2312. /* We've lost link, so the controller stops DMA,
  2313. * but we've got queued Tx work that's never going
  2314. * to get done, so reset controller to flush Tx.
  2315. * (Do the reset outside of interrupt context). */
  2316. adapter->tx_timeout_count++;
  2317. schedule_work(&adapter->reset_task);
  2318. }
  2319. }
  2320. /* Cause software interrupt to ensure rx ring is cleaned */
  2321. E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_RXDMT0);
  2322. /* Force detection of hung controller every watchdog period */
  2323. adapter->detect_tx_hung = TRUE;
  2324. /* With 82571 controllers, LAA may be overwritten due to controller
  2325. * reset from the other port. Set the appropriate LAA in RAR[0] */
  2326. if (adapter->hw.mac_type == e1000_82571 && adapter->hw.laa_is_present)
  2327. e1000_rar_set(&adapter->hw, adapter->hw.mac_addr, 0);
  2328. /* Reset the timer */
  2329. mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
  2330. }
  2331. enum latency_range {
  2332. lowest_latency = 0,
  2333. low_latency = 1,
  2334. bulk_latency = 2,
  2335. latency_invalid = 255
  2336. };
  2337. /**
  2338. * e1000_update_itr - update the dynamic ITR value based on statistics
  2339. * Stores a new ITR value based on packets and byte
  2340. * counts during the last interrupt. The advantage of per interrupt
  2341. * computation is faster updates and more accurate ITR for the current
  2342. * traffic pattern. Constants in this function were computed
  2343. * based on theoretical maximum wire speed and thresholds were set based
  2344. * on testing data as well as attempting to minimize response time
  2345. * while increasing bulk throughput.
  2346. * this functionality is controlled by the InterruptThrottleRate module
  2347. * parameter (see e1000_param.c)
  2348. * @adapter: pointer to adapter
  2349. * @itr_setting: current adapter->itr
  2350. * @packets: the number of packets during this measurement interval
  2351. * @bytes: the number of bytes during this measurement interval
  2352. **/
  2353. static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
  2354. uint16_t itr_setting,
  2355. int packets,
  2356. int bytes)
  2357. {
  2358. unsigned int retval = itr_setting;
  2359. struct e1000_hw *hw = &adapter->hw;
  2360. if (unlikely(hw->mac_type < e1000_82540))
  2361. goto update_itr_done;
  2362. if (packets == 0)
  2363. goto update_itr_done;
  2364. switch (itr_setting) {
  2365. case lowest_latency:
  2366. /* jumbo frames get bulk treatment*/
  2367. if (bytes/packets > 8000)
  2368. retval = bulk_latency;
  2369. else if ((packets < 5) && (bytes > 512))
  2370. retval = low_latency;
  2371. break;
  2372. case low_latency: /* 50 usec aka 20000 ints/s */
  2373. if (bytes > 10000) {
  2374. /* jumbo frames need bulk latency setting */
  2375. if (bytes/packets > 8000)
  2376. retval = bulk_latency;
  2377. else if ((packets < 10) || ((bytes/packets) > 1200))
  2378. retval = bulk_latency;
  2379. else if ((packets > 35))
  2380. retval = lowest_latency;
  2381. } else if (bytes/packets > 2000)
  2382. retval = bulk_latency;
  2383. else if (packets <= 2 && bytes < 512)
  2384. retval = lowest_latency;
  2385. break;
  2386. case bulk_latency: /* 250 usec aka 4000 ints/s */
  2387. if (bytes > 25000) {
  2388. if (packets > 35)
  2389. retval = low_latency;
  2390. } else if (bytes < 6000) {
  2391. retval = low_latency;
  2392. }
  2393. break;
  2394. }
  2395. update_itr_done:
  2396. return retval;
  2397. }
  2398. static void e1000_set_itr(struct e1000_adapter *adapter)
  2399. {
  2400. struct e1000_hw *hw = &adapter->hw;
  2401. uint16_t current_itr;
  2402. uint32_t new_itr = adapter->itr;
  2403. if (unlikely(hw->mac_type < e1000_82540))
  2404. return;
  2405. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  2406. if (unlikely(adapter->link_speed != SPEED_1000)) {
  2407. current_itr = 0;
  2408. new_itr = 4000;
  2409. goto set_itr_now;
  2410. }
  2411. adapter->tx_itr = e1000_update_itr(adapter,
  2412. adapter->tx_itr,
  2413. adapter->total_tx_packets,
  2414. adapter->total_tx_bytes);
  2415. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2416. if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
  2417. adapter->tx_itr = low_latency;
  2418. adapter->rx_itr = e1000_update_itr(adapter,
  2419. adapter->rx_itr,
  2420. adapter->total_rx_packets,
  2421. adapter->total_rx_bytes);
  2422. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2423. if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
  2424. adapter->rx_itr = low_latency;
  2425. current_itr = max(adapter->rx_itr, adapter->tx_itr);
  2426. switch (current_itr) {
  2427. /* counts and packets in update_itr are dependent on these numbers */
  2428. case lowest_latency:
  2429. new_itr = 70000;
  2430. break;
  2431. case low_latency:
  2432. new_itr = 20000; /* aka hwitr = ~200 */
  2433. break;
  2434. case bulk_latency:
  2435. new_itr = 4000;
  2436. break;
  2437. default:
  2438. break;
  2439. }
  2440. set_itr_now:
  2441. if (new_itr != adapter->itr) {
  2442. /* this attempts to bias the interrupt rate towards Bulk
  2443. * by adding intermediate steps when interrupt rate is
  2444. * increasing */
  2445. new_itr = new_itr > adapter->itr ?
  2446. min(adapter->itr + (new_itr >> 2), new_itr) :
  2447. new_itr;
  2448. adapter->itr = new_itr;
  2449. E1000_WRITE_REG(hw, ITR, 1000000000 / (new_itr * 256));
  2450. }
  2451. return;
  2452. }
  2453. #define E1000_TX_FLAGS_CSUM 0x00000001
  2454. #define E1000_TX_FLAGS_VLAN 0x00000002
  2455. #define E1000_TX_FLAGS_TSO 0x00000004
  2456. #define E1000_TX_FLAGS_IPV4 0x00000008
  2457. #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
  2458. #define E1000_TX_FLAGS_VLAN_SHIFT 16
  2459. static int
  2460. e1000_tso(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2461. struct sk_buff *skb)
  2462. {
  2463. struct e1000_context_desc *context_desc;
  2464. struct e1000_buffer *buffer_info;
  2465. unsigned int i;
  2466. uint32_t cmd_length = 0;
  2467. uint16_t ipcse = 0, tucse, mss;
  2468. uint8_t ipcss, ipcso, tucss, tucso, hdr_len;
  2469. int err;
  2470. if (skb_is_gso(skb)) {
  2471. if (skb_header_cloned(skb)) {
  2472. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  2473. if (err)
  2474. return err;
  2475. }
  2476. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  2477. mss = skb_shinfo(skb)->gso_size;
  2478. if (skb->protocol == htons(ETH_P_IP)) {
  2479. struct iphdr *iph = ip_hdr(skb);
  2480. iph->tot_len = 0;
  2481. iph->check = 0;
  2482. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  2483. iph->daddr, 0,
  2484. IPPROTO_TCP,
  2485. 0);
  2486. cmd_length = E1000_TXD_CMD_IP;
  2487. ipcse = skb_transport_offset(skb) - 1;
  2488. } else if (skb->protocol == htons(ETH_P_IPV6)) {
  2489. ipv6_hdr(skb)->payload_len = 0;
  2490. tcp_hdr(skb)->check =
  2491. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  2492. &ipv6_hdr(skb)->daddr,
  2493. 0, IPPROTO_TCP, 0);
  2494. ipcse = 0;
  2495. }
  2496. ipcss = skb_network_offset(skb);
  2497. ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
  2498. tucss = skb_transport_offset(skb);
  2499. tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
  2500. tucse = 0;
  2501. cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
  2502. E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
  2503. i = tx_ring->next_to_use;
  2504. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  2505. buffer_info = &tx_ring->buffer_info[i];
  2506. context_desc->lower_setup.ip_fields.ipcss = ipcss;
  2507. context_desc->lower_setup.ip_fields.ipcso = ipcso;
  2508. context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
  2509. context_desc->upper_setup.tcp_fields.tucss = tucss;
  2510. context_desc->upper_setup.tcp_fields.tucso = tucso;
  2511. context_desc->upper_setup.tcp_fields.tucse = cpu_to_le16(tucse);
  2512. context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
  2513. context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
  2514. context_desc->cmd_and_length = cpu_to_le32(cmd_length);
  2515. buffer_info->time_stamp = jiffies;
  2516. buffer_info->next_to_watch = i;
  2517. if (++i == tx_ring->count) i = 0;
  2518. tx_ring->next_to_use = i;
  2519. return TRUE;
  2520. }
  2521. return FALSE;
  2522. }
  2523. static boolean_t
  2524. e1000_tx_csum(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2525. struct sk_buff *skb)
  2526. {
  2527. struct e1000_context_desc *context_desc;
  2528. struct e1000_buffer *buffer_info;
  2529. unsigned int i;
  2530. uint8_t css;
  2531. if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
  2532. css = skb_transport_offset(skb);
  2533. i = tx_ring->next_to_use;
  2534. buffer_info = &tx_ring->buffer_info[i];
  2535. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  2536. context_desc->lower_setup.ip_config = 0;
  2537. context_desc->upper_setup.tcp_fields.tucss = css;
  2538. context_desc->upper_setup.tcp_fields.tucso =
  2539. css + skb->csum_offset;
  2540. context_desc->upper_setup.tcp_fields.tucse = 0;
  2541. context_desc->tcp_seg_setup.data = 0;
  2542. context_desc->cmd_and_length = cpu_to_le32(E1000_TXD_CMD_DEXT);
  2543. buffer_info->time_stamp = jiffies;
  2544. buffer_info->next_to_watch = i;
  2545. if (unlikely(++i == tx_ring->count)) i = 0;
  2546. tx_ring->next_to_use = i;
  2547. return TRUE;
  2548. }
  2549. return FALSE;
  2550. }
  2551. #define E1000_MAX_TXD_PWR 12
  2552. #define E1000_MAX_DATA_PER_TXD (1<<E1000_MAX_TXD_PWR)
  2553. static int
  2554. e1000_tx_map(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2555. struct sk_buff *skb, unsigned int first, unsigned int max_per_txd,
  2556. unsigned int nr_frags, unsigned int mss)
  2557. {
  2558. struct e1000_buffer *buffer_info;
  2559. unsigned int len = skb->len;
  2560. unsigned int offset = 0, size, count = 0, i;
  2561. unsigned int f;
  2562. len -= skb->data_len;
  2563. i = tx_ring->next_to_use;
  2564. while (len) {
  2565. buffer_info = &tx_ring->buffer_info[i];
  2566. size = min(len, max_per_txd);
  2567. /* Workaround for Controller erratum --
  2568. * descriptor for non-tso packet in a linear SKB that follows a
  2569. * tso gets written back prematurely before the data is fully
  2570. * DMA'd to the controller */
  2571. if (!skb->data_len && tx_ring->last_tx_tso &&
  2572. !skb_is_gso(skb)) {
  2573. tx_ring->last_tx_tso = 0;
  2574. size -= 4;
  2575. }
  2576. /* Workaround for premature desc write-backs
  2577. * in TSO mode. Append 4-byte sentinel desc */
  2578. if (unlikely(mss && !nr_frags && size == len && size > 8))
  2579. size -= 4;
  2580. /* work-around for errata 10 and it applies
  2581. * to all controllers in PCI-X mode
  2582. * The fix is to make sure that the first descriptor of a
  2583. * packet is smaller than 2048 - 16 - 16 (or 2016) bytes
  2584. */
  2585. if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
  2586. (size > 2015) && count == 0))
  2587. size = 2015;
  2588. /* Workaround for potential 82544 hang in PCI-X. Avoid
  2589. * terminating buffers within evenly-aligned dwords. */
  2590. if (unlikely(adapter->pcix_82544 &&
  2591. !((unsigned long)(skb->data + offset + size - 1) & 4) &&
  2592. size > 4))
  2593. size -= 4;
  2594. buffer_info->length = size;
  2595. buffer_info->dma =
  2596. pci_map_single(adapter->pdev,
  2597. skb->data + offset,
  2598. size,
  2599. PCI_DMA_TODEVICE);
  2600. buffer_info->time_stamp = jiffies;
  2601. buffer_info->next_to_watch = i;
  2602. len -= size;
  2603. offset += size;
  2604. count++;
  2605. if (unlikely(++i == tx_ring->count)) i = 0;
  2606. }
  2607. for (f = 0; f < nr_frags; f++) {
  2608. struct skb_frag_struct *frag;
  2609. frag = &skb_shinfo(skb)->frags[f];
  2610. len = frag->size;
  2611. offset = frag->page_offset;
  2612. while (len) {
  2613. buffer_info = &tx_ring->buffer_info[i];
  2614. size = min(len, max_per_txd);
  2615. /* Workaround for premature desc write-backs
  2616. * in TSO mode. Append 4-byte sentinel desc */
  2617. if (unlikely(mss && f == (nr_frags-1) && size == len && size > 8))
  2618. size -= 4;
  2619. /* Workaround for potential 82544 hang in PCI-X.
  2620. * Avoid terminating buffers within evenly-aligned
  2621. * dwords. */
  2622. if (unlikely(adapter->pcix_82544 &&
  2623. !((unsigned long)(frag->page+offset+size-1) & 4) &&
  2624. size > 4))
  2625. size -= 4;
  2626. buffer_info->length = size;
  2627. buffer_info->dma =
  2628. pci_map_page(adapter->pdev,
  2629. frag->page,
  2630. offset,
  2631. size,
  2632. PCI_DMA_TODEVICE);
  2633. buffer_info->time_stamp = jiffies;
  2634. buffer_info->next_to_watch = i;
  2635. len -= size;
  2636. offset += size;
  2637. count++;
  2638. if (unlikely(++i == tx_ring->count)) i = 0;
  2639. }
  2640. }
  2641. i = (i == 0) ? tx_ring->count - 1 : i - 1;
  2642. tx_ring->buffer_info[i].skb = skb;
  2643. tx_ring->buffer_info[first].next_to_watch = i;
  2644. return count;
  2645. }
  2646. static void
  2647. e1000_tx_queue(struct e1000_adapter *adapter, struct e1000_tx_ring *tx_ring,
  2648. int tx_flags, int count)
  2649. {
  2650. struct e1000_tx_desc *tx_desc = NULL;
  2651. struct e1000_buffer *buffer_info;
  2652. uint32_t txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
  2653. unsigned int i;
  2654. if (likely(tx_flags & E1000_TX_FLAGS_TSO)) {
  2655. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
  2656. E1000_TXD_CMD_TSE;
  2657. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  2658. if (likely(tx_flags & E1000_TX_FLAGS_IPV4))
  2659. txd_upper |= E1000_TXD_POPTS_IXSM << 8;
  2660. }
  2661. if (likely(tx_flags & E1000_TX_FLAGS_CSUM)) {
  2662. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  2663. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  2664. }
  2665. if (unlikely(tx_flags & E1000_TX_FLAGS_VLAN)) {
  2666. txd_lower |= E1000_TXD_CMD_VLE;
  2667. txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
  2668. }
  2669. i = tx_ring->next_to_use;
  2670. while (count--) {
  2671. buffer_info = &tx_ring->buffer_info[i];
  2672. tx_desc = E1000_TX_DESC(*tx_ring, i);
  2673. tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  2674. tx_desc->lower.data =
  2675. cpu_to_le32(txd_lower | buffer_info->length);
  2676. tx_desc->upper.data = cpu_to_le32(txd_upper);
  2677. if (unlikely(++i == tx_ring->count)) i = 0;
  2678. }
  2679. tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
  2680. /* Force memory writes to complete before letting h/w
  2681. * know there are new descriptors to fetch. (Only
  2682. * applicable for weak-ordered memory model archs,
  2683. * such as IA-64). */
  2684. wmb();
  2685. tx_ring->next_to_use = i;
  2686. writel(i, adapter->hw.hw_addr + tx_ring->tdt);
  2687. /* we need this if more than one processor can write to our tail
  2688. * at a time, it syncronizes IO on IA64/Altix systems */
  2689. mmiowb();
  2690. }
  2691. /**
  2692. * 82547 workaround to avoid controller hang in half-duplex environment.
  2693. * The workaround is to avoid queuing a large packet that would span
  2694. * the internal Tx FIFO ring boundary by notifying the stack to resend
  2695. * the packet at a later time. This gives the Tx FIFO an opportunity to
  2696. * flush all packets. When that occurs, we reset the Tx FIFO pointers
  2697. * to the beginning of the Tx FIFO.
  2698. **/
  2699. #define E1000_FIFO_HDR 0x10
  2700. #define E1000_82547_PAD_LEN 0x3E0
  2701. static int
  2702. e1000_82547_fifo_workaround(struct e1000_adapter *adapter, struct sk_buff *skb)
  2703. {
  2704. uint32_t fifo_space = adapter->tx_fifo_size - adapter->tx_fifo_head;
  2705. uint32_t skb_fifo_len = skb->len + E1000_FIFO_HDR;
  2706. skb_fifo_len = ALIGN(skb_fifo_len, E1000_FIFO_HDR);
  2707. if (adapter->link_duplex != HALF_DUPLEX)
  2708. goto no_fifo_stall_required;
  2709. if (atomic_read(&adapter->tx_fifo_stall))
  2710. return 1;
  2711. if (skb_fifo_len >= (E1000_82547_PAD_LEN + fifo_space)) {
  2712. atomic_set(&adapter->tx_fifo_stall, 1);
  2713. return 1;
  2714. }
  2715. no_fifo_stall_required:
  2716. adapter->tx_fifo_head += skb_fifo_len;
  2717. if (adapter->tx_fifo_head >= adapter->tx_fifo_size)
  2718. adapter->tx_fifo_head -= adapter->tx_fifo_size;
  2719. return 0;
  2720. }
  2721. #define MINIMUM_DHCP_PACKET_SIZE 282
  2722. static int
  2723. e1000_transfer_dhcp_info(struct e1000_adapter *adapter, struct sk_buff *skb)
  2724. {
  2725. struct e1000_hw *hw = &adapter->hw;
  2726. uint16_t length, offset;
  2727. if (vlan_tx_tag_present(skb)) {
  2728. if (!((vlan_tx_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
  2729. ( adapter->hw.mng_cookie.status &
  2730. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT)) )
  2731. return 0;
  2732. }
  2733. if (skb->len > MINIMUM_DHCP_PACKET_SIZE) {
  2734. struct ethhdr *eth = (struct ethhdr *) skb->data;
  2735. if ((htons(ETH_P_IP) == eth->h_proto)) {
  2736. const struct iphdr *ip =
  2737. (struct iphdr *)((uint8_t *)skb->data+14);
  2738. if (IPPROTO_UDP == ip->protocol) {
  2739. struct udphdr *udp =
  2740. (struct udphdr *)((uint8_t *)ip +
  2741. (ip->ihl << 2));
  2742. if (ntohs(udp->dest) == 67) {
  2743. offset = (uint8_t *)udp + 8 - skb->data;
  2744. length = skb->len - offset;
  2745. return e1000_mng_write_dhcp_info(hw,
  2746. (uint8_t *)udp + 8,
  2747. length);
  2748. }
  2749. }
  2750. }
  2751. }
  2752. return 0;
  2753. }
  2754. static int __e1000_maybe_stop_tx(struct net_device *netdev, int size)
  2755. {
  2756. struct e1000_adapter *adapter = netdev_priv(netdev);
  2757. struct e1000_tx_ring *tx_ring = adapter->tx_ring;
  2758. netif_stop_queue(netdev);
  2759. /* Herbert's original patch had:
  2760. * smp_mb__after_netif_stop_queue();
  2761. * but since that doesn't exist yet, just open code it. */
  2762. smp_mb();
  2763. /* We need to check again in a case another CPU has just
  2764. * made room available. */
  2765. if (likely(E1000_DESC_UNUSED(tx_ring) < size))
  2766. return -EBUSY;
  2767. /* A reprieve! */
  2768. netif_start_queue(netdev);
  2769. ++adapter->restart_queue;
  2770. return 0;
  2771. }
  2772. static int e1000_maybe_stop_tx(struct net_device *netdev,
  2773. struct e1000_tx_ring *tx_ring, int size)
  2774. {
  2775. if (likely(E1000_DESC_UNUSED(tx_ring) >= size))
  2776. return 0;
  2777. return __e1000_maybe_stop_tx(netdev, size);
  2778. }
  2779. #define TXD_USE_COUNT(S, X) (((S) >> (X)) + 1 )
  2780. static int
  2781. e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
  2782. {
  2783. struct e1000_adapter *adapter = netdev_priv(netdev);
  2784. struct e1000_tx_ring *tx_ring;
  2785. unsigned int first, max_per_txd = E1000_MAX_DATA_PER_TXD;
  2786. unsigned int max_txd_pwr = E1000_MAX_TXD_PWR;
  2787. unsigned int tx_flags = 0;
  2788. unsigned int len = skb->len - skb->data_len;
  2789. unsigned long flags;
  2790. unsigned int nr_frags;
  2791. unsigned int mss;
  2792. int count = 0;
  2793. int tso;
  2794. unsigned int f;
  2795. /* This goes back to the question of how to logically map a tx queue
  2796. * to a flow. Right now, performance is impacted slightly negatively
  2797. * if using multiple tx queues. If the stack breaks away from a
  2798. * single qdisc implementation, we can look at this again. */
  2799. tx_ring = adapter->tx_ring;
  2800. if (unlikely(skb->len <= 0)) {
  2801. dev_kfree_skb_any(skb);
  2802. return NETDEV_TX_OK;
  2803. }
  2804. /* 82571 and newer doesn't need the workaround that limited descriptor
  2805. * length to 4kB */
  2806. if (adapter->hw.mac_type >= e1000_82571)
  2807. max_per_txd = 8192;
  2808. mss = skb_shinfo(skb)->gso_size;
  2809. /* The controller does a simple calculation to
  2810. * make sure there is enough room in the FIFO before
  2811. * initiating the DMA for each buffer. The calc is:
  2812. * 4 = ceil(buffer len/mss). To make sure we don't
  2813. * overrun the FIFO, adjust the max buffer len if mss
  2814. * drops. */
  2815. if (mss) {
  2816. uint8_t hdr_len;
  2817. max_per_txd = min(mss << 2, max_per_txd);
  2818. max_txd_pwr = fls(max_per_txd) - 1;
  2819. /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
  2820. * points to just header, pull a few bytes of payload from
  2821. * frags into skb->data */
  2822. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  2823. if (skb->data_len && hdr_len == len) {
  2824. switch (adapter->hw.mac_type) {
  2825. unsigned int pull_size;
  2826. case e1000_82544:
  2827. /* Make sure we have room to chop off 4 bytes,
  2828. * and that the end alignment will work out to
  2829. * this hardware's requirements
  2830. * NOTE: this is a TSO only workaround
  2831. * if end byte alignment not correct move us
  2832. * into the next dword */
  2833. if ((unsigned long)(skb_tail_pointer(skb) - 1) & 4)
  2834. break;
  2835. /* fall through */
  2836. case e1000_82571:
  2837. case e1000_82572:
  2838. case e1000_82573:
  2839. case e1000_ich8lan:
  2840. pull_size = min((unsigned int)4, skb->data_len);
  2841. if (!__pskb_pull_tail(skb, pull_size)) {
  2842. DPRINTK(DRV, ERR,
  2843. "__pskb_pull_tail failed.\n");
  2844. dev_kfree_skb_any(skb);
  2845. return NETDEV_TX_OK;
  2846. }
  2847. len = skb->len - skb->data_len;
  2848. break;
  2849. default:
  2850. /* do nothing */
  2851. break;
  2852. }
  2853. }
  2854. }
  2855. /* reserve a descriptor for the offload context */
  2856. if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
  2857. count++;
  2858. count++;
  2859. /* Controller Erratum workaround */
  2860. if (!skb->data_len && tx_ring->last_tx_tso && !skb_is_gso(skb))
  2861. count++;
  2862. count += TXD_USE_COUNT(len, max_txd_pwr);
  2863. if (adapter->pcix_82544)
  2864. count++;
  2865. /* work-around for errata 10 and it applies to all controllers
  2866. * in PCI-X mode, so add one more descriptor to the count
  2867. */
  2868. if (unlikely((adapter->hw.bus_type == e1000_bus_type_pcix) &&
  2869. (len > 2015)))
  2870. count++;
  2871. nr_frags = skb_shinfo(skb)->nr_frags;
  2872. for (f = 0; f < nr_frags; f++)
  2873. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size,
  2874. max_txd_pwr);
  2875. if (adapter->pcix_82544)
  2876. count += nr_frags;
  2877. if (adapter->hw.tx_pkt_filtering &&
  2878. (adapter->hw.mac_type == e1000_82573))
  2879. e1000_transfer_dhcp_info(adapter, skb);
  2880. if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags))
  2881. /* Collision - tell upper layer to requeue */
  2882. return NETDEV_TX_LOCKED;
  2883. /* need: count + 2 desc gap to keep tail from touching
  2884. * head, otherwise try next time */
  2885. if (unlikely(e1000_maybe_stop_tx(netdev, tx_ring, count + 2))) {
  2886. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2887. return NETDEV_TX_BUSY;
  2888. }
  2889. if (unlikely(adapter->hw.mac_type == e1000_82547)) {
  2890. if (unlikely(e1000_82547_fifo_workaround(adapter, skb))) {
  2891. netif_stop_queue(netdev);
  2892. mod_timer(&adapter->tx_fifo_stall_timer, jiffies + 1);
  2893. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2894. return NETDEV_TX_BUSY;
  2895. }
  2896. }
  2897. if (unlikely(adapter->vlgrp && vlan_tx_tag_present(skb))) {
  2898. tx_flags |= E1000_TX_FLAGS_VLAN;
  2899. tx_flags |= (vlan_tx_tag_get(skb) << E1000_TX_FLAGS_VLAN_SHIFT);
  2900. }
  2901. first = tx_ring->next_to_use;
  2902. tso = e1000_tso(adapter, tx_ring, skb);
  2903. if (tso < 0) {
  2904. dev_kfree_skb_any(skb);
  2905. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2906. return NETDEV_TX_OK;
  2907. }
  2908. if (likely(tso)) {
  2909. tx_ring->last_tx_tso = 1;
  2910. tx_flags |= E1000_TX_FLAGS_TSO;
  2911. } else if (likely(e1000_tx_csum(adapter, tx_ring, skb)))
  2912. tx_flags |= E1000_TX_FLAGS_CSUM;
  2913. /* Old method was to assume IPv4 packet by default if TSO was enabled.
  2914. * 82571 hardware supports TSO capabilities for IPv6 as well...
  2915. * no longer assume, we must. */
  2916. if (likely(skb->protocol == htons(ETH_P_IP)))
  2917. tx_flags |= E1000_TX_FLAGS_IPV4;
  2918. e1000_tx_queue(adapter, tx_ring, tx_flags,
  2919. e1000_tx_map(adapter, tx_ring, skb, first,
  2920. max_per_txd, nr_frags, mss));
  2921. netdev->trans_start = jiffies;
  2922. /* Make sure there is space in the ring for the next send. */
  2923. e1000_maybe_stop_tx(netdev, tx_ring, MAX_SKB_FRAGS + 2);
  2924. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  2925. return NETDEV_TX_OK;
  2926. }
  2927. /**
  2928. * e1000_tx_timeout - Respond to a Tx Hang
  2929. * @netdev: network interface device structure
  2930. **/
  2931. static void
  2932. e1000_tx_timeout(struct net_device *netdev)
  2933. {
  2934. struct e1000_adapter *adapter = netdev_priv(netdev);
  2935. /* Do the reset outside of interrupt context */
  2936. adapter->tx_timeout_count++;
  2937. schedule_work(&adapter->reset_task);
  2938. }
  2939. static void
  2940. e1000_reset_task(struct work_struct *work)
  2941. {
  2942. struct e1000_adapter *adapter =
  2943. container_of(work, struct e1000_adapter, reset_task);
  2944. e1000_reinit_locked(adapter);
  2945. }
  2946. /**
  2947. * e1000_get_stats - Get System Network Statistics
  2948. * @netdev: network interface device structure
  2949. *
  2950. * Returns the address of the device statistics structure.
  2951. * The statistics are actually updated from the timer callback.
  2952. **/
  2953. static struct net_device_stats *
  2954. e1000_get_stats(struct net_device *netdev)
  2955. {
  2956. struct e1000_adapter *adapter = netdev_priv(netdev);
  2957. /* only return the current stats */
  2958. return &adapter->net_stats;
  2959. }
  2960. /**
  2961. * e1000_change_mtu - Change the Maximum Transfer Unit
  2962. * @netdev: network interface device structure
  2963. * @new_mtu: new value for maximum frame size
  2964. *
  2965. * Returns 0 on success, negative on failure
  2966. **/
  2967. static int
  2968. e1000_change_mtu(struct net_device *netdev, int new_mtu)
  2969. {
  2970. struct e1000_adapter *adapter = netdev_priv(netdev);
  2971. int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
  2972. uint16_t eeprom_data = 0;
  2973. if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
  2974. (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  2975. DPRINTK(PROBE, ERR, "Invalid MTU setting\n");
  2976. return -EINVAL;
  2977. }
  2978. /* Adapter-specific max frame size limits. */
  2979. switch (adapter->hw.mac_type) {
  2980. case e1000_undefined ... e1000_82542_rev2_1:
  2981. case e1000_ich8lan:
  2982. if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
  2983. DPRINTK(PROBE, ERR, "Jumbo Frames not supported.\n");
  2984. return -EINVAL;
  2985. }
  2986. break;
  2987. case e1000_82573:
  2988. /* Jumbo Frames not supported if:
  2989. * - this is not an 82573L device
  2990. * - ASPM is enabled in any way (0x1A bits 3:2) */
  2991. e1000_read_eeprom(&adapter->hw, EEPROM_INIT_3GIO_3, 1,
  2992. &eeprom_data);
  2993. if ((adapter->hw.device_id != E1000_DEV_ID_82573L) ||
  2994. (eeprom_data & EEPROM_WORD1A_ASPM_MASK)) {
  2995. if (max_frame > MAXIMUM_ETHERNET_FRAME_SIZE) {
  2996. DPRINTK(PROBE, ERR,
  2997. "Jumbo Frames not supported.\n");
  2998. return -EINVAL;
  2999. }
  3000. break;
  3001. }
  3002. /* ERT will be enabled later to enable wire speed receives */
  3003. /* fall through to get support */
  3004. case e1000_82571:
  3005. case e1000_82572:
  3006. case e1000_80003es2lan:
  3007. #define MAX_STD_JUMBO_FRAME_SIZE 9234
  3008. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  3009. DPRINTK(PROBE, ERR, "MTU > 9216 not supported.\n");
  3010. return -EINVAL;
  3011. }
  3012. break;
  3013. default:
  3014. /* Capable of supporting up to MAX_JUMBO_FRAME_SIZE limit. */
  3015. break;
  3016. }
  3017. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  3018. * means we reserve 2 more, this pushes us to allocate from the next
  3019. * larger slab size
  3020. * i.e. RXBUFFER_2048 --> size-4096 slab */
  3021. if (max_frame <= E1000_RXBUFFER_256)
  3022. adapter->rx_buffer_len = E1000_RXBUFFER_256;
  3023. else if (max_frame <= E1000_RXBUFFER_512)
  3024. adapter->rx_buffer_len = E1000_RXBUFFER_512;
  3025. else if (max_frame <= E1000_RXBUFFER_1024)
  3026. adapter->rx_buffer_len = E1000_RXBUFFER_1024;
  3027. else if (max_frame <= E1000_RXBUFFER_2048)
  3028. adapter->rx_buffer_len = E1000_RXBUFFER_2048;
  3029. else if (max_frame <= E1000_RXBUFFER_4096)
  3030. adapter->rx_buffer_len = E1000_RXBUFFER_4096;
  3031. else if (max_frame <= E1000_RXBUFFER_8192)
  3032. adapter->rx_buffer_len = E1000_RXBUFFER_8192;
  3033. else if (max_frame <= E1000_RXBUFFER_16384)
  3034. adapter->rx_buffer_len = E1000_RXBUFFER_16384;
  3035. /* adjust allocation if LPE protects us, and we aren't using SBP */
  3036. if (!adapter->hw.tbi_compatibility_on &&
  3037. ((max_frame == MAXIMUM_ETHERNET_FRAME_SIZE) ||
  3038. (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE)))
  3039. adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  3040. netdev->mtu = new_mtu;
  3041. adapter->hw.max_frame_size = max_frame;
  3042. if (netif_running(netdev))
  3043. e1000_reinit_locked(adapter);
  3044. return 0;
  3045. }
  3046. /**
  3047. * e1000_update_stats - Update the board statistics counters
  3048. * @adapter: board private structure
  3049. **/
  3050. void
  3051. e1000_update_stats(struct e1000_adapter *adapter)
  3052. {
  3053. struct e1000_hw *hw = &adapter->hw;
  3054. struct pci_dev *pdev = adapter->pdev;
  3055. unsigned long flags;
  3056. uint16_t phy_tmp;
  3057. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  3058. /*
  3059. * Prevent stats update while adapter is being reset, or if the pci
  3060. * connection is down.
  3061. */
  3062. if (adapter->link_speed == 0)
  3063. return;
  3064. if (pci_channel_offline(pdev))
  3065. return;
  3066. spin_lock_irqsave(&adapter->stats_lock, flags);
  3067. /* these counters are modified from e1000_tbi_adjust_stats,
  3068. * called from the interrupt context, so they must only
  3069. * be written while holding adapter->stats_lock
  3070. */
  3071. adapter->stats.crcerrs += E1000_READ_REG(hw, CRCERRS);
  3072. adapter->stats.gprc += E1000_READ_REG(hw, GPRC);
  3073. adapter->stats.gorcl += E1000_READ_REG(hw, GORCL);
  3074. adapter->stats.gorch += E1000_READ_REG(hw, GORCH);
  3075. adapter->stats.bprc += E1000_READ_REG(hw, BPRC);
  3076. adapter->stats.mprc += E1000_READ_REG(hw, MPRC);
  3077. adapter->stats.roc += E1000_READ_REG(hw, ROC);
  3078. if (adapter->hw.mac_type != e1000_ich8lan) {
  3079. adapter->stats.prc64 += E1000_READ_REG(hw, PRC64);
  3080. adapter->stats.prc127 += E1000_READ_REG(hw, PRC127);
  3081. adapter->stats.prc255 += E1000_READ_REG(hw, PRC255);
  3082. adapter->stats.prc511 += E1000_READ_REG(hw, PRC511);
  3083. adapter->stats.prc1023 += E1000_READ_REG(hw, PRC1023);
  3084. adapter->stats.prc1522 += E1000_READ_REG(hw, PRC1522);
  3085. }
  3086. adapter->stats.symerrs += E1000_READ_REG(hw, SYMERRS);
  3087. adapter->stats.mpc += E1000_READ_REG(hw, MPC);
  3088. adapter->stats.scc += E1000_READ_REG(hw, SCC);
  3089. adapter->stats.ecol += E1000_READ_REG(hw, ECOL);
  3090. adapter->stats.mcc += E1000_READ_REG(hw, MCC);
  3091. adapter->stats.latecol += E1000_READ_REG(hw, LATECOL);
  3092. adapter->stats.dc += E1000_READ_REG(hw, DC);
  3093. adapter->stats.sec += E1000_READ_REG(hw, SEC);
  3094. adapter->stats.rlec += E1000_READ_REG(hw, RLEC);
  3095. adapter->stats.xonrxc += E1000_READ_REG(hw, XONRXC);
  3096. adapter->stats.xontxc += E1000_READ_REG(hw, XONTXC);
  3097. adapter->stats.xoffrxc += E1000_READ_REG(hw, XOFFRXC);
  3098. adapter->stats.xofftxc += E1000_READ_REG(hw, XOFFTXC);
  3099. adapter->stats.fcruc += E1000_READ_REG(hw, FCRUC);
  3100. adapter->stats.gptc += E1000_READ_REG(hw, GPTC);
  3101. adapter->stats.gotcl += E1000_READ_REG(hw, GOTCL);
  3102. adapter->stats.gotch += E1000_READ_REG(hw, GOTCH);
  3103. adapter->stats.rnbc += E1000_READ_REG(hw, RNBC);
  3104. adapter->stats.ruc += E1000_READ_REG(hw, RUC);
  3105. adapter->stats.rfc += E1000_READ_REG(hw, RFC);
  3106. adapter->stats.rjc += E1000_READ_REG(hw, RJC);
  3107. adapter->stats.torl += E1000_READ_REG(hw, TORL);
  3108. adapter->stats.torh += E1000_READ_REG(hw, TORH);
  3109. adapter->stats.totl += E1000_READ_REG(hw, TOTL);
  3110. adapter->stats.toth += E1000_READ_REG(hw, TOTH);
  3111. adapter->stats.tpr += E1000_READ_REG(hw, TPR);
  3112. if (adapter->hw.mac_type != e1000_ich8lan) {
  3113. adapter->stats.ptc64 += E1000_READ_REG(hw, PTC64);
  3114. adapter->stats.ptc127 += E1000_READ_REG(hw, PTC127);
  3115. adapter->stats.ptc255 += E1000_READ_REG(hw, PTC255);
  3116. adapter->stats.ptc511 += E1000_READ_REG(hw, PTC511);
  3117. adapter->stats.ptc1023 += E1000_READ_REG(hw, PTC1023);
  3118. adapter->stats.ptc1522 += E1000_READ_REG(hw, PTC1522);
  3119. }
  3120. adapter->stats.mptc += E1000_READ_REG(hw, MPTC);
  3121. adapter->stats.bptc += E1000_READ_REG(hw, BPTC);
  3122. /* used for adaptive IFS */
  3123. hw->tx_packet_delta = E1000_READ_REG(hw, TPT);
  3124. adapter->stats.tpt += hw->tx_packet_delta;
  3125. hw->collision_delta = E1000_READ_REG(hw, COLC);
  3126. adapter->stats.colc += hw->collision_delta;
  3127. if (hw->mac_type >= e1000_82543) {
  3128. adapter->stats.algnerrc += E1000_READ_REG(hw, ALGNERRC);
  3129. adapter->stats.rxerrc += E1000_READ_REG(hw, RXERRC);
  3130. adapter->stats.tncrs += E1000_READ_REG(hw, TNCRS);
  3131. adapter->stats.cexterr += E1000_READ_REG(hw, CEXTERR);
  3132. adapter->stats.tsctc += E1000_READ_REG(hw, TSCTC);
  3133. adapter->stats.tsctfc += E1000_READ_REG(hw, TSCTFC);
  3134. }
  3135. if (hw->mac_type > e1000_82547_rev_2) {
  3136. adapter->stats.iac += E1000_READ_REG(hw, IAC);
  3137. adapter->stats.icrxoc += E1000_READ_REG(hw, ICRXOC);
  3138. if (adapter->hw.mac_type != e1000_ich8lan) {
  3139. adapter->stats.icrxptc += E1000_READ_REG(hw, ICRXPTC);
  3140. adapter->stats.icrxatc += E1000_READ_REG(hw, ICRXATC);
  3141. adapter->stats.ictxptc += E1000_READ_REG(hw, ICTXPTC);
  3142. adapter->stats.ictxatc += E1000_READ_REG(hw, ICTXATC);
  3143. adapter->stats.ictxqec += E1000_READ_REG(hw, ICTXQEC);
  3144. adapter->stats.ictxqmtc += E1000_READ_REG(hw, ICTXQMTC);
  3145. adapter->stats.icrxdmtc += E1000_READ_REG(hw, ICRXDMTC);
  3146. }
  3147. }
  3148. /* Fill out the OS statistics structure */
  3149. adapter->net_stats.rx_packets = adapter->stats.gprc;
  3150. adapter->net_stats.tx_packets = adapter->stats.gptc;
  3151. adapter->net_stats.rx_bytes = adapter->stats.gorcl;
  3152. adapter->net_stats.tx_bytes = adapter->stats.gotcl;
  3153. adapter->net_stats.multicast = adapter->stats.mprc;
  3154. adapter->net_stats.collisions = adapter->stats.colc;
  3155. /* Rx Errors */
  3156. /* RLEC on some newer hardware can be incorrect so build
  3157. * our own version based on RUC and ROC */
  3158. adapter->net_stats.rx_errors = adapter->stats.rxerrc +
  3159. adapter->stats.crcerrs + adapter->stats.algnerrc +
  3160. adapter->stats.ruc + adapter->stats.roc +
  3161. adapter->stats.cexterr;
  3162. adapter->stats.rlerrc = adapter->stats.ruc + adapter->stats.roc;
  3163. adapter->net_stats.rx_length_errors = adapter->stats.rlerrc;
  3164. adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs;
  3165. adapter->net_stats.rx_frame_errors = adapter->stats.algnerrc;
  3166. adapter->net_stats.rx_missed_errors = adapter->stats.mpc;
  3167. /* Tx Errors */
  3168. adapter->stats.txerrc = adapter->stats.ecol + adapter->stats.latecol;
  3169. adapter->net_stats.tx_errors = adapter->stats.txerrc;
  3170. adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
  3171. adapter->net_stats.tx_window_errors = adapter->stats.latecol;
  3172. adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
  3173. if (adapter->hw.bad_tx_carr_stats_fd &&
  3174. adapter->link_duplex == FULL_DUPLEX) {
  3175. adapter->net_stats.tx_carrier_errors = 0;
  3176. adapter->stats.tncrs = 0;
  3177. }
  3178. /* Tx Dropped needs to be maintained elsewhere */
  3179. /* Phy Stats */
  3180. if (hw->media_type == e1000_media_type_copper) {
  3181. if ((adapter->link_speed == SPEED_1000) &&
  3182. (!e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
  3183. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  3184. adapter->phy_stats.idle_errors += phy_tmp;
  3185. }
  3186. if ((hw->mac_type <= e1000_82546) &&
  3187. (hw->phy_type == e1000_phy_m88) &&
  3188. !e1000_read_phy_reg(hw, M88E1000_RX_ERR_CNTR, &phy_tmp))
  3189. adapter->phy_stats.receive_errors += phy_tmp;
  3190. }
  3191. /* Management Stats */
  3192. if (adapter->hw.has_smbus) {
  3193. adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
  3194. adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
  3195. adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
  3196. }
  3197. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  3198. }
  3199. /**
  3200. * e1000_intr_msi - Interrupt Handler
  3201. * @irq: interrupt number
  3202. * @data: pointer to a network interface device structure
  3203. **/
  3204. static irqreturn_t
  3205. e1000_intr_msi(int irq, void *data)
  3206. {
  3207. struct net_device *netdev = data;
  3208. struct e1000_adapter *adapter = netdev_priv(netdev);
  3209. struct e1000_hw *hw = &adapter->hw;
  3210. #ifndef CONFIG_E1000_NAPI
  3211. int i;
  3212. #endif
  3213. uint32_t icr = E1000_READ_REG(hw, ICR);
  3214. #ifdef CONFIG_E1000_NAPI
  3215. /* read ICR disables interrupts using IAM, so keep up with our
  3216. * enable/disable accounting */
  3217. atomic_inc(&adapter->irq_sem);
  3218. #endif
  3219. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  3220. hw->get_link_status = 1;
  3221. /* 80003ES2LAN workaround-- For packet buffer work-around on
  3222. * link down event; disable receives here in the ISR and reset
  3223. * adapter in watchdog */
  3224. if (netif_carrier_ok(netdev) &&
  3225. (adapter->hw.mac_type == e1000_80003es2lan)) {
  3226. /* disable receives */
  3227. uint32_t rctl = E1000_READ_REG(hw, RCTL);
  3228. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  3229. }
  3230. /* guard against interrupt when we're going down */
  3231. if (!test_bit(__E1000_DOWN, &adapter->flags))
  3232. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  3233. }
  3234. #ifdef CONFIG_E1000_NAPI
  3235. if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
  3236. adapter->total_tx_bytes = 0;
  3237. adapter->total_tx_packets = 0;
  3238. adapter->total_rx_bytes = 0;
  3239. adapter->total_rx_packets = 0;
  3240. __netif_rx_schedule(netdev, &adapter->napi);
  3241. } else
  3242. e1000_irq_enable(adapter);
  3243. #else
  3244. adapter->total_tx_bytes = 0;
  3245. adapter->total_rx_bytes = 0;
  3246. adapter->total_tx_packets = 0;
  3247. adapter->total_rx_packets = 0;
  3248. for (i = 0; i < E1000_MAX_INTR; i++)
  3249. if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
  3250. !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
  3251. break;
  3252. if (likely(adapter->itr_setting & 3))
  3253. e1000_set_itr(adapter);
  3254. #endif
  3255. return IRQ_HANDLED;
  3256. }
  3257. /**
  3258. * e1000_intr - Interrupt Handler
  3259. * @irq: interrupt number
  3260. * @data: pointer to a network interface device structure
  3261. **/
  3262. static irqreturn_t
  3263. e1000_intr(int irq, void *data)
  3264. {
  3265. struct net_device *netdev = data;
  3266. struct e1000_adapter *adapter = netdev_priv(netdev);
  3267. struct e1000_hw *hw = &adapter->hw;
  3268. uint32_t rctl, icr = E1000_READ_REG(hw, ICR);
  3269. #ifndef CONFIG_E1000_NAPI
  3270. int i;
  3271. #endif
  3272. if (unlikely(!icr))
  3273. return IRQ_NONE; /* Not our interrupt */
  3274. #ifdef CONFIG_E1000_NAPI
  3275. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  3276. * not set, then the adapter didn't send an interrupt */
  3277. if (unlikely(hw->mac_type >= e1000_82571 &&
  3278. !(icr & E1000_ICR_INT_ASSERTED)))
  3279. return IRQ_NONE;
  3280. /* Interrupt Auto-Mask...upon reading ICR,
  3281. * interrupts are masked. No need for the
  3282. * IMC write, but it does mean we should
  3283. * account for it ASAP. */
  3284. if (likely(hw->mac_type >= e1000_82571))
  3285. atomic_inc(&adapter->irq_sem);
  3286. #endif
  3287. if (unlikely(icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC))) {
  3288. hw->get_link_status = 1;
  3289. /* 80003ES2LAN workaround--
  3290. * For packet buffer work-around on link down event;
  3291. * disable receives here in the ISR and
  3292. * reset adapter in watchdog
  3293. */
  3294. if (netif_carrier_ok(netdev) &&
  3295. (adapter->hw.mac_type == e1000_80003es2lan)) {
  3296. /* disable receives */
  3297. rctl = E1000_READ_REG(hw, RCTL);
  3298. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  3299. }
  3300. /* guard against interrupt when we're going down */
  3301. if (!test_bit(__E1000_DOWN, &adapter->flags))
  3302. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  3303. }
  3304. #ifdef CONFIG_E1000_NAPI
  3305. if (unlikely(hw->mac_type < e1000_82571)) {
  3306. /* disable interrupts, without the synchronize_irq bit */
  3307. atomic_inc(&adapter->irq_sem);
  3308. E1000_WRITE_REG(hw, IMC, ~0);
  3309. E1000_WRITE_FLUSH(hw);
  3310. }
  3311. if (likely(netif_rx_schedule_prep(netdev, &adapter->napi))) {
  3312. adapter->total_tx_bytes = 0;
  3313. adapter->total_tx_packets = 0;
  3314. adapter->total_rx_bytes = 0;
  3315. adapter->total_rx_packets = 0;
  3316. __netif_rx_schedule(netdev, &adapter->napi);
  3317. } else
  3318. /* this really should not happen! if it does it is basically a
  3319. * bug, but not a hard error, so enable ints and continue */
  3320. e1000_irq_enable(adapter);
  3321. #else
  3322. /* Writing IMC and IMS is needed for 82547.
  3323. * Due to Hub Link bus being occupied, an interrupt
  3324. * de-assertion message is not able to be sent.
  3325. * When an interrupt assertion message is generated later,
  3326. * two messages are re-ordered and sent out.
  3327. * That causes APIC to think 82547 is in de-assertion
  3328. * state, while 82547 is in assertion state, resulting
  3329. * in dead lock. Writing IMC forces 82547 into
  3330. * de-assertion state.
  3331. */
  3332. if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2) {
  3333. atomic_inc(&adapter->irq_sem);
  3334. E1000_WRITE_REG(hw, IMC, ~0);
  3335. }
  3336. adapter->total_tx_bytes = 0;
  3337. adapter->total_rx_bytes = 0;
  3338. adapter->total_tx_packets = 0;
  3339. adapter->total_rx_packets = 0;
  3340. for (i = 0; i < E1000_MAX_INTR; i++)
  3341. if (unlikely(!adapter->clean_rx(adapter, adapter->rx_ring) &
  3342. !e1000_clean_tx_irq(adapter, adapter->tx_ring)))
  3343. break;
  3344. if (likely(adapter->itr_setting & 3))
  3345. e1000_set_itr(adapter);
  3346. if (hw->mac_type == e1000_82547 || hw->mac_type == e1000_82547_rev_2)
  3347. e1000_irq_enable(adapter);
  3348. #endif
  3349. return IRQ_HANDLED;
  3350. }
  3351. #ifdef CONFIG_E1000_NAPI
  3352. /**
  3353. * e1000_clean - NAPI Rx polling callback
  3354. * @adapter: board private structure
  3355. **/
  3356. static int
  3357. e1000_clean(struct napi_struct *napi, int budget)
  3358. {
  3359. struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter, napi);
  3360. struct net_device *poll_dev = adapter->netdev;
  3361. int tx_cleaned = 0, work_done = 0;
  3362. /* Must NOT use netdev_priv macro here. */
  3363. adapter = poll_dev->priv;
  3364. /* Keep link state information with original netdev */
  3365. if (!netif_carrier_ok(poll_dev))
  3366. goto quit_polling;
  3367. /* e1000_clean is called per-cpu. This lock protects
  3368. * tx_ring[0] from being cleaned by multiple cpus
  3369. * simultaneously. A failure obtaining the lock means
  3370. * tx_ring[0] is currently being cleaned anyway. */
  3371. if (spin_trylock(&adapter->tx_queue_lock)) {
  3372. tx_cleaned = e1000_clean_tx_irq(adapter,
  3373. &adapter->tx_ring[0]);
  3374. spin_unlock(&adapter->tx_queue_lock);
  3375. }
  3376. adapter->clean_rx(adapter, &adapter->rx_ring[0],
  3377. &work_done, budget);
  3378. /* If no Tx and not enough Rx work done, exit the polling mode */
  3379. if ((!tx_cleaned && (work_done < budget)) ||
  3380. !netif_running(poll_dev)) {
  3381. quit_polling:
  3382. if (likely(adapter->itr_setting & 3))
  3383. e1000_set_itr(adapter);
  3384. netif_rx_complete(poll_dev, napi);
  3385. e1000_irq_enable(adapter);
  3386. }
  3387. return work_done;
  3388. }
  3389. #endif
  3390. /**
  3391. * e1000_clean_tx_irq - Reclaim resources after transmit completes
  3392. * @adapter: board private structure
  3393. **/
  3394. static boolean_t
  3395. e1000_clean_tx_irq(struct e1000_adapter *adapter,
  3396. struct e1000_tx_ring *tx_ring)
  3397. {
  3398. struct net_device *netdev = adapter->netdev;
  3399. struct e1000_tx_desc *tx_desc, *eop_desc;
  3400. struct e1000_buffer *buffer_info;
  3401. unsigned int i, eop;
  3402. #ifdef CONFIG_E1000_NAPI
  3403. unsigned int count = 0;
  3404. #endif
  3405. boolean_t cleaned = FALSE;
  3406. unsigned int total_tx_bytes=0, total_tx_packets=0;
  3407. i = tx_ring->next_to_clean;
  3408. eop = tx_ring->buffer_info[i].next_to_watch;
  3409. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  3410. while (eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) {
  3411. for (cleaned = FALSE; !cleaned; ) {
  3412. tx_desc = E1000_TX_DESC(*tx_ring, i);
  3413. buffer_info = &tx_ring->buffer_info[i];
  3414. cleaned = (i == eop);
  3415. if (cleaned) {
  3416. struct sk_buff *skb = buffer_info->skb;
  3417. unsigned int segs, bytecount;
  3418. segs = skb_shinfo(skb)->gso_segs ?: 1;
  3419. /* multiply data chunks by size of headers */
  3420. bytecount = ((segs - 1) * skb_headlen(skb)) +
  3421. skb->len;
  3422. total_tx_packets += segs;
  3423. total_tx_bytes += bytecount;
  3424. }
  3425. e1000_unmap_and_free_tx_resource(adapter, buffer_info);
  3426. tx_desc->upper.data = 0;
  3427. if (unlikely(++i == tx_ring->count)) i = 0;
  3428. }
  3429. eop = tx_ring->buffer_info[i].next_to_watch;
  3430. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  3431. #ifdef CONFIG_E1000_NAPI
  3432. #define E1000_TX_WEIGHT 64
  3433. /* weight of a sort for tx, to avoid endless transmit cleanup */
  3434. if (count++ == E1000_TX_WEIGHT) break;
  3435. #endif
  3436. }
  3437. tx_ring->next_to_clean = i;
  3438. #define TX_WAKE_THRESHOLD 32
  3439. if (unlikely(cleaned && netif_carrier_ok(netdev) &&
  3440. E1000_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD)) {
  3441. /* Make sure that anybody stopping the queue after this
  3442. * sees the new next_to_clean.
  3443. */
  3444. smp_mb();
  3445. if (netif_queue_stopped(netdev)) {
  3446. netif_wake_queue(netdev);
  3447. ++adapter->restart_queue;
  3448. }
  3449. }
  3450. if (adapter->detect_tx_hung) {
  3451. /* Detect a transmit hang in hardware, this serializes the
  3452. * check with the clearing of time_stamp and movement of i */
  3453. adapter->detect_tx_hung = FALSE;
  3454. if (tx_ring->buffer_info[eop].dma &&
  3455. time_after(jiffies, tx_ring->buffer_info[eop].time_stamp +
  3456. (adapter->tx_timeout_factor * HZ))
  3457. && !(E1000_READ_REG(&adapter->hw, STATUS) &
  3458. E1000_STATUS_TXOFF)) {
  3459. /* detected Tx unit hang */
  3460. DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n"
  3461. " Tx Queue <%lu>\n"
  3462. " TDH <%x>\n"
  3463. " TDT <%x>\n"
  3464. " next_to_use <%x>\n"
  3465. " next_to_clean <%x>\n"
  3466. "buffer_info[next_to_clean]\n"
  3467. " time_stamp <%lx>\n"
  3468. " next_to_watch <%x>\n"
  3469. " jiffies <%lx>\n"
  3470. " next_to_watch.status <%x>\n",
  3471. (unsigned long)((tx_ring - adapter->tx_ring) /
  3472. sizeof(struct e1000_tx_ring)),
  3473. readl(adapter->hw.hw_addr + tx_ring->tdh),
  3474. readl(adapter->hw.hw_addr + tx_ring->tdt),
  3475. tx_ring->next_to_use,
  3476. tx_ring->next_to_clean,
  3477. tx_ring->buffer_info[eop].time_stamp,
  3478. eop,
  3479. jiffies,
  3480. eop_desc->upper.fields.status);
  3481. netif_stop_queue(netdev);
  3482. }
  3483. }
  3484. adapter->total_tx_bytes += total_tx_bytes;
  3485. adapter->total_tx_packets += total_tx_packets;
  3486. return cleaned;
  3487. }
  3488. /**
  3489. * e1000_rx_checksum - Receive Checksum Offload for 82543
  3490. * @adapter: board private structure
  3491. * @status_err: receive descriptor status and error fields
  3492. * @csum: receive descriptor csum field
  3493. * @sk_buff: socket buffer with received data
  3494. **/
  3495. static void
  3496. e1000_rx_checksum(struct e1000_adapter *adapter,
  3497. uint32_t status_err, uint32_t csum,
  3498. struct sk_buff *skb)
  3499. {
  3500. uint16_t status = (uint16_t)status_err;
  3501. uint8_t errors = (uint8_t)(status_err >> 24);
  3502. skb->ip_summed = CHECKSUM_NONE;
  3503. /* 82543 or newer only */
  3504. if (unlikely(adapter->hw.mac_type < e1000_82543)) return;
  3505. /* Ignore Checksum bit is set */
  3506. if (unlikely(status & E1000_RXD_STAT_IXSM)) return;
  3507. /* TCP/UDP checksum error bit is set */
  3508. if (unlikely(errors & E1000_RXD_ERR_TCPE)) {
  3509. /* let the stack verify checksum errors */
  3510. adapter->hw_csum_err++;
  3511. return;
  3512. }
  3513. /* TCP/UDP Checksum has not been calculated */
  3514. if (adapter->hw.mac_type <= e1000_82547_rev_2) {
  3515. if (!(status & E1000_RXD_STAT_TCPCS))
  3516. return;
  3517. } else {
  3518. if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
  3519. return;
  3520. }
  3521. /* It must be a TCP or UDP packet with a valid checksum */
  3522. if (likely(status & E1000_RXD_STAT_TCPCS)) {
  3523. /* TCP checksum is good */
  3524. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3525. } else if (adapter->hw.mac_type > e1000_82547_rev_2) {
  3526. /* IP fragment with UDP payload */
  3527. /* Hardware complements the payload checksum, so we undo it
  3528. * and then put the value in host order for further stack use.
  3529. */
  3530. csum = ntohl(csum ^ 0xFFFF);
  3531. skb->csum = csum;
  3532. skb->ip_summed = CHECKSUM_COMPLETE;
  3533. }
  3534. adapter->hw_csum_good++;
  3535. }
  3536. /**
  3537. * e1000_clean_rx_irq - Send received data up the network stack; legacy
  3538. * @adapter: board private structure
  3539. **/
  3540. static boolean_t
  3541. #ifdef CONFIG_E1000_NAPI
  3542. e1000_clean_rx_irq(struct e1000_adapter *adapter,
  3543. struct e1000_rx_ring *rx_ring,
  3544. int *work_done, int work_to_do)
  3545. #else
  3546. e1000_clean_rx_irq(struct e1000_adapter *adapter,
  3547. struct e1000_rx_ring *rx_ring)
  3548. #endif
  3549. {
  3550. struct net_device *netdev = adapter->netdev;
  3551. struct pci_dev *pdev = adapter->pdev;
  3552. struct e1000_rx_desc *rx_desc, *next_rxd;
  3553. struct e1000_buffer *buffer_info, *next_buffer;
  3554. unsigned long flags;
  3555. uint32_t length;
  3556. uint8_t last_byte;
  3557. unsigned int i;
  3558. int cleaned_count = 0;
  3559. boolean_t cleaned = FALSE;
  3560. unsigned int total_rx_bytes=0, total_rx_packets=0;
  3561. i = rx_ring->next_to_clean;
  3562. rx_desc = E1000_RX_DESC(*rx_ring, i);
  3563. buffer_info = &rx_ring->buffer_info[i];
  3564. while (rx_desc->status & E1000_RXD_STAT_DD) {
  3565. struct sk_buff *skb;
  3566. u8 status;
  3567. #ifdef CONFIG_E1000_NAPI
  3568. if (*work_done >= work_to_do)
  3569. break;
  3570. (*work_done)++;
  3571. #endif
  3572. status = rx_desc->status;
  3573. skb = buffer_info->skb;
  3574. buffer_info->skb = NULL;
  3575. prefetch(skb->data - NET_IP_ALIGN);
  3576. if (++i == rx_ring->count) i = 0;
  3577. next_rxd = E1000_RX_DESC(*rx_ring, i);
  3578. prefetch(next_rxd);
  3579. next_buffer = &rx_ring->buffer_info[i];
  3580. cleaned = TRUE;
  3581. cleaned_count++;
  3582. pci_unmap_single(pdev,
  3583. buffer_info->dma,
  3584. buffer_info->length,
  3585. PCI_DMA_FROMDEVICE);
  3586. length = le16_to_cpu(rx_desc->length);
  3587. if (unlikely(!(status & E1000_RXD_STAT_EOP))) {
  3588. /* All receives must fit into a single buffer */
  3589. E1000_DBG("%s: Receive packet consumed multiple"
  3590. " buffers\n", netdev->name);
  3591. /* recycle */
  3592. buffer_info->skb = skb;
  3593. goto next_desc;
  3594. }
  3595. if (unlikely(rx_desc->errors & E1000_RXD_ERR_FRAME_ERR_MASK)) {
  3596. last_byte = *(skb->data + length - 1);
  3597. if (TBI_ACCEPT(&adapter->hw, status,
  3598. rx_desc->errors, length, last_byte)) {
  3599. spin_lock_irqsave(&adapter->stats_lock, flags);
  3600. e1000_tbi_adjust_stats(&adapter->hw,
  3601. &adapter->stats,
  3602. length, skb->data);
  3603. spin_unlock_irqrestore(&adapter->stats_lock,
  3604. flags);
  3605. length--;
  3606. } else {
  3607. /* recycle */
  3608. buffer_info->skb = skb;
  3609. goto next_desc;
  3610. }
  3611. }
  3612. /* adjust length to remove Ethernet CRC, this must be
  3613. * done after the TBI_ACCEPT workaround above */
  3614. length -= 4;
  3615. /* probably a little skewed due to removing CRC */
  3616. total_rx_bytes += length;
  3617. total_rx_packets++;
  3618. /* code added for copybreak, this should improve
  3619. * performance for small packets with large amounts
  3620. * of reassembly being done in the stack */
  3621. if (length < copybreak) {
  3622. struct sk_buff *new_skb =
  3623. netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
  3624. if (new_skb) {
  3625. skb_reserve(new_skb, NET_IP_ALIGN);
  3626. skb_copy_to_linear_data_offset(new_skb,
  3627. -NET_IP_ALIGN,
  3628. (skb->data -
  3629. NET_IP_ALIGN),
  3630. (length +
  3631. NET_IP_ALIGN));
  3632. /* save the skb in buffer_info as good */
  3633. buffer_info->skb = skb;
  3634. skb = new_skb;
  3635. }
  3636. /* else just continue with the old one */
  3637. }
  3638. /* end copybreak code */
  3639. skb_put(skb, length);
  3640. /* Receive Checksum Offload */
  3641. e1000_rx_checksum(adapter,
  3642. (uint32_t)(status) |
  3643. ((uint32_t)(rx_desc->errors) << 24),
  3644. le16_to_cpu(rx_desc->csum), skb);
  3645. skb->protocol = eth_type_trans(skb, netdev);
  3646. #ifdef CONFIG_E1000_NAPI
  3647. if (unlikely(adapter->vlgrp &&
  3648. (status & E1000_RXD_STAT_VP))) {
  3649. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  3650. le16_to_cpu(rx_desc->special) &
  3651. E1000_RXD_SPC_VLAN_MASK);
  3652. } else {
  3653. netif_receive_skb(skb);
  3654. }
  3655. #else /* CONFIG_E1000_NAPI */
  3656. if (unlikely(adapter->vlgrp &&
  3657. (status & E1000_RXD_STAT_VP))) {
  3658. vlan_hwaccel_rx(skb, adapter->vlgrp,
  3659. le16_to_cpu(rx_desc->special) &
  3660. E1000_RXD_SPC_VLAN_MASK);
  3661. } else {
  3662. netif_rx(skb);
  3663. }
  3664. #endif /* CONFIG_E1000_NAPI */
  3665. netdev->last_rx = jiffies;
  3666. next_desc:
  3667. rx_desc->status = 0;
  3668. /* return some buffers to hardware, one at a time is too slow */
  3669. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  3670. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3671. cleaned_count = 0;
  3672. }
  3673. /* use prefetched values */
  3674. rx_desc = next_rxd;
  3675. buffer_info = next_buffer;
  3676. }
  3677. rx_ring->next_to_clean = i;
  3678. cleaned_count = E1000_DESC_UNUSED(rx_ring);
  3679. if (cleaned_count)
  3680. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3681. adapter->total_rx_packets += total_rx_packets;
  3682. adapter->total_rx_bytes += total_rx_bytes;
  3683. return cleaned;
  3684. }
  3685. /**
  3686. * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
  3687. * @adapter: board private structure
  3688. **/
  3689. static boolean_t
  3690. #ifdef CONFIG_E1000_NAPI
  3691. e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  3692. struct e1000_rx_ring *rx_ring,
  3693. int *work_done, int work_to_do)
  3694. #else
  3695. e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
  3696. struct e1000_rx_ring *rx_ring)
  3697. #endif
  3698. {
  3699. union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
  3700. struct net_device *netdev = adapter->netdev;
  3701. struct pci_dev *pdev = adapter->pdev;
  3702. struct e1000_buffer *buffer_info, *next_buffer;
  3703. struct e1000_ps_page *ps_page;
  3704. struct e1000_ps_page_dma *ps_page_dma;
  3705. struct sk_buff *skb;
  3706. unsigned int i, j;
  3707. uint32_t length, staterr;
  3708. int cleaned_count = 0;
  3709. boolean_t cleaned = FALSE;
  3710. unsigned int total_rx_bytes=0, total_rx_packets=0;
  3711. i = rx_ring->next_to_clean;
  3712. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  3713. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  3714. buffer_info = &rx_ring->buffer_info[i];
  3715. while (staterr & E1000_RXD_STAT_DD) {
  3716. ps_page = &rx_ring->ps_page[i];
  3717. ps_page_dma = &rx_ring->ps_page_dma[i];
  3718. #ifdef CONFIG_E1000_NAPI
  3719. if (unlikely(*work_done >= work_to_do))
  3720. break;
  3721. (*work_done)++;
  3722. #endif
  3723. skb = buffer_info->skb;
  3724. /* in the packet split case this is header only */
  3725. prefetch(skb->data - NET_IP_ALIGN);
  3726. if (++i == rx_ring->count) i = 0;
  3727. next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
  3728. prefetch(next_rxd);
  3729. next_buffer = &rx_ring->buffer_info[i];
  3730. cleaned = TRUE;
  3731. cleaned_count++;
  3732. pci_unmap_single(pdev, buffer_info->dma,
  3733. buffer_info->length,
  3734. PCI_DMA_FROMDEVICE);
  3735. if (unlikely(!(staterr & E1000_RXD_STAT_EOP))) {
  3736. E1000_DBG("%s: Packet Split buffers didn't pick up"
  3737. " the full packet\n", netdev->name);
  3738. dev_kfree_skb_irq(skb);
  3739. goto next_desc;
  3740. }
  3741. if (unlikely(staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK)) {
  3742. dev_kfree_skb_irq(skb);
  3743. goto next_desc;
  3744. }
  3745. length = le16_to_cpu(rx_desc->wb.middle.length0);
  3746. if (unlikely(!length)) {
  3747. E1000_DBG("%s: Last part of the packet spanning"
  3748. " multiple descriptors\n", netdev->name);
  3749. dev_kfree_skb_irq(skb);
  3750. goto next_desc;
  3751. }
  3752. /* Good Receive */
  3753. skb_put(skb, length);
  3754. {
  3755. /* this looks ugly, but it seems compiler issues make it
  3756. more efficient than reusing j */
  3757. int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
  3758. /* page alloc/put takes too long and effects small packet
  3759. * throughput, so unsplit small packets and save the alloc/put*/
  3760. if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
  3761. u8 *vaddr;
  3762. /* there is no documentation about how to call
  3763. * kmap_atomic, so we can't hold the mapping
  3764. * very long */
  3765. pci_dma_sync_single_for_cpu(pdev,
  3766. ps_page_dma->ps_page_dma[0],
  3767. PAGE_SIZE,
  3768. PCI_DMA_FROMDEVICE);
  3769. vaddr = kmap_atomic(ps_page->ps_page[0],
  3770. KM_SKB_DATA_SOFTIRQ);
  3771. memcpy(skb_tail_pointer(skb), vaddr, l1);
  3772. kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
  3773. pci_dma_sync_single_for_device(pdev,
  3774. ps_page_dma->ps_page_dma[0],
  3775. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  3776. /* remove the CRC */
  3777. l1 -= 4;
  3778. skb_put(skb, l1);
  3779. goto copydone;
  3780. } /* if */
  3781. }
  3782. for (j = 0; j < adapter->rx_ps_pages; j++) {
  3783. if (!(length= le16_to_cpu(rx_desc->wb.upper.length[j])))
  3784. break;
  3785. pci_unmap_page(pdev, ps_page_dma->ps_page_dma[j],
  3786. PAGE_SIZE, PCI_DMA_FROMDEVICE);
  3787. ps_page_dma->ps_page_dma[j] = 0;
  3788. skb_fill_page_desc(skb, j, ps_page->ps_page[j], 0,
  3789. length);
  3790. ps_page->ps_page[j] = NULL;
  3791. skb->len += length;
  3792. skb->data_len += length;
  3793. skb->truesize += length;
  3794. }
  3795. /* strip the ethernet crc, problem is we're using pages now so
  3796. * this whole operation can get a little cpu intensive */
  3797. pskb_trim(skb, skb->len - 4);
  3798. copydone:
  3799. total_rx_bytes += skb->len;
  3800. total_rx_packets++;
  3801. e1000_rx_checksum(adapter, staterr,
  3802. le16_to_cpu(rx_desc->wb.lower.hi_dword.csum_ip.csum), skb);
  3803. skb->protocol = eth_type_trans(skb, netdev);
  3804. if (likely(rx_desc->wb.upper.header_status &
  3805. cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP)))
  3806. adapter->rx_hdr_split++;
  3807. #ifdef CONFIG_E1000_NAPI
  3808. if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
  3809. vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
  3810. le16_to_cpu(rx_desc->wb.middle.vlan) &
  3811. E1000_RXD_SPC_VLAN_MASK);
  3812. } else {
  3813. netif_receive_skb(skb);
  3814. }
  3815. #else /* CONFIG_E1000_NAPI */
  3816. if (unlikely(adapter->vlgrp && (staterr & E1000_RXD_STAT_VP))) {
  3817. vlan_hwaccel_rx(skb, adapter->vlgrp,
  3818. le16_to_cpu(rx_desc->wb.middle.vlan) &
  3819. E1000_RXD_SPC_VLAN_MASK);
  3820. } else {
  3821. netif_rx(skb);
  3822. }
  3823. #endif /* CONFIG_E1000_NAPI */
  3824. netdev->last_rx = jiffies;
  3825. next_desc:
  3826. rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
  3827. buffer_info->skb = NULL;
  3828. /* return some buffers to hardware, one at a time is too slow */
  3829. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  3830. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3831. cleaned_count = 0;
  3832. }
  3833. /* use prefetched values */
  3834. rx_desc = next_rxd;
  3835. buffer_info = next_buffer;
  3836. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  3837. }
  3838. rx_ring->next_to_clean = i;
  3839. cleaned_count = E1000_DESC_UNUSED(rx_ring);
  3840. if (cleaned_count)
  3841. adapter->alloc_rx_buf(adapter, rx_ring, cleaned_count);
  3842. adapter->total_rx_packets += total_rx_packets;
  3843. adapter->total_rx_bytes += total_rx_bytes;
  3844. return cleaned;
  3845. }
  3846. /**
  3847. * e1000_alloc_rx_buffers - Replace used receive buffers; legacy & extended
  3848. * @adapter: address of board private structure
  3849. **/
  3850. static void
  3851. e1000_alloc_rx_buffers(struct e1000_adapter *adapter,
  3852. struct e1000_rx_ring *rx_ring,
  3853. int cleaned_count)
  3854. {
  3855. struct net_device *netdev = adapter->netdev;
  3856. struct pci_dev *pdev = adapter->pdev;
  3857. struct e1000_rx_desc *rx_desc;
  3858. struct e1000_buffer *buffer_info;
  3859. struct sk_buff *skb;
  3860. unsigned int i;
  3861. unsigned int bufsz = adapter->rx_buffer_len + NET_IP_ALIGN;
  3862. i = rx_ring->next_to_use;
  3863. buffer_info = &rx_ring->buffer_info[i];
  3864. while (cleaned_count--) {
  3865. skb = buffer_info->skb;
  3866. if (skb) {
  3867. skb_trim(skb, 0);
  3868. goto map_skb;
  3869. }
  3870. skb = netdev_alloc_skb(netdev, bufsz);
  3871. if (unlikely(!skb)) {
  3872. /* Better luck next round */
  3873. adapter->alloc_rx_buff_failed++;
  3874. break;
  3875. }
  3876. /* Fix for errata 23, can't cross 64kB boundary */
  3877. if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
  3878. struct sk_buff *oldskb = skb;
  3879. DPRINTK(RX_ERR, ERR, "skb align check failed: %u bytes "
  3880. "at %p\n", bufsz, skb->data);
  3881. /* Try again, without freeing the previous */
  3882. skb = netdev_alloc_skb(netdev, bufsz);
  3883. /* Failed allocation, critical failure */
  3884. if (!skb) {
  3885. dev_kfree_skb(oldskb);
  3886. break;
  3887. }
  3888. if (!e1000_check_64k_bound(adapter, skb->data, bufsz)) {
  3889. /* give up */
  3890. dev_kfree_skb(skb);
  3891. dev_kfree_skb(oldskb);
  3892. break; /* while !buffer_info->skb */
  3893. }
  3894. /* Use new allocation */
  3895. dev_kfree_skb(oldskb);
  3896. }
  3897. /* Make buffer alignment 2 beyond a 16 byte boundary
  3898. * this will result in a 16 byte aligned IP header after
  3899. * the 14 byte MAC header is removed
  3900. */
  3901. skb_reserve(skb, NET_IP_ALIGN);
  3902. buffer_info->skb = skb;
  3903. buffer_info->length = adapter->rx_buffer_len;
  3904. map_skb:
  3905. buffer_info->dma = pci_map_single(pdev,
  3906. skb->data,
  3907. adapter->rx_buffer_len,
  3908. PCI_DMA_FROMDEVICE);
  3909. /* Fix for errata 23, can't cross 64kB boundary */
  3910. if (!e1000_check_64k_bound(adapter,
  3911. (void *)(unsigned long)buffer_info->dma,
  3912. adapter->rx_buffer_len)) {
  3913. DPRINTK(RX_ERR, ERR,
  3914. "dma align check failed: %u bytes at %p\n",
  3915. adapter->rx_buffer_len,
  3916. (void *)(unsigned long)buffer_info->dma);
  3917. dev_kfree_skb(skb);
  3918. buffer_info->skb = NULL;
  3919. pci_unmap_single(pdev, buffer_info->dma,
  3920. adapter->rx_buffer_len,
  3921. PCI_DMA_FROMDEVICE);
  3922. break; /* while !buffer_info->skb */
  3923. }
  3924. rx_desc = E1000_RX_DESC(*rx_ring, i);
  3925. rx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  3926. if (unlikely(++i == rx_ring->count))
  3927. i = 0;
  3928. buffer_info = &rx_ring->buffer_info[i];
  3929. }
  3930. if (likely(rx_ring->next_to_use != i)) {
  3931. rx_ring->next_to_use = i;
  3932. if (unlikely(i-- == 0))
  3933. i = (rx_ring->count - 1);
  3934. /* Force memory writes to complete before letting h/w
  3935. * know there are new descriptors to fetch. (Only
  3936. * applicable for weak-ordered memory model archs,
  3937. * such as IA-64). */
  3938. wmb();
  3939. writel(i, adapter->hw.hw_addr + rx_ring->rdt);
  3940. }
  3941. }
  3942. /**
  3943. * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
  3944. * @adapter: address of board private structure
  3945. **/
  3946. static void
  3947. e1000_alloc_rx_buffers_ps(struct e1000_adapter *adapter,
  3948. struct e1000_rx_ring *rx_ring,
  3949. int cleaned_count)
  3950. {
  3951. struct net_device *netdev = adapter->netdev;
  3952. struct pci_dev *pdev = adapter->pdev;
  3953. union e1000_rx_desc_packet_split *rx_desc;
  3954. struct e1000_buffer *buffer_info;
  3955. struct e1000_ps_page *ps_page;
  3956. struct e1000_ps_page_dma *ps_page_dma;
  3957. struct sk_buff *skb;
  3958. unsigned int i, j;
  3959. i = rx_ring->next_to_use;
  3960. buffer_info = &rx_ring->buffer_info[i];
  3961. ps_page = &rx_ring->ps_page[i];
  3962. ps_page_dma = &rx_ring->ps_page_dma[i];
  3963. while (cleaned_count--) {
  3964. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  3965. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  3966. if (j < adapter->rx_ps_pages) {
  3967. if (likely(!ps_page->ps_page[j])) {
  3968. ps_page->ps_page[j] =
  3969. alloc_page(GFP_ATOMIC);
  3970. if (unlikely(!ps_page->ps_page[j])) {
  3971. adapter->alloc_rx_buff_failed++;
  3972. goto no_buffers;
  3973. }
  3974. ps_page_dma->ps_page_dma[j] =
  3975. pci_map_page(pdev,
  3976. ps_page->ps_page[j],
  3977. 0, PAGE_SIZE,
  3978. PCI_DMA_FROMDEVICE);
  3979. }
  3980. /* Refresh the desc even if buffer_addrs didn't
  3981. * change because each write-back erases
  3982. * this info.
  3983. */
  3984. rx_desc->read.buffer_addr[j+1] =
  3985. cpu_to_le64(ps_page_dma->ps_page_dma[j]);
  3986. } else
  3987. rx_desc->read.buffer_addr[j+1] = ~0;
  3988. }
  3989. skb = netdev_alloc_skb(netdev,
  3990. adapter->rx_ps_bsize0 + NET_IP_ALIGN);
  3991. if (unlikely(!skb)) {
  3992. adapter->alloc_rx_buff_failed++;
  3993. break;
  3994. }
  3995. /* Make buffer alignment 2 beyond a 16 byte boundary
  3996. * this will result in a 16 byte aligned IP header after
  3997. * the 14 byte MAC header is removed
  3998. */
  3999. skb_reserve(skb, NET_IP_ALIGN);
  4000. buffer_info->skb = skb;
  4001. buffer_info->length = adapter->rx_ps_bsize0;
  4002. buffer_info->dma = pci_map_single(pdev, skb->data,
  4003. adapter->rx_ps_bsize0,
  4004. PCI_DMA_FROMDEVICE);
  4005. rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
  4006. if (unlikely(++i == rx_ring->count)) i = 0;
  4007. buffer_info = &rx_ring->buffer_info[i];
  4008. ps_page = &rx_ring->ps_page[i];
  4009. ps_page_dma = &rx_ring->ps_page_dma[i];
  4010. }
  4011. no_buffers:
  4012. if (likely(rx_ring->next_to_use != i)) {
  4013. rx_ring->next_to_use = i;
  4014. if (unlikely(i-- == 0)) i = (rx_ring->count - 1);
  4015. /* Force memory writes to complete before letting h/w
  4016. * know there are new descriptors to fetch. (Only
  4017. * applicable for weak-ordered memory model archs,
  4018. * such as IA-64). */
  4019. wmb();
  4020. /* Hardware increments by 16 bytes, but packet split
  4021. * descriptors are 32 bytes...so we increment tail
  4022. * twice as much.
  4023. */
  4024. writel(i<<1, adapter->hw.hw_addr + rx_ring->rdt);
  4025. }
  4026. }
  4027. /**
  4028. * e1000_smartspeed - Workaround for SmartSpeed on 82541 and 82547 controllers.
  4029. * @adapter:
  4030. **/
  4031. static void
  4032. e1000_smartspeed(struct e1000_adapter *adapter)
  4033. {
  4034. uint16_t phy_status;
  4035. uint16_t phy_ctrl;
  4036. if ((adapter->hw.phy_type != e1000_phy_igp) || !adapter->hw.autoneg ||
  4037. !(adapter->hw.autoneg_advertised & ADVERTISE_1000_FULL))
  4038. return;
  4039. if (adapter->smartspeed == 0) {
  4040. /* If Master/Slave config fault is asserted twice,
  4041. * we assume back-to-back */
  4042. e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
  4043. if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
  4044. e1000_read_phy_reg(&adapter->hw, PHY_1000T_STATUS, &phy_status);
  4045. if (!(phy_status & SR_1000T_MS_CONFIG_FAULT)) return;
  4046. e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
  4047. if (phy_ctrl & CR_1000T_MS_ENABLE) {
  4048. phy_ctrl &= ~CR_1000T_MS_ENABLE;
  4049. e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL,
  4050. phy_ctrl);
  4051. adapter->smartspeed++;
  4052. if (!e1000_phy_setup_autoneg(&adapter->hw) &&
  4053. !e1000_read_phy_reg(&adapter->hw, PHY_CTRL,
  4054. &phy_ctrl)) {
  4055. phy_ctrl |= (MII_CR_AUTO_NEG_EN |
  4056. MII_CR_RESTART_AUTO_NEG);
  4057. e1000_write_phy_reg(&adapter->hw, PHY_CTRL,
  4058. phy_ctrl);
  4059. }
  4060. }
  4061. return;
  4062. } else if (adapter->smartspeed == E1000_SMARTSPEED_DOWNSHIFT) {
  4063. /* If still no link, perhaps using 2/3 pair cable */
  4064. e1000_read_phy_reg(&adapter->hw, PHY_1000T_CTRL, &phy_ctrl);
  4065. phy_ctrl |= CR_1000T_MS_ENABLE;
  4066. e1000_write_phy_reg(&adapter->hw, PHY_1000T_CTRL, phy_ctrl);
  4067. if (!e1000_phy_setup_autoneg(&adapter->hw) &&
  4068. !e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_ctrl)) {
  4069. phy_ctrl |= (MII_CR_AUTO_NEG_EN |
  4070. MII_CR_RESTART_AUTO_NEG);
  4071. e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_ctrl);
  4072. }
  4073. }
  4074. /* Restart process after E1000_SMARTSPEED_MAX iterations */
  4075. if (adapter->smartspeed++ == E1000_SMARTSPEED_MAX)
  4076. adapter->smartspeed = 0;
  4077. }
  4078. /**
  4079. * e1000_ioctl -
  4080. * @netdev:
  4081. * @ifreq:
  4082. * @cmd:
  4083. **/
  4084. static int
  4085. e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  4086. {
  4087. switch (cmd) {
  4088. case SIOCGMIIPHY:
  4089. case SIOCGMIIREG:
  4090. case SIOCSMIIREG:
  4091. return e1000_mii_ioctl(netdev, ifr, cmd);
  4092. default:
  4093. return -EOPNOTSUPP;
  4094. }
  4095. }
  4096. /**
  4097. * e1000_mii_ioctl -
  4098. * @netdev:
  4099. * @ifreq:
  4100. * @cmd:
  4101. **/
  4102. static int
  4103. e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  4104. {
  4105. struct e1000_adapter *adapter = netdev_priv(netdev);
  4106. struct mii_ioctl_data *data = if_mii(ifr);
  4107. int retval;
  4108. uint16_t mii_reg;
  4109. uint16_t spddplx;
  4110. unsigned long flags;
  4111. if (adapter->hw.media_type != e1000_media_type_copper)
  4112. return -EOPNOTSUPP;
  4113. switch (cmd) {
  4114. case SIOCGMIIPHY:
  4115. data->phy_id = adapter->hw.phy_addr;
  4116. break;
  4117. case SIOCGMIIREG:
  4118. if (!capable(CAP_NET_ADMIN))
  4119. return -EPERM;
  4120. spin_lock_irqsave(&adapter->stats_lock, flags);
  4121. if (e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
  4122. &data->val_out)) {
  4123. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  4124. return -EIO;
  4125. }
  4126. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  4127. break;
  4128. case SIOCSMIIREG:
  4129. if (!capable(CAP_NET_ADMIN))
  4130. return -EPERM;
  4131. if (data->reg_num & ~(0x1F))
  4132. return -EFAULT;
  4133. mii_reg = data->val_in;
  4134. spin_lock_irqsave(&adapter->stats_lock, flags);
  4135. if (e1000_write_phy_reg(&adapter->hw, data->reg_num,
  4136. mii_reg)) {
  4137. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  4138. return -EIO;
  4139. }
  4140. if (adapter->hw.media_type == e1000_media_type_copper) {
  4141. switch (data->reg_num) {
  4142. case PHY_CTRL:
  4143. if (mii_reg & MII_CR_POWER_DOWN)
  4144. break;
  4145. if (mii_reg & MII_CR_AUTO_NEG_EN) {
  4146. adapter->hw.autoneg = 1;
  4147. adapter->hw.autoneg_advertised = 0x2F;
  4148. } else {
  4149. if (mii_reg & 0x40)
  4150. spddplx = SPEED_1000;
  4151. else if (mii_reg & 0x2000)
  4152. spddplx = SPEED_100;
  4153. else
  4154. spddplx = SPEED_10;
  4155. spddplx += (mii_reg & 0x100)
  4156. ? DUPLEX_FULL :
  4157. DUPLEX_HALF;
  4158. retval = e1000_set_spd_dplx(adapter,
  4159. spddplx);
  4160. if (retval) {
  4161. spin_unlock_irqrestore(
  4162. &adapter->stats_lock,
  4163. flags);
  4164. return retval;
  4165. }
  4166. }
  4167. if (netif_running(adapter->netdev))
  4168. e1000_reinit_locked(adapter);
  4169. else
  4170. e1000_reset(adapter);
  4171. break;
  4172. case M88E1000_PHY_SPEC_CTRL:
  4173. case M88E1000_EXT_PHY_SPEC_CTRL:
  4174. if (e1000_phy_reset(&adapter->hw)) {
  4175. spin_unlock_irqrestore(
  4176. &adapter->stats_lock, flags);
  4177. return -EIO;
  4178. }
  4179. break;
  4180. }
  4181. } else {
  4182. switch (data->reg_num) {
  4183. case PHY_CTRL:
  4184. if (mii_reg & MII_CR_POWER_DOWN)
  4185. break;
  4186. if (netif_running(adapter->netdev))
  4187. e1000_reinit_locked(adapter);
  4188. else
  4189. e1000_reset(adapter);
  4190. break;
  4191. }
  4192. }
  4193. spin_unlock_irqrestore(&adapter->stats_lock, flags);
  4194. break;
  4195. default:
  4196. return -EOPNOTSUPP;
  4197. }
  4198. return E1000_SUCCESS;
  4199. }
  4200. void
  4201. e1000_pci_set_mwi(struct e1000_hw *hw)
  4202. {
  4203. struct e1000_adapter *adapter = hw->back;
  4204. int ret_val = pci_set_mwi(adapter->pdev);
  4205. if (ret_val)
  4206. DPRINTK(PROBE, ERR, "Error in setting MWI\n");
  4207. }
  4208. void
  4209. e1000_pci_clear_mwi(struct e1000_hw *hw)
  4210. {
  4211. struct e1000_adapter *adapter = hw->back;
  4212. pci_clear_mwi(adapter->pdev);
  4213. }
  4214. void
  4215. e1000_read_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  4216. {
  4217. struct e1000_adapter *adapter = hw->back;
  4218. pci_read_config_word(adapter->pdev, reg, value);
  4219. }
  4220. void
  4221. e1000_write_pci_cfg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  4222. {
  4223. struct e1000_adapter *adapter = hw->back;
  4224. pci_write_config_word(adapter->pdev, reg, *value);
  4225. }
  4226. int
  4227. e1000_pcix_get_mmrbc(struct e1000_hw *hw)
  4228. {
  4229. struct e1000_adapter *adapter = hw->back;
  4230. return pcix_get_mmrbc(adapter->pdev);
  4231. }
  4232. void
  4233. e1000_pcix_set_mmrbc(struct e1000_hw *hw, int mmrbc)
  4234. {
  4235. struct e1000_adapter *adapter = hw->back;
  4236. pcix_set_mmrbc(adapter->pdev, mmrbc);
  4237. }
  4238. int32_t
  4239. e1000_read_pcie_cap_reg(struct e1000_hw *hw, uint32_t reg, uint16_t *value)
  4240. {
  4241. struct e1000_adapter *adapter = hw->back;
  4242. uint16_t cap_offset;
  4243. cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
  4244. if (!cap_offset)
  4245. return -E1000_ERR_CONFIG;
  4246. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  4247. return E1000_SUCCESS;
  4248. }
  4249. void
  4250. e1000_io_write(struct e1000_hw *hw, unsigned long port, uint32_t value)
  4251. {
  4252. outl(value, port);
  4253. }
  4254. static void
  4255. e1000_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
  4256. {
  4257. struct e1000_adapter *adapter = netdev_priv(netdev);
  4258. uint32_t ctrl, rctl;
  4259. e1000_irq_disable(adapter);
  4260. adapter->vlgrp = grp;
  4261. if (grp) {
  4262. /* enable VLAN tag insert/strip */
  4263. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  4264. ctrl |= E1000_CTRL_VME;
  4265. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  4266. if (adapter->hw.mac_type != e1000_ich8lan) {
  4267. /* enable VLAN receive filtering */
  4268. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  4269. rctl |= E1000_RCTL_VFE;
  4270. rctl &= ~E1000_RCTL_CFIEN;
  4271. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  4272. e1000_update_mng_vlan(adapter);
  4273. }
  4274. } else {
  4275. /* disable VLAN tag insert/strip */
  4276. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  4277. ctrl &= ~E1000_CTRL_VME;
  4278. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  4279. if (adapter->hw.mac_type != e1000_ich8lan) {
  4280. /* disable VLAN filtering */
  4281. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  4282. rctl &= ~E1000_RCTL_VFE;
  4283. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  4284. if (adapter->mng_vlan_id !=
  4285. (uint16_t)E1000_MNG_VLAN_NONE) {
  4286. e1000_vlan_rx_kill_vid(netdev,
  4287. adapter->mng_vlan_id);
  4288. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  4289. }
  4290. }
  4291. }
  4292. e1000_irq_enable(adapter);
  4293. }
  4294. static void
  4295. e1000_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
  4296. {
  4297. struct e1000_adapter *adapter = netdev_priv(netdev);
  4298. uint32_t vfta, index;
  4299. if ((adapter->hw.mng_cookie.status &
  4300. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
  4301. (vid == adapter->mng_vlan_id))
  4302. return;
  4303. /* add VID to filter table */
  4304. index = (vid >> 5) & 0x7F;
  4305. vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  4306. vfta |= (1 << (vid & 0x1F));
  4307. e1000_write_vfta(&adapter->hw, index, vfta);
  4308. }
  4309. static void
  4310. e1000_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
  4311. {
  4312. struct e1000_adapter *adapter = netdev_priv(netdev);
  4313. uint32_t vfta, index;
  4314. e1000_irq_disable(adapter);
  4315. vlan_group_set_device(adapter->vlgrp, vid, NULL);
  4316. e1000_irq_enable(adapter);
  4317. if ((adapter->hw.mng_cookie.status &
  4318. E1000_MNG_DHCP_COOKIE_STATUS_VLAN_SUPPORT) &&
  4319. (vid == adapter->mng_vlan_id)) {
  4320. /* release control to f/w */
  4321. e1000_release_hw_control(adapter);
  4322. return;
  4323. }
  4324. /* remove VID from filter table */
  4325. index = (vid >> 5) & 0x7F;
  4326. vfta = E1000_READ_REG_ARRAY(&adapter->hw, VFTA, index);
  4327. vfta &= ~(1 << (vid & 0x1F));
  4328. e1000_write_vfta(&adapter->hw, index, vfta);
  4329. }
  4330. static void
  4331. e1000_restore_vlan(struct e1000_adapter *adapter)
  4332. {
  4333. e1000_vlan_rx_register(adapter->netdev, adapter->vlgrp);
  4334. if (adapter->vlgrp) {
  4335. uint16_t vid;
  4336. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  4337. if (!vlan_group_get_device(adapter->vlgrp, vid))
  4338. continue;
  4339. e1000_vlan_rx_add_vid(adapter->netdev, vid);
  4340. }
  4341. }
  4342. }
  4343. int
  4344. e1000_set_spd_dplx(struct e1000_adapter *adapter, uint16_t spddplx)
  4345. {
  4346. adapter->hw.autoneg = 0;
  4347. /* Fiber NICs only allow 1000 gbps Full duplex */
  4348. if ((adapter->hw.media_type == e1000_media_type_fiber) &&
  4349. spddplx != (SPEED_1000 + DUPLEX_FULL)) {
  4350. DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
  4351. return -EINVAL;
  4352. }
  4353. switch (spddplx) {
  4354. case SPEED_10 + DUPLEX_HALF:
  4355. adapter->hw.forced_speed_duplex = e1000_10_half;
  4356. break;
  4357. case SPEED_10 + DUPLEX_FULL:
  4358. adapter->hw.forced_speed_duplex = e1000_10_full;
  4359. break;
  4360. case SPEED_100 + DUPLEX_HALF:
  4361. adapter->hw.forced_speed_duplex = e1000_100_half;
  4362. break;
  4363. case SPEED_100 + DUPLEX_FULL:
  4364. adapter->hw.forced_speed_duplex = e1000_100_full;
  4365. break;
  4366. case SPEED_1000 + DUPLEX_FULL:
  4367. adapter->hw.autoneg = 1;
  4368. adapter->hw.autoneg_advertised = ADVERTISE_1000_FULL;
  4369. break;
  4370. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  4371. default:
  4372. DPRINTK(PROBE, ERR, "Unsupported Speed/Duplex configuration\n");
  4373. return -EINVAL;
  4374. }
  4375. return 0;
  4376. }
  4377. static int
  4378. e1000_suspend(struct pci_dev *pdev, pm_message_t state)
  4379. {
  4380. struct net_device *netdev = pci_get_drvdata(pdev);
  4381. struct e1000_adapter *adapter = netdev_priv(netdev);
  4382. uint32_t ctrl, ctrl_ext, rctl, status;
  4383. uint32_t wufc = adapter->wol;
  4384. #ifdef CONFIG_PM
  4385. int retval = 0;
  4386. #endif
  4387. netif_device_detach(netdev);
  4388. if (netif_running(netdev)) {
  4389. WARN_ON(test_bit(__E1000_RESETTING, &adapter->flags));
  4390. e1000_down(adapter);
  4391. }
  4392. #ifdef CONFIG_PM
  4393. retval = pci_save_state(pdev);
  4394. if (retval)
  4395. return retval;
  4396. #endif
  4397. status = E1000_READ_REG(&adapter->hw, STATUS);
  4398. if (status & E1000_STATUS_LU)
  4399. wufc &= ~E1000_WUFC_LNKC;
  4400. if (wufc) {
  4401. e1000_setup_rctl(adapter);
  4402. e1000_set_multi(netdev);
  4403. /* turn on all-multi mode if wake on multicast is enabled */
  4404. if (wufc & E1000_WUFC_MC) {
  4405. rctl = E1000_READ_REG(&adapter->hw, RCTL);
  4406. rctl |= E1000_RCTL_MPE;
  4407. E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
  4408. }
  4409. if (adapter->hw.mac_type >= e1000_82540) {
  4410. ctrl = E1000_READ_REG(&adapter->hw, CTRL);
  4411. /* advertise wake from D3Cold */
  4412. #define E1000_CTRL_ADVD3WUC 0x00100000
  4413. /* phy power management enable */
  4414. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  4415. ctrl |= E1000_CTRL_ADVD3WUC |
  4416. E1000_CTRL_EN_PHY_PWR_MGMT;
  4417. E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
  4418. }
  4419. if (adapter->hw.media_type == e1000_media_type_fiber ||
  4420. adapter->hw.media_type == e1000_media_type_internal_serdes) {
  4421. /* keep the laser running in D3 */
  4422. ctrl_ext = E1000_READ_REG(&adapter->hw, CTRL_EXT);
  4423. ctrl_ext |= E1000_CTRL_EXT_SDP7_DATA;
  4424. E1000_WRITE_REG(&adapter->hw, CTRL_EXT, ctrl_ext);
  4425. }
  4426. /* Allow time for pending master requests to run */
  4427. e1000_disable_pciex_master(&adapter->hw);
  4428. E1000_WRITE_REG(&adapter->hw, WUC, E1000_WUC_PME_EN);
  4429. E1000_WRITE_REG(&adapter->hw, WUFC, wufc);
  4430. pci_enable_wake(pdev, PCI_D3hot, 1);
  4431. pci_enable_wake(pdev, PCI_D3cold, 1);
  4432. } else {
  4433. E1000_WRITE_REG(&adapter->hw, WUC, 0);
  4434. E1000_WRITE_REG(&adapter->hw, WUFC, 0);
  4435. pci_enable_wake(pdev, PCI_D3hot, 0);
  4436. pci_enable_wake(pdev, PCI_D3cold, 0);
  4437. }
  4438. e1000_release_manageability(adapter);
  4439. /* make sure adapter isn't asleep if manageability is enabled */
  4440. if (adapter->en_mng_pt) {
  4441. pci_enable_wake(pdev, PCI_D3hot, 1);
  4442. pci_enable_wake(pdev, PCI_D3cold, 1);
  4443. }
  4444. if (adapter->hw.phy_type == e1000_phy_igp_3)
  4445. e1000_phy_powerdown_workaround(&adapter->hw);
  4446. if (netif_running(netdev))
  4447. e1000_free_irq(adapter);
  4448. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  4449. * would have already happened in close and is redundant. */
  4450. e1000_release_hw_control(adapter);
  4451. pci_disable_device(pdev);
  4452. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  4453. return 0;
  4454. }
  4455. #ifdef CONFIG_PM
  4456. static int
  4457. e1000_resume(struct pci_dev *pdev)
  4458. {
  4459. struct net_device *netdev = pci_get_drvdata(pdev);
  4460. struct e1000_adapter *adapter = netdev_priv(netdev);
  4461. uint32_t err;
  4462. pci_set_power_state(pdev, PCI_D0);
  4463. pci_restore_state(pdev);
  4464. if ((err = pci_enable_device(pdev))) {
  4465. printk(KERN_ERR "e1000: Cannot enable PCI device from suspend\n");
  4466. return err;
  4467. }
  4468. pci_set_master(pdev);
  4469. pci_enable_wake(pdev, PCI_D3hot, 0);
  4470. pci_enable_wake(pdev, PCI_D3cold, 0);
  4471. if (netif_running(netdev) && (err = e1000_request_irq(adapter)))
  4472. return err;
  4473. e1000_power_up_phy(adapter);
  4474. e1000_reset(adapter);
  4475. E1000_WRITE_REG(&adapter->hw, WUS, ~0);
  4476. e1000_init_manageability(adapter);
  4477. if (netif_running(netdev))
  4478. e1000_up(adapter);
  4479. netif_device_attach(netdev);
  4480. /* If the controller is 82573 and f/w is AMT, do not set
  4481. * DRV_LOAD until the interface is up. For all other cases,
  4482. * let the f/w know that the h/w is now under the control
  4483. * of the driver. */
  4484. if (adapter->hw.mac_type != e1000_82573 ||
  4485. !e1000_check_mng_mode(&adapter->hw))
  4486. e1000_get_hw_control(adapter);
  4487. return 0;
  4488. }
  4489. #endif
  4490. static void e1000_shutdown(struct pci_dev *pdev)
  4491. {
  4492. e1000_suspend(pdev, PMSG_SUSPEND);
  4493. }
  4494. #ifdef CONFIG_NET_POLL_CONTROLLER
  4495. /*
  4496. * Polling 'interrupt' - used by things like netconsole to send skbs
  4497. * without having to re-enable interrupts. It's not called while
  4498. * the interrupt routine is executing.
  4499. */
  4500. static void
  4501. e1000_netpoll(struct net_device *netdev)
  4502. {
  4503. struct e1000_adapter *adapter = netdev_priv(netdev);
  4504. disable_irq(adapter->pdev->irq);
  4505. e1000_intr(adapter->pdev->irq, netdev);
  4506. e1000_clean_tx_irq(adapter, adapter->tx_ring);
  4507. #ifndef CONFIG_E1000_NAPI
  4508. adapter->clean_rx(adapter, adapter->rx_ring);
  4509. #endif
  4510. enable_irq(adapter->pdev->irq);
  4511. }
  4512. #endif
  4513. /**
  4514. * e1000_io_error_detected - called when PCI error is detected
  4515. * @pdev: Pointer to PCI device
  4516. * @state: The current pci conneection state
  4517. *
  4518. * This function is called after a PCI bus error affecting
  4519. * this device has been detected.
  4520. */
  4521. static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  4522. {
  4523. struct net_device *netdev = pci_get_drvdata(pdev);
  4524. struct e1000_adapter *adapter = netdev->priv;
  4525. netif_device_detach(netdev);
  4526. if (netif_running(netdev))
  4527. e1000_down(adapter);
  4528. pci_disable_device(pdev);
  4529. /* Request a slot slot reset. */
  4530. return PCI_ERS_RESULT_NEED_RESET;
  4531. }
  4532. /**
  4533. * e1000_io_slot_reset - called after the pci bus has been reset.
  4534. * @pdev: Pointer to PCI device
  4535. *
  4536. * Restart the card from scratch, as if from a cold-boot. Implementation
  4537. * resembles the first-half of the e1000_resume routine.
  4538. */
  4539. static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
  4540. {
  4541. struct net_device *netdev = pci_get_drvdata(pdev);
  4542. struct e1000_adapter *adapter = netdev->priv;
  4543. if (pci_enable_device(pdev)) {
  4544. printk(KERN_ERR "e1000: Cannot re-enable PCI device after reset.\n");
  4545. return PCI_ERS_RESULT_DISCONNECT;
  4546. }
  4547. pci_set_master(pdev);
  4548. pci_enable_wake(pdev, PCI_D3hot, 0);
  4549. pci_enable_wake(pdev, PCI_D3cold, 0);
  4550. e1000_reset(adapter);
  4551. E1000_WRITE_REG(&adapter->hw, WUS, ~0);
  4552. return PCI_ERS_RESULT_RECOVERED;
  4553. }
  4554. /**
  4555. * e1000_io_resume - called when traffic can start flowing again.
  4556. * @pdev: Pointer to PCI device
  4557. *
  4558. * This callback is called when the error recovery driver tells us that
  4559. * its OK to resume normal operation. Implementation resembles the
  4560. * second-half of the e1000_resume routine.
  4561. */
  4562. static void e1000_io_resume(struct pci_dev *pdev)
  4563. {
  4564. struct net_device *netdev = pci_get_drvdata(pdev);
  4565. struct e1000_adapter *adapter = netdev->priv;
  4566. e1000_init_manageability(adapter);
  4567. if (netif_running(netdev)) {
  4568. if (e1000_up(adapter)) {
  4569. printk("e1000: can't bring device back up after reset\n");
  4570. return;
  4571. }
  4572. }
  4573. netif_device_attach(netdev);
  4574. /* If the controller is 82573 and f/w is AMT, do not set
  4575. * DRV_LOAD until the interface is up. For all other cases,
  4576. * let the f/w know that the h/w is now under the control
  4577. * of the driver. */
  4578. if (adapter->hw.mac_type != e1000_82573 ||
  4579. !e1000_check_mng_mode(&adapter->hw))
  4580. e1000_get_hw_control(adapter);
  4581. }
  4582. /* e1000_main.c */