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