bnx2.c 191 KB

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