bnx2.c 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004, 2005 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Written by: Michael Chan (mchan@broadcom.com)
  10. */
  11. #include "bnx2.h"
  12. #include "bnx2_fw.h"
  13. #define DRV_MODULE_NAME "bnx2"
  14. #define PFX DRV_MODULE_NAME ": "
  15. #define DRV_MODULE_VERSION "1.2.19"
  16. #define DRV_MODULE_RELDATE "May 23, 2005"
  17. #define RUN_AT(x) (jiffies + (x))
  18. /* Time in jiffies before concluding the transmitter is hung. */
  19. #define TX_TIMEOUT (5*HZ)
  20. static char version[] __devinitdata =
  21. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  22. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  23. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706 Driver");
  24. MODULE_LICENSE("GPL");
  25. MODULE_VERSION(DRV_MODULE_VERSION);
  26. static int disable_msi = 0;
  27. module_param(disable_msi, int, 0);
  28. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  29. typedef enum {
  30. BCM5706 = 0,
  31. NC370T,
  32. NC370I,
  33. BCM5706S,
  34. NC370F,
  35. } board_t;
  36. /* indexed by board_t, above */
  37. static struct {
  38. char *name;
  39. } board_info[] __devinitdata = {
  40. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  41. { "HP NC370T Multifunction Gigabit Server Adapter" },
  42. { "HP NC370i Multifunction Gigabit Server Adapter" },
  43. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  44. { "HP NC370F Multifunction Gigabit Server Adapter" },
  45. };
  46. static struct pci_device_id bnx2_pci_tbl[] = {
  47. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  48. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  49. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  50. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  51. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  52. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  53. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  54. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  55. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  56. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  57. { 0, }
  58. };
  59. static struct flash_spec flash_table[] =
  60. {
  61. /* Slow EEPROM */
  62. {0x00000000, 0x40030380, 0x009f0081, 0xa184a053, 0xaf000400,
  63. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  64. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  65. "EEPROM - slow"},
  66. /* Fast EEPROM */
  67. {0x02000000, 0x62008380, 0x009f0081, 0xa184a053, 0xaf000400,
  68. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  69. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  70. "EEPROM - fast"},
  71. /* ATMEL AT45DB011B (buffered flash) */
  72. {0x02000003, 0x6e008173, 0x00570081, 0x68848353, 0xaf000400,
  73. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  74. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  75. "Buffered flash"},
  76. /* Saifun SA25F005 (non-buffered flash) */
  77. /* strap, cfg1, & write1 need updates */
  78. {0x01000003, 0x5f008081, 0x00050081, 0x03840253, 0xaf020406,
  79. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  80. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  81. "Non-buffered flash (64kB)"},
  82. /* Saifun SA25F010 (non-buffered flash) */
  83. /* strap, cfg1, & write1 need updates */
  84. {0x00000001, 0x47008081, 0x00050081, 0x03840253, 0xaf020406,
  85. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  86. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  87. "Non-buffered flash (128kB)"},
  88. /* Saifun SA25F020 (non-buffered flash) */
  89. /* strap, cfg1, & write1 need updates */
  90. {0x00000003, 0x4f008081, 0x00050081, 0x03840253, 0xaf020406,
  91. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  92. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  93. "Non-buffered flash (256kB)"},
  94. };
  95. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  96. static u32
  97. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  98. {
  99. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  100. return (REG_RD(bp, BNX2_PCICFG_REG_WINDOW));
  101. }
  102. static void
  103. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  104. {
  105. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  106. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  107. }
  108. static void
  109. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  110. {
  111. offset += cid_addr;
  112. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  113. REG_WR(bp, BNX2_CTX_DATA, val);
  114. }
  115. static int
  116. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  117. {
  118. u32 val1;
  119. int i, ret;
  120. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  121. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  122. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  123. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  124. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  125. udelay(40);
  126. }
  127. val1 = (bp->phy_addr << 21) | (reg << 16) |
  128. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  129. BNX2_EMAC_MDIO_COMM_START_BUSY;
  130. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  131. for (i = 0; i < 50; i++) {
  132. udelay(10);
  133. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  134. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  135. udelay(5);
  136. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  137. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  138. break;
  139. }
  140. }
  141. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  142. *val = 0x0;
  143. ret = -EBUSY;
  144. }
  145. else {
  146. *val = val1;
  147. ret = 0;
  148. }
  149. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  150. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  151. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  152. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  153. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  154. udelay(40);
  155. }
  156. return ret;
  157. }
  158. static int
  159. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  160. {
  161. u32 val1;
  162. int i, ret;
  163. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  164. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  165. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  166. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  167. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  168. udelay(40);
  169. }
  170. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  171. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  172. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  173. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  174. for (i = 0; i < 50; i++) {
  175. udelay(10);
  176. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  177. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  178. udelay(5);
  179. break;
  180. }
  181. }
  182. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  183. ret = -EBUSY;
  184. else
  185. ret = 0;
  186. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  187. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  188. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  189. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  190. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  191. udelay(40);
  192. }
  193. return ret;
  194. }
  195. static void
  196. bnx2_disable_int(struct bnx2 *bp)
  197. {
  198. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  199. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  200. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  201. }
  202. static void
  203. bnx2_enable_int(struct bnx2 *bp)
  204. {
  205. u32 val;
  206. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  207. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
  208. val = REG_RD(bp, BNX2_HC_COMMAND);
  209. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  210. }
  211. static void
  212. bnx2_disable_int_sync(struct bnx2 *bp)
  213. {
  214. atomic_inc(&bp->intr_sem);
  215. bnx2_disable_int(bp);
  216. synchronize_irq(bp->pdev->irq);
  217. }
  218. static void
  219. bnx2_netif_stop(struct bnx2 *bp)
  220. {
  221. bnx2_disable_int_sync(bp);
  222. if (netif_running(bp->dev)) {
  223. netif_poll_disable(bp->dev);
  224. netif_tx_disable(bp->dev);
  225. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  226. }
  227. }
  228. static void
  229. bnx2_netif_start(struct bnx2 *bp)
  230. {
  231. if (atomic_dec_and_test(&bp->intr_sem)) {
  232. if (netif_running(bp->dev)) {
  233. netif_wake_queue(bp->dev);
  234. netif_poll_enable(bp->dev);
  235. bnx2_enable_int(bp);
  236. }
  237. }
  238. }
  239. static void
  240. bnx2_free_mem(struct bnx2 *bp)
  241. {
  242. if (bp->stats_blk) {
  243. pci_free_consistent(bp->pdev, sizeof(struct statistics_block),
  244. bp->stats_blk, bp->stats_blk_mapping);
  245. bp->stats_blk = NULL;
  246. }
  247. if (bp->status_blk) {
  248. pci_free_consistent(bp->pdev, sizeof(struct status_block),
  249. bp->status_blk, bp->status_blk_mapping);
  250. bp->status_blk = NULL;
  251. }
  252. if (bp->tx_desc_ring) {
  253. pci_free_consistent(bp->pdev,
  254. sizeof(struct tx_bd) * TX_DESC_CNT,
  255. bp->tx_desc_ring, bp->tx_desc_mapping);
  256. bp->tx_desc_ring = NULL;
  257. }
  258. if (bp->tx_buf_ring) {
  259. kfree(bp->tx_buf_ring);
  260. bp->tx_buf_ring = NULL;
  261. }
  262. if (bp->rx_desc_ring) {
  263. pci_free_consistent(bp->pdev,
  264. sizeof(struct rx_bd) * RX_DESC_CNT,
  265. bp->rx_desc_ring, bp->rx_desc_mapping);
  266. bp->rx_desc_ring = NULL;
  267. }
  268. if (bp->rx_buf_ring) {
  269. kfree(bp->rx_buf_ring);
  270. bp->rx_buf_ring = NULL;
  271. }
  272. }
  273. static int
  274. bnx2_alloc_mem(struct bnx2 *bp)
  275. {
  276. bp->tx_buf_ring = kmalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
  277. GFP_KERNEL);
  278. if (bp->tx_buf_ring == NULL)
  279. return -ENOMEM;
  280. memset(bp->tx_buf_ring, 0, sizeof(struct sw_bd) * TX_DESC_CNT);
  281. bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
  282. sizeof(struct tx_bd) *
  283. TX_DESC_CNT,
  284. &bp->tx_desc_mapping);
  285. if (bp->tx_desc_ring == NULL)
  286. goto alloc_mem_err;
  287. bp->rx_buf_ring = kmalloc(sizeof(struct sw_bd) * RX_DESC_CNT,
  288. GFP_KERNEL);
  289. if (bp->rx_buf_ring == NULL)
  290. goto alloc_mem_err;
  291. memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT);
  292. bp->rx_desc_ring = pci_alloc_consistent(bp->pdev,
  293. sizeof(struct rx_bd) *
  294. RX_DESC_CNT,
  295. &bp->rx_desc_mapping);
  296. if (bp->rx_desc_ring == NULL)
  297. goto alloc_mem_err;
  298. bp->status_blk = pci_alloc_consistent(bp->pdev,
  299. sizeof(struct status_block),
  300. &bp->status_blk_mapping);
  301. if (bp->status_blk == NULL)
  302. goto alloc_mem_err;
  303. memset(bp->status_blk, 0, sizeof(struct status_block));
  304. bp->stats_blk = pci_alloc_consistent(bp->pdev,
  305. sizeof(struct statistics_block),
  306. &bp->stats_blk_mapping);
  307. if (bp->stats_blk == NULL)
  308. goto alloc_mem_err;
  309. memset(bp->stats_blk, 0, sizeof(struct statistics_block));
  310. return 0;
  311. alloc_mem_err:
  312. bnx2_free_mem(bp);
  313. return -ENOMEM;
  314. }
  315. static void
  316. bnx2_report_link(struct bnx2 *bp)
  317. {
  318. if (bp->link_up) {
  319. netif_carrier_on(bp->dev);
  320. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  321. printk("%d Mbps ", bp->line_speed);
  322. if (bp->duplex == DUPLEX_FULL)
  323. printk("full duplex");
  324. else
  325. printk("half duplex");
  326. if (bp->flow_ctrl) {
  327. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  328. printk(", receive ");
  329. if (bp->flow_ctrl & FLOW_CTRL_TX)
  330. printk("& transmit ");
  331. }
  332. else {
  333. printk(", transmit ");
  334. }
  335. printk("flow control ON");
  336. }
  337. printk("\n");
  338. }
  339. else {
  340. netif_carrier_off(bp->dev);
  341. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  342. }
  343. }
  344. static void
  345. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  346. {
  347. u32 local_adv, remote_adv;
  348. bp->flow_ctrl = 0;
  349. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  350. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  351. if (bp->duplex == DUPLEX_FULL) {
  352. bp->flow_ctrl = bp->req_flow_ctrl;
  353. }
  354. return;
  355. }
  356. if (bp->duplex != DUPLEX_FULL) {
  357. return;
  358. }
  359. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  360. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  361. if (bp->phy_flags & PHY_SERDES_FLAG) {
  362. u32 new_local_adv = 0;
  363. u32 new_remote_adv = 0;
  364. if (local_adv & ADVERTISE_1000XPAUSE)
  365. new_local_adv |= ADVERTISE_PAUSE_CAP;
  366. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  367. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  368. if (remote_adv & ADVERTISE_1000XPAUSE)
  369. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  370. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  371. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  372. local_adv = new_local_adv;
  373. remote_adv = new_remote_adv;
  374. }
  375. /* See Table 28B-3 of 802.3ab-1999 spec. */
  376. if (local_adv & ADVERTISE_PAUSE_CAP) {
  377. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  378. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  379. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  380. }
  381. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  382. bp->flow_ctrl = FLOW_CTRL_RX;
  383. }
  384. }
  385. else {
  386. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  387. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  388. }
  389. }
  390. }
  391. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  392. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  393. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  394. bp->flow_ctrl = FLOW_CTRL_TX;
  395. }
  396. }
  397. }
  398. static int
  399. bnx2_serdes_linkup(struct bnx2 *bp)
  400. {
  401. u32 bmcr, local_adv, remote_adv, common;
  402. bp->link_up = 1;
  403. bp->line_speed = SPEED_1000;
  404. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  405. if (bmcr & BMCR_FULLDPLX) {
  406. bp->duplex = DUPLEX_FULL;
  407. }
  408. else {
  409. bp->duplex = DUPLEX_HALF;
  410. }
  411. if (!(bmcr & BMCR_ANENABLE)) {
  412. return 0;
  413. }
  414. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  415. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  416. common = local_adv & remote_adv;
  417. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  418. if (common & ADVERTISE_1000XFULL) {
  419. bp->duplex = DUPLEX_FULL;
  420. }
  421. else {
  422. bp->duplex = DUPLEX_HALF;
  423. }
  424. }
  425. return 0;
  426. }
  427. static int
  428. bnx2_copper_linkup(struct bnx2 *bp)
  429. {
  430. u32 bmcr;
  431. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  432. if (bmcr & BMCR_ANENABLE) {
  433. u32 local_adv, remote_adv, common;
  434. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  435. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  436. common = local_adv & (remote_adv >> 2);
  437. if (common & ADVERTISE_1000FULL) {
  438. bp->line_speed = SPEED_1000;
  439. bp->duplex = DUPLEX_FULL;
  440. }
  441. else if (common & ADVERTISE_1000HALF) {
  442. bp->line_speed = SPEED_1000;
  443. bp->duplex = DUPLEX_HALF;
  444. }
  445. else {
  446. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  447. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  448. common = local_adv & remote_adv;
  449. if (common & ADVERTISE_100FULL) {
  450. bp->line_speed = SPEED_100;
  451. bp->duplex = DUPLEX_FULL;
  452. }
  453. else if (common & ADVERTISE_100HALF) {
  454. bp->line_speed = SPEED_100;
  455. bp->duplex = DUPLEX_HALF;
  456. }
  457. else if (common & ADVERTISE_10FULL) {
  458. bp->line_speed = SPEED_10;
  459. bp->duplex = DUPLEX_FULL;
  460. }
  461. else if (common & ADVERTISE_10HALF) {
  462. bp->line_speed = SPEED_10;
  463. bp->duplex = DUPLEX_HALF;
  464. }
  465. else {
  466. bp->line_speed = 0;
  467. bp->link_up = 0;
  468. }
  469. }
  470. }
  471. else {
  472. if (bmcr & BMCR_SPEED100) {
  473. bp->line_speed = SPEED_100;
  474. }
  475. else {
  476. bp->line_speed = SPEED_10;
  477. }
  478. if (bmcr & BMCR_FULLDPLX) {
  479. bp->duplex = DUPLEX_FULL;
  480. }
  481. else {
  482. bp->duplex = DUPLEX_HALF;
  483. }
  484. }
  485. return 0;
  486. }
  487. static int
  488. bnx2_set_mac_link(struct bnx2 *bp)
  489. {
  490. u32 val;
  491. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  492. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  493. (bp->duplex == DUPLEX_HALF)) {
  494. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  495. }
  496. /* Configure the EMAC mode register. */
  497. val = REG_RD(bp, BNX2_EMAC_MODE);
  498. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  499. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK);
  500. if (bp->link_up) {
  501. if (bp->line_speed != SPEED_1000)
  502. val |= BNX2_EMAC_MODE_PORT_MII;
  503. else
  504. val |= BNX2_EMAC_MODE_PORT_GMII;
  505. }
  506. else {
  507. val |= BNX2_EMAC_MODE_PORT_GMII;
  508. }
  509. /* Set the MAC to operate in the appropriate duplex mode. */
  510. if (bp->duplex == DUPLEX_HALF)
  511. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  512. REG_WR(bp, BNX2_EMAC_MODE, val);
  513. /* Enable/disable rx PAUSE. */
  514. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  515. if (bp->flow_ctrl & FLOW_CTRL_RX)
  516. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  517. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  518. /* Enable/disable tx PAUSE. */
  519. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  520. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  521. if (bp->flow_ctrl & FLOW_CTRL_TX)
  522. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  523. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  524. /* Acknowledge the interrupt. */
  525. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  526. return 0;
  527. }
  528. static int
  529. bnx2_set_link(struct bnx2 *bp)
  530. {
  531. u32 bmsr;
  532. u8 link_up;
  533. if (bp->loopback == MAC_LOOPBACK) {
  534. bp->link_up = 1;
  535. return 0;
  536. }
  537. link_up = bp->link_up;
  538. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  539. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  540. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  541. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  542. u32 val;
  543. val = REG_RD(bp, BNX2_EMAC_STATUS);
  544. if (val & BNX2_EMAC_STATUS_LINK)
  545. bmsr |= BMSR_LSTATUS;
  546. else
  547. bmsr &= ~BMSR_LSTATUS;
  548. }
  549. if (bmsr & BMSR_LSTATUS) {
  550. bp->link_up = 1;
  551. if (bp->phy_flags & PHY_SERDES_FLAG) {
  552. bnx2_serdes_linkup(bp);
  553. }
  554. else {
  555. bnx2_copper_linkup(bp);
  556. }
  557. bnx2_resolve_flow_ctrl(bp);
  558. }
  559. else {
  560. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  561. (bp->autoneg & AUTONEG_SPEED)) {
  562. u32 bmcr;
  563. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  564. if (!(bmcr & BMCR_ANENABLE)) {
  565. bnx2_write_phy(bp, MII_BMCR, bmcr |
  566. BMCR_ANENABLE);
  567. }
  568. }
  569. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  570. bp->link_up = 0;
  571. }
  572. if (bp->link_up != link_up) {
  573. bnx2_report_link(bp);
  574. }
  575. bnx2_set_mac_link(bp);
  576. return 0;
  577. }
  578. static int
  579. bnx2_reset_phy(struct bnx2 *bp)
  580. {
  581. int i;
  582. u32 reg;
  583. bnx2_write_phy(bp, MII_BMCR, BMCR_RESET);
  584. #define PHY_RESET_MAX_WAIT 100
  585. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  586. udelay(10);
  587. bnx2_read_phy(bp, MII_BMCR, &reg);
  588. if (!(reg & BMCR_RESET)) {
  589. udelay(20);
  590. break;
  591. }
  592. }
  593. if (i == PHY_RESET_MAX_WAIT) {
  594. return -EBUSY;
  595. }
  596. return 0;
  597. }
  598. static u32
  599. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  600. {
  601. u32 adv = 0;
  602. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  603. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  604. if (bp->phy_flags & PHY_SERDES_FLAG) {
  605. adv = ADVERTISE_1000XPAUSE;
  606. }
  607. else {
  608. adv = ADVERTISE_PAUSE_CAP;
  609. }
  610. }
  611. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  612. if (bp->phy_flags & PHY_SERDES_FLAG) {
  613. adv = ADVERTISE_1000XPSE_ASYM;
  614. }
  615. else {
  616. adv = ADVERTISE_PAUSE_ASYM;
  617. }
  618. }
  619. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  620. if (bp->phy_flags & PHY_SERDES_FLAG) {
  621. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  622. }
  623. else {
  624. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  625. }
  626. }
  627. return adv;
  628. }
  629. static int
  630. bnx2_setup_serdes_phy(struct bnx2 *bp)
  631. {
  632. u32 adv, bmcr;
  633. u32 new_adv = 0;
  634. if (!(bp->autoneg & AUTONEG_SPEED)) {
  635. u32 new_bmcr;
  636. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  637. new_bmcr = bmcr & ~BMCR_ANENABLE;
  638. new_bmcr |= BMCR_SPEED1000;
  639. if (bp->req_duplex == DUPLEX_FULL) {
  640. new_bmcr |= BMCR_FULLDPLX;
  641. }
  642. else {
  643. new_bmcr &= ~BMCR_FULLDPLX;
  644. }
  645. if (new_bmcr != bmcr) {
  646. /* Force a link down visible on the other side */
  647. if (bp->link_up) {
  648. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  649. adv &= ~(ADVERTISE_1000XFULL |
  650. ADVERTISE_1000XHALF);
  651. bnx2_write_phy(bp, MII_ADVERTISE, adv);
  652. bnx2_write_phy(bp, MII_BMCR, bmcr |
  653. BMCR_ANRESTART | BMCR_ANENABLE);
  654. bp->link_up = 0;
  655. netif_carrier_off(bp->dev);
  656. }
  657. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  658. }
  659. return 0;
  660. }
  661. if (bp->advertising & ADVERTISED_1000baseT_Full)
  662. new_adv |= ADVERTISE_1000XFULL;
  663. new_adv |= bnx2_phy_get_pause_adv(bp);
  664. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  665. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  666. bp->serdes_an_pending = 0;
  667. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  668. /* Force a link down visible on the other side */
  669. if (bp->link_up) {
  670. int i;
  671. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  672. for (i = 0; i < 110; i++) {
  673. udelay(100);
  674. }
  675. }
  676. bnx2_write_phy(bp, MII_ADVERTISE, new_adv);
  677. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART |
  678. BMCR_ANENABLE);
  679. bp->serdes_an_pending = SERDES_AN_TIMEOUT / bp->timer_interval;
  680. }
  681. return 0;
  682. }
  683. #define ETHTOOL_ALL_FIBRE_SPEED \
  684. (ADVERTISED_1000baseT_Full)
  685. #define ETHTOOL_ALL_COPPER_SPEED \
  686. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  687. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  688. ADVERTISED_1000baseT_Full)
  689. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  690. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  691. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  692. static int
  693. bnx2_setup_copper_phy(struct bnx2 *bp)
  694. {
  695. u32 bmcr;
  696. u32 new_bmcr;
  697. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  698. if (bp->autoneg & AUTONEG_SPEED) {
  699. u32 adv_reg, adv1000_reg;
  700. u32 new_adv_reg = 0;
  701. u32 new_adv1000_reg = 0;
  702. bnx2_read_phy(bp, MII_ADVERTISE, &adv_reg);
  703. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  704. ADVERTISE_PAUSE_ASYM);
  705. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  706. adv1000_reg &= PHY_ALL_1000_SPEED;
  707. if (bp->advertising & ADVERTISED_10baseT_Half)
  708. new_adv_reg |= ADVERTISE_10HALF;
  709. if (bp->advertising & ADVERTISED_10baseT_Full)
  710. new_adv_reg |= ADVERTISE_10FULL;
  711. if (bp->advertising & ADVERTISED_100baseT_Half)
  712. new_adv_reg |= ADVERTISE_100HALF;
  713. if (bp->advertising & ADVERTISED_100baseT_Full)
  714. new_adv_reg |= ADVERTISE_100FULL;
  715. if (bp->advertising & ADVERTISED_1000baseT_Full)
  716. new_adv1000_reg |= ADVERTISE_1000FULL;
  717. new_adv_reg |= ADVERTISE_CSMA;
  718. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  719. if ((adv1000_reg != new_adv1000_reg) ||
  720. (adv_reg != new_adv_reg) ||
  721. ((bmcr & BMCR_ANENABLE) == 0)) {
  722. bnx2_write_phy(bp, MII_ADVERTISE, new_adv_reg);
  723. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  724. bnx2_write_phy(bp, MII_BMCR, BMCR_ANRESTART |
  725. BMCR_ANENABLE);
  726. }
  727. else if (bp->link_up) {
  728. /* Flow ctrl may have changed from auto to forced */
  729. /* or vice-versa. */
  730. bnx2_resolve_flow_ctrl(bp);
  731. bnx2_set_mac_link(bp);
  732. }
  733. return 0;
  734. }
  735. new_bmcr = 0;
  736. if (bp->req_line_speed == SPEED_100) {
  737. new_bmcr |= BMCR_SPEED100;
  738. }
  739. if (bp->req_duplex == DUPLEX_FULL) {
  740. new_bmcr |= BMCR_FULLDPLX;
  741. }
  742. if (new_bmcr != bmcr) {
  743. u32 bmsr;
  744. int i = 0;
  745. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  746. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  747. if (bmsr & BMSR_LSTATUS) {
  748. /* Force link down */
  749. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  750. do {
  751. udelay(100);
  752. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  753. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  754. i++;
  755. } while ((bmsr & BMSR_LSTATUS) && (i < 620));
  756. }
  757. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  758. /* Normally, the new speed is setup after the link has
  759. * gone down and up again. In some cases, link will not go
  760. * down so we need to set up the new speed here.
  761. */
  762. if (bmsr & BMSR_LSTATUS) {
  763. bp->line_speed = bp->req_line_speed;
  764. bp->duplex = bp->req_duplex;
  765. bnx2_resolve_flow_ctrl(bp);
  766. bnx2_set_mac_link(bp);
  767. }
  768. }
  769. return 0;
  770. }
  771. static int
  772. bnx2_setup_phy(struct bnx2 *bp)
  773. {
  774. if (bp->loopback == MAC_LOOPBACK)
  775. return 0;
  776. if (bp->phy_flags & PHY_SERDES_FLAG) {
  777. return (bnx2_setup_serdes_phy(bp));
  778. }
  779. else {
  780. return (bnx2_setup_copper_phy(bp));
  781. }
  782. }
  783. static int
  784. bnx2_init_serdes_phy(struct bnx2 *bp)
  785. {
  786. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  787. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  788. REG_WR(bp, BNX2_MISC_UNUSED0, 0x300);
  789. }
  790. if (bp->dev->mtu > 1500) {
  791. u32 val;
  792. /* Set extended packet length bit */
  793. bnx2_write_phy(bp, 0x18, 0x7);
  794. bnx2_read_phy(bp, 0x18, &val);
  795. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  796. bnx2_write_phy(bp, 0x1c, 0x6c00);
  797. bnx2_read_phy(bp, 0x1c, &val);
  798. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  799. }
  800. else {
  801. u32 val;
  802. bnx2_write_phy(bp, 0x18, 0x7);
  803. bnx2_read_phy(bp, 0x18, &val);
  804. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  805. bnx2_write_phy(bp, 0x1c, 0x6c00);
  806. bnx2_read_phy(bp, 0x1c, &val);
  807. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  808. }
  809. return 0;
  810. }
  811. static int
  812. bnx2_init_copper_phy(struct bnx2 *bp)
  813. {
  814. bp->phy_flags |= PHY_CRC_FIX_FLAG;
  815. if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
  816. bnx2_write_phy(bp, 0x18, 0x0c00);
  817. bnx2_write_phy(bp, 0x17, 0x000a);
  818. bnx2_write_phy(bp, 0x15, 0x310b);
  819. bnx2_write_phy(bp, 0x17, 0x201f);
  820. bnx2_write_phy(bp, 0x15, 0x9506);
  821. bnx2_write_phy(bp, 0x17, 0x401f);
  822. bnx2_write_phy(bp, 0x15, 0x14e2);
  823. bnx2_write_phy(bp, 0x18, 0x0400);
  824. }
  825. if (bp->dev->mtu > 1500) {
  826. u32 val;
  827. /* Set extended packet length bit */
  828. bnx2_write_phy(bp, 0x18, 0x7);
  829. bnx2_read_phy(bp, 0x18, &val);
  830. bnx2_write_phy(bp, 0x18, val | 0x4000);
  831. bnx2_read_phy(bp, 0x10, &val);
  832. bnx2_write_phy(bp, 0x10, val | 0x1);
  833. }
  834. else {
  835. u32 val;
  836. bnx2_write_phy(bp, 0x18, 0x7);
  837. bnx2_read_phy(bp, 0x18, &val);
  838. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  839. bnx2_read_phy(bp, 0x10, &val);
  840. bnx2_write_phy(bp, 0x10, val & ~0x1);
  841. }
  842. return 0;
  843. }
  844. static int
  845. bnx2_init_phy(struct bnx2 *bp)
  846. {
  847. u32 val;
  848. int rc = 0;
  849. bp->phy_flags &= ~PHY_INT_MODE_MASK_FLAG;
  850. bp->phy_flags |= PHY_INT_MODE_LINK_READY_FLAG;
  851. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  852. bnx2_reset_phy(bp);
  853. bnx2_read_phy(bp, MII_PHYSID1, &val);
  854. bp->phy_id = val << 16;
  855. bnx2_read_phy(bp, MII_PHYSID2, &val);
  856. bp->phy_id |= val & 0xffff;
  857. if (bp->phy_flags & PHY_SERDES_FLAG) {
  858. rc = bnx2_init_serdes_phy(bp);
  859. }
  860. else {
  861. rc = bnx2_init_copper_phy(bp);
  862. }
  863. bnx2_setup_phy(bp);
  864. return rc;
  865. }
  866. static int
  867. bnx2_set_mac_loopback(struct bnx2 *bp)
  868. {
  869. u32 mac_mode;
  870. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  871. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  872. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  873. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  874. bp->link_up = 1;
  875. return 0;
  876. }
  877. static int
  878. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data)
  879. {
  880. int i;
  881. u32 val;
  882. if (bp->fw_timed_out)
  883. return -EBUSY;
  884. bp->fw_wr_seq++;
  885. msg_data |= bp->fw_wr_seq;
  886. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_MB, msg_data);
  887. /* wait for an acknowledgement. */
  888. for (i = 0; i < (FW_ACK_TIME_OUT_MS * 1000)/5; i++) {
  889. udelay(5);
  890. val = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_FW_MB);
  891. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  892. break;
  893. }
  894. /* If we timed out, inform the firmware that this is the case. */
  895. if (((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) &&
  896. ((msg_data & BNX2_DRV_MSG_DATA) != BNX2_DRV_MSG_DATA_WAIT0)) {
  897. msg_data &= ~BNX2_DRV_MSG_CODE;
  898. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  899. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_MB, msg_data);
  900. bp->fw_timed_out = 1;
  901. return -EBUSY;
  902. }
  903. return 0;
  904. }
  905. static void
  906. bnx2_init_context(struct bnx2 *bp)
  907. {
  908. u32 vcid;
  909. vcid = 96;
  910. while (vcid) {
  911. u32 vcid_addr, pcid_addr, offset;
  912. vcid--;
  913. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  914. u32 new_vcid;
  915. vcid_addr = GET_PCID_ADDR(vcid);
  916. if (vcid & 0x8) {
  917. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  918. }
  919. else {
  920. new_vcid = vcid;
  921. }
  922. pcid_addr = GET_PCID_ADDR(new_vcid);
  923. }
  924. else {
  925. vcid_addr = GET_CID_ADDR(vcid);
  926. pcid_addr = vcid_addr;
  927. }
  928. REG_WR(bp, BNX2_CTX_VIRT_ADDR, 0x00);
  929. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  930. /* Zero out the context. */
  931. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
  932. CTX_WR(bp, 0x00, offset, 0);
  933. }
  934. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  935. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  936. }
  937. }
  938. static int
  939. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  940. {
  941. u16 *good_mbuf;
  942. u32 good_mbuf_cnt;
  943. u32 val;
  944. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  945. if (good_mbuf == NULL) {
  946. printk(KERN_ERR PFX "Failed to allocate memory in "
  947. "bnx2_alloc_bad_rbuf\n");
  948. return -ENOMEM;
  949. }
  950. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  951. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  952. good_mbuf_cnt = 0;
  953. /* Allocate a bunch of mbufs and save the good ones in an array. */
  954. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  955. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  956. REG_WR_IND(bp, BNX2_RBUF_COMMAND, BNX2_RBUF_COMMAND_ALLOC_REQ);
  957. val = REG_RD_IND(bp, BNX2_RBUF_FW_BUF_ALLOC);
  958. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  959. /* The addresses with Bit 9 set are bad memory blocks. */
  960. if (!(val & (1 << 9))) {
  961. good_mbuf[good_mbuf_cnt] = (u16) val;
  962. good_mbuf_cnt++;
  963. }
  964. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  965. }
  966. /* Free the good ones back to the mbuf pool thus discarding
  967. * all the bad ones. */
  968. while (good_mbuf_cnt) {
  969. good_mbuf_cnt--;
  970. val = good_mbuf[good_mbuf_cnt];
  971. val = (val << 9) | val | 1;
  972. REG_WR_IND(bp, BNX2_RBUF_FW_BUF_FREE, val);
  973. }
  974. kfree(good_mbuf);
  975. return 0;
  976. }
  977. static void
  978. bnx2_set_mac_addr(struct bnx2 *bp)
  979. {
  980. u32 val;
  981. u8 *mac_addr = bp->dev->dev_addr;
  982. val = (mac_addr[0] << 8) | mac_addr[1];
  983. REG_WR(bp, BNX2_EMAC_MAC_MATCH0, val);
  984. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  985. (mac_addr[4] << 8) | mac_addr[5];
  986. REG_WR(bp, BNX2_EMAC_MAC_MATCH1, val);
  987. }
  988. static inline int
  989. bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
  990. {
  991. struct sk_buff *skb;
  992. struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
  993. dma_addr_t mapping;
  994. struct rx_bd *rxbd = &bp->rx_desc_ring[index];
  995. unsigned long align;
  996. skb = dev_alloc_skb(bp->rx_buf_size);
  997. if (skb == NULL) {
  998. return -ENOMEM;
  999. }
  1000. if (unlikely((align = (unsigned long) skb->data & 0x7))) {
  1001. skb_reserve(skb, 8 - align);
  1002. }
  1003. skb->dev = bp->dev;
  1004. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  1005. PCI_DMA_FROMDEVICE);
  1006. rx_buf->skb = skb;
  1007. pci_unmap_addr_set(rx_buf, mapping, mapping);
  1008. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  1009. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  1010. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1011. return 0;
  1012. }
  1013. static void
  1014. bnx2_phy_int(struct bnx2 *bp)
  1015. {
  1016. u32 new_link_state, old_link_state;
  1017. new_link_state = bp->status_blk->status_attn_bits &
  1018. STATUS_ATTN_BITS_LINK_STATE;
  1019. old_link_state = bp->status_blk->status_attn_bits_ack &
  1020. STATUS_ATTN_BITS_LINK_STATE;
  1021. if (new_link_state != old_link_state) {
  1022. if (new_link_state) {
  1023. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD,
  1024. STATUS_ATTN_BITS_LINK_STATE);
  1025. }
  1026. else {
  1027. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD,
  1028. STATUS_ATTN_BITS_LINK_STATE);
  1029. }
  1030. bnx2_set_link(bp);
  1031. }
  1032. }
  1033. static void
  1034. bnx2_tx_int(struct bnx2 *bp)
  1035. {
  1036. u16 hw_cons, sw_cons, sw_ring_cons;
  1037. int tx_free_bd = 0;
  1038. hw_cons = bp->status_blk->status_tx_quick_consumer_index0;
  1039. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1040. hw_cons++;
  1041. }
  1042. sw_cons = bp->tx_cons;
  1043. while (sw_cons != hw_cons) {
  1044. struct sw_bd *tx_buf;
  1045. struct sk_buff *skb;
  1046. int i, last;
  1047. sw_ring_cons = TX_RING_IDX(sw_cons);
  1048. tx_buf = &bp->tx_buf_ring[sw_ring_cons];
  1049. skb = tx_buf->skb;
  1050. #ifdef BCM_TSO
  1051. /* partial BD completions possible with TSO packets */
  1052. if (skb_shinfo(skb)->tso_size) {
  1053. u16 last_idx, last_ring_idx;
  1054. last_idx = sw_cons +
  1055. skb_shinfo(skb)->nr_frags + 1;
  1056. last_ring_idx = sw_ring_cons +
  1057. skb_shinfo(skb)->nr_frags + 1;
  1058. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  1059. last_idx++;
  1060. }
  1061. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  1062. break;
  1063. }
  1064. }
  1065. #endif
  1066. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  1067. skb_headlen(skb), PCI_DMA_TODEVICE);
  1068. tx_buf->skb = NULL;
  1069. last = skb_shinfo(skb)->nr_frags;
  1070. for (i = 0; i < last; i++) {
  1071. sw_cons = NEXT_TX_BD(sw_cons);
  1072. pci_unmap_page(bp->pdev,
  1073. pci_unmap_addr(
  1074. &bp->tx_buf_ring[TX_RING_IDX(sw_cons)],
  1075. mapping),
  1076. skb_shinfo(skb)->frags[i].size,
  1077. PCI_DMA_TODEVICE);
  1078. }
  1079. sw_cons = NEXT_TX_BD(sw_cons);
  1080. tx_free_bd += last + 1;
  1081. dev_kfree_skb_irq(skb);
  1082. hw_cons = bp->status_blk->status_tx_quick_consumer_index0;
  1083. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1084. hw_cons++;
  1085. }
  1086. }
  1087. atomic_add(tx_free_bd, &bp->tx_avail_bd);
  1088. if (unlikely(netif_queue_stopped(bp->dev))) {
  1089. unsigned long flags;
  1090. spin_lock_irqsave(&bp->tx_lock, flags);
  1091. if ((netif_queue_stopped(bp->dev)) &&
  1092. (atomic_read(&bp->tx_avail_bd) > MAX_SKB_FRAGS)) {
  1093. netif_wake_queue(bp->dev);
  1094. }
  1095. spin_unlock_irqrestore(&bp->tx_lock, flags);
  1096. }
  1097. bp->tx_cons = sw_cons;
  1098. }
  1099. static inline void
  1100. bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
  1101. u16 cons, u16 prod)
  1102. {
  1103. struct sw_bd *cons_rx_buf = &bp->rx_buf_ring[cons];
  1104. struct sw_bd *prod_rx_buf = &bp->rx_buf_ring[prod];
  1105. struct rx_bd *cons_bd = &bp->rx_desc_ring[cons];
  1106. struct rx_bd *prod_bd = &bp->rx_desc_ring[prod];
  1107. pci_dma_sync_single_for_device(bp->pdev,
  1108. pci_unmap_addr(cons_rx_buf, mapping),
  1109. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1110. prod_rx_buf->skb = cons_rx_buf->skb;
  1111. pci_unmap_addr_set(prod_rx_buf, mapping,
  1112. pci_unmap_addr(cons_rx_buf, mapping));
  1113. memcpy(prod_bd, cons_bd, 8);
  1114. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1115. }
  1116. static int
  1117. bnx2_rx_int(struct bnx2 *bp, int budget)
  1118. {
  1119. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  1120. struct l2_fhdr *rx_hdr;
  1121. int rx_pkt = 0;
  1122. hw_cons = bp->status_blk->status_rx_quick_consumer_index0;
  1123. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
  1124. hw_cons++;
  1125. }
  1126. sw_cons = bp->rx_cons;
  1127. sw_prod = bp->rx_prod;
  1128. /* Memory barrier necessary as speculative reads of the rx
  1129. * buffer can be ahead of the index in the status block
  1130. */
  1131. rmb();
  1132. while (sw_cons != hw_cons) {
  1133. unsigned int len;
  1134. u16 status;
  1135. struct sw_bd *rx_buf;
  1136. struct sk_buff *skb;
  1137. sw_ring_cons = RX_RING_IDX(sw_cons);
  1138. sw_ring_prod = RX_RING_IDX(sw_prod);
  1139. rx_buf = &bp->rx_buf_ring[sw_ring_cons];
  1140. skb = rx_buf->skb;
  1141. pci_dma_sync_single_for_cpu(bp->pdev,
  1142. pci_unmap_addr(rx_buf, mapping),
  1143. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1144. rx_hdr = (struct l2_fhdr *) skb->data;
  1145. len = rx_hdr->l2_fhdr_pkt_len - 4;
  1146. if (rx_hdr->l2_fhdr_errors &
  1147. (L2_FHDR_ERRORS_BAD_CRC |
  1148. L2_FHDR_ERRORS_PHY_DECODE |
  1149. L2_FHDR_ERRORS_ALIGNMENT |
  1150. L2_FHDR_ERRORS_TOO_SHORT |
  1151. L2_FHDR_ERRORS_GIANT_FRAME)) {
  1152. goto reuse_rx;
  1153. }
  1154. /* Since we don't have a jumbo ring, copy small packets
  1155. * if mtu > 1500
  1156. */
  1157. if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
  1158. struct sk_buff *new_skb;
  1159. new_skb = dev_alloc_skb(len + 2);
  1160. if (new_skb == NULL)
  1161. goto reuse_rx;
  1162. /* aligned copy */
  1163. memcpy(new_skb->data,
  1164. skb->data + bp->rx_offset - 2,
  1165. len + 2);
  1166. skb_reserve(new_skb, 2);
  1167. skb_put(new_skb, len);
  1168. new_skb->dev = bp->dev;
  1169. bnx2_reuse_rx_skb(bp, skb,
  1170. sw_ring_cons, sw_ring_prod);
  1171. skb = new_skb;
  1172. }
  1173. else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
  1174. pci_unmap_single(bp->pdev,
  1175. pci_unmap_addr(rx_buf, mapping),
  1176. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  1177. skb_reserve(skb, bp->rx_offset);
  1178. skb_put(skb, len);
  1179. }
  1180. else {
  1181. reuse_rx:
  1182. bnx2_reuse_rx_skb(bp, skb,
  1183. sw_ring_cons, sw_ring_prod);
  1184. goto next_rx;
  1185. }
  1186. skb->protocol = eth_type_trans(skb, bp->dev);
  1187. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  1188. (htons(skb->protocol) != 0x8100)) {
  1189. dev_kfree_skb_irq(skb);
  1190. goto next_rx;
  1191. }
  1192. status = rx_hdr->l2_fhdr_status;
  1193. skb->ip_summed = CHECKSUM_NONE;
  1194. if (bp->rx_csum &&
  1195. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  1196. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  1197. u16 cksum = rx_hdr->l2_fhdr_tcp_udp_xsum;
  1198. if (cksum == 0xffff)
  1199. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1200. }
  1201. #ifdef BCM_VLAN
  1202. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) && (bp->vlgrp != 0)) {
  1203. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1204. rx_hdr->l2_fhdr_vlan_tag);
  1205. }
  1206. else
  1207. #endif
  1208. netif_receive_skb(skb);
  1209. bp->dev->last_rx = jiffies;
  1210. rx_pkt++;
  1211. next_rx:
  1212. rx_buf->skb = NULL;
  1213. sw_cons = NEXT_RX_BD(sw_cons);
  1214. sw_prod = NEXT_RX_BD(sw_prod);
  1215. if ((rx_pkt == budget))
  1216. break;
  1217. }
  1218. bp->rx_cons = sw_cons;
  1219. bp->rx_prod = sw_prod;
  1220. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, sw_prod);
  1221. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  1222. mmiowb();
  1223. return rx_pkt;
  1224. }
  1225. /* MSI ISR - The only difference between this and the INTx ISR
  1226. * is that the MSI interrupt is always serviced.
  1227. */
  1228. static irqreturn_t
  1229. bnx2_msi(int irq, void *dev_instance, struct pt_regs *regs)
  1230. {
  1231. struct net_device *dev = dev_instance;
  1232. struct bnx2 *bp = dev->priv;
  1233. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1234. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1235. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1236. /* Return here if interrupt is disabled. */
  1237. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1238. return IRQ_RETVAL(1);
  1239. }
  1240. if (netif_rx_schedule_prep(dev)) {
  1241. __netif_rx_schedule(dev);
  1242. }
  1243. return IRQ_RETVAL(1);
  1244. }
  1245. static irqreturn_t
  1246. bnx2_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
  1247. {
  1248. struct net_device *dev = dev_instance;
  1249. struct bnx2 *bp = dev->priv;
  1250. /* When using INTx, it is possible for the interrupt to arrive
  1251. * at the CPU before the status block posted prior to the
  1252. * interrupt. Reading a register will flush the status block.
  1253. * When using MSI, the MSI message will always complete after
  1254. * the status block write.
  1255. */
  1256. if ((bp->status_blk->status_idx == bp->last_status_idx) ||
  1257. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  1258. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  1259. return IRQ_RETVAL(0);
  1260. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1261. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1262. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1263. /* Return here if interrupt is shared and is disabled. */
  1264. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1265. return IRQ_RETVAL(1);
  1266. }
  1267. if (netif_rx_schedule_prep(dev)) {
  1268. __netif_rx_schedule(dev);
  1269. }
  1270. return IRQ_RETVAL(1);
  1271. }
  1272. static int
  1273. bnx2_poll(struct net_device *dev, int *budget)
  1274. {
  1275. struct bnx2 *bp = dev->priv;
  1276. int rx_done = 1;
  1277. bp->last_status_idx = bp->status_blk->status_idx;
  1278. rmb();
  1279. if ((bp->status_blk->status_attn_bits &
  1280. STATUS_ATTN_BITS_LINK_STATE) !=
  1281. (bp->status_blk->status_attn_bits_ack &
  1282. STATUS_ATTN_BITS_LINK_STATE)) {
  1283. unsigned long flags;
  1284. spin_lock_irqsave(&bp->phy_lock, flags);
  1285. bnx2_phy_int(bp);
  1286. spin_unlock_irqrestore(&bp->phy_lock, flags);
  1287. }
  1288. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->tx_cons) {
  1289. bnx2_tx_int(bp);
  1290. }
  1291. if (bp->status_blk->status_rx_quick_consumer_index0 != bp->rx_cons) {
  1292. int orig_budget = *budget;
  1293. int work_done;
  1294. if (orig_budget > dev->quota)
  1295. orig_budget = dev->quota;
  1296. work_done = bnx2_rx_int(bp, orig_budget);
  1297. *budget -= work_done;
  1298. dev->quota -= work_done;
  1299. if (work_done >= orig_budget) {
  1300. rx_done = 0;
  1301. }
  1302. }
  1303. if (rx_done) {
  1304. netif_rx_complete(dev);
  1305. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1306. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1307. bp->last_status_idx);
  1308. return 0;
  1309. }
  1310. return 1;
  1311. }
  1312. /* Called with rtnl_lock from vlan functions and also dev->xmit_lock
  1313. * from set_multicast.
  1314. */
  1315. static void
  1316. bnx2_set_rx_mode(struct net_device *dev)
  1317. {
  1318. struct bnx2 *bp = dev->priv;
  1319. u32 rx_mode, sort_mode;
  1320. int i;
  1321. unsigned long flags;
  1322. spin_lock_irqsave(&bp->phy_lock, flags);
  1323. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  1324. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  1325. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  1326. #ifdef BCM_VLAN
  1327. if (!bp->vlgrp) {
  1328. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1329. }
  1330. #else
  1331. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1332. #endif
  1333. if (dev->flags & IFF_PROMISC) {
  1334. /* Promiscuous mode. */
  1335. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  1336. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN;
  1337. }
  1338. else if (dev->flags & IFF_ALLMULTI) {
  1339. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1340. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1341. 0xffffffff);
  1342. }
  1343. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  1344. }
  1345. else {
  1346. /* Accept one or more multicast(s). */
  1347. struct dev_mc_list *mclist;
  1348. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  1349. u32 regidx;
  1350. u32 bit;
  1351. u32 crc;
  1352. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  1353. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1354. i++, mclist = mclist->next) {
  1355. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  1356. bit = crc & 0xff;
  1357. regidx = (bit & 0xe0) >> 5;
  1358. bit &= 0x1f;
  1359. mc_filter[regidx] |= (1 << bit);
  1360. }
  1361. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1362. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1363. mc_filter[i]);
  1364. }
  1365. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  1366. }
  1367. if (rx_mode != bp->rx_mode) {
  1368. bp->rx_mode = rx_mode;
  1369. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  1370. }
  1371. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1372. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  1373. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  1374. spin_unlock_irqrestore(&bp->phy_lock, flags);
  1375. }
  1376. static void
  1377. load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
  1378. u32 rv2p_proc)
  1379. {
  1380. int i;
  1381. u32 val;
  1382. for (i = 0; i < rv2p_code_len; i += 8) {
  1383. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, *rv2p_code);
  1384. rv2p_code++;
  1385. REG_WR(bp, BNX2_RV2P_INSTR_LOW, *rv2p_code);
  1386. rv2p_code++;
  1387. if (rv2p_proc == RV2P_PROC1) {
  1388. val = (i / 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  1389. REG_WR(bp, BNX2_RV2P_PROC1_ADDR_CMD, val);
  1390. }
  1391. else {
  1392. val = (i / 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  1393. REG_WR(bp, BNX2_RV2P_PROC2_ADDR_CMD, val);
  1394. }
  1395. }
  1396. /* Reset the processor, un-stall is done later. */
  1397. if (rv2p_proc == RV2P_PROC1) {
  1398. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  1399. }
  1400. else {
  1401. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  1402. }
  1403. }
  1404. static void
  1405. load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
  1406. {
  1407. u32 offset;
  1408. u32 val;
  1409. /* Halt the CPU. */
  1410. val = REG_RD_IND(bp, cpu_reg->mode);
  1411. val |= cpu_reg->mode_value_halt;
  1412. REG_WR_IND(bp, cpu_reg->mode, val);
  1413. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1414. /* Load the Text area. */
  1415. offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
  1416. if (fw->text) {
  1417. int j;
  1418. for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
  1419. REG_WR_IND(bp, offset, fw->text[j]);
  1420. }
  1421. }
  1422. /* Load the Data area. */
  1423. offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
  1424. if (fw->data) {
  1425. int j;
  1426. for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
  1427. REG_WR_IND(bp, offset, fw->data[j]);
  1428. }
  1429. }
  1430. /* Load the SBSS area. */
  1431. offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
  1432. if (fw->sbss) {
  1433. int j;
  1434. for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
  1435. REG_WR_IND(bp, offset, fw->sbss[j]);
  1436. }
  1437. }
  1438. /* Load the BSS area. */
  1439. offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
  1440. if (fw->bss) {
  1441. int j;
  1442. for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
  1443. REG_WR_IND(bp, offset, fw->bss[j]);
  1444. }
  1445. }
  1446. /* Load the Read-Only area. */
  1447. offset = cpu_reg->spad_base +
  1448. (fw->rodata_addr - cpu_reg->mips_view_base);
  1449. if (fw->rodata) {
  1450. int j;
  1451. for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
  1452. REG_WR_IND(bp, offset, fw->rodata[j]);
  1453. }
  1454. }
  1455. /* Clear the pre-fetch instruction. */
  1456. REG_WR_IND(bp, cpu_reg->inst, 0);
  1457. REG_WR_IND(bp, cpu_reg->pc, fw->start_addr);
  1458. /* Start the CPU. */
  1459. val = REG_RD_IND(bp, cpu_reg->mode);
  1460. val &= ~cpu_reg->mode_value_halt;
  1461. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1462. REG_WR_IND(bp, cpu_reg->mode, val);
  1463. }
  1464. static void
  1465. bnx2_init_cpus(struct bnx2 *bp)
  1466. {
  1467. struct cpu_reg cpu_reg;
  1468. struct fw_info fw;
  1469. /* Initialize the RV2P processor. */
  1470. load_rv2p_fw(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), RV2P_PROC1);
  1471. load_rv2p_fw(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), RV2P_PROC2);
  1472. /* Initialize the RX Processor. */
  1473. cpu_reg.mode = BNX2_RXP_CPU_MODE;
  1474. cpu_reg.mode_value_halt = BNX2_RXP_CPU_MODE_SOFT_HALT;
  1475. cpu_reg.mode_value_sstep = BNX2_RXP_CPU_MODE_STEP_ENA;
  1476. cpu_reg.state = BNX2_RXP_CPU_STATE;
  1477. cpu_reg.state_value_clear = 0xffffff;
  1478. cpu_reg.gpr0 = BNX2_RXP_CPU_REG_FILE;
  1479. cpu_reg.evmask = BNX2_RXP_CPU_EVENT_MASK;
  1480. cpu_reg.pc = BNX2_RXP_CPU_PROGRAM_COUNTER;
  1481. cpu_reg.inst = BNX2_RXP_CPU_INSTRUCTION;
  1482. cpu_reg.bp = BNX2_RXP_CPU_HW_BREAKPOINT;
  1483. cpu_reg.spad_base = BNX2_RXP_SCRATCH;
  1484. cpu_reg.mips_view_base = 0x8000000;
  1485. fw.ver_major = bnx2_RXP_b06FwReleaseMajor;
  1486. fw.ver_minor = bnx2_RXP_b06FwReleaseMinor;
  1487. fw.ver_fix = bnx2_RXP_b06FwReleaseFix;
  1488. fw.start_addr = bnx2_RXP_b06FwStartAddr;
  1489. fw.text_addr = bnx2_RXP_b06FwTextAddr;
  1490. fw.text_len = bnx2_RXP_b06FwTextLen;
  1491. fw.text_index = 0;
  1492. fw.text = bnx2_RXP_b06FwText;
  1493. fw.data_addr = bnx2_RXP_b06FwDataAddr;
  1494. fw.data_len = bnx2_RXP_b06FwDataLen;
  1495. fw.data_index = 0;
  1496. fw.data = bnx2_RXP_b06FwData;
  1497. fw.sbss_addr = bnx2_RXP_b06FwSbssAddr;
  1498. fw.sbss_len = bnx2_RXP_b06FwSbssLen;
  1499. fw.sbss_index = 0;
  1500. fw.sbss = bnx2_RXP_b06FwSbss;
  1501. fw.bss_addr = bnx2_RXP_b06FwBssAddr;
  1502. fw.bss_len = bnx2_RXP_b06FwBssLen;
  1503. fw.bss_index = 0;
  1504. fw.bss = bnx2_RXP_b06FwBss;
  1505. fw.rodata_addr = bnx2_RXP_b06FwRodataAddr;
  1506. fw.rodata_len = bnx2_RXP_b06FwRodataLen;
  1507. fw.rodata_index = 0;
  1508. fw.rodata = bnx2_RXP_b06FwRodata;
  1509. load_cpu_fw(bp, &cpu_reg, &fw);
  1510. /* Initialize the TX Processor. */
  1511. cpu_reg.mode = BNX2_TXP_CPU_MODE;
  1512. cpu_reg.mode_value_halt = BNX2_TXP_CPU_MODE_SOFT_HALT;
  1513. cpu_reg.mode_value_sstep = BNX2_TXP_CPU_MODE_STEP_ENA;
  1514. cpu_reg.state = BNX2_TXP_CPU_STATE;
  1515. cpu_reg.state_value_clear = 0xffffff;
  1516. cpu_reg.gpr0 = BNX2_TXP_CPU_REG_FILE;
  1517. cpu_reg.evmask = BNX2_TXP_CPU_EVENT_MASK;
  1518. cpu_reg.pc = BNX2_TXP_CPU_PROGRAM_COUNTER;
  1519. cpu_reg.inst = BNX2_TXP_CPU_INSTRUCTION;
  1520. cpu_reg.bp = BNX2_TXP_CPU_HW_BREAKPOINT;
  1521. cpu_reg.spad_base = BNX2_TXP_SCRATCH;
  1522. cpu_reg.mips_view_base = 0x8000000;
  1523. fw.ver_major = bnx2_TXP_b06FwReleaseMajor;
  1524. fw.ver_minor = bnx2_TXP_b06FwReleaseMinor;
  1525. fw.ver_fix = bnx2_TXP_b06FwReleaseFix;
  1526. fw.start_addr = bnx2_TXP_b06FwStartAddr;
  1527. fw.text_addr = bnx2_TXP_b06FwTextAddr;
  1528. fw.text_len = bnx2_TXP_b06FwTextLen;
  1529. fw.text_index = 0;
  1530. fw.text = bnx2_TXP_b06FwText;
  1531. fw.data_addr = bnx2_TXP_b06FwDataAddr;
  1532. fw.data_len = bnx2_TXP_b06FwDataLen;
  1533. fw.data_index = 0;
  1534. fw.data = bnx2_TXP_b06FwData;
  1535. fw.sbss_addr = bnx2_TXP_b06FwSbssAddr;
  1536. fw.sbss_len = bnx2_TXP_b06FwSbssLen;
  1537. fw.sbss_index = 0;
  1538. fw.sbss = bnx2_TXP_b06FwSbss;
  1539. fw.bss_addr = bnx2_TXP_b06FwBssAddr;
  1540. fw.bss_len = bnx2_TXP_b06FwBssLen;
  1541. fw.bss_index = 0;
  1542. fw.bss = bnx2_TXP_b06FwBss;
  1543. fw.rodata_addr = bnx2_TXP_b06FwRodataAddr;
  1544. fw.rodata_len = bnx2_TXP_b06FwRodataLen;
  1545. fw.rodata_index = 0;
  1546. fw.rodata = bnx2_TXP_b06FwRodata;
  1547. load_cpu_fw(bp, &cpu_reg, &fw);
  1548. /* Initialize the TX Patch-up Processor. */
  1549. cpu_reg.mode = BNX2_TPAT_CPU_MODE;
  1550. cpu_reg.mode_value_halt = BNX2_TPAT_CPU_MODE_SOFT_HALT;
  1551. cpu_reg.mode_value_sstep = BNX2_TPAT_CPU_MODE_STEP_ENA;
  1552. cpu_reg.state = BNX2_TPAT_CPU_STATE;
  1553. cpu_reg.state_value_clear = 0xffffff;
  1554. cpu_reg.gpr0 = BNX2_TPAT_CPU_REG_FILE;
  1555. cpu_reg.evmask = BNX2_TPAT_CPU_EVENT_MASK;
  1556. cpu_reg.pc = BNX2_TPAT_CPU_PROGRAM_COUNTER;
  1557. cpu_reg.inst = BNX2_TPAT_CPU_INSTRUCTION;
  1558. cpu_reg.bp = BNX2_TPAT_CPU_HW_BREAKPOINT;
  1559. cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
  1560. cpu_reg.mips_view_base = 0x8000000;
  1561. fw.ver_major = bnx2_TPAT_b06FwReleaseMajor;
  1562. fw.ver_minor = bnx2_TPAT_b06FwReleaseMinor;
  1563. fw.ver_fix = bnx2_TPAT_b06FwReleaseFix;
  1564. fw.start_addr = bnx2_TPAT_b06FwStartAddr;
  1565. fw.text_addr = bnx2_TPAT_b06FwTextAddr;
  1566. fw.text_len = bnx2_TPAT_b06FwTextLen;
  1567. fw.text_index = 0;
  1568. fw.text = bnx2_TPAT_b06FwText;
  1569. fw.data_addr = bnx2_TPAT_b06FwDataAddr;
  1570. fw.data_len = bnx2_TPAT_b06FwDataLen;
  1571. fw.data_index = 0;
  1572. fw.data = bnx2_TPAT_b06FwData;
  1573. fw.sbss_addr = bnx2_TPAT_b06FwSbssAddr;
  1574. fw.sbss_len = bnx2_TPAT_b06FwSbssLen;
  1575. fw.sbss_index = 0;
  1576. fw.sbss = bnx2_TPAT_b06FwSbss;
  1577. fw.bss_addr = bnx2_TPAT_b06FwBssAddr;
  1578. fw.bss_len = bnx2_TPAT_b06FwBssLen;
  1579. fw.bss_index = 0;
  1580. fw.bss = bnx2_TPAT_b06FwBss;
  1581. fw.rodata_addr = bnx2_TPAT_b06FwRodataAddr;
  1582. fw.rodata_len = bnx2_TPAT_b06FwRodataLen;
  1583. fw.rodata_index = 0;
  1584. fw.rodata = bnx2_TPAT_b06FwRodata;
  1585. load_cpu_fw(bp, &cpu_reg, &fw);
  1586. /* Initialize the Completion Processor. */
  1587. cpu_reg.mode = BNX2_COM_CPU_MODE;
  1588. cpu_reg.mode_value_halt = BNX2_COM_CPU_MODE_SOFT_HALT;
  1589. cpu_reg.mode_value_sstep = BNX2_COM_CPU_MODE_STEP_ENA;
  1590. cpu_reg.state = BNX2_COM_CPU_STATE;
  1591. cpu_reg.state_value_clear = 0xffffff;
  1592. cpu_reg.gpr0 = BNX2_COM_CPU_REG_FILE;
  1593. cpu_reg.evmask = BNX2_COM_CPU_EVENT_MASK;
  1594. cpu_reg.pc = BNX2_COM_CPU_PROGRAM_COUNTER;
  1595. cpu_reg.inst = BNX2_COM_CPU_INSTRUCTION;
  1596. cpu_reg.bp = BNX2_COM_CPU_HW_BREAKPOINT;
  1597. cpu_reg.spad_base = BNX2_COM_SCRATCH;
  1598. cpu_reg.mips_view_base = 0x8000000;
  1599. fw.ver_major = bnx2_COM_b06FwReleaseMajor;
  1600. fw.ver_minor = bnx2_COM_b06FwReleaseMinor;
  1601. fw.ver_fix = bnx2_COM_b06FwReleaseFix;
  1602. fw.start_addr = bnx2_COM_b06FwStartAddr;
  1603. fw.text_addr = bnx2_COM_b06FwTextAddr;
  1604. fw.text_len = bnx2_COM_b06FwTextLen;
  1605. fw.text_index = 0;
  1606. fw.text = bnx2_COM_b06FwText;
  1607. fw.data_addr = bnx2_COM_b06FwDataAddr;
  1608. fw.data_len = bnx2_COM_b06FwDataLen;
  1609. fw.data_index = 0;
  1610. fw.data = bnx2_COM_b06FwData;
  1611. fw.sbss_addr = bnx2_COM_b06FwSbssAddr;
  1612. fw.sbss_len = bnx2_COM_b06FwSbssLen;
  1613. fw.sbss_index = 0;
  1614. fw.sbss = bnx2_COM_b06FwSbss;
  1615. fw.bss_addr = bnx2_COM_b06FwBssAddr;
  1616. fw.bss_len = bnx2_COM_b06FwBssLen;
  1617. fw.bss_index = 0;
  1618. fw.bss = bnx2_COM_b06FwBss;
  1619. fw.rodata_addr = bnx2_COM_b06FwRodataAddr;
  1620. fw.rodata_len = bnx2_COM_b06FwRodataLen;
  1621. fw.rodata_index = 0;
  1622. fw.rodata = bnx2_COM_b06FwRodata;
  1623. load_cpu_fw(bp, &cpu_reg, &fw);
  1624. }
  1625. static int
  1626. bnx2_set_power_state(struct bnx2 *bp, int state)
  1627. {
  1628. u16 pmcsr;
  1629. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  1630. switch (state) {
  1631. case 0: {
  1632. u32 val;
  1633. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1634. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  1635. PCI_PM_CTRL_PME_STATUS);
  1636. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  1637. /* delay required during transition out of D3hot */
  1638. msleep(20);
  1639. val = REG_RD(bp, BNX2_EMAC_MODE);
  1640. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  1641. val &= ~BNX2_EMAC_MODE_MPKT;
  1642. REG_WR(bp, BNX2_EMAC_MODE, val);
  1643. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1644. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1645. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1646. break;
  1647. }
  1648. case 3: {
  1649. int i;
  1650. u32 val, wol_msg;
  1651. if (bp->wol) {
  1652. u32 advertising;
  1653. u8 autoneg;
  1654. autoneg = bp->autoneg;
  1655. advertising = bp->advertising;
  1656. bp->autoneg = AUTONEG_SPEED;
  1657. bp->advertising = ADVERTISED_10baseT_Half |
  1658. ADVERTISED_10baseT_Full |
  1659. ADVERTISED_100baseT_Half |
  1660. ADVERTISED_100baseT_Full |
  1661. ADVERTISED_Autoneg;
  1662. bnx2_setup_copper_phy(bp);
  1663. bp->autoneg = autoneg;
  1664. bp->advertising = advertising;
  1665. bnx2_set_mac_addr(bp);
  1666. val = REG_RD(bp, BNX2_EMAC_MODE);
  1667. /* Enable port mode. */
  1668. val &= ~BNX2_EMAC_MODE_PORT;
  1669. val |= BNX2_EMAC_MODE_PORT_MII |
  1670. BNX2_EMAC_MODE_MPKT_RCVD |
  1671. BNX2_EMAC_MODE_ACPI_RCVD |
  1672. BNX2_EMAC_MODE_FORCE_LINK |
  1673. BNX2_EMAC_MODE_MPKT;
  1674. REG_WR(bp, BNX2_EMAC_MODE, val);
  1675. /* receive all multicast */
  1676. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1677. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1678. 0xffffffff);
  1679. }
  1680. REG_WR(bp, BNX2_EMAC_RX_MODE,
  1681. BNX2_EMAC_RX_MODE_SORT_MODE);
  1682. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  1683. BNX2_RPM_SORT_USER0_MC_EN;
  1684. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1685. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  1686. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  1687. BNX2_RPM_SORT_USER0_ENA);
  1688. /* Need to enable EMAC and RPM for WOL. */
  1689. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1690. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  1691. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  1692. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  1693. val = REG_RD(bp, BNX2_RPM_CONFIG);
  1694. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  1695. REG_WR(bp, BNX2_RPM_CONFIG, val);
  1696. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  1697. }
  1698. else {
  1699. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  1700. }
  1701. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg);
  1702. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  1703. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  1704. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  1705. if (bp->wol)
  1706. pmcsr |= 3;
  1707. }
  1708. else {
  1709. pmcsr |= 3;
  1710. }
  1711. if (bp->wol) {
  1712. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  1713. }
  1714. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  1715. pmcsr);
  1716. /* No more memory access after this point until
  1717. * device is brought back to D0.
  1718. */
  1719. udelay(50);
  1720. break;
  1721. }
  1722. default:
  1723. return -EINVAL;
  1724. }
  1725. return 0;
  1726. }
  1727. static int
  1728. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  1729. {
  1730. u32 val;
  1731. int j;
  1732. /* Request access to the flash interface. */
  1733. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  1734. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1735. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  1736. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  1737. break;
  1738. udelay(5);
  1739. }
  1740. if (j >= NVRAM_TIMEOUT_COUNT)
  1741. return -EBUSY;
  1742. return 0;
  1743. }
  1744. static int
  1745. bnx2_release_nvram_lock(struct bnx2 *bp)
  1746. {
  1747. int j;
  1748. u32 val;
  1749. /* Relinquish nvram interface. */
  1750. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  1751. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1752. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  1753. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  1754. break;
  1755. udelay(5);
  1756. }
  1757. if (j >= NVRAM_TIMEOUT_COUNT)
  1758. return -EBUSY;
  1759. return 0;
  1760. }
  1761. static int
  1762. bnx2_enable_nvram_write(struct bnx2 *bp)
  1763. {
  1764. u32 val;
  1765. val = REG_RD(bp, BNX2_MISC_CFG);
  1766. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  1767. if (!bp->flash_info->buffered) {
  1768. int j;
  1769. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1770. REG_WR(bp, BNX2_NVM_COMMAND,
  1771. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  1772. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1773. udelay(5);
  1774. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1775. if (val & BNX2_NVM_COMMAND_DONE)
  1776. break;
  1777. }
  1778. if (j >= NVRAM_TIMEOUT_COUNT)
  1779. return -EBUSY;
  1780. }
  1781. return 0;
  1782. }
  1783. static void
  1784. bnx2_disable_nvram_write(struct bnx2 *bp)
  1785. {
  1786. u32 val;
  1787. val = REG_RD(bp, BNX2_MISC_CFG);
  1788. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  1789. }
  1790. static void
  1791. bnx2_enable_nvram_access(struct bnx2 *bp)
  1792. {
  1793. u32 val;
  1794. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  1795. /* Enable both bits, even on read. */
  1796. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  1797. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  1798. }
  1799. static void
  1800. bnx2_disable_nvram_access(struct bnx2 *bp)
  1801. {
  1802. u32 val;
  1803. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  1804. /* Disable both bits, even after read. */
  1805. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  1806. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  1807. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  1808. }
  1809. static int
  1810. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  1811. {
  1812. u32 cmd;
  1813. int j;
  1814. if (bp->flash_info->buffered)
  1815. /* Buffered flash, no erase needed */
  1816. return 0;
  1817. /* Build an erase command */
  1818. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  1819. BNX2_NVM_COMMAND_DOIT;
  1820. /* Need to clear DONE bit separately. */
  1821. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1822. /* Address of the NVRAM to read from. */
  1823. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1824. /* Issue an erase command. */
  1825. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1826. /* Wait for completion. */
  1827. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1828. u32 val;
  1829. udelay(5);
  1830. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1831. if (val & BNX2_NVM_COMMAND_DONE)
  1832. break;
  1833. }
  1834. if (j >= NVRAM_TIMEOUT_COUNT)
  1835. return -EBUSY;
  1836. return 0;
  1837. }
  1838. static int
  1839. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  1840. {
  1841. u32 cmd;
  1842. int j;
  1843. /* Build the command word. */
  1844. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  1845. /* Calculate an offset of a buffered flash. */
  1846. if (bp->flash_info->buffered) {
  1847. offset = ((offset / bp->flash_info->page_size) <<
  1848. bp->flash_info->page_bits) +
  1849. (offset % bp->flash_info->page_size);
  1850. }
  1851. /* Need to clear DONE bit separately. */
  1852. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1853. /* Address of the NVRAM to read from. */
  1854. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1855. /* Issue a read command. */
  1856. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1857. /* Wait for completion. */
  1858. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1859. u32 val;
  1860. udelay(5);
  1861. val = REG_RD(bp, BNX2_NVM_COMMAND);
  1862. if (val & BNX2_NVM_COMMAND_DONE) {
  1863. val = REG_RD(bp, BNX2_NVM_READ);
  1864. val = be32_to_cpu(val);
  1865. memcpy(ret_val, &val, 4);
  1866. break;
  1867. }
  1868. }
  1869. if (j >= NVRAM_TIMEOUT_COUNT)
  1870. return -EBUSY;
  1871. return 0;
  1872. }
  1873. static int
  1874. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  1875. {
  1876. u32 cmd, val32;
  1877. int j;
  1878. /* Build the command word. */
  1879. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  1880. /* Calculate an offset of a buffered flash. */
  1881. if (bp->flash_info->buffered) {
  1882. offset = ((offset / bp->flash_info->page_size) <<
  1883. bp->flash_info->page_bits) +
  1884. (offset % bp->flash_info->page_size);
  1885. }
  1886. /* Need to clear DONE bit separately. */
  1887. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  1888. memcpy(&val32, val, 4);
  1889. val32 = cpu_to_be32(val32);
  1890. /* Write the data. */
  1891. REG_WR(bp, BNX2_NVM_WRITE, val32);
  1892. /* Address of the NVRAM to write to. */
  1893. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  1894. /* Issue the write command. */
  1895. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  1896. /* Wait for completion. */
  1897. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  1898. udelay(5);
  1899. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  1900. break;
  1901. }
  1902. if (j >= NVRAM_TIMEOUT_COUNT)
  1903. return -EBUSY;
  1904. return 0;
  1905. }
  1906. static int
  1907. bnx2_init_nvram(struct bnx2 *bp)
  1908. {
  1909. u32 val;
  1910. int j, entry_count, rc;
  1911. struct flash_spec *flash;
  1912. /* Determine the selected interface. */
  1913. val = REG_RD(bp, BNX2_NVM_CFG1);
  1914. entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
  1915. rc = 0;
  1916. if (val & 0x40000000) {
  1917. /* Flash interface has been reconfigured */
  1918. for (j = 0, flash = &flash_table[0]; j < entry_count;
  1919. j++, flash++) {
  1920. if (val == flash->config1) {
  1921. bp->flash_info = flash;
  1922. break;
  1923. }
  1924. }
  1925. }
  1926. else {
  1927. /* Not yet been reconfigured */
  1928. for (j = 0, flash = &flash_table[0]; j < entry_count;
  1929. j++, flash++) {
  1930. if ((val & FLASH_STRAP_MASK) == flash->strapping) {
  1931. bp->flash_info = flash;
  1932. /* Request access to the flash interface. */
  1933. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  1934. return rc;
  1935. /* Enable access to flash interface */
  1936. bnx2_enable_nvram_access(bp);
  1937. /* Reconfigure the flash interface */
  1938. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  1939. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  1940. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  1941. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  1942. /* Disable access to flash interface */
  1943. bnx2_disable_nvram_access(bp);
  1944. bnx2_release_nvram_lock(bp);
  1945. break;
  1946. }
  1947. }
  1948. } /* if (val & 0x40000000) */
  1949. if (j == entry_count) {
  1950. bp->flash_info = NULL;
  1951. printk(KERN_ALERT "Unknown flash/EEPROM type.\n");
  1952. rc = -ENODEV;
  1953. }
  1954. return rc;
  1955. }
  1956. static int
  1957. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  1958. int buf_size)
  1959. {
  1960. int rc = 0;
  1961. u32 cmd_flags, offset32, len32, extra;
  1962. if (buf_size == 0)
  1963. return 0;
  1964. /* Request access to the flash interface. */
  1965. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  1966. return rc;
  1967. /* Enable access to flash interface */
  1968. bnx2_enable_nvram_access(bp);
  1969. len32 = buf_size;
  1970. offset32 = offset;
  1971. extra = 0;
  1972. cmd_flags = 0;
  1973. if (offset32 & 3) {
  1974. u8 buf[4];
  1975. u32 pre_len;
  1976. offset32 &= ~3;
  1977. pre_len = 4 - (offset & 3);
  1978. if (pre_len >= len32) {
  1979. pre_len = len32;
  1980. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  1981. BNX2_NVM_COMMAND_LAST;
  1982. }
  1983. else {
  1984. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  1985. }
  1986. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  1987. if (rc)
  1988. return rc;
  1989. memcpy(ret_buf, buf + (offset & 3), pre_len);
  1990. offset32 += 4;
  1991. ret_buf += pre_len;
  1992. len32 -= pre_len;
  1993. }
  1994. if (len32 & 3) {
  1995. extra = 4 - (len32 & 3);
  1996. len32 = (len32 + 4) & ~3;
  1997. }
  1998. if (len32 == 4) {
  1999. u8 buf[4];
  2000. if (cmd_flags)
  2001. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2002. else
  2003. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2004. BNX2_NVM_COMMAND_LAST;
  2005. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2006. memcpy(ret_buf, buf, 4 - extra);
  2007. }
  2008. else if (len32 > 0) {
  2009. u8 buf[4];
  2010. /* Read the first word. */
  2011. if (cmd_flags)
  2012. cmd_flags = 0;
  2013. else
  2014. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2015. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  2016. /* Advance to the next dword. */
  2017. offset32 += 4;
  2018. ret_buf += 4;
  2019. len32 -= 4;
  2020. while (len32 > 4 && rc == 0) {
  2021. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  2022. /* Advance to the next dword. */
  2023. offset32 += 4;
  2024. ret_buf += 4;
  2025. len32 -= 4;
  2026. }
  2027. if (rc)
  2028. return rc;
  2029. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2030. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2031. memcpy(ret_buf, buf, 4 - extra);
  2032. }
  2033. /* Disable access to flash interface */
  2034. bnx2_disable_nvram_access(bp);
  2035. bnx2_release_nvram_lock(bp);
  2036. return rc;
  2037. }
  2038. static int
  2039. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  2040. int buf_size)
  2041. {
  2042. u32 written, offset32, len32;
  2043. u8 *buf, start[4], end[4];
  2044. int rc = 0;
  2045. int align_start, align_end;
  2046. buf = data_buf;
  2047. offset32 = offset;
  2048. len32 = buf_size;
  2049. align_start = align_end = 0;
  2050. if ((align_start = (offset32 & 3))) {
  2051. offset32 &= ~3;
  2052. len32 += align_start;
  2053. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  2054. return rc;
  2055. }
  2056. if (len32 & 3) {
  2057. if ((len32 > 4) || !align_start) {
  2058. align_end = 4 - (len32 & 3);
  2059. len32 += align_end;
  2060. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4,
  2061. end, 4))) {
  2062. return rc;
  2063. }
  2064. }
  2065. }
  2066. if (align_start || align_end) {
  2067. buf = kmalloc(len32, GFP_KERNEL);
  2068. if (buf == 0)
  2069. return -ENOMEM;
  2070. if (align_start) {
  2071. memcpy(buf, start, 4);
  2072. }
  2073. if (align_end) {
  2074. memcpy(buf + len32 - 4, end, 4);
  2075. }
  2076. memcpy(buf + align_start, data_buf, buf_size);
  2077. }
  2078. written = 0;
  2079. while ((written < len32) && (rc == 0)) {
  2080. u32 page_start, page_end, data_start, data_end;
  2081. u32 addr, cmd_flags;
  2082. int i;
  2083. u8 flash_buffer[264];
  2084. /* Find the page_start addr */
  2085. page_start = offset32 + written;
  2086. page_start -= (page_start % bp->flash_info->page_size);
  2087. /* Find the page_end addr */
  2088. page_end = page_start + bp->flash_info->page_size;
  2089. /* Find the data_start addr */
  2090. data_start = (written == 0) ? offset32 : page_start;
  2091. /* Find the data_end addr */
  2092. data_end = (page_end > offset32 + len32) ?
  2093. (offset32 + len32) : page_end;
  2094. /* Request access to the flash interface. */
  2095. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2096. goto nvram_write_end;
  2097. /* Enable access to flash interface */
  2098. bnx2_enable_nvram_access(bp);
  2099. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2100. if (bp->flash_info->buffered == 0) {
  2101. int j;
  2102. /* Read the whole page into the buffer
  2103. * (non-buffer flash only) */
  2104. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  2105. if (j == (bp->flash_info->page_size - 4)) {
  2106. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2107. }
  2108. rc = bnx2_nvram_read_dword(bp,
  2109. page_start + j,
  2110. &flash_buffer[j],
  2111. cmd_flags);
  2112. if (rc)
  2113. goto nvram_write_end;
  2114. cmd_flags = 0;
  2115. }
  2116. }
  2117. /* Enable writes to flash interface (unlock write-protect) */
  2118. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  2119. goto nvram_write_end;
  2120. /* Erase the page */
  2121. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  2122. goto nvram_write_end;
  2123. /* Re-enable the write again for the actual write */
  2124. bnx2_enable_nvram_write(bp);
  2125. /* Loop to write back the buffer data from page_start to
  2126. * data_start */
  2127. i = 0;
  2128. if (bp->flash_info->buffered == 0) {
  2129. for (addr = page_start; addr < data_start;
  2130. addr += 4, i += 4) {
  2131. rc = bnx2_nvram_write_dword(bp, addr,
  2132. &flash_buffer[i], cmd_flags);
  2133. if (rc != 0)
  2134. goto nvram_write_end;
  2135. cmd_flags = 0;
  2136. }
  2137. }
  2138. /* Loop to write the new data from data_start to data_end */
  2139. for (addr = data_start; addr < data_end; addr += 4, i++) {
  2140. if ((addr == page_end - 4) ||
  2141. ((bp->flash_info->buffered) &&
  2142. (addr == data_end - 4))) {
  2143. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2144. }
  2145. rc = bnx2_nvram_write_dword(bp, addr, buf,
  2146. cmd_flags);
  2147. if (rc != 0)
  2148. goto nvram_write_end;
  2149. cmd_flags = 0;
  2150. buf += 4;
  2151. }
  2152. /* Loop to write back the buffer data from data_end
  2153. * to page_end */
  2154. if (bp->flash_info->buffered == 0) {
  2155. for (addr = data_end; addr < page_end;
  2156. addr += 4, i += 4) {
  2157. if (addr == page_end-4) {
  2158. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2159. }
  2160. rc = bnx2_nvram_write_dword(bp, addr,
  2161. &flash_buffer[i], cmd_flags);
  2162. if (rc != 0)
  2163. goto nvram_write_end;
  2164. cmd_flags = 0;
  2165. }
  2166. }
  2167. /* Disable writes to flash interface (lock write-protect) */
  2168. bnx2_disable_nvram_write(bp);
  2169. /* Disable access to flash interface */
  2170. bnx2_disable_nvram_access(bp);
  2171. bnx2_release_nvram_lock(bp);
  2172. /* Increment written */
  2173. written += data_end - data_start;
  2174. }
  2175. nvram_write_end:
  2176. if (align_start || align_end)
  2177. kfree(buf);
  2178. return rc;
  2179. }
  2180. static int
  2181. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  2182. {
  2183. u32 val;
  2184. int i, rc = 0;
  2185. /* Wait for the current PCI transaction to complete before
  2186. * issuing a reset. */
  2187. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  2188. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  2189. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  2190. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  2191. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  2192. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  2193. udelay(5);
  2194. /* Deposit a driver reset signature so the firmware knows that
  2195. * this is a soft reset. */
  2196. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_RESET_SIGNATURE,
  2197. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  2198. bp->fw_timed_out = 0;
  2199. /* Wait for the firmware to tell us it is ok to issue a reset. */
  2200. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code);
  2201. /* Do a dummy read to force the chip to complete all current transaction
  2202. * before we issue a reset. */
  2203. val = REG_RD(bp, BNX2_MISC_ID);
  2204. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2205. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2206. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2207. /* Chip reset. */
  2208. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  2209. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2210. (CHIP_ID(bp) == CHIP_ID_5706_A1))
  2211. msleep(15);
  2212. /* Reset takes approximate 30 usec */
  2213. for (i = 0; i < 10; i++) {
  2214. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  2215. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2216. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
  2217. break;
  2218. }
  2219. udelay(10);
  2220. }
  2221. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2222. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  2223. printk(KERN_ERR PFX "Chip reset did not complete\n");
  2224. return -EBUSY;
  2225. }
  2226. /* Make sure byte swapping is properly configured. */
  2227. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  2228. if (val != 0x01020304) {
  2229. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  2230. return -ENODEV;
  2231. }
  2232. bp->fw_timed_out = 0;
  2233. /* Wait for the firmware to finish its initialization. */
  2234. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code);
  2235. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2236. /* Adjust the voltage regular to two steps lower. The default
  2237. * of this register is 0x0000000e. */
  2238. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  2239. /* Remove bad rbuf memory from the free pool. */
  2240. rc = bnx2_alloc_bad_rbuf(bp);
  2241. }
  2242. return rc;
  2243. }
  2244. static int
  2245. bnx2_init_chip(struct bnx2 *bp)
  2246. {
  2247. u32 val;
  2248. /* Make sure the interrupt is not active. */
  2249. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2250. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  2251. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  2252. #ifdef __BIG_ENDIAN
  2253. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  2254. #endif
  2255. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  2256. DMA_READ_CHANS << 12 |
  2257. DMA_WRITE_CHANS << 16;
  2258. val |= (0x2 << 20) | (1 << 11);
  2259. if ((bp->flags & PCIX_FLAG) && (bp->bus_speed_mhz = 133))
  2260. val |= (1 << 23);
  2261. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  2262. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & PCIX_FLAG))
  2263. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  2264. REG_WR(bp, BNX2_DMA_CONFIG, val);
  2265. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2266. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  2267. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  2268. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  2269. }
  2270. if (bp->flags & PCIX_FLAG) {
  2271. u16 val16;
  2272. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2273. &val16);
  2274. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2275. val16 & ~PCI_X_CMD_ERO);
  2276. }
  2277. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2278. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  2279. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  2280. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  2281. /* Initialize context mapping and zero out the quick contexts. The
  2282. * context block must have already been enabled. */
  2283. bnx2_init_context(bp);
  2284. bnx2_init_cpus(bp);
  2285. bnx2_init_nvram(bp);
  2286. bnx2_set_mac_addr(bp);
  2287. val = REG_RD(bp, BNX2_MQ_CONFIG);
  2288. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  2289. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  2290. REG_WR(bp, BNX2_MQ_CONFIG, val);
  2291. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  2292. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  2293. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  2294. val = (BCM_PAGE_BITS - 8) << 24;
  2295. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  2296. /* Configure page size. */
  2297. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  2298. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  2299. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  2300. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  2301. val = bp->mac_addr[0] +
  2302. (bp->mac_addr[1] << 8) +
  2303. (bp->mac_addr[2] << 16) +
  2304. bp->mac_addr[3] +
  2305. (bp->mac_addr[4] << 8) +
  2306. (bp->mac_addr[5] << 16);
  2307. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  2308. /* Program the MTU. Also include 4 bytes for CRC32. */
  2309. val = bp->dev->mtu + ETH_HLEN + 4;
  2310. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  2311. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  2312. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  2313. bp->last_status_idx = 0;
  2314. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  2315. /* Set up how to generate a link change interrupt. */
  2316. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  2317. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  2318. (u64) bp->status_blk_mapping & 0xffffffff);
  2319. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  2320. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  2321. (u64) bp->stats_blk_mapping & 0xffffffff);
  2322. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  2323. (u64) bp->stats_blk_mapping >> 32);
  2324. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  2325. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  2326. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  2327. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  2328. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  2329. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  2330. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  2331. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  2332. REG_WR(bp, BNX2_HC_COM_TICKS,
  2333. (bp->com_ticks_int << 16) | bp->com_ticks);
  2334. REG_WR(bp, BNX2_HC_CMD_TICKS,
  2335. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  2336. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks & 0xffff00);
  2337. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  2338. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  2339. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_COLLECT_STATS);
  2340. else {
  2341. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_RX_TMR_MODE |
  2342. BNX2_HC_CONFIG_TX_TMR_MODE |
  2343. BNX2_HC_CONFIG_COLLECT_STATS);
  2344. }
  2345. /* Clear internal stats counters. */
  2346. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  2347. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
  2348. /* Initialize the receive filter. */
  2349. bnx2_set_rx_mode(bp->dev);
  2350. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET);
  2351. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
  2352. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  2353. udelay(20);
  2354. return 0;
  2355. }
  2356. static void
  2357. bnx2_init_tx_ring(struct bnx2 *bp)
  2358. {
  2359. struct tx_bd *txbd;
  2360. u32 val;
  2361. txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
  2362. txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
  2363. txbd->tx_bd_haddr_lo = (u64) bp->tx_desc_mapping & 0xffffffff;
  2364. bp->tx_prod = 0;
  2365. bp->tx_cons = 0;
  2366. bp->tx_prod_bseq = 0;
  2367. atomic_set(&bp->tx_avail_bd, bp->tx_ring_size);
  2368. val = BNX2_L2CTX_TYPE_TYPE_L2;
  2369. val |= BNX2_L2CTX_TYPE_SIZE_L2;
  2370. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TYPE, val);
  2371. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2;
  2372. val |= 8 << 16;
  2373. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_CMD_TYPE, val);
  2374. val = (u64) bp->tx_desc_mapping >> 32;
  2375. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_HI, val);
  2376. val = (u64) bp->tx_desc_mapping & 0xffffffff;
  2377. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_LO, val);
  2378. }
  2379. static void
  2380. bnx2_init_rx_ring(struct bnx2 *bp)
  2381. {
  2382. struct rx_bd *rxbd;
  2383. int i;
  2384. u16 prod, ring_prod;
  2385. u32 val;
  2386. /* 8 for CRC and VLAN */
  2387. bp->rx_buf_use_size = bp->dev->mtu + ETH_HLEN + bp->rx_offset + 8;
  2388. /* 8 for alignment */
  2389. bp->rx_buf_size = bp->rx_buf_use_size + 8;
  2390. ring_prod = prod = bp->rx_prod = 0;
  2391. bp->rx_cons = 0;
  2392. bp->rx_prod_bseq = 0;
  2393. rxbd = &bp->rx_desc_ring[0];
  2394. for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) {
  2395. rxbd->rx_bd_len = bp->rx_buf_use_size;
  2396. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  2397. }
  2398. rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping >> 32;
  2399. rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping & 0xffffffff;
  2400. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  2401. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  2402. val |= 0x02 << 8;
  2403. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
  2404. val = (u64) bp->rx_desc_mapping >> 32;
  2405. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
  2406. val = (u64) bp->rx_desc_mapping & 0xffffffff;
  2407. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
  2408. for ( ;ring_prod < bp->rx_ring_size; ) {
  2409. if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
  2410. break;
  2411. }
  2412. prod = NEXT_RX_BD(prod);
  2413. ring_prod = RX_RING_IDX(prod);
  2414. }
  2415. bp->rx_prod = prod;
  2416. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, prod);
  2417. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  2418. }
  2419. static void
  2420. bnx2_free_tx_skbs(struct bnx2 *bp)
  2421. {
  2422. int i;
  2423. if (bp->tx_buf_ring == NULL)
  2424. return;
  2425. for (i = 0; i < TX_DESC_CNT; ) {
  2426. struct sw_bd *tx_buf = &bp->tx_buf_ring[i];
  2427. struct sk_buff *skb = tx_buf->skb;
  2428. int j, last;
  2429. if (skb == NULL) {
  2430. i++;
  2431. continue;
  2432. }
  2433. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  2434. skb_headlen(skb), PCI_DMA_TODEVICE);
  2435. tx_buf->skb = NULL;
  2436. last = skb_shinfo(skb)->nr_frags;
  2437. for (j = 0; j < last; j++) {
  2438. tx_buf = &bp->tx_buf_ring[i + j + 1];
  2439. pci_unmap_page(bp->pdev,
  2440. pci_unmap_addr(tx_buf, mapping),
  2441. skb_shinfo(skb)->frags[j].size,
  2442. PCI_DMA_TODEVICE);
  2443. }
  2444. dev_kfree_skb_any(skb);
  2445. i += j + 1;
  2446. }
  2447. }
  2448. static void
  2449. bnx2_free_rx_skbs(struct bnx2 *bp)
  2450. {
  2451. int i;
  2452. if (bp->rx_buf_ring == NULL)
  2453. return;
  2454. for (i = 0; i < RX_DESC_CNT; i++) {
  2455. struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
  2456. struct sk_buff *skb = rx_buf->skb;
  2457. if (skb == 0)
  2458. continue;
  2459. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  2460. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  2461. rx_buf->skb = NULL;
  2462. dev_kfree_skb_any(skb);
  2463. }
  2464. }
  2465. static void
  2466. bnx2_free_skbs(struct bnx2 *bp)
  2467. {
  2468. bnx2_free_tx_skbs(bp);
  2469. bnx2_free_rx_skbs(bp);
  2470. }
  2471. static int
  2472. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  2473. {
  2474. int rc;
  2475. rc = bnx2_reset_chip(bp, reset_code);
  2476. bnx2_free_skbs(bp);
  2477. if (rc)
  2478. return rc;
  2479. bnx2_init_chip(bp);
  2480. bnx2_init_tx_ring(bp);
  2481. bnx2_init_rx_ring(bp);
  2482. return 0;
  2483. }
  2484. static int
  2485. bnx2_init_nic(struct bnx2 *bp)
  2486. {
  2487. int rc;
  2488. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  2489. return rc;
  2490. bnx2_init_phy(bp);
  2491. bnx2_set_link(bp);
  2492. return 0;
  2493. }
  2494. static int
  2495. bnx2_test_registers(struct bnx2 *bp)
  2496. {
  2497. int ret;
  2498. int i;
  2499. static struct {
  2500. u16 offset;
  2501. u16 flags;
  2502. u32 rw_mask;
  2503. u32 ro_mask;
  2504. } reg_tbl[] = {
  2505. { 0x006c, 0, 0x00000000, 0x0000003f },
  2506. { 0x0090, 0, 0xffffffff, 0x00000000 },
  2507. { 0x0094, 0, 0x00000000, 0x00000000 },
  2508. { 0x0404, 0, 0x00003f00, 0x00000000 },
  2509. { 0x0418, 0, 0x00000000, 0xffffffff },
  2510. { 0x041c, 0, 0x00000000, 0xffffffff },
  2511. { 0x0420, 0, 0x00000000, 0x80ffffff },
  2512. { 0x0424, 0, 0x00000000, 0x00000000 },
  2513. { 0x0428, 0, 0x00000000, 0x00000001 },
  2514. { 0x0450, 0, 0x00000000, 0x0000ffff },
  2515. { 0x0454, 0, 0x00000000, 0xffffffff },
  2516. { 0x0458, 0, 0x00000000, 0xffffffff },
  2517. { 0x0808, 0, 0x00000000, 0xffffffff },
  2518. { 0x0854, 0, 0x00000000, 0xffffffff },
  2519. { 0x0868, 0, 0x00000000, 0x77777777 },
  2520. { 0x086c, 0, 0x00000000, 0x77777777 },
  2521. { 0x0870, 0, 0x00000000, 0x77777777 },
  2522. { 0x0874, 0, 0x00000000, 0x77777777 },
  2523. { 0x0c00, 0, 0x00000000, 0x00000001 },
  2524. { 0x0c04, 0, 0x00000000, 0x03ff0001 },
  2525. { 0x0c08, 0, 0x0f0ff073, 0x00000000 },
  2526. { 0x0c0c, 0, 0x00ffffff, 0x00000000 },
  2527. { 0x0c30, 0, 0x00000000, 0xffffffff },
  2528. { 0x0c34, 0, 0x00000000, 0xffffffff },
  2529. { 0x0c38, 0, 0x00000000, 0xffffffff },
  2530. { 0x0c3c, 0, 0x00000000, 0xffffffff },
  2531. { 0x0c40, 0, 0x00000000, 0xffffffff },
  2532. { 0x0c44, 0, 0x00000000, 0xffffffff },
  2533. { 0x0c48, 0, 0x00000000, 0x0007ffff },
  2534. { 0x0c4c, 0, 0x00000000, 0xffffffff },
  2535. { 0x0c50, 0, 0x00000000, 0xffffffff },
  2536. { 0x0c54, 0, 0x00000000, 0xffffffff },
  2537. { 0x0c58, 0, 0x00000000, 0xffffffff },
  2538. { 0x0c5c, 0, 0x00000000, 0xffffffff },
  2539. { 0x0c60, 0, 0x00000000, 0xffffffff },
  2540. { 0x0c64, 0, 0x00000000, 0xffffffff },
  2541. { 0x0c68, 0, 0x00000000, 0xffffffff },
  2542. { 0x0c6c, 0, 0x00000000, 0xffffffff },
  2543. { 0x0c70, 0, 0x00000000, 0xffffffff },
  2544. { 0x0c74, 0, 0x00000000, 0xffffffff },
  2545. { 0x0c78, 0, 0x00000000, 0xffffffff },
  2546. { 0x0c7c, 0, 0x00000000, 0xffffffff },
  2547. { 0x0c80, 0, 0x00000000, 0xffffffff },
  2548. { 0x0c84, 0, 0x00000000, 0xffffffff },
  2549. { 0x0c88, 0, 0x00000000, 0xffffffff },
  2550. { 0x0c8c, 0, 0x00000000, 0xffffffff },
  2551. { 0x0c90, 0, 0x00000000, 0xffffffff },
  2552. { 0x0c94, 0, 0x00000000, 0xffffffff },
  2553. { 0x0c98, 0, 0x00000000, 0xffffffff },
  2554. { 0x0c9c, 0, 0x00000000, 0xffffffff },
  2555. { 0x0ca0, 0, 0x00000000, 0xffffffff },
  2556. { 0x0ca4, 0, 0x00000000, 0xffffffff },
  2557. { 0x0ca8, 0, 0x00000000, 0x0007ffff },
  2558. { 0x0cac, 0, 0x00000000, 0xffffffff },
  2559. { 0x0cb0, 0, 0x00000000, 0xffffffff },
  2560. { 0x0cb4, 0, 0x00000000, 0xffffffff },
  2561. { 0x0cb8, 0, 0x00000000, 0xffffffff },
  2562. { 0x0cbc, 0, 0x00000000, 0xffffffff },
  2563. { 0x0cc0, 0, 0x00000000, 0xffffffff },
  2564. { 0x0cc4, 0, 0x00000000, 0xffffffff },
  2565. { 0x0cc8, 0, 0x00000000, 0xffffffff },
  2566. { 0x0ccc, 0, 0x00000000, 0xffffffff },
  2567. { 0x0cd0, 0, 0x00000000, 0xffffffff },
  2568. { 0x0cd4, 0, 0x00000000, 0xffffffff },
  2569. { 0x0cd8, 0, 0x00000000, 0xffffffff },
  2570. { 0x0cdc, 0, 0x00000000, 0xffffffff },
  2571. { 0x0ce0, 0, 0x00000000, 0xffffffff },
  2572. { 0x0ce4, 0, 0x00000000, 0xffffffff },
  2573. { 0x0ce8, 0, 0x00000000, 0xffffffff },
  2574. { 0x0cec, 0, 0x00000000, 0xffffffff },
  2575. { 0x0cf0, 0, 0x00000000, 0xffffffff },
  2576. { 0x0cf4, 0, 0x00000000, 0xffffffff },
  2577. { 0x0cf8, 0, 0x00000000, 0xffffffff },
  2578. { 0x0cfc, 0, 0x00000000, 0xffffffff },
  2579. { 0x0d00, 0, 0x00000000, 0xffffffff },
  2580. { 0x0d04, 0, 0x00000000, 0xffffffff },
  2581. { 0x1000, 0, 0x00000000, 0x00000001 },
  2582. { 0x1004, 0, 0x00000000, 0x000f0001 },
  2583. { 0x1044, 0, 0x00000000, 0xffc003ff },
  2584. { 0x1080, 0, 0x00000000, 0x0001ffff },
  2585. { 0x1084, 0, 0x00000000, 0xffffffff },
  2586. { 0x1088, 0, 0x00000000, 0xffffffff },
  2587. { 0x108c, 0, 0x00000000, 0xffffffff },
  2588. { 0x1090, 0, 0x00000000, 0xffffffff },
  2589. { 0x1094, 0, 0x00000000, 0xffffffff },
  2590. { 0x1098, 0, 0x00000000, 0xffffffff },
  2591. { 0x109c, 0, 0x00000000, 0xffffffff },
  2592. { 0x10a0, 0, 0x00000000, 0xffffffff },
  2593. { 0x1408, 0, 0x01c00800, 0x00000000 },
  2594. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  2595. { 0x14a8, 0, 0x00000000, 0x000001ff },
  2596. { 0x14ac, 0, 0x4fffffff, 0x10000000 },
  2597. { 0x14b0, 0, 0x00000002, 0x00000001 },
  2598. { 0x14b8, 0, 0x00000000, 0x00000000 },
  2599. { 0x14c0, 0, 0x00000000, 0x00000009 },
  2600. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  2601. { 0x14cc, 0, 0x00000000, 0x00000001 },
  2602. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  2603. { 0x1500, 0, 0x00000000, 0xffffffff },
  2604. { 0x1504, 0, 0x00000000, 0xffffffff },
  2605. { 0x1508, 0, 0x00000000, 0xffffffff },
  2606. { 0x150c, 0, 0x00000000, 0xffffffff },
  2607. { 0x1510, 0, 0x00000000, 0xffffffff },
  2608. { 0x1514, 0, 0x00000000, 0xffffffff },
  2609. { 0x1518, 0, 0x00000000, 0xffffffff },
  2610. { 0x151c, 0, 0x00000000, 0xffffffff },
  2611. { 0x1520, 0, 0x00000000, 0xffffffff },
  2612. { 0x1524, 0, 0x00000000, 0xffffffff },
  2613. { 0x1528, 0, 0x00000000, 0xffffffff },
  2614. { 0x152c, 0, 0x00000000, 0xffffffff },
  2615. { 0x1530, 0, 0x00000000, 0xffffffff },
  2616. { 0x1534, 0, 0x00000000, 0xffffffff },
  2617. { 0x1538, 0, 0x00000000, 0xffffffff },
  2618. { 0x153c, 0, 0x00000000, 0xffffffff },
  2619. { 0x1540, 0, 0x00000000, 0xffffffff },
  2620. { 0x1544, 0, 0x00000000, 0xffffffff },
  2621. { 0x1548, 0, 0x00000000, 0xffffffff },
  2622. { 0x154c, 0, 0x00000000, 0xffffffff },
  2623. { 0x1550, 0, 0x00000000, 0xffffffff },
  2624. { 0x1554, 0, 0x00000000, 0xffffffff },
  2625. { 0x1558, 0, 0x00000000, 0xffffffff },
  2626. { 0x1600, 0, 0x00000000, 0xffffffff },
  2627. { 0x1604, 0, 0x00000000, 0xffffffff },
  2628. { 0x1608, 0, 0x00000000, 0xffffffff },
  2629. { 0x160c, 0, 0x00000000, 0xffffffff },
  2630. { 0x1610, 0, 0x00000000, 0xffffffff },
  2631. { 0x1614, 0, 0x00000000, 0xffffffff },
  2632. { 0x1618, 0, 0x00000000, 0xffffffff },
  2633. { 0x161c, 0, 0x00000000, 0xffffffff },
  2634. { 0x1620, 0, 0x00000000, 0xffffffff },
  2635. { 0x1624, 0, 0x00000000, 0xffffffff },
  2636. { 0x1628, 0, 0x00000000, 0xffffffff },
  2637. { 0x162c, 0, 0x00000000, 0xffffffff },
  2638. { 0x1630, 0, 0x00000000, 0xffffffff },
  2639. { 0x1634, 0, 0x00000000, 0xffffffff },
  2640. { 0x1638, 0, 0x00000000, 0xffffffff },
  2641. { 0x163c, 0, 0x00000000, 0xffffffff },
  2642. { 0x1640, 0, 0x00000000, 0xffffffff },
  2643. { 0x1644, 0, 0x00000000, 0xffffffff },
  2644. { 0x1648, 0, 0x00000000, 0xffffffff },
  2645. { 0x164c, 0, 0x00000000, 0xffffffff },
  2646. { 0x1650, 0, 0x00000000, 0xffffffff },
  2647. { 0x1654, 0, 0x00000000, 0xffffffff },
  2648. { 0x1800, 0, 0x00000000, 0x00000001 },
  2649. { 0x1804, 0, 0x00000000, 0x00000003 },
  2650. { 0x1840, 0, 0x00000000, 0xffffffff },
  2651. { 0x1844, 0, 0x00000000, 0xffffffff },
  2652. { 0x1848, 0, 0x00000000, 0xffffffff },
  2653. { 0x184c, 0, 0x00000000, 0xffffffff },
  2654. { 0x1850, 0, 0x00000000, 0xffffffff },
  2655. { 0x1900, 0, 0x7ffbffff, 0x00000000 },
  2656. { 0x1904, 0, 0xffffffff, 0x00000000 },
  2657. { 0x190c, 0, 0xffffffff, 0x00000000 },
  2658. { 0x1914, 0, 0xffffffff, 0x00000000 },
  2659. { 0x191c, 0, 0xffffffff, 0x00000000 },
  2660. { 0x1924, 0, 0xffffffff, 0x00000000 },
  2661. { 0x192c, 0, 0xffffffff, 0x00000000 },
  2662. { 0x1934, 0, 0xffffffff, 0x00000000 },
  2663. { 0x193c, 0, 0xffffffff, 0x00000000 },
  2664. { 0x1944, 0, 0xffffffff, 0x00000000 },
  2665. { 0x194c, 0, 0xffffffff, 0x00000000 },
  2666. { 0x1954, 0, 0xffffffff, 0x00000000 },
  2667. { 0x195c, 0, 0xffffffff, 0x00000000 },
  2668. { 0x1964, 0, 0xffffffff, 0x00000000 },
  2669. { 0x196c, 0, 0xffffffff, 0x00000000 },
  2670. { 0x1974, 0, 0xffffffff, 0x00000000 },
  2671. { 0x197c, 0, 0xffffffff, 0x00000000 },
  2672. { 0x1980, 0, 0x0700ffff, 0x00000000 },
  2673. { 0x1c00, 0, 0x00000000, 0x00000001 },
  2674. { 0x1c04, 0, 0x00000000, 0x00000003 },
  2675. { 0x1c08, 0, 0x0000000f, 0x00000000 },
  2676. { 0x1c40, 0, 0x00000000, 0xffffffff },
  2677. { 0x1c44, 0, 0x00000000, 0xffffffff },
  2678. { 0x1c48, 0, 0x00000000, 0xffffffff },
  2679. { 0x1c4c, 0, 0x00000000, 0xffffffff },
  2680. { 0x1c50, 0, 0x00000000, 0xffffffff },
  2681. { 0x1d00, 0, 0x7ffbffff, 0x00000000 },
  2682. { 0x1d04, 0, 0xffffffff, 0x00000000 },
  2683. { 0x1d0c, 0, 0xffffffff, 0x00000000 },
  2684. { 0x1d14, 0, 0xffffffff, 0x00000000 },
  2685. { 0x1d1c, 0, 0xffffffff, 0x00000000 },
  2686. { 0x1d24, 0, 0xffffffff, 0x00000000 },
  2687. { 0x1d2c, 0, 0xffffffff, 0x00000000 },
  2688. { 0x1d34, 0, 0xffffffff, 0x00000000 },
  2689. { 0x1d3c, 0, 0xffffffff, 0x00000000 },
  2690. { 0x1d44, 0, 0xffffffff, 0x00000000 },
  2691. { 0x1d4c, 0, 0xffffffff, 0x00000000 },
  2692. { 0x1d54, 0, 0xffffffff, 0x00000000 },
  2693. { 0x1d5c, 0, 0xffffffff, 0x00000000 },
  2694. { 0x1d64, 0, 0xffffffff, 0x00000000 },
  2695. { 0x1d6c, 0, 0xffffffff, 0x00000000 },
  2696. { 0x1d74, 0, 0xffffffff, 0x00000000 },
  2697. { 0x1d7c, 0, 0xffffffff, 0x00000000 },
  2698. { 0x1d80, 0, 0x0700ffff, 0x00000000 },
  2699. { 0x2004, 0, 0x00000000, 0x0337000f },
  2700. { 0x2008, 0, 0xffffffff, 0x00000000 },
  2701. { 0x200c, 0, 0xffffffff, 0x00000000 },
  2702. { 0x2010, 0, 0xffffffff, 0x00000000 },
  2703. { 0x2014, 0, 0x801fff80, 0x00000000 },
  2704. { 0x2018, 0, 0x000003ff, 0x00000000 },
  2705. { 0x2800, 0, 0x00000000, 0x00000001 },
  2706. { 0x2804, 0, 0x00000000, 0x00003f01 },
  2707. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  2708. { 0x2810, 0, 0xffff0000, 0x00000000 },
  2709. { 0x2814, 0, 0xffff0000, 0x00000000 },
  2710. { 0x2818, 0, 0xffff0000, 0x00000000 },
  2711. { 0x281c, 0, 0xffff0000, 0x00000000 },
  2712. { 0x2834, 0, 0xffffffff, 0x00000000 },
  2713. { 0x2840, 0, 0x00000000, 0xffffffff },
  2714. { 0x2844, 0, 0x00000000, 0xffffffff },
  2715. { 0x2848, 0, 0xffffffff, 0x00000000 },
  2716. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  2717. { 0x2c00, 0, 0x00000000, 0x00000011 },
  2718. { 0x2c04, 0, 0x00000000, 0x00030007 },
  2719. { 0x3000, 0, 0x00000000, 0x00000001 },
  2720. { 0x3004, 0, 0x00000000, 0x007007ff },
  2721. { 0x3008, 0, 0x00000003, 0x00000000 },
  2722. { 0x300c, 0, 0xffffffff, 0x00000000 },
  2723. { 0x3010, 0, 0xffffffff, 0x00000000 },
  2724. { 0x3014, 0, 0xffffffff, 0x00000000 },
  2725. { 0x3034, 0, 0xffffffff, 0x00000000 },
  2726. { 0x3038, 0, 0xffffffff, 0x00000000 },
  2727. { 0x3050, 0, 0x00000001, 0x00000000 },
  2728. { 0x3c00, 0, 0x00000000, 0x00000001 },
  2729. { 0x3c04, 0, 0x00000000, 0x00070000 },
  2730. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  2731. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  2732. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  2733. { 0x3c14, 0, 0x00000000, 0xffffffff },
  2734. { 0x3c18, 0, 0x00000000, 0xffffffff },
  2735. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  2736. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  2737. { 0x3c24, 0, 0xffffffff, 0x00000000 },
  2738. { 0x3c28, 0, 0xffffffff, 0x00000000 },
  2739. { 0x3c2c, 0, 0xffffffff, 0x00000000 },
  2740. { 0x3c30, 0, 0xffffffff, 0x00000000 },
  2741. { 0x3c34, 0, 0xffffffff, 0x00000000 },
  2742. { 0x3c38, 0, 0xffffffff, 0x00000000 },
  2743. { 0x3c3c, 0, 0xffffffff, 0x00000000 },
  2744. { 0x3c40, 0, 0xffffffff, 0x00000000 },
  2745. { 0x3c44, 0, 0xffffffff, 0x00000000 },
  2746. { 0x3c48, 0, 0xffffffff, 0x00000000 },
  2747. { 0x3c4c, 0, 0xffffffff, 0x00000000 },
  2748. { 0x3c50, 0, 0xffffffff, 0x00000000 },
  2749. { 0x3c54, 0, 0xffffffff, 0x00000000 },
  2750. { 0x3c58, 0, 0xffffffff, 0x00000000 },
  2751. { 0x3c5c, 0, 0xffffffff, 0x00000000 },
  2752. { 0x3c60, 0, 0xffffffff, 0x00000000 },
  2753. { 0x3c64, 0, 0xffffffff, 0x00000000 },
  2754. { 0x3c68, 0, 0xffffffff, 0x00000000 },
  2755. { 0x3c6c, 0, 0xffffffff, 0x00000000 },
  2756. { 0x3c70, 0, 0xffffffff, 0x00000000 },
  2757. { 0x3c74, 0, 0x0000003f, 0x00000000 },
  2758. { 0x3c78, 0, 0x00000000, 0x00000000 },
  2759. { 0x3c7c, 0, 0x00000000, 0x00000000 },
  2760. { 0x3c80, 0, 0x3fffffff, 0x00000000 },
  2761. { 0x3c84, 0, 0x0000003f, 0x00000000 },
  2762. { 0x3c88, 0, 0x00000000, 0xffffffff },
  2763. { 0x3c8c, 0, 0x00000000, 0xffffffff },
  2764. { 0x4000, 0, 0x00000000, 0x00000001 },
  2765. { 0x4004, 0, 0x00000000, 0x00030000 },
  2766. { 0x4008, 0, 0x00000ff0, 0x00000000 },
  2767. { 0x400c, 0, 0xffffffff, 0x00000000 },
  2768. { 0x4088, 0, 0x00000000, 0x00070303 },
  2769. { 0x4400, 0, 0x00000000, 0x00000001 },
  2770. { 0x4404, 0, 0x00000000, 0x00003f01 },
  2771. { 0x4408, 0, 0x7fff00ff, 0x00000000 },
  2772. { 0x440c, 0, 0xffffffff, 0x00000000 },
  2773. { 0x4410, 0, 0xffff, 0x0000 },
  2774. { 0x4414, 0, 0xffff, 0x0000 },
  2775. { 0x4418, 0, 0xffff, 0x0000 },
  2776. { 0x441c, 0, 0xffff, 0x0000 },
  2777. { 0x4428, 0, 0xffffffff, 0x00000000 },
  2778. { 0x442c, 0, 0xffffffff, 0x00000000 },
  2779. { 0x4430, 0, 0xffffffff, 0x00000000 },
  2780. { 0x4434, 0, 0xffffffff, 0x00000000 },
  2781. { 0x4438, 0, 0xffffffff, 0x00000000 },
  2782. { 0x443c, 0, 0xffffffff, 0x00000000 },
  2783. { 0x4440, 0, 0xffffffff, 0x00000000 },
  2784. { 0x4444, 0, 0xffffffff, 0x00000000 },
  2785. { 0x4c00, 0, 0x00000000, 0x00000001 },
  2786. { 0x4c04, 0, 0x00000000, 0x0000003f },
  2787. { 0x4c08, 0, 0xffffffff, 0x00000000 },
  2788. { 0x4c0c, 0, 0x0007fc00, 0x00000000 },
  2789. { 0x4c10, 0, 0x80003fe0, 0x00000000 },
  2790. { 0x4c14, 0, 0xffffffff, 0x00000000 },
  2791. { 0x4c44, 0, 0x00000000, 0x9fff9fff },
  2792. { 0x4c48, 0, 0x00000000, 0xb3009fff },
  2793. { 0x4c4c, 0, 0x00000000, 0x77f33b30 },
  2794. { 0x4c50, 0, 0x00000000, 0xffffffff },
  2795. { 0x5004, 0, 0x00000000, 0x0000007f },
  2796. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  2797. { 0x500c, 0, 0xf800f800, 0x07ff07ff },
  2798. { 0x5400, 0, 0x00000008, 0x00000001 },
  2799. { 0x5404, 0, 0x00000000, 0x0000003f },
  2800. { 0x5408, 0, 0x0000001f, 0x00000000 },
  2801. { 0x540c, 0, 0xffffffff, 0x00000000 },
  2802. { 0x5410, 0, 0xffffffff, 0x00000000 },
  2803. { 0x5414, 0, 0x0000ffff, 0x00000000 },
  2804. { 0x5418, 0, 0x0000ffff, 0x00000000 },
  2805. { 0x541c, 0, 0x0000ffff, 0x00000000 },
  2806. { 0x5420, 0, 0x0000ffff, 0x00000000 },
  2807. { 0x5428, 0, 0x000000ff, 0x00000000 },
  2808. { 0x542c, 0, 0xff00ffff, 0x00000000 },
  2809. { 0x5430, 0, 0x001fff80, 0x00000000 },
  2810. { 0x5438, 0, 0xffffffff, 0x00000000 },
  2811. { 0x543c, 0, 0xffffffff, 0x00000000 },
  2812. { 0x5440, 0, 0xf800f800, 0x07ff07ff },
  2813. { 0x5c00, 0, 0x00000000, 0x00000001 },
  2814. { 0x5c04, 0, 0x00000000, 0x0003000f },
  2815. { 0x5c08, 0, 0x00000003, 0x00000000 },
  2816. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  2817. { 0x5c10, 0, 0x00000000, 0xffffffff },
  2818. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  2819. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  2820. { 0x5c88, 0, 0x00000000, 0x00077373 },
  2821. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  2822. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  2823. { 0x680c, 0, 0xffffffff, 0x00000000 },
  2824. { 0x6810, 0, 0xffffffff, 0x00000000 },
  2825. { 0x6814, 0, 0xffffffff, 0x00000000 },
  2826. { 0x6818, 0, 0xffffffff, 0x00000000 },
  2827. { 0x681c, 0, 0xffffffff, 0x00000000 },
  2828. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  2829. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  2830. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  2831. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  2832. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  2833. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  2834. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  2835. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  2836. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  2837. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  2838. { 0x684c, 0, 0xffffffff, 0x00000000 },
  2839. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  2840. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  2841. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  2842. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  2843. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  2844. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  2845. { 0xffff, 0, 0x00000000, 0x00000000 },
  2846. };
  2847. ret = 0;
  2848. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  2849. u32 offset, rw_mask, ro_mask, save_val, val;
  2850. offset = (u32) reg_tbl[i].offset;
  2851. rw_mask = reg_tbl[i].rw_mask;
  2852. ro_mask = reg_tbl[i].ro_mask;
  2853. save_val = readl(bp->regview + offset);
  2854. writel(0, bp->regview + offset);
  2855. val = readl(bp->regview + offset);
  2856. if ((val & rw_mask) != 0) {
  2857. goto reg_test_err;
  2858. }
  2859. if ((val & ro_mask) != (save_val & ro_mask)) {
  2860. goto reg_test_err;
  2861. }
  2862. writel(0xffffffff, bp->regview + offset);
  2863. val = readl(bp->regview + offset);
  2864. if ((val & rw_mask) != rw_mask) {
  2865. goto reg_test_err;
  2866. }
  2867. if ((val & ro_mask) != (save_val & ro_mask)) {
  2868. goto reg_test_err;
  2869. }
  2870. writel(save_val, bp->regview + offset);
  2871. continue;
  2872. reg_test_err:
  2873. writel(save_val, bp->regview + offset);
  2874. ret = -ENODEV;
  2875. break;
  2876. }
  2877. return ret;
  2878. }
  2879. static int
  2880. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  2881. {
  2882. static u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  2883. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  2884. int i;
  2885. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  2886. u32 offset;
  2887. for (offset = 0; offset < size; offset += 4) {
  2888. REG_WR_IND(bp, start + offset, test_pattern[i]);
  2889. if (REG_RD_IND(bp, start + offset) !=
  2890. test_pattern[i]) {
  2891. return -ENODEV;
  2892. }
  2893. }
  2894. }
  2895. return 0;
  2896. }
  2897. static int
  2898. bnx2_test_memory(struct bnx2 *bp)
  2899. {
  2900. int ret = 0;
  2901. int i;
  2902. static struct {
  2903. u32 offset;
  2904. u32 len;
  2905. } mem_tbl[] = {
  2906. { 0x60000, 0x4000 },
  2907. { 0xa0000, 0x4000 },
  2908. { 0xe0000, 0x4000 },
  2909. { 0x120000, 0x4000 },
  2910. { 0x1a0000, 0x4000 },
  2911. { 0x160000, 0x4000 },
  2912. { 0xffffffff, 0 },
  2913. };
  2914. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  2915. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  2916. mem_tbl[i].len)) != 0) {
  2917. return ret;
  2918. }
  2919. }
  2920. return ret;
  2921. }
  2922. static int
  2923. bnx2_test_loopback(struct bnx2 *bp)
  2924. {
  2925. unsigned int pkt_size, num_pkts, i;
  2926. struct sk_buff *skb, *rx_skb;
  2927. unsigned char *packet;
  2928. u16 rx_start_idx, rx_idx, send_idx;
  2929. u32 send_bseq, val;
  2930. dma_addr_t map;
  2931. struct tx_bd *txbd;
  2932. struct sw_bd *rx_buf;
  2933. struct l2_fhdr *rx_hdr;
  2934. int ret = -ENODEV;
  2935. if (!netif_running(bp->dev))
  2936. return -ENODEV;
  2937. bp->loopback = MAC_LOOPBACK;
  2938. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_DIAG);
  2939. bnx2_set_mac_loopback(bp);
  2940. pkt_size = 1514;
  2941. skb = dev_alloc_skb(pkt_size);
  2942. packet = skb_put(skb, pkt_size);
  2943. memcpy(packet, bp->mac_addr, 6);
  2944. memset(packet + 6, 0x0, 8);
  2945. for (i = 14; i < pkt_size; i++)
  2946. packet[i] = (unsigned char) (i & 0xff);
  2947. map = pci_map_single(bp->pdev, skb->data, pkt_size,
  2948. PCI_DMA_TODEVICE);
  2949. val = REG_RD(bp, BNX2_HC_COMMAND);
  2950. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2951. REG_RD(bp, BNX2_HC_COMMAND);
  2952. udelay(5);
  2953. rx_start_idx = bp->status_blk->status_rx_quick_consumer_index0;
  2954. send_idx = 0;
  2955. send_bseq = 0;
  2956. num_pkts = 0;
  2957. txbd = &bp->tx_desc_ring[send_idx];
  2958. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  2959. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  2960. txbd->tx_bd_mss_nbytes = pkt_size;
  2961. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  2962. num_pkts++;
  2963. send_idx = NEXT_TX_BD(send_idx);
  2964. send_bseq += pkt_size;
  2965. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, send_idx);
  2966. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, send_bseq);
  2967. udelay(100);
  2968. val = REG_RD(bp, BNX2_HC_COMMAND);
  2969. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  2970. REG_RD(bp, BNX2_HC_COMMAND);
  2971. udelay(5);
  2972. pci_unmap_single(bp->pdev, map, pkt_size, PCI_DMA_TODEVICE);
  2973. dev_kfree_skb_irq(skb);
  2974. if (bp->status_blk->status_tx_quick_consumer_index0 != send_idx) {
  2975. goto loopback_test_done;
  2976. }
  2977. rx_idx = bp->status_blk->status_rx_quick_consumer_index0;
  2978. if (rx_idx != rx_start_idx + num_pkts) {
  2979. goto loopback_test_done;
  2980. }
  2981. rx_buf = &bp->rx_buf_ring[rx_start_idx];
  2982. rx_skb = rx_buf->skb;
  2983. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  2984. skb_reserve(rx_skb, bp->rx_offset);
  2985. pci_dma_sync_single_for_cpu(bp->pdev,
  2986. pci_unmap_addr(rx_buf, mapping),
  2987. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  2988. if (rx_hdr->l2_fhdr_errors &
  2989. (L2_FHDR_ERRORS_BAD_CRC |
  2990. L2_FHDR_ERRORS_PHY_DECODE |
  2991. L2_FHDR_ERRORS_ALIGNMENT |
  2992. L2_FHDR_ERRORS_TOO_SHORT |
  2993. L2_FHDR_ERRORS_GIANT_FRAME)) {
  2994. goto loopback_test_done;
  2995. }
  2996. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  2997. goto loopback_test_done;
  2998. }
  2999. for (i = 14; i < pkt_size; i++) {
  3000. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  3001. goto loopback_test_done;
  3002. }
  3003. }
  3004. ret = 0;
  3005. loopback_test_done:
  3006. bp->loopback = 0;
  3007. return ret;
  3008. }
  3009. #define NVRAM_SIZE 0x200
  3010. #define CRC32_RESIDUAL 0xdebb20e3
  3011. static int
  3012. bnx2_test_nvram(struct bnx2 *bp)
  3013. {
  3014. u32 buf[NVRAM_SIZE / 4];
  3015. u8 *data = (u8 *) buf;
  3016. int rc = 0;
  3017. u32 magic, csum;
  3018. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  3019. goto test_nvram_done;
  3020. magic = be32_to_cpu(buf[0]);
  3021. if (magic != 0x669955aa) {
  3022. rc = -ENODEV;
  3023. goto test_nvram_done;
  3024. }
  3025. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  3026. goto test_nvram_done;
  3027. csum = ether_crc_le(0x100, data);
  3028. if (csum != CRC32_RESIDUAL) {
  3029. rc = -ENODEV;
  3030. goto test_nvram_done;
  3031. }
  3032. csum = ether_crc_le(0x100, data + 0x100);
  3033. if (csum != CRC32_RESIDUAL) {
  3034. rc = -ENODEV;
  3035. }
  3036. test_nvram_done:
  3037. return rc;
  3038. }
  3039. static int
  3040. bnx2_test_link(struct bnx2 *bp)
  3041. {
  3042. u32 bmsr;
  3043. spin_lock_irq(&bp->phy_lock);
  3044. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3045. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3046. spin_unlock_irq(&bp->phy_lock);
  3047. if (bmsr & BMSR_LSTATUS) {
  3048. return 0;
  3049. }
  3050. return -ENODEV;
  3051. }
  3052. static int
  3053. bnx2_test_intr(struct bnx2 *bp)
  3054. {
  3055. int i;
  3056. u32 val;
  3057. u16 status_idx;
  3058. if (!netif_running(bp->dev))
  3059. return -ENODEV;
  3060. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  3061. /* This register is not touched during run-time. */
  3062. val = REG_RD(bp, BNX2_HC_COMMAND);
  3063. REG_WR(bp, BNX2_HC_COMMAND, val | BNX2_HC_COMMAND_COAL_NOW);
  3064. REG_RD(bp, BNX2_HC_COMMAND);
  3065. for (i = 0; i < 10; i++) {
  3066. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  3067. status_idx) {
  3068. break;
  3069. }
  3070. msleep_interruptible(10);
  3071. }
  3072. if (i < 10)
  3073. return 0;
  3074. return -ENODEV;
  3075. }
  3076. static void
  3077. bnx2_timer(unsigned long data)
  3078. {
  3079. struct bnx2 *bp = (struct bnx2 *) data;
  3080. u32 msg;
  3081. if (atomic_read(&bp->intr_sem) != 0)
  3082. goto bnx2_restart_timer;
  3083. msg = (u32) ++bp->fw_drv_pulse_wr_seq;
  3084. REG_WR_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DRV_PULSE_MB, msg);
  3085. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  3086. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  3087. unsigned long flags;
  3088. spin_lock_irqsave(&bp->phy_lock, flags);
  3089. if (bp->serdes_an_pending) {
  3090. bp->serdes_an_pending--;
  3091. }
  3092. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3093. u32 bmcr;
  3094. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3095. if (bmcr & BMCR_ANENABLE) {
  3096. u32 phy1, phy2;
  3097. bnx2_write_phy(bp, 0x1c, 0x7c00);
  3098. bnx2_read_phy(bp, 0x1c, &phy1);
  3099. bnx2_write_phy(bp, 0x17, 0x0f01);
  3100. bnx2_read_phy(bp, 0x15, &phy2);
  3101. bnx2_write_phy(bp, 0x17, 0x0f01);
  3102. bnx2_read_phy(bp, 0x15, &phy2);
  3103. if ((phy1 & 0x10) && /* SIGNAL DETECT */
  3104. !(phy2 & 0x20)) { /* no CONFIG */
  3105. bmcr &= ~BMCR_ANENABLE;
  3106. bmcr |= BMCR_SPEED1000 |
  3107. BMCR_FULLDPLX;
  3108. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3109. bp->phy_flags |=
  3110. PHY_PARALLEL_DETECT_FLAG;
  3111. }
  3112. }
  3113. }
  3114. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  3115. (bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)) {
  3116. u32 phy2;
  3117. bnx2_write_phy(bp, 0x17, 0x0f01);
  3118. bnx2_read_phy(bp, 0x15, &phy2);
  3119. if (phy2 & 0x20) {
  3120. u32 bmcr;
  3121. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3122. bmcr |= BMCR_ANENABLE;
  3123. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3124. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  3125. }
  3126. }
  3127. spin_unlock_irqrestore(&bp->phy_lock, flags);
  3128. }
  3129. bnx2_restart_timer:
  3130. bp->timer.expires = RUN_AT(bp->timer_interval);
  3131. add_timer(&bp->timer);
  3132. }
  3133. /* Called with rtnl_lock */
  3134. static int
  3135. bnx2_open(struct net_device *dev)
  3136. {
  3137. struct bnx2 *bp = dev->priv;
  3138. int rc;
  3139. bnx2_set_power_state(bp, 0);
  3140. bnx2_disable_int(bp);
  3141. rc = bnx2_alloc_mem(bp);
  3142. if (rc)
  3143. return rc;
  3144. if ((CHIP_ID(bp) != CHIP_ID_5706_A0) &&
  3145. (CHIP_ID(bp) != CHIP_ID_5706_A1) &&
  3146. !disable_msi) {
  3147. if (pci_enable_msi(bp->pdev) == 0) {
  3148. bp->flags |= USING_MSI_FLAG;
  3149. rc = request_irq(bp->pdev->irq, bnx2_msi, 0, dev->name,
  3150. dev);
  3151. }
  3152. else {
  3153. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3154. SA_SHIRQ, dev->name, dev);
  3155. }
  3156. }
  3157. else {
  3158. rc = request_irq(bp->pdev->irq, bnx2_interrupt, SA_SHIRQ,
  3159. dev->name, dev);
  3160. }
  3161. if (rc) {
  3162. bnx2_free_mem(bp);
  3163. return rc;
  3164. }
  3165. rc = bnx2_init_nic(bp);
  3166. if (rc) {
  3167. free_irq(bp->pdev->irq, dev);
  3168. if (bp->flags & USING_MSI_FLAG) {
  3169. pci_disable_msi(bp->pdev);
  3170. bp->flags &= ~USING_MSI_FLAG;
  3171. }
  3172. bnx2_free_skbs(bp);
  3173. bnx2_free_mem(bp);
  3174. return rc;
  3175. }
  3176. init_timer(&bp->timer);
  3177. bp->timer.expires = RUN_AT(bp->timer_interval);
  3178. bp->timer.data = (unsigned long) bp;
  3179. bp->timer.function = bnx2_timer;
  3180. add_timer(&bp->timer);
  3181. atomic_set(&bp->intr_sem, 0);
  3182. bnx2_enable_int(bp);
  3183. if (bp->flags & USING_MSI_FLAG) {
  3184. /* Test MSI to make sure it is working
  3185. * If MSI test fails, go back to INTx mode
  3186. */
  3187. if (bnx2_test_intr(bp) != 0) {
  3188. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  3189. " using MSI, switching to INTx mode. Please"
  3190. " report this failure to the PCI maintainer"
  3191. " and include system chipset information.\n",
  3192. bp->dev->name);
  3193. bnx2_disable_int(bp);
  3194. free_irq(bp->pdev->irq, dev);
  3195. pci_disable_msi(bp->pdev);
  3196. bp->flags &= ~USING_MSI_FLAG;
  3197. rc = bnx2_init_nic(bp);
  3198. if (!rc) {
  3199. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3200. SA_SHIRQ, dev->name, dev);
  3201. }
  3202. if (rc) {
  3203. bnx2_free_skbs(bp);
  3204. bnx2_free_mem(bp);
  3205. del_timer_sync(&bp->timer);
  3206. return rc;
  3207. }
  3208. bnx2_enable_int(bp);
  3209. }
  3210. }
  3211. if (bp->flags & USING_MSI_FLAG) {
  3212. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  3213. }
  3214. netif_start_queue(dev);
  3215. return 0;
  3216. }
  3217. static void
  3218. bnx2_reset_task(void *data)
  3219. {
  3220. struct bnx2 *bp = data;
  3221. bnx2_netif_stop(bp);
  3222. bnx2_init_nic(bp);
  3223. atomic_set(&bp->intr_sem, 1);
  3224. bnx2_netif_start(bp);
  3225. }
  3226. static void
  3227. bnx2_tx_timeout(struct net_device *dev)
  3228. {
  3229. struct bnx2 *bp = dev->priv;
  3230. /* This allows the netif to be shutdown gracefully before resetting */
  3231. schedule_work(&bp->reset_task);
  3232. }
  3233. #ifdef BCM_VLAN
  3234. /* Called with rtnl_lock */
  3235. static void
  3236. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  3237. {
  3238. struct bnx2 *bp = dev->priv;
  3239. bnx2_netif_stop(bp);
  3240. bp->vlgrp = vlgrp;
  3241. bnx2_set_rx_mode(dev);
  3242. bnx2_netif_start(bp);
  3243. }
  3244. /* Called with rtnl_lock */
  3245. static void
  3246. bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
  3247. {
  3248. struct bnx2 *bp = dev->priv;
  3249. bnx2_netif_stop(bp);
  3250. if (bp->vlgrp)
  3251. bp->vlgrp->vlan_devices[vid] = NULL;
  3252. bnx2_set_rx_mode(dev);
  3253. bnx2_netif_start(bp);
  3254. }
  3255. #endif
  3256. /* Called with dev->xmit_lock.
  3257. * hard_start_xmit is pseudo-lockless - a lock is only required when
  3258. * the tx queue is full. This way, we get the benefit of lockless
  3259. * operations most of the time without the complexities to handle
  3260. * netif_stop_queue/wake_queue race conditions.
  3261. */
  3262. static int
  3263. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3264. {
  3265. struct bnx2 *bp = dev->priv;
  3266. dma_addr_t mapping;
  3267. struct tx_bd *txbd;
  3268. struct sw_bd *tx_buf;
  3269. u32 len, vlan_tag_flags, last_frag, mss;
  3270. u16 prod, ring_prod;
  3271. int i;
  3272. if (unlikely(atomic_read(&bp->tx_avail_bd) <
  3273. (skb_shinfo(skb)->nr_frags + 1))) {
  3274. netif_stop_queue(dev);
  3275. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  3276. dev->name);
  3277. return NETDEV_TX_BUSY;
  3278. }
  3279. len = skb_headlen(skb);
  3280. prod = bp->tx_prod;
  3281. ring_prod = TX_RING_IDX(prod);
  3282. vlan_tag_flags = 0;
  3283. if (skb->ip_summed == CHECKSUM_HW) {
  3284. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  3285. }
  3286. if (bp->vlgrp != 0 && vlan_tx_tag_present(skb)) {
  3287. vlan_tag_flags |=
  3288. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  3289. }
  3290. #ifdef BCM_TSO
  3291. if ((mss = skb_shinfo(skb)->tso_size) &&
  3292. (skb->len > (bp->dev->mtu + ETH_HLEN))) {
  3293. u32 tcp_opt_len, ip_tcp_len;
  3294. if (skb_header_cloned(skb) &&
  3295. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3296. dev_kfree_skb(skb);
  3297. return NETDEV_TX_OK;
  3298. }
  3299. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3300. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  3301. tcp_opt_len = 0;
  3302. if (skb->h.th->doff > 5) {
  3303. tcp_opt_len = (skb->h.th->doff - 5) << 2;
  3304. }
  3305. ip_tcp_len = (skb->nh.iph->ihl << 2) + sizeof(struct tcphdr);
  3306. skb->nh.iph->check = 0;
  3307. skb->nh.iph->tot_len = ntohs(mss + ip_tcp_len + tcp_opt_len);
  3308. skb->h.th->check =
  3309. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3310. skb->nh.iph->daddr,
  3311. 0, IPPROTO_TCP, 0);
  3312. if (tcp_opt_len || (skb->nh.iph->ihl > 5)) {
  3313. vlan_tag_flags |= ((skb->nh.iph->ihl - 5) +
  3314. (tcp_opt_len >> 2)) << 8;
  3315. }
  3316. }
  3317. else
  3318. #endif
  3319. {
  3320. mss = 0;
  3321. }
  3322. mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3323. tx_buf = &bp->tx_buf_ring[ring_prod];
  3324. tx_buf->skb = skb;
  3325. pci_unmap_addr_set(tx_buf, mapping, mapping);
  3326. txbd = &bp->tx_desc_ring[ring_prod];
  3327. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3328. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3329. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3330. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  3331. last_frag = skb_shinfo(skb)->nr_frags;
  3332. for (i = 0; i < last_frag; i++) {
  3333. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3334. prod = NEXT_TX_BD(prod);
  3335. ring_prod = TX_RING_IDX(prod);
  3336. txbd = &bp->tx_desc_ring[ring_prod];
  3337. len = frag->size;
  3338. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  3339. len, PCI_DMA_TODEVICE);
  3340. pci_unmap_addr_set(&bp->tx_buf_ring[ring_prod],
  3341. mapping, mapping);
  3342. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3343. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3344. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3345. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  3346. }
  3347. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  3348. prod = NEXT_TX_BD(prod);
  3349. bp->tx_prod_bseq += skb->len;
  3350. atomic_sub(last_frag + 1, &bp->tx_avail_bd);
  3351. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, prod);
  3352. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
  3353. mmiowb();
  3354. bp->tx_prod = prod;
  3355. dev->trans_start = jiffies;
  3356. if (unlikely(atomic_read(&bp->tx_avail_bd) <= MAX_SKB_FRAGS)) {
  3357. unsigned long flags;
  3358. spin_lock_irqsave(&bp->tx_lock, flags);
  3359. if (atomic_read(&bp->tx_avail_bd) <= MAX_SKB_FRAGS) {
  3360. netif_stop_queue(dev);
  3361. if (atomic_read(&bp->tx_avail_bd) > MAX_SKB_FRAGS)
  3362. netif_wake_queue(dev);
  3363. }
  3364. spin_unlock_irqrestore(&bp->tx_lock, flags);
  3365. }
  3366. return NETDEV_TX_OK;
  3367. }
  3368. /* Called with rtnl_lock */
  3369. static int
  3370. bnx2_close(struct net_device *dev)
  3371. {
  3372. struct bnx2 *bp = dev->priv;
  3373. u32 reset_code;
  3374. flush_scheduled_work();
  3375. bnx2_netif_stop(bp);
  3376. del_timer_sync(&bp->timer);
  3377. if (bp->wol)
  3378. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3379. else
  3380. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3381. bnx2_reset_chip(bp, reset_code);
  3382. free_irq(bp->pdev->irq, dev);
  3383. if (bp->flags & USING_MSI_FLAG) {
  3384. pci_disable_msi(bp->pdev);
  3385. bp->flags &= ~USING_MSI_FLAG;
  3386. }
  3387. bnx2_free_skbs(bp);
  3388. bnx2_free_mem(bp);
  3389. bp->link_up = 0;
  3390. netif_carrier_off(bp->dev);
  3391. bnx2_set_power_state(bp, 3);
  3392. return 0;
  3393. }
  3394. #define GET_NET_STATS64(ctr) \
  3395. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  3396. (unsigned long) (ctr##_lo)
  3397. #define GET_NET_STATS32(ctr) \
  3398. (ctr##_lo)
  3399. #if (BITS_PER_LONG == 64)
  3400. #define GET_NET_STATS GET_NET_STATS64
  3401. #else
  3402. #define GET_NET_STATS GET_NET_STATS32
  3403. #endif
  3404. static struct net_device_stats *
  3405. bnx2_get_stats(struct net_device *dev)
  3406. {
  3407. struct bnx2 *bp = dev->priv;
  3408. struct statistics_block *stats_blk = bp->stats_blk;
  3409. struct net_device_stats *net_stats = &bp->net_stats;
  3410. if (bp->stats_blk == NULL) {
  3411. return net_stats;
  3412. }
  3413. net_stats->rx_packets =
  3414. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  3415. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  3416. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  3417. net_stats->tx_packets =
  3418. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  3419. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  3420. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  3421. net_stats->rx_bytes =
  3422. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  3423. net_stats->tx_bytes =
  3424. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  3425. net_stats->multicast =
  3426. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  3427. net_stats->collisions =
  3428. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  3429. net_stats->rx_length_errors =
  3430. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  3431. stats_blk->stat_EtherStatsOverrsizePkts);
  3432. net_stats->rx_over_errors =
  3433. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  3434. net_stats->rx_frame_errors =
  3435. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  3436. net_stats->rx_crc_errors =
  3437. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  3438. net_stats->rx_errors = net_stats->rx_length_errors +
  3439. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  3440. net_stats->rx_crc_errors;
  3441. net_stats->tx_aborted_errors =
  3442. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  3443. stats_blk->stat_Dot3StatsLateCollisions);
  3444. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3445. net_stats->tx_carrier_errors = 0;
  3446. else {
  3447. net_stats->tx_carrier_errors =
  3448. (unsigned long)
  3449. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  3450. }
  3451. net_stats->tx_errors =
  3452. (unsigned long)
  3453. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  3454. +
  3455. net_stats->tx_aborted_errors +
  3456. net_stats->tx_carrier_errors;
  3457. return net_stats;
  3458. }
  3459. /* All ethtool functions called with rtnl_lock */
  3460. static int
  3461. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3462. {
  3463. struct bnx2 *bp = dev->priv;
  3464. cmd->supported = SUPPORTED_Autoneg;
  3465. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3466. cmd->supported |= SUPPORTED_1000baseT_Full |
  3467. SUPPORTED_FIBRE;
  3468. cmd->port = PORT_FIBRE;
  3469. }
  3470. else {
  3471. cmd->supported |= SUPPORTED_10baseT_Half |
  3472. SUPPORTED_10baseT_Full |
  3473. SUPPORTED_100baseT_Half |
  3474. SUPPORTED_100baseT_Full |
  3475. SUPPORTED_1000baseT_Full |
  3476. SUPPORTED_TP;
  3477. cmd->port = PORT_TP;
  3478. }
  3479. cmd->advertising = bp->advertising;
  3480. if (bp->autoneg & AUTONEG_SPEED) {
  3481. cmd->autoneg = AUTONEG_ENABLE;
  3482. }
  3483. else {
  3484. cmd->autoneg = AUTONEG_DISABLE;
  3485. }
  3486. if (netif_carrier_ok(dev)) {
  3487. cmd->speed = bp->line_speed;
  3488. cmd->duplex = bp->duplex;
  3489. }
  3490. else {
  3491. cmd->speed = -1;
  3492. cmd->duplex = -1;
  3493. }
  3494. cmd->transceiver = XCVR_INTERNAL;
  3495. cmd->phy_address = bp->phy_addr;
  3496. return 0;
  3497. }
  3498. static int
  3499. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3500. {
  3501. struct bnx2 *bp = dev->priv;
  3502. u8 autoneg = bp->autoneg;
  3503. u8 req_duplex = bp->req_duplex;
  3504. u16 req_line_speed = bp->req_line_speed;
  3505. u32 advertising = bp->advertising;
  3506. if (cmd->autoneg == AUTONEG_ENABLE) {
  3507. autoneg |= AUTONEG_SPEED;
  3508. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  3509. /* allow advertising 1 speed */
  3510. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  3511. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  3512. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  3513. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  3514. if (bp->phy_flags & PHY_SERDES_FLAG)
  3515. return -EINVAL;
  3516. advertising = cmd->advertising;
  3517. }
  3518. else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
  3519. advertising = cmd->advertising;
  3520. }
  3521. else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
  3522. return -EINVAL;
  3523. }
  3524. else {
  3525. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3526. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  3527. }
  3528. else {
  3529. advertising = ETHTOOL_ALL_COPPER_SPEED;
  3530. }
  3531. }
  3532. advertising |= ADVERTISED_Autoneg;
  3533. }
  3534. else {
  3535. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3536. if ((cmd->speed != SPEED_1000) ||
  3537. (cmd->duplex != DUPLEX_FULL)) {
  3538. return -EINVAL;
  3539. }
  3540. }
  3541. else if (cmd->speed == SPEED_1000) {
  3542. return -EINVAL;
  3543. }
  3544. autoneg &= ~AUTONEG_SPEED;
  3545. req_line_speed = cmd->speed;
  3546. req_duplex = cmd->duplex;
  3547. advertising = 0;
  3548. }
  3549. bp->autoneg = autoneg;
  3550. bp->advertising = advertising;
  3551. bp->req_line_speed = req_line_speed;
  3552. bp->req_duplex = req_duplex;
  3553. spin_lock_irq(&bp->phy_lock);
  3554. bnx2_setup_phy(bp);
  3555. spin_unlock_irq(&bp->phy_lock);
  3556. return 0;
  3557. }
  3558. static void
  3559. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  3560. {
  3561. struct bnx2 *bp = dev->priv;
  3562. strcpy(info->driver, DRV_MODULE_NAME);
  3563. strcpy(info->version, DRV_MODULE_VERSION);
  3564. strcpy(info->bus_info, pci_name(bp->pdev));
  3565. info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
  3566. info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
  3567. info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
  3568. info->fw_version[6] = (bp->fw_ver & 0xff) + '0';
  3569. info->fw_version[1] = info->fw_version[3] = info->fw_version[5] = '.';
  3570. info->fw_version[7] = 0;
  3571. }
  3572. static void
  3573. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3574. {
  3575. struct bnx2 *bp = dev->priv;
  3576. if (bp->flags & NO_WOL_FLAG) {
  3577. wol->supported = 0;
  3578. wol->wolopts = 0;
  3579. }
  3580. else {
  3581. wol->supported = WAKE_MAGIC;
  3582. if (bp->wol)
  3583. wol->wolopts = WAKE_MAGIC;
  3584. else
  3585. wol->wolopts = 0;
  3586. }
  3587. memset(&wol->sopass, 0, sizeof(wol->sopass));
  3588. }
  3589. static int
  3590. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3591. {
  3592. struct bnx2 *bp = dev->priv;
  3593. if (wol->wolopts & ~WAKE_MAGIC)
  3594. return -EINVAL;
  3595. if (wol->wolopts & WAKE_MAGIC) {
  3596. if (bp->flags & NO_WOL_FLAG)
  3597. return -EINVAL;
  3598. bp->wol = 1;
  3599. }
  3600. else {
  3601. bp->wol = 0;
  3602. }
  3603. return 0;
  3604. }
  3605. static int
  3606. bnx2_nway_reset(struct net_device *dev)
  3607. {
  3608. struct bnx2 *bp = dev->priv;
  3609. u32 bmcr;
  3610. if (!(bp->autoneg & AUTONEG_SPEED)) {
  3611. return -EINVAL;
  3612. }
  3613. spin_lock_irq(&bp->phy_lock);
  3614. /* Force a link down visible on the other side */
  3615. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3616. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  3617. spin_unlock_irq(&bp->phy_lock);
  3618. msleep(20);
  3619. spin_lock_irq(&bp->phy_lock);
  3620. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  3621. bp->serdes_an_pending = SERDES_AN_TIMEOUT /
  3622. bp->timer_interval;
  3623. }
  3624. }
  3625. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3626. bmcr &= ~BMCR_LOOPBACK;
  3627. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  3628. spin_unlock_irq(&bp->phy_lock);
  3629. return 0;
  3630. }
  3631. static int
  3632. bnx2_get_eeprom_len(struct net_device *dev)
  3633. {
  3634. struct bnx2 *bp = dev->priv;
  3635. if (bp->flash_info == 0)
  3636. return 0;
  3637. return (int) bp->flash_info->total_size;
  3638. }
  3639. static int
  3640. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3641. u8 *eebuf)
  3642. {
  3643. struct bnx2 *bp = dev->priv;
  3644. int rc;
  3645. if (eeprom->offset > bp->flash_info->total_size)
  3646. return -EINVAL;
  3647. if ((eeprom->offset + eeprom->len) > bp->flash_info->total_size)
  3648. eeprom->len = bp->flash_info->total_size - eeprom->offset;
  3649. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  3650. return rc;
  3651. }
  3652. static int
  3653. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  3654. u8 *eebuf)
  3655. {
  3656. struct bnx2 *bp = dev->priv;
  3657. int rc;
  3658. if (eeprom->offset > bp->flash_info->total_size)
  3659. return -EINVAL;
  3660. if ((eeprom->offset + eeprom->len) > bp->flash_info->total_size)
  3661. eeprom->len = bp->flash_info->total_size - eeprom->offset;
  3662. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  3663. return rc;
  3664. }
  3665. static int
  3666. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  3667. {
  3668. struct bnx2 *bp = dev->priv;
  3669. memset(coal, 0, sizeof(struct ethtool_coalesce));
  3670. coal->rx_coalesce_usecs = bp->rx_ticks;
  3671. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  3672. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  3673. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  3674. coal->tx_coalesce_usecs = bp->tx_ticks;
  3675. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  3676. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  3677. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  3678. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  3679. return 0;
  3680. }
  3681. static int
  3682. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  3683. {
  3684. struct bnx2 *bp = dev->priv;
  3685. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  3686. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  3687. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  3688. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  3689. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  3690. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  3691. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  3692. if (bp->rx_quick_cons_trip_int > 0xff)
  3693. bp->rx_quick_cons_trip_int = 0xff;
  3694. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  3695. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  3696. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  3697. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  3698. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  3699. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  3700. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  3701. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  3702. 0xff;
  3703. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  3704. if (bp->stats_ticks > 0xffff00) bp->stats_ticks = 0xffff00;
  3705. bp->stats_ticks &= 0xffff00;
  3706. if (netif_running(bp->dev)) {
  3707. bnx2_netif_stop(bp);
  3708. bnx2_init_nic(bp);
  3709. bnx2_netif_start(bp);
  3710. }
  3711. return 0;
  3712. }
  3713. static void
  3714. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  3715. {
  3716. struct bnx2 *bp = dev->priv;
  3717. ering->rx_max_pending = MAX_RX_DESC_CNT;
  3718. ering->rx_mini_max_pending = 0;
  3719. ering->rx_jumbo_max_pending = 0;
  3720. ering->rx_pending = bp->rx_ring_size;
  3721. ering->rx_mini_pending = 0;
  3722. ering->rx_jumbo_pending = 0;
  3723. ering->tx_max_pending = MAX_TX_DESC_CNT;
  3724. ering->tx_pending = bp->tx_ring_size;
  3725. }
  3726. static int
  3727. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  3728. {
  3729. struct bnx2 *bp = dev->priv;
  3730. if ((ering->rx_pending > MAX_RX_DESC_CNT) ||
  3731. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  3732. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  3733. return -EINVAL;
  3734. }
  3735. bp->rx_ring_size = ering->rx_pending;
  3736. bp->tx_ring_size = ering->tx_pending;
  3737. if (netif_running(bp->dev)) {
  3738. bnx2_netif_stop(bp);
  3739. bnx2_init_nic(bp);
  3740. bnx2_netif_start(bp);
  3741. }
  3742. return 0;
  3743. }
  3744. static void
  3745. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  3746. {
  3747. struct bnx2 *bp = dev->priv;
  3748. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  3749. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  3750. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  3751. }
  3752. static int
  3753. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  3754. {
  3755. struct bnx2 *bp = dev->priv;
  3756. bp->req_flow_ctrl = 0;
  3757. if (epause->rx_pause)
  3758. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  3759. if (epause->tx_pause)
  3760. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  3761. if (epause->autoneg) {
  3762. bp->autoneg |= AUTONEG_FLOW_CTRL;
  3763. }
  3764. else {
  3765. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  3766. }
  3767. spin_lock_irq(&bp->phy_lock);
  3768. bnx2_setup_phy(bp);
  3769. spin_unlock_irq(&bp->phy_lock);
  3770. return 0;
  3771. }
  3772. static u32
  3773. bnx2_get_rx_csum(struct net_device *dev)
  3774. {
  3775. struct bnx2 *bp = dev->priv;
  3776. return bp->rx_csum;
  3777. }
  3778. static int
  3779. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  3780. {
  3781. struct bnx2 *bp = dev->priv;
  3782. bp->rx_csum = data;
  3783. return 0;
  3784. }
  3785. #define BNX2_NUM_STATS 45
  3786. static struct {
  3787. char string[ETH_GSTRING_LEN];
  3788. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  3789. { "rx_bytes" },
  3790. { "rx_error_bytes" },
  3791. { "tx_bytes" },
  3792. { "tx_error_bytes" },
  3793. { "rx_ucast_packets" },
  3794. { "rx_mcast_packets" },
  3795. { "rx_bcast_packets" },
  3796. { "tx_ucast_packets" },
  3797. { "tx_mcast_packets" },
  3798. { "tx_bcast_packets" },
  3799. { "tx_mac_errors" },
  3800. { "tx_carrier_errors" },
  3801. { "rx_crc_errors" },
  3802. { "rx_align_errors" },
  3803. { "tx_single_collisions" },
  3804. { "tx_multi_collisions" },
  3805. { "tx_deferred" },
  3806. { "tx_excess_collisions" },
  3807. { "tx_late_collisions" },
  3808. { "tx_total_collisions" },
  3809. { "rx_fragments" },
  3810. { "rx_jabbers" },
  3811. { "rx_undersize_packets" },
  3812. { "rx_oversize_packets" },
  3813. { "rx_64_byte_packets" },
  3814. { "rx_65_to_127_byte_packets" },
  3815. { "rx_128_to_255_byte_packets" },
  3816. { "rx_256_to_511_byte_packets" },
  3817. { "rx_512_to_1023_byte_packets" },
  3818. { "rx_1024_to_1522_byte_packets" },
  3819. { "rx_1523_to_9022_byte_packets" },
  3820. { "tx_64_byte_packets" },
  3821. { "tx_65_to_127_byte_packets" },
  3822. { "tx_128_to_255_byte_packets" },
  3823. { "tx_256_to_511_byte_packets" },
  3824. { "tx_512_to_1023_byte_packets" },
  3825. { "tx_1024_to_1522_byte_packets" },
  3826. { "tx_1523_to_9022_byte_packets" },
  3827. { "rx_xon_frames" },
  3828. { "rx_xoff_frames" },
  3829. { "tx_xon_frames" },
  3830. { "tx_xoff_frames" },
  3831. { "rx_mac_ctrl_frames" },
  3832. { "rx_filtered_packets" },
  3833. { "rx_discards" },
  3834. };
  3835. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  3836. static unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  3837. STATS_OFFSET32(stat_IfHCInOctets_hi),
  3838. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  3839. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  3840. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  3841. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  3842. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  3843. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  3844. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  3845. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  3846. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  3847. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  3848. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  3849. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  3850. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  3851. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  3852. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  3853. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  3854. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  3855. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  3856. STATS_OFFSET32(stat_EtherStatsCollisions),
  3857. STATS_OFFSET32(stat_EtherStatsFragments),
  3858. STATS_OFFSET32(stat_EtherStatsJabbers),
  3859. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  3860. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  3861. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  3862. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  3863. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  3864. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  3865. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  3866. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  3867. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  3868. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  3869. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  3870. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  3871. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  3872. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  3873. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  3874. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  3875. STATS_OFFSET32(stat_XonPauseFramesReceived),
  3876. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  3877. STATS_OFFSET32(stat_OutXonSent),
  3878. STATS_OFFSET32(stat_OutXoffSent),
  3879. STATS_OFFSET32(stat_MacControlFramesReceived),
  3880. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  3881. STATS_OFFSET32(stat_IfInMBUFDiscards),
  3882. };
  3883. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  3884. * skipped because of errata.
  3885. */
  3886. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  3887. 8,0,8,8,8,8,8,8,8,8,
  3888. 4,0,4,4,4,4,4,4,4,4,
  3889. 4,4,4,4,4,4,4,4,4,4,
  3890. 4,4,4,4,4,4,4,4,4,4,
  3891. 4,4,4,4,4,
  3892. };
  3893. #define BNX2_NUM_TESTS 6
  3894. static struct {
  3895. char string[ETH_GSTRING_LEN];
  3896. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  3897. { "register_test (offline)" },
  3898. { "memory_test (offline)" },
  3899. { "loopback_test (offline)" },
  3900. { "nvram_test (online)" },
  3901. { "interrupt_test (online)" },
  3902. { "link_test (online)" },
  3903. };
  3904. static int
  3905. bnx2_self_test_count(struct net_device *dev)
  3906. {
  3907. return BNX2_NUM_TESTS;
  3908. }
  3909. static void
  3910. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  3911. {
  3912. struct bnx2 *bp = dev->priv;
  3913. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  3914. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  3915. bnx2_netif_stop(bp);
  3916. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  3917. bnx2_free_skbs(bp);
  3918. if (bnx2_test_registers(bp) != 0) {
  3919. buf[0] = 1;
  3920. etest->flags |= ETH_TEST_FL_FAILED;
  3921. }
  3922. if (bnx2_test_memory(bp) != 0) {
  3923. buf[1] = 1;
  3924. etest->flags |= ETH_TEST_FL_FAILED;
  3925. }
  3926. if (bnx2_test_loopback(bp) != 0) {
  3927. buf[2] = 1;
  3928. etest->flags |= ETH_TEST_FL_FAILED;
  3929. }
  3930. if (!netif_running(bp->dev)) {
  3931. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  3932. }
  3933. else {
  3934. bnx2_init_nic(bp);
  3935. bnx2_netif_start(bp);
  3936. }
  3937. /* wait for link up */
  3938. msleep_interruptible(3000);
  3939. if ((!bp->link_up) && !(bp->phy_flags & PHY_SERDES_FLAG))
  3940. msleep_interruptible(4000);
  3941. }
  3942. if (bnx2_test_nvram(bp) != 0) {
  3943. buf[3] = 1;
  3944. etest->flags |= ETH_TEST_FL_FAILED;
  3945. }
  3946. if (bnx2_test_intr(bp) != 0) {
  3947. buf[4] = 1;
  3948. etest->flags |= ETH_TEST_FL_FAILED;
  3949. }
  3950. if (bnx2_test_link(bp) != 0) {
  3951. buf[5] = 1;
  3952. etest->flags |= ETH_TEST_FL_FAILED;
  3953. }
  3954. }
  3955. static void
  3956. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  3957. {
  3958. switch (stringset) {
  3959. case ETH_SS_STATS:
  3960. memcpy(buf, bnx2_stats_str_arr,
  3961. sizeof(bnx2_stats_str_arr));
  3962. break;
  3963. case ETH_SS_TEST:
  3964. memcpy(buf, bnx2_tests_str_arr,
  3965. sizeof(bnx2_tests_str_arr));
  3966. break;
  3967. }
  3968. }
  3969. static int
  3970. bnx2_get_stats_count(struct net_device *dev)
  3971. {
  3972. return BNX2_NUM_STATS;
  3973. }
  3974. static void
  3975. bnx2_get_ethtool_stats(struct net_device *dev,
  3976. struct ethtool_stats *stats, u64 *buf)
  3977. {
  3978. struct bnx2 *bp = dev->priv;
  3979. int i;
  3980. u32 *hw_stats = (u32 *) bp->stats_blk;
  3981. u8 *stats_len_arr = NULL;
  3982. if (hw_stats == NULL) {
  3983. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  3984. return;
  3985. }
  3986. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3987. stats_len_arr = bnx2_5706_stats_len_arr;
  3988. for (i = 0; i < BNX2_NUM_STATS; i++) {
  3989. if (stats_len_arr[i] == 0) {
  3990. /* skip this counter */
  3991. buf[i] = 0;
  3992. continue;
  3993. }
  3994. if (stats_len_arr[i] == 4) {
  3995. /* 4-byte counter */
  3996. buf[i] = (u64)
  3997. *(hw_stats + bnx2_stats_offset_arr[i]);
  3998. continue;
  3999. }
  4000. /* 8-byte counter */
  4001. buf[i] = (((u64) *(hw_stats +
  4002. bnx2_stats_offset_arr[i])) << 32) +
  4003. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  4004. }
  4005. }
  4006. static int
  4007. bnx2_phys_id(struct net_device *dev, u32 data)
  4008. {
  4009. struct bnx2 *bp = dev->priv;
  4010. int i;
  4011. u32 save;
  4012. if (data == 0)
  4013. data = 2;
  4014. save = REG_RD(bp, BNX2_MISC_CFG);
  4015. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  4016. for (i = 0; i < (data * 2); i++) {
  4017. if ((i % 2) == 0) {
  4018. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  4019. }
  4020. else {
  4021. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  4022. BNX2_EMAC_LED_1000MB_OVERRIDE |
  4023. BNX2_EMAC_LED_100MB_OVERRIDE |
  4024. BNX2_EMAC_LED_10MB_OVERRIDE |
  4025. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  4026. BNX2_EMAC_LED_TRAFFIC);
  4027. }
  4028. msleep_interruptible(500);
  4029. if (signal_pending(current))
  4030. break;
  4031. }
  4032. REG_WR(bp, BNX2_EMAC_LED, 0);
  4033. REG_WR(bp, BNX2_MISC_CFG, save);
  4034. return 0;
  4035. }
  4036. static struct ethtool_ops bnx2_ethtool_ops = {
  4037. .get_settings = bnx2_get_settings,
  4038. .set_settings = bnx2_set_settings,
  4039. .get_drvinfo = bnx2_get_drvinfo,
  4040. .get_wol = bnx2_get_wol,
  4041. .set_wol = bnx2_set_wol,
  4042. .nway_reset = bnx2_nway_reset,
  4043. .get_link = ethtool_op_get_link,
  4044. .get_eeprom_len = bnx2_get_eeprom_len,
  4045. .get_eeprom = bnx2_get_eeprom,
  4046. .set_eeprom = bnx2_set_eeprom,
  4047. .get_coalesce = bnx2_get_coalesce,
  4048. .set_coalesce = bnx2_set_coalesce,
  4049. .get_ringparam = bnx2_get_ringparam,
  4050. .set_ringparam = bnx2_set_ringparam,
  4051. .get_pauseparam = bnx2_get_pauseparam,
  4052. .set_pauseparam = bnx2_set_pauseparam,
  4053. .get_rx_csum = bnx2_get_rx_csum,
  4054. .set_rx_csum = bnx2_set_rx_csum,
  4055. .get_tx_csum = ethtool_op_get_tx_csum,
  4056. .set_tx_csum = ethtool_op_set_tx_csum,
  4057. .get_sg = ethtool_op_get_sg,
  4058. .set_sg = ethtool_op_set_sg,
  4059. #ifdef BCM_TSO
  4060. .get_tso = ethtool_op_get_tso,
  4061. .set_tso = ethtool_op_set_tso,
  4062. #endif
  4063. .self_test_count = bnx2_self_test_count,
  4064. .self_test = bnx2_self_test,
  4065. .get_strings = bnx2_get_strings,
  4066. .phys_id = bnx2_phys_id,
  4067. .get_stats_count = bnx2_get_stats_count,
  4068. .get_ethtool_stats = bnx2_get_ethtool_stats,
  4069. };
  4070. /* Called with rtnl_lock */
  4071. static int
  4072. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  4073. {
  4074. struct mii_ioctl_data *data = if_mii(ifr);
  4075. struct bnx2 *bp = dev->priv;
  4076. int err;
  4077. switch(cmd) {
  4078. case SIOCGMIIPHY:
  4079. data->phy_id = bp->phy_addr;
  4080. /* fallthru */
  4081. case SIOCGMIIREG: {
  4082. u32 mii_regval;
  4083. spin_lock_irq(&bp->phy_lock);
  4084. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  4085. spin_unlock_irq(&bp->phy_lock);
  4086. data->val_out = mii_regval;
  4087. return err;
  4088. }
  4089. case SIOCSMIIREG:
  4090. if (!capable(CAP_NET_ADMIN))
  4091. return -EPERM;
  4092. spin_lock_irq(&bp->phy_lock);
  4093. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  4094. spin_unlock_irq(&bp->phy_lock);
  4095. return err;
  4096. default:
  4097. /* do nothing */
  4098. break;
  4099. }
  4100. return -EOPNOTSUPP;
  4101. }
  4102. /* Called with rtnl_lock */
  4103. static int
  4104. bnx2_change_mac_addr(struct net_device *dev, void *p)
  4105. {
  4106. struct sockaddr *addr = p;
  4107. struct bnx2 *bp = dev->priv;
  4108. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4109. if (netif_running(dev))
  4110. bnx2_set_mac_addr(bp);
  4111. return 0;
  4112. }
  4113. /* Called with rtnl_lock */
  4114. static int
  4115. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  4116. {
  4117. struct bnx2 *bp = dev->priv;
  4118. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  4119. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  4120. return -EINVAL;
  4121. dev->mtu = new_mtu;
  4122. if (netif_running(dev)) {
  4123. bnx2_netif_stop(bp);
  4124. bnx2_init_nic(bp);
  4125. bnx2_netif_start(bp);
  4126. }
  4127. return 0;
  4128. }
  4129. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4130. static void
  4131. poll_bnx2(struct net_device *dev)
  4132. {
  4133. struct bnx2 *bp = dev->priv;
  4134. disable_irq(bp->pdev->irq);
  4135. bnx2_interrupt(bp->pdev->irq, dev, NULL);
  4136. enable_irq(bp->pdev->irq);
  4137. }
  4138. #endif
  4139. static int __devinit
  4140. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  4141. {
  4142. struct bnx2 *bp;
  4143. unsigned long mem_len;
  4144. int rc;
  4145. u32 reg;
  4146. SET_MODULE_OWNER(dev);
  4147. SET_NETDEV_DEV(dev, &pdev->dev);
  4148. bp = dev->priv;
  4149. bp->flags = 0;
  4150. bp->phy_flags = 0;
  4151. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  4152. rc = pci_enable_device(pdev);
  4153. if (rc) {
  4154. printk(KERN_ERR PFX "Cannot enable PCI device, aborting.");
  4155. goto err_out;
  4156. }
  4157. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  4158. printk(KERN_ERR PFX "Cannot find PCI device base address, "
  4159. "aborting.\n");
  4160. rc = -ENODEV;
  4161. goto err_out_disable;
  4162. }
  4163. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  4164. if (rc) {
  4165. printk(KERN_ERR PFX "Cannot obtain PCI resources, aborting.\n");
  4166. goto err_out_disable;
  4167. }
  4168. pci_set_master(pdev);
  4169. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  4170. if (bp->pm_cap == 0) {
  4171. printk(KERN_ERR PFX "Cannot find power management capability, "
  4172. "aborting.\n");
  4173. rc = -EIO;
  4174. goto err_out_release;
  4175. }
  4176. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  4177. if (bp->pcix_cap == 0) {
  4178. printk(KERN_ERR PFX "Cannot find PCIX capability, aborting.\n");
  4179. rc = -EIO;
  4180. goto err_out_release;
  4181. }
  4182. if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
  4183. bp->flags |= USING_DAC_FLAG;
  4184. if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
  4185. printk(KERN_ERR PFX "pci_set_consistent_dma_mask "
  4186. "failed, aborting.\n");
  4187. rc = -EIO;
  4188. goto err_out_release;
  4189. }
  4190. }
  4191. else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
  4192. printk(KERN_ERR PFX "System does not support DMA, aborting.\n");
  4193. rc = -EIO;
  4194. goto err_out_release;
  4195. }
  4196. bp->dev = dev;
  4197. bp->pdev = pdev;
  4198. spin_lock_init(&bp->phy_lock);
  4199. spin_lock_init(&bp->tx_lock);
  4200. INIT_WORK(&bp->reset_task, bnx2_reset_task, bp);
  4201. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  4202. mem_len = MB_GET_CID_ADDR(17);
  4203. dev->mem_end = dev->mem_start + mem_len;
  4204. dev->irq = pdev->irq;
  4205. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  4206. if (!bp->regview) {
  4207. printk(KERN_ERR PFX "Cannot map register space, aborting.\n");
  4208. rc = -ENOMEM;
  4209. goto err_out_release;
  4210. }
  4211. /* Configure byte swap and enable write to the reg_window registers.
  4212. * Rely on CPU to do target byte swapping on big endian systems
  4213. * The chip's target access swapping will not swap all accesses
  4214. */
  4215. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  4216. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  4217. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  4218. bnx2_set_power_state(bp, 0);
  4219. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  4220. bp->phy_addr = 1;
  4221. /* Get bus information. */
  4222. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  4223. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  4224. u32 clkreg;
  4225. bp->flags |= PCIX_FLAG;
  4226. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  4227. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  4228. switch (clkreg) {
  4229. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  4230. bp->bus_speed_mhz = 133;
  4231. break;
  4232. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  4233. bp->bus_speed_mhz = 100;
  4234. break;
  4235. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  4236. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  4237. bp->bus_speed_mhz = 66;
  4238. break;
  4239. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  4240. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  4241. bp->bus_speed_mhz = 50;
  4242. break;
  4243. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  4244. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  4245. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  4246. bp->bus_speed_mhz = 33;
  4247. break;
  4248. }
  4249. }
  4250. else {
  4251. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  4252. bp->bus_speed_mhz = 66;
  4253. else
  4254. bp->bus_speed_mhz = 33;
  4255. }
  4256. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  4257. bp->flags |= PCI_32BIT_FLAG;
  4258. /* 5706A0 may falsely detect SERR and PERR. */
  4259. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4260. reg = REG_RD(bp, PCI_COMMAND);
  4261. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  4262. REG_WR(bp, PCI_COMMAND, reg);
  4263. }
  4264. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  4265. !(bp->flags & PCIX_FLAG)) {
  4266. printk(KERN_ERR PFX "5706 A1 can only be used in a PCIX bus, "
  4267. "aborting.\n");
  4268. goto err_out_unmap;
  4269. }
  4270. bnx2_init_nvram(bp);
  4271. /* Get the permanent MAC address. First we need to make sure the
  4272. * firmware is actually running.
  4273. */
  4274. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_DEV_INFO_SIGNATURE);
  4275. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  4276. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  4277. printk(KERN_ERR PFX "Firmware not running, aborting.\n");
  4278. rc = -ENODEV;
  4279. goto err_out_unmap;
  4280. }
  4281. bp->fw_ver = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE +
  4282. BNX2_DEV_INFO_BC_REV);
  4283. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_PORT_HW_CFG_MAC_UPPER);
  4284. bp->mac_addr[0] = (u8) (reg >> 8);
  4285. bp->mac_addr[1] = (u8) reg;
  4286. reg = REG_RD_IND(bp, HOST_VIEW_SHMEM_BASE + BNX2_PORT_HW_CFG_MAC_LOWER);
  4287. bp->mac_addr[2] = (u8) (reg >> 24);
  4288. bp->mac_addr[3] = (u8) (reg >> 16);
  4289. bp->mac_addr[4] = (u8) (reg >> 8);
  4290. bp->mac_addr[5] = (u8) reg;
  4291. bp->tx_ring_size = MAX_TX_DESC_CNT;
  4292. bp->rx_ring_size = 100;
  4293. bp->rx_csum = 1;
  4294. bp->rx_offset = sizeof(struct l2_fhdr) + 2;
  4295. bp->tx_quick_cons_trip_int = 20;
  4296. bp->tx_quick_cons_trip = 20;
  4297. bp->tx_ticks_int = 80;
  4298. bp->tx_ticks = 80;
  4299. bp->rx_quick_cons_trip_int = 6;
  4300. bp->rx_quick_cons_trip = 6;
  4301. bp->rx_ticks_int = 18;
  4302. bp->rx_ticks = 18;
  4303. bp->stats_ticks = 1000000 & 0xffff00;
  4304. bp->timer_interval = HZ;
  4305. /* Disable WOL support if we are running on a SERDES chip. */
  4306. if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) {
  4307. bp->phy_flags |= PHY_SERDES_FLAG;
  4308. bp->flags |= NO_WOL_FLAG;
  4309. }
  4310. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4311. bp->tx_quick_cons_trip_int =
  4312. bp->tx_quick_cons_trip;
  4313. bp->tx_ticks_int = bp->tx_ticks;
  4314. bp->rx_quick_cons_trip_int =
  4315. bp->rx_quick_cons_trip;
  4316. bp->rx_ticks_int = bp->rx_ticks;
  4317. bp->comp_prod_trip_int = bp->comp_prod_trip;
  4318. bp->com_ticks_int = bp->com_ticks;
  4319. bp->cmd_ticks_int = bp->cmd_ticks;
  4320. }
  4321. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  4322. bp->req_line_speed = 0;
  4323. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4324. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  4325. }
  4326. else {
  4327. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  4328. }
  4329. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  4330. return 0;
  4331. err_out_unmap:
  4332. if (bp->regview) {
  4333. iounmap(bp->regview);
  4334. }
  4335. err_out_release:
  4336. pci_release_regions(pdev);
  4337. err_out_disable:
  4338. pci_disable_device(pdev);
  4339. pci_set_drvdata(pdev, NULL);
  4340. err_out:
  4341. return rc;
  4342. }
  4343. static int __devinit
  4344. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4345. {
  4346. static int version_printed = 0;
  4347. struct net_device *dev = NULL;
  4348. struct bnx2 *bp;
  4349. int rc, i;
  4350. if (version_printed++ == 0)
  4351. printk(KERN_INFO "%s", version);
  4352. /* dev zeroed in init_etherdev */
  4353. dev = alloc_etherdev(sizeof(*bp));
  4354. if (!dev)
  4355. return -ENOMEM;
  4356. rc = bnx2_init_board(pdev, dev);
  4357. if (rc < 0) {
  4358. free_netdev(dev);
  4359. return rc;
  4360. }
  4361. dev->open = bnx2_open;
  4362. dev->hard_start_xmit = bnx2_start_xmit;
  4363. dev->stop = bnx2_close;
  4364. dev->get_stats = bnx2_get_stats;
  4365. dev->set_multicast_list = bnx2_set_rx_mode;
  4366. dev->do_ioctl = bnx2_ioctl;
  4367. dev->set_mac_address = bnx2_change_mac_addr;
  4368. dev->change_mtu = bnx2_change_mtu;
  4369. dev->tx_timeout = bnx2_tx_timeout;
  4370. dev->watchdog_timeo = TX_TIMEOUT;
  4371. #ifdef BCM_VLAN
  4372. dev->vlan_rx_register = bnx2_vlan_rx_register;
  4373. dev->vlan_rx_kill_vid = bnx2_vlan_rx_kill_vid;
  4374. #endif
  4375. dev->poll = bnx2_poll;
  4376. dev->ethtool_ops = &bnx2_ethtool_ops;
  4377. dev->weight = 64;
  4378. bp = dev->priv;
  4379. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4380. dev->poll_controller = poll_bnx2;
  4381. #endif
  4382. if ((rc = register_netdev(dev))) {
  4383. printk(KERN_ERR PFX "Cannot register net device\n");
  4384. if (bp->regview)
  4385. iounmap(bp->regview);
  4386. pci_release_regions(pdev);
  4387. pci_disable_device(pdev);
  4388. pci_set_drvdata(pdev, NULL);
  4389. free_netdev(dev);
  4390. return rc;
  4391. }
  4392. pci_set_drvdata(pdev, dev);
  4393. memcpy(dev->dev_addr, bp->mac_addr, 6);
  4394. bp->name = board_info[ent->driver_data].name,
  4395. printk(KERN_INFO "%s: %s (%c%d) PCI%s %s %dMHz found at mem %lx, "
  4396. "IRQ %d, ",
  4397. dev->name,
  4398. bp->name,
  4399. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  4400. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  4401. ((bp->flags & PCIX_FLAG) ? "-X" : ""),
  4402. ((bp->flags & PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
  4403. bp->bus_speed_mhz,
  4404. dev->base_addr,
  4405. bp->pdev->irq);
  4406. printk("node addr ");
  4407. for (i = 0; i < 6; i++)
  4408. printk("%2.2x", dev->dev_addr[i]);
  4409. printk("\n");
  4410. dev->features |= NETIF_F_SG;
  4411. if (bp->flags & USING_DAC_FLAG)
  4412. dev->features |= NETIF_F_HIGHDMA;
  4413. dev->features |= NETIF_F_IP_CSUM;
  4414. #ifdef BCM_VLAN
  4415. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  4416. #endif
  4417. #ifdef BCM_TSO
  4418. dev->features |= NETIF_F_TSO;
  4419. #endif
  4420. netif_carrier_off(bp->dev);
  4421. return 0;
  4422. }
  4423. static void __devexit
  4424. bnx2_remove_one(struct pci_dev *pdev)
  4425. {
  4426. struct net_device *dev = pci_get_drvdata(pdev);
  4427. struct bnx2 *bp = dev->priv;
  4428. unregister_netdev(dev);
  4429. if (bp->regview)
  4430. iounmap(bp->regview);
  4431. free_netdev(dev);
  4432. pci_release_regions(pdev);
  4433. pci_disable_device(pdev);
  4434. pci_set_drvdata(pdev, NULL);
  4435. }
  4436. static int
  4437. bnx2_suspend(struct pci_dev *pdev, u32 state)
  4438. {
  4439. struct net_device *dev = pci_get_drvdata(pdev);
  4440. struct bnx2 *bp = dev->priv;
  4441. u32 reset_code;
  4442. if (!netif_running(dev))
  4443. return 0;
  4444. bnx2_netif_stop(bp);
  4445. netif_device_detach(dev);
  4446. del_timer_sync(&bp->timer);
  4447. if (bp->wol)
  4448. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4449. else
  4450. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4451. bnx2_reset_chip(bp, reset_code);
  4452. bnx2_free_skbs(bp);
  4453. bnx2_set_power_state(bp, state);
  4454. return 0;
  4455. }
  4456. static int
  4457. bnx2_resume(struct pci_dev *pdev)
  4458. {
  4459. struct net_device *dev = pci_get_drvdata(pdev);
  4460. struct bnx2 *bp = dev->priv;
  4461. if (!netif_running(dev))
  4462. return 0;
  4463. bnx2_set_power_state(bp, 0);
  4464. netif_device_attach(dev);
  4465. bnx2_init_nic(bp);
  4466. bnx2_netif_start(bp);
  4467. return 0;
  4468. }
  4469. static struct pci_driver bnx2_pci_driver = {
  4470. .name = DRV_MODULE_NAME,
  4471. .id_table = bnx2_pci_tbl,
  4472. .probe = bnx2_init_one,
  4473. .remove = __devexit_p(bnx2_remove_one),
  4474. .suspend = bnx2_suspend,
  4475. .resume = bnx2_resume,
  4476. };
  4477. static int __init bnx2_init(void)
  4478. {
  4479. return pci_module_init(&bnx2_pci_driver);
  4480. }
  4481. static void __exit bnx2_cleanup(void)
  4482. {
  4483. pci_unregister_driver(&bnx2_pci_driver);
  4484. }
  4485. module_init(bnx2_init);
  4486. module_exit(bnx2_cleanup);