bnx2x_main.c 289 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2011 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. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/device.h> /* for dev_info() */
  21. #include <linux/timer.h>
  22. #include <linux/errno.h>
  23. #include <linux/ioport.h>
  24. #include <linux/slab.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/pci.h>
  27. #include <linux/init.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/bitops.h>
  33. #include <linux/irq.h>
  34. #include <linux/delay.h>
  35. #include <asm/byteorder.h>
  36. #include <linux/time.h>
  37. #include <linux/ethtool.h>
  38. #include <linux/mii.h>
  39. #include <linux/if_vlan.h>
  40. #include <net/ip.h>
  41. #include <net/ipv6.h>
  42. #include <net/tcp.h>
  43. #include <net/checksum.h>
  44. #include <net/ip6_checksum.h>
  45. #include <linux/workqueue.h>
  46. #include <linux/crc32.h>
  47. #include <linux/crc32c.h>
  48. #include <linux/prefetch.h>
  49. #include <linux/zlib.h>
  50. #include <linux/io.h>
  51. #include <linux/stringify.h>
  52. #include "bnx2x.h"
  53. #include "bnx2x_init.h"
  54. #include "bnx2x_init_ops.h"
  55. #include "bnx2x_cmn.h"
  56. #include "bnx2x_dcb.h"
  57. #include "bnx2x_sp.h"
  58. #include <linux/firmware.h>
  59. #include "bnx2x_fw_file_hdr.h"
  60. /* FW files */
  61. #define FW_FILE_VERSION \
  62. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  63. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  64. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  65. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  66. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  67. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  68. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  69. /* Time in jiffies before concluding the transmitter is hung */
  70. #define TX_TIMEOUT (5*HZ)
  71. static char version[] __devinitdata =
  72. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  73. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  74. MODULE_AUTHOR("Eliezer Tamir");
  75. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  76. "BCM57710/57711/57711E/"
  77. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  78. "57840/57840_MF Driver");
  79. MODULE_LICENSE("GPL");
  80. MODULE_VERSION(DRV_MODULE_VERSION);
  81. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  82. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  83. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  84. static int multi_mode = 1;
  85. module_param(multi_mode, int, 0);
  86. MODULE_PARM_DESC(multi_mode, " Multi queue mode "
  87. "(0 Disable; 1 Enable (default))");
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
  91. " (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. static int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int poll;
  105. module_param(poll, int, 0);
  106. MODULE_PARM_DESC(poll, " Use polling (for debug)");
  107. static int mrrs = -1;
  108. module_param(mrrs, int, 0);
  109. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  110. static int debug;
  111. module_param(debug, int, 0);
  112. MODULE_PARM_DESC(debug, " Default debug msglevel");
  113. struct workqueue_struct *bnx2x_wq;
  114. enum bnx2x_board_type {
  115. BCM57710 = 0,
  116. BCM57711,
  117. BCM57711E,
  118. BCM57712,
  119. BCM57712_MF,
  120. BCM57800,
  121. BCM57800_MF,
  122. BCM57810,
  123. BCM57810_MF,
  124. BCM57840,
  125. BCM57840_MF
  126. };
  127. /* indexed by board_type, above */
  128. static struct {
  129. char *name;
  130. } board_info[] __devinitdata = {
  131. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  132. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  133. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  134. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  135. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  136. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  140. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  141. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
  142. "Ethernet Multi Function"}
  143. };
  144. #ifndef PCI_DEVICE_ID_NX2_57710
  145. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  146. #endif
  147. #ifndef PCI_DEVICE_ID_NX2_57711
  148. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  149. #endif
  150. #ifndef PCI_DEVICE_ID_NX2_57711E
  151. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  152. #endif
  153. #ifndef PCI_DEVICE_ID_NX2_57712
  154. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  155. #endif
  156. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  157. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  158. #endif
  159. #ifndef PCI_DEVICE_ID_NX2_57800
  160. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  161. #endif
  162. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  163. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57810
  166. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  169. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57840
  172. #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  175. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  176. #endif
  177. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  178. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  179. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  180. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  181. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  182. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  183. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  184. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  185. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  186. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  187. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
  188. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  189. { 0 }
  190. };
  191. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  192. /****************************************************************************
  193. * General service functions
  194. ****************************************************************************/
  195. static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
  196. u32 addr, dma_addr_t mapping)
  197. {
  198. REG_WR(bp, addr, U64_LO(mapping));
  199. REG_WR(bp, addr + 4, U64_HI(mapping));
  200. }
  201. static inline void storm_memset_spq_addr(struct bnx2x *bp,
  202. dma_addr_t mapping, u16 abs_fid)
  203. {
  204. u32 addr = XSEM_REG_FAST_MEMORY +
  205. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  206. __storm_memset_dma_mapping(bp, addr, mapping);
  207. }
  208. static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  209. u16 pf_id)
  210. {
  211. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  212. pf_id);
  213. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  214. pf_id);
  215. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  216. pf_id);
  217. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  218. pf_id);
  219. }
  220. static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  221. u8 enable)
  222. {
  223. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  224. enable);
  225. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  226. enable);
  227. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  228. enable);
  229. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  230. enable);
  231. }
  232. static inline void storm_memset_eq_data(struct bnx2x *bp,
  233. struct event_ring_data *eq_data,
  234. u16 pfid)
  235. {
  236. size_t size = sizeof(struct event_ring_data);
  237. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  238. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  239. }
  240. static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  241. u16 pfid)
  242. {
  243. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  244. REG_WR16(bp, addr, eq_prod);
  245. }
  246. /* used only at init
  247. * locking is done by mcp
  248. */
  249. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  250. {
  251. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  252. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  253. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  254. PCICFG_VENDOR_ID_OFFSET);
  255. }
  256. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  257. {
  258. u32 val;
  259. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  260. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  261. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  262. PCICFG_VENDOR_ID_OFFSET);
  263. return val;
  264. }
  265. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  266. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  267. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  268. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  269. #define DMAE_DP_DST_NONE "dst_addr [none]"
  270. static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
  271. int msglvl)
  272. {
  273. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  274. switch (dmae->opcode & DMAE_COMMAND_DST) {
  275. case DMAE_CMD_DST_PCI:
  276. if (src_type == DMAE_CMD_SRC_PCI)
  277. DP(msglvl, "DMAE: opcode 0x%08x\n"
  278. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  279. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  280. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  281. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  282. dmae->comp_addr_hi, dmae->comp_addr_lo,
  283. dmae->comp_val);
  284. else
  285. DP(msglvl, "DMAE: opcode 0x%08x\n"
  286. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  287. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  288. dmae->opcode, dmae->src_addr_lo >> 2,
  289. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  290. dmae->comp_addr_hi, dmae->comp_addr_lo,
  291. dmae->comp_val);
  292. break;
  293. case DMAE_CMD_DST_GRC:
  294. if (src_type == DMAE_CMD_SRC_PCI)
  295. DP(msglvl, "DMAE: opcode 0x%08x\n"
  296. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  297. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  298. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  299. dmae->len, dmae->dst_addr_lo >> 2,
  300. dmae->comp_addr_hi, dmae->comp_addr_lo,
  301. dmae->comp_val);
  302. else
  303. DP(msglvl, "DMAE: opcode 0x%08x\n"
  304. "src [%08x], len [%d*4], dst [%08x]\n"
  305. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  306. dmae->opcode, dmae->src_addr_lo >> 2,
  307. dmae->len, dmae->dst_addr_lo >> 2,
  308. dmae->comp_addr_hi, dmae->comp_addr_lo,
  309. dmae->comp_val);
  310. break;
  311. default:
  312. if (src_type == DMAE_CMD_SRC_PCI)
  313. DP(msglvl, "DMAE: opcode 0x%08x\n"
  314. DP_LEVEL "src_addr [%x:%08x] len [%d * 4] "
  315. "dst_addr [none]\n"
  316. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  317. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  318. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  319. dmae->comp_val);
  320. else
  321. DP(msglvl, "DMAE: opcode 0x%08x\n"
  322. DP_LEVEL "src_addr [%08x] len [%d * 4] "
  323. "dst_addr [none]\n"
  324. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  325. dmae->opcode, dmae->src_addr_lo >> 2,
  326. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  327. dmae->comp_val);
  328. break;
  329. }
  330. }
  331. /* copy command into DMAE command memory and set DMAE command go */
  332. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  333. {
  334. u32 cmd_offset;
  335. int i;
  336. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  337. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  338. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  339. DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
  340. idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
  341. }
  342. REG_WR(bp, dmae_reg_go_c[idx], 1);
  343. }
  344. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  345. {
  346. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  347. DMAE_CMD_C_ENABLE);
  348. }
  349. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  350. {
  351. return opcode & ~DMAE_CMD_SRC_RESET;
  352. }
  353. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  354. bool with_comp, u8 comp_type)
  355. {
  356. u32 opcode = 0;
  357. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  358. (dst_type << DMAE_COMMAND_DST_SHIFT));
  359. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  360. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  361. opcode |= ((BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  362. (BP_E1HVN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  363. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  364. #ifdef __BIG_ENDIAN
  365. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  366. #else
  367. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  368. #endif
  369. if (with_comp)
  370. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  371. return opcode;
  372. }
  373. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  374. struct dmae_command *dmae,
  375. u8 src_type, u8 dst_type)
  376. {
  377. memset(dmae, 0, sizeof(struct dmae_command));
  378. /* set the opcode */
  379. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  380. true, DMAE_COMP_PCI);
  381. /* fill in the completion parameters */
  382. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  383. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  384. dmae->comp_val = DMAE_COMP_VAL;
  385. }
  386. /* issue a dmae command over the init-channel and wailt for completion */
  387. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  388. struct dmae_command *dmae)
  389. {
  390. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  391. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  392. int rc = 0;
  393. DP(BNX2X_MSG_OFF, "data before [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  394. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  395. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  396. /*
  397. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  398. * as long as this code is called both from syscall context and
  399. * from ndo_set_rx_mode() flow that may be called from BH.
  400. */
  401. spin_lock_bh(&bp->dmae_lock);
  402. /* reset completion */
  403. *wb_comp = 0;
  404. /* post the command on the channel used for initializations */
  405. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  406. /* wait for completion */
  407. udelay(5);
  408. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  409. DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
  410. if (!cnt) {
  411. BNX2X_ERR("DMAE timeout!\n");
  412. rc = DMAE_TIMEOUT;
  413. goto unlock;
  414. }
  415. cnt--;
  416. udelay(50);
  417. }
  418. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  419. BNX2X_ERR("DMAE PCI error!\n");
  420. rc = DMAE_PCI_ERROR;
  421. }
  422. DP(BNX2X_MSG_OFF, "data after [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  423. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  424. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  425. unlock:
  426. spin_unlock_bh(&bp->dmae_lock);
  427. return rc;
  428. }
  429. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  430. u32 len32)
  431. {
  432. struct dmae_command dmae;
  433. if (!bp->dmae_ready) {
  434. u32 *data = bnx2x_sp(bp, wb_data[0]);
  435. DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
  436. " using indirect\n", dst_addr, len32);
  437. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  438. return;
  439. }
  440. /* set opcode and fixed command fields */
  441. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  442. /* fill in addresses and len */
  443. dmae.src_addr_lo = U64_LO(dma_addr);
  444. dmae.src_addr_hi = U64_HI(dma_addr);
  445. dmae.dst_addr_lo = dst_addr >> 2;
  446. dmae.dst_addr_hi = 0;
  447. dmae.len = len32;
  448. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  449. /* issue the command and wait for completion */
  450. bnx2x_issue_dmae_with_comp(bp, &dmae);
  451. }
  452. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  453. {
  454. struct dmae_command dmae;
  455. if (!bp->dmae_ready) {
  456. u32 *data = bnx2x_sp(bp, wb_data[0]);
  457. int i;
  458. DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
  459. " using indirect\n", src_addr, len32);
  460. for (i = 0; i < len32; i++)
  461. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  462. return;
  463. }
  464. /* set opcode and fixed command fields */
  465. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  466. /* fill in addresses and len */
  467. dmae.src_addr_lo = src_addr >> 2;
  468. dmae.src_addr_hi = 0;
  469. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  470. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  471. dmae.len = len32;
  472. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  473. /* issue the command and wait for completion */
  474. bnx2x_issue_dmae_with_comp(bp, &dmae);
  475. }
  476. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  477. u32 addr, u32 len)
  478. {
  479. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  480. int offset = 0;
  481. while (len > dmae_wr_max) {
  482. bnx2x_write_dmae(bp, phys_addr + offset,
  483. addr + offset, dmae_wr_max);
  484. offset += dmae_wr_max * 4;
  485. len -= dmae_wr_max;
  486. }
  487. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  488. }
  489. /* used only for slowpath so not inlined */
  490. static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
  491. {
  492. u32 wb_write[2];
  493. wb_write[0] = val_hi;
  494. wb_write[1] = val_lo;
  495. REG_WR_DMAE(bp, reg, wb_write, 2);
  496. }
  497. #ifdef USE_WB_RD
  498. static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
  499. {
  500. u32 wb_data[2];
  501. REG_RD_DMAE(bp, reg, wb_data, 2);
  502. return HILO_U64(wb_data[0], wb_data[1]);
  503. }
  504. #endif
  505. static int bnx2x_mc_assert(struct bnx2x *bp)
  506. {
  507. char last_idx;
  508. int i, rc = 0;
  509. u32 row0, row1, row2, row3;
  510. /* XSTORM */
  511. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  512. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  513. if (last_idx)
  514. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  515. /* print the asserts */
  516. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  517. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  518. XSTORM_ASSERT_LIST_OFFSET(i));
  519. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  520. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  521. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  522. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  523. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  524. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  525. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  526. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  527. " 0x%08x 0x%08x 0x%08x\n",
  528. i, row3, row2, row1, row0);
  529. rc++;
  530. } else {
  531. break;
  532. }
  533. }
  534. /* TSTORM */
  535. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  536. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  537. if (last_idx)
  538. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  539. /* print the asserts */
  540. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  541. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  542. TSTORM_ASSERT_LIST_OFFSET(i));
  543. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  544. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  545. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  546. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  547. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  548. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  549. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  550. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  551. " 0x%08x 0x%08x 0x%08x\n",
  552. i, row3, row2, row1, row0);
  553. rc++;
  554. } else {
  555. break;
  556. }
  557. }
  558. /* CSTORM */
  559. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  560. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  561. if (last_idx)
  562. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  563. /* print the asserts */
  564. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  565. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  566. CSTORM_ASSERT_LIST_OFFSET(i));
  567. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  568. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  569. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  570. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  571. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  572. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  573. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  574. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  575. " 0x%08x 0x%08x 0x%08x\n",
  576. i, row3, row2, row1, row0);
  577. rc++;
  578. } else {
  579. break;
  580. }
  581. }
  582. /* USTORM */
  583. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  584. USTORM_ASSERT_LIST_INDEX_OFFSET);
  585. if (last_idx)
  586. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  587. /* print the asserts */
  588. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  589. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  590. USTORM_ASSERT_LIST_OFFSET(i));
  591. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  592. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  593. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  594. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  595. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  596. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  597. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  598. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
  599. " 0x%08x 0x%08x 0x%08x\n",
  600. i, row3, row2, row1, row0);
  601. rc++;
  602. } else {
  603. break;
  604. }
  605. }
  606. return rc;
  607. }
  608. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  609. {
  610. u32 addr, val;
  611. u32 mark, offset;
  612. __be32 data[9];
  613. int word;
  614. u32 trace_shmem_base;
  615. if (BP_NOMCP(bp)) {
  616. BNX2X_ERR("NO MCP - can not dump\n");
  617. return;
  618. }
  619. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  620. (bp->common.bc_ver & 0xff0000) >> 16,
  621. (bp->common.bc_ver & 0xff00) >> 8,
  622. (bp->common.bc_ver & 0xff));
  623. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  624. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  625. printk("%s" "MCP PC at 0x%x\n", lvl, val);
  626. if (BP_PATH(bp) == 0)
  627. trace_shmem_base = bp->common.shmem_base;
  628. else
  629. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  630. addr = trace_shmem_base - 0x0800 + 4;
  631. mark = REG_RD(bp, addr);
  632. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  633. + ((mark + 0x3) & ~0x3) - 0x08000000;
  634. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  635. printk("%s", lvl);
  636. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  637. for (word = 0; word < 8; word++)
  638. data[word] = htonl(REG_RD(bp, offset + 4*word));
  639. data[8] = 0x0;
  640. pr_cont("%s", (char *)data);
  641. }
  642. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  643. for (word = 0; word < 8; word++)
  644. data[word] = htonl(REG_RD(bp, offset + 4*word));
  645. data[8] = 0x0;
  646. pr_cont("%s", (char *)data);
  647. }
  648. printk("%s" "end of fw dump\n", lvl);
  649. }
  650. static inline void bnx2x_fw_dump(struct bnx2x *bp)
  651. {
  652. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  653. }
  654. void bnx2x_panic_dump(struct bnx2x *bp)
  655. {
  656. int i;
  657. u16 j;
  658. struct hc_sp_status_block_data sp_sb_data;
  659. int func = BP_FUNC(bp);
  660. #ifdef BNX2X_STOP_ON_ERROR
  661. u16 start = 0, end = 0;
  662. #endif
  663. bp->stats_state = STATS_STATE_DISABLED;
  664. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  665. BNX2X_ERR("begin crash dump -----------------\n");
  666. /* Indices */
  667. /* Common */
  668. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)"
  669. " spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  670. bp->def_idx, bp->def_att_idx, bp->attn_state,
  671. bp->spq_prod_idx, bp->stats_counter);
  672. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  673. bp->def_status_blk->atten_status_block.attn_bits,
  674. bp->def_status_blk->atten_status_block.attn_bits_ack,
  675. bp->def_status_blk->atten_status_block.status_block_id,
  676. bp->def_status_blk->atten_status_block.attn_bits_index);
  677. BNX2X_ERR(" def (");
  678. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  679. pr_cont("0x%x%s",
  680. bp->def_status_blk->sp_sb.index_values[i],
  681. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  682. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  683. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  684. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  685. i*sizeof(u32));
  686. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) "
  687. "pf_id(0x%x) vnic_id(0x%x) "
  688. "vf_id(0x%x) vf_valid (0x%x) "
  689. "state(0x%x)\n",
  690. sp_sb_data.igu_sb_id,
  691. sp_sb_data.igu_seg_id,
  692. sp_sb_data.p_func.pf_id,
  693. sp_sb_data.p_func.vnic_id,
  694. sp_sb_data.p_func.vf_id,
  695. sp_sb_data.p_func.vf_valid,
  696. sp_sb_data.state);
  697. for_each_eth_queue(bp, i) {
  698. struct bnx2x_fastpath *fp = &bp->fp[i];
  699. int loop;
  700. struct hc_status_block_data_e2 sb_data_e2;
  701. struct hc_status_block_data_e1x sb_data_e1x;
  702. struct hc_status_block_sm *hc_sm_p =
  703. CHIP_IS_E1x(bp) ?
  704. sb_data_e1x.common.state_machine :
  705. sb_data_e2.common.state_machine;
  706. struct hc_index_data *hc_index_p =
  707. CHIP_IS_E1x(bp) ?
  708. sb_data_e1x.index_data :
  709. sb_data_e2.index_data;
  710. int data_size;
  711. u32 *sb_data_p;
  712. /* Rx */
  713. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)"
  714. " rx_comp_prod(0x%x)"
  715. " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  716. i, fp->rx_bd_prod, fp->rx_bd_cons,
  717. fp->rx_comp_prod,
  718. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  719. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)"
  720. " fp_hc_idx(0x%x)\n",
  721. fp->rx_sge_prod, fp->last_max_sge,
  722. le16_to_cpu(fp->fp_hc_idx));
  723. /* Tx */
  724. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)"
  725. " tx_bd_prod(0x%x) tx_bd_cons(0x%x)"
  726. " *tx_cons_sb(0x%x)\n",
  727. i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
  728. fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
  729. loop = CHIP_IS_E1x(bp) ?
  730. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  731. /* host sb data */
  732. #ifdef BCM_CNIC
  733. if (IS_FCOE_FP(fp))
  734. continue;
  735. #endif
  736. BNX2X_ERR(" run indexes (");
  737. for (j = 0; j < HC_SB_MAX_SM; j++)
  738. pr_cont("0x%x%s",
  739. fp->sb_running_index[j],
  740. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  741. BNX2X_ERR(" indexes (");
  742. for (j = 0; j < loop; j++)
  743. pr_cont("0x%x%s",
  744. fp->sb_index_values[j],
  745. (j == loop - 1) ? ")" : " ");
  746. /* fw sb data */
  747. data_size = CHIP_IS_E1x(bp) ?
  748. sizeof(struct hc_status_block_data_e1x) :
  749. sizeof(struct hc_status_block_data_e2);
  750. data_size /= sizeof(u32);
  751. sb_data_p = CHIP_IS_E1x(bp) ?
  752. (u32 *)&sb_data_e1x :
  753. (u32 *)&sb_data_e2;
  754. /* copy sb data in here */
  755. for (j = 0; j < data_size; j++)
  756. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  757. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  758. j * sizeof(u32));
  759. if (!CHIP_IS_E1x(bp)) {
  760. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
  761. "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
  762. "state(0x%x)\n",
  763. sb_data_e2.common.p_func.pf_id,
  764. sb_data_e2.common.p_func.vf_id,
  765. sb_data_e2.common.p_func.vf_valid,
  766. sb_data_e2.common.p_func.vnic_id,
  767. sb_data_e2.common.same_igu_sb_1b,
  768. sb_data_e2.common.state);
  769. } else {
  770. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
  771. "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
  772. "state(0x%x)\n",
  773. sb_data_e1x.common.p_func.pf_id,
  774. sb_data_e1x.common.p_func.vf_id,
  775. sb_data_e1x.common.p_func.vf_valid,
  776. sb_data_e1x.common.p_func.vnic_id,
  777. sb_data_e1x.common.same_igu_sb_1b,
  778. sb_data_e1x.common.state);
  779. }
  780. /* SB_SMs data */
  781. for (j = 0; j < HC_SB_MAX_SM; j++) {
  782. pr_cont("SM[%d] __flags (0x%x) "
  783. "igu_sb_id (0x%x) igu_seg_id(0x%x) "
  784. "time_to_expire (0x%x) "
  785. "timer_value(0x%x)\n", j,
  786. hc_sm_p[j].__flags,
  787. hc_sm_p[j].igu_sb_id,
  788. hc_sm_p[j].igu_seg_id,
  789. hc_sm_p[j].time_to_expire,
  790. hc_sm_p[j].timer_value);
  791. }
  792. /* Indecies data */
  793. for (j = 0; j < loop; j++) {
  794. pr_cont("INDEX[%d] flags (0x%x) "
  795. "timeout (0x%x)\n", j,
  796. hc_index_p[j].flags,
  797. hc_index_p[j].timeout);
  798. }
  799. }
  800. #ifdef BNX2X_STOP_ON_ERROR
  801. /* Rings */
  802. /* Rx */
  803. for_each_rx_queue(bp, i) {
  804. struct bnx2x_fastpath *fp = &bp->fp[i];
  805. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  806. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  807. for (j = start; j != end; j = RX_BD(j + 1)) {
  808. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  809. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  810. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  811. i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
  812. }
  813. start = RX_SGE(fp->rx_sge_prod);
  814. end = RX_SGE(fp->last_max_sge);
  815. for (j = start; j != end; j = RX_SGE(j + 1)) {
  816. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  817. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  818. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  819. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  820. }
  821. start = RCQ_BD(fp->rx_comp_cons - 10);
  822. end = RCQ_BD(fp->rx_comp_cons + 503);
  823. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  824. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  825. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  826. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  827. }
  828. }
  829. /* Tx */
  830. for_each_tx_queue(bp, i) {
  831. struct bnx2x_fastpath *fp = &bp->fp[i];
  832. start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
  833. end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
  834. for (j = start; j != end; j = TX_BD(j + 1)) {
  835. struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
  836. BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n",
  837. i, j, sw_bd->skb, sw_bd->first_bd);
  838. }
  839. start = TX_BD(fp->tx_bd_cons - 10);
  840. end = TX_BD(fp->tx_bd_cons + 254);
  841. for (j = start; j != end; j = TX_BD(j + 1)) {
  842. u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
  843. BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n",
  844. i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
  845. }
  846. }
  847. #endif
  848. bnx2x_fw_dump(bp);
  849. bnx2x_mc_assert(bp);
  850. BNX2X_ERR("end crash dump -----------------\n");
  851. }
  852. /*
  853. * FLR Support for E2
  854. *
  855. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  856. * initialization.
  857. */
  858. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  859. #define FLR_WAIT_INTERAVAL 50 /* usec */
  860. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERAVAL) /* 200 */
  861. struct pbf_pN_buf_regs {
  862. int pN;
  863. u32 init_crd;
  864. u32 crd;
  865. u32 crd_freed;
  866. };
  867. struct pbf_pN_cmd_regs {
  868. int pN;
  869. u32 lines_occup;
  870. u32 lines_freed;
  871. };
  872. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  873. struct pbf_pN_buf_regs *regs,
  874. u32 poll_count)
  875. {
  876. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  877. u32 cur_cnt = poll_count;
  878. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  879. crd = crd_start = REG_RD(bp, regs->crd);
  880. init_crd = REG_RD(bp, regs->init_crd);
  881. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  882. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  883. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  884. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  885. (init_crd - crd_start))) {
  886. if (cur_cnt--) {
  887. udelay(FLR_WAIT_INTERAVAL);
  888. crd = REG_RD(bp, regs->crd);
  889. crd_freed = REG_RD(bp, regs->crd_freed);
  890. } else {
  891. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  892. regs->pN);
  893. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  894. regs->pN, crd);
  895. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  896. regs->pN, crd_freed);
  897. break;
  898. }
  899. }
  900. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  901. poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
  902. }
  903. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  904. struct pbf_pN_cmd_regs *regs,
  905. u32 poll_count)
  906. {
  907. u32 occup, to_free, freed, freed_start;
  908. u32 cur_cnt = poll_count;
  909. occup = to_free = REG_RD(bp, regs->lines_occup);
  910. freed = freed_start = REG_RD(bp, regs->lines_freed);
  911. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  912. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  913. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  914. if (cur_cnt--) {
  915. udelay(FLR_WAIT_INTERAVAL);
  916. occup = REG_RD(bp, regs->lines_occup);
  917. freed = REG_RD(bp, regs->lines_freed);
  918. } else {
  919. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  920. regs->pN);
  921. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  922. regs->pN, occup);
  923. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  924. regs->pN, freed);
  925. break;
  926. }
  927. }
  928. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  929. poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
  930. }
  931. static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  932. u32 expected, u32 poll_count)
  933. {
  934. u32 cur_cnt = poll_count;
  935. u32 val;
  936. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  937. udelay(FLR_WAIT_INTERAVAL);
  938. return val;
  939. }
  940. static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  941. char *msg, u32 poll_cnt)
  942. {
  943. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  944. if (val != 0) {
  945. BNX2X_ERR("%s usage count=%d\n", msg, val);
  946. return 1;
  947. }
  948. return 0;
  949. }
  950. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  951. {
  952. /* adjust polling timeout */
  953. if (CHIP_REV_IS_EMUL(bp))
  954. return FLR_POLL_CNT * 2000;
  955. if (CHIP_REV_IS_FPGA(bp))
  956. return FLR_POLL_CNT * 120;
  957. return FLR_POLL_CNT;
  958. }
  959. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  960. {
  961. struct pbf_pN_cmd_regs cmd_regs[] = {
  962. {0, (CHIP_IS_E3B0(bp)) ?
  963. PBF_REG_TQ_OCCUPANCY_Q0 :
  964. PBF_REG_P0_TQ_OCCUPANCY,
  965. (CHIP_IS_E3B0(bp)) ?
  966. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  967. PBF_REG_P0_TQ_LINES_FREED_CNT},
  968. {1, (CHIP_IS_E3B0(bp)) ?
  969. PBF_REG_TQ_OCCUPANCY_Q1 :
  970. PBF_REG_P1_TQ_OCCUPANCY,
  971. (CHIP_IS_E3B0(bp)) ?
  972. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  973. PBF_REG_P1_TQ_LINES_FREED_CNT},
  974. {4, (CHIP_IS_E3B0(bp)) ?
  975. PBF_REG_TQ_OCCUPANCY_LB_Q :
  976. PBF_REG_P4_TQ_OCCUPANCY,
  977. (CHIP_IS_E3B0(bp)) ?
  978. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  979. PBF_REG_P4_TQ_LINES_FREED_CNT}
  980. };
  981. struct pbf_pN_buf_regs buf_regs[] = {
  982. {0, (CHIP_IS_E3B0(bp)) ?
  983. PBF_REG_INIT_CRD_Q0 :
  984. PBF_REG_P0_INIT_CRD ,
  985. (CHIP_IS_E3B0(bp)) ?
  986. PBF_REG_CREDIT_Q0 :
  987. PBF_REG_P0_CREDIT,
  988. (CHIP_IS_E3B0(bp)) ?
  989. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  990. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  991. {1, (CHIP_IS_E3B0(bp)) ?
  992. PBF_REG_INIT_CRD_Q1 :
  993. PBF_REG_P1_INIT_CRD,
  994. (CHIP_IS_E3B0(bp)) ?
  995. PBF_REG_CREDIT_Q1 :
  996. PBF_REG_P1_CREDIT,
  997. (CHIP_IS_E3B0(bp)) ?
  998. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  999. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1000. {4, (CHIP_IS_E3B0(bp)) ?
  1001. PBF_REG_INIT_CRD_LB_Q :
  1002. PBF_REG_P4_INIT_CRD,
  1003. (CHIP_IS_E3B0(bp)) ?
  1004. PBF_REG_CREDIT_LB_Q :
  1005. PBF_REG_P4_CREDIT,
  1006. (CHIP_IS_E3B0(bp)) ?
  1007. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1008. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1009. };
  1010. int i;
  1011. /* Verify the command queues are flushed P0, P1, P4 */
  1012. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1013. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1014. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1015. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1016. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1017. }
  1018. #define OP_GEN_PARAM(param) \
  1019. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1020. #define OP_GEN_TYPE(type) \
  1021. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1022. #define OP_GEN_AGG_VECT(index) \
  1023. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1024. static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  1025. u32 poll_cnt)
  1026. {
  1027. struct sdm_op_gen op_gen = {0};
  1028. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1029. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1030. int ret = 0;
  1031. if (REG_RD(bp, comp_addr)) {
  1032. BNX2X_ERR("Cleanup complete is not 0\n");
  1033. return 1;
  1034. }
  1035. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1036. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1037. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1038. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1039. DP(BNX2X_MSG_SP, "FW Final cleanup\n");
  1040. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1041. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1042. BNX2X_ERR("FW final cleanup did not succeed\n");
  1043. ret = 1;
  1044. }
  1045. /* Zero completion for nxt FLR */
  1046. REG_WR(bp, comp_addr, 0);
  1047. return ret;
  1048. }
  1049. static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1050. {
  1051. int pos;
  1052. u16 status;
  1053. pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
  1054. if (!pos)
  1055. return false;
  1056. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  1057. return status & PCI_EXP_DEVSTA_TRPND;
  1058. }
  1059. /* PF FLR specific routines
  1060. */
  1061. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1062. {
  1063. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1064. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1065. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1066. "CFC PF usage counter timed out",
  1067. poll_cnt))
  1068. return 1;
  1069. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1070. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1071. DORQ_REG_PF_USAGE_CNT,
  1072. "DQ PF usage counter timed out",
  1073. poll_cnt))
  1074. return 1;
  1075. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1076. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1077. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1078. "QM PF usage counter timed out",
  1079. poll_cnt))
  1080. return 1;
  1081. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1082. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1083. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1084. "Timers VNIC usage counter timed out",
  1085. poll_cnt))
  1086. return 1;
  1087. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1088. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1089. "Timers NUM_SCANS usage counter timed out",
  1090. poll_cnt))
  1091. return 1;
  1092. /* Wait DMAE PF usage counter to zero */
  1093. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1094. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1095. "DMAE dommand register timed out",
  1096. poll_cnt))
  1097. return 1;
  1098. return 0;
  1099. }
  1100. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1101. {
  1102. u32 val;
  1103. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1104. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1105. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1106. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1107. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1108. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1109. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1110. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1111. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1112. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1113. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1114. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1115. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1116. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1117. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1118. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1119. val);
  1120. }
  1121. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1122. {
  1123. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1124. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1125. /* Re-enable PF target read access */
  1126. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1127. /* Poll HW usage counters */
  1128. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1129. return -EBUSY;
  1130. /* Zero the igu 'trailing edge' and 'leading edge' */
  1131. /* Send the FW cleanup command */
  1132. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1133. return -EBUSY;
  1134. /* ATC cleanup */
  1135. /* Verify TX hw is flushed */
  1136. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1137. /* Wait 100ms (not adjusted according to platform) */
  1138. msleep(100);
  1139. /* Verify no pending pci transactions */
  1140. if (bnx2x_is_pcie_pending(bp->pdev))
  1141. BNX2X_ERR("PCIE Transactions still pending\n");
  1142. /* Debug */
  1143. bnx2x_hw_enable_status(bp);
  1144. /*
  1145. * Master enable - Due to WB DMAE writes performed before this
  1146. * register is re-initialized as part of the regular function init
  1147. */
  1148. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1149. return 0;
  1150. }
  1151. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1152. {
  1153. int port = BP_PORT(bp);
  1154. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1155. u32 val = REG_RD(bp, addr);
  1156. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1157. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1158. if (msix) {
  1159. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1160. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1161. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1162. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1163. } else if (msi) {
  1164. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1165. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1166. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1167. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1168. } else {
  1169. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1170. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1171. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1172. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1173. if (!CHIP_IS_E1(bp)) {
  1174. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  1175. val, port, addr);
  1176. REG_WR(bp, addr, val);
  1177. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1178. }
  1179. }
  1180. if (CHIP_IS_E1(bp))
  1181. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1182. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
  1183. val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1184. REG_WR(bp, addr, val);
  1185. /*
  1186. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1187. */
  1188. mmiowb();
  1189. barrier();
  1190. if (!CHIP_IS_E1(bp)) {
  1191. /* init leading/trailing edge */
  1192. if (IS_MF(bp)) {
  1193. val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
  1194. if (bp->port.pmf)
  1195. /* enable nig and gpio3 attention */
  1196. val |= 0x1100;
  1197. } else
  1198. val = 0xffff;
  1199. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1200. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1201. }
  1202. /* Make sure that interrupts are indeed enabled from here on */
  1203. mmiowb();
  1204. }
  1205. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1206. {
  1207. u32 val;
  1208. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1209. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1210. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1211. if (msix) {
  1212. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1213. IGU_PF_CONF_SINGLE_ISR_EN);
  1214. val |= (IGU_PF_CONF_FUNC_EN |
  1215. IGU_PF_CONF_MSI_MSIX_EN |
  1216. IGU_PF_CONF_ATTN_BIT_EN);
  1217. } else if (msi) {
  1218. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1219. val |= (IGU_PF_CONF_FUNC_EN |
  1220. IGU_PF_CONF_MSI_MSIX_EN |
  1221. IGU_PF_CONF_ATTN_BIT_EN |
  1222. IGU_PF_CONF_SINGLE_ISR_EN);
  1223. } else {
  1224. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1225. val |= (IGU_PF_CONF_FUNC_EN |
  1226. IGU_PF_CONF_INT_LINE_EN |
  1227. IGU_PF_CONF_ATTN_BIT_EN |
  1228. IGU_PF_CONF_SINGLE_ISR_EN);
  1229. }
  1230. DP(NETIF_MSG_INTR, "write 0x%x to IGU mode %s\n",
  1231. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1232. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1233. barrier();
  1234. /* init leading/trailing edge */
  1235. if (IS_MF(bp)) {
  1236. val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
  1237. if (bp->port.pmf)
  1238. /* enable nig and gpio3 attention */
  1239. val |= 0x1100;
  1240. } else
  1241. val = 0xffff;
  1242. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1243. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1244. /* Make sure that interrupts are indeed enabled from here on */
  1245. mmiowb();
  1246. }
  1247. void bnx2x_int_enable(struct bnx2x *bp)
  1248. {
  1249. if (bp->common.int_block == INT_BLOCK_HC)
  1250. bnx2x_hc_int_enable(bp);
  1251. else
  1252. bnx2x_igu_int_enable(bp);
  1253. }
  1254. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1255. {
  1256. int port = BP_PORT(bp);
  1257. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1258. u32 val = REG_RD(bp, addr);
  1259. /*
  1260. * in E1 we must use only PCI configuration space to disable
  1261. * MSI/MSIX capablility
  1262. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1263. */
  1264. if (CHIP_IS_E1(bp)) {
  1265. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1266. * Use mask register to prevent from HC sending interrupts
  1267. * after we exit the function
  1268. */
  1269. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1270. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1271. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1272. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1273. } else
  1274. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1275. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1276. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1277. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1278. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  1279. val, port, addr);
  1280. /* flush all outstanding writes */
  1281. mmiowb();
  1282. REG_WR(bp, addr, val);
  1283. if (REG_RD(bp, addr) != val)
  1284. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1285. }
  1286. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1287. {
  1288. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1289. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1290. IGU_PF_CONF_INT_LINE_EN |
  1291. IGU_PF_CONF_ATTN_BIT_EN);
  1292. DP(NETIF_MSG_INTR, "write %x to IGU\n", val);
  1293. /* flush all outstanding writes */
  1294. mmiowb();
  1295. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1296. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1297. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1298. }
  1299. static void bnx2x_int_disable(struct bnx2x *bp)
  1300. {
  1301. if (bp->common.int_block == INT_BLOCK_HC)
  1302. bnx2x_hc_int_disable(bp);
  1303. else
  1304. bnx2x_igu_int_disable(bp);
  1305. }
  1306. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1307. {
  1308. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1309. int i, offset;
  1310. if (disable_hw)
  1311. /* prevent the HW from sending interrupts */
  1312. bnx2x_int_disable(bp);
  1313. /* make sure all ISRs are done */
  1314. if (msix) {
  1315. synchronize_irq(bp->msix_table[0].vector);
  1316. offset = 1;
  1317. #ifdef BCM_CNIC
  1318. offset++;
  1319. #endif
  1320. for_each_eth_queue(bp, i)
  1321. synchronize_irq(bp->msix_table[offset++].vector);
  1322. } else
  1323. synchronize_irq(bp->pdev->irq);
  1324. /* make sure sp_task is not running */
  1325. cancel_delayed_work(&bp->sp_task);
  1326. flush_workqueue(bnx2x_wq);
  1327. }
  1328. /* fast path */
  1329. /*
  1330. * General service functions
  1331. */
  1332. /* Return true if succeeded to acquire the lock */
  1333. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1334. {
  1335. u32 lock_status;
  1336. u32 resource_bit = (1 << resource);
  1337. int func = BP_FUNC(bp);
  1338. u32 hw_lock_control_reg;
  1339. DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
  1340. /* Validating that the resource is within range */
  1341. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1342. DP(NETIF_MSG_HW,
  1343. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1344. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1345. return false;
  1346. }
  1347. if (func <= 5)
  1348. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1349. else
  1350. hw_lock_control_reg =
  1351. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1352. /* Try to acquire the lock */
  1353. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1354. lock_status = REG_RD(bp, hw_lock_control_reg);
  1355. if (lock_status & resource_bit)
  1356. return true;
  1357. DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
  1358. return false;
  1359. }
  1360. /**
  1361. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1362. *
  1363. * @bp: driver handle
  1364. *
  1365. * Returns the recovery leader resource id according to the engine this function
  1366. * belongs to. Currently only only 2 engines is supported.
  1367. */
  1368. static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1369. {
  1370. if (BP_PATH(bp))
  1371. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1372. else
  1373. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1374. }
  1375. /**
  1376. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1377. *
  1378. * @bp: driver handle
  1379. *
  1380. * Tries to aquire a leader lock for cuurent engine.
  1381. */
  1382. static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1383. {
  1384. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1385. }
  1386. #ifdef BCM_CNIC
  1387. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1388. #endif
  1389. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1390. {
  1391. struct bnx2x *bp = fp->bp;
  1392. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1393. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1394. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1395. struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
  1396. DP(BNX2X_MSG_SP,
  1397. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1398. fp->index, cid, command, bp->state,
  1399. rr_cqe->ramrod_cqe.ramrod_type);
  1400. switch (command) {
  1401. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1402. DP(NETIF_MSG_IFUP, "got UPDATE ramrod. CID %d\n", cid);
  1403. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1404. break;
  1405. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1406. DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", cid);
  1407. drv_cmd = BNX2X_Q_CMD_SETUP;
  1408. break;
  1409. case (RAMROD_CMD_ID_ETH_HALT):
  1410. DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", cid);
  1411. drv_cmd = BNX2X_Q_CMD_HALT;
  1412. break;
  1413. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1414. DP(NETIF_MSG_IFDOWN, "got MULTI[%d] teminate ramrod\n", cid);
  1415. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1416. break;
  1417. case (RAMROD_CMD_ID_ETH_EMPTY):
  1418. DP(NETIF_MSG_IFDOWN, "got MULTI[%d] empty ramrod\n", cid);
  1419. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1420. break;
  1421. default:
  1422. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1423. command, fp->index);
  1424. return;
  1425. }
  1426. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1427. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1428. /* q_obj->complete_cmd() failure means that this was
  1429. * an unexpected completion.
  1430. *
  1431. * In this case we don't want to increase the bp->spq_left
  1432. * because apparently we haven't sent this command the first
  1433. * place.
  1434. */
  1435. #ifdef BNX2X_STOP_ON_ERROR
  1436. bnx2x_panic();
  1437. #else
  1438. return;
  1439. #endif
  1440. smp_mb__before_atomic_inc();
  1441. atomic_inc(&bp->cq_spq_left);
  1442. /* push the change in bp->spq_left and towards the memory */
  1443. smp_mb__after_atomic_inc();
  1444. return;
  1445. }
  1446. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1447. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1448. {
  1449. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1450. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1451. start);
  1452. }
  1453. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1454. {
  1455. struct bnx2x *bp = netdev_priv(dev_instance);
  1456. u16 status = bnx2x_ack_int(bp);
  1457. u16 mask;
  1458. int i;
  1459. /* Return here if interrupt is shared and it's not for us */
  1460. if (unlikely(status == 0)) {
  1461. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1462. return IRQ_NONE;
  1463. }
  1464. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1465. #ifdef BNX2X_STOP_ON_ERROR
  1466. if (unlikely(bp->panic))
  1467. return IRQ_HANDLED;
  1468. #endif
  1469. for_each_eth_queue(bp, i) {
  1470. struct bnx2x_fastpath *fp = &bp->fp[i];
  1471. mask = 0x2 << (fp->index + CNIC_CONTEXT_USE);
  1472. if (status & mask) {
  1473. /* Handle Rx or Tx according to SB id */
  1474. prefetch(fp->rx_cons_sb);
  1475. prefetch(fp->tx_cons_sb);
  1476. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1477. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1478. status &= ~mask;
  1479. }
  1480. }
  1481. #ifdef BCM_CNIC
  1482. mask = 0x2;
  1483. if (status & (mask | 0x1)) {
  1484. struct cnic_ops *c_ops = NULL;
  1485. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1486. rcu_read_lock();
  1487. c_ops = rcu_dereference(bp->cnic_ops);
  1488. if (c_ops)
  1489. c_ops->cnic_handler(bp->cnic_data, NULL);
  1490. rcu_read_unlock();
  1491. }
  1492. status &= ~mask;
  1493. }
  1494. #endif
  1495. if (unlikely(status & 0x1)) {
  1496. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1497. status &= ~0x1;
  1498. if (!status)
  1499. return IRQ_HANDLED;
  1500. }
  1501. if (unlikely(status))
  1502. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1503. status);
  1504. return IRQ_HANDLED;
  1505. }
  1506. /* Link */
  1507. /*
  1508. * General service functions
  1509. */
  1510. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1511. {
  1512. u32 lock_status;
  1513. u32 resource_bit = (1 << resource);
  1514. int func = BP_FUNC(bp);
  1515. u32 hw_lock_control_reg;
  1516. int cnt;
  1517. /* Validating that the resource is within range */
  1518. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1519. DP(NETIF_MSG_HW,
  1520. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1521. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1522. return -EINVAL;
  1523. }
  1524. if (func <= 5) {
  1525. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1526. } else {
  1527. hw_lock_control_reg =
  1528. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1529. }
  1530. /* Validating that the resource is not already taken */
  1531. lock_status = REG_RD(bp, hw_lock_control_reg);
  1532. if (lock_status & resource_bit) {
  1533. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1534. lock_status, resource_bit);
  1535. return -EEXIST;
  1536. }
  1537. /* Try for 5 second every 5ms */
  1538. for (cnt = 0; cnt < 1000; cnt++) {
  1539. /* Try to acquire the lock */
  1540. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1541. lock_status = REG_RD(bp, hw_lock_control_reg);
  1542. if (lock_status & resource_bit)
  1543. return 0;
  1544. msleep(5);
  1545. }
  1546. DP(NETIF_MSG_HW, "Timeout\n");
  1547. return -EAGAIN;
  1548. }
  1549. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1550. {
  1551. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1552. }
  1553. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1554. {
  1555. u32 lock_status;
  1556. u32 resource_bit = (1 << resource);
  1557. int func = BP_FUNC(bp);
  1558. u32 hw_lock_control_reg;
  1559. DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
  1560. /* Validating that the resource is within range */
  1561. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1562. DP(NETIF_MSG_HW,
  1563. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1564. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1565. return -EINVAL;
  1566. }
  1567. if (func <= 5) {
  1568. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1569. } else {
  1570. hw_lock_control_reg =
  1571. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1572. }
  1573. /* Validating that the resource is currently taken */
  1574. lock_status = REG_RD(bp, hw_lock_control_reg);
  1575. if (!(lock_status & resource_bit)) {
  1576. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1577. lock_status, resource_bit);
  1578. return -EFAULT;
  1579. }
  1580. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1581. return 0;
  1582. }
  1583. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1584. {
  1585. /* The GPIO should be swapped if swap register is set and active */
  1586. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1587. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1588. int gpio_shift = gpio_num +
  1589. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1590. u32 gpio_mask = (1 << gpio_shift);
  1591. u32 gpio_reg;
  1592. int value;
  1593. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1594. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1595. return -EINVAL;
  1596. }
  1597. /* read GPIO value */
  1598. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1599. /* get the requested pin value */
  1600. if ((gpio_reg & gpio_mask) == gpio_mask)
  1601. value = 1;
  1602. else
  1603. value = 0;
  1604. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1605. return value;
  1606. }
  1607. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1608. {
  1609. /* The GPIO should be swapped if swap register is set and active */
  1610. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1611. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1612. int gpio_shift = gpio_num +
  1613. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1614. u32 gpio_mask = (1 << gpio_shift);
  1615. u32 gpio_reg;
  1616. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1617. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1618. return -EINVAL;
  1619. }
  1620. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1621. /* read GPIO and mask except the float bits */
  1622. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1623. switch (mode) {
  1624. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1625. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
  1626. gpio_num, gpio_shift);
  1627. /* clear FLOAT and set CLR */
  1628. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1629. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1630. break;
  1631. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1632. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
  1633. gpio_num, gpio_shift);
  1634. /* clear FLOAT and set SET */
  1635. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1636. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1637. break;
  1638. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1639. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
  1640. gpio_num, gpio_shift);
  1641. /* set FLOAT */
  1642. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1643. break;
  1644. default:
  1645. break;
  1646. }
  1647. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1648. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1649. return 0;
  1650. }
  1651. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1652. {
  1653. /* The GPIO should be swapped if swap register is set and active */
  1654. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1655. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1656. int gpio_shift = gpio_num +
  1657. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1658. u32 gpio_mask = (1 << gpio_shift);
  1659. u32 gpio_reg;
  1660. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1661. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1662. return -EINVAL;
  1663. }
  1664. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1665. /* read GPIO int */
  1666. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1667. switch (mode) {
  1668. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1669. DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
  1670. "output low\n", gpio_num, gpio_shift);
  1671. /* clear SET and set CLR */
  1672. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1673. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1674. break;
  1675. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1676. DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
  1677. "output high\n", gpio_num, gpio_shift);
  1678. /* clear CLR and set SET */
  1679. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1680. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1681. break;
  1682. default:
  1683. break;
  1684. }
  1685. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1686. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1687. return 0;
  1688. }
  1689. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1690. {
  1691. u32 spio_mask = (1 << spio_num);
  1692. u32 spio_reg;
  1693. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1694. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1695. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1696. return -EINVAL;
  1697. }
  1698. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1699. /* read SPIO and mask except the float bits */
  1700. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1701. switch (mode) {
  1702. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1703. DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
  1704. /* clear FLOAT and set CLR */
  1705. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1706. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1707. break;
  1708. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1709. DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
  1710. /* clear FLOAT and set SET */
  1711. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1712. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1713. break;
  1714. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1715. DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
  1716. /* set FLOAT */
  1717. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1718. break;
  1719. default:
  1720. break;
  1721. }
  1722. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1723. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1724. return 0;
  1725. }
  1726. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1727. {
  1728. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1729. switch (bp->link_vars.ieee_fc &
  1730. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1731. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1732. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1733. ADVERTISED_Pause);
  1734. break;
  1735. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1736. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1737. ADVERTISED_Pause);
  1738. break;
  1739. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1740. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1741. break;
  1742. default:
  1743. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1744. ADVERTISED_Pause);
  1745. break;
  1746. }
  1747. }
  1748. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1749. {
  1750. if (!BP_NOMCP(bp)) {
  1751. u8 rc;
  1752. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1753. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1754. /* Initialize link parameters structure variables */
  1755. /* It is recommended to turn off RX FC for jumbo frames
  1756. for better performance */
  1757. if ((CHIP_IS_E1x(bp)) && (bp->dev->mtu > 5000))
  1758. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1759. else
  1760. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1761. bnx2x_acquire_phy_lock(bp);
  1762. if (load_mode == LOAD_DIAG) {
  1763. bp->link_params.loopback_mode = LOOPBACK_XGXS;
  1764. bp->link_params.req_line_speed[cfx_idx] = SPEED_10000;
  1765. }
  1766. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1767. bnx2x_release_phy_lock(bp);
  1768. bnx2x_calc_fc_adv(bp);
  1769. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1770. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1771. bnx2x_link_report(bp);
  1772. }
  1773. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1774. return rc;
  1775. }
  1776. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1777. return -EINVAL;
  1778. }
  1779. void bnx2x_link_set(struct bnx2x *bp)
  1780. {
  1781. if (!BP_NOMCP(bp)) {
  1782. bnx2x_acquire_phy_lock(bp);
  1783. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1784. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1785. bnx2x_release_phy_lock(bp);
  1786. bnx2x_calc_fc_adv(bp);
  1787. } else
  1788. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1789. }
  1790. static void bnx2x__link_reset(struct bnx2x *bp)
  1791. {
  1792. if (!BP_NOMCP(bp)) {
  1793. bnx2x_acquire_phy_lock(bp);
  1794. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1795. bnx2x_release_phy_lock(bp);
  1796. } else
  1797. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1798. }
  1799. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1800. {
  1801. u8 rc = 0;
  1802. if (!BP_NOMCP(bp)) {
  1803. bnx2x_acquire_phy_lock(bp);
  1804. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1805. is_serdes);
  1806. bnx2x_release_phy_lock(bp);
  1807. } else
  1808. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1809. return rc;
  1810. }
  1811. static void bnx2x_init_port_minmax(struct bnx2x *bp)
  1812. {
  1813. u32 r_param = bp->link_vars.line_speed / 8;
  1814. u32 fair_periodic_timeout_usec;
  1815. u32 t_fair;
  1816. memset(&(bp->cmng.rs_vars), 0,
  1817. sizeof(struct rate_shaping_vars_per_port));
  1818. memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
  1819. /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
  1820. bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
  1821. /* this is the threshold below which no timer arming will occur
  1822. 1.25 coefficient is for the threshold to be a little bigger
  1823. than the real time, to compensate for timer in-accuracy */
  1824. bp->cmng.rs_vars.rs_threshold =
  1825. (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
  1826. /* resolution of fairness timer */
  1827. fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
  1828. /* for 10G it is 1000usec. for 1G it is 10000usec. */
  1829. t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
  1830. /* this is the threshold below which we won't arm the timer anymore */
  1831. bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
  1832. /* we multiply by 1e3/8 to get bytes/msec.
  1833. We don't want the credits to pass a credit
  1834. of the t_fair*FAIR_MEM (algorithm resolution) */
  1835. bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
  1836. /* since each tick is 4 usec */
  1837. bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
  1838. }
  1839. /* Calculates the sum of vn_min_rates.
  1840. It's needed for further normalizing of the min_rates.
  1841. Returns:
  1842. sum of vn_min_rates.
  1843. or
  1844. 0 - if all the min_rates are 0.
  1845. In the later case fainess algorithm should be deactivated.
  1846. If not all min_rates are zero then those that are zeroes will be set to 1.
  1847. */
  1848. static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
  1849. {
  1850. int all_zero = 1;
  1851. int vn;
  1852. bp->vn_weight_sum = 0;
  1853. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  1854. u32 vn_cfg = bp->mf_config[vn];
  1855. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1856. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1857. /* Skip hidden vns */
  1858. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1859. continue;
  1860. /* If min rate is zero - set it to 1 */
  1861. if (!vn_min_rate)
  1862. vn_min_rate = DEF_MIN_RATE;
  1863. else
  1864. all_zero = 0;
  1865. bp->vn_weight_sum += vn_min_rate;
  1866. }
  1867. /* if ETS or all min rates are zeros - disable fairness */
  1868. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1869. bp->cmng.flags.cmng_enables &=
  1870. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1871. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1872. } else if (all_zero) {
  1873. bp->cmng.flags.cmng_enables &=
  1874. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1875. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  1876. " fairness will be disabled\n");
  1877. } else
  1878. bp->cmng.flags.cmng_enables |=
  1879. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1880. }
  1881. static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
  1882. {
  1883. struct rate_shaping_vars_per_vn m_rs_vn;
  1884. struct fairness_vars_per_vn m_fair_vn;
  1885. u32 vn_cfg = bp->mf_config[vn];
  1886. int func = 2*vn + BP_PORT(bp);
  1887. u16 vn_min_rate, vn_max_rate;
  1888. int i;
  1889. /* If function is hidden - set min and max to zeroes */
  1890. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
  1891. vn_min_rate = 0;
  1892. vn_max_rate = 0;
  1893. } else {
  1894. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1895. vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1896. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1897. /* If fairness is enabled (not all min rates are zeroes) and
  1898. if current min rate is zero - set it to 1.
  1899. This is a requirement of the algorithm. */
  1900. if (bp->vn_weight_sum && (vn_min_rate == 0))
  1901. vn_min_rate = DEF_MIN_RATE;
  1902. if (IS_MF_SI(bp))
  1903. /* maxCfg in percents of linkspeed */
  1904. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1905. else
  1906. /* maxCfg is absolute in 100Mb units */
  1907. vn_max_rate = maxCfg * 100;
  1908. }
  1909. DP(NETIF_MSG_IFUP,
  1910. "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
  1911. func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
  1912. memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
  1913. memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
  1914. /* global vn counter - maximal Mbps for this vn */
  1915. m_rs_vn.vn_counter.rate = vn_max_rate;
  1916. /* quota - number of bytes transmitted in this period */
  1917. m_rs_vn.vn_counter.quota =
  1918. (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
  1919. if (bp->vn_weight_sum) {
  1920. /* credit for each period of the fairness algorithm:
  1921. number of bytes in T_FAIR (the vn share the port rate).
  1922. vn_weight_sum should not be larger than 10000, thus
  1923. T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
  1924. than zero */
  1925. m_fair_vn.vn_credit_delta =
  1926. max_t(u32, (vn_min_rate * (T_FAIR_COEF /
  1927. (8 * bp->vn_weight_sum))),
  1928. (bp->cmng.fair_vars.fair_threshold +
  1929. MIN_ABOVE_THRESH));
  1930. DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
  1931. m_fair_vn.vn_credit_delta);
  1932. }
  1933. /* Store it to internal memory */
  1934. for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
  1935. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1936. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
  1937. ((u32 *)(&m_rs_vn))[i]);
  1938. for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
  1939. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1940. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
  1941. ((u32 *)(&m_fair_vn))[i]);
  1942. }
  1943. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1944. {
  1945. if (CHIP_REV_IS_SLOW(bp))
  1946. return CMNG_FNS_NONE;
  1947. if (IS_MF(bp))
  1948. return CMNG_FNS_MINMAX;
  1949. return CMNG_FNS_NONE;
  1950. }
  1951. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1952. {
  1953. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1954. if (BP_NOMCP(bp))
  1955. return; /* what should be the default bvalue in this case */
  1956. /* For 2 port configuration the absolute function number formula
  1957. * is:
  1958. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1959. *
  1960. * and there are 4 functions per port
  1961. *
  1962. * For 4 port configuration it is
  1963. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1964. *
  1965. * and there are 2 functions per port
  1966. */
  1967. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  1968. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1969. if (func >= E1H_FUNC_MAX)
  1970. break;
  1971. bp->mf_config[vn] =
  1972. MF_CFG_RD(bp, func_mf_config[func].config);
  1973. }
  1974. }
  1975. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1976. {
  1977. if (cmng_type == CMNG_FNS_MINMAX) {
  1978. int vn;
  1979. /* clear cmng_enables */
  1980. bp->cmng.flags.cmng_enables = 0;
  1981. /* read mf conf from shmem */
  1982. if (read_cfg)
  1983. bnx2x_read_mf_cfg(bp);
  1984. /* Init rate shaping and fairness contexts */
  1985. bnx2x_init_port_minmax(bp);
  1986. /* vn_weight_sum and enable fairness if not 0 */
  1987. bnx2x_calc_vn_weight_sum(bp);
  1988. /* calculate and set min-max rate for each vn */
  1989. if (bp->port.pmf)
  1990. for (vn = VN_0; vn < E1HVN_MAX; vn++)
  1991. bnx2x_init_vn_minmax(bp, vn);
  1992. /* always enable rate shaping and fairness */
  1993. bp->cmng.flags.cmng_enables |=
  1994. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1995. if (!bp->vn_weight_sum)
  1996. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  1997. " fairness will be disabled\n");
  1998. return;
  1999. }
  2000. /* rate shaping and fairness are disabled */
  2001. DP(NETIF_MSG_IFUP,
  2002. "rate shaping and fairness are disabled\n");
  2003. }
  2004. static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
  2005. {
  2006. int port = BP_PORT(bp);
  2007. int func;
  2008. int vn;
  2009. /* Set the attention towards other drivers on the same port */
  2010. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  2011. if (vn == BP_E1HVN(bp))
  2012. continue;
  2013. func = ((vn << 1) | port);
  2014. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  2015. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  2016. }
  2017. }
  2018. /* This function is called upon link interrupt */
  2019. static void bnx2x_link_attn(struct bnx2x *bp)
  2020. {
  2021. /* Make sure that we are synced with the current statistics */
  2022. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2023. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2024. if (bp->link_vars.link_up) {
  2025. /* dropless flow control */
  2026. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2027. int port = BP_PORT(bp);
  2028. u32 pause_enabled = 0;
  2029. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2030. pause_enabled = 1;
  2031. REG_WR(bp, BAR_USTRORM_INTMEM +
  2032. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2033. pause_enabled);
  2034. }
  2035. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2036. struct host_port_stats *pstats;
  2037. pstats = bnx2x_sp(bp, port_stats);
  2038. /* reset old mac stats */
  2039. memset(&(pstats->mac_stx[0]), 0,
  2040. sizeof(struct mac_stx));
  2041. }
  2042. if (bp->state == BNX2X_STATE_OPEN)
  2043. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2044. }
  2045. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2046. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2047. if (cmng_fns != CMNG_FNS_NONE) {
  2048. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2049. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2050. } else
  2051. /* rate shaping and fairness are disabled */
  2052. DP(NETIF_MSG_IFUP,
  2053. "single function mode without fairness\n");
  2054. }
  2055. __bnx2x_link_report(bp);
  2056. if (IS_MF(bp))
  2057. bnx2x_link_sync_notify(bp);
  2058. }
  2059. void bnx2x__link_status_update(struct bnx2x *bp)
  2060. {
  2061. if (bp->state != BNX2X_STATE_OPEN)
  2062. return;
  2063. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2064. if (bp->link_vars.link_up)
  2065. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2066. else
  2067. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2068. /* indicate link status */
  2069. bnx2x_link_report(bp);
  2070. }
  2071. static void bnx2x_pmf_update(struct bnx2x *bp)
  2072. {
  2073. int port = BP_PORT(bp);
  2074. u32 val;
  2075. bp->port.pmf = 1;
  2076. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  2077. bnx2x_dcbx_pmf_update(bp);
  2078. /* enable nig attention */
  2079. val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
  2080. if (bp->common.int_block == INT_BLOCK_HC) {
  2081. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2082. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2083. } else if (!CHIP_IS_E1x(bp)) {
  2084. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2085. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2086. }
  2087. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2088. }
  2089. /* end of Link */
  2090. /* slow path */
  2091. /*
  2092. * General service functions
  2093. */
  2094. /* send the MCP a request, block until there is a reply */
  2095. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2096. {
  2097. int mb_idx = BP_FW_MB_IDX(bp);
  2098. u32 seq;
  2099. u32 rc = 0;
  2100. u32 cnt = 1;
  2101. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2102. mutex_lock(&bp->fw_mb_mutex);
  2103. seq = ++bp->fw_seq;
  2104. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2105. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2106. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2107. (command | seq), param);
  2108. do {
  2109. /* let the FW do it's magic ... */
  2110. msleep(delay);
  2111. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2112. /* Give the FW up to 5 second (500*10ms) */
  2113. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2114. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2115. cnt*delay, rc, seq);
  2116. /* is this a reply to our command? */
  2117. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2118. rc &= FW_MSG_CODE_MASK;
  2119. else {
  2120. /* FW BUG! */
  2121. BNX2X_ERR("FW failed to respond!\n");
  2122. bnx2x_fw_dump(bp);
  2123. rc = 0;
  2124. }
  2125. mutex_unlock(&bp->fw_mb_mutex);
  2126. return rc;
  2127. }
  2128. static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
  2129. {
  2130. #ifdef BCM_CNIC
  2131. /* Statistics are not supported for CNIC Clients at the moment */
  2132. if (IS_FCOE_FP(fp))
  2133. return false;
  2134. #endif
  2135. return true;
  2136. }
  2137. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2138. {
  2139. if (CHIP_IS_E1x(bp)) {
  2140. struct tstorm_eth_function_common_config tcfg = {0};
  2141. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2142. }
  2143. /* Enable the function in the FW */
  2144. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2145. storm_memset_func_en(bp, p->func_id, 1);
  2146. /* spq */
  2147. if (p->func_flgs & FUNC_FLG_SPQ) {
  2148. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2149. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2150. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2151. }
  2152. }
  2153. static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2154. struct bnx2x_fastpath *fp,
  2155. bool leading)
  2156. {
  2157. unsigned long flags = 0;
  2158. /* PF driver will always initialize the Queue to an ACTIVE state */
  2159. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2160. /* calculate other queue flags */
  2161. if (IS_MF_SD(bp))
  2162. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2163. if (IS_FCOE_FP(fp))
  2164. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2165. if (!fp->disable_tpa)
  2166. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2167. if (stat_counter_valid(bp, fp)) {
  2168. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2169. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2170. }
  2171. if (leading) {
  2172. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2173. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2174. }
  2175. /* Always set HW VLAN stripping */
  2176. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2177. return flags;
  2178. }
  2179. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2180. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init)
  2181. {
  2182. gen_init->stat_id = bnx2x_stats_id(fp);
  2183. gen_init->spcl_id = fp->cl_id;
  2184. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2185. if (IS_FCOE_FP(fp))
  2186. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2187. else
  2188. gen_init->mtu = bp->dev->mtu;
  2189. }
  2190. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2191. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2192. struct bnx2x_rxq_setup_params *rxq_init)
  2193. {
  2194. u8 max_sge = 0;
  2195. u16 sge_sz = 0;
  2196. u16 tpa_agg_size = 0;
  2197. if (!fp->disable_tpa) {
  2198. pause->sge_th_hi = 250;
  2199. pause->sge_th_lo = 150;
  2200. tpa_agg_size = min_t(u32,
  2201. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2202. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2203. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2204. SGE_PAGE_SHIFT;
  2205. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2206. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2207. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2208. 0xffff);
  2209. }
  2210. /* pause - not for e1 */
  2211. if (!CHIP_IS_E1(bp)) {
  2212. pause->bd_th_hi = 350;
  2213. pause->bd_th_lo = 250;
  2214. pause->rcq_th_hi = 350;
  2215. pause->rcq_th_lo = 250;
  2216. pause->pri_map = 1;
  2217. }
  2218. /* rxq setup */
  2219. rxq_init->dscr_map = fp->rx_desc_mapping;
  2220. rxq_init->sge_map = fp->rx_sge_mapping;
  2221. rxq_init->rcq_map = fp->rx_comp_mapping;
  2222. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2223. /* This should be a maximum number of data bytes that may be
  2224. * placed on the BD (not including paddings).
  2225. */
  2226. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
  2227. IP_HEADER_ALIGNMENT_PADDING;
  2228. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2229. rxq_init->tpa_agg_sz = tpa_agg_size;
  2230. rxq_init->sge_buf_sz = sge_sz;
  2231. rxq_init->max_sges_pkt = max_sge;
  2232. rxq_init->rss_engine_id = BP_FUNC(bp);
  2233. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2234. *
  2235. * For PF Clients it should be the maximum avaliable number.
  2236. * VF driver(s) may want to define it to a smaller value.
  2237. */
  2238. rxq_init->max_tpa_queues =
  2239. (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
  2240. ETH_MAX_AGGREGATION_QUEUES_E1H_E2);
  2241. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2242. rxq_init->fw_sb_id = fp->fw_sb_id;
  2243. if (IS_FCOE_FP(fp))
  2244. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2245. else
  2246. rxq_init->sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
  2247. }
  2248. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2249. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init)
  2250. {
  2251. txq_init->dscr_map = fp->tx_desc_mapping;
  2252. txq_init->sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
  2253. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2254. txq_init->fw_sb_id = fp->fw_sb_id;
  2255. /*
  2256. * set the tss leading client id for TX classfication ==
  2257. * leading RSS client id
  2258. */
  2259. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2260. if (IS_FCOE_FP(fp)) {
  2261. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2262. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2263. }
  2264. }
  2265. static void bnx2x_pf_init(struct bnx2x *bp)
  2266. {
  2267. struct bnx2x_func_init_params func_init = {0};
  2268. struct event_ring_data eq_data = { {0} };
  2269. u16 flags;
  2270. if (!CHIP_IS_E1x(bp)) {
  2271. /* reset IGU PF statistics: MSIX + ATTN */
  2272. /* PF */
  2273. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2274. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2275. (CHIP_MODE_IS_4_PORT(bp) ?
  2276. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2277. /* ATTN */
  2278. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2279. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2280. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2281. (CHIP_MODE_IS_4_PORT(bp) ?
  2282. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2283. }
  2284. /* function setup flags */
  2285. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2286. /* This flag is relevant for E1x only.
  2287. * E2 doesn't have a TPA configuration in a function level.
  2288. */
  2289. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2290. func_init.func_flgs = flags;
  2291. func_init.pf_id = BP_FUNC(bp);
  2292. func_init.func_id = BP_FUNC(bp);
  2293. func_init.spq_map = bp->spq_mapping;
  2294. func_init.spq_prod = bp->spq_prod_idx;
  2295. bnx2x_func_init(bp, &func_init);
  2296. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2297. /*
  2298. * Congestion management values depend on the link rate
  2299. * There is no active link so initial link rate is set to 10 Gbps.
  2300. * When the link comes up The congestion management values are
  2301. * re-calculated according to the actual link rate.
  2302. */
  2303. bp->link_vars.line_speed = SPEED_10000;
  2304. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2305. /* Only the PMF sets the HW */
  2306. if (bp->port.pmf)
  2307. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2308. /* init Event Queue */
  2309. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2310. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2311. eq_data.producer = bp->eq_prod;
  2312. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2313. eq_data.sb_id = DEF_SB_ID;
  2314. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2315. }
  2316. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2317. {
  2318. int port = BP_PORT(bp);
  2319. bnx2x_tx_disable(bp);
  2320. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2321. }
  2322. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2323. {
  2324. int port = BP_PORT(bp);
  2325. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2326. /* Tx queue should be only reenabled */
  2327. netif_tx_wake_all_queues(bp->dev);
  2328. /*
  2329. * Should not call netif_carrier_on since it will be called if the link
  2330. * is up when checking for link state
  2331. */
  2332. }
  2333. /* called due to MCP event (on pmf):
  2334. * reread new bandwidth configuration
  2335. * configure FW
  2336. * notify others function about the change
  2337. */
  2338. static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
  2339. {
  2340. if (bp->link_vars.link_up) {
  2341. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2342. bnx2x_link_sync_notify(bp);
  2343. }
  2344. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2345. }
  2346. static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
  2347. {
  2348. bnx2x_config_mf_bw(bp);
  2349. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2350. }
  2351. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2352. {
  2353. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2354. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2355. /*
  2356. * This is the only place besides the function initialization
  2357. * where the bp->flags can change so it is done without any
  2358. * locks
  2359. */
  2360. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2361. DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
  2362. bp->flags |= MF_FUNC_DIS;
  2363. bnx2x_e1h_disable(bp);
  2364. } else {
  2365. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2366. bp->flags &= ~MF_FUNC_DIS;
  2367. bnx2x_e1h_enable(bp);
  2368. }
  2369. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2370. }
  2371. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2372. bnx2x_config_mf_bw(bp);
  2373. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2374. }
  2375. /* Report results to MCP */
  2376. if (dcc_event)
  2377. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2378. else
  2379. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2380. }
  2381. /* must be called under the spq lock */
  2382. static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2383. {
  2384. struct eth_spe *next_spe = bp->spq_prod_bd;
  2385. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2386. bp->spq_prod_bd = bp->spq;
  2387. bp->spq_prod_idx = 0;
  2388. DP(NETIF_MSG_TIMER, "end of spq\n");
  2389. } else {
  2390. bp->spq_prod_bd++;
  2391. bp->spq_prod_idx++;
  2392. }
  2393. return next_spe;
  2394. }
  2395. /* must be called under the spq lock */
  2396. static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
  2397. {
  2398. int func = BP_FUNC(bp);
  2399. /* Make sure that BD data is updated before writing the producer */
  2400. wmb();
  2401. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2402. bp->spq_prod_idx);
  2403. mmiowb();
  2404. }
  2405. /**
  2406. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2407. *
  2408. * @cmd: command to check
  2409. * @cmd_type: command type
  2410. */
  2411. static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2412. {
  2413. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2414. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2415. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2416. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2417. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2418. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2419. return true;
  2420. else
  2421. return false;
  2422. }
  2423. /**
  2424. * bnx2x_sp_post - place a single command on an SP ring
  2425. *
  2426. * @bp: driver handle
  2427. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2428. * @cid: SW CID the command is related to
  2429. * @data_hi: command private data address (high 32 bits)
  2430. * @data_lo: command private data address (low 32 bits)
  2431. * @cmd_type: command type (e.g. NONE, ETH)
  2432. *
  2433. * SP data is handled as if it's always an address pair, thus data fields are
  2434. * not swapped to little endian in upper functions. Instead this function swaps
  2435. * data as if it's two u32 fields.
  2436. */
  2437. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2438. u32 data_hi, u32 data_lo, int cmd_type)
  2439. {
  2440. struct eth_spe *spe;
  2441. u16 type;
  2442. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2443. #ifdef BNX2X_STOP_ON_ERROR
  2444. if (unlikely(bp->panic))
  2445. return -EIO;
  2446. #endif
  2447. spin_lock_bh(&bp->spq_lock);
  2448. if (common) {
  2449. if (!atomic_read(&bp->eq_spq_left)) {
  2450. BNX2X_ERR("BUG! EQ ring full!\n");
  2451. spin_unlock_bh(&bp->spq_lock);
  2452. bnx2x_panic();
  2453. return -EBUSY;
  2454. }
  2455. } else if (!atomic_read(&bp->cq_spq_left)) {
  2456. BNX2X_ERR("BUG! SPQ ring full!\n");
  2457. spin_unlock_bh(&bp->spq_lock);
  2458. bnx2x_panic();
  2459. return -EBUSY;
  2460. }
  2461. spe = bnx2x_sp_get_next(bp);
  2462. /* CID needs port number to be encoded int it */
  2463. spe->hdr.conn_and_cmd_data =
  2464. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2465. HW_CID(bp, cid));
  2466. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2467. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2468. SPE_HDR_FUNCTION_ID);
  2469. spe->hdr.type = cpu_to_le16(type);
  2470. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2471. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2472. /* stats ramrod has it's own slot on the spq */
  2473. if (command != RAMROD_CMD_ID_COMMON_STAT_QUERY) {
  2474. /*
  2475. * It's ok if the actual decrement is issued towards the memory
  2476. * somewhere between the spin_lock and spin_unlock. Thus no
  2477. * more explict memory barrier is needed.
  2478. */
  2479. if (common)
  2480. atomic_dec(&bp->eq_spq_left);
  2481. else
  2482. atomic_dec(&bp->cq_spq_left);
  2483. }
  2484. DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
  2485. "SPQE[%x] (%x:%x) command %d hw_cid %x data (%x:%x) "
  2486. "type(0x%x) left (ETH, COMMON) (%x,%x)\n",
  2487. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2488. (u32)(U64_LO(bp->spq_mapping) +
  2489. (void *)bp->spq_prod_bd - (void *)bp->spq), command,
  2490. HW_CID(bp, cid), data_hi, data_lo, type,
  2491. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2492. bnx2x_sp_prod_update(bp);
  2493. spin_unlock_bh(&bp->spq_lock);
  2494. return 0;
  2495. }
  2496. /* acquire split MCP access lock register */
  2497. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2498. {
  2499. u32 j, val;
  2500. int rc = 0;
  2501. might_sleep();
  2502. for (j = 0; j < 1000; j++) {
  2503. val = (1UL << 31);
  2504. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2505. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2506. if (val & (1L << 31))
  2507. break;
  2508. msleep(5);
  2509. }
  2510. if (!(val & (1L << 31))) {
  2511. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2512. rc = -EBUSY;
  2513. }
  2514. return rc;
  2515. }
  2516. /* release split MCP access lock register */
  2517. static void bnx2x_release_alr(struct bnx2x *bp)
  2518. {
  2519. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2520. }
  2521. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2522. #define BNX2X_DEF_SB_IDX 0x0002
  2523. static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2524. {
  2525. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2526. u16 rc = 0;
  2527. barrier(); /* status block is written to by the chip */
  2528. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2529. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2530. rc |= BNX2X_DEF_SB_ATT_IDX;
  2531. }
  2532. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2533. bp->def_idx = def_sb->sp_sb.running_index;
  2534. rc |= BNX2X_DEF_SB_IDX;
  2535. }
  2536. /* Do not reorder: indecies reading should complete before handling */
  2537. barrier();
  2538. return rc;
  2539. }
  2540. /*
  2541. * slow path service functions
  2542. */
  2543. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2544. {
  2545. int port = BP_PORT(bp);
  2546. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2547. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2548. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2549. NIG_REG_MASK_INTERRUPT_PORT0;
  2550. u32 aeu_mask;
  2551. u32 nig_mask = 0;
  2552. u32 reg_addr;
  2553. if (bp->attn_state & asserted)
  2554. BNX2X_ERR("IGU ERROR\n");
  2555. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2556. aeu_mask = REG_RD(bp, aeu_addr);
  2557. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2558. aeu_mask, asserted);
  2559. aeu_mask &= ~(asserted & 0x3ff);
  2560. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2561. REG_WR(bp, aeu_addr, aeu_mask);
  2562. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2563. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2564. bp->attn_state |= asserted;
  2565. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2566. if (asserted & ATTN_HARD_WIRED_MASK) {
  2567. if (asserted & ATTN_NIG_FOR_FUNC) {
  2568. bnx2x_acquire_phy_lock(bp);
  2569. /* save nig interrupt mask */
  2570. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2571. /* If nig_mask is not set, no need to call the update
  2572. * function.
  2573. */
  2574. if (nig_mask) {
  2575. REG_WR(bp, nig_int_mask_addr, 0);
  2576. bnx2x_link_attn(bp);
  2577. }
  2578. /* handle unicore attn? */
  2579. }
  2580. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2581. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2582. if (asserted & GPIO_2_FUNC)
  2583. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2584. if (asserted & GPIO_3_FUNC)
  2585. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2586. if (asserted & GPIO_4_FUNC)
  2587. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2588. if (port == 0) {
  2589. if (asserted & ATTN_GENERAL_ATTN_1) {
  2590. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2591. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2592. }
  2593. if (asserted & ATTN_GENERAL_ATTN_2) {
  2594. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2595. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2596. }
  2597. if (asserted & ATTN_GENERAL_ATTN_3) {
  2598. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2599. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2600. }
  2601. } else {
  2602. if (asserted & ATTN_GENERAL_ATTN_4) {
  2603. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2604. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2605. }
  2606. if (asserted & ATTN_GENERAL_ATTN_5) {
  2607. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2608. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2609. }
  2610. if (asserted & ATTN_GENERAL_ATTN_6) {
  2611. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2612. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2613. }
  2614. }
  2615. } /* if hardwired */
  2616. if (bp->common.int_block == INT_BLOCK_HC)
  2617. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2618. COMMAND_REG_ATTN_BITS_SET);
  2619. else
  2620. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2621. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2622. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2623. REG_WR(bp, reg_addr, asserted);
  2624. /* now set back the mask */
  2625. if (asserted & ATTN_NIG_FOR_FUNC) {
  2626. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2627. bnx2x_release_phy_lock(bp);
  2628. }
  2629. }
  2630. static inline void bnx2x_fan_failure(struct bnx2x *bp)
  2631. {
  2632. int port = BP_PORT(bp);
  2633. u32 ext_phy_config;
  2634. /* mark the failure */
  2635. ext_phy_config =
  2636. SHMEM_RD(bp,
  2637. dev_info.port_hw_config[port].external_phy_config);
  2638. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2639. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2640. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2641. ext_phy_config);
  2642. /* log the failure */
  2643. netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
  2644. " the driver to shutdown the card to prevent permanent"
  2645. " damage. Please contact OEM Support for assistance\n");
  2646. }
  2647. static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2648. {
  2649. int port = BP_PORT(bp);
  2650. int reg_offset;
  2651. u32 val;
  2652. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2653. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2654. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2655. val = REG_RD(bp, reg_offset);
  2656. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2657. REG_WR(bp, reg_offset, val);
  2658. BNX2X_ERR("SPIO5 hw attention\n");
  2659. /* Fan failure attention */
  2660. bnx2x_hw_reset_phy(&bp->link_params);
  2661. bnx2x_fan_failure(bp);
  2662. }
  2663. if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
  2664. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
  2665. bnx2x_acquire_phy_lock(bp);
  2666. bnx2x_handle_module_detect_int(&bp->link_params);
  2667. bnx2x_release_phy_lock(bp);
  2668. }
  2669. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2670. val = REG_RD(bp, reg_offset);
  2671. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2672. REG_WR(bp, reg_offset, val);
  2673. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  2674. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  2675. bnx2x_panic();
  2676. }
  2677. }
  2678. static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  2679. {
  2680. u32 val;
  2681. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  2682. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  2683. BNX2X_ERR("DB hw attention 0x%x\n", val);
  2684. /* DORQ discard attention */
  2685. if (val & 0x2)
  2686. BNX2X_ERR("FATAL error from DORQ\n");
  2687. }
  2688. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  2689. int port = BP_PORT(bp);
  2690. int reg_offset;
  2691. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  2692. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  2693. val = REG_RD(bp, reg_offset);
  2694. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  2695. REG_WR(bp, reg_offset, val);
  2696. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  2697. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  2698. bnx2x_panic();
  2699. }
  2700. }
  2701. static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  2702. {
  2703. u32 val;
  2704. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  2705. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  2706. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  2707. /* CFC error attention */
  2708. if (val & 0x2)
  2709. BNX2X_ERR("FATAL error from CFC\n");
  2710. }
  2711. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  2712. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  2713. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  2714. /* RQ_USDMDP_FIFO_OVERFLOW */
  2715. if (val & 0x18000)
  2716. BNX2X_ERR("FATAL error from PXP\n");
  2717. if (!CHIP_IS_E1x(bp)) {
  2718. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  2719. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  2720. }
  2721. }
  2722. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  2723. int port = BP_PORT(bp);
  2724. int reg_offset;
  2725. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  2726. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  2727. val = REG_RD(bp, reg_offset);
  2728. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  2729. REG_WR(bp, reg_offset, val);
  2730. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  2731. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  2732. bnx2x_panic();
  2733. }
  2734. }
  2735. static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  2736. {
  2737. u32 val;
  2738. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  2739. if (attn & BNX2X_PMF_LINK_ASSERT) {
  2740. int func = BP_FUNC(bp);
  2741. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  2742. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  2743. func_mf_config[BP_ABS_FUNC(bp)].config);
  2744. val = SHMEM_RD(bp,
  2745. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  2746. if (val & DRV_STATUS_DCC_EVENT_MASK)
  2747. bnx2x_dcc_event(bp,
  2748. (val & DRV_STATUS_DCC_EVENT_MASK));
  2749. if (val & DRV_STATUS_SET_MF_BW)
  2750. bnx2x_set_mf_bw(bp);
  2751. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  2752. bnx2x_pmf_update(bp);
  2753. /* Always call it here: bnx2x_link_report() will
  2754. * prevent the link indication duplication.
  2755. */
  2756. bnx2x__link_status_update(bp);
  2757. if (bp->port.pmf &&
  2758. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  2759. bp->dcbx_enabled > 0)
  2760. /* start dcbx state machine */
  2761. bnx2x_dcbx_set_params(bp,
  2762. BNX2X_DCBX_STATE_NEG_RECEIVED);
  2763. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  2764. BNX2X_ERR("MC assert!\n");
  2765. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  2766. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  2767. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  2768. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  2769. bnx2x_panic();
  2770. } else if (attn & BNX2X_MCP_ASSERT) {
  2771. BNX2X_ERR("MCP assert!\n");
  2772. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  2773. bnx2x_fw_dump(bp);
  2774. } else
  2775. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  2776. }
  2777. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  2778. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  2779. if (attn & BNX2X_GRC_TIMEOUT) {
  2780. val = CHIP_IS_E1(bp) ? 0 :
  2781. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  2782. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  2783. }
  2784. if (attn & BNX2X_GRC_RSV) {
  2785. val = CHIP_IS_E1(bp) ? 0 :
  2786. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  2787. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  2788. }
  2789. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  2790. }
  2791. }
  2792. /*
  2793. * Bits map:
  2794. * 0-7 - Engine0 load counter.
  2795. * 8-15 - Engine1 load counter.
  2796. * 16 - Engine0 RESET_IN_PROGRESS bit.
  2797. * 17 - Engine1 RESET_IN_PROGRESS bit.
  2798. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  2799. * on the engine
  2800. * 19 - Engine1 ONE_IS_LOADED.
  2801. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  2802. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  2803. * just the one belonging to its engine).
  2804. *
  2805. */
  2806. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  2807. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  2808. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  2809. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  2810. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  2811. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  2812. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  2813. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  2814. /*
  2815. * Set the GLOBAL_RESET bit.
  2816. *
  2817. * Should be run under rtnl lock
  2818. */
  2819. void bnx2x_set_reset_global(struct bnx2x *bp)
  2820. {
  2821. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2822. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  2823. barrier();
  2824. mmiowb();
  2825. }
  2826. /*
  2827. * Clear the GLOBAL_RESET bit.
  2828. *
  2829. * Should be run under rtnl lock
  2830. */
  2831. static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
  2832. {
  2833. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2834. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  2835. barrier();
  2836. mmiowb();
  2837. }
  2838. /*
  2839. * Checks the GLOBAL_RESET bit.
  2840. *
  2841. * should be run under rtnl lock
  2842. */
  2843. static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
  2844. {
  2845. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2846. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  2847. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  2848. }
  2849. /*
  2850. * Clear RESET_IN_PROGRESS bit for the current engine.
  2851. *
  2852. * Should be run under rtnl lock
  2853. */
  2854. static inline void bnx2x_set_reset_done(struct bnx2x *bp)
  2855. {
  2856. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2857. u32 bit = BP_PATH(bp) ?
  2858. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2859. /* Clear the bit */
  2860. val &= ~bit;
  2861. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2862. barrier();
  2863. mmiowb();
  2864. }
  2865. /*
  2866. * Set RESET_IN_PROGRESS for the current engine.
  2867. *
  2868. * should be run under rtnl lock
  2869. */
  2870. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  2871. {
  2872. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2873. u32 bit = BP_PATH(bp) ?
  2874. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2875. /* Set the bit */
  2876. val |= bit;
  2877. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2878. barrier();
  2879. mmiowb();
  2880. }
  2881. /*
  2882. * Checks the RESET_IN_PROGRESS bit for the given engine.
  2883. * should be run under rtnl lock
  2884. */
  2885. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  2886. {
  2887. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2888. u32 bit = engine ?
  2889. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2890. /* return false if bit is set */
  2891. return (val & bit) ? false : true;
  2892. }
  2893. /*
  2894. * Increment the load counter for the current engine.
  2895. *
  2896. * should be run under rtnl lock
  2897. */
  2898. void bnx2x_inc_load_cnt(struct bnx2x *bp)
  2899. {
  2900. u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2901. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  2902. BNX2X_PATH0_LOAD_CNT_MASK;
  2903. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  2904. BNX2X_PATH0_LOAD_CNT_SHIFT;
  2905. DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
  2906. /* get the current counter value */
  2907. val1 = (val & mask) >> shift;
  2908. /* increment... */
  2909. val1++;
  2910. /* clear the old value */
  2911. val &= ~mask;
  2912. /* set the new one */
  2913. val |= ((val1 << shift) & mask);
  2914. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2915. barrier();
  2916. mmiowb();
  2917. }
  2918. /**
  2919. * bnx2x_dec_load_cnt - decrement the load counter
  2920. *
  2921. * @bp: driver handle
  2922. *
  2923. * Should be run under rtnl lock.
  2924. * Decrements the load counter for the current engine. Returns
  2925. * the new counter value.
  2926. */
  2927. u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
  2928. {
  2929. u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2930. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  2931. BNX2X_PATH0_LOAD_CNT_MASK;
  2932. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  2933. BNX2X_PATH0_LOAD_CNT_SHIFT;
  2934. DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
  2935. /* get the current counter value */
  2936. val1 = (val & mask) >> shift;
  2937. /* decrement... */
  2938. val1--;
  2939. /* clear the old value */
  2940. val &= ~mask;
  2941. /* set the new one */
  2942. val |= ((val1 << shift) & mask);
  2943. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2944. barrier();
  2945. mmiowb();
  2946. return val1;
  2947. }
  2948. /*
  2949. * Read the load counter for the current engine.
  2950. *
  2951. * should be run under rtnl lock
  2952. */
  2953. static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
  2954. {
  2955. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  2956. BNX2X_PATH0_LOAD_CNT_MASK);
  2957. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  2958. BNX2X_PATH0_LOAD_CNT_SHIFT);
  2959. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2960. DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
  2961. val = (val & mask) >> shift;
  2962. DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
  2963. return val;
  2964. }
  2965. /*
  2966. * Reset the load counter for the current engine.
  2967. *
  2968. * should be run under rtnl lock
  2969. */
  2970. static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
  2971. {
  2972. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2973. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  2974. BNX2X_PATH0_LOAD_CNT_MASK);
  2975. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  2976. }
  2977. static inline void _print_next_block(int idx, const char *blk)
  2978. {
  2979. if (idx)
  2980. pr_cont(", ");
  2981. pr_cont("%s", blk);
  2982. }
  2983. static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  2984. bool print)
  2985. {
  2986. int i = 0;
  2987. u32 cur_bit = 0;
  2988. for (i = 0; sig; i++) {
  2989. cur_bit = ((u32)0x1 << i);
  2990. if (sig & cur_bit) {
  2991. switch (cur_bit) {
  2992. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  2993. if (print)
  2994. _print_next_block(par_num++, "BRB");
  2995. break;
  2996. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  2997. if (print)
  2998. _print_next_block(par_num++, "PARSER");
  2999. break;
  3000. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3001. if (print)
  3002. _print_next_block(par_num++, "TSDM");
  3003. break;
  3004. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3005. if (print)
  3006. _print_next_block(par_num++,
  3007. "SEARCHER");
  3008. break;
  3009. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3010. if (print)
  3011. _print_next_block(par_num++, "TCM");
  3012. break;
  3013. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3014. if (print)
  3015. _print_next_block(par_num++, "TSEMI");
  3016. break;
  3017. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3018. if (print)
  3019. _print_next_block(par_num++, "XPB");
  3020. break;
  3021. }
  3022. /* Clear the bit */
  3023. sig &= ~cur_bit;
  3024. }
  3025. }
  3026. return par_num;
  3027. }
  3028. static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3029. bool *global, bool print)
  3030. {
  3031. int i = 0;
  3032. u32 cur_bit = 0;
  3033. for (i = 0; sig; i++) {
  3034. cur_bit = ((u32)0x1 << i);
  3035. if (sig & cur_bit) {
  3036. switch (cur_bit) {
  3037. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3038. if (print)
  3039. _print_next_block(par_num++, "PBF");
  3040. break;
  3041. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3042. if (print)
  3043. _print_next_block(par_num++, "QM");
  3044. break;
  3045. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3046. if (print)
  3047. _print_next_block(par_num++, "TM");
  3048. break;
  3049. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3050. if (print)
  3051. _print_next_block(par_num++, "XSDM");
  3052. break;
  3053. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3054. if (print)
  3055. _print_next_block(par_num++, "XCM");
  3056. break;
  3057. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3058. if (print)
  3059. _print_next_block(par_num++, "XSEMI");
  3060. break;
  3061. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3062. if (print)
  3063. _print_next_block(par_num++,
  3064. "DOORBELLQ");
  3065. break;
  3066. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3067. if (print)
  3068. _print_next_block(par_num++, "NIG");
  3069. break;
  3070. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3071. if (print)
  3072. _print_next_block(par_num++,
  3073. "VAUX PCI CORE");
  3074. *global = true;
  3075. break;
  3076. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3077. if (print)
  3078. _print_next_block(par_num++, "DEBUG");
  3079. break;
  3080. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3081. if (print)
  3082. _print_next_block(par_num++, "USDM");
  3083. break;
  3084. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3085. if (print)
  3086. _print_next_block(par_num++, "USEMI");
  3087. break;
  3088. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3089. if (print)
  3090. _print_next_block(par_num++, "UPB");
  3091. break;
  3092. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3093. if (print)
  3094. _print_next_block(par_num++, "CSDM");
  3095. break;
  3096. }
  3097. /* Clear the bit */
  3098. sig &= ~cur_bit;
  3099. }
  3100. }
  3101. return par_num;
  3102. }
  3103. static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3104. bool print)
  3105. {
  3106. int i = 0;
  3107. u32 cur_bit = 0;
  3108. for (i = 0; sig; i++) {
  3109. cur_bit = ((u32)0x1 << i);
  3110. if (sig & cur_bit) {
  3111. switch (cur_bit) {
  3112. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3113. if (print)
  3114. _print_next_block(par_num++, "CSEMI");
  3115. break;
  3116. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3117. if (print)
  3118. _print_next_block(par_num++, "PXP");
  3119. break;
  3120. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3121. if (print)
  3122. _print_next_block(par_num++,
  3123. "PXPPCICLOCKCLIENT");
  3124. break;
  3125. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3126. if (print)
  3127. _print_next_block(par_num++, "CFC");
  3128. break;
  3129. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3130. if (print)
  3131. _print_next_block(par_num++, "CDU");
  3132. break;
  3133. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3134. if (print)
  3135. _print_next_block(par_num++, "DMAE");
  3136. break;
  3137. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3138. if (print)
  3139. _print_next_block(par_num++, "IGU");
  3140. break;
  3141. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3142. if (print)
  3143. _print_next_block(par_num++, "MISC");
  3144. break;
  3145. }
  3146. /* Clear the bit */
  3147. sig &= ~cur_bit;
  3148. }
  3149. }
  3150. return par_num;
  3151. }
  3152. static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3153. bool *global, bool print)
  3154. {
  3155. int i = 0;
  3156. u32 cur_bit = 0;
  3157. for (i = 0; sig; i++) {
  3158. cur_bit = ((u32)0x1 << i);
  3159. if (sig & cur_bit) {
  3160. switch (cur_bit) {
  3161. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3162. if (print)
  3163. _print_next_block(par_num++, "MCP ROM");
  3164. *global = true;
  3165. break;
  3166. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3167. if (print)
  3168. _print_next_block(par_num++,
  3169. "MCP UMP RX");
  3170. *global = true;
  3171. break;
  3172. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3173. if (print)
  3174. _print_next_block(par_num++,
  3175. "MCP UMP TX");
  3176. *global = true;
  3177. break;
  3178. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3179. if (print)
  3180. _print_next_block(par_num++,
  3181. "MCP SCPAD");
  3182. *global = true;
  3183. break;
  3184. }
  3185. /* Clear the bit */
  3186. sig &= ~cur_bit;
  3187. }
  3188. }
  3189. return par_num;
  3190. }
  3191. static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3192. u32 sig0, u32 sig1, u32 sig2, u32 sig3)
  3193. {
  3194. if ((sig0 & HW_PRTY_ASSERT_SET_0) || (sig1 & HW_PRTY_ASSERT_SET_1) ||
  3195. (sig2 & HW_PRTY_ASSERT_SET_2) || (sig3 & HW_PRTY_ASSERT_SET_3)) {
  3196. int par_num = 0;
  3197. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
  3198. "[0]:0x%08x [1]:0x%08x "
  3199. "[2]:0x%08x [3]:0x%08x\n",
  3200. sig0 & HW_PRTY_ASSERT_SET_0,
  3201. sig1 & HW_PRTY_ASSERT_SET_1,
  3202. sig2 & HW_PRTY_ASSERT_SET_2,
  3203. sig3 & HW_PRTY_ASSERT_SET_3);
  3204. if (print)
  3205. netdev_err(bp->dev,
  3206. "Parity errors detected in blocks: ");
  3207. par_num = bnx2x_check_blocks_with_parity0(
  3208. sig0 & HW_PRTY_ASSERT_SET_0, par_num, print);
  3209. par_num = bnx2x_check_blocks_with_parity1(
  3210. sig1 & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3211. par_num = bnx2x_check_blocks_with_parity2(
  3212. sig2 & HW_PRTY_ASSERT_SET_2, par_num, print);
  3213. par_num = bnx2x_check_blocks_with_parity3(
  3214. sig3 & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3215. if (print)
  3216. pr_cont("\n");
  3217. return true;
  3218. } else
  3219. return false;
  3220. }
  3221. /**
  3222. * bnx2x_chk_parity_attn - checks for parity attentions.
  3223. *
  3224. * @bp: driver handle
  3225. * @global: true if there was a global attention
  3226. * @print: show parity attention in syslog
  3227. */
  3228. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3229. {
  3230. struct attn_route attn;
  3231. int port = BP_PORT(bp);
  3232. attn.sig[0] = REG_RD(bp,
  3233. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3234. port*4);
  3235. attn.sig[1] = REG_RD(bp,
  3236. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3237. port*4);
  3238. attn.sig[2] = REG_RD(bp,
  3239. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3240. port*4);
  3241. attn.sig[3] = REG_RD(bp,
  3242. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3243. port*4);
  3244. return bnx2x_parity_attn(bp, global, print, attn.sig[0], attn.sig[1],
  3245. attn.sig[2], attn.sig[3]);
  3246. }
  3247. static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3248. {
  3249. u32 val;
  3250. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3251. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3252. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3253. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3254. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3255. "ADDRESS_ERROR\n");
  3256. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3257. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3258. "INCORRECT_RCV_BEHAVIOR\n");
  3259. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3260. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3261. "WAS_ERROR_ATTN\n");
  3262. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3263. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3264. "VF_LENGTH_VIOLATION_ATTN\n");
  3265. if (val &
  3266. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3267. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3268. "VF_GRC_SPACE_VIOLATION_ATTN\n");
  3269. if (val &
  3270. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3271. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3272. "VF_MSIX_BAR_VIOLATION_ATTN\n");
  3273. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3274. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3275. "TCPL_ERROR_ATTN\n");
  3276. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3277. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3278. "TCPL_IN_TWO_RCBS_ATTN\n");
  3279. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3280. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3281. "CSSNOOP_FIFO_OVERFLOW\n");
  3282. }
  3283. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3284. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3285. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3286. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3287. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3288. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3289. BNX2X_ERR("ATC_ATC_INT_STS_REG"
  3290. "_ATC_TCPL_TO_NOT_PEND\n");
  3291. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3292. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3293. "ATC_GPA_MULTIPLE_HITS\n");
  3294. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3295. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3296. "ATC_RCPL_TO_EMPTY_CNT\n");
  3297. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3298. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3299. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3300. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3301. "ATC_IREQ_LESS_THAN_STU\n");
  3302. }
  3303. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3304. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3305. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3306. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3307. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3308. }
  3309. }
  3310. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3311. {
  3312. struct attn_route attn, *group_mask;
  3313. int port = BP_PORT(bp);
  3314. int index;
  3315. u32 reg_addr;
  3316. u32 val;
  3317. u32 aeu_mask;
  3318. bool global = false;
  3319. /* need to take HW lock because MCP or other port might also
  3320. try to handle this event */
  3321. bnx2x_acquire_alr(bp);
  3322. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3323. #ifndef BNX2X_STOP_ON_ERROR
  3324. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3325. schedule_delayed_work(&bp->reset_task, 0);
  3326. /* Disable HW interrupts */
  3327. bnx2x_int_disable(bp);
  3328. /* In case of parity errors don't handle attentions so that
  3329. * other function would "see" parity errors.
  3330. */
  3331. #else
  3332. bnx2x_panic();
  3333. #endif
  3334. bnx2x_release_alr(bp);
  3335. return;
  3336. }
  3337. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3338. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3339. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3340. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3341. if (!CHIP_IS_E1x(bp))
  3342. attn.sig[4] =
  3343. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3344. else
  3345. attn.sig[4] = 0;
  3346. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3347. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3348. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3349. if (deasserted & (1 << index)) {
  3350. group_mask = &bp->attn_group[index];
  3351. DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
  3352. "%08x %08x %08x\n",
  3353. index,
  3354. group_mask->sig[0], group_mask->sig[1],
  3355. group_mask->sig[2], group_mask->sig[3],
  3356. group_mask->sig[4]);
  3357. bnx2x_attn_int_deasserted4(bp,
  3358. attn.sig[4] & group_mask->sig[4]);
  3359. bnx2x_attn_int_deasserted3(bp,
  3360. attn.sig[3] & group_mask->sig[3]);
  3361. bnx2x_attn_int_deasserted1(bp,
  3362. attn.sig[1] & group_mask->sig[1]);
  3363. bnx2x_attn_int_deasserted2(bp,
  3364. attn.sig[2] & group_mask->sig[2]);
  3365. bnx2x_attn_int_deasserted0(bp,
  3366. attn.sig[0] & group_mask->sig[0]);
  3367. }
  3368. }
  3369. bnx2x_release_alr(bp);
  3370. if (bp->common.int_block == INT_BLOCK_HC)
  3371. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3372. COMMAND_REG_ATTN_BITS_CLR);
  3373. else
  3374. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3375. val = ~deasserted;
  3376. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3377. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3378. REG_WR(bp, reg_addr, val);
  3379. if (~bp->attn_state & deasserted)
  3380. BNX2X_ERR("IGU ERROR\n");
  3381. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3382. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3383. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3384. aeu_mask = REG_RD(bp, reg_addr);
  3385. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3386. aeu_mask, deasserted);
  3387. aeu_mask |= (deasserted & 0x3ff);
  3388. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3389. REG_WR(bp, reg_addr, aeu_mask);
  3390. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3391. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3392. bp->attn_state &= ~deasserted;
  3393. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3394. }
  3395. static void bnx2x_attn_int(struct bnx2x *bp)
  3396. {
  3397. /* read local copy of bits */
  3398. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3399. attn_bits);
  3400. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3401. attn_bits_ack);
  3402. u32 attn_state = bp->attn_state;
  3403. /* look for changed bits */
  3404. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3405. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3406. DP(NETIF_MSG_HW,
  3407. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3408. attn_bits, attn_ack, asserted, deasserted);
  3409. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3410. BNX2X_ERR("BAD attention state\n");
  3411. /* handle bits that were raised */
  3412. if (asserted)
  3413. bnx2x_attn_int_asserted(bp, asserted);
  3414. if (deasserted)
  3415. bnx2x_attn_int_deasserted(bp, deasserted);
  3416. }
  3417. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3418. u16 index, u8 op, u8 update)
  3419. {
  3420. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3421. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3422. igu_addr);
  3423. }
  3424. static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3425. {
  3426. /* No memory barriers */
  3427. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3428. mmiowb(); /* keep prod updates ordered */
  3429. }
  3430. #ifdef BCM_CNIC
  3431. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3432. union event_ring_elem *elem)
  3433. {
  3434. u8 err = elem->message.error;
  3435. if (!bp->cnic_eth_dev.starting_cid ||
  3436. (cid < bp->cnic_eth_dev.starting_cid &&
  3437. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3438. return 1;
  3439. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3440. if (unlikely(err)) {
  3441. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3442. cid);
  3443. bnx2x_panic_dump(bp);
  3444. }
  3445. bnx2x_cnic_cfc_comp(bp, cid, err);
  3446. return 0;
  3447. }
  3448. #endif
  3449. static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3450. {
  3451. struct bnx2x_mcast_ramrod_params rparam;
  3452. int rc;
  3453. memset(&rparam, 0, sizeof(rparam));
  3454. rparam.mcast_obj = &bp->mcast_obj;
  3455. netif_addr_lock_bh(bp->dev);
  3456. /* Clear pending state for the last command */
  3457. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3458. /* If there are pending mcast commands - send them */
  3459. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3460. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3461. if (rc < 0)
  3462. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3463. rc);
  3464. }
  3465. netif_addr_unlock_bh(bp->dev);
  3466. }
  3467. static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3468. union event_ring_elem *elem)
  3469. {
  3470. unsigned long ramrod_flags = 0;
  3471. int rc = 0;
  3472. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3473. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3474. /* Always push next commands out, don't wait here */
  3475. __set_bit(RAMROD_CONT, &ramrod_flags);
  3476. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3477. case BNX2X_FILTER_MAC_PENDING:
  3478. #ifdef BCM_CNIC
  3479. if (cid == BNX2X_ISCSI_ETH_CID)
  3480. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3481. else
  3482. #endif
  3483. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3484. break;
  3485. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3486. case BNX2X_FILTER_MCAST_PENDING:
  3487. /* This is only relevant for 57710 where multicast MACs are
  3488. * configured as unicast MACs using the same ramrod.
  3489. */
  3490. bnx2x_handle_mcast_eqe(bp);
  3491. return;
  3492. default:
  3493. BNX2X_ERR("Unsupported classification command: %d\n",
  3494. elem->message.data.eth_event.echo);
  3495. return;
  3496. }
  3497. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3498. if (rc < 0)
  3499. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3500. else if (rc > 0)
  3501. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3502. }
  3503. #ifdef BCM_CNIC
  3504. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3505. #endif
  3506. static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3507. {
  3508. netif_addr_lock_bh(bp->dev);
  3509. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3510. /* Send rx_mode command again if was requested */
  3511. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3512. bnx2x_set_storm_rx_mode(bp);
  3513. #ifdef BCM_CNIC
  3514. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3515. &bp->sp_state))
  3516. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3517. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3518. &bp->sp_state))
  3519. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3520. #endif
  3521. netif_addr_unlock_bh(bp->dev);
  3522. }
  3523. static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3524. struct bnx2x *bp, u32 cid)
  3525. {
  3526. #ifdef BCM_CNIC
  3527. if (cid == BNX2X_FCOE_ETH_CID)
  3528. return &bnx2x_fcoe(bp, q_obj);
  3529. else
  3530. #endif
  3531. return &bnx2x_fp(bp, cid, q_obj);
  3532. }
  3533. static void bnx2x_eq_int(struct bnx2x *bp)
  3534. {
  3535. u16 hw_cons, sw_cons, sw_prod;
  3536. union event_ring_elem *elem;
  3537. u32 cid;
  3538. u8 opcode;
  3539. int spqe_cnt = 0;
  3540. struct bnx2x_queue_sp_obj *q_obj;
  3541. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  3542. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  3543. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  3544. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  3545. * when we get the the next-page we nned to adjust so the loop
  3546. * condition below will be met. The next element is the size of a
  3547. * regular element and hence incrementing by 1
  3548. */
  3549. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  3550. hw_cons++;
  3551. /* This function may never run in parallel with itself for a
  3552. * specific bp, thus there is no need in "paired" read memory
  3553. * barrier here.
  3554. */
  3555. sw_cons = bp->eq_cons;
  3556. sw_prod = bp->eq_prod;
  3557. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->cq_spq_left %u\n",
  3558. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  3559. for (; sw_cons != hw_cons;
  3560. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  3561. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  3562. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  3563. opcode = elem->message.opcode;
  3564. /* handle eq element */
  3565. switch (opcode) {
  3566. case EVENT_RING_OPCODE_STAT_QUERY:
  3567. DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
  3568. bp->stats_comp++);
  3569. /* nothing to do with stats comp */
  3570. continue;
  3571. case EVENT_RING_OPCODE_CFC_DEL:
  3572. /* handle according to cid range */
  3573. /*
  3574. * we may want to verify here that the bp state is
  3575. * HALTING
  3576. */
  3577. DP(NETIF_MSG_IFDOWN,
  3578. "got delete ramrod for MULTI[%d]\n", cid);
  3579. #ifdef BCM_CNIC
  3580. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  3581. goto next_spqe;
  3582. #endif
  3583. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  3584. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  3585. break;
  3586. goto next_spqe;
  3587. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  3588. DP(NETIF_MSG_IFUP, "got STOP TRAFFIC\n");
  3589. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  3590. goto next_spqe;
  3591. case EVENT_RING_OPCODE_START_TRAFFIC:
  3592. DP(NETIF_MSG_IFUP, "got START TRAFFIC\n");
  3593. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  3594. goto next_spqe;
  3595. case EVENT_RING_OPCODE_FUNCTION_START:
  3596. DP(NETIF_MSG_IFUP, "got FUNC_START ramrod\n");
  3597. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  3598. break;
  3599. goto next_spqe;
  3600. case EVENT_RING_OPCODE_FUNCTION_STOP:
  3601. DP(NETIF_MSG_IFDOWN, "got FUNC_STOP ramrod\n");
  3602. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  3603. break;
  3604. goto next_spqe;
  3605. }
  3606. switch (opcode | bp->state) {
  3607. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3608. BNX2X_STATE_OPEN):
  3609. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3610. BNX2X_STATE_OPENING_WAIT4_PORT):
  3611. cid = elem->message.data.eth_event.echo &
  3612. BNX2X_SWCID_MASK;
  3613. DP(NETIF_MSG_IFUP, "got RSS_UPDATE ramrod. CID %d\n",
  3614. cid);
  3615. rss_raw->clear_pending(rss_raw);
  3616. break;
  3617. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  3618. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  3619. case (EVENT_RING_OPCODE_SET_MAC |
  3620. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3621. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3622. BNX2X_STATE_OPEN):
  3623. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3624. BNX2X_STATE_DIAG):
  3625. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3626. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3627. DP(NETIF_MSG_IFUP, "got (un)set mac ramrod\n");
  3628. bnx2x_handle_classification_eqe(bp, elem);
  3629. break;
  3630. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3631. BNX2X_STATE_OPEN):
  3632. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3633. BNX2X_STATE_DIAG):
  3634. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3635. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3636. DP(NETIF_MSG_IFUP, "got mcast ramrod\n");
  3637. bnx2x_handle_mcast_eqe(bp);
  3638. break;
  3639. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3640. BNX2X_STATE_OPEN):
  3641. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3642. BNX2X_STATE_DIAG):
  3643. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3644. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3645. DP(NETIF_MSG_IFUP, "got rx_mode ramrod\n");
  3646. bnx2x_handle_rx_mode_eqe(bp);
  3647. break;
  3648. default:
  3649. /* unknown event log error and continue */
  3650. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  3651. elem->message.opcode, bp->state);
  3652. }
  3653. next_spqe:
  3654. spqe_cnt++;
  3655. } /* for */
  3656. smp_mb__before_atomic_inc();
  3657. atomic_add(spqe_cnt, &bp->eq_spq_left);
  3658. bp->eq_cons = sw_cons;
  3659. bp->eq_prod = sw_prod;
  3660. /* Make sure that above mem writes were issued towards the memory */
  3661. smp_wmb();
  3662. /* update producer */
  3663. bnx2x_update_eq_prod(bp, bp->eq_prod);
  3664. }
  3665. static void bnx2x_sp_task(struct work_struct *work)
  3666. {
  3667. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  3668. u16 status;
  3669. status = bnx2x_update_dsb_idx(bp);
  3670. /* if (status == 0) */
  3671. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  3672. DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
  3673. /* HW attentions */
  3674. if (status & BNX2X_DEF_SB_ATT_IDX) {
  3675. bnx2x_attn_int(bp);
  3676. status &= ~BNX2X_DEF_SB_ATT_IDX;
  3677. }
  3678. /* SP events: STAT_QUERY and others */
  3679. if (status & BNX2X_DEF_SB_IDX) {
  3680. #ifdef BCM_CNIC
  3681. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  3682. if ((!NO_FCOE(bp)) &&
  3683. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp)))
  3684. napi_schedule(&bnx2x_fcoe(bp, napi));
  3685. #endif
  3686. /* Handle EQ completions */
  3687. bnx2x_eq_int(bp);
  3688. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  3689. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  3690. status &= ~BNX2X_DEF_SB_IDX;
  3691. }
  3692. if (unlikely(status))
  3693. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  3694. status);
  3695. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  3696. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  3697. }
  3698. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  3699. {
  3700. struct net_device *dev = dev_instance;
  3701. struct bnx2x *bp = netdev_priv(dev);
  3702. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  3703. IGU_INT_DISABLE, 0);
  3704. #ifdef BNX2X_STOP_ON_ERROR
  3705. if (unlikely(bp->panic))
  3706. return IRQ_HANDLED;
  3707. #endif
  3708. #ifdef BCM_CNIC
  3709. {
  3710. struct cnic_ops *c_ops;
  3711. rcu_read_lock();
  3712. c_ops = rcu_dereference(bp->cnic_ops);
  3713. if (c_ops)
  3714. c_ops->cnic_handler(bp->cnic_data, NULL);
  3715. rcu_read_unlock();
  3716. }
  3717. #endif
  3718. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  3719. return IRQ_HANDLED;
  3720. }
  3721. /* end of slow path */
  3722. void bnx2x_drv_pulse(struct bnx2x *bp)
  3723. {
  3724. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  3725. bp->fw_drv_pulse_wr_seq);
  3726. }
  3727. static void bnx2x_timer(unsigned long data)
  3728. {
  3729. struct bnx2x *bp = (struct bnx2x *) data;
  3730. if (!netif_running(bp->dev))
  3731. return;
  3732. if (poll) {
  3733. struct bnx2x_fastpath *fp = &bp->fp[0];
  3734. bnx2x_tx_int(fp);
  3735. bnx2x_rx_int(fp, 1000);
  3736. }
  3737. if (!BP_NOMCP(bp)) {
  3738. int mb_idx = BP_FW_MB_IDX(bp);
  3739. u32 drv_pulse;
  3740. u32 mcp_pulse;
  3741. ++bp->fw_drv_pulse_wr_seq;
  3742. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  3743. /* TBD - add SYSTEM_TIME */
  3744. drv_pulse = bp->fw_drv_pulse_wr_seq;
  3745. bnx2x_drv_pulse(bp);
  3746. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  3747. MCP_PULSE_SEQ_MASK);
  3748. /* The delta between driver pulse and mcp response
  3749. * should be 1 (before mcp response) or 0 (after mcp response)
  3750. */
  3751. if ((drv_pulse != mcp_pulse) &&
  3752. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  3753. /* someone lost a heartbeat... */
  3754. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  3755. drv_pulse, mcp_pulse);
  3756. }
  3757. }
  3758. if (bp->state == BNX2X_STATE_OPEN)
  3759. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  3760. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3761. }
  3762. /* end of Statistics */
  3763. /* nic init */
  3764. /*
  3765. * nic init service functions
  3766. */
  3767. static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  3768. {
  3769. u32 i;
  3770. if (!(len%4) && !(addr%4))
  3771. for (i = 0; i < len; i += 4)
  3772. REG_WR(bp, addr + i, fill);
  3773. else
  3774. for (i = 0; i < len; i++)
  3775. REG_WR8(bp, addr + i, fill);
  3776. }
  3777. /* helper: writes FP SP data to FW - data_size in dwords */
  3778. static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  3779. int fw_sb_id,
  3780. u32 *sb_data_p,
  3781. u32 data_size)
  3782. {
  3783. int index;
  3784. for (index = 0; index < data_size; index++)
  3785. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3786. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  3787. sizeof(u32)*index,
  3788. *(sb_data_p + index));
  3789. }
  3790. static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  3791. {
  3792. u32 *sb_data_p;
  3793. u32 data_size = 0;
  3794. struct hc_status_block_data_e2 sb_data_e2;
  3795. struct hc_status_block_data_e1x sb_data_e1x;
  3796. /* disable the function first */
  3797. if (!CHIP_IS_E1x(bp)) {
  3798. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  3799. sb_data_e2.common.state = SB_DISABLED;
  3800. sb_data_e2.common.p_func.vf_valid = false;
  3801. sb_data_p = (u32 *)&sb_data_e2;
  3802. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  3803. } else {
  3804. memset(&sb_data_e1x, 0,
  3805. sizeof(struct hc_status_block_data_e1x));
  3806. sb_data_e1x.common.state = SB_DISABLED;
  3807. sb_data_e1x.common.p_func.vf_valid = false;
  3808. sb_data_p = (u32 *)&sb_data_e1x;
  3809. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  3810. }
  3811. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  3812. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3813. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  3814. CSTORM_STATUS_BLOCK_SIZE);
  3815. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3816. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  3817. CSTORM_SYNC_BLOCK_SIZE);
  3818. }
  3819. /* helper: writes SP SB data to FW */
  3820. static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  3821. struct hc_sp_status_block_data *sp_sb_data)
  3822. {
  3823. int func = BP_FUNC(bp);
  3824. int i;
  3825. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  3826. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3827. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  3828. i*sizeof(u32),
  3829. *((u32 *)sp_sb_data + i));
  3830. }
  3831. static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
  3832. {
  3833. int func = BP_FUNC(bp);
  3834. struct hc_sp_status_block_data sp_sb_data;
  3835. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  3836. sp_sb_data.state = SB_DISABLED;
  3837. sp_sb_data.p_func.vf_valid = false;
  3838. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  3839. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3840. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  3841. CSTORM_SP_STATUS_BLOCK_SIZE);
  3842. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3843. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  3844. CSTORM_SP_SYNC_BLOCK_SIZE);
  3845. }
  3846. static inline
  3847. void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  3848. int igu_sb_id, int igu_seg_id)
  3849. {
  3850. hc_sm->igu_sb_id = igu_sb_id;
  3851. hc_sm->igu_seg_id = igu_seg_id;
  3852. hc_sm->timer_value = 0xFF;
  3853. hc_sm->time_to_expire = 0xFFFFFFFF;
  3854. }
  3855. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  3856. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  3857. {
  3858. int igu_seg_id;
  3859. struct hc_status_block_data_e2 sb_data_e2;
  3860. struct hc_status_block_data_e1x sb_data_e1x;
  3861. struct hc_status_block_sm *hc_sm_p;
  3862. int data_size;
  3863. u32 *sb_data_p;
  3864. if (CHIP_INT_MODE_IS_BC(bp))
  3865. igu_seg_id = HC_SEG_ACCESS_NORM;
  3866. else
  3867. igu_seg_id = IGU_SEG_ACCESS_NORM;
  3868. bnx2x_zero_fp_sb(bp, fw_sb_id);
  3869. if (!CHIP_IS_E1x(bp)) {
  3870. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  3871. sb_data_e2.common.state = SB_ENABLED;
  3872. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  3873. sb_data_e2.common.p_func.vf_id = vfid;
  3874. sb_data_e2.common.p_func.vf_valid = vf_valid;
  3875. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  3876. sb_data_e2.common.same_igu_sb_1b = true;
  3877. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  3878. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  3879. hc_sm_p = sb_data_e2.common.state_machine;
  3880. sb_data_p = (u32 *)&sb_data_e2;
  3881. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  3882. } else {
  3883. memset(&sb_data_e1x, 0,
  3884. sizeof(struct hc_status_block_data_e1x));
  3885. sb_data_e1x.common.state = SB_ENABLED;
  3886. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  3887. sb_data_e1x.common.p_func.vf_id = 0xff;
  3888. sb_data_e1x.common.p_func.vf_valid = false;
  3889. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  3890. sb_data_e1x.common.same_igu_sb_1b = true;
  3891. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  3892. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  3893. hc_sm_p = sb_data_e1x.common.state_machine;
  3894. sb_data_p = (u32 *)&sb_data_e1x;
  3895. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  3896. }
  3897. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  3898. igu_sb_id, igu_seg_id);
  3899. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  3900. igu_sb_id, igu_seg_id);
  3901. DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
  3902. /* write indecies to HW */
  3903. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  3904. }
  3905. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  3906. u16 tx_usec, u16 rx_usec)
  3907. {
  3908. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, U_SB_ETH_RX_CQ_INDEX,
  3909. false, rx_usec);
  3910. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, C_SB_ETH_TX_CQ_INDEX,
  3911. false, tx_usec);
  3912. }
  3913. static void bnx2x_init_def_sb(struct bnx2x *bp)
  3914. {
  3915. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3916. dma_addr_t mapping = bp->def_status_blk_mapping;
  3917. int igu_sp_sb_index;
  3918. int igu_seg_id;
  3919. int port = BP_PORT(bp);
  3920. int func = BP_FUNC(bp);
  3921. int reg_offset;
  3922. u64 section;
  3923. int index;
  3924. struct hc_sp_status_block_data sp_sb_data;
  3925. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  3926. if (CHIP_INT_MODE_IS_BC(bp)) {
  3927. igu_sp_sb_index = DEF_SB_IGU_ID;
  3928. igu_seg_id = HC_SEG_ACCESS_DEF;
  3929. } else {
  3930. igu_sp_sb_index = bp->igu_dsb_id;
  3931. igu_seg_id = IGU_SEG_ACCESS_DEF;
  3932. }
  3933. /* ATTN */
  3934. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  3935. atten_status_block);
  3936. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  3937. bp->attn_state = 0;
  3938. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3939. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3940. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3941. int sindex;
  3942. /* take care of sig[0]..sig[4] */
  3943. for (sindex = 0; sindex < 4; sindex++)
  3944. bp->attn_group[index].sig[sindex] =
  3945. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  3946. if (!CHIP_IS_E1x(bp))
  3947. /*
  3948. * enable5 is separate from the rest of the registers,
  3949. * and therefore the address skip is 4
  3950. * and not 16 between the different groups
  3951. */
  3952. bp->attn_group[index].sig[4] = REG_RD(bp,
  3953. reg_offset + 0x10 + 0x4*index);
  3954. else
  3955. bp->attn_group[index].sig[4] = 0;
  3956. }
  3957. if (bp->common.int_block == INT_BLOCK_HC) {
  3958. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  3959. HC_REG_ATTN_MSG0_ADDR_L);
  3960. REG_WR(bp, reg_offset, U64_LO(section));
  3961. REG_WR(bp, reg_offset + 4, U64_HI(section));
  3962. } else if (!CHIP_IS_E1x(bp)) {
  3963. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  3964. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  3965. }
  3966. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  3967. sp_sb);
  3968. bnx2x_zero_sp_sb(bp);
  3969. sp_sb_data.state = SB_ENABLED;
  3970. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  3971. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  3972. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  3973. sp_sb_data.igu_seg_id = igu_seg_id;
  3974. sp_sb_data.p_func.pf_id = func;
  3975. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  3976. sp_sb_data.p_func.vf_id = 0xff;
  3977. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  3978. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  3979. }
  3980. void bnx2x_update_coalesce(struct bnx2x *bp)
  3981. {
  3982. int i;
  3983. for_each_eth_queue(bp, i)
  3984. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  3985. bp->tx_ticks, bp->rx_ticks);
  3986. }
  3987. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  3988. {
  3989. spin_lock_init(&bp->spq_lock);
  3990. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  3991. bp->spq_prod_idx = 0;
  3992. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  3993. bp->spq_prod_bd = bp->spq;
  3994. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  3995. }
  3996. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  3997. {
  3998. int i;
  3999. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4000. union event_ring_elem *elem =
  4001. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4002. elem->next_page.addr.hi =
  4003. cpu_to_le32(U64_HI(bp->eq_mapping +
  4004. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4005. elem->next_page.addr.lo =
  4006. cpu_to_le32(U64_LO(bp->eq_mapping +
  4007. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4008. }
  4009. bp->eq_cons = 0;
  4010. bp->eq_prod = NUM_EQ_DESC;
  4011. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4012. /* we want a warning message before it gets rought... */
  4013. atomic_set(&bp->eq_spq_left,
  4014. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4015. }
  4016. /* called with netif_addr_lock_bh() */
  4017. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4018. unsigned long rx_mode_flags,
  4019. unsigned long rx_accept_flags,
  4020. unsigned long tx_accept_flags,
  4021. unsigned long ramrod_flags)
  4022. {
  4023. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4024. int rc;
  4025. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4026. /* Prepare ramrod parameters */
  4027. ramrod_param.cid = 0;
  4028. ramrod_param.cl_id = cl_id;
  4029. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4030. ramrod_param.func_id = BP_FUNC(bp);
  4031. ramrod_param.pstate = &bp->sp_state;
  4032. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4033. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4034. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4035. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4036. ramrod_param.ramrod_flags = ramrod_flags;
  4037. ramrod_param.rx_mode_flags = rx_mode_flags;
  4038. ramrod_param.rx_accept_flags = rx_accept_flags;
  4039. ramrod_param.tx_accept_flags = tx_accept_flags;
  4040. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4041. if (rc < 0) {
  4042. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4043. return;
  4044. }
  4045. }
  4046. /* called with netif_addr_lock_bh() */
  4047. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4048. {
  4049. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4050. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4051. #ifdef BCM_CNIC
  4052. if (!NO_FCOE(bp))
  4053. /* Configure rx_mode of FCoE Queue */
  4054. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4055. #endif
  4056. switch (bp->rx_mode) {
  4057. case BNX2X_RX_MODE_NONE:
  4058. /*
  4059. * 'drop all' supersedes any accept flags that may have been
  4060. * passed to the function.
  4061. */
  4062. break;
  4063. case BNX2X_RX_MODE_NORMAL:
  4064. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4065. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4066. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4067. /* internal switching mode */
  4068. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4069. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4070. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4071. break;
  4072. case BNX2X_RX_MODE_ALLMULTI:
  4073. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4074. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4075. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4076. /* internal switching mode */
  4077. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4078. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4079. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4080. break;
  4081. case BNX2X_RX_MODE_PROMISC:
  4082. /* According to deffinition of SI mode, iface in promisc mode
  4083. * should receive matched and unmatched (in resolution of port)
  4084. * unicast packets.
  4085. */
  4086. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4087. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4088. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4089. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4090. /* internal switching mode */
  4091. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4092. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4093. if (IS_MF_SI(bp))
  4094. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4095. else
  4096. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4097. break;
  4098. default:
  4099. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4100. return;
  4101. }
  4102. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4103. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4104. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4105. }
  4106. __set_bit(RAMROD_RX, &ramrod_flags);
  4107. __set_bit(RAMROD_TX, &ramrod_flags);
  4108. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4109. tx_accept_flags, ramrod_flags);
  4110. }
  4111. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4112. {
  4113. int i;
  4114. if (IS_MF_SI(bp))
  4115. /*
  4116. * In switch independent mode, the TSTORM needs to accept
  4117. * packets that failed classification, since approximate match
  4118. * mac addresses aren't written to NIG LLH
  4119. */
  4120. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4121. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4122. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4123. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4124. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4125. /* Zero this manually as its initialization is
  4126. currently missing in the initTool */
  4127. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4128. REG_WR(bp, BAR_USTRORM_INTMEM +
  4129. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4130. if (!CHIP_IS_E1x(bp)) {
  4131. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4132. CHIP_INT_MODE_IS_BC(bp) ?
  4133. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4134. }
  4135. }
  4136. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4137. {
  4138. switch (load_code) {
  4139. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4140. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4141. bnx2x_init_internal_common(bp);
  4142. /* no break */
  4143. case FW_MSG_CODE_DRV_LOAD_PORT:
  4144. /* nothing to do */
  4145. /* no break */
  4146. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4147. /* internal memory per function is
  4148. initialized inside bnx2x_pf_init */
  4149. break;
  4150. default:
  4151. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4152. break;
  4153. }
  4154. }
  4155. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4156. {
  4157. return fp->bp->igu_base_sb + fp->index + CNIC_CONTEXT_USE;
  4158. }
  4159. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4160. {
  4161. return fp->bp->base_fw_ndsb + fp->index + CNIC_CONTEXT_USE;
  4162. }
  4163. static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4164. {
  4165. if (CHIP_IS_E1x(fp->bp))
  4166. return BP_L_ID(fp->bp) + fp->index;
  4167. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4168. return bnx2x_fp_igu_sb_id(fp);
  4169. }
  4170. static void bnx2x_init_fp(struct bnx2x *bp, int fp_idx)
  4171. {
  4172. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4173. unsigned long q_type = 0;
  4174. fp->cid = fp_idx;
  4175. fp->cl_id = bnx2x_fp_cl_id(fp);
  4176. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4177. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4178. /* qZone id equals to FW (per path) client id */
  4179. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4180. /* init shortcut */
  4181. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4182. /* Setup SB indicies */
  4183. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4184. fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
  4185. /* Configure Queue State object */
  4186. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4187. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4188. bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, fp->cid, BP_FUNC(bp),
  4189. bnx2x_sp(bp, q_rdata), bnx2x_sp_mapping(bp, q_rdata),
  4190. q_type);
  4191. /**
  4192. * Configure classification DBs: Always enable Tx switching
  4193. */
  4194. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4195. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
  4196. "cl_id %d fw_sb %d igu_sb %d\n",
  4197. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4198. fp->igu_sb_id);
  4199. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4200. fp->fw_sb_id, fp->igu_sb_id);
  4201. bnx2x_update_fpsb_idx(fp);
  4202. }
  4203. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4204. {
  4205. int i;
  4206. for_each_eth_queue(bp, i)
  4207. bnx2x_init_fp(bp, i);
  4208. #ifdef BCM_CNIC
  4209. if (!NO_FCOE(bp))
  4210. bnx2x_init_fcoe_fp(bp);
  4211. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4212. BNX2X_VF_ID_INVALID, false,
  4213. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4214. #endif
  4215. /* Initialize MOD_ABS interrupts */
  4216. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4217. bp->common.shmem_base, bp->common.shmem2_base,
  4218. BP_PORT(bp));
  4219. /* ensure status block indices were read */
  4220. rmb();
  4221. bnx2x_init_def_sb(bp);
  4222. bnx2x_update_dsb_idx(bp);
  4223. bnx2x_init_rx_rings(bp);
  4224. bnx2x_init_tx_rings(bp);
  4225. bnx2x_init_sp_ring(bp);
  4226. bnx2x_init_eq_ring(bp);
  4227. bnx2x_init_internal(bp, load_code);
  4228. bnx2x_pf_init(bp);
  4229. bnx2x_stats_init(bp);
  4230. /* flush all before enabling interrupts */
  4231. mb();
  4232. mmiowb();
  4233. bnx2x_int_enable(bp);
  4234. /* Check for SPIO5 */
  4235. bnx2x_attn_int_deasserted0(bp,
  4236. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4237. AEU_INPUTS_ATTN_BITS_SPIO5);
  4238. }
  4239. /* end of nic init */
  4240. /*
  4241. * gzip service functions
  4242. */
  4243. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4244. {
  4245. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4246. &bp->gunzip_mapping, GFP_KERNEL);
  4247. if (bp->gunzip_buf == NULL)
  4248. goto gunzip_nomem1;
  4249. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4250. if (bp->strm == NULL)
  4251. goto gunzip_nomem2;
  4252. bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
  4253. GFP_KERNEL);
  4254. if (bp->strm->workspace == NULL)
  4255. goto gunzip_nomem3;
  4256. return 0;
  4257. gunzip_nomem3:
  4258. kfree(bp->strm);
  4259. bp->strm = NULL;
  4260. gunzip_nomem2:
  4261. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4262. bp->gunzip_mapping);
  4263. bp->gunzip_buf = NULL;
  4264. gunzip_nomem1:
  4265. netdev_err(bp->dev, "Cannot allocate firmware buffer for"
  4266. " un-compression\n");
  4267. return -ENOMEM;
  4268. }
  4269. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4270. {
  4271. if (bp->strm) {
  4272. kfree(bp->strm->workspace);
  4273. kfree(bp->strm);
  4274. bp->strm = NULL;
  4275. }
  4276. if (bp->gunzip_buf) {
  4277. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4278. bp->gunzip_mapping);
  4279. bp->gunzip_buf = NULL;
  4280. }
  4281. }
  4282. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4283. {
  4284. int n, rc;
  4285. /* check gzip header */
  4286. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4287. BNX2X_ERR("Bad gzip header\n");
  4288. return -EINVAL;
  4289. }
  4290. n = 10;
  4291. #define FNAME 0x8
  4292. if (zbuf[3] & FNAME)
  4293. while ((zbuf[n++] != 0) && (n < len));
  4294. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4295. bp->strm->avail_in = len - n;
  4296. bp->strm->next_out = bp->gunzip_buf;
  4297. bp->strm->avail_out = FW_BUF_SIZE;
  4298. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4299. if (rc != Z_OK)
  4300. return rc;
  4301. rc = zlib_inflate(bp->strm, Z_FINISH);
  4302. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4303. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4304. bp->strm->msg);
  4305. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4306. if (bp->gunzip_outlen & 0x3)
  4307. netdev_err(bp->dev, "Firmware decompression error:"
  4308. " gunzip_outlen (%d) not aligned\n",
  4309. bp->gunzip_outlen);
  4310. bp->gunzip_outlen >>= 2;
  4311. zlib_inflateEnd(bp->strm);
  4312. if (rc == Z_STREAM_END)
  4313. return 0;
  4314. return rc;
  4315. }
  4316. /* nic load/unload */
  4317. /*
  4318. * General service functions
  4319. */
  4320. /* send a NIG loopback debug packet */
  4321. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4322. {
  4323. u32 wb_write[3];
  4324. /* Ethernet source and destination addresses */
  4325. wb_write[0] = 0x55555555;
  4326. wb_write[1] = 0x55555555;
  4327. wb_write[2] = 0x20; /* SOP */
  4328. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4329. /* NON-IP protocol */
  4330. wb_write[0] = 0x09000000;
  4331. wb_write[1] = 0x55555555;
  4332. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4333. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4334. }
  4335. /* some of the internal memories
  4336. * are not directly readable from the driver
  4337. * to test them we send debug packets
  4338. */
  4339. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4340. {
  4341. int factor;
  4342. int count, i;
  4343. u32 val = 0;
  4344. if (CHIP_REV_IS_FPGA(bp))
  4345. factor = 120;
  4346. else if (CHIP_REV_IS_EMUL(bp))
  4347. factor = 200;
  4348. else
  4349. factor = 1;
  4350. /* Disable inputs of parser neighbor blocks */
  4351. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4352. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4353. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4354. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4355. /* Write 0 to parser credits for CFC search request */
  4356. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4357. /* send Ethernet packet */
  4358. bnx2x_lb_pckt(bp);
  4359. /* TODO do i reset NIG statistic? */
  4360. /* Wait until NIG register shows 1 packet of size 0x10 */
  4361. count = 1000 * factor;
  4362. while (count) {
  4363. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4364. val = *bnx2x_sp(bp, wb_data[0]);
  4365. if (val == 0x10)
  4366. break;
  4367. msleep(10);
  4368. count--;
  4369. }
  4370. if (val != 0x10) {
  4371. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4372. return -1;
  4373. }
  4374. /* Wait until PRS register shows 1 packet */
  4375. count = 1000 * factor;
  4376. while (count) {
  4377. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4378. if (val == 1)
  4379. break;
  4380. msleep(10);
  4381. count--;
  4382. }
  4383. if (val != 0x1) {
  4384. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4385. return -2;
  4386. }
  4387. /* Reset and init BRB, PRS */
  4388. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4389. msleep(50);
  4390. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4391. msleep(50);
  4392. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4393. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4394. DP(NETIF_MSG_HW, "part2\n");
  4395. /* Disable inputs of parser neighbor blocks */
  4396. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4397. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4398. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4399. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4400. /* Write 0 to parser credits for CFC search request */
  4401. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4402. /* send 10 Ethernet packets */
  4403. for (i = 0; i < 10; i++)
  4404. bnx2x_lb_pckt(bp);
  4405. /* Wait until NIG register shows 10 + 1
  4406. packets of size 11*0x10 = 0xb0 */
  4407. count = 1000 * factor;
  4408. while (count) {
  4409. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4410. val = *bnx2x_sp(bp, wb_data[0]);
  4411. if (val == 0xb0)
  4412. break;
  4413. msleep(10);
  4414. count--;
  4415. }
  4416. if (val != 0xb0) {
  4417. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4418. return -3;
  4419. }
  4420. /* Wait until PRS register shows 2 packets */
  4421. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4422. if (val != 2)
  4423. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4424. /* Write 1 to parser credits for CFC search request */
  4425. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4426. /* Wait until PRS register shows 3 packets */
  4427. msleep(10 * factor);
  4428. /* Wait until NIG register shows 1 packet of size 0x10 */
  4429. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4430. if (val != 3)
  4431. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4432. /* clear NIG EOP FIFO */
  4433. for (i = 0; i < 11; i++)
  4434. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4435. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  4436. if (val != 1) {
  4437. BNX2X_ERR("clear of NIG failed\n");
  4438. return -4;
  4439. }
  4440. /* Reset and init BRB, PRS, NIG */
  4441. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4442. msleep(50);
  4443. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4444. msleep(50);
  4445. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4446. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4447. #ifndef BCM_CNIC
  4448. /* set NIC mode */
  4449. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4450. #endif
  4451. /* Enable inputs of parser neighbor blocks */
  4452. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  4453. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  4454. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  4455. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  4456. DP(NETIF_MSG_HW, "done\n");
  4457. return 0; /* OK */
  4458. }
  4459. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  4460. {
  4461. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4462. if (!CHIP_IS_E1x(bp))
  4463. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  4464. else
  4465. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  4466. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4467. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4468. /*
  4469. * mask read length error interrupts in brb for parser
  4470. * (parsing unit and 'checksum and crc' unit)
  4471. * these errors are legal (PU reads fixed length and CAC can cause
  4472. * read length error on truncated packets)
  4473. */
  4474. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  4475. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  4476. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  4477. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  4478. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  4479. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  4480. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  4481. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  4482. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  4483. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  4484. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  4485. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  4486. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  4487. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  4488. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  4489. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  4490. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  4491. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  4492. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  4493. if (CHIP_REV_IS_FPGA(bp))
  4494. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  4495. else if (!CHIP_IS_E1x(bp))
  4496. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  4497. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  4498. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  4499. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  4500. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  4501. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  4502. else
  4503. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  4504. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  4505. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  4506. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  4507. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  4508. if (!CHIP_IS_E1x(bp))
  4509. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  4510. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  4511. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  4512. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  4513. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  4514. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  4515. }
  4516. static void bnx2x_reset_common(struct bnx2x *bp)
  4517. {
  4518. u32 val = 0x1400;
  4519. /* reset_common */
  4520. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4521. 0xd3ffff7f);
  4522. if (CHIP_IS_E3(bp)) {
  4523. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4524. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4525. }
  4526. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  4527. }
  4528. static void bnx2x_setup_dmae(struct bnx2x *bp)
  4529. {
  4530. bp->dmae_ready = 0;
  4531. spin_lock_init(&bp->dmae_lock);
  4532. }
  4533. static void bnx2x_init_pxp(struct bnx2x *bp)
  4534. {
  4535. u16 devctl;
  4536. int r_order, w_order;
  4537. pci_read_config_word(bp->pdev,
  4538. bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
  4539. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  4540. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  4541. if (bp->mrrs == -1)
  4542. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  4543. else {
  4544. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  4545. r_order = bp->mrrs;
  4546. }
  4547. bnx2x_init_pxp_arb(bp, r_order, w_order);
  4548. }
  4549. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  4550. {
  4551. int is_required;
  4552. u32 val;
  4553. int port;
  4554. if (BP_NOMCP(bp))
  4555. return;
  4556. is_required = 0;
  4557. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  4558. SHARED_HW_CFG_FAN_FAILURE_MASK;
  4559. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  4560. is_required = 1;
  4561. /*
  4562. * The fan failure mechanism is usually related to the PHY type since
  4563. * the power consumption of the board is affected by the PHY. Currently,
  4564. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  4565. */
  4566. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  4567. for (port = PORT_0; port < PORT_MAX; port++) {
  4568. is_required |=
  4569. bnx2x_fan_failure_det_req(
  4570. bp,
  4571. bp->common.shmem_base,
  4572. bp->common.shmem2_base,
  4573. port);
  4574. }
  4575. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  4576. if (is_required == 0)
  4577. return;
  4578. /* Fan failure is indicated by SPIO 5 */
  4579. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  4580. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  4581. /* set to active low mode */
  4582. val = REG_RD(bp, MISC_REG_SPIO_INT);
  4583. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  4584. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  4585. REG_WR(bp, MISC_REG_SPIO_INT, val);
  4586. /* enable interrupt to signal the IGU */
  4587. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  4588. val |= (1 << MISC_REGISTERS_SPIO_5);
  4589. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  4590. }
  4591. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  4592. {
  4593. u32 offset = 0;
  4594. if (CHIP_IS_E1(bp))
  4595. return;
  4596. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  4597. return;
  4598. switch (BP_ABS_FUNC(bp)) {
  4599. case 0:
  4600. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  4601. break;
  4602. case 1:
  4603. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  4604. break;
  4605. case 2:
  4606. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  4607. break;
  4608. case 3:
  4609. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  4610. break;
  4611. case 4:
  4612. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  4613. break;
  4614. case 5:
  4615. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  4616. break;
  4617. case 6:
  4618. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  4619. break;
  4620. case 7:
  4621. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  4622. break;
  4623. default:
  4624. return;
  4625. }
  4626. REG_WR(bp, offset, pretend_func_num);
  4627. REG_RD(bp, offset);
  4628. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  4629. }
  4630. void bnx2x_pf_disable(struct bnx2x *bp)
  4631. {
  4632. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  4633. val &= ~IGU_PF_CONF_FUNC_EN;
  4634. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  4635. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4636. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  4637. }
  4638. static inline void bnx2x__common_init_phy(struct bnx2x *bp)
  4639. {
  4640. u32 shmem_base[2], shmem2_base[2];
  4641. shmem_base[0] = bp->common.shmem_base;
  4642. shmem2_base[0] = bp->common.shmem2_base;
  4643. if (!CHIP_IS_E1x(bp)) {
  4644. shmem_base[1] =
  4645. SHMEM2_RD(bp, other_shmem_base_addr);
  4646. shmem2_base[1] =
  4647. SHMEM2_RD(bp, other_shmem2_base_addr);
  4648. }
  4649. bnx2x_acquire_phy_lock(bp);
  4650. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  4651. bp->common.chip_id);
  4652. bnx2x_release_phy_lock(bp);
  4653. }
  4654. /**
  4655. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  4656. *
  4657. * @bp: driver handle
  4658. */
  4659. static int bnx2x_init_hw_common(struct bnx2x *bp)
  4660. {
  4661. u32 val;
  4662. DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
  4663. bnx2x_reset_common(bp);
  4664. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  4665. val = 0xfffc;
  4666. if (CHIP_IS_E3(bp)) {
  4667. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4668. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4669. }
  4670. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  4671. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  4672. if (!CHIP_IS_E1x(bp)) {
  4673. u8 abs_func_id;
  4674. /**
  4675. * 4-port mode or 2-port mode we need to turn of master-enable
  4676. * for everyone, after that, turn it back on for self.
  4677. * so, we disregard multi-function or not, and always disable
  4678. * for all functions on the given path, this means 0,2,4,6 for
  4679. * path 0 and 1,3,5,7 for path 1
  4680. */
  4681. for (abs_func_id = BP_PATH(bp);
  4682. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  4683. if (abs_func_id == BP_ABS_FUNC(bp)) {
  4684. REG_WR(bp,
  4685. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  4686. 1);
  4687. continue;
  4688. }
  4689. bnx2x_pretend_func(bp, abs_func_id);
  4690. /* clear pf enable */
  4691. bnx2x_pf_disable(bp);
  4692. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  4693. }
  4694. }
  4695. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  4696. if (CHIP_IS_E1(bp)) {
  4697. /* enable HW interrupt from PXP on USDM overflow
  4698. bit 16 on INT_MASK_0 */
  4699. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4700. }
  4701. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  4702. bnx2x_init_pxp(bp);
  4703. #ifdef __BIG_ENDIAN
  4704. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  4705. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  4706. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  4707. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  4708. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  4709. /* make sure this value is 0 */
  4710. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  4711. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  4712. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  4713. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  4714. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  4715. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  4716. #endif
  4717. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  4718. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  4719. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  4720. /* let the HW do it's magic ... */
  4721. msleep(100);
  4722. /* finish PXP init */
  4723. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  4724. if (val != 1) {
  4725. BNX2X_ERR("PXP2 CFG failed\n");
  4726. return -EBUSY;
  4727. }
  4728. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  4729. if (val != 1) {
  4730. BNX2X_ERR("PXP2 RD_INIT failed\n");
  4731. return -EBUSY;
  4732. }
  4733. /* Timers bug workaround E2 only. We need to set the entire ILT to
  4734. * have entries with value "0" and valid bit on.
  4735. * This needs to be done by the first PF that is loaded in a path
  4736. * (i.e. common phase)
  4737. */
  4738. if (!CHIP_IS_E1x(bp)) {
  4739. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  4740. * (i.e. vnic3) to start even if it is marked as "scan-off".
  4741. * This occurs when a different function (func2,3) is being marked
  4742. * as "scan-off". Real-life scenario for example: if a driver is being
  4743. * load-unloaded while func6,7 are down. This will cause the timer to access
  4744. * the ilt, translate to a logical address and send a request to read/write.
  4745. * Since the ilt for the function that is down is not valid, this will cause
  4746. * a translation error which is unrecoverable.
  4747. * The Workaround is intended to make sure that when this happens nothing fatal
  4748. * will occur. The workaround:
  4749. * 1. First PF driver which loads on a path will:
  4750. * a. After taking the chip out of reset, by using pretend,
  4751. * it will write "0" to the following registers of
  4752. * the other vnics.
  4753. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4754. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  4755. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  4756. * And for itself it will write '1' to
  4757. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  4758. * dmae-operations (writing to pram for example.)
  4759. * note: can be done for only function 6,7 but cleaner this
  4760. * way.
  4761. * b. Write zero+valid to the entire ILT.
  4762. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  4763. * VNIC3 (of that port). The range allocated will be the
  4764. * entire ILT. This is needed to prevent ILT range error.
  4765. * 2. Any PF driver load flow:
  4766. * a. ILT update with the physical addresses of the allocated
  4767. * logical pages.
  4768. * b. Wait 20msec. - note that this timeout is needed to make
  4769. * sure there are no requests in one of the PXP internal
  4770. * queues with "old" ILT addresses.
  4771. * c. PF enable in the PGLC.
  4772. * d. Clear the was_error of the PF in the PGLC. (could have
  4773. * occured while driver was down)
  4774. * e. PF enable in the CFC (WEAK + STRONG)
  4775. * f. Timers scan enable
  4776. * 3. PF driver unload flow:
  4777. * a. Clear the Timers scan_en.
  4778. * b. Polling for scan_on=0 for that PF.
  4779. * c. Clear the PF enable bit in the PXP.
  4780. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  4781. * e. Write zero+valid to all ILT entries (The valid bit must
  4782. * stay set)
  4783. * f. If this is VNIC 3 of a port then also init
  4784. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  4785. * to the last enrty in the ILT.
  4786. *
  4787. * Notes:
  4788. * Currently the PF error in the PGLC is non recoverable.
  4789. * In the future the there will be a recovery routine for this error.
  4790. * Currently attention is masked.
  4791. * Having an MCP lock on the load/unload process does not guarantee that
  4792. * there is no Timer disable during Func6/7 enable. This is because the
  4793. * Timers scan is currently being cleared by the MCP on FLR.
  4794. * Step 2.d can be done only for PF6/7 and the driver can also check if
  4795. * there is error before clearing it. But the flow above is simpler and
  4796. * more general.
  4797. * All ILT entries are written by zero+valid and not just PF6/7
  4798. * ILT entries since in the future the ILT entries allocation for
  4799. * PF-s might be dynamic.
  4800. */
  4801. struct ilt_client_info ilt_cli;
  4802. struct bnx2x_ilt ilt;
  4803. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  4804. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  4805. /* initialize dummy TM client */
  4806. ilt_cli.start = 0;
  4807. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  4808. ilt_cli.client_num = ILT_CLIENT_TM;
  4809. /* Step 1: set zeroes to all ilt page entries with valid bit on
  4810. * Step 2: set the timers first/last ilt entry to point
  4811. * to the entire range to prevent ILT range error for 3rd/4th
  4812. * vnic (this code assumes existance of the vnic)
  4813. *
  4814. * both steps performed by call to bnx2x_ilt_client_init_op()
  4815. * with dummy TM client
  4816. *
  4817. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  4818. * and his brother are split registers
  4819. */
  4820. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  4821. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  4822. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  4823. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  4824. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  4825. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  4826. }
  4827. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  4828. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  4829. if (!CHIP_IS_E1x(bp)) {
  4830. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  4831. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  4832. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  4833. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  4834. /* let the HW do it's magic ... */
  4835. do {
  4836. msleep(200);
  4837. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  4838. } while (factor-- && (val != 1));
  4839. if (val != 1) {
  4840. BNX2X_ERR("ATC_INIT failed\n");
  4841. return -EBUSY;
  4842. }
  4843. }
  4844. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  4845. /* clean the DMAE memory */
  4846. bp->dmae_ready = 1;
  4847. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  4848. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  4849. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  4850. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  4851. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  4852. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  4853. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  4854. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  4855. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  4856. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  4857. /* QM queues pointers table */
  4858. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  4859. /* soft reset pulse */
  4860. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  4861. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  4862. #ifdef BCM_CNIC
  4863. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  4864. #endif
  4865. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  4866. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  4867. if (!CHIP_REV_IS_SLOW(bp))
  4868. /* enable hw interrupt from doorbell Q */
  4869. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4870. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4871. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4872. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  4873. if (!CHIP_IS_E1(bp))
  4874. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  4875. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
  4876. /* Bit-map indicating which L2 hdrs may appear
  4877. * after the basic Ethernet header
  4878. */
  4879. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  4880. bp->path_has_ovlan ? 7 : 6);
  4881. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  4882. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  4883. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  4884. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  4885. if (!CHIP_IS_E1x(bp)) {
  4886. /* reset VFC memories */
  4887. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  4888. VFC_MEMORIES_RST_REG_CAM_RST |
  4889. VFC_MEMORIES_RST_REG_RAM_RST);
  4890. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  4891. VFC_MEMORIES_RST_REG_CAM_RST |
  4892. VFC_MEMORIES_RST_REG_RAM_RST);
  4893. msleep(20);
  4894. }
  4895. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  4896. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  4897. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  4898. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  4899. /* sync semi rtc */
  4900. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4901. 0x80000000);
  4902. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  4903. 0x80000000);
  4904. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  4905. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  4906. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  4907. if (!CHIP_IS_E1x(bp))
  4908. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  4909. bp->path_has_ovlan ? 7 : 6);
  4910. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  4911. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  4912. #ifdef BCM_CNIC
  4913. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  4914. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  4915. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  4916. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  4917. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  4918. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  4919. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  4920. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  4921. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  4922. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  4923. #endif
  4924. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  4925. if (sizeof(union cdu_context) != 1024)
  4926. /* we currently assume that a context is 1024 bytes */
  4927. dev_alert(&bp->pdev->dev, "please adjust the size "
  4928. "of cdu_context(%ld)\n",
  4929. (long)sizeof(union cdu_context));
  4930. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  4931. val = (4 << 24) + (0 << 12) + 1024;
  4932. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  4933. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  4934. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  4935. /* enable context validation interrupt from CFC */
  4936. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4937. /* set the thresholds to prevent CFC/CDU race */
  4938. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  4939. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  4940. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  4941. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  4942. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  4943. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  4944. /* Reset PCIE errors for debug */
  4945. REG_WR(bp, 0x2814, 0xffffffff);
  4946. REG_WR(bp, 0x3820, 0xffffffff);
  4947. if (!CHIP_IS_E1x(bp)) {
  4948. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  4949. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  4950. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  4951. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  4952. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  4953. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  4954. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  4955. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  4956. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  4957. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  4958. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  4959. }
  4960. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  4961. if (!CHIP_IS_E1(bp)) {
  4962. /* in E3 this done in per-port section */
  4963. if (!CHIP_IS_E3(bp))
  4964. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  4965. }
  4966. if (CHIP_IS_E1H(bp))
  4967. /* not applicable for E2 (and above ...) */
  4968. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  4969. if (CHIP_REV_IS_SLOW(bp))
  4970. msleep(200);
  4971. /* finish CFC init */
  4972. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  4973. if (val != 1) {
  4974. BNX2X_ERR("CFC LL_INIT failed\n");
  4975. return -EBUSY;
  4976. }
  4977. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  4978. if (val != 1) {
  4979. BNX2X_ERR("CFC AC_INIT failed\n");
  4980. return -EBUSY;
  4981. }
  4982. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  4983. if (val != 1) {
  4984. BNX2X_ERR("CFC CAM_INIT failed\n");
  4985. return -EBUSY;
  4986. }
  4987. REG_WR(bp, CFC_REG_DEBUG0, 0);
  4988. if (CHIP_IS_E1(bp)) {
  4989. /* read NIG statistic
  4990. to see if this is our first up since powerup */
  4991. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4992. val = *bnx2x_sp(bp, wb_data[0]);
  4993. /* do internal memory self test */
  4994. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  4995. BNX2X_ERR("internal mem self test failed\n");
  4996. return -EBUSY;
  4997. }
  4998. }
  4999. bnx2x_setup_fan_failure_detection(bp);
  5000. /* clear PXP2 attentions */
  5001. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5002. bnx2x_enable_blocks_attention(bp);
  5003. bnx2x_enable_blocks_parity(bp);
  5004. if (!BP_NOMCP(bp)) {
  5005. if (CHIP_IS_E1x(bp))
  5006. bnx2x__common_init_phy(bp);
  5007. } else
  5008. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5009. return 0;
  5010. }
  5011. /**
  5012. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5013. *
  5014. * @bp: driver handle
  5015. */
  5016. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5017. {
  5018. int rc = bnx2x_init_hw_common(bp);
  5019. if (rc)
  5020. return rc;
  5021. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5022. if (!BP_NOMCP(bp))
  5023. bnx2x__common_init_phy(bp);
  5024. return 0;
  5025. }
  5026. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5027. {
  5028. int port = BP_PORT(bp);
  5029. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5030. u32 low, high;
  5031. u32 val;
  5032. bnx2x__link_reset(bp);
  5033. DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
  5034. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5035. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5036. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5037. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5038. /* Timers bug workaround: disables the pf_master bit in pglue at
  5039. * common phase, we need to enable it here before any dmae access are
  5040. * attempted. Therefore we manually added the enable-master to the
  5041. * port phase (it also happens in the function phase)
  5042. */
  5043. if (!CHIP_IS_E1x(bp))
  5044. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5045. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5046. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5047. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5048. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5049. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5050. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5051. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5052. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5053. /* QM cid (connection) count */
  5054. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5055. #ifdef BCM_CNIC
  5056. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5057. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5058. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5059. #endif
  5060. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5061. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5062. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5063. if (IS_MF(bp))
  5064. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5065. else if (bp->dev->mtu > 4096) {
  5066. if (bp->flags & ONE_PORT_FLAG)
  5067. low = 160;
  5068. else {
  5069. val = bp->dev->mtu;
  5070. /* (24*1024 + val*4)/256 */
  5071. low = 96 + (val/64) +
  5072. ((val % 64) ? 1 : 0);
  5073. }
  5074. } else
  5075. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5076. high = low + 56; /* 14*1024/256 */
  5077. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5078. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5079. }
  5080. if (CHIP_MODE_IS_4_PORT(bp))
  5081. REG_WR(bp, (BP_PORT(bp) ?
  5082. BRB1_REG_MAC_GUARANTIED_1 :
  5083. BRB1_REG_MAC_GUARANTIED_0), 40);
  5084. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5085. if (CHIP_IS_E3B0(bp))
  5086. /* Ovlan exists only if we are in multi-function +
  5087. * switch-dependent mode, in switch-independent there
  5088. * is no ovlan headers
  5089. */
  5090. REG_WR(bp, BP_PORT(bp) ?
  5091. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5092. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5093. (bp->path_has_ovlan ? 7 : 6));
  5094. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5095. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5096. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5097. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5098. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5099. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5100. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5101. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5102. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5103. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5104. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5105. if (CHIP_IS_E1x(bp)) {
  5106. /* configure PBF to work without PAUSE mtu 9000 */
  5107. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5108. /* update threshold */
  5109. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5110. /* update init credit */
  5111. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5112. /* probe changes */
  5113. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5114. udelay(50);
  5115. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5116. }
  5117. #ifdef BCM_CNIC
  5118. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5119. #endif
  5120. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5121. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5122. if (CHIP_IS_E1(bp)) {
  5123. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5124. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5125. }
  5126. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5127. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5128. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5129. /* init aeu_mask_attn_func_0/1:
  5130. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5131. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5132. * bits 4-7 are used for "per vn group attention" */
  5133. val = IS_MF(bp) ? 0xF7 : 0x7;
  5134. /* Enable DCBX attention for all but E1 */
  5135. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5136. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5137. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5138. if (!CHIP_IS_E1x(bp)) {
  5139. /* Bit-map indicating which L2 hdrs may appear after the
  5140. * basic Ethernet header
  5141. */
  5142. REG_WR(bp, BP_PORT(bp) ?
  5143. NIG_REG_P1_HDRS_AFTER_BASIC :
  5144. NIG_REG_P0_HDRS_AFTER_BASIC,
  5145. IS_MF_SD(bp) ? 7 : 6);
  5146. if (CHIP_IS_E3(bp))
  5147. REG_WR(bp, BP_PORT(bp) ?
  5148. NIG_REG_LLH1_MF_MODE :
  5149. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5150. }
  5151. if (!CHIP_IS_E3(bp))
  5152. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5153. if (!CHIP_IS_E1(bp)) {
  5154. /* 0x2 disable mf_ov, 0x1 enable */
  5155. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5156. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5157. if (!CHIP_IS_E1x(bp)) {
  5158. val = 0;
  5159. switch (bp->mf_mode) {
  5160. case MULTI_FUNCTION_SD:
  5161. val = 1;
  5162. break;
  5163. case MULTI_FUNCTION_SI:
  5164. val = 2;
  5165. break;
  5166. }
  5167. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5168. NIG_REG_LLH0_CLS_TYPE), val);
  5169. }
  5170. {
  5171. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5172. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5173. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5174. }
  5175. }
  5176. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5177. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5178. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5179. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5180. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5181. val = REG_RD(bp, reg_addr);
  5182. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5183. REG_WR(bp, reg_addr, val);
  5184. }
  5185. return 0;
  5186. }
  5187. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5188. {
  5189. int reg;
  5190. if (CHIP_IS_E1(bp))
  5191. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5192. else
  5193. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5194. bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
  5195. }
  5196. static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5197. {
  5198. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5199. }
  5200. static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5201. {
  5202. u32 i, base = FUNC_ILT_BASE(func);
  5203. for (i = base; i < base + ILT_PER_FUNC; i++)
  5204. bnx2x_ilt_wr(bp, i, 0);
  5205. }
  5206. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5207. {
  5208. int port = BP_PORT(bp);
  5209. int func = BP_FUNC(bp);
  5210. int init_phase = PHASE_PF0 + func;
  5211. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5212. u16 cdu_ilt_start;
  5213. u32 addr, val;
  5214. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5215. int i, main_mem_width;
  5216. DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
  5217. /* FLR cleanup - hmmm */
  5218. if (!CHIP_IS_E1x(bp))
  5219. bnx2x_pf_flr_clnup(bp);
  5220. /* set MSI reconfigure capability */
  5221. if (bp->common.int_block == INT_BLOCK_HC) {
  5222. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5223. val = REG_RD(bp, addr);
  5224. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5225. REG_WR(bp, addr, val);
  5226. }
  5227. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5228. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5229. ilt = BP_ILT(bp);
  5230. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5231. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5232. ilt->lines[cdu_ilt_start + i].page =
  5233. bp->context.vcxt + (ILT_PAGE_CIDS * i);
  5234. ilt->lines[cdu_ilt_start + i].page_mapping =
  5235. bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
  5236. /* cdu ilt pages are allocated manually so there's no need to
  5237. set the size */
  5238. }
  5239. bnx2x_ilt_init_op(bp, INITOP_SET);
  5240. #ifdef BCM_CNIC
  5241. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5242. /* T1 hash bits value determines the T1 number of entries */
  5243. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5244. #endif
  5245. #ifndef BCM_CNIC
  5246. /* set NIC mode */
  5247. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5248. #endif /* BCM_CNIC */
  5249. if (!CHIP_IS_E1x(bp)) {
  5250. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5251. /* Turn on a single ISR mode in IGU if driver is going to use
  5252. * INT#x or MSI
  5253. */
  5254. if (!(bp->flags & USING_MSIX_FLAG))
  5255. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5256. /*
  5257. * Timers workaround bug: function init part.
  5258. * Need to wait 20msec after initializing ILT,
  5259. * needed to make sure there are no requests in
  5260. * one of the PXP internal queues with "old" ILT addresses
  5261. */
  5262. msleep(20);
  5263. /*
  5264. * Master enable - Due to WB DMAE writes performed before this
  5265. * register is re-initialized as part of the regular function
  5266. * init
  5267. */
  5268. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5269. /* Enable the function in IGU */
  5270. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5271. }
  5272. bp->dmae_ready = 1;
  5273. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5274. if (!CHIP_IS_E1x(bp))
  5275. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5276. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5277. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5278. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5279. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5280. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5281. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5282. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5283. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5284. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5285. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5286. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5287. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5288. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5289. if (!CHIP_IS_E1x(bp))
  5290. REG_WR(bp, QM_REG_PF_EN, 1);
  5291. if (!CHIP_IS_E1x(bp)) {
  5292. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5293. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5294. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5295. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5296. }
  5297. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5298. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5299. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5300. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5301. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5302. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5303. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5304. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5305. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5306. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5307. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5308. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5309. if (!CHIP_IS_E1x(bp))
  5310. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5311. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5312. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5313. if (!CHIP_IS_E1x(bp))
  5314. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5315. if (IS_MF(bp)) {
  5316. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5317. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5318. }
  5319. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5320. /* HC init per function */
  5321. if (bp->common.int_block == INT_BLOCK_HC) {
  5322. if (CHIP_IS_E1H(bp)) {
  5323. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5324. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5325. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5326. }
  5327. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5328. } else {
  5329. int num_segs, sb_idx, prod_offset;
  5330. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5331. if (!CHIP_IS_E1x(bp)) {
  5332. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  5333. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  5334. }
  5335. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5336. if (!CHIP_IS_E1x(bp)) {
  5337. int dsb_idx = 0;
  5338. /**
  5339. * Producer memory:
  5340. * E2 mode: address 0-135 match to the mapping memory;
  5341. * 136 - PF0 default prod; 137 - PF1 default prod;
  5342. * 138 - PF2 default prod; 139 - PF3 default prod;
  5343. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  5344. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  5345. * 144-147 reserved.
  5346. *
  5347. * E1.5 mode - In backward compatible mode;
  5348. * for non default SB; each even line in the memory
  5349. * holds the U producer and each odd line hold
  5350. * the C producer. The first 128 producers are for
  5351. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  5352. * producers are for the DSB for each PF.
  5353. * Each PF has five segments: (the order inside each
  5354. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  5355. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  5356. * 144-147 attn prods;
  5357. */
  5358. /* non-default-status-blocks */
  5359. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5360. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  5361. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  5362. prod_offset = (bp->igu_base_sb + sb_idx) *
  5363. num_segs;
  5364. for (i = 0; i < num_segs; i++) {
  5365. addr = IGU_REG_PROD_CONS_MEMORY +
  5366. (prod_offset + i) * 4;
  5367. REG_WR(bp, addr, 0);
  5368. }
  5369. /* send consumer update with value 0 */
  5370. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  5371. USTORM_ID, 0, IGU_INT_NOP, 1);
  5372. bnx2x_igu_clear_sb(bp,
  5373. bp->igu_base_sb + sb_idx);
  5374. }
  5375. /* default-status-blocks */
  5376. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5377. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  5378. if (CHIP_MODE_IS_4_PORT(bp))
  5379. dsb_idx = BP_FUNC(bp);
  5380. else
  5381. dsb_idx = BP_E1HVN(bp);
  5382. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  5383. IGU_BC_BASE_DSB_PROD + dsb_idx :
  5384. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  5385. for (i = 0; i < (num_segs * E1HVN_MAX);
  5386. i += E1HVN_MAX) {
  5387. addr = IGU_REG_PROD_CONS_MEMORY +
  5388. (prod_offset + i)*4;
  5389. REG_WR(bp, addr, 0);
  5390. }
  5391. /* send consumer update with 0 */
  5392. if (CHIP_INT_MODE_IS_BC(bp)) {
  5393. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5394. USTORM_ID, 0, IGU_INT_NOP, 1);
  5395. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5396. CSTORM_ID, 0, IGU_INT_NOP, 1);
  5397. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5398. XSTORM_ID, 0, IGU_INT_NOP, 1);
  5399. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5400. TSTORM_ID, 0, IGU_INT_NOP, 1);
  5401. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5402. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5403. } else {
  5404. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5405. USTORM_ID, 0, IGU_INT_NOP, 1);
  5406. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5407. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5408. }
  5409. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  5410. /* !!! these should become driver const once
  5411. rf-tool supports split-68 const */
  5412. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  5413. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  5414. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  5415. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  5416. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  5417. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  5418. }
  5419. }
  5420. /* Reset PCIE errors for debug */
  5421. REG_WR(bp, 0x2114, 0xffffffff);
  5422. REG_WR(bp, 0x2120, 0xffffffff);
  5423. if (CHIP_IS_E1x(bp)) {
  5424. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  5425. main_mem_base = HC_REG_MAIN_MEMORY +
  5426. BP_PORT(bp) * (main_mem_size * 4);
  5427. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  5428. main_mem_width = 8;
  5429. val = REG_RD(bp, main_mem_prty_clr);
  5430. if (val)
  5431. DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
  5432. "block during "
  5433. "function init (0x%x)!\n", val);
  5434. /* Clear "false" parity errors in MSI-X table */
  5435. for (i = main_mem_base;
  5436. i < main_mem_base + main_mem_size * 4;
  5437. i += main_mem_width) {
  5438. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  5439. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  5440. i, main_mem_width / 4);
  5441. }
  5442. /* Clear HC parity attention */
  5443. REG_RD(bp, main_mem_prty_clr);
  5444. }
  5445. #ifdef BNX2X_STOP_ON_ERROR
  5446. /* Enable STORMs SP logging */
  5447. REG_WR8(bp, BAR_USTRORM_INTMEM +
  5448. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5449. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5450. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5451. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5452. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5453. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  5454. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5455. #endif
  5456. bnx2x_phy_probe(&bp->link_params);
  5457. return 0;
  5458. }
  5459. void bnx2x_free_mem(struct bnx2x *bp)
  5460. {
  5461. /* fastpath */
  5462. bnx2x_free_fp_mem(bp);
  5463. /* end of fastpath */
  5464. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  5465. sizeof(struct host_sp_status_block));
  5466. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5467. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5468. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  5469. sizeof(struct bnx2x_slowpath));
  5470. BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
  5471. bp->context.size);
  5472. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  5473. BNX2X_FREE(bp->ilt->lines);
  5474. #ifdef BCM_CNIC
  5475. if (!CHIP_IS_E1x(bp))
  5476. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  5477. sizeof(struct host_hc_status_block_e2));
  5478. else
  5479. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  5480. sizeof(struct host_hc_status_block_e1x));
  5481. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  5482. #endif
  5483. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  5484. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  5485. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5486. }
  5487. static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  5488. {
  5489. int num_groups;
  5490. /* number of eth_queues */
  5491. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
  5492. /* Total number of FW statistics requests =
  5493. * 1 for port stats + 1 for PF stats + num_eth_queues */
  5494. bp->fw_stats_num = 2 + num_queue_stats;
  5495. /* Request is built from stats_query_header and an array of
  5496. * stats_query_cmd_group each of which contains
  5497. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  5498. * configured in the stats_query_header.
  5499. */
  5500. num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
  5501. (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  5502. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  5503. num_groups * sizeof(struct stats_query_cmd_group);
  5504. /* Data for statistics requests + stats_conter
  5505. *
  5506. * stats_counter holds per-STORM counters that are incremented
  5507. * when STORM has finished with the current request.
  5508. */
  5509. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  5510. sizeof(struct per_pf_stats) +
  5511. sizeof(struct per_queue_stats) * num_queue_stats +
  5512. sizeof(struct stats_counter);
  5513. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  5514. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5515. /* Set shortcuts */
  5516. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  5517. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  5518. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  5519. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  5520. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  5521. bp->fw_stats_req_sz;
  5522. return 0;
  5523. alloc_mem_err:
  5524. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5525. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5526. return -ENOMEM;
  5527. }
  5528. int bnx2x_alloc_mem(struct bnx2x *bp)
  5529. {
  5530. #ifdef BCM_CNIC
  5531. if (!CHIP_IS_E1x(bp))
  5532. /* size = the status block + ramrod buffers */
  5533. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  5534. sizeof(struct host_hc_status_block_e2));
  5535. else
  5536. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  5537. sizeof(struct host_hc_status_block_e1x));
  5538. /* allocate searcher T2 table */
  5539. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  5540. #endif
  5541. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  5542. sizeof(struct host_sp_status_block));
  5543. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  5544. sizeof(struct bnx2x_slowpath));
  5545. /* Allocated memory for FW statistics */
  5546. if (bnx2x_alloc_fw_stats_mem(bp))
  5547. goto alloc_mem_err;
  5548. bp->context.size = sizeof(union cdu_context) * bp->l2_cid_count;
  5549. BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
  5550. bp->context.size);
  5551. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  5552. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  5553. goto alloc_mem_err;
  5554. /* Slow path ring */
  5555. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  5556. /* EQ */
  5557. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  5558. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5559. /* fastpath */
  5560. /* need to be done at the end, since it's self adjusting to amount
  5561. * of memory available for RSS queues
  5562. */
  5563. if (bnx2x_alloc_fp_mem(bp))
  5564. goto alloc_mem_err;
  5565. return 0;
  5566. alloc_mem_err:
  5567. bnx2x_free_mem(bp);
  5568. return -ENOMEM;
  5569. }
  5570. /*
  5571. * Init service functions
  5572. */
  5573. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  5574. struct bnx2x_vlan_mac_obj *obj, bool set,
  5575. int mac_type, unsigned long *ramrod_flags)
  5576. {
  5577. int rc;
  5578. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  5579. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5580. /* Fill general parameters */
  5581. ramrod_param.vlan_mac_obj = obj;
  5582. ramrod_param.ramrod_flags = *ramrod_flags;
  5583. /* Fill a user request section if needed */
  5584. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  5585. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  5586. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  5587. /* Set the command: ADD or DEL */
  5588. if (set)
  5589. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  5590. else
  5591. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  5592. }
  5593. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  5594. if (rc < 0)
  5595. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  5596. return rc;
  5597. }
  5598. int bnx2x_del_all_macs(struct bnx2x *bp,
  5599. struct bnx2x_vlan_mac_obj *mac_obj,
  5600. int mac_type, bool wait_for_comp)
  5601. {
  5602. int rc;
  5603. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  5604. /* Wait for completion of requested */
  5605. if (wait_for_comp)
  5606. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5607. /* Set the mac type of addresses we want to clear */
  5608. __set_bit(mac_type, &vlan_mac_flags);
  5609. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  5610. if (rc < 0)
  5611. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  5612. return rc;
  5613. }
  5614. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  5615. {
  5616. unsigned long ramrod_flags = 0;
  5617. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  5618. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5619. /* Eth MAC is set on RSS leading client (fp[0]) */
  5620. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
  5621. BNX2X_ETH_MAC, &ramrod_flags);
  5622. }
  5623. int bnx2x_setup_leading(struct bnx2x *bp)
  5624. {
  5625. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  5626. }
  5627. /**
  5628. * bnx2x_set_int_mode - configure interrupt mode
  5629. *
  5630. * @bp: driver handle
  5631. *
  5632. * In case of MSI-X it will also try to enable MSI-X.
  5633. */
  5634. static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
  5635. {
  5636. switch (int_mode) {
  5637. case INT_MODE_MSI:
  5638. bnx2x_enable_msi(bp);
  5639. /* falling through... */
  5640. case INT_MODE_INTx:
  5641. bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
  5642. DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
  5643. break;
  5644. default:
  5645. /* Set number of queues according to bp->multi_mode value */
  5646. bnx2x_set_num_queues(bp);
  5647. DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
  5648. bp->num_queues);
  5649. /* if we can't use MSI-X we only need one fp,
  5650. * so try to enable MSI-X with the requested number of fp's
  5651. * and fallback to MSI or legacy INTx with one fp
  5652. */
  5653. if (bnx2x_enable_msix(bp)) {
  5654. /* failed to enable MSI-X */
  5655. if (bp->multi_mode)
  5656. DP(NETIF_MSG_IFUP,
  5657. "Multi requested but failed to "
  5658. "enable MSI-X (%d), "
  5659. "set number of queues to %d\n",
  5660. bp->num_queues,
  5661. 1 + NONE_ETH_CONTEXT_USE);
  5662. bp->num_queues = 1 + NONE_ETH_CONTEXT_USE;
  5663. /* Try to enable MSI */
  5664. if (!(bp->flags & DISABLE_MSI_FLAG))
  5665. bnx2x_enable_msi(bp);
  5666. }
  5667. break;
  5668. }
  5669. }
  5670. /* must be called prioir to any HW initializations */
  5671. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  5672. {
  5673. return L2_ILT_LINES(bp);
  5674. }
  5675. void bnx2x_ilt_set_info(struct bnx2x *bp)
  5676. {
  5677. struct ilt_client_info *ilt_client;
  5678. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5679. u16 line = 0;
  5680. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  5681. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  5682. /* CDU */
  5683. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  5684. ilt_client->client_num = ILT_CLIENT_CDU;
  5685. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  5686. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  5687. ilt_client->start = line;
  5688. line += bnx2x_cid_ilt_lines(bp);
  5689. #ifdef BCM_CNIC
  5690. line += CNIC_ILT_LINES;
  5691. #endif
  5692. ilt_client->end = line - 1;
  5693. DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
  5694. "flags 0x%x, hw psz %d\n",
  5695. ilt_client->start,
  5696. ilt_client->end,
  5697. ilt_client->page_size,
  5698. ilt_client->flags,
  5699. ilog2(ilt_client->page_size >> 12));
  5700. /* QM */
  5701. if (QM_INIT(bp->qm_cid_count)) {
  5702. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  5703. ilt_client->client_num = ILT_CLIENT_QM;
  5704. ilt_client->page_size = QM_ILT_PAGE_SZ;
  5705. ilt_client->flags = 0;
  5706. ilt_client->start = line;
  5707. /* 4 bytes for each cid */
  5708. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  5709. QM_ILT_PAGE_SZ);
  5710. ilt_client->end = line - 1;
  5711. DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
  5712. "flags 0x%x, hw psz %d\n",
  5713. ilt_client->start,
  5714. ilt_client->end,
  5715. ilt_client->page_size,
  5716. ilt_client->flags,
  5717. ilog2(ilt_client->page_size >> 12));
  5718. }
  5719. /* SRC */
  5720. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  5721. #ifdef BCM_CNIC
  5722. ilt_client->client_num = ILT_CLIENT_SRC;
  5723. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  5724. ilt_client->flags = 0;
  5725. ilt_client->start = line;
  5726. line += SRC_ILT_LINES;
  5727. ilt_client->end = line - 1;
  5728. DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
  5729. "flags 0x%x, hw psz %d\n",
  5730. ilt_client->start,
  5731. ilt_client->end,
  5732. ilt_client->page_size,
  5733. ilt_client->flags,
  5734. ilog2(ilt_client->page_size >> 12));
  5735. #else
  5736. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  5737. #endif
  5738. /* TM */
  5739. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  5740. #ifdef BCM_CNIC
  5741. ilt_client->client_num = ILT_CLIENT_TM;
  5742. ilt_client->page_size = TM_ILT_PAGE_SZ;
  5743. ilt_client->flags = 0;
  5744. ilt_client->start = line;
  5745. line += TM_ILT_LINES;
  5746. ilt_client->end = line - 1;
  5747. DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
  5748. "flags 0x%x, hw psz %d\n",
  5749. ilt_client->start,
  5750. ilt_client->end,
  5751. ilt_client->page_size,
  5752. ilt_client->flags,
  5753. ilog2(ilt_client->page_size >> 12));
  5754. #else
  5755. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  5756. #endif
  5757. BUG_ON(line > ILT_MAX_LINES);
  5758. }
  5759. /**
  5760. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  5761. *
  5762. * @bp: driver handle
  5763. * @fp: pointer to fastpath
  5764. * @init_params: pointer to parameters structure
  5765. *
  5766. * parameters configured:
  5767. * - HC configuration
  5768. * - Queue's CDU context
  5769. */
  5770. static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  5771. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  5772. {
  5773. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  5774. if (!IS_FCOE_FP(fp)) {
  5775. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  5776. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  5777. /* If HC is supporterd, enable host coalescing in the transition
  5778. * to INIT state.
  5779. */
  5780. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  5781. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  5782. /* HC rate */
  5783. init_params->rx.hc_rate = bp->rx_ticks ?
  5784. (1000000 / bp->rx_ticks) : 0;
  5785. init_params->tx.hc_rate = bp->tx_ticks ?
  5786. (1000000 / bp->tx_ticks) : 0;
  5787. /* FW SB ID */
  5788. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  5789. fp->fw_sb_id;
  5790. /*
  5791. * CQ index among the SB indices: FCoE clients uses the default
  5792. * SB, therefore it's different.
  5793. */
  5794. init_params->rx.sb_cq_index = U_SB_ETH_RX_CQ_INDEX;
  5795. init_params->tx.sb_cq_index = C_SB_ETH_TX_CQ_INDEX;
  5796. }
  5797. init_params->cxt = &bp->context.vcxt[fp->cid].eth;
  5798. }
  5799. /**
  5800. * bnx2x_setup_queue - setup queue
  5801. *
  5802. * @bp: driver handle
  5803. * @fp: pointer to fastpath
  5804. * @leading: is leading
  5805. *
  5806. * This function performs 2 steps in a Queue state machine
  5807. * actually: 1) RESET->INIT 2) INIT->SETUP
  5808. */
  5809. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  5810. bool leading)
  5811. {
  5812. struct bnx2x_queue_state_params q_params = {0};
  5813. struct bnx2x_queue_setup_params *setup_params =
  5814. &q_params.params.setup;
  5815. int rc;
  5816. /* reset IGU state skip FCoE L2 queue */
  5817. if (!IS_FCOE_FP(fp))
  5818. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  5819. IGU_INT_ENABLE, 0);
  5820. q_params.q_obj = &fp->q_obj;
  5821. /* We want to wait for completion in this context */
  5822. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  5823. /* Prepare the INIT parameters */
  5824. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  5825. /* Set the command */
  5826. q_params.cmd = BNX2X_Q_CMD_INIT;
  5827. /* Change the state to INIT */
  5828. rc = bnx2x_queue_state_change(bp, &q_params);
  5829. if (rc) {
  5830. BNX2X_ERR("Queue INIT failed\n");
  5831. return rc;
  5832. }
  5833. /* Now move the Queue to the SETUP state... */
  5834. memset(setup_params, 0, sizeof(*setup_params));
  5835. /* Set QUEUE flags */
  5836. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  5837. /* Set general SETUP parameters */
  5838. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params);
  5839. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause,
  5840. &setup_params->rxq_params);
  5841. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params);
  5842. /* Set the command */
  5843. q_params.cmd = BNX2X_Q_CMD_SETUP;
  5844. /* Change the state to SETUP */
  5845. rc = bnx2x_queue_state_change(bp, &q_params);
  5846. if (rc)
  5847. BNX2X_ERR("Queue SETUP failed\n");
  5848. return rc;
  5849. }
  5850. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  5851. {
  5852. struct bnx2x_fastpath *fp = &bp->fp[index];
  5853. struct bnx2x_queue_state_params q_params = {0};
  5854. int rc;
  5855. q_params.q_obj = &fp->q_obj;
  5856. /* We want to wait for completion in this context */
  5857. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  5858. /* halt the connection */
  5859. q_params.cmd = BNX2X_Q_CMD_HALT;
  5860. rc = bnx2x_queue_state_change(bp, &q_params);
  5861. if (rc)
  5862. return rc;
  5863. /* terminate the connection */
  5864. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  5865. rc = bnx2x_queue_state_change(bp, &q_params);
  5866. if (rc)
  5867. return rc;
  5868. /* delete cfc entry */
  5869. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  5870. return bnx2x_queue_state_change(bp, &q_params);
  5871. }
  5872. static void bnx2x_reset_func(struct bnx2x *bp)
  5873. {
  5874. int port = BP_PORT(bp);
  5875. int func = BP_FUNC(bp);
  5876. int i;
  5877. /* Disable the function in the FW */
  5878. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  5879. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  5880. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  5881. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  5882. /* FP SBs */
  5883. for_each_eth_queue(bp, i) {
  5884. struct bnx2x_fastpath *fp = &bp->fp[i];
  5885. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5886. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  5887. SB_DISABLED);
  5888. }
  5889. #ifdef BCM_CNIC
  5890. /* CNIC SB */
  5891. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5892. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  5893. SB_DISABLED);
  5894. #endif
  5895. /* SP SB */
  5896. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5897. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  5898. SB_DISABLED);
  5899. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  5900. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  5901. 0);
  5902. /* Configure IGU */
  5903. if (bp->common.int_block == INT_BLOCK_HC) {
  5904. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5905. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5906. } else {
  5907. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  5908. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  5909. }
  5910. #ifdef BCM_CNIC
  5911. /* Disable Timer scan */
  5912. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  5913. /*
  5914. * Wait for at least 10ms and up to 2 second for the timers scan to
  5915. * complete
  5916. */
  5917. for (i = 0; i < 200; i++) {
  5918. msleep(10);
  5919. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  5920. break;
  5921. }
  5922. #endif
  5923. /* Clear ILT */
  5924. bnx2x_clear_func_ilt(bp, func);
  5925. /* Timers workaround bug for E2: if this is vnic-3,
  5926. * we need to set the entire ilt range for this timers.
  5927. */
  5928. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  5929. struct ilt_client_info ilt_cli;
  5930. /* use dummy TM client */
  5931. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5932. ilt_cli.start = 0;
  5933. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5934. ilt_cli.client_num = ILT_CLIENT_TM;
  5935. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  5936. }
  5937. /* this assumes that reset_port() called before reset_func()*/
  5938. if (!CHIP_IS_E1x(bp))
  5939. bnx2x_pf_disable(bp);
  5940. bp->dmae_ready = 0;
  5941. }
  5942. static void bnx2x_reset_port(struct bnx2x *bp)
  5943. {
  5944. int port = BP_PORT(bp);
  5945. u32 val;
  5946. /* Reset physical Link */
  5947. bnx2x__link_reset(bp);
  5948. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5949. /* Do not rcv packets to BRB */
  5950. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  5951. /* Do not direct rcv packets that are not for MCP to the BRB */
  5952. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  5953. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  5954. /* Configure AEU */
  5955. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  5956. msleep(100);
  5957. /* Check for BRB port occupancy */
  5958. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  5959. if (val)
  5960. DP(NETIF_MSG_IFDOWN,
  5961. "BRB1 is not empty %d blocks are occupied\n", val);
  5962. /* TODO: Close Doorbell port? */
  5963. }
  5964. static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  5965. {
  5966. struct bnx2x_func_state_params func_params = {0};
  5967. /* Prepare parameters for function state transitions */
  5968. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  5969. func_params.f_obj = &bp->func_obj;
  5970. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  5971. func_params.params.hw_init.load_phase = load_code;
  5972. return bnx2x_func_state_change(bp, &func_params);
  5973. }
  5974. static inline int bnx2x_func_stop(struct bnx2x *bp)
  5975. {
  5976. struct bnx2x_func_state_params func_params = {0};
  5977. int rc;
  5978. /* Prepare parameters for function state transitions */
  5979. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  5980. func_params.f_obj = &bp->func_obj;
  5981. func_params.cmd = BNX2X_F_CMD_STOP;
  5982. /*
  5983. * Try to stop the function the 'good way'. If fails (in case
  5984. * of a parity error during bnx2x_chip_cleanup()) and we are
  5985. * not in a debug mode, perform a state transaction in order to
  5986. * enable further HW_RESET transaction.
  5987. */
  5988. rc = bnx2x_func_state_change(bp, &func_params);
  5989. if (rc) {
  5990. #ifdef BNX2X_STOP_ON_ERROR
  5991. return rc;
  5992. #else
  5993. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
  5994. "transaction\n");
  5995. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  5996. return bnx2x_func_state_change(bp, &func_params);
  5997. #endif
  5998. }
  5999. return 0;
  6000. }
  6001. /**
  6002. * bnx2x_send_unload_req - request unload mode from the MCP.
  6003. *
  6004. * @bp: driver handle
  6005. * @unload_mode: requested function's unload mode
  6006. *
  6007. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6008. */
  6009. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6010. {
  6011. u32 reset_code = 0;
  6012. int port = BP_PORT(bp);
  6013. /* Select the UNLOAD request mode */
  6014. if (unload_mode == UNLOAD_NORMAL)
  6015. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6016. else if (bp->flags & NO_WOL_FLAG)
  6017. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6018. else if (bp->wol) {
  6019. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6020. u8 *mac_addr = bp->dev->dev_addr;
  6021. u32 val;
  6022. /* The mac address is written to entries 1-4 to
  6023. preserve entry 0 which is used by the PMF */
  6024. u8 entry = (BP_E1HVN(bp) + 1)*8;
  6025. val = (mac_addr[0] << 8) | mac_addr[1];
  6026. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6027. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6028. (mac_addr[4] << 8) | mac_addr[5];
  6029. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6030. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6031. } else
  6032. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6033. /* Send the request to the MCP */
  6034. if (!BP_NOMCP(bp))
  6035. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6036. else {
  6037. int path = BP_PATH(bp);
  6038. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
  6039. "%d, %d, %d\n",
  6040. path, load_count[path][0], load_count[path][1],
  6041. load_count[path][2]);
  6042. load_count[path][0]--;
  6043. load_count[path][1 + port]--;
  6044. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
  6045. "%d, %d, %d\n",
  6046. path, load_count[path][0], load_count[path][1],
  6047. load_count[path][2]);
  6048. if (load_count[path][0] == 0)
  6049. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6050. else if (load_count[path][1 + port] == 0)
  6051. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6052. else
  6053. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6054. }
  6055. return reset_code;
  6056. }
  6057. /**
  6058. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6059. *
  6060. * @bp: driver handle
  6061. */
  6062. void bnx2x_send_unload_done(struct bnx2x *bp)
  6063. {
  6064. /* Report UNLOAD_DONE to MCP */
  6065. if (!BP_NOMCP(bp))
  6066. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6067. }
  6068. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6069. {
  6070. int port = BP_PORT(bp);
  6071. int i, rc;
  6072. struct bnx2x_mcast_ramrod_params rparam = {0};
  6073. u32 reset_code;
  6074. /* Wait until tx fastpath tasks complete */
  6075. for_each_tx_queue(bp, i) {
  6076. struct bnx2x_fastpath *fp = &bp->fp[i];
  6077. rc = bnx2x_clean_tx_queue(bp, fp);
  6078. #ifdef BNX2X_STOP_ON_ERROR
  6079. if (rc)
  6080. return;
  6081. #endif
  6082. }
  6083. /* Give HW time to discard old tx messages */
  6084. usleep_range(1000, 1000);
  6085. /* Clean all ETH MACs */
  6086. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
  6087. if (rc < 0)
  6088. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6089. /* Clean up UC list */
  6090. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
  6091. true);
  6092. if (rc < 0)
  6093. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
  6094. "%d\n", rc);
  6095. /* Disable LLH */
  6096. if (!CHIP_IS_E1(bp))
  6097. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6098. /* Set "drop all" (stop Rx).
  6099. * We need to take a netif_addr_lock() here in order to prevent
  6100. * a race between the completion code and this code.
  6101. */
  6102. netif_addr_lock_bh(bp->dev);
  6103. /* Schedule the rx_mode command */
  6104. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6105. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6106. else
  6107. bnx2x_set_storm_rx_mode(bp);
  6108. /* Cleanup multicast configuration */
  6109. rparam.mcast_obj = &bp->mcast_obj;
  6110. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6111. if (rc < 0)
  6112. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6113. netif_addr_unlock_bh(bp->dev);
  6114. /* Close multi and leading connections
  6115. * Completions for ramrods are collected in a synchronous way
  6116. */
  6117. for_each_queue(bp, i)
  6118. if (bnx2x_stop_queue(bp, i))
  6119. #ifdef BNX2X_STOP_ON_ERROR
  6120. return;
  6121. #else
  6122. goto unload_error;
  6123. #endif
  6124. /* If SP settings didn't get completed so far - something
  6125. * very wrong has happen.
  6126. */
  6127. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  6128. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  6129. #ifndef BNX2X_STOP_ON_ERROR
  6130. unload_error:
  6131. #endif
  6132. rc = bnx2x_func_stop(bp);
  6133. if (rc) {
  6134. BNX2X_ERR("Function stop failed!\n");
  6135. #ifdef BNX2X_STOP_ON_ERROR
  6136. return;
  6137. #endif
  6138. }
  6139. /*
  6140. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6141. * this function should perform FUNC, PORT or COMMON HW
  6142. * reset.
  6143. */
  6144. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6145. /* Disable HW interrupts, NAPI */
  6146. bnx2x_netif_stop(bp, 1);
  6147. /* Release IRQs */
  6148. bnx2x_free_irq(bp);
  6149. /* Reset the chip */
  6150. rc = bnx2x_reset_hw(bp, reset_code);
  6151. if (rc)
  6152. BNX2X_ERR("HW_RESET failed\n");
  6153. /* Report UNLOAD_DONE to MCP */
  6154. bnx2x_send_unload_done(bp);
  6155. }
  6156. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  6157. {
  6158. u32 val;
  6159. DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
  6160. if (CHIP_IS_E1(bp)) {
  6161. int port = BP_PORT(bp);
  6162. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6163. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  6164. val = REG_RD(bp, addr);
  6165. val &= ~(0x300);
  6166. REG_WR(bp, addr, val);
  6167. } else {
  6168. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  6169. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  6170. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  6171. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  6172. }
  6173. }
  6174. /* Close gates #2, #3 and #4: */
  6175. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  6176. {
  6177. u32 val;
  6178. /* Gates #2 and #4a are closed/opened for "not E1" only */
  6179. if (!CHIP_IS_E1(bp)) {
  6180. /* #4 */
  6181. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  6182. /* #2 */
  6183. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  6184. }
  6185. /* #3 */
  6186. if (CHIP_IS_E1x(bp)) {
  6187. /* Prevent interrupts from HC on both ports */
  6188. val = REG_RD(bp, HC_REG_CONFIG_1);
  6189. REG_WR(bp, HC_REG_CONFIG_1,
  6190. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  6191. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  6192. val = REG_RD(bp, HC_REG_CONFIG_0);
  6193. REG_WR(bp, HC_REG_CONFIG_0,
  6194. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  6195. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  6196. } else {
  6197. /* Prevent incomming interrupts in IGU */
  6198. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  6199. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  6200. (!close) ?
  6201. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  6202. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  6203. }
  6204. DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
  6205. close ? "closing" : "opening");
  6206. mmiowb();
  6207. }
  6208. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  6209. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  6210. {
  6211. /* Do some magic... */
  6212. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6213. *magic_val = val & SHARED_MF_CLP_MAGIC;
  6214. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  6215. }
  6216. /**
  6217. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  6218. *
  6219. * @bp: driver handle
  6220. * @magic_val: old value of the `magic' bit.
  6221. */
  6222. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  6223. {
  6224. /* Restore the `magic' bit value... */
  6225. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6226. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  6227. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  6228. }
  6229. /**
  6230. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  6231. *
  6232. * @bp: driver handle
  6233. * @magic_val: old value of 'magic' bit.
  6234. *
  6235. * Takes care of CLP configurations.
  6236. */
  6237. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  6238. {
  6239. u32 shmem;
  6240. u32 validity_offset;
  6241. DP(NETIF_MSG_HW, "Starting\n");
  6242. /* Set `magic' bit in order to save MF config */
  6243. if (!CHIP_IS_E1(bp))
  6244. bnx2x_clp_reset_prep(bp, magic_val);
  6245. /* Get shmem offset */
  6246. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6247. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  6248. /* Clear validity map flags */
  6249. if (shmem > 0)
  6250. REG_WR(bp, shmem + validity_offset, 0);
  6251. }
  6252. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  6253. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  6254. /**
  6255. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  6256. *
  6257. * @bp: driver handle
  6258. */
  6259. static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
  6260. {
  6261. /* special handling for emulation and FPGA,
  6262. wait 10 times longer */
  6263. if (CHIP_REV_IS_SLOW(bp))
  6264. msleep(MCP_ONE_TIMEOUT*10);
  6265. else
  6266. msleep(MCP_ONE_TIMEOUT);
  6267. }
  6268. /*
  6269. * initializes bp->common.shmem_base and waits for validity signature to appear
  6270. */
  6271. static int bnx2x_init_shmem(struct bnx2x *bp)
  6272. {
  6273. int cnt = 0;
  6274. u32 val = 0;
  6275. do {
  6276. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6277. if (bp->common.shmem_base) {
  6278. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  6279. if (val & SHR_MEM_VALIDITY_MB)
  6280. return 0;
  6281. }
  6282. bnx2x_mcp_wait_one(bp);
  6283. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  6284. BNX2X_ERR("BAD MCP validity signature\n");
  6285. return -ENODEV;
  6286. }
  6287. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  6288. {
  6289. int rc = bnx2x_init_shmem(bp);
  6290. /* Restore the `magic' bit value */
  6291. if (!CHIP_IS_E1(bp))
  6292. bnx2x_clp_reset_done(bp, magic_val);
  6293. return rc;
  6294. }
  6295. static void bnx2x_pxp_prep(struct bnx2x *bp)
  6296. {
  6297. if (!CHIP_IS_E1(bp)) {
  6298. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  6299. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  6300. mmiowb();
  6301. }
  6302. }
  6303. /*
  6304. * Reset the whole chip except for:
  6305. * - PCIE core
  6306. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  6307. * one reset bit)
  6308. * - IGU
  6309. * - MISC (including AEU)
  6310. * - GRC
  6311. * - RBCN, RBCP
  6312. */
  6313. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  6314. {
  6315. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  6316. u32 global_bits2;
  6317. /*
  6318. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  6319. * (per chip) blocks.
  6320. */
  6321. global_bits2 =
  6322. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  6323. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  6324. not_reset_mask1 =
  6325. MISC_REGISTERS_RESET_REG_1_RST_HC |
  6326. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  6327. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  6328. not_reset_mask2 =
  6329. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  6330. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  6331. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  6332. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  6333. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  6334. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  6335. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  6336. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B;
  6337. reset_mask1 = 0xffffffff;
  6338. if (CHIP_IS_E1(bp))
  6339. reset_mask2 = 0xffff;
  6340. else
  6341. reset_mask2 = 0x1ffff;
  6342. if (CHIP_IS_E3(bp)) {
  6343. reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  6344. reset_mask2 |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  6345. }
  6346. /* Don't reset global blocks unless we need to */
  6347. if (!global)
  6348. reset_mask2 &= ~global_bits2;
  6349. /*
  6350. * In case of attention in the QM, we need to reset PXP
  6351. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  6352. * because otherwise QM reset would release 'close the gates' shortly
  6353. * before resetting the PXP, then the PSWRQ would send a write
  6354. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  6355. * read the payload data from PSWWR, but PSWWR would not
  6356. * respond. The write queue in PGLUE would stuck, dmae commands
  6357. * would not return. Therefore it's important to reset the second
  6358. * reset register (containing the
  6359. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  6360. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  6361. * bit).
  6362. */
  6363. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6364. reset_mask2 & (~not_reset_mask2));
  6365. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6366. reset_mask1 & (~not_reset_mask1));
  6367. barrier();
  6368. mmiowb();
  6369. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, reset_mask2);
  6370. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  6371. mmiowb();
  6372. }
  6373. /**
  6374. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  6375. * It should get cleared in no more than 1s.
  6376. *
  6377. * @bp: driver handle
  6378. *
  6379. * It should get cleared in no more than 1s. Returns 0 if
  6380. * pending writes bit gets cleared.
  6381. */
  6382. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  6383. {
  6384. u32 cnt = 1000;
  6385. u32 pend_bits = 0;
  6386. do {
  6387. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  6388. if (pend_bits == 0)
  6389. break;
  6390. usleep_range(1000, 1000);
  6391. } while (cnt-- > 0);
  6392. if (cnt <= 0) {
  6393. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  6394. pend_bits);
  6395. return -EBUSY;
  6396. }
  6397. return 0;
  6398. }
  6399. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  6400. {
  6401. int cnt = 1000;
  6402. u32 val = 0;
  6403. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  6404. /* Empty the Tetris buffer, wait for 1s */
  6405. do {
  6406. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  6407. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  6408. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  6409. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  6410. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  6411. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  6412. ((port_is_idle_0 & 0x1) == 0x1) &&
  6413. ((port_is_idle_1 & 0x1) == 0x1) &&
  6414. (pgl_exp_rom2 == 0xffffffff))
  6415. break;
  6416. usleep_range(1000, 1000);
  6417. } while (cnt-- > 0);
  6418. if (cnt <= 0) {
  6419. DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
  6420. " are still"
  6421. " outstanding read requests after 1s!\n");
  6422. DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
  6423. " port_is_idle_0=0x%08x,"
  6424. " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  6425. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  6426. pgl_exp_rom2);
  6427. return -EAGAIN;
  6428. }
  6429. barrier();
  6430. /* Close gates #2, #3 and #4 */
  6431. bnx2x_set_234_gates(bp, true);
  6432. /* Poll for IGU VQs for 57712 and newer chips */
  6433. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  6434. return -EAGAIN;
  6435. /* TBD: Indicate that "process kill" is in progress to MCP */
  6436. /* Clear "unprepared" bit */
  6437. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  6438. barrier();
  6439. /* Make sure all is written to the chip before the reset */
  6440. mmiowb();
  6441. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  6442. * PSWHST, GRC and PSWRD Tetris buffer.
  6443. */
  6444. usleep_range(1000, 1000);
  6445. /* Prepare to chip reset: */
  6446. /* MCP */
  6447. if (global)
  6448. bnx2x_reset_mcp_prep(bp, &val);
  6449. /* PXP */
  6450. bnx2x_pxp_prep(bp);
  6451. barrier();
  6452. /* reset the chip */
  6453. bnx2x_process_kill_chip_reset(bp, global);
  6454. barrier();
  6455. /* Recover after reset: */
  6456. /* MCP */
  6457. if (global && bnx2x_reset_mcp_comp(bp, val))
  6458. return -EAGAIN;
  6459. /* TBD: Add resetting the NO_MCP mode DB here */
  6460. /* PXP */
  6461. bnx2x_pxp_prep(bp);
  6462. /* Open the gates #2, #3 and #4 */
  6463. bnx2x_set_234_gates(bp, false);
  6464. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  6465. * reset state, re-enable attentions. */
  6466. return 0;
  6467. }
  6468. int bnx2x_leader_reset(struct bnx2x *bp)
  6469. {
  6470. int rc = 0;
  6471. bool global = bnx2x_reset_is_global(bp);
  6472. /* Try to recover after the failure */
  6473. if (bnx2x_process_kill(bp, global)) {
  6474. netdev_err(bp->dev, "Something bad had happen on engine %d! "
  6475. "Aii!\n", BP_PATH(bp));
  6476. rc = -EAGAIN;
  6477. goto exit_leader_reset;
  6478. }
  6479. /*
  6480. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  6481. * state.
  6482. */
  6483. bnx2x_set_reset_done(bp);
  6484. if (global)
  6485. bnx2x_clear_reset_global(bp);
  6486. exit_leader_reset:
  6487. bp->is_leader = 0;
  6488. bnx2x_release_leader_lock(bp);
  6489. smp_mb();
  6490. return rc;
  6491. }
  6492. static inline void bnx2x_recovery_failed(struct bnx2x *bp)
  6493. {
  6494. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  6495. /* Disconnect this device */
  6496. netif_device_detach(bp->dev);
  6497. /*
  6498. * Block ifup for all function on this engine until "process kill"
  6499. * or power cycle.
  6500. */
  6501. bnx2x_set_reset_in_progress(bp);
  6502. /* Shut down the power */
  6503. bnx2x_set_power_state(bp, PCI_D3hot);
  6504. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  6505. smp_mb();
  6506. }
  6507. /*
  6508. * Assumption: runs under rtnl lock. This together with the fact
  6509. * that it's called only from bnx2x_reset_task() ensure that it
  6510. * will never be called when netif_running(bp->dev) is false.
  6511. */
  6512. static void bnx2x_parity_recover(struct bnx2x *bp)
  6513. {
  6514. bool global = false;
  6515. DP(NETIF_MSG_HW, "Handling parity\n");
  6516. while (1) {
  6517. switch (bp->recovery_state) {
  6518. case BNX2X_RECOVERY_INIT:
  6519. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  6520. bnx2x_chk_parity_attn(bp, &global, false);
  6521. /* Try to get a LEADER_LOCK HW lock */
  6522. if (bnx2x_trylock_leader_lock(bp)) {
  6523. bnx2x_set_reset_in_progress(bp);
  6524. /*
  6525. * Check if there is a global attention and if
  6526. * there was a global attention, set the global
  6527. * reset bit.
  6528. */
  6529. if (global)
  6530. bnx2x_set_reset_global(bp);
  6531. bp->is_leader = 1;
  6532. }
  6533. /* Stop the driver */
  6534. /* If interface has been removed - break */
  6535. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  6536. return;
  6537. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  6538. /*
  6539. * Reset MCP command sequence number and MCP mail box
  6540. * sequence as we are going to reset the MCP.
  6541. */
  6542. if (global) {
  6543. bp->fw_seq = 0;
  6544. bp->fw_drv_pulse_wr_seq = 0;
  6545. }
  6546. /* Ensure "is_leader", MCP command sequence and
  6547. * "recovery_state" update values are seen on other
  6548. * CPUs.
  6549. */
  6550. smp_mb();
  6551. break;
  6552. case BNX2X_RECOVERY_WAIT:
  6553. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  6554. if (bp->is_leader) {
  6555. int other_engine = BP_PATH(bp) ? 0 : 1;
  6556. u32 other_load_counter =
  6557. bnx2x_get_load_cnt(bp, other_engine);
  6558. u32 load_counter =
  6559. bnx2x_get_load_cnt(bp, BP_PATH(bp));
  6560. global = bnx2x_reset_is_global(bp);
  6561. /*
  6562. * In case of a parity in a global block, let
  6563. * the first leader that performs a
  6564. * leader_reset() reset the global blocks in
  6565. * order to clear global attentions. Otherwise
  6566. * the the gates will remain closed for that
  6567. * engine.
  6568. */
  6569. if (load_counter ||
  6570. (global && other_load_counter)) {
  6571. /* Wait until all other functions get
  6572. * down.
  6573. */
  6574. schedule_delayed_work(&bp->reset_task,
  6575. HZ/10);
  6576. return;
  6577. } else {
  6578. /* If all other functions got down -
  6579. * try to bring the chip back to
  6580. * normal. In any case it's an exit
  6581. * point for a leader.
  6582. */
  6583. if (bnx2x_leader_reset(bp)) {
  6584. bnx2x_recovery_failed(bp);
  6585. return;
  6586. }
  6587. /* If we are here, means that the
  6588. * leader has succeeded and doesn't
  6589. * want to be a leader any more. Try
  6590. * to continue as a none-leader.
  6591. */
  6592. break;
  6593. }
  6594. } else { /* non-leader */
  6595. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  6596. /* Try to get a LEADER_LOCK HW lock as
  6597. * long as a former leader may have
  6598. * been unloaded by the user or
  6599. * released a leadership by another
  6600. * reason.
  6601. */
  6602. if (bnx2x_trylock_leader_lock(bp)) {
  6603. /* I'm a leader now! Restart a
  6604. * switch case.
  6605. */
  6606. bp->is_leader = 1;
  6607. break;
  6608. }
  6609. schedule_delayed_work(&bp->reset_task,
  6610. HZ/10);
  6611. return;
  6612. } else {
  6613. /*
  6614. * If there was a global attention, wait
  6615. * for it to be cleared.
  6616. */
  6617. if (bnx2x_reset_is_global(bp)) {
  6618. schedule_delayed_work(
  6619. &bp->reset_task, HZ/10);
  6620. return;
  6621. }
  6622. if (bnx2x_nic_load(bp, LOAD_NORMAL))
  6623. bnx2x_recovery_failed(bp);
  6624. else {
  6625. bp->recovery_state =
  6626. BNX2X_RECOVERY_DONE;
  6627. smp_mb();
  6628. }
  6629. return;
  6630. }
  6631. }
  6632. default:
  6633. return;
  6634. }
  6635. }
  6636. }
  6637. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  6638. * scheduled on a general queue in order to prevent a dead lock.
  6639. */
  6640. static void bnx2x_reset_task(struct work_struct *work)
  6641. {
  6642. struct bnx2x *bp = container_of(work, struct bnx2x, reset_task.work);
  6643. #ifdef BNX2X_STOP_ON_ERROR
  6644. BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
  6645. " so reset not done to allow debug dump,\n"
  6646. KERN_ERR " you will need to reboot when done\n");
  6647. return;
  6648. #endif
  6649. rtnl_lock();
  6650. if (!netif_running(bp->dev))
  6651. goto reset_task_exit;
  6652. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE))
  6653. bnx2x_parity_recover(bp);
  6654. else {
  6655. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  6656. bnx2x_nic_load(bp, LOAD_NORMAL);
  6657. }
  6658. reset_task_exit:
  6659. rtnl_unlock();
  6660. }
  6661. /* end of nic load/unload */
  6662. /*
  6663. * Init service functions
  6664. */
  6665. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  6666. {
  6667. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  6668. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  6669. return base + (BP_ABS_FUNC(bp)) * stride;
  6670. }
  6671. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  6672. {
  6673. u32 reg = bnx2x_get_pretend_reg(bp);
  6674. /* Flush all outstanding writes */
  6675. mmiowb();
  6676. /* Pretend to be function 0 */
  6677. REG_WR(bp, reg, 0);
  6678. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  6679. /* From now we are in the "like-E1" mode */
  6680. bnx2x_int_disable(bp);
  6681. /* Flush all outstanding writes */
  6682. mmiowb();
  6683. /* Restore the original function */
  6684. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  6685. REG_RD(bp, reg);
  6686. }
  6687. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  6688. {
  6689. if (CHIP_IS_E1(bp))
  6690. bnx2x_int_disable(bp);
  6691. else
  6692. bnx2x_undi_int_disable_e1h(bp);
  6693. }
  6694. static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
  6695. {
  6696. u32 val;
  6697. /* Check if there is any driver already loaded */
  6698. val = REG_RD(bp, MISC_REG_UNPREPARED);
  6699. if (val == 0x1) {
  6700. /* Check if it is the UNDI driver
  6701. * UNDI driver initializes CID offset for normal bell to 0x7
  6702. */
  6703. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6704. val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  6705. if (val == 0x7) {
  6706. u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6707. /* save our pf_num */
  6708. int orig_pf_num = bp->pf_num;
  6709. int port;
  6710. u32 swap_en, swap_val, value;
  6711. /* clear the UNDI indication */
  6712. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  6713. BNX2X_DEV_INFO("UNDI is active! reset device\n");
  6714. /* try unload UNDI on port 0 */
  6715. bp->pf_num = 0;
  6716. bp->fw_seq =
  6717. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  6718. DRV_MSG_SEQ_NUMBER_MASK);
  6719. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6720. /* if UNDI is loaded on the other port */
  6721. if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  6722. /* send "DONE" for previous unload */
  6723. bnx2x_fw_command(bp,
  6724. DRV_MSG_CODE_UNLOAD_DONE, 0);
  6725. /* unload UNDI on port 1 */
  6726. bp->pf_num = 1;
  6727. bp->fw_seq =
  6728. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  6729. DRV_MSG_SEQ_NUMBER_MASK);
  6730. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6731. bnx2x_fw_command(bp, reset_code, 0);
  6732. }
  6733. /* now it's safe to release the lock */
  6734. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6735. bnx2x_undi_int_disable(bp);
  6736. port = BP_PORT(bp);
  6737. /* close input traffic and wait for it */
  6738. /* Do not rcv packets to BRB */
  6739. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
  6740. NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
  6741. /* Do not direct rcv packets that are not for MCP to
  6742. * the BRB */
  6743. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6744. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6745. /* clear AEU */
  6746. REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6747. MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
  6748. msleep(10);
  6749. /* save NIG port swap info */
  6750. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  6751. swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  6752. /* reset device */
  6753. REG_WR(bp,
  6754. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6755. 0xd3ffffff);
  6756. value = 0x1400;
  6757. if (CHIP_IS_E3(bp)) {
  6758. value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  6759. value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  6760. }
  6761. REG_WR(bp,
  6762. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6763. value);
  6764. /* take the NIG out of reset and restore swap values */
  6765. REG_WR(bp,
  6766. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6767. MISC_REGISTERS_RESET_REG_1_RST_NIG);
  6768. REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
  6769. REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
  6770. /* send unload done to the MCP */
  6771. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6772. /* restore our func and fw_seq */
  6773. bp->pf_num = orig_pf_num;
  6774. bp->fw_seq =
  6775. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  6776. DRV_MSG_SEQ_NUMBER_MASK);
  6777. } else
  6778. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6779. }
  6780. }
  6781. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  6782. {
  6783. u32 val, val2, val3, val4, id;
  6784. u16 pmc;
  6785. /* Get the chip revision id and number. */
  6786. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  6787. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  6788. id = ((val & 0xffff) << 16);
  6789. val = REG_RD(bp, MISC_REG_CHIP_REV);
  6790. id |= ((val & 0xf) << 12);
  6791. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  6792. id |= ((val & 0xff) << 4);
  6793. val = REG_RD(bp, MISC_REG_BOND_ID);
  6794. id |= (val & 0xf);
  6795. bp->common.chip_id = id;
  6796. /* Set doorbell size */
  6797. bp->db_size = (1 << BNX2X_DB_SHIFT);
  6798. if (!CHIP_IS_E1x(bp)) {
  6799. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  6800. if ((val & 1) == 0)
  6801. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  6802. else
  6803. val = (val >> 1) & 1;
  6804. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  6805. "2_PORT_MODE");
  6806. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  6807. CHIP_2_PORT_MODE;
  6808. if (CHIP_MODE_IS_4_PORT(bp))
  6809. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  6810. else
  6811. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  6812. } else {
  6813. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  6814. bp->pfid = bp->pf_num; /* 0..7 */
  6815. }
  6816. bp->link_params.chip_id = bp->common.chip_id;
  6817. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  6818. val = (REG_RD(bp, 0x2874) & 0x55);
  6819. if ((bp->common.chip_id & 0x1) ||
  6820. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  6821. bp->flags |= ONE_PORT_FLAG;
  6822. BNX2X_DEV_INFO("single port device\n");
  6823. }
  6824. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  6825. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  6826. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  6827. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  6828. bp->common.flash_size, bp->common.flash_size);
  6829. bnx2x_init_shmem(bp);
  6830. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  6831. MISC_REG_GENERIC_CR_1 :
  6832. MISC_REG_GENERIC_CR_0));
  6833. bp->link_params.shmem_base = bp->common.shmem_base;
  6834. bp->link_params.shmem2_base = bp->common.shmem2_base;
  6835. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  6836. bp->common.shmem_base, bp->common.shmem2_base);
  6837. if (!bp->common.shmem_base) {
  6838. BNX2X_DEV_INFO("MCP not active\n");
  6839. bp->flags |= NO_MCP_FLAG;
  6840. return;
  6841. }
  6842. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  6843. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  6844. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  6845. SHARED_HW_CFG_LED_MODE_MASK) >>
  6846. SHARED_HW_CFG_LED_MODE_SHIFT);
  6847. bp->link_params.feature_config_flags = 0;
  6848. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  6849. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  6850. bp->link_params.feature_config_flags |=
  6851. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  6852. else
  6853. bp->link_params.feature_config_flags &=
  6854. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  6855. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  6856. bp->common.bc_ver = val;
  6857. BNX2X_DEV_INFO("bc_ver %X\n", val);
  6858. if (val < BNX2X_BC_VER) {
  6859. /* for now only warn
  6860. * later we might need to enforce this */
  6861. BNX2X_ERR("This driver needs bc_ver %X but found %X, "
  6862. "please upgrade BC\n", BNX2X_BC_VER, val);
  6863. }
  6864. bp->link_params.feature_config_flags |=
  6865. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  6866. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  6867. bp->link_params.feature_config_flags |=
  6868. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  6869. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  6870. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  6871. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  6872. BNX2X_DEV_INFO("%sWoL capable\n",
  6873. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  6874. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  6875. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  6876. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  6877. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  6878. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  6879. val, val2, val3, val4);
  6880. }
  6881. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  6882. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  6883. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  6884. {
  6885. int pfid = BP_FUNC(bp);
  6886. int vn = BP_E1HVN(bp);
  6887. int igu_sb_id;
  6888. u32 val;
  6889. u8 fid;
  6890. bp->igu_base_sb = 0xff;
  6891. bp->igu_sb_cnt = 0;
  6892. if (CHIP_INT_MODE_IS_BC(bp)) {
  6893. bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
  6894. NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
  6895. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  6896. FP_SB_MAX_E1x;
  6897. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  6898. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  6899. return;
  6900. }
  6901. /* IGU in normal mode - read CAM */
  6902. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  6903. igu_sb_id++) {
  6904. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  6905. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  6906. continue;
  6907. fid = IGU_FID(val);
  6908. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  6909. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  6910. continue;
  6911. if (IGU_VEC(val) == 0)
  6912. /* default status block */
  6913. bp->igu_dsb_id = igu_sb_id;
  6914. else {
  6915. if (bp->igu_base_sb == 0xff)
  6916. bp->igu_base_sb = igu_sb_id;
  6917. bp->igu_sb_cnt++;
  6918. }
  6919. }
  6920. }
  6921. /* It's expected that number of CAM entries for this
  6922. * functions is equal to the MSI-X table size (which was a
  6923. * used during bp->l2_cid_count value calculation.
  6924. * We want a harsh warning if these values are different!
  6925. */
  6926. WARN_ON(bp->igu_sb_cnt != NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
  6927. if (bp->igu_sb_cnt == 0)
  6928. BNX2X_ERR("CAM configuration error\n");
  6929. }
  6930. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  6931. u32 switch_cfg)
  6932. {
  6933. int cfg_size = 0, idx, port = BP_PORT(bp);
  6934. /* Aggregation of supported attributes of all external phys */
  6935. bp->port.supported[0] = 0;
  6936. bp->port.supported[1] = 0;
  6937. switch (bp->link_params.num_phys) {
  6938. case 1:
  6939. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  6940. cfg_size = 1;
  6941. break;
  6942. case 2:
  6943. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  6944. cfg_size = 1;
  6945. break;
  6946. case 3:
  6947. if (bp->link_params.multi_phy_config &
  6948. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  6949. bp->port.supported[1] =
  6950. bp->link_params.phy[EXT_PHY1].supported;
  6951. bp->port.supported[0] =
  6952. bp->link_params.phy[EXT_PHY2].supported;
  6953. } else {
  6954. bp->port.supported[0] =
  6955. bp->link_params.phy[EXT_PHY1].supported;
  6956. bp->port.supported[1] =
  6957. bp->link_params.phy[EXT_PHY2].supported;
  6958. }
  6959. cfg_size = 2;
  6960. break;
  6961. }
  6962. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  6963. BNX2X_ERR("NVRAM config error. BAD phy config."
  6964. "PHY1 config 0x%x, PHY2 config 0x%x\n",
  6965. SHMEM_RD(bp,
  6966. dev_info.port_hw_config[port].external_phy_config),
  6967. SHMEM_RD(bp,
  6968. dev_info.port_hw_config[port].external_phy_config2));
  6969. return;
  6970. }
  6971. if (CHIP_IS_E3(bp))
  6972. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  6973. else {
  6974. switch (switch_cfg) {
  6975. case SWITCH_CFG_1G:
  6976. bp->port.phy_addr = REG_RD(
  6977. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  6978. break;
  6979. case SWITCH_CFG_10G:
  6980. bp->port.phy_addr = REG_RD(
  6981. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  6982. break;
  6983. default:
  6984. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  6985. bp->port.link_config[0]);
  6986. return;
  6987. }
  6988. }
  6989. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  6990. /* mask what we support according to speed_cap_mask per configuration */
  6991. for (idx = 0; idx < cfg_size; idx++) {
  6992. if (!(bp->link_params.speed_cap_mask[idx] &
  6993. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  6994. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  6995. if (!(bp->link_params.speed_cap_mask[idx] &
  6996. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  6997. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  6998. if (!(bp->link_params.speed_cap_mask[idx] &
  6999. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  7000. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  7001. if (!(bp->link_params.speed_cap_mask[idx] &
  7002. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  7003. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  7004. if (!(bp->link_params.speed_cap_mask[idx] &
  7005. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  7006. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  7007. SUPPORTED_1000baseT_Full);
  7008. if (!(bp->link_params.speed_cap_mask[idx] &
  7009. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  7010. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  7011. if (!(bp->link_params.speed_cap_mask[idx] &
  7012. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  7013. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  7014. }
  7015. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  7016. bp->port.supported[1]);
  7017. }
  7018. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  7019. {
  7020. u32 link_config, idx, cfg_size = 0;
  7021. bp->port.advertising[0] = 0;
  7022. bp->port.advertising[1] = 0;
  7023. switch (bp->link_params.num_phys) {
  7024. case 1:
  7025. case 2:
  7026. cfg_size = 1;
  7027. break;
  7028. case 3:
  7029. cfg_size = 2;
  7030. break;
  7031. }
  7032. for (idx = 0; idx < cfg_size; idx++) {
  7033. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  7034. link_config = bp->port.link_config[idx];
  7035. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  7036. case PORT_FEATURE_LINK_SPEED_AUTO:
  7037. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  7038. bp->link_params.req_line_speed[idx] =
  7039. SPEED_AUTO_NEG;
  7040. bp->port.advertising[idx] |=
  7041. bp->port.supported[idx];
  7042. } else {
  7043. /* force 10G, no AN */
  7044. bp->link_params.req_line_speed[idx] =
  7045. SPEED_10000;
  7046. bp->port.advertising[idx] |=
  7047. (ADVERTISED_10000baseT_Full |
  7048. ADVERTISED_FIBRE);
  7049. continue;
  7050. }
  7051. break;
  7052. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  7053. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  7054. bp->link_params.req_line_speed[idx] =
  7055. SPEED_10;
  7056. bp->port.advertising[idx] |=
  7057. (ADVERTISED_10baseT_Full |
  7058. ADVERTISED_TP);
  7059. } else {
  7060. BNX2X_ERR("NVRAM config error. "
  7061. "Invalid link_config 0x%x"
  7062. " speed_cap_mask 0x%x\n",
  7063. link_config,
  7064. bp->link_params.speed_cap_mask[idx]);
  7065. return;
  7066. }
  7067. break;
  7068. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  7069. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  7070. bp->link_params.req_line_speed[idx] =
  7071. SPEED_10;
  7072. bp->link_params.req_duplex[idx] =
  7073. DUPLEX_HALF;
  7074. bp->port.advertising[idx] |=
  7075. (ADVERTISED_10baseT_Half |
  7076. ADVERTISED_TP);
  7077. } else {
  7078. BNX2X_ERR("NVRAM config error. "
  7079. "Invalid link_config 0x%x"
  7080. " speed_cap_mask 0x%x\n",
  7081. link_config,
  7082. bp->link_params.speed_cap_mask[idx]);
  7083. return;
  7084. }
  7085. break;
  7086. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  7087. if (bp->port.supported[idx] &
  7088. SUPPORTED_100baseT_Full) {
  7089. bp->link_params.req_line_speed[idx] =
  7090. SPEED_100;
  7091. bp->port.advertising[idx] |=
  7092. (ADVERTISED_100baseT_Full |
  7093. ADVERTISED_TP);
  7094. } else {
  7095. BNX2X_ERR("NVRAM config error. "
  7096. "Invalid link_config 0x%x"
  7097. " speed_cap_mask 0x%x\n",
  7098. link_config,
  7099. bp->link_params.speed_cap_mask[idx]);
  7100. return;
  7101. }
  7102. break;
  7103. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  7104. if (bp->port.supported[idx] &
  7105. SUPPORTED_100baseT_Half) {
  7106. bp->link_params.req_line_speed[idx] =
  7107. SPEED_100;
  7108. bp->link_params.req_duplex[idx] =
  7109. DUPLEX_HALF;
  7110. bp->port.advertising[idx] |=
  7111. (ADVERTISED_100baseT_Half |
  7112. ADVERTISED_TP);
  7113. } else {
  7114. BNX2X_ERR("NVRAM config error. "
  7115. "Invalid link_config 0x%x"
  7116. " speed_cap_mask 0x%x\n",
  7117. link_config,
  7118. bp->link_params.speed_cap_mask[idx]);
  7119. return;
  7120. }
  7121. break;
  7122. case PORT_FEATURE_LINK_SPEED_1G:
  7123. if (bp->port.supported[idx] &
  7124. SUPPORTED_1000baseT_Full) {
  7125. bp->link_params.req_line_speed[idx] =
  7126. SPEED_1000;
  7127. bp->port.advertising[idx] |=
  7128. (ADVERTISED_1000baseT_Full |
  7129. ADVERTISED_TP);
  7130. } else {
  7131. BNX2X_ERR("NVRAM config error. "
  7132. "Invalid link_config 0x%x"
  7133. " speed_cap_mask 0x%x\n",
  7134. link_config,
  7135. bp->link_params.speed_cap_mask[idx]);
  7136. return;
  7137. }
  7138. break;
  7139. case PORT_FEATURE_LINK_SPEED_2_5G:
  7140. if (bp->port.supported[idx] &
  7141. SUPPORTED_2500baseX_Full) {
  7142. bp->link_params.req_line_speed[idx] =
  7143. SPEED_2500;
  7144. bp->port.advertising[idx] |=
  7145. (ADVERTISED_2500baseX_Full |
  7146. ADVERTISED_TP);
  7147. } else {
  7148. BNX2X_ERR("NVRAM config error. "
  7149. "Invalid link_config 0x%x"
  7150. " speed_cap_mask 0x%x\n",
  7151. link_config,
  7152. bp->link_params.speed_cap_mask[idx]);
  7153. return;
  7154. }
  7155. break;
  7156. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  7157. if (bp->port.supported[idx] &
  7158. SUPPORTED_10000baseT_Full) {
  7159. bp->link_params.req_line_speed[idx] =
  7160. SPEED_10000;
  7161. bp->port.advertising[idx] |=
  7162. (ADVERTISED_10000baseT_Full |
  7163. ADVERTISED_FIBRE);
  7164. } else {
  7165. BNX2X_ERR("NVRAM config error. "
  7166. "Invalid link_config 0x%x"
  7167. " speed_cap_mask 0x%x\n",
  7168. link_config,
  7169. bp->link_params.speed_cap_mask[idx]);
  7170. return;
  7171. }
  7172. break;
  7173. case PORT_FEATURE_LINK_SPEED_20G:
  7174. bp->link_params.req_line_speed[idx] = SPEED_20000;
  7175. break;
  7176. default:
  7177. BNX2X_ERR("NVRAM config error. "
  7178. "BAD link speed link_config 0x%x\n",
  7179. link_config);
  7180. bp->link_params.req_line_speed[idx] =
  7181. SPEED_AUTO_NEG;
  7182. bp->port.advertising[idx] =
  7183. bp->port.supported[idx];
  7184. break;
  7185. }
  7186. bp->link_params.req_flow_ctrl[idx] = (link_config &
  7187. PORT_FEATURE_FLOW_CONTROL_MASK);
  7188. if ((bp->link_params.req_flow_ctrl[idx] ==
  7189. BNX2X_FLOW_CTRL_AUTO) &&
  7190. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  7191. bp->link_params.req_flow_ctrl[idx] =
  7192. BNX2X_FLOW_CTRL_NONE;
  7193. }
  7194. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
  7195. " 0x%x advertising 0x%x\n",
  7196. bp->link_params.req_line_speed[idx],
  7197. bp->link_params.req_duplex[idx],
  7198. bp->link_params.req_flow_ctrl[idx],
  7199. bp->port.advertising[idx]);
  7200. }
  7201. }
  7202. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  7203. {
  7204. mac_hi = cpu_to_be16(mac_hi);
  7205. mac_lo = cpu_to_be32(mac_lo);
  7206. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  7207. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  7208. }
  7209. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  7210. {
  7211. int port = BP_PORT(bp);
  7212. u32 config;
  7213. u32 ext_phy_type, ext_phy_config;
  7214. bp->link_params.bp = bp;
  7215. bp->link_params.port = port;
  7216. bp->link_params.lane_config =
  7217. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  7218. bp->link_params.speed_cap_mask[0] =
  7219. SHMEM_RD(bp,
  7220. dev_info.port_hw_config[port].speed_capability_mask);
  7221. bp->link_params.speed_cap_mask[1] =
  7222. SHMEM_RD(bp,
  7223. dev_info.port_hw_config[port].speed_capability_mask2);
  7224. bp->port.link_config[0] =
  7225. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  7226. bp->port.link_config[1] =
  7227. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  7228. bp->link_params.multi_phy_config =
  7229. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  7230. /* If the device is capable of WoL, set the default state according
  7231. * to the HW
  7232. */
  7233. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  7234. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  7235. (config & PORT_FEATURE_WOL_ENABLED));
  7236. BNX2X_DEV_INFO("lane_config 0x%08x "
  7237. "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  7238. bp->link_params.lane_config,
  7239. bp->link_params.speed_cap_mask[0],
  7240. bp->port.link_config[0]);
  7241. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  7242. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  7243. bnx2x_phy_probe(&bp->link_params);
  7244. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  7245. bnx2x_link_settings_requested(bp);
  7246. /*
  7247. * If connected directly, work with the internal PHY, otherwise, work
  7248. * with the external PHY
  7249. */
  7250. ext_phy_config =
  7251. SHMEM_RD(bp,
  7252. dev_info.port_hw_config[port].external_phy_config);
  7253. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  7254. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7255. bp->mdio.prtad = bp->port.phy_addr;
  7256. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  7257. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  7258. bp->mdio.prtad =
  7259. XGXS_EXT_PHY_ADDR(ext_phy_config);
  7260. /*
  7261. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  7262. * In MF mode, it is set to cover self test cases
  7263. */
  7264. if (IS_MF(bp))
  7265. bp->port.need_hw_lock = 1;
  7266. else
  7267. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  7268. bp->common.shmem_base,
  7269. bp->common.shmem2_base);
  7270. }
  7271. #ifdef BCM_CNIC
  7272. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  7273. {
  7274. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7275. drv_lic_key[BP_PORT(bp)].max_iscsi_conn);
  7276. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7277. drv_lic_key[BP_PORT(bp)].max_fcoe_conn);
  7278. /* Get the number of maximum allowed iSCSI and FCoE connections */
  7279. bp->cnic_eth_dev.max_iscsi_conn =
  7280. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  7281. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  7282. bp->cnic_eth_dev.max_fcoe_conn =
  7283. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  7284. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  7285. BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
  7286. bp->cnic_eth_dev.max_iscsi_conn,
  7287. bp->cnic_eth_dev.max_fcoe_conn);
  7288. /* If mamimum allowed number of connections is zero -
  7289. * disable the feature.
  7290. */
  7291. if (!bp->cnic_eth_dev.max_iscsi_conn)
  7292. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  7293. if (!bp->cnic_eth_dev.max_fcoe_conn)
  7294. bp->flags |= NO_FCOE_FLAG;
  7295. }
  7296. #endif
  7297. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  7298. {
  7299. u32 val, val2;
  7300. int func = BP_ABS_FUNC(bp);
  7301. int port = BP_PORT(bp);
  7302. #ifdef BCM_CNIC
  7303. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  7304. u8 *fip_mac = bp->fip_mac;
  7305. #endif
  7306. /* Zero primary MAC configuration */
  7307. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  7308. if (BP_NOMCP(bp)) {
  7309. BNX2X_ERROR("warning: random MAC workaround active\n");
  7310. random_ether_addr(bp->dev->dev_addr);
  7311. } else if (IS_MF(bp)) {
  7312. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  7313. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  7314. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  7315. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  7316. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  7317. #ifdef BCM_CNIC
  7318. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  7319. * FCoE MAC then the appropriate feature should be disabled.
  7320. */
  7321. if (IS_MF_SI(bp)) {
  7322. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  7323. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  7324. val2 = MF_CFG_RD(bp, func_ext_config[func].
  7325. iscsi_mac_addr_upper);
  7326. val = MF_CFG_RD(bp, func_ext_config[func].
  7327. iscsi_mac_addr_lower);
  7328. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  7329. BNX2X_DEV_INFO("Read iSCSI MAC: "
  7330. BNX2X_MAC_FMT"\n",
  7331. BNX2X_MAC_PRN_LIST(iscsi_mac));
  7332. } else
  7333. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  7334. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  7335. val2 = MF_CFG_RD(bp, func_ext_config[func].
  7336. fcoe_mac_addr_upper);
  7337. val = MF_CFG_RD(bp, func_ext_config[func].
  7338. fcoe_mac_addr_lower);
  7339. bnx2x_set_mac_buf(fip_mac, val, val2);
  7340. BNX2X_DEV_INFO("Read FCoE L2 MAC to "
  7341. BNX2X_MAC_FMT"\n",
  7342. BNX2X_MAC_PRN_LIST(fip_mac));
  7343. } else
  7344. bp->flags |= NO_FCOE_FLAG;
  7345. }
  7346. #endif
  7347. } else {
  7348. /* in SF read MACs from port configuration */
  7349. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  7350. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  7351. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  7352. #ifdef BCM_CNIC
  7353. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7354. iscsi_mac_upper);
  7355. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7356. iscsi_mac_lower);
  7357. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  7358. #endif
  7359. }
  7360. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  7361. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  7362. #ifdef BCM_CNIC
  7363. /* Set the FCoE MAC in modes other then MF_SI */
  7364. if (!CHIP_IS_E1x(bp)) {
  7365. if (IS_MF_SD(bp))
  7366. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  7367. else if (!IS_MF(bp))
  7368. memcpy(fip_mac, iscsi_mac, ETH_ALEN);
  7369. }
  7370. /* Disable iSCSI if MAC configuration is
  7371. * invalid.
  7372. */
  7373. if (!is_valid_ether_addr(iscsi_mac)) {
  7374. bp->flags |= NO_ISCSI_FLAG;
  7375. memset(iscsi_mac, 0, ETH_ALEN);
  7376. }
  7377. /* Disable FCoE if MAC configuration is
  7378. * invalid.
  7379. */
  7380. if (!is_valid_ether_addr(fip_mac)) {
  7381. bp->flags |= NO_FCOE_FLAG;
  7382. memset(bp->fip_mac, 0, ETH_ALEN);
  7383. }
  7384. #endif
  7385. if (!is_valid_ether_addr(bp->dev->dev_addr))
  7386. dev_err(&bp->pdev->dev,
  7387. "bad Ethernet MAC address configuration: "
  7388. BNX2X_MAC_FMT", change it manually before bringing up "
  7389. "the appropriate network interface\n",
  7390. BNX2X_MAC_PRN_LIST(bp->dev->dev_addr));
  7391. }
  7392. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  7393. {
  7394. int /*abs*/func = BP_ABS_FUNC(bp);
  7395. int vn;
  7396. u32 val = 0;
  7397. int rc = 0;
  7398. bnx2x_get_common_hwinfo(bp);
  7399. if (CHIP_IS_E1x(bp)) {
  7400. bp->common.int_block = INT_BLOCK_HC;
  7401. bp->igu_dsb_id = DEF_SB_IGU_ID;
  7402. bp->igu_base_sb = 0;
  7403. bp->igu_sb_cnt = min_t(u8, FP_SB_MAX_E1x,
  7404. NUM_IGU_SB_REQUIRED(bp->l2_cid_count));
  7405. } else {
  7406. bp->common.int_block = INT_BLOCK_IGU;
  7407. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7408. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  7409. int tout = 5000;
  7410. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  7411. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  7412. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  7413. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  7414. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  7415. tout--;
  7416. usleep_range(1000, 1000);
  7417. }
  7418. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  7419. dev_err(&bp->pdev->dev,
  7420. "FORCING Normal Mode failed!!!\n");
  7421. return -EPERM;
  7422. }
  7423. }
  7424. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  7425. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  7426. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  7427. } else
  7428. BNX2X_DEV_INFO("IGU Normal Mode\n");
  7429. bnx2x_get_igu_cam_info(bp);
  7430. }
  7431. /*
  7432. * set base FW non-default (fast path) status block id, this value is
  7433. * used to initialize the fw_sb_id saved on the fp/queue structure to
  7434. * determine the id used by the FW.
  7435. */
  7436. if (CHIP_IS_E1x(bp))
  7437. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  7438. else /*
  7439. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  7440. * the same queue are indicated on the same IGU SB). So we prefer
  7441. * FW and IGU SBs to be the same value.
  7442. */
  7443. bp->base_fw_ndsb = bp->igu_base_sb;
  7444. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  7445. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  7446. bp->igu_sb_cnt, bp->base_fw_ndsb);
  7447. /*
  7448. * Initialize MF configuration
  7449. */
  7450. bp->mf_ov = 0;
  7451. bp->mf_mode = 0;
  7452. vn = BP_E1HVN(bp);
  7453. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  7454. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  7455. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  7456. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  7457. if (SHMEM2_HAS(bp, mf_cfg_addr))
  7458. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  7459. else
  7460. bp->common.mf_cfg_base = bp->common.shmem_base +
  7461. offsetof(struct shmem_region, func_mb) +
  7462. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  7463. /*
  7464. * get mf configuration:
  7465. * 1. existence of MF configuration
  7466. * 2. MAC address must be legal (check only upper bytes)
  7467. * for Switch-Independent mode;
  7468. * OVLAN must be legal for Switch-Dependent mode
  7469. * 3. SF_MODE configures specific MF mode
  7470. */
  7471. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  7472. /* get mf configuration */
  7473. val = SHMEM_RD(bp,
  7474. dev_info.shared_feature_config.config);
  7475. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  7476. switch (val) {
  7477. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  7478. val = MF_CFG_RD(bp, func_mf_config[func].
  7479. mac_upper);
  7480. /* check for legal mac (upper bytes)*/
  7481. if (val != 0xffff) {
  7482. bp->mf_mode = MULTI_FUNCTION_SI;
  7483. bp->mf_config[vn] = MF_CFG_RD(bp,
  7484. func_mf_config[func].config);
  7485. } else
  7486. BNX2X_DEV_INFO("illegal MAC address "
  7487. "for SI\n");
  7488. break;
  7489. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  7490. /* get OV configuration */
  7491. val = MF_CFG_RD(bp,
  7492. func_mf_config[FUNC_0].e1hov_tag);
  7493. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  7494. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  7495. bp->mf_mode = MULTI_FUNCTION_SD;
  7496. bp->mf_config[vn] = MF_CFG_RD(bp,
  7497. func_mf_config[func].config);
  7498. } else
  7499. BNX2X_DEV_INFO("illegal OV for SD\n");
  7500. break;
  7501. default:
  7502. /* Unknown configuration: reset mf_config */
  7503. bp->mf_config[vn] = 0;
  7504. BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val);
  7505. }
  7506. }
  7507. BNX2X_DEV_INFO("%s function mode\n",
  7508. IS_MF(bp) ? "multi" : "single");
  7509. switch (bp->mf_mode) {
  7510. case MULTI_FUNCTION_SD:
  7511. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  7512. FUNC_MF_CFG_E1HOV_TAG_MASK;
  7513. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  7514. bp->mf_ov = val;
  7515. bp->path_has_ovlan = true;
  7516. BNX2X_DEV_INFO("MF OV for func %d is %d "
  7517. "(0x%04x)\n", func, bp->mf_ov,
  7518. bp->mf_ov);
  7519. } else {
  7520. dev_err(&bp->pdev->dev,
  7521. "No valid MF OV for func %d, "
  7522. "aborting\n", func);
  7523. return -EPERM;
  7524. }
  7525. break;
  7526. case MULTI_FUNCTION_SI:
  7527. BNX2X_DEV_INFO("func %d is in MF "
  7528. "switch-independent mode\n", func);
  7529. break;
  7530. default:
  7531. if (vn) {
  7532. dev_err(&bp->pdev->dev,
  7533. "VN %d is in a single function mode, "
  7534. "aborting\n", vn);
  7535. return -EPERM;
  7536. }
  7537. break;
  7538. }
  7539. /* check if other port on the path needs ovlan:
  7540. * Since MF configuration is shared between ports
  7541. * Possible mixed modes are only
  7542. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  7543. */
  7544. if (CHIP_MODE_IS_4_PORT(bp) &&
  7545. !bp->path_has_ovlan &&
  7546. !IS_MF(bp) &&
  7547. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  7548. u8 other_port = !BP_PORT(bp);
  7549. u8 other_func = BP_PATH(bp) + 2*other_port;
  7550. val = MF_CFG_RD(bp,
  7551. func_mf_config[other_func].e1hov_tag);
  7552. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  7553. bp->path_has_ovlan = true;
  7554. }
  7555. }
  7556. /* adjust igu_sb_cnt to MF for E1x */
  7557. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  7558. bp->igu_sb_cnt /= E1HVN_MAX;
  7559. /* port info */
  7560. bnx2x_get_port_hwinfo(bp);
  7561. if (!BP_NOMCP(bp)) {
  7562. bp->fw_seq =
  7563. (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  7564. DRV_MSG_SEQ_NUMBER_MASK);
  7565. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  7566. }
  7567. /* Get MAC addresses */
  7568. bnx2x_get_mac_hwinfo(bp);
  7569. #ifdef BCM_CNIC
  7570. bnx2x_get_cnic_info(bp);
  7571. #endif
  7572. /* Get current FW pulse sequence */
  7573. if (!BP_NOMCP(bp)) {
  7574. int mb_idx = BP_FW_MB_IDX(bp);
  7575. bp->fw_drv_pulse_wr_seq =
  7576. (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
  7577. DRV_PULSE_SEQ_MASK);
  7578. BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
  7579. }
  7580. return rc;
  7581. }
  7582. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  7583. {
  7584. int cnt, i, block_end, rodi;
  7585. char vpd_data[BNX2X_VPD_LEN+1];
  7586. char str_id_reg[VENDOR_ID_LEN+1];
  7587. char str_id_cap[VENDOR_ID_LEN+1];
  7588. u8 len;
  7589. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
  7590. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  7591. if (cnt < BNX2X_VPD_LEN)
  7592. goto out_not_found;
  7593. i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
  7594. PCI_VPD_LRDT_RO_DATA);
  7595. if (i < 0)
  7596. goto out_not_found;
  7597. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  7598. pci_vpd_lrdt_size(&vpd_data[i]);
  7599. i += PCI_VPD_LRDT_TAG_SIZE;
  7600. if (block_end > BNX2X_VPD_LEN)
  7601. goto out_not_found;
  7602. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  7603. PCI_VPD_RO_KEYWORD_MFR_ID);
  7604. if (rodi < 0)
  7605. goto out_not_found;
  7606. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  7607. if (len != VENDOR_ID_LEN)
  7608. goto out_not_found;
  7609. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  7610. /* vendor specific info */
  7611. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  7612. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  7613. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  7614. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  7615. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  7616. PCI_VPD_RO_KEYWORD_VENDOR0);
  7617. if (rodi >= 0) {
  7618. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  7619. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  7620. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  7621. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  7622. bp->fw_ver[len] = ' ';
  7623. }
  7624. }
  7625. return;
  7626. }
  7627. out_not_found:
  7628. return;
  7629. }
  7630. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  7631. {
  7632. u32 flags = 0;
  7633. if (CHIP_REV_IS_FPGA(bp))
  7634. SET_FLAGS(flags, MODE_FPGA);
  7635. else if (CHIP_REV_IS_EMUL(bp))
  7636. SET_FLAGS(flags, MODE_EMUL);
  7637. else
  7638. SET_FLAGS(flags, MODE_ASIC);
  7639. if (CHIP_MODE_IS_4_PORT(bp))
  7640. SET_FLAGS(flags, MODE_PORT4);
  7641. else
  7642. SET_FLAGS(flags, MODE_PORT2);
  7643. if (CHIP_IS_E2(bp))
  7644. SET_FLAGS(flags, MODE_E2);
  7645. else if (CHIP_IS_E3(bp)) {
  7646. SET_FLAGS(flags, MODE_E3);
  7647. if (CHIP_REV(bp) == CHIP_REV_Ax)
  7648. SET_FLAGS(flags, MODE_E3_A0);
  7649. else {/*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  7650. SET_FLAGS(flags, MODE_E3_B0);
  7651. SET_FLAGS(flags, MODE_COS_BC);
  7652. }
  7653. }
  7654. if (IS_MF(bp)) {
  7655. SET_FLAGS(flags, MODE_MF);
  7656. switch (bp->mf_mode) {
  7657. case MULTI_FUNCTION_SD:
  7658. SET_FLAGS(flags, MODE_MF_SD);
  7659. break;
  7660. case MULTI_FUNCTION_SI:
  7661. SET_FLAGS(flags, MODE_MF_SI);
  7662. break;
  7663. }
  7664. } else
  7665. SET_FLAGS(flags, MODE_SF);
  7666. #if defined(__LITTLE_ENDIAN)
  7667. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  7668. #else /*(__BIG_ENDIAN)*/
  7669. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  7670. #endif
  7671. INIT_MODE_FLAGS(bp) = flags;
  7672. }
  7673. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  7674. {
  7675. int func;
  7676. int timer_interval;
  7677. int rc;
  7678. mutex_init(&bp->port.phy_mutex);
  7679. mutex_init(&bp->fw_mb_mutex);
  7680. spin_lock_init(&bp->stats_lock);
  7681. #ifdef BCM_CNIC
  7682. mutex_init(&bp->cnic_mutex);
  7683. #endif
  7684. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  7685. INIT_DELAYED_WORK(&bp->reset_task, bnx2x_reset_task);
  7686. rc = bnx2x_get_hwinfo(bp);
  7687. if (rc)
  7688. return rc;
  7689. bnx2x_set_modes_bitmap(bp);
  7690. rc = bnx2x_alloc_mem_bp(bp);
  7691. if (rc)
  7692. return rc;
  7693. bnx2x_read_fwinfo(bp);
  7694. func = BP_FUNC(bp);
  7695. /* need to reset chip if undi was active */
  7696. if (!BP_NOMCP(bp))
  7697. bnx2x_undi_unload(bp);
  7698. if (CHIP_REV_IS_FPGA(bp))
  7699. dev_err(&bp->pdev->dev, "FPGA detected\n");
  7700. if (BP_NOMCP(bp) && (func == 0))
  7701. dev_err(&bp->pdev->dev, "MCP disabled, "
  7702. "must load devices in order!\n");
  7703. bp->multi_mode = multi_mode;
  7704. /* Set TPA flags */
  7705. if (disable_tpa) {
  7706. bp->flags &= ~TPA_ENABLE_FLAG;
  7707. bp->dev->features &= ~NETIF_F_LRO;
  7708. } else {
  7709. bp->flags |= TPA_ENABLE_FLAG;
  7710. bp->dev->features |= NETIF_F_LRO;
  7711. }
  7712. bp->disable_tpa = disable_tpa;
  7713. if (CHIP_IS_E1(bp))
  7714. bp->dropless_fc = 0;
  7715. else
  7716. bp->dropless_fc = dropless_fc;
  7717. bp->mrrs = mrrs;
  7718. bp->tx_ring_size = MAX_TX_AVAIL;
  7719. /* make sure that the numbers are in the right granularity */
  7720. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  7721. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  7722. timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
  7723. bp->current_interval = (poll ? poll : timer_interval);
  7724. init_timer(&bp->timer);
  7725. bp->timer.expires = jiffies + bp->current_interval;
  7726. bp->timer.data = (unsigned long) bp;
  7727. bp->timer.function = bnx2x_timer;
  7728. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  7729. bnx2x_dcbx_init_params(bp);
  7730. #ifdef BCM_CNIC
  7731. if (CHIP_IS_E1x(bp))
  7732. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  7733. else
  7734. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  7735. #endif
  7736. return rc;
  7737. }
  7738. /****************************************************************************
  7739. * General service functions
  7740. ****************************************************************************/
  7741. /*
  7742. * net_device service functions
  7743. */
  7744. /* called with rtnl_lock */
  7745. static int bnx2x_open(struct net_device *dev)
  7746. {
  7747. struct bnx2x *bp = netdev_priv(dev);
  7748. bool global = false;
  7749. int other_engine = BP_PATH(bp) ? 0 : 1;
  7750. u32 other_load_counter, load_counter;
  7751. netif_carrier_off(dev);
  7752. bnx2x_set_power_state(bp, PCI_D0);
  7753. other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
  7754. load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
  7755. /*
  7756. * If parity had happen during the unload, then attentions
  7757. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  7758. * want the first function loaded on the current engine to
  7759. * complete the recovery.
  7760. */
  7761. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  7762. bnx2x_chk_parity_attn(bp, &global, true))
  7763. do {
  7764. /*
  7765. * If there are attentions and they are in a global
  7766. * blocks, set the GLOBAL_RESET bit regardless whether
  7767. * it will be this function that will complete the
  7768. * recovery or not.
  7769. */
  7770. if (global)
  7771. bnx2x_set_reset_global(bp);
  7772. /*
  7773. * Only the first function on the current engine should
  7774. * try to recover in open. In case of attentions in
  7775. * global blocks only the first in the chip should try
  7776. * to recover.
  7777. */
  7778. if ((!load_counter &&
  7779. (!global || !other_load_counter)) &&
  7780. bnx2x_trylock_leader_lock(bp) &&
  7781. !bnx2x_leader_reset(bp)) {
  7782. netdev_info(bp->dev, "Recovered in open\n");
  7783. break;
  7784. }
  7785. /* recovery has failed... */
  7786. bnx2x_set_power_state(bp, PCI_D3hot);
  7787. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7788. netdev_err(bp->dev, "Recovery flow hasn't been properly"
  7789. " completed yet. Try again later. If u still see this"
  7790. " message after a few retries then power cycle is"
  7791. " required.\n");
  7792. return -EAGAIN;
  7793. } while (0);
  7794. bp->recovery_state = BNX2X_RECOVERY_DONE;
  7795. return bnx2x_nic_load(bp, LOAD_OPEN);
  7796. }
  7797. /* called with rtnl_lock */
  7798. static int bnx2x_close(struct net_device *dev)
  7799. {
  7800. struct bnx2x *bp = netdev_priv(dev);
  7801. /* Unload the driver, release IRQs */
  7802. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  7803. /* Power off */
  7804. bnx2x_set_power_state(bp, PCI_D3hot);
  7805. return 0;
  7806. }
  7807. static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  7808. struct bnx2x_mcast_ramrod_params *p)
  7809. {
  7810. int mc_count = netdev_mc_count(bp->dev);
  7811. struct bnx2x_mcast_list_elem *mc_mac =
  7812. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  7813. struct netdev_hw_addr *ha;
  7814. if (!mc_mac)
  7815. return -ENOMEM;
  7816. INIT_LIST_HEAD(&p->mcast_list);
  7817. netdev_for_each_mc_addr(ha, bp->dev) {
  7818. mc_mac->mac = bnx2x_mc_addr(ha);
  7819. list_add_tail(&mc_mac->link, &p->mcast_list);
  7820. mc_mac++;
  7821. }
  7822. p->mcast_list_len = mc_count;
  7823. return 0;
  7824. }
  7825. static inline void bnx2x_free_mcast_macs_list(
  7826. struct bnx2x_mcast_ramrod_params *p)
  7827. {
  7828. struct bnx2x_mcast_list_elem *mc_mac =
  7829. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  7830. link);
  7831. WARN_ON(!mc_mac);
  7832. kfree(mc_mac);
  7833. }
  7834. /**
  7835. * bnx2x_set_uc_list - configure a new unicast MACs list.
  7836. *
  7837. * @bp: driver handle
  7838. *
  7839. * We will use zero (0) as a MAC type for these MACs.
  7840. */
  7841. static inline int bnx2x_set_uc_list(struct bnx2x *bp)
  7842. {
  7843. int rc;
  7844. struct net_device *dev = bp->dev;
  7845. struct netdev_hw_addr *ha;
  7846. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  7847. unsigned long ramrod_flags = 0;
  7848. /* First schedule a cleanup up of old configuration */
  7849. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  7850. if (rc < 0) {
  7851. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  7852. return rc;
  7853. }
  7854. netdev_for_each_uc_addr(ha, dev) {
  7855. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  7856. BNX2X_UC_LIST_MAC, &ramrod_flags);
  7857. if (rc < 0) {
  7858. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  7859. rc);
  7860. return rc;
  7861. }
  7862. }
  7863. /* Execute the pending commands */
  7864. __set_bit(RAMROD_CONT, &ramrod_flags);
  7865. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  7866. BNX2X_UC_LIST_MAC, &ramrod_flags);
  7867. }
  7868. static inline int bnx2x_set_mc_list(struct bnx2x *bp)
  7869. {
  7870. struct net_device *dev = bp->dev;
  7871. struct bnx2x_mcast_ramrod_params rparam = {0};
  7872. int rc = 0;
  7873. rparam.mcast_obj = &bp->mcast_obj;
  7874. /* first, clear all configured multicast MACs */
  7875. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7876. if (rc < 0) {
  7877. BNX2X_ERR("Failed to clear multicast "
  7878. "configuration: %d\n", rc);
  7879. return rc;
  7880. }
  7881. /* then, configure a new MACs list */
  7882. if (netdev_mc_count(dev)) {
  7883. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  7884. if (rc) {
  7885. BNX2X_ERR("Failed to create multicast MACs "
  7886. "list: %d\n", rc);
  7887. return rc;
  7888. }
  7889. /* Now add the new MACs */
  7890. rc = bnx2x_config_mcast(bp, &rparam,
  7891. BNX2X_MCAST_CMD_ADD);
  7892. if (rc < 0)
  7893. BNX2X_ERR("Failed to set a new multicast "
  7894. "configuration: %d\n", rc);
  7895. bnx2x_free_mcast_macs_list(&rparam);
  7896. }
  7897. return rc;
  7898. }
  7899. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  7900. void bnx2x_set_rx_mode(struct net_device *dev)
  7901. {
  7902. struct bnx2x *bp = netdev_priv(dev);
  7903. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  7904. if (bp->state != BNX2X_STATE_OPEN) {
  7905. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  7906. return;
  7907. }
  7908. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  7909. if (dev->flags & IFF_PROMISC)
  7910. rx_mode = BNX2X_RX_MODE_PROMISC;
  7911. else if ((dev->flags & IFF_ALLMULTI) ||
  7912. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  7913. CHIP_IS_E1(bp)))
  7914. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  7915. else {
  7916. /* some multicasts */
  7917. if (bnx2x_set_mc_list(bp) < 0)
  7918. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  7919. if (bnx2x_set_uc_list(bp) < 0)
  7920. rx_mode = BNX2X_RX_MODE_PROMISC;
  7921. }
  7922. bp->rx_mode = rx_mode;
  7923. /* Schedule the rx_mode command */
  7924. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  7925. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7926. return;
  7927. }
  7928. bnx2x_set_storm_rx_mode(bp);
  7929. }
  7930. /* called with rtnl_lock */
  7931. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  7932. int devad, u16 addr)
  7933. {
  7934. struct bnx2x *bp = netdev_priv(netdev);
  7935. u16 value;
  7936. int rc;
  7937. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  7938. prtad, devad, addr);
  7939. /* The HW expects different devad if CL22 is used */
  7940. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  7941. bnx2x_acquire_phy_lock(bp);
  7942. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  7943. bnx2x_release_phy_lock(bp);
  7944. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  7945. if (!rc)
  7946. rc = value;
  7947. return rc;
  7948. }
  7949. /* called with rtnl_lock */
  7950. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  7951. u16 addr, u16 value)
  7952. {
  7953. struct bnx2x *bp = netdev_priv(netdev);
  7954. int rc;
  7955. DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
  7956. " value 0x%x\n", prtad, devad, addr, value);
  7957. /* The HW expects different devad if CL22 is used */
  7958. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  7959. bnx2x_acquire_phy_lock(bp);
  7960. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  7961. bnx2x_release_phy_lock(bp);
  7962. return rc;
  7963. }
  7964. /* called with rtnl_lock */
  7965. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  7966. {
  7967. struct bnx2x *bp = netdev_priv(dev);
  7968. struct mii_ioctl_data *mdio = if_mii(ifr);
  7969. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  7970. mdio->phy_id, mdio->reg_num, mdio->val_in);
  7971. if (!netif_running(dev))
  7972. return -EAGAIN;
  7973. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  7974. }
  7975. #ifdef CONFIG_NET_POLL_CONTROLLER
  7976. static void poll_bnx2x(struct net_device *dev)
  7977. {
  7978. struct bnx2x *bp = netdev_priv(dev);
  7979. disable_irq(bp->pdev->irq);
  7980. bnx2x_interrupt(bp->pdev->irq, dev);
  7981. enable_irq(bp->pdev->irq);
  7982. }
  7983. #endif
  7984. static const struct net_device_ops bnx2x_netdev_ops = {
  7985. .ndo_open = bnx2x_open,
  7986. .ndo_stop = bnx2x_close,
  7987. .ndo_start_xmit = bnx2x_start_xmit,
  7988. .ndo_select_queue = bnx2x_select_queue,
  7989. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  7990. .ndo_set_mac_address = bnx2x_change_mac_addr,
  7991. .ndo_validate_addr = eth_validate_addr,
  7992. .ndo_do_ioctl = bnx2x_ioctl,
  7993. .ndo_change_mtu = bnx2x_change_mtu,
  7994. .ndo_fix_features = bnx2x_fix_features,
  7995. .ndo_set_features = bnx2x_set_features,
  7996. .ndo_tx_timeout = bnx2x_tx_timeout,
  7997. #ifdef CONFIG_NET_POLL_CONTROLLER
  7998. .ndo_poll_controller = poll_bnx2x,
  7999. #endif
  8000. };
  8001. static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
  8002. {
  8003. struct device *dev = &bp->pdev->dev;
  8004. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  8005. bp->flags |= USING_DAC_FLAG;
  8006. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  8007. dev_err(dev, "dma_set_coherent_mask failed, "
  8008. "aborting\n");
  8009. return -EIO;
  8010. }
  8011. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  8012. dev_err(dev, "System does not support DMA, aborting\n");
  8013. return -EIO;
  8014. }
  8015. return 0;
  8016. }
  8017. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  8018. struct net_device *dev,
  8019. unsigned long board_type)
  8020. {
  8021. struct bnx2x *bp;
  8022. int rc;
  8023. SET_NETDEV_DEV(dev, &pdev->dev);
  8024. bp = netdev_priv(dev);
  8025. bp->dev = dev;
  8026. bp->pdev = pdev;
  8027. bp->flags = 0;
  8028. bp->pf_num = PCI_FUNC(pdev->devfn);
  8029. rc = pci_enable_device(pdev);
  8030. if (rc) {
  8031. dev_err(&bp->pdev->dev,
  8032. "Cannot enable PCI device, aborting\n");
  8033. goto err_out;
  8034. }
  8035. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  8036. dev_err(&bp->pdev->dev,
  8037. "Cannot find PCI device base address, aborting\n");
  8038. rc = -ENODEV;
  8039. goto err_out_disable;
  8040. }
  8041. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  8042. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  8043. " base address, aborting\n");
  8044. rc = -ENODEV;
  8045. goto err_out_disable;
  8046. }
  8047. if (atomic_read(&pdev->enable_cnt) == 1) {
  8048. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  8049. if (rc) {
  8050. dev_err(&bp->pdev->dev,
  8051. "Cannot obtain PCI resources, aborting\n");
  8052. goto err_out_disable;
  8053. }
  8054. pci_set_master(pdev);
  8055. pci_save_state(pdev);
  8056. }
  8057. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  8058. if (bp->pm_cap == 0) {
  8059. dev_err(&bp->pdev->dev,
  8060. "Cannot find power management capability, aborting\n");
  8061. rc = -EIO;
  8062. goto err_out_release;
  8063. }
  8064. bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  8065. if (bp->pcie_cap == 0) {
  8066. dev_err(&bp->pdev->dev,
  8067. "Cannot find PCI Express capability, aborting\n");
  8068. rc = -EIO;
  8069. goto err_out_release;
  8070. }
  8071. rc = bnx2x_set_coherency_mask(bp);
  8072. if (rc)
  8073. goto err_out_release;
  8074. dev->mem_start = pci_resource_start(pdev, 0);
  8075. dev->base_addr = dev->mem_start;
  8076. dev->mem_end = pci_resource_end(pdev, 0);
  8077. dev->irq = pdev->irq;
  8078. bp->regview = pci_ioremap_bar(pdev, 0);
  8079. if (!bp->regview) {
  8080. dev_err(&bp->pdev->dev,
  8081. "Cannot map register space, aborting\n");
  8082. rc = -ENOMEM;
  8083. goto err_out_release;
  8084. }
  8085. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  8086. min_t(u64, BNX2X_DB_SIZE(bp),
  8087. pci_resource_len(pdev, 2)));
  8088. if (!bp->doorbells) {
  8089. dev_err(&bp->pdev->dev,
  8090. "Cannot map doorbell space, aborting\n");
  8091. rc = -ENOMEM;
  8092. goto err_out_unmap;
  8093. }
  8094. bnx2x_set_power_state(bp, PCI_D0);
  8095. /* clean indirect addresses */
  8096. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  8097. PCICFG_VENDOR_ID_OFFSET);
  8098. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
  8099. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
  8100. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
  8101. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
  8102. /**
  8103. * Enable internal target-read (in case we are probed after PF FLR).
  8104. * Must be done prior to any BAR read access
  8105. */
  8106. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  8107. /* Reset the load counter */
  8108. bnx2x_clear_load_cnt(bp);
  8109. dev->watchdog_timeo = TX_TIMEOUT;
  8110. dev->netdev_ops = &bnx2x_netdev_ops;
  8111. bnx2x_set_ethtool_ops(dev);
  8112. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8113. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  8114. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX;
  8115. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8116. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  8117. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  8118. if (bp->flags & USING_DAC_FLAG)
  8119. dev->features |= NETIF_F_HIGHDMA;
  8120. /* Add Loopback capability to the device */
  8121. dev->hw_features |= NETIF_F_LOOPBACK;
  8122. #ifdef BCM_DCBNL
  8123. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  8124. #endif
  8125. /* get_port_hwinfo() will set prtad and mmds properly */
  8126. bp->mdio.prtad = MDIO_PRTAD_NONE;
  8127. bp->mdio.mmds = 0;
  8128. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8129. bp->mdio.dev = dev;
  8130. bp->mdio.mdio_read = bnx2x_mdio_read;
  8131. bp->mdio.mdio_write = bnx2x_mdio_write;
  8132. return 0;
  8133. err_out_unmap:
  8134. if (bp->regview) {
  8135. iounmap(bp->regview);
  8136. bp->regview = NULL;
  8137. }
  8138. if (bp->doorbells) {
  8139. iounmap(bp->doorbells);
  8140. bp->doorbells = NULL;
  8141. }
  8142. err_out_release:
  8143. if (atomic_read(&pdev->enable_cnt) == 1)
  8144. pci_release_regions(pdev);
  8145. err_out_disable:
  8146. pci_disable_device(pdev);
  8147. pci_set_drvdata(pdev, NULL);
  8148. err_out:
  8149. return rc;
  8150. }
  8151. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  8152. int *width, int *speed)
  8153. {
  8154. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  8155. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  8156. /* return value of 1=2.5GHz 2=5GHz */
  8157. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  8158. }
  8159. static int bnx2x_check_firmware(struct bnx2x *bp)
  8160. {
  8161. const struct firmware *firmware = bp->firmware;
  8162. struct bnx2x_fw_file_hdr *fw_hdr;
  8163. struct bnx2x_fw_file_section *sections;
  8164. u32 offset, len, num_ops;
  8165. u16 *ops_offsets;
  8166. int i;
  8167. const u8 *fw_ver;
  8168. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
  8169. return -EINVAL;
  8170. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  8171. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  8172. /* Make sure none of the offsets and sizes make us read beyond
  8173. * the end of the firmware data */
  8174. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  8175. offset = be32_to_cpu(sections[i].offset);
  8176. len = be32_to_cpu(sections[i].len);
  8177. if (offset + len > firmware->size) {
  8178. dev_err(&bp->pdev->dev,
  8179. "Section %d length is out of bounds\n", i);
  8180. return -EINVAL;
  8181. }
  8182. }
  8183. /* Likewise for the init_ops offsets */
  8184. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  8185. ops_offsets = (u16 *)(firmware->data + offset);
  8186. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  8187. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  8188. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  8189. dev_err(&bp->pdev->dev,
  8190. "Section offset %d is out of bounds\n", i);
  8191. return -EINVAL;
  8192. }
  8193. }
  8194. /* Check FW version */
  8195. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  8196. fw_ver = firmware->data + offset;
  8197. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  8198. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  8199. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  8200. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  8201. dev_err(&bp->pdev->dev,
  8202. "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  8203. fw_ver[0], fw_ver[1], fw_ver[2],
  8204. fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
  8205. BCM_5710_FW_MINOR_VERSION,
  8206. BCM_5710_FW_REVISION_VERSION,
  8207. BCM_5710_FW_ENGINEERING_VERSION);
  8208. return -EINVAL;
  8209. }
  8210. return 0;
  8211. }
  8212. static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  8213. {
  8214. const __be32 *source = (const __be32 *)_source;
  8215. u32 *target = (u32 *)_target;
  8216. u32 i;
  8217. for (i = 0; i < n/4; i++)
  8218. target[i] = be32_to_cpu(source[i]);
  8219. }
  8220. /*
  8221. Ops array is stored in the following format:
  8222. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  8223. */
  8224. static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  8225. {
  8226. const __be32 *source = (const __be32 *)_source;
  8227. struct raw_op *target = (struct raw_op *)_target;
  8228. u32 i, j, tmp;
  8229. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  8230. tmp = be32_to_cpu(source[j]);
  8231. target[i].op = (tmp >> 24) & 0xff;
  8232. target[i].offset = tmp & 0xffffff;
  8233. target[i].raw_data = be32_to_cpu(source[j + 1]);
  8234. }
  8235. }
  8236. /**
  8237. * IRO array is stored in the following format:
  8238. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  8239. */
  8240. static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  8241. {
  8242. const __be32 *source = (const __be32 *)_source;
  8243. struct iro *target = (struct iro *)_target;
  8244. u32 i, j, tmp;
  8245. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  8246. target[i].base = be32_to_cpu(source[j]);
  8247. j++;
  8248. tmp = be32_to_cpu(source[j]);
  8249. target[i].m1 = (tmp >> 16) & 0xffff;
  8250. target[i].m2 = tmp & 0xffff;
  8251. j++;
  8252. tmp = be32_to_cpu(source[j]);
  8253. target[i].m3 = (tmp >> 16) & 0xffff;
  8254. target[i].size = tmp & 0xffff;
  8255. j++;
  8256. }
  8257. }
  8258. static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  8259. {
  8260. const __be16 *source = (const __be16 *)_source;
  8261. u16 *target = (u16 *)_target;
  8262. u32 i;
  8263. for (i = 0; i < n/2; i++)
  8264. target[i] = be16_to_cpu(source[i]);
  8265. }
  8266. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  8267. do { \
  8268. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  8269. bp->arr = kmalloc(len, GFP_KERNEL); \
  8270. if (!bp->arr) { \
  8271. pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
  8272. goto lbl; \
  8273. } \
  8274. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  8275. (u8 *)bp->arr, len); \
  8276. } while (0)
  8277. int bnx2x_init_firmware(struct bnx2x *bp)
  8278. {
  8279. const char *fw_file_name;
  8280. struct bnx2x_fw_file_hdr *fw_hdr;
  8281. int rc;
  8282. if (CHIP_IS_E1(bp))
  8283. fw_file_name = FW_FILE_NAME_E1;
  8284. else if (CHIP_IS_E1H(bp))
  8285. fw_file_name = FW_FILE_NAME_E1H;
  8286. else if (!CHIP_IS_E1x(bp))
  8287. fw_file_name = FW_FILE_NAME_E2;
  8288. else {
  8289. BNX2X_ERR("Unsupported chip revision\n");
  8290. return -EINVAL;
  8291. }
  8292. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  8293. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  8294. if (rc) {
  8295. BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
  8296. goto request_firmware_exit;
  8297. }
  8298. rc = bnx2x_check_firmware(bp);
  8299. if (rc) {
  8300. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  8301. goto request_firmware_exit;
  8302. }
  8303. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  8304. /* Initialize the pointers to the init arrays */
  8305. /* Blob */
  8306. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  8307. /* Opcodes */
  8308. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  8309. /* Offsets */
  8310. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  8311. be16_to_cpu_n);
  8312. /* STORMs firmware */
  8313. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8314. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  8315. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  8316. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  8317. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8318. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  8319. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  8320. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  8321. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8322. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  8323. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  8324. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  8325. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8326. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  8327. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  8328. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  8329. /* IRO */
  8330. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  8331. return 0;
  8332. iro_alloc_err:
  8333. kfree(bp->init_ops_offsets);
  8334. init_offsets_alloc_err:
  8335. kfree(bp->init_ops);
  8336. init_ops_alloc_err:
  8337. kfree(bp->init_data);
  8338. request_firmware_exit:
  8339. release_firmware(bp->firmware);
  8340. return rc;
  8341. }
  8342. static void bnx2x_release_firmware(struct bnx2x *bp)
  8343. {
  8344. kfree(bp->init_ops_offsets);
  8345. kfree(bp->init_ops);
  8346. kfree(bp->init_data);
  8347. release_firmware(bp->firmware);
  8348. }
  8349. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  8350. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  8351. .init_hw_cmn = bnx2x_init_hw_common,
  8352. .init_hw_port = bnx2x_init_hw_port,
  8353. .init_hw_func = bnx2x_init_hw_func,
  8354. .reset_hw_cmn = bnx2x_reset_common,
  8355. .reset_hw_port = bnx2x_reset_port,
  8356. .reset_hw_func = bnx2x_reset_func,
  8357. .gunzip_init = bnx2x_gunzip_init,
  8358. .gunzip_end = bnx2x_gunzip_end,
  8359. .init_fw = bnx2x_init_firmware,
  8360. .release_fw = bnx2x_release_firmware,
  8361. };
  8362. void bnx2x__init_func_obj(struct bnx2x *bp)
  8363. {
  8364. /* Prepare DMAE related driver resources */
  8365. bnx2x_setup_dmae(bp);
  8366. bnx2x_init_func_obj(bp, &bp->func_obj,
  8367. bnx2x_sp(bp, func_rdata),
  8368. bnx2x_sp_mapping(bp, func_rdata),
  8369. &bnx2x_func_sp_drv);
  8370. }
  8371. /* must be called after sriov-enable */
  8372. static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp, int l2_cid_count)
  8373. {
  8374. int cid_count = L2_FP_COUNT(l2_cid_count);
  8375. #ifdef BCM_CNIC
  8376. cid_count += CNIC_CID_MAX;
  8377. #endif
  8378. return roundup(cid_count, QM_CID_ROUND);
  8379. }
  8380. /**
  8381. * bnx2x_pci_msix_table_size - get the size of the MSI-X table.
  8382. *
  8383. * @dev: pci device
  8384. *
  8385. */
  8386. static inline int bnx2x_pci_msix_table_size(struct pci_dev *pdev)
  8387. {
  8388. int pos;
  8389. u16 control;
  8390. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  8391. if (!pos)
  8392. return 0;
  8393. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  8394. return (control & PCI_MSIX_FLAGS_QSIZE) + 1;
  8395. }
  8396. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  8397. const struct pci_device_id *ent)
  8398. {
  8399. struct net_device *dev = NULL;
  8400. struct bnx2x *bp;
  8401. int pcie_width, pcie_speed;
  8402. int rc, cid_count;
  8403. switch (ent->driver_data) {
  8404. case BCM57710:
  8405. case BCM57711:
  8406. case BCM57711E:
  8407. case BCM57712:
  8408. case BCM57712_MF:
  8409. case BCM57800:
  8410. case BCM57800_MF:
  8411. case BCM57810:
  8412. case BCM57810_MF:
  8413. case BCM57840:
  8414. case BCM57840_MF:
  8415. /* The size requested for the MSI-X table corresponds to the
  8416. * actual amount of avaliable IGU/HC status blocks. It includes
  8417. * the default SB vector but we want cid_count to contain the
  8418. * amount of only non-default SBs, that's what '-1' stands for.
  8419. */
  8420. cid_count = bnx2x_pci_msix_table_size(pdev) - 1;
  8421. /* do not allow initial cid_count grow above 16
  8422. * since Special CIDs starts from this number
  8423. * use old FP_SB_MAX_E1x define for this matter
  8424. */
  8425. cid_count = min_t(int, FP_SB_MAX_E1x, cid_count);
  8426. WARN_ON(!cid_count);
  8427. break;
  8428. default:
  8429. pr_err("Unknown board_type (%ld), aborting\n",
  8430. ent->driver_data);
  8431. return -ENODEV;
  8432. }
  8433. cid_count += FCOE_CONTEXT_USE;
  8434. /* dev zeroed in init_etherdev */
  8435. dev = alloc_etherdev_mq(sizeof(*bp), cid_count);
  8436. if (!dev) {
  8437. dev_err(&pdev->dev, "Cannot allocate net device\n");
  8438. return -ENOMEM;
  8439. }
  8440. /* We don't need a Tx queue for a CNIC and an OOO Rx-only ring,
  8441. * so update a cid_count after a netdev allocation.
  8442. */
  8443. cid_count += CNIC_CONTEXT_USE;
  8444. bp = netdev_priv(dev);
  8445. bp->msg_enable = debug;
  8446. pci_set_drvdata(pdev, dev);
  8447. bp->l2_cid_count = cid_count;
  8448. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  8449. if (rc < 0) {
  8450. free_netdev(dev);
  8451. return rc;
  8452. }
  8453. BNX2X_DEV_INFO("cid_count=%d\n", cid_count);
  8454. rc = bnx2x_init_bp(bp);
  8455. if (rc)
  8456. goto init_one_exit;
  8457. /* calc qm_cid_count */
  8458. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp, cid_count);
  8459. #ifdef BCM_CNIC
  8460. /* disable FCOE L2 queue for E1x*/
  8461. if (CHIP_IS_E1x(bp))
  8462. bp->flags |= NO_FCOE_FLAG;
  8463. #endif
  8464. /* Configure interrupt mode: try to enable MSI-X/MSI if
  8465. * needed, set bp->num_queues appropriately.
  8466. */
  8467. bnx2x_set_int_mode(bp);
  8468. /* Add all NAPI objects */
  8469. bnx2x_add_all_napi(bp);
  8470. rc = register_netdev(dev);
  8471. if (rc) {
  8472. dev_err(&pdev->dev, "Cannot register net device\n");
  8473. goto init_one_exit;
  8474. }
  8475. #ifdef BCM_CNIC
  8476. if (!NO_FCOE(bp)) {
  8477. /* Add storage MAC address */
  8478. rtnl_lock();
  8479. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  8480. rtnl_unlock();
  8481. }
  8482. #endif
  8483. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  8484. netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
  8485. " IRQ %d, ", board_info[ent->driver_data].name,
  8486. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  8487. pcie_width,
  8488. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  8489. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  8490. "5GHz (Gen2)" : "2.5GHz",
  8491. dev->base_addr, bp->pdev->irq);
  8492. pr_cont("node addr %pM\n", dev->dev_addr);
  8493. return 0;
  8494. init_one_exit:
  8495. if (bp->regview)
  8496. iounmap(bp->regview);
  8497. if (bp->doorbells)
  8498. iounmap(bp->doorbells);
  8499. free_netdev(dev);
  8500. if (atomic_read(&pdev->enable_cnt) == 1)
  8501. pci_release_regions(pdev);
  8502. pci_disable_device(pdev);
  8503. pci_set_drvdata(pdev, NULL);
  8504. return rc;
  8505. }
  8506. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  8507. {
  8508. struct net_device *dev = pci_get_drvdata(pdev);
  8509. struct bnx2x *bp;
  8510. if (!dev) {
  8511. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  8512. return;
  8513. }
  8514. bp = netdev_priv(dev);
  8515. #ifdef BCM_CNIC
  8516. /* Delete storage MAC address */
  8517. if (!NO_FCOE(bp)) {
  8518. rtnl_lock();
  8519. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  8520. rtnl_unlock();
  8521. }
  8522. #endif
  8523. #ifdef BCM_DCBNL
  8524. /* Delete app tlvs from dcbnl */
  8525. bnx2x_dcbnl_update_applist(bp, true);
  8526. #endif
  8527. unregister_netdev(dev);
  8528. /* Delete all NAPI objects */
  8529. bnx2x_del_all_napi(bp);
  8530. /* Power on: we can't let PCI layer write to us while we are in D3 */
  8531. bnx2x_set_power_state(bp, PCI_D0);
  8532. /* Disable MSI/MSI-X */
  8533. bnx2x_disable_msi(bp);
  8534. /* Power off */
  8535. bnx2x_set_power_state(bp, PCI_D3hot);
  8536. /* Make sure RESET task is not scheduled before continuing */
  8537. cancel_delayed_work_sync(&bp->reset_task);
  8538. if (bp->regview)
  8539. iounmap(bp->regview);
  8540. if (bp->doorbells)
  8541. iounmap(bp->doorbells);
  8542. bnx2x_free_mem_bp(bp);
  8543. free_netdev(dev);
  8544. if (atomic_read(&pdev->enable_cnt) == 1)
  8545. pci_release_regions(pdev);
  8546. pci_disable_device(pdev);
  8547. pci_set_drvdata(pdev, NULL);
  8548. }
  8549. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  8550. {
  8551. int i;
  8552. bp->state = BNX2X_STATE_ERROR;
  8553. bp->rx_mode = BNX2X_RX_MODE_NONE;
  8554. #ifdef BCM_CNIC
  8555. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  8556. #endif
  8557. /* Stop Tx */
  8558. bnx2x_tx_disable(bp);
  8559. bnx2x_netif_stop(bp, 0);
  8560. del_timer_sync(&bp->timer);
  8561. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  8562. /* Release IRQs */
  8563. bnx2x_free_irq(bp);
  8564. /* Free SKBs, SGEs, TPA pool and driver internals */
  8565. bnx2x_free_skbs(bp);
  8566. for_each_rx_queue(bp, i)
  8567. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  8568. bnx2x_free_mem(bp);
  8569. bp->state = BNX2X_STATE_CLOSED;
  8570. netif_carrier_off(bp->dev);
  8571. return 0;
  8572. }
  8573. static void bnx2x_eeh_recover(struct bnx2x *bp)
  8574. {
  8575. u32 val;
  8576. mutex_init(&bp->port.phy_mutex);
  8577. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  8578. bp->link_params.shmem_base = bp->common.shmem_base;
  8579. BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
  8580. if (!bp->common.shmem_base ||
  8581. (bp->common.shmem_base < 0xA0000) ||
  8582. (bp->common.shmem_base >= 0xC0000)) {
  8583. BNX2X_DEV_INFO("MCP not active\n");
  8584. bp->flags |= NO_MCP_FLAG;
  8585. return;
  8586. }
  8587. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  8588. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  8589. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  8590. BNX2X_ERR("BAD MCP validity signature\n");
  8591. if (!BP_NOMCP(bp)) {
  8592. bp->fw_seq =
  8593. (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  8594. DRV_MSG_SEQ_NUMBER_MASK);
  8595. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  8596. }
  8597. }
  8598. /**
  8599. * bnx2x_io_error_detected - called when PCI error is detected
  8600. * @pdev: Pointer to PCI device
  8601. * @state: The current pci connection state
  8602. *
  8603. * This function is called after a PCI bus error affecting
  8604. * this device has been detected.
  8605. */
  8606. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  8607. pci_channel_state_t state)
  8608. {
  8609. struct net_device *dev = pci_get_drvdata(pdev);
  8610. struct bnx2x *bp = netdev_priv(dev);
  8611. rtnl_lock();
  8612. netif_device_detach(dev);
  8613. if (state == pci_channel_io_perm_failure) {
  8614. rtnl_unlock();
  8615. return PCI_ERS_RESULT_DISCONNECT;
  8616. }
  8617. if (netif_running(dev))
  8618. bnx2x_eeh_nic_unload(bp);
  8619. pci_disable_device(pdev);
  8620. rtnl_unlock();
  8621. /* Request a slot reset */
  8622. return PCI_ERS_RESULT_NEED_RESET;
  8623. }
  8624. /**
  8625. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  8626. * @pdev: Pointer to PCI device
  8627. *
  8628. * Restart the card from scratch, as if from a cold-boot.
  8629. */
  8630. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  8631. {
  8632. struct net_device *dev = pci_get_drvdata(pdev);
  8633. struct bnx2x *bp = netdev_priv(dev);
  8634. rtnl_lock();
  8635. if (pci_enable_device(pdev)) {
  8636. dev_err(&pdev->dev,
  8637. "Cannot re-enable PCI device after reset\n");
  8638. rtnl_unlock();
  8639. return PCI_ERS_RESULT_DISCONNECT;
  8640. }
  8641. pci_set_master(pdev);
  8642. pci_restore_state(pdev);
  8643. if (netif_running(dev))
  8644. bnx2x_set_power_state(bp, PCI_D0);
  8645. rtnl_unlock();
  8646. return PCI_ERS_RESULT_RECOVERED;
  8647. }
  8648. /**
  8649. * bnx2x_io_resume - called when traffic can start flowing again
  8650. * @pdev: Pointer to PCI device
  8651. *
  8652. * This callback is called when the error recovery driver tells us that
  8653. * its OK to resume normal operation.
  8654. */
  8655. static void bnx2x_io_resume(struct pci_dev *pdev)
  8656. {
  8657. struct net_device *dev = pci_get_drvdata(pdev);
  8658. struct bnx2x *bp = netdev_priv(dev);
  8659. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  8660. netdev_err(bp->dev, "Handling parity error recovery. "
  8661. "Try again later\n");
  8662. return;
  8663. }
  8664. rtnl_lock();
  8665. bnx2x_eeh_recover(bp);
  8666. if (netif_running(dev))
  8667. bnx2x_nic_load(bp, LOAD_NORMAL);
  8668. netif_device_attach(dev);
  8669. rtnl_unlock();
  8670. }
  8671. static struct pci_error_handlers bnx2x_err_handler = {
  8672. .error_detected = bnx2x_io_error_detected,
  8673. .slot_reset = bnx2x_io_slot_reset,
  8674. .resume = bnx2x_io_resume,
  8675. };
  8676. static struct pci_driver bnx2x_pci_driver = {
  8677. .name = DRV_MODULE_NAME,
  8678. .id_table = bnx2x_pci_tbl,
  8679. .probe = bnx2x_init_one,
  8680. .remove = __devexit_p(bnx2x_remove_one),
  8681. .suspend = bnx2x_suspend,
  8682. .resume = bnx2x_resume,
  8683. .err_handler = &bnx2x_err_handler,
  8684. };
  8685. static int __init bnx2x_init(void)
  8686. {
  8687. int ret;
  8688. pr_info("%s", version);
  8689. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  8690. if (bnx2x_wq == NULL) {
  8691. pr_err("Cannot create workqueue\n");
  8692. return -ENOMEM;
  8693. }
  8694. ret = pci_register_driver(&bnx2x_pci_driver);
  8695. if (ret) {
  8696. pr_err("Cannot register driver\n");
  8697. destroy_workqueue(bnx2x_wq);
  8698. }
  8699. return ret;
  8700. }
  8701. static void __exit bnx2x_cleanup(void)
  8702. {
  8703. pci_unregister_driver(&bnx2x_pci_driver);
  8704. destroy_workqueue(bnx2x_wq);
  8705. }
  8706. module_init(bnx2x_init);
  8707. module_exit(bnx2x_cleanup);
  8708. #ifdef BCM_CNIC
  8709. /**
  8710. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  8711. *
  8712. * @bp: driver handle
  8713. * @set: set or clear the CAM entry
  8714. *
  8715. * This function will wait until the ramdord completion returns.
  8716. * Return 0 if success, -ENODEV if ramrod doesn't return.
  8717. */
  8718. static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  8719. {
  8720. unsigned long ramrod_flags = 0;
  8721. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  8722. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  8723. &bp->iscsi_l2_mac_obj, true,
  8724. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  8725. }
  8726. /* count denotes the number of new completions we have seen */
  8727. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  8728. {
  8729. struct eth_spe *spe;
  8730. #ifdef BNX2X_STOP_ON_ERROR
  8731. if (unlikely(bp->panic))
  8732. return;
  8733. #endif
  8734. spin_lock_bh(&bp->spq_lock);
  8735. BUG_ON(bp->cnic_spq_pending < count);
  8736. bp->cnic_spq_pending -= count;
  8737. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  8738. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  8739. & SPE_HDR_CONN_TYPE) >>
  8740. SPE_HDR_CONN_TYPE_SHIFT;
  8741. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  8742. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  8743. /* Set validation for iSCSI L2 client before sending SETUP
  8744. * ramrod
  8745. */
  8746. if (type == ETH_CONNECTION_TYPE) {
  8747. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
  8748. bnx2x_set_ctx_validation(bp, &bp->context.
  8749. vcxt[BNX2X_ISCSI_ETH_CID].eth,
  8750. BNX2X_ISCSI_ETH_CID);
  8751. }
  8752. /*
  8753. * There may be not more than 8 L2, not more than 8 L5 SPEs
  8754. * and in the air. We also check that number of outstanding
  8755. * COMMON ramrods is not more than the EQ and SPQ can
  8756. * accommodate.
  8757. */
  8758. if (type == ETH_CONNECTION_TYPE) {
  8759. if (!atomic_read(&bp->cq_spq_left))
  8760. break;
  8761. else
  8762. atomic_dec(&bp->cq_spq_left);
  8763. } else if (type == NONE_CONNECTION_TYPE) {
  8764. if (!atomic_read(&bp->eq_spq_left))
  8765. break;
  8766. else
  8767. atomic_dec(&bp->eq_spq_left);
  8768. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  8769. (type == FCOE_CONNECTION_TYPE)) {
  8770. if (bp->cnic_spq_pending >=
  8771. bp->cnic_eth_dev.max_kwqe_pending)
  8772. break;
  8773. else
  8774. bp->cnic_spq_pending++;
  8775. } else {
  8776. BNX2X_ERR("Unknown SPE type: %d\n", type);
  8777. bnx2x_panic();
  8778. break;
  8779. }
  8780. spe = bnx2x_sp_get_next(bp);
  8781. *spe = *bp->cnic_kwq_cons;
  8782. DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
  8783. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  8784. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  8785. bp->cnic_kwq_cons = bp->cnic_kwq;
  8786. else
  8787. bp->cnic_kwq_cons++;
  8788. }
  8789. bnx2x_sp_prod_update(bp);
  8790. spin_unlock_bh(&bp->spq_lock);
  8791. }
  8792. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  8793. struct kwqe_16 *kwqes[], u32 count)
  8794. {
  8795. struct bnx2x *bp = netdev_priv(dev);
  8796. int i;
  8797. #ifdef BNX2X_STOP_ON_ERROR
  8798. if (unlikely(bp->panic))
  8799. return -EIO;
  8800. #endif
  8801. spin_lock_bh(&bp->spq_lock);
  8802. for (i = 0; i < count; i++) {
  8803. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  8804. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  8805. break;
  8806. *bp->cnic_kwq_prod = *spe;
  8807. bp->cnic_kwq_pending++;
  8808. DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
  8809. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  8810. spe->data.update_data_addr.hi,
  8811. spe->data.update_data_addr.lo,
  8812. bp->cnic_kwq_pending);
  8813. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  8814. bp->cnic_kwq_prod = bp->cnic_kwq;
  8815. else
  8816. bp->cnic_kwq_prod++;
  8817. }
  8818. spin_unlock_bh(&bp->spq_lock);
  8819. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  8820. bnx2x_cnic_sp_post(bp, 0);
  8821. return i;
  8822. }
  8823. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  8824. {
  8825. struct cnic_ops *c_ops;
  8826. int rc = 0;
  8827. mutex_lock(&bp->cnic_mutex);
  8828. c_ops = rcu_dereference_protected(bp->cnic_ops,
  8829. lockdep_is_held(&bp->cnic_mutex));
  8830. if (c_ops)
  8831. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  8832. mutex_unlock(&bp->cnic_mutex);
  8833. return rc;
  8834. }
  8835. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  8836. {
  8837. struct cnic_ops *c_ops;
  8838. int rc = 0;
  8839. rcu_read_lock();
  8840. c_ops = rcu_dereference(bp->cnic_ops);
  8841. if (c_ops)
  8842. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  8843. rcu_read_unlock();
  8844. return rc;
  8845. }
  8846. /*
  8847. * for commands that have no data
  8848. */
  8849. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  8850. {
  8851. struct cnic_ctl_info ctl = {0};
  8852. ctl.cmd = cmd;
  8853. return bnx2x_cnic_ctl_send(bp, &ctl);
  8854. }
  8855. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  8856. {
  8857. struct cnic_ctl_info ctl = {0};
  8858. /* first we tell CNIC and only then we count this as a completion */
  8859. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  8860. ctl.data.comp.cid = cid;
  8861. ctl.data.comp.error = err;
  8862. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  8863. bnx2x_cnic_sp_post(bp, 0);
  8864. }
  8865. /* Called with netif_addr_lock_bh() taken.
  8866. * Sets an rx_mode config for an iSCSI ETH client.
  8867. * Doesn't block.
  8868. * Completion should be checked outside.
  8869. */
  8870. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  8871. {
  8872. unsigned long accept_flags = 0, ramrod_flags = 0;
  8873. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  8874. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  8875. if (start) {
  8876. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  8877. * because it's the only way for UIO Queue to accept
  8878. * multicasts (in non-promiscuous mode only one Queue per
  8879. * function will receive multicast packets (leading in our
  8880. * case).
  8881. */
  8882. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  8883. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  8884. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  8885. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  8886. /* Clear STOP_PENDING bit if START is requested */
  8887. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  8888. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  8889. } else
  8890. /* Clear START_PENDING bit if STOP is requested */
  8891. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  8892. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  8893. set_bit(sched_state, &bp->sp_state);
  8894. else {
  8895. __set_bit(RAMROD_RX, &ramrod_flags);
  8896. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  8897. ramrod_flags);
  8898. }
  8899. }
  8900. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  8901. {
  8902. struct bnx2x *bp = netdev_priv(dev);
  8903. int rc = 0;
  8904. switch (ctl->cmd) {
  8905. case DRV_CTL_CTXTBL_WR_CMD: {
  8906. u32 index = ctl->data.io.offset;
  8907. dma_addr_t addr = ctl->data.io.dma_addr;
  8908. bnx2x_ilt_wr(bp, index, addr);
  8909. break;
  8910. }
  8911. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  8912. int count = ctl->data.credit.credit_count;
  8913. bnx2x_cnic_sp_post(bp, count);
  8914. break;
  8915. }
  8916. /* rtnl_lock is held. */
  8917. case DRV_CTL_START_L2_CMD: {
  8918. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  8919. unsigned long sp_bits = 0;
  8920. /* Configure the iSCSI classification object */
  8921. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  8922. cp->iscsi_l2_client_id,
  8923. cp->iscsi_l2_cid, BP_FUNC(bp),
  8924. bnx2x_sp(bp, mac_rdata),
  8925. bnx2x_sp_mapping(bp, mac_rdata),
  8926. BNX2X_FILTER_MAC_PENDING,
  8927. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  8928. &bp->macs_pool);
  8929. /* Set iSCSI MAC address */
  8930. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  8931. if (rc)
  8932. break;
  8933. mmiowb();
  8934. barrier();
  8935. /* Start accepting on iSCSI L2 ring */
  8936. netif_addr_lock_bh(dev);
  8937. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  8938. netif_addr_unlock_bh(dev);
  8939. /* bits to wait on */
  8940. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  8941. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  8942. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  8943. BNX2X_ERR("rx_mode completion timed out!\n");
  8944. break;
  8945. }
  8946. /* rtnl_lock is held. */
  8947. case DRV_CTL_STOP_L2_CMD: {
  8948. unsigned long sp_bits = 0;
  8949. /* Stop accepting on iSCSI L2 ring */
  8950. netif_addr_lock_bh(dev);
  8951. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  8952. netif_addr_unlock_bh(dev);
  8953. /* bits to wait on */
  8954. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  8955. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  8956. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  8957. BNX2X_ERR("rx_mode completion timed out!\n");
  8958. mmiowb();
  8959. barrier();
  8960. /* Unset iSCSI L2 MAC */
  8961. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  8962. BNX2X_ISCSI_ETH_MAC, true);
  8963. break;
  8964. }
  8965. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  8966. int count = ctl->data.credit.credit_count;
  8967. smp_mb__before_atomic_inc();
  8968. atomic_add(count, &bp->cq_spq_left);
  8969. smp_mb__after_atomic_inc();
  8970. break;
  8971. }
  8972. default:
  8973. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  8974. rc = -EINVAL;
  8975. }
  8976. return rc;
  8977. }
  8978. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  8979. {
  8980. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  8981. if (bp->flags & USING_MSIX_FLAG) {
  8982. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  8983. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  8984. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  8985. } else {
  8986. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  8987. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  8988. }
  8989. if (!CHIP_IS_E1x(bp))
  8990. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  8991. else
  8992. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  8993. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  8994. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  8995. cp->irq_arr[1].status_blk = bp->def_status_blk;
  8996. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  8997. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  8998. cp->num_irq = 2;
  8999. }
  9000. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  9001. void *data)
  9002. {
  9003. struct bnx2x *bp = netdev_priv(dev);
  9004. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9005. if (ops == NULL)
  9006. return -EINVAL;
  9007. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  9008. if (!bp->cnic_kwq)
  9009. return -ENOMEM;
  9010. bp->cnic_kwq_cons = bp->cnic_kwq;
  9011. bp->cnic_kwq_prod = bp->cnic_kwq;
  9012. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  9013. bp->cnic_spq_pending = 0;
  9014. bp->cnic_kwq_pending = 0;
  9015. bp->cnic_data = data;
  9016. cp->num_irq = 0;
  9017. cp->drv_state |= CNIC_DRV_STATE_REGD;
  9018. cp->iro_arr = bp->iro_arr;
  9019. bnx2x_setup_cnic_irq_info(bp);
  9020. rcu_assign_pointer(bp->cnic_ops, ops);
  9021. return 0;
  9022. }
  9023. static int bnx2x_unregister_cnic(struct net_device *dev)
  9024. {
  9025. struct bnx2x *bp = netdev_priv(dev);
  9026. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9027. mutex_lock(&bp->cnic_mutex);
  9028. cp->drv_state = 0;
  9029. rcu_assign_pointer(bp->cnic_ops, NULL);
  9030. mutex_unlock(&bp->cnic_mutex);
  9031. synchronize_rcu();
  9032. kfree(bp->cnic_kwq);
  9033. bp->cnic_kwq = NULL;
  9034. return 0;
  9035. }
  9036. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  9037. {
  9038. struct bnx2x *bp = netdev_priv(dev);
  9039. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9040. /* If both iSCSI and FCoE are disabled - return NULL in
  9041. * order to indicate CNIC that it should not try to work
  9042. * with this device.
  9043. */
  9044. if (NO_ISCSI(bp) && NO_FCOE(bp))
  9045. return NULL;
  9046. cp->drv_owner = THIS_MODULE;
  9047. cp->chip_id = CHIP_ID(bp);
  9048. cp->pdev = bp->pdev;
  9049. cp->io_base = bp->regview;
  9050. cp->io_base2 = bp->doorbells;
  9051. cp->max_kwqe_pending = 8;
  9052. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  9053. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  9054. bnx2x_cid_ilt_lines(bp);
  9055. cp->ctx_tbl_len = CNIC_ILT_LINES;
  9056. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  9057. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  9058. cp->drv_ctl = bnx2x_drv_ctl;
  9059. cp->drv_register_cnic = bnx2x_register_cnic;
  9060. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  9061. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
  9062. cp->iscsi_l2_client_id =
  9063. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9064. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
  9065. if (NO_ISCSI_OOO(bp))
  9066. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  9067. if (NO_ISCSI(bp))
  9068. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  9069. if (NO_FCOE(bp))
  9070. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  9071. DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
  9072. "starting cid %d\n",
  9073. cp->ctx_blk_size,
  9074. cp->ctx_tbl_offset,
  9075. cp->ctx_tbl_len,
  9076. cp->starting_cid);
  9077. return cp;
  9078. }
  9079. EXPORT_SYMBOL(bnx2x_cnic_probe);
  9080. #endif /* BCM_CNIC */