bnx2.c 157 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004-2007 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 <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/kernel.h>
  14. #include <linux/timer.h>
  15. #include <linux/errno.h>
  16. #include <linux/ioport.h>
  17. #include <linux/slab.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/dma-mapping.h>
  26. #include <asm/bitops.h>
  27. #include <asm/io.h>
  28. #include <asm/irq.h>
  29. #include <linux/delay.h>
  30. #include <asm/byteorder.h>
  31. #include <asm/page.h>
  32. #include <linux/time.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/mii.h>
  35. #ifdef NETIF_F_HW_VLAN_TX
  36. #include <linux/if_vlan.h>
  37. #define BCM_VLAN 1
  38. #endif
  39. #include <net/ip.h>
  40. #include <net/tcp.h>
  41. #include <net/checksum.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/crc32.h>
  44. #include <linux/prefetch.h>
  45. #include <linux/cache.h>
  46. #include <linux/zlib.h>
  47. #include "bnx2.h"
  48. #include "bnx2_fw.h"
  49. #include "bnx2_fw2.h"
  50. #define DRV_MODULE_NAME "bnx2"
  51. #define PFX DRV_MODULE_NAME ": "
  52. #define DRV_MODULE_VERSION "1.5.11"
  53. #define DRV_MODULE_RELDATE "June 4, 2007"
  54. #define RUN_AT(x) (jiffies + (x))
  55. /* Time in jiffies before concluding the transmitter is hung. */
  56. #define TX_TIMEOUT (5*HZ)
  57. static const char version[] __devinitdata =
  58. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  59. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  60. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708 Driver");
  61. MODULE_LICENSE("GPL");
  62. MODULE_VERSION(DRV_MODULE_VERSION);
  63. static int disable_msi = 0;
  64. module_param(disable_msi, int, 0);
  65. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  66. typedef enum {
  67. BCM5706 = 0,
  68. NC370T,
  69. NC370I,
  70. BCM5706S,
  71. NC370F,
  72. BCM5708,
  73. BCM5708S,
  74. BCM5709,
  75. BCM5709S,
  76. } board_t;
  77. /* indexed by board_t, above */
  78. static const struct {
  79. char *name;
  80. } board_info[] __devinitdata = {
  81. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  82. { "HP NC370T Multifunction Gigabit Server Adapter" },
  83. { "HP NC370i Multifunction Gigabit Server Adapter" },
  84. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  85. { "HP NC370F Multifunction Gigabit Server Adapter" },
  86. { "Broadcom NetXtreme II BCM5708 1000Base-T" },
  87. { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
  88. { "Broadcom NetXtreme II BCM5709 1000Base-T" },
  89. { "Broadcom NetXtreme II BCM5709 1000Base-SX" },
  90. };
  91. static struct pci_device_id bnx2_pci_tbl[] = {
  92. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  93. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  94. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  95. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  96. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  97. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  98. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708,
  99. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708 },
  100. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  101. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  102. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  103. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  104. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708S,
  105. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708S },
  106. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709,
  107. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709 },
  108. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709S,
  109. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709S },
  110. { 0, }
  111. };
  112. static struct flash_spec flash_table[] =
  113. {
  114. /* Slow EEPROM */
  115. {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
  116. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  117. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  118. "EEPROM - slow"},
  119. /* Expansion entry 0001 */
  120. {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
  121. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  122. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  123. "Entry 0001"},
  124. /* Saifun SA25F010 (non-buffered flash) */
  125. /* strap, cfg1, & write1 need updates */
  126. {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
  127. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  128. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  129. "Non-buffered flash (128kB)"},
  130. /* Saifun SA25F020 (non-buffered flash) */
  131. /* strap, cfg1, & write1 need updates */
  132. {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
  133. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  134. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  135. "Non-buffered flash (256kB)"},
  136. /* Expansion entry 0100 */
  137. {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
  138. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  139. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  140. "Entry 0100"},
  141. /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
  142. {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
  143. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  144. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
  145. "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
  146. /* Entry 0110: ST M45PE20 (non-buffered flash)*/
  147. {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
  148. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  149. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
  150. "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
  151. /* Saifun SA25F005 (non-buffered flash) */
  152. /* strap, cfg1, & write1 need updates */
  153. {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
  154. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  155. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  156. "Non-buffered flash (64kB)"},
  157. /* Fast EEPROM */
  158. {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
  159. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  160. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  161. "EEPROM - fast"},
  162. /* Expansion entry 1001 */
  163. {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
  164. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  165. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  166. "Entry 1001"},
  167. /* Expansion entry 1010 */
  168. {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
  169. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  170. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  171. "Entry 1010"},
  172. /* ATMEL AT45DB011B (buffered flash) */
  173. {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
  174. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  175. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  176. "Buffered flash (128kB)"},
  177. /* Expansion entry 1100 */
  178. {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
  179. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  180. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  181. "Entry 1100"},
  182. /* Expansion entry 1101 */
  183. {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
  184. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  185. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  186. "Entry 1101"},
  187. /* Ateml Expansion entry 1110 */
  188. {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
  189. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  190. BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
  191. "Entry 1110 (Atmel)"},
  192. /* ATMEL AT45DB021B (buffered flash) */
  193. {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
  194. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  195. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
  196. "Buffered flash (256kB)"},
  197. };
  198. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  199. static inline u32 bnx2_tx_avail(struct bnx2 *bp)
  200. {
  201. u32 diff;
  202. smp_mb();
  203. /* The ring uses 256 indices for 255 entries, one of them
  204. * needs to be skipped.
  205. */
  206. diff = bp->tx_prod - bp->tx_cons;
  207. if (unlikely(diff >= TX_DESC_CNT)) {
  208. diff &= 0xffff;
  209. if (diff == TX_DESC_CNT)
  210. diff = MAX_TX_DESC_CNT;
  211. }
  212. return (bp->tx_ring_size - diff);
  213. }
  214. static u32
  215. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  216. {
  217. u32 val;
  218. spin_lock_bh(&bp->indirect_lock);
  219. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  220. val = REG_RD(bp, BNX2_PCICFG_REG_WINDOW);
  221. spin_unlock_bh(&bp->indirect_lock);
  222. return val;
  223. }
  224. static void
  225. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  226. {
  227. spin_lock_bh(&bp->indirect_lock);
  228. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  229. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  230. spin_unlock_bh(&bp->indirect_lock);
  231. }
  232. static void
  233. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  234. {
  235. offset += cid_addr;
  236. spin_lock_bh(&bp->indirect_lock);
  237. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  238. int i;
  239. REG_WR(bp, BNX2_CTX_CTX_DATA, val);
  240. REG_WR(bp, BNX2_CTX_CTX_CTRL,
  241. offset | BNX2_CTX_CTX_CTRL_WRITE_REQ);
  242. for (i = 0; i < 5; i++) {
  243. u32 val;
  244. val = REG_RD(bp, BNX2_CTX_CTX_CTRL);
  245. if ((val & BNX2_CTX_CTX_CTRL_WRITE_REQ) == 0)
  246. break;
  247. udelay(5);
  248. }
  249. } else {
  250. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  251. REG_WR(bp, BNX2_CTX_DATA, val);
  252. }
  253. spin_unlock_bh(&bp->indirect_lock);
  254. }
  255. static int
  256. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  257. {
  258. u32 val1;
  259. int i, ret;
  260. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  261. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  262. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  263. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  264. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  265. udelay(40);
  266. }
  267. val1 = (bp->phy_addr << 21) | (reg << 16) |
  268. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  269. BNX2_EMAC_MDIO_COMM_START_BUSY;
  270. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  271. for (i = 0; i < 50; i++) {
  272. udelay(10);
  273. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  274. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  275. udelay(5);
  276. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  277. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  278. break;
  279. }
  280. }
  281. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  282. *val = 0x0;
  283. ret = -EBUSY;
  284. }
  285. else {
  286. *val = val1;
  287. ret = 0;
  288. }
  289. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  290. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  291. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  292. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  293. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  294. udelay(40);
  295. }
  296. return ret;
  297. }
  298. static int
  299. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  300. {
  301. u32 val1;
  302. int i, ret;
  303. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  304. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  305. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  306. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  307. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  308. udelay(40);
  309. }
  310. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  311. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  312. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  313. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  314. for (i = 0; i < 50; i++) {
  315. udelay(10);
  316. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  317. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  318. udelay(5);
  319. break;
  320. }
  321. }
  322. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  323. ret = -EBUSY;
  324. else
  325. ret = 0;
  326. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  327. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  328. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  329. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  330. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  331. udelay(40);
  332. }
  333. return ret;
  334. }
  335. static void
  336. bnx2_disable_int(struct bnx2 *bp)
  337. {
  338. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  339. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  340. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  341. }
  342. static void
  343. bnx2_enable_int(struct bnx2 *bp)
  344. {
  345. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  346. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  347. BNX2_PCICFG_INT_ACK_CMD_MASK_INT | bp->last_status_idx);
  348. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  349. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
  350. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  351. }
  352. static void
  353. bnx2_disable_int_sync(struct bnx2 *bp)
  354. {
  355. atomic_inc(&bp->intr_sem);
  356. bnx2_disable_int(bp);
  357. synchronize_irq(bp->pdev->irq);
  358. }
  359. static void
  360. bnx2_netif_stop(struct bnx2 *bp)
  361. {
  362. bnx2_disable_int_sync(bp);
  363. if (netif_running(bp->dev)) {
  364. netif_poll_disable(bp->dev);
  365. netif_tx_disable(bp->dev);
  366. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  367. }
  368. }
  369. static void
  370. bnx2_netif_start(struct bnx2 *bp)
  371. {
  372. if (atomic_dec_and_test(&bp->intr_sem)) {
  373. if (netif_running(bp->dev)) {
  374. netif_wake_queue(bp->dev);
  375. netif_poll_enable(bp->dev);
  376. bnx2_enable_int(bp);
  377. }
  378. }
  379. }
  380. static void
  381. bnx2_free_mem(struct bnx2 *bp)
  382. {
  383. int i;
  384. for (i = 0; i < bp->ctx_pages; i++) {
  385. if (bp->ctx_blk[i]) {
  386. pci_free_consistent(bp->pdev, BCM_PAGE_SIZE,
  387. bp->ctx_blk[i],
  388. bp->ctx_blk_mapping[i]);
  389. bp->ctx_blk[i] = NULL;
  390. }
  391. }
  392. if (bp->status_blk) {
  393. pci_free_consistent(bp->pdev, bp->status_stats_size,
  394. bp->status_blk, bp->status_blk_mapping);
  395. bp->status_blk = NULL;
  396. bp->stats_blk = NULL;
  397. }
  398. if (bp->tx_desc_ring) {
  399. pci_free_consistent(bp->pdev,
  400. sizeof(struct tx_bd) * TX_DESC_CNT,
  401. bp->tx_desc_ring, bp->tx_desc_mapping);
  402. bp->tx_desc_ring = NULL;
  403. }
  404. kfree(bp->tx_buf_ring);
  405. bp->tx_buf_ring = NULL;
  406. for (i = 0; i < bp->rx_max_ring; i++) {
  407. if (bp->rx_desc_ring[i])
  408. pci_free_consistent(bp->pdev,
  409. sizeof(struct rx_bd) * RX_DESC_CNT,
  410. bp->rx_desc_ring[i],
  411. bp->rx_desc_mapping[i]);
  412. bp->rx_desc_ring[i] = NULL;
  413. }
  414. vfree(bp->rx_buf_ring);
  415. bp->rx_buf_ring = NULL;
  416. }
  417. static int
  418. bnx2_alloc_mem(struct bnx2 *bp)
  419. {
  420. int i, status_blk_size;
  421. bp->tx_buf_ring = kzalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
  422. GFP_KERNEL);
  423. if (bp->tx_buf_ring == NULL)
  424. return -ENOMEM;
  425. bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
  426. sizeof(struct tx_bd) *
  427. TX_DESC_CNT,
  428. &bp->tx_desc_mapping);
  429. if (bp->tx_desc_ring == NULL)
  430. goto alloc_mem_err;
  431. bp->rx_buf_ring = vmalloc(sizeof(struct sw_bd) * RX_DESC_CNT *
  432. bp->rx_max_ring);
  433. if (bp->rx_buf_ring == NULL)
  434. goto alloc_mem_err;
  435. memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT *
  436. bp->rx_max_ring);
  437. for (i = 0; i < bp->rx_max_ring; i++) {
  438. bp->rx_desc_ring[i] =
  439. pci_alloc_consistent(bp->pdev,
  440. sizeof(struct rx_bd) * RX_DESC_CNT,
  441. &bp->rx_desc_mapping[i]);
  442. if (bp->rx_desc_ring[i] == NULL)
  443. goto alloc_mem_err;
  444. }
  445. /* Combine status and statistics blocks into one allocation. */
  446. status_blk_size = L1_CACHE_ALIGN(sizeof(struct status_block));
  447. bp->status_stats_size = status_blk_size +
  448. sizeof(struct statistics_block);
  449. bp->status_blk = pci_alloc_consistent(bp->pdev, bp->status_stats_size,
  450. &bp->status_blk_mapping);
  451. if (bp->status_blk == NULL)
  452. goto alloc_mem_err;
  453. memset(bp->status_blk, 0, bp->status_stats_size);
  454. bp->stats_blk = (void *) ((unsigned long) bp->status_blk +
  455. status_blk_size);
  456. bp->stats_blk_mapping = bp->status_blk_mapping + status_blk_size;
  457. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  458. bp->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
  459. if (bp->ctx_pages == 0)
  460. bp->ctx_pages = 1;
  461. for (i = 0; i < bp->ctx_pages; i++) {
  462. bp->ctx_blk[i] = pci_alloc_consistent(bp->pdev,
  463. BCM_PAGE_SIZE,
  464. &bp->ctx_blk_mapping[i]);
  465. if (bp->ctx_blk[i] == NULL)
  466. goto alloc_mem_err;
  467. }
  468. }
  469. return 0;
  470. alloc_mem_err:
  471. bnx2_free_mem(bp);
  472. return -ENOMEM;
  473. }
  474. static void
  475. bnx2_report_fw_link(struct bnx2 *bp)
  476. {
  477. u32 fw_link_status = 0;
  478. if (bp->link_up) {
  479. u32 bmsr;
  480. switch (bp->line_speed) {
  481. case SPEED_10:
  482. if (bp->duplex == DUPLEX_HALF)
  483. fw_link_status = BNX2_LINK_STATUS_10HALF;
  484. else
  485. fw_link_status = BNX2_LINK_STATUS_10FULL;
  486. break;
  487. case SPEED_100:
  488. if (bp->duplex == DUPLEX_HALF)
  489. fw_link_status = BNX2_LINK_STATUS_100HALF;
  490. else
  491. fw_link_status = BNX2_LINK_STATUS_100FULL;
  492. break;
  493. case SPEED_1000:
  494. if (bp->duplex == DUPLEX_HALF)
  495. fw_link_status = BNX2_LINK_STATUS_1000HALF;
  496. else
  497. fw_link_status = BNX2_LINK_STATUS_1000FULL;
  498. break;
  499. case SPEED_2500:
  500. if (bp->duplex == DUPLEX_HALF)
  501. fw_link_status = BNX2_LINK_STATUS_2500HALF;
  502. else
  503. fw_link_status = BNX2_LINK_STATUS_2500FULL;
  504. break;
  505. }
  506. fw_link_status |= BNX2_LINK_STATUS_LINK_UP;
  507. if (bp->autoneg) {
  508. fw_link_status |= BNX2_LINK_STATUS_AN_ENABLED;
  509. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  510. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  511. if (!(bmsr & BMSR_ANEGCOMPLETE) ||
  512. bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)
  513. fw_link_status |= BNX2_LINK_STATUS_PARALLEL_DET;
  514. else
  515. fw_link_status |= BNX2_LINK_STATUS_AN_COMPLETE;
  516. }
  517. }
  518. else
  519. fw_link_status = BNX2_LINK_STATUS_LINK_DOWN;
  520. REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status);
  521. }
  522. static void
  523. bnx2_report_link(struct bnx2 *bp)
  524. {
  525. if (bp->link_up) {
  526. netif_carrier_on(bp->dev);
  527. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  528. printk("%d Mbps ", bp->line_speed);
  529. if (bp->duplex == DUPLEX_FULL)
  530. printk("full duplex");
  531. else
  532. printk("half duplex");
  533. if (bp->flow_ctrl) {
  534. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  535. printk(", receive ");
  536. if (bp->flow_ctrl & FLOW_CTRL_TX)
  537. printk("& transmit ");
  538. }
  539. else {
  540. printk(", transmit ");
  541. }
  542. printk("flow control ON");
  543. }
  544. printk("\n");
  545. }
  546. else {
  547. netif_carrier_off(bp->dev);
  548. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  549. }
  550. bnx2_report_fw_link(bp);
  551. }
  552. static void
  553. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  554. {
  555. u32 local_adv, remote_adv;
  556. bp->flow_ctrl = 0;
  557. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  558. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  559. if (bp->duplex == DUPLEX_FULL) {
  560. bp->flow_ctrl = bp->req_flow_ctrl;
  561. }
  562. return;
  563. }
  564. if (bp->duplex != DUPLEX_FULL) {
  565. return;
  566. }
  567. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  568. (CHIP_NUM(bp) == CHIP_NUM_5708)) {
  569. u32 val;
  570. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  571. if (val & BCM5708S_1000X_STAT1_TX_PAUSE)
  572. bp->flow_ctrl |= FLOW_CTRL_TX;
  573. if (val & BCM5708S_1000X_STAT1_RX_PAUSE)
  574. bp->flow_ctrl |= FLOW_CTRL_RX;
  575. return;
  576. }
  577. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  578. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  579. if (bp->phy_flags & PHY_SERDES_FLAG) {
  580. u32 new_local_adv = 0;
  581. u32 new_remote_adv = 0;
  582. if (local_adv & ADVERTISE_1000XPAUSE)
  583. new_local_adv |= ADVERTISE_PAUSE_CAP;
  584. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  585. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  586. if (remote_adv & ADVERTISE_1000XPAUSE)
  587. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  588. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  589. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  590. local_adv = new_local_adv;
  591. remote_adv = new_remote_adv;
  592. }
  593. /* See Table 28B-3 of 802.3ab-1999 spec. */
  594. if (local_adv & ADVERTISE_PAUSE_CAP) {
  595. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  596. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  597. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  598. }
  599. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  600. bp->flow_ctrl = FLOW_CTRL_RX;
  601. }
  602. }
  603. else {
  604. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  605. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  606. }
  607. }
  608. }
  609. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  610. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  611. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  612. bp->flow_ctrl = FLOW_CTRL_TX;
  613. }
  614. }
  615. }
  616. static int
  617. bnx2_5709s_linkup(struct bnx2 *bp)
  618. {
  619. u32 val, speed;
  620. bp->link_up = 1;
  621. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_GP_STATUS);
  622. bnx2_read_phy(bp, MII_BNX2_GP_TOP_AN_STATUS1, &val);
  623. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  624. if ((bp->autoneg & AUTONEG_SPEED) == 0) {
  625. bp->line_speed = bp->req_line_speed;
  626. bp->duplex = bp->req_duplex;
  627. return 0;
  628. }
  629. speed = val & MII_BNX2_GP_TOP_AN_SPEED_MSK;
  630. switch (speed) {
  631. case MII_BNX2_GP_TOP_AN_SPEED_10:
  632. bp->line_speed = SPEED_10;
  633. break;
  634. case MII_BNX2_GP_TOP_AN_SPEED_100:
  635. bp->line_speed = SPEED_100;
  636. break;
  637. case MII_BNX2_GP_TOP_AN_SPEED_1G:
  638. case MII_BNX2_GP_TOP_AN_SPEED_1GKV:
  639. bp->line_speed = SPEED_1000;
  640. break;
  641. case MII_BNX2_GP_TOP_AN_SPEED_2_5G:
  642. bp->line_speed = SPEED_2500;
  643. break;
  644. }
  645. if (val & MII_BNX2_GP_TOP_AN_FD)
  646. bp->duplex = DUPLEX_FULL;
  647. else
  648. bp->duplex = DUPLEX_HALF;
  649. return 0;
  650. }
  651. static int
  652. bnx2_5708s_linkup(struct bnx2 *bp)
  653. {
  654. u32 val;
  655. bp->link_up = 1;
  656. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  657. switch (val & BCM5708S_1000X_STAT1_SPEED_MASK) {
  658. case BCM5708S_1000X_STAT1_SPEED_10:
  659. bp->line_speed = SPEED_10;
  660. break;
  661. case BCM5708S_1000X_STAT1_SPEED_100:
  662. bp->line_speed = SPEED_100;
  663. break;
  664. case BCM5708S_1000X_STAT1_SPEED_1G:
  665. bp->line_speed = SPEED_1000;
  666. break;
  667. case BCM5708S_1000X_STAT1_SPEED_2G5:
  668. bp->line_speed = SPEED_2500;
  669. break;
  670. }
  671. if (val & BCM5708S_1000X_STAT1_FD)
  672. bp->duplex = DUPLEX_FULL;
  673. else
  674. bp->duplex = DUPLEX_HALF;
  675. return 0;
  676. }
  677. static int
  678. bnx2_5706s_linkup(struct bnx2 *bp)
  679. {
  680. u32 bmcr, local_adv, remote_adv, common;
  681. bp->link_up = 1;
  682. bp->line_speed = SPEED_1000;
  683. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  684. if (bmcr & BMCR_FULLDPLX) {
  685. bp->duplex = DUPLEX_FULL;
  686. }
  687. else {
  688. bp->duplex = DUPLEX_HALF;
  689. }
  690. if (!(bmcr & BMCR_ANENABLE)) {
  691. return 0;
  692. }
  693. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  694. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  695. common = local_adv & remote_adv;
  696. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  697. if (common & ADVERTISE_1000XFULL) {
  698. bp->duplex = DUPLEX_FULL;
  699. }
  700. else {
  701. bp->duplex = DUPLEX_HALF;
  702. }
  703. }
  704. return 0;
  705. }
  706. static int
  707. bnx2_copper_linkup(struct bnx2 *bp)
  708. {
  709. u32 bmcr;
  710. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  711. if (bmcr & BMCR_ANENABLE) {
  712. u32 local_adv, remote_adv, common;
  713. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  714. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  715. common = local_adv & (remote_adv >> 2);
  716. if (common & ADVERTISE_1000FULL) {
  717. bp->line_speed = SPEED_1000;
  718. bp->duplex = DUPLEX_FULL;
  719. }
  720. else if (common & ADVERTISE_1000HALF) {
  721. bp->line_speed = SPEED_1000;
  722. bp->duplex = DUPLEX_HALF;
  723. }
  724. else {
  725. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  726. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  727. common = local_adv & remote_adv;
  728. if (common & ADVERTISE_100FULL) {
  729. bp->line_speed = SPEED_100;
  730. bp->duplex = DUPLEX_FULL;
  731. }
  732. else if (common & ADVERTISE_100HALF) {
  733. bp->line_speed = SPEED_100;
  734. bp->duplex = DUPLEX_HALF;
  735. }
  736. else if (common & ADVERTISE_10FULL) {
  737. bp->line_speed = SPEED_10;
  738. bp->duplex = DUPLEX_FULL;
  739. }
  740. else if (common & ADVERTISE_10HALF) {
  741. bp->line_speed = SPEED_10;
  742. bp->duplex = DUPLEX_HALF;
  743. }
  744. else {
  745. bp->line_speed = 0;
  746. bp->link_up = 0;
  747. }
  748. }
  749. }
  750. else {
  751. if (bmcr & BMCR_SPEED100) {
  752. bp->line_speed = SPEED_100;
  753. }
  754. else {
  755. bp->line_speed = SPEED_10;
  756. }
  757. if (bmcr & BMCR_FULLDPLX) {
  758. bp->duplex = DUPLEX_FULL;
  759. }
  760. else {
  761. bp->duplex = DUPLEX_HALF;
  762. }
  763. }
  764. return 0;
  765. }
  766. static int
  767. bnx2_set_mac_link(struct bnx2 *bp)
  768. {
  769. u32 val;
  770. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  771. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  772. (bp->duplex == DUPLEX_HALF)) {
  773. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  774. }
  775. /* Configure the EMAC mode register. */
  776. val = REG_RD(bp, BNX2_EMAC_MODE);
  777. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  778. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  779. BNX2_EMAC_MODE_25G_MODE);
  780. if (bp->link_up) {
  781. switch (bp->line_speed) {
  782. case SPEED_10:
  783. if (CHIP_NUM(bp) != CHIP_NUM_5706) {
  784. val |= BNX2_EMAC_MODE_PORT_MII_10M;
  785. break;
  786. }
  787. /* fall through */
  788. case SPEED_100:
  789. val |= BNX2_EMAC_MODE_PORT_MII;
  790. break;
  791. case SPEED_2500:
  792. val |= BNX2_EMAC_MODE_25G_MODE;
  793. /* fall through */
  794. case SPEED_1000:
  795. val |= BNX2_EMAC_MODE_PORT_GMII;
  796. break;
  797. }
  798. }
  799. else {
  800. val |= BNX2_EMAC_MODE_PORT_GMII;
  801. }
  802. /* Set the MAC to operate in the appropriate duplex mode. */
  803. if (bp->duplex == DUPLEX_HALF)
  804. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  805. REG_WR(bp, BNX2_EMAC_MODE, val);
  806. /* Enable/disable rx PAUSE. */
  807. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  808. if (bp->flow_ctrl & FLOW_CTRL_RX)
  809. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  810. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  811. /* Enable/disable tx PAUSE. */
  812. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  813. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  814. if (bp->flow_ctrl & FLOW_CTRL_TX)
  815. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  816. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  817. /* Acknowledge the interrupt. */
  818. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  819. return 0;
  820. }
  821. static void
  822. bnx2_enable_bmsr1(struct bnx2 *bp)
  823. {
  824. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  825. (CHIP_NUM(bp) == CHIP_NUM_5709))
  826. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  827. MII_BNX2_BLK_ADDR_GP_STATUS);
  828. }
  829. static void
  830. bnx2_disable_bmsr1(struct bnx2 *bp)
  831. {
  832. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  833. (CHIP_NUM(bp) == CHIP_NUM_5709))
  834. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  835. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  836. }
  837. static int
  838. bnx2_test_and_enable_2g5(struct bnx2 *bp)
  839. {
  840. u32 up1;
  841. int ret = 1;
  842. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  843. return 0;
  844. if (bp->autoneg & AUTONEG_SPEED)
  845. bp->advertising |= ADVERTISED_2500baseX_Full;
  846. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  847. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  848. bnx2_read_phy(bp, bp->mii_up1, &up1);
  849. if (!(up1 & BCM5708S_UP1_2G5)) {
  850. up1 |= BCM5708S_UP1_2G5;
  851. bnx2_write_phy(bp, bp->mii_up1, up1);
  852. ret = 0;
  853. }
  854. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  855. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  856. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  857. return ret;
  858. }
  859. static int
  860. bnx2_test_and_disable_2g5(struct bnx2 *bp)
  861. {
  862. u32 up1;
  863. int ret = 0;
  864. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  865. return 0;
  866. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  867. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  868. bnx2_read_phy(bp, bp->mii_up1, &up1);
  869. if (up1 & BCM5708S_UP1_2G5) {
  870. up1 &= ~BCM5708S_UP1_2G5;
  871. bnx2_write_phy(bp, bp->mii_up1, up1);
  872. ret = 1;
  873. }
  874. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  875. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  876. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  877. return ret;
  878. }
  879. static void
  880. bnx2_enable_forced_2g5(struct bnx2 *bp)
  881. {
  882. u32 bmcr;
  883. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  884. return;
  885. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  886. u32 val;
  887. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  888. MII_BNX2_BLK_ADDR_SERDES_DIG);
  889. bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val);
  890. val &= ~MII_BNX2_SD_MISC1_FORCE_MSK;
  891. val |= MII_BNX2_SD_MISC1_FORCE | MII_BNX2_SD_MISC1_FORCE_2_5G;
  892. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
  893. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  894. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  895. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  896. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  897. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  898. bmcr |= BCM5708S_BMCR_FORCE_2500;
  899. }
  900. if (bp->autoneg & AUTONEG_SPEED) {
  901. bmcr &= ~BMCR_ANENABLE;
  902. if (bp->req_duplex == DUPLEX_FULL)
  903. bmcr |= BMCR_FULLDPLX;
  904. }
  905. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  906. }
  907. static void
  908. bnx2_disable_forced_2g5(struct bnx2 *bp)
  909. {
  910. u32 bmcr;
  911. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  912. return;
  913. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  914. u32 val;
  915. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  916. MII_BNX2_BLK_ADDR_SERDES_DIG);
  917. bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_MISC1, &val);
  918. val &= ~MII_BNX2_SD_MISC1_FORCE;
  919. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_MISC1, val);
  920. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR,
  921. MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  922. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  923. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  924. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  925. bmcr &= ~BCM5708S_BMCR_FORCE_2500;
  926. }
  927. if (bp->autoneg & AUTONEG_SPEED)
  928. bmcr |= BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_ANRESTART;
  929. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  930. }
  931. static int
  932. bnx2_set_link(struct bnx2 *bp)
  933. {
  934. u32 bmsr;
  935. u8 link_up;
  936. if (bp->loopback == MAC_LOOPBACK || bp->loopback == PHY_LOOPBACK) {
  937. bp->link_up = 1;
  938. return 0;
  939. }
  940. link_up = bp->link_up;
  941. bnx2_enable_bmsr1(bp);
  942. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  943. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  944. bnx2_disable_bmsr1(bp);
  945. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  946. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  947. u32 val;
  948. val = REG_RD(bp, BNX2_EMAC_STATUS);
  949. if (val & BNX2_EMAC_STATUS_LINK)
  950. bmsr |= BMSR_LSTATUS;
  951. else
  952. bmsr &= ~BMSR_LSTATUS;
  953. }
  954. if (bmsr & BMSR_LSTATUS) {
  955. bp->link_up = 1;
  956. if (bp->phy_flags & PHY_SERDES_FLAG) {
  957. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  958. bnx2_5706s_linkup(bp);
  959. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  960. bnx2_5708s_linkup(bp);
  961. else if (CHIP_NUM(bp) == CHIP_NUM_5709)
  962. bnx2_5709s_linkup(bp);
  963. }
  964. else {
  965. bnx2_copper_linkup(bp);
  966. }
  967. bnx2_resolve_flow_ctrl(bp);
  968. }
  969. else {
  970. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  971. (bp->autoneg & AUTONEG_SPEED))
  972. bnx2_disable_forced_2g5(bp);
  973. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  974. bp->link_up = 0;
  975. }
  976. if (bp->link_up != link_up) {
  977. bnx2_report_link(bp);
  978. }
  979. bnx2_set_mac_link(bp);
  980. return 0;
  981. }
  982. static int
  983. bnx2_reset_phy(struct bnx2 *bp)
  984. {
  985. int i;
  986. u32 reg;
  987. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_RESET);
  988. #define PHY_RESET_MAX_WAIT 100
  989. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  990. udelay(10);
  991. bnx2_read_phy(bp, bp->mii_bmcr, &reg);
  992. if (!(reg & BMCR_RESET)) {
  993. udelay(20);
  994. break;
  995. }
  996. }
  997. if (i == PHY_RESET_MAX_WAIT) {
  998. return -EBUSY;
  999. }
  1000. return 0;
  1001. }
  1002. static u32
  1003. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  1004. {
  1005. u32 adv = 0;
  1006. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  1007. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  1008. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1009. adv = ADVERTISE_1000XPAUSE;
  1010. }
  1011. else {
  1012. adv = ADVERTISE_PAUSE_CAP;
  1013. }
  1014. }
  1015. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  1016. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1017. adv = ADVERTISE_1000XPSE_ASYM;
  1018. }
  1019. else {
  1020. adv = ADVERTISE_PAUSE_ASYM;
  1021. }
  1022. }
  1023. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  1024. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1025. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  1026. }
  1027. else {
  1028. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  1029. }
  1030. }
  1031. return adv;
  1032. }
  1033. static int
  1034. bnx2_setup_serdes_phy(struct bnx2 *bp)
  1035. {
  1036. u32 adv, bmcr;
  1037. u32 new_adv = 0;
  1038. if (!(bp->autoneg & AUTONEG_SPEED)) {
  1039. u32 new_bmcr;
  1040. int force_link_down = 0;
  1041. if (bp->req_line_speed == SPEED_2500) {
  1042. if (!bnx2_test_and_enable_2g5(bp))
  1043. force_link_down = 1;
  1044. } else if (bp->req_line_speed == SPEED_1000) {
  1045. if (bnx2_test_and_disable_2g5(bp))
  1046. force_link_down = 1;
  1047. }
  1048. bnx2_read_phy(bp, bp->mii_adv, &adv);
  1049. adv &= ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF);
  1050. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1051. new_bmcr = bmcr & ~BMCR_ANENABLE;
  1052. new_bmcr |= BMCR_SPEED1000;
  1053. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  1054. if (bp->req_line_speed == SPEED_2500)
  1055. bnx2_enable_forced_2g5(bp);
  1056. else if (bp->req_line_speed == SPEED_1000) {
  1057. bnx2_disable_forced_2g5(bp);
  1058. new_bmcr &= ~0x2000;
  1059. }
  1060. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  1061. if (bp->req_line_speed == SPEED_2500)
  1062. new_bmcr |= BCM5708S_BMCR_FORCE_2500;
  1063. else
  1064. new_bmcr = bmcr & ~BCM5708S_BMCR_FORCE_2500;
  1065. }
  1066. if (bp->req_duplex == DUPLEX_FULL) {
  1067. adv |= ADVERTISE_1000XFULL;
  1068. new_bmcr |= BMCR_FULLDPLX;
  1069. }
  1070. else {
  1071. adv |= ADVERTISE_1000XHALF;
  1072. new_bmcr &= ~BMCR_FULLDPLX;
  1073. }
  1074. if ((new_bmcr != bmcr) || (force_link_down)) {
  1075. /* Force a link down visible on the other side */
  1076. if (bp->link_up) {
  1077. bnx2_write_phy(bp, bp->mii_adv, adv &
  1078. ~(ADVERTISE_1000XFULL |
  1079. ADVERTISE_1000XHALF));
  1080. bnx2_write_phy(bp, bp->mii_bmcr, bmcr |
  1081. BMCR_ANRESTART | BMCR_ANENABLE);
  1082. bp->link_up = 0;
  1083. netif_carrier_off(bp->dev);
  1084. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1085. bnx2_report_link(bp);
  1086. }
  1087. bnx2_write_phy(bp, bp->mii_adv, adv);
  1088. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1089. } else {
  1090. bnx2_resolve_flow_ctrl(bp);
  1091. bnx2_set_mac_link(bp);
  1092. }
  1093. return 0;
  1094. }
  1095. bnx2_test_and_enable_2g5(bp);
  1096. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1097. new_adv |= ADVERTISE_1000XFULL;
  1098. new_adv |= bnx2_phy_get_pause_adv(bp);
  1099. bnx2_read_phy(bp, bp->mii_adv, &adv);
  1100. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1101. bp->serdes_an_pending = 0;
  1102. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  1103. /* Force a link down visible on the other side */
  1104. if (bp->link_up) {
  1105. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1106. spin_unlock_bh(&bp->phy_lock);
  1107. msleep(20);
  1108. spin_lock_bh(&bp->phy_lock);
  1109. }
  1110. bnx2_write_phy(bp, bp->mii_adv, new_adv);
  1111. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART |
  1112. BMCR_ANENABLE);
  1113. /* Speed up link-up time when the link partner
  1114. * does not autonegotiate which is very common
  1115. * in blade servers. Some blade servers use
  1116. * IPMI for kerboard input and it's important
  1117. * to minimize link disruptions. Autoneg. involves
  1118. * exchanging base pages plus 3 next pages and
  1119. * normally completes in about 120 msec.
  1120. */
  1121. bp->current_interval = SERDES_AN_TIMEOUT;
  1122. bp->serdes_an_pending = 1;
  1123. mod_timer(&bp->timer, jiffies + bp->current_interval);
  1124. } else {
  1125. bnx2_resolve_flow_ctrl(bp);
  1126. bnx2_set_mac_link(bp);
  1127. }
  1128. return 0;
  1129. }
  1130. #define ETHTOOL_ALL_FIBRE_SPEED \
  1131. (ADVERTISED_1000baseT_Full)
  1132. #define ETHTOOL_ALL_COPPER_SPEED \
  1133. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  1134. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  1135. ADVERTISED_1000baseT_Full)
  1136. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  1137. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  1138. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  1139. static int
  1140. bnx2_setup_copper_phy(struct bnx2 *bp)
  1141. {
  1142. u32 bmcr;
  1143. u32 new_bmcr;
  1144. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1145. if (bp->autoneg & AUTONEG_SPEED) {
  1146. u32 adv_reg, adv1000_reg;
  1147. u32 new_adv_reg = 0;
  1148. u32 new_adv1000_reg = 0;
  1149. bnx2_read_phy(bp, bp->mii_adv, &adv_reg);
  1150. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  1151. ADVERTISE_PAUSE_ASYM);
  1152. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  1153. adv1000_reg &= PHY_ALL_1000_SPEED;
  1154. if (bp->advertising & ADVERTISED_10baseT_Half)
  1155. new_adv_reg |= ADVERTISE_10HALF;
  1156. if (bp->advertising & ADVERTISED_10baseT_Full)
  1157. new_adv_reg |= ADVERTISE_10FULL;
  1158. if (bp->advertising & ADVERTISED_100baseT_Half)
  1159. new_adv_reg |= ADVERTISE_100HALF;
  1160. if (bp->advertising & ADVERTISED_100baseT_Full)
  1161. new_adv_reg |= ADVERTISE_100FULL;
  1162. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1163. new_adv1000_reg |= ADVERTISE_1000FULL;
  1164. new_adv_reg |= ADVERTISE_CSMA;
  1165. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  1166. if ((adv1000_reg != new_adv1000_reg) ||
  1167. (adv_reg != new_adv_reg) ||
  1168. ((bmcr & BMCR_ANENABLE) == 0)) {
  1169. bnx2_write_phy(bp, bp->mii_adv, new_adv_reg);
  1170. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  1171. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_ANRESTART |
  1172. BMCR_ANENABLE);
  1173. }
  1174. else if (bp->link_up) {
  1175. /* Flow ctrl may have changed from auto to forced */
  1176. /* or vice-versa. */
  1177. bnx2_resolve_flow_ctrl(bp);
  1178. bnx2_set_mac_link(bp);
  1179. }
  1180. return 0;
  1181. }
  1182. new_bmcr = 0;
  1183. if (bp->req_line_speed == SPEED_100) {
  1184. new_bmcr |= BMCR_SPEED100;
  1185. }
  1186. if (bp->req_duplex == DUPLEX_FULL) {
  1187. new_bmcr |= BMCR_FULLDPLX;
  1188. }
  1189. if (new_bmcr != bmcr) {
  1190. u32 bmsr;
  1191. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1192. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1193. if (bmsr & BMSR_LSTATUS) {
  1194. /* Force link down */
  1195. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1196. spin_unlock_bh(&bp->phy_lock);
  1197. msleep(50);
  1198. spin_lock_bh(&bp->phy_lock);
  1199. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1200. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1201. }
  1202. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1203. /* Normally, the new speed is setup after the link has
  1204. * gone down and up again. In some cases, link will not go
  1205. * down so we need to set up the new speed here.
  1206. */
  1207. if (bmsr & BMSR_LSTATUS) {
  1208. bp->line_speed = bp->req_line_speed;
  1209. bp->duplex = bp->req_duplex;
  1210. bnx2_resolve_flow_ctrl(bp);
  1211. bnx2_set_mac_link(bp);
  1212. }
  1213. } else {
  1214. bnx2_resolve_flow_ctrl(bp);
  1215. bnx2_set_mac_link(bp);
  1216. }
  1217. return 0;
  1218. }
  1219. static int
  1220. bnx2_setup_phy(struct bnx2 *bp)
  1221. {
  1222. if (bp->loopback == MAC_LOOPBACK)
  1223. return 0;
  1224. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1225. return (bnx2_setup_serdes_phy(bp));
  1226. }
  1227. else {
  1228. return (bnx2_setup_copper_phy(bp));
  1229. }
  1230. }
  1231. static int
  1232. bnx2_init_5709s_phy(struct bnx2 *bp)
  1233. {
  1234. u32 val;
  1235. bp->mii_bmcr = MII_BMCR + 0x10;
  1236. bp->mii_bmsr = MII_BMSR + 0x10;
  1237. bp->mii_bmsr1 = MII_BNX2_GP_TOP_AN_STATUS1;
  1238. bp->mii_adv = MII_ADVERTISE + 0x10;
  1239. bp->mii_lpa = MII_LPA + 0x10;
  1240. bp->mii_up1 = MII_BNX2_OVER1G_UP1;
  1241. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_AER);
  1242. bnx2_write_phy(bp, MII_BNX2_AER_AER, MII_BNX2_AER_AER_AN_MMD);
  1243. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1244. bnx2_reset_phy(bp);
  1245. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_SERDES_DIG);
  1246. bnx2_read_phy(bp, MII_BNX2_SERDES_DIG_1000XCTL1, &val);
  1247. val &= ~MII_BNX2_SD_1000XCTL1_AUTODET;
  1248. val |= MII_BNX2_SD_1000XCTL1_FIBER;
  1249. bnx2_write_phy(bp, MII_BNX2_SERDES_DIG_1000XCTL1, val);
  1250. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_OVER1G);
  1251. bnx2_read_phy(bp, MII_BNX2_OVER1G_UP1, &val);
  1252. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)
  1253. val |= BCM5708S_UP1_2G5;
  1254. else
  1255. val &= ~BCM5708S_UP1_2G5;
  1256. bnx2_write_phy(bp, MII_BNX2_OVER1G_UP1, val);
  1257. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_BAM_NXTPG);
  1258. bnx2_read_phy(bp, MII_BNX2_BAM_NXTPG_CTL, &val);
  1259. val |= MII_BNX2_NXTPG_CTL_T2 | MII_BNX2_NXTPG_CTL_BAM;
  1260. bnx2_write_phy(bp, MII_BNX2_BAM_NXTPG_CTL, val);
  1261. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_CL73_USERB0);
  1262. val = MII_BNX2_CL73_BAM_EN | MII_BNX2_CL73_BAM_STA_MGR_EN |
  1263. MII_BNX2_CL73_BAM_NP_AFT_BP_EN;
  1264. bnx2_write_phy(bp, MII_BNX2_CL73_BAM_CTL1, val);
  1265. bnx2_write_phy(bp, MII_BNX2_BLK_ADDR, MII_BNX2_BLK_ADDR_COMBO_IEEEB0);
  1266. return 0;
  1267. }
  1268. static int
  1269. bnx2_init_5708s_phy(struct bnx2 *bp)
  1270. {
  1271. u32 val;
  1272. bnx2_reset_phy(bp);
  1273. bp->mii_up1 = BCM5708S_UP1;
  1274. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG3);
  1275. bnx2_write_phy(bp, BCM5708S_DIG_3_0, BCM5708S_DIG_3_0_USE_IEEE);
  1276. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1277. bnx2_read_phy(bp, BCM5708S_1000X_CTL1, &val);
  1278. val |= BCM5708S_1000X_CTL1_FIBER_MODE | BCM5708S_1000X_CTL1_AUTODET_EN;
  1279. bnx2_write_phy(bp, BCM5708S_1000X_CTL1, val);
  1280. bnx2_read_phy(bp, BCM5708S_1000X_CTL2, &val);
  1281. val |= BCM5708S_1000X_CTL2_PLLEL_DET_EN;
  1282. bnx2_write_phy(bp, BCM5708S_1000X_CTL2, val);
  1283. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) {
  1284. bnx2_read_phy(bp, BCM5708S_UP1, &val);
  1285. val |= BCM5708S_UP1_2G5;
  1286. bnx2_write_phy(bp, BCM5708S_UP1, val);
  1287. }
  1288. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  1289. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  1290. (CHIP_ID(bp) == CHIP_ID_5708_B1)) {
  1291. /* increase tx signal amplitude */
  1292. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1293. BCM5708S_BLK_ADDR_TX_MISC);
  1294. bnx2_read_phy(bp, BCM5708S_TX_ACTL1, &val);
  1295. val &= ~BCM5708S_TX_ACTL1_DRIVER_VCM;
  1296. bnx2_write_phy(bp, BCM5708S_TX_ACTL1, val);
  1297. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1298. }
  1299. val = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG) &
  1300. BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK;
  1301. if (val) {
  1302. u32 is_backplane;
  1303. is_backplane = REG_RD_IND(bp, bp->shmem_base +
  1304. BNX2_SHARED_HW_CFG_CONFIG);
  1305. if (is_backplane & BNX2_SHARED_HW_CFG_PHY_BACKPLANE) {
  1306. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1307. BCM5708S_BLK_ADDR_TX_MISC);
  1308. bnx2_write_phy(bp, BCM5708S_TX_ACTL3, val);
  1309. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1310. BCM5708S_BLK_ADDR_DIG);
  1311. }
  1312. }
  1313. return 0;
  1314. }
  1315. static int
  1316. bnx2_init_5706s_phy(struct bnx2 *bp)
  1317. {
  1318. bnx2_reset_phy(bp);
  1319. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  1320. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1321. REG_WR(bp, BNX2_MISC_GP_HW_CTL0, 0x300);
  1322. if (bp->dev->mtu > 1500) {
  1323. u32 val;
  1324. /* Set extended packet length bit */
  1325. bnx2_write_phy(bp, 0x18, 0x7);
  1326. bnx2_read_phy(bp, 0x18, &val);
  1327. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  1328. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1329. bnx2_read_phy(bp, 0x1c, &val);
  1330. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  1331. }
  1332. else {
  1333. u32 val;
  1334. bnx2_write_phy(bp, 0x18, 0x7);
  1335. bnx2_read_phy(bp, 0x18, &val);
  1336. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1337. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1338. bnx2_read_phy(bp, 0x1c, &val);
  1339. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  1340. }
  1341. return 0;
  1342. }
  1343. static int
  1344. bnx2_init_copper_phy(struct bnx2 *bp)
  1345. {
  1346. u32 val;
  1347. bnx2_reset_phy(bp);
  1348. if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
  1349. bnx2_write_phy(bp, 0x18, 0x0c00);
  1350. bnx2_write_phy(bp, 0x17, 0x000a);
  1351. bnx2_write_phy(bp, 0x15, 0x310b);
  1352. bnx2_write_phy(bp, 0x17, 0x201f);
  1353. bnx2_write_phy(bp, 0x15, 0x9506);
  1354. bnx2_write_phy(bp, 0x17, 0x401f);
  1355. bnx2_write_phy(bp, 0x15, 0x14e2);
  1356. bnx2_write_phy(bp, 0x18, 0x0400);
  1357. }
  1358. if (bp->phy_flags & PHY_DIS_EARLY_DAC_FLAG) {
  1359. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS,
  1360. MII_BNX2_DSP_EXPAND_REG | 0x8);
  1361. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
  1362. val &= ~(1 << 8);
  1363. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val);
  1364. }
  1365. if (bp->dev->mtu > 1500) {
  1366. /* Set extended packet length bit */
  1367. bnx2_write_phy(bp, 0x18, 0x7);
  1368. bnx2_read_phy(bp, 0x18, &val);
  1369. bnx2_write_phy(bp, 0x18, val | 0x4000);
  1370. bnx2_read_phy(bp, 0x10, &val);
  1371. bnx2_write_phy(bp, 0x10, val | 0x1);
  1372. }
  1373. else {
  1374. bnx2_write_phy(bp, 0x18, 0x7);
  1375. bnx2_read_phy(bp, 0x18, &val);
  1376. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1377. bnx2_read_phy(bp, 0x10, &val);
  1378. bnx2_write_phy(bp, 0x10, val & ~0x1);
  1379. }
  1380. /* ethernet@wirespeed */
  1381. bnx2_write_phy(bp, 0x18, 0x7007);
  1382. bnx2_read_phy(bp, 0x18, &val);
  1383. bnx2_write_phy(bp, 0x18, val | (1 << 15) | (1 << 4));
  1384. return 0;
  1385. }
  1386. static int
  1387. bnx2_init_phy(struct bnx2 *bp)
  1388. {
  1389. u32 val;
  1390. int rc = 0;
  1391. bp->phy_flags &= ~PHY_INT_MODE_MASK_FLAG;
  1392. bp->phy_flags |= PHY_INT_MODE_LINK_READY_FLAG;
  1393. bp->mii_bmcr = MII_BMCR;
  1394. bp->mii_bmsr = MII_BMSR;
  1395. bp->mii_bmsr1 = MII_BMSR;
  1396. bp->mii_adv = MII_ADVERTISE;
  1397. bp->mii_lpa = MII_LPA;
  1398. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  1399. bnx2_read_phy(bp, MII_PHYSID1, &val);
  1400. bp->phy_id = val << 16;
  1401. bnx2_read_phy(bp, MII_PHYSID2, &val);
  1402. bp->phy_id |= val & 0xffff;
  1403. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1404. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1405. rc = bnx2_init_5706s_phy(bp);
  1406. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  1407. rc = bnx2_init_5708s_phy(bp);
  1408. else if (CHIP_NUM(bp) == CHIP_NUM_5709)
  1409. rc = bnx2_init_5709s_phy(bp);
  1410. }
  1411. else {
  1412. rc = bnx2_init_copper_phy(bp);
  1413. }
  1414. bnx2_setup_phy(bp);
  1415. return rc;
  1416. }
  1417. static int
  1418. bnx2_set_mac_loopback(struct bnx2 *bp)
  1419. {
  1420. u32 mac_mode;
  1421. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1422. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  1423. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  1424. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1425. bp->link_up = 1;
  1426. return 0;
  1427. }
  1428. static int bnx2_test_link(struct bnx2 *);
  1429. static int
  1430. bnx2_set_phy_loopback(struct bnx2 *bp)
  1431. {
  1432. u32 mac_mode;
  1433. int rc, i;
  1434. spin_lock_bh(&bp->phy_lock);
  1435. rc = bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK | BMCR_FULLDPLX |
  1436. BMCR_SPEED1000);
  1437. spin_unlock_bh(&bp->phy_lock);
  1438. if (rc)
  1439. return rc;
  1440. for (i = 0; i < 10; i++) {
  1441. if (bnx2_test_link(bp) == 0)
  1442. break;
  1443. msleep(100);
  1444. }
  1445. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1446. mac_mode &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  1447. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  1448. BNX2_EMAC_MODE_25G_MODE);
  1449. mac_mode |= BNX2_EMAC_MODE_PORT_GMII;
  1450. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1451. bp->link_up = 1;
  1452. return 0;
  1453. }
  1454. static int
  1455. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int silent)
  1456. {
  1457. int i;
  1458. u32 val;
  1459. bp->fw_wr_seq++;
  1460. msg_data |= bp->fw_wr_seq;
  1461. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1462. /* wait for an acknowledgement. */
  1463. for (i = 0; i < (FW_ACK_TIME_OUT_MS / 10); i++) {
  1464. msleep(10);
  1465. val = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_MB);
  1466. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  1467. break;
  1468. }
  1469. if ((msg_data & BNX2_DRV_MSG_DATA) == BNX2_DRV_MSG_DATA_WAIT0)
  1470. return 0;
  1471. /* If we timed out, inform the firmware that this is the case. */
  1472. if ((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) {
  1473. if (!silent)
  1474. printk(KERN_ERR PFX "fw sync timeout, reset code = "
  1475. "%x\n", msg_data);
  1476. msg_data &= ~BNX2_DRV_MSG_CODE;
  1477. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  1478. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1479. return -EBUSY;
  1480. }
  1481. if ((val & BNX2_FW_MSG_STATUS_MASK) != BNX2_FW_MSG_STATUS_OK)
  1482. return -EIO;
  1483. return 0;
  1484. }
  1485. static int
  1486. bnx2_init_5709_context(struct bnx2 *bp)
  1487. {
  1488. int i, ret = 0;
  1489. u32 val;
  1490. val = BNX2_CTX_COMMAND_ENABLED | BNX2_CTX_COMMAND_MEM_INIT | (1 << 12);
  1491. val |= (BCM_PAGE_BITS - 8) << 16;
  1492. REG_WR(bp, BNX2_CTX_COMMAND, val);
  1493. for (i = 0; i < 10; i++) {
  1494. val = REG_RD(bp, BNX2_CTX_COMMAND);
  1495. if (!(val & BNX2_CTX_COMMAND_MEM_INIT))
  1496. break;
  1497. udelay(2);
  1498. }
  1499. if (val & BNX2_CTX_COMMAND_MEM_INIT)
  1500. return -EBUSY;
  1501. for (i = 0; i < bp->ctx_pages; i++) {
  1502. int j;
  1503. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA0,
  1504. (bp->ctx_blk_mapping[i] & 0xffffffff) |
  1505. BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID);
  1506. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA1,
  1507. (u64) bp->ctx_blk_mapping[i] >> 32);
  1508. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL, i |
  1509. BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
  1510. for (j = 0; j < 10; j++) {
  1511. val = REG_RD(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL);
  1512. if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ))
  1513. break;
  1514. udelay(5);
  1515. }
  1516. if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) {
  1517. ret = -EBUSY;
  1518. break;
  1519. }
  1520. }
  1521. return ret;
  1522. }
  1523. static void
  1524. bnx2_init_context(struct bnx2 *bp)
  1525. {
  1526. u32 vcid;
  1527. vcid = 96;
  1528. while (vcid) {
  1529. u32 vcid_addr, pcid_addr, offset;
  1530. int i;
  1531. vcid--;
  1532. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  1533. u32 new_vcid;
  1534. vcid_addr = GET_PCID_ADDR(vcid);
  1535. if (vcid & 0x8) {
  1536. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  1537. }
  1538. else {
  1539. new_vcid = vcid;
  1540. }
  1541. pcid_addr = GET_PCID_ADDR(new_vcid);
  1542. }
  1543. else {
  1544. vcid_addr = GET_CID_ADDR(vcid);
  1545. pcid_addr = vcid_addr;
  1546. }
  1547. for (i = 0; i < (CTX_SIZE / PHY_CTX_SIZE); i++) {
  1548. vcid_addr += (i << PHY_CTX_SHIFT);
  1549. pcid_addr += (i << PHY_CTX_SHIFT);
  1550. REG_WR(bp, BNX2_CTX_VIRT_ADDR, 0x00);
  1551. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1552. /* Zero out the context. */
  1553. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4)
  1554. CTX_WR(bp, 0x00, offset, 0);
  1555. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  1556. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1557. }
  1558. }
  1559. }
  1560. static int
  1561. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  1562. {
  1563. u16 *good_mbuf;
  1564. u32 good_mbuf_cnt;
  1565. u32 val;
  1566. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  1567. if (good_mbuf == NULL) {
  1568. printk(KERN_ERR PFX "Failed to allocate memory in "
  1569. "bnx2_alloc_bad_rbuf\n");
  1570. return -ENOMEM;
  1571. }
  1572. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1573. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  1574. good_mbuf_cnt = 0;
  1575. /* Allocate a bunch of mbufs and save the good ones in an array. */
  1576. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1577. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  1578. REG_WR_IND(bp, BNX2_RBUF_COMMAND, BNX2_RBUF_COMMAND_ALLOC_REQ);
  1579. val = REG_RD_IND(bp, BNX2_RBUF_FW_BUF_ALLOC);
  1580. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  1581. /* The addresses with Bit 9 set are bad memory blocks. */
  1582. if (!(val & (1 << 9))) {
  1583. good_mbuf[good_mbuf_cnt] = (u16) val;
  1584. good_mbuf_cnt++;
  1585. }
  1586. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1587. }
  1588. /* Free the good ones back to the mbuf pool thus discarding
  1589. * all the bad ones. */
  1590. while (good_mbuf_cnt) {
  1591. good_mbuf_cnt--;
  1592. val = good_mbuf[good_mbuf_cnt];
  1593. val = (val << 9) | val | 1;
  1594. REG_WR_IND(bp, BNX2_RBUF_FW_BUF_FREE, val);
  1595. }
  1596. kfree(good_mbuf);
  1597. return 0;
  1598. }
  1599. static void
  1600. bnx2_set_mac_addr(struct bnx2 *bp)
  1601. {
  1602. u32 val;
  1603. u8 *mac_addr = bp->dev->dev_addr;
  1604. val = (mac_addr[0] << 8) | mac_addr[1];
  1605. REG_WR(bp, BNX2_EMAC_MAC_MATCH0, val);
  1606. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  1607. (mac_addr[4] << 8) | mac_addr[5];
  1608. REG_WR(bp, BNX2_EMAC_MAC_MATCH1, val);
  1609. }
  1610. static inline int
  1611. bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
  1612. {
  1613. struct sk_buff *skb;
  1614. struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
  1615. dma_addr_t mapping;
  1616. struct rx_bd *rxbd = &bp->rx_desc_ring[RX_RING(index)][RX_IDX(index)];
  1617. unsigned long align;
  1618. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  1619. if (skb == NULL) {
  1620. return -ENOMEM;
  1621. }
  1622. if (unlikely((align = (unsigned long) skb->data & (BNX2_RX_ALIGN - 1))))
  1623. skb_reserve(skb, BNX2_RX_ALIGN - align);
  1624. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  1625. PCI_DMA_FROMDEVICE);
  1626. rx_buf->skb = skb;
  1627. pci_unmap_addr_set(rx_buf, mapping, mapping);
  1628. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  1629. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  1630. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1631. return 0;
  1632. }
  1633. static int
  1634. bnx2_phy_event_is_set(struct bnx2 *bp, u32 event)
  1635. {
  1636. struct status_block *sblk = bp->status_blk;
  1637. u32 new_link_state, old_link_state;
  1638. int is_set = 1;
  1639. new_link_state = sblk->status_attn_bits & event;
  1640. old_link_state = sblk->status_attn_bits_ack & event;
  1641. if (new_link_state != old_link_state) {
  1642. if (new_link_state)
  1643. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD, event);
  1644. else
  1645. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD, event);
  1646. } else
  1647. is_set = 0;
  1648. return is_set;
  1649. }
  1650. static void
  1651. bnx2_phy_int(struct bnx2 *bp)
  1652. {
  1653. if (bnx2_phy_event_is_set(bp, STATUS_ATTN_BITS_LINK_STATE)) {
  1654. spin_lock(&bp->phy_lock);
  1655. bnx2_set_link(bp);
  1656. spin_unlock(&bp->phy_lock);
  1657. }
  1658. }
  1659. static void
  1660. bnx2_tx_int(struct bnx2 *bp)
  1661. {
  1662. struct status_block *sblk = bp->status_blk;
  1663. u16 hw_cons, sw_cons, sw_ring_cons;
  1664. int tx_free_bd = 0;
  1665. hw_cons = bp->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
  1666. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1667. hw_cons++;
  1668. }
  1669. sw_cons = bp->tx_cons;
  1670. while (sw_cons != hw_cons) {
  1671. struct sw_bd *tx_buf;
  1672. struct sk_buff *skb;
  1673. int i, last;
  1674. sw_ring_cons = TX_RING_IDX(sw_cons);
  1675. tx_buf = &bp->tx_buf_ring[sw_ring_cons];
  1676. skb = tx_buf->skb;
  1677. /* partial BD completions possible with TSO packets */
  1678. if (skb_is_gso(skb)) {
  1679. u16 last_idx, last_ring_idx;
  1680. last_idx = sw_cons +
  1681. skb_shinfo(skb)->nr_frags + 1;
  1682. last_ring_idx = sw_ring_cons +
  1683. skb_shinfo(skb)->nr_frags + 1;
  1684. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  1685. last_idx++;
  1686. }
  1687. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  1688. break;
  1689. }
  1690. }
  1691. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  1692. skb_headlen(skb), PCI_DMA_TODEVICE);
  1693. tx_buf->skb = NULL;
  1694. last = skb_shinfo(skb)->nr_frags;
  1695. for (i = 0; i < last; i++) {
  1696. sw_cons = NEXT_TX_BD(sw_cons);
  1697. pci_unmap_page(bp->pdev,
  1698. pci_unmap_addr(
  1699. &bp->tx_buf_ring[TX_RING_IDX(sw_cons)],
  1700. mapping),
  1701. skb_shinfo(skb)->frags[i].size,
  1702. PCI_DMA_TODEVICE);
  1703. }
  1704. sw_cons = NEXT_TX_BD(sw_cons);
  1705. tx_free_bd += last + 1;
  1706. dev_kfree_skb(skb);
  1707. hw_cons = bp->hw_tx_cons =
  1708. sblk->status_tx_quick_consumer_index0;
  1709. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1710. hw_cons++;
  1711. }
  1712. }
  1713. bp->tx_cons = sw_cons;
  1714. /* Need to make the tx_cons update visible to bnx2_start_xmit()
  1715. * before checking for netif_queue_stopped(). Without the
  1716. * memory barrier, there is a small possibility that bnx2_start_xmit()
  1717. * will miss it and cause the queue to be stopped forever.
  1718. */
  1719. smp_mb();
  1720. if (unlikely(netif_queue_stopped(bp->dev)) &&
  1721. (bnx2_tx_avail(bp) > bp->tx_wake_thresh)) {
  1722. netif_tx_lock(bp->dev);
  1723. if ((netif_queue_stopped(bp->dev)) &&
  1724. (bnx2_tx_avail(bp) > bp->tx_wake_thresh))
  1725. netif_wake_queue(bp->dev);
  1726. netif_tx_unlock(bp->dev);
  1727. }
  1728. }
  1729. static inline void
  1730. bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
  1731. u16 cons, u16 prod)
  1732. {
  1733. struct sw_bd *cons_rx_buf, *prod_rx_buf;
  1734. struct rx_bd *cons_bd, *prod_bd;
  1735. cons_rx_buf = &bp->rx_buf_ring[cons];
  1736. prod_rx_buf = &bp->rx_buf_ring[prod];
  1737. pci_dma_sync_single_for_device(bp->pdev,
  1738. pci_unmap_addr(cons_rx_buf, mapping),
  1739. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1740. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1741. prod_rx_buf->skb = skb;
  1742. if (cons == prod)
  1743. return;
  1744. pci_unmap_addr_set(prod_rx_buf, mapping,
  1745. pci_unmap_addr(cons_rx_buf, mapping));
  1746. cons_bd = &bp->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  1747. prod_bd = &bp->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  1748. prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
  1749. prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
  1750. }
  1751. static int
  1752. bnx2_rx_int(struct bnx2 *bp, int budget)
  1753. {
  1754. struct status_block *sblk = bp->status_blk;
  1755. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  1756. struct l2_fhdr *rx_hdr;
  1757. int rx_pkt = 0;
  1758. hw_cons = bp->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
  1759. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
  1760. hw_cons++;
  1761. }
  1762. sw_cons = bp->rx_cons;
  1763. sw_prod = bp->rx_prod;
  1764. /* Memory barrier necessary as speculative reads of the rx
  1765. * buffer can be ahead of the index in the status block
  1766. */
  1767. rmb();
  1768. while (sw_cons != hw_cons) {
  1769. unsigned int len;
  1770. u32 status;
  1771. struct sw_bd *rx_buf;
  1772. struct sk_buff *skb;
  1773. dma_addr_t dma_addr;
  1774. sw_ring_cons = RX_RING_IDX(sw_cons);
  1775. sw_ring_prod = RX_RING_IDX(sw_prod);
  1776. rx_buf = &bp->rx_buf_ring[sw_ring_cons];
  1777. skb = rx_buf->skb;
  1778. rx_buf->skb = NULL;
  1779. dma_addr = pci_unmap_addr(rx_buf, mapping);
  1780. pci_dma_sync_single_for_cpu(bp->pdev, dma_addr,
  1781. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1782. rx_hdr = (struct l2_fhdr *) skb->data;
  1783. len = rx_hdr->l2_fhdr_pkt_len - 4;
  1784. if ((status = rx_hdr->l2_fhdr_status) &
  1785. (L2_FHDR_ERRORS_BAD_CRC |
  1786. L2_FHDR_ERRORS_PHY_DECODE |
  1787. L2_FHDR_ERRORS_ALIGNMENT |
  1788. L2_FHDR_ERRORS_TOO_SHORT |
  1789. L2_FHDR_ERRORS_GIANT_FRAME)) {
  1790. goto reuse_rx;
  1791. }
  1792. /* Since we don't have a jumbo ring, copy small packets
  1793. * if mtu > 1500
  1794. */
  1795. if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
  1796. struct sk_buff *new_skb;
  1797. new_skb = netdev_alloc_skb(bp->dev, len + 2);
  1798. if (new_skb == NULL)
  1799. goto reuse_rx;
  1800. /* aligned copy */
  1801. skb_copy_from_linear_data_offset(skb, bp->rx_offset - 2,
  1802. new_skb->data, len + 2);
  1803. skb_reserve(new_skb, 2);
  1804. skb_put(new_skb, len);
  1805. bnx2_reuse_rx_skb(bp, skb,
  1806. sw_ring_cons, sw_ring_prod);
  1807. skb = new_skb;
  1808. }
  1809. else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
  1810. pci_unmap_single(bp->pdev, dma_addr,
  1811. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  1812. skb_reserve(skb, bp->rx_offset);
  1813. skb_put(skb, len);
  1814. }
  1815. else {
  1816. reuse_rx:
  1817. bnx2_reuse_rx_skb(bp, skb,
  1818. sw_ring_cons, sw_ring_prod);
  1819. goto next_rx;
  1820. }
  1821. skb->protocol = eth_type_trans(skb, bp->dev);
  1822. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  1823. (ntohs(skb->protocol) != 0x8100)) {
  1824. dev_kfree_skb(skb);
  1825. goto next_rx;
  1826. }
  1827. skb->ip_summed = CHECKSUM_NONE;
  1828. if (bp->rx_csum &&
  1829. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  1830. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  1831. if (likely((status & (L2_FHDR_ERRORS_TCP_XSUM |
  1832. L2_FHDR_ERRORS_UDP_XSUM)) == 0))
  1833. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1834. }
  1835. #ifdef BCM_VLAN
  1836. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) && (bp->vlgrp != 0)) {
  1837. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1838. rx_hdr->l2_fhdr_vlan_tag);
  1839. }
  1840. else
  1841. #endif
  1842. netif_receive_skb(skb);
  1843. bp->dev->last_rx = jiffies;
  1844. rx_pkt++;
  1845. next_rx:
  1846. sw_cons = NEXT_RX_BD(sw_cons);
  1847. sw_prod = NEXT_RX_BD(sw_prod);
  1848. if ((rx_pkt == budget))
  1849. break;
  1850. /* Refresh hw_cons to see if there is new work */
  1851. if (sw_cons == hw_cons) {
  1852. hw_cons = bp->hw_rx_cons =
  1853. sblk->status_rx_quick_consumer_index0;
  1854. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT)
  1855. hw_cons++;
  1856. rmb();
  1857. }
  1858. }
  1859. bp->rx_cons = sw_cons;
  1860. bp->rx_prod = sw_prod;
  1861. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, sw_prod);
  1862. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  1863. mmiowb();
  1864. return rx_pkt;
  1865. }
  1866. /* MSI ISR - The only difference between this and the INTx ISR
  1867. * is that the MSI interrupt is always serviced.
  1868. */
  1869. static irqreturn_t
  1870. bnx2_msi(int irq, void *dev_instance)
  1871. {
  1872. struct net_device *dev = dev_instance;
  1873. struct bnx2 *bp = netdev_priv(dev);
  1874. prefetch(bp->status_blk);
  1875. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1876. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1877. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1878. /* Return here if interrupt is disabled. */
  1879. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1880. return IRQ_HANDLED;
  1881. netif_rx_schedule(dev);
  1882. return IRQ_HANDLED;
  1883. }
  1884. static irqreturn_t
  1885. bnx2_msi_1shot(int irq, void *dev_instance)
  1886. {
  1887. struct net_device *dev = dev_instance;
  1888. struct bnx2 *bp = netdev_priv(dev);
  1889. prefetch(bp->status_blk);
  1890. /* Return here if interrupt is disabled. */
  1891. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1892. return IRQ_HANDLED;
  1893. netif_rx_schedule(dev);
  1894. return IRQ_HANDLED;
  1895. }
  1896. static irqreturn_t
  1897. bnx2_interrupt(int irq, void *dev_instance)
  1898. {
  1899. struct net_device *dev = dev_instance;
  1900. struct bnx2 *bp = netdev_priv(dev);
  1901. /* When using INTx, it is possible for the interrupt to arrive
  1902. * at the CPU before the status block posted prior to the
  1903. * interrupt. Reading a register will flush the status block.
  1904. * When using MSI, the MSI message will always complete after
  1905. * the status block write.
  1906. */
  1907. if ((bp->status_blk->status_idx == bp->last_status_idx) &&
  1908. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  1909. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  1910. return IRQ_NONE;
  1911. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1912. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1913. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1914. /* Return here if interrupt is shared and is disabled. */
  1915. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1916. return IRQ_HANDLED;
  1917. netif_rx_schedule(dev);
  1918. return IRQ_HANDLED;
  1919. }
  1920. #define STATUS_ATTN_EVENTS STATUS_ATTN_BITS_LINK_STATE
  1921. static inline int
  1922. bnx2_has_work(struct bnx2 *bp)
  1923. {
  1924. struct status_block *sblk = bp->status_blk;
  1925. if ((sblk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) ||
  1926. (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons))
  1927. return 1;
  1928. if ((sblk->status_attn_bits & STATUS_ATTN_EVENTS) !=
  1929. (sblk->status_attn_bits_ack & STATUS_ATTN_EVENTS))
  1930. return 1;
  1931. return 0;
  1932. }
  1933. static int
  1934. bnx2_poll(struct net_device *dev, int *budget)
  1935. {
  1936. struct bnx2 *bp = netdev_priv(dev);
  1937. struct status_block *sblk = bp->status_blk;
  1938. u32 status_attn_bits = sblk->status_attn_bits;
  1939. u32 status_attn_bits_ack = sblk->status_attn_bits_ack;
  1940. if ((status_attn_bits & STATUS_ATTN_EVENTS) !=
  1941. (status_attn_bits_ack & STATUS_ATTN_EVENTS)) {
  1942. bnx2_phy_int(bp);
  1943. /* This is needed to take care of transient status
  1944. * during link changes.
  1945. */
  1946. REG_WR(bp, BNX2_HC_COMMAND,
  1947. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  1948. REG_RD(bp, BNX2_HC_COMMAND);
  1949. }
  1950. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)
  1951. bnx2_tx_int(bp);
  1952. if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) {
  1953. int orig_budget = *budget;
  1954. int work_done;
  1955. if (orig_budget > dev->quota)
  1956. orig_budget = dev->quota;
  1957. work_done = bnx2_rx_int(bp, orig_budget);
  1958. *budget -= work_done;
  1959. dev->quota -= work_done;
  1960. }
  1961. bp->last_status_idx = bp->status_blk->status_idx;
  1962. rmb();
  1963. if (!bnx2_has_work(bp)) {
  1964. netif_rx_complete(dev);
  1965. if (likely(bp->flags & USING_MSI_FLAG)) {
  1966. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1967. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1968. bp->last_status_idx);
  1969. return 0;
  1970. }
  1971. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1972. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1973. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  1974. bp->last_status_idx);
  1975. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1976. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1977. bp->last_status_idx);
  1978. return 0;
  1979. }
  1980. return 1;
  1981. }
  1982. /* Called with rtnl_lock from vlan functions and also netif_tx_lock
  1983. * from set_multicast.
  1984. */
  1985. static void
  1986. bnx2_set_rx_mode(struct net_device *dev)
  1987. {
  1988. struct bnx2 *bp = netdev_priv(dev);
  1989. u32 rx_mode, sort_mode;
  1990. int i;
  1991. spin_lock_bh(&bp->phy_lock);
  1992. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  1993. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  1994. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  1995. #ifdef BCM_VLAN
  1996. if (!bp->vlgrp && !(bp->flags & ASF_ENABLE_FLAG))
  1997. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1998. #else
  1999. if (!(bp->flags & ASF_ENABLE_FLAG))
  2000. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  2001. #endif
  2002. if (dev->flags & IFF_PROMISC) {
  2003. /* Promiscuous mode. */
  2004. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  2005. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
  2006. BNX2_RPM_SORT_USER0_PROM_VLAN;
  2007. }
  2008. else if (dev->flags & IFF_ALLMULTI) {
  2009. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2010. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2011. 0xffffffff);
  2012. }
  2013. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  2014. }
  2015. else {
  2016. /* Accept one or more multicast(s). */
  2017. struct dev_mc_list *mclist;
  2018. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  2019. u32 regidx;
  2020. u32 bit;
  2021. u32 crc;
  2022. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  2023. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  2024. i++, mclist = mclist->next) {
  2025. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  2026. bit = crc & 0xff;
  2027. regidx = (bit & 0xe0) >> 5;
  2028. bit &= 0x1f;
  2029. mc_filter[regidx] |= (1 << bit);
  2030. }
  2031. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2032. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2033. mc_filter[i]);
  2034. }
  2035. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  2036. }
  2037. if (rx_mode != bp->rx_mode) {
  2038. bp->rx_mode = rx_mode;
  2039. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  2040. }
  2041. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  2042. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  2043. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  2044. spin_unlock_bh(&bp->phy_lock);
  2045. }
  2046. #define FW_BUF_SIZE 0x8000
  2047. static int
  2048. bnx2_gunzip_init(struct bnx2 *bp)
  2049. {
  2050. if ((bp->gunzip_buf = vmalloc(FW_BUF_SIZE)) == NULL)
  2051. goto gunzip_nomem1;
  2052. if ((bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL)) == NULL)
  2053. goto gunzip_nomem2;
  2054. bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
  2055. if (bp->strm->workspace == NULL)
  2056. goto gunzip_nomem3;
  2057. return 0;
  2058. gunzip_nomem3:
  2059. kfree(bp->strm);
  2060. bp->strm = NULL;
  2061. gunzip_nomem2:
  2062. vfree(bp->gunzip_buf);
  2063. bp->gunzip_buf = NULL;
  2064. gunzip_nomem1:
  2065. printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for "
  2066. "uncompression.\n", bp->dev->name);
  2067. return -ENOMEM;
  2068. }
  2069. static void
  2070. bnx2_gunzip_end(struct bnx2 *bp)
  2071. {
  2072. kfree(bp->strm->workspace);
  2073. kfree(bp->strm);
  2074. bp->strm = NULL;
  2075. if (bp->gunzip_buf) {
  2076. vfree(bp->gunzip_buf);
  2077. bp->gunzip_buf = NULL;
  2078. }
  2079. }
  2080. static int
  2081. bnx2_gunzip(struct bnx2 *bp, u8 *zbuf, int len, void **outbuf, int *outlen)
  2082. {
  2083. int n, rc;
  2084. /* check gzip header */
  2085. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED))
  2086. return -EINVAL;
  2087. n = 10;
  2088. #define FNAME 0x8
  2089. if (zbuf[3] & FNAME)
  2090. while ((zbuf[n++] != 0) && (n < len));
  2091. bp->strm->next_in = zbuf + n;
  2092. bp->strm->avail_in = len - n;
  2093. bp->strm->next_out = bp->gunzip_buf;
  2094. bp->strm->avail_out = FW_BUF_SIZE;
  2095. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  2096. if (rc != Z_OK)
  2097. return rc;
  2098. rc = zlib_inflate(bp->strm, Z_FINISH);
  2099. *outlen = FW_BUF_SIZE - bp->strm->avail_out;
  2100. *outbuf = bp->gunzip_buf;
  2101. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  2102. printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
  2103. bp->dev->name, bp->strm->msg);
  2104. zlib_inflateEnd(bp->strm);
  2105. if (rc == Z_STREAM_END)
  2106. return 0;
  2107. return rc;
  2108. }
  2109. static void
  2110. load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
  2111. u32 rv2p_proc)
  2112. {
  2113. int i;
  2114. u32 val;
  2115. for (i = 0; i < rv2p_code_len; i += 8) {
  2116. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, cpu_to_le32(*rv2p_code));
  2117. rv2p_code++;
  2118. REG_WR(bp, BNX2_RV2P_INSTR_LOW, cpu_to_le32(*rv2p_code));
  2119. rv2p_code++;
  2120. if (rv2p_proc == RV2P_PROC1) {
  2121. val = (i / 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  2122. REG_WR(bp, BNX2_RV2P_PROC1_ADDR_CMD, val);
  2123. }
  2124. else {
  2125. val = (i / 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  2126. REG_WR(bp, BNX2_RV2P_PROC2_ADDR_CMD, val);
  2127. }
  2128. }
  2129. /* Reset the processor, un-stall is done later. */
  2130. if (rv2p_proc == RV2P_PROC1) {
  2131. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  2132. }
  2133. else {
  2134. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  2135. }
  2136. }
  2137. static int
  2138. load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
  2139. {
  2140. u32 offset;
  2141. u32 val;
  2142. int rc;
  2143. /* Halt the CPU. */
  2144. val = REG_RD_IND(bp, cpu_reg->mode);
  2145. val |= cpu_reg->mode_value_halt;
  2146. REG_WR_IND(bp, cpu_reg->mode, val);
  2147. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  2148. /* Load the Text area. */
  2149. offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
  2150. if (fw->gz_text) {
  2151. u32 text_len;
  2152. void *text;
  2153. rc = bnx2_gunzip(bp, fw->gz_text, fw->gz_text_len, &text,
  2154. &text_len);
  2155. if (rc)
  2156. return rc;
  2157. fw->text = text;
  2158. }
  2159. if (fw->gz_text) {
  2160. int j;
  2161. for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
  2162. REG_WR_IND(bp, offset, cpu_to_le32(fw->text[j]));
  2163. }
  2164. }
  2165. /* Load the Data area. */
  2166. offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
  2167. if (fw->data) {
  2168. int j;
  2169. for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
  2170. REG_WR_IND(bp, offset, fw->data[j]);
  2171. }
  2172. }
  2173. /* Load the SBSS area. */
  2174. offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
  2175. if (fw->sbss) {
  2176. int j;
  2177. for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
  2178. REG_WR_IND(bp, offset, fw->sbss[j]);
  2179. }
  2180. }
  2181. /* Load the BSS area. */
  2182. offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
  2183. if (fw->bss) {
  2184. int j;
  2185. for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
  2186. REG_WR_IND(bp, offset, fw->bss[j]);
  2187. }
  2188. }
  2189. /* Load the Read-Only area. */
  2190. offset = cpu_reg->spad_base +
  2191. (fw->rodata_addr - cpu_reg->mips_view_base);
  2192. if (fw->rodata) {
  2193. int j;
  2194. for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
  2195. REG_WR_IND(bp, offset, fw->rodata[j]);
  2196. }
  2197. }
  2198. /* Clear the pre-fetch instruction. */
  2199. REG_WR_IND(bp, cpu_reg->inst, 0);
  2200. REG_WR_IND(bp, cpu_reg->pc, fw->start_addr);
  2201. /* Start the CPU. */
  2202. val = REG_RD_IND(bp, cpu_reg->mode);
  2203. val &= ~cpu_reg->mode_value_halt;
  2204. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  2205. REG_WR_IND(bp, cpu_reg->mode, val);
  2206. return 0;
  2207. }
  2208. static int
  2209. bnx2_init_cpus(struct bnx2 *bp)
  2210. {
  2211. struct cpu_reg cpu_reg;
  2212. struct fw_info *fw;
  2213. int rc = 0;
  2214. void *text;
  2215. u32 text_len;
  2216. if ((rc = bnx2_gunzip_init(bp)) != 0)
  2217. return rc;
  2218. /* Initialize the RV2P processor. */
  2219. rc = bnx2_gunzip(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), &text,
  2220. &text_len);
  2221. if (rc)
  2222. goto init_cpu_err;
  2223. load_rv2p_fw(bp, text, text_len, RV2P_PROC1);
  2224. rc = bnx2_gunzip(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), &text,
  2225. &text_len);
  2226. if (rc)
  2227. goto init_cpu_err;
  2228. load_rv2p_fw(bp, text, text_len, RV2P_PROC2);
  2229. /* Initialize the RX Processor. */
  2230. cpu_reg.mode = BNX2_RXP_CPU_MODE;
  2231. cpu_reg.mode_value_halt = BNX2_RXP_CPU_MODE_SOFT_HALT;
  2232. cpu_reg.mode_value_sstep = BNX2_RXP_CPU_MODE_STEP_ENA;
  2233. cpu_reg.state = BNX2_RXP_CPU_STATE;
  2234. cpu_reg.state_value_clear = 0xffffff;
  2235. cpu_reg.gpr0 = BNX2_RXP_CPU_REG_FILE;
  2236. cpu_reg.evmask = BNX2_RXP_CPU_EVENT_MASK;
  2237. cpu_reg.pc = BNX2_RXP_CPU_PROGRAM_COUNTER;
  2238. cpu_reg.inst = BNX2_RXP_CPU_INSTRUCTION;
  2239. cpu_reg.bp = BNX2_RXP_CPU_HW_BREAKPOINT;
  2240. cpu_reg.spad_base = BNX2_RXP_SCRATCH;
  2241. cpu_reg.mips_view_base = 0x8000000;
  2242. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2243. fw = &bnx2_rxp_fw_09;
  2244. else
  2245. fw = &bnx2_rxp_fw_06;
  2246. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2247. if (rc)
  2248. goto init_cpu_err;
  2249. /* Initialize the TX Processor. */
  2250. cpu_reg.mode = BNX2_TXP_CPU_MODE;
  2251. cpu_reg.mode_value_halt = BNX2_TXP_CPU_MODE_SOFT_HALT;
  2252. cpu_reg.mode_value_sstep = BNX2_TXP_CPU_MODE_STEP_ENA;
  2253. cpu_reg.state = BNX2_TXP_CPU_STATE;
  2254. cpu_reg.state_value_clear = 0xffffff;
  2255. cpu_reg.gpr0 = BNX2_TXP_CPU_REG_FILE;
  2256. cpu_reg.evmask = BNX2_TXP_CPU_EVENT_MASK;
  2257. cpu_reg.pc = BNX2_TXP_CPU_PROGRAM_COUNTER;
  2258. cpu_reg.inst = BNX2_TXP_CPU_INSTRUCTION;
  2259. cpu_reg.bp = BNX2_TXP_CPU_HW_BREAKPOINT;
  2260. cpu_reg.spad_base = BNX2_TXP_SCRATCH;
  2261. cpu_reg.mips_view_base = 0x8000000;
  2262. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2263. fw = &bnx2_txp_fw_09;
  2264. else
  2265. fw = &bnx2_txp_fw_06;
  2266. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2267. if (rc)
  2268. goto init_cpu_err;
  2269. /* Initialize the TX Patch-up Processor. */
  2270. cpu_reg.mode = BNX2_TPAT_CPU_MODE;
  2271. cpu_reg.mode_value_halt = BNX2_TPAT_CPU_MODE_SOFT_HALT;
  2272. cpu_reg.mode_value_sstep = BNX2_TPAT_CPU_MODE_STEP_ENA;
  2273. cpu_reg.state = BNX2_TPAT_CPU_STATE;
  2274. cpu_reg.state_value_clear = 0xffffff;
  2275. cpu_reg.gpr0 = BNX2_TPAT_CPU_REG_FILE;
  2276. cpu_reg.evmask = BNX2_TPAT_CPU_EVENT_MASK;
  2277. cpu_reg.pc = BNX2_TPAT_CPU_PROGRAM_COUNTER;
  2278. cpu_reg.inst = BNX2_TPAT_CPU_INSTRUCTION;
  2279. cpu_reg.bp = BNX2_TPAT_CPU_HW_BREAKPOINT;
  2280. cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
  2281. cpu_reg.mips_view_base = 0x8000000;
  2282. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2283. fw = &bnx2_tpat_fw_09;
  2284. else
  2285. fw = &bnx2_tpat_fw_06;
  2286. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2287. if (rc)
  2288. goto init_cpu_err;
  2289. /* Initialize the Completion Processor. */
  2290. cpu_reg.mode = BNX2_COM_CPU_MODE;
  2291. cpu_reg.mode_value_halt = BNX2_COM_CPU_MODE_SOFT_HALT;
  2292. cpu_reg.mode_value_sstep = BNX2_COM_CPU_MODE_STEP_ENA;
  2293. cpu_reg.state = BNX2_COM_CPU_STATE;
  2294. cpu_reg.state_value_clear = 0xffffff;
  2295. cpu_reg.gpr0 = BNX2_COM_CPU_REG_FILE;
  2296. cpu_reg.evmask = BNX2_COM_CPU_EVENT_MASK;
  2297. cpu_reg.pc = BNX2_COM_CPU_PROGRAM_COUNTER;
  2298. cpu_reg.inst = BNX2_COM_CPU_INSTRUCTION;
  2299. cpu_reg.bp = BNX2_COM_CPU_HW_BREAKPOINT;
  2300. cpu_reg.spad_base = BNX2_COM_SCRATCH;
  2301. cpu_reg.mips_view_base = 0x8000000;
  2302. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2303. fw = &bnx2_com_fw_09;
  2304. else
  2305. fw = &bnx2_com_fw_06;
  2306. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2307. if (rc)
  2308. goto init_cpu_err;
  2309. /* Initialize the Command Processor. */
  2310. cpu_reg.mode = BNX2_CP_CPU_MODE;
  2311. cpu_reg.mode_value_halt = BNX2_CP_CPU_MODE_SOFT_HALT;
  2312. cpu_reg.mode_value_sstep = BNX2_CP_CPU_MODE_STEP_ENA;
  2313. cpu_reg.state = BNX2_CP_CPU_STATE;
  2314. cpu_reg.state_value_clear = 0xffffff;
  2315. cpu_reg.gpr0 = BNX2_CP_CPU_REG_FILE;
  2316. cpu_reg.evmask = BNX2_CP_CPU_EVENT_MASK;
  2317. cpu_reg.pc = BNX2_CP_CPU_PROGRAM_COUNTER;
  2318. cpu_reg.inst = BNX2_CP_CPU_INSTRUCTION;
  2319. cpu_reg.bp = BNX2_CP_CPU_HW_BREAKPOINT;
  2320. cpu_reg.spad_base = BNX2_CP_SCRATCH;
  2321. cpu_reg.mips_view_base = 0x8000000;
  2322. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  2323. fw = &bnx2_cp_fw_09;
  2324. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2325. if (rc)
  2326. goto init_cpu_err;
  2327. }
  2328. init_cpu_err:
  2329. bnx2_gunzip_end(bp);
  2330. return rc;
  2331. }
  2332. static int
  2333. bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
  2334. {
  2335. u16 pmcsr;
  2336. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  2337. switch (state) {
  2338. case PCI_D0: {
  2339. u32 val;
  2340. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  2341. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  2342. PCI_PM_CTRL_PME_STATUS);
  2343. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  2344. /* delay required during transition out of D3hot */
  2345. msleep(20);
  2346. val = REG_RD(bp, BNX2_EMAC_MODE);
  2347. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  2348. val &= ~BNX2_EMAC_MODE_MPKT;
  2349. REG_WR(bp, BNX2_EMAC_MODE, val);
  2350. val = REG_RD(bp, BNX2_RPM_CONFIG);
  2351. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  2352. REG_WR(bp, BNX2_RPM_CONFIG, val);
  2353. break;
  2354. }
  2355. case PCI_D3hot: {
  2356. int i;
  2357. u32 val, wol_msg;
  2358. if (bp->wol) {
  2359. u32 advertising;
  2360. u8 autoneg;
  2361. autoneg = bp->autoneg;
  2362. advertising = bp->advertising;
  2363. bp->autoneg = AUTONEG_SPEED;
  2364. bp->advertising = ADVERTISED_10baseT_Half |
  2365. ADVERTISED_10baseT_Full |
  2366. ADVERTISED_100baseT_Half |
  2367. ADVERTISED_100baseT_Full |
  2368. ADVERTISED_Autoneg;
  2369. bnx2_setup_copper_phy(bp);
  2370. bp->autoneg = autoneg;
  2371. bp->advertising = advertising;
  2372. bnx2_set_mac_addr(bp);
  2373. val = REG_RD(bp, BNX2_EMAC_MODE);
  2374. /* Enable port mode. */
  2375. val &= ~BNX2_EMAC_MODE_PORT;
  2376. val |= BNX2_EMAC_MODE_PORT_MII |
  2377. BNX2_EMAC_MODE_MPKT_RCVD |
  2378. BNX2_EMAC_MODE_ACPI_RCVD |
  2379. BNX2_EMAC_MODE_MPKT;
  2380. REG_WR(bp, BNX2_EMAC_MODE, val);
  2381. /* receive all multicast */
  2382. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2383. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2384. 0xffffffff);
  2385. }
  2386. REG_WR(bp, BNX2_EMAC_RX_MODE,
  2387. BNX2_EMAC_RX_MODE_SORT_MODE);
  2388. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  2389. BNX2_RPM_SORT_USER0_MC_EN;
  2390. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  2391. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  2392. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  2393. BNX2_RPM_SORT_USER0_ENA);
  2394. /* Need to enable EMAC and RPM for WOL. */
  2395. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2396. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  2397. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  2398. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  2399. val = REG_RD(bp, BNX2_RPM_CONFIG);
  2400. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  2401. REG_WR(bp, BNX2_RPM_CONFIG, val);
  2402. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  2403. }
  2404. else {
  2405. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  2406. }
  2407. if (!(bp->flags & NO_WOL_FLAG))
  2408. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 0);
  2409. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  2410. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2411. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  2412. if (bp->wol)
  2413. pmcsr |= 3;
  2414. }
  2415. else {
  2416. pmcsr |= 3;
  2417. }
  2418. if (bp->wol) {
  2419. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  2420. }
  2421. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  2422. pmcsr);
  2423. /* No more memory access after this point until
  2424. * device is brought back to D0.
  2425. */
  2426. udelay(50);
  2427. break;
  2428. }
  2429. default:
  2430. return -EINVAL;
  2431. }
  2432. return 0;
  2433. }
  2434. static int
  2435. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  2436. {
  2437. u32 val;
  2438. int j;
  2439. /* Request access to the flash interface. */
  2440. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  2441. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2442. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2443. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  2444. break;
  2445. udelay(5);
  2446. }
  2447. if (j >= NVRAM_TIMEOUT_COUNT)
  2448. return -EBUSY;
  2449. return 0;
  2450. }
  2451. static int
  2452. bnx2_release_nvram_lock(struct bnx2 *bp)
  2453. {
  2454. int j;
  2455. u32 val;
  2456. /* Relinquish nvram interface. */
  2457. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  2458. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2459. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2460. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  2461. break;
  2462. udelay(5);
  2463. }
  2464. if (j >= NVRAM_TIMEOUT_COUNT)
  2465. return -EBUSY;
  2466. return 0;
  2467. }
  2468. static int
  2469. bnx2_enable_nvram_write(struct bnx2 *bp)
  2470. {
  2471. u32 val;
  2472. val = REG_RD(bp, BNX2_MISC_CFG);
  2473. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  2474. if (!bp->flash_info->buffered) {
  2475. int j;
  2476. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2477. REG_WR(bp, BNX2_NVM_COMMAND,
  2478. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  2479. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2480. udelay(5);
  2481. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2482. if (val & BNX2_NVM_COMMAND_DONE)
  2483. break;
  2484. }
  2485. if (j >= NVRAM_TIMEOUT_COUNT)
  2486. return -EBUSY;
  2487. }
  2488. return 0;
  2489. }
  2490. static void
  2491. bnx2_disable_nvram_write(struct bnx2 *bp)
  2492. {
  2493. u32 val;
  2494. val = REG_RD(bp, BNX2_MISC_CFG);
  2495. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  2496. }
  2497. static void
  2498. bnx2_enable_nvram_access(struct bnx2 *bp)
  2499. {
  2500. u32 val;
  2501. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2502. /* Enable both bits, even on read. */
  2503. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2504. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  2505. }
  2506. static void
  2507. bnx2_disable_nvram_access(struct bnx2 *bp)
  2508. {
  2509. u32 val;
  2510. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2511. /* Disable both bits, even after read. */
  2512. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2513. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  2514. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  2515. }
  2516. static int
  2517. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  2518. {
  2519. u32 cmd;
  2520. int j;
  2521. if (bp->flash_info->buffered)
  2522. /* Buffered flash, no erase needed */
  2523. return 0;
  2524. /* Build an erase command */
  2525. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  2526. BNX2_NVM_COMMAND_DOIT;
  2527. /* Need to clear DONE bit separately. */
  2528. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2529. /* Address of the NVRAM to read from. */
  2530. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2531. /* Issue an erase command. */
  2532. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2533. /* Wait for completion. */
  2534. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2535. u32 val;
  2536. udelay(5);
  2537. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2538. if (val & BNX2_NVM_COMMAND_DONE)
  2539. break;
  2540. }
  2541. if (j >= NVRAM_TIMEOUT_COUNT)
  2542. return -EBUSY;
  2543. return 0;
  2544. }
  2545. static int
  2546. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  2547. {
  2548. u32 cmd;
  2549. int j;
  2550. /* Build the command word. */
  2551. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  2552. /* Calculate an offset of a buffered flash. */
  2553. if (bp->flash_info->buffered) {
  2554. offset = ((offset / bp->flash_info->page_size) <<
  2555. bp->flash_info->page_bits) +
  2556. (offset % bp->flash_info->page_size);
  2557. }
  2558. /* Need to clear DONE bit separately. */
  2559. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2560. /* Address of the NVRAM to read from. */
  2561. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2562. /* Issue a read command. */
  2563. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2564. /* Wait for completion. */
  2565. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2566. u32 val;
  2567. udelay(5);
  2568. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2569. if (val & BNX2_NVM_COMMAND_DONE) {
  2570. val = REG_RD(bp, BNX2_NVM_READ);
  2571. val = be32_to_cpu(val);
  2572. memcpy(ret_val, &val, 4);
  2573. break;
  2574. }
  2575. }
  2576. if (j >= NVRAM_TIMEOUT_COUNT)
  2577. return -EBUSY;
  2578. return 0;
  2579. }
  2580. static int
  2581. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  2582. {
  2583. u32 cmd, val32;
  2584. int j;
  2585. /* Build the command word. */
  2586. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  2587. /* Calculate an offset of a buffered flash. */
  2588. if (bp->flash_info->buffered) {
  2589. offset = ((offset / bp->flash_info->page_size) <<
  2590. bp->flash_info->page_bits) +
  2591. (offset % bp->flash_info->page_size);
  2592. }
  2593. /* Need to clear DONE bit separately. */
  2594. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2595. memcpy(&val32, val, 4);
  2596. val32 = cpu_to_be32(val32);
  2597. /* Write the data. */
  2598. REG_WR(bp, BNX2_NVM_WRITE, val32);
  2599. /* Address of the NVRAM to write to. */
  2600. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2601. /* Issue the write command. */
  2602. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2603. /* Wait for completion. */
  2604. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2605. udelay(5);
  2606. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  2607. break;
  2608. }
  2609. if (j >= NVRAM_TIMEOUT_COUNT)
  2610. return -EBUSY;
  2611. return 0;
  2612. }
  2613. static int
  2614. bnx2_init_nvram(struct bnx2 *bp)
  2615. {
  2616. u32 val;
  2617. int j, entry_count, rc;
  2618. struct flash_spec *flash;
  2619. /* Determine the selected interface. */
  2620. val = REG_RD(bp, BNX2_NVM_CFG1);
  2621. entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
  2622. rc = 0;
  2623. if (val & 0x40000000) {
  2624. /* Flash interface has been reconfigured */
  2625. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2626. j++, flash++) {
  2627. if ((val & FLASH_BACKUP_STRAP_MASK) ==
  2628. (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
  2629. bp->flash_info = flash;
  2630. break;
  2631. }
  2632. }
  2633. }
  2634. else {
  2635. u32 mask;
  2636. /* Not yet been reconfigured */
  2637. if (val & (1 << 23))
  2638. mask = FLASH_BACKUP_STRAP_MASK;
  2639. else
  2640. mask = FLASH_STRAP_MASK;
  2641. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2642. j++, flash++) {
  2643. if ((val & mask) == (flash->strapping & mask)) {
  2644. bp->flash_info = flash;
  2645. /* Request access to the flash interface. */
  2646. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2647. return rc;
  2648. /* Enable access to flash interface */
  2649. bnx2_enable_nvram_access(bp);
  2650. /* Reconfigure the flash interface */
  2651. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  2652. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  2653. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  2654. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  2655. /* Disable access to flash interface */
  2656. bnx2_disable_nvram_access(bp);
  2657. bnx2_release_nvram_lock(bp);
  2658. break;
  2659. }
  2660. }
  2661. } /* if (val & 0x40000000) */
  2662. if (j == entry_count) {
  2663. bp->flash_info = NULL;
  2664. printk(KERN_ALERT PFX "Unknown flash/EEPROM type.\n");
  2665. return -ENODEV;
  2666. }
  2667. val = REG_RD_IND(bp, bp->shmem_base + BNX2_SHARED_HW_CFG_CONFIG2);
  2668. val &= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK;
  2669. if (val)
  2670. bp->flash_size = val;
  2671. else
  2672. bp->flash_size = bp->flash_info->total_size;
  2673. return rc;
  2674. }
  2675. static int
  2676. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  2677. int buf_size)
  2678. {
  2679. int rc = 0;
  2680. u32 cmd_flags, offset32, len32, extra;
  2681. if (buf_size == 0)
  2682. return 0;
  2683. /* Request access to the flash interface. */
  2684. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2685. return rc;
  2686. /* Enable access to flash interface */
  2687. bnx2_enable_nvram_access(bp);
  2688. len32 = buf_size;
  2689. offset32 = offset;
  2690. extra = 0;
  2691. cmd_flags = 0;
  2692. if (offset32 & 3) {
  2693. u8 buf[4];
  2694. u32 pre_len;
  2695. offset32 &= ~3;
  2696. pre_len = 4 - (offset & 3);
  2697. if (pre_len >= len32) {
  2698. pre_len = len32;
  2699. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2700. BNX2_NVM_COMMAND_LAST;
  2701. }
  2702. else {
  2703. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2704. }
  2705. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2706. if (rc)
  2707. return rc;
  2708. memcpy(ret_buf, buf + (offset & 3), pre_len);
  2709. offset32 += 4;
  2710. ret_buf += pre_len;
  2711. len32 -= pre_len;
  2712. }
  2713. if (len32 & 3) {
  2714. extra = 4 - (len32 & 3);
  2715. len32 = (len32 + 4) & ~3;
  2716. }
  2717. if (len32 == 4) {
  2718. u8 buf[4];
  2719. if (cmd_flags)
  2720. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2721. else
  2722. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2723. BNX2_NVM_COMMAND_LAST;
  2724. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2725. memcpy(ret_buf, buf, 4 - extra);
  2726. }
  2727. else if (len32 > 0) {
  2728. u8 buf[4];
  2729. /* Read the first word. */
  2730. if (cmd_flags)
  2731. cmd_flags = 0;
  2732. else
  2733. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2734. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  2735. /* Advance to the next dword. */
  2736. offset32 += 4;
  2737. ret_buf += 4;
  2738. len32 -= 4;
  2739. while (len32 > 4 && rc == 0) {
  2740. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  2741. /* Advance to the next dword. */
  2742. offset32 += 4;
  2743. ret_buf += 4;
  2744. len32 -= 4;
  2745. }
  2746. if (rc)
  2747. return rc;
  2748. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2749. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2750. memcpy(ret_buf, buf, 4 - extra);
  2751. }
  2752. /* Disable access to flash interface */
  2753. bnx2_disable_nvram_access(bp);
  2754. bnx2_release_nvram_lock(bp);
  2755. return rc;
  2756. }
  2757. static int
  2758. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  2759. int buf_size)
  2760. {
  2761. u32 written, offset32, len32;
  2762. u8 *buf, start[4], end[4], *align_buf = NULL, *flash_buffer = NULL;
  2763. int rc = 0;
  2764. int align_start, align_end;
  2765. buf = data_buf;
  2766. offset32 = offset;
  2767. len32 = buf_size;
  2768. align_start = align_end = 0;
  2769. if ((align_start = (offset32 & 3))) {
  2770. offset32 &= ~3;
  2771. len32 += align_start;
  2772. if (len32 < 4)
  2773. len32 = 4;
  2774. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  2775. return rc;
  2776. }
  2777. if (len32 & 3) {
  2778. align_end = 4 - (len32 & 3);
  2779. len32 += align_end;
  2780. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4, end, 4)))
  2781. return rc;
  2782. }
  2783. if (align_start || align_end) {
  2784. align_buf = kmalloc(len32, GFP_KERNEL);
  2785. if (align_buf == NULL)
  2786. return -ENOMEM;
  2787. if (align_start) {
  2788. memcpy(align_buf, start, 4);
  2789. }
  2790. if (align_end) {
  2791. memcpy(align_buf + len32 - 4, end, 4);
  2792. }
  2793. memcpy(align_buf + align_start, data_buf, buf_size);
  2794. buf = align_buf;
  2795. }
  2796. if (bp->flash_info->buffered == 0) {
  2797. flash_buffer = kmalloc(264, GFP_KERNEL);
  2798. if (flash_buffer == NULL) {
  2799. rc = -ENOMEM;
  2800. goto nvram_write_end;
  2801. }
  2802. }
  2803. written = 0;
  2804. while ((written < len32) && (rc == 0)) {
  2805. u32 page_start, page_end, data_start, data_end;
  2806. u32 addr, cmd_flags;
  2807. int i;
  2808. /* Find the page_start addr */
  2809. page_start = offset32 + written;
  2810. page_start -= (page_start % bp->flash_info->page_size);
  2811. /* Find the page_end addr */
  2812. page_end = page_start + bp->flash_info->page_size;
  2813. /* Find the data_start addr */
  2814. data_start = (written == 0) ? offset32 : page_start;
  2815. /* Find the data_end addr */
  2816. data_end = (page_end > offset32 + len32) ?
  2817. (offset32 + len32) : page_end;
  2818. /* Request access to the flash interface. */
  2819. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2820. goto nvram_write_end;
  2821. /* Enable access to flash interface */
  2822. bnx2_enable_nvram_access(bp);
  2823. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2824. if (bp->flash_info->buffered == 0) {
  2825. int j;
  2826. /* Read the whole page into the buffer
  2827. * (non-buffer flash only) */
  2828. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  2829. if (j == (bp->flash_info->page_size - 4)) {
  2830. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2831. }
  2832. rc = bnx2_nvram_read_dword(bp,
  2833. page_start + j,
  2834. &flash_buffer[j],
  2835. cmd_flags);
  2836. if (rc)
  2837. goto nvram_write_end;
  2838. cmd_flags = 0;
  2839. }
  2840. }
  2841. /* Enable writes to flash interface (unlock write-protect) */
  2842. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  2843. goto nvram_write_end;
  2844. /* Loop to write back the buffer data from page_start to
  2845. * data_start */
  2846. i = 0;
  2847. if (bp->flash_info->buffered == 0) {
  2848. /* Erase the page */
  2849. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  2850. goto nvram_write_end;
  2851. /* Re-enable the write again for the actual write */
  2852. bnx2_enable_nvram_write(bp);
  2853. for (addr = page_start; addr < data_start;
  2854. addr += 4, i += 4) {
  2855. rc = bnx2_nvram_write_dword(bp, addr,
  2856. &flash_buffer[i], cmd_flags);
  2857. if (rc != 0)
  2858. goto nvram_write_end;
  2859. cmd_flags = 0;
  2860. }
  2861. }
  2862. /* Loop to write the new data from data_start to data_end */
  2863. for (addr = data_start; addr < data_end; addr += 4, i += 4) {
  2864. if ((addr == page_end - 4) ||
  2865. ((bp->flash_info->buffered) &&
  2866. (addr == data_end - 4))) {
  2867. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2868. }
  2869. rc = bnx2_nvram_write_dword(bp, addr, buf,
  2870. cmd_flags);
  2871. if (rc != 0)
  2872. goto nvram_write_end;
  2873. cmd_flags = 0;
  2874. buf += 4;
  2875. }
  2876. /* Loop to write back the buffer data from data_end
  2877. * to page_end */
  2878. if (bp->flash_info->buffered == 0) {
  2879. for (addr = data_end; addr < page_end;
  2880. addr += 4, i += 4) {
  2881. if (addr == page_end-4) {
  2882. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2883. }
  2884. rc = bnx2_nvram_write_dword(bp, addr,
  2885. &flash_buffer[i], cmd_flags);
  2886. if (rc != 0)
  2887. goto nvram_write_end;
  2888. cmd_flags = 0;
  2889. }
  2890. }
  2891. /* Disable writes to flash interface (lock write-protect) */
  2892. bnx2_disable_nvram_write(bp);
  2893. /* Disable access to flash interface */
  2894. bnx2_disable_nvram_access(bp);
  2895. bnx2_release_nvram_lock(bp);
  2896. /* Increment written */
  2897. written += data_end - data_start;
  2898. }
  2899. nvram_write_end:
  2900. kfree(flash_buffer);
  2901. kfree(align_buf);
  2902. return rc;
  2903. }
  2904. static int
  2905. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  2906. {
  2907. u32 val;
  2908. int i, rc = 0;
  2909. /* Wait for the current PCI transaction to complete before
  2910. * issuing a reset. */
  2911. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  2912. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  2913. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  2914. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  2915. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  2916. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  2917. udelay(5);
  2918. /* Wait for the firmware to tell us it is ok to issue a reset. */
  2919. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1);
  2920. /* Deposit a driver reset signature so the firmware knows that
  2921. * this is a soft reset. */
  2922. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_RESET_SIGNATURE,
  2923. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  2924. /* Do a dummy read to force the chip to complete all current transaction
  2925. * before we issue a reset. */
  2926. val = REG_RD(bp, BNX2_MISC_ID);
  2927. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  2928. REG_WR(bp, BNX2_MISC_COMMAND, BNX2_MISC_COMMAND_SW_RESET);
  2929. REG_RD(bp, BNX2_MISC_COMMAND);
  2930. udelay(5);
  2931. val = BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2932. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2933. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG, val);
  2934. } else {
  2935. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2936. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2937. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2938. /* Chip reset. */
  2939. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  2940. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2941. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  2942. current->state = TASK_UNINTERRUPTIBLE;
  2943. schedule_timeout(HZ / 50);
  2944. }
  2945. /* Reset takes approximate 30 usec */
  2946. for (i = 0; i < 10; i++) {
  2947. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  2948. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2949. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
  2950. break;
  2951. udelay(10);
  2952. }
  2953. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2954. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  2955. printk(KERN_ERR PFX "Chip reset did not complete\n");
  2956. return -EBUSY;
  2957. }
  2958. }
  2959. /* Make sure byte swapping is properly configured. */
  2960. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  2961. if (val != 0x01020304) {
  2962. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  2963. return -ENODEV;
  2964. }
  2965. /* Wait for the firmware to finish its initialization. */
  2966. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code, 0);
  2967. if (rc)
  2968. return rc;
  2969. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2970. /* Adjust the voltage regular to two steps lower. The default
  2971. * of this register is 0x0000000e. */
  2972. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  2973. /* Remove bad rbuf memory from the free pool. */
  2974. rc = bnx2_alloc_bad_rbuf(bp);
  2975. }
  2976. return rc;
  2977. }
  2978. static int
  2979. bnx2_init_chip(struct bnx2 *bp)
  2980. {
  2981. u32 val;
  2982. int rc;
  2983. /* Make sure the interrupt is not active. */
  2984. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2985. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  2986. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  2987. #ifdef __BIG_ENDIAN
  2988. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  2989. #endif
  2990. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  2991. DMA_READ_CHANS << 12 |
  2992. DMA_WRITE_CHANS << 16;
  2993. val |= (0x2 << 20) | (1 << 11);
  2994. if ((bp->flags & PCIX_FLAG) && (bp->bus_speed_mhz == 133))
  2995. val |= (1 << 23);
  2996. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  2997. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & PCIX_FLAG))
  2998. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  2999. REG_WR(bp, BNX2_DMA_CONFIG, val);
  3000. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  3001. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  3002. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  3003. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  3004. }
  3005. if (bp->flags & PCIX_FLAG) {
  3006. u16 val16;
  3007. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  3008. &val16);
  3009. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  3010. val16 & ~PCI_X_CMD_ERO);
  3011. }
  3012. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  3013. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  3014. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  3015. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  3016. /* Initialize context mapping and zero out the quick contexts. The
  3017. * context block must have already been enabled. */
  3018. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3019. rc = bnx2_init_5709_context(bp);
  3020. if (rc)
  3021. return rc;
  3022. } else
  3023. bnx2_init_context(bp);
  3024. if ((rc = bnx2_init_cpus(bp)) != 0)
  3025. return rc;
  3026. bnx2_init_nvram(bp);
  3027. bnx2_set_mac_addr(bp);
  3028. val = REG_RD(bp, BNX2_MQ_CONFIG);
  3029. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  3030. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  3031. if (CHIP_ID(bp) == CHIP_ID_5709_A0 || CHIP_ID(bp) == CHIP_ID_5709_A1)
  3032. val |= BNX2_MQ_CONFIG_HALT_DIS;
  3033. REG_WR(bp, BNX2_MQ_CONFIG, val);
  3034. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  3035. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  3036. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  3037. val = (BCM_PAGE_BITS - 8) << 24;
  3038. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  3039. /* Configure page size. */
  3040. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  3041. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  3042. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  3043. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  3044. val = bp->mac_addr[0] +
  3045. (bp->mac_addr[1] << 8) +
  3046. (bp->mac_addr[2] << 16) +
  3047. bp->mac_addr[3] +
  3048. (bp->mac_addr[4] << 8) +
  3049. (bp->mac_addr[5] << 16);
  3050. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  3051. /* Program the MTU. Also include 4 bytes for CRC32. */
  3052. val = bp->dev->mtu + ETH_HLEN + 4;
  3053. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  3054. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  3055. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  3056. bp->last_status_idx = 0;
  3057. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  3058. /* Set up how to generate a link change interrupt. */
  3059. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  3060. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  3061. (u64) bp->status_blk_mapping & 0xffffffff);
  3062. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  3063. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  3064. (u64) bp->stats_blk_mapping & 0xffffffff);
  3065. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  3066. (u64) bp->stats_blk_mapping >> 32);
  3067. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  3068. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  3069. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  3070. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  3071. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  3072. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  3073. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  3074. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  3075. REG_WR(bp, BNX2_HC_COM_TICKS,
  3076. (bp->com_ticks_int << 16) | bp->com_ticks);
  3077. REG_WR(bp, BNX2_HC_CMD_TICKS,
  3078. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  3079. if (CHIP_NUM(bp) == CHIP_NUM_5708)
  3080. REG_WR(bp, BNX2_HC_STATS_TICKS, 0);
  3081. else
  3082. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks & 0xffff00);
  3083. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  3084. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  3085. val = BNX2_HC_CONFIG_COLLECT_STATS;
  3086. else {
  3087. val = BNX2_HC_CONFIG_RX_TMR_MODE | BNX2_HC_CONFIG_TX_TMR_MODE |
  3088. BNX2_HC_CONFIG_COLLECT_STATS;
  3089. }
  3090. if (bp->flags & ONE_SHOT_MSI_FLAG)
  3091. val |= BNX2_HC_CONFIG_ONE_SHOT;
  3092. REG_WR(bp, BNX2_HC_CONFIG, val);
  3093. /* Clear internal stats counters. */
  3094. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  3095. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_EVENTS);
  3096. if (REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_FEATURE) &
  3097. BNX2_PORT_FEATURE_ASF_ENABLED)
  3098. bp->flags |= ASF_ENABLE_FLAG;
  3099. /* Initialize the receive filter. */
  3100. bnx2_set_rx_mode(bp->dev);
  3101. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3102. val = REG_RD(bp, BNX2_MISC_NEW_CORE_CTL);
  3103. val |= BNX2_MISC_NEW_CORE_CTL_DMA_ENABLE;
  3104. REG_WR(bp, BNX2_MISC_NEW_CORE_CTL, val);
  3105. }
  3106. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
  3107. 0);
  3108. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
  3109. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  3110. udelay(20);
  3111. bp->hc_cmd = REG_RD(bp, BNX2_HC_COMMAND);
  3112. return rc;
  3113. }
  3114. static void
  3115. bnx2_init_tx_context(struct bnx2 *bp, u32 cid)
  3116. {
  3117. u32 val, offset0, offset1, offset2, offset3;
  3118. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  3119. offset0 = BNX2_L2CTX_TYPE_XI;
  3120. offset1 = BNX2_L2CTX_CMD_TYPE_XI;
  3121. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI;
  3122. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI;
  3123. } else {
  3124. offset0 = BNX2_L2CTX_TYPE;
  3125. offset1 = BNX2_L2CTX_CMD_TYPE;
  3126. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI;
  3127. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO;
  3128. }
  3129. val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2;
  3130. CTX_WR(bp, GET_CID_ADDR(cid), offset0, val);
  3131. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
  3132. CTX_WR(bp, GET_CID_ADDR(cid), offset1, val);
  3133. val = (u64) bp->tx_desc_mapping >> 32;
  3134. CTX_WR(bp, GET_CID_ADDR(cid), offset2, val);
  3135. val = (u64) bp->tx_desc_mapping & 0xffffffff;
  3136. CTX_WR(bp, GET_CID_ADDR(cid), offset3, val);
  3137. }
  3138. static void
  3139. bnx2_init_tx_ring(struct bnx2 *bp)
  3140. {
  3141. struct tx_bd *txbd;
  3142. u32 cid;
  3143. bp->tx_wake_thresh = bp->tx_ring_size / 2;
  3144. txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
  3145. txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
  3146. txbd->tx_bd_haddr_lo = (u64) bp->tx_desc_mapping & 0xffffffff;
  3147. bp->tx_prod = 0;
  3148. bp->tx_cons = 0;
  3149. bp->hw_tx_cons = 0;
  3150. bp->tx_prod_bseq = 0;
  3151. cid = TX_CID;
  3152. bp->tx_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BIDX;
  3153. bp->tx_bseq_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BSEQ;
  3154. bnx2_init_tx_context(bp, cid);
  3155. }
  3156. static void
  3157. bnx2_init_rx_ring(struct bnx2 *bp)
  3158. {
  3159. struct rx_bd *rxbd;
  3160. int i;
  3161. u16 prod, ring_prod;
  3162. u32 val;
  3163. /* 8 for CRC and VLAN */
  3164. bp->rx_buf_use_size = bp->dev->mtu + ETH_HLEN + bp->rx_offset + 8;
  3165. /* hw alignment */
  3166. bp->rx_buf_size = bp->rx_buf_use_size + BNX2_RX_ALIGN;
  3167. ring_prod = prod = bp->rx_prod = 0;
  3168. bp->rx_cons = 0;
  3169. bp->hw_rx_cons = 0;
  3170. bp->rx_prod_bseq = 0;
  3171. for (i = 0; i < bp->rx_max_ring; i++) {
  3172. int j;
  3173. rxbd = &bp->rx_desc_ring[i][0];
  3174. for (j = 0; j < MAX_RX_DESC_CNT; j++, rxbd++) {
  3175. rxbd->rx_bd_len = bp->rx_buf_use_size;
  3176. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  3177. }
  3178. if (i == (bp->rx_max_ring - 1))
  3179. j = 0;
  3180. else
  3181. j = i + 1;
  3182. rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping[j] >> 32;
  3183. rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping[j] &
  3184. 0xffffffff;
  3185. }
  3186. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  3187. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  3188. val |= 0x02 << 8;
  3189. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
  3190. val = (u64) bp->rx_desc_mapping[0] >> 32;
  3191. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
  3192. val = (u64) bp->rx_desc_mapping[0] & 0xffffffff;
  3193. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
  3194. for (i = 0; i < bp->rx_ring_size; i++) {
  3195. if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
  3196. break;
  3197. }
  3198. prod = NEXT_RX_BD(prod);
  3199. ring_prod = RX_RING_IDX(prod);
  3200. }
  3201. bp->rx_prod = prod;
  3202. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, prod);
  3203. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  3204. }
  3205. static void
  3206. bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
  3207. {
  3208. u32 num_rings, max;
  3209. bp->rx_ring_size = size;
  3210. num_rings = 1;
  3211. while (size > MAX_RX_DESC_CNT) {
  3212. size -= MAX_RX_DESC_CNT;
  3213. num_rings++;
  3214. }
  3215. /* round to next power of 2 */
  3216. max = MAX_RX_RINGS;
  3217. while ((max & num_rings) == 0)
  3218. max >>= 1;
  3219. if (num_rings != max)
  3220. max <<= 1;
  3221. bp->rx_max_ring = max;
  3222. bp->rx_max_ring_idx = (bp->rx_max_ring * RX_DESC_CNT) - 1;
  3223. }
  3224. static void
  3225. bnx2_free_tx_skbs(struct bnx2 *bp)
  3226. {
  3227. int i;
  3228. if (bp->tx_buf_ring == NULL)
  3229. return;
  3230. for (i = 0; i < TX_DESC_CNT; ) {
  3231. struct sw_bd *tx_buf = &bp->tx_buf_ring[i];
  3232. struct sk_buff *skb = tx_buf->skb;
  3233. int j, last;
  3234. if (skb == NULL) {
  3235. i++;
  3236. continue;
  3237. }
  3238. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  3239. skb_headlen(skb), PCI_DMA_TODEVICE);
  3240. tx_buf->skb = NULL;
  3241. last = skb_shinfo(skb)->nr_frags;
  3242. for (j = 0; j < last; j++) {
  3243. tx_buf = &bp->tx_buf_ring[i + j + 1];
  3244. pci_unmap_page(bp->pdev,
  3245. pci_unmap_addr(tx_buf, mapping),
  3246. skb_shinfo(skb)->frags[j].size,
  3247. PCI_DMA_TODEVICE);
  3248. }
  3249. dev_kfree_skb(skb);
  3250. i += j + 1;
  3251. }
  3252. }
  3253. static void
  3254. bnx2_free_rx_skbs(struct bnx2 *bp)
  3255. {
  3256. int i;
  3257. if (bp->rx_buf_ring == NULL)
  3258. return;
  3259. for (i = 0; i < bp->rx_max_ring_idx; i++) {
  3260. struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
  3261. struct sk_buff *skb = rx_buf->skb;
  3262. if (skb == NULL)
  3263. continue;
  3264. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  3265. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  3266. rx_buf->skb = NULL;
  3267. dev_kfree_skb(skb);
  3268. }
  3269. }
  3270. static void
  3271. bnx2_free_skbs(struct bnx2 *bp)
  3272. {
  3273. bnx2_free_tx_skbs(bp);
  3274. bnx2_free_rx_skbs(bp);
  3275. }
  3276. static int
  3277. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  3278. {
  3279. int rc;
  3280. rc = bnx2_reset_chip(bp, reset_code);
  3281. bnx2_free_skbs(bp);
  3282. if (rc)
  3283. return rc;
  3284. if ((rc = bnx2_init_chip(bp)) != 0)
  3285. return rc;
  3286. bnx2_init_tx_ring(bp);
  3287. bnx2_init_rx_ring(bp);
  3288. return 0;
  3289. }
  3290. static int
  3291. bnx2_init_nic(struct bnx2 *bp)
  3292. {
  3293. int rc;
  3294. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  3295. return rc;
  3296. spin_lock_bh(&bp->phy_lock);
  3297. bnx2_init_phy(bp);
  3298. spin_unlock_bh(&bp->phy_lock);
  3299. bnx2_set_link(bp);
  3300. return 0;
  3301. }
  3302. static int
  3303. bnx2_test_registers(struct bnx2 *bp)
  3304. {
  3305. int ret;
  3306. int i, is_5709;
  3307. static const struct {
  3308. u16 offset;
  3309. u16 flags;
  3310. #define BNX2_FL_NOT_5709 1
  3311. u32 rw_mask;
  3312. u32 ro_mask;
  3313. } reg_tbl[] = {
  3314. { 0x006c, 0, 0x00000000, 0x0000003f },
  3315. { 0x0090, 0, 0xffffffff, 0x00000000 },
  3316. { 0x0094, 0, 0x00000000, 0x00000000 },
  3317. { 0x0404, BNX2_FL_NOT_5709, 0x00003f00, 0x00000000 },
  3318. { 0x0418, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3319. { 0x041c, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3320. { 0x0420, BNX2_FL_NOT_5709, 0x00000000, 0x80ffffff },
  3321. { 0x0424, BNX2_FL_NOT_5709, 0x00000000, 0x00000000 },
  3322. { 0x0428, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  3323. { 0x0450, BNX2_FL_NOT_5709, 0x00000000, 0x0000ffff },
  3324. { 0x0454, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3325. { 0x0458, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3326. { 0x0808, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3327. { 0x0854, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3328. { 0x0868, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3329. { 0x086c, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3330. { 0x0870, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3331. { 0x0874, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3332. { 0x0c00, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  3333. { 0x0c04, BNX2_FL_NOT_5709, 0x00000000, 0x03ff0001 },
  3334. { 0x0c08, BNX2_FL_NOT_5709, 0x0f0ff073, 0x00000000 },
  3335. { 0x1000, 0, 0x00000000, 0x00000001 },
  3336. { 0x1004, 0, 0x00000000, 0x000f0001 },
  3337. { 0x1408, 0, 0x01c00800, 0x00000000 },
  3338. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  3339. { 0x14a8, 0, 0x00000000, 0x000001ff },
  3340. { 0x14ac, 0, 0x0fffffff, 0x10000000 },
  3341. { 0x14b0, 0, 0x00000002, 0x00000001 },
  3342. { 0x14b8, 0, 0x00000000, 0x00000000 },
  3343. { 0x14c0, 0, 0x00000000, 0x00000009 },
  3344. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  3345. { 0x14cc, 0, 0x00000000, 0x00000001 },
  3346. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  3347. { 0x1800, 0, 0x00000000, 0x00000001 },
  3348. { 0x1804, 0, 0x00000000, 0x00000003 },
  3349. { 0x2800, 0, 0x00000000, 0x00000001 },
  3350. { 0x2804, 0, 0x00000000, 0x00003f01 },
  3351. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  3352. { 0x2810, 0, 0xffff0000, 0x00000000 },
  3353. { 0x2814, 0, 0xffff0000, 0x00000000 },
  3354. { 0x2818, 0, 0xffff0000, 0x00000000 },
  3355. { 0x281c, 0, 0xffff0000, 0x00000000 },
  3356. { 0x2834, 0, 0xffffffff, 0x00000000 },
  3357. { 0x2840, 0, 0x00000000, 0xffffffff },
  3358. { 0x2844, 0, 0x00000000, 0xffffffff },
  3359. { 0x2848, 0, 0xffffffff, 0x00000000 },
  3360. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  3361. { 0x2c00, 0, 0x00000000, 0x00000011 },
  3362. { 0x2c04, 0, 0x00000000, 0x00030007 },
  3363. { 0x3c00, 0, 0x00000000, 0x00000001 },
  3364. { 0x3c04, 0, 0x00000000, 0x00070000 },
  3365. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  3366. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  3367. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  3368. { 0x3c14, 0, 0x00000000, 0xffffffff },
  3369. { 0x3c18, 0, 0x00000000, 0xffffffff },
  3370. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  3371. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  3372. { 0x5004, 0, 0x00000000, 0x0000007f },
  3373. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  3374. { 0x5c00, 0, 0x00000000, 0x00000001 },
  3375. { 0x5c04, 0, 0x00000000, 0x0003000f },
  3376. { 0x5c08, 0, 0x00000003, 0x00000000 },
  3377. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  3378. { 0x5c10, 0, 0x00000000, 0xffffffff },
  3379. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  3380. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  3381. { 0x5c88, 0, 0x00000000, 0x00077373 },
  3382. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  3383. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  3384. { 0x680c, 0, 0xffffffff, 0x00000000 },
  3385. { 0x6810, 0, 0xffffffff, 0x00000000 },
  3386. { 0x6814, 0, 0xffffffff, 0x00000000 },
  3387. { 0x6818, 0, 0xffffffff, 0x00000000 },
  3388. { 0x681c, 0, 0xffffffff, 0x00000000 },
  3389. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  3390. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  3391. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  3392. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  3393. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  3394. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  3395. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  3396. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  3397. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  3398. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  3399. { 0x684c, 0, 0xffffffff, 0x00000000 },
  3400. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  3401. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  3402. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  3403. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  3404. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  3405. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  3406. { 0xffff, 0, 0x00000000, 0x00000000 },
  3407. };
  3408. ret = 0;
  3409. is_5709 = 0;
  3410. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  3411. is_5709 = 1;
  3412. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  3413. u32 offset, rw_mask, ro_mask, save_val, val;
  3414. u16 flags = reg_tbl[i].flags;
  3415. if (is_5709 && (flags & BNX2_FL_NOT_5709))
  3416. continue;
  3417. offset = (u32) reg_tbl[i].offset;
  3418. rw_mask = reg_tbl[i].rw_mask;
  3419. ro_mask = reg_tbl[i].ro_mask;
  3420. save_val = readl(bp->regview + offset);
  3421. writel(0, bp->regview + offset);
  3422. val = readl(bp->regview + offset);
  3423. if ((val & rw_mask) != 0) {
  3424. goto reg_test_err;
  3425. }
  3426. if ((val & ro_mask) != (save_val & ro_mask)) {
  3427. goto reg_test_err;
  3428. }
  3429. writel(0xffffffff, bp->regview + offset);
  3430. val = readl(bp->regview + offset);
  3431. if ((val & rw_mask) != rw_mask) {
  3432. goto reg_test_err;
  3433. }
  3434. if ((val & ro_mask) != (save_val & ro_mask)) {
  3435. goto reg_test_err;
  3436. }
  3437. writel(save_val, bp->regview + offset);
  3438. continue;
  3439. reg_test_err:
  3440. writel(save_val, bp->regview + offset);
  3441. ret = -ENODEV;
  3442. break;
  3443. }
  3444. return ret;
  3445. }
  3446. static int
  3447. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  3448. {
  3449. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  3450. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  3451. int i;
  3452. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  3453. u32 offset;
  3454. for (offset = 0; offset < size; offset += 4) {
  3455. REG_WR_IND(bp, start + offset, test_pattern[i]);
  3456. if (REG_RD_IND(bp, start + offset) !=
  3457. test_pattern[i]) {
  3458. return -ENODEV;
  3459. }
  3460. }
  3461. }
  3462. return 0;
  3463. }
  3464. static int
  3465. bnx2_test_memory(struct bnx2 *bp)
  3466. {
  3467. int ret = 0;
  3468. int i;
  3469. static struct mem_entry {
  3470. u32 offset;
  3471. u32 len;
  3472. } mem_tbl_5706[] = {
  3473. { 0x60000, 0x4000 },
  3474. { 0xa0000, 0x3000 },
  3475. { 0xe0000, 0x4000 },
  3476. { 0x120000, 0x4000 },
  3477. { 0x1a0000, 0x4000 },
  3478. { 0x160000, 0x4000 },
  3479. { 0xffffffff, 0 },
  3480. },
  3481. mem_tbl_5709[] = {
  3482. { 0x60000, 0x4000 },
  3483. { 0xa0000, 0x3000 },
  3484. { 0xe0000, 0x4000 },
  3485. { 0x120000, 0x4000 },
  3486. { 0x1a0000, 0x4000 },
  3487. { 0xffffffff, 0 },
  3488. };
  3489. struct mem_entry *mem_tbl;
  3490. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  3491. mem_tbl = mem_tbl_5709;
  3492. else
  3493. mem_tbl = mem_tbl_5706;
  3494. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  3495. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  3496. mem_tbl[i].len)) != 0) {
  3497. return ret;
  3498. }
  3499. }
  3500. return ret;
  3501. }
  3502. #define BNX2_MAC_LOOPBACK 0
  3503. #define BNX2_PHY_LOOPBACK 1
  3504. static int
  3505. bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
  3506. {
  3507. unsigned int pkt_size, num_pkts, i;
  3508. struct sk_buff *skb, *rx_skb;
  3509. unsigned char *packet;
  3510. u16 rx_start_idx, rx_idx;
  3511. dma_addr_t map;
  3512. struct tx_bd *txbd;
  3513. struct sw_bd *rx_buf;
  3514. struct l2_fhdr *rx_hdr;
  3515. int ret = -ENODEV;
  3516. if (loopback_mode == BNX2_MAC_LOOPBACK) {
  3517. bp->loopback = MAC_LOOPBACK;
  3518. bnx2_set_mac_loopback(bp);
  3519. }
  3520. else if (loopback_mode == BNX2_PHY_LOOPBACK) {
  3521. bp->loopback = PHY_LOOPBACK;
  3522. bnx2_set_phy_loopback(bp);
  3523. }
  3524. else
  3525. return -EINVAL;
  3526. pkt_size = 1514;
  3527. skb = netdev_alloc_skb(bp->dev, pkt_size);
  3528. if (!skb)
  3529. return -ENOMEM;
  3530. packet = skb_put(skb, pkt_size);
  3531. memcpy(packet, bp->dev->dev_addr, 6);
  3532. memset(packet + 6, 0x0, 8);
  3533. for (i = 14; i < pkt_size; i++)
  3534. packet[i] = (unsigned char) (i & 0xff);
  3535. map = pci_map_single(bp->pdev, skb->data, pkt_size,
  3536. PCI_DMA_TODEVICE);
  3537. REG_WR(bp, BNX2_HC_COMMAND,
  3538. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3539. REG_RD(bp, BNX2_HC_COMMAND);
  3540. udelay(5);
  3541. rx_start_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3542. num_pkts = 0;
  3543. txbd = &bp->tx_desc_ring[TX_RING_IDX(bp->tx_prod)];
  3544. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  3545. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  3546. txbd->tx_bd_mss_nbytes = pkt_size;
  3547. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  3548. num_pkts++;
  3549. bp->tx_prod = NEXT_TX_BD(bp->tx_prod);
  3550. bp->tx_prod_bseq += pkt_size;
  3551. REG_WR16(bp, bp->tx_bidx_addr, bp->tx_prod);
  3552. REG_WR(bp, bp->tx_bseq_addr, bp->tx_prod_bseq);
  3553. udelay(100);
  3554. REG_WR(bp, BNX2_HC_COMMAND,
  3555. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3556. REG_RD(bp, BNX2_HC_COMMAND);
  3557. udelay(5);
  3558. pci_unmap_single(bp->pdev, map, pkt_size, PCI_DMA_TODEVICE);
  3559. dev_kfree_skb(skb);
  3560. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->tx_prod) {
  3561. goto loopback_test_done;
  3562. }
  3563. rx_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3564. if (rx_idx != rx_start_idx + num_pkts) {
  3565. goto loopback_test_done;
  3566. }
  3567. rx_buf = &bp->rx_buf_ring[rx_start_idx];
  3568. rx_skb = rx_buf->skb;
  3569. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  3570. skb_reserve(rx_skb, bp->rx_offset);
  3571. pci_dma_sync_single_for_cpu(bp->pdev,
  3572. pci_unmap_addr(rx_buf, mapping),
  3573. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  3574. if (rx_hdr->l2_fhdr_status &
  3575. (L2_FHDR_ERRORS_BAD_CRC |
  3576. L2_FHDR_ERRORS_PHY_DECODE |
  3577. L2_FHDR_ERRORS_ALIGNMENT |
  3578. L2_FHDR_ERRORS_TOO_SHORT |
  3579. L2_FHDR_ERRORS_GIANT_FRAME)) {
  3580. goto loopback_test_done;
  3581. }
  3582. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  3583. goto loopback_test_done;
  3584. }
  3585. for (i = 14; i < pkt_size; i++) {
  3586. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  3587. goto loopback_test_done;
  3588. }
  3589. }
  3590. ret = 0;
  3591. loopback_test_done:
  3592. bp->loopback = 0;
  3593. return ret;
  3594. }
  3595. #define BNX2_MAC_LOOPBACK_FAILED 1
  3596. #define BNX2_PHY_LOOPBACK_FAILED 2
  3597. #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
  3598. BNX2_PHY_LOOPBACK_FAILED)
  3599. static int
  3600. bnx2_test_loopback(struct bnx2 *bp)
  3601. {
  3602. int rc = 0;
  3603. if (!netif_running(bp->dev))
  3604. return BNX2_LOOPBACK_FAILED;
  3605. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  3606. spin_lock_bh(&bp->phy_lock);
  3607. bnx2_init_phy(bp);
  3608. spin_unlock_bh(&bp->phy_lock);
  3609. if (bnx2_run_loopback(bp, BNX2_MAC_LOOPBACK))
  3610. rc |= BNX2_MAC_LOOPBACK_FAILED;
  3611. if (bnx2_run_loopback(bp, BNX2_PHY_LOOPBACK))
  3612. rc |= BNX2_PHY_LOOPBACK_FAILED;
  3613. return rc;
  3614. }
  3615. #define NVRAM_SIZE 0x200
  3616. #define CRC32_RESIDUAL 0xdebb20e3
  3617. static int
  3618. bnx2_test_nvram(struct bnx2 *bp)
  3619. {
  3620. u32 buf[NVRAM_SIZE / 4];
  3621. u8 *data = (u8 *) buf;
  3622. int rc = 0;
  3623. u32 magic, csum;
  3624. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  3625. goto test_nvram_done;
  3626. magic = be32_to_cpu(buf[0]);
  3627. if (magic != 0x669955aa) {
  3628. rc = -ENODEV;
  3629. goto test_nvram_done;
  3630. }
  3631. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  3632. goto test_nvram_done;
  3633. csum = ether_crc_le(0x100, data);
  3634. if (csum != CRC32_RESIDUAL) {
  3635. rc = -ENODEV;
  3636. goto test_nvram_done;
  3637. }
  3638. csum = ether_crc_le(0x100, data + 0x100);
  3639. if (csum != CRC32_RESIDUAL) {
  3640. rc = -ENODEV;
  3641. }
  3642. test_nvram_done:
  3643. return rc;
  3644. }
  3645. static int
  3646. bnx2_test_link(struct bnx2 *bp)
  3647. {
  3648. u32 bmsr;
  3649. spin_lock_bh(&bp->phy_lock);
  3650. bnx2_enable_bmsr1(bp);
  3651. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  3652. bnx2_read_phy(bp, bp->mii_bmsr1, &bmsr);
  3653. bnx2_disable_bmsr1(bp);
  3654. spin_unlock_bh(&bp->phy_lock);
  3655. if (bmsr & BMSR_LSTATUS) {
  3656. return 0;
  3657. }
  3658. return -ENODEV;
  3659. }
  3660. static int
  3661. bnx2_test_intr(struct bnx2 *bp)
  3662. {
  3663. int i;
  3664. u16 status_idx;
  3665. if (!netif_running(bp->dev))
  3666. return -ENODEV;
  3667. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  3668. /* This register is not touched during run-time. */
  3669. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  3670. REG_RD(bp, BNX2_HC_COMMAND);
  3671. for (i = 0; i < 10; i++) {
  3672. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  3673. status_idx) {
  3674. break;
  3675. }
  3676. msleep_interruptible(10);
  3677. }
  3678. if (i < 10)
  3679. return 0;
  3680. return -ENODEV;
  3681. }
  3682. static void
  3683. bnx2_5706_serdes_timer(struct bnx2 *bp)
  3684. {
  3685. spin_lock(&bp->phy_lock);
  3686. if (bp->serdes_an_pending)
  3687. bp->serdes_an_pending--;
  3688. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3689. u32 bmcr;
  3690. bp->current_interval = bp->timer_interval;
  3691. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  3692. if (bmcr & BMCR_ANENABLE) {
  3693. u32 phy1, phy2;
  3694. bnx2_write_phy(bp, 0x1c, 0x7c00);
  3695. bnx2_read_phy(bp, 0x1c, &phy1);
  3696. bnx2_write_phy(bp, 0x17, 0x0f01);
  3697. bnx2_read_phy(bp, 0x15, &phy2);
  3698. bnx2_write_phy(bp, 0x17, 0x0f01);
  3699. bnx2_read_phy(bp, 0x15, &phy2);
  3700. if ((phy1 & 0x10) && /* SIGNAL DETECT */
  3701. !(phy2 & 0x20)) { /* no CONFIG */
  3702. bmcr &= ~BMCR_ANENABLE;
  3703. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  3704. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  3705. bp->phy_flags |= PHY_PARALLEL_DETECT_FLAG;
  3706. }
  3707. }
  3708. }
  3709. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  3710. (bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)) {
  3711. u32 phy2;
  3712. bnx2_write_phy(bp, 0x17, 0x0f01);
  3713. bnx2_read_phy(bp, 0x15, &phy2);
  3714. if (phy2 & 0x20) {
  3715. u32 bmcr;
  3716. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  3717. bmcr |= BMCR_ANENABLE;
  3718. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  3719. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  3720. }
  3721. } else
  3722. bp->current_interval = bp->timer_interval;
  3723. spin_unlock(&bp->phy_lock);
  3724. }
  3725. static void
  3726. bnx2_5708_serdes_timer(struct bnx2 *bp)
  3727. {
  3728. if ((bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) == 0) {
  3729. bp->serdes_an_pending = 0;
  3730. return;
  3731. }
  3732. spin_lock(&bp->phy_lock);
  3733. if (bp->serdes_an_pending)
  3734. bp->serdes_an_pending--;
  3735. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3736. u32 bmcr;
  3737. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  3738. if (bmcr & BMCR_ANENABLE) {
  3739. bnx2_enable_forced_2g5(bp);
  3740. bp->current_interval = SERDES_FORCED_TIMEOUT;
  3741. } else {
  3742. bnx2_disable_forced_2g5(bp);
  3743. bp->serdes_an_pending = 2;
  3744. bp->current_interval = bp->timer_interval;
  3745. }
  3746. } else
  3747. bp->current_interval = bp->timer_interval;
  3748. spin_unlock(&bp->phy_lock);
  3749. }
  3750. static void
  3751. bnx2_timer(unsigned long data)
  3752. {
  3753. struct bnx2 *bp = (struct bnx2 *) data;
  3754. u32 msg;
  3755. if (!netif_running(bp->dev))
  3756. return;
  3757. if (atomic_read(&bp->intr_sem) != 0)
  3758. goto bnx2_restart_timer;
  3759. msg = (u32) ++bp->fw_drv_pulse_wr_seq;
  3760. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_PULSE_MB, msg);
  3761. bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT);
  3762. /* workaround occasional corrupted counters */
  3763. if (CHIP_NUM(bp) == CHIP_NUM_5708 && bp->stats_ticks)
  3764. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd |
  3765. BNX2_HC_COMMAND_STATS_NOW);
  3766. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3767. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3768. bnx2_5706_serdes_timer(bp);
  3769. else
  3770. bnx2_5708_serdes_timer(bp);
  3771. }
  3772. bnx2_restart_timer:
  3773. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3774. }
  3775. static int
  3776. bnx2_request_irq(struct bnx2 *bp)
  3777. {
  3778. struct net_device *dev = bp->dev;
  3779. int rc = 0;
  3780. if (bp->flags & USING_MSI_FLAG) {
  3781. irq_handler_t fn = bnx2_msi;
  3782. if (bp->flags & ONE_SHOT_MSI_FLAG)
  3783. fn = bnx2_msi_1shot;
  3784. rc = request_irq(bp->pdev->irq, fn, 0, dev->name, dev);
  3785. } else
  3786. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3787. IRQF_SHARED, dev->name, dev);
  3788. return rc;
  3789. }
  3790. static void
  3791. bnx2_free_irq(struct bnx2 *bp)
  3792. {
  3793. struct net_device *dev = bp->dev;
  3794. if (bp->flags & USING_MSI_FLAG) {
  3795. free_irq(bp->pdev->irq, dev);
  3796. pci_disable_msi(bp->pdev);
  3797. bp->flags &= ~(USING_MSI_FLAG | ONE_SHOT_MSI_FLAG);
  3798. } else
  3799. free_irq(bp->pdev->irq, dev);
  3800. }
  3801. /* Called with rtnl_lock */
  3802. static int
  3803. bnx2_open(struct net_device *dev)
  3804. {
  3805. struct bnx2 *bp = netdev_priv(dev);
  3806. int rc;
  3807. netif_carrier_off(dev);
  3808. bnx2_set_power_state(bp, PCI_D0);
  3809. bnx2_disable_int(bp);
  3810. rc = bnx2_alloc_mem(bp);
  3811. if (rc)
  3812. return rc;
  3813. if ((bp->flags & MSI_CAP_FLAG) && !disable_msi) {
  3814. if (pci_enable_msi(bp->pdev) == 0) {
  3815. bp->flags |= USING_MSI_FLAG;
  3816. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  3817. bp->flags |= ONE_SHOT_MSI_FLAG;
  3818. }
  3819. }
  3820. rc = bnx2_request_irq(bp);
  3821. if (rc) {
  3822. bnx2_free_mem(bp);
  3823. return rc;
  3824. }
  3825. rc = bnx2_init_nic(bp);
  3826. if (rc) {
  3827. bnx2_free_irq(bp);
  3828. bnx2_free_skbs(bp);
  3829. bnx2_free_mem(bp);
  3830. return rc;
  3831. }
  3832. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3833. atomic_set(&bp->intr_sem, 0);
  3834. bnx2_enable_int(bp);
  3835. if (bp->flags & USING_MSI_FLAG) {
  3836. /* Test MSI to make sure it is working
  3837. * If MSI test fails, go back to INTx mode
  3838. */
  3839. if (bnx2_test_intr(bp) != 0) {
  3840. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  3841. " using MSI, switching to INTx mode. Please"
  3842. " report this failure to the PCI maintainer"
  3843. " and include system chipset information.\n",
  3844. bp->dev->name);
  3845. bnx2_disable_int(bp);
  3846. bnx2_free_irq(bp);
  3847. rc = bnx2_init_nic(bp);
  3848. if (!rc)
  3849. rc = bnx2_request_irq(bp);
  3850. if (rc) {
  3851. bnx2_free_skbs(bp);
  3852. bnx2_free_mem(bp);
  3853. del_timer_sync(&bp->timer);
  3854. return rc;
  3855. }
  3856. bnx2_enable_int(bp);
  3857. }
  3858. }
  3859. if (bp->flags & USING_MSI_FLAG) {
  3860. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  3861. }
  3862. netif_start_queue(dev);
  3863. return 0;
  3864. }
  3865. static void
  3866. bnx2_reset_task(struct work_struct *work)
  3867. {
  3868. struct bnx2 *bp = container_of(work, struct bnx2, reset_task);
  3869. if (!netif_running(bp->dev))
  3870. return;
  3871. bp->in_reset_task = 1;
  3872. bnx2_netif_stop(bp);
  3873. bnx2_init_nic(bp);
  3874. atomic_set(&bp->intr_sem, 1);
  3875. bnx2_netif_start(bp);
  3876. bp->in_reset_task = 0;
  3877. }
  3878. static void
  3879. bnx2_tx_timeout(struct net_device *dev)
  3880. {
  3881. struct bnx2 *bp = netdev_priv(dev);
  3882. /* This allows the netif to be shutdown gracefully before resetting */
  3883. schedule_work(&bp->reset_task);
  3884. }
  3885. #ifdef BCM_VLAN
  3886. /* Called with rtnl_lock */
  3887. static void
  3888. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  3889. {
  3890. struct bnx2 *bp = netdev_priv(dev);
  3891. bnx2_netif_stop(bp);
  3892. bp->vlgrp = vlgrp;
  3893. bnx2_set_rx_mode(dev);
  3894. bnx2_netif_start(bp);
  3895. }
  3896. #endif
  3897. /* Called with netif_tx_lock.
  3898. * bnx2_tx_int() runs without netif_tx_lock unless it needs to call
  3899. * netif_wake_queue().
  3900. */
  3901. static int
  3902. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3903. {
  3904. struct bnx2 *bp = netdev_priv(dev);
  3905. dma_addr_t mapping;
  3906. struct tx_bd *txbd;
  3907. struct sw_bd *tx_buf;
  3908. u32 len, vlan_tag_flags, last_frag, mss;
  3909. u16 prod, ring_prod;
  3910. int i;
  3911. if (unlikely(bnx2_tx_avail(bp) < (skb_shinfo(skb)->nr_frags + 1))) {
  3912. netif_stop_queue(dev);
  3913. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  3914. dev->name);
  3915. return NETDEV_TX_BUSY;
  3916. }
  3917. len = skb_headlen(skb);
  3918. prod = bp->tx_prod;
  3919. ring_prod = TX_RING_IDX(prod);
  3920. vlan_tag_flags = 0;
  3921. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  3922. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  3923. }
  3924. if (bp->vlgrp != 0 && vlan_tx_tag_present(skb)) {
  3925. vlan_tag_flags |=
  3926. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  3927. }
  3928. if ((mss = skb_shinfo(skb)->gso_size)) {
  3929. u32 tcp_opt_len, ip_tcp_len;
  3930. struct iphdr *iph;
  3931. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  3932. tcp_opt_len = tcp_optlen(skb);
  3933. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) {
  3934. u32 tcp_off = skb_transport_offset(skb) -
  3935. sizeof(struct ipv6hdr) - ETH_HLEN;
  3936. vlan_tag_flags |= ((tcp_opt_len >> 2) << 8) |
  3937. TX_BD_FLAGS_SW_FLAGS;
  3938. if (likely(tcp_off == 0))
  3939. vlan_tag_flags &= ~TX_BD_FLAGS_TCP6_OFF0_MSK;
  3940. else {
  3941. tcp_off >>= 3;
  3942. vlan_tag_flags |= ((tcp_off & 0x3) <<
  3943. TX_BD_FLAGS_TCP6_OFF0_SHL) |
  3944. ((tcp_off & 0x10) <<
  3945. TX_BD_FLAGS_TCP6_OFF4_SHL);
  3946. mss |= (tcp_off & 0xc) << TX_BD_TCP6_OFF2_SHL;
  3947. }
  3948. } else {
  3949. if (skb_header_cloned(skb) &&
  3950. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3951. dev_kfree_skb(skb);
  3952. return NETDEV_TX_OK;
  3953. }
  3954. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3955. iph = ip_hdr(skb);
  3956. iph->check = 0;
  3957. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3958. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3959. iph->daddr, 0,
  3960. IPPROTO_TCP,
  3961. 0);
  3962. if (tcp_opt_len || (iph->ihl > 5)) {
  3963. vlan_tag_flags |= ((iph->ihl - 5) +
  3964. (tcp_opt_len >> 2)) << 8;
  3965. }
  3966. }
  3967. } else
  3968. mss = 0;
  3969. mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3970. tx_buf = &bp->tx_buf_ring[ring_prod];
  3971. tx_buf->skb = skb;
  3972. pci_unmap_addr_set(tx_buf, mapping, mapping);
  3973. txbd = &bp->tx_desc_ring[ring_prod];
  3974. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3975. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3976. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3977. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  3978. last_frag = skb_shinfo(skb)->nr_frags;
  3979. for (i = 0; i < last_frag; i++) {
  3980. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3981. prod = NEXT_TX_BD(prod);
  3982. ring_prod = TX_RING_IDX(prod);
  3983. txbd = &bp->tx_desc_ring[ring_prod];
  3984. len = frag->size;
  3985. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  3986. len, PCI_DMA_TODEVICE);
  3987. pci_unmap_addr_set(&bp->tx_buf_ring[ring_prod],
  3988. mapping, mapping);
  3989. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3990. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3991. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3992. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  3993. }
  3994. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  3995. prod = NEXT_TX_BD(prod);
  3996. bp->tx_prod_bseq += skb->len;
  3997. REG_WR16(bp, bp->tx_bidx_addr, prod);
  3998. REG_WR(bp, bp->tx_bseq_addr, bp->tx_prod_bseq);
  3999. mmiowb();
  4000. bp->tx_prod = prod;
  4001. dev->trans_start = jiffies;
  4002. if (unlikely(bnx2_tx_avail(bp) <= MAX_SKB_FRAGS)) {
  4003. netif_stop_queue(dev);
  4004. if (bnx2_tx_avail(bp) > bp->tx_wake_thresh)
  4005. netif_wake_queue(dev);
  4006. }
  4007. return NETDEV_TX_OK;
  4008. }
  4009. /* Called with rtnl_lock */
  4010. static int
  4011. bnx2_close(struct net_device *dev)
  4012. {
  4013. struct bnx2 *bp = netdev_priv(dev);
  4014. u32 reset_code;
  4015. /* Calling flush_scheduled_work() may deadlock because
  4016. * linkwatch_event() may be on the workqueue and it will try to get
  4017. * the rtnl_lock which we are holding.
  4018. */
  4019. while (bp->in_reset_task)
  4020. msleep(1);
  4021. bnx2_netif_stop(bp);
  4022. del_timer_sync(&bp->timer);
  4023. if (bp->flags & NO_WOL_FLAG)
  4024. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  4025. else if (bp->wol)
  4026. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4027. else
  4028. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4029. bnx2_reset_chip(bp, reset_code);
  4030. bnx2_free_irq(bp);
  4031. bnx2_free_skbs(bp);
  4032. bnx2_free_mem(bp);
  4033. bp->link_up = 0;
  4034. netif_carrier_off(bp->dev);
  4035. bnx2_set_power_state(bp, PCI_D3hot);
  4036. return 0;
  4037. }
  4038. #define GET_NET_STATS64(ctr) \
  4039. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  4040. (unsigned long) (ctr##_lo)
  4041. #define GET_NET_STATS32(ctr) \
  4042. (ctr##_lo)
  4043. #if (BITS_PER_LONG == 64)
  4044. #define GET_NET_STATS GET_NET_STATS64
  4045. #else
  4046. #define GET_NET_STATS GET_NET_STATS32
  4047. #endif
  4048. static struct net_device_stats *
  4049. bnx2_get_stats(struct net_device *dev)
  4050. {
  4051. struct bnx2 *bp = netdev_priv(dev);
  4052. struct statistics_block *stats_blk = bp->stats_blk;
  4053. struct net_device_stats *net_stats = &bp->net_stats;
  4054. if (bp->stats_blk == NULL) {
  4055. return net_stats;
  4056. }
  4057. net_stats->rx_packets =
  4058. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  4059. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  4060. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  4061. net_stats->tx_packets =
  4062. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  4063. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  4064. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  4065. net_stats->rx_bytes =
  4066. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  4067. net_stats->tx_bytes =
  4068. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  4069. net_stats->multicast =
  4070. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  4071. net_stats->collisions =
  4072. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  4073. net_stats->rx_length_errors =
  4074. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  4075. stats_blk->stat_EtherStatsOverrsizePkts);
  4076. net_stats->rx_over_errors =
  4077. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  4078. net_stats->rx_frame_errors =
  4079. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  4080. net_stats->rx_crc_errors =
  4081. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  4082. net_stats->rx_errors = net_stats->rx_length_errors +
  4083. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  4084. net_stats->rx_crc_errors;
  4085. net_stats->tx_aborted_errors =
  4086. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  4087. stats_blk->stat_Dot3StatsLateCollisions);
  4088. if ((CHIP_NUM(bp) == CHIP_NUM_5706) ||
  4089. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  4090. net_stats->tx_carrier_errors = 0;
  4091. else {
  4092. net_stats->tx_carrier_errors =
  4093. (unsigned long)
  4094. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  4095. }
  4096. net_stats->tx_errors =
  4097. (unsigned long)
  4098. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  4099. +
  4100. net_stats->tx_aborted_errors +
  4101. net_stats->tx_carrier_errors;
  4102. net_stats->rx_missed_errors =
  4103. (unsigned long) (stats_blk->stat_IfInMBUFDiscards +
  4104. stats_blk->stat_FwRxDrop);
  4105. return net_stats;
  4106. }
  4107. /* All ethtool functions called with rtnl_lock */
  4108. static int
  4109. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  4110. {
  4111. struct bnx2 *bp = netdev_priv(dev);
  4112. cmd->supported = SUPPORTED_Autoneg;
  4113. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4114. cmd->supported |= SUPPORTED_1000baseT_Full |
  4115. SUPPORTED_FIBRE;
  4116. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)
  4117. cmd->supported |= SUPPORTED_2500baseX_Full;
  4118. cmd->port = PORT_FIBRE;
  4119. }
  4120. else {
  4121. cmd->supported |= SUPPORTED_10baseT_Half |
  4122. SUPPORTED_10baseT_Full |
  4123. SUPPORTED_100baseT_Half |
  4124. SUPPORTED_100baseT_Full |
  4125. SUPPORTED_1000baseT_Full |
  4126. SUPPORTED_TP;
  4127. cmd->port = PORT_TP;
  4128. }
  4129. cmd->advertising = bp->advertising;
  4130. if (bp->autoneg & AUTONEG_SPEED) {
  4131. cmd->autoneg = AUTONEG_ENABLE;
  4132. }
  4133. else {
  4134. cmd->autoneg = AUTONEG_DISABLE;
  4135. }
  4136. if (netif_carrier_ok(dev)) {
  4137. cmd->speed = bp->line_speed;
  4138. cmd->duplex = bp->duplex;
  4139. }
  4140. else {
  4141. cmd->speed = -1;
  4142. cmd->duplex = -1;
  4143. }
  4144. cmd->transceiver = XCVR_INTERNAL;
  4145. cmd->phy_address = bp->phy_addr;
  4146. return 0;
  4147. }
  4148. static int
  4149. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  4150. {
  4151. struct bnx2 *bp = netdev_priv(dev);
  4152. u8 autoneg = bp->autoneg;
  4153. u8 req_duplex = bp->req_duplex;
  4154. u16 req_line_speed = bp->req_line_speed;
  4155. u32 advertising = bp->advertising;
  4156. if (cmd->autoneg == AUTONEG_ENABLE) {
  4157. autoneg |= AUTONEG_SPEED;
  4158. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  4159. /* allow advertising 1 speed */
  4160. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  4161. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  4162. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  4163. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  4164. if (bp->phy_flags & PHY_SERDES_FLAG)
  4165. return -EINVAL;
  4166. advertising = cmd->advertising;
  4167. } else if (cmd->advertising == ADVERTISED_2500baseX_Full) {
  4168. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  4169. return -EINVAL;
  4170. } else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
  4171. advertising = cmd->advertising;
  4172. }
  4173. else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
  4174. return -EINVAL;
  4175. }
  4176. else {
  4177. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4178. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  4179. }
  4180. else {
  4181. advertising = ETHTOOL_ALL_COPPER_SPEED;
  4182. }
  4183. }
  4184. advertising |= ADVERTISED_Autoneg;
  4185. }
  4186. else {
  4187. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4188. if ((cmd->speed != SPEED_1000 &&
  4189. cmd->speed != SPEED_2500) ||
  4190. (cmd->duplex != DUPLEX_FULL))
  4191. return -EINVAL;
  4192. if (cmd->speed == SPEED_2500 &&
  4193. !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  4194. return -EINVAL;
  4195. }
  4196. else if (cmd->speed == SPEED_1000) {
  4197. return -EINVAL;
  4198. }
  4199. autoneg &= ~AUTONEG_SPEED;
  4200. req_line_speed = cmd->speed;
  4201. req_duplex = cmd->duplex;
  4202. advertising = 0;
  4203. }
  4204. bp->autoneg = autoneg;
  4205. bp->advertising = advertising;
  4206. bp->req_line_speed = req_line_speed;
  4207. bp->req_duplex = req_duplex;
  4208. spin_lock_bh(&bp->phy_lock);
  4209. bnx2_setup_phy(bp);
  4210. spin_unlock_bh(&bp->phy_lock);
  4211. return 0;
  4212. }
  4213. static void
  4214. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  4215. {
  4216. struct bnx2 *bp = netdev_priv(dev);
  4217. strcpy(info->driver, DRV_MODULE_NAME);
  4218. strcpy(info->version, DRV_MODULE_VERSION);
  4219. strcpy(info->bus_info, pci_name(bp->pdev));
  4220. info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
  4221. info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
  4222. info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
  4223. info->fw_version[1] = info->fw_version[3] = '.';
  4224. info->fw_version[5] = 0;
  4225. }
  4226. #define BNX2_REGDUMP_LEN (32 * 1024)
  4227. static int
  4228. bnx2_get_regs_len(struct net_device *dev)
  4229. {
  4230. return BNX2_REGDUMP_LEN;
  4231. }
  4232. static void
  4233. bnx2_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
  4234. {
  4235. u32 *p = _p, i, offset;
  4236. u8 *orig_p = _p;
  4237. struct bnx2 *bp = netdev_priv(dev);
  4238. u32 reg_boundaries[] = { 0x0000, 0x0098, 0x0400, 0x045c,
  4239. 0x0800, 0x0880, 0x0c00, 0x0c10,
  4240. 0x0c30, 0x0d08, 0x1000, 0x101c,
  4241. 0x1040, 0x1048, 0x1080, 0x10a4,
  4242. 0x1400, 0x1490, 0x1498, 0x14f0,
  4243. 0x1500, 0x155c, 0x1580, 0x15dc,
  4244. 0x1600, 0x1658, 0x1680, 0x16d8,
  4245. 0x1800, 0x1820, 0x1840, 0x1854,
  4246. 0x1880, 0x1894, 0x1900, 0x1984,
  4247. 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
  4248. 0x1c80, 0x1c94, 0x1d00, 0x1d84,
  4249. 0x2000, 0x2030, 0x23c0, 0x2400,
  4250. 0x2800, 0x2820, 0x2830, 0x2850,
  4251. 0x2b40, 0x2c10, 0x2fc0, 0x3058,
  4252. 0x3c00, 0x3c94, 0x4000, 0x4010,
  4253. 0x4080, 0x4090, 0x43c0, 0x4458,
  4254. 0x4c00, 0x4c18, 0x4c40, 0x4c54,
  4255. 0x4fc0, 0x5010, 0x53c0, 0x5444,
  4256. 0x5c00, 0x5c18, 0x5c80, 0x5c90,
  4257. 0x5fc0, 0x6000, 0x6400, 0x6428,
  4258. 0x6800, 0x6848, 0x684c, 0x6860,
  4259. 0x6888, 0x6910, 0x8000 };
  4260. regs->version = 0;
  4261. memset(p, 0, BNX2_REGDUMP_LEN);
  4262. if (!netif_running(bp->dev))
  4263. return;
  4264. i = 0;
  4265. offset = reg_boundaries[0];
  4266. p += offset;
  4267. while (offset < BNX2_REGDUMP_LEN) {
  4268. *p++ = REG_RD(bp, offset);
  4269. offset += 4;
  4270. if (offset == reg_boundaries[i + 1]) {
  4271. offset = reg_boundaries[i + 2];
  4272. p = (u32 *) (orig_p + offset);
  4273. i += 2;
  4274. }
  4275. }
  4276. }
  4277. static void
  4278. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  4279. {
  4280. struct bnx2 *bp = netdev_priv(dev);
  4281. if (bp->flags & NO_WOL_FLAG) {
  4282. wol->supported = 0;
  4283. wol->wolopts = 0;
  4284. }
  4285. else {
  4286. wol->supported = WAKE_MAGIC;
  4287. if (bp->wol)
  4288. wol->wolopts = WAKE_MAGIC;
  4289. else
  4290. wol->wolopts = 0;
  4291. }
  4292. memset(&wol->sopass, 0, sizeof(wol->sopass));
  4293. }
  4294. static int
  4295. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  4296. {
  4297. struct bnx2 *bp = netdev_priv(dev);
  4298. if (wol->wolopts & ~WAKE_MAGIC)
  4299. return -EINVAL;
  4300. if (wol->wolopts & WAKE_MAGIC) {
  4301. if (bp->flags & NO_WOL_FLAG)
  4302. return -EINVAL;
  4303. bp->wol = 1;
  4304. }
  4305. else {
  4306. bp->wol = 0;
  4307. }
  4308. return 0;
  4309. }
  4310. static int
  4311. bnx2_nway_reset(struct net_device *dev)
  4312. {
  4313. struct bnx2 *bp = netdev_priv(dev);
  4314. u32 bmcr;
  4315. if (!(bp->autoneg & AUTONEG_SPEED)) {
  4316. return -EINVAL;
  4317. }
  4318. spin_lock_bh(&bp->phy_lock);
  4319. /* Force a link down visible on the other side */
  4320. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4321. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  4322. spin_unlock_bh(&bp->phy_lock);
  4323. msleep(20);
  4324. spin_lock_bh(&bp->phy_lock);
  4325. bp->current_interval = SERDES_AN_TIMEOUT;
  4326. bp->serdes_an_pending = 1;
  4327. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4328. }
  4329. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4330. bmcr &= ~BMCR_LOOPBACK;
  4331. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  4332. spin_unlock_bh(&bp->phy_lock);
  4333. return 0;
  4334. }
  4335. static int
  4336. bnx2_get_eeprom_len(struct net_device *dev)
  4337. {
  4338. struct bnx2 *bp = netdev_priv(dev);
  4339. if (bp->flash_info == NULL)
  4340. return 0;
  4341. return (int) bp->flash_size;
  4342. }
  4343. static int
  4344. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  4345. u8 *eebuf)
  4346. {
  4347. struct bnx2 *bp = netdev_priv(dev);
  4348. int rc;
  4349. /* parameters already validated in ethtool_get_eeprom */
  4350. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  4351. return rc;
  4352. }
  4353. static int
  4354. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  4355. u8 *eebuf)
  4356. {
  4357. struct bnx2 *bp = netdev_priv(dev);
  4358. int rc;
  4359. /* parameters already validated in ethtool_set_eeprom */
  4360. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  4361. return rc;
  4362. }
  4363. static int
  4364. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4365. {
  4366. struct bnx2 *bp = netdev_priv(dev);
  4367. memset(coal, 0, sizeof(struct ethtool_coalesce));
  4368. coal->rx_coalesce_usecs = bp->rx_ticks;
  4369. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  4370. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  4371. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  4372. coal->tx_coalesce_usecs = bp->tx_ticks;
  4373. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  4374. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  4375. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  4376. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  4377. return 0;
  4378. }
  4379. static int
  4380. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4381. {
  4382. struct bnx2 *bp = netdev_priv(dev);
  4383. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  4384. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  4385. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  4386. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  4387. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  4388. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  4389. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  4390. if (bp->rx_quick_cons_trip_int > 0xff)
  4391. bp->rx_quick_cons_trip_int = 0xff;
  4392. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  4393. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  4394. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  4395. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  4396. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  4397. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  4398. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  4399. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  4400. 0xff;
  4401. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  4402. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  4403. if (bp->stats_ticks != 0 && bp->stats_ticks != USEC_PER_SEC)
  4404. bp->stats_ticks = USEC_PER_SEC;
  4405. }
  4406. if (bp->stats_ticks > 0xffff00) bp->stats_ticks = 0xffff00;
  4407. bp->stats_ticks &= 0xffff00;
  4408. if (netif_running(bp->dev)) {
  4409. bnx2_netif_stop(bp);
  4410. bnx2_init_nic(bp);
  4411. bnx2_netif_start(bp);
  4412. }
  4413. return 0;
  4414. }
  4415. static void
  4416. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4417. {
  4418. struct bnx2 *bp = netdev_priv(dev);
  4419. ering->rx_max_pending = MAX_TOTAL_RX_DESC_CNT;
  4420. ering->rx_mini_max_pending = 0;
  4421. ering->rx_jumbo_max_pending = 0;
  4422. ering->rx_pending = bp->rx_ring_size;
  4423. ering->rx_mini_pending = 0;
  4424. ering->rx_jumbo_pending = 0;
  4425. ering->tx_max_pending = MAX_TX_DESC_CNT;
  4426. ering->tx_pending = bp->tx_ring_size;
  4427. }
  4428. static int
  4429. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4430. {
  4431. struct bnx2 *bp = netdev_priv(dev);
  4432. if ((ering->rx_pending > MAX_TOTAL_RX_DESC_CNT) ||
  4433. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  4434. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  4435. return -EINVAL;
  4436. }
  4437. if (netif_running(bp->dev)) {
  4438. bnx2_netif_stop(bp);
  4439. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  4440. bnx2_free_skbs(bp);
  4441. bnx2_free_mem(bp);
  4442. }
  4443. bnx2_set_rx_ring_size(bp, ering->rx_pending);
  4444. bp->tx_ring_size = ering->tx_pending;
  4445. if (netif_running(bp->dev)) {
  4446. int rc;
  4447. rc = bnx2_alloc_mem(bp);
  4448. if (rc)
  4449. return rc;
  4450. bnx2_init_nic(bp);
  4451. bnx2_netif_start(bp);
  4452. }
  4453. return 0;
  4454. }
  4455. static void
  4456. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4457. {
  4458. struct bnx2 *bp = netdev_priv(dev);
  4459. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  4460. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  4461. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  4462. }
  4463. static int
  4464. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4465. {
  4466. struct bnx2 *bp = netdev_priv(dev);
  4467. bp->req_flow_ctrl = 0;
  4468. if (epause->rx_pause)
  4469. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  4470. if (epause->tx_pause)
  4471. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  4472. if (epause->autoneg) {
  4473. bp->autoneg |= AUTONEG_FLOW_CTRL;
  4474. }
  4475. else {
  4476. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  4477. }
  4478. spin_lock_bh(&bp->phy_lock);
  4479. bnx2_setup_phy(bp);
  4480. spin_unlock_bh(&bp->phy_lock);
  4481. return 0;
  4482. }
  4483. static u32
  4484. bnx2_get_rx_csum(struct net_device *dev)
  4485. {
  4486. struct bnx2 *bp = netdev_priv(dev);
  4487. return bp->rx_csum;
  4488. }
  4489. static int
  4490. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  4491. {
  4492. struct bnx2 *bp = netdev_priv(dev);
  4493. bp->rx_csum = data;
  4494. return 0;
  4495. }
  4496. static int
  4497. bnx2_set_tso(struct net_device *dev, u32 data)
  4498. {
  4499. struct bnx2 *bp = netdev_priv(dev);
  4500. if (data) {
  4501. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  4502. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4503. dev->features |= NETIF_F_TSO6;
  4504. } else
  4505. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6 |
  4506. NETIF_F_TSO_ECN);
  4507. return 0;
  4508. }
  4509. #define BNX2_NUM_STATS 46
  4510. static struct {
  4511. char string[ETH_GSTRING_LEN];
  4512. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  4513. { "rx_bytes" },
  4514. { "rx_error_bytes" },
  4515. { "tx_bytes" },
  4516. { "tx_error_bytes" },
  4517. { "rx_ucast_packets" },
  4518. { "rx_mcast_packets" },
  4519. { "rx_bcast_packets" },
  4520. { "tx_ucast_packets" },
  4521. { "tx_mcast_packets" },
  4522. { "tx_bcast_packets" },
  4523. { "tx_mac_errors" },
  4524. { "tx_carrier_errors" },
  4525. { "rx_crc_errors" },
  4526. { "rx_align_errors" },
  4527. { "tx_single_collisions" },
  4528. { "tx_multi_collisions" },
  4529. { "tx_deferred" },
  4530. { "tx_excess_collisions" },
  4531. { "tx_late_collisions" },
  4532. { "tx_total_collisions" },
  4533. { "rx_fragments" },
  4534. { "rx_jabbers" },
  4535. { "rx_undersize_packets" },
  4536. { "rx_oversize_packets" },
  4537. { "rx_64_byte_packets" },
  4538. { "rx_65_to_127_byte_packets" },
  4539. { "rx_128_to_255_byte_packets" },
  4540. { "rx_256_to_511_byte_packets" },
  4541. { "rx_512_to_1023_byte_packets" },
  4542. { "rx_1024_to_1522_byte_packets" },
  4543. { "rx_1523_to_9022_byte_packets" },
  4544. { "tx_64_byte_packets" },
  4545. { "tx_65_to_127_byte_packets" },
  4546. { "tx_128_to_255_byte_packets" },
  4547. { "tx_256_to_511_byte_packets" },
  4548. { "tx_512_to_1023_byte_packets" },
  4549. { "tx_1024_to_1522_byte_packets" },
  4550. { "tx_1523_to_9022_byte_packets" },
  4551. { "rx_xon_frames" },
  4552. { "rx_xoff_frames" },
  4553. { "tx_xon_frames" },
  4554. { "tx_xoff_frames" },
  4555. { "rx_mac_ctrl_frames" },
  4556. { "rx_filtered_packets" },
  4557. { "rx_discards" },
  4558. { "rx_fw_discards" },
  4559. };
  4560. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  4561. static const unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  4562. STATS_OFFSET32(stat_IfHCInOctets_hi),
  4563. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  4564. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  4565. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  4566. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  4567. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  4568. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  4569. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  4570. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  4571. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  4572. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  4573. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  4574. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  4575. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  4576. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  4577. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  4578. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  4579. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  4580. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  4581. STATS_OFFSET32(stat_EtherStatsCollisions),
  4582. STATS_OFFSET32(stat_EtherStatsFragments),
  4583. STATS_OFFSET32(stat_EtherStatsJabbers),
  4584. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  4585. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  4586. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  4587. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  4588. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  4589. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  4590. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  4591. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  4592. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  4593. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  4594. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  4595. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  4596. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  4597. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  4598. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  4599. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  4600. STATS_OFFSET32(stat_XonPauseFramesReceived),
  4601. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  4602. STATS_OFFSET32(stat_OutXonSent),
  4603. STATS_OFFSET32(stat_OutXoffSent),
  4604. STATS_OFFSET32(stat_MacControlFramesReceived),
  4605. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  4606. STATS_OFFSET32(stat_IfInMBUFDiscards),
  4607. STATS_OFFSET32(stat_FwRxDrop),
  4608. };
  4609. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  4610. * skipped because of errata.
  4611. */
  4612. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  4613. 8,0,8,8,8,8,8,8,8,8,
  4614. 4,0,4,4,4,4,4,4,4,4,
  4615. 4,4,4,4,4,4,4,4,4,4,
  4616. 4,4,4,4,4,4,4,4,4,4,
  4617. 4,4,4,4,4,4,
  4618. };
  4619. static u8 bnx2_5708_stats_len_arr[BNX2_NUM_STATS] = {
  4620. 8,0,8,8,8,8,8,8,8,8,
  4621. 4,4,4,4,4,4,4,4,4,4,
  4622. 4,4,4,4,4,4,4,4,4,4,
  4623. 4,4,4,4,4,4,4,4,4,4,
  4624. 4,4,4,4,4,4,
  4625. };
  4626. #define BNX2_NUM_TESTS 6
  4627. static struct {
  4628. char string[ETH_GSTRING_LEN];
  4629. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  4630. { "register_test (offline)" },
  4631. { "memory_test (offline)" },
  4632. { "loopback_test (offline)" },
  4633. { "nvram_test (online)" },
  4634. { "interrupt_test (online)" },
  4635. { "link_test (online)" },
  4636. };
  4637. static int
  4638. bnx2_self_test_count(struct net_device *dev)
  4639. {
  4640. return BNX2_NUM_TESTS;
  4641. }
  4642. static void
  4643. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  4644. {
  4645. struct bnx2 *bp = netdev_priv(dev);
  4646. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  4647. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  4648. int i;
  4649. bnx2_netif_stop(bp);
  4650. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  4651. bnx2_free_skbs(bp);
  4652. if (bnx2_test_registers(bp) != 0) {
  4653. buf[0] = 1;
  4654. etest->flags |= ETH_TEST_FL_FAILED;
  4655. }
  4656. if (bnx2_test_memory(bp) != 0) {
  4657. buf[1] = 1;
  4658. etest->flags |= ETH_TEST_FL_FAILED;
  4659. }
  4660. if ((buf[2] = bnx2_test_loopback(bp)) != 0)
  4661. etest->flags |= ETH_TEST_FL_FAILED;
  4662. if (!netif_running(bp->dev)) {
  4663. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  4664. }
  4665. else {
  4666. bnx2_init_nic(bp);
  4667. bnx2_netif_start(bp);
  4668. }
  4669. /* wait for link up */
  4670. for (i = 0; i < 7; i++) {
  4671. if (bp->link_up)
  4672. break;
  4673. msleep_interruptible(1000);
  4674. }
  4675. }
  4676. if (bnx2_test_nvram(bp) != 0) {
  4677. buf[3] = 1;
  4678. etest->flags |= ETH_TEST_FL_FAILED;
  4679. }
  4680. if (bnx2_test_intr(bp) != 0) {
  4681. buf[4] = 1;
  4682. etest->flags |= ETH_TEST_FL_FAILED;
  4683. }
  4684. if (bnx2_test_link(bp) != 0) {
  4685. buf[5] = 1;
  4686. etest->flags |= ETH_TEST_FL_FAILED;
  4687. }
  4688. }
  4689. static void
  4690. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  4691. {
  4692. switch (stringset) {
  4693. case ETH_SS_STATS:
  4694. memcpy(buf, bnx2_stats_str_arr,
  4695. sizeof(bnx2_stats_str_arr));
  4696. break;
  4697. case ETH_SS_TEST:
  4698. memcpy(buf, bnx2_tests_str_arr,
  4699. sizeof(bnx2_tests_str_arr));
  4700. break;
  4701. }
  4702. }
  4703. static int
  4704. bnx2_get_stats_count(struct net_device *dev)
  4705. {
  4706. return BNX2_NUM_STATS;
  4707. }
  4708. static void
  4709. bnx2_get_ethtool_stats(struct net_device *dev,
  4710. struct ethtool_stats *stats, u64 *buf)
  4711. {
  4712. struct bnx2 *bp = netdev_priv(dev);
  4713. int i;
  4714. u32 *hw_stats = (u32 *) bp->stats_blk;
  4715. u8 *stats_len_arr = NULL;
  4716. if (hw_stats == NULL) {
  4717. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  4718. return;
  4719. }
  4720. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  4721. (CHIP_ID(bp) == CHIP_ID_5706_A1) ||
  4722. (CHIP_ID(bp) == CHIP_ID_5706_A2) ||
  4723. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  4724. stats_len_arr = bnx2_5706_stats_len_arr;
  4725. else
  4726. stats_len_arr = bnx2_5708_stats_len_arr;
  4727. for (i = 0; i < BNX2_NUM_STATS; i++) {
  4728. if (stats_len_arr[i] == 0) {
  4729. /* skip this counter */
  4730. buf[i] = 0;
  4731. continue;
  4732. }
  4733. if (stats_len_arr[i] == 4) {
  4734. /* 4-byte counter */
  4735. buf[i] = (u64)
  4736. *(hw_stats + bnx2_stats_offset_arr[i]);
  4737. continue;
  4738. }
  4739. /* 8-byte counter */
  4740. buf[i] = (((u64) *(hw_stats +
  4741. bnx2_stats_offset_arr[i])) << 32) +
  4742. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  4743. }
  4744. }
  4745. static int
  4746. bnx2_phys_id(struct net_device *dev, u32 data)
  4747. {
  4748. struct bnx2 *bp = netdev_priv(dev);
  4749. int i;
  4750. u32 save;
  4751. if (data == 0)
  4752. data = 2;
  4753. save = REG_RD(bp, BNX2_MISC_CFG);
  4754. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  4755. for (i = 0; i < (data * 2); i++) {
  4756. if ((i % 2) == 0) {
  4757. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  4758. }
  4759. else {
  4760. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  4761. BNX2_EMAC_LED_1000MB_OVERRIDE |
  4762. BNX2_EMAC_LED_100MB_OVERRIDE |
  4763. BNX2_EMAC_LED_10MB_OVERRIDE |
  4764. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  4765. BNX2_EMAC_LED_TRAFFIC);
  4766. }
  4767. msleep_interruptible(500);
  4768. if (signal_pending(current))
  4769. break;
  4770. }
  4771. REG_WR(bp, BNX2_EMAC_LED, 0);
  4772. REG_WR(bp, BNX2_MISC_CFG, save);
  4773. return 0;
  4774. }
  4775. static int
  4776. bnx2_set_tx_csum(struct net_device *dev, u32 data)
  4777. {
  4778. struct bnx2 *bp = netdev_priv(dev);
  4779. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4780. return (ethtool_op_set_tx_hw_csum(dev, data));
  4781. else
  4782. return (ethtool_op_set_tx_csum(dev, data));
  4783. }
  4784. static const struct ethtool_ops bnx2_ethtool_ops = {
  4785. .get_settings = bnx2_get_settings,
  4786. .set_settings = bnx2_set_settings,
  4787. .get_drvinfo = bnx2_get_drvinfo,
  4788. .get_regs_len = bnx2_get_regs_len,
  4789. .get_regs = bnx2_get_regs,
  4790. .get_wol = bnx2_get_wol,
  4791. .set_wol = bnx2_set_wol,
  4792. .nway_reset = bnx2_nway_reset,
  4793. .get_link = ethtool_op_get_link,
  4794. .get_eeprom_len = bnx2_get_eeprom_len,
  4795. .get_eeprom = bnx2_get_eeprom,
  4796. .set_eeprom = bnx2_set_eeprom,
  4797. .get_coalesce = bnx2_get_coalesce,
  4798. .set_coalesce = bnx2_set_coalesce,
  4799. .get_ringparam = bnx2_get_ringparam,
  4800. .set_ringparam = bnx2_set_ringparam,
  4801. .get_pauseparam = bnx2_get_pauseparam,
  4802. .set_pauseparam = bnx2_set_pauseparam,
  4803. .get_rx_csum = bnx2_get_rx_csum,
  4804. .set_rx_csum = bnx2_set_rx_csum,
  4805. .get_tx_csum = ethtool_op_get_tx_csum,
  4806. .set_tx_csum = bnx2_set_tx_csum,
  4807. .get_sg = ethtool_op_get_sg,
  4808. .set_sg = ethtool_op_set_sg,
  4809. .get_tso = ethtool_op_get_tso,
  4810. .set_tso = bnx2_set_tso,
  4811. .self_test_count = bnx2_self_test_count,
  4812. .self_test = bnx2_self_test,
  4813. .get_strings = bnx2_get_strings,
  4814. .phys_id = bnx2_phys_id,
  4815. .get_stats_count = bnx2_get_stats_count,
  4816. .get_ethtool_stats = bnx2_get_ethtool_stats,
  4817. .get_perm_addr = ethtool_op_get_perm_addr,
  4818. };
  4819. /* Called with rtnl_lock */
  4820. static int
  4821. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  4822. {
  4823. struct mii_ioctl_data *data = if_mii(ifr);
  4824. struct bnx2 *bp = netdev_priv(dev);
  4825. int err;
  4826. switch(cmd) {
  4827. case SIOCGMIIPHY:
  4828. data->phy_id = bp->phy_addr;
  4829. /* fallthru */
  4830. case SIOCGMIIREG: {
  4831. u32 mii_regval;
  4832. if (!netif_running(dev))
  4833. return -EAGAIN;
  4834. spin_lock_bh(&bp->phy_lock);
  4835. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  4836. spin_unlock_bh(&bp->phy_lock);
  4837. data->val_out = mii_regval;
  4838. return err;
  4839. }
  4840. case SIOCSMIIREG:
  4841. if (!capable(CAP_NET_ADMIN))
  4842. return -EPERM;
  4843. if (!netif_running(dev))
  4844. return -EAGAIN;
  4845. spin_lock_bh(&bp->phy_lock);
  4846. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  4847. spin_unlock_bh(&bp->phy_lock);
  4848. return err;
  4849. default:
  4850. /* do nothing */
  4851. break;
  4852. }
  4853. return -EOPNOTSUPP;
  4854. }
  4855. /* Called with rtnl_lock */
  4856. static int
  4857. bnx2_change_mac_addr(struct net_device *dev, void *p)
  4858. {
  4859. struct sockaddr *addr = p;
  4860. struct bnx2 *bp = netdev_priv(dev);
  4861. if (!is_valid_ether_addr(addr->sa_data))
  4862. return -EINVAL;
  4863. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4864. if (netif_running(dev))
  4865. bnx2_set_mac_addr(bp);
  4866. return 0;
  4867. }
  4868. /* Called with rtnl_lock */
  4869. static int
  4870. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  4871. {
  4872. struct bnx2 *bp = netdev_priv(dev);
  4873. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  4874. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  4875. return -EINVAL;
  4876. dev->mtu = new_mtu;
  4877. if (netif_running(dev)) {
  4878. bnx2_netif_stop(bp);
  4879. bnx2_init_nic(bp);
  4880. bnx2_netif_start(bp);
  4881. }
  4882. return 0;
  4883. }
  4884. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4885. static void
  4886. poll_bnx2(struct net_device *dev)
  4887. {
  4888. struct bnx2 *bp = netdev_priv(dev);
  4889. disable_irq(bp->pdev->irq);
  4890. bnx2_interrupt(bp->pdev->irq, dev);
  4891. enable_irq(bp->pdev->irq);
  4892. }
  4893. #endif
  4894. static void __devinit
  4895. bnx2_get_5709_media(struct bnx2 *bp)
  4896. {
  4897. u32 val = REG_RD(bp, BNX2_MISC_DUAL_MEDIA_CTRL);
  4898. u32 bond_id = val & BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID;
  4899. u32 strap;
  4900. if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C)
  4901. return;
  4902. else if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
  4903. bp->phy_flags |= PHY_SERDES_FLAG;
  4904. return;
  4905. }
  4906. if (val & BNX2_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
  4907. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
  4908. else
  4909. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
  4910. if (PCI_FUNC(bp->pdev->devfn) == 0) {
  4911. switch (strap) {
  4912. case 0x4:
  4913. case 0x5:
  4914. case 0x6:
  4915. bp->phy_flags |= PHY_SERDES_FLAG;
  4916. return;
  4917. }
  4918. } else {
  4919. switch (strap) {
  4920. case 0x1:
  4921. case 0x2:
  4922. case 0x4:
  4923. bp->phy_flags |= PHY_SERDES_FLAG;
  4924. return;
  4925. }
  4926. }
  4927. }
  4928. static void __devinit
  4929. bnx2_get_pci_speed(struct bnx2 *bp)
  4930. {
  4931. u32 reg;
  4932. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  4933. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  4934. u32 clkreg;
  4935. bp->flags |= PCIX_FLAG;
  4936. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  4937. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  4938. switch (clkreg) {
  4939. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  4940. bp->bus_speed_mhz = 133;
  4941. break;
  4942. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  4943. bp->bus_speed_mhz = 100;
  4944. break;
  4945. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  4946. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  4947. bp->bus_speed_mhz = 66;
  4948. break;
  4949. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  4950. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  4951. bp->bus_speed_mhz = 50;
  4952. break;
  4953. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  4954. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  4955. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  4956. bp->bus_speed_mhz = 33;
  4957. break;
  4958. }
  4959. }
  4960. else {
  4961. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  4962. bp->bus_speed_mhz = 66;
  4963. else
  4964. bp->bus_speed_mhz = 33;
  4965. }
  4966. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  4967. bp->flags |= PCI_32BIT_FLAG;
  4968. }
  4969. static int __devinit
  4970. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  4971. {
  4972. struct bnx2 *bp;
  4973. unsigned long mem_len;
  4974. int rc;
  4975. u32 reg;
  4976. u64 dma_mask, persist_dma_mask;
  4977. SET_MODULE_OWNER(dev);
  4978. SET_NETDEV_DEV(dev, &pdev->dev);
  4979. bp = netdev_priv(dev);
  4980. bp->flags = 0;
  4981. bp->phy_flags = 0;
  4982. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  4983. rc = pci_enable_device(pdev);
  4984. if (rc) {
  4985. dev_err(&pdev->dev, "Cannot enable PCI device, aborting.");
  4986. goto err_out;
  4987. }
  4988. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  4989. dev_err(&pdev->dev,
  4990. "Cannot find PCI device base address, aborting.\n");
  4991. rc = -ENODEV;
  4992. goto err_out_disable;
  4993. }
  4994. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  4995. if (rc) {
  4996. dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting.\n");
  4997. goto err_out_disable;
  4998. }
  4999. pci_set_master(pdev);
  5000. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  5001. if (bp->pm_cap == 0) {
  5002. dev_err(&pdev->dev,
  5003. "Cannot find power management capability, aborting.\n");
  5004. rc = -EIO;
  5005. goto err_out_release;
  5006. }
  5007. bp->dev = dev;
  5008. bp->pdev = pdev;
  5009. spin_lock_init(&bp->phy_lock);
  5010. spin_lock_init(&bp->indirect_lock);
  5011. INIT_WORK(&bp->reset_task, bnx2_reset_task);
  5012. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  5013. mem_len = MB_GET_CID_ADDR(TX_TSS_CID + 1);
  5014. dev->mem_end = dev->mem_start + mem_len;
  5015. dev->irq = pdev->irq;
  5016. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  5017. if (!bp->regview) {
  5018. dev_err(&pdev->dev, "Cannot map register space, aborting.\n");
  5019. rc = -ENOMEM;
  5020. goto err_out_release;
  5021. }
  5022. /* Configure byte swap and enable write to the reg_window registers.
  5023. * Rely on CPU to do target byte swapping on big endian systems
  5024. * The chip's target access swapping will not swap all accesses
  5025. */
  5026. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  5027. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  5028. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  5029. bnx2_set_power_state(bp, PCI_D0);
  5030. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  5031. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  5032. if (pci_find_capability(pdev, PCI_CAP_ID_EXP) == 0) {
  5033. dev_err(&pdev->dev,
  5034. "Cannot find PCIE capability, aborting.\n");
  5035. rc = -EIO;
  5036. goto err_out_unmap;
  5037. }
  5038. bp->flags |= PCIE_FLAG;
  5039. } else {
  5040. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  5041. if (bp->pcix_cap == 0) {
  5042. dev_err(&pdev->dev,
  5043. "Cannot find PCIX capability, aborting.\n");
  5044. rc = -EIO;
  5045. goto err_out_unmap;
  5046. }
  5047. }
  5048. if (CHIP_ID(bp) != CHIP_ID_5706_A0 && CHIP_ID(bp) != CHIP_ID_5706_A1) {
  5049. if (pci_find_capability(pdev, PCI_CAP_ID_MSI))
  5050. bp->flags |= MSI_CAP_FLAG;
  5051. }
  5052. /* 5708 cannot support DMA addresses > 40-bit. */
  5053. if (CHIP_NUM(bp) == CHIP_NUM_5708)
  5054. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  5055. else
  5056. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  5057. /* Configure DMA attributes. */
  5058. if (pci_set_dma_mask(pdev, dma_mask) == 0) {
  5059. dev->features |= NETIF_F_HIGHDMA;
  5060. rc = pci_set_consistent_dma_mask(pdev, persist_dma_mask);
  5061. if (rc) {
  5062. dev_err(&pdev->dev,
  5063. "pci_set_consistent_dma_mask failed, aborting.\n");
  5064. goto err_out_unmap;
  5065. }
  5066. } else if ((rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) != 0) {
  5067. dev_err(&pdev->dev, "System does not support DMA, aborting.\n");
  5068. goto err_out_unmap;
  5069. }
  5070. if (!(bp->flags & PCIE_FLAG))
  5071. bnx2_get_pci_speed(bp);
  5072. /* 5706A0 may falsely detect SERR and PERR. */
  5073. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  5074. reg = REG_RD(bp, PCI_COMMAND);
  5075. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  5076. REG_WR(bp, PCI_COMMAND, reg);
  5077. }
  5078. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  5079. !(bp->flags & PCIX_FLAG)) {
  5080. dev_err(&pdev->dev,
  5081. "5706 A1 can only be used in a PCIX bus, aborting.\n");
  5082. goto err_out_unmap;
  5083. }
  5084. bnx2_init_nvram(bp);
  5085. reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE);
  5086. if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
  5087. BNX2_SHM_HDR_SIGNATURE_SIG) {
  5088. u32 off = PCI_FUNC(pdev->devfn) << 2;
  5089. bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0 + off);
  5090. } else
  5091. bp->shmem_base = HOST_VIEW_SHMEM_BASE;
  5092. /* Get the permanent MAC address. First we need to make sure the
  5093. * firmware is actually running.
  5094. */
  5095. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_SIGNATURE);
  5096. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  5097. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  5098. dev_err(&pdev->dev, "Firmware not running, aborting.\n");
  5099. rc = -ENODEV;
  5100. goto err_out_unmap;
  5101. }
  5102. bp->fw_ver = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
  5103. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER);
  5104. bp->mac_addr[0] = (u8) (reg >> 8);
  5105. bp->mac_addr[1] = (u8) reg;
  5106. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_LOWER);
  5107. bp->mac_addr[2] = (u8) (reg >> 24);
  5108. bp->mac_addr[3] = (u8) (reg >> 16);
  5109. bp->mac_addr[4] = (u8) (reg >> 8);
  5110. bp->mac_addr[5] = (u8) reg;
  5111. bp->tx_ring_size = MAX_TX_DESC_CNT;
  5112. bnx2_set_rx_ring_size(bp, 255);
  5113. bp->rx_csum = 1;
  5114. bp->rx_offset = sizeof(struct l2_fhdr) + 2;
  5115. bp->tx_quick_cons_trip_int = 20;
  5116. bp->tx_quick_cons_trip = 20;
  5117. bp->tx_ticks_int = 80;
  5118. bp->tx_ticks = 80;
  5119. bp->rx_quick_cons_trip_int = 6;
  5120. bp->rx_quick_cons_trip = 6;
  5121. bp->rx_ticks_int = 18;
  5122. bp->rx_ticks = 18;
  5123. bp->stats_ticks = 1000000 & 0xffff00;
  5124. bp->timer_interval = HZ;
  5125. bp->current_interval = HZ;
  5126. bp->phy_addr = 1;
  5127. /* Disable WOL support if we are running on a SERDES chip. */
  5128. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  5129. bnx2_get_5709_media(bp);
  5130. else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
  5131. bp->phy_flags |= PHY_SERDES_FLAG;
  5132. if (bp->phy_flags & PHY_SERDES_FLAG) {
  5133. bp->flags |= NO_WOL_FLAG;
  5134. if (CHIP_NUM(bp) != CHIP_NUM_5706) {
  5135. bp->phy_addr = 2;
  5136. reg = REG_RD_IND(bp, bp->shmem_base +
  5137. BNX2_SHARED_HW_CFG_CONFIG);
  5138. if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
  5139. bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
  5140. }
  5141. } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
  5142. CHIP_NUM(bp) == CHIP_NUM_5708)
  5143. bp->phy_flags |= PHY_CRC_FIX_FLAG;
  5144. else if (CHIP_ID(bp) == CHIP_ID_5709_A0)
  5145. bp->phy_flags |= PHY_DIS_EARLY_DAC_FLAG;
  5146. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  5147. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  5148. (CHIP_ID(bp) == CHIP_ID_5708_B1))
  5149. bp->flags |= NO_WOL_FLAG;
  5150. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  5151. bp->tx_quick_cons_trip_int =
  5152. bp->tx_quick_cons_trip;
  5153. bp->tx_ticks_int = bp->tx_ticks;
  5154. bp->rx_quick_cons_trip_int =
  5155. bp->rx_quick_cons_trip;
  5156. bp->rx_ticks_int = bp->rx_ticks;
  5157. bp->comp_prod_trip_int = bp->comp_prod_trip;
  5158. bp->com_ticks_int = bp->com_ticks;
  5159. bp->cmd_ticks_int = bp->cmd_ticks;
  5160. }
  5161. /* Disable MSI on 5706 if AMD 8132 bridge is found.
  5162. *
  5163. * MSI is defined to be 32-bit write. The 5706 does 64-bit MSI writes
  5164. * with byte enables disabled on the unused 32-bit word. This is legal
  5165. * but causes problems on the AMD 8132 which will eventually stop
  5166. * responding after a while.
  5167. *
  5168. * AMD believes this incompatibility is unique to the 5706, and
  5169. * prefers to locally disable MSI rather than globally disabling it.
  5170. */
  5171. if (CHIP_NUM(bp) == CHIP_NUM_5706 && disable_msi == 0) {
  5172. struct pci_dev *amd_8132 = NULL;
  5173. while ((amd_8132 = pci_get_device(PCI_VENDOR_ID_AMD,
  5174. PCI_DEVICE_ID_AMD_8132_BRIDGE,
  5175. amd_8132))) {
  5176. u8 rev;
  5177. pci_read_config_byte(amd_8132, PCI_REVISION_ID, &rev);
  5178. if (rev >= 0x10 && rev <= 0x13) {
  5179. disable_msi = 1;
  5180. pci_dev_put(amd_8132);
  5181. break;
  5182. }
  5183. }
  5184. }
  5185. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  5186. bp->req_line_speed = 0;
  5187. if (bp->phy_flags & PHY_SERDES_FLAG) {
  5188. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  5189. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
  5190. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  5191. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  5192. bp->autoneg = 0;
  5193. bp->req_line_speed = bp->line_speed = SPEED_1000;
  5194. bp->req_duplex = DUPLEX_FULL;
  5195. }
  5196. }
  5197. else {
  5198. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  5199. }
  5200. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  5201. init_timer(&bp->timer);
  5202. bp->timer.expires = RUN_AT(bp->timer_interval);
  5203. bp->timer.data = (unsigned long) bp;
  5204. bp->timer.function = bnx2_timer;
  5205. return 0;
  5206. err_out_unmap:
  5207. if (bp->regview) {
  5208. iounmap(bp->regview);
  5209. bp->regview = NULL;
  5210. }
  5211. err_out_release:
  5212. pci_release_regions(pdev);
  5213. err_out_disable:
  5214. pci_disable_device(pdev);
  5215. pci_set_drvdata(pdev, NULL);
  5216. err_out:
  5217. return rc;
  5218. }
  5219. static char * __devinit
  5220. bnx2_bus_string(struct bnx2 *bp, char *str)
  5221. {
  5222. char *s = str;
  5223. if (bp->flags & PCIE_FLAG) {
  5224. s += sprintf(s, "PCI Express");
  5225. } else {
  5226. s += sprintf(s, "PCI");
  5227. if (bp->flags & PCIX_FLAG)
  5228. s += sprintf(s, "-X");
  5229. if (bp->flags & PCI_32BIT_FLAG)
  5230. s += sprintf(s, " 32-bit");
  5231. else
  5232. s += sprintf(s, " 64-bit");
  5233. s += sprintf(s, " %dMHz", bp->bus_speed_mhz);
  5234. }
  5235. return str;
  5236. }
  5237. static int __devinit
  5238. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  5239. {
  5240. static int version_printed = 0;
  5241. struct net_device *dev = NULL;
  5242. struct bnx2 *bp;
  5243. int rc, i;
  5244. char str[40];
  5245. if (version_printed++ == 0)
  5246. printk(KERN_INFO "%s", version);
  5247. /* dev zeroed in init_etherdev */
  5248. dev = alloc_etherdev(sizeof(*bp));
  5249. if (!dev)
  5250. return -ENOMEM;
  5251. rc = bnx2_init_board(pdev, dev);
  5252. if (rc < 0) {
  5253. free_netdev(dev);
  5254. return rc;
  5255. }
  5256. dev->open = bnx2_open;
  5257. dev->hard_start_xmit = bnx2_start_xmit;
  5258. dev->stop = bnx2_close;
  5259. dev->get_stats = bnx2_get_stats;
  5260. dev->set_multicast_list = bnx2_set_rx_mode;
  5261. dev->do_ioctl = bnx2_ioctl;
  5262. dev->set_mac_address = bnx2_change_mac_addr;
  5263. dev->change_mtu = bnx2_change_mtu;
  5264. dev->tx_timeout = bnx2_tx_timeout;
  5265. dev->watchdog_timeo = TX_TIMEOUT;
  5266. #ifdef BCM_VLAN
  5267. dev->vlan_rx_register = bnx2_vlan_rx_register;
  5268. #endif
  5269. dev->poll = bnx2_poll;
  5270. dev->ethtool_ops = &bnx2_ethtool_ops;
  5271. dev->weight = 64;
  5272. bp = netdev_priv(dev);
  5273. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  5274. dev->poll_controller = poll_bnx2;
  5275. #endif
  5276. pci_set_drvdata(pdev, dev);
  5277. memcpy(dev->dev_addr, bp->mac_addr, 6);
  5278. memcpy(dev->perm_addr, bp->mac_addr, 6);
  5279. bp->name = board_info[ent->driver_data].name;
  5280. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  5281. dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
  5282. else
  5283. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  5284. #ifdef BCM_VLAN
  5285. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  5286. #endif
  5287. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  5288. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  5289. dev->features |= NETIF_F_TSO6;
  5290. if ((rc = register_netdev(dev))) {
  5291. dev_err(&pdev->dev, "Cannot register net device\n");
  5292. if (bp->regview)
  5293. iounmap(bp->regview);
  5294. pci_release_regions(pdev);
  5295. pci_disable_device(pdev);
  5296. pci_set_drvdata(pdev, NULL);
  5297. free_netdev(dev);
  5298. return rc;
  5299. }
  5300. printk(KERN_INFO "%s: %s (%c%d) %s found at mem %lx, "
  5301. "IRQ %d, ",
  5302. dev->name,
  5303. bp->name,
  5304. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  5305. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  5306. bnx2_bus_string(bp, str),
  5307. dev->base_addr,
  5308. bp->pdev->irq);
  5309. printk("node addr ");
  5310. for (i = 0; i < 6; i++)
  5311. printk("%2.2x", dev->dev_addr[i]);
  5312. printk("\n");
  5313. return 0;
  5314. }
  5315. static void __devexit
  5316. bnx2_remove_one(struct pci_dev *pdev)
  5317. {
  5318. struct net_device *dev = pci_get_drvdata(pdev);
  5319. struct bnx2 *bp = netdev_priv(dev);
  5320. flush_scheduled_work();
  5321. unregister_netdev(dev);
  5322. if (bp->regview)
  5323. iounmap(bp->regview);
  5324. free_netdev(dev);
  5325. pci_release_regions(pdev);
  5326. pci_disable_device(pdev);
  5327. pci_set_drvdata(pdev, NULL);
  5328. }
  5329. static int
  5330. bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
  5331. {
  5332. struct net_device *dev = pci_get_drvdata(pdev);
  5333. struct bnx2 *bp = netdev_priv(dev);
  5334. u32 reset_code;
  5335. if (!netif_running(dev))
  5336. return 0;
  5337. flush_scheduled_work();
  5338. bnx2_netif_stop(bp);
  5339. netif_device_detach(dev);
  5340. del_timer_sync(&bp->timer);
  5341. if (bp->flags & NO_WOL_FLAG)
  5342. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  5343. else if (bp->wol)
  5344. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  5345. else
  5346. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  5347. bnx2_reset_chip(bp, reset_code);
  5348. bnx2_free_skbs(bp);
  5349. pci_save_state(pdev);
  5350. bnx2_set_power_state(bp, pci_choose_state(pdev, state));
  5351. return 0;
  5352. }
  5353. static int
  5354. bnx2_resume(struct pci_dev *pdev)
  5355. {
  5356. struct net_device *dev = pci_get_drvdata(pdev);
  5357. struct bnx2 *bp = netdev_priv(dev);
  5358. if (!netif_running(dev))
  5359. return 0;
  5360. pci_restore_state(pdev);
  5361. bnx2_set_power_state(bp, PCI_D0);
  5362. netif_device_attach(dev);
  5363. bnx2_init_nic(bp);
  5364. bnx2_netif_start(bp);
  5365. return 0;
  5366. }
  5367. static struct pci_driver bnx2_pci_driver = {
  5368. .name = DRV_MODULE_NAME,
  5369. .id_table = bnx2_pci_tbl,
  5370. .probe = bnx2_init_one,
  5371. .remove = __devexit_p(bnx2_remove_one),
  5372. .suspend = bnx2_suspend,
  5373. .resume = bnx2_resume,
  5374. };
  5375. static int __init bnx2_init(void)
  5376. {
  5377. return pci_register_driver(&bnx2_pci_driver);
  5378. }
  5379. static void __exit bnx2_cleanup(void)
  5380. {
  5381. pci_unregister_driver(&bnx2_pci_driver);
  5382. }
  5383. module_init(bnx2_init);
  5384. module_exit(bnx2_cleanup);