bnx2.c 184 KB

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