bnx2.c 192 KB

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