bnx2.c 166 KB

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