e1000_main.c 152 KB

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