bnx2.c 166 KB

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