bnx2x_main.c 320 KB

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