bnx2.c 133 KB

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