e1000_main.c 154 KB

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