bnx2.c 196 KB

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