bnx2.c 185 KB

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