bnx2.c 144 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004, 2005, 2006 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 <asm/bitops.h>
  27. #include <asm/io.h>
  28. #include <asm/irq.h>
  29. #include <linux/delay.h>
  30. #include <asm/byteorder.h>
  31. #include <asm/page.h>
  32. #include <linux/time.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/mii.h>
  35. #ifdef NETIF_F_HW_VLAN_TX
  36. #include <linux/if_vlan.h>
  37. #define BCM_VLAN 1
  38. #endif
  39. #ifdef NETIF_F_TSO
  40. #include <net/ip.h>
  41. #include <net/tcp.h>
  42. #include <net/checksum.h>
  43. #define BCM_TSO 1
  44. #endif
  45. #include <linux/workqueue.h>
  46. #include <linux/crc32.h>
  47. #include <linux/prefetch.h>
  48. #include <linux/cache.h>
  49. #include <linux/zlib.h>
  50. #include "bnx2.h"
  51. #include "bnx2_fw.h"
  52. #define DRV_MODULE_NAME "bnx2"
  53. #define PFX DRV_MODULE_NAME ": "
  54. #define DRV_MODULE_VERSION "1.4.45"
  55. #define DRV_MODULE_RELDATE "September 29, 2006"
  56. #define RUN_AT(x) (jiffies + (x))
  57. /* Time in jiffies before concluding the transmitter is hung. */
  58. #define TX_TIMEOUT (5*HZ)
  59. static const char version[] __devinitdata =
  60. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  61. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  62. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708 Driver");
  63. MODULE_LICENSE("GPL");
  64. MODULE_VERSION(DRV_MODULE_VERSION);
  65. static int disable_msi = 0;
  66. module_param(disable_msi, int, 0);
  67. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  68. typedef enum {
  69. BCM5706 = 0,
  70. NC370T,
  71. NC370I,
  72. BCM5706S,
  73. NC370F,
  74. BCM5708,
  75. BCM5708S,
  76. } board_t;
  77. /* indexed by board_t, above */
  78. static const struct {
  79. char *name;
  80. } board_info[] __devinitdata = {
  81. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  82. { "HP NC370T Multifunction Gigabit Server Adapter" },
  83. { "HP NC370i Multifunction Gigabit Server Adapter" },
  84. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  85. { "HP NC370F Multifunction Gigabit Server Adapter" },
  86. { "Broadcom NetXtreme II BCM5708 1000Base-T" },
  87. { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
  88. };
  89. static struct pci_device_id bnx2_pci_tbl[] = {
  90. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  91. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  92. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  93. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  94. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  95. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  96. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708,
  97. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708 },
  98. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  99. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  100. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  101. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  102. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708S,
  103. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708S },
  104. { 0, }
  105. };
  106. static struct flash_spec flash_table[] =
  107. {
  108. /* Slow EEPROM */
  109. {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
  110. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  111. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  112. "EEPROM - slow"},
  113. /* Expansion entry 0001 */
  114. {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
  115. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  116. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  117. "Entry 0001"},
  118. /* Saifun SA25F010 (non-buffered flash) */
  119. /* strap, cfg1, & write1 need updates */
  120. {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
  121. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  122. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  123. "Non-buffered flash (128kB)"},
  124. /* Saifun SA25F020 (non-buffered flash) */
  125. /* strap, cfg1, & write1 need updates */
  126. {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
  127. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  128. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  129. "Non-buffered flash (256kB)"},
  130. /* Expansion entry 0100 */
  131. {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
  132. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  133. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  134. "Entry 0100"},
  135. /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
  136. {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
  137. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  138. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
  139. "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
  140. /* Entry 0110: ST M45PE20 (non-buffered flash)*/
  141. {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
  142. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  143. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
  144. "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
  145. /* Saifun SA25F005 (non-buffered flash) */
  146. /* strap, cfg1, & write1 need updates */
  147. {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
  148. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  149. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  150. "Non-buffered flash (64kB)"},
  151. /* Fast EEPROM */
  152. {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
  153. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  154. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  155. "EEPROM - fast"},
  156. /* Expansion entry 1001 */
  157. {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
  158. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  159. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  160. "Entry 1001"},
  161. /* Expansion entry 1010 */
  162. {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
  163. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  164. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  165. "Entry 1010"},
  166. /* ATMEL AT45DB011B (buffered flash) */
  167. {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
  168. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  169. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  170. "Buffered flash (128kB)"},
  171. /* Expansion entry 1100 */
  172. {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
  173. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  174. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  175. "Entry 1100"},
  176. /* Expansion entry 1101 */
  177. {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
  178. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  179. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  180. "Entry 1101"},
  181. /* Ateml Expansion entry 1110 */
  182. {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
  183. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  184. BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
  185. "Entry 1110 (Atmel)"},
  186. /* ATMEL AT45DB021B (buffered flash) */
  187. {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
  188. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  189. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
  190. "Buffered flash (256kB)"},
  191. };
  192. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  193. static inline u32 bnx2_tx_avail(struct bnx2 *bp)
  194. {
  195. u32 diff;
  196. smp_mb();
  197. diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons);
  198. if (diff > MAX_TX_DESC_CNT)
  199. diff = (diff & MAX_TX_DESC_CNT) - 1;
  200. return (bp->tx_ring_size - diff);
  201. }
  202. static u32
  203. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  204. {
  205. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  206. return (REG_RD(bp, BNX2_PCICFG_REG_WINDOW));
  207. }
  208. static void
  209. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  210. {
  211. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  212. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  213. }
  214. static void
  215. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  216. {
  217. offset += cid_addr;
  218. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  219. REG_WR(bp, BNX2_CTX_DATA, val);
  220. }
  221. static int
  222. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  223. {
  224. u32 val1;
  225. int i, ret;
  226. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  227. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  228. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  229. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  230. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  231. udelay(40);
  232. }
  233. val1 = (bp->phy_addr << 21) | (reg << 16) |
  234. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  235. BNX2_EMAC_MDIO_COMM_START_BUSY;
  236. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  237. for (i = 0; i < 50; i++) {
  238. udelay(10);
  239. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  240. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  241. udelay(5);
  242. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  243. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  244. break;
  245. }
  246. }
  247. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  248. *val = 0x0;
  249. ret = -EBUSY;
  250. }
  251. else {
  252. *val = val1;
  253. ret = 0;
  254. }
  255. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  256. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  257. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  258. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  259. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  260. udelay(40);
  261. }
  262. return ret;
  263. }
  264. static int
  265. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  266. {
  267. u32 val1;
  268. int i, ret;
  269. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  270. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  271. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  272. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  273. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  274. udelay(40);
  275. }
  276. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  277. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  278. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  279. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  280. for (i = 0; i < 50; i++) {
  281. udelay(10);
  282. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  283. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  284. udelay(5);
  285. break;
  286. }
  287. }
  288. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  289. ret = -EBUSY;
  290. else
  291. ret = 0;
  292. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  293. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  294. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  295. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  296. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  297. udelay(40);
  298. }
  299. return ret;
  300. }
  301. static void
  302. bnx2_disable_int(struct bnx2 *bp)
  303. {
  304. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  305. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  306. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  307. }
  308. static void
  309. bnx2_enable_int(struct bnx2 *bp)
  310. {
  311. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  312. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  313. BNX2_PCICFG_INT_ACK_CMD_MASK_INT | bp->last_status_idx);
  314. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  315. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
  316. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  317. }
  318. static void
  319. bnx2_disable_int_sync(struct bnx2 *bp)
  320. {
  321. atomic_inc(&bp->intr_sem);
  322. bnx2_disable_int(bp);
  323. synchronize_irq(bp->pdev->irq);
  324. }
  325. static void
  326. bnx2_netif_stop(struct bnx2 *bp)
  327. {
  328. bnx2_disable_int_sync(bp);
  329. if (netif_running(bp->dev)) {
  330. netif_poll_disable(bp->dev);
  331. netif_tx_disable(bp->dev);
  332. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  333. }
  334. }
  335. static void
  336. bnx2_netif_start(struct bnx2 *bp)
  337. {
  338. if (atomic_dec_and_test(&bp->intr_sem)) {
  339. if (netif_running(bp->dev)) {
  340. netif_wake_queue(bp->dev);
  341. netif_poll_enable(bp->dev);
  342. bnx2_enable_int(bp);
  343. }
  344. }
  345. }
  346. static void
  347. bnx2_free_mem(struct bnx2 *bp)
  348. {
  349. int i;
  350. if (bp->status_blk) {
  351. pci_free_consistent(bp->pdev, bp->status_stats_size,
  352. bp->status_blk, bp->status_blk_mapping);
  353. bp->status_blk = NULL;
  354. bp->stats_blk = NULL;
  355. }
  356. if (bp->tx_desc_ring) {
  357. pci_free_consistent(bp->pdev,
  358. sizeof(struct tx_bd) * TX_DESC_CNT,
  359. bp->tx_desc_ring, bp->tx_desc_mapping);
  360. bp->tx_desc_ring = NULL;
  361. }
  362. kfree(bp->tx_buf_ring);
  363. bp->tx_buf_ring = NULL;
  364. for (i = 0; i < bp->rx_max_ring; i++) {
  365. if (bp->rx_desc_ring[i])
  366. pci_free_consistent(bp->pdev,
  367. sizeof(struct rx_bd) * RX_DESC_CNT,
  368. bp->rx_desc_ring[i],
  369. bp->rx_desc_mapping[i]);
  370. bp->rx_desc_ring[i] = NULL;
  371. }
  372. vfree(bp->rx_buf_ring);
  373. bp->rx_buf_ring = NULL;
  374. }
  375. static int
  376. bnx2_alloc_mem(struct bnx2 *bp)
  377. {
  378. int i, status_blk_size;
  379. bp->tx_buf_ring = kzalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
  380. GFP_KERNEL);
  381. if (bp->tx_buf_ring == NULL)
  382. return -ENOMEM;
  383. bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
  384. sizeof(struct tx_bd) *
  385. TX_DESC_CNT,
  386. &bp->tx_desc_mapping);
  387. if (bp->tx_desc_ring == NULL)
  388. goto alloc_mem_err;
  389. bp->rx_buf_ring = vmalloc(sizeof(struct sw_bd) * RX_DESC_CNT *
  390. bp->rx_max_ring);
  391. if (bp->rx_buf_ring == NULL)
  392. goto alloc_mem_err;
  393. memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT *
  394. bp->rx_max_ring);
  395. for (i = 0; i < bp->rx_max_ring; i++) {
  396. bp->rx_desc_ring[i] =
  397. pci_alloc_consistent(bp->pdev,
  398. sizeof(struct rx_bd) * RX_DESC_CNT,
  399. &bp->rx_desc_mapping[i]);
  400. if (bp->rx_desc_ring[i] == NULL)
  401. goto alloc_mem_err;
  402. }
  403. /* Combine status and statistics blocks into one allocation. */
  404. status_blk_size = L1_CACHE_ALIGN(sizeof(struct status_block));
  405. bp->status_stats_size = status_blk_size +
  406. sizeof(struct statistics_block);
  407. bp->status_blk = pci_alloc_consistent(bp->pdev, bp->status_stats_size,
  408. &bp->status_blk_mapping);
  409. if (bp->status_blk == NULL)
  410. goto alloc_mem_err;
  411. memset(bp->status_blk, 0, bp->status_stats_size);
  412. bp->stats_blk = (void *) ((unsigned long) bp->status_blk +
  413. status_blk_size);
  414. bp->stats_blk_mapping = bp->status_blk_mapping + status_blk_size;
  415. return 0;
  416. alloc_mem_err:
  417. bnx2_free_mem(bp);
  418. return -ENOMEM;
  419. }
  420. static void
  421. bnx2_report_fw_link(struct bnx2 *bp)
  422. {
  423. u32 fw_link_status = 0;
  424. if (bp->link_up) {
  425. u32 bmsr;
  426. switch (bp->line_speed) {
  427. case SPEED_10:
  428. if (bp->duplex == DUPLEX_HALF)
  429. fw_link_status = BNX2_LINK_STATUS_10HALF;
  430. else
  431. fw_link_status = BNX2_LINK_STATUS_10FULL;
  432. break;
  433. case SPEED_100:
  434. if (bp->duplex == DUPLEX_HALF)
  435. fw_link_status = BNX2_LINK_STATUS_100HALF;
  436. else
  437. fw_link_status = BNX2_LINK_STATUS_100FULL;
  438. break;
  439. case SPEED_1000:
  440. if (bp->duplex == DUPLEX_HALF)
  441. fw_link_status = BNX2_LINK_STATUS_1000HALF;
  442. else
  443. fw_link_status = BNX2_LINK_STATUS_1000FULL;
  444. break;
  445. case SPEED_2500:
  446. if (bp->duplex == DUPLEX_HALF)
  447. fw_link_status = BNX2_LINK_STATUS_2500HALF;
  448. else
  449. fw_link_status = BNX2_LINK_STATUS_2500FULL;
  450. break;
  451. }
  452. fw_link_status |= BNX2_LINK_STATUS_LINK_UP;
  453. if (bp->autoneg) {
  454. fw_link_status |= BNX2_LINK_STATUS_AN_ENABLED;
  455. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  456. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  457. if (!(bmsr & BMSR_ANEGCOMPLETE) ||
  458. bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)
  459. fw_link_status |= BNX2_LINK_STATUS_PARALLEL_DET;
  460. else
  461. fw_link_status |= BNX2_LINK_STATUS_AN_COMPLETE;
  462. }
  463. }
  464. else
  465. fw_link_status = BNX2_LINK_STATUS_LINK_DOWN;
  466. REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status);
  467. }
  468. static void
  469. bnx2_report_link(struct bnx2 *bp)
  470. {
  471. if (bp->link_up) {
  472. netif_carrier_on(bp->dev);
  473. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  474. printk("%d Mbps ", bp->line_speed);
  475. if (bp->duplex == DUPLEX_FULL)
  476. printk("full duplex");
  477. else
  478. printk("half duplex");
  479. if (bp->flow_ctrl) {
  480. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  481. printk(", receive ");
  482. if (bp->flow_ctrl & FLOW_CTRL_TX)
  483. printk("& transmit ");
  484. }
  485. else {
  486. printk(", transmit ");
  487. }
  488. printk("flow control ON");
  489. }
  490. printk("\n");
  491. }
  492. else {
  493. netif_carrier_off(bp->dev);
  494. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  495. }
  496. bnx2_report_fw_link(bp);
  497. }
  498. static void
  499. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  500. {
  501. u32 local_adv, remote_adv;
  502. bp->flow_ctrl = 0;
  503. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  504. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  505. if (bp->duplex == DUPLEX_FULL) {
  506. bp->flow_ctrl = bp->req_flow_ctrl;
  507. }
  508. return;
  509. }
  510. if (bp->duplex != DUPLEX_FULL) {
  511. return;
  512. }
  513. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  514. (CHIP_NUM(bp) == CHIP_NUM_5708)) {
  515. u32 val;
  516. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  517. if (val & BCM5708S_1000X_STAT1_TX_PAUSE)
  518. bp->flow_ctrl |= FLOW_CTRL_TX;
  519. if (val & BCM5708S_1000X_STAT1_RX_PAUSE)
  520. bp->flow_ctrl |= FLOW_CTRL_RX;
  521. return;
  522. }
  523. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  524. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  525. if (bp->phy_flags & PHY_SERDES_FLAG) {
  526. u32 new_local_adv = 0;
  527. u32 new_remote_adv = 0;
  528. if (local_adv & ADVERTISE_1000XPAUSE)
  529. new_local_adv |= ADVERTISE_PAUSE_CAP;
  530. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  531. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  532. if (remote_adv & ADVERTISE_1000XPAUSE)
  533. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  534. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  535. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  536. local_adv = new_local_adv;
  537. remote_adv = new_remote_adv;
  538. }
  539. /* See Table 28B-3 of 802.3ab-1999 spec. */
  540. if (local_adv & ADVERTISE_PAUSE_CAP) {
  541. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  542. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  543. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  544. }
  545. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  546. bp->flow_ctrl = FLOW_CTRL_RX;
  547. }
  548. }
  549. else {
  550. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  551. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  552. }
  553. }
  554. }
  555. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  556. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  557. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  558. bp->flow_ctrl = FLOW_CTRL_TX;
  559. }
  560. }
  561. }
  562. static int
  563. bnx2_5708s_linkup(struct bnx2 *bp)
  564. {
  565. u32 val;
  566. bp->link_up = 1;
  567. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  568. switch (val & BCM5708S_1000X_STAT1_SPEED_MASK) {
  569. case BCM5708S_1000X_STAT1_SPEED_10:
  570. bp->line_speed = SPEED_10;
  571. break;
  572. case BCM5708S_1000X_STAT1_SPEED_100:
  573. bp->line_speed = SPEED_100;
  574. break;
  575. case BCM5708S_1000X_STAT1_SPEED_1G:
  576. bp->line_speed = SPEED_1000;
  577. break;
  578. case BCM5708S_1000X_STAT1_SPEED_2G5:
  579. bp->line_speed = SPEED_2500;
  580. break;
  581. }
  582. if (val & BCM5708S_1000X_STAT1_FD)
  583. bp->duplex = DUPLEX_FULL;
  584. else
  585. bp->duplex = DUPLEX_HALF;
  586. return 0;
  587. }
  588. static int
  589. bnx2_5706s_linkup(struct bnx2 *bp)
  590. {
  591. u32 bmcr, local_adv, remote_adv, common;
  592. bp->link_up = 1;
  593. bp->line_speed = SPEED_1000;
  594. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  595. if (bmcr & BMCR_FULLDPLX) {
  596. bp->duplex = DUPLEX_FULL;
  597. }
  598. else {
  599. bp->duplex = DUPLEX_HALF;
  600. }
  601. if (!(bmcr & BMCR_ANENABLE)) {
  602. return 0;
  603. }
  604. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  605. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  606. common = local_adv & remote_adv;
  607. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  608. if (common & ADVERTISE_1000XFULL) {
  609. bp->duplex = DUPLEX_FULL;
  610. }
  611. else {
  612. bp->duplex = DUPLEX_HALF;
  613. }
  614. }
  615. return 0;
  616. }
  617. static int
  618. bnx2_copper_linkup(struct bnx2 *bp)
  619. {
  620. u32 bmcr;
  621. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  622. if (bmcr & BMCR_ANENABLE) {
  623. u32 local_adv, remote_adv, common;
  624. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  625. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  626. common = local_adv & (remote_adv >> 2);
  627. if (common & ADVERTISE_1000FULL) {
  628. bp->line_speed = SPEED_1000;
  629. bp->duplex = DUPLEX_FULL;
  630. }
  631. else if (common & ADVERTISE_1000HALF) {
  632. bp->line_speed = SPEED_1000;
  633. bp->duplex = DUPLEX_HALF;
  634. }
  635. else {
  636. bnx2_read_phy(bp, MII_ADVERTISE, &local_adv);
  637. bnx2_read_phy(bp, MII_LPA, &remote_adv);
  638. common = local_adv & remote_adv;
  639. if (common & ADVERTISE_100FULL) {
  640. bp->line_speed = SPEED_100;
  641. bp->duplex = DUPLEX_FULL;
  642. }
  643. else if (common & ADVERTISE_100HALF) {
  644. bp->line_speed = SPEED_100;
  645. bp->duplex = DUPLEX_HALF;
  646. }
  647. else if (common & ADVERTISE_10FULL) {
  648. bp->line_speed = SPEED_10;
  649. bp->duplex = DUPLEX_FULL;
  650. }
  651. else if (common & ADVERTISE_10HALF) {
  652. bp->line_speed = SPEED_10;
  653. bp->duplex = DUPLEX_HALF;
  654. }
  655. else {
  656. bp->line_speed = 0;
  657. bp->link_up = 0;
  658. }
  659. }
  660. }
  661. else {
  662. if (bmcr & BMCR_SPEED100) {
  663. bp->line_speed = SPEED_100;
  664. }
  665. else {
  666. bp->line_speed = SPEED_10;
  667. }
  668. if (bmcr & BMCR_FULLDPLX) {
  669. bp->duplex = DUPLEX_FULL;
  670. }
  671. else {
  672. bp->duplex = DUPLEX_HALF;
  673. }
  674. }
  675. return 0;
  676. }
  677. static int
  678. bnx2_set_mac_link(struct bnx2 *bp)
  679. {
  680. u32 val;
  681. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  682. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  683. (bp->duplex == DUPLEX_HALF)) {
  684. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  685. }
  686. /* Configure the EMAC mode register. */
  687. val = REG_RD(bp, BNX2_EMAC_MODE);
  688. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  689. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  690. BNX2_EMAC_MODE_25G);
  691. if (bp->link_up) {
  692. switch (bp->line_speed) {
  693. case SPEED_10:
  694. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  695. val |= BNX2_EMAC_MODE_PORT_MII_10;
  696. break;
  697. }
  698. /* fall through */
  699. case SPEED_100:
  700. val |= BNX2_EMAC_MODE_PORT_MII;
  701. break;
  702. case SPEED_2500:
  703. val |= BNX2_EMAC_MODE_25G;
  704. /* fall through */
  705. case SPEED_1000:
  706. val |= BNX2_EMAC_MODE_PORT_GMII;
  707. break;
  708. }
  709. }
  710. else {
  711. val |= BNX2_EMAC_MODE_PORT_GMII;
  712. }
  713. /* Set the MAC to operate in the appropriate duplex mode. */
  714. if (bp->duplex == DUPLEX_HALF)
  715. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  716. REG_WR(bp, BNX2_EMAC_MODE, val);
  717. /* Enable/disable rx PAUSE. */
  718. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  719. if (bp->flow_ctrl & FLOW_CTRL_RX)
  720. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  721. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  722. /* Enable/disable tx PAUSE. */
  723. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  724. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  725. if (bp->flow_ctrl & FLOW_CTRL_TX)
  726. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  727. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  728. /* Acknowledge the interrupt. */
  729. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  730. return 0;
  731. }
  732. static int
  733. bnx2_set_link(struct bnx2 *bp)
  734. {
  735. u32 bmsr;
  736. u8 link_up;
  737. if (bp->loopback == MAC_LOOPBACK || bp->loopback == PHY_LOOPBACK) {
  738. bp->link_up = 1;
  739. return 0;
  740. }
  741. link_up = bp->link_up;
  742. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  743. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  744. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  745. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  746. u32 val;
  747. val = REG_RD(bp, BNX2_EMAC_STATUS);
  748. if (val & BNX2_EMAC_STATUS_LINK)
  749. bmsr |= BMSR_LSTATUS;
  750. else
  751. bmsr &= ~BMSR_LSTATUS;
  752. }
  753. if (bmsr & BMSR_LSTATUS) {
  754. bp->link_up = 1;
  755. if (bp->phy_flags & PHY_SERDES_FLAG) {
  756. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  757. bnx2_5706s_linkup(bp);
  758. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  759. bnx2_5708s_linkup(bp);
  760. }
  761. else {
  762. bnx2_copper_linkup(bp);
  763. }
  764. bnx2_resolve_flow_ctrl(bp);
  765. }
  766. else {
  767. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  768. (bp->autoneg & AUTONEG_SPEED)) {
  769. u32 bmcr;
  770. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  771. bmcr &= ~BCM5708S_BMCR_FORCE_2500;
  772. if (!(bmcr & BMCR_ANENABLE)) {
  773. bnx2_write_phy(bp, MII_BMCR, bmcr |
  774. BMCR_ANENABLE);
  775. }
  776. }
  777. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  778. bp->link_up = 0;
  779. }
  780. if (bp->link_up != link_up) {
  781. bnx2_report_link(bp);
  782. }
  783. bnx2_set_mac_link(bp);
  784. return 0;
  785. }
  786. static int
  787. bnx2_reset_phy(struct bnx2 *bp)
  788. {
  789. int i;
  790. u32 reg;
  791. bnx2_write_phy(bp, MII_BMCR, BMCR_RESET);
  792. #define PHY_RESET_MAX_WAIT 100
  793. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  794. udelay(10);
  795. bnx2_read_phy(bp, MII_BMCR, &reg);
  796. if (!(reg & BMCR_RESET)) {
  797. udelay(20);
  798. break;
  799. }
  800. }
  801. if (i == PHY_RESET_MAX_WAIT) {
  802. return -EBUSY;
  803. }
  804. return 0;
  805. }
  806. static u32
  807. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  808. {
  809. u32 adv = 0;
  810. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  811. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  812. if (bp->phy_flags & PHY_SERDES_FLAG) {
  813. adv = ADVERTISE_1000XPAUSE;
  814. }
  815. else {
  816. adv = ADVERTISE_PAUSE_CAP;
  817. }
  818. }
  819. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  820. if (bp->phy_flags & PHY_SERDES_FLAG) {
  821. adv = ADVERTISE_1000XPSE_ASYM;
  822. }
  823. else {
  824. adv = ADVERTISE_PAUSE_ASYM;
  825. }
  826. }
  827. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  828. if (bp->phy_flags & PHY_SERDES_FLAG) {
  829. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  830. }
  831. else {
  832. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  833. }
  834. }
  835. return adv;
  836. }
  837. static int
  838. bnx2_setup_serdes_phy(struct bnx2 *bp)
  839. {
  840. u32 adv, bmcr, up1;
  841. u32 new_adv = 0;
  842. if (!(bp->autoneg & AUTONEG_SPEED)) {
  843. u32 new_bmcr;
  844. int force_link_down = 0;
  845. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  846. adv &= ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF);
  847. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  848. new_bmcr = bmcr & ~(BMCR_ANENABLE | BCM5708S_BMCR_FORCE_2500);
  849. new_bmcr |= BMCR_SPEED1000;
  850. if (bp->req_line_speed == SPEED_2500) {
  851. new_bmcr |= BCM5708S_BMCR_FORCE_2500;
  852. bnx2_read_phy(bp, BCM5708S_UP1, &up1);
  853. if (!(up1 & BCM5708S_UP1_2G5)) {
  854. up1 |= BCM5708S_UP1_2G5;
  855. bnx2_write_phy(bp, BCM5708S_UP1, up1);
  856. force_link_down = 1;
  857. }
  858. } else if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  859. bnx2_read_phy(bp, BCM5708S_UP1, &up1);
  860. if (up1 & BCM5708S_UP1_2G5) {
  861. up1 &= ~BCM5708S_UP1_2G5;
  862. bnx2_write_phy(bp, BCM5708S_UP1, up1);
  863. force_link_down = 1;
  864. }
  865. }
  866. if (bp->req_duplex == DUPLEX_FULL) {
  867. adv |= ADVERTISE_1000XFULL;
  868. new_bmcr |= BMCR_FULLDPLX;
  869. }
  870. else {
  871. adv |= ADVERTISE_1000XHALF;
  872. new_bmcr &= ~BMCR_FULLDPLX;
  873. }
  874. if ((new_bmcr != bmcr) || (force_link_down)) {
  875. /* Force a link down visible on the other side */
  876. if (bp->link_up) {
  877. bnx2_write_phy(bp, MII_ADVERTISE, adv &
  878. ~(ADVERTISE_1000XFULL |
  879. ADVERTISE_1000XHALF));
  880. bnx2_write_phy(bp, MII_BMCR, bmcr |
  881. BMCR_ANRESTART | BMCR_ANENABLE);
  882. bp->link_up = 0;
  883. netif_carrier_off(bp->dev);
  884. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  885. bnx2_report_link(bp);
  886. }
  887. bnx2_write_phy(bp, MII_ADVERTISE, adv);
  888. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  889. }
  890. return 0;
  891. }
  892. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) {
  893. bnx2_read_phy(bp, BCM5708S_UP1, &up1);
  894. up1 |= BCM5708S_UP1_2G5;
  895. bnx2_write_phy(bp, BCM5708S_UP1, up1);
  896. }
  897. if (bp->advertising & ADVERTISED_1000baseT_Full)
  898. new_adv |= ADVERTISE_1000XFULL;
  899. new_adv |= bnx2_phy_get_pause_adv(bp);
  900. bnx2_read_phy(bp, MII_ADVERTISE, &adv);
  901. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  902. bp->serdes_an_pending = 0;
  903. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  904. /* Force a link down visible on the other side */
  905. if (bp->link_up) {
  906. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  907. spin_unlock_bh(&bp->phy_lock);
  908. msleep(20);
  909. spin_lock_bh(&bp->phy_lock);
  910. }
  911. bnx2_write_phy(bp, MII_ADVERTISE, new_adv);
  912. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART |
  913. BMCR_ANENABLE);
  914. /* Speed up link-up time when the link partner
  915. * does not autonegotiate which is very common
  916. * in blade servers. Some blade servers use
  917. * IPMI for kerboard input and it's important
  918. * to minimize link disruptions. Autoneg. involves
  919. * exchanging base pages plus 3 next pages and
  920. * normally completes in about 120 msec.
  921. */
  922. bp->current_interval = SERDES_AN_TIMEOUT;
  923. bp->serdes_an_pending = 1;
  924. mod_timer(&bp->timer, jiffies + bp->current_interval);
  925. }
  926. return 0;
  927. }
  928. #define ETHTOOL_ALL_FIBRE_SPEED \
  929. (ADVERTISED_1000baseT_Full)
  930. #define ETHTOOL_ALL_COPPER_SPEED \
  931. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  932. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  933. ADVERTISED_1000baseT_Full)
  934. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  935. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  936. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  937. static int
  938. bnx2_setup_copper_phy(struct bnx2 *bp)
  939. {
  940. u32 bmcr;
  941. u32 new_bmcr;
  942. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  943. if (bp->autoneg & AUTONEG_SPEED) {
  944. u32 adv_reg, adv1000_reg;
  945. u32 new_adv_reg = 0;
  946. u32 new_adv1000_reg = 0;
  947. bnx2_read_phy(bp, MII_ADVERTISE, &adv_reg);
  948. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  949. ADVERTISE_PAUSE_ASYM);
  950. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  951. adv1000_reg &= PHY_ALL_1000_SPEED;
  952. if (bp->advertising & ADVERTISED_10baseT_Half)
  953. new_adv_reg |= ADVERTISE_10HALF;
  954. if (bp->advertising & ADVERTISED_10baseT_Full)
  955. new_adv_reg |= ADVERTISE_10FULL;
  956. if (bp->advertising & ADVERTISED_100baseT_Half)
  957. new_adv_reg |= ADVERTISE_100HALF;
  958. if (bp->advertising & ADVERTISED_100baseT_Full)
  959. new_adv_reg |= ADVERTISE_100FULL;
  960. if (bp->advertising & ADVERTISED_1000baseT_Full)
  961. new_adv1000_reg |= ADVERTISE_1000FULL;
  962. new_adv_reg |= ADVERTISE_CSMA;
  963. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  964. if ((adv1000_reg != new_adv1000_reg) ||
  965. (adv_reg != new_adv_reg) ||
  966. ((bmcr & BMCR_ANENABLE) == 0)) {
  967. bnx2_write_phy(bp, MII_ADVERTISE, new_adv_reg);
  968. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  969. bnx2_write_phy(bp, MII_BMCR, BMCR_ANRESTART |
  970. BMCR_ANENABLE);
  971. }
  972. else if (bp->link_up) {
  973. /* Flow ctrl may have changed from auto to forced */
  974. /* or vice-versa. */
  975. bnx2_resolve_flow_ctrl(bp);
  976. bnx2_set_mac_link(bp);
  977. }
  978. return 0;
  979. }
  980. new_bmcr = 0;
  981. if (bp->req_line_speed == SPEED_100) {
  982. new_bmcr |= BMCR_SPEED100;
  983. }
  984. if (bp->req_duplex == DUPLEX_FULL) {
  985. new_bmcr |= BMCR_FULLDPLX;
  986. }
  987. if (new_bmcr != bmcr) {
  988. u32 bmsr;
  989. int i = 0;
  990. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  991. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  992. if (bmsr & BMSR_LSTATUS) {
  993. /* Force link down */
  994. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  995. do {
  996. udelay(100);
  997. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  998. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  999. i++;
  1000. } while ((bmsr & BMSR_LSTATUS) && (i < 620));
  1001. }
  1002. bnx2_write_phy(bp, MII_BMCR, new_bmcr);
  1003. /* Normally, the new speed is setup after the link has
  1004. * gone down and up again. In some cases, link will not go
  1005. * down so we need to set up the new speed here.
  1006. */
  1007. if (bmsr & BMSR_LSTATUS) {
  1008. bp->line_speed = bp->req_line_speed;
  1009. bp->duplex = bp->req_duplex;
  1010. bnx2_resolve_flow_ctrl(bp);
  1011. bnx2_set_mac_link(bp);
  1012. }
  1013. }
  1014. return 0;
  1015. }
  1016. static int
  1017. bnx2_setup_phy(struct bnx2 *bp)
  1018. {
  1019. if (bp->loopback == MAC_LOOPBACK)
  1020. return 0;
  1021. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1022. return (bnx2_setup_serdes_phy(bp));
  1023. }
  1024. else {
  1025. return (bnx2_setup_copper_phy(bp));
  1026. }
  1027. }
  1028. static int
  1029. bnx2_init_5708s_phy(struct bnx2 *bp)
  1030. {
  1031. u32 val;
  1032. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG3);
  1033. bnx2_write_phy(bp, BCM5708S_DIG_3_0, BCM5708S_DIG_3_0_USE_IEEE);
  1034. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1035. bnx2_read_phy(bp, BCM5708S_1000X_CTL1, &val);
  1036. val |= BCM5708S_1000X_CTL1_FIBER_MODE | BCM5708S_1000X_CTL1_AUTODET_EN;
  1037. bnx2_write_phy(bp, BCM5708S_1000X_CTL1, val);
  1038. bnx2_read_phy(bp, BCM5708S_1000X_CTL2, &val);
  1039. val |= BCM5708S_1000X_CTL2_PLLEL_DET_EN;
  1040. bnx2_write_phy(bp, BCM5708S_1000X_CTL2, val);
  1041. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) {
  1042. bnx2_read_phy(bp, BCM5708S_UP1, &val);
  1043. val |= BCM5708S_UP1_2G5;
  1044. bnx2_write_phy(bp, BCM5708S_UP1, val);
  1045. }
  1046. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  1047. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  1048. (CHIP_ID(bp) == CHIP_ID_5708_B1)) {
  1049. /* increase tx signal amplitude */
  1050. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1051. BCM5708S_BLK_ADDR_TX_MISC);
  1052. bnx2_read_phy(bp, BCM5708S_TX_ACTL1, &val);
  1053. val &= ~BCM5708S_TX_ACTL1_DRIVER_VCM;
  1054. bnx2_write_phy(bp, BCM5708S_TX_ACTL1, val);
  1055. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1056. }
  1057. val = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG) &
  1058. BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK;
  1059. if (val) {
  1060. u32 is_backplane;
  1061. is_backplane = REG_RD_IND(bp, bp->shmem_base +
  1062. BNX2_SHARED_HW_CFG_CONFIG);
  1063. if (is_backplane & BNX2_SHARED_HW_CFG_PHY_BACKPLANE) {
  1064. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1065. BCM5708S_BLK_ADDR_TX_MISC);
  1066. bnx2_write_phy(bp, BCM5708S_TX_ACTL3, val);
  1067. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1068. BCM5708S_BLK_ADDR_DIG);
  1069. }
  1070. }
  1071. return 0;
  1072. }
  1073. static int
  1074. bnx2_init_5706s_phy(struct bnx2 *bp)
  1075. {
  1076. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  1077. if (CHIP_NUM(bp) == CHIP_NUM_5706) {
  1078. REG_WR(bp, BNX2_MISC_UNUSED0, 0x300);
  1079. }
  1080. if (bp->dev->mtu > 1500) {
  1081. u32 val;
  1082. /* Set extended packet length bit */
  1083. bnx2_write_phy(bp, 0x18, 0x7);
  1084. bnx2_read_phy(bp, 0x18, &val);
  1085. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  1086. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1087. bnx2_read_phy(bp, 0x1c, &val);
  1088. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  1089. }
  1090. else {
  1091. u32 val;
  1092. bnx2_write_phy(bp, 0x18, 0x7);
  1093. bnx2_read_phy(bp, 0x18, &val);
  1094. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1095. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1096. bnx2_read_phy(bp, 0x1c, &val);
  1097. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  1098. }
  1099. return 0;
  1100. }
  1101. static int
  1102. bnx2_init_copper_phy(struct bnx2 *bp)
  1103. {
  1104. u32 val;
  1105. bp->phy_flags |= PHY_CRC_FIX_FLAG;
  1106. if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
  1107. bnx2_write_phy(bp, 0x18, 0x0c00);
  1108. bnx2_write_phy(bp, 0x17, 0x000a);
  1109. bnx2_write_phy(bp, 0x15, 0x310b);
  1110. bnx2_write_phy(bp, 0x17, 0x201f);
  1111. bnx2_write_phy(bp, 0x15, 0x9506);
  1112. bnx2_write_phy(bp, 0x17, 0x401f);
  1113. bnx2_write_phy(bp, 0x15, 0x14e2);
  1114. bnx2_write_phy(bp, 0x18, 0x0400);
  1115. }
  1116. if (bp->dev->mtu > 1500) {
  1117. /* Set extended packet length bit */
  1118. bnx2_write_phy(bp, 0x18, 0x7);
  1119. bnx2_read_phy(bp, 0x18, &val);
  1120. bnx2_write_phy(bp, 0x18, val | 0x4000);
  1121. bnx2_read_phy(bp, 0x10, &val);
  1122. bnx2_write_phy(bp, 0x10, val | 0x1);
  1123. }
  1124. else {
  1125. bnx2_write_phy(bp, 0x18, 0x7);
  1126. bnx2_read_phy(bp, 0x18, &val);
  1127. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1128. bnx2_read_phy(bp, 0x10, &val);
  1129. bnx2_write_phy(bp, 0x10, val & ~0x1);
  1130. }
  1131. /* ethernet@wirespeed */
  1132. bnx2_write_phy(bp, 0x18, 0x7007);
  1133. bnx2_read_phy(bp, 0x18, &val);
  1134. bnx2_write_phy(bp, 0x18, val | (1 << 15) | (1 << 4));
  1135. return 0;
  1136. }
  1137. static int
  1138. bnx2_init_phy(struct bnx2 *bp)
  1139. {
  1140. u32 val;
  1141. int rc = 0;
  1142. bp->phy_flags &= ~PHY_INT_MODE_MASK_FLAG;
  1143. bp->phy_flags |= PHY_INT_MODE_LINK_READY_FLAG;
  1144. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  1145. bnx2_reset_phy(bp);
  1146. bnx2_read_phy(bp, MII_PHYSID1, &val);
  1147. bp->phy_id = val << 16;
  1148. bnx2_read_phy(bp, MII_PHYSID2, &val);
  1149. bp->phy_id |= val & 0xffff;
  1150. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1151. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1152. rc = bnx2_init_5706s_phy(bp);
  1153. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  1154. rc = bnx2_init_5708s_phy(bp);
  1155. }
  1156. else {
  1157. rc = bnx2_init_copper_phy(bp);
  1158. }
  1159. bnx2_setup_phy(bp);
  1160. return rc;
  1161. }
  1162. static int
  1163. bnx2_set_mac_loopback(struct bnx2 *bp)
  1164. {
  1165. u32 mac_mode;
  1166. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1167. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  1168. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  1169. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1170. bp->link_up = 1;
  1171. return 0;
  1172. }
  1173. static int bnx2_test_link(struct bnx2 *);
  1174. static int
  1175. bnx2_set_phy_loopback(struct bnx2 *bp)
  1176. {
  1177. u32 mac_mode;
  1178. int rc, i;
  1179. spin_lock_bh(&bp->phy_lock);
  1180. rc = bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX |
  1181. BMCR_SPEED1000);
  1182. spin_unlock_bh(&bp->phy_lock);
  1183. if (rc)
  1184. return rc;
  1185. for (i = 0; i < 10; i++) {
  1186. if (bnx2_test_link(bp) == 0)
  1187. break;
  1188. msleep(100);
  1189. }
  1190. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1191. mac_mode &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  1192. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  1193. BNX2_EMAC_MODE_25G);
  1194. mac_mode |= BNX2_EMAC_MODE_PORT_GMII;
  1195. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1196. bp->link_up = 1;
  1197. return 0;
  1198. }
  1199. static int
  1200. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int silent)
  1201. {
  1202. int i;
  1203. u32 val;
  1204. bp->fw_wr_seq++;
  1205. msg_data |= bp->fw_wr_seq;
  1206. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1207. /* wait for an acknowledgement. */
  1208. for (i = 0; i < (FW_ACK_TIME_OUT_MS / 10); i++) {
  1209. msleep(10);
  1210. val = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_MB);
  1211. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  1212. break;
  1213. }
  1214. if ((msg_data & BNX2_DRV_MSG_DATA) == BNX2_DRV_MSG_DATA_WAIT0)
  1215. return 0;
  1216. /* If we timed out, inform the firmware that this is the case. */
  1217. if ((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) {
  1218. if (!silent)
  1219. printk(KERN_ERR PFX "fw sync timeout, reset code = "
  1220. "%x\n", msg_data);
  1221. msg_data &= ~BNX2_DRV_MSG_CODE;
  1222. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  1223. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1224. return -EBUSY;
  1225. }
  1226. if ((val & BNX2_FW_MSG_STATUS_MASK) != BNX2_FW_MSG_STATUS_OK)
  1227. return -EIO;
  1228. return 0;
  1229. }
  1230. static void
  1231. bnx2_init_context(struct bnx2 *bp)
  1232. {
  1233. u32 vcid;
  1234. vcid = 96;
  1235. while (vcid) {
  1236. u32 vcid_addr, pcid_addr, offset;
  1237. vcid--;
  1238. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  1239. u32 new_vcid;
  1240. vcid_addr = GET_PCID_ADDR(vcid);
  1241. if (vcid & 0x8) {
  1242. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  1243. }
  1244. else {
  1245. new_vcid = vcid;
  1246. }
  1247. pcid_addr = GET_PCID_ADDR(new_vcid);
  1248. }
  1249. else {
  1250. vcid_addr = GET_CID_ADDR(vcid);
  1251. pcid_addr = vcid_addr;
  1252. }
  1253. REG_WR(bp, BNX2_CTX_VIRT_ADDR, 0x00);
  1254. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1255. /* Zero out the context. */
  1256. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
  1257. CTX_WR(bp, 0x00, offset, 0);
  1258. }
  1259. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  1260. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1261. }
  1262. }
  1263. static int
  1264. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  1265. {
  1266. u16 *good_mbuf;
  1267. u32 good_mbuf_cnt;
  1268. u32 val;
  1269. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  1270. if (good_mbuf == NULL) {
  1271. printk(KERN_ERR PFX "Failed to allocate memory in "
  1272. "bnx2_alloc_bad_rbuf\n");
  1273. return -ENOMEM;
  1274. }
  1275. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1276. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  1277. good_mbuf_cnt = 0;
  1278. /* Allocate a bunch of mbufs and save the good ones in an array. */
  1279. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1280. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  1281. REG_WR_IND(bp, BNX2_RBUF_COMMAND, BNX2_RBUF_COMMAND_ALLOC_REQ);
  1282. val = REG_RD_IND(bp, BNX2_RBUF_FW_BUF_ALLOC);
  1283. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  1284. /* The addresses with Bit 9 set are bad memory blocks. */
  1285. if (!(val & (1 << 9))) {
  1286. good_mbuf[good_mbuf_cnt] = (u16) val;
  1287. good_mbuf_cnt++;
  1288. }
  1289. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1290. }
  1291. /* Free the good ones back to the mbuf pool thus discarding
  1292. * all the bad ones. */
  1293. while (good_mbuf_cnt) {
  1294. good_mbuf_cnt--;
  1295. val = good_mbuf[good_mbuf_cnt];
  1296. val = (val << 9) | val | 1;
  1297. REG_WR_IND(bp, BNX2_RBUF_FW_BUF_FREE, val);
  1298. }
  1299. kfree(good_mbuf);
  1300. return 0;
  1301. }
  1302. static void
  1303. bnx2_set_mac_addr(struct bnx2 *bp)
  1304. {
  1305. u32 val;
  1306. u8 *mac_addr = bp->dev->dev_addr;
  1307. val = (mac_addr[0] << 8) | mac_addr[1];
  1308. REG_WR(bp, BNX2_EMAC_MAC_MATCH0, val);
  1309. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  1310. (mac_addr[4] << 8) | mac_addr[5];
  1311. REG_WR(bp, BNX2_EMAC_MAC_MATCH1, val);
  1312. }
  1313. static inline int
  1314. bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
  1315. {
  1316. struct sk_buff *skb;
  1317. struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
  1318. dma_addr_t mapping;
  1319. struct rx_bd *rxbd = &bp->rx_desc_ring[RX_RING(index)][RX_IDX(index)];
  1320. unsigned long align;
  1321. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  1322. if (skb == NULL) {
  1323. return -ENOMEM;
  1324. }
  1325. if (unlikely((align = (unsigned long) skb->data & 0x7))) {
  1326. skb_reserve(skb, 8 - align);
  1327. }
  1328. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  1329. PCI_DMA_FROMDEVICE);
  1330. rx_buf->skb = skb;
  1331. pci_unmap_addr_set(rx_buf, mapping, mapping);
  1332. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  1333. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  1334. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1335. return 0;
  1336. }
  1337. static void
  1338. bnx2_phy_int(struct bnx2 *bp)
  1339. {
  1340. u32 new_link_state, old_link_state;
  1341. new_link_state = bp->status_blk->status_attn_bits &
  1342. STATUS_ATTN_BITS_LINK_STATE;
  1343. old_link_state = bp->status_blk->status_attn_bits_ack &
  1344. STATUS_ATTN_BITS_LINK_STATE;
  1345. if (new_link_state != old_link_state) {
  1346. if (new_link_state) {
  1347. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD,
  1348. STATUS_ATTN_BITS_LINK_STATE);
  1349. }
  1350. else {
  1351. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD,
  1352. STATUS_ATTN_BITS_LINK_STATE);
  1353. }
  1354. bnx2_set_link(bp);
  1355. }
  1356. }
  1357. static void
  1358. bnx2_tx_int(struct bnx2 *bp)
  1359. {
  1360. struct status_block *sblk = bp->status_blk;
  1361. u16 hw_cons, sw_cons, sw_ring_cons;
  1362. int tx_free_bd = 0;
  1363. hw_cons = bp->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
  1364. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1365. hw_cons++;
  1366. }
  1367. sw_cons = bp->tx_cons;
  1368. while (sw_cons != hw_cons) {
  1369. struct sw_bd *tx_buf;
  1370. struct sk_buff *skb;
  1371. int i, last;
  1372. sw_ring_cons = TX_RING_IDX(sw_cons);
  1373. tx_buf = &bp->tx_buf_ring[sw_ring_cons];
  1374. skb = tx_buf->skb;
  1375. #ifdef BCM_TSO
  1376. /* partial BD completions possible with TSO packets */
  1377. if (skb_is_gso(skb)) {
  1378. u16 last_idx, last_ring_idx;
  1379. last_idx = sw_cons +
  1380. skb_shinfo(skb)->nr_frags + 1;
  1381. last_ring_idx = sw_ring_cons +
  1382. skb_shinfo(skb)->nr_frags + 1;
  1383. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  1384. last_idx++;
  1385. }
  1386. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  1387. break;
  1388. }
  1389. }
  1390. #endif
  1391. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  1392. skb_headlen(skb), PCI_DMA_TODEVICE);
  1393. tx_buf->skb = NULL;
  1394. last = skb_shinfo(skb)->nr_frags;
  1395. for (i = 0; i < last; i++) {
  1396. sw_cons = NEXT_TX_BD(sw_cons);
  1397. pci_unmap_page(bp->pdev,
  1398. pci_unmap_addr(
  1399. &bp->tx_buf_ring[TX_RING_IDX(sw_cons)],
  1400. mapping),
  1401. skb_shinfo(skb)->frags[i].size,
  1402. PCI_DMA_TODEVICE);
  1403. }
  1404. sw_cons = NEXT_TX_BD(sw_cons);
  1405. tx_free_bd += last + 1;
  1406. dev_kfree_skb(skb);
  1407. hw_cons = bp->hw_tx_cons =
  1408. sblk->status_tx_quick_consumer_index0;
  1409. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1410. hw_cons++;
  1411. }
  1412. }
  1413. bp->tx_cons = sw_cons;
  1414. /* Need to make the tx_cons update visible to bnx2_start_xmit()
  1415. * before checking for netif_queue_stopped(). Without the
  1416. * memory barrier, there is a small possibility that bnx2_start_xmit()
  1417. * will miss it and cause the queue to be stopped forever.
  1418. */
  1419. smp_mb();
  1420. if (unlikely(netif_queue_stopped(bp->dev)) &&
  1421. (bnx2_tx_avail(bp) > bp->tx_wake_thresh)) {
  1422. netif_tx_lock(bp->dev);
  1423. if ((netif_queue_stopped(bp->dev)) &&
  1424. (bnx2_tx_avail(bp) > bp->tx_wake_thresh))
  1425. netif_wake_queue(bp->dev);
  1426. netif_tx_unlock(bp->dev);
  1427. }
  1428. }
  1429. static inline void
  1430. bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
  1431. u16 cons, u16 prod)
  1432. {
  1433. struct sw_bd *cons_rx_buf, *prod_rx_buf;
  1434. struct rx_bd *cons_bd, *prod_bd;
  1435. cons_rx_buf = &bp->rx_buf_ring[cons];
  1436. prod_rx_buf = &bp->rx_buf_ring[prod];
  1437. pci_dma_sync_single_for_device(bp->pdev,
  1438. pci_unmap_addr(cons_rx_buf, mapping),
  1439. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1440. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1441. prod_rx_buf->skb = skb;
  1442. if (cons == prod)
  1443. return;
  1444. pci_unmap_addr_set(prod_rx_buf, mapping,
  1445. pci_unmap_addr(cons_rx_buf, mapping));
  1446. cons_bd = &bp->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  1447. prod_bd = &bp->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  1448. prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
  1449. prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
  1450. }
  1451. static int
  1452. bnx2_rx_int(struct bnx2 *bp, int budget)
  1453. {
  1454. struct status_block *sblk = bp->status_blk;
  1455. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  1456. struct l2_fhdr *rx_hdr;
  1457. int rx_pkt = 0;
  1458. hw_cons = bp->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
  1459. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
  1460. hw_cons++;
  1461. }
  1462. sw_cons = bp->rx_cons;
  1463. sw_prod = bp->rx_prod;
  1464. /* Memory barrier necessary as speculative reads of the rx
  1465. * buffer can be ahead of the index in the status block
  1466. */
  1467. rmb();
  1468. while (sw_cons != hw_cons) {
  1469. unsigned int len;
  1470. u32 status;
  1471. struct sw_bd *rx_buf;
  1472. struct sk_buff *skb;
  1473. dma_addr_t dma_addr;
  1474. sw_ring_cons = RX_RING_IDX(sw_cons);
  1475. sw_ring_prod = RX_RING_IDX(sw_prod);
  1476. rx_buf = &bp->rx_buf_ring[sw_ring_cons];
  1477. skb = rx_buf->skb;
  1478. rx_buf->skb = NULL;
  1479. dma_addr = pci_unmap_addr(rx_buf, mapping);
  1480. pci_dma_sync_single_for_cpu(bp->pdev, dma_addr,
  1481. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1482. rx_hdr = (struct l2_fhdr *) skb->data;
  1483. len = rx_hdr->l2_fhdr_pkt_len - 4;
  1484. if ((status = rx_hdr->l2_fhdr_status) &
  1485. (L2_FHDR_ERRORS_BAD_CRC |
  1486. L2_FHDR_ERRORS_PHY_DECODE |
  1487. L2_FHDR_ERRORS_ALIGNMENT |
  1488. L2_FHDR_ERRORS_TOO_SHORT |
  1489. L2_FHDR_ERRORS_GIANT_FRAME)) {
  1490. goto reuse_rx;
  1491. }
  1492. /* Since we don't have a jumbo ring, copy small packets
  1493. * if mtu > 1500
  1494. */
  1495. if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
  1496. struct sk_buff *new_skb;
  1497. new_skb = netdev_alloc_skb(bp->dev, len + 2);
  1498. if (new_skb == NULL)
  1499. goto reuse_rx;
  1500. /* aligned copy */
  1501. memcpy(new_skb->data,
  1502. skb->data + bp->rx_offset - 2,
  1503. len + 2);
  1504. skb_reserve(new_skb, 2);
  1505. skb_put(new_skb, len);
  1506. bnx2_reuse_rx_skb(bp, skb,
  1507. sw_ring_cons, sw_ring_prod);
  1508. skb = new_skb;
  1509. }
  1510. else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
  1511. pci_unmap_single(bp->pdev, dma_addr,
  1512. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  1513. skb_reserve(skb, bp->rx_offset);
  1514. skb_put(skb, len);
  1515. }
  1516. else {
  1517. reuse_rx:
  1518. bnx2_reuse_rx_skb(bp, skb,
  1519. sw_ring_cons, sw_ring_prod);
  1520. goto next_rx;
  1521. }
  1522. skb->protocol = eth_type_trans(skb, bp->dev);
  1523. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  1524. (ntohs(skb->protocol) != 0x8100)) {
  1525. dev_kfree_skb(skb);
  1526. goto next_rx;
  1527. }
  1528. skb->ip_summed = CHECKSUM_NONE;
  1529. if (bp->rx_csum &&
  1530. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  1531. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  1532. if (likely((status & (L2_FHDR_ERRORS_TCP_XSUM |
  1533. L2_FHDR_ERRORS_UDP_XSUM)) == 0))
  1534. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1535. }
  1536. #ifdef BCM_VLAN
  1537. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) && (bp->vlgrp != 0)) {
  1538. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1539. rx_hdr->l2_fhdr_vlan_tag);
  1540. }
  1541. else
  1542. #endif
  1543. netif_receive_skb(skb);
  1544. bp->dev->last_rx = jiffies;
  1545. rx_pkt++;
  1546. next_rx:
  1547. sw_cons = NEXT_RX_BD(sw_cons);
  1548. sw_prod = NEXT_RX_BD(sw_prod);
  1549. if ((rx_pkt == budget))
  1550. break;
  1551. /* Refresh hw_cons to see if there is new work */
  1552. if (sw_cons == hw_cons) {
  1553. hw_cons = bp->hw_rx_cons =
  1554. sblk->status_rx_quick_consumer_index0;
  1555. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT)
  1556. hw_cons++;
  1557. rmb();
  1558. }
  1559. }
  1560. bp->rx_cons = sw_cons;
  1561. bp->rx_prod = sw_prod;
  1562. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, sw_prod);
  1563. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  1564. mmiowb();
  1565. return rx_pkt;
  1566. }
  1567. /* MSI ISR - The only difference between this and the INTx ISR
  1568. * is that the MSI interrupt is always serviced.
  1569. */
  1570. static irqreturn_t
  1571. bnx2_msi(int irq, void *dev_instance)
  1572. {
  1573. struct net_device *dev = dev_instance;
  1574. struct bnx2 *bp = netdev_priv(dev);
  1575. prefetch(bp->status_blk);
  1576. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1577. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1578. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1579. /* Return here if interrupt is disabled. */
  1580. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1581. return IRQ_HANDLED;
  1582. netif_rx_schedule(dev);
  1583. return IRQ_HANDLED;
  1584. }
  1585. static irqreturn_t
  1586. bnx2_interrupt(int irq, void *dev_instance)
  1587. {
  1588. struct net_device *dev = dev_instance;
  1589. struct bnx2 *bp = netdev_priv(dev);
  1590. /* When using INTx, it is possible for the interrupt to arrive
  1591. * at the CPU before the status block posted prior to the
  1592. * interrupt. Reading a register will flush the status block.
  1593. * When using MSI, the MSI message will always complete after
  1594. * the status block write.
  1595. */
  1596. if ((bp->status_blk->status_idx == bp->last_status_idx) &&
  1597. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  1598. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  1599. return IRQ_NONE;
  1600. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1601. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1602. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1603. /* Return here if interrupt is shared and is disabled. */
  1604. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1605. return IRQ_HANDLED;
  1606. netif_rx_schedule(dev);
  1607. return IRQ_HANDLED;
  1608. }
  1609. static inline int
  1610. bnx2_has_work(struct bnx2 *bp)
  1611. {
  1612. struct status_block *sblk = bp->status_blk;
  1613. if ((sblk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) ||
  1614. (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons))
  1615. return 1;
  1616. if (((sblk->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) != 0) !=
  1617. bp->link_up)
  1618. return 1;
  1619. return 0;
  1620. }
  1621. static int
  1622. bnx2_poll(struct net_device *dev, int *budget)
  1623. {
  1624. struct bnx2 *bp = netdev_priv(dev);
  1625. if ((bp->status_blk->status_attn_bits &
  1626. STATUS_ATTN_BITS_LINK_STATE) !=
  1627. (bp->status_blk->status_attn_bits_ack &
  1628. STATUS_ATTN_BITS_LINK_STATE)) {
  1629. spin_lock(&bp->phy_lock);
  1630. bnx2_phy_int(bp);
  1631. spin_unlock(&bp->phy_lock);
  1632. /* This is needed to take care of transient status
  1633. * during link changes.
  1634. */
  1635. REG_WR(bp, BNX2_HC_COMMAND,
  1636. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  1637. REG_RD(bp, BNX2_HC_COMMAND);
  1638. }
  1639. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)
  1640. bnx2_tx_int(bp);
  1641. if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) {
  1642. int orig_budget = *budget;
  1643. int work_done;
  1644. if (orig_budget > dev->quota)
  1645. orig_budget = dev->quota;
  1646. work_done = bnx2_rx_int(bp, orig_budget);
  1647. *budget -= work_done;
  1648. dev->quota -= work_done;
  1649. }
  1650. bp->last_status_idx = bp->status_blk->status_idx;
  1651. rmb();
  1652. if (!bnx2_has_work(bp)) {
  1653. netif_rx_complete(dev);
  1654. if (likely(bp->flags & USING_MSI_FLAG)) {
  1655. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1656. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1657. bp->last_status_idx);
  1658. return 0;
  1659. }
  1660. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1661. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1662. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  1663. bp->last_status_idx);
  1664. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1665. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1666. bp->last_status_idx);
  1667. return 0;
  1668. }
  1669. return 1;
  1670. }
  1671. /* Called with rtnl_lock from vlan functions and also netif_tx_lock
  1672. * from set_multicast.
  1673. */
  1674. static void
  1675. bnx2_set_rx_mode(struct net_device *dev)
  1676. {
  1677. struct bnx2 *bp = netdev_priv(dev);
  1678. u32 rx_mode, sort_mode;
  1679. int i;
  1680. spin_lock_bh(&bp->phy_lock);
  1681. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  1682. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  1683. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  1684. #ifdef BCM_VLAN
  1685. if (!bp->vlgrp && !(bp->flags & ASF_ENABLE_FLAG))
  1686. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1687. #else
  1688. if (!(bp->flags & ASF_ENABLE_FLAG))
  1689. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1690. #endif
  1691. if (dev->flags & IFF_PROMISC) {
  1692. /* Promiscuous mode. */
  1693. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  1694. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
  1695. BNX2_RPM_SORT_USER0_PROM_VLAN;
  1696. }
  1697. else if (dev->flags & IFF_ALLMULTI) {
  1698. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1699. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1700. 0xffffffff);
  1701. }
  1702. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  1703. }
  1704. else {
  1705. /* Accept one or more multicast(s). */
  1706. struct dev_mc_list *mclist;
  1707. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  1708. u32 regidx;
  1709. u32 bit;
  1710. u32 crc;
  1711. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  1712. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1713. i++, mclist = mclist->next) {
  1714. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  1715. bit = crc & 0xff;
  1716. regidx = (bit & 0xe0) >> 5;
  1717. bit &= 0x1f;
  1718. mc_filter[regidx] |= (1 << bit);
  1719. }
  1720. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1721. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1722. mc_filter[i]);
  1723. }
  1724. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  1725. }
  1726. if (rx_mode != bp->rx_mode) {
  1727. bp->rx_mode = rx_mode;
  1728. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  1729. }
  1730. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1731. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  1732. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  1733. spin_unlock_bh(&bp->phy_lock);
  1734. }
  1735. #define FW_BUF_SIZE 0x8000
  1736. static int
  1737. bnx2_gunzip_init(struct bnx2 *bp)
  1738. {
  1739. if ((bp->gunzip_buf = vmalloc(FW_BUF_SIZE)) == NULL)
  1740. goto gunzip_nomem1;
  1741. if ((bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL)) == NULL)
  1742. goto gunzip_nomem2;
  1743. bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
  1744. if (bp->strm->workspace == NULL)
  1745. goto gunzip_nomem3;
  1746. return 0;
  1747. gunzip_nomem3:
  1748. kfree(bp->strm);
  1749. bp->strm = NULL;
  1750. gunzip_nomem2:
  1751. vfree(bp->gunzip_buf);
  1752. bp->gunzip_buf = NULL;
  1753. gunzip_nomem1:
  1754. printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for "
  1755. "uncompression.\n", bp->dev->name);
  1756. return -ENOMEM;
  1757. }
  1758. static void
  1759. bnx2_gunzip_end(struct bnx2 *bp)
  1760. {
  1761. kfree(bp->strm->workspace);
  1762. kfree(bp->strm);
  1763. bp->strm = NULL;
  1764. if (bp->gunzip_buf) {
  1765. vfree(bp->gunzip_buf);
  1766. bp->gunzip_buf = NULL;
  1767. }
  1768. }
  1769. static int
  1770. bnx2_gunzip(struct bnx2 *bp, u8 *zbuf, int len, void **outbuf, int *outlen)
  1771. {
  1772. int n, rc;
  1773. /* check gzip header */
  1774. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED))
  1775. return -EINVAL;
  1776. n = 10;
  1777. #define FNAME 0x8
  1778. if (zbuf[3] & FNAME)
  1779. while ((zbuf[n++] != 0) && (n < len));
  1780. bp->strm->next_in = zbuf + n;
  1781. bp->strm->avail_in = len - n;
  1782. bp->strm->next_out = bp->gunzip_buf;
  1783. bp->strm->avail_out = FW_BUF_SIZE;
  1784. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  1785. if (rc != Z_OK)
  1786. return rc;
  1787. rc = zlib_inflate(bp->strm, Z_FINISH);
  1788. *outlen = FW_BUF_SIZE - bp->strm->avail_out;
  1789. *outbuf = bp->gunzip_buf;
  1790. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  1791. printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
  1792. bp->dev->name, bp->strm->msg);
  1793. zlib_inflateEnd(bp->strm);
  1794. if (rc == Z_STREAM_END)
  1795. return 0;
  1796. return rc;
  1797. }
  1798. static void
  1799. load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
  1800. u32 rv2p_proc)
  1801. {
  1802. int i;
  1803. u32 val;
  1804. for (i = 0; i < rv2p_code_len; i += 8) {
  1805. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, cpu_to_le32(*rv2p_code));
  1806. rv2p_code++;
  1807. REG_WR(bp, BNX2_RV2P_INSTR_LOW, cpu_to_le32(*rv2p_code));
  1808. rv2p_code++;
  1809. if (rv2p_proc == RV2P_PROC1) {
  1810. val = (i / 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  1811. REG_WR(bp, BNX2_RV2P_PROC1_ADDR_CMD, val);
  1812. }
  1813. else {
  1814. val = (i / 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  1815. REG_WR(bp, BNX2_RV2P_PROC2_ADDR_CMD, val);
  1816. }
  1817. }
  1818. /* Reset the processor, un-stall is done later. */
  1819. if (rv2p_proc == RV2P_PROC1) {
  1820. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  1821. }
  1822. else {
  1823. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  1824. }
  1825. }
  1826. static void
  1827. load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
  1828. {
  1829. u32 offset;
  1830. u32 val;
  1831. /* Halt the CPU. */
  1832. val = REG_RD_IND(bp, cpu_reg->mode);
  1833. val |= cpu_reg->mode_value_halt;
  1834. REG_WR_IND(bp, cpu_reg->mode, val);
  1835. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1836. /* Load the Text area. */
  1837. offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
  1838. if (fw->text) {
  1839. int j;
  1840. for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
  1841. REG_WR_IND(bp, offset, cpu_to_le32(fw->text[j]));
  1842. }
  1843. }
  1844. /* Load the Data area. */
  1845. offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
  1846. if (fw->data) {
  1847. int j;
  1848. for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
  1849. REG_WR_IND(bp, offset, fw->data[j]);
  1850. }
  1851. }
  1852. /* Load the SBSS area. */
  1853. offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
  1854. if (fw->sbss) {
  1855. int j;
  1856. for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
  1857. REG_WR_IND(bp, offset, fw->sbss[j]);
  1858. }
  1859. }
  1860. /* Load the BSS area. */
  1861. offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
  1862. if (fw->bss) {
  1863. int j;
  1864. for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
  1865. REG_WR_IND(bp, offset, fw->bss[j]);
  1866. }
  1867. }
  1868. /* Load the Read-Only area. */
  1869. offset = cpu_reg->spad_base +
  1870. (fw->rodata_addr - cpu_reg->mips_view_base);
  1871. if (fw->rodata) {
  1872. int j;
  1873. for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
  1874. REG_WR_IND(bp, offset, fw->rodata[j]);
  1875. }
  1876. }
  1877. /* Clear the pre-fetch instruction. */
  1878. REG_WR_IND(bp, cpu_reg->inst, 0);
  1879. REG_WR_IND(bp, cpu_reg->pc, fw->start_addr);
  1880. /* Start the CPU. */
  1881. val = REG_RD_IND(bp, cpu_reg->mode);
  1882. val &= ~cpu_reg->mode_value_halt;
  1883. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1884. REG_WR_IND(bp, cpu_reg->mode, val);
  1885. }
  1886. static int
  1887. bnx2_init_cpus(struct bnx2 *bp)
  1888. {
  1889. struct cpu_reg cpu_reg;
  1890. struct fw_info fw;
  1891. int rc = 0;
  1892. void *text;
  1893. u32 text_len;
  1894. if ((rc = bnx2_gunzip_init(bp)) != 0)
  1895. return rc;
  1896. /* Initialize the RV2P processor. */
  1897. rc = bnx2_gunzip(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), &text,
  1898. &text_len);
  1899. if (rc)
  1900. goto init_cpu_err;
  1901. load_rv2p_fw(bp, text, text_len, RV2P_PROC1);
  1902. rc = bnx2_gunzip(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), &text,
  1903. &text_len);
  1904. if (rc)
  1905. goto init_cpu_err;
  1906. load_rv2p_fw(bp, text, text_len, RV2P_PROC2);
  1907. /* Initialize the RX Processor. */
  1908. cpu_reg.mode = BNX2_RXP_CPU_MODE;
  1909. cpu_reg.mode_value_halt = BNX2_RXP_CPU_MODE_SOFT_HALT;
  1910. cpu_reg.mode_value_sstep = BNX2_RXP_CPU_MODE_STEP_ENA;
  1911. cpu_reg.state = BNX2_RXP_CPU_STATE;
  1912. cpu_reg.state_value_clear = 0xffffff;
  1913. cpu_reg.gpr0 = BNX2_RXP_CPU_REG_FILE;
  1914. cpu_reg.evmask = BNX2_RXP_CPU_EVENT_MASK;
  1915. cpu_reg.pc = BNX2_RXP_CPU_PROGRAM_COUNTER;
  1916. cpu_reg.inst = BNX2_RXP_CPU_INSTRUCTION;
  1917. cpu_reg.bp = BNX2_RXP_CPU_HW_BREAKPOINT;
  1918. cpu_reg.spad_base = BNX2_RXP_SCRATCH;
  1919. cpu_reg.mips_view_base = 0x8000000;
  1920. fw.ver_major = bnx2_RXP_b06FwReleaseMajor;
  1921. fw.ver_minor = bnx2_RXP_b06FwReleaseMinor;
  1922. fw.ver_fix = bnx2_RXP_b06FwReleaseFix;
  1923. fw.start_addr = bnx2_RXP_b06FwStartAddr;
  1924. fw.text_addr = bnx2_RXP_b06FwTextAddr;
  1925. fw.text_len = bnx2_RXP_b06FwTextLen;
  1926. fw.text_index = 0;
  1927. rc = bnx2_gunzip(bp, bnx2_RXP_b06FwText, sizeof(bnx2_RXP_b06FwText),
  1928. &text, &text_len);
  1929. if (rc)
  1930. goto init_cpu_err;
  1931. fw.text = text;
  1932. fw.data_addr = bnx2_RXP_b06FwDataAddr;
  1933. fw.data_len = bnx2_RXP_b06FwDataLen;
  1934. fw.data_index = 0;
  1935. fw.data = bnx2_RXP_b06FwData;
  1936. fw.sbss_addr = bnx2_RXP_b06FwSbssAddr;
  1937. fw.sbss_len = bnx2_RXP_b06FwSbssLen;
  1938. fw.sbss_index = 0;
  1939. fw.sbss = bnx2_RXP_b06FwSbss;
  1940. fw.bss_addr = bnx2_RXP_b06FwBssAddr;
  1941. fw.bss_len = bnx2_RXP_b06FwBssLen;
  1942. fw.bss_index = 0;
  1943. fw.bss = bnx2_RXP_b06FwBss;
  1944. fw.rodata_addr = bnx2_RXP_b06FwRodataAddr;
  1945. fw.rodata_len = bnx2_RXP_b06FwRodataLen;
  1946. fw.rodata_index = 0;
  1947. fw.rodata = bnx2_RXP_b06FwRodata;
  1948. load_cpu_fw(bp, &cpu_reg, &fw);
  1949. /* Initialize the TX Processor. */
  1950. cpu_reg.mode = BNX2_TXP_CPU_MODE;
  1951. cpu_reg.mode_value_halt = BNX2_TXP_CPU_MODE_SOFT_HALT;
  1952. cpu_reg.mode_value_sstep = BNX2_TXP_CPU_MODE_STEP_ENA;
  1953. cpu_reg.state = BNX2_TXP_CPU_STATE;
  1954. cpu_reg.state_value_clear = 0xffffff;
  1955. cpu_reg.gpr0 = BNX2_TXP_CPU_REG_FILE;
  1956. cpu_reg.evmask = BNX2_TXP_CPU_EVENT_MASK;
  1957. cpu_reg.pc = BNX2_TXP_CPU_PROGRAM_COUNTER;
  1958. cpu_reg.inst = BNX2_TXP_CPU_INSTRUCTION;
  1959. cpu_reg.bp = BNX2_TXP_CPU_HW_BREAKPOINT;
  1960. cpu_reg.spad_base = BNX2_TXP_SCRATCH;
  1961. cpu_reg.mips_view_base = 0x8000000;
  1962. fw.ver_major = bnx2_TXP_b06FwReleaseMajor;
  1963. fw.ver_minor = bnx2_TXP_b06FwReleaseMinor;
  1964. fw.ver_fix = bnx2_TXP_b06FwReleaseFix;
  1965. fw.start_addr = bnx2_TXP_b06FwStartAddr;
  1966. fw.text_addr = bnx2_TXP_b06FwTextAddr;
  1967. fw.text_len = bnx2_TXP_b06FwTextLen;
  1968. fw.text_index = 0;
  1969. rc = bnx2_gunzip(bp, bnx2_TXP_b06FwText, sizeof(bnx2_TXP_b06FwText),
  1970. &text, &text_len);
  1971. if (rc)
  1972. goto init_cpu_err;
  1973. fw.text = text;
  1974. fw.data_addr = bnx2_TXP_b06FwDataAddr;
  1975. fw.data_len = bnx2_TXP_b06FwDataLen;
  1976. fw.data_index = 0;
  1977. fw.data = bnx2_TXP_b06FwData;
  1978. fw.sbss_addr = bnx2_TXP_b06FwSbssAddr;
  1979. fw.sbss_len = bnx2_TXP_b06FwSbssLen;
  1980. fw.sbss_index = 0;
  1981. fw.sbss = bnx2_TXP_b06FwSbss;
  1982. fw.bss_addr = bnx2_TXP_b06FwBssAddr;
  1983. fw.bss_len = bnx2_TXP_b06FwBssLen;
  1984. fw.bss_index = 0;
  1985. fw.bss = bnx2_TXP_b06FwBss;
  1986. fw.rodata_addr = bnx2_TXP_b06FwRodataAddr;
  1987. fw.rodata_len = bnx2_TXP_b06FwRodataLen;
  1988. fw.rodata_index = 0;
  1989. fw.rodata = bnx2_TXP_b06FwRodata;
  1990. load_cpu_fw(bp, &cpu_reg, &fw);
  1991. /* Initialize the TX Patch-up Processor. */
  1992. cpu_reg.mode = BNX2_TPAT_CPU_MODE;
  1993. cpu_reg.mode_value_halt = BNX2_TPAT_CPU_MODE_SOFT_HALT;
  1994. cpu_reg.mode_value_sstep = BNX2_TPAT_CPU_MODE_STEP_ENA;
  1995. cpu_reg.state = BNX2_TPAT_CPU_STATE;
  1996. cpu_reg.state_value_clear = 0xffffff;
  1997. cpu_reg.gpr0 = BNX2_TPAT_CPU_REG_FILE;
  1998. cpu_reg.evmask = BNX2_TPAT_CPU_EVENT_MASK;
  1999. cpu_reg.pc = BNX2_TPAT_CPU_PROGRAM_COUNTER;
  2000. cpu_reg.inst = BNX2_TPAT_CPU_INSTRUCTION;
  2001. cpu_reg.bp = BNX2_TPAT_CPU_HW_BREAKPOINT;
  2002. cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
  2003. cpu_reg.mips_view_base = 0x8000000;
  2004. fw.ver_major = bnx2_TPAT_b06FwReleaseMajor;
  2005. fw.ver_minor = bnx2_TPAT_b06FwReleaseMinor;
  2006. fw.ver_fix = bnx2_TPAT_b06FwReleaseFix;
  2007. fw.start_addr = bnx2_TPAT_b06FwStartAddr;
  2008. fw.text_addr = bnx2_TPAT_b06FwTextAddr;
  2009. fw.text_len = bnx2_TPAT_b06FwTextLen;
  2010. fw.text_index = 0;
  2011. rc = bnx2_gunzip(bp, bnx2_TPAT_b06FwText, sizeof(bnx2_TPAT_b06FwText),
  2012. &text, &text_len);
  2013. if (rc)
  2014. goto init_cpu_err;
  2015. fw.text = text;
  2016. fw.data_addr = bnx2_TPAT_b06FwDataAddr;
  2017. fw.data_len = bnx2_TPAT_b06FwDataLen;
  2018. fw.data_index = 0;
  2019. fw.data = bnx2_TPAT_b06FwData;
  2020. fw.sbss_addr = bnx2_TPAT_b06FwSbssAddr;
  2021. fw.sbss_len = bnx2_TPAT_b06FwSbssLen;
  2022. fw.sbss_index = 0;
  2023. fw.sbss = bnx2_TPAT_b06FwSbss;
  2024. fw.bss_addr = bnx2_TPAT_b06FwBssAddr;
  2025. fw.bss_len = bnx2_TPAT_b06FwBssLen;
  2026. fw.bss_index = 0;
  2027. fw.bss = bnx2_TPAT_b06FwBss;
  2028. fw.rodata_addr = bnx2_TPAT_b06FwRodataAddr;
  2029. fw.rodata_len = bnx2_TPAT_b06FwRodataLen;
  2030. fw.rodata_index = 0;
  2031. fw.rodata = bnx2_TPAT_b06FwRodata;
  2032. load_cpu_fw(bp, &cpu_reg, &fw);
  2033. /* Initialize the Completion Processor. */
  2034. cpu_reg.mode = BNX2_COM_CPU_MODE;
  2035. cpu_reg.mode_value_halt = BNX2_COM_CPU_MODE_SOFT_HALT;
  2036. cpu_reg.mode_value_sstep = BNX2_COM_CPU_MODE_STEP_ENA;
  2037. cpu_reg.state = BNX2_COM_CPU_STATE;
  2038. cpu_reg.state_value_clear = 0xffffff;
  2039. cpu_reg.gpr0 = BNX2_COM_CPU_REG_FILE;
  2040. cpu_reg.evmask = BNX2_COM_CPU_EVENT_MASK;
  2041. cpu_reg.pc = BNX2_COM_CPU_PROGRAM_COUNTER;
  2042. cpu_reg.inst = BNX2_COM_CPU_INSTRUCTION;
  2043. cpu_reg.bp = BNX2_COM_CPU_HW_BREAKPOINT;
  2044. cpu_reg.spad_base = BNX2_COM_SCRATCH;
  2045. cpu_reg.mips_view_base = 0x8000000;
  2046. fw.ver_major = bnx2_COM_b06FwReleaseMajor;
  2047. fw.ver_minor = bnx2_COM_b06FwReleaseMinor;
  2048. fw.ver_fix = bnx2_COM_b06FwReleaseFix;
  2049. fw.start_addr = bnx2_COM_b06FwStartAddr;
  2050. fw.text_addr = bnx2_COM_b06FwTextAddr;
  2051. fw.text_len = bnx2_COM_b06FwTextLen;
  2052. fw.text_index = 0;
  2053. rc = bnx2_gunzip(bp, bnx2_COM_b06FwText, sizeof(bnx2_COM_b06FwText),
  2054. &text, &text_len);
  2055. if (rc)
  2056. goto init_cpu_err;
  2057. fw.text = text;
  2058. fw.data_addr = bnx2_COM_b06FwDataAddr;
  2059. fw.data_len = bnx2_COM_b06FwDataLen;
  2060. fw.data_index = 0;
  2061. fw.data = bnx2_COM_b06FwData;
  2062. fw.sbss_addr = bnx2_COM_b06FwSbssAddr;
  2063. fw.sbss_len = bnx2_COM_b06FwSbssLen;
  2064. fw.sbss_index = 0;
  2065. fw.sbss = bnx2_COM_b06FwSbss;
  2066. fw.bss_addr = bnx2_COM_b06FwBssAddr;
  2067. fw.bss_len = bnx2_COM_b06FwBssLen;
  2068. fw.bss_index = 0;
  2069. fw.bss = bnx2_COM_b06FwBss;
  2070. fw.rodata_addr = bnx2_COM_b06FwRodataAddr;
  2071. fw.rodata_len = bnx2_COM_b06FwRodataLen;
  2072. fw.rodata_index = 0;
  2073. fw.rodata = bnx2_COM_b06FwRodata;
  2074. load_cpu_fw(bp, &cpu_reg, &fw);
  2075. init_cpu_err:
  2076. bnx2_gunzip_end(bp);
  2077. return rc;
  2078. }
  2079. static int
  2080. bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
  2081. {
  2082. u16 pmcsr;
  2083. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  2084. switch (state) {
  2085. case PCI_D0: {
  2086. u32 val;
  2087. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  2088. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  2089. PCI_PM_CTRL_PME_STATUS);
  2090. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  2091. /* delay required during transition out of D3hot */
  2092. msleep(20);
  2093. val = REG_RD(bp, BNX2_EMAC_MODE);
  2094. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  2095. val &= ~BNX2_EMAC_MODE_MPKT;
  2096. REG_WR(bp, BNX2_EMAC_MODE, val);
  2097. val = REG_RD(bp, BNX2_RPM_CONFIG);
  2098. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  2099. REG_WR(bp, BNX2_RPM_CONFIG, val);
  2100. break;
  2101. }
  2102. case PCI_D3hot: {
  2103. int i;
  2104. u32 val, wol_msg;
  2105. if (bp->wol) {
  2106. u32 advertising;
  2107. u8 autoneg;
  2108. autoneg = bp->autoneg;
  2109. advertising = bp->advertising;
  2110. bp->autoneg = AUTONEG_SPEED;
  2111. bp->advertising = ADVERTISED_10baseT_Half |
  2112. ADVERTISED_10baseT_Full |
  2113. ADVERTISED_100baseT_Half |
  2114. ADVERTISED_100baseT_Full |
  2115. ADVERTISED_Autoneg;
  2116. bnx2_setup_copper_phy(bp);
  2117. bp->autoneg = autoneg;
  2118. bp->advertising = advertising;
  2119. bnx2_set_mac_addr(bp);
  2120. val = REG_RD(bp, BNX2_EMAC_MODE);
  2121. /* Enable port mode. */
  2122. val &= ~BNX2_EMAC_MODE_PORT;
  2123. val |= BNX2_EMAC_MODE_PORT_MII |
  2124. BNX2_EMAC_MODE_MPKT_RCVD |
  2125. BNX2_EMAC_MODE_ACPI_RCVD |
  2126. BNX2_EMAC_MODE_MPKT;
  2127. REG_WR(bp, BNX2_EMAC_MODE, val);
  2128. /* receive all multicast */
  2129. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2130. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2131. 0xffffffff);
  2132. }
  2133. REG_WR(bp, BNX2_EMAC_RX_MODE,
  2134. BNX2_EMAC_RX_MODE_SORT_MODE);
  2135. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  2136. BNX2_RPM_SORT_USER0_MC_EN;
  2137. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  2138. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  2139. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  2140. BNX2_RPM_SORT_USER0_ENA);
  2141. /* Need to enable EMAC and RPM for WOL. */
  2142. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2143. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  2144. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  2145. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  2146. val = REG_RD(bp, BNX2_RPM_CONFIG);
  2147. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  2148. REG_WR(bp, BNX2_RPM_CONFIG, val);
  2149. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  2150. }
  2151. else {
  2152. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  2153. }
  2154. if (!(bp->flags & NO_WOL_FLAG))
  2155. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 0);
  2156. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  2157. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2158. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  2159. if (bp->wol)
  2160. pmcsr |= 3;
  2161. }
  2162. else {
  2163. pmcsr |= 3;
  2164. }
  2165. if (bp->wol) {
  2166. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  2167. }
  2168. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  2169. pmcsr);
  2170. /* No more memory access after this point until
  2171. * device is brought back to D0.
  2172. */
  2173. udelay(50);
  2174. break;
  2175. }
  2176. default:
  2177. return -EINVAL;
  2178. }
  2179. return 0;
  2180. }
  2181. static int
  2182. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  2183. {
  2184. u32 val;
  2185. int j;
  2186. /* Request access to the flash interface. */
  2187. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  2188. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2189. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2190. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  2191. break;
  2192. udelay(5);
  2193. }
  2194. if (j >= NVRAM_TIMEOUT_COUNT)
  2195. return -EBUSY;
  2196. return 0;
  2197. }
  2198. static int
  2199. bnx2_release_nvram_lock(struct bnx2 *bp)
  2200. {
  2201. int j;
  2202. u32 val;
  2203. /* Relinquish nvram interface. */
  2204. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  2205. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2206. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2207. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  2208. break;
  2209. udelay(5);
  2210. }
  2211. if (j >= NVRAM_TIMEOUT_COUNT)
  2212. return -EBUSY;
  2213. return 0;
  2214. }
  2215. static int
  2216. bnx2_enable_nvram_write(struct bnx2 *bp)
  2217. {
  2218. u32 val;
  2219. val = REG_RD(bp, BNX2_MISC_CFG);
  2220. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  2221. if (!bp->flash_info->buffered) {
  2222. int j;
  2223. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2224. REG_WR(bp, BNX2_NVM_COMMAND,
  2225. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  2226. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2227. udelay(5);
  2228. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2229. if (val & BNX2_NVM_COMMAND_DONE)
  2230. break;
  2231. }
  2232. if (j >= NVRAM_TIMEOUT_COUNT)
  2233. return -EBUSY;
  2234. }
  2235. return 0;
  2236. }
  2237. static void
  2238. bnx2_disable_nvram_write(struct bnx2 *bp)
  2239. {
  2240. u32 val;
  2241. val = REG_RD(bp, BNX2_MISC_CFG);
  2242. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  2243. }
  2244. static void
  2245. bnx2_enable_nvram_access(struct bnx2 *bp)
  2246. {
  2247. u32 val;
  2248. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2249. /* Enable both bits, even on read. */
  2250. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2251. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  2252. }
  2253. static void
  2254. bnx2_disable_nvram_access(struct bnx2 *bp)
  2255. {
  2256. u32 val;
  2257. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2258. /* Disable both bits, even after read. */
  2259. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2260. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  2261. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  2262. }
  2263. static int
  2264. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  2265. {
  2266. u32 cmd;
  2267. int j;
  2268. if (bp->flash_info->buffered)
  2269. /* Buffered flash, no erase needed */
  2270. return 0;
  2271. /* Build an erase command */
  2272. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  2273. BNX2_NVM_COMMAND_DOIT;
  2274. /* Need to clear DONE bit separately. */
  2275. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2276. /* Address of the NVRAM to read from. */
  2277. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2278. /* Issue an erase command. */
  2279. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2280. /* Wait for completion. */
  2281. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2282. u32 val;
  2283. udelay(5);
  2284. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2285. if (val & BNX2_NVM_COMMAND_DONE)
  2286. break;
  2287. }
  2288. if (j >= NVRAM_TIMEOUT_COUNT)
  2289. return -EBUSY;
  2290. return 0;
  2291. }
  2292. static int
  2293. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  2294. {
  2295. u32 cmd;
  2296. int j;
  2297. /* Build the command word. */
  2298. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  2299. /* Calculate an offset of a buffered flash. */
  2300. if (bp->flash_info->buffered) {
  2301. offset = ((offset / bp->flash_info->page_size) <<
  2302. bp->flash_info->page_bits) +
  2303. (offset % bp->flash_info->page_size);
  2304. }
  2305. /* Need to clear DONE bit separately. */
  2306. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2307. /* Address of the NVRAM to read from. */
  2308. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2309. /* Issue a read command. */
  2310. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2311. /* Wait for completion. */
  2312. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2313. u32 val;
  2314. udelay(5);
  2315. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2316. if (val & BNX2_NVM_COMMAND_DONE) {
  2317. val = REG_RD(bp, BNX2_NVM_READ);
  2318. val = be32_to_cpu(val);
  2319. memcpy(ret_val, &val, 4);
  2320. break;
  2321. }
  2322. }
  2323. if (j >= NVRAM_TIMEOUT_COUNT)
  2324. return -EBUSY;
  2325. return 0;
  2326. }
  2327. static int
  2328. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  2329. {
  2330. u32 cmd, val32;
  2331. int j;
  2332. /* Build the command word. */
  2333. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  2334. /* Calculate an offset of a buffered flash. */
  2335. if (bp->flash_info->buffered) {
  2336. offset = ((offset / bp->flash_info->page_size) <<
  2337. bp->flash_info->page_bits) +
  2338. (offset % bp->flash_info->page_size);
  2339. }
  2340. /* Need to clear DONE bit separately. */
  2341. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2342. memcpy(&val32, val, 4);
  2343. val32 = cpu_to_be32(val32);
  2344. /* Write the data. */
  2345. REG_WR(bp, BNX2_NVM_WRITE, val32);
  2346. /* Address of the NVRAM to write to. */
  2347. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2348. /* Issue the write command. */
  2349. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2350. /* Wait for completion. */
  2351. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2352. udelay(5);
  2353. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  2354. break;
  2355. }
  2356. if (j >= NVRAM_TIMEOUT_COUNT)
  2357. return -EBUSY;
  2358. return 0;
  2359. }
  2360. static int
  2361. bnx2_init_nvram(struct bnx2 *bp)
  2362. {
  2363. u32 val;
  2364. int j, entry_count, rc;
  2365. struct flash_spec *flash;
  2366. /* Determine the selected interface. */
  2367. val = REG_RD(bp, BNX2_NVM_CFG1);
  2368. entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
  2369. rc = 0;
  2370. if (val & 0x40000000) {
  2371. /* Flash interface has been reconfigured */
  2372. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2373. j++, flash++) {
  2374. if ((val & FLASH_BACKUP_STRAP_MASK) ==
  2375. (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
  2376. bp->flash_info = flash;
  2377. break;
  2378. }
  2379. }
  2380. }
  2381. else {
  2382. u32 mask;
  2383. /* Not yet been reconfigured */
  2384. if (val & (1 << 23))
  2385. mask = FLASH_BACKUP_STRAP_MASK;
  2386. else
  2387. mask = FLASH_STRAP_MASK;
  2388. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2389. j++, flash++) {
  2390. if ((val & mask) == (flash->strapping & mask)) {
  2391. bp->flash_info = flash;
  2392. /* Request access to the flash interface. */
  2393. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2394. return rc;
  2395. /* Enable access to flash interface */
  2396. bnx2_enable_nvram_access(bp);
  2397. /* Reconfigure the flash interface */
  2398. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  2399. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  2400. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  2401. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  2402. /* Disable access to flash interface */
  2403. bnx2_disable_nvram_access(bp);
  2404. bnx2_release_nvram_lock(bp);
  2405. break;
  2406. }
  2407. }
  2408. } /* if (val & 0x40000000) */
  2409. if (j == entry_count) {
  2410. bp->flash_info = NULL;
  2411. printk(KERN_ALERT PFX "Unknown flash/EEPROM type.\n");
  2412. return -ENODEV;
  2413. }
  2414. val = REG_RD_IND(bp, bp->shmem_base + BNX2_SHARED_HW_CFG_CONFIG2);
  2415. val &= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK;
  2416. if (val)
  2417. bp->flash_size = val;
  2418. else
  2419. bp->flash_size = bp->flash_info->total_size;
  2420. return rc;
  2421. }
  2422. static int
  2423. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  2424. int buf_size)
  2425. {
  2426. int rc = 0;
  2427. u32 cmd_flags, offset32, len32, extra;
  2428. if (buf_size == 0)
  2429. return 0;
  2430. /* Request access to the flash interface. */
  2431. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2432. return rc;
  2433. /* Enable access to flash interface */
  2434. bnx2_enable_nvram_access(bp);
  2435. len32 = buf_size;
  2436. offset32 = offset;
  2437. extra = 0;
  2438. cmd_flags = 0;
  2439. if (offset32 & 3) {
  2440. u8 buf[4];
  2441. u32 pre_len;
  2442. offset32 &= ~3;
  2443. pre_len = 4 - (offset & 3);
  2444. if (pre_len >= len32) {
  2445. pre_len = len32;
  2446. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2447. BNX2_NVM_COMMAND_LAST;
  2448. }
  2449. else {
  2450. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2451. }
  2452. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2453. if (rc)
  2454. return rc;
  2455. memcpy(ret_buf, buf + (offset & 3), pre_len);
  2456. offset32 += 4;
  2457. ret_buf += pre_len;
  2458. len32 -= pre_len;
  2459. }
  2460. if (len32 & 3) {
  2461. extra = 4 - (len32 & 3);
  2462. len32 = (len32 + 4) & ~3;
  2463. }
  2464. if (len32 == 4) {
  2465. u8 buf[4];
  2466. if (cmd_flags)
  2467. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2468. else
  2469. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2470. BNX2_NVM_COMMAND_LAST;
  2471. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2472. memcpy(ret_buf, buf, 4 - extra);
  2473. }
  2474. else if (len32 > 0) {
  2475. u8 buf[4];
  2476. /* Read the first word. */
  2477. if (cmd_flags)
  2478. cmd_flags = 0;
  2479. else
  2480. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2481. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  2482. /* Advance to the next dword. */
  2483. offset32 += 4;
  2484. ret_buf += 4;
  2485. len32 -= 4;
  2486. while (len32 > 4 && rc == 0) {
  2487. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  2488. /* Advance to the next dword. */
  2489. offset32 += 4;
  2490. ret_buf += 4;
  2491. len32 -= 4;
  2492. }
  2493. if (rc)
  2494. return rc;
  2495. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2496. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2497. memcpy(ret_buf, buf, 4 - extra);
  2498. }
  2499. /* Disable access to flash interface */
  2500. bnx2_disable_nvram_access(bp);
  2501. bnx2_release_nvram_lock(bp);
  2502. return rc;
  2503. }
  2504. static int
  2505. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  2506. int buf_size)
  2507. {
  2508. u32 written, offset32, len32;
  2509. u8 *buf, start[4], end[4], *flash_buffer = NULL;
  2510. int rc = 0;
  2511. int align_start, align_end;
  2512. buf = data_buf;
  2513. offset32 = offset;
  2514. len32 = buf_size;
  2515. align_start = align_end = 0;
  2516. if ((align_start = (offset32 & 3))) {
  2517. offset32 &= ~3;
  2518. len32 += align_start;
  2519. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  2520. return rc;
  2521. }
  2522. if (len32 & 3) {
  2523. if ((len32 > 4) || !align_start) {
  2524. align_end = 4 - (len32 & 3);
  2525. len32 += align_end;
  2526. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4,
  2527. end, 4))) {
  2528. return rc;
  2529. }
  2530. }
  2531. }
  2532. if (align_start || align_end) {
  2533. buf = kmalloc(len32, GFP_KERNEL);
  2534. if (buf == 0)
  2535. return -ENOMEM;
  2536. if (align_start) {
  2537. memcpy(buf, start, 4);
  2538. }
  2539. if (align_end) {
  2540. memcpy(buf + len32 - 4, end, 4);
  2541. }
  2542. memcpy(buf + align_start, data_buf, buf_size);
  2543. }
  2544. if (bp->flash_info->buffered == 0) {
  2545. flash_buffer = kmalloc(264, GFP_KERNEL);
  2546. if (flash_buffer == NULL) {
  2547. rc = -ENOMEM;
  2548. goto nvram_write_end;
  2549. }
  2550. }
  2551. written = 0;
  2552. while ((written < len32) && (rc == 0)) {
  2553. u32 page_start, page_end, data_start, data_end;
  2554. u32 addr, cmd_flags;
  2555. int i;
  2556. /* Find the page_start addr */
  2557. page_start = offset32 + written;
  2558. page_start -= (page_start % bp->flash_info->page_size);
  2559. /* Find the page_end addr */
  2560. page_end = page_start + bp->flash_info->page_size;
  2561. /* Find the data_start addr */
  2562. data_start = (written == 0) ? offset32 : page_start;
  2563. /* Find the data_end addr */
  2564. data_end = (page_end > offset32 + len32) ?
  2565. (offset32 + len32) : page_end;
  2566. /* Request access to the flash interface. */
  2567. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2568. goto nvram_write_end;
  2569. /* Enable access to flash interface */
  2570. bnx2_enable_nvram_access(bp);
  2571. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2572. if (bp->flash_info->buffered == 0) {
  2573. int j;
  2574. /* Read the whole page into the buffer
  2575. * (non-buffer flash only) */
  2576. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  2577. if (j == (bp->flash_info->page_size - 4)) {
  2578. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2579. }
  2580. rc = bnx2_nvram_read_dword(bp,
  2581. page_start + j,
  2582. &flash_buffer[j],
  2583. cmd_flags);
  2584. if (rc)
  2585. goto nvram_write_end;
  2586. cmd_flags = 0;
  2587. }
  2588. }
  2589. /* Enable writes to flash interface (unlock write-protect) */
  2590. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  2591. goto nvram_write_end;
  2592. /* Erase the page */
  2593. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  2594. goto nvram_write_end;
  2595. /* Re-enable the write again for the actual write */
  2596. bnx2_enable_nvram_write(bp);
  2597. /* Loop to write back the buffer data from page_start to
  2598. * data_start */
  2599. i = 0;
  2600. if (bp->flash_info->buffered == 0) {
  2601. for (addr = page_start; addr < data_start;
  2602. addr += 4, i += 4) {
  2603. rc = bnx2_nvram_write_dword(bp, addr,
  2604. &flash_buffer[i], cmd_flags);
  2605. if (rc != 0)
  2606. goto nvram_write_end;
  2607. cmd_flags = 0;
  2608. }
  2609. }
  2610. /* Loop to write the new data from data_start to data_end */
  2611. for (addr = data_start; addr < data_end; addr += 4, i += 4) {
  2612. if ((addr == page_end - 4) ||
  2613. ((bp->flash_info->buffered) &&
  2614. (addr == data_end - 4))) {
  2615. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2616. }
  2617. rc = bnx2_nvram_write_dword(bp, addr, buf,
  2618. cmd_flags);
  2619. if (rc != 0)
  2620. goto nvram_write_end;
  2621. cmd_flags = 0;
  2622. buf += 4;
  2623. }
  2624. /* Loop to write back the buffer data from data_end
  2625. * to page_end */
  2626. if (bp->flash_info->buffered == 0) {
  2627. for (addr = data_end; addr < page_end;
  2628. addr += 4, i += 4) {
  2629. if (addr == page_end-4) {
  2630. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2631. }
  2632. rc = bnx2_nvram_write_dword(bp, addr,
  2633. &flash_buffer[i], cmd_flags);
  2634. if (rc != 0)
  2635. goto nvram_write_end;
  2636. cmd_flags = 0;
  2637. }
  2638. }
  2639. /* Disable writes to flash interface (lock write-protect) */
  2640. bnx2_disable_nvram_write(bp);
  2641. /* Disable access to flash interface */
  2642. bnx2_disable_nvram_access(bp);
  2643. bnx2_release_nvram_lock(bp);
  2644. /* Increment written */
  2645. written += data_end - data_start;
  2646. }
  2647. nvram_write_end:
  2648. if (bp->flash_info->buffered == 0)
  2649. kfree(flash_buffer);
  2650. if (align_start || align_end)
  2651. kfree(buf);
  2652. return rc;
  2653. }
  2654. static int
  2655. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  2656. {
  2657. u32 val;
  2658. int i, rc = 0;
  2659. /* Wait for the current PCI transaction to complete before
  2660. * issuing a reset. */
  2661. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  2662. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  2663. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  2664. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  2665. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  2666. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  2667. udelay(5);
  2668. /* Wait for the firmware to tell us it is ok to issue a reset. */
  2669. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1);
  2670. /* Deposit a driver reset signature so the firmware knows that
  2671. * this is a soft reset. */
  2672. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_RESET_SIGNATURE,
  2673. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  2674. /* Do a dummy read to force the chip to complete all current transaction
  2675. * before we issue a reset. */
  2676. val = REG_RD(bp, BNX2_MISC_ID);
  2677. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2678. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2679. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2680. /* Chip reset. */
  2681. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  2682. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2683. (CHIP_ID(bp) == CHIP_ID_5706_A1))
  2684. msleep(15);
  2685. /* Reset takes approximate 30 usec */
  2686. for (i = 0; i < 10; i++) {
  2687. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  2688. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2689. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
  2690. break;
  2691. }
  2692. udelay(10);
  2693. }
  2694. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2695. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  2696. printk(KERN_ERR PFX "Chip reset did not complete\n");
  2697. return -EBUSY;
  2698. }
  2699. /* Make sure byte swapping is properly configured. */
  2700. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  2701. if (val != 0x01020304) {
  2702. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  2703. return -ENODEV;
  2704. }
  2705. /* Wait for the firmware to finish its initialization. */
  2706. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code, 0);
  2707. if (rc)
  2708. return rc;
  2709. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2710. /* Adjust the voltage regular to two steps lower. The default
  2711. * of this register is 0x0000000e. */
  2712. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  2713. /* Remove bad rbuf memory from the free pool. */
  2714. rc = bnx2_alloc_bad_rbuf(bp);
  2715. }
  2716. return rc;
  2717. }
  2718. static int
  2719. bnx2_init_chip(struct bnx2 *bp)
  2720. {
  2721. u32 val;
  2722. int rc;
  2723. /* Make sure the interrupt is not active. */
  2724. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2725. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  2726. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  2727. #ifdef __BIG_ENDIAN
  2728. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  2729. #endif
  2730. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  2731. DMA_READ_CHANS << 12 |
  2732. DMA_WRITE_CHANS << 16;
  2733. val |= (0x2 << 20) | (1 << 11);
  2734. if ((bp->flags & PCIX_FLAG) && (bp->bus_speed_mhz == 133))
  2735. val |= (1 << 23);
  2736. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  2737. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & PCIX_FLAG))
  2738. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  2739. REG_WR(bp, BNX2_DMA_CONFIG, val);
  2740. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2741. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  2742. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  2743. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  2744. }
  2745. if (bp->flags & PCIX_FLAG) {
  2746. u16 val16;
  2747. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2748. &val16);
  2749. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2750. val16 & ~PCI_X_CMD_ERO);
  2751. }
  2752. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2753. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  2754. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  2755. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  2756. /* Initialize context mapping and zero out the quick contexts. The
  2757. * context block must have already been enabled. */
  2758. bnx2_init_context(bp);
  2759. if ((rc = bnx2_init_cpus(bp)) != 0)
  2760. return rc;
  2761. bnx2_init_nvram(bp);
  2762. bnx2_set_mac_addr(bp);
  2763. val = REG_RD(bp, BNX2_MQ_CONFIG);
  2764. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  2765. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  2766. REG_WR(bp, BNX2_MQ_CONFIG, val);
  2767. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  2768. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  2769. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  2770. val = (BCM_PAGE_BITS - 8) << 24;
  2771. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  2772. /* Configure page size. */
  2773. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  2774. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  2775. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  2776. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  2777. val = bp->mac_addr[0] +
  2778. (bp->mac_addr[1] << 8) +
  2779. (bp->mac_addr[2] << 16) +
  2780. bp->mac_addr[3] +
  2781. (bp->mac_addr[4] << 8) +
  2782. (bp->mac_addr[5] << 16);
  2783. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  2784. /* Program the MTU. Also include 4 bytes for CRC32. */
  2785. val = bp->dev->mtu + ETH_HLEN + 4;
  2786. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  2787. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  2788. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  2789. bp->last_status_idx = 0;
  2790. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  2791. /* Set up how to generate a link change interrupt. */
  2792. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  2793. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  2794. (u64) bp->status_blk_mapping & 0xffffffff);
  2795. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  2796. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  2797. (u64) bp->stats_blk_mapping & 0xffffffff);
  2798. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  2799. (u64) bp->stats_blk_mapping >> 32);
  2800. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  2801. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  2802. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  2803. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  2804. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  2805. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  2806. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  2807. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  2808. REG_WR(bp, BNX2_HC_COM_TICKS,
  2809. (bp->com_ticks_int << 16) | bp->com_ticks);
  2810. REG_WR(bp, BNX2_HC_CMD_TICKS,
  2811. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  2812. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks & 0xffff00);
  2813. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  2814. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  2815. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_COLLECT_STATS);
  2816. else {
  2817. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_RX_TMR_MODE |
  2818. BNX2_HC_CONFIG_TX_TMR_MODE |
  2819. BNX2_HC_CONFIG_COLLECT_STATS);
  2820. }
  2821. /* Clear internal stats counters. */
  2822. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  2823. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
  2824. if (REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_FEATURE) &
  2825. BNX2_PORT_FEATURE_ASF_ENABLED)
  2826. bp->flags |= ASF_ENABLE_FLAG;
  2827. /* Initialize the receive filter. */
  2828. bnx2_set_rx_mode(bp->dev);
  2829. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
  2830. 0);
  2831. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
  2832. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  2833. udelay(20);
  2834. bp->hc_cmd = REG_RD(bp, BNX2_HC_COMMAND);
  2835. return rc;
  2836. }
  2837. static void
  2838. bnx2_init_tx_ring(struct bnx2 *bp)
  2839. {
  2840. struct tx_bd *txbd;
  2841. u32 val;
  2842. bp->tx_wake_thresh = bp->tx_ring_size / 2;
  2843. txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
  2844. txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
  2845. txbd->tx_bd_haddr_lo = (u64) bp->tx_desc_mapping & 0xffffffff;
  2846. bp->tx_prod = 0;
  2847. bp->tx_cons = 0;
  2848. bp->hw_tx_cons = 0;
  2849. bp->tx_prod_bseq = 0;
  2850. val = BNX2_L2CTX_TYPE_TYPE_L2;
  2851. val |= BNX2_L2CTX_TYPE_SIZE_L2;
  2852. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TYPE, val);
  2853. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2;
  2854. val |= 8 << 16;
  2855. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_CMD_TYPE, val);
  2856. val = (u64) bp->tx_desc_mapping >> 32;
  2857. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_HI, val);
  2858. val = (u64) bp->tx_desc_mapping & 0xffffffff;
  2859. CTX_WR(bp, GET_CID_ADDR(TX_CID), BNX2_L2CTX_TBDR_BHADDR_LO, val);
  2860. }
  2861. static void
  2862. bnx2_init_rx_ring(struct bnx2 *bp)
  2863. {
  2864. struct rx_bd *rxbd;
  2865. int i;
  2866. u16 prod, ring_prod;
  2867. u32 val;
  2868. /* 8 for CRC and VLAN */
  2869. bp->rx_buf_use_size = bp->dev->mtu + ETH_HLEN + bp->rx_offset + 8;
  2870. /* 8 for alignment */
  2871. bp->rx_buf_size = bp->rx_buf_use_size + 8;
  2872. ring_prod = prod = bp->rx_prod = 0;
  2873. bp->rx_cons = 0;
  2874. bp->hw_rx_cons = 0;
  2875. bp->rx_prod_bseq = 0;
  2876. for (i = 0; i < bp->rx_max_ring; i++) {
  2877. int j;
  2878. rxbd = &bp->rx_desc_ring[i][0];
  2879. for (j = 0; j < MAX_RX_DESC_CNT; j++, rxbd++) {
  2880. rxbd->rx_bd_len = bp->rx_buf_use_size;
  2881. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  2882. }
  2883. if (i == (bp->rx_max_ring - 1))
  2884. j = 0;
  2885. else
  2886. j = i + 1;
  2887. rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping[j] >> 32;
  2888. rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping[j] &
  2889. 0xffffffff;
  2890. }
  2891. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  2892. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  2893. val |= 0x02 << 8;
  2894. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
  2895. val = (u64) bp->rx_desc_mapping[0] >> 32;
  2896. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
  2897. val = (u64) bp->rx_desc_mapping[0] & 0xffffffff;
  2898. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
  2899. for (i = 0; i < bp->rx_ring_size; i++) {
  2900. if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
  2901. break;
  2902. }
  2903. prod = NEXT_RX_BD(prod);
  2904. ring_prod = RX_RING_IDX(prod);
  2905. }
  2906. bp->rx_prod = prod;
  2907. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, prod);
  2908. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  2909. }
  2910. static void
  2911. bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
  2912. {
  2913. u32 num_rings, max;
  2914. bp->rx_ring_size = size;
  2915. num_rings = 1;
  2916. while (size > MAX_RX_DESC_CNT) {
  2917. size -= MAX_RX_DESC_CNT;
  2918. num_rings++;
  2919. }
  2920. /* round to next power of 2 */
  2921. max = MAX_RX_RINGS;
  2922. while ((max & num_rings) == 0)
  2923. max >>= 1;
  2924. if (num_rings != max)
  2925. max <<= 1;
  2926. bp->rx_max_ring = max;
  2927. bp->rx_max_ring_idx = (bp->rx_max_ring * RX_DESC_CNT) - 1;
  2928. }
  2929. static void
  2930. bnx2_free_tx_skbs(struct bnx2 *bp)
  2931. {
  2932. int i;
  2933. if (bp->tx_buf_ring == NULL)
  2934. return;
  2935. for (i = 0; i < TX_DESC_CNT; ) {
  2936. struct sw_bd *tx_buf = &bp->tx_buf_ring[i];
  2937. struct sk_buff *skb = tx_buf->skb;
  2938. int j, last;
  2939. if (skb == NULL) {
  2940. i++;
  2941. continue;
  2942. }
  2943. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  2944. skb_headlen(skb), PCI_DMA_TODEVICE);
  2945. tx_buf->skb = NULL;
  2946. last = skb_shinfo(skb)->nr_frags;
  2947. for (j = 0; j < last; j++) {
  2948. tx_buf = &bp->tx_buf_ring[i + j + 1];
  2949. pci_unmap_page(bp->pdev,
  2950. pci_unmap_addr(tx_buf, mapping),
  2951. skb_shinfo(skb)->frags[j].size,
  2952. PCI_DMA_TODEVICE);
  2953. }
  2954. dev_kfree_skb(skb);
  2955. i += j + 1;
  2956. }
  2957. }
  2958. static void
  2959. bnx2_free_rx_skbs(struct bnx2 *bp)
  2960. {
  2961. int i;
  2962. if (bp->rx_buf_ring == NULL)
  2963. return;
  2964. for (i = 0; i < bp->rx_max_ring_idx; i++) {
  2965. struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
  2966. struct sk_buff *skb = rx_buf->skb;
  2967. if (skb == NULL)
  2968. continue;
  2969. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  2970. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  2971. rx_buf->skb = NULL;
  2972. dev_kfree_skb(skb);
  2973. }
  2974. }
  2975. static void
  2976. bnx2_free_skbs(struct bnx2 *bp)
  2977. {
  2978. bnx2_free_tx_skbs(bp);
  2979. bnx2_free_rx_skbs(bp);
  2980. }
  2981. static int
  2982. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  2983. {
  2984. int rc;
  2985. rc = bnx2_reset_chip(bp, reset_code);
  2986. bnx2_free_skbs(bp);
  2987. if (rc)
  2988. return rc;
  2989. if ((rc = bnx2_init_chip(bp)) != 0)
  2990. return rc;
  2991. bnx2_init_tx_ring(bp);
  2992. bnx2_init_rx_ring(bp);
  2993. return 0;
  2994. }
  2995. static int
  2996. bnx2_init_nic(struct bnx2 *bp)
  2997. {
  2998. int rc;
  2999. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  3000. return rc;
  3001. spin_lock_bh(&bp->phy_lock);
  3002. bnx2_init_phy(bp);
  3003. spin_unlock_bh(&bp->phy_lock);
  3004. bnx2_set_link(bp);
  3005. return 0;
  3006. }
  3007. static int
  3008. bnx2_test_registers(struct bnx2 *bp)
  3009. {
  3010. int ret;
  3011. int i;
  3012. static const struct {
  3013. u16 offset;
  3014. u16 flags;
  3015. u32 rw_mask;
  3016. u32 ro_mask;
  3017. } reg_tbl[] = {
  3018. { 0x006c, 0, 0x00000000, 0x0000003f },
  3019. { 0x0090, 0, 0xffffffff, 0x00000000 },
  3020. { 0x0094, 0, 0x00000000, 0x00000000 },
  3021. { 0x0404, 0, 0x00003f00, 0x00000000 },
  3022. { 0x0418, 0, 0x00000000, 0xffffffff },
  3023. { 0x041c, 0, 0x00000000, 0xffffffff },
  3024. { 0x0420, 0, 0x00000000, 0x80ffffff },
  3025. { 0x0424, 0, 0x00000000, 0x00000000 },
  3026. { 0x0428, 0, 0x00000000, 0x00000001 },
  3027. { 0x0450, 0, 0x00000000, 0x0000ffff },
  3028. { 0x0454, 0, 0x00000000, 0xffffffff },
  3029. { 0x0458, 0, 0x00000000, 0xffffffff },
  3030. { 0x0808, 0, 0x00000000, 0xffffffff },
  3031. { 0x0854, 0, 0x00000000, 0xffffffff },
  3032. { 0x0868, 0, 0x00000000, 0x77777777 },
  3033. { 0x086c, 0, 0x00000000, 0x77777777 },
  3034. { 0x0870, 0, 0x00000000, 0x77777777 },
  3035. { 0x0874, 0, 0x00000000, 0x77777777 },
  3036. { 0x0c00, 0, 0x00000000, 0x00000001 },
  3037. { 0x0c04, 0, 0x00000000, 0x03ff0001 },
  3038. { 0x0c08, 0, 0x0f0ff073, 0x00000000 },
  3039. { 0x1000, 0, 0x00000000, 0x00000001 },
  3040. { 0x1004, 0, 0x00000000, 0x000f0001 },
  3041. { 0x1408, 0, 0x01c00800, 0x00000000 },
  3042. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  3043. { 0x14a8, 0, 0x00000000, 0x000001ff },
  3044. { 0x14ac, 0, 0x0fffffff, 0x10000000 },
  3045. { 0x14b0, 0, 0x00000002, 0x00000001 },
  3046. { 0x14b8, 0, 0x00000000, 0x00000000 },
  3047. { 0x14c0, 0, 0x00000000, 0x00000009 },
  3048. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  3049. { 0x14cc, 0, 0x00000000, 0x00000001 },
  3050. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  3051. { 0x1800, 0, 0x00000000, 0x00000001 },
  3052. { 0x1804, 0, 0x00000000, 0x00000003 },
  3053. { 0x2800, 0, 0x00000000, 0x00000001 },
  3054. { 0x2804, 0, 0x00000000, 0x00003f01 },
  3055. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  3056. { 0x2810, 0, 0xffff0000, 0x00000000 },
  3057. { 0x2814, 0, 0xffff0000, 0x00000000 },
  3058. { 0x2818, 0, 0xffff0000, 0x00000000 },
  3059. { 0x281c, 0, 0xffff0000, 0x00000000 },
  3060. { 0x2834, 0, 0xffffffff, 0x00000000 },
  3061. { 0x2840, 0, 0x00000000, 0xffffffff },
  3062. { 0x2844, 0, 0x00000000, 0xffffffff },
  3063. { 0x2848, 0, 0xffffffff, 0x00000000 },
  3064. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  3065. { 0x2c00, 0, 0x00000000, 0x00000011 },
  3066. { 0x2c04, 0, 0x00000000, 0x00030007 },
  3067. { 0x3c00, 0, 0x00000000, 0x00000001 },
  3068. { 0x3c04, 0, 0x00000000, 0x00070000 },
  3069. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  3070. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  3071. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  3072. { 0x3c14, 0, 0x00000000, 0xffffffff },
  3073. { 0x3c18, 0, 0x00000000, 0xffffffff },
  3074. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  3075. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  3076. { 0x5004, 0, 0x00000000, 0x0000007f },
  3077. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  3078. { 0x500c, 0, 0xf800f800, 0x07ff07ff },
  3079. { 0x5c00, 0, 0x00000000, 0x00000001 },
  3080. { 0x5c04, 0, 0x00000000, 0x0003000f },
  3081. { 0x5c08, 0, 0x00000003, 0x00000000 },
  3082. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  3083. { 0x5c10, 0, 0x00000000, 0xffffffff },
  3084. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  3085. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  3086. { 0x5c88, 0, 0x00000000, 0x00077373 },
  3087. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  3088. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  3089. { 0x680c, 0, 0xffffffff, 0x00000000 },
  3090. { 0x6810, 0, 0xffffffff, 0x00000000 },
  3091. { 0x6814, 0, 0xffffffff, 0x00000000 },
  3092. { 0x6818, 0, 0xffffffff, 0x00000000 },
  3093. { 0x681c, 0, 0xffffffff, 0x00000000 },
  3094. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  3095. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  3096. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  3097. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  3098. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  3099. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  3100. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  3101. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  3102. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  3103. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  3104. { 0x684c, 0, 0xffffffff, 0x00000000 },
  3105. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  3106. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  3107. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  3108. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  3109. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  3110. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  3111. { 0xffff, 0, 0x00000000, 0x00000000 },
  3112. };
  3113. ret = 0;
  3114. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  3115. u32 offset, rw_mask, ro_mask, save_val, val;
  3116. offset = (u32) reg_tbl[i].offset;
  3117. rw_mask = reg_tbl[i].rw_mask;
  3118. ro_mask = reg_tbl[i].ro_mask;
  3119. save_val = readl(bp->regview + offset);
  3120. writel(0, bp->regview + offset);
  3121. val = readl(bp->regview + offset);
  3122. if ((val & rw_mask) != 0) {
  3123. goto reg_test_err;
  3124. }
  3125. if ((val & ro_mask) != (save_val & ro_mask)) {
  3126. goto reg_test_err;
  3127. }
  3128. writel(0xffffffff, bp->regview + offset);
  3129. val = readl(bp->regview + offset);
  3130. if ((val & rw_mask) != rw_mask) {
  3131. goto reg_test_err;
  3132. }
  3133. if ((val & ro_mask) != (save_val & ro_mask)) {
  3134. goto reg_test_err;
  3135. }
  3136. writel(save_val, bp->regview + offset);
  3137. continue;
  3138. reg_test_err:
  3139. writel(save_val, bp->regview + offset);
  3140. ret = -ENODEV;
  3141. break;
  3142. }
  3143. return ret;
  3144. }
  3145. static int
  3146. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  3147. {
  3148. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  3149. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  3150. int i;
  3151. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  3152. u32 offset;
  3153. for (offset = 0; offset < size; offset += 4) {
  3154. REG_WR_IND(bp, start + offset, test_pattern[i]);
  3155. if (REG_RD_IND(bp, start + offset) !=
  3156. test_pattern[i]) {
  3157. return -ENODEV;
  3158. }
  3159. }
  3160. }
  3161. return 0;
  3162. }
  3163. static int
  3164. bnx2_test_memory(struct bnx2 *bp)
  3165. {
  3166. int ret = 0;
  3167. int i;
  3168. static const struct {
  3169. u32 offset;
  3170. u32 len;
  3171. } mem_tbl[] = {
  3172. { 0x60000, 0x4000 },
  3173. { 0xa0000, 0x3000 },
  3174. { 0xe0000, 0x4000 },
  3175. { 0x120000, 0x4000 },
  3176. { 0x1a0000, 0x4000 },
  3177. { 0x160000, 0x4000 },
  3178. { 0xffffffff, 0 },
  3179. };
  3180. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  3181. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  3182. mem_tbl[i].len)) != 0) {
  3183. return ret;
  3184. }
  3185. }
  3186. return ret;
  3187. }
  3188. #define BNX2_MAC_LOOPBACK 0
  3189. #define BNX2_PHY_LOOPBACK 1
  3190. static int
  3191. bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
  3192. {
  3193. unsigned int pkt_size, num_pkts, i;
  3194. struct sk_buff *skb, *rx_skb;
  3195. unsigned char *packet;
  3196. u16 rx_start_idx, rx_idx;
  3197. dma_addr_t map;
  3198. struct tx_bd *txbd;
  3199. struct sw_bd *rx_buf;
  3200. struct l2_fhdr *rx_hdr;
  3201. int ret = -ENODEV;
  3202. if (loopback_mode == BNX2_MAC_LOOPBACK) {
  3203. bp->loopback = MAC_LOOPBACK;
  3204. bnx2_set_mac_loopback(bp);
  3205. }
  3206. else if (loopback_mode == BNX2_PHY_LOOPBACK) {
  3207. bp->loopback = PHY_LOOPBACK;
  3208. bnx2_set_phy_loopback(bp);
  3209. }
  3210. else
  3211. return -EINVAL;
  3212. pkt_size = 1514;
  3213. skb = netdev_alloc_skb(bp->dev, pkt_size);
  3214. if (!skb)
  3215. return -ENOMEM;
  3216. packet = skb_put(skb, pkt_size);
  3217. memcpy(packet, bp->mac_addr, 6);
  3218. memset(packet + 6, 0x0, 8);
  3219. for (i = 14; i < pkt_size; i++)
  3220. packet[i] = (unsigned char) (i & 0xff);
  3221. map = pci_map_single(bp->pdev, skb->data, pkt_size,
  3222. PCI_DMA_TODEVICE);
  3223. REG_WR(bp, BNX2_HC_COMMAND,
  3224. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3225. REG_RD(bp, BNX2_HC_COMMAND);
  3226. udelay(5);
  3227. rx_start_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3228. num_pkts = 0;
  3229. txbd = &bp->tx_desc_ring[TX_RING_IDX(bp->tx_prod)];
  3230. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  3231. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  3232. txbd->tx_bd_mss_nbytes = pkt_size;
  3233. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  3234. num_pkts++;
  3235. bp->tx_prod = NEXT_TX_BD(bp->tx_prod);
  3236. bp->tx_prod_bseq += pkt_size;
  3237. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, bp->tx_prod);
  3238. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
  3239. udelay(100);
  3240. REG_WR(bp, BNX2_HC_COMMAND,
  3241. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3242. REG_RD(bp, BNX2_HC_COMMAND);
  3243. udelay(5);
  3244. pci_unmap_single(bp->pdev, map, pkt_size, PCI_DMA_TODEVICE);
  3245. dev_kfree_skb(skb);
  3246. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->tx_prod) {
  3247. goto loopback_test_done;
  3248. }
  3249. rx_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3250. if (rx_idx != rx_start_idx + num_pkts) {
  3251. goto loopback_test_done;
  3252. }
  3253. rx_buf = &bp->rx_buf_ring[rx_start_idx];
  3254. rx_skb = rx_buf->skb;
  3255. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  3256. skb_reserve(rx_skb, bp->rx_offset);
  3257. pci_dma_sync_single_for_cpu(bp->pdev,
  3258. pci_unmap_addr(rx_buf, mapping),
  3259. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  3260. if (rx_hdr->l2_fhdr_status &
  3261. (L2_FHDR_ERRORS_BAD_CRC |
  3262. L2_FHDR_ERRORS_PHY_DECODE |
  3263. L2_FHDR_ERRORS_ALIGNMENT |
  3264. L2_FHDR_ERRORS_TOO_SHORT |
  3265. L2_FHDR_ERRORS_GIANT_FRAME)) {
  3266. goto loopback_test_done;
  3267. }
  3268. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  3269. goto loopback_test_done;
  3270. }
  3271. for (i = 14; i < pkt_size; i++) {
  3272. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  3273. goto loopback_test_done;
  3274. }
  3275. }
  3276. ret = 0;
  3277. loopback_test_done:
  3278. bp->loopback = 0;
  3279. return ret;
  3280. }
  3281. #define BNX2_MAC_LOOPBACK_FAILED 1
  3282. #define BNX2_PHY_LOOPBACK_FAILED 2
  3283. #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
  3284. BNX2_PHY_LOOPBACK_FAILED)
  3285. static int
  3286. bnx2_test_loopback(struct bnx2 *bp)
  3287. {
  3288. int rc = 0;
  3289. if (!netif_running(bp->dev))
  3290. return BNX2_LOOPBACK_FAILED;
  3291. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  3292. spin_lock_bh(&bp->phy_lock);
  3293. bnx2_init_phy(bp);
  3294. spin_unlock_bh(&bp->phy_lock);
  3295. if (bnx2_run_loopback(bp, BNX2_MAC_LOOPBACK))
  3296. rc |= BNX2_MAC_LOOPBACK_FAILED;
  3297. if (bnx2_run_loopback(bp, BNX2_PHY_LOOPBACK))
  3298. rc |= BNX2_PHY_LOOPBACK_FAILED;
  3299. return rc;
  3300. }
  3301. #define NVRAM_SIZE 0x200
  3302. #define CRC32_RESIDUAL 0xdebb20e3
  3303. static int
  3304. bnx2_test_nvram(struct bnx2 *bp)
  3305. {
  3306. u32 buf[NVRAM_SIZE / 4];
  3307. u8 *data = (u8 *) buf;
  3308. int rc = 0;
  3309. u32 magic, csum;
  3310. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  3311. goto test_nvram_done;
  3312. magic = be32_to_cpu(buf[0]);
  3313. if (magic != 0x669955aa) {
  3314. rc = -ENODEV;
  3315. goto test_nvram_done;
  3316. }
  3317. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  3318. goto test_nvram_done;
  3319. csum = ether_crc_le(0x100, data);
  3320. if (csum != CRC32_RESIDUAL) {
  3321. rc = -ENODEV;
  3322. goto test_nvram_done;
  3323. }
  3324. csum = ether_crc_le(0x100, data + 0x100);
  3325. if (csum != CRC32_RESIDUAL) {
  3326. rc = -ENODEV;
  3327. }
  3328. test_nvram_done:
  3329. return rc;
  3330. }
  3331. static int
  3332. bnx2_test_link(struct bnx2 *bp)
  3333. {
  3334. u32 bmsr;
  3335. spin_lock_bh(&bp->phy_lock);
  3336. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3337. bnx2_read_phy(bp, MII_BMSR, &bmsr);
  3338. spin_unlock_bh(&bp->phy_lock);
  3339. if (bmsr & BMSR_LSTATUS) {
  3340. return 0;
  3341. }
  3342. return -ENODEV;
  3343. }
  3344. static int
  3345. bnx2_test_intr(struct bnx2 *bp)
  3346. {
  3347. int i;
  3348. u16 status_idx;
  3349. if (!netif_running(bp->dev))
  3350. return -ENODEV;
  3351. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  3352. /* This register is not touched during run-time. */
  3353. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  3354. REG_RD(bp, BNX2_HC_COMMAND);
  3355. for (i = 0; i < 10; i++) {
  3356. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  3357. status_idx) {
  3358. break;
  3359. }
  3360. msleep_interruptible(10);
  3361. }
  3362. if (i < 10)
  3363. return 0;
  3364. return -ENODEV;
  3365. }
  3366. static void
  3367. bnx2_5706_serdes_timer(struct bnx2 *bp)
  3368. {
  3369. spin_lock(&bp->phy_lock);
  3370. if (bp->serdes_an_pending)
  3371. bp->serdes_an_pending--;
  3372. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3373. u32 bmcr;
  3374. bp->current_interval = bp->timer_interval;
  3375. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3376. if (bmcr & BMCR_ANENABLE) {
  3377. u32 phy1, phy2;
  3378. bnx2_write_phy(bp, 0x1c, 0x7c00);
  3379. bnx2_read_phy(bp, 0x1c, &phy1);
  3380. bnx2_write_phy(bp, 0x17, 0x0f01);
  3381. bnx2_read_phy(bp, 0x15, &phy2);
  3382. bnx2_write_phy(bp, 0x17, 0x0f01);
  3383. bnx2_read_phy(bp, 0x15, &phy2);
  3384. if ((phy1 & 0x10) && /* SIGNAL DETECT */
  3385. !(phy2 & 0x20)) { /* no CONFIG */
  3386. bmcr &= ~BMCR_ANENABLE;
  3387. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  3388. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3389. bp->phy_flags |= PHY_PARALLEL_DETECT_FLAG;
  3390. }
  3391. }
  3392. }
  3393. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  3394. (bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)) {
  3395. u32 phy2;
  3396. bnx2_write_phy(bp, 0x17, 0x0f01);
  3397. bnx2_read_phy(bp, 0x15, &phy2);
  3398. if (phy2 & 0x20) {
  3399. u32 bmcr;
  3400. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3401. bmcr |= BMCR_ANENABLE;
  3402. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3403. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  3404. }
  3405. } else
  3406. bp->current_interval = bp->timer_interval;
  3407. spin_unlock(&bp->phy_lock);
  3408. }
  3409. static void
  3410. bnx2_5708_serdes_timer(struct bnx2 *bp)
  3411. {
  3412. if ((bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) == 0) {
  3413. bp->serdes_an_pending = 0;
  3414. return;
  3415. }
  3416. spin_lock(&bp->phy_lock);
  3417. if (bp->serdes_an_pending)
  3418. bp->serdes_an_pending--;
  3419. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3420. u32 bmcr;
  3421. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  3422. if (bmcr & BMCR_ANENABLE) {
  3423. bmcr &= ~BMCR_ANENABLE;
  3424. bmcr |= BMCR_FULLDPLX | BCM5708S_BMCR_FORCE_2500;
  3425. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3426. bp->current_interval = SERDES_FORCED_TIMEOUT;
  3427. } else {
  3428. bmcr &= ~(BMCR_FULLDPLX | BCM5708S_BMCR_FORCE_2500);
  3429. bmcr |= BMCR_ANENABLE;
  3430. bnx2_write_phy(bp, MII_BMCR, bmcr);
  3431. bp->serdes_an_pending = 2;
  3432. bp->current_interval = bp->timer_interval;
  3433. }
  3434. } else
  3435. bp->current_interval = bp->timer_interval;
  3436. spin_unlock(&bp->phy_lock);
  3437. }
  3438. static void
  3439. bnx2_timer(unsigned long data)
  3440. {
  3441. struct bnx2 *bp = (struct bnx2 *) data;
  3442. u32 msg;
  3443. if (!netif_running(bp->dev))
  3444. return;
  3445. if (atomic_read(&bp->intr_sem) != 0)
  3446. goto bnx2_restart_timer;
  3447. msg = (u32) ++bp->fw_drv_pulse_wr_seq;
  3448. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_PULSE_MB, msg);
  3449. bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT);
  3450. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3451. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3452. bnx2_5706_serdes_timer(bp);
  3453. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  3454. bnx2_5708_serdes_timer(bp);
  3455. }
  3456. bnx2_restart_timer:
  3457. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3458. }
  3459. /* Called with rtnl_lock */
  3460. static int
  3461. bnx2_open(struct net_device *dev)
  3462. {
  3463. struct bnx2 *bp = netdev_priv(dev);
  3464. int rc;
  3465. bnx2_set_power_state(bp, PCI_D0);
  3466. bnx2_disable_int(bp);
  3467. rc = bnx2_alloc_mem(bp);
  3468. if (rc)
  3469. return rc;
  3470. if ((CHIP_ID(bp) != CHIP_ID_5706_A0) &&
  3471. (CHIP_ID(bp) != CHIP_ID_5706_A1) &&
  3472. !disable_msi) {
  3473. if (pci_enable_msi(bp->pdev) == 0) {
  3474. bp->flags |= USING_MSI_FLAG;
  3475. rc = request_irq(bp->pdev->irq, bnx2_msi, 0, dev->name,
  3476. dev);
  3477. }
  3478. else {
  3479. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3480. IRQF_SHARED, dev->name, dev);
  3481. }
  3482. }
  3483. else {
  3484. rc = request_irq(bp->pdev->irq, bnx2_interrupt, IRQF_SHARED,
  3485. dev->name, dev);
  3486. }
  3487. if (rc) {
  3488. bnx2_free_mem(bp);
  3489. return rc;
  3490. }
  3491. rc = bnx2_init_nic(bp);
  3492. if (rc) {
  3493. free_irq(bp->pdev->irq, dev);
  3494. if (bp->flags & USING_MSI_FLAG) {
  3495. pci_disable_msi(bp->pdev);
  3496. bp->flags &= ~USING_MSI_FLAG;
  3497. }
  3498. bnx2_free_skbs(bp);
  3499. bnx2_free_mem(bp);
  3500. return rc;
  3501. }
  3502. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3503. atomic_set(&bp->intr_sem, 0);
  3504. bnx2_enable_int(bp);
  3505. if (bp->flags & USING_MSI_FLAG) {
  3506. /* Test MSI to make sure it is working
  3507. * If MSI test fails, go back to INTx mode
  3508. */
  3509. if (bnx2_test_intr(bp) != 0) {
  3510. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  3511. " using MSI, switching to INTx mode. Please"
  3512. " report this failure to the PCI maintainer"
  3513. " and include system chipset information.\n",
  3514. bp->dev->name);
  3515. bnx2_disable_int(bp);
  3516. free_irq(bp->pdev->irq, dev);
  3517. pci_disable_msi(bp->pdev);
  3518. bp->flags &= ~USING_MSI_FLAG;
  3519. rc = bnx2_init_nic(bp);
  3520. if (!rc) {
  3521. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3522. IRQF_SHARED, dev->name, dev);
  3523. }
  3524. if (rc) {
  3525. bnx2_free_skbs(bp);
  3526. bnx2_free_mem(bp);
  3527. del_timer_sync(&bp->timer);
  3528. return rc;
  3529. }
  3530. bnx2_enable_int(bp);
  3531. }
  3532. }
  3533. if (bp->flags & USING_MSI_FLAG) {
  3534. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  3535. }
  3536. netif_start_queue(dev);
  3537. return 0;
  3538. }
  3539. static void
  3540. bnx2_reset_task(void *data)
  3541. {
  3542. struct bnx2 *bp = data;
  3543. if (!netif_running(bp->dev))
  3544. return;
  3545. bp->in_reset_task = 1;
  3546. bnx2_netif_stop(bp);
  3547. bnx2_init_nic(bp);
  3548. atomic_set(&bp->intr_sem, 1);
  3549. bnx2_netif_start(bp);
  3550. bp->in_reset_task = 0;
  3551. }
  3552. static void
  3553. bnx2_tx_timeout(struct net_device *dev)
  3554. {
  3555. struct bnx2 *bp = netdev_priv(dev);
  3556. /* This allows the netif to be shutdown gracefully before resetting */
  3557. schedule_work(&bp->reset_task);
  3558. }
  3559. #ifdef BCM_VLAN
  3560. /* Called with rtnl_lock */
  3561. static void
  3562. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  3563. {
  3564. struct bnx2 *bp = netdev_priv(dev);
  3565. bnx2_netif_stop(bp);
  3566. bp->vlgrp = vlgrp;
  3567. bnx2_set_rx_mode(dev);
  3568. bnx2_netif_start(bp);
  3569. }
  3570. /* Called with rtnl_lock */
  3571. static void
  3572. bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
  3573. {
  3574. struct bnx2 *bp = netdev_priv(dev);
  3575. bnx2_netif_stop(bp);
  3576. if (bp->vlgrp)
  3577. bp->vlgrp->vlan_devices[vid] = NULL;
  3578. bnx2_set_rx_mode(dev);
  3579. bnx2_netif_start(bp);
  3580. }
  3581. #endif
  3582. /* Called with netif_tx_lock.
  3583. * bnx2_tx_int() runs without netif_tx_lock unless it needs to call
  3584. * netif_wake_queue().
  3585. */
  3586. static int
  3587. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3588. {
  3589. struct bnx2 *bp = netdev_priv(dev);
  3590. dma_addr_t mapping;
  3591. struct tx_bd *txbd;
  3592. struct sw_bd *tx_buf;
  3593. u32 len, vlan_tag_flags, last_frag, mss;
  3594. u16 prod, ring_prod;
  3595. int i;
  3596. if (unlikely(bnx2_tx_avail(bp) < (skb_shinfo(skb)->nr_frags + 1))) {
  3597. netif_stop_queue(dev);
  3598. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  3599. dev->name);
  3600. return NETDEV_TX_BUSY;
  3601. }
  3602. len = skb_headlen(skb);
  3603. prod = bp->tx_prod;
  3604. ring_prod = TX_RING_IDX(prod);
  3605. vlan_tag_flags = 0;
  3606. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  3607. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  3608. }
  3609. if (bp->vlgrp != 0 && vlan_tx_tag_present(skb)) {
  3610. vlan_tag_flags |=
  3611. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  3612. }
  3613. #ifdef BCM_TSO
  3614. if ((mss = skb_shinfo(skb)->gso_size) &&
  3615. (skb->len > (bp->dev->mtu + ETH_HLEN))) {
  3616. u32 tcp_opt_len, ip_tcp_len;
  3617. if (skb_header_cloned(skb) &&
  3618. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3619. dev_kfree_skb(skb);
  3620. return NETDEV_TX_OK;
  3621. }
  3622. tcp_opt_len = ((skb->h.th->doff - 5) * 4);
  3623. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  3624. tcp_opt_len = 0;
  3625. if (skb->h.th->doff > 5) {
  3626. tcp_opt_len = (skb->h.th->doff - 5) << 2;
  3627. }
  3628. ip_tcp_len = (skb->nh.iph->ihl << 2) + sizeof(struct tcphdr);
  3629. skb->nh.iph->check = 0;
  3630. skb->nh.iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3631. skb->h.th->check =
  3632. ~csum_tcpudp_magic(skb->nh.iph->saddr,
  3633. skb->nh.iph->daddr,
  3634. 0, IPPROTO_TCP, 0);
  3635. if (tcp_opt_len || (skb->nh.iph->ihl > 5)) {
  3636. vlan_tag_flags |= ((skb->nh.iph->ihl - 5) +
  3637. (tcp_opt_len >> 2)) << 8;
  3638. }
  3639. }
  3640. else
  3641. #endif
  3642. {
  3643. mss = 0;
  3644. }
  3645. mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3646. tx_buf = &bp->tx_buf_ring[ring_prod];
  3647. tx_buf->skb = skb;
  3648. pci_unmap_addr_set(tx_buf, mapping, mapping);
  3649. txbd = &bp->tx_desc_ring[ring_prod];
  3650. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3651. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3652. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3653. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  3654. last_frag = skb_shinfo(skb)->nr_frags;
  3655. for (i = 0; i < last_frag; i++) {
  3656. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3657. prod = NEXT_TX_BD(prod);
  3658. ring_prod = TX_RING_IDX(prod);
  3659. txbd = &bp->tx_desc_ring[ring_prod];
  3660. len = frag->size;
  3661. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  3662. len, PCI_DMA_TODEVICE);
  3663. pci_unmap_addr_set(&bp->tx_buf_ring[ring_prod],
  3664. mapping, mapping);
  3665. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3666. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3667. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3668. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  3669. }
  3670. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  3671. prod = NEXT_TX_BD(prod);
  3672. bp->tx_prod_bseq += skb->len;
  3673. REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, prod);
  3674. REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
  3675. mmiowb();
  3676. bp->tx_prod = prod;
  3677. dev->trans_start = jiffies;
  3678. if (unlikely(bnx2_tx_avail(bp) <= MAX_SKB_FRAGS)) {
  3679. netif_stop_queue(dev);
  3680. if (bnx2_tx_avail(bp) > bp->tx_wake_thresh)
  3681. netif_wake_queue(dev);
  3682. }
  3683. return NETDEV_TX_OK;
  3684. }
  3685. /* Called with rtnl_lock */
  3686. static int
  3687. bnx2_close(struct net_device *dev)
  3688. {
  3689. struct bnx2 *bp = netdev_priv(dev);
  3690. u32 reset_code;
  3691. /* Calling flush_scheduled_work() may deadlock because
  3692. * linkwatch_event() may be on the workqueue and it will try to get
  3693. * the rtnl_lock which we are holding.
  3694. */
  3695. while (bp->in_reset_task)
  3696. msleep(1);
  3697. bnx2_netif_stop(bp);
  3698. del_timer_sync(&bp->timer);
  3699. if (bp->flags & NO_WOL_FLAG)
  3700. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  3701. else if (bp->wol)
  3702. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3703. else
  3704. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3705. bnx2_reset_chip(bp, reset_code);
  3706. free_irq(bp->pdev->irq, dev);
  3707. if (bp->flags & USING_MSI_FLAG) {
  3708. pci_disable_msi(bp->pdev);
  3709. bp->flags &= ~USING_MSI_FLAG;
  3710. }
  3711. bnx2_free_skbs(bp);
  3712. bnx2_free_mem(bp);
  3713. bp->link_up = 0;
  3714. netif_carrier_off(bp->dev);
  3715. bnx2_set_power_state(bp, PCI_D3hot);
  3716. return 0;
  3717. }
  3718. #define GET_NET_STATS64(ctr) \
  3719. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  3720. (unsigned long) (ctr##_lo)
  3721. #define GET_NET_STATS32(ctr) \
  3722. (ctr##_lo)
  3723. #if (BITS_PER_LONG == 64)
  3724. #define GET_NET_STATS GET_NET_STATS64
  3725. #else
  3726. #define GET_NET_STATS GET_NET_STATS32
  3727. #endif
  3728. static struct net_device_stats *
  3729. bnx2_get_stats(struct net_device *dev)
  3730. {
  3731. struct bnx2 *bp = netdev_priv(dev);
  3732. struct statistics_block *stats_blk = bp->stats_blk;
  3733. struct net_device_stats *net_stats = &bp->net_stats;
  3734. if (bp->stats_blk == NULL) {
  3735. return net_stats;
  3736. }
  3737. net_stats->rx_packets =
  3738. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  3739. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  3740. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  3741. net_stats->tx_packets =
  3742. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  3743. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  3744. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  3745. net_stats->rx_bytes =
  3746. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  3747. net_stats->tx_bytes =
  3748. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  3749. net_stats->multicast =
  3750. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  3751. net_stats->collisions =
  3752. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  3753. net_stats->rx_length_errors =
  3754. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  3755. stats_blk->stat_EtherStatsOverrsizePkts);
  3756. net_stats->rx_over_errors =
  3757. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  3758. net_stats->rx_frame_errors =
  3759. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  3760. net_stats->rx_crc_errors =
  3761. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  3762. net_stats->rx_errors = net_stats->rx_length_errors +
  3763. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  3764. net_stats->rx_crc_errors;
  3765. net_stats->tx_aborted_errors =
  3766. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  3767. stats_blk->stat_Dot3StatsLateCollisions);
  3768. if ((CHIP_NUM(bp) == CHIP_NUM_5706) ||
  3769. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  3770. net_stats->tx_carrier_errors = 0;
  3771. else {
  3772. net_stats->tx_carrier_errors =
  3773. (unsigned long)
  3774. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  3775. }
  3776. net_stats->tx_errors =
  3777. (unsigned long)
  3778. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  3779. +
  3780. net_stats->tx_aborted_errors +
  3781. net_stats->tx_carrier_errors;
  3782. net_stats->rx_missed_errors =
  3783. (unsigned long) (stats_blk->stat_IfInMBUFDiscards +
  3784. stats_blk->stat_FwRxDrop);
  3785. return net_stats;
  3786. }
  3787. /* All ethtool functions called with rtnl_lock */
  3788. static int
  3789. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3790. {
  3791. struct bnx2 *bp = netdev_priv(dev);
  3792. cmd->supported = SUPPORTED_Autoneg;
  3793. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3794. cmd->supported |= SUPPORTED_1000baseT_Full |
  3795. SUPPORTED_FIBRE;
  3796. cmd->port = PORT_FIBRE;
  3797. }
  3798. else {
  3799. cmd->supported |= SUPPORTED_10baseT_Half |
  3800. SUPPORTED_10baseT_Full |
  3801. SUPPORTED_100baseT_Half |
  3802. SUPPORTED_100baseT_Full |
  3803. SUPPORTED_1000baseT_Full |
  3804. SUPPORTED_TP;
  3805. cmd->port = PORT_TP;
  3806. }
  3807. cmd->advertising = bp->advertising;
  3808. if (bp->autoneg & AUTONEG_SPEED) {
  3809. cmd->autoneg = AUTONEG_ENABLE;
  3810. }
  3811. else {
  3812. cmd->autoneg = AUTONEG_DISABLE;
  3813. }
  3814. if (netif_carrier_ok(dev)) {
  3815. cmd->speed = bp->line_speed;
  3816. cmd->duplex = bp->duplex;
  3817. }
  3818. else {
  3819. cmd->speed = -1;
  3820. cmd->duplex = -1;
  3821. }
  3822. cmd->transceiver = XCVR_INTERNAL;
  3823. cmd->phy_address = bp->phy_addr;
  3824. return 0;
  3825. }
  3826. static int
  3827. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3828. {
  3829. struct bnx2 *bp = netdev_priv(dev);
  3830. u8 autoneg = bp->autoneg;
  3831. u8 req_duplex = bp->req_duplex;
  3832. u16 req_line_speed = bp->req_line_speed;
  3833. u32 advertising = bp->advertising;
  3834. if (cmd->autoneg == AUTONEG_ENABLE) {
  3835. autoneg |= AUTONEG_SPEED;
  3836. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  3837. /* allow advertising 1 speed */
  3838. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  3839. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  3840. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  3841. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  3842. if (bp->phy_flags & PHY_SERDES_FLAG)
  3843. return -EINVAL;
  3844. advertising = cmd->advertising;
  3845. }
  3846. else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
  3847. advertising = cmd->advertising;
  3848. }
  3849. else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
  3850. return -EINVAL;
  3851. }
  3852. else {
  3853. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3854. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  3855. }
  3856. else {
  3857. advertising = ETHTOOL_ALL_COPPER_SPEED;
  3858. }
  3859. }
  3860. advertising |= ADVERTISED_Autoneg;
  3861. }
  3862. else {
  3863. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3864. if ((cmd->speed != SPEED_1000 &&
  3865. cmd->speed != SPEED_2500) ||
  3866. (cmd->duplex != DUPLEX_FULL))
  3867. return -EINVAL;
  3868. if (cmd->speed == SPEED_2500 &&
  3869. !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  3870. return -EINVAL;
  3871. }
  3872. else if (cmd->speed == SPEED_1000) {
  3873. return -EINVAL;
  3874. }
  3875. autoneg &= ~AUTONEG_SPEED;
  3876. req_line_speed = cmd->speed;
  3877. req_duplex = cmd->duplex;
  3878. advertising = 0;
  3879. }
  3880. bp->autoneg = autoneg;
  3881. bp->advertising = advertising;
  3882. bp->req_line_speed = req_line_speed;
  3883. bp->req_duplex = req_duplex;
  3884. spin_lock_bh(&bp->phy_lock);
  3885. bnx2_setup_phy(bp);
  3886. spin_unlock_bh(&bp->phy_lock);
  3887. return 0;
  3888. }
  3889. static void
  3890. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  3891. {
  3892. struct bnx2 *bp = netdev_priv(dev);
  3893. strcpy(info->driver, DRV_MODULE_NAME);
  3894. strcpy(info->version, DRV_MODULE_VERSION);
  3895. strcpy(info->bus_info, pci_name(bp->pdev));
  3896. info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
  3897. info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
  3898. info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
  3899. info->fw_version[1] = info->fw_version[3] = '.';
  3900. info->fw_version[5] = 0;
  3901. }
  3902. #define BNX2_REGDUMP_LEN (32 * 1024)
  3903. static int
  3904. bnx2_get_regs_len(struct net_device *dev)
  3905. {
  3906. return BNX2_REGDUMP_LEN;
  3907. }
  3908. static void
  3909. bnx2_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
  3910. {
  3911. u32 *p = _p, i, offset;
  3912. u8 *orig_p = _p;
  3913. struct bnx2 *bp = netdev_priv(dev);
  3914. u32 reg_boundaries[] = { 0x0000, 0x0098, 0x0400, 0x045c,
  3915. 0x0800, 0x0880, 0x0c00, 0x0c10,
  3916. 0x0c30, 0x0d08, 0x1000, 0x101c,
  3917. 0x1040, 0x1048, 0x1080, 0x10a4,
  3918. 0x1400, 0x1490, 0x1498, 0x14f0,
  3919. 0x1500, 0x155c, 0x1580, 0x15dc,
  3920. 0x1600, 0x1658, 0x1680, 0x16d8,
  3921. 0x1800, 0x1820, 0x1840, 0x1854,
  3922. 0x1880, 0x1894, 0x1900, 0x1984,
  3923. 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
  3924. 0x1c80, 0x1c94, 0x1d00, 0x1d84,
  3925. 0x2000, 0x2030, 0x23c0, 0x2400,
  3926. 0x2800, 0x2820, 0x2830, 0x2850,
  3927. 0x2b40, 0x2c10, 0x2fc0, 0x3058,
  3928. 0x3c00, 0x3c94, 0x4000, 0x4010,
  3929. 0x4080, 0x4090, 0x43c0, 0x4458,
  3930. 0x4c00, 0x4c18, 0x4c40, 0x4c54,
  3931. 0x4fc0, 0x5010, 0x53c0, 0x5444,
  3932. 0x5c00, 0x5c18, 0x5c80, 0x5c90,
  3933. 0x5fc0, 0x6000, 0x6400, 0x6428,
  3934. 0x6800, 0x6848, 0x684c, 0x6860,
  3935. 0x6888, 0x6910, 0x8000 };
  3936. regs->version = 0;
  3937. memset(p, 0, BNX2_REGDUMP_LEN);
  3938. if (!netif_running(bp->dev))
  3939. return;
  3940. i = 0;
  3941. offset = reg_boundaries[0];
  3942. p += offset;
  3943. while (offset < BNX2_REGDUMP_LEN) {
  3944. *p++ = REG_RD(bp, offset);
  3945. offset += 4;
  3946. if (offset == reg_boundaries[i + 1]) {
  3947. offset = reg_boundaries[i + 2];
  3948. p = (u32 *) (orig_p + offset);
  3949. i += 2;
  3950. }
  3951. }
  3952. }
  3953. static void
  3954. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3955. {
  3956. struct bnx2 *bp = netdev_priv(dev);
  3957. if (bp->flags & NO_WOL_FLAG) {
  3958. wol->supported = 0;
  3959. wol->wolopts = 0;
  3960. }
  3961. else {
  3962. wol->supported = WAKE_MAGIC;
  3963. if (bp->wol)
  3964. wol->wolopts = WAKE_MAGIC;
  3965. else
  3966. wol->wolopts = 0;
  3967. }
  3968. memset(&wol->sopass, 0, sizeof(wol->sopass));
  3969. }
  3970. static int
  3971. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  3972. {
  3973. struct bnx2 *bp = netdev_priv(dev);
  3974. if (wol->wolopts & ~WAKE_MAGIC)
  3975. return -EINVAL;
  3976. if (wol->wolopts & WAKE_MAGIC) {
  3977. if (bp->flags & NO_WOL_FLAG)
  3978. return -EINVAL;
  3979. bp->wol = 1;
  3980. }
  3981. else {
  3982. bp->wol = 0;
  3983. }
  3984. return 0;
  3985. }
  3986. static int
  3987. bnx2_nway_reset(struct net_device *dev)
  3988. {
  3989. struct bnx2 *bp = netdev_priv(dev);
  3990. u32 bmcr;
  3991. if (!(bp->autoneg & AUTONEG_SPEED)) {
  3992. return -EINVAL;
  3993. }
  3994. spin_lock_bh(&bp->phy_lock);
  3995. /* Force a link down visible on the other side */
  3996. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3997. bnx2_write_phy(bp, MII_BMCR, BMCR_LOOPBACK);
  3998. spin_unlock_bh(&bp->phy_lock);
  3999. msleep(20);
  4000. spin_lock_bh(&bp->phy_lock);
  4001. bp->current_interval = SERDES_AN_TIMEOUT;
  4002. bp->serdes_an_pending = 1;
  4003. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4004. }
  4005. bnx2_read_phy(bp, MII_BMCR, &bmcr);
  4006. bmcr &= ~BMCR_LOOPBACK;
  4007. bnx2_write_phy(bp, MII_BMCR, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  4008. spin_unlock_bh(&bp->phy_lock);
  4009. return 0;
  4010. }
  4011. static int
  4012. bnx2_get_eeprom_len(struct net_device *dev)
  4013. {
  4014. struct bnx2 *bp = netdev_priv(dev);
  4015. if (bp->flash_info == NULL)
  4016. return 0;
  4017. return (int) bp->flash_size;
  4018. }
  4019. static int
  4020. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  4021. u8 *eebuf)
  4022. {
  4023. struct bnx2 *bp = netdev_priv(dev);
  4024. int rc;
  4025. /* parameters already validated in ethtool_get_eeprom */
  4026. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  4027. return rc;
  4028. }
  4029. static int
  4030. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  4031. u8 *eebuf)
  4032. {
  4033. struct bnx2 *bp = netdev_priv(dev);
  4034. int rc;
  4035. /* parameters already validated in ethtool_set_eeprom */
  4036. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  4037. return rc;
  4038. }
  4039. static int
  4040. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4041. {
  4042. struct bnx2 *bp = netdev_priv(dev);
  4043. memset(coal, 0, sizeof(struct ethtool_coalesce));
  4044. coal->rx_coalesce_usecs = bp->rx_ticks;
  4045. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  4046. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  4047. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  4048. coal->tx_coalesce_usecs = bp->tx_ticks;
  4049. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  4050. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  4051. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  4052. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  4053. return 0;
  4054. }
  4055. static int
  4056. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4057. {
  4058. struct bnx2 *bp = netdev_priv(dev);
  4059. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  4060. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  4061. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  4062. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  4063. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  4064. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  4065. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  4066. if (bp->rx_quick_cons_trip_int > 0xff)
  4067. bp->rx_quick_cons_trip_int = 0xff;
  4068. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  4069. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  4070. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  4071. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  4072. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  4073. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  4074. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  4075. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  4076. 0xff;
  4077. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  4078. if (bp->stats_ticks > 0xffff00) bp->stats_ticks = 0xffff00;
  4079. bp->stats_ticks &= 0xffff00;
  4080. if (netif_running(bp->dev)) {
  4081. bnx2_netif_stop(bp);
  4082. bnx2_init_nic(bp);
  4083. bnx2_netif_start(bp);
  4084. }
  4085. return 0;
  4086. }
  4087. static void
  4088. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4089. {
  4090. struct bnx2 *bp = netdev_priv(dev);
  4091. ering->rx_max_pending = MAX_TOTAL_RX_DESC_CNT;
  4092. ering->rx_mini_max_pending = 0;
  4093. ering->rx_jumbo_max_pending = 0;
  4094. ering->rx_pending = bp->rx_ring_size;
  4095. ering->rx_mini_pending = 0;
  4096. ering->rx_jumbo_pending = 0;
  4097. ering->tx_max_pending = MAX_TX_DESC_CNT;
  4098. ering->tx_pending = bp->tx_ring_size;
  4099. }
  4100. static int
  4101. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4102. {
  4103. struct bnx2 *bp = netdev_priv(dev);
  4104. if ((ering->rx_pending > MAX_TOTAL_RX_DESC_CNT) ||
  4105. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  4106. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  4107. return -EINVAL;
  4108. }
  4109. if (netif_running(bp->dev)) {
  4110. bnx2_netif_stop(bp);
  4111. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  4112. bnx2_free_skbs(bp);
  4113. bnx2_free_mem(bp);
  4114. }
  4115. bnx2_set_rx_ring_size(bp, ering->rx_pending);
  4116. bp->tx_ring_size = ering->tx_pending;
  4117. if (netif_running(bp->dev)) {
  4118. int rc;
  4119. rc = bnx2_alloc_mem(bp);
  4120. if (rc)
  4121. return rc;
  4122. bnx2_init_nic(bp);
  4123. bnx2_netif_start(bp);
  4124. }
  4125. return 0;
  4126. }
  4127. static void
  4128. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4129. {
  4130. struct bnx2 *bp = netdev_priv(dev);
  4131. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  4132. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  4133. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  4134. }
  4135. static int
  4136. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4137. {
  4138. struct bnx2 *bp = netdev_priv(dev);
  4139. bp->req_flow_ctrl = 0;
  4140. if (epause->rx_pause)
  4141. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  4142. if (epause->tx_pause)
  4143. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  4144. if (epause->autoneg) {
  4145. bp->autoneg |= AUTONEG_FLOW_CTRL;
  4146. }
  4147. else {
  4148. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  4149. }
  4150. spin_lock_bh(&bp->phy_lock);
  4151. bnx2_setup_phy(bp);
  4152. spin_unlock_bh(&bp->phy_lock);
  4153. return 0;
  4154. }
  4155. static u32
  4156. bnx2_get_rx_csum(struct net_device *dev)
  4157. {
  4158. struct bnx2 *bp = netdev_priv(dev);
  4159. return bp->rx_csum;
  4160. }
  4161. static int
  4162. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  4163. {
  4164. struct bnx2 *bp = netdev_priv(dev);
  4165. bp->rx_csum = data;
  4166. return 0;
  4167. }
  4168. static int
  4169. bnx2_set_tso(struct net_device *dev, u32 data)
  4170. {
  4171. if (data)
  4172. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  4173. else
  4174. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
  4175. return 0;
  4176. }
  4177. #define BNX2_NUM_STATS 46
  4178. static struct {
  4179. char string[ETH_GSTRING_LEN];
  4180. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  4181. { "rx_bytes" },
  4182. { "rx_error_bytes" },
  4183. { "tx_bytes" },
  4184. { "tx_error_bytes" },
  4185. { "rx_ucast_packets" },
  4186. { "rx_mcast_packets" },
  4187. { "rx_bcast_packets" },
  4188. { "tx_ucast_packets" },
  4189. { "tx_mcast_packets" },
  4190. { "tx_bcast_packets" },
  4191. { "tx_mac_errors" },
  4192. { "tx_carrier_errors" },
  4193. { "rx_crc_errors" },
  4194. { "rx_align_errors" },
  4195. { "tx_single_collisions" },
  4196. { "tx_multi_collisions" },
  4197. { "tx_deferred" },
  4198. { "tx_excess_collisions" },
  4199. { "tx_late_collisions" },
  4200. { "tx_total_collisions" },
  4201. { "rx_fragments" },
  4202. { "rx_jabbers" },
  4203. { "rx_undersize_packets" },
  4204. { "rx_oversize_packets" },
  4205. { "rx_64_byte_packets" },
  4206. { "rx_65_to_127_byte_packets" },
  4207. { "rx_128_to_255_byte_packets" },
  4208. { "rx_256_to_511_byte_packets" },
  4209. { "rx_512_to_1023_byte_packets" },
  4210. { "rx_1024_to_1522_byte_packets" },
  4211. { "rx_1523_to_9022_byte_packets" },
  4212. { "tx_64_byte_packets" },
  4213. { "tx_65_to_127_byte_packets" },
  4214. { "tx_128_to_255_byte_packets" },
  4215. { "tx_256_to_511_byte_packets" },
  4216. { "tx_512_to_1023_byte_packets" },
  4217. { "tx_1024_to_1522_byte_packets" },
  4218. { "tx_1523_to_9022_byte_packets" },
  4219. { "rx_xon_frames" },
  4220. { "rx_xoff_frames" },
  4221. { "tx_xon_frames" },
  4222. { "tx_xoff_frames" },
  4223. { "rx_mac_ctrl_frames" },
  4224. { "rx_filtered_packets" },
  4225. { "rx_discards" },
  4226. { "rx_fw_discards" },
  4227. };
  4228. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  4229. static const unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  4230. STATS_OFFSET32(stat_IfHCInOctets_hi),
  4231. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  4232. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  4233. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  4234. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  4235. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  4236. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  4237. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  4238. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  4239. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  4240. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  4241. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  4242. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  4243. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  4244. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  4245. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  4246. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  4247. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  4248. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  4249. STATS_OFFSET32(stat_EtherStatsCollisions),
  4250. STATS_OFFSET32(stat_EtherStatsFragments),
  4251. STATS_OFFSET32(stat_EtherStatsJabbers),
  4252. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  4253. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  4254. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  4255. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  4256. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  4257. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  4258. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  4259. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  4260. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  4261. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  4262. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  4263. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  4264. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  4265. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  4266. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  4267. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  4268. STATS_OFFSET32(stat_XonPauseFramesReceived),
  4269. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  4270. STATS_OFFSET32(stat_OutXonSent),
  4271. STATS_OFFSET32(stat_OutXoffSent),
  4272. STATS_OFFSET32(stat_MacControlFramesReceived),
  4273. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  4274. STATS_OFFSET32(stat_IfInMBUFDiscards),
  4275. STATS_OFFSET32(stat_FwRxDrop),
  4276. };
  4277. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  4278. * skipped because of errata.
  4279. */
  4280. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  4281. 8,0,8,8,8,8,8,8,8,8,
  4282. 4,0,4,4,4,4,4,4,4,4,
  4283. 4,4,4,4,4,4,4,4,4,4,
  4284. 4,4,4,4,4,4,4,4,4,4,
  4285. 4,4,4,4,4,4,
  4286. };
  4287. static u8 bnx2_5708_stats_len_arr[BNX2_NUM_STATS] = {
  4288. 8,0,8,8,8,8,8,8,8,8,
  4289. 4,4,4,4,4,4,4,4,4,4,
  4290. 4,4,4,4,4,4,4,4,4,4,
  4291. 4,4,4,4,4,4,4,4,4,4,
  4292. 4,4,4,4,4,4,
  4293. };
  4294. #define BNX2_NUM_TESTS 6
  4295. static struct {
  4296. char string[ETH_GSTRING_LEN];
  4297. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  4298. { "register_test (offline)" },
  4299. { "memory_test (offline)" },
  4300. { "loopback_test (offline)" },
  4301. { "nvram_test (online)" },
  4302. { "interrupt_test (online)" },
  4303. { "link_test (online)" },
  4304. };
  4305. static int
  4306. bnx2_self_test_count(struct net_device *dev)
  4307. {
  4308. return BNX2_NUM_TESTS;
  4309. }
  4310. static void
  4311. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  4312. {
  4313. struct bnx2 *bp = netdev_priv(dev);
  4314. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  4315. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  4316. int i;
  4317. bnx2_netif_stop(bp);
  4318. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  4319. bnx2_free_skbs(bp);
  4320. if (bnx2_test_registers(bp) != 0) {
  4321. buf[0] = 1;
  4322. etest->flags |= ETH_TEST_FL_FAILED;
  4323. }
  4324. if (bnx2_test_memory(bp) != 0) {
  4325. buf[1] = 1;
  4326. etest->flags |= ETH_TEST_FL_FAILED;
  4327. }
  4328. if ((buf[2] = bnx2_test_loopback(bp)) != 0)
  4329. etest->flags |= ETH_TEST_FL_FAILED;
  4330. if (!netif_running(bp->dev)) {
  4331. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  4332. }
  4333. else {
  4334. bnx2_init_nic(bp);
  4335. bnx2_netif_start(bp);
  4336. }
  4337. /* wait for link up */
  4338. for (i = 0; i < 7; i++) {
  4339. if (bp->link_up)
  4340. break;
  4341. msleep_interruptible(1000);
  4342. }
  4343. }
  4344. if (bnx2_test_nvram(bp) != 0) {
  4345. buf[3] = 1;
  4346. etest->flags |= ETH_TEST_FL_FAILED;
  4347. }
  4348. if (bnx2_test_intr(bp) != 0) {
  4349. buf[4] = 1;
  4350. etest->flags |= ETH_TEST_FL_FAILED;
  4351. }
  4352. if (bnx2_test_link(bp) != 0) {
  4353. buf[5] = 1;
  4354. etest->flags |= ETH_TEST_FL_FAILED;
  4355. }
  4356. }
  4357. static void
  4358. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  4359. {
  4360. switch (stringset) {
  4361. case ETH_SS_STATS:
  4362. memcpy(buf, bnx2_stats_str_arr,
  4363. sizeof(bnx2_stats_str_arr));
  4364. break;
  4365. case ETH_SS_TEST:
  4366. memcpy(buf, bnx2_tests_str_arr,
  4367. sizeof(bnx2_tests_str_arr));
  4368. break;
  4369. }
  4370. }
  4371. static int
  4372. bnx2_get_stats_count(struct net_device *dev)
  4373. {
  4374. return BNX2_NUM_STATS;
  4375. }
  4376. static void
  4377. bnx2_get_ethtool_stats(struct net_device *dev,
  4378. struct ethtool_stats *stats, u64 *buf)
  4379. {
  4380. struct bnx2 *bp = netdev_priv(dev);
  4381. int i;
  4382. u32 *hw_stats = (u32 *) bp->stats_blk;
  4383. u8 *stats_len_arr = NULL;
  4384. if (hw_stats == NULL) {
  4385. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  4386. return;
  4387. }
  4388. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  4389. (CHIP_ID(bp) == CHIP_ID_5706_A1) ||
  4390. (CHIP_ID(bp) == CHIP_ID_5706_A2) ||
  4391. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  4392. stats_len_arr = bnx2_5706_stats_len_arr;
  4393. else
  4394. stats_len_arr = bnx2_5708_stats_len_arr;
  4395. for (i = 0; i < BNX2_NUM_STATS; i++) {
  4396. if (stats_len_arr[i] == 0) {
  4397. /* skip this counter */
  4398. buf[i] = 0;
  4399. continue;
  4400. }
  4401. if (stats_len_arr[i] == 4) {
  4402. /* 4-byte counter */
  4403. buf[i] = (u64)
  4404. *(hw_stats + bnx2_stats_offset_arr[i]);
  4405. continue;
  4406. }
  4407. /* 8-byte counter */
  4408. buf[i] = (((u64) *(hw_stats +
  4409. bnx2_stats_offset_arr[i])) << 32) +
  4410. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  4411. }
  4412. }
  4413. static int
  4414. bnx2_phys_id(struct net_device *dev, u32 data)
  4415. {
  4416. struct bnx2 *bp = netdev_priv(dev);
  4417. int i;
  4418. u32 save;
  4419. if (data == 0)
  4420. data = 2;
  4421. save = REG_RD(bp, BNX2_MISC_CFG);
  4422. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  4423. for (i = 0; i < (data * 2); i++) {
  4424. if ((i % 2) == 0) {
  4425. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  4426. }
  4427. else {
  4428. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  4429. BNX2_EMAC_LED_1000MB_OVERRIDE |
  4430. BNX2_EMAC_LED_100MB_OVERRIDE |
  4431. BNX2_EMAC_LED_10MB_OVERRIDE |
  4432. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  4433. BNX2_EMAC_LED_TRAFFIC);
  4434. }
  4435. msleep_interruptible(500);
  4436. if (signal_pending(current))
  4437. break;
  4438. }
  4439. REG_WR(bp, BNX2_EMAC_LED, 0);
  4440. REG_WR(bp, BNX2_MISC_CFG, save);
  4441. return 0;
  4442. }
  4443. static const struct ethtool_ops bnx2_ethtool_ops = {
  4444. .get_settings = bnx2_get_settings,
  4445. .set_settings = bnx2_set_settings,
  4446. .get_drvinfo = bnx2_get_drvinfo,
  4447. .get_regs_len = bnx2_get_regs_len,
  4448. .get_regs = bnx2_get_regs,
  4449. .get_wol = bnx2_get_wol,
  4450. .set_wol = bnx2_set_wol,
  4451. .nway_reset = bnx2_nway_reset,
  4452. .get_link = ethtool_op_get_link,
  4453. .get_eeprom_len = bnx2_get_eeprom_len,
  4454. .get_eeprom = bnx2_get_eeprom,
  4455. .set_eeprom = bnx2_set_eeprom,
  4456. .get_coalesce = bnx2_get_coalesce,
  4457. .set_coalesce = bnx2_set_coalesce,
  4458. .get_ringparam = bnx2_get_ringparam,
  4459. .set_ringparam = bnx2_set_ringparam,
  4460. .get_pauseparam = bnx2_get_pauseparam,
  4461. .set_pauseparam = bnx2_set_pauseparam,
  4462. .get_rx_csum = bnx2_get_rx_csum,
  4463. .set_rx_csum = bnx2_set_rx_csum,
  4464. .get_tx_csum = ethtool_op_get_tx_csum,
  4465. .set_tx_csum = ethtool_op_set_tx_csum,
  4466. .get_sg = ethtool_op_get_sg,
  4467. .set_sg = ethtool_op_set_sg,
  4468. #ifdef BCM_TSO
  4469. .get_tso = ethtool_op_get_tso,
  4470. .set_tso = bnx2_set_tso,
  4471. #endif
  4472. .self_test_count = bnx2_self_test_count,
  4473. .self_test = bnx2_self_test,
  4474. .get_strings = bnx2_get_strings,
  4475. .phys_id = bnx2_phys_id,
  4476. .get_stats_count = bnx2_get_stats_count,
  4477. .get_ethtool_stats = bnx2_get_ethtool_stats,
  4478. .get_perm_addr = ethtool_op_get_perm_addr,
  4479. };
  4480. /* Called with rtnl_lock */
  4481. static int
  4482. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  4483. {
  4484. struct mii_ioctl_data *data = if_mii(ifr);
  4485. struct bnx2 *bp = netdev_priv(dev);
  4486. int err;
  4487. switch(cmd) {
  4488. case SIOCGMIIPHY:
  4489. data->phy_id = bp->phy_addr;
  4490. /* fallthru */
  4491. case SIOCGMIIREG: {
  4492. u32 mii_regval;
  4493. spin_lock_bh(&bp->phy_lock);
  4494. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  4495. spin_unlock_bh(&bp->phy_lock);
  4496. data->val_out = mii_regval;
  4497. return err;
  4498. }
  4499. case SIOCSMIIREG:
  4500. if (!capable(CAP_NET_ADMIN))
  4501. return -EPERM;
  4502. spin_lock_bh(&bp->phy_lock);
  4503. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  4504. spin_unlock_bh(&bp->phy_lock);
  4505. return err;
  4506. default:
  4507. /* do nothing */
  4508. break;
  4509. }
  4510. return -EOPNOTSUPP;
  4511. }
  4512. /* Called with rtnl_lock */
  4513. static int
  4514. bnx2_change_mac_addr(struct net_device *dev, void *p)
  4515. {
  4516. struct sockaddr *addr = p;
  4517. struct bnx2 *bp = netdev_priv(dev);
  4518. if (!is_valid_ether_addr(addr->sa_data))
  4519. return -EINVAL;
  4520. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4521. if (netif_running(dev))
  4522. bnx2_set_mac_addr(bp);
  4523. return 0;
  4524. }
  4525. /* Called with rtnl_lock */
  4526. static int
  4527. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  4528. {
  4529. struct bnx2 *bp = netdev_priv(dev);
  4530. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  4531. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  4532. return -EINVAL;
  4533. dev->mtu = new_mtu;
  4534. if (netif_running(dev)) {
  4535. bnx2_netif_stop(bp);
  4536. bnx2_init_nic(bp);
  4537. bnx2_netif_start(bp);
  4538. }
  4539. return 0;
  4540. }
  4541. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4542. static void
  4543. poll_bnx2(struct net_device *dev)
  4544. {
  4545. struct bnx2 *bp = netdev_priv(dev);
  4546. disable_irq(bp->pdev->irq);
  4547. bnx2_interrupt(bp->pdev->irq, dev);
  4548. enable_irq(bp->pdev->irq);
  4549. }
  4550. #endif
  4551. static int __devinit
  4552. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  4553. {
  4554. struct bnx2 *bp;
  4555. unsigned long mem_len;
  4556. int rc;
  4557. u32 reg;
  4558. SET_MODULE_OWNER(dev);
  4559. SET_NETDEV_DEV(dev, &pdev->dev);
  4560. bp = netdev_priv(dev);
  4561. bp->flags = 0;
  4562. bp->phy_flags = 0;
  4563. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  4564. rc = pci_enable_device(pdev);
  4565. if (rc) {
  4566. dev_err(&pdev->dev, "Cannot enable PCI device, aborting.");
  4567. goto err_out;
  4568. }
  4569. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  4570. dev_err(&pdev->dev,
  4571. "Cannot find PCI device base address, aborting.\n");
  4572. rc = -ENODEV;
  4573. goto err_out_disable;
  4574. }
  4575. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  4576. if (rc) {
  4577. dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting.\n");
  4578. goto err_out_disable;
  4579. }
  4580. pci_set_master(pdev);
  4581. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  4582. if (bp->pm_cap == 0) {
  4583. dev_err(&pdev->dev,
  4584. "Cannot find power management capability, aborting.\n");
  4585. rc = -EIO;
  4586. goto err_out_release;
  4587. }
  4588. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  4589. if (bp->pcix_cap == 0) {
  4590. dev_err(&pdev->dev, "Cannot find PCIX capability, aborting.\n");
  4591. rc = -EIO;
  4592. goto err_out_release;
  4593. }
  4594. if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
  4595. bp->flags |= USING_DAC_FLAG;
  4596. if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) {
  4597. dev_err(&pdev->dev,
  4598. "pci_set_consistent_dma_mask failed, aborting.\n");
  4599. rc = -EIO;
  4600. goto err_out_release;
  4601. }
  4602. }
  4603. else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
  4604. dev_err(&pdev->dev, "System does not support DMA, aborting.\n");
  4605. rc = -EIO;
  4606. goto err_out_release;
  4607. }
  4608. bp->dev = dev;
  4609. bp->pdev = pdev;
  4610. spin_lock_init(&bp->phy_lock);
  4611. INIT_WORK(&bp->reset_task, bnx2_reset_task, bp);
  4612. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  4613. mem_len = MB_GET_CID_ADDR(17);
  4614. dev->mem_end = dev->mem_start + mem_len;
  4615. dev->irq = pdev->irq;
  4616. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  4617. if (!bp->regview) {
  4618. dev_err(&pdev->dev, "Cannot map register space, aborting.\n");
  4619. rc = -ENOMEM;
  4620. goto err_out_release;
  4621. }
  4622. /* Configure byte swap and enable write to the reg_window registers.
  4623. * Rely on CPU to do target byte swapping on big endian systems
  4624. * The chip's target access swapping will not swap all accesses
  4625. */
  4626. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  4627. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  4628. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  4629. bnx2_set_power_state(bp, PCI_D0);
  4630. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  4631. /* Get bus information. */
  4632. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  4633. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  4634. u32 clkreg;
  4635. bp->flags |= PCIX_FLAG;
  4636. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  4637. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  4638. switch (clkreg) {
  4639. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  4640. bp->bus_speed_mhz = 133;
  4641. break;
  4642. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  4643. bp->bus_speed_mhz = 100;
  4644. break;
  4645. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  4646. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  4647. bp->bus_speed_mhz = 66;
  4648. break;
  4649. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  4650. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  4651. bp->bus_speed_mhz = 50;
  4652. break;
  4653. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  4654. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  4655. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  4656. bp->bus_speed_mhz = 33;
  4657. break;
  4658. }
  4659. }
  4660. else {
  4661. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  4662. bp->bus_speed_mhz = 66;
  4663. else
  4664. bp->bus_speed_mhz = 33;
  4665. }
  4666. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  4667. bp->flags |= PCI_32BIT_FLAG;
  4668. /* 5706A0 may falsely detect SERR and PERR. */
  4669. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4670. reg = REG_RD(bp, PCI_COMMAND);
  4671. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  4672. REG_WR(bp, PCI_COMMAND, reg);
  4673. }
  4674. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  4675. !(bp->flags & PCIX_FLAG)) {
  4676. dev_err(&pdev->dev,
  4677. "5706 A1 can only be used in a PCIX bus, aborting.\n");
  4678. goto err_out_unmap;
  4679. }
  4680. bnx2_init_nvram(bp);
  4681. reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE);
  4682. if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
  4683. BNX2_SHM_HDR_SIGNATURE_SIG)
  4684. bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0);
  4685. else
  4686. bp->shmem_base = HOST_VIEW_SHMEM_BASE;
  4687. /* Get the permanent MAC address. First we need to make sure the
  4688. * firmware is actually running.
  4689. */
  4690. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_SIGNATURE);
  4691. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  4692. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  4693. dev_err(&pdev->dev, "Firmware not running, aborting.\n");
  4694. rc = -ENODEV;
  4695. goto err_out_unmap;
  4696. }
  4697. bp->fw_ver = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
  4698. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER);
  4699. bp->mac_addr[0] = (u8) (reg >> 8);
  4700. bp->mac_addr[1] = (u8) reg;
  4701. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_LOWER);
  4702. bp->mac_addr[2] = (u8) (reg >> 24);
  4703. bp->mac_addr[3] = (u8) (reg >> 16);
  4704. bp->mac_addr[4] = (u8) (reg >> 8);
  4705. bp->mac_addr[5] = (u8) reg;
  4706. bp->tx_ring_size = MAX_TX_DESC_CNT;
  4707. bnx2_set_rx_ring_size(bp, 255);
  4708. bp->rx_csum = 1;
  4709. bp->rx_offset = sizeof(struct l2_fhdr) + 2;
  4710. bp->tx_quick_cons_trip_int = 20;
  4711. bp->tx_quick_cons_trip = 20;
  4712. bp->tx_ticks_int = 80;
  4713. bp->tx_ticks = 80;
  4714. bp->rx_quick_cons_trip_int = 6;
  4715. bp->rx_quick_cons_trip = 6;
  4716. bp->rx_ticks_int = 18;
  4717. bp->rx_ticks = 18;
  4718. bp->stats_ticks = 1000000 & 0xffff00;
  4719. bp->timer_interval = HZ;
  4720. bp->current_interval = HZ;
  4721. bp->phy_addr = 1;
  4722. /* Disable WOL support if we are running on a SERDES chip. */
  4723. if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) {
  4724. bp->phy_flags |= PHY_SERDES_FLAG;
  4725. bp->flags |= NO_WOL_FLAG;
  4726. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  4727. bp->phy_addr = 2;
  4728. reg = REG_RD_IND(bp, bp->shmem_base +
  4729. BNX2_SHARED_HW_CFG_CONFIG);
  4730. if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
  4731. bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
  4732. }
  4733. }
  4734. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  4735. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  4736. (CHIP_ID(bp) == CHIP_ID_5708_B1))
  4737. bp->flags |= NO_WOL_FLAG;
  4738. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4739. bp->tx_quick_cons_trip_int =
  4740. bp->tx_quick_cons_trip;
  4741. bp->tx_ticks_int = bp->tx_ticks;
  4742. bp->rx_quick_cons_trip_int =
  4743. bp->rx_quick_cons_trip;
  4744. bp->rx_ticks_int = bp->rx_ticks;
  4745. bp->comp_prod_trip_int = bp->comp_prod_trip;
  4746. bp->com_ticks_int = bp->com_ticks;
  4747. bp->cmd_ticks_int = bp->cmd_ticks;
  4748. }
  4749. /* Disable MSI on 5706 if AMD 8132 bridge is found.
  4750. *
  4751. * MSI is defined to be 32-bit write. The 5706 does 64-bit MSI writes
  4752. * with byte enables disabled on the unused 32-bit word. This is legal
  4753. * but causes problems on the AMD 8132 which will eventually stop
  4754. * responding after a while.
  4755. *
  4756. * AMD believes this incompatibility is unique to the 5706, and
  4757. * prefers to locally disable MSI rather than globally disabling it
  4758. * using pci_msi_quirk.
  4759. */
  4760. if (CHIP_NUM(bp) == CHIP_NUM_5706 && disable_msi == 0) {
  4761. struct pci_dev *amd_8132 = NULL;
  4762. while ((amd_8132 = pci_get_device(PCI_VENDOR_ID_AMD,
  4763. PCI_DEVICE_ID_AMD_8132_BRIDGE,
  4764. amd_8132))) {
  4765. u8 rev;
  4766. pci_read_config_byte(amd_8132, PCI_REVISION_ID, &rev);
  4767. if (rev >= 0x10 && rev <= 0x13) {
  4768. disable_msi = 1;
  4769. pci_dev_put(amd_8132);
  4770. break;
  4771. }
  4772. }
  4773. }
  4774. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  4775. bp->req_line_speed = 0;
  4776. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4777. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  4778. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
  4779. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  4780. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  4781. bp->autoneg = 0;
  4782. bp->req_line_speed = bp->line_speed = SPEED_1000;
  4783. bp->req_duplex = DUPLEX_FULL;
  4784. }
  4785. }
  4786. else {
  4787. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  4788. }
  4789. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  4790. init_timer(&bp->timer);
  4791. bp->timer.expires = RUN_AT(bp->timer_interval);
  4792. bp->timer.data = (unsigned long) bp;
  4793. bp->timer.function = bnx2_timer;
  4794. return 0;
  4795. err_out_unmap:
  4796. if (bp->regview) {
  4797. iounmap(bp->regview);
  4798. bp->regview = NULL;
  4799. }
  4800. err_out_release:
  4801. pci_release_regions(pdev);
  4802. err_out_disable:
  4803. pci_disable_device(pdev);
  4804. pci_set_drvdata(pdev, NULL);
  4805. err_out:
  4806. return rc;
  4807. }
  4808. static int __devinit
  4809. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4810. {
  4811. static int version_printed = 0;
  4812. struct net_device *dev = NULL;
  4813. struct bnx2 *bp;
  4814. int rc, i;
  4815. if (version_printed++ == 0)
  4816. printk(KERN_INFO "%s", version);
  4817. /* dev zeroed in init_etherdev */
  4818. dev = alloc_etherdev(sizeof(*bp));
  4819. if (!dev)
  4820. return -ENOMEM;
  4821. rc = bnx2_init_board(pdev, dev);
  4822. if (rc < 0) {
  4823. free_netdev(dev);
  4824. return rc;
  4825. }
  4826. dev->open = bnx2_open;
  4827. dev->hard_start_xmit = bnx2_start_xmit;
  4828. dev->stop = bnx2_close;
  4829. dev->get_stats = bnx2_get_stats;
  4830. dev->set_multicast_list = bnx2_set_rx_mode;
  4831. dev->do_ioctl = bnx2_ioctl;
  4832. dev->set_mac_address = bnx2_change_mac_addr;
  4833. dev->change_mtu = bnx2_change_mtu;
  4834. dev->tx_timeout = bnx2_tx_timeout;
  4835. dev->watchdog_timeo = TX_TIMEOUT;
  4836. #ifdef BCM_VLAN
  4837. dev->vlan_rx_register = bnx2_vlan_rx_register;
  4838. dev->vlan_rx_kill_vid = bnx2_vlan_rx_kill_vid;
  4839. #endif
  4840. dev->poll = bnx2_poll;
  4841. dev->ethtool_ops = &bnx2_ethtool_ops;
  4842. dev->weight = 64;
  4843. bp = netdev_priv(dev);
  4844. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4845. dev->poll_controller = poll_bnx2;
  4846. #endif
  4847. if ((rc = register_netdev(dev))) {
  4848. dev_err(&pdev->dev, "Cannot register net device\n");
  4849. if (bp->regview)
  4850. iounmap(bp->regview);
  4851. pci_release_regions(pdev);
  4852. pci_disable_device(pdev);
  4853. pci_set_drvdata(pdev, NULL);
  4854. free_netdev(dev);
  4855. return rc;
  4856. }
  4857. pci_set_drvdata(pdev, dev);
  4858. memcpy(dev->dev_addr, bp->mac_addr, 6);
  4859. memcpy(dev->perm_addr, bp->mac_addr, 6);
  4860. bp->name = board_info[ent->driver_data].name,
  4861. printk(KERN_INFO "%s: %s (%c%d) PCI%s %s %dMHz found at mem %lx, "
  4862. "IRQ %d, ",
  4863. dev->name,
  4864. bp->name,
  4865. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  4866. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  4867. ((bp->flags & PCIX_FLAG) ? "-X" : ""),
  4868. ((bp->flags & PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
  4869. bp->bus_speed_mhz,
  4870. dev->base_addr,
  4871. bp->pdev->irq);
  4872. printk("node addr ");
  4873. for (i = 0; i < 6; i++)
  4874. printk("%2.2x", dev->dev_addr[i]);
  4875. printk("\n");
  4876. dev->features |= NETIF_F_SG;
  4877. if (bp->flags & USING_DAC_FLAG)
  4878. dev->features |= NETIF_F_HIGHDMA;
  4879. dev->features |= NETIF_F_IP_CSUM;
  4880. #ifdef BCM_VLAN
  4881. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  4882. #endif
  4883. #ifdef BCM_TSO
  4884. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  4885. #endif
  4886. netif_carrier_off(bp->dev);
  4887. return 0;
  4888. }
  4889. static void __devexit
  4890. bnx2_remove_one(struct pci_dev *pdev)
  4891. {
  4892. struct net_device *dev = pci_get_drvdata(pdev);
  4893. struct bnx2 *bp = netdev_priv(dev);
  4894. flush_scheduled_work();
  4895. unregister_netdev(dev);
  4896. if (bp->regview)
  4897. iounmap(bp->regview);
  4898. free_netdev(dev);
  4899. pci_release_regions(pdev);
  4900. pci_disable_device(pdev);
  4901. pci_set_drvdata(pdev, NULL);
  4902. }
  4903. static int
  4904. bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
  4905. {
  4906. struct net_device *dev = pci_get_drvdata(pdev);
  4907. struct bnx2 *bp = netdev_priv(dev);
  4908. u32 reset_code;
  4909. if (!netif_running(dev))
  4910. return 0;
  4911. flush_scheduled_work();
  4912. bnx2_netif_stop(bp);
  4913. netif_device_detach(dev);
  4914. del_timer_sync(&bp->timer);
  4915. if (bp->flags & NO_WOL_FLAG)
  4916. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  4917. else if (bp->wol)
  4918. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  4919. else
  4920. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  4921. bnx2_reset_chip(bp, reset_code);
  4922. bnx2_free_skbs(bp);
  4923. bnx2_set_power_state(bp, pci_choose_state(pdev, state));
  4924. return 0;
  4925. }
  4926. static int
  4927. bnx2_resume(struct pci_dev *pdev)
  4928. {
  4929. struct net_device *dev = pci_get_drvdata(pdev);
  4930. struct bnx2 *bp = netdev_priv(dev);
  4931. if (!netif_running(dev))
  4932. return 0;
  4933. bnx2_set_power_state(bp, PCI_D0);
  4934. netif_device_attach(dev);
  4935. bnx2_init_nic(bp);
  4936. bnx2_netif_start(bp);
  4937. return 0;
  4938. }
  4939. static struct pci_driver bnx2_pci_driver = {
  4940. .name = DRV_MODULE_NAME,
  4941. .id_table = bnx2_pci_tbl,
  4942. .probe = bnx2_init_one,
  4943. .remove = __devexit_p(bnx2_remove_one),
  4944. .suspend = bnx2_suspend,
  4945. .resume = bnx2_resume,
  4946. };
  4947. static int __init bnx2_init(void)
  4948. {
  4949. return pci_register_driver(&bnx2_pci_driver);
  4950. }
  4951. static void __exit bnx2_cleanup(void)
  4952. {
  4953. pci_unregister_driver(&bnx2_pci_driver);
  4954. }
  4955. module_init(bnx2_init);
  4956. module_exit(bnx2_cleanup);