bnx2x_main.c 301 KB

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