bnx2.c 134 KB

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