bnx2.c 139 KB

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