e1000_main.c 152 KB

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