bnx2x_main.c 418 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461
  1. /* bnx2x_main.c: QLogic Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. * Copyright (c) 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  12. * Written by: Eliezer Tamir
  13. * Based on code from Michael Chan's bnx2 driver
  14. * UDP CSUM errata workaround by Arik Gendelman
  15. * Slowpath and fastpath rework by Vladislav Zolotarov
  16. * Statistics and Link management by Yitchak Gertner
  17. *
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/kernel.h>
  23. #include <linux/device.h> /* for dev_info() */
  24. #include <linux/timer.h>
  25. #include <linux/errno.h>
  26. #include <linux/ioport.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/pci.h>
  30. #include <linux/aer.h>
  31. #include <linux/init.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/bitops.h>
  37. #include <linux/irq.h>
  38. #include <linux/delay.h>
  39. #include <asm/byteorder.h>
  40. #include <linux/time.h>
  41. #include <linux/ethtool.h>
  42. #include <linux/mii.h>
  43. #include <linux/if_vlan.h>
  44. #include <linux/crash_dump.h>
  45. #include <net/ip.h>
  46. #include <net/ipv6.h>
  47. #include <net/tcp.h>
  48. #include <net/vxlan.h>
  49. #include <net/checksum.h>
  50. #include <net/ip6_checksum.h>
  51. #include <linux/workqueue.h>
  52. #include <linux/crc32.h>
  53. #include <linux/crc32c.h>
  54. #include <linux/prefetch.h>
  55. #include <linux/zlib.h>
  56. #include <linux/io.h>
  57. #include <linux/semaphore.h>
  58. #include <linux/stringify.h>
  59. #include <linux/vmalloc.h>
  60. #include "bnx2x.h"
  61. #include "bnx2x_init.h"
  62. #include "bnx2x_init_ops.h"
  63. #include "bnx2x_cmn.h"
  64. #include "bnx2x_vfpf.h"
  65. #include "bnx2x_dcb.h"
  66. #include "bnx2x_sp.h"
  67. #include <linux/firmware.h>
  68. #include "bnx2x_fw_file_hdr.h"
  69. /* FW files */
  70. /*(DEBLOBBED)*/
  71. #define FW_FILE_NAME_E1 "/*(DEBLOBBED)*/"
  72. #define FW_FILE_NAME_E1H "/*(DEBLOBBED)*/"
  73. #define FW_FILE_NAME_E2 "/*(DEBLOBBED)*/"
  74. #define bnx2x_init_block(bp, start, end) \
  75. return (printk(KERN_ERR "%s: Missing Free firmware\n", bp->dev->name),\
  76. -EINVAL)
  77. /* Time in jiffies before concluding the transmitter is hung */
  78. #define TX_TIMEOUT (5*HZ)
  79. static char version[] =
  80. "QLogic 5771x/578xx 10/20-Gigabit Ethernet Driver "
  81. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  82. MODULE_AUTHOR("Eliezer Tamir");
  83. MODULE_DESCRIPTION("QLogic "
  84. "BCM57710/57711/57711E/"
  85. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  86. "57840/57840_MF Driver");
  87. MODULE_LICENSE("GPL");
  88. MODULE_VERSION(DRV_MODULE_VERSION);
  89. /*(DEBLOBBED)*/
  90. int bnx2x_num_queues;
  91. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  92. MODULE_PARM_DESC(num_queues,
  93. " Set number of queues (default is as a number of CPUs)");
  94. static int disable_tpa;
  95. module_param(disable_tpa, int, S_IRUGO);
  96. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  97. static int int_mode;
  98. module_param(int_mode, int, S_IRUGO);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, S_IRUGO);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, S_IRUGO);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, S_IRUGO);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. static struct workqueue_struct *bnx2x_wq;
  111. struct workqueue_struct *bnx2x_iov_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr[2];
  118. u32 umac_val[2];
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "QLogic BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "QLogic BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "QLogic BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "QLogic BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "QLogic BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "QLogic BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "QLogic BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "QLogic BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "QLogic BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "QLogic BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "QLogic BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "QLogic BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "QLogic BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "QLogic BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "QLogic BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "QLogic BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "QLogic BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static const struct pci_device_id bnx2x_pci_tbl[] = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  253. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  255. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  256. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  257. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  258. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  259. { 0 }
  260. };
  261. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  262. /* Global resources for unloading a previously loaded device */
  263. #define BNX2X_PREV_WAIT_NEEDED 1
  264. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  265. static LIST_HEAD(bnx2x_prev_list);
  266. /* Forward declaration */
  267. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  268. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  269. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  270. /****************************************************************************
  271. * General service functions
  272. ****************************************************************************/
  273. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  274. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  275. u32 addr, dma_addr_t mapping)
  276. {
  277. REG_WR(bp, addr, U64_LO(mapping));
  278. REG_WR(bp, addr + 4, U64_HI(mapping));
  279. }
  280. static void storm_memset_spq_addr(struct bnx2x *bp,
  281. dma_addr_t mapping, u16 abs_fid)
  282. {
  283. u32 addr = XSEM_REG_FAST_MEMORY +
  284. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  285. __storm_memset_dma_mapping(bp, addr, mapping);
  286. }
  287. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  288. u16 pf_id)
  289. {
  290. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  291. pf_id);
  292. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  293. pf_id);
  294. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  295. pf_id);
  296. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  297. pf_id);
  298. }
  299. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  300. u8 enable)
  301. {
  302. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  303. enable);
  304. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  305. enable);
  306. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  307. enable);
  308. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  309. enable);
  310. }
  311. static void storm_memset_eq_data(struct bnx2x *bp,
  312. struct event_ring_data *eq_data,
  313. u16 pfid)
  314. {
  315. size_t size = sizeof(struct event_ring_data);
  316. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  317. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  318. }
  319. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  320. u16 pfid)
  321. {
  322. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  323. REG_WR16(bp, addr, eq_prod);
  324. }
  325. /* used only at init
  326. * locking is done by mcp
  327. */
  328. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  329. {
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  331. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  332. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  333. PCICFG_VENDOR_ID_OFFSET);
  334. }
  335. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  336. {
  337. u32 val;
  338. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  339. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  340. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  341. PCICFG_VENDOR_ID_OFFSET);
  342. return val;
  343. }
  344. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  345. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  346. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  347. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  348. #define DMAE_DP_DST_NONE "dst_addr [none]"
  349. static void bnx2x_dp_dmae(struct bnx2x *bp,
  350. struct dmae_command *dmae, int msglvl)
  351. {
  352. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  353. int i;
  354. switch (dmae->opcode & DMAE_COMMAND_DST) {
  355. case DMAE_CMD_DST_PCI:
  356. if (src_type == DMAE_CMD_SRC_PCI)
  357. DP(msglvl, "DMAE: opcode 0x%08x\n"
  358. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  359. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  360. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  361. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  362. dmae->comp_addr_hi, dmae->comp_addr_lo,
  363. dmae->comp_val);
  364. else
  365. DP(msglvl, "DMAE: opcode 0x%08x\n"
  366. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  367. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  368. dmae->opcode, dmae->src_addr_lo >> 2,
  369. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  370. dmae->comp_addr_hi, dmae->comp_addr_lo,
  371. dmae->comp_val);
  372. break;
  373. case DMAE_CMD_DST_GRC:
  374. if (src_type == DMAE_CMD_SRC_PCI)
  375. DP(msglvl, "DMAE: opcode 0x%08x\n"
  376. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  377. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  378. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  379. dmae->len, dmae->dst_addr_lo >> 2,
  380. dmae->comp_addr_hi, dmae->comp_addr_lo,
  381. dmae->comp_val);
  382. else
  383. DP(msglvl, "DMAE: opcode 0x%08x\n"
  384. "src [%08x], len [%d*4], dst [%08x]\n"
  385. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  386. dmae->opcode, dmae->src_addr_lo >> 2,
  387. dmae->len, dmae->dst_addr_lo >> 2,
  388. dmae->comp_addr_hi, dmae->comp_addr_lo,
  389. dmae->comp_val);
  390. break;
  391. default:
  392. if (src_type == DMAE_CMD_SRC_PCI)
  393. DP(msglvl, "DMAE: opcode 0x%08x\n"
  394. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  395. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  396. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  397. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  398. dmae->comp_val);
  399. else
  400. DP(msglvl, "DMAE: opcode 0x%08x\n"
  401. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  402. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  403. dmae->opcode, dmae->src_addr_lo >> 2,
  404. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  405. dmae->comp_val);
  406. break;
  407. }
  408. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  409. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  410. i, *(((u32 *)dmae) + i));
  411. }
  412. /* copy command into DMAE command memory and set DMAE command go */
  413. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  414. {
  415. u32 cmd_offset;
  416. int i;
  417. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  418. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  419. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  420. }
  421. REG_WR(bp, dmae_reg_go_c[idx], 1);
  422. }
  423. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  424. {
  425. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  426. DMAE_CMD_C_ENABLE);
  427. }
  428. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  429. {
  430. return opcode & ~DMAE_CMD_SRC_RESET;
  431. }
  432. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  433. bool with_comp, u8 comp_type)
  434. {
  435. u32 opcode = 0;
  436. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  437. (dst_type << DMAE_COMMAND_DST_SHIFT));
  438. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  439. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  440. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  441. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  442. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  443. #ifdef __BIG_ENDIAN
  444. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  445. #else
  446. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  447. #endif
  448. if (with_comp)
  449. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  450. return opcode;
  451. }
  452. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  453. struct dmae_command *dmae,
  454. u8 src_type, u8 dst_type)
  455. {
  456. memset(dmae, 0, sizeof(struct dmae_command));
  457. /* set the opcode */
  458. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  459. true, DMAE_COMP_PCI);
  460. /* fill in the completion parameters */
  461. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  462. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  463. dmae->comp_val = DMAE_COMP_VAL;
  464. }
  465. /* issue a dmae command over the init-channel and wait for completion */
  466. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  467. u32 *comp)
  468. {
  469. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  470. int rc = 0;
  471. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  472. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  473. * as long as this code is called both from syscall context and
  474. * from ndo_set_rx_mode() flow that may be called from BH.
  475. */
  476. spin_lock_bh(&bp->dmae_lock);
  477. /* reset completion */
  478. *comp = 0;
  479. /* post the command on the channel used for initializations */
  480. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  481. /* wait for completion */
  482. udelay(5);
  483. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  484. if (!cnt ||
  485. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  486. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  487. BNX2X_ERR("DMAE timeout!\n");
  488. rc = DMAE_TIMEOUT;
  489. goto unlock;
  490. }
  491. cnt--;
  492. udelay(50);
  493. }
  494. if (*comp & DMAE_PCI_ERR_FLAG) {
  495. BNX2X_ERR("DMAE PCI error!\n");
  496. rc = DMAE_PCI_ERROR;
  497. }
  498. unlock:
  499. spin_unlock_bh(&bp->dmae_lock);
  500. return rc;
  501. }
  502. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  503. u32 len32)
  504. {
  505. int rc;
  506. struct dmae_command dmae;
  507. if (!bp->dmae_ready) {
  508. u32 *data = bnx2x_sp(bp, wb_data[0]);
  509. if (CHIP_IS_E1(bp))
  510. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  511. else
  512. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  513. return;
  514. }
  515. /* set opcode and fixed command fields */
  516. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  517. /* fill in addresses and len */
  518. dmae.src_addr_lo = U64_LO(dma_addr);
  519. dmae.src_addr_hi = U64_HI(dma_addr);
  520. dmae.dst_addr_lo = dst_addr >> 2;
  521. dmae.dst_addr_hi = 0;
  522. dmae.len = len32;
  523. /* issue the command and wait for completion */
  524. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  525. if (rc) {
  526. BNX2X_ERR("DMAE returned failure %d\n", rc);
  527. #ifdef BNX2X_STOP_ON_ERROR
  528. bnx2x_panic();
  529. #endif
  530. }
  531. }
  532. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  533. {
  534. int rc;
  535. struct dmae_command dmae;
  536. if (!bp->dmae_ready) {
  537. u32 *data = bnx2x_sp(bp, wb_data[0]);
  538. int i;
  539. if (CHIP_IS_E1(bp))
  540. for (i = 0; i < len32; i++)
  541. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  542. else
  543. for (i = 0; i < len32; i++)
  544. data[i] = REG_RD(bp, src_addr + i*4);
  545. return;
  546. }
  547. /* set opcode and fixed command fields */
  548. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  549. /* fill in addresses and len */
  550. dmae.src_addr_lo = src_addr >> 2;
  551. dmae.src_addr_hi = 0;
  552. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  553. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  554. dmae.len = len32;
  555. /* issue the command and wait for completion */
  556. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  557. if (rc) {
  558. BNX2X_ERR("DMAE returned failure %d\n", rc);
  559. #ifdef BNX2X_STOP_ON_ERROR
  560. bnx2x_panic();
  561. #endif
  562. }
  563. }
  564. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  565. u32 addr, u32 len)
  566. {
  567. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  568. int offset = 0;
  569. while (len > dmae_wr_max) {
  570. bnx2x_write_dmae(bp, phys_addr + offset,
  571. addr + offset, dmae_wr_max);
  572. offset += dmae_wr_max * 4;
  573. len -= dmae_wr_max;
  574. }
  575. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  576. }
  577. enum storms {
  578. XSTORM,
  579. TSTORM,
  580. CSTORM,
  581. USTORM,
  582. MAX_STORMS
  583. };
  584. #define STORMS_NUM 4
  585. #define REGS_IN_ENTRY 4
  586. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  587. enum storms storm,
  588. int entry)
  589. {
  590. switch (storm) {
  591. case XSTORM:
  592. return XSTORM_ASSERT_LIST_OFFSET(entry);
  593. case TSTORM:
  594. return TSTORM_ASSERT_LIST_OFFSET(entry);
  595. case CSTORM:
  596. return CSTORM_ASSERT_LIST_OFFSET(entry);
  597. case USTORM:
  598. return USTORM_ASSERT_LIST_OFFSET(entry);
  599. case MAX_STORMS:
  600. default:
  601. BNX2X_ERR("unknown storm\n");
  602. }
  603. return -EINVAL;
  604. }
  605. static int bnx2x_mc_assert(struct bnx2x *bp)
  606. {
  607. char last_idx;
  608. int i, j, rc = 0;
  609. enum storms storm;
  610. u32 regs[REGS_IN_ENTRY];
  611. u32 bar_storm_intmem[STORMS_NUM] = {
  612. BAR_XSTRORM_INTMEM,
  613. BAR_TSTRORM_INTMEM,
  614. BAR_CSTRORM_INTMEM,
  615. BAR_USTRORM_INTMEM
  616. };
  617. u32 storm_assert_list_index[STORMS_NUM] = {
  618. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  619. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  620. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  621. USTORM_ASSERT_LIST_INDEX_OFFSET
  622. };
  623. char *storms_string[STORMS_NUM] = {
  624. "XSTORM",
  625. "TSTORM",
  626. "CSTORM",
  627. "USTORM"
  628. };
  629. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  630. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  631. storm_assert_list_index[storm]);
  632. if (last_idx)
  633. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  634. storms_string[storm], last_idx);
  635. /* print the asserts */
  636. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  637. /* read a single assert entry */
  638. for (j = 0; j < REGS_IN_ENTRY; j++)
  639. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  640. bnx2x_get_assert_list_entry(bp,
  641. storm,
  642. i) +
  643. sizeof(u32) * j);
  644. /* log entry if it contains a valid assert */
  645. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  646. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  647. storms_string[storm], i, regs[3],
  648. regs[2], regs[1], regs[0]);
  649. rc++;
  650. } else {
  651. break;
  652. }
  653. }
  654. }
  655. BNX2X_ERR("Chip Revision: %s, /*(DEBLOBBED)*/\n",
  656. CHIP_IS_E1(bp) ? "everest1" :
  657. CHIP_IS_E1H(bp) ? "everest1h" :
  658. CHIP_IS_E2(bp) ? "everest2" : "everest3"/*(DEBLOBBED)*/);
  659. return rc;
  660. }
  661. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  662. #define SCRATCH_BUFFER_SIZE(bp) \
  663. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  664. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  665. {
  666. u32 addr, val;
  667. u32 mark, offset;
  668. __be32 data[9];
  669. int word;
  670. u32 trace_shmem_base;
  671. if (BP_NOMCP(bp)) {
  672. BNX2X_ERR("NO MCP - can not dump\n");
  673. return;
  674. }
  675. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  676. (bp->common.bc_ver & 0xff0000) >> 16,
  677. (bp->common.bc_ver & 0xff00) >> 8,
  678. (bp->common.bc_ver & 0xff));
  679. if (pci_channel_offline(bp->pdev)) {
  680. BNX2X_ERR("Cannot dump MCP info while in PCI error\n");
  681. return;
  682. }
  683. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  684. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  685. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  686. if (BP_PATH(bp) == 0)
  687. trace_shmem_base = bp->common.shmem_base;
  688. else
  689. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  690. /* sanity */
  691. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  692. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  693. SCRATCH_BUFFER_SIZE(bp)) {
  694. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  695. trace_shmem_base);
  696. return;
  697. }
  698. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  699. /* validate TRCB signature */
  700. mark = REG_RD(bp, addr);
  701. if (mark != MFW_TRACE_SIGNATURE) {
  702. BNX2X_ERR("Trace buffer signature is missing.");
  703. return ;
  704. }
  705. /* read cyclic buffer pointer */
  706. addr += 4;
  707. mark = REG_RD(bp, addr);
  708. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  709. if (mark >= trace_shmem_base || mark < addr + 4) {
  710. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  711. return;
  712. }
  713. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  714. printk("%s", lvl);
  715. /* dump buffer after the mark */
  716. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  717. for (word = 0; word < 8; word++)
  718. data[word] = htonl(REG_RD(bp, offset + 4*word));
  719. data[8] = 0x0;
  720. pr_cont("%s", (char *)data);
  721. }
  722. /* dump buffer before the mark */
  723. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  724. for (word = 0; word < 8; word++)
  725. data[word] = htonl(REG_RD(bp, offset + 4*word));
  726. data[8] = 0x0;
  727. pr_cont("%s", (char *)data);
  728. }
  729. printk("%s" "end of fw dump\n", lvl);
  730. }
  731. static void bnx2x_fw_dump(struct bnx2x *bp)
  732. {
  733. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  734. }
  735. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  736. {
  737. int port = BP_PORT(bp);
  738. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  739. u32 val = REG_RD(bp, addr);
  740. /* in E1 we must use only PCI configuration space to disable
  741. * MSI/MSIX capability
  742. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  743. */
  744. if (CHIP_IS_E1(bp)) {
  745. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  746. * Use mask register to prevent from HC sending interrupts
  747. * after we exit the function
  748. */
  749. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  750. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  751. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  752. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  753. } else
  754. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  755. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  756. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  757. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  758. DP(NETIF_MSG_IFDOWN,
  759. "write %x to HC %d (addr 0x%x)\n",
  760. val, port, addr);
  761. /* flush all outstanding writes */
  762. mmiowb();
  763. REG_WR(bp, addr, val);
  764. if (REG_RD(bp, addr) != val)
  765. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  766. }
  767. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  768. {
  769. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  770. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  771. IGU_PF_CONF_INT_LINE_EN |
  772. IGU_PF_CONF_ATTN_BIT_EN);
  773. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  774. /* flush all outstanding writes */
  775. mmiowb();
  776. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  777. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  778. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  779. }
  780. static void bnx2x_int_disable(struct bnx2x *bp)
  781. {
  782. if (bp->common.int_block == INT_BLOCK_HC)
  783. bnx2x_hc_int_disable(bp);
  784. else
  785. bnx2x_igu_int_disable(bp);
  786. }
  787. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  788. {
  789. int i;
  790. u16 j;
  791. struct hc_sp_status_block_data sp_sb_data;
  792. int func = BP_FUNC(bp);
  793. #ifdef BNX2X_STOP_ON_ERROR
  794. u16 start = 0, end = 0;
  795. u8 cos;
  796. #endif
  797. if (IS_PF(bp) && disable_int)
  798. bnx2x_int_disable(bp);
  799. bp->stats_state = STATS_STATE_DISABLED;
  800. bp->eth_stats.unrecoverable_error++;
  801. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  802. BNX2X_ERR("begin crash dump -----------------\n");
  803. /* Indices */
  804. /* Common */
  805. if (IS_PF(bp)) {
  806. struct host_sp_status_block *def_sb = bp->def_status_blk;
  807. int data_size, cstorm_offset;
  808. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  809. bp->def_idx, bp->def_att_idx, bp->attn_state,
  810. bp->spq_prod_idx, bp->stats_counter);
  811. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  812. def_sb->atten_status_block.attn_bits,
  813. def_sb->atten_status_block.attn_bits_ack,
  814. def_sb->atten_status_block.status_block_id,
  815. def_sb->atten_status_block.attn_bits_index);
  816. BNX2X_ERR(" def (");
  817. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  818. pr_cont("0x%x%s",
  819. def_sb->sp_sb.index_values[i],
  820. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  821. data_size = sizeof(struct hc_sp_status_block_data) /
  822. sizeof(u32);
  823. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  824. for (i = 0; i < data_size; i++)
  825. *((u32 *)&sp_sb_data + i) =
  826. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  827. i * sizeof(u32));
  828. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
  829. sp_sb_data.igu_sb_id,
  830. sp_sb_data.igu_seg_id,
  831. sp_sb_data.p_func.pf_id,
  832. sp_sb_data.p_func.vnic_id,
  833. sp_sb_data.p_func.vf_id,
  834. sp_sb_data.p_func.vf_valid,
  835. sp_sb_data.state);
  836. }
  837. for_each_eth_queue(bp, i) {
  838. struct bnx2x_fastpath *fp = &bp->fp[i];
  839. int loop;
  840. struct hc_status_block_data_e2 sb_data_e2;
  841. struct hc_status_block_data_e1x sb_data_e1x;
  842. struct hc_status_block_sm *hc_sm_p =
  843. CHIP_IS_E1x(bp) ?
  844. sb_data_e1x.common.state_machine :
  845. sb_data_e2.common.state_machine;
  846. struct hc_index_data *hc_index_p =
  847. CHIP_IS_E1x(bp) ?
  848. sb_data_e1x.index_data :
  849. sb_data_e2.index_data;
  850. u8 data_size, cos;
  851. u32 *sb_data_p;
  852. struct bnx2x_fp_txdata txdata;
  853. if (!bp->fp)
  854. break;
  855. if (!fp->rx_cons_sb)
  856. continue;
  857. /* Rx */
  858. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  859. i, fp->rx_bd_prod, fp->rx_bd_cons,
  860. fp->rx_comp_prod,
  861. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  862. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  863. fp->rx_sge_prod, fp->last_max_sge,
  864. le16_to_cpu(fp->fp_hc_idx));
  865. /* Tx */
  866. for_each_cos_in_tx_queue(fp, cos)
  867. {
  868. if (!fp->txdata_ptr[cos])
  869. break;
  870. txdata = *fp->txdata_ptr[cos];
  871. if (!txdata.tx_cons_sb)
  872. continue;
  873. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  874. i, txdata.tx_pkt_prod,
  875. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  876. txdata.tx_bd_cons,
  877. le16_to_cpu(*txdata.tx_cons_sb));
  878. }
  879. loop = CHIP_IS_E1x(bp) ?
  880. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  881. /* host sb data */
  882. if (IS_FCOE_FP(fp))
  883. continue;
  884. BNX2X_ERR(" run indexes (");
  885. for (j = 0; j < HC_SB_MAX_SM; j++)
  886. pr_cont("0x%x%s",
  887. fp->sb_running_index[j],
  888. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  889. BNX2X_ERR(" indexes (");
  890. for (j = 0; j < loop; j++)
  891. pr_cont("0x%x%s",
  892. fp->sb_index_values[j],
  893. (j == loop - 1) ? ")" : " ");
  894. /* VF cannot access FW refelection for status block */
  895. if (IS_VF(bp))
  896. continue;
  897. /* fw sb data */
  898. data_size = CHIP_IS_E1x(bp) ?
  899. sizeof(struct hc_status_block_data_e1x) :
  900. sizeof(struct hc_status_block_data_e2);
  901. data_size /= sizeof(u32);
  902. sb_data_p = CHIP_IS_E1x(bp) ?
  903. (u32 *)&sb_data_e1x :
  904. (u32 *)&sb_data_e2;
  905. /* copy sb data in here */
  906. for (j = 0; j < data_size; j++)
  907. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  908. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  909. j * sizeof(u32));
  910. if (!CHIP_IS_E1x(bp)) {
  911. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  912. sb_data_e2.common.p_func.pf_id,
  913. sb_data_e2.common.p_func.vf_id,
  914. sb_data_e2.common.p_func.vf_valid,
  915. sb_data_e2.common.p_func.vnic_id,
  916. sb_data_e2.common.same_igu_sb_1b,
  917. sb_data_e2.common.state);
  918. } else {
  919. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  920. sb_data_e1x.common.p_func.pf_id,
  921. sb_data_e1x.common.p_func.vf_id,
  922. sb_data_e1x.common.p_func.vf_valid,
  923. sb_data_e1x.common.p_func.vnic_id,
  924. sb_data_e1x.common.same_igu_sb_1b,
  925. sb_data_e1x.common.state);
  926. }
  927. /* SB_SMs data */
  928. for (j = 0; j < HC_SB_MAX_SM; j++) {
  929. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  930. j, hc_sm_p[j].__flags,
  931. hc_sm_p[j].igu_sb_id,
  932. hc_sm_p[j].igu_seg_id,
  933. hc_sm_p[j].time_to_expire,
  934. hc_sm_p[j].timer_value);
  935. }
  936. /* Indices data */
  937. for (j = 0; j < loop; j++) {
  938. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  939. hc_index_p[j].flags,
  940. hc_index_p[j].timeout);
  941. }
  942. }
  943. #ifdef BNX2X_STOP_ON_ERROR
  944. if (IS_PF(bp)) {
  945. /* event queue */
  946. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  947. for (i = 0; i < NUM_EQ_DESC; i++) {
  948. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  949. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  950. i, bp->eq_ring[i].message.opcode,
  951. bp->eq_ring[i].message.error);
  952. BNX2X_ERR("data: %x %x %x\n",
  953. data[0], data[1], data[2]);
  954. }
  955. }
  956. /* Rings */
  957. /* Rx */
  958. for_each_valid_rx_queue(bp, i) {
  959. struct bnx2x_fastpath *fp = &bp->fp[i];
  960. if (!bp->fp)
  961. break;
  962. if (!fp->rx_cons_sb)
  963. continue;
  964. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  965. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  966. for (j = start; j != end; j = RX_BD(j + 1)) {
  967. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  968. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  969. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  970. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  971. }
  972. start = RX_SGE(fp->rx_sge_prod);
  973. end = RX_SGE(fp->last_max_sge);
  974. for (j = start; j != end; j = RX_SGE(j + 1)) {
  975. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  976. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  977. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  978. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  979. }
  980. start = RCQ_BD(fp->rx_comp_cons - 10);
  981. end = RCQ_BD(fp->rx_comp_cons + 503);
  982. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  983. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  984. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  985. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  986. }
  987. }
  988. /* Tx */
  989. for_each_valid_tx_queue(bp, i) {
  990. struct bnx2x_fastpath *fp = &bp->fp[i];
  991. if (!bp->fp)
  992. break;
  993. for_each_cos_in_tx_queue(fp, cos) {
  994. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  995. if (!fp->txdata_ptr[cos])
  996. break;
  997. if (!txdata->tx_cons_sb)
  998. continue;
  999. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  1000. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  1001. for (j = start; j != end; j = TX_BD(j + 1)) {
  1002. struct sw_tx_bd *sw_bd =
  1003. &txdata->tx_buf_ring[j];
  1004. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1005. i, cos, j, sw_bd->skb,
  1006. sw_bd->first_bd);
  1007. }
  1008. start = TX_BD(txdata->tx_bd_cons - 10);
  1009. end = TX_BD(txdata->tx_bd_cons + 254);
  1010. for (j = start; j != end; j = TX_BD(j + 1)) {
  1011. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1012. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1013. i, cos, j, tx_bd[0], tx_bd[1],
  1014. tx_bd[2], tx_bd[3]);
  1015. }
  1016. }
  1017. }
  1018. #endif
  1019. if (IS_PF(bp)) {
  1020. bnx2x_fw_dump(bp);
  1021. bnx2x_mc_assert(bp);
  1022. }
  1023. BNX2X_ERR("end crash dump -----------------\n");
  1024. }
  1025. /*
  1026. * FLR Support for E2
  1027. *
  1028. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1029. * initialization.
  1030. */
  1031. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1032. #define FLR_WAIT_INTERVAL 50 /* usec */
  1033. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1034. struct pbf_pN_buf_regs {
  1035. int pN;
  1036. u32 init_crd;
  1037. u32 crd;
  1038. u32 crd_freed;
  1039. };
  1040. struct pbf_pN_cmd_regs {
  1041. int pN;
  1042. u32 lines_occup;
  1043. u32 lines_freed;
  1044. };
  1045. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1046. struct pbf_pN_buf_regs *regs,
  1047. u32 poll_count)
  1048. {
  1049. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1050. u32 cur_cnt = poll_count;
  1051. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1052. crd = crd_start = REG_RD(bp, regs->crd);
  1053. init_crd = REG_RD(bp, regs->init_crd);
  1054. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1055. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1056. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1057. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1058. (init_crd - crd_start))) {
  1059. if (cur_cnt--) {
  1060. udelay(FLR_WAIT_INTERVAL);
  1061. crd = REG_RD(bp, regs->crd);
  1062. crd_freed = REG_RD(bp, regs->crd_freed);
  1063. } else {
  1064. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1065. regs->pN);
  1066. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1067. regs->pN, crd);
  1068. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1069. regs->pN, crd_freed);
  1070. break;
  1071. }
  1072. }
  1073. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1074. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1075. }
  1076. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1077. struct pbf_pN_cmd_regs *regs,
  1078. u32 poll_count)
  1079. {
  1080. u32 occup, to_free, freed, freed_start;
  1081. u32 cur_cnt = poll_count;
  1082. occup = to_free = REG_RD(bp, regs->lines_occup);
  1083. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1084. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1085. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1086. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1087. if (cur_cnt--) {
  1088. udelay(FLR_WAIT_INTERVAL);
  1089. occup = REG_RD(bp, regs->lines_occup);
  1090. freed = REG_RD(bp, regs->lines_freed);
  1091. } else {
  1092. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1093. regs->pN);
  1094. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1095. regs->pN, occup);
  1096. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1097. regs->pN, freed);
  1098. break;
  1099. }
  1100. }
  1101. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1102. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1103. }
  1104. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1105. u32 expected, u32 poll_count)
  1106. {
  1107. u32 cur_cnt = poll_count;
  1108. u32 val;
  1109. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1110. udelay(FLR_WAIT_INTERVAL);
  1111. return val;
  1112. }
  1113. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1114. char *msg, u32 poll_cnt)
  1115. {
  1116. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1117. if (val != 0) {
  1118. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1119. return 1;
  1120. }
  1121. return 0;
  1122. }
  1123. /* Common routines with VF FLR cleanup */
  1124. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1125. {
  1126. /* adjust polling timeout */
  1127. if (CHIP_REV_IS_EMUL(bp))
  1128. return FLR_POLL_CNT * 2000;
  1129. if (CHIP_REV_IS_FPGA(bp))
  1130. return FLR_POLL_CNT * 120;
  1131. return FLR_POLL_CNT;
  1132. }
  1133. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1134. {
  1135. struct pbf_pN_cmd_regs cmd_regs[] = {
  1136. {0, (CHIP_IS_E3B0(bp)) ?
  1137. PBF_REG_TQ_OCCUPANCY_Q0 :
  1138. PBF_REG_P0_TQ_OCCUPANCY,
  1139. (CHIP_IS_E3B0(bp)) ?
  1140. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1141. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1142. {1, (CHIP_IS_E3B0(bp)) ?
  1143. PBF_REG_TQ_OCCUPANCY_Q1 :
  1144. PBF_REG_P1_TQ_OCCUPANCY,
  1145. (CHIP_IS_E3B0(bp)) ?
  1146. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1147. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1148. {4, (CHIP_IS_E3B0(bp)) ?
  1149. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1150. PBF_REG_P4_TQ_OCCUPANCY,
  1151. (CHIP_IS_E3B0(bp)) ?
  1152. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1153. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1154. };
  1155. struct pbf_pN_buf_regs buf_regs[] = {
  1156. {0, (CHIP_IS_E3B0(bp)) ?
  1157. PBF_REG_INIT_CRD_Q0 :
  1158. PBF_REG_P0_INIT_CRD ,
  1159. (CHIP_IS_E3B0(bp)) ?
  1160. PBF_REG_CREDIT_Q0 :
  1161. PBF_REG_P0_CREDIT,
  1162. (CHIP_IS_E3B0(bp)) ?
  1163. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1164. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1165. {1, (CHIP_IS_E3B0(bp)) ?
  1166. PBF_REG_INIT_CRD_Q1 :
  1167. PBF_REG_P1_INIT_CRD,
  1168. (CHIP_IS_E3B0(bp)) ?
  1169. PBF_REG_CREDIT_Q1 :
  1170. PBF_REG_P1_CREDIT,
  1171. (CHIP_IS_E3B0(bp)) ?
  1172. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1173. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1174. {4, (CHIP_IS_E3B0(bp)) ?
  1175. PBF_REG_INIT_CRD_LB_Q :
  1176. PBF_REG_P4_INIT_CRD,
  1177. (CHIP_IS_E3B0(bp)) ?
  1178. PBF_REG_CREDIT_LB_Q :
  1179. PBF_REG_P4_CREDIT,
  1180. (CHIP_IS_E3B0(bp)) ?
  1181. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1182. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1183. };
  1184. int i;
  1185. /* Verify the command queues are flushed P0, P1, P4 */
  1186. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1187. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1188. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1189. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1190. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1191. }
  1192. #define OP_GEN_PARAM(param) \
  1193. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1194. #define OP_GEN_TYPE(type) \
  1195. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1196. #define OP_GEN_AGG_VECT(index) \
  1197. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1198. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1199. {
  1200. u32 op_gen_command = 0;
  1201. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1202. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1203. int ret = 0;
  1204. if (REG_RD(bp, comp_addr)) {
  1205. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1206. return 1;
  1207. }
  1208. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1209. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1210. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1211. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1212. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1213. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1214. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1215. BNX2X_ERR("FW final cleanup did not succeed\n");
  1216. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1217. (REG_RD(bp, comp_addr)));
  1218. bnx2x_panic();
  1219. return 1;
  1220. }
  1221. /* Zero completion for next FLR */
  1222. REG_WR(bp, comp_addr, 0);
  1223. return ret;
  1224. }
  1225. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1226. {
  1227. u16 status;
  1228. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1229. return status & PCI_EXP_DEVSTA_TRPND;
  1230. }
  1231. /* PF FLR specific routines
  1232. */
  1233. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1234. {
  1235. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1236. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1237. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1238. "CFC PF usage counter timed out",
  1239. poll_cnt))
  1240. return 1;
  1241. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1242. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1243. DORQ_REG_PF_USAGE_CNT,
  1244. "DQ PF usage counter timed out",
  1245. poll_cnt))
  1246. return 1;
  1247. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1248. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1249. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1250. "QM PF usage counter timed out",
  1251. poll_cnt))
  1252. return 1;
  1253. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1254. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1255. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1256. "Timers VNIC usage counter timed out",
  1257. poll_cnt))
  1258. return 1;
  1259. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1260. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1261. "Timers NUM_SCANS usage counter timed out",
  1262. poll_cnt))
  1263. return 1;
  1264. /* Wait DMAE PF usage counter to zero */
  1265. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1266. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1267. "DMAE command register timed out",
  1268. poll_cnt))
  1269. return 1;
  1270. return 0;
  1271. }
  1272. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1273. {
  1274. u32 val;
  1275. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1276. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1277. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1278. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1279. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1280. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1281. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1282. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1283. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1284. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1285. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1286. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1287. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1288. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1289. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1290. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1291. val);
  1292. }
  1293. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1294. {
  1295. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1296. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1297. /* Re-enable PF target read access */
  1298. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1299. /* Poll HW usage counters */
  1300. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1301. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1302. return -EBUSY;
  1303. /* Zero the igu 'trailing edge' and 'leading edge' */
  1304. /* Send the FW cleanup command */
  1305. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1306. return -EBUSY;
  1307. /* ATC cleanup */
  1308. /* Verify TX hw is flushed */
  1309. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1310. /* Wait 100ms (not adjusted according to platform) */
  1311. msleep(100);
  1312. /* Verify no pending pci transactions */
  1313. if (bnx2x_is_pcie_pending(bp->pdev))
  1314. BNX2X_ERR("PCIE Transactions still pending\n");
  1315. /* Debug */
  1316. bnx2x_hw_enable_status(bp);
  1317. /*
  1318. * Master enable - Due to WB DMAE writes performed before this
  1319. * register is re-initialized as part of the regular function init
  1320. */
  1321. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1322. return 0;
  1323. }
  1324. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1325. {
  1326. int port = BP_PORT(bp);
  1327. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1328. u32 val = REG_RD(bp, addr);
  1329. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1330. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1331. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1332. if (msix) {
  1333. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1334. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1335. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1336. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1337. if (single_msix)
  1338. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1339. } else if (msi) {
  1340. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1341. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1342. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1343. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1344. } else {
  1345. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1346. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1347. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1348. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1349. if (!CHIP_IS_E1(bp)) {
  1350. DP(NETIF_MSG_IFUP,
  1351. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1352. REG_WR(bp, addr, val);
  1353. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1354. }
  1355. }
  1356. if (CHIP_IS_E1(bp))
  1357. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1358. DP(NETIF_MSG_IFUP,
  1359. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1360. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1361. REG_WR(bp, addr, val);
  1362. /*
  1363. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1364. */
  1365. mmiowb();
  1366. barrier();
  1367. if (!CHIP_IS_E1(bp)) {
  1368. /* init leading/trailing edge */
  1369. if (IS_MF(bp)) {
  1370. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1371. if (bp->port.pmf)
  1372. /* enable nig and gpio3 attention */
  1373. val |= 0x1100;
  1374. } else
  1375. val = 0xffff;
  1376. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1377. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1378. }
  1379. /* Make sure that interrupts are indeed enabled from here on */
  1380. mmiowb();
  1381. }
  1382. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1383. {
  1384. u32 val;
  1385. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1386. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1387. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1388. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1389. if (msix) {
  1390. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1391. IGU_PF_CONF_SINGLE_ISR_EN);
  1392. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1393. IGU_PF_CONF_ATTN_BIT_EN);
  1394. if (single_msix)
  1395. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1396. } else if (msi) {
  1397. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1398. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1399. IGU_PF_CONF_ATTN_BIT_EN |
  1400. IGU_PF_CONF_SINGLE_ISR_EN);
  1401. } else {
  1402. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1403. val |= (IGU_PF_CONF_INT_LINE_EN |
  1404. IGU_PF_CONF_ATTN_BIT_EN |
  1405. IGU_PF_CONF_SINGLE_ISR_EN);
  1406. }
  1407. /* Clean previous status - need to configure igu prior to ack*/
  1408. if ((!msix) || single_msix) {
  1409. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1410. bnx2x_ack_int(bp);
  1411. }
  1412. val |= IGU_PF_CONF_FUNC_EN;
  1413. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1414. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1415. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1416. if (val & IGU_PF_CONF_INT_LINE_EN)
  1417. pci_intx(bp->pdev, true);
  1418. barrier();
  1419. /* init leading/trailing edge */
  1420. if (IS_MF(bp)) {
  1421. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1422. if (bp->port.pmf)
  1423. /* enable nig and gpio3 attention */
  1424. val |= 0x1100;
  1425. } else
  1426. val = 0xffff;
  1427. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1428. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1429. /* Make sure that interrupts are indeed enabled from here on */
  1430. mmiowb();
  1431. }
  1432. void bnx2x_int_enable(struct bnx2x *bp)
  1433. {
  1434. if (bp->common.int_block == INT_BLOCK_HC)
  1435. bnx2x_hc_int_enable(bp);
  1436. else
  1437. bnx2x_igu_int_enable(bp);
  1438. }
  1439. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1440. {
  1441. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1442. int i, offset;
  1443. if (disable_hw)
  1444. /* prevent the HW from sending interrupts */
  1445. bnx2x_int_disable(bp);
  1446. /* make sure all ISRs are done */
  1447. if (msix) {
  1448. synchronize_irq(bp->msix_table[0].vector);
  1449. offset = 1;
  1450. if (CNIC_SUPPORT(bp))
  1451. offset++;
  1452. for_each_eth_queue(bp, i)
  1453. synchronize_irq(bp->msix_table[offset++].vector);
  1454. } else
  1455. synchronize_irq(bp->pdev->irq);
  1456. /* make sure sp_task is not running */
  1457. cancel_delayed_work(&bp->sp_task);
  1458. cancel_delayed_work(&bp->period_task);
  1459. flush_workqueue(bnx2x_wq);
  1460. }
  1461. /* fast path */
  1462. /*
  1463. * General service functions
  1464. */
  1465. /* Return true if succeeded to acquire the lock */
  1466. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1467. {
  1468. u32 lock_status;
  1469. u32 resource_bit = (1 << resource);
  1470. int func = BP_FUNC(bp);
  1471. u32 hw_lock_control_reg;
  1472. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1473. "Trying to take a lock on resource %d\n", resource);
  1474. /* Validating that the resource is within range */
  1475. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1476. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1477. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1478. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1479. return false;
  1480. }
  1481. if (func <= 5)
  1482. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1483. else
  1484. hw_lock_control_reg =
  1485. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1486. /* Try to acquire the lock */
  1487. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1488. lock_status = REG_RD(bp, hw_lock_control_reg);
  1489. if (lock_status & resource_bit)
  1490. return true;
  1491. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1492. "Failed to get a lock on resource %d\n", resource);
  1493. return false;
  1494. }
  1495. /**
  1496. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1497. *
  1498. * @bp: driver handle
  1499. *
  1500. * Returns the recovery leader resource id according to the engine this function
  1501. * belongs to. Currently only only 2 engines is supported.
  1502. */
  1503. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1504. {
  1505. if (BP_PATH(bp))
  1506. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1507. else
  1508. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1509. }
  1510. /**
  1511. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1512. *
  1513. * @bp: driver handle
  1514. *
  1515. * Tries to acquire a leader lock for current engine.
  1516. */
  1517. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1518. {
  1519. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1520. }
  1521. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1522. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1523. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1524. {
  1525. /* Set the interrupt occurred bit for the sp-task to recognize it
  1526. * must ack the interrupt and transition according to the IGU
  1527. * state machine.
  1528. */
  1529. atomic_set(&bp->interrupt_occurred, 1);
  1530. /* The sp_task must execute only after this bit
  1531. * is set, otherwise we will get out of sync and miss all
  1532. * further interrupts. Hence, the barrier.
  1533. */
  1534. smp_wmb();
  1535. /* schedule sp_task to workqueue */
  1536. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1537. }
  1538. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1539. {
  1540. struct bnx2x *bp = fp->bp;
  1541. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1542. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1543. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1544. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1545. DP(BNX2X_MSG_SP,
  1546. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1547. fp->index, cid, command, bp->state,
  1548. rr_cqe->ramrod_cqe.ramrod_type);
  1549. /* If cid is within VF range, replace the slowpath object with the
  1550. * one corresponding to this VF
  1551. */
  1552. if (cid >= BNX2X_FIRST_VF_CID &&
  1553. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1554. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1555. switch (command) {
  1556. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1557. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1558. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1559. break;
  1560. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1561. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1562. drv_cmd = BNX2X_Q_CMD_SETUP;
  1563. break;
  1564. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1565. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1566. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1567. break;
  1568. case (RAMROD_CMD_ID_ETH_HALT):
  1569. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1570. drv_cmd = BNX2X_Q_CMD_HALT;
  1571. break;
  1572. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1573. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1574. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1575. break;
  1576. case (RAMROD_CMD_ID_ETH_EMPTY):
  1577. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1578. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1579. break;
  1580. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1581. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1582. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1583. break;
  1584. default:
  1585. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1586. command, fp->index);
  1587. return;
  1588. }
  1589. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1590. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1591. /* q_obj->complete_cmd() failure means that this was
  1592. * an unexpected completion.
  1593. *
  1594. * In this case we don't want to increase the bp->spq_left
  1595. * because apparently we haven't sent this command the first
  1596. * place.
  1597. */
  1598. #ifdef BNX2X_STOP_ON_ERROR
  1599. bnx2x_panic();
  1600. #else
  1601. return;
  1602. #endif
  1603. smp_mb__before_atomic();
  1604. atomic_inc(&bp->cq_spq_left);
  1605. /* push the change in bp->spq_left and towards the memory */
  1606. smp_mb__after_atomic();
  1607. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1608. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1609. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1610. /* if Q update ramrod is completed for last Q in AFEX vif set
  1611. * flow, then ACK MCP at the end
  1612. *
  1613. * mark pending ACK to MCP bit.
  1614. * prevent case that both bits are cleared.
  1615. * At the end of load/unload driver checks that
  1616. * sp_state is cleared, and this order prevents
  1617. * races
  1618. */
  1619. smp_mb__before_atomic();
  1620. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1621. wmb();
  1622. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1623. smp_mb__after_atomic();
  1624. /* schedule the sp task as mcp ack is required */
  1625. bnx2x_schedule_sp_task(bp);
  1626. }
  1627. return;
  1628. }
  1629. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1630. {
  1631. struct bnx2x *bp = netdev_priv(dev_instance);
  1632. u16 status = bnx2x_ack_int(bp);
  1633. u16 mask;
  1634. int i;
  1635. u8 cos;
  1636. /* Return here if interrupt is shared and it's not for us */
  1637. if (unlikely(status == 0)) {
  1638. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1639. return IRQ_NONE;
  1640. }
  1641. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1642. #ifdef BNX2X_STOP_ON_ERROR
  1643. if (unlikely(bp->panic))
  1644. return IRQ_HANDLED;
  1645. #endif
  1646. for_each_eth_queue(bp, i) {
  1647. struct bnx2x_fastpath *fp = &bp->fp[i];
  1648. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1649. if (status & mask) {
  1650. /* Handle Rx or Tx according to SB id */
  1651. for_each_cos_in_tx_queue(fp, cos)
  1652. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1653. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1654. napi_schedule_irqoff(&bnx2x_fp(bp, fp->index, napi));
  1655. status &= ~mask;
  1656. }
  1657. }
  1658. if (CNIC_SUPPORT(bp)) {
  1659. mask = 0x2;
  1660. if (status & (mask | 0x1)) {
  1661. struct cnic_ops *c_ops = NULL;
  1662. rcu_read_lock();
  1663. c_ops = rcu_dereference(bp->cnic_ops);
  1664. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1665. CNIC_DRV_STATE_HANDLES_IRQ))
  1666. c_ops->cnic_handler(bp->cnic_data, NULL);
  1667. rcu_read_unlock();
  1668. status &= ~mask;
  1669. }
  1670. }
  1671. if (unlikely(status & 0x1)) {
  1672. /* schedule sp task to perform default status block work, ack
  1673. * attentions and enable interrupts.
  1674. */
  1675. bnx2x_schedule_sp_task(bp);
  1676. status &= ~0x1;
  1677. if (!status)
  1678. return IRQ_HANDLED;
  1679. }
  1680. if (unlikely(status))
  1681. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1682. status);
  1683. return IRQ_HANDLED;
  1684. }
  1685. /* Link */
  1686. /*
  1687. * General service functions
  1688. */
  1689. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1690. {
  1691. u32 lock_status;
  1692. u32 resource_bit = (1 << resource);
  1693. int func = BP_FUNC(bp);
  1694. u32 hw_lock_control_reg;
  1695. int cnt;
  1696. /* Validating that the resource is within range */
  1697. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1698. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1699. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1700. return -EINVAL;
  1701. }
  1702. if (func <= 5) {
  1703. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1704. } else {
  1705. hw_lock_control_reg =
  1706. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1707. }
  1708. /* Validating that the resource is not already taken */
  1709. lock_status = REG_RD(bp, hw_lock_control_reg);
  1710. if (lock_status & resource_bit) {
  1711. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1712. lock_status, resource_bit);
  1713. return -EEXIST;
  1714. }
  1715. /* Try for 5 second every 5ms */
  1716. for (cnt = 0; cnt < 1000; cnt++) {
  1717. /* Try to acquire the lock */
  1718. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1719. lock_status = REG_RD(bp, hw_lock_control_reg);
  1720. if (lock_status & resource_bit)
  1721. return 0;
  1722. usleep_range(5000, 10000);
  1723. }
  1724. BNX2X_ERR("Timeout\n");
  1725. return -EAGAIN;
  1726. }
  1727. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1728. {
  1729. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1730. }
  1731. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1732. {
  1733. u32 lock_status;
  1734. u32 resource_bit = (1 << resource);
  1735. int func = BP_FUNC(bp);
  1736. u32 hw_lock_control_reg;
  1737. /* Validating that the resource is within range */
  1738. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1739. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1740. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1741. return -EINVAL;
  1742. }
  1743. if (func <= 5) {
  1744. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1745. } else {
  1746. hw_lock_control_reg =
  1747. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1748. }
  1749. /* Validating that the resource is currently taken */
  1750. lock_status = REG_RD(bp, hw_lock_control_reg);
  1751. if (!(lock_status & resource_bit)) {
  1752. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1753. lock_status, resource_bit);
  1754. return -EFAULT;
  1755. }
  1756. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1757. return 0;
  1758. }
  1759. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1760. {
  1761. /* The GPIO should be swapped if swap register is set and active */
  1762. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1763. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1764. int gpio_shift = gpio_num +
  1765. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1766. u32 gpio_mask = (1 << gpio_shift);
  1767. u32 gpio_reg;
  1768. int value;
  1769. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1770. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1771. return -EINVAL;
  1772. }
  1773. /* read GPIO value */
  1774. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1775. /* get the requested pin value */
  1776. if ((gpio_reg & gpio_mask) == gpio_mask)
  1777. value = 1;
  1778. else
  1779. value = 0;
  1780. return value;
  1781. }
  1782. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1783. {
  1784. /* The GPIO should be swapped if swap register is set and active */
  1785. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1786. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1787. int gpio_shift = gpio_num +
  1788. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1789. u32 gpio_mask = (1 << gpio_shift);
  1790. u32 gpio_reg;
  1791. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1792. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1793. return -EINVAL;
  1794. }
  1795. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1796. /* read GPIO and mask except the float bits */
  1797. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1798. switch (mode) {
  1799. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1800. DP(NETIF_MSG_LINK,
  1801. "Set GPIO %d (shift %d) -> output low\n",
  1802. gpio_num, gpio_shift);
  1803. /* clear FLOAT and set CLR */
  1804. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1805. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1806. break;
  1807. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1808. DP(NETIF_MSG_LINK,
  1809. "Set GPIO %d (shift %d) -> output high\n",
  1810. gpio_num, gpio_shift);
  1811. /* clear FLOAT and set SET */
  1812. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1813. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1814. break;
  1815. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1816. DP(NETIF_MSG_LINK,
  1817. "Set GPIO %d (shift %d) -> input\n",
  1818. gpio_num, gpio_shift);
  1819. /* set FLOAT */
  1820. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1821. break;
  1822. default:
  1823. break;
  1824. }
  1825. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1826. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1827. return 0;
  1828. }
  1829. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1830. {
  1831. u32 gpio_reg = 0;
  1832. int rc = 0;
  1833. /* Any port swapping should be handled by caller. */
  1834. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1835. /* read GPIO and mask except the float bits */
  1836. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1837. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1838. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1839. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1840. switch (mode) {
  1841. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1842. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1843. /* set CLR */
  1844. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1845. break;
  1846. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1847. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1848. /* set SET */
  1849. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1850. break;
  1851. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1852. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1853. /* set FLOAT */
  1854. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1855. break;
  1856. default:
  1857. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1858. rc = -EINVAL;
  1859. break;
  1860. }
  1861. if (rc == 0)
  1862. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1863. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1864. return rc;
  1865. }
  1866. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1867. {
  1868. /* The GPIO should be swapped if swap register is set and active */
  1869. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1870. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1871. int gpio_shift = gpio_num +
  1872. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1873. u32 gpio_mask = (1 << gpio_shift);
  1874. u32 gpio_reg;
  1875. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1876. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1877. return -EINVAL;
  1878. }
  1879. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1880. /* read GPIO int */
  1881. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1882. switch (mode) {
  1883. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1884. DP(NETIF_MSG_LINK,
  1885. "Clear GPIO INT %d (shift %d) -> output low\n",
  1886. gpio_num, gpio_shift);
  1887. /* clear SET and set CLR */
  1888. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1889. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1890. break;
  1891. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1892. DP(NETIF_MSG_LINK,
  1893. "Set GPIO INT %d (shift %d) -> output high\n",
  1894. gpio_num, gpio_shift);
  1895. /* clear CLR and set SET */
  1896. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1897. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1898. break;
  1899. default:
  1900. break;
  1901. }
  1902. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1903. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1904. return 0;
  1905. }
  1906. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1907. {
  1908. u32 spio_reg;
  1909. /* Only 2 SPIOs are configurable */
  1910. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1911. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1912. return -EINVAL;
  1913. }
  1914. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1915. /* read SPIO and mask except the float bits */
  1916. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1917. switch (mode) {
  1918. case MISC_SPIO_OUTPUT_LOW:
  1919. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1920. /* clear FLOAT and set CLR */
  1921. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1922. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1923. break;
  1924. case MISC_SPIO_OUTPUT_HIGH:
  1925. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1926. /* clear FLOAT and set SET */
  1927. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1928. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1929. break;
  1930. case MISC_SPIO_INPUT_HI_Z:
  1931. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1932. /* set FLOAT */
  1933. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1934. break;
  1935. default:
  1936. break;
  1937. }
  1938. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1939. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1940. return 0;
  1941. }
  1942. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1943. {
  1944. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1945. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1946. ADVERTISED_Pause);
  1947. switch (bp->link_vars.ieee_fc &
  1948. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1949. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1950. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1951. ADVERTISED_Pause);
  1952. break;
  1953. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1954. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1955. break;
  1956. default:
  1957. break;
  1958. }
  1959. }
  1960. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1961. {
  1962. /* Initialize link parameters structure variables
  1963. * It is recommended to turn off RX FC for jumbo frames
  1964. * for better performance
  1965. */
  1966. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1967. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1968. else
  1969. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1970. }
  1971. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1972. {
  1973. u32 pause_enabled = 0;
  1974. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1975. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1976. pause_enabled = 1;
  1977. REG_WR(bp, BAR_USTRORM_INTMEM +
  1978. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1979. pause_enabled);
  1980. }
  1981. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1982. pause_enabled ? "enabled" : "disabled");
  1983. }
  1984. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1985. {
  1986. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1987. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1988. if (!BP_NOMCP(bp)) {
  1989. bnx2x_set_requested_fc(bp);
  1990. bnx2x_acquire_phy_lock(bp);
  1991. if (load_mode == LOAD_DIAG) {
  1992. struct link_params *lp = &bp->link_params;
  1993. lp->loopback_mode = LOOPBACK_XGXS;
  1994. /* Prefer doing PHY loopback at highest speed */
  1995. if (lp->req_line_speed[cfx_idx] < SPEED_20000) {
  1996. if (lp->speed_cap_mask[cfx_idx] &
  1997. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
  1998. lp->req_line_speed[cfx_idx] =
  1999. SPEED_20000;
  2000. else if (lp->speed_cap_mask[cfx_idx] &
  2001. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  2002. lp->req_line_speed[cfx_idx] =
  2003. SPEED_10000;
  2004. else
  2005. lp->req_line_speed[cfx_idx] =
  2006. SPEED_1000;
  2007. }
  2008. }
  2009. if (load_mode == LOAD_LOOPBACK_EXT) {
  2010. struct link_params *lp = &bp->link_params;
  2011. lp->loopback_mode = LOOPBACK_EXT;
  2012. }
  2013. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2014. bnx2x_release_phy_lock(bp);
  2015. bnx2x_init_dropless_fc(bp);
  2016. bnx2x_calc_fc_adv(bp);
  2017. if (bp->link_vars.link_up) {
  2018. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2019. bnx2x_link_report(bp);
  2020. }
  2021. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2022. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2023. return rc;
  2024. }
  2025. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2026. return -EINVAL;
  2027. }
  2028. void bnx2x_link_set(struct bnx2x *bp)
  2029. {
  2030. if (!BP_NOMCP(bp)) {
  2031. bnx2x_acquire_phy_lock(bp);
  2032. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2033. bnx2x_release_phy_lock(bp);
  2034. bnx2x_init_dropless_fc(bp);
  2035. bnx2x_calc_fc_adv(bp);
  2036. } else
  2037. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2038. }
  2039. static void bnx2x__link_reset(struct bnx2x *bp)
  2040. {
  2041. if (!BP_NOMCP(bp)) {
  2042. bnx2x_acquire_phy_lock(bp);
  2043. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2044. bnx2x_release_phy_lock(bp);
  2045. } else
  2046. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2047. }
  2048. void bnx2x_force_link_reset(struct bnx2x *bp)
  2049. {
  2050. bnx2x_acquire_phy_lock(bp);
  2051. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2052. bnx2x_release_phy_lock(bp);
  2053. }
  2054. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2055. {
  2056. u8 rc = 0;
  2057. if (!BP_NOMCP(bp)) {
  2058. bnx2x_acquire_phy_lock(bp);
  2059. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2060. is_serdes);
  2061. bnx2x_release_phy_lock(bp);
  2062. } else
  2063. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2064. return rc;
  2065. }
  2066. /* Calculates the sum of vn_min_rates.
  2067. It's needed for further normalizing of the min_rates.
  2068. Returns:
  2069. sum of vn_min_rates.
  2070. or
  2071. 0 - if all the min_rates are 0.
  2072. In the later case fairness algorithm should be deactivated.
  2073. If not all min_rates are zero then those that are zeroes will be set to 1.
  2074. */
  2075. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2076. struct cmng_init_input *input)
  2077. {
  2078. int all_zero = 1;
  2079. int vn;
  2080. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2081. u32 vn_cfg = bp->mf_config[vn];
  2082. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2083. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2084. /* Skip hidden vns */
  2085. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2086. vn_min_rate = 0;
  2087. /* If min rate is zero - set it to 1 */
  2088. else if (!vn_min_rate)
  2089. vn_min_rate = DEF_MIN_RATE;
  2090. else
  2091. all_zero = 0;
  2092. input->vnic_min_rate[vn] = vn_min_rate;
  2093. }
  2094. /* if ETS or all min rates are zeros - disable fairness */
  2095. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2096. input->flags.cmng_enables &=
  2097. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2098. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2099. } else if (all_zero) {
  2100. input->flags.cmng_enables &=
  2101. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2102. DP(NETIF_MSG_IFUP,
  2103. "All MIN values are zeroes fairness will be disabled\n");
  2104. } else
  2105. input->flags.cmng_enables |=
  2106. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2107. }
  2108. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2109. struct cmng_init_input *input)
  2110. {
  2111. u16 vn_max_rate;
  2112. u32 vn_cfg = bp->mf_config[vn];
  2113. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2114. vn_max_rate = 0;
  2115. else {
  2116. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2117. if (IS_MF_PERCENT_BW(bp)) {
  2118. /* maxCfg in percents of linkspeed */
  2119. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2120. } else /* SD modes */
  2121. /* maxCfg is absolute in 100Mb units */
  2122. vn_max_rate = maxCfg * 100;
  2123. }
  2124. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2125. input->vnic_max_rate[vn] = vn_max_rate;
  2126. }
  2127. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2128. {
  2129. if (CHIP_REV_IS_SLOW(bp))
  2130. return CMNG_FNS_NONE;
  2131. if (IS_MF(bp))
  2132. return CMNG_FNS_MINMAX;
  2133. return CMNG_FNS_NONE;
  2134. }
  2135. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2136. {
  2137. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2138. if (BP_NOMCP(bp))
  2139. return; /* what should be the default value in this case */
  2140. /* For 2 port configuration the absolute function number formula
  2141. * is:
  2142. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2143. *
  2144. * and there are 4 functions per port
  2145. *
  2146. * For 4 port configuration it is
  2147. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2148. *
  2149. * and there are 2 functions per port
  2150. */
  2151. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2152. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2153. if (func >= E1H_FUNC_MAX)
  2154. break;
  2155. bp->mf_config[vn] =
  2156. MF_CFG_RD(bp, func_mf_config[func].config);
  2157. }
  2158. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2159. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2160. bp->flags |= MF_FUNC_DIS;
  2161. } else {
  2162. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2163. bp->flags &= ~MF_FUNC_DIS;
  2164. }
  2165. }
  2166. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2167. {
  2168. struct cmng_init_input input;
  2169. memset(&input, 0, sizeof(struct cmng_init_input));
  2170. input.port_rate = bp->link_vars.line_speed;
  2171. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2172. int vn;
  2173. /* read mf conf from shmem */
  2174. if (read_cfg)
  2175. bnx2x_read_mf_cfg(bp);
  2176. /* vn_weight_sum and enable fairness if not 0 */
  2177. bnx2x_calc_vn_min(bp, &input);
  2178. /* calculate and set min-max rate for each vn */
  2179. if (bp->port.pmf)
  2180. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2181. bnx2x_calc_vn_max(bp, vn, &input);
  2182. /* always enable rate shaping and fairness */
  2183. input.flags.cmng_enables |=
  2184. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2185. bnx2x_init_cmng(&input, &bp->cmng);
  2186. return;
  2187. }
  2188. /* rate shaping and fairness are disabled */
  2189. DP(NETIF_MSG_IFUP,
  2190. "rate shaping and fairness are disabled\n");
  2191. }
  2192. static void storm_memset_cmng(struct bnx2x *bp,
  2193. struct cmng_init *cmng,
  2194. u8 port)
  2195. {
  2196. int vn;
  2197. size_t size = sizeof(struct cmng_struct_per_port);
  2198. u32 addr = BAR_XSTRORM_INTMEM +
  2199. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2200. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2201. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2202. int func = func_by_vn(bp, vn);
  2203. addr = BAR_XSTRORM_INTMEM +
  2204. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2205. size = sizeof(struct rate_shaping_vars_per_vn);
  2206. __storm_memset_struct(bp, addr, size,
  2207. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2208. addr = BAR_XSTRORM_INTMEM +
  2209. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2210. size = sizeof(struct fairness_vars_per_vn);
  2211. __storm_memset_struct(bp, addr, size,
  2212. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2213. }
  2214. }
  2215. /* init cmng mode in HW according to local configuration */
  2216. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2217. {
  2218. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2219. if (cmng_fns != CMNG_FNS_NONE) {
  2220. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2221. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2222. } else {
  2223. /* rate shaping and fairness are disabled */
  2224. DP(NETIF_MSG_IFUP,
  2225. "single function mode without fairness\n");
  2226. }
  2227. }
  2228. /* This function is called upon link interrupt */
  2229. static void bnx2x_link_attn(struct bnx2x *bp)
  2230. {
  2231. /* Make sure that we are synced with the current statistics */
  2232. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2233. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2234. bnx2x_init_dropless_fc(bp);
  2235. if (bp->link_vars.link_up) {
  2236. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2237. struct host_port_stats *pstats;
  2238. pstats = bnx2x_sp(bp, port_stats);
  2239. /* reset old mac stats */
  2240. memset(&(pstats->mac_stx[0]), 0,
  2241. sizeof(struct mac_stx));
  2242. }
  2243. if (bp->state == BNX2X_STATE_OPEN)
  2244. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2245. }
  2246. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2247. bnx2x_set_local_cmng(bp);
  2248. __bnx2x_link_report(bp);
  2249. if (IS_MF(bp))
  2250. bnx2x_link_sync_notify(bp);
  2251. }
  2252. void bnx2x__link_status_update(struct bnx2x *bp)
  2253. {
  2254. if (bp->state != BNX2X_STATE_OPEN)
  2255. return;
  2256. /* read updated dcb configuration */
  2257. if (IS_PF(bp)) {
  2258. bnx2x_dcbx_pmf_update(bp);
  2259. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2260. if (bp->link_vars.link_up)
  2261. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2262. else
  2263. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2264. /* indicate link status */
  2265. bnx2x_link_report(bp);
  2266. } else { /* VF */
  2267. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2268. SUPPORTED_10baseT_Full |
  2269. SUPPORTED_100baseT_Half |
  2270. SUPPORTED_100baseT_Full |
  2271. SUPPORTED_1000baseT_Full |
  2272. SUPPORTED_2500baseX_Full |
  2273. SUPPORTED_10000baseT_Full |
  2274. SUPPORTED_TP |
  2275. SUPPORTED_FIBRE |
  2276. SUPPORTED_Autoneg |
  2277. SUPPORTED_Pause |
  2278. SUPPORTED_Asym_Pause);
  2279. bp->port.advertising[0] = bp->port.supported[0];
  2280. bp->link_params.bp = bp;
  2281. bp->link_params.port = BP_PORT(bp);
  2282. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2283. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2284. bp->link_params.req_line_speed[0] = SPEED_10000;
  2285. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2286. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2287. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2288. bp->link_vars.line_speed = SPEED_10000;
  2289. bp->link_vars.link_status =
  2290. (LINK_STATUS_LINK_UP |
  2291. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2292. bp->link_vars.link_up = 1;
  2293. bp->link_vars.duplex = DUPLEX_FULL;
  2294. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2295. __bnx2x_link_report(bp);
  2296. bnx2x_sample_bulletin(bp);
  2297. /* if bulletin board did not have an update for link status
  2298. * __bnx2x_link_report will report current status
  2299. * but it will NOT duplicate report in case of already reported
  2300. * during sampling bulletin board.
  2301. */
  2302. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2303. }
  2304. }
  2305. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2306. u16 vlan_val, u8 allowed_prio)
  2307. {
  2308. struct bnx2x_func_state_params func_params = {NULL};
  2309. struct bnx2x_func_afex_update_params *f_update_params =
  2310. &func_params.params.afex_update;
  2311. func_params.f_obj = &bp->func_obj;
  2312. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2313. /* no need to wait for RAMROD completion, so don't
  2314. * set RAMROD_COMP_WAIT flag
  2315. */
  2316. f_update_params->vif_id = vifid;
  2317. f_update_params->afex_default_vlan = vlan_val;
  2318. f_update_params->allowed_priorities = allowed_prio;
  2319. /* if ramrod can not be sent, response to MCP immediately */
  2320. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2321. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2322. return 0;
  2323. }
  2324. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2325. u16 vif_index, u8 func_bit_map)
  2326. {
  2327. struct bnx2x_func_state_params func_params = {NULL};
  2328. struct bnx2x_func_afex_viflists_params *update_params =
  2329. &func_params.params.afex_viflists;
  2330. int rc;
  2331. u32 drv_msg_code;
  2332. /* validate only LIST_SET and LIST_GET are received from switch */
  2333. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2334. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2335. cmd_type);
  2336. func_params.f_obj = &bp->func_obj;
  2337. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2338. /* set parameters according to cmd_type */
  2339. update_params->afex_vif_list_command = cmd_type;
  2340. update_params->vif_list_index = vif_index;
  2341. update_params->func_bit_map =
  2342. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2343. update_params->func_to_clear = 0;
  2344. drv_msg_code =
  2345. (cmd_type == VIF_LIST_RULE_GET) ?
  2346. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2347. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2348. /* if ramrod can not be sent, respond to MCP immediately for
  2349. * SET and GET requests (other are not triggered from MCP)
  2350. */
  2351. rc = bnx2x_func_state_change(bp, &func_params);
  2352. if (rc < 0)
  2353. bnx2x_fw_command(bp, drv_msg_code, 0);
  2354. return 0;
  2355. }
  2356. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2357. {
  2358. struct afex_stats afex_stats;
  2359. u32 func = BP_ABS_FUNC(bp);
  2360. u32 mf_config;
  2361. u16 vlan_val;
  2362. u32 vlan_prio;
  2363. u16 vif_id;
  2364. u8 allowed_prio;
  2365. u8 vlan_mode;
  2366. u32 addr_to_write, vifid, addrs, stats_type, i;
  2367. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2368. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2369. DP(BNX2X_MSG_MCP,
  2370. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2371. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2372. }
  2373. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2374. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2375. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2376. DP(BNX2X_MSG_MCP,
  2377. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2378. vifid, addrs);
  2379. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2380. addrs);
  2381. }
  2382. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2383. addr_to_write = SHMEM2_RD(bp,
  2384. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2385. stats_type = SHMEM2_RD(bp,
  2386. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2387. DP(BNX2X_MSG_MCP,
  2388. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2389. addr_to_write);
  2390. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2391. /* write response to scratchpad, for MCP */
  2392. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2393. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2394. *(((u32 *)(&afex_stats))+i));
  2395. /* send ack message to MCP */
  2396. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2397. }
  2398. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2399. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2400. bp->mf_config[BP_VN(bp)] = mf_config;
  2401. DP(BNX2X_MSG_MCP,
  2402. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2403. mf_config);
  2404. /* if VIF_SET is "enabled" */
  2405. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2406. /* set rate limit directly to internal RAM */
  2407. struct cmng_init_input cmng_input;
  2408. struct rate_shaping_vars_per_vn m_rs_vn;
  2409. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2410. u32 addr = BAR_XSTRORM_INTMEM +
  2411. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2412. bp->mf_config[BP_VN(bp)] = mf_config;
  2413. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2414. m_rs_vn.vn_counter.rate =
  2415. cmng_input.vnic_max_rate[BP_VN(bp)];
  2416. m_rs_vn.vn_counter.quota =
  2417. (m_rs_vn.vn_counter.rate *
  2418. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2419. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2420. /* read relevant values from mf_cfg struct in shmem */
  2421. vif_id =
  2422. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2423. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2424. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2425. vlan_val =
  2426. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2427. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2428. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2429. vlan_prio = (mf_config &
  2430. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2431. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2432. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2433. vlan_mode =
  2434. (MF_CFG_RD(bp,
  2435. func_mf_config[func].afex_config) &
  2436. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2437. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2438. allowed_prio =
  2439. (MF_CFG_RD(bp,
  2440. func_mf_config[func].afex_config) &
  2441. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2442. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2443. /* send ramrod to FW, return in case of failure */
  2444. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2445. allowed_prio))
  2446. return;
  2447. bp->afex_def_vlan_tag = vlan_val;
  2448. bp->afex_vlan_mode = vlan_mode;
  2449. } else {
  2450. /* notify link down because BP->flags is disabled */
  2451. bnx2x_link_report(bp);
  2452. /* send INVALID VIF ramrod to FW */
  2453. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2454. /* Reset the default afex VLAN */
  2455. bp->afex_def_vlan_tag = -1;
  2456. }
  2457. }
  2458. }
  2459. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2460. {
  2461. struct bnx2x_func_switch_update_params *switch_update_params;
  2462. struct bnx2x_func_state_params func_params;
  2463. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2464. switch_update_params = &func_params.params.switch_update;
  2465. func_params.f_obj = &bp->func_obj;
  2466. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2467. if (IS_MF_UFP(bp) || IS_MF_BD(bp)) {
  2468. int func = BP_ABS_FUNC(bp);
  2469. u32 val;
  2470. /* Re-learn the S-tag from shmem */
  2471. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2472. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2473. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2474. bp->mf_ov = val;
  2475. } else {
  2476. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2477. goto fail;
  2478. }
  2479. /* Configure new S-tag in LLH */
  2480. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2481. bp->mf_ov);
  2482. /* Send Ramrod to update FW of change */
  2483. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2484. &switch_update_params->changes);
  2485. switch_update_params->vlan = bp->mf_ov;
  2486. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2487. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2488. bp->mf_ov);
  2489. goto fail;
  2490. } else {
  2491. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n",
  2492. bp->mf_ov);
  2493. }
  2494. } else {
  2495. goto fail;
  2496. }
  2497. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2498. return;
  2499. fail:
  2500. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2501. }
  2502. static void bnx2x_pmf_update(struct bnx2x *bp)
  2503. {
  2504. int port = BP_PORT(bp);
  2505. u32 val;
  2506. bp->port.pmf = 1;
  2507. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2508. /*
  2509. * We need the mb() to ensure the ordering between the writing to
  2510. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2511. */
  2512. smp_mb();
  2513. /* queue a periodic task */
  2514. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2515. bnx2x_dcbx_pmf_update(bp);
  2516. /* enable nig attention */
  2517. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2518. if (bp->common.int_block == INT_BLOCK_HC) {
  2519. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2520. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2521. } else if (!CHIP_IS_E1x(bp)) {
  2522. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2523. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2524. }
  2525. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2526. }
  2527. /* end of Link */
  2528. /* slow path */
  2529. /*
  2530. * General service functions
  2531. */
  2532. /* send the MCP a request, block until there is a reply */
  2533. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2534. {
  2535. int mb_idx = BP_FW_MB_IDX(bp);
  2536. u32 seq;
  2537. u32 rc = 0;
  2538. u32 cnt = 1;
  2539. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2540. mutex_lock(&bp->fw_mb_mutex);
  2541. seq = ++bp->fw_seq;
  2542. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2543. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2544. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2545. (command | seq), param);
  2546. do {
  2547. /* let the FW do it's magic ... */
  2548. msleep(delay);
  2549. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2550. /* Give the FW up to 5 second (500*10ms) */
  2551. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2552. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2553. cnt*delay, rc, seq);
  2554. /* is this a reply to our command? */
  2555. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2556. rc &= FW_MSG_CODE_MASK;
  2557. else {
  2558. /* FW BUG! */
  2559. BNX2X_ERR("FW failed to respond!\n");
  2560. bnx2x_fw_dump(bp);
  2561. rc = 0;
  2562. }
  2563. mutex_unlock(&bp->fw_mb_mutex);
  2564. return rc;
  2565. }
  2566. static void storm_memset_func_cfg(struct bnx2x *bp,
  2567. struct tstorm_eth_function_common_config *tcfg,
  2568. u16 abs_fid)
  2569. {
  2570. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2571. u32 addr = BAR_TSTRORM_INTMEM +
  2572. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2573. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2574. }
  2575. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2576. {
  2577. if (CHIP_IS_E1x(bp)) {
  2578. struct tstorm_eth_function_common_config tcfg = {0};
  2579. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2580. }
  2581. /* Enable the function in the FW */
  2582. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2583. storm_memset_func_en(bp, p->func_id, 1);
  2584. /* spq */
  2585. if (p->spq_active) {
  2586. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2587. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2588. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2589. }
  2590. }
  2591. /**
  2592. * bnx2x_get_common_flags - Return common flags
  2593. *
  2594. * @bp device handle
  2595. * @fp queue handle
  2596. * @zero_stats TRUE if statistics zeroing is needed
  2597. *
  2598. * Return the flags that are common for the Tx-only and not normal connections.
  2599. */
  2600. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2601. struct bnx2x_fastpath *fp,
  2602. bool zero_stats)
  2603. {
  2604. unsigned long flags = 0;
  2605. /* PF driver will always initialize the Queue to an ACTIVE state */
  2606. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2607. /* tx only connections collect statistics (on the same index as the
  2608. * parent connection). The statistics are zeroed when the parent
  2609. * connection is initialized.
  2610. */
  2611. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2612. if (zero_stats)
  2613. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2614. if (bp->flags & TX_SWITCHING)
  2615. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2616. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2617. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2618. #ifdef BNX2X_STOP_ON_ERROR
  2619. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2620. #endif
  2621. return flags;
  2622. }
  2623. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2624. struct bnx2x_fastpath *fp,
  2625. bool leading)
  2626. {
  2627. unsigned long flags = 0;
  2628. /* calculate other queue flags */
  2629. if (IS_MF_SD(bp))
  2630. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2631. if (IS_FCOE_FP(fp)) {
  2632. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2633. /* For FCoE - force usage of default priority (for afex) */
  2634. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2635. }
  2636. if (fp->mode != TPA_MODE_DISABLED) {
  2637. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2638. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2639. if (fp->mode == TPA_MODE_GRO)
  2640. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2641. }
  2642. if (leading) {
  2643. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2644. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2645. }
  2646. /* Always set HW VLAN stripping */
  2647. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2648. /* configure silent vlan removal */
  2649. if (IS_MF_AFEX(bp))
  2650. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2651. return flags | bnx2x_get_common_flags(bp, fp, true);
  2652. }
  2653. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2654. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2655. u8 cos)
  2656. {
  2657. gen_init->stat_id = bnx2x_stats_id(fp);
  2658. gen_init->spcl_id = fp->cl_id;
  2659. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2660. if (IS_FCOE_FP(fp))
  2661. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2662. else
  2663. gen_init->mtu = bp->dev->mtu;
  2664. gen_init->cos = cos;
  2665. gen_init->fp_hsi = ETH_FP_HSI_VERSION;
  2666. }
  2667. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2668. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2669. struct bnx2x_rxq_setup_params *rxq_init)
  2670. {
  2671. u8 max_sge = 0;
  2672. u16 sge_sz = 0;
  2673. u16 tpa_agg_size = 0;
  2674. if (fp->mode != TPA_MODE_DISABLED) {
  2675. pause->sge_th_lo = SGE_TH_LO(bp);
  2676. pause->sge_th_hi = SGE_TH_HI(bp);
  2677. /* validate SGE ring has enough to cross high threshold */
  2678. WARN_ON(bp->dropless_fc &&
  2679. pause->sge_th_hi + FW_PREFETCH_CNT >
  2680. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2681. tpa_agg_size = TPA_AGG_SIZE;
  2682. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2683. SGE_PAGE_SHIFT;
  2684. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2685. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2686. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2687. }
  2688. /* pause - not for e1 */
  2689. if (!CHIP_IS_E1(bp)) {
  2690. pause->bd_th_lo = BD_TH_LO(bp);
  2691. pause->bd_th_hi = BD_TH_HI(bp);
  2692. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2693. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2694. /*
  2695. * validate that rings have enough entries to cross
  2696. * high thresholds
  2697. */
  2698. WARN_ON(bp->dropless_fc &&
  2699. pause->bd_th_hi + FW_PREFETCH_CNT >
  2700. bp->rx_ring_size);
  2701. WARN_ON(bp->dropless_fc &&
  2702. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2703. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2704. pause->pri_map = 1;
  2705. }
  2706. /* rxq setup */
  2707. rxq_init->dscr_map = fp->rx_desc_mapping;
  2708. rxq_init->sge_map = fp->rx_sge_mapping;
  2709. rxq_init->rcq_map = fp->rx_comp_mapping;
  2710. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2711. /* This should be a maximum number of data bytes that may be
  2712. * placed on the BD (not including paddings).
  2713. */
  2714. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2715. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2716. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2717. rxq_init->tpa_agg_sz = tpa_agg_size;
  2718. rxq_init->sge_buf_sz = sge_sz;
  2719. rxq_init->max_sges_pkt = max_sge;
  2720. rxq_init->rss_engine_id = BP_FUNC(bp);
  2721. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2722. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2723. *
  2724. * For PF Clients it should be the maximum available number.
  2725. * VF driver(s) may want to define it to a smaller value.
  2726. */
  2727. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2728. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2729. rxq_init->fw_sb_id = fp->fw_sb_id;
  2730. if (IS_FCOE_FP(fp))
  2731. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2732. else
  2733. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2734. /* configure silent vlan removal
  2735. * if multi function mode is afex, then mask default vlan
  2736. */
  2737. if (IS_MF_AFEX(bp)) {
  2738. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2739. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2740. }
  2741. }
  2742. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2743. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2744. u8 cos)
  2745. {
  2746. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2747. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2748. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2749. txq_init->fw_sb_id = fp->fw_sb_id;
  2750. /*
  2751. * set the tss leading client id for TX classification ==
  2752. * leading RSS client id
  2753. */
  2754. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2755. if (IS_FCOE_FP(fp)) {
  2756. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2757. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2758. }
  2759. }
  2760. static void bnx2x_pf_init(struct bnx2x *bp)
  2761. {
  2762. struct bnx2x_func_init_params func_init = {0};
  2763. struct event_ring_data eq_data = { {0} };
  2764. if (!CHIP_IS_E1x(bp)) {
  2765. /* reset IGU PF statistics: MSIX + ATTN */
  2766. /* PF */
  2767. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2768. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2769. (CHIP_MODE_IS_4_PORT(bp) ?
  2770. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2771. /* ATTN */
  2772. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2773. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2774. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2775. (CHIP_MODE_IS_4_PORT(bp) ?
  2776. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2777. }
  2778. func_init.spq_active = true;
  2779. func_init.pf_id = BP_FUNC(bp);
  2780. func_init.func_id = BP_FUNC(bp);
  2781. func_init.spq_map = bp->spq_mapping;
  2782. func_init.spq_prod = bp->spq_prod_idx;
  2783. bnx2x_func_init(bp, &func_init);
  2784. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2785. /*
  2786. * Congestion management values depend on the link rate
  2787. * There is no active link so initial link rate is set to 10 Gbps.
  2788. * When the link comes up The congestion management values are
  2789. * re-calculated according to the actual link rate.
  2790. */
  2791. bp->link_vars.line_speed = SPEED_10000;
  2792. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2793. /* Only the PMF sets the HW */
  2794. if (bp->port.pmf)
  2795. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2796. /* init Event Queue - PCI bus guarantees correct endianity*/
  2797. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2798. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2799. eq_data.producer = bp->eq_prod;
  2800. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2801. eq_data.sb_id = DEF_SB_ID;
  2802. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2803. }
  2804. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2805. {
  2806. int port = BP_PORT(bp);
  2807. bnx2x_tx_disable(bp);
  2808. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2809. }
  2810. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2811. {
  2812. int port = BP_PORT(bp);
  2813. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2814. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2815. /* Tx queue should be only re-enabled */
  2816. netif_tx_wake_all_queues(bp->dev);
  2817. /*
  2818. * Should not call netif_carrier_on since it will be called if the link
  2819. * is up when checking for link state
  2820. */
  2821. }
  2822. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2823. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2824. {
  2825. struct eth_stats_info *ether_stat =
  2826. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2827. struct bnx2x_vlan_mac_obj *mac_obj =
  2828. &bp->sp_objs->mac_obj;
  2829. int i;
  2830. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2831. ETH_STAT_INFO_VERSION_LEN);
  2832. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2833. * mac_local field in ether_stat struct. The base address is offset by 2
  2834. * bytes to account for the field being 8 bytes but a mac address is
  2835. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2836. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2837. * allocated by the ether_stat struct, so the macs will land in their
  2838. * proper positions.
  2839. */
  2840. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2841. memset(ether_stat->mac_local + i, 0,
  2842. sizeof(ether_stat->mac_local[0]));
  2843. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2844. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2845. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2846. ETH_ALEN);
  2847. ether_stat->mtu_size = bp->dev->mtu;
  2848. if (bp->dev->features & NETIF_F_RXCSUM)
  2849. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2850. if (bp->dev->features & NETIF_F_TSO)
  2851. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2852. ether_stat->feature_flags |= bp->common.boot_mode;
  2853. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2854. ether_stat->txq_size = bp->tx_ring_size;
  2855. ether_stat->rxq_size = bp->rx_ring_size;
  2856. #ifdef CONFIG_BNX2X_SRIOV
  2857. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2858. #endif
  2859. }
  2860. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2861. {
  2862. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2863. struct fcoe_stats_info *fcoe_stat =
  2864. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2865. if (!CNIC_LOADED(bp))
  2866. return;
  2867. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2868. fcoe_stat->qos_priority =
  2869. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2870. /* insert FCoE stats from ramrod response */
  2871. if (!NO_FCOE(bp)) {
  2872. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2873. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2874. tstorm_queue_statistics;
  2875. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2876. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2877. xstorm_queue_statistics;
  2878. struct fcoe_statistics_params *fw_fcoe_stat =
  2879. &bp->fw_stats_data->fcoe;
  2880. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2881. fcoe_stat->rx_bytes_lo,
  2882. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2883. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2884. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2885. fcoe_stat->rx_bytes_lo,
  2886. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2887. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2888. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2889. fcoe_stat->rx_bytes_lo,
  2890. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2891. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2892. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2893. fcoe_stat->rx_bytes_lo,
  2894. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2895. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2896. fcoe_stat->rx_frames_lo,
  2897. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2898. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2899. fcoe_stat->rx_frames_lo,
  2900. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2901. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2902. fcoe_stat->rx_frames_lo,
  2903. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2904. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2905. fcoe_stat->rx_frames_lo,
  2906. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2907. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2908. fcoe_stat->tx_bytes_lo,
  2909. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2910. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2911. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2912. fcoe_stat->tx_bytes_lo,
  2913. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2914. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2915. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2916. fcoe_stat->tx_bytes_lo,
  2917. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2918. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2919. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2920. fcoe_stat->tx_bytes_lo,
  2921. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2922. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2923. fcoe_stat->tx_frames_lo,
  2924. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2925. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2926. fcoe_stat->tx_frames_lo,
  2927. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2928. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2929. fcoe_stat->tx_frames_lo,
  2930. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2931. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2932. fcoe_stat->tx_frames_lo,
  2933. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2934. }
  2935. /* ask L5 driver to add data to the struct */
  2936. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2937. }
  2938. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2939. {
  2940. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2941. struct iscsi_stats_info *iscsi_stat =
  2942. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2943. if (!CNIC_LOADED(bp))
  2944. return;
  2945. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2946. ETH_ALEN);
  2947. iscsi_stat->qos_priority =
  2948. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2949. /* ask L5 driver to add data to the struct */
  2950. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2951. }
  2952. /* called due to MCP event (on pmf):
  2953. * reread new bandwidth configuration
  2954. * configure FW
  2955. * notify others function about the change
  2956. */
  2957. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2958. {
  2959. if (bp->link_vars.link_up) {
  2960. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2961. bnx2x_link_sync_notify(bp);
  2962. }
  2963. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2964. }
  2965. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2966. {
  2967. bnx2x_config_mf_bw(bp);
  2968. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2969. }
  2970. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2971. {
  2972. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2973. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2974. }
  2975. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2976. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2977. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2978. {
  2979. enum drv_info_opcode op_code;
  2980. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2981. bool release = false;
  2982. int wait;
  2983. /* if drv_info version supported by MFW doesn't match - send NACK */
  2984. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2985. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2986. return;
  2987. }
  2988. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2989. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2990. /* Must prevent other flows from accessing drv_info_to_mcp */
  2991. mutex_lock(&bp->drv_info_mutex);
  2992. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2993. sizeof(union drv_info_to_mcp));
  2994. switch (op_code) {
  2995. case ETH_STATS_OPCODE:
  2996. bnx2x_drv_info_ether_stat(bp);
  2997. break;
  2998. case FCOE_STATS_OPCODE:
  2999. bnx2x_drv_info_fcoe_stat(bp);
  3000. break;
  3001. case ISCSI_STATS_OPCODE:
  3002. bnx2x_drv_info_iscsi_stat(bp);
  3003. break;
  3004. default:
  3005. /* if op code isn't supported - send NACK */
  3006. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3007. goto out;
  3008. }
  3009. /* if we got drv_info attn from MFW then these fields are defined in
  3010. * shmem2 for sure
  3011. */
  3012. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3013. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3014. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3015. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3016. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3017. /* Since possible management wants both this and get_driver_version
  3018. * need to wait until management notifies us it finished utilizing
  3019. * the buffer.
  3020. */
  3021. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3022. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3023. } else if (!bp->drv_info_mng_owner) {
  3024. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3025. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3026. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3027. /* Management is done; need to clear indication */
  3028. if (indication & bit) {
  3029. SHMEM2_WR(bp, mfw_drv_indication,
  3030. indication & ~bit);
  3031. release = true;
  3032. break;
  3033. }
  3034. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3035. }
  3036. }
  3037. if (!release) {
  3038. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3039. bp->drv_info_mng_owner = true;
  3040. }
  3041. out:
  3042. mutex_unlock(&bp->drv_info_mutex);
  3043. }
  3044. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3045. {
  3046. u8 vals[4];
  3047. int i = 0;
  3048. if (bnx2x_format) {
  3049. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3050. &vals[0], &vals[1], &vals[2], &vals[3]);
  3051. if (i > 0)
  3052. vals[0] -= '0';
  3053. } else {
  3054. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3055. &vals[0], &vals[1], &vals[2], &vals[3]);
  3056. }
  3057. while (i < 4)
  3058. vals[i++] = 0;
  3059. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3060. }
  3061. void bnx2x_update_mng_version(struct bnx2x *bp)
  3062. {
  3063. u32 iscsiver = DRV_VER_NOT_LOADED;
  3064. u32 fcoever = DRV_VER_NOT_LOADED;
  3065. u32 ethver = DRV_VER_NOT_LOADED;
  3066. int idx = BP_FW_MB_IDX(bp);
  3067. u8 *version;
  3068. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3069. return;
  3070. mutex_lock(&bp->drv_info_mutex);
  3071. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3072. if (bp->drv_info_mng_owner)
  3073. goto out;
  3074. if (bp->state != BNX2X_STATE_OPEN)
  3075. goto out;
  3076. /* Parse ethernet driver version */
  3077. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3078. if (!CNIC_LOADED(bp))
  3079. goto out;
  3080. /* Try getting storage driver version via cnic */
  3081. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3082. sizeof(union drv_info_to_mcp));
  3083. bnx2x_drv_info_iscsi_stat(bp);
  3084. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3085. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3086. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3087. sizeof(union drv_info_to_mcp));
  3088. bnx2x_drv_info_fcoe_stat(bp);
  3089. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3090. fcoever = bnx2x_update_mng_version_utility(version, false);
  3091. out:
  3092. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3093. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3094. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3095. mutex_unlock(&bp->drv_info_mutex);
  3096. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3097. ethver, iscsiver, fcoever);
  3098. }
  3099. void bnx2x_update_mfw_dump(struct bnx2x *bp)
  3100. {
  3101. u32 drv_ver;
  3102. u32 valid_dump;
  3103. if (!SHMEM2_HAS(bp, drv_info))
  3104. return;
  3105. /* Update Driver load time, possibly broken in y2038 */
  3106. SHMEM2_WR(bp, drv_info.epoc, (u32)ktime_get_real_seconds());
  3107. drv_ver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3108. SHMEM2_WR(bp, drv_info.drv_ver, drv_ver);
  3109. SHMEM2_WR(bp, drv_info.fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  3110. /* Check & notify On-Chip dump. */
  3111. valid_dump = SHMEM2_RD(bp, drv_info.valid_dump);
  3112. if (valid_dump & FIRST_DUMP_VALID)
  3113. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 1st partition\n");
  3114. if (valid_dump & SECOND_DUMP_VALID)
  3115. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 2nd partition\n");
  3116. }
  3117. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3118. {
  3119. u32 cmd_ok, cmd_fail;
  3120. /* sanity */
  3121. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3122. event & DRV_STATUS_OEM_EVENT_MASK) {
  3123. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3124. return;
  3125. }
  3126. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3127. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3128. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3129. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3130. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3131. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3132. }
  3133. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3134. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3135. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3136. /* This is the only place besides the function initialization
  3137. * where the bp->flags can change so it is done without any
  3138. * locks
  3139. */
  3140. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3141. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3142. bp->flags |= MF_FUNC_DIS;
  3143. bnx2x_e1h_disable(bp);
  3144. } else {
  3145. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3146. bp->flags &= ~MF_FUNC_DIS;
  3147. bnx2x_e1h_enable(bp);
  3148. }
  3149. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3150. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3151. }
  3152. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3153. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3154. bnx2x_config_mf_bw(bp);
  3155. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3156. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3157. }
  3158. /* Report results to MCP */
  3159. if (event)
  3160. bnx2x_fw_command(bp, cmd_fail, 0);
  3161. else
  3162. bnx2x_fw_command(bp, cmd_ok, 0);
  3163. }
  3164. /* must be called under the spq lock */
  3165. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3166. {
  3167. struct eth_spe *next_spe = bp->spq_prod_bd;
  3168. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3169. bp->spq_prod_bd = bp->spq;
  3170. bp->spq_prod_idx = 0;
  3171. DP(BNX2X_MSG_SP, "end of spq\n");
  3172. } else {
  3173. bp->spq_prod_bd++;
  3174. bp->spq_prod_idx++;
  3175. }
  3176. return next_spe;
  3177. }
  3178. /* must be called under the spq lock */
  3179. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3180. {
  3181. int func = BP_FUNC(bp);
  3182. /*
  3183. * Make sure that BD data is updated before writing the producer:
  3184. * BD data is written to the memory, the producer is read from the
  3185. * memory, thus we need a full memory barrier to ensure the ordering.
  3186. */
  3187. mb();
  3188. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3189. bp->spq_prod_idx);
  3190. mmiowb();
  3191. }
  3192. /**
  3193. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3194. *
  3195. * @cmd: command to check
  3196. * @cmd_type: command type
  3197. */
  3198. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3199. {
  3200. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3201. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3202. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3203. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3204. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3205. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3206. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3207. return true;
  3208. else
  3209. return false;
  3210. }
  3211. /**
  3212. * bnx2x_sp_post - place a single command on an SP ring
  3213. *
  3214. * @bp: driver handle
  3215. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3216. * @cid: SW CID the command is related to
  3217. * @data_hi: command private data address (high 32 bits)
  3218. * @data_lo: command private data address (low 32 bits)
  3219. * @cmd_type: command type (e.g. NONE, ETH)
  3220. *
  3221. * SP data is handled as if it's always an address pair, thus data fields are
  3222. * not swapped to little endian in upper functions. Instead this function swaps
  3223. * data as if it's two u32 fields.
  3224. */
  3225. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3226. u32 data_hi, u32 data_lo, int cmd_type)
  3227. {
  3228. struct eth_spe *spe;
  3229. u16 type;
  3230. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3231. #ifdef BNX2X_STOP_ON_ERROR
  3232. if (unlikely(bp->panic)) {
  3233. BNX2X_ERR("Can't post SP when there is panic\n");
  3234. return -EIO;
  3235. }
  3236. #endif
  3237. spin_lock_bh(&bp->spq_lock);
  3238. if (common) {
  3239. if (!atomic_read(&bp->eq_spq_left)) {
  3240. BNX2X_ERR("BUG! EQ ring full!\n");
  3241. spin_unlock_bh(&bp->spq_lock);
  3242. bnx2x_panic();
  3243. return -EBUSY;
  3244. }
  3245. } else if (!atomic_read(&bp->cq_spq_left)) {
  3246. BNX2X_ERR("BUG! SPQ ring full!\n");
  3247. spin_unlock_bh(&bp->spq_lock);
  3248. bnx2x_panic();
  3249. return -EBUSY;
  3250. }
  3251. spe = bnx2x_sp_get_next(bp);
  3252. /* CID needs port number to be encoded int it */
  3253. spe->hdr.conn_and_cmd_data =
  3254. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3255. HW_CID(bp, cid));
  3256. /* In some cases, type may already contain the func-id
  3257. * mainly in SRIOV related use cases, so we add it here only
  3258. * if it's not already set.
  3259. */
  3260. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3261. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3262. SPE_HDR_CONN_TYPE;
  3263. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3264. SPE_HDR_FUNCTION_ID);
  3265. } else {
  3266. type = cmd_type;
  3267. }
  3268. spe->hdr.type = cpu_to_le16(type);
  3269. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3270. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3271. /*
  3272. * It's ok if the actual decrement is issued towards the memory
  3273. * somewhere between the spin_lock and spin_unlock. Thus no
  3274. * more explicit memory barrier is needed.
  3275. */
  3276. if (common)
  3277. atomic_dec(&bp->eq_spq_left);
  3278. else
  3279. atomic_dec(&bp->cq_spq_left);
  3280. DP(BNX2X_MSG_SP,
  3281. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3282. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3283. (u32)(U64_LO(bp->spq_mapping) +
  3284. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3285. HW_CID(bp, cid), data_hi, data_lo, type,
  3286. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3287. bnx2x_sp_prod_update(bp);
  3288. spin_unlock_bh(&bp->spq_lock);
  3289. return 0;
  3290. }
  3291. /* acquire split MCP access lock register */
  3292. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3293. {
  3294. u32 j, val;
  3295. int rc = 0;
  3296. might_sleep();
  3297. for (j = 0; j < 1000; j++) {
  3298. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3299. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3300. if (val & MCPR_ACCESS_LOCK_LOCK)
  3301. break;
  3302. usleep_range(5000, 10000);
  3303. }
  3304. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3305. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3306. rc = -EBUSY;
  3307. }
  3308. return rc;
  3309. }
  3310. /* release split MCP access lock register */
  3311. static void bnx2x_release_alr(struct bnx2x *bp)
  3312. {
  3313. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3314. }
  3315. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3316. #define BNX2X_DEF_SB_IDX 0x0002
  3317. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3318. {
  3319. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3320. u16 rc = 0;
  3321. barrier(); /* status block is written to by the chip */
  3322. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3323. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3324. rc |= BNX2X_DEF_SB_ATT_IDX;
  3325. }
  3326. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3327. bp->def_idx = def_sb->sp_sb.running_index;
  3328. rc |= BNX2X_DEF_SB_IDX;
  3329. }
  3330. /* Do not reorder: indices reading should complete before handling */
  3331. barrier();
  3332. return rc;
  3333. }
  3334. /*
  3335. * slow path service functions
  3336. */
  3337. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3338. {
  3339. int port = BP_PORT(bp);
  3340. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3341. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3342. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3343. NIG_REG_MASK_INTERRUPT_PORT0;
  3344. u32 aeu_mask;
  3345. u32 nig_mask = 0;
  3346. u32 reg_addr;
  3347. if (bp->attn_state & asserted)
  3348. BNX2X_ERR("IGU ERROR\n");
  3349. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3350. aeu_mask = REG_RD(bp, aeu_addr);
  3351. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3352. aeu_mask, asserted);
  3353. aeu_mask &= ~(asserted & 0x3ff);
  3354. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3355. REG_WR(bp, aeu_addr, aeu_mask);
  3356. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3357. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3358. bp->attn_state |= asserted;
  3359. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3360. if (asserted & ATTN_HARD_WIRED_MASK) {
  3361. if (asserted & ATTN_NIG_FOR_FUNC) {
  3362. bnx2x_acquire_phy_lock(bp);
  3363. /* save nig interrupt mask */
  3364. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3365. /* If nig_mask is not set, no need to call the update
  3366. * function.
  3367. */
  3368. if (nig_mask) {
  3369. REG_WR(bp, nig_int_mask_addr, 0);
  3370. bnx2x_link_attn(bp);
  3371. }
  3372. /* handle unicore attn? */
  3373. }
  3374. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3375. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3376. if (asserted & GPIO_2_FUNC)
  3377. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3378. if (asserted & GPIO_3_FUNC)
  3379. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3380. if (asserted & GPIO_4_FUNC)
  3381. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3382. if (port == 0) {
  3383. if (asserted & ATTN_GENERAL_ATTN_1) {
  3384. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3385. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3386. }
  3387. if (asserted & ATTN_GENERAL_ATTN_2) {
  3388. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3389. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3390. }
  3391. if (asserted & ATTN_GENERAL_ATTN_3) {
  3392. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3393. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3394. }
  3395. } else {
  3396. if (asserted & ATTN_GENERAL_ATTN_4) {
  3397. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3398. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3399. }
  3400. if (asserted & ATTN_GENERAL_ATTN_5) {
  3401. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3402. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3403. }
  3404. if (asserted & ATTN_GENERAL_ATTN_6) {
  3405. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3406. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3407. }
  3408. }
  3409. } /* if hardwired */
  3410. if (bp->common.int_block == INT_BLOCK_HC)
  3411. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3412. COMMAND_REG_ATTN_BITS_SET);
  3413. else
  3414. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3415. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3416. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3417. REG_WR(bp, reg_addr, asserted);
  3418. /* now set back the mask */
  3419. if (asserted & ATTN_NIG_FOR_FUNC) {
  3420. /* Verify that IGU ack through BAR was written before restoring
  3421. * NIG mask. This loop should exit after 2-3 iterations max.
  3422. */
  3423. if (bp->common.int_block != INT_BLOCK_HC) {
  3424. u32 cnt = 0, igu_acked;
  3425. do {
  3426. igu_acked = REG_RD(bp,
  3427. IGU_REG_ATTENTION_ACK_BITS);
  3428. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3429. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3430. if (!igu_acked)
  3431. DP(NETIF_MSG_HW,
  3432. "Failed to verify IGU ack on time\n");
  3433. barrier();
  3434. }
  3435. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3436. bnx2x_release_phy_lock(bp);
  3437. }
  3438. }
  3439. static void bnx2x_fan_failure(struct bnx2x *bp)
  3440. {
  3441. int port = BP_PORT(bp);
  3442. u32 ext_phy_config;
  3443. /* mark the failure */
  3444. ext_phy_config =
  3445. SHMEM_RD(bp,
  3446. dev_info.port_hw_config[port].external_phy_config);
  3447. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3448. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3449. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3450. ext_phy_config);
  3451. /* log the failure */
  3452. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3453. "Please contact OEM Support for assistance\n");
  3454. /* Schedule device reset (unload)
  3455. * This is due to some boards consuming sufficient power when driver is
  3456. * up to overheat if fan fails.
  3457. */
  3458. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3459. }
  3460. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3461. {
  3462. int port = BP_PORT(bp);
  3463. int reg_offset;
  3464. u32 val;
  3465. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3466. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3467. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3468. val = REG_RD(bp, reg_offset);
  3469. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3470. REG_WR(bp, reg_offset, val);
  3471. BNX2X_ERR("SPIO5 hw attention\n");
  3472. /* Fan failure attention */
  3473. bnx2x_hw_reset_phy(&bp->link_params);
  3474. bnx2x_fan_failure(bp);
  3475. }
  3476. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3477. bnx2x_acquire_phy_lock(bp);
  3478. bnx2x_handle_module_detect_int(&bp->link_params);
  3479. bnx2x_release_phy_lock(bp);
  3480. }
  3481. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3482. val = REG_RD(bp, reg_offset);
  3483. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3484. REG_WR(bp, reg_offset, val);
  3485. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3486. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3487. bnx2x_panic();
  3488. }
  3489. }
  3490. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3491. {
  3492. u32 val;
  3493. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3494. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3495. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3496. /* DORQ discard attention */
  3497. if (val & 0x2)
  3498. BNX2X_ERR("FATAL error from DORQ\n");
  3499. }
  3500. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3501. int port = BP_PORT(bp);
  3502. int reg_offset;
  3503. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3504. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3505. val = REG_RD(bp, reg_offset);
  3506. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3507. REG_WR(bp, reg_offset, val);
  3508. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3509. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3510. bnx2x_panic();
  3511. }
  3512. }
  3513. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3514. {
  3515. u32 val;
  3516. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3517. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3518. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3519. /* CFC error attention */
  3520. if (val & 0x2)
  3521. BNX2X_ERR("FATAL error from CFC\n");
  3522. }
  3523. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3524. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3525. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3526. /* RQ_USDMDP_FIFO_OVERFLOW */
  3527. if (val & 0x18000)
  3528. BNX2X_ERR("FATAL error from PXP\n");
  3529. if (!CHIP_IS_E1x(bp)) {
  3530. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3531. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3532. }
  3533. }
  3534. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3535. int port = BP_PORT(bp);
  3536. int reg_offset;
  3537. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3538. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3539. val = REG_RD(bp, reg_offset);
  3540. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3541. REG_WR(bp, reg_offset, val);
  3542. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3543. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3544. bnx2x_panic();
  3545. }
  3546. }
  3547. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3548. {
  3549. u32 val;
  3550. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3551. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3552. int func = BP_FUNC(bp);
  3553. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3554. bnx2x_read_mf_cfg(bp);
  3555. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3556. func_mf_config[BP_ABS_FUNC(bp)].config);
  3557. val = SHMEM_RD(bp,
  3558. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3559. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3560. DRV_STATUS_OEM_EVENT_MASK))
  3561. bnx2x_oem_event(bp,
  3562. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3563. DRV_STATUS_OEM_EVENT_MASK)));
  3564. if (val & DRV_STATUS_SET_MF_BW)
  3565. bnx2x_set_mf_bw(bp);
  3566. if (val & DRV_STATUS_DRV_INFO_REQ)
  3567. bnx2x_handle_drv_info_req(bp);
  3568. if (val & DRV_STATUS_VF_DISABLED)
  3569. bnx2x_schedule_iov_task(bp,
  3570. BNX2X_IOV_HANDLE_FLR);
  3571. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3572. bnx2x_pmf_update(bp);
  3573. if (bp->port.pmf &&
  3574. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3575. bp->dcbx_enabled > 0)
  3576. /* start dcbx state machine */
  3577. bnx2x_dcbx_set_params(bp,
  3578. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3579. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3580. bnx2x_handle_afex_cmd(bp,
  3581. val & DRV_STATUS_AFEX_EVENT_MASK);
  3582. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3583. bnx2x_handle_eee_event(bp);
  3584. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3585. bnx2x_handle_update_svid_cmd(bp);
  3586. if (bp->link_vars.periodic_flags &
  3587. PERIODIC_FLAGS_LINK_EVENT) {
  3588. /* sync with link */
  3589. bnx2x_acquire_phy_lock(bp);
  3590. bp->link_vars.periodic_flags &=
  3591. ~PERIODIC_FLAGS_LINK_EVENT;
  3592. bnx2x_release_phy_lock(bp);
  3593. if (IS_MF(bp))
  3594. bnx2x_link_sync_notify(bp);
  3595. bnx2x_link_report(bp);
  3596. }
  3597. /* Always call it here: bnx2x_link_report() will
  3598. * prevent the link indication duplication.
  3599. */
  3600. bnx2x__link_status_update(bp);
  3601. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3602. BNX2X_ERR("MC assert!\n");
  3603. bnx2x_mc_assert(bp);
  3604. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3605. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3606. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3607. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3608. bnx2x_panic();
  3609. } else if (attn & BNX2X_MCP_ASSERT) {
  3610. BNX2X_ERR("MCP assert!\n");
  3611. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3612. bnx2x_fw_dump(bp);
  3613. } else
  3614. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3615. }
  3616. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3617. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3618. if (attn & BNX2X_GRC_TIMEOUT) {
  3619. val = CHIP_IS_E1(bp) ? 0 :
  3620. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3621. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3622. }
  3623. if (attn & BNX2X_GRC_RSV) {
  3624. val = CHIP_IS_E1(bp) ? 0 :
  3625. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3626. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3627. }
  3628. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3629. }
  3630. }
  3631. /*
  3632. * Bits map:
  3633. * 0-7 - Engine0 load counter.
  3634. * 8-15 - Engine1 load counter.
  3635. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3636. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3637. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3638. * on the engine
  3639. * 19 - Engine1 ONE_IS_LOADED.
  3640. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3641. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3642. * just the one belonging to its engine).
  3643. *
  3644. */
  3645. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3646. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3647. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3648. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3649. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3650. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3651. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3652. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3653. /*
  3654. * Set the GLOBAL_RESET bit.
  3655. *
  3656. * Should be run under rtnl lock
  3657. */
  3658. void bnx2x_set_reset_global(struct bnx2x *bp)
  3659. {
  3660. u32 val;
  3661. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3662. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3663. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3664. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3665. }
  3666. /*
  3667. * Clear the GLOBAL_RESET bit.
  3668. *
  3669. * Should be run under rtnl lock
  3670. */
  3671. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3672. {
  3673. u32 val;
  3674. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3675. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3676. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3677. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3678. }
  3679. /*
  3680. * Checks the GLOBAL_RESET bit.
  3681. *
  3682. * should be run under rtnl lock
  3683. */
  3684. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3685. {
  3686. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3687. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3688. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3689. }
  3690. /*
  3691. * Clear RESET_IN_PROGRESS bit for the current engine.
  3692. *
  3693. * Should be run under rtnl lock
  3694. */
  3695. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3696. {
  3697. u32 val;
  3698. u32 bit = BP_PATH(bp) ?
  3699. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3700. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3701. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3702. /* Clear the bit */
  3703. val &= ~bit;
  3704. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3705. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3706. }
  3707. /*
  3708. * Set RESET_IN_PROGRESS for the current engine.
  3709. *
  3710. * should be run under rtnl lock
  3711. */
  3712. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3713. {
  3714. u32 val;
  3715. u32 bit = BP_PATH(bp) ?
  3716. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3717. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3718. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3719. /* Set the bit */
  3720. val |= bit;
  3721. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3722. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3723. }
  3724. /*
  3725. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3726. * should be run under rtnl lock
  3727. */
  3728. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3729. {
  3730. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3731. u32 bit = engine ?
  3732. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3733. /* return false if bit is set */
  3734. return (val & bit) ? false : true;
  3735. }
  3736. /*
  3737. * set pf load for the current pf.
  3738. *
  3739. * should be run under rtnl lock
  3740. */
  3741. void bnx2x_set_pf_load(struct bnx2x *bp)
  3742. {
  3743. u32 val1, val;
  3744. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3745. BNX2X_PATH0_LOAD_CNT_MASK;
  3746. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3747. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3748. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3749. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3750. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3751. /* get the current counter value */
  3752. val1 = (val & mask) >> shift;
  3753. /* set bit of that PF */
  3754. val1 |= (1 << bp->pf_num);
  3755. /* clear the old value */
  3756. val &= ~mask;
  3757. /* set the new one */
  3758. val |= ((val1 << shift) & mask);
  3759. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3760. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3761. }
  3762. /**
  3763. * bnx2x_clear_pf_load - clear pf load mark
  3764. *
  3765. * @bp: driver handle
  3766. *
  3767. * Should be run under rtnl lock.
  3768. * Decrements the load counter for the current engine. Returns
  3769. * whether other functions are still loaded
  3770. */
  3771. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3772. {
  3773. u32 val1, val;
  3774. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3775. BNX2X_PATH0_LOAD_CNT_MASK;
  3776. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3777. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3778. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3779. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3780. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3781. /* get the current counter value */
  3782. val1 = (val & mask) >> shift;
  3783. /* clear bit of that PF */
  3784. val1 &= ~(1 << bp->pf_num);
  3785. /* clear the old value */
  3786. val &= ~mask;
  3787. /* set the new one */
  3788. val |= ((val1 << shift) & mask);
  3789. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3790. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3791. return val1 != 0;
  3792. }
  3793. /*
  3794. * Read the load status for the current engine.
  3795. *
  3796. * should be run under rtnl lock
  3797. */
  3798. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3799. {
  3800. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3801. BNX2X_PATH0_LOAD_CNT_MASK);
  3802. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3803. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3804. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3805. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3806. val = (val & mask) >> shift;
  3807. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3808. engine, val);
  3809. return val != 0;
  3810. }
  3811. static void _print_parity(struct bnx2x *bp, u32 reg)
  3812. {
  3813. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3814. }
  3815. static void _print_next_block(int idx, const char *blk)
  3816. {
  3817. pr_cont("%s%s", idx ? ", " : "", blk);
  3818. }
  3819. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3820. int *par_num, bool print)
  3821. {
  3822. u32 cur_bit;
  3823. bool res;
  3824. int i;
  3825. res = false;
  3826. for (i = 0; sig; i++) {
  3827. cur_bit = (0x1UL << i);
  3828. if (sig & cur_bit) {
  3829. res |= true; /* Each bit is real error! */
  3830. if (print) {
  3831. switch (cur_bit) {
  3832. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3833. _print_next_block((*par_num)++, "BRB");
  3834. _print_parity(bp,
  3835. BRB1_REG_BRB1_PRTY_STS);
  3836. break;
  3837. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3838. _print_next_block((*par_num)++,
  3839. "PARSER");
  3840. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3841. break;
  3842. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3843. _print_next_block((*par_num)++, "TSDM");
  3844. _print_parity(bp,
  3845. TSDM_REG_TSDM_PRTY_STS);
  3846. break;
  3847. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3848. _print_next_block((*par_num)++,
  3849. "SEARCHER");
  3850. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3851. break;
  3852. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3853. _print_next_block((*par_num)++, "TCM");
  3854. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3855. break;
  3856. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3857. _print_next_block((*par_num)++,
  3858. "TSEMI");
  3859. _print_parity(bp,
  3860. TSEM_REG_TSEM_PRTY_STS_0);
  3861. _print_parity(bp,
  3862. TSEM_REG_TSEM_PRTY_STS_1);
  3863. break;
  3864. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3865. _print_next_block((*par_num)++, "XPB");
  3866. _print_parity(bp, GRCBASE_XPB +
  3867. PB_REG_PB_PRTY_STS);
  3868. break;
  3869. }
  3870. }
  3871. /* Clear the bit */
  3872. sig &= ~cur_bit;
  3873. }
  3874. }
  3875. return res;
  3876. }
  3877. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3878. int *par_num, bool *global,
  3879. bool print)
  3880. {
  3881. u32 cur_bit;
  3882. bool res;
  3883. int i;
  3884. res = false;
  3885. for (i = 0; sig; i++) {
  3886. cur_bit = (0x1UL << i);
  3887. if (sig & cur_bit) {
  3888. res |= true; /* Each bit is real error! */
  3889. switch (cur_bit) {
  3890. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3891. if (print) {
  3892. _print_next_block((*par_num)++, "PBF");
  3893. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3894. }
  3895. break;
  3896. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3897. if (print) {
  3898. _print_next_block((*par_num)++, "QM");
  3899. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3900. }
  3901. break;
  3902. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3903. if (print) {
  3904. _print_next_block((*par_num)++, "TM");
  3905. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3906. }
  3907. break;
  3908. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3909. if (print) {
  3910. _print_next_block((*par_num)++, "XSDM");
  3911. _print_parity(bp,
  3912. XSDM_REG_XSDM_PRTY_STS);
  3913. }
  3914. break;
  3915. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3916. if (print) {
  3917. _print_next_block((*par_num)++, "XCM");
  3918. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3919. }
  3920. break;
  3921. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3922. if (print) {
  3923. _print_next_block((*par_num)++,
  3924. "XSEMI");
  3925. _print_parity(bp,
  3926. XSEM_REG_XSEM_PRTY_STS_0);
  3927. _print_parity(bp,
  3928. XSEM_REG_XSEM_PRTY_STS_1);
  3929. }
  3930. break;
  3931. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3932. if (print) {
  3933. _print_next_block((*par_num)++,
  3934. "DOORBELLQ");
  3935. _print_parity(bp,
  3936. DORQ_REG_DORQ_PRTY_STS);
  3937. }
  3938. break;
  3939. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3940. if (print) {
  3941. _print_next_block((*par_num)++, "NIG");
  3942. if (CHIP_IS_E1x(bp)) {
  3943. _print_parity(bp,
  3944. NIG_REG_NIG_PRTY_STS);
  3945. } else {
  3946. _print_parity(bp,
  3947. NIG_REG_NIG_PRTY_STS_0);
  3948. _print_parity(bp,
  3949. NIG_REG_NIG_PRTY_STS_1);
  3950. }
  3951. }
  3952. break;
  3953. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3954. if (print)
  3955. _print_next_block((*par_num)++,
  3956. "VAUX PCI CORE");
  3957. *global = true;
  3958. break;
  3959. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3960. if (print) {
  3961. _print_next_block((*par_num)++,
  3962. "DEBUG");
  3963. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3964. }
  3965. break;
  3966. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3967. if (print) {
  3968. _print_next_block((*par_num)++, "USDM");
  3969. _print_parity(bp,
  3970. USDM_REG_USDM_PRTY_STS);
  3971. }
  3972. break;
  3973. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3974. if (print) {
  3975. _print_next_block((*par_num)++, "UCM");
  3976. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3977. }
  3978. break;
  3979. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3980. if (print) {
  3981. _print_next_block((*par_num)++,
  3982. "USEMI");
  3983. _print_parity(bp,
  3984. USEM_REG_USEM_PRTY_STS_0);
  3985. _print_parity(bp,
  3986. USEM_REG_USEM_PRTY_STS_1);
  3987. }
  3988. break;
  3989. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3990. if (print) {
  3991. _print_next_block((*par_num)++, "UPB");
  3992. _print_parity(bp, GRCBASE_UPB +
  3993. PB_REG_PB_PRTY_STS);
  3994. }
  3995. break;
  3996. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3997. if (print) {
  3998. _print_next_block((*par_num)++, "CSDM");
  3999. _print_parity(bp,
  4000. CSDM_REG_CSDM_PRTY_STS);
  4001. }
  4002. break;
  4003. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  4004. if (print) {
  4005. _print_next_block((*par_num)++, "CCM");
  4006. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  4007. }
  4008. break;
  4009. }
  4010. /* Clear the bit */
  4011. sig &= ~cur_bit;
  4012. }
  4013. }
  4014. return res;
  4015. }
  4016. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  4017. int *par_num, bool print)
  4018. {
  4019. u32 cur_bit;
  4020. bool res;
  4021. int i;
  4022. res = false;
  4023. for (i = 0; sig; i++) {
  4024. cur_bit = (0x1UL << i);
  4025. if (sig & cur_bit) {
  4026. res = true; /* Each bit is real error! */
  4027. if (print) {
  4028. switch (cur_bit) {
  4029. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4030. _print_next_block((*par_num)++,
  4031. "CSEMI");
  4032. _print_parity(bp,
  4033. CSEM_REG_CSEM_PRTY_STS_0);
  4034. _print_parity(bp,
  4035. CSEM_REG_CSEM_PRTY_STS_1);
  4036. break;
  4037. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4038. _print_next_block((*par_num)++, "PXP");
  4039. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4040. _print_parity(bp,
  4041. PXP2_REG_PXP2_PRTY_STS_0);
  4042. _print_parity(bp,
  4043. PXP2_REG_PXP2_PRTY_STS_1);
  4044. break;
  4045. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4046. _print_next_block((*par_num)++,
  4047. "PXPPCICLOCKCLIENT");
  4048. break;
  4049. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4050. _print_next_block((*par_num)++, "CFC");
  4051. _print_parity(bp,
  4052. CFC_REG_CFC_PRTY_STS);
  4053. break;
  4054. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4055. _print_next_block((*par_num)++, "CDU");
  4056. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4057. break;
  4058. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4059. _print_next_block((*par_num)++, "DMAE");
  4060. _print_parity(bp,
  4061. DMAE_REG_DMAE_PRTY_STS);
  4062. break;
  4063. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4064. _print_next_block((*par_num)++, "IGU");
  4065. if (CHIP_IS_E1x(bp))
  4066. _print_parity(bp,
  4067. HC_REG_HC_PRTY_STS);
  4068. else
  4069. _print_parity(bp,
  4070. IGU_REG_IGU_PRTY_STS);
  4071. break;
  4072. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4073. _print_next_block((*par_num)++, "MISC");
  4074. _print_parity(bp,
  4075. MISC_REG_MISC_PRTY_STS);
  4076. break;
  4077. }
  4078. }
  4079. /* Clear the bit */
  4080. sig &= ~cur_bit;
  4081. }
  4082. }
  4083. return res;
  4084. }
  4085. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4086. int *par_num, bool *global,
  4087. bool print)
  4088. {
  4089. bool res = false;
  4090. u32 cur_bit;
  4091. int i;
  4092. for (i = 0; sig; i++) {
  4093. cur_bit = (0x1UL << i);
  4094. if (sig & cur_bit) {
  4095. switch (cur_bit) {
  4096. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4097. if (print)
  4098. _print_next_block((*par_num)++,
  4099. "MCP ROM");
  4100. *global = true;
  4101. res = true;
  4102. break;
  4103. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4104. if (print)
  4105. _print_next_block((*par_num)++,
  4106. "MCP UMP RX");
  4107. *global = true;
  4108. res = true;
  4109. break;
  4110. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4111. if (print)
  4112. _print_next_block((*par_num)++,
  4113. "MCP UMP TX");
  4114. *global = true;
  4115. res = true;
  4116. break;
  4117. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4118. (*par_num)++;
  4119. /* clear latched SCPAD PATIRY from MCP */
  4120. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4121. 1UL << 10);
  4122. break;
  4123. }
  4124. /* Clear the bit */
  4125. sig &= ~cur_bit;
  4126. }
  4127. }
  4128. return res;
  4129. }
  4130. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4131. int *par_num, bool print)
  4132. {
  4133. u32 cur_bit;
  4134. bool res;
  4135. int i;
  4136. res = false;
  4137. for (i = 0; sig; i++) {
  4138. cur_bit = (0x1UL << i);
  4139. if (sig & cur_bit) {
  4140. res = true; /* Each bit is real error! */
  4141. if (print) {
  4142. switch (cur_bit) {
  4143. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4144. _print_next_block((*par_num)++,
  4145. "PGLUE_B");
  4146. _print_parity(bp,
  4147. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4148. break;
  4149. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4150. _print_next_block((*par_num)++, "ATC");
  4151. _print_parity(bp,
  4152. ATC_REG_ATC_PRTY_STS);
  4153. break;
  4154. }
  4155. }
  4156. /* Clear the bit */
  4157. sig &= ~cur_bit;
  4158. }
  4159. }
  4160. return res;
  4161. }
  4162. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4163. u32 *sig)
  4164. {
  4165. bool res = false;
  4166. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4167. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4168. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4169. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4170. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4171. int par_num = 0;
  4172. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4173. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4174. sig[0] & HW_PRTY_ASSERT_SET_0,
  4175. sig[1] & HW_PRTY_ASSERT_SET_1,
  4176. sig[2] & HW_PRTY_ASSERT_SET_2,
  4177. sig[3] & HW_PRTY_ASSERT_SET_3,
  4178. sig[4] & HW_PRTY_ASSERT_SET_4);
  4179. if (print) {
  4180. if (((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4181. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4182. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4183. (sig[4] & HW_PRTY_ASSERT_SET_4)) ||
  4184. (sig[3] & HW_PRTY_ASSERT_SET_3_WITHOUT_SCPAD)) {
  4185. netdev_err(bp->dev,
  4186. "Parity errors detected in blocks: ");
  4187. } else {
  4188. print = false;
  4189. }
  4190. }
  4191. res |= bnx2x_check_blocks_with_parity0(bp,
  4192. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4193. res |= bnx2x_check_blocks_with_parity1(bp,
  4194. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4195. res |= bnx2x_check_blocks_with_parity2(bp,
  4196. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4197. res |= bnx2x_check_blocks_with_parity3(bp,
  4198. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4199. res |= bnx2x_check_blocks_with_parity4(bp,
  4200. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4201. if (print)
  4202. pr_cont("\n");
  4203. }
  4204. return res;
  4205. }
  4206. /**
  4207. * bnx2x_chk_parity_attn - checks for parity attentions.
  4208. *
  4209. * @bp: driver handle
  4210. * @global: true if there was a global attention
  4211. * @print: show parity attention in syslog
  4212. */
  4213. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4214. {
  4215. struct attn_route attn = { {0} };
  4216. int port = BP_PORT(bp);
  4217. attn.sig[0] = REG_RD(bp,
  4218. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4219. port*4);
  4220. attn.sig[1] = REG_RD(bp,
  4221. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4222. port*4);
  4223. attn.sig[2] = REG_RD(bp,
  4224. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4225. port*4);
  4226. attn.sig[3] = REG_RD(bp,
  4227. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4228. port*4);
  4229. /* Since MCP attentions can't be disabled inside the block, we need to
  4230. * read AEU registers to see whether they're currently disabled
  4231. */
  4232. attn.sig[3] &= ((REG_RD(bp,
  4233. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4234. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4235. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4236. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4237. if (!CHIP_IS_E1x(bp))
  4238. attn.sig[4] = REG_RD(bp,
  4239. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4240. port*4);
  4241. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4242. }
  4243. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4244. {
  4245. u32 val;
  4246. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4247. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4248. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4249. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4250. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4251. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4252. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4253. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4254. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4255. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4256. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4257. if (val &
  4258. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4259. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4260. if (val &
  4261. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4262. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4263. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4264. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4265. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4266. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4267. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4268. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4269. }
  4270. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4271. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4272. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4273. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4274. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4275. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4276. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4277. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4278. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4279. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4280. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4281. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4282. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4283. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4284. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4285. }
  4286. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4287. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4288. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4289. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4290. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4291. }
  4292. }
  4293. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4294. {
  4295. struct attn_route attn, *group_mask;
  4296. int port = BP_PORT(bp);
  4297. int index;
  4298. u32 reg_addr;
  4299. u32 val;
  4300. u32 aeu_mask;
  4301. bool global = false;
  4302. /* need to take HW lock because MCP or other port might also
  4303. try to handle this event */
  4304. bnx2x_acquire_alr(bp);
  4305. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4306. #ifndef BNX2X_STOP_ON_ERROR
  4307. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4308. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4309. /* Disable HW interrupts */
  4310. bnx2x_int_disable(bp);
  4311. /* In case of parity errors don't handle attentions so that
  4312. * other function would "see" parity errors.
  4313. */
  4314. #else
  4315. bnx2x_panic();
  4316. #endif
  4317. bnx2x_release_alr(bp);
  4318. return;
  4319. }
  4320. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4321. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4322. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4323. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4324. if (!CHIP_IS_E1x(bp))
  4325. attn.sig[4] =
  4326. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4327. else
  4328. attn.sig[4] = 0;
  4329. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4330. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4331. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4332. if (deasserted & (1 << index)) {
  4333. group_mask = &bp->attn_group[index];
  4334. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4335. index,
  4336. group_mask->sig[0], group_mask->sig[1],
  4337. group_mask->sig[2], group_mask->sig[3],
  4338. group_mask->sig[4]);
  4339. bnx2x_attn_int_deasserted4(bp,
  4340. attn.sig[4] & group_mask->sig[4]);
  4341. bnx2x_attn_int_deasserted3(bp,
  4342. attn.sig[3] & group_mask->sig[3]);
  4343. bnx2x_attn_int_deasserted1(bp,
  4344. attn.sig[1] & group_mask->sig[1]);
  4345. bnx2x_attn_int_deasserted2(bp,
  4346. attn.sig[2] & group_mask->sig[2]);
  4347. bnx2x_attn_int_deasserted0(bp,
  4348. attn.sig[0] & group_mask->sig[0]);
  4349. }
  4350. }
  4351. bnx2x_release_alr(bp);
  4352. if (bp->common.int_block == INT_BLOCK_HC)
  4353. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4354. COMMAND_REG_ATTN_BITS_CLR);
  4355. else
  4356. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4357. val = ~deasserted;
  4358. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4359. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4360. REG_WR(bp, reg_addr, val);
  4361. if (~bp->attn_state & deasserted)
  4362. BNX2X_ERR("IGU ERROR\n");
  4363. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4364. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4365. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4366. aeu_mask = REG_RD(bp, reg_addr);
  4367. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4368. aeu_mask, deasserted);
  4369. aeu_mask |= (deasserted & 0x3ff);
  4370. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4371. REG_WR(bp, reg_addr, aeu_mask);
  4372. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4373. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4374. bp->attn_state &= ~deasserted;
  4375. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4376. }
  4377. static void bnx2x_attn_int(struct bnx2x *bp)
  4378. {
  4379. /* read local copy of bits */
  4380. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4381. attn_bits);
  4382. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4383. attn_bits_ack);
  4384. u32 attn_state = bp->attn_state;
  4385. /* look for changed bits */
  4386. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4387. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4388. DP(NETIF_MSG_HW,
  4389. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4390. attn_bits, attn_ack, asserted, deasserted);
  4391. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4392. BNX2X_ERR("BAD attention state\n");
  4393. /* handle bits that were raised */
  4394. if (asserted)
  4395. bnx2x_attn_int_asserted(bp, asserted);
  4396. if (deasserted)
  4397. bnx2x_attn_int_deasserted(bp, deasserted);
  4398. }
  4399. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4400. u16 index, u8 op, u8 update)
  4401. {
  4402. u32 igu_addr = bp->igu_base_addr;
  4403. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4404. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4405. igu_addr);
  4406. }
  4407. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4408. {
  4409. /* No memory barriers */
  4410. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4411. mmiowb(); /* keep prod updates ordered */
  4412. }
  4413. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4414. union event_ring_elem *elem)
  4415. {
  4416. u8 err = elem->message.error;
  4417. if (!bp->cnic_eth_dev.starting_cid ||
  4418. (cid < bp->cnic_eth_dev.starting_cid &&
  4419. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4420. return 1;
  4421. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4422. if (unlikely(err)) {
  4423. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4424. cid);
  4425. bnx2x_panic_dump(bp, false);
  4426. }
  4427. bnx2x_cnic_cfc_comp(bp, cid, err);
  4428. return 0;
  4429. }
  4430. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4431. {
  4432. struct bnx2x_mcast_ramrod_params rparam;
  4433. int rc;
  4434. memset(&rparam, 0, sizeof(rparam));
  4435. rparam.mcast_obj = &bp->mcast_obj;
  4436. netif_addr_lock_bh(bp->dev);
  4437. /* Clear pending state for the last command */
  4438. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4439. /* If there are pending mcast commands - send them */
  4440. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4441. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4442. if (rc < 0)
  4443. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4444. rc);
  4445. }
  4446. netif_addr_unlock_bh(bp->dev);
  4447. }
  4448. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4449. union event_ring_elem *elem)
  4450. {
  4451. unsigned long ramrod_flags = 0;
  4452. int rc = 0;
  4453. u32 echo = le32_to_cpu(elem->message.data.eth_event.echo);
  4454. u32 cid = echo & BNX2X_SWCID_MASK;
  4455. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4456. /* Always push next commands out, don't wait here */
  4457. __set_bit(RAMROD_CONT, &ramrod_flags);
  4458. switch (echo >> BNX2X_SWCID_SHIFT) {
  4459. case BNX2X_FILTER_MAC_PENDING:
  4460. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4461. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4462. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4463. else
  4464. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4465. break;
  4466. case BNX2X_FILTER_VLAN_PENDING:
  4467. DP(BNX2X_MSG_SP, "Got SETUP_VLAN completions\n");
  4468. vlan_mac_obj = &bp->sp_objs[cid].vlan_obj;
  4469. break;
  4470. case BNX2X_FILTER_MCAST_PENDING:
  4471. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4472. /* This is only relevant for 57710 where multicast MACs are
  4473. * configured as unicast MACs using the same ramrod.
  4474. */
  4475. bnx2x_handle_mcast_eqe(bp);
  4476. return;
  4477. default:
  4478. BNX2X_ERR("Unsupported classification command: 0x%x\n", echo);
  4479. return;
  4480. }
  4481. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4482. if (rc < 0)
  4483. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4484. else if (rc > 0)
  4485. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4486. }
  4487. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4488. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4489. {
  4490. netif_addr_lock_bh(bp->dev);
  4491. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4492. /* Send rx_mode command again if was requested */
  4493. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4494. bnx2x_set_storm_rx_mode(bp);
  4495. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4496. &bp->sp_state))
  4497. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4498. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4499. &bp->sp_state))
  4500. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4501. netif_addr_unlock_bh(bp->dev);
  4502. }
  4503. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4504. union event_ring_elem *elem)
  4505. {
  4506. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4507. DP(BNX2X_MSG_SP,
  4508. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4509. elem->message.data.vif_list_event.func_bit_map);
  4510. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4511. elem->message.data.vif_list_event.func_bit_map);
  4512. } else if (elem->message.data.vif_list_event.echo ==
  4513. VIF_LIST_RULE_SET) {
  4514. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4515. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4516. }
  4517. }
  4518. /* called with rtnl_lock */
  4519. static void bnx2x_after_function_update(struct bnx2x *bp)
  4520. {
  4521. int q, rc;
  4522. struct bnx2x_fastpath *fp;
  4523. struct bnx2x_queue_state_params queue_params = {NULL};
  4524. struct bnx2x_queue_update_params *q_update_params =
  4525. &queue_params.params.update;
  4526. /* Send Q update command with afex vlan removal values for all Qs */
  4527. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4528. /* set silent vlan removal values according to vlan mode */
  4529. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4530. &q_update_params->update_flags);
  4531. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4532. &q_update_params->update_flags);
  4533. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4534. /* in access mode mark mask and value are 0 to strip all vlans */
  4535. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4536. q_update_params->silent_removal_value = 0;
  4537. q_update_params->silent_removal_mask = 0;
  4538. } else {
  4539. q_update_params->silent_removal_value =
  4540. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4541. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4542. }
  4543. for_each_eth_queue(bp, q) {
  4544. /* Set the appropriate Queue object */
  4545. fp = &bp->fp[q];
  4546. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4547. /* send the ramrod */
  4548. rc = bnx2x_queue_state_change(bp, &queue_params);
  4549. if (rc < 0)
  4550. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4551. q);
  4552. }
  4553. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4554. fp = &bp->fp[FCOE_IDX(bp)];
  4555. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4556. /* clear pending completion bit */
  4557. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4558. /* mark latest Q bit */
  4559. smp_mb__before_atomic();
  4560. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4561. smp_mb__after_atomic();
  4562. /* send Q update ramrod for FCoE Q */
  4563. rc = bnx2x_queue_state_change(bp, &queue_params);
  4564. if (rc < 0)
  4565. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4566. q);
  4567. } else {
  4568. /* If no FCoE ring - ACK MCP now */
  4569. bnx2x_link_report(bp);
  4570. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4571. }
  4572. }
  4573. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4574. struct bnx2x *bp, u32 cid)
  4575. {
  4576. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4577. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4578. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4579. else
  4580. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4581. }
  4582. static void bnx2x_eq_int(struct bnx2x *bp)
  4583. {
  4584. u16 hw_cons, sw_cons, sw_prod;
  4585. union event_ring_elem *elem;
  4586. u8 echo;
  4587. u32 cid;
  4588. u8 opcode;
  4589. int rc, spqe_cnt = 0;
  4590. struct bnx2x_queue_sp_obj *q_obj;
  4591. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4592. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4593. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4594. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4595. * when we get the next-page we need to adjust so the loop
  4596. * condition below will be met. The next element is the size of a
  4597. * regular element and hence incrementing by 1
  4598. */
  4599. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4600. hw_cons++;
  4601. /* This function may never run in parallel with itself for a
  4602. * specific bp, thus there is no need in "paired" read memory
  4603. * barrier here.
  4604. */
  4605. sw_cons = bp->eq_cons;
  4606. sw_prod = bp->eq_prod;
  4607. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4608. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4609. for (; sw_cons != hw_cons;
  4610. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4611. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4612. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4613. if (!rc) {
  4614. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4615. rc);
  4616. goto next_spqe;
  4617. }
  4618. opcode = elem->message.opcode;
  4619. /* handle eq element */
  4620. switch (opcode) {
  4621. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4622. bnx2x_vf_mbx_schedule(bp,
  4623. &elem->message.data.vf_pf_event);
  4624. continue;
  4625. case EVENT_RING_OPCODE_STAT_QUERY:
  4626. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4627. "got statistics comp event %d\n",
  4628. bp->stats_comp++);
  4629. /* nothing to do with stats comp */
  4630. goto next_spqe;
  4631. case EVENT_RING_OPCODE_CFC_DEL:
  4632. /* handle according to cid range */
  4633. /*
  4634. * we may want to verify here that the bp state is
  4635. * HALTING
  4636. */
  4637. /* elem CID originates from FW; actually LE */
  4638. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4639. DP(BNX2X_MSG_SP,
  4640. "got delete ramrod for MULTI[%d]\n", cid);
  4641. if (CNIC_LOADED(bp) &&
  4642. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4643. goto next_spqe;
  4644. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4645. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4646. break;
  4647. goto next_spqe;
  4648. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4649. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4650. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4651. if (f_obj->complete_cmd(bp, f_obj,
  4652. BNX2X_F_CMD_TX_STOP))
  4653. break;
  4654. goto next_spqe;
  4655. case EVENT_RING_OPCODE_START_TRAFFIC:
  4656. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4657. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4658. if (f_obj->complete_cmd(bp, f_obj,
  4659. BNX2X_F_CMD_TX_START))
  4660. break;
  4661. goto next_spqe;
  4662. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4663. echo = elem->message.data.function_update_event.echo;
  4664. if (echo == SWITCH_UPDATE) {
  4665. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4666. "got FUNC_SWITCH_UPDATE ramrod\n");
  4667. if (f_obj->complete_cmd(
  4668. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4669. break;
  4670. } else {
  4671. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4672. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4673. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4674. f_obj->complete_cmd(bp, f_obj,
  4675. BNX2X_F_CMD_AFEX_UPDATE);
  4676. /* We will perform the Queues update from
  4677. * sp_rtnl task as all Queue SP operations
  4678. * should run under rtnl_lock.
  4679. */
  4680. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4681. }
  4682. goto next_spqe;
  4683. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4684. f_obj->complete_cmd(bp, f_obj,
  4685. BNX2X_F_CMD_AFEX_VIFLISTS);
  4686. bnx2x_after_afex_vif_lists(bp, elem);
  4687. goto next_spqe;
  4688. case EVENT_RING_OPCODE_FUNCTION_START:
  4689. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4690. "got FUNC_START ramrod\n");
  4691. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4692. break;
  4693. goto next_spqe;
  4694. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4695. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4696. "got FUNC_STOP ramrod\n");
  4697. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4698. break;
  4699. goto next_spqe;
  4700. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4701. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4702. "got set_timesync ramrod completion\n");
  4703. if (f_obj->complete_cmd(bp, f_obj,
  4704. BNX2X_F_CMD_SET_TIMESYNC))
  4705. break;
  4706. goto next_spqe;
  4707. }
  4708. switch (opcode | bp->state) {
  4709. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4710. BNX2X_STATE_OPEN):
  4711. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4712. BNX2X_STATE_OPENING_WAIT4_PORT):
  4713. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4714. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4715. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4716. SW_CID(elem->message.data.eth_event.echo));
  4717. rss_raw->clear_pending(rss_raw);
  4718. break;
  4719. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4720. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4721. case (EVENT_RING_OPCODE_SET_MAC |
  4722. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4723. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4724. BNX2X_STATE_OPEN):
  4725. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4726. BNX2X_STATE_DIAG):
  4727. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4728. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4729. DP(BNX2X_MSG_SP, "got (un)set vlan/mac ramrod\n");
  4730. bnx2x_handle_classification_eqe(bp, elem);
  4731. break;
  4732. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4733. BNX2X_STATE_OPEN):
  4734. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4735. BNX2X_STATE_DIAG):
  4736. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4737. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4738. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4739. bnx2x_handle_mcast_eqe(bp);
  4740. break;
  4741. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4742. BNX2X_STATE_OPEN):
  4743. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4744. BNX2X_STATE_DIAG):
  4745. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4746. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4747. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4748. bnx2x_handle_rx_mode_eqe(bp);
  4749. break;
  4750. default:
  4751. /* unknown event log error and continue */
  4752. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4753. elem->message.opcode, bp->state);
  4754. }
  4755. next_spqe:
  4756. spqe_cnt++;
  4757. } /* for */
  4758. smp_mb__before_atomic();
  4759. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4760. bp->eq_cons = sw_cons;
  4761. bp->eq_prod = sw_prod;
  4762. /* Make sure that above mem writes were issued towards the memory */
  4763. smp_wmb();
  4764. /* update producer */
  4765. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4766. }
  4767. static void bnx2x_sp_task(struct work_struct *work)
  4768. {
  4769. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4770. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4771. /* make sure the atomic interrupt_occurred has been written */
  4772. smp_rmb();
  4773. if (atomic_read(&bp->interrupt_occurred)) {
  4774. /* what work needs to be performed? */
  4775. u16 status = bnx2x_update_dsb_idx(bp);
  4776. DP(BNX2X_MSG_SP, "status %x\n", status);
  4777. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4778. atomic_set(&bp->interrupt_occurred, 0);
  4779. /* HW attentions */
  4780. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4781. bnx2x_attn_int(bp);
  4782. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4783. }
  4784. /* SP events: STAT_QUERY and others */
  4785. if (status & BNX2X_DEF_SB_IDX) {
  4786. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4787. if (FCOE_INIT(bp) &&
  4788. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4789. /* Prevent local bottom-halves from running as
  4790. * we are going to change the local NAPI list.
  4791. */
  4792. local_bh_disable();
  4793. napi_schedule(&bnx2x_fcoe(bp, napi));
  4794. local_bh_enable();
  4795. }
  4796. /* Handle EQ completions */
  4797. bnx2x_eq_int(bp);
  4798. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4799. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4800. status &= ~BNX2X_DEF_SB_IDX;
  4801. }
  4802. /* if status is non zero then perhaps something went wrong */
  4803. if (unlikely(status))
  4804. DP(BNX2X_MSG_SP,
  4805. "got an unknown interrupt! (status 0x%x)\n", status);
  4806. /* ack status block only if something was actually handled */
  4807. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4808. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4809. }
  4810. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4811. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4812. &bp->sp_state)) {
  4813. bnx2x_link_report(bp);
  4814. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4815. }
  4816. }
  4817. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4818. {
  4819. struct net_device *dev = dev_instance;
  4820. struct bnx2x *bp = netdev_priv(dev);
  4821. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4822. IGU_INT_DISABLE, 0);
  4823. #ifdef BNX2X_STOP_ON_ERROR
  4824. if (unlikely(bp->panic))
  4825. return IRQ_HANDLED;
  4826. #endif
  4827. if (CNIC_LOADED(bp)) {
  4828. struct cnic_ops *c_ops;
  4829. rcu_read_lock();
  4830. c_ops = rcu_dereference(bp->cnic_ops);
  4831. if (c_ops)
  4832. c_ops->cnic_handler(bp->cnic_data, NULL);
  4833. rcu_read_unlock();
  4834. }
  4835. /* schedule sp task to perform default status block work, ack
  4836. * attentions and enable interrupts.
  4837. */
  4838. bnx2x_schedule_sp_task(bp);
  4839. return IRQ_HANDLED;
  4840. }
  4841. /* end of slow path */
  4842. void bnx2x_drv_pulse(struct bnx2x *bp)
  4843. {
  4844. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4845. bp->fw_drv_pulse_wr_seq);
  4846. }
  4847. static void bnx2x_timer(unsigned long data)
  4848. {
  4849. struct bnx2x *bp = (struct bnx2x *) data;
  4850. if (!netif_running(bp->dev))
  4851. return;
  4852. if (IS_PF(bp) &&
  4853. !BP_NOMCP(bp)) {
  4854. int mb_idx = BP_FW_MB_IDX(bp);
  4855. u16 drv_pulse;
  4856. u16 mcp_pulse;
  4857. ++bp->fw_drv_pulse_wr_seq;
  4858. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4859. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4860. bnx2x_drv_pulse(bp);
  4861. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4862. MCP_PULSE_SEQ_MASK);
  4863. /* The delta between driver pulse and mcp response
  4864. * should not get too big. If the MFW is more than 5 pulses
  4865. * behind, we should worry about it enough to generate an error
  4866. * log.
  4867. */
  4868. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4869. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4870. drv_pulse, mcp_pulse);
  4871. }
  4872. if (bp->state == BNX2X_STATE_OPEN)
  4873. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4874. /* sample pf vf bulletin board for new posts from pf */
  4875. if (IS_VF(bp))
  4876. bnx2x_timer_sriov(bp);
  4877. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4878. }
  4879. /* end of Statistics */
  4880. /* nic init */
  4881. /*
  4882. * nic init service functions
  4883. */
  4884. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4885. {
  4886. u32 i;
  4887. if (!(len%4) && !(addr%4))
  4888. for (i = 0; i < len; i += 4)
  4889. REG_WR(bp, addr + i, fill);
  4890. else
  4891. for (i = 0; i < len; i++)
  4892. REG_WR8(bp, addr + i, fill);
  4893. }
  4894. /* helper: writes FP SP data to FW - data_size in dwords */
  4895. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4896. int fw_sb_id,
  4897. u32 *sb_data_p,
  4898. u32 data_size)
  4899. {
  4900. int index;
  4901. for (index = 0; index < data_size; index++)
  4902. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4903. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4904. sizeof(u32)*index,
  4905. *(sb_data_p + index));
  4906. }
  4907. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4908. {
  4909. u32 *sb_data_p;
  4910. u32 data_size = 0;
  4911. struct hc_status_block_data_e2 sb_data_e2;
  4912. struct hc_status_block_data_e1x sb_data_e1x;
  4913. /* disable the function first */
  4914. if (!CHIP_IS_E1x(bp)) {
  4915. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4916. sb_data_e2.common.state = SB_DISABLED;
  4917. sb_data_e2.common.p_func.vf_valid = false;
  4918. sb_data_p = (u32 *)&sb_data_e2;
  4919. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4920. } else {
  4921. memset(&sb_data_e1x, 0,
  4922. sizeof(struct hc_status_block_data_e1x));
  4923. sb_data_e1x.common.state = SB_DISABLED;
  4924. sb_data_e1x.common.p_func.vf_valid = false;
  4925. sb_data_p = (u32 *)&sb_data_e1x;
  4926. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4927. }
  4928. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4929. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4930. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4931. CSTORM_STATUS_BLOCK_SIZE);
  4932. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4933. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4934. CSTORM_SYNC_BLOCK_SIZE);
  4935. }
  4936. /* helper: writes SP SB data to FW */
  4937. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4938. struct hc_sp_status_block_data *sp_sb_data)
  4939. {
  4940. int func = BP_FUNC(bp);
  4941. int i;
  4942. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4943. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4944. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4945. i*sizeof(u32),
  4946. *((u32 *)sp_sb_data + i));
  4947. }
  4948. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4949. {
  4950. int func = BP_FUNC(bp);
  4951. struct hc_sp_status_block_data sp_sb_data;
  4952. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4953. sp_sb_data.state = SB_DISABLED;
  4954. sp_sb_data.p_func.vf_valid = false;
  4955. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4956. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4957. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4958. CSTORM_SP_STATUS_BLOCK_SIZE);
  4959. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4960. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4961. CSTORM_SP_SYNC_BLOCK_SIZE);
  4962. }
  4963. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4964. int igu_sb_id, int igu_seg_id)
  4965. {
  4966. hc_sm->igu_sb_id = igu_sb_id;
  4967. hc_sm->igu_seg_id = igu_seg_id;
  4968. hc_sm->timer_value = 0xFF;
  4969. hc_sm->time_to_expire = 0xFFFFFFFF;
  4970. }
  4971. /* allocates state machine ids. */
  4972. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4973. {
  4974. /* zero out state machine indices */
  4975. /* rx indices */
  4976. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4977. /* tx indices */
  4978. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4979. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4980. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4981. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4982. /* map indices */
  4983. /* rx indices */
  4984. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4985. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4986. /* tx indices */
  4987. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4988. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4989. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4990. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4991. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4992. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4993. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4994. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4995. }
  4996. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4997. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4998. {
  4999. int igu_seg_id;
  5000. struct hc_status_block_data_e2 sb_data_e2;
  5001. struct hc_status_block_data_e1x sb_data_e1x;
  5002. struct hc_status_block_sm *hc_sm_p;
  5003. int data_size;
  5004. u32 *sb_data_p;
  5005. if (CHIP_INT_MODE_IS_BC(bp))
  5006. igu_seg_id = HC_SEG_ACCESS_NORM;
  5007. else
  5008. igu_seg_id = IGU_SEG_ACCESS_NORM;
  5009. bnx2x_zero_fp_sb(bp, fw_sb_id);
  5010. if (!CHIP_IS_E1x(bp)) {
  5011. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  5012. sb_data_e2.common.state = SB_ENABLED;
  5013. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  5014. sb_data_e2.common.p_func.vf_id = vfid;
  5015. sb_data_e2.common.p_func.vf_valid = vf_valid;
  5016. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  5017. sb_data_e2.common.same_igu_sb_1b = true;
  5018. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  5019. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  5020. hc_sm_p = sb_data_e2.common.state_machine;
  5021. sb_data_p = (u32 *)&sb_data_e2;
  5022. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  5023. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  5024. } else {
  5025. memset(&sb_data_e1x, 0,
  5026. sizeof(struct hc_status_block_data_e1x));
  5027. sb_data_e1x.common.state = SB_ENABLED;
  5028. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5029. sb_data_e1x.common.p_func.vf_id = 0xff;
  5030. sb_data_e1x.common.p_func.vf_valid = false;
  5031. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5032. sb_data_e1x.common.same_igu_sb_1b = true;
  5033. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5034. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5035. hc_sm_p = sb_data_e1x.common.state_machine;
  5036. sb_data_p = (u32 *)&sb_data_e1x;
  5037. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5038. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5039. }
  5040. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5041. igu_sb_id, igu_seg_id);
  5042. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5043. igu_sb_id, igu_seg_id);
  5044. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5045. /* write indices to HW - PCI guarantees endianity of regpairs */
  5046. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5047. }
  5048. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5049. u16 tx_usec, u16 rx_usec)
  5050. {
  5051. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5052. false, rx_usec);
  5053. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5054. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5055. tx_usec);
  5056. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5057. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5058. tx_usec);
  5059. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5060. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5061. tx_usec);
  5062. }
  5063. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5064. {
  5065. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5066. dma_addr_t mapping = bp->def_status_blk_mapping;
  5067. int igu_sp_sb_index;
  5068. int igu_seg_id;
  5069. int port = BP_PORT(bp);
  5070. int func = BP_FUNC(bp);
  5071. int reg_offset, reg_offset_en5;
  5072. u64 section;
  5073. int index;
  5074. struct hc_sp_status_block_data sp_sb_data;
  5075. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5076. if (CHIP_INT_MODE_IS_BC(bp)) {
  5077. igu_sp_sb_index = DEF_SB_IGU_ID;
  5078. igu_seg_id = HC_SEG_ACCESS_DEF;
  5079. } else {
  5080. igu_sp_sb_index = bp->igu_dsb_id;
  5081. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5082. }
  5083. /* ATTN */
  5084. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5085. atten_status_block);
  5086. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5087. bp->attn_state = 0;
  5088. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5089. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5090. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5091. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5092. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5093. int sindex;
  5094. /* take care of sig[0]..sig[4] */
  5095. for (sindex = 0; sindex < 4; sindex++)
  5096. bp->attn_group[index].sig[sindex] =
  5097. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5098. if (!CHIP_IS_E1x(bp))
  5099. /*
  5100. * enable5 is separate from the rest of the registers,
  5101. * and therefore the address skip is 4
  5102. * and not 16 between the different groups
  5103. */
  5104. bp->attn_group[index].sig[4] = REG_RD(bp,
  5105. reg_offset_en5 + 0x4*index);
  5106. else
  5107. bp->attn_group[index].sig[4] = 0;
  5108. }
  5109. if (bp->common.int_block == INT_BLOCK_HC) {
  5110. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5111. HC_REG_ATTN_MSG0_ADDR_L);
  5112. REG_WR(bp, reg_offset, U64_LO(section));
  5113. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5114. } else if (!CHIP_IS_E1x(bp)) {
  5115. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5116. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5117. }
  5118. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5119. sp_sb);
  5120. bnx2x_zero_sp_sb(bp);
  5121. /* PCI guarantees endianity of regpairs */
  5122. sp_sb_data.state = SB_ENABLED;
  5123. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5124. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5125. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5126. sp_sb_data.igu_seg_id = igu_seg_id;
  5127. sp_sb_data.p_func.pf_id = func;
  5128. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5129. sp_sb_data.p_func.vf_id = 0xff;
  5130. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5131. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5132. }
  5133. void bnx2x_update_coalesce(struct bnx2x *bp)
  5134. {
  5135. int i;
  5136. for_each_eth_queue(bp, i)
  5137. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5138. bp->tx_ticks, bp->rx_ticks);
  5139. }
  5140. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5141. {
  5142. spin_lock_init(&bp->spq_lock);
  5143. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5144. bp->spq_prod_idx = 0;
  5145. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5146. bp->spq_prod_bd = bp->spq;
  5147. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5148. }
  5149. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5150. {
  5151. int i;
  5152. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5153. union event_ring_elem *elem =
  5154. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5155. elem->next_page.addr.hi =
  5156. cpu_to_le32(U64_HI(bp->eq_mapping +
  5157. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5158. elem->next_page.addr.lo =
  5159. cpu_to_le32(U64_LO(bp->eq_mapping +
  5160. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5161. }
  5162. bp->eq_cons = 0;
  5163. bp->eq_prod = NUM_EQ_DESC;
  5164. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5165. /* we want a warning message before it gets wrought... */
  5166. atomic_set(&bp->eq_spq_left,
  5167. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5168. }
  5169. /* called with netif_addr_lock_bh() */
  5170. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5171. unsigned long rx_mode_flags,
  5172. unsigned long rx_accept_flags,
  5173. unsigned long tx_accept_flags,
  5174. unsigned long ramrod_flags)
  5175. {
  5176. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5177. int rc;
  5178. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5179. /* Prepare ramrod parameters */
  5180. ramrod_param.cid = 0;
  5181. ramrod_param.cl_id = cl_id;
  5182. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5183. ramrod_param.func_id = BP_FUNC(bp);
  5184. ramrod_param.pstate = &bp->sp_state;
  5185. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5186. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5187. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5188. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5189. ramrod_param.ramrod_flags = ramrod_flags;
  5190. ramrod_param.rx_mode_flags = rx_mode_flags;
  5191. ramrod_param.rx_accept_flags = rx_accept_flags;
  5192. ramrod_param.tx_accept_flags = tx_accept_flags;
  5193. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5194. if (rc < 0) {
  5195. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5196. return rc;
  5197. }
  5198. return 0;
  5199. }
  5200. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5201. unsigned long *rx_accept_flags,
  5202. unsigned long *tx_accept_flags)
  5203. {
  5204. /* Clear the flags first */
  5205. *rx_accept_flags = 0;
  5206. *tx_accept_flags = 0;
  5207. switch (rx_mode) {
  5208. case BNX2X_RX_MODE_NONE:
  5209. /*
  5210. * 'drop all' supersedes any accept flags that may have been
  5211. * passed to the function.
  5212. */
  5213. break;
  5214. case BNX2X_RX_MODE_NORMAL:
  5215. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5216. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5217. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5218. /* internal switching mode */
  5219. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5220. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5221. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5222. if (bp->accept_any_vlan) {
  5223. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5224. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5225. }
  5226. break;
  5227. case BNX2X_RX_MODE_ALLMULTI:
  5228. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5229. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5230. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5231. /* internal switching mode */
  5232. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5233. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5234. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5235. if (bp->accept_any_vlan) {
  5236. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5237. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5238. }
  5239. break;
  5240. case BNX2X_RX_MODE_PROMISC:
  5241. /* According to definition of SI mode, iface in promisc mode
  5242. * should receive matched and unmatched (in resolution of port)
  5243. * unicast packets.
  5244. */
  5245. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5246. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5247. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5248. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5249. /* internal switching mode */
  5250. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5251. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5252. if (IS_MF_SI(bp))
  5253. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5254. else
  5255. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5256. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5257. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5258. break;
  5259. default:
  5260. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5261. return -EINVAL;
  5262. }
  5263. return 0;
  5264. }
  5265. /* called with netif_addr_lock_bh() */
  5266. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5267. {
  5268. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5269. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5270. int rc;
  5271. if (!NO_FCOE(bp))
  5272. /* Configure rx_mode of FCoE Queue */
  5273. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5274. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5275. &tx_accept_flags);
  5276. if (rc)
  5277. return rc;
  5278. __set_bit(RAMROD_RX, &ramrod_flags);
  5279. __set_bit(RAMROD_TX, &ramrod_flags);
  5280. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5281. rx_accept_flags, tx_accept_flags,
  5282. ramrod_flags);
  5283. }
  5284. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5285. {
  5286. int i;
  5287. /* Zero this manually as its initialization is
  5288. currently missing in the initTool */
  5289. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5290. REG_WR(bp, BAR_USTRORM_INTMEM +
  5291. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5292. if (!CHIP_IS_E1x(bp)) {
  5293. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5294. CHIP_INT_MODE_IS_BC(bp) ?
  5295. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5296. }
  5297. }
  5298. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5299. {
  5300. switch (load_code) {
  5301. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5302. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5303. bnx2x_init_internal_common(bp);
  5304. /* no break */
  5305. case FW_MSG_CODE_DRV_LOAD_PORT:
  5306. /* nothing to do */
  5307. /* no break */
  5308. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5309. /* internal memory per function is
  5310. initialized inside bnx2x_pf_init */
  5311. break;
  5312. default:
  5313. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5314. break;
  5315. }
  5316. }
  5317. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5318. {
  5319. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5320. }
  5321. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5322. {
  5323. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5324. }
  5325. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5326. {
  5327. if (CHIP_IS_E1x(fp->bp))
  5328. return BP_L_ID(fp->bp) + fp->index;
  5329. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5330. return bnx2x_fp_igu_sb_id(fp);
  5331. }
  5332. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5333. {
  5334. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5335. u8 cos;
  5336. unsigned long q_type = 0;
  5337. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5338. fp->rx_queue = fp_idx;
  5339. fp->cid = fp_idx;
  5340. fp->cl_id = bnx2x_fp_cl_id(fp);
  5341. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5342. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5343. /* qZone id equals to FW (per path) client id */
  5344. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5345. /* init shortcut */
  5346. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5347. /* Setup SB indices */
  5348. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5349. /* Configure Queue State object */
  5350. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5351. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5352. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5353. /* init tx data */
  5354. for_each_cos_in_tx_queue(fp, cos) {
  5355. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5356. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5357. FP_COS_TO_TXQ(fp, cos, bp),
  5358. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5359. cids[cos] = fp->txdata_ptr[cos]->cid;
  5360. }
  5361. /* nothing more for vf to do here */
  5362. if (IS_VF(bp))
  5363. return;
  5364. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5365. fp->fw_sb_id, fp->igu_sb_id);
  5366. bnx2x_update_fpsb_idx(fp);
  5367. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5368. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5369. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5370. /**
  5371. * Configure classification DBs: Always enable Tx switching
  5372. */
  5373. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5374. DP(NETIF_MSG_IFUP,
  5375. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5376. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5377. fp->igu_sb_id);
  5378. }
  5379. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5380. {
  5381. int i;
  5382. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5383. struct eth_tx_next_bd *tx_next_bd =
  5384. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5385. tx_next_bd->addr_hi =
  5386. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5387. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5388. tx_next_bd->addr_lo =
  5389. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5390. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5391. }
  5392. *txdata->tx_cons_sb = cpu_to_le16(0);
  5393. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5394. txdata->tx_db.data.zero_fill1 = 0;
  5395. txdata->tx_db.data.prod = 0;
  5396. txdata->tx_pkt_prod = 0;
  5397. txdata->tx_pkt_cons = 0;
  5398. txdata->tx_bd_prod = 0;
  5399. txdata->tx_bd_cons = 0;
  5400. txdata->tx_pkt = 0;
  5401. }
  5402. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5403. {
  5404. int i;
  5405. for_each_tx_queue_cnic(bp, i)
  5406. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5407. }
  5408. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5409. {
  5410. int i;
  5411. u8 cos;
  5412. for_each_eth_queue(bp, i)
  5413. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5414. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5415. }
  5416. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5417. {
  5418. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5419. unsigned long q_type = 0;
  5420. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5421. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5422. BNX2X_FCOE_ETH_CL_ID_IDX);
  5423. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5424. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5425. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5426. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5427. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5428. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5429. fp);
  5430. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5431. /* qZone id equals to FW (per path) client id */
  5432. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5433. /* init shortcut */
  5434. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5435. bnx2x_rx_ustorm_prods_offset(fp);
  5436. /* Configure Queue State object */
  5437. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5438. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5439. /* No multi-CoS for FCoE L2 client */
  5440. BUG_ON(fp->max_cos != 1);
  5441. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5442. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5443. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5444. DP(NETIF_MSG_IFUP,
  5445. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5446. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5447. fp->igu_sb_id);
  5448. }
  5449. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5450. {
  5451. if (!NO_FCOE(bp))
  5452. bnx2x_init_fcoe_fp(bp);
  5453. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5454. BNX2X_VF_ID_INVALID, false,
  5455. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5456. /* ensure status block indices were read */
  5457. rmb();
  5458. bnx2x_init_rx_rings_cnic(bp);
  5459. bnx2x_init_tx_rings_cnic(bp);
  5460. /* flush all */
  5461. mb();
  5462. mmiowb();
  5463. }
  5464. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5465. {
  5466. int i;
  5467. /* Setup NIC internals and enable interrupts */
  5468. for_each_eth_queue(bp, i)
  5469. bnx2x_init_eth_fp(bp, i);
  5470. /* ensure status block indices were read */
  5471. rmb();
  5472. bnx2x_init_rx_rings(bp);
  5473. bnx2x_init_tx_rings(bp);
  5474. if (IS_PF(bp)) {
  5475. /* Initialize MOD_ABS interrupts */
  5476. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5477. bp->common.shmem_base,
  5478. bp->common.shmem2_base, BP_PORT(bp));
  5479. /* initialize the default status block and sp ring */
  5480. bnx2x_init_def_sb(bp);
  5481. bnx2x_update_dsb_idx(bp);
  5482. bnx2x_init_sp_ring(bp);
  5483. } else {
  5484. bnx2x_memset_stats(bp);
  5485. }
  5486. }
  5487. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5488. {
  5489. bnx2x_init_eq_ring(bp);
  5490. bnx2x_init_internal(bp, load_code);
  5491. bnx2x_pf_init(bp);
  5492. bnx2x_stats_init(bp);
  5493. /* flush all before enabling interrupts */
  5494. mb();
  5495. mmiowb();
  5496. bnx2x_int_enable(bp);
  5497. /* Check for SPIO5 */
  5498. bnx2x_attn_int_deasserted0(bp,
  5499. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5500. AEU_INPUTS_ATTN_BITS_SPIO5);
  5501. }
  5502. /* gzip service functions */
  5503. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5504. {
  5505. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5506. &bp->gunzip_mapping, GFP_KERNEL);
  5507. if (bp->gunzip_buf == NULL)
  5508. goto gunzip_nomem1;
  5509. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5510. if (bp->strm == NULL)
  5511. goto gunzip_nomem2;
  5512. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5513. if (bp->strm->workspace == NULL)
  5514. goto gunzip_nomem3;
  5515. return 0;
  5516. gunzip_nomem3:
  5517. kfree(bp->strm);
  5518. bp->strm = NULL;
  5519. gunzip_nomem2:
  5520. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5521. bp->gunzip_mapping);
  5522. bp->gunzip_buf = NULL;
  5523. gunzip_nomem1:
  5524. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5525. return -ENOMEM;
  5526. }
  5527. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5528. {
  5529. if (bp->strm) {
  5530. vfree(bp->strm->workspace);
  5531. kfree(bp->strm);
  5532. bp->strm = NULL;
  5533. }
  5534. if (bp->gunzip_buf) {
  5535. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5536. bp->gunzip_mapping);
  5537. bp->gunzip_buf = NULL;
  5538. }
  5539. }
  5540. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5541. {
  5542. int n, rc;
  5543. /* check gzip header */
  5544. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5545. BNX2X_ERR("Bad gzip header\n");
  5546. return -EINVAL;
  5547. }
  5548. n = 10;
  5549. #define FNAME 0x8
  5550. if (zbuf[3] & FNAME)
  5551. while ((zbuf[n++] != 0) && (n < len));
  5552. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5553. bp->strm->avail_in = len - n;
  5554. bp->strm->next_out = bp->gunzip_buf;
  5555. bp->strm->avail_out = FW_BUF_SIZE;
  5556. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5557. if (rc != Z_OK)
  5558. return rc;
  5559. rc = zlib_inflate(bp->strm, Z_FINISH);
  5560. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5561. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5562. bp->strm->msg);
  5563. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5564. if (bp->gunzip_outlen & 0x3)
  5565. netdev_err(bp->dev,
  5566. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5567. bp->gunzip_outlen);
  5568. bp->gunzip_outlen >>= 2;
  5569. zlib_inflateEnd(bp->strm);
  5570. if (rc == Z_STREAM_END)
  5571. return 0;
  5572. return rc;
  5573. }
  5574. /* nic load/unload */
  5575. /*
  5576. * General service functions
  5577. */
  5578. /* send a NIG loopback debug packet */
  5579. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5580. {
  5581. u32 wb_write[3];
  5582. /* Ethernet source and destination addresses */
  5583. wb_write[0] = 0x55555555;
  5584. wb_write[1] = 0x55555555;
  5585. wb_write[2] = 0x20; /* SOP */
  5586. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5587. /* NON-IP protocol */
  5588. wb_write[0] = 0x09000000;
  5589. wb_write[1] = 0x55555555;
  5590. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5591. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5592. }
  5593. /* some of the internal memories
  5594. * are not directly readable from the driver
  5595. * to test them we send debug packets
  5596. */
  5597. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5598. {
  5599. int factor;
  5600. int count, i;
  5601. u32 val = 0;
  5602. if (CHIP_REV_IS_FPGA(bp))
  5603. factor = 120;
  5604. else if (CHIP_REV_IS_EMUL(bp))
  5605. factor = 200;
  5606. else
  5607. factor = 1;
  5608. /* Disable inputs of parser neighbor blocks */
  5609. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5610. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5611. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5612. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5613. /* Write 0 to parser credits for CFC search request */
  5614. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5615. /* send Ethernet packet */
  5616. bnx2x_lb_pckt(bp);
  5617. /* TODO do i reset NIG statistic? */
  5618. /* Wait until NIG register shows 1 packet of size 0x10 */
  5619. count = 1000 * factor;
  5620. while (count) {
  5621. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5622. val = *bnx2x_sp(bp, wb_data[0]);
  5623. if (val == 0x10)
  5624. break;
  5625. usleep_range(10000, 20000);
  5626. count--;
  5627. }
  5628. if (val != 0x10) {
  5629. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5630. return -1;
  5631. }
  5632. /* Wait until PRS register shows 1 packet */
  5633. count = 1000 * factor;
  5634. while (count) {
  5635. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5636. if (val == 1)
  5637. break;
  5638. usleep_range(10000, 20000);
  5639. count--;
  5640. }
  5641. if (val != 0x1) {
  5642. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5643. return -2;
  5644. }
  5645. /* Reset and init BRB, PRS */
  5646. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5647. msleep(50);
  5648. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5649. msleep(50);
  5650. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5651. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5652. DP(NETIF_MSG_HW, "part2\n");
  5653. /* Disable inputs of parser neighbor blocks */
  5654. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5655. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5656. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5657. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5658. /* Write 0 to parser credits for CFC search request */
  5659. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5660. /* send 10 Ethernet packets */
  5661. for (i = 0; i < 10; i++)
  5662. bnx2x_lb_pckt(bp);
  5663. /* Wait until NIG register shows 10 + 1
  5664. packets of size 11*0x10 = 0xb0 */
  5665. count = 1000 * factor;
  5666. while (count) {
  5667. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5668. val = *bnx2x_sp(bp, wb_data[0]);
  5669. if (val == 0xb0)
  5670. break;
  5671. usleep_range(10000, 20000);
  5672. count--;
  5673. }
  5674. if (val != 0xb0) {
  5675. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5676. return -3;
  5677. }
  5678. /* Wait until PRS register shows 2 packets */
  5679. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5680. if (val != 2)
  5681. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5682. /* Write 1 to parser credits for CFC search request */
  5683. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5684. /* Wait until PRS register shows 3 packets */
  5685. msleep(10 * factor);
  5686. /* Wait until NIG register shows 1 packet of size 0x10 */
  5687. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5688. if (val != 3)
  5689. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5690. /* clear NIG EOP FIFO */
  5691. for (i = 0; i < 11; i++)
  5692. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5693. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5694. if (val != 1) {
  5695. BNX2X_ERR("clear of NIG failed\n");
  5696. return -4;
  5697. }
  5698. /* Reset and init BRB, PRS, NIG */
  5699. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5700. msleep(50);
  5701. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5702. msleep(50);
  5703. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5704. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5705. if (!CNIC_SUPPORT(bp))
  5706. /* set NIC mode */
  5707. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5708. /* Enable inputs of parser neighbor blocks */
  5709. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5710. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5711. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5712. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5713. DP(NETIF_MSG_HW, "done\n");
  5714. return 0; /* OK */
  5715. }
  5716. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5717. {
  5718. u32 val;
  5719. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5720. if (!CHIP_IS_E1x(bp))
  5721. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5722. else
  5723. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5724. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5725. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5726. /*
  5727. * mask read length error interrupts in brb for parser
  5728. * (parsing unit and 'checksum and crc' unit)
  5729. * these errors are legal (PU reads fixed length and CAC can cause
  5730. * read length error on truncated packets)
  5731. */
  5732. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5733. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5734. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5735. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5736. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5737. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5738. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5739. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5740. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5741. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5742. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5743. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5744. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5745. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5746. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5747. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5748. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5749. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5750. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5751. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5752. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5753. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5754. if (!CHIP_IS_E1x(bp))
  5755. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5756. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5757. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5758. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5759. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5760. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5761. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5762. if (!CHIP_IS_E1x(bp))
  5763. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5764. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5765. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5766. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5767. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5768. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5769. }
  5770. static void bnx2x_reset_common(struct bnx2x *bp)
  5771. {
  5772. u32 val = 0x1400;
  5773. /* reset_common */
  5774. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5775. 0xd3ffff7f);
  5776. if (CHIP_IS_E3(bp)) {
  5777. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5778. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5779. }
  5780. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5781. }
  5782. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5783. {
  5784. bp->dmae_ready = 0;
  5785. spin_lock_init(&bp->dmae_lock);
  5786. }
  5787. static void bnx2x_init_pxp(struct bnx2x *bp)
  5788. {
  5789. u16 devctl;
  5790. int r_order, w_order;
  5791. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5792. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5793. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5794. if (bp->mrrs == -1)
  5795. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5796. else {
  5797. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5798. r_order = bp->mrrs;
  5799. }
  5800. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5801. }
  5802. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5803. {
  5804. int is_required;
  5805. u32 val;
  5806. int port;
  5807. if (BP_NOMCP(bp))
  5808. return;
  5809. is_required = 0;
  5810. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5811. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5812. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5813. is_required = 1;
  5814. /*
  5815. * The fan failure mechanism is usually related to the PHY type since
  5816. * the power consumption of the board is affected by the PHY. Currently,
  5817. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5818. */
  5819. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5820. for (port = PORT_0; port < PORT_MAX; port++) {
  5821. is_required |=
  5822. bnx2x_fan_failure_det_req(
  5823. bp,
  5824. bp->common.shmem_base,
  5825. bp->common.shmem2_base,
  5826. port);
  5827. }
  5828. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5829. if (is_required == 0)
  5830. return;
  5831. /* Fan failure is indicated by SPIO 5 */
  5832. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5833. /* set to active low mode */
  5834. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5835. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5836. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5837. /* enable interrupt to signal the IGU */
  5838. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5839. val |= MISC_SPIO_SPIO5;
  5840. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5841. }
  5842. void bnx2x_pf_disable(struct bnx2x *bp)
  5843. {
  5844. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5845. val &= ~IGU_PF_CONF_FUNC_EN;
  5846. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5847. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5848. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5849. }
  5850. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5851. {
  5852. u32 shmem_base[2], shmem2_base[2];
  5853. /* Avoid common init in case MFW supports LFA */
  5854. if (SHMEM2_RD(bp, size) >
  5855. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5856. return;
  5857. shmem_base[0] = bp->common.shmem_base;
  5858. shmem2_base[0] = bp->common.shmem2_base;
  5859. if (!CHIP_IS_E1x(bp)) {
  5860. shmem_base[1] =
  5861. SHMEM2_RD(bp, other_shmem_base_addr);
  5862. shmem2_base[1] =
  5863. SHMEM2_RD(bp, other_shmem2_base_addr);
  5864. }
  5865. bnx2x_acquire_phy_lock(bp);
  5866. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5867. bp->common.chip_id);
  5868. bnx2x_release_phy_lock(bp);
  5869. }
  5870. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5871. {
  5872. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5873. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5874. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5875. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5876. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5877. /* make sure this value is 0 */
  5878. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5879. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5880. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5881. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5882. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5883. }
  5884. static void bnx2x_set_endianity(struct bnx2x *bp)
  5885. {
  5886. #ifdef __BIG_ENDIAN
  5887. bnx2x_config_endianity(bp, 1);
  5888. #else
  5889. bnx2x_config_endianity(bp, 0);
  5890. #endif
  5891. }
  5892. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5893. {
  5894. bnx2x_config_endianity(bp, 0);
  5895. }
  5896. /**
  5897. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5898. *
  5899. * @bp: driver handle
  5900. */
  5901. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5902. {
  5903. u32 val;
  5904. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5905. /*
  5906. * take the RESET lock to protect undi_unload flow from accessing
  5907. * registers while we're resetting the chip
  5908. */
  5909. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5910. bnx2x_reset_common(bp);
  5911. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5912. val = 0xfffc;
  5913. if (CHIP_IS_E3(bp)) {
  5914. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5915. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5916. }
  5917. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5918. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5919. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5920. if (!CHIP_IS_E1x(bp)) {
  5921. u8 abs_func_id;
  5922. /**
  5923. * 4-port mode or 2-port mode we need to turn of master-enable
  5924. * for everyone, after that, turn it back on for self.
  5925. * so, we disregard multi-function or not, and always disable
  5926. * for all functions on the given path, this means 0,2,4,6 for
  5927. * path 0 and 1,3,5,7 for path 1
  5928. */
  5929. for (abs_func_id = BP_PATH(bp);
  5930. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5931. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5932. REG_WR(bp,
  5933. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5934. 1);
  5935. continue;
  5936. }
  5937. bnx2x_pretend_func(bp, abs_func_id);
  5938. /* clear pf enable */
  5939. bnx2x_pf_disable(bp);
  5940. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5941. }
  5942. }
  5943. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5944. if (CHIP_IS_E1(bp)) {
  5945. /* enable HW interrupt from PXP on USDM overflow
  5946. bit 16 on INT_MASK_0 */
  5947. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5948. }
  5949. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5950. bnx2x_init_pxp(bp);
  5951. bnx2x_set_endianity(bp);
  5952. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5953. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5954. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5955. /* let the HW do it's magic ... */
  5956. msleep(100);
  5957. /* finish PXP init */
  5958. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5959. if (val != 1) {
  5960. BNX2X_ERR("PXP2 CFG failed\n");
  5961. return -EBUSY;
  5962. }
  5963. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5964. if (val != 1) {
  5965. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5966. return -EBUSY;
  5967. }
  5968. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5969. * have entries with value "0" and valid bit on.
  5970. * This needs to be done by the first PF that is loaded in a path
  5971. * (i.e. common phase)
  5972. */
  5973. if (!CHIP_IS_E1x(bp)) {
  5974. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5975. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5976. * This occurs when a different function (func2,3) is being marked
  5977. * as "scan-off". Real-life scenario for example: if a driver is being
  5978. * load-unloaded while func6,7 are down. This will cause the timer to access
  5979. * the ilt, translate to a logical address and send a request to read/write.
  5980. * Since the ilt for the function that is down is not valid, this will cause
  5981. * a translation error which is unrecoverable.
  5982. * The Workaround is intended to make sure that when this happens nothing fatal
  5983. * will occur. The workaround:
  5984. * 1. First PF driver which loads on a path will:
  5985. * a. After taking the chip out of reset, by using pretend,
  5986. * it will write "0" to the following registers of
  5987. * the other vnics.
  5988. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5989. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5990. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5991. * And for itself it will write '1' to
  5992. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5993. * dmae-operations (writing to pram for example.)
  5994. * note: can be done for only function 6,7 but cleaner this
  5995. * way.
  5996. * b. Write zero+valid to the entire ILT.
  5997. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5998. * VNIC3 (of that port). The range allocated will be the
  5999. * entire ILT. This is needed to prevent ILT range error.
  6000. * 2. Any PF driver load flow:
  6001. * a. ILT update with the physical addresses of the allocated
  6002. * logical pages.
  6003. * b. Wait 20msec. - note that this timeout is needed to make
  6004. * sure there are no requests in one of the PXP internal
  6005. * queues with "old" ILT addresses.
  6006. * c. PF enable in the PGLC.
  6007. * d. Clear the was_error of the PF in the PGLC. (could have
  6008. * occurred while driver was down)
  6009. * e. PF enable in the CFC (WEAK + STRONG)
  6010. * f. Timers scan enable
  6011. * 3. PF driver unload flow:
  6012. * a. Clear the Timers scan_en.
  6013. * b. Polling for scan_on=0 for that PF.
  6014. * c. Clear the PF enable bit in the PXP.
  6015. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  6016. * e. Write zero+valid to all ILT entries (The valid bit must
  6017. * stay set)
  6018. * f. If this is VNIC 3 of a port then also init
  6019. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  6020. * to the last entry in the ILT.
  6021. *
  6022. * Notes:
  6023. * Currently the PF error in the PGLC is non recoverable.
  6024. * In the future the there will be a recovery routine for this error.
  6025. * Currently attention is masked.
  6026. * Having an MCP lock on the load/unload process does not guarantee that
  6027. * there is no Timer disable during Func6/7 enable. This is because the
  6028. * Timers scan is currently being cleared by the MCP on FLR.
  6029. * Step 2.d can be done only for PF6/7 and the driver can also check if
  6030. * there is error before clearing it. But the flow above is simpler and
  6031. * more general.
  6032. * All ILT entries are written by zero+valid and not just PF6/7
  6033. * ILT entries since in the future the ILT entries allocation for
  6034. * PF-s might be dynamic.
  6035. */
  6036. struct ilt_client_info ilt_cli;
  6037. struct bnx2x_ilt ilt;
  6038. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6039. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6040. /* initialize dummy TM client */
  6041. ilt_cli.start = 0;
  6042. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6043. ilt_cli.client_num = ILT_CLIENT_TM;
  6044. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6045. * Step 2: set the timers first/last ilt entry to point
  6046. * to the entire range to prevent ILT range error for 3rd/4th
  6047. * vnic (this code assumes existence of the vnic)
  6048. *
  6049. * both steps performed by call to bnx2x_ilt_client_init_op()
  6050. * with dummy TM client
  6051. *
  6052. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6053. * and his brother are split registers
  6054. */
  6055. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6056. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6057. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6058. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6059. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6060. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6061. }
  6062. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6063. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6064. if (!CHIP_IS_E1x(bp)) {
  6065. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6066. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6067. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6068. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6069. /* let the HW do it's magic ... */
  6070. do {
  6071. msleep(200);
  6072. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6073. } while (factor-- && (val != 1));
  6074. if (val != 1) {
  6075. BNX2X_ERR("ATC_INIT failed\n");
  6076. return -EBUSY;
  6077. }
  6078. }
  6079. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6080. bnx2x_iov_init_dmae(bp);
  6081. /* clean the DMAE memory */
  6082. bp->dmae_ready = 1;
  6083. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6084. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6085. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6086. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6087. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6088. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6089. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6090. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6091. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6092. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6093. /* QM queues pointers table */
  6094. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6095. /* soft reset pulse */
  6096. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6097. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6098. if (CNIC_SUPPORT(bp))
  6099. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6100. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6101. if (!CHIP_REV_IS_SLOW(bp))
  6102. /* enable hw interrupt from doorbell Q */
  6103. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6104. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6105. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6106. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6107. if (!CHIP_IS_E1(bp))
  6108. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6109. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6110. if (IS_MF_AFEX(bp)) {
  6111. /* configure that VNTag and VLAN headers must be
  6112. * received in afex mode
  6113. */
  6114. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6115. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6116. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6117. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6118. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6119. } else {
  6120. /* Bit-map indicating which L2 hdrs may appear
  6121. * after the basic Ethernet header
  6122. */
  6123. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6124. bp->path_has_ovlan ? 7 : 6);
  6125. }
  6126. }
  6127. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6128. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6129. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6130. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6131. if (!CHIP_IS_E1x(bp)) {
  6132. /* reset VFC memories */
  6133. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6134. VFC_MEMORIES_RST_REG_CAM_RST |
  6135. VFC_MEMORIES_RST_REG_RAM_RST);
  6136. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6137. VFC_MEMORIES_RST_REG_CAM_RST |
  6138. VFC_MEMORIES_RST_REG_RAM_RST);
  6139. msleep(20);
  6140. }
  6141. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6142. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6143. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6144. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6145. /* sync semi rtc */
  6146. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6147. 0x80000000);
  6148. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6149. 0x80000000);
  6150. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6151. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6152. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6153. if (!CHIP_IS_E1x(bp)) {
  6154. if (IS_MF_AFEX(bp)) {
  6155. /* configure that VNTag and VLAN headers must be
  6156. * sent in afex mode
  6157. */
  6158. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6159. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6160. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6161. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6162. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6163. } else {
  6164. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6165. bp->path_has_ovlan ? 7 : 6);
  6166. }
  6167. }
  6168. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6169. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6170. if (CNIC_SUPPORT(bp)) {
  6171. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6172. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6173. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6174. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6175. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6176. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6177. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6178. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6179. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6180. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6181. }
  6182. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6183. if (sizeof(union cdu_context) != 1024)
  6184. /* we currently assume that a context is 1024 bytes */
  6185. dev_alert(&bp->pdev->dev,
  6186. "please adjust the size of cdu_context(%ld)\n",
  6187. (long)sizeof(union cdu_context));
  6188. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6189. val = (4 << 24) + (0 << 12) + 1024;
  6190. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6191. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6192. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6193. /* enable context validation interrupt from CFC */
  6194. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6195. /* set the thresholds to prevent CFC/CDU race */
  6196. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6197. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6198. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6199. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6200. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6201. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6202. /* Reset PCIE errors for debug */
  6203. REG_WR(bp, 0x2814, 0xffffffff);
  6204. REG_WR(bp, 0x3820, 0xffffffff);
  6205. if (!CHIP_IS_E1x(bp)) {
  6206. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6207. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6208. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6209. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6210. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6211. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6212. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6213. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6214. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6215. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6216. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6217. }
  6218. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6219. if (!CHIP_IS_E1(bp)) {
  6220. /* in E3 this done in per-port section */
  6221. if (!CHIP_IS_E3(bp))
  6222. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6223. }
  6224. if (CHIP_IS_E1H(bp))
  6225. /* not applicable for E2 (and above ...) */
  6226. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6227. if (CHIP_REV_IS_SLOW(bp))
  6228. msleep(200);
  6229. /* finish CFC init */
  6230. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6231. if (val != 1) {
  6232. BNX2X_ERR("CFC LL_INIT failed\n");
  6233. return -EBUSY;
  6234. }
  6235. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6236. if (val != 1) {
  6237. BNX2X_ERR("CFC AC_INIT failed\n");
  6238. return -EBUSY;
  6239. }
  6240. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6241. if (val != 1) {
  6242. BNX2X_ERR("CFC CAM_INIT failed\n");
  6243. return -EBUSY;
  6244. }
  6245. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6246. if (CHIP_IS_E1(bp)) {
  6247. /* read NIG statistic
  6248. to see if this is our first up since powerup */
  6249. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6250. val = *bnx2x_sp(bp, wb_data[0]);
  6251. /* do internal memory self test */
  6252. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6253. BNX2X_ERR("internal mem self test failed\n");
  6254. return -EBUSY;
  6255. }
  6256. }
  6257. bnx2x_setup_fan_failure_detection(bp);
  6258. /* clear PXP2 attentions */
  6259. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6260. bnx2x_enable_blocks_attention(bp);
  6261. bnx2x_enable_blocks_parity(bp);
  6262. if (!BP_NOMCP(bp)) {
  6263. if (CHIP_IS_E1x(bp))
  6264. bnx2x__common_init_phy(bp);
  6265. } else
  6266. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6267. if (SHMEM2_HAS(bp, netproc_fw_ver))
  6268. SHMEM2_WR(bp, netproc_fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  6269. return 0;
  6270. }
  6271. /**
  6272. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6273. *
  6274. * @bp: driver handle
  6275. */
  6276. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6277. {
  6278. int rc = bnx2x_init_hw_common(bp);
  6279. if (rc)
  6280. return rc;
  6281. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6282. if (!BP_NOMCP(bp))
  6283. bnx2x__common_init_phy(bp);
  6284. return 0;
  6285. }
  6286. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6287. {
  6288. int port = BP_PORT(bp);
  6289. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6290. u32 low, high;
  6291. u32 val, reg;
  6292. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6293. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6294. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6295. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6296. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6297. /* Timers bug workaround: disables the pf_master bit in pglue at
  6298. * common phase, we need to enable it here before any dmae access are
  6299. * attempted. Therefore we manually added the enable-master to the
  6300. * port phase (it also happens in the function phase)
  6301. */
  6302. if (!CHIP_IS_E1x(bp))
  6303. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6304. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6305. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6306. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6307. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6308. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6309. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6310. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6311. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6312. /* QM cid (connection) count */
  6313. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6314. if (CNIC_SUPPORT(bp)) {
  6315. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6316. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6317. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6318. }
  6319. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6320. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6321. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6322. if (IS_MF(bp))
  6323. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6324. else if (bp->dev->mtu > 4096) {
  6325. if (bp->flags & ONE_PORT_FLAG)
  6326. low = 160;
  6327. else {
  6328. val = bp->dev->mtu;
  6329. /* (24*1024 + val*4)/256 */
  6330. low = 96 + (val/64) +
  6331. ((val % 64) ? 1 : 0);
  6332. }
  6333. } else
  6334. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6335. high = low + 56; /* 14*1024/256 */
  6336. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6337. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6338. }
  6339. if (CHIP_MODE_IS_4_PORT(bp))
  6340. REG_WR(bp, (BP_PORT(bp) ?
  6341. BRB1_REG_MAC_GUARANTIED_1 :
  6342. BRB1_REG_MAC_GUARANTIED_0), 40);
  6343. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6344. if (CHIP_IS_E3B0(bp)) {
  6345. if (IS_MF_AFEX(bp)) {
  6346. /* configure headers for AFEX mode */
  6347. REG_WR(bp, BP_PORT(bp) ?
  6348. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6349. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6350. REG_WR(bp, BP_PORT(bp) ?
  6351. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6352. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6353. REG_WR(bp, BP_PORT(bp) ?
  6354. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6355. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6356. } else {
  6357. /* Ovlan exists only if we are in multi-function +
  6358. * switch-dependent mode, in switch-independent there
  6359. * is no ovlan headers
  6360. */
  6361. REG_WR(bp, BP_PORT(bp) ?
  6362. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6363. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6364. (bp->path_has_ovlan ? 7 : 6));
  6365. }
  6366. }
  6367. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6368. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6369. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6370. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6371. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6372. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6373. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6374. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6375. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6376. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6377. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6378. if (CHIP_IS_E1x(bp)) {
  6379. /* configure PBF to work without PAUSE mtu 9000 */
  6380. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6381. /* update threshold */
  6382. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6383. /* update init credit */
  6384. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6385. /* probe changes */
  6386. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6387. udelay(50);
  6388. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6389. }
  6390. if (CNIC_SUPPORT(bp))
  6391. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6392. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6393. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6394. if (CHIP_IS_E1(bp)) {
  6395. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6396. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6397. }
  6398. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6399. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6400. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6401. /* init aeu_mask_attn_func_0/1:
  6402. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6403. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6404. * bits 4-7 are used for "per vn group attention" */
  6405. val = IS_MF(bp) ? 0xF7 : 0x7;
  6406. /* Enable DCBX attention for all but E1 */
  6407. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6408. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6409. /* SCPAD_PARITY should NOT trigger close the gates */
  6410. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6411. REG_WR(bp, reg,
  6412. REG_RD(bp, reg) &
  6413. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6414. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6415. REG_WR(bp, reg,
  6416. REG_RD(bp, reg) &
  6417. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6418. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6419. if (!CHIP_IS_E1x(bp)) {
  6420. /* Bit-map indicating which L2 hdrs may appear after the
  6421. * basic Ethernet header
  6422. */
  6423. if (IS_MF_AFEX(bp))
  6424. REG_WR(bp, BP_PORT(bp) ?
  6425. NIG_REG_P1_HDRS_AFTER_BASIC :
  6426. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6427. else
  6428. REG_WR(bp, BP_PORT(bp) ?
  6429. NIG_REG_P1_HDRS_AFTER_BASIC :
  6430. NIG_REG_P0_HDRS_AFTER_BASIC,
  6431. IS_MF_SD(bp) ? 7 : 6);
  6432. if (CHIP_IS_E3(bp))
  6433. REG_WR(bp, BP_PORT(bp) ?
  6434. NIG_REG_LLH1_MF_MODE :
  6435. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6436. }
  6437. if (!CHIP_IS_E3(bp))
  6438. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6439. if (!CHIP_IS_E1(bp)) {
  6440. /* 0x2 disable mf_ov, 0x1 enable */
  6441. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6442. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6443. if (!CHIP_IS_E1x(bp)) {
  6444. val = 0;
  6445. switch (bp->mf_mode) {
  6446. case MULTI_FUNCTION_SD:
  6447. val = 1;
  6448. break;
  6449. case MULTI_FUNCTION_SI:
  6450. case MULTI_FUNCTION_AFEX:
  6451. val = 2;
  6452. break;
  6453. }
  6454. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6455. NIG_REG_LLH0_CLS_TYPE), val);
  6456. }
  6457. {
  6458. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6459. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6460. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6461. }
  6462. }
  6463. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6464. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6465. if (val & MISC_SPIO_SPIO5) {
  6466. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6467. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6468. val = REG_RD(bp, reg_addr);
  6469. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6470. REG_WR(bp, reg_addr, val);
  6471. }
  6472. return 0;
  6473. }
  6474. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6475. {
  6476. int reg;
  6477. u32 wb_write[2];
  6478. if (CHIP_IS_E1(bp))
  6479. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6480. else
  6481. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6482. wb_write[0] = ONCHIP_ADDR1(addr);
  6483. wb_write[1] = ONCHIP_ADDR2(addr);
  6484. REG_WR_DMAE(bp, reg, wb_write, 2);
  6485. }
  6486. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6487. {
  6488. u32 data, ctl, cnt = 100;
  6489. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6490. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6491. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6492. u32 sb_bit = 1 << (idu_sb_id%32);
  6493. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6494. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6495. /* Not supported in BC mode */
  6496. if (CHIP_INT_MODE_IS_BC(bp))
  6497. return;
  6498. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6499. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6500. IGU_REGULAR_CLEANUP_SET |
  6501. IGU_REGULAR_BCLEANUP;
  6502. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6503. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6504. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6505. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6506. data, igu_addr_data);
  6507. REG_WR(bp, igu_addr_data, data);
  6508. mmiowb();
  6509. barrier();
  6510. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6511. ctl, igu_addr_ctl);
  6512. REG_WR(bp, igu_addr_ctl, ctl);
  6513. mmiowb();
  6514. barrier();
  6515. /* wait for clean up to finish */
  6516. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6517. msleep(20);
  6518. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6519. DP(NETIF_MSG_HW,
  6520. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6521. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6522. }
  6523. }
  6524. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6525. {
  6526. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6527. }
  6528. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6529. {
  6530. u32 i, base = FUNC_ILT_BASE(func);
  6531. for (i = base; i < base + ILT_PER_FUNC; i++)
  6532. bnx2x_ilt_wr(bp, i, 0);
  6533. }
  6534. static void bnx2x_init_searcher(struct bnx2x *bp)
  6535. {
  6536. int port = BP_PORT(bp);
  6537. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6538. /* T1 hash bits value determines the T1 number of entries */
  6539. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6540. }
  6541. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6542. {
  6543. int rc;
  6544. struct bnx2x_func_state_params func_params = {NULL};
  6545. struct bnx2x_func_switch_update_params *switch_update_params =
  6546. &func_params.params.switch_update;
  6547. /* Prepare parameters for function state transitions */
  6548. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6549. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6550. func_params.f_obj = &bp->func_obj;
  6551. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6552. /* Function parameters */
  6553. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6554. &switch_update_params->changes);
  6555. if (suspend)
  6556. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6557. &switch_update_params->changes);
  6558. rc = bnx2x_func_state_change(bp, &func_params);
  6559. return rc;
  6560. }
  6561. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6562. {
  6563. int rc, i, port = BP_PORT(bp);
  6564. int vlan_en = 0, mac_en[NUM_MACS];
  6565. /* Close input from network */
  6566. if (bp->mf_mode == SINGLE_FUNCTION) {
  6567. bnx2x_set_rx_filter(&bp->link_params, 0);
  6568. } else {
  6569. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6570. NIG_REG_LLH0_FUNC_EN);
  6571. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6572. NIG_REG_LLH0_FUNC_EN, 0);
  6573. for (i = 0; i < NUM_MACS; i++) {
  6574. mac_en[i] = REG_RD(bp, port ?
  6575. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6576. 4 * i) :
  6577. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6578. 4 * i));
  6579. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6580. 4 * i) :
  6581. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6582. }
  6583. }
  6584. /* Close BMC to host */
  6585. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6586. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6587. /* Suspend Tx switching to the PF. Completion of this ramrod
  6588. * further guarantees that all the packets of that PF / child
  6589. * VFs in BRB were processed by the Parser, so it is safe to
  6590. * change the NIC_MODE register.
  6591. */
  6592. rc = bnx2x_func_switch_update(bp, 1);
  6593. if (rc) {
  6594. BNX2X_ERR("Can't suspend tx-switching!\n");
  6595. return rc;
  6596. }
  6597. /* Change NIC_MODE register */
  6598. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6599. /* Open input from network */
  6600. if (bp->mf_mode == SINGLE_FUNCTION) {
  6601. bnx2x_set_rx_filter(&bp->link_params, 1);
  6602. } else {
  6603. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6604. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6605. for (i = 0; i < NUM_MACS; i++) {
  6606. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6607. 4 * i) :
  6608. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6609. mac_en[i]);
  6610. }
  6611. }
  6612. /* Enable BMC to host */
  6613. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6614. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6615. /* Resume Tx switching to the PF */
  6616. rc = bnx2x_func_switch_update(bp, 0);
  6617. if (rc) {
  6618. BNX2X_ERR("Can't resume tx-switching!\n");
  6619. return rc;
  6620. }
  6621. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6622. return 0;
  6623. }
  6624. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6625. {
  6626. int rc;
  6627. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6628. if (CONFIGURE_NIC_MODE(bp)) {
  6629. /* Configure searcher as part of function hw init */
  6630. bnx2x_init_searcher(bp);
  6631. /* Reset NIC mode */
  6632. rc = bnx2x_reset_nic_mode(bp);
  6633. if (rc)
  6634. BNX2X_ERR("Can't change NIC mode!\n");
  6635. return rc;
  6636. }
  6637. return 0;
  6638. }
  6639. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  6640. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  6641. * the addresses of the transaction, resulting in was-error bit set in the pci
  6642. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  6643. * to clear the interrupt which detected this from the pglueb and the was done
  6644. * bit
  6645. */
  6646. static void bnx2x_clean_pglue_errors(struct bnx2x *bp)
  6647. {
  6648. if (!CHIP_IS_E1x(bp))
  6649. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  6650. 1 << BP_ABS_FUNC(bp));
  6651. }
  6652. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6653. {
  6654. int port = BP_PORT(bp);
  6655. int func = BP_FUNC(bp);
  6656. int init_phase = PHASE_PF0 + func;
  6657. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6658. u16 cdu_ilt_start;
  6659. u32 addr, val;
  6660. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6661. int i, main_mem_width, rc;
  6662. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6663. /* FLR cleanup - hmmm */
  6664. if (!CHIP_IS_E1x(bp)) {
  6665. rc = bnx2x_pf_flr_clnup(bp);
  6666. if (rc) {
  6667. bnx2x_fw_dump(bp);
  6668. return rc;
  6669. }
  6670. }
  6671. /* set MSI reconfigure capability */
  6672. if (bp->common.int_block == INT_BLOCK_HC) {
  6673. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6674. val = REG_RD(bp, addr);
  6675. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6676. REG_WR(bp, addr, val);
  6677. }
  6678. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6679. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6680. ilt = BP_ILT(bp);
  6681. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6682. if (IS_SRIOV(bp))
  6683. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6684. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6685. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6686. * those of the VFs, so start line should be reset
  6687. */
  6688. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6689. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6690. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6691. ilt->lines[cdu_ilt_start + i].page_mapping =
  6692. bp->context[i].cxt_mapping;
  6693. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6694. }
  6695. bnx2x_ilt_init_op(bp, INITOP_SET);
  6696. if (!CONFIGURE_NIC_MODE(bp)) {
  6697. bnx2x_init_searcher(bp);
  6698. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6699. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6700. } else {
  6701. /* Set NIC mode */
  6702. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6703. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6704. }
  6705. if (!CHIP_IS_E1x(bp)) {
  6706. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6707. /* Turn on a single ISR mode in IGU if driver is going to use
  6708. * INT#x or MSI
  6709. */
  6710. if (!(bp->flags & USING_MSIX_FLAG))
  6711. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6712. /*
  6713. * Timers workaround bug: function init part.
  6714. * Need to wait 20msec after initializing ILT,
  6715. * needed to make sure there are no requests in
  6716. * one of the PXP internal queues with "old" ILT addresses
  6717. */
  6718. msleep(20);
  6719. /*
  6720. * Master enable - Due to WB DMAE writes performed before this
  6721. * register is re-initialized as part of the regular function
  6722. * init
  6723. */
  6724. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6725. /* Enable the function in IGU */
  6726. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6727. }
  6728. bp->dmae_ready = 1;
  6729. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6730. bnx2x_clean_pglue_errors(bp);
  6731. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6732. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6733. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6734. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6735. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6736. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6737. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6738. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6739. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6740. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6741. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6742. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6743. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6744. if (!CHIP_IS_E1x(bp))
  6745. REG_WR(bp, QM_REG_PF_EN, 1);
  6746. if (!CHIP_IS_E1x(bp)) {
  6747. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6748. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6749. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6750. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6751. }
  6752. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6753. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6754. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6755. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6756. bnx2x_iov_init_dq(bp);
  6757. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6758. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6759. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6760. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6761. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6762. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6763. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6764. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6765. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6766. if (!CHIP_IS_E1x(bp))
  6767. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6768. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6769. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6770. if (!CHIP_IS_E1x(bp))
  6771. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6772. if (IS_MF(bp)) {
  6773. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6774. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6775. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6776. bp->mf_ov);
  6777. }
  6778. }
  6779. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6780. /* HC init per function */
  6781. if (bp->common.int_block == INT_BLOCK_HC) {
  6782. if (CHIP_IS_E1H(bp)) {
  6783. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6784. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6785. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6786. }
  6787. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6788. } else {
  6789. int num_segs, sb_idx, prod_offset;
  6790. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6791. if (!CHIP_IS_E1x(bp)) {
  6792. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6793. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6794. }
  6795. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6796. if (!CHIP_IS_E1x(bp)) {
  6797. int dsb_idx = 0;
  6798. /**
  6799. * Producer memory:
  6800. * E2 mode: address 0-135 match to the mapping memory;
  6801. * 136 - PF0 default prod; 137 - PF1 default prod;
  6802. * 138 - PF2 default prod; 139 - PF3 default prod;
  6803. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6804. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6805. * 144-147 reserved.
  6806. *
  6807. * E1.5 mode - In backward compatible mode;
  6808. * for non default SB; each even line in the memory
  6809. * holds the U producer and each odd line hold
  6810. * the C producer. The first 128 producers are for
  6811. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6812. * producers are for the DSB for each PF.
  6813. * Each PF has five segments: (the order inside each
  6814. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6815. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6816. * 144-147 attn prods;
  6817. */
  6818. /* non-default-status-blocks */
  6819. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6820. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6821. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6822. prod_offset = (bp->igu_base_sb + sb_idx) *
  6823. num_segs;
  6824. for (i = 0; i < num_segs; i++) {
  6825. addr = IGU_REG_PROD_CONS_MEMORY +
  6826. (prod_offset + i) * 4;
  6827. REG_WR(bp, addr, 0);
  6828. }
  6829. /* send consumer update with value 0 */
  6830. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6831. USTORM_ID, 0, IGU_INT_NOP, 1);
  6832. bnx2x_igu_clear_sb(bp,
  6833. bp->igu_base_sb + sb_idx);
  6834. }
  6835. /* default-status-blocks */
  6836. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6837. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6838. if (CHIP_MODE_IS_4_PORT(bp))
  6839. dsb_idx = BP_FUNC(bp);
  6840. else
  6841. dsb_idx = BP_VN(bp);
  6842. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6843. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6844. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6845. /*
  6846. * igu prods come in chunks of E1HVN_MAX (4) -
  6847. * does not matters what is the current chip mode
  6848. */
  6849. for (i = 0; i < (num_segs * E1HVN_MAX);
  6850. i += E1HVN_MAX) {
  6851. addr = IGU_REG_PROD_CONS_MEMORY +
  6852. (prod_offset + i)*4;
  6853. REG_WR(bp, addr, 0);
  6854. }
  6855. /* send consumer update with 0 */
  6856. if (CHIP_INT_MODE_IS_BC(bp)) {
  6857. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6858. USTORM_ID, 0, IGU_INT_NOP, 1);
  6859. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6860. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6861. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6862. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6863. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6864. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6865. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6866. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6867. } else {
  6868. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6869. USTORM_ID, 0, IGU_INT_NOP, 1);
  6870. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6871. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6872. }
  6873. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6874. /* !!! These should become driver const once
  6875. rf-tool supports split-68 const */
  6876. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6877. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6878. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6879. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6880. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6881. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6882. }
  6883. }
  6884. /* Reset PCIE errors for debug */
  6885. REG_WR(bp, 0x2114, 0xffffffff);
  6886. REG_WR(bp, 0x2120, 0xffffffff);
  6887. if (CHIP_IS_E1x(bp)) {
  6888. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6889. main_mem_base = HC_REG_MAIN_MEMORY +
  6890. BP_PORT(bp) * (main_mem_size * 4);
  6891. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6892. main_mem_width = 8;
  6893. val = REG_RD(bp, main_mem_prty_clr);
  6894. if (val)
  6895. DP(NETIF_MSG_HW,
  6896. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6897. val);
  6898. /* Clear "false" parity errors in MSI-X table */
  6899. for (i = main_mem_base;
  6900. i < main_mem_base + main_mem_size * 4;
  6901. i += main_mem_width) {
  6902. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6903. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6904. i, main_mem_width / 4);
  6905. }
  6906. /* Clear HC parity attention */
  6907. REG_RD(bp, main_mem_prty_clr);
  6908. }
  6909. #ifdef BNX2X_STOP_ON_ERROR
  6910. /* Enable STORMs SP logging */
  6911. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6912. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6913. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6914. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6915. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6916. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6917. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6918. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6919. #endif
  6920. bnx2x_phy_probe(&bp->link_params);
  6921. return 0;
  6922. }
  6923. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6924. {
  6925. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6926. if (!CHIP_IS_E1x(bp))
  6927. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6928. sizeof(struct host_hc_status_block_e2));
  6929. else
  6930. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6931. sizeof(struct host_hc_status_block_e1x));
  6932. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6933. }
  6934. void bnx2x_free_mem(struct bnx2x *bp)
  6935. {
  6936. int i;
  6937. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6938. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6939. if (IS_VF(bp))
  6940. return;
  6941. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6942. sizeof(struct host_sp_status_block));
  6943. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6944. sizeof(struct bnx2x_slowpath));
  6945. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6946. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6947. bp->context[i].size);
  6948. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6949. BNX2X_FREE(bp->ilt->lines);
  6950. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6951. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6952. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6953. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6954. bnx2x_iov_free_mem(bp);
  6955. }
  6956. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6957. {
  6958. if (!CHIP_IS_E1x(bp)) {
  6959. /* size = the status block + ramrod buffers */
  6960. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6961. sizeof(struct host_hc_status_block_e2));
  6962. if (!bp->cnic_sb.e2_sb)
  6963. goto alloc_mem_err;
  6964. } else {
  6965. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6966. sizeof(struct host_hc_status_block_e1x));
  6967. if (!bp->cnic_sb.e1x_sb)
  6968. goto alloc_mem_err;
  6969. }
  6970. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6971. /* allocate searcher T2 table, as it wasn't allocated before */
  6972. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6973. if (!bp->t2)
  6974. goto alloc_mem_err;
  6975. }
  6976. /* write address to which L5 should insert its values */
  6977. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6978. &bp->slowpath->drv_info_to_mcp;
  6979. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6980. goto alloc_mem_err;
  6981. return 0;
  6982. alloc_mem_err:
  6983. bnx2x_free_mem_cnic(bp);
  6984. BNX2X_ERR("Can't allocate memory\n");
  6985. return -ENOMEM;
  6986. }
  6987. int bnx2x_alloc_mem(struct bnx2x *bp)
  6988. {
  6989. int i, allocated, context_size;
  6990. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6991. /* allocate searcher T2 table */
  6992. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6993. if (!bp->t2)
  6994. goto alloc_mem_err;
  6995. }
  6996. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6997. sizeof(struct host_sp_status_block));
  6998. if (!bp->def_status_blk)
  6999. goto alloc_mem_err;
  7000. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  7001. sizeof(struct bnx2x_slowpath));
  7002. if (!bp->slowpath)
  7003. goto alloc_mem_err;
  7004. /* Allocate memory for CDU context:
  7005. * This memory is allocated separately and not in the generic ILT
  7006. * functions because CDU differs in few aspects:
  7007. * 1. There are multiple entities allocating memory for context -
  7008. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  7009. * its own ILT lines.
  7010. * 2. Since CDU page-size is not a single 4KB page (which is the case
  7011. * for the other ILT clients), to be efficient we want to support
  7012. * allocation of sub-page-size in the last entry.
  7013. * 3. Context pointers are used by the driver to pass to FW / update
  7014. * the context (for the other ILT clients the pointers are used just to
  7015. * free the memory during unload).
  7016. */
  7017. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  7018. for (i = 0, allocated = 0; allocated < context_size; i++) {
  7019. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  7020. (context_size - allocated));
  7021. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  7022. bp->context[i].size);
  7023. if (!bp->context[i].vcxt)
  7024. goto alloc_mem_err;
  7025. allocated += bp->context[i].size;
  7026. }
  7027. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  7028. GFP_KERNEL);
  7029. if (!bp->ilt->lines)
  7030. goto alloc_mem_err;
  7031. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  7032. goto alloc_mem_err;
  7033. if (bnx2x_iov_alloc_mem(bp))
  7034. goto alloc_mem_err;
  7035. /* Slow path ring */
  7036. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  7037. if (!bp->spq)
  7038. goto alloc_mem_err;
  7039. /* EQ */
  7040. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  7041. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  7042. if (!bp->eq_ring)
  7043. goto alloc_mem_err;
  7044. return 0;
  7045. alloc_mem_err:
  7046. bnx2x_free_mem(bp);
  7047. BNX2X_ERR("Can't allocate memory\n");
  7048. return -ENOMEM;
  7049. }
  7050. /*
  7051. * Init service functions
  7052. */
  7053. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7054. struct bnx2x_vlan_mac_obj *obj, bool set,
  7055. int mac_type, unsigned long *ramrod_flags)
  7056. {
  7057. int rc;
  7058. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7059. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7060. /* Fill general parameters */
  7061. ramrod_param.vlan_mac_obj = obj;
  7062. ramrod_param.ramrod_flags = *ramrod_flags;
  7063. /* Fill a user request section if needed */
  7064. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7065. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7066. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7067. /* Set the command: ADD or DEL */
  7068. if (set)
  7069. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7070. else
  7071. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7072. }
  7073. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7074. if (rc == -EEXIST) {
  7075. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7076. /* do not treat adding same MAC as error */
  7077. rc = 0;
  7078. } else if (rc < 0)
  7079. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7080. return rc;
  7081. }
  7082. int bnx2x_set_vlan_one(struct bnx2x *bp, u16 vlan,
  7083. struct bnx2x_vlan_mac_obj *obj, bool set,
  7084. unsigned long *ramrod_flags)
  7085. {
  7086. int rc;
  7087. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7088. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7089. /* Fill general parameters */
  7090. ramrod_param.vlan_mac_obj = obj;
  7091. ramrod_param.ramrod_flags = *ramrod_flags;
  7092. /* Fill a user request section if needed */
  7093. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7094. ramrod_param.user_req.u.vlan.vlan = vlan;
  7095. /* Set the command: ADD or DEL */
  7096. if (set)
  7097. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7098. else
  7099. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7100. }
  7101. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7102. if (rc == -EEXIST) {
  7103. /* Do not treat adding same vlan as error. */
  7104. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7105. rc = 0;
  7106. } else if (rc < 0) {
  7107. BNX2X_ERR("%s VLAN failed\n", (set ? "Set" : "Del"));
  7108. }
  7109. return rc;
  7110. }
  7111. int bnx2x_del_all_macs(struct bnx2x *bp,
  7112. struct bnx2x_vlan_mac_obj *mac_obj,
  7113. int mac_type, bool wait_for_comp)
  7114. {
  7115. int rc;
  7116. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7117. /* Wait for completion of requested */
  7118. if (wait_for_comp)
  7119. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7120. /* Set the mac type of addresses we want to clear */
  7121. __set_bit(mac_type, &vlan_mac_flags);
  7122. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7123. if (rc < 0)
  7124. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7125. return rc;
  7126. }
  7127. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7128. {
  7129. if (IS_PF(bp)) {
  7130. unsigned long ramrod_flags = 0;
  7131. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7132. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7133. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7134. &bp->sp_objs->mac_obj, set,
  7135. BNX2X_ETH_MAC, &ramrod_flags);
  7136. } else { /* vf */
  7137. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7138. bp->fp->index, set);
  7139. }
  7140. }
  7141. int bnx2x_setup_leading(struct bnx2x *bp)
  7142. {
  7143. if (IS_PF(bp))
  7144. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7145. else /* VF */
  7146. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7147. }
  7148. /**
  7149. * bnx2x_set_int_mode - configure interrupt mode
  7150. *
  7151. * @bp: driver handle
  7152. *
  7153. * In case of MSI-X it will also try to enable MSI-X.
  7154. */
  7155. int bnx2x_set_int_mode(struct bnx2x *bp)
  7156. {
  7157. int rc = 0;
  7158. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7159. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7160. return -EINVAL;
  7161. }
  7162. switch (int_mode) {
  7163. case BNX2X_INT_MODE_MSIX:
  7164. /* attempt to enable msix */
  7165. rc = bnx2x_enable_msix(bp);
  7166. /* msix attained */
  7167. if (!rc)
  7168. return 0;
  7169. /* vfs use only msix */
  7170. if (rc && IS_VF(bp))
  7171. return rc;
  7172. /* failed to enable multiple MSI-X */
  7173. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7174. bp->num_queues,
  7175. 1 + bp->num_cnic_queues);
  7176. /* falling through... */
  7177. case BNX2X_INT_MODE_MSI:
  7178. bnx2x_enable_msi(bp);
  7179. /* falling through... */
  7180. case BNX2X_INT_MODE_INTX:
  7181. bp->num_ethernet_queues = 1;
  7182. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7183. BNX2X_DEV_INFO("set number of queues to 1\n");
  7184. break;
  7185. default:
  7186. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7187. return -EINVAL;
  7188. }
  7189. return 0;
  7190. }
  7191. /* must be called prior to any HW initializations */
  7192. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7193. {
  7194. if (IS_SRIOV(bp))
  7195. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7196. return L2_ILT_LINES(bp);
  7197. }
  7198. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7199. {
  7200. struct ilt_client_info *ilt_client;
  7201. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7202. u16 line = 0;
  7203. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7204. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7205. /* CDU */
  7206. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7207. ilt_client->client_num = ILT_CLIENT_CDU;
  7208. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7209. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7210. ilt_client->start = line;
  7211. line += bnx2x_cid_ilt_lines(bp);
  7212. if (CNIC_SUPPORT(bp))
  7213. line += CNIC_ILT_LINES;
  7214. ilt_client->end = line - 1;
  7215. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7216. ilt_client->start,
  7217. ilt_client->end,
  7218. ilt_client->page_size,
  7219. ilt_client->flags,
  7220. ilog2(ilt_client->page_size >> 12));
  7221. /* QM */
  7222. if (QM_INIT(bp->qm_cid_count)) {
  7223. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7224. ilt_client->client_num = ILT_CLIENT_QM;
  7225. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7226. ilt_client->flags = 0;
  7227. ilt_client->start = line;
  7228. /* 4 bytes for each cid */
  7229. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7230. QM_ILT_PAGE_SZ);
  7231. ilt_client->end = line - 1;
  7232. DP(NETIF_MSG_IFUP,
  7233. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7234. ilt_client->start,
  7235. ilt_client->end,
  7236. ilt_client->page_size,
  7237. ilt_client->flags,
  7238. ilog2(ilt_client->page_size >> 12));
  7239. }
  7240. if (CNIC_SUPPORT(bp)) {
  7241. /* SRC */
  7242. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7243. ilt_client->client_num = ILT_CLIENT_SRC;
  7244. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7245. ilt_client->flags = 0;
  7246. ilt_client->start = line;
  7247. line += SRC_ILT_LINES;
  7248. ilt_client->end = line - 1;
  7249. DP(NETIF_MSG_IFUP,
  7250. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7251. ilt_client->start,
  7252. ilt_client->end,
  7253. ilt_client->page_size,
  7254. ilt_client->flags,
  7255. ilog2(ilt_client->page_size >> 12));
  7256. /* TM */
  7257. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7258. ilt_client->client_num = ILT_CLIENT_TM;
  7259. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7260. ilt_client->flags = 0;
  7261. ilt_client->start = line;
  7262. line += TM_ILT_LINES;
  7263. ilt_client->end = line - 1;
  7264. DP(NETIF_MSG_IFUP,
  7265. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7266. ilt_client->start,
  7267. ilt_client->end,
  7268. ilt_client->page_size,
  7269. ilt_client->flags,
  7270. ilog2(ilt_client->page_size >> 12));
  7271. }
  7272. BUG_ON(line > ILT_MAX_LINES);
  7273. }
  7274. /**
  7275. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7276. *
  7277. * @bp: driver handle
  7278. * @fp: pointer to fastpath
  7279. * @init_params: pointer to parameters structure
  7280. *
  7281. * parameters configured:
  7282. * - HC configuration
  7283. * - Queue's CDU context
  7284. */
  7285. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7286. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7287. {
  7288. u8 cos;
  7289. int cxt_index, cxt_offset;
  7290. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7291. if (!IS_FCOE_FP(fp)) {
  7292. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7293. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7294. /* If HC is supported, enable host coalescing in the transition
  7295. * to INIT state.
  7296. */
  7297. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7298. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7299. /* HC rate */
  7300. init_params->rx.hc_rate = bp->rx_ticks ?
  7301. (1000000 / bp->rx_ticks) : 0;
  7302. init_params->tx.hc_rate = bp->tx_ticks ?
  7303. (1000000 / bp->tx_ticks) : 0;
  7304. /* FW SB ID */
  7305. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7306. fp->fw_sb_id;
  7307. /*
  7308. * CQ index among the SB indices: FCoE clients uses the default
  7309. * SB, therefore it's different.
  7310. */
  7311. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7312. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7313. }
  7314. /* set maximum number of COSs supported by this queue */
  7315. init_params->max_cos = fp->max_cos;
  7316. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7317. fp->index, init_params->max_cos);
  7318. /* set the context pointers queue object */
  7319. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7320. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7321. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7322. ILT_PAGE_CIDS);
  7323. init_params->cxts[cos] =
  7324. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7325. }
  7326. }
  7327. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7328. struct bnx2x_queue_state_params *q_params,
  7329. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7330. int tx_index, bool leading)
  7331. {
  7332. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7333. /* Set the command */
  7334. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7335. /* Set tx-only QUEUE flags: don't zero statistics */
  7336. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7337. /* choose the index of the cid to send the slow path on */
  7338. tx_only_params->cid_index = tx_index;
  7339. /* Set general TX_ONLY_SETUP parameters */
  7340. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7341. /* Set Tx TX_ONLY_SETUP parameters */
  7342. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7343. DP(NETIF_MSG_IFUP,
  7344. "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
  7345. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7346. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7347. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7348. /* send the ramrod */
  7349. return bnx2x_queue_state_change(bp, q_params);
  7350. }
  7351. /**
  7352. * bnx2x_setup_queue - setup queue
  7353. *
  7354. * @bp: driver handle
  7355. * @fp: pointer to fastpath
  7356. * @leading: is leading
  7357. *
  7358. * This function performs 2 steps in a Queue state machine
  7359. * actually: 1) RESET->INIT 2) INIT->SETUP
  7360. */
  7361. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7362. bool leading)
  7363. {
  7364. struct bnx2x_queue_state_params q_params = {NULL};
  7365. struct bnx2x_queue_setup_params *setup_params =
  7366. &q_params.params.setup;
  7367. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7368. &q_params.params.tx_only;
  7369. int rc;
  7370. u8 tx_index;
  7371. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7372. /* reset IGU state skip FCoE L2 queue */
  7373. if (!IS_FCOE_FP(fp))
  7374. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7375. IGU_INT_ENABLE, 0);
  7376. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7377. /* We want to wait for completion in this context */
  7378. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7379. /* Prepare the INIT parameters */
  7380. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7381. /* Set the command */
  7382. q_params.cmd = BNX2X_Q_CMD_INIT;
  7383. /* Change the state to INIT */
  7384. rc = bnx2x_queue_state_change(bp, &q_params);
  7385. if (rc) {
  7386. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7387. return rc;
  7388. }
  7389. DP(NETIF_MSG_IFUP, "init complete\n");
  7390. /* Now move the Queue to the SETUP state... */
  7391. memset(setup_params, 0, sizeof(*setup_params));
  7392. /* Set QUEUE flags */
  7393. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7394. /* Set general SETUP parameters */
  7395. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7396. FIRST_TX_COS_INDEX);
  7397. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7398. &setup_params->rxq_params);
  7399. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7400. FIRST_TX_COS_INDEX);
  7401. /* Set the command */
  7402. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7403. if (IS_FCOE_FP(fp))
  7404. bp->fcoe_init = true;
  7405. /* Change the state to SETUP */
  7406. rc = bnx2x_queue_state_change(bp, &q_params);
  7407. if (rc) {
  7408. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7409. return rc;
  7410. }
  7411. /* loop through the relevant tx-only indices */
  7412. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7413. tx_index < fp->max_cos;
  7414. tx_index++) {
  7415. /* prepare and send tx-only ramrod*/
  7416. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7417. tx_only_params, tx_index, leading);
  7418. if (rc) {
  7419. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7420. fp->index, tx_index);
  7421. return rc;
  7422. }
  7423. }
  7424. return rc;
  7425. }
  7426. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7427. {
  7428. struct bnx2x_fastpath *fp = &bp->fp[index];
  7429. struct bnx2x_fp_txdata *txdata;
  7430. struct bnx2x_queue_state_params q_params = {NULL};
  7431. int rc, tx_index;
  7432. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7433. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7434. /* We want to wait for completion in this context */
  7435. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7436. /* close tx-only connections */
  7437. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7438. tx_index < fp->max_cos;
  7439. tx_index++){
  7440. /* ascertain this is a normal queue*/
  7441. txdata = fp->txdata_ptr[tx_index];
  7442. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7443. txdata->txq_index);
  7444. /* send halt terminate on tx-only connection */
  7445. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7446. memset(&q_params.params.terminate, 0,
  7447. sizeof(q_params.params.terminate));
  7448. q_params.params.terminate.cid_index = tx_index;
  7449. rc = bnx2x_queue_state_change(bp, &q_params);
  7450. if (rc)
  7451. return rc;
  7452. /* send halt terminate on tx-only connection */
  7453. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7454. memset(&q_params.params.cfc_del, 0,
  7455. sizeof(q_params.params.cfc_del));
  7456. q_params.params.cfc_del.cid_index = tx_index;
  7457. rc = bnx2x_queue_state_change(bp, &q_params);
  7458. if (rc)
  7459. return rc;
  7460. }
  7461. /* Stop the primary connection: */
  7462. /* ...halt the connection */
  7463. q_params.cmd = BNX2X_Q_CMD_HALT;
  7464. rc = bnx2x_queue_state_change(bp, &q_params);
  7465. if (rc)
  7466. return rc;
  7467. /* ...terminate the connection */
  7468. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7469. memset(&q_params.params.terminate, 0,
  7470. sizeof(q_params.params.terminate));
  7471. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7472. rc = bnx2x_queue_state_change(bp, &q_params);
  7473. if (rc)
  7474. return rc;
  7475. /* ...delete cfc entry */
  7476. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7477. memset(&q_params.params.cfc_del, 0,
  7478. sizeof(q_params.params.cfc_del));
  7479. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7480. return bnx2x_queue_state_change(bp, &q_params);
  7481. }
  7482. static void bnx2x_reset_func(struct bnx2x *bp)
  7483. {
  7484. int port = BP_PORT(bp);
  7485. int func = BP_FUNC(bp);
  7486. int i;
  7487. /* Disable the function in the FW */
  7488. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7489. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7490. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7491. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7492. /* FP SBs */
  7493. for_each_eth_queue(bp, i) {
  7494. struct bnx2x_fastpath *fp = &bp->fp[i];
  7495. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7496. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7497. SB_DISABLED);
  7498. }
  7499. if (CNIC_LOADED(bp))
  7500. /* CNIC SB */
  7501. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7502. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7503. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7504. /* SP SB */
  7505. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7506. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7507. SB_DISABLED);
  7508. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7509. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7510. 0);
  7511. /* Configure IGU */
  7512. if (bp->common.int_block == INT_BLOCK_HC) {
  7513. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7514. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7515. } else {
  7516. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7517. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7518. }
  7519. if (CNIC_LOADED(bp)) {
  7520. /* Disable Timer scan */
  7521. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7522. /*
  7523. * Wait for at least 10ms and up to 2 second for the timers
  7524. * scan to complete
  7525. */
  7526. for (i = 0; i < 200; i++) {
  7527. usleep_range(10000, 20000);
  7528. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7529. break;
  7530. }
  7531. }
  7532. /* Clear ILT */
  7533. bnx2x_clear_func_ilt(bp, func);
  7534. /* Timers workaround bug for E2: if this is vnic-3,
  7535. * we need to set the entire ilt range for this timers.
  7536. */
  7537. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7538. struct ilt_client_info ilt_cli;
  7539. /* use dummy TM client */
  7540. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7541. ilt_cli.start = 0;
  7542. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7543. ilt_cli.client_num = ILT_CLIENT_TM;
  7544. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7545. }
  7546. /* this assumes that reset_port() called before reset_func()*/
  7547. if (!CHIP_IS_E1x(bp))
  7548. bnx2x_pf_disable(bp);
  7549. bp->dmae_ready = 0;
  7550. }
  7551. static void bnx2x_reset_port(struct bnx2x *bp)
  7552. {
  7553. int port = BP_PORT(bp);
  7554. u32 val;
  7555. /* Reset physical Link */
  7556. bnx2x__link_reset(bp);
  7557. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7558. /* Do not rcv packets to BRB */
  7559. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7560. /* Do not direct rcv packets that are not for MCP to the BRB */
  7561. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7562. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7563. /* Configure AEU */
  7564. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7565. msleep(100);
  7566. /* Check for BRB port occupancy */
  7567. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7568. if (val)
  7569. DP(NETIF_MSG_IFDOWN,
  7570. "BRB1 is not empty %d blocks are occupied\n", val);
  7571. /* TODO: Close Doorbell port? */
  7572. }
  7573. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7574. {
  7575. struct bnx2x_func_state_params func_params = {NULL};
  7576. /* Prepare parameters for function state transitions */
  7577. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7578. func_params.f_obj = &bp->func_obj;
  7579. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7580. func_params.params.hw_init.load_phase = load_code;
  7581. return bnx2x_func_state_change(bp, &func_params);
  7582. }
  7583. static int bnx2x_func_stop(struct bnx2x *bp)
  7584. {
  7585. struct bnx2x_func_state_params func_params = {NULL};
  7586. int rc;
  7587. /* Prepare parameters for function state transitions */
  7588. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7589. func_params.f_obj = &bp->func_obj;
  7590. func_params.cmd = BNX2X_F_CMD_STOP;
  7591. /*
  7592. * Try to stop the function the 'good way'. If fails (in case
  7593. * of a parity error during bnx2x_chip_cleanup()) and we are
  7594. * not in a debug mode, perform a state transaction in order to
  7595. * enable further HW_RESET transaction.
  7596. */
  7597. rc = bnx2x_func_state_change(bp, &func_params);
  7598. if (rc) {
  7599. #ifdef BNX2X_STOP_ON_ERROR
  7600. return rc;
  7601. #else
  7602. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7603. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7604. return bnx2x_func_state_change(bp, &func_params);
  7605. #endif
  7606. }
  7607. return 0;
  7608. }
  7609. /**
  7610. * bnx2x_send_unload_req - request unload mode from the MCP.
  7611. *
  7612. * @bp: driver handle
  7613. * @unload_mode: requested function's unload mode
  7614. *
  7615. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7616. */
  7617. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7618. {
  7619. u32 reset_code = 0;
  7620. int port = BP_PORT(bp);
  7621. /* Select the UNLOAD request mode */
  7622. if (unload_mode == UNLOAD_NORMAL)
  7623. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7624. else if (bp->flags & NO_WOL_FLAG)
  7625. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7626. else if (bp->wol) {
  7627. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7628. u8 *mac_addr = bp->dev->dev_addr;
  7629. struct pci_dev *pdev = bp->pdev;
  7630. u32 val;
  7631. u16 pmc;
  7632. /* The mac address is written to entries 1-4 to
  7633. * preserve entry 0 which is used by the PMF
  7634. */
  7635. u8 entry = (BP_VN(bp) + 1)*8;
  7636. val = (mac_addr[0] << 8) | mac_addr[1];
  7637. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7638. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7639. (mac_addr[4] << 8) | mac_addr[5];
  7640. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7641. /* Enable the PME and clear the status */
  7642. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7643. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7644. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7645. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7646. } else
  7647. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7648. /* Send the request to the MCP */
  7649. if (!BP_NOMCP(bp))
  7650. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7651. else {
  7652. int path = BP_PATH(bp);
  7653. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7654. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7655. bnx2x_load_count[path][2]);
  7656. bnx2x_load_count[path][0]--;
  7657. bnx2x_load_count[path][1 + port]--;
  7658. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7659. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7660. bnx2x_load_count[path][2]);
  7661. if (bnx2x_load_count[path][0] == 0)
  7662. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7663. else if (bnx2x_load_count[path][1 + port] == 0)
  7664. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7665. else
  7666. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7667. }
  7668. return reset_code;
  7669. }
  7670. /**
  7671. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7672. *
  7673. * @bp: driver handle
  7674. * @keep_link: true iff link should be kept up
  7675. */
  7676. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7677. {
  7678. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7679. /* Report UNLOAD_DONE to MCP */
  7680. if (!BP_NOMCP(bp))
  7681. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7682. }
  7683. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7684. {
  7685. int tout = 50;
  7686. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7687. if (!bp->port.pmf)
  7688. return 0;
  7689. /*
  7690. * (assumption: No Attention from MCP at this stage)
  7691. * PMF probably in the middle of TX disable/enable transaction
  7692. * 1. Sync IRS for default SB
  7693. * 2. Sync SP queue - this guarantees us that attention handling started
  7694. * 3. Wait, that TX disable/enable transaction completes
  7695. *
  7696. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7697. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7698. * received completion for the transaction the state is TX_STOPPED.
  7699. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7700. * transaction.
  7701. */
  7702. /* make sure default SB ISR is done */
  7703. if (msix)
  7704. synchronize_irq(bp->msix_table[0].vector);
  7705. else
  7706. synchronize_irq(bp->pdev->irq);
  7707. flush_workqueue(bnx2x_wq);
  7708. flush_workqueue(bnx2x_iov_wq);
  7709. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7710. BNX2X_F_STATE_STARTED && tout--)
  7711. msleep(20);
  7712. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7713. BNX2X_F_STATE_STARTED) {
  7714. #ifdef BNX2X_STOP_ON_ERROR
  7715. BNX2X_ERR("Wrong function state\n");
  7716. return -EBUSY;
  7717. #else
  7718. /*
  7719. * Failed to complete the transaction in a "good way"
  7720. * Force both transactions with CLR bit
  7721. */
  7722. struct bnx2x_func_state_params func_params = {NULL};
  7723. DP(NETIF_MSG_IFDOWN,
  7724. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7725. func_params.f_obj = &bp->func_obj;
  7726. __set_bit(RAMROD_DRV_CLR_ONLY,
  7727. &func_params.ramrod_flags);
  7728. /* STARTED-->TX_ST0PPED */
  7729. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7730. bnx2x_func_state_change(bp, &func_params);
  7731. /* TX_ST0PPED-->STARTED */
  7732. func_params.cmd = BNX2X_F_CMD_TX_START;
  7733. return bnx2x_func_state_change(bp, &func_params);
  7734. #endif
  7735. }
  7736. return 0;
  7737. }
  7738. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7739. {
  7740. int port = BP_PORT(bp);
  7741. /* Disable sending PTP packets to host */
  7742. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7743. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7744. /* Reset PTP event detection rules */
  7745. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7746. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7747. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7748. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7749. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7750. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7751. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7752. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7753. /* Disable the PTP feature */
  7754. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7755. NIG_REG_P0_PTP_EN, 0x0);
  7756. }
  7757. /* Called during unload, to stop PTP-related stuff */
  7758. static void bnx2x_stop_ptp(struct bnx2x *bp)
  7759. {
  7760. /* Cancel PTP work queue. Should be done after the Tx queues are
  7761. * drained to prevent additional scheduling.
  7762. */
  7763. cancel_work_sync(&bp->ptp_task);
  7764. if (bp->ptp_tx_skb) {
  7765. dev_kfree_skb_any(bp->ptp_tx_skb);
  7766. bp->ptp_tx_skb = NULL;
  7767. }
  7768. /* Disable PTP in HW */
  7769. bnx2x_disable_ptp(bp);
  7770. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7771. }
  7772. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7773. {
  7774. int port = BP_PORT(bp);
  7775. int i, rc = 0;
  7776. u8 cos;
  7777. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7778. u32 reset_code;
  7779. /* Wait until tx fastpath tasks complete */
  7780. for_each_tx_queue(bp, i) {
  7781. struct bnx2x_fastpath *fp = &bp->fp[i];
  7782. for_each_cos_in_tx_queue(fp, cos)
  7783. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7784. #ifdef BNX2X_STOP_ON_ERROR
  7785. if (rc)
  7786. return;
  7787. #endif
  7788. }
  7789. /* Give HW time to discard old tx messages */
  7790. usleep_range(1000, 2000);
  7791. /* Clean all ETH MACs */
  7792. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7793. false);
  7794. if (rc < 0)
  7795. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7796. /* Clean up UC list */
  7797. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7798. true);
  7799. if (rc < 0)
  7800. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7801. rc);
  7802. /* Disable LLH */
  7803. if (!CHIP_IS_E1(bp))
  7804. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7805. /* Set "drop all" (stop Rx).
  7806. * We need to take a netif_addr_lock() here in order to prevent
  7807. * a race between the completion code and this code.
  7808. */
  7809. netif_addr_lock_bh(bp->dev);
  7810. /* Schedule the rx_mode command */
  7811. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7812. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7813. else
  7814. bnx2x_set_storm_rx_mode(bp);
  7815. /* Cleanup multicast configuration */
  7816. rparam.mcast_obj = &bp->mcast_obj;
  7817. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7818. if (rc < 0)
  7819. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7820. netif_addr_unlock_bh(bp->dev);
  7821. bnx2x_iov_chip_cleanup(bp);
  7822. /*
  7823. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7824. * this function should perform FUNC, PORT or COMMON HW
  7825. * reset.
  7826. */
  7827. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7828. /*
  7829. * (assumption: No Attention from MCP at this stage)
  7830. * PMF probably in the middle of TX disable/enable transaction
  7831. */
  7832. rc = bnx2x_func_wait_started(bp);
  7833. if (rc) {
  7834. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7835. #ifdef BNX2X_STOP_ON_ERROR
  7836. return;
  7837. #endif
  7838. }
  7839. /* Close multi and leading connections
  7840. * Completions for ramrods are collected in a synchronous way
  7841. */
  7842. for_each_eth_queue(bp, i)
  7843. if (bnx2x_stop_queue(bp, i))
  7844. #ifdef BNX2X_STOP_ON_ERROR
  7845. return;
  7846. #else
  7847. goto unload_error;
  7848. #endif
  7849. if (CNIC_LOADED(bp)) {
  7850. for_each_cnic_queue(bp, i)
  7851. if (bnx2x_stop_queue(bp, i))
  7852. #ifdef BNX2X_STOP_ON_ERROR
  7853. return;
  7854. #else
  7855. goto unload_error;
  7856. #endif
  7857. }
  7858. /* If SP settings didn't get completed so far - something
  7859. * very wrong has happen.
  7860. */
  7861. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7862. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7863. #ifndef BNX2X_STOP_ON_ERROR
  7864. unload_error:
  7865. #endif
  7866. rc = bnx2x_func_stop(bp);
  7867. if (rc) {
  7868. BNX2X_ERR("Function stop failed!\n");
  7869. #ifdef BNX2X_STOP_ON_ERROR
  7870. return;
  7871. #endif
  7872. }
  7873. /* stop_ptp should be after the Tx queues are drained to prevent
  7874. * scheduling to the cancelled PTP work queue. It should also be after
  7875. * function stop ramrod is sent, since as part of this ramrod FW access
  7876. * PTP registers.
  7877. */
  7878. if (bp->flags & PTP_SUPPORTED)
  7879. bnx2x_stop_ptp(bp);
  7880. /* Disable HW interrupts, NAPI */
  7881. bnx2x_netif_stop(bp, 1);
  7882. /* Delete all NAPI objects */
  7883. bnx2x_del_all_napi(bp);
  7884. if (CNIC_LOADED(bp))
  7885. bnx2x_del_all_napi_cnic(bp);
  7886. /* Release IRQs */
  7887. bnx2x_free_irq(bp);
  7888. /* Reset the chip, unless PCI function is offline. If we reach this
  7889. * point following a PCI error handling, it means device is really
  7890. * in a bad state and we're about to remove it, so reset the chip
  7891. * is not a good idea.
  7892. */
  7893. if (!pci_channel_offline(bp->pdev)) {
  7894. rc = bnx2x_reset_hw(bp, reset_code);
  7895. if (rc)
  7896. BNX2X_ERR("HW_RESET failed\n");
  7897. }
  7898. /* Report UNLOAD_DONE to MCP */
  7899. bnx2x_send_unload_done(bp, keep_link);
  7900. }
  7901. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7902. {
  7903. u32 val;
  7904. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7905. if (CHIP_IS_E1(bp)) {
  7906. int port = BP_PORT(bp);
  7907. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7908. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7909. val = REG_RD(bp, addr);
  7910. val &= ~(0x300);
  7911. REG_WR(bp, addr, val);
  7912. } else {
  7913. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7914. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7915. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7916. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7917. }
  7918. }
  7919. /* Close gates #2, #3 and #4: */
  7920. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7921. {
  7922. u32 val;
  7923. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7924. if (!CHIP_IS_E1(bp)) {
  7925. /* #4 */
  7926. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7927. /* #2 */
  7928. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7929. }
  7930. /* #3 */
  7931. if (CHIP_IS_E1x(bp)) {
  7932. /* Prevent interrupts from HC on both ports */
  7933. val = REG_RD(bp, HC_REG_CONFIG_1);
  7934. REG_WR(bp, HC_REG_CONFIG_1,
  7935. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7936. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7937. val = REG_RD(bp, HC_REG_CONFIG_0);
  7938. REG_WR(bp, HC_REG_CONFIG_0,
  7939. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7940. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7941. } else {
  7942. /* Prevent incoming interrupts in IGU */
  7943. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7944. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7945. (!close) ?
  7946. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7947. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7948. }
  7949. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7950. close ? "closing" : "opening");
  7951. mmiowb();
  7952. }
  7953. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7954. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7955. {
  7956. /* Do some magic... */
  7957. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7958. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7959. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7960. }
  7961. /**
  7962. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7963. *
  7964. * @bp: driver handle
  7965. * @magic_val: old value of the `magic' bit.
  7966. */
  7967. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7968. {
  7969. /* Restore the `magic' bit value... */
  7970. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7971. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7972. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7973. }
  7974. /**
  7975. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7976. *
  7977. * @bp: driver handle
  7978. * @magic_val: old value of 'magic' bit.
  7979. *
  7980. * Takes care of CLP configurations.
  7981. */
  7982. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7983. {
  7984. u32 shmem;
  7985. u32 validity_offset;
  7986. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7987. /* Set `magic' bit in order to save MF config */
  7988. if (!CHIP_IS_E1(bp))
  7989. bnx2x_clp_reset_prep(bp, magic_val);
  7990. /* Get shmem offset */
  7991. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7992. validity_offset =
  7993. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7994. /* Clear validity map flags */
  7995. if (shmem > 0)
  7996. REG_WR(bp, shmem + validity_offset, 0);
  7997. }
  7998. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7999. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  8000. /**
  8001. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  8002. *
  8003. * @bp: driver handle
  8004. */
  8005. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  8006. {
  8007. /* special handling for emulation and FPGA,
  8008. wait 10 times longer */
  8009. if (CHIP_REV_IS_SLOW(bp))
  8010. msleep(MCP_ONE_TIMEOUT*10);
  8011. else
  8012. msleep(MCP_ONE_TIMEOUT);
  8013. }
  8014. /*
  8015. * initializes bp->common.shmem_base and waits for validity signature to appear
  8016. */
  8017. static int bnx2x_init_shmem(struct bnx2x *bp)
  8018. {
  8019. int cnt = 0;
  8020. u32 val = 0;
  8021. do {
  8022. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  8023. /* If we read all 0xFFs, means we are in PCI error state and
  8024. * should bail out to avoid crashes on adapter's FW reads.
  8025. */
  8026. if (bp->common.shmem_base == 0xFFFFFFFF) {
  8027. bp->flags |= NO_MCP_FLAG;
  8028. return -ENODEV;
  8029. }
  8030. if (bp->common.shmem_base) {
  8031. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  8032. if (val & SHR_MEM_VALIDITY_MB)
  8033. return 0;
  8034. }
  8035. bnx2x_mcp_wait_one(bp);
  8036. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  8037. BNX2X_ERR("BAD MCP validity signature\n");
  8038. return -ENODEV;
  8039. }
  8040. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  8041. {
  8042. int rc = bnx2x_init_shmem(bp);
  8043. /* Restore the `magic' bit value */
  8044. if (!CHIP_IS_E1(bp))
  8045. bnx2x_clp_reset_done(bp, magic_val);
  8046. return rc;
  8047. }
  8048. static void bnx2x_pxp_prep(struct bnx2x *bp)
  8049. {
  8050. if (!CHIP_IS_E1(bp)) {
  8051. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  8052. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  8053. mmiowb();
  8054. }
  8055. }
  8056. /*
  8057. * Reset the whole chip except for:
  8058. * - PCIE core
  8059. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  8060. * one reset bit)
  8061. * - IGU
  8062. * - MISC (including AEU)
  8063. * - GRC
  8064. * - RBCN, RBCP
  8065. */
  8066. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  8067. {
  8068. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  8069. u32 global_bits2, stay_reset2;
  8070. /*
  8071. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  8072. * (per chip) blocks.
  8073. */
  8074. global_bits2 =
  8075. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  8076. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  8077. /* Don't reset the following blocks.
  8078. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  8079. * reset, as in 4 port device they might still be owned
  8080. * by the MCP (there is only one leader per path).
  8081. */
  8082. not_reset_mask1 =
  8083. MISC_REGISTERS_RESET_REG_1_RST_HC |
  8084. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  8085. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  8086. not_reset_mask2 =
  8087. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  8088. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8089. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8090. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8091. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8092. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8093. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8094. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8095. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8096. MISC_REGISTERS_RESET_REG_2_PGLC |
  8097. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8098. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8099. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8100. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8101. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8102. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8103. /*
  8104. * Keep the following blocks in reset:
  8105. * - all xxMACs are handled by the bnx2x_link code.
  8106. */
  8107. stay_reset2 =
  8108. MISC_REGISTERS_RESET_REG_2_XMAC |
  8109. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8110. /* Full reset masks according to the chip */
  8111. reset_mask1 = 0xffffffff;
  8112. if (CHIP_IS_E1(bp))
  8113. reset_mask2 = 0xffff;
  8114. else if (CHIP_IS_E1H(bp))
  8115. reset_mask2 = 0x1ffff;
  8116. else if (CHIP_IS_E2(bp))
  8117. reset_mask2 = 0xfffff;
  8118. else /* CHIP_IS_E3 */
  8119. reset_mask2 = 0x3ffffff;
  8120. /* Don't reset global blocks unless we need to */
  8121. if (!global)
  8122. reset_mask2 &= ~global_bits2;
  8123. /*
  8124. * In case of attention in the QM, we need to reset PXP
  8125. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8126. * because otherwise QM reset would release 'close the gates' shortly
  8127. * before resetting the PXP, then the PSWRQ would send a write
  8128. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8129. * read the payload data from PSWWR, but PSWWR would not
  8130. * respond. The write queue in PGLUE would stuck, dmae commands
  8131. * would not return. Therefore it's important to reset the second
  8132. * reset register (containing the
  8133. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8134. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8135. * bit).
  8136. */
  8137. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8138. reset_mask2 & (~not_reset_mask2));
  8139. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8140. reset_mask1 & (~not_reset_mask1));
  8141. barrier();
  8142. mmiowb();
  8143. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8144. reset_mask2 & (~stay_reset2));
  8145. barrier();
  8146. mmiowb();
  8147. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8148. mmiowb();
  8149. }
  8150. /**
  8151. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8152. * It should get cleared in no more than 1s.
  8153. *
  8154. * @bp: driver handle
  8155. *
  8156. * It should get cleared in no more than 1s. Returns 0 if
  8157. * pending writes bit gets cleared.
  8158. */
  8159. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8160. {
  8161. u32 cnt = 1000;
  8162. u32 pend_bits = 0;
  8163. do {
  8164. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8165. if (pend_bits == 0)
  8166. break;
  8167. usleep_range(1000, 2000);
  8168. } while (cnt-- > 0);
  8169. if (cnt <= 0) {
  8170. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8171. pend_bits);
  8172. return -EBUSY;
  8173. }
  8174. return 0;
  8175. }
  8176. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8177. {
  8178. int cnt = 1000;
  8179. u32 val = 0;
  8180. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8181. u32 tags_63_32 = 0;
  8182. /* Empty the Tetris buffer, wait for 1s */
  8183. do {
  8184. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8185. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8186. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8187. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8188. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8189. if (CHIP_IS_E3(bp))
  8190. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8191. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8192. ((port_is_idle_0 & 0x1) == 0x1) &&
  8193. ((port_is_idle_1 & 0x1) == 0x1) &&
  8194. (pgl_exp_rom2 == 0xffffffff) &&
  8195. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8196. break;
  8197. usleep_range(1000, 2000);
  8198. } while (cnt-- > 0);
  8199. if (cnt <= 0) {
  8200. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8201. BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  8202. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8203. pgl_exp_rom2);
  8204. return -EAGAIN;
  8205. }
  8206. barrier();
  8207. /* Close gates #2, #3 and #4 */
  8208. bnx2x_set_234_gates(bp, true);
  8209. /* Poll for IGU VQs for 57712 and newer chips */
  8210. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8211. return -EAGAIN;
  8212. /* TBD: Indicate that "process kill" is in progress to MCP */
  8213. /* Clear "unprepared" bit */
  8214. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8215. barrier();
  8216. /* Make sure all is written to the chip before the reset */
  8217. mmiowb();
  8218. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8219. * PSWHST, GRC and PSWRD Tetris buffer.
  8220. */
  8221. usleep_range(1000, 2000);
  8222. /* Prepare to chip reset: */
  8223. /* MCP */
  8224. if (global)
  8225. bnx2x_reset_mcp_prep(bp, &val);
  8226. /* PXP */
  8227. bnx2x_pxp_prep(bp);
  8228. barrier();
  8229. /* reset the chip */
  8230. bnx2x_process_kill_chip_reset(bp, global);
  8231. barrier();
  8232. /* clear errors in PGB */
  8233. if (!CHIP_IS_E1x(bp))
  8234. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8235. /* Recover after reset: */
  8236. /* MCP */
  8237. if (global && bnx2x_reset_mcp_comp(bp, val))
  8238. return -EAGAIN;
  8239. /* TBD: Add resetting the NO_MCP mode DB here */
  8240. /* Open the gates #2, #3 and #4 */
  8241. bnx2x_set_234_gates(bp, false);
  8242. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8243. * reset state, re-enable attentions. */
  8244. return 0;
  8245. }
  8246. static int bnx2x_leader_reset(struct bnx2x *bp)
  8247. {
  8248. int rc = 0;
  8249. bool global = bnx2x_reset_is_global(bp);
  8250. u32 load_code;
  8251. /* if not going to reset MCP - load "fake" driver to reset HW while
  8252. * driver is owner of the HW
  8253. */
  8254. if (!global && !BP_NOMCP(bp)) {
  8255. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8256. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8257. if (!load_code) {
  8258. BNX2X_ERR("MCP response failure, aborting\n");
  8259. rc = -EAGAIN;
  8260. goto exit_leader_reset;
  8261. }
  8262. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8263. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8264. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8265. rc = -EAGAIN;
  8266. goto exit_leader_reset2;
  8267. }
  8268. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8269. if (!load_code) {
  8270. BNX2X_ERR("MCP response failure, aborting\n");
  8271. rc = -EAGAIN;
  8272. goto exit_leader_reset2;
  8273. }
  8274. }
  8275. /* Try to recover after the failure */
  8276. if (bnx2x_process_kill(bp, global)) {
  8277. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8278. BP_PATH(bp));
  8279. rc = -EAGAIN;
  8280. goto exit_leader_reset2;
  8281. }
  8282. /*
  8283. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8284. * state.
  8285. */
  8286. bnx2x_set_reset_done(bp);
  8287. if (global)
  8288. bnx2x_clear_reset_global(bp);
  8289. exit_leader_reset2:
  8290. /* unload "fake driver" if it was loaded */
  8291. if (!global && !BP_NOMCP(bp)) {
  8292. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8293. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8294. }
  8295. exit_leader_reset:
  8296. bp->is_leader = 0;
  8297. bnx2x_release_leader_lock(bp);
  8298. smp_mb();
  8299. return rc;
  8300. }
  8301. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8302. {
  8303. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8304. /* Disconnect this device */
  8305. netif_device_detach(bp->dev);
  8306. /*
  8307. * Block ifup for all function on this engine until "process kill"
  8308. * or power cycle.
  8309. */
  8310. bnx2x_set_reset_in_progress(bp);
  8311. /* Shut down the power */
  8312. bnx2x_set_power_state(bp, PCI_D3hot);
  8313. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8314. smp_mb();
  8315. }
  8316. /*
  8317. * Assumption: runs under rtnl lock. This together with the fact
  8318. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8319. * will never be called when netif_running(bp->dev) is false.
  8320. */
  8321. static void bnx2x_parity_recover(struct bnx2x *bp)
  8322. {
  8323. bool global = false;
  8324. u32 error_recovered, error_unrecovered;
  8325. bool is_parity;
  8326. DP(NETIF_MSG_HW, "Handling parity\n");
  8327. while (1) {
  8328. switch (bp->recovery_state) {
  8329. case BNX2X_RECOVERY_INIT:
  8330. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8331. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8332. WARN_ON(!is_parity);
  8333. /* Try to get a LEADER_LOCK HW lock */
  8334. if (bnx2x_trylock_leader_lock(bp)) {
  8335. bnx2x_set_reset_in_progress(bp);
  8336. /*
  8337. * Check if there is a global attention and if
  8338. * there was a global attention, set the global
  8339. * reset bit.
  8340. */
  8341. if (global)
  8342. bnx2x_set_reset_global(bp);
  8343. bp->is_leader = 1;
  8344. }
  8345. /* Stop the driver */
  8346. /* If interface has been removed - break */
  8347. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8348. return;
  8349. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8350. /* Ensure "is_leader", MCP command sequence and
  8351. * "recovery_state" update values are seen on other
  8352. * CPUs.
  8353. */
  8354. smp_mb();
  8355. break;
  8356. case BNX2X_RECOVERY_WAIT:
  8357. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8358. if (bp->is_leader) {
  8359. int other_engine = BP_PATH(bp) ? 0 : 1;
  8360. bool other_load_status =
  8361. bnx2x_get_load_status(bp, other_engine);
  8362. bool load_status =
  8363. bnx2x_get_load_status(bp, BP_PATH(bp));
  8364. global = bnx2x_reset_is_global(bp);
  8365. /*
  8366. * In case of a parity in a global block, let
  8367. * the first leader that performs a
  8368. * leader_reset() reset the global blocks in
  8369. * order to clear global attentions. Otherwise
  8370. * the gates will remain closed for that
  8371. * engine.
  8372. */
  8373. if (load_status ||
  8374. (global && other_load_status)) {
  8375. /* Wait until all other functions get
  8376. * down.
  8377. */
  8378. schedule_delayed_work(&bp->sp_rtnl_task,
  8379. HZ/10);
  8380. return;
  8381. } else {
  8382. /* If all other functions got down -
  8383. * try to bring the chip back to
  8384. * normal. In any case it's an exit
  8385. * point for a leader.
  8386. */
  8387. if (bnx2x_leader_reset(bp)) {
  8388. bnx2x_recovery_failed(bp);
  8389. return;
  8390. }
  8391. /* If we are here, means that the
  8392. * leader has succeeded and doesn't
  8393. * want to be a leader any more. Try
  8394. * to continue as a none-leader.
  8395. */
  8396. break;
  8397. }
  8398. } else { /* non-leader */
  8399. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8400. /* Try to get a LEADER_LOCK HW lock as
  8401. * long as a former leader may have
  8402. * been unloaded by the user or
  8403. * released a leadership by another
  8404. * reason.
  8405. */
  8406. if (bnx2x_trylock_leader_lock(bp)) {
  8407. /* I'm a leader now! Restart a
  8408. * switch case.
  8409. */
  8410. bp->is_leader = 1;
  8411. break;
  8412. }
  8413. schedule_delayed_work(&bp->sp_rtnl_task,
  8414. HZ/10);
  8415. return;
  8416. } else {
  8417. /*
  8418. * If there was a global attention, wait
  8419. * for it to be cleared.
  8420. */
  8421. if (bnx2x_reset_is_global(bp)) {
  8422. schedule_delayed_work(
  8423. &bp->sp_rtnl_task,
  8424. HZ/10);
  8425. return;
  8426. }
  8427. error_recovered =
  8428. bp->eth_stats.recoverable_error;
  8429. error_unrecovered =
  8430. bp->eth_stats.unrecoverable_error;
  8431. bp->recovery_state =
  8432. BNX2X_RECOVERY_NIC_LOADING;
  8433. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8434. error_unrecovered++;
  8435. netdev_err(bp->dev,
  8436. "Recovery failed. Power cycle needed\n");
  8437. /* Disconnect this device */
  8438. netif_device_detach(bp->dev);
  8439. /* Shut down the power */
  8440. bnx2x_set_power_state(
  8441. bp, PCI_D3hot);
  8442. smp_mb();
  8443. } else {
  8444. bp->recovery_state =
  8445. BNX2X_RECOVERY_DONE;
  8446. error_recovered++;
  8447. smp_mb();
  8448. }
  8449. bp->eth_stats.recoverable_error =
  8450. error_recovered;
  8451. bp->eth_stats.unrecoverable_error =
  8452. error_unrecovered;
  8453. return;
  8454. }
  8455. }
  8456. default:
  8457. return;
  8458. }
  8459. }
  8460. }
  8461. static int bnx2x_udp_port_update(struct bnx2x *bp)
  8462. {
  8463. struct bnx2x_func_switch_update_params *switch_update_params;
  8464. struct bnx2x_func_state_params func_params = {NULL};
  8465. struct bnx2x_udp_tunnel *udp_tunnel;
  8466. u16 vxlan_port = 0, geneve_port = 0;
  8467. int rc;
  8468. switch_update_params = &func_params.params.switch_update;
  8469. /* Prepare parameters for function state transitions */
  8470. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  8471. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  8472. func_params.f_obj = &bp->func_obj;
  8473. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  8474. /* Function parameters */
  8475. __set_bit(BNX2X_F_UPDATE_TUNNEL_CFG_CHNG,
  8476. &switch_update_params->changes);
  8477. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count) {
  8478. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE];
  8479. geneve_port = udp_tunnel->dst_port;
  8480. switch_update_params->geneve_dst_port = geneve_port;
  8481. }
  8482. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count) {
  8483. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN];
  8484. vxlan_port = udp_tunnel->dst_port;
  8485. switch_update_params->vxlan_dst_port = vxlan_port;
  8486. }
  8487. /* Re-enable inner-rss for the offloaded UDP tunnels */
  8488. __set_bit(BNX2X_F_UPDATE_TUNNEL_INNER_RSS,
  8489. &switch_update_params->changes);
  8490. rc = bnx2x_func_state_change(bp, &func_params);
  8491. if (rc)
  8492. BNX2X_ERR("failed to set UDP dst port to %04x %04x (rc = 0x%x)\n",
  8493. vxlan_port, geneve_port, rc);
  8494. else
  8495. DP(BNX2X_MSG_SP,
  8496. "Configured UDP ports: Vxlan [%04x] Geneve [%04x]\n",
  8497. vxlan_port, geneve_port);
  8498. return rc;
  8499. }
  8500. static void __bnx2x_add_udp_port(struct bnx2x *bp, u16 port,
  8501. enum bnx2x_udp_port_type type)
  8502. {
  8503. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8504. if (!netif_running(bp->dev) || !IS_PF(bp) || CHIP_IS_E1x(bp))
  8505. return;
  8506. if (udp_port->count && udp_port->dst_port == port) {
  8507. udp_port->count++;
  8508. return;
  8509. }
  8510. if (udp_port->count) {
  8511. DP(BNX2X_MSG_SP,
  8512. "UDP tunnel [%d] - destination port limit reached\n",
  8513. type);
  8514. return;
  8515. }
  8516. udp_port->dst_port = port;
  8517. udp_port->count = 1;
  8518. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8519. }
  8520. static void __bnx2x_del_udp_port(struct bnx2x *bp, u16 port,
  8521. enum bnx2x_udp_port_type type)
  8522. {
  8523. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8524. if (!IS_PF(bp) || CHIP_IS_E1x(bp))
  8525. return;
  8526. if (!udp_port->count || udp_port->dst_port != port) {
  8527. DP(BNX2X_MSG_SP, "Invalid UDP tunnel [%d] port\n",
  8528. type);
  8529. return;
  8530. }
  8531. /* Remove reference, and make certain it's no longer in use */
  8532. udp_port->count--;
  8533. if (udp_port->count)
  8534. return;
  8535. udp_port->dst_port = 0;
  8536. if (netif_running(bp->dev))
  8537. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8538. else
  8539. DP(BNX2X_MSG_SP, "Deleted UDP tunnel [%d] port %d\n",
  8540. type, port);
  8541. }
  8542. static void bnx2x_udp_tunnel_add(struct net_device *netdev,
  8543. struct udp_tunnel_info *ti)
  8544. {
  8545. struct bnx2x *bp = netdev_priv(netdev);
  8546. u16 t_port = ntohs(ti->port);
  8547. switch (ti->type) {
  8548. case UDP_TUNNEL_TYPE_VXLAN:
  8549. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8550. break;
  8551. case UDP_TUNNEL_TYPE_GENEVE:
  8552. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8553. break;
  8554. default:
  8555. break;
  8556. }
  8557. }
  8558. static void bnx2x_udp_tunnel_del(struct net_device *netdev,
  8559. struct udp_tunnel_info *ti)
  8560. {
  8561. struct bnx2x *bp = netdev_priv(netdev);
  8562. u16 t_port = ntohs(ti->port);
  8563. switch (ti->type) {
  8564. case UDP_TUNNEL_TYPE_VXLAN:
  8565. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8566. break;
  8567. case UDP_TUNNEL_TYPE_GENEVE:
  8568. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8569. break;
  8570. default:
  8571. break;
  8572. }
  8573. }
  8574. static int bnx2x_close(struct net_device *dev);
  8575. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8576. * scheduled on a general queue in order to prevent a dead lock.
  8577. */
  8578. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8579. {
  8580. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8581. rtnl_lock();
  8582. if (!netif_running(bp->dev)) {
  8583. rtnl_unlock();
  8584. return;
  8585. }
  8586. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8587. #ifdef BNX2X_STOP_ON_ERROR
  8588. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8589. "you will need to reboot when done\n");
  8590. goto sp_rtnl_not_reset;
  8591. #endif
  8592. /*
  8593. * Clear all pending SP commands as we are going to reset the
  8594. * function anyway.
  8595. */
  8596. bp->sp_rtnl_state = 0;
  8597. smp_mb();
  8598. bnx2x_parity_recover(bp);
  8599. rtnl_unlock();
  8600. return;
  8601. }
  8602. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8603. #ifdef BNX2X_STOP_ON_ERROR
  8604. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8605. "you will need to reboot when done\n");
  8606. goto sp_rtnl_not_reset;
  8607. #endif
  8608. /*
  8609. * Clear all pending SP commands as we are going to reset the
  8610. * function anyway.
  8611. */
  8612. bp->sp_rtnl_state = 0;
  8613. smp_mb();
  8614. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8615. bnx2x_nic_load(bp, LOAD_NORMAL);
  8616. rtnl_unlock();
  8617. return;
  8618. }
  8619. #ifdef BNX2X_STOP_ON_ERROR
  8620. sp_rtnl_not_reset:
  8621. #endif
  8622. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8623. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8624. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8625. bnx2x_after_function_update(bp);
  8626. /*
  8627. * in case of fan failure we need to reset id if the "stop on error"
  8628. * debug flag is set, since we trying to prevent permanent overheating
  8629. * damage
  8630. */
  8631. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8632. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8633. netif_device_detach(bp->dev);
  8634. bnx2x_close(bp->dev);
  8635. rtnl_unlock();
  8636. return;
  8637. }
  8638. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8639. DP(BNX2X_MSG_SP,
  8640. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8641. bnx2x_vfpf_set_mcast(bp->dev);
  8642. }
  8643. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8644. &bp->sp_rtnl_state)){
  8645. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8646. bnx2x_tx_disable(bp);
  8647. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8648. }
  8649. }
  8650. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8651. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8652. bnx2x_set_rx_mode_inner(bp);
  8653. }
  8654. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8655. &bp->sp_rtnl_state))
  8656. bnx2x_pf_set_vfs_vlan(bp);
  8657. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8658. bnx2x_dcbx_stop_hw_tx(bp);
  8659. bnx2x_dcbx_resume_hw_tx(bp);
  8660. }
  8661. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8662. &bp->sp_rtnl_state))
  8663. bnx2x_update_mng_version(bp);
  8664. if (test_and_clear_bit(BNX2X_SP_RTNL_CHANGE_UDP_PORT,
  8665. &bp->sp_rtnl_state)) {
  8666. if (bnx2x_udp_port_update(bp)) {
  8667. /* On error, forget configuration */
  8668. memset(bp->udp_tunnel_ports, 0,
  8669. sizeof(struct bnx2x_udp_tunnel) *
  8670. BNX2X_UDP_PORT_MAX);
  8671. } else {
  8672. /* Since we don't store additional port information,
  8673. * if no ports are configured for any feature ask for
  8674. * information about currently configured ports.
  8675. */
  8676. if (!bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count &&
  8677. !bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count)
  8678. udp_tunnel_get_rx_info(bp->dev);
  8679. }
  8680. }
  8681. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8682. * can be called from other contexts as well)
  8683. */
  8684. rtnl_unlock();
  8685. /* enable SR-IOV if applicable */
  8686. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8687. &bp->sp_rtnl_state)) {
  8688. bnx2x_disable_sriov(bp);
  8689. bnx2x_enable_sriov(bp);
  8690. }
  8691. }
  8692. static void bnx2x_period_task(struct work_struct *work)
  8693. {
  8694. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8695. if (!netif_running(bp->dev))
  8696. goto period_task_exit;
  8697. if (CHIP_REV_IS_SLOW(bp)) {
  8698. BNX2X_ERR("period task called on emulation, ignoring\n");
  8699. goto period_task_exit;
  8700. }
  8701. bnx2x_acquire_phy_lock(bp);
  8702. /*
  8703. * The barrier is needed to ensure the ordering between the writing to
  8704. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8705. * the reading here.
  8706. */
  8707. smp_mb();
  8708. if (bp->port.pmf) {
  8709. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8710. /* Re-queue task in 1 sec */
  8711. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8712. }
  8713. bnx2x_release_phy_lock(bp);
  8714. period_task_exit:
  8715. return;
  8716. }
  8717. /*
  8718. * Init service functions
  8719. */
  8720. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8721. {
  8722. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8723. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8724. return base + (BP_ABS_FUNC(bp)) * stride;
  8725. }
  8726. static bool bnx2x_prev_unload_close_umac(struct bnx2x *bp,
  8727. u8 port, u32 reset_reg,
  8728. struct bnx2x_mac_vals *vals)
  8729. {
  8730. u32 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8731. u32 base_addr;
  8732. if (!(mask & reset_reg))
  8733. return false;
  8734. BNX2X_DEV_INFO("Disable umac Rx %02x\n", port);
  8735. base_addr = port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8736. vals->umac_addr[port] = base_addr + UMAC_REG_COMMAND_CONFIG;
  8737. vals->umac_val[port] = REG_RD(bp, vals->umac_addr[port]);
  8738. REG_WR(bp, vals->umac_addr[port], 0);
  8739. return true;
  8740. }
  8741. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8742. struct bnx2x_mac_vals *vals)
  8743. {
  8744. u32 val, base_addr, offset, mask, reset_reg;
  8745. bool mac_stopped = false;
  8746. u8 port = BP_PORT(bp);
  8747. /* reset addresses as they also mark which values were changed */
  8748. memset(vals, 0, sizeof(*vals));
  8749. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8750. if (!CHIP_IS_E3(bp)) {
  8751. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8752. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8753. if ((mask & reset_reg) && val) {
  8754. u32 wb_data[2];
  8755. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8756. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8757. : NIG_REG_INGRESS_BMAC0_MEM;
  8758. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8759. : BIGMAC_REGISTER_BMAC_CONTROL;
  8760. /*
  8761. * use rd/wr since we cannot use dmae. This is safe
  8762. * since MCP won't access the bus due to the request
  8763. * to unload, and no function on the path can be
  8764. * loaded at this time.
  8765. */
  8766. wb_data[0] = REG_RD(bp, base_addr + offset);
  8767. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8768. vals->bmac_addr = base_addr + offset;
  8769. vals->bmac_val[0] = wb_data[0];
  8770. vals->bmac_val[1] = wb_data[1];
  8771. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8772. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8773. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8774. }
  8775. BNX2X_DEV_INFO("Disable emac Rx\n");
  8776. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8777. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8778. REG_WR(bp, vals->emac_addr, 0);
  8779. mac_stopped = true;
  8780. } else {
  8781. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8782. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8783. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8784. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8785. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8786. val & ~(1 << 1));
  8787. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8788. val | (1 << 1));
  8789. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8790. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8791. REG_WR(bp, vals->xmac_addr, 0);
  8792. mac_stopped = true;
  8793. }
  8794. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 0,
  8795. reset_reg, vals);
  8796. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 1,
  8797. reset_reg, vals);
  8798. }
  8799. if (mac_stopped)
  8800. msleep(20);
  8801. }
  8802. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8803. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8804. 0x1848 + ((f) << 4))
  8805. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8806. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8807. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8808. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8809. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8810. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8811. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8812. {
  8813. /* UNDI marks its presence in DORQ -
  8814. * it initializes CID offset for normal bell to 0x7
  8815. */
  8816. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8817. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8818. return false;
  8819. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8820. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8821. return true;
  8822. }
  8823. return false;
  8824. }
  8825. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8826. {
  8827. u16 rcq, bd;
  8828. u32 addr, tmp_reg;
  8829. if (BP_FUNC(bp) < 2)
  8830. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8831. else
  8832. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8833. tmp_reg = REG_RD(bp, addr);
  8834. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8835. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8836. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8837. REG_WR(bp, addr, tmp_reg);
  8838. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8839. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8840. }
  8841. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8842. {
  8843. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8844. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8845. if (!rc) {
  8846. BNX2X_ERR("MCP response failure, aborting\n");
  8847. return -EBUSY;
  8848. }
  8849. return 0;
  8850. }
  8851. static struct bnx2x_prev_path_list *
  8852. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8853. {
  8854. struct bnx2x_prev_path_list *tmp_list;
  8855. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8856. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8857. bp->pdev->bus->number == tmp_list->bus &&
  8858. BP_PATH(bp) == tmp_list->path)
  8859. return tmp_list;
  8860. return NULL;
  8861. }
  8862. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8863. {
  8864. struct bnx2x_prev_path_list *tmp_list;
  8865. int rc;
  8866. rc = down_interruptible(&bnx2x_prev_sem);
  8867. if (rc) {
  8868. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8869. return rc;
  8870. }
  8871. tmp_list = bnx2x_prev_path_get_entry(bp);
  8872. if (tmp_list) {
  8873. tmp_list->aer = 1;
  8874. rc = 0;
  8875. } else {
  8876. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8877. BP_PATH(bp));
  8878. }
  8879. up(&bnx2x_prev_sem);
  8880. return rc;
  8881. }
  8882. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8883. {
  8884. struct bnx2x_prev_path_list *tmp_list;
  8885. bool rc = false;
  8886. if (down_trylock(&bnx2x_prev_sem))
  8887. return false;
  8888. tmp_list = bnx2x_prev_path_get_entry(bp);
  8889. if (tmp_list) {
  8890. if (tmp_list->aer) {
  8891. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8892. BP_PATH(bp));
  8893. } else {
  8894. rc = true;
  8895. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8896. BP_PATH(bp));
  8897. }
  8898. }
  8899. up(&bnx2x_prev_sem);
  8900. return rc;
  8901. }
  8902. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8903. {
  8904. struct bnx2x_prev_path_list *entry;
  8905. bool val;
  8906. down(&bnx2x_prev_sem);
  8907. entry = bnx2x_prev_path_get_entry(bp);
  8908. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8909. up(&bnx2x_prev_sem);
  8910. return val;
  8911. }
  8912. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8913. {
  8914. struct bnx2x_prev_path_list *tmp_list;
  8915. int rc;
  8916. rc = down_interruptible(&bnx2x_prev_sem);
  8917. if (rc) {
  8918. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8919. return rc;
  8920. }
  8921. /* Check whether the entry for this path already exists */
  8922. tmp_list = bnx2x_prev_path_get_entry(bp);
  8923. if (tmp_list) {
  8924. if (!tmp_list->aer) {
  8925. BNX2X_ERR("Re-Marking the path.\n");
  8926. } else {
  8927. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8928. BP_PATH(bp));
  8929. tmp_list->aer = 0;
  8930. }
  8931. up(&bnx2x_prev_sem);
  8932. return 0;
  8933. }
  8934. up(&bnx2x_prev_sem);
  8935. /* Create an entry for this path and add it */
  8936. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8937. if (!tmp_list) {
  8938. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8939. return -ENOMEM;
  8940. }
  8941. tmp_list->bus = bp->pdev->bus->number;
  8942. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8943. tmp_list->path = BP_PATH(bp);
  8944. tmp_list->aer = 0;
  8945. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8946. rc = down_interruptible(&bnx2x_prev_sem);
  8947. if (rc) {
  8948. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8949. kfree(tmp_list);
  8950. } else {
  8951. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8952. BP_PATH(bp));
  8953. list_add(&tmp_list->list, &bnx2x_prev_list);
  8954. up(&bnx2x_prev_sem);
  8955. }
  8956. return rc;
  8957. }
  8958. static int bnx2x_do_flr(struct bnx2x *bp)
  8959. {
  8960. struct pci_dev *dev = bp->pdev;
  8961. if (CHIP_IS_E1x(bp)) {
  8962. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8963. return -EINVAL;
  8964. }
  8965. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8966. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8967. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8968. bp->common.bc_ver);
  8969. return -EINVAL;
  8970. }
  8971. if (!pci_wait_for_pending_transaction(dev))
  8972. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8973. BNX2X_DEV_INFO("Initiating FLR\n");
  8974. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8975. return 0;
  8976. }
  8977. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8978. {
  8979. int rc;
  8980. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8981. /* Test if previous unload process was already finished for this path */
  8982. if (bnx2x_prev_is_path_marked(bp))
  8983. return bnx2x_prev_mcp_done(bp);
  8984. BNX2X_DEV_INFO("Path is unmarked\n");
  8985. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8986. if (bnx2x_prev_is_after_undi(bp))
  8987. goto out;
  8988. /* If function has FLR capabilities, and existing FW version matches
  8989. * the one required, then FLR will be sufficient to clean any residue
  8990. * left by previous driver
  8991. */
  8992. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8993. if (!rc) {
  8994. /* fw version is good */
  8995. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8996. rc = bnx2x_do_flr(bp);
  8997. }
  8998. if (!rc) {
  8999. /* FLR was performed */
  9000. BNX2X_DEV_INFO("FLR successful\n");
  9001. return 0;
  9002. }
  9003. BNX2X_DEV_INFO("Could not FLR\n");
  9004. out:
  9005. /* Close the MCP request, return failure*/
  9006. rc = bnx2x_prev_mcp_done(bp);
  9007. if (!rc)
  9008. rc = BNX2X_PREV_WAIT_NEEDED;
  9009. return rc;
  9010. }
  9011. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  9012. {
  9013. u32 reset_reg, tmp_reg = 0, rc;
  9014. bool prev_undi = false;
  9015. struct bnx2x_mac_vals mac_vals;
  9016. /* It is possible a previous function received 'common' answer,
  9017. * but hasn't loaded yet, therefore creating a scenario of
  9018. * multiple functions receiving 'common' on the same path.
  9019. */
  9020. BNX2X_DEV_INFO("Common unload Flow\n");
  9021. memset(&mac_vals, 0, sizeof(mac_vals));
  9022. if (bnx2x_prev_is_path_marked(bp))
  9023. return bnx2x_prev_mcp_done(bp);
  9024. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  9025. /* Reset should be performed after BRB is emptied */
  9026. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  9027. u32 timer_count = 1000;
  9028. /* Close the MAC Rx to prevent BRB from filling up */
  9029. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  9030. /* close LLH filters for both ports towards the BRB */
  9031. bnx2x_set_rx_filter(&bp->link_params, 0);
  9032. bp->link_params.port ^= 1;
  9033. bnx2x_set_rx_filter(&bp->link_params, 0);
  9034. bp->link_params.port ^= 1;
  9035. /* Check if the UNDI driver was previously loaded */
  9036. if (bnx2x_prev_is_after_undi(bp)) {
  9037. prev_undi = true;
  9038. /* clear the UNDI indication */
  9039. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  9040. /* clear possible idle check errors */
  9041. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  9042. }
  9043. if (!CHIP_IS_E1x(bp))
  9044. /* block FW from writing to host */
  9045. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  9046. /* wait until BRB is empty */
  9047. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9048. while (timer_count) {
  9049. u32 prev_brb = tmp_reg;
  9050. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9051. if (!tmp_reg)
  9052. break;
  9053. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  9054. /* reset timer as long as BRB actually gets emptied */
  9055. if (prev_brb > tmp_reg)
  9056. timer_count = 1000;
  9057. else
  9058. timer_count--;
  9059. /* If UNDI resides in memory, manually increment it */
  9060. if (prev_undi)
  9061. bnx2x_prev_unload_undi_inc(bp, 1);
  9062. udelay(10);
  9063. }
  9064. if (!timer_count)
  9065. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  9066. }
  9067. /* No packets are in the pipeline, path is ready for reset */
  9068. bnx2x_reset_common(bp);
  9069. if (mac_vals.xmac_addr)
  9070. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  9071. if (mac_vals.umac_addr[0])
  9072. REG_WR(bp, mac_vals.umac_addr[0], mac_vals.umac_val[0]);
  9073. if (mac_vals.umac_addr[1])
  9074. REG_WR(bp, mac_vals.umac_addr[1], mac_vals.umac_val[1]);
  9075. if (mac_vals.emac_addr)
  9076. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  9077. if (mac_vals.bmac_addr) {
  9078. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  9079. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  9080. }
  9081. rc = bnx2x_prev_mark_path(bp, prev_undi);
  9082. if (rc) {
  9083. bnx2x_prev_mcp_done(bp);
  9084. return rc;
  9085. }
  9086. return bnx2x_prev_mcp_done(bp);
  9087. }
  9088. static int bnx2x_prev_unload(struct bnx2x *bp)
  9089. {
  9090. int time_counter = 10;
  9091. u32 rc, fw, hw_lock_reg, hw_lock_val;
  9092. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  9093. /* clear hw from errors which may have resulted from an interrupted
  9094. * dmae transaction.
  9095. */
  9096. bnx2x_clean_pglue_errors(bp);
  9097. /* Release previously held locks */
  9098. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  9099. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  9100. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  9101. hw_lock_val = REG_RD(bp, hw_lock_reg);
  9102. if (hw_lock_val) {
  9103. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  9104. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  9105. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  9106. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  9107. }
  9108. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  9109. REG_WR(bp, hw_lock_reg, 0xffffffff);
  9110. } else
  9111. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  9112. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  9113. BNX2X_DEV_INFO("Release previously held alr\n");
  9114. bnx2x_release_alr(bp);
  9115. }
  9116. do {
  9117. int aer = 0;
  9118. /* Lock MCP using an unload request */
  9119. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  9120. if (!fw) {
  9121. BNX2X_ERR("MCP response failure, aborting\n");
  9122. rc = -EBUSY;
  9123. break;
  9124. }
  9125. rc = down_interruptible(&bnx2x_prev_sem);
  9126. if (rc) {
  9127. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  9128. rc);
  9129. } else {
  9130. /* If Path is marked by EEH, ignore unload status */
  9131. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  9132. bnx2x_prev_path_get_entry(bp)->aer);
  9133. up(&bnx2x_prev_sem);
  9134. }
  9135. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  9136. rc = bnx2x_prev_unload_common(bp);
  9137. break;
  9138. }
  9139. /* non-common reply from MCP might require looping */
  9140. rc = bnx2x_prev_unload_uncommon(bp);
  9141. if (rc != BNX2X_PREV_WAIT_NEEDED)
  9142. break;
  9143. msleep(20);
  9144. } while (--time_counter);
  9145. if (!time_counter || rc) {
  9146. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  9147. rc = -EPROBE_DEFER;
  9148. }
  9149. /* Mark function if its port was used to boot from SAN */
  9150. if (bnx2x_port_after_undi(bp))
  9151. bp->link_params.feature_config_flags |=
  9152. FEATURE_CONFIG_BOOT_FROM_SAN;
  9153. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  9154. return rc;
  9155. }
  9156. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  9157. {
  9158. u32 val, val2, val3, val4, id, boot_mode;
  9159. u16 pmc;
  9160. /* Get the chip revision id and number. */
  9161. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  9162. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  9163. id = ((val & 0xffff) << 16);
  9164. val = REG_RD(bp, MISC_REG_CHIP_REV);
  9165. id |= ((val & 0xf) << 12);
  9166. /* Metal is read from PCI regs, but we can't access >=0x400 from
  9167. * the configuration space (so we need to reg_rd)
  9168. */
  9169. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  9170. id |= (((val >> 24) & 0xf) << 4);
  9171. val = REG_RD(bp, MISC_REG_BOND_ID);
  9172. id |= (val & 0xf);
  9173. bp->common.chip_id = id;
  9174. /* force 57811 according to MISC register */
  9175. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  9176. if (CHIP_IS_57810(bp))
  9177. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  9178. (bp->common.chip_id & 0x0000FFFF);
  9179. else if (CHIP_IS_57810_MF(bp))
  9180. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  9181. (bp->common.chip_id & 0x0000FFFF);
  9182. bp->common.chip_id |= 0x1;
  9183. }
  9184. /* Set doorbell size */
  9185. bp->db_size = (1 << BNX2X_DB_SHIFT);
  9186. if (!CHIP_IS_E1x(bp)) {
  9187. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  9188. if ((val & 1) == 0)
  9189. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  9190. else
  9191. val = (val >> 1) & 1;
  9192. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  9193. "2_PORT_MODE");
  9194. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  9195. CHIP_2_PORT_MODE;
  9196. if (CHIP_MODE_IS_4_PORT(bp))
  9197. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  9198. else
  9199. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  9200. } else {
  9201. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  9202. bp->pfid = bp->pf_num; /* 0..7 */
  9203. }
  9204. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  9205. bp->link_params.chip_id = bp->common.chip_id;
  9206. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  9207. val = (REG_RD(bp, 0x2874) & 0x55);
  9208. if ((bp->common.chip_id & 0x1) ||
  9209. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  9210. bp->flags |= ONE_PORT_FLAG;
  9211. BNX2X_DEV_INFO("single port device\n");
  9212. }
  9213. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9214. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9215. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9216. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9217. bp->common.flash_size, bp->common.flash_size);
  9218. bnx2x_init_shmem(bp);
  9219. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9220. MISC_REG_GENERIC_CR_1 :
  9221. MISC_REG_GENERIC_CR_0));
  9222. bp->link_params.shmem_base = bp->common.shmem_base;
  9223. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9224. if (SHMEM2_RD(bp, size) >
  9225. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9226. bp->link_params.lfa_base =
  9227. REG_RD(bp, bp->common.shmem2_base +
  9228. (u32)offsetof(struct shmem2_region,
  9229. lfa_host_addr[BP_PORT(bp)]));
  9230. else
  9231. bp->link_params.lfa_base = 0;
  9232. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9233. bp->common.shmem_base, bp->common.shmem2_base);
  9234. if (!bp->common.shmem_base) {
  9235. BNX2X_DEV_INFO("MCP not active\n");
  9236. bp->flags |= NO_MCP_FLAG;
  9237. return;
  9238. }
  9239. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9240. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9241. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9242. SHARED_HW_CFG_LED_MODE_MASK) >>
  9243. SHARED_HW_CFG_LED_MODE_SHIFT);
  9244. bp->link_params.feature_config_flags = 0;
  9245. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9246. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9247. bp->link_params.feature_config_flags |=
  9248. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9249. else
  9250. bp->link_params.feature_config_flags &=
  9251. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9252. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9253. bp->common.bc_ver = val;
  9254. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9255. if (val < BNX2X_BC_VER) {
  9256. /* for now only warn
  9257. * later we might need to enforce this */
  9258. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9259. BNX2X_BC_VER, val);
  9260. }
  9261. bp->link_params.feature_config_flags |=
  9262. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9263. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9264. bp->link_params.feature_config_flags |=
  9265. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9266. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9267. bp->link_params.feature_config_flags |=
  9268. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9269. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9270. bp->link_params.feature_config_flags |=
  9271. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9272. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9273. bp->link_params.feature_config_flags |=
  9274. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9275. FEATURE_CONFIG_MT_SUPPORT : 0;
  9276. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9277. BC_SUPPORTS_PFC_STATS : 0;
  9278. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9279. BC_SUPPORTS_FCOE_FEATURES : 0;
  9280. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9281. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9282. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9283. BC_SUPPORTS_RMMOD_CMD : 0;
  9284. boot_mode = SHMEM_RD(bp,
  9285. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9286. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9287. switch (boot_mode) {
  9288. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9289. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9290. break;
  9291. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9292. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9293. break;
  9294. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9295. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9296. break;
  9297. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9298. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9299. break;
  9300. }
  9301. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9302. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9303. BNX2X_DEV_INFO("%sWoL capable\n",
  9304. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9305. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9306. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9307. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9308. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9309. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9310. val, val2, val3, val4);
  9311. }
  9312. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9313. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9314. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9315. {
  9316. int pfid = BP_FUNC(bp);
  9317. int igu_sb_id;
  9318. u32 val;
  9319. u8 fid, igu_sb_cnt = 0;
  9320. bp->igu_base_sb = 0xff;
  9321. if (CHIP_INT_MODE_IS_BC(bp)) {
  9322. int vn = BP_VN(bp);
  9323. igu_sb_cnt = bp->igu_sb_cnt;
  9324. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9325. FP_SB_MAX_E1x;
  9326. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9327. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9328. return 0;
  9329. }
  9330. /* IGU in normal mode - read CAM */
  9331. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9332. igu_sb_id++) {
  9333. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9334. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9335. continue;
  9336. fid = IGU_FID(val);
  9337. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9338. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9339. continue;
  9340. if (IGU_VEC(val) == 0)
  9341. /* default status block */
  9342. bp->igu_dsb_id = igu_sb_id;
  9343. else {
  9344. if (bp->igu_base_sb == 0xff)
  9345. bp->igu_base_sb = igu_sb_id;
  9346. igu_sb_cnt++;
  9347. }
  9348. }
  9349. }
  9350. #ifdef CONFIG_PCI_MSI
  9351. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9352. * optional that number of CAM entries will not be equal to the value
  9353. * advertised in PCI.
  9354. * Driver should use the minimal value of both as the actual status
  9355. * block count
  9356. */
  9357. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9358. #endif
  9359. if (igu_sb_cnt == 0) {
  9360. BNX2X_ERR("CAM configuration error\n");
  9361. return -EINVAL;
  9362. }
  9363. return 0;
  9364. }
  9365. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9366. {
  9367. int cfg_size = 0, idx, port = BP_PORT(bp);
  9368. /* Aggregation of supported attributes of all external phys */
  9369. bp->port.supported[0] = 0;
  9370. bp->port.supported[1] = 0;
  9371. switch (bp->link_params.num_phys) {
  9372. case 1:
  9373. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9374. cfg_size = 1;
  9375. break;
  9376. case 2:
  9377. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9378. cfg_size = 1;
  9379. break;
  9380. case 3:
  9381. if (bp->link_params.multi_phy_config &
  9382. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9383. bp->port.supported[1] =
  9384. bp->link_params.phy[EXT_PHY1].supported;
  9385. bp->port.supported[0] =
  9386. bp->link_params.phy[EXT_PHY2].supported;
  9387. } else {
  9388. bp->port.supported[0] =
  9389. bp->link_params.phy[EXT_PHY1].supported;
  9390. bp->port.supported[1] =
  9391. bp->link_params.phy[EXT_PHY2].supported;
  9392. }
  9393. cfg_size = 2;
  9394. break;
  9395. }
  9396. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9397. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9398. SHMEM_RD(bp,
  9399. dev_info.port_hw_config[port].external_phy_config),
  9400. SHMEM_RD(bp,
  9401. dev_info.port_hw_config[port].external_phy_config2));
  9402. return;
  9403. }
  9404. if (CHIP_IS_E3(bp))
  9405. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9406. else {
  9407. switch (switch_cfg) {
  9408. case SWITCH_CFG_1G:
  9409. bp->port.phy_addr = REG_RD(
  9410. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9411. break;
  9412. case SWITCH_CFG_10G:
  9413. bp->port.phy_addr = REG_RD(
  9414. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9415. break;
  9416. default:
  9417. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9418. bp->port.link_config[0]);
  9419. return;
  9420. }
  9421. }
  9422. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9423. /* mask what we support according to speed_cap_mask per configuration */
  9424. for (idx = 0; idx < cfg_size; idx++) {
  9425. if (!(bp->link_params.speed_cap_mask[idx] &
  9426. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9427. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9428. if (!(bp->link_params.speed_cap_mask[idx] &
  9429. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9430. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9431. if (!(bp->link_params.speed_cap_mask[idx] &
  9432. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9433. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9434. if (!(bp->link_params.speed_cap_mask[idx] &
  9435. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9436. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9437. if (!(bp->link_params.speed_cap_mask[idx] &
  9438. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9439. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9440. SUPPORTED_1000baseT_Full);
  9441. if (!(bp->link_params.speed_cap_mask[idx] &
  9442. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9443. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9444. if (!(bp->link_params.speed_cap_mask[idx] &
  9445. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9446. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9447. if (!(bp->link_params.speed_cap_mask[idx] &
  9448. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9449. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9450. }
  9451. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9452. bp->port.supported[1]);
  9453. }
  9454. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9455. {
  9456. u32 link_config, idx, cfg_size = 0;
  9457. bp->port.advertising[0] = 0;
  9458. bp->port.advertising[1] = 0;
  9459. switch (bp->link_params.num_phys) {
  9460. case 1:
  9461. case 2:
  9462. cfg_size = 1;
  9463. break;
  9464. case 3:
  9465. cfg_size = 2;
  9466. break;
  9467. }
  9468. for (idx = 0; idx < cfg_size; idx++) {
  9469. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9470. link_config = bp->port.link_config[idx];
  9471. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9472. case PORT_FEATURE_LINK_SPEED_AUTO:
  9473. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9474. bp->link_params.req_line_speed[idx] =
  9475. SPEED_AUTO_NEG;
  9476. bp->port.advertising[idx] |=
  9477. bp->port.supported[idx];
  9478. if (bp->link_params.phy[EXT_PHY1].type ==
  9479. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9480. bp->port.advertising[idx] |=
  9481. (SUPPORTED_100baseT_Half |
  9482. SUPPORTED_100baseT_Full);
  9483. } else {
  9484. /* force 10G, no AN */
  9485. bp->link_params.req_line_speed[idx] =
  9486. SPEED_10000;
  9487. bp->port.advertising[idx] |=
  9488. (ADVERTISED_10000baseT_Full |
  9489. ADVERTISED_FIBRE);
  9490. continue;
  9491. }
  9492. break;
  9493. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9494. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9495. bp->link_params.req_line_speed[idx] =
  9496. SPEED_10;
  9497. bp->port.advertising[idx] |=
  9498. (ADVERTISED_10baseT_Full |
  9499. ADVERTISED_TP);
  9500. } else {
  9501. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9502. link_config,
  9503. bp->link_params.speed_cap_mask[idx]);
  9504. return;
  9505. }
  9506. break;
  9507. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9508. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9509. bp->link_params.req_line_speed[idx] =
  9510. SPEED_10;
  9511. bp->link_params.req_duplex[idx] =
  9512. DUPLEX_HALF;
  9513. bp->port.advertising[idx] |=
  9514. (ADVERTISED_10baseT_Half |
  9515. ADVERTISED_TP);
  9516. } else {
  9517. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9518. link_config,
  9519. bp->link_params.speed_cap_mask[idx]);
  9520. return;
  9521. }
  9522. break;
  9523. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9524. if (bp->port.supported[idx] &
  9525. SUPPORTED_100baseT_Full) {
  9526. bp->link_params.req_line_speed[idx] =
  9527. SPEED_100;
  9528. bp->port.advertising[idx] |=
  9529. (ADVERTISED_100baseT_Full |
  9530. ADVERTISED_TP);
  9531. } else {
  9532. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9533. link_config,
  9534. bp->link_params.speed_cap_mask[idx]);
  9535. return;
  9536. }
  9537. break;
  9538. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9539. if (bp->port.supported[idx] &
  9540. SUPPORTED_100baseT_Half) {
  9541. bp->link_params.req_line_speed[idx] =
  9542. SPEED_100;
  9543. bp->link_params.req_duplex[idx] =
  9544. DUPLEX_HALF;
  9545. bp->port.advertising[idx] |=
  9546. (ADVERTISED_100baseT_Half |
  9547. ADVERTISED_TP);
  9548. } else {
  9549. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9550. link_config,
  9551. bp->link_params.speed_cap_mask[idx]);
  9552. return;
  9553. }
  9554. break;
  9555. case PORT_FEATURE_LINK_SPEED_1G:
  9556. if (bp->port.supported[idx] &
  9557. SUPPORTED_1000baseT_Full) {
  9558. bp->link_params.req_line_speed[idx] =
  9559. SPEED_1000;
  9560. bp->port.advertising[idx] |=
  9561. (ADVERTISED_1000baseT_Full |
  9562. ADVERTISED_TP);
  9563. } else if (bp->port.supported[idx] &
  9564. SUPPORTED_1000baseKX_Full) {
  9565. bp->link_params.req_line_speed[idx] =
  9566. SPEED_1000;
  9567. bp->port.advertising[idx] |=
  9568. ADVERTISED_1000baseKX_Full;
  9569. } else {
  9570. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9571. link_config,
  9572. bp->link_params.speed_cap_mask[idx]);
  9573. return;
  9574. }
  9575. break;
  9576. case PORT_FEATURE_LINK_SPEED_2_5G:
  9577. if (bp->port.supported[idx] &
  9578. SUPPORTED_2500baseX_Full) {
  9579. bp->link_params.req_line_speed[idx] =
  9580. SPEED_2500;
  9581. bp->port.advertising[idx] |=
  9582. (ADVERTISED_2500baseX_Full |
  9583. ADVERTISED_TP);
  9584. } else {
  9585. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9586. link_config,
  9587. bp->link_params.speed_cap_mask[idx]);
  9588. return;
  9589. }
  9590. break;
  9591. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9592. if (bp->port.supported[idx] &
  9593. SUPPORTED_10000baseT_Full) {
  9594. bp->link_params.req_line_speed[idx] =
  9595. SPEED_10000;
  9596. bp->port.advertising[idx] |=
  9597. (ADVERTISED_10000baseT_Full |
  9598. ADVERTISED_FIBRE);
  9599. } else if (bp->port.supported[idx] &
  9600. SUPPORTED_10000baseKR_Full) {
  9601. bp->link_params.req_line_speed[idx] =
  9602. SPEED_10000;
  9603. bp->port.advertising[idx] |=
  9604. (ADVERTISED_10000baseKR_Full |
  9605. ADVERTISED_FIBRE);
  9606. } else {
  9607. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9608. link_config,
  9609. bp->link_params.speed_cap_mask[idx]);
  9610. return;
  9611. }
  9612. break;
  9613. case PORT_FEATURE_LINK_SPEED_20G:
  9614. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9615. break;
  9616. default:
  9617. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9618. link_config);
  9619. bp->link_params.req_line_speed[idx] =
  9620. SPEED_AUTO_NEG;
  9621. bp->port.advertising[idx] =
  9622. bp->port.supported[idx];
  9623. break;
  9624. }
  9625. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9626. PORT_FEATURE_FLOW_CONTROL_MASK);
  9627. if (bp->link_params.req_flow_ctrl[idx] ==
  9628. BNX2X_FLOW_CTRL_AUTO) {
  9629. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9630. bp->link_params.req_flow_ctrl[idx] =
  9631. BNX2X_FLOW_CTRL_NONE;
  9632. else
  9633. bnx2x_set_requested_fc(bp);
  9634. }
  9635. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9636. bp->link_params.req_line_speed[idx],
  9637. bp->link_params.req_duplex[idx],
  9638. bp->link_params.req_flow_ctrl[idx],
  9639. bp->port.advertising[idx]);
  9640. }
  9641. }
  9642. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9643. {
  9644. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9645. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9646. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9647. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9648. }
  9649. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9650. {
  9651. int port = BP_PORT(bp);
  9652. u32 config;
  9653. u32 ext_phy_type, ext_phy_config, eee_mode;
  9654. bp->link_params.bp = bp;
  9655. bp->link_params.port = port;
  9656. bp->link_params.lane_config =
  9657. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9658. bp->link_params.speed_cap_mask[0] =
  9659. SHMEM_RD(bp,
  9660. dev_info.port_hw_config[port].speed_capability_mask) &
  9661. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9662. bp->link_params.speed_cap_mask[1] =
  9663. SHMEM_RD(bp,
  9664. dev_info.port_hw_config[port].speed_capability_mask2) &
  9665. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9666. bp->port.link_config[0] =
  9667. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9668. bp->port.link_config[1] =
  9669. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9670. bp->link_params.multi_phy_config =
  9671. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9672. /* If the device is capable of WoL, set the default state according
  9673. * to the HW
  9674. */
  9675. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9676. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9677. (config & PORT_FEATURE_WOL_ENABLED));
  9678. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9679. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9680. bp->flags |= NO_ISCSI_FLAG;
  9681. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9682. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9683. bp->flags |= NO_FCOE_FLAG;
  9684. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9685. bp->link_params.lane_config,
  9686. bp->link_params.speed_cap_mask[0],
  9687. bp->port.link_config[0]);
  9688. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9689. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9690. bnx2x_phy_probe(&bp->link_params);
  9691. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9692. bnx2x_link_settings_requested(bp);
  9693. /*
  9694. * If connected directly, work with the internal PHY, otherwise, work
  9695. * with the external PHY
  9696. */
  9697. ext_phy_config =
  9698. SHMEM_RD(bp,
  9699. dev_info.port_hw_config[port].external_phy_config);
  9700. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9701. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9702. bp->mdio.prtad = bp->port.phy_addr;
  9703. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9704. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9705. bp->mdio.prtad =
  9706. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9707. /* Configure link feature according to nvram value */
  9708. eee_mode = (((SHMEM_RD(bp, dev_info.
  9709. port_feature_config[port].eee_power_mode)) &
  9710. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9711. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9712. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9713. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9714. EEE_MODE_ENABLE_LPI |
  9715. EEE_MODE_OUTPUT_TIME;
  9716. } else {
  9717. bp->link_params.eee_mode = 0;
  9718. }
  9719. }
  9720. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9721. {
  9722. u32 no_flags = NO_ISCSI_FLAG;
  9723. int port = BP_PORT(bp);
  9724. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9725. drv_lic_key[port].max_iscsi_conn);
  9726. if (!CNIC_SUPPORT(bp)) {
  9727. bp->flags |= no_flags;
  9728. return;
  9729. }
  9730. /* Get the number of maximum allowed iSCSI connections */
  9731. bp->cnic_eth_dev.max_iscsi_conn =
  9732. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9733. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9734. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9735. bp->cnic_eth_dev.max_iscsi_conn);
  9736. /*
  9737. * If maximum allowed number of connections is zero -
  9738. * disable the feature.
  9739. */
  9740. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9741. bp->flags |= no_flags;
  9742. }
  9743. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9744. {
  9745. /* Port info */
  9746. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9747. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9748. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9749. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9750. /* Node info */
  9751. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9752. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9753. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9754. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9755. }
  9756. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9757. {
  9758. u8 count = 0;
  9759. if (IS_MF(bp)) {
  9760. u8 fid;
  9761. /* iterate over absolute function ids for this path: */
  9762. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9763. if (IS_MF_SD(bp)) {
  9764. u32 cfg = MF_CFG_RD(bp,
  9765. func_mf_config[fid].config);
  9766. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9767. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9768. FUNC_MF_CFG_PROTOCOL_FCOE))
  9769. count++;
  9770. } else {
  9771. u32 cfg = MF_CFG_RD(bp,
  9772. func_ext_config[fid].
  9773. func_cfg);
  9774. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9775. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9776. count++;
  9777. }
  9778. }
  9779. } else { /* SF */
  9780. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9781. for (port = 0; port < port_cnt; port++) {
  9782. u32 lic = SHMEM_RD(bp,
  9783. drv_lic_key[port].max_fcoe_conn) ^
  9784. FW_ENCODE_32BIT_PATTERN;
  9785. if (lic)
  9786. count++;
  9787. }
  9788. }
  9789. return count;
  9790. }
  9791. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9792. {
  9793. int port = BP_PORT(bp);
  9794. int func = BP_ABS_FUNC(bp);
  9795. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9796. drv_lic_key[port].max_fcoe_conn);
  9797. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9798. if (!CNIC_SUPPORT(bp)) {
  9799. bp->flags |= NO_FCOE_FLAG;
  9800. return;
  9801. }
  9802. /* Get the number of maximum allowed FCoE connections */
  9803. bp->cnic_eth_dev.max_fcoe_conn =
  9804. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9805. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9806. /* Calculate the number of maximum allowed FCoE tasks */
  9807. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9808. /* check if FCoE resources must be shared between different functions */
  9809. if (num_fcoe_func)
  9810. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9811. /* Read the WWN: */
  9812. if (!IS_MF(bp)) {
  9813. /* Port info */
  9814. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9815. SHMEM_RD(bp,
  9816. dev_info.port_hw_config[port].
  9817. fcoe_wwn_port_name_upper);
  9818. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9819. SHMEM_RD(bp,
  9820. dev_info.port_hw_config[port].
  9821. fcoe_wwn_port_name_lower);
  9822. /* Node info */
  9823. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9824. SHMEM_RD(bp,
  9825. dev_info.port_hw_config[port].
  9826. fcoe_wwn_node_name_upper);
  9827. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9828. SHMEM_RD(bp,
  9829. dev_info.port_hw_config[port].
  9830. fcoe_wwn_node_name_lower);
  9831. } else if (!IS_MF_SD(bp)) {
  9832. /* Read the WWN info only if the FCoE feature is enabled for
  9833. * this function.
  9834. */
  9835. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9836. bnx2x_get_ext_wwn_info(bp, func);
  9837. } else {
  9838. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9839. bnx2x_get_ext_wwn_info(bp, func);
  9840. }
  9841. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9842. /*
  9843. * If maximum allowed number of connections is zero -
  9844. * disable the feature.
  9845. */
  9846. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9847. bp->flags |= NO_FCOE_FLAG;
  9848. }
  9849. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9850. {
  9851. /*
  9852. * iSCSI may be dynamically disabled but reading
  9853. * info here we will decrease memory usage by driver
  9854. * if the feature is disabled for good
  9855. */
  9856. bnx2x_get_iscsi_info(bp);
  9857. bnx2x_get_fcoe_info(bp);
  9858. }
  9859. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9860. {
  9861. u32 val, val2;
  9862. int func = BP_ABS_FUNC(bp);
  9863. int port = BP_PORT(bp);
  9864. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9865. u8 *fip_mac = bp->fip_mac;
  9866. if (IS_MF(bp)) {
  9867. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9868. * FCoE MAC then the appropriate feature should be disabled.
  9869. * In non SD mode features configuration comes from struct
  9870. * func_ext_config.
  9871. */
  9872. if (!IS_MF_SD(bp)) {
  9873. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9874. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9875. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9876. iscsi_mac_addr_upper);
  9877. val = MF_CFG_RD(bp, func_ext_config[func].
  9878. iscsi_mac_addr_lower);
  9879. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9880. BNX2X_DEV_INFO
  9881. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9882. } else {
  9883. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9884. }
  9885. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9886. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9887. fcoe_mac_addr_upper);
  9888. val = MF_CFG_RD(bp, func_ext_config[func].
  9889. fcoe_mac_addr_lower);
  9890. bnx2x_set_mac_buf(fip_mac, val, val2);
  9891. BNX2X_DEV_INFO
  9892. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9893. } else {
  9894. bp->flags |= NO_FCOE_FLAG;
  9895. }
  9896. bp->mf_ext_config = cfg;
  9897. } else { /* SD MODE */
  9898. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9899. /* use primary mac as iscsi mac */
  9900. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9901. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9902. BNX2X_DEV_INFO
  9903. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9904. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9905. /* use primary mac as fip mac */
  9906. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9907. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9908. BNX2X_DEV_INFO
  9909. ("Read FIP MAC: %pM\n", fip_mac);
  9910. }
  9911. }
  9912. /* If this is a storage-only interface, use SAN mac as
  9913. * primary MAC. Notice that for SD this is already the case,
  9914. * as the SAN mac was copied from the primary MAC.
  9915. */
  9916. if (IS_MF_FCOE_AFEX(bp))
  9917. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9918. } else {
  9919. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9920. iscsi_mac_upper);
  9921. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9922. iscsi_mac_lower);
  9923. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9924. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9925. fcoe_fip_mac_upper);
  9926. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9927. fcoe_fip_mac_lower);
  9928. bnx2x_set_mac_buf(fip_mac, val, val2);
  9929. }
  9930. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9931. if (!is_valid_ether_addr(iscsi_mac)) {
  9932. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9933. eth_zero_addr(iscsi_mac);
  9934. }
  9935. /* Disable FCoE if MAC configuration is invalid. */
  9936. if (!is_valid_ether_addr(fip_mac)) {
  9937. bp->flags |= NO_FCOE_FLAG;
  9938. eth_zero_addr(bp->fip_mac);
  9939. }
  9940. }
  9941. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9942. {
  9943. u32 val, val2;
  9944. int func = BP_ABS_FUNC(bp);
  9945. int port = BP_PORT(bp);
  9946. /* Zero primary MAC configuration */
  9947. eth_zero_addr(bp->dev->dev_addr);
  9948. if (BP_NOMCP(bp)) {
  9949. BNX2X_ERROR("warning: random MAC workaround active\n");
  9950. eth_hw_addr_random(bp->dev);
  9951. } else if (IS_MF(bp)) {
  9952. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9953. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9954. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9955. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9956. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9957. if (CNIC_SUPPORT(bp))
  9958. bnx2x_get_cnic_mac_hwinfo(bp);
  9959. } else {
  9960. /* in SF read MACs from port configuration */
  9961. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9962. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9963. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9964. if (CNIC_SUPPORT(bp))
  9965. bnx2x_get_cnic_mac_hwinfo(bp);
  9966. }
  9967. if (!BP_NOMCP(bp)) {
  9968. /* Read physical port identifier from shmem */
  9969. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9970. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9971. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9972. bp->flags |= HAS_PHYS_PORT_ID;
  9973. }
  9974. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9975. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9976. dev_err(&bp->pdev->dev,
  9977. "bad Ethernet MAC address configuration: %pM\n"
  9978. "change it manually before bringing up the appropriate network interface\n",
  9979. bp->dev->dev_addr);
  9980. }
  9981. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9982. {
  9983. int tmp;
  9984. u32 cfg;
  9985. if (IS_VF(bp))
  9986. return false;
  9987. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9988. /* Take function: tmp = func */
  9989. tmp = BP_ABS_FUNC(bp);
  9990. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9991. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9992. } else {
  9993. /* Take port: tmp = port */
  9994. tmp = BP_PORT(bp);
  9995. cfg = SHMEM_RD(bp,
  9996. dev_info.port_hw_config[tmp].generic_features);
  9997. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9998. }
  9999. return cfg;
  10000. }
  10001. static void validate_set_si_mode(struct bnx2x *bp)
  10002. {
  10003. u8 func = BP_ABS_FUNC(bp);
  10004. u32 val;
  10005. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  10006. /* check for legal mac (upper bytes) */
  10007. if (val != 0xffff) {
  10008. bp->mf_mode = MULTI_FUNCTION_SI;
  10009. bp->mf_config[BP_VN(bp)] =
  10010. MF_CFG_RD(bp, func_mf_config[func].config);
  10011. } else
  10012. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  10013. }
  10014. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  10015. {
  10016. int /*abs*/func = BP_ABS_FUNC(bp);
  10017. int vn, mfw_vn;
  10018. u32 val = 0, val2 = 0;
  10019. int rc = 0;
  10020. /* Validate that chip access is feasible */
  10021. if (REG_RD(bp, MISC_REG_CHIP_NUM) == 0xffffffff) {
  10022. dev_err(&bp->pdev->dev,
  10023. "Chip read returns all Fs. Preventing probe from continuing\n");
  10024. return -EINVAL;
  10025. }
  10026. bnx2x_get_common_hwinfo(bp);
  10027. /*
  10028. * initialize IGU parameters
  10029. */
  10030. if (CHIP_IS_E1x(bp)) {
  10031. bp->common.int_block = INT_BLOCK_HC;
  10032. bp->igu_dsb_id = DEF_SB_IGU_ID;
  10033. bp->igu_base_sb = 0;
  10034. } else {
  10035. bp->common.int_block = INT_BLOCK_IGU;
  10036. /* do not allow device reset during IGU info processing */
  10037. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10038. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  10039. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10040. int tout = 5000;
  10041. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  10042. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  10043. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  10044. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  10045. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10046. tout--;
  10047. usleep_range(1000, 2000);
  10048. }
  10049. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10050. dev_err(&bp->pdev->dev,
  10051. "FORCING Normal Mode failed!!!\n");
  10052. bnx2x_release_hw_lock(bp,
  10053. HW_LOCK_RESOURCE_RESET);
  10054. return -EPERM;
  10055. }
  10056. }
  10057. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10058. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  10059. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  10060. } else
  10061. BNX2X_DEV_INFO("IGU Normal Mode\n");
  10062. rc = bnx2x_get_igu_cam_info(bp);
  10063. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10064. if (rc)
  10065. return rc;
  10066. }
  10067. /*
  10068. * set base FW non-default (fast path) status block id, this value is
  10069. * used to initialize the fw_sb_id saved on the fp/queue structure to
  10070. * determine the id used by the FW.
  10071. */
  10072. if (CHIP_IS_E1x(bp))
  10073. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  10074. else /*
  10075. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  10076. * the same queue are indicated on the same IGU SB). So we prefer
  10077. * FW and IGU SBs to be the same value.
  10078. */
  10079. bp->base_fw_ndsb = bp->igu_base_sb;
  10080. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  10081. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  10082. bp->igu_sb_cnt, bp->base_fw_ndsb);
  10083. /*
  10084. * Initialize MF configuration
  10085. */
  10086. bp->mf_ov = 0;
  10087. bp->mf_mode = 0;
  10088. bp->mf_sub_mode = 0;
  10089. vn = BP_VN(bp);
  10090. mfw_vn = BP_FW_MB_IDX(bp);
  10091. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  10092. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  10093. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  10094. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  10095. if (SHMEM2_HAS(bp, mf_cfg_addr))
  10096. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  10097. else
  10098. bp->common.mf_cfg_base = bp->common.shmem_base +
  10099. offsetof(struct shmem_region, func_mb) +
  10100. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  10101. /*
  10102. * get mf configuration:
  10103. * 1. Existence of MF configuration
  10104. * 2. MAC address must be legal (check only upper bytes)
  10105. * for Switch-Independent mode;
  10106. * OVLAN must be legal for Switch-Dependent mode
  10107. * 3. SF_MODE configures specific MF mode
  10108. */
  10109. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10110. /* get mf configuration */
  10111. val = SHMEM_RD(bp,
  10112. dev_info.shared_feature_config.config);
  10113. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  10114. switch (val) {
  10115. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  10116. validate_set_si_mode(bp);
  10117. break;
  10118. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  10119. if ((!CHIP_IS_E1x(bp)) &&
  10120. (MF_CFG_RD(bp, func_mf_config[func].
  10121. mac_upper) != 0xffff) &&
  10122. (SHMEM2_HAS(bp,
  10123. afex_driver_support))) {
  10124. bp->mf_mode = MULTI_FUNCTION_AFEX;
  10125. bp->mf_config[vn] = MF_CFG_RD(bp,
  10126. func_mf_config[func].config);
  10127. } else {
  10128. BNX2X_DEV_INFO("can not configure afex mode\n");
  10129. }
  10130. break;
  10131. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  10132. /* get OV configuration */
  10133. val = MF_CFG_RD(bp,
  10134. func_mf_config[FUNC_0].e1hov_tag);
  10135. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  10136. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10137. bp->mf_mode = MULTI_FUNCTION_SD;
  10138. bp->mf_config[vn] = MF_CFG_RD(bp,
  10139. func_mf_config[func].config);
  10140. } else
  10141. BNX2X_DEV_INFO("illegal OV for SD\n");
  10142. break;
  10143. case SHARED_FEAT_CFG_FORCE_SF_MODE_BD_MODE:
  10144. bp->mf_mode = MULTI_FUNCTION_SD;
  10145. bp->mf_sub_mode = SUB_MF_MODE_BD;
  10146. bp->mf_config[vn] =
  10147. MF_CFG_RD(bp,
  10148. func_mf_config[func].config);
  10149. if (SHMEM2_HAS(bp, mtu_size)) {
  10150. int mtu_idx = BP_FW_MB_IDX(bp);
  10151. u16 mtu_size;
  10152. u32 mtu;
  10153. mtu = SHMEM2_RD(bp, mtu_size[mtu_idx]);
  10154. mtu_size = (u16)mtu;
  10155. DP(NETIF_MSG_IFUP, "Read MTU size %04x [%08x]\n",
  10156. mtu_size, mtu);
  10157. /* if valid: update device mtu */
  10158. if (((mtu_size + ETH_HLEN) >=
  10159. ETH_MIN_PACKET_SIZE) &&
  10160. (mtu_size <=
  10161. ETH_MAX_JUMBO_PACKET_SIZE))
  10162. bp->dev->mtu = mtu_size;
  10163. }
  10164. break;
  10165. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  10166. bp->mf_mode = MULTI_FUNCTION_SD;
  10167. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  10168. bp->mf_config[vn] =
  10169. MF_CFG_RD(bp,
  10170. func_mf_config[func].config);
  10171. break;
  10172. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  10173. bp->mf_config[vn] = 0;
  10174. break;
  10175. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  10176. val2 = SHMEM_RD(bp,
  10177. dev_info.shared_hw_config.config_3);
  10178. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  10179. switch (val2) {
  10180. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  10181. validate_set_si_mode(bp);
  10182. bp->mf_sub_mode =
  10183. SUB_MF_MODE_NPAR1_DOT_5;
  10184. break;
  10185. default:
  10186. /* Unknown configuration */
  10187. bp->mf_config[vn] = 0;
  10188. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  10189. val);
  10190. }
  10191. break;
  10192. default:
  10193. /* Unknown configuration: reset mf_config */
  10194. bp->mf_config[vn] = 0;
  10195. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  10196. }
  10197. }
  10198. BNX2X_DEV_INFO("%s function mode\n",
  10199. IS_MF(bp) ? "multi" : "single");
  10200. switch (bp->mf_mode) {
  10201. case MULTI_FUNCTION_SD:
  10202. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  10203. FUNC_MF_CFG_E1HOV_TAG_MASK;
  10204. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10205. bp->mf_ov = val;
  10206. bp->path_has_ovlan = true;
  10207. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  10208. func, bp->mf_ov, bp->mf_ov);
  10209. } else if ((bp->mf_sub_mode == SUB_MF_MODE_UFP) ||
  10210. (bp->mf_sub_mode == SUB_MF_MODE_BD)) {
  10211. dev_err(&bp->pdev->dev,
  10212. "Unexpected - no valid MF OV for func %d in UFP/BD mode\n",
  10213. func);
  10214. bp->path_has_ovlan = true;
  10215. } else {
  10216. dev_err(&bp->pdev->dev,
  10217. "No valid MF OV for func %d, aborting\n",
  10218. func);
  10219. return -EPERM;
  10220. }
  10221. break;
  10222. case MULTI_FUNCTION_AFEX:
  10223. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  10224. break;
  10225. case MULTI_FUNCTION_SI:
  10226. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  10227. func);
  10228. break;
  10229. default:
  10230. if (vn) {
  10231. dev_err(&bp->pdev->dev,
  10232. "VN %d is in a single function mode, aborting\n",
  10233. vn);
  10234. return -EPERM;
  10235. }
  10236. break;
  10237. }
  10238. /* check if other port on the path needs ovlan:
  10239. * Since MF configuration is shared between ports
  10240. * Possible mixed modes are only
  10241. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  10242. */
  10243. if (CHIP_MODE_IS_4_PORT(bp) &&
  10244. !bp->path_has_ovlan &&
  10245. !IS_MF(bp) &&
  10246. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10247. u8 other_port = !BP_PORT(bp);
  10248. u8 other_func = BP_PATH(bp) + 2*other_port;
  10249. val = MF_CFG_RD(bp,
  10250. func_mf_config[other_func].e1hov_tag);
  10251. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  10252. bp->path_has_ovlan = true;
  10253. }
  10254. }
  10255. /* adjust igu_sb_cnt to MF for E1H */
  10256. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10257. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10258. /* port info */
  10259. bnx2x_get_port_hwinfo(bp);
  10260. /* Get MAC addresses */
  10261. bnx2x_get_mac_hwinfo(bp);
  10262. bnx2x_get_cnic_info(bp);
  10263. return rc;
  10264. }
  10265. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10266. {
  10267. int cnt, i, block_end, rodi;
  10268. char vpd_start[BNX2X_VPD_LEN+1];
  10269. char str_id_reg[VENDOR_ID_LEN+1];
  10270. char str_id_cap[VENDOR_ID_LEN+1];
  10271. char *vpd_data;
  10272. char *vpd_extended_data = NULL;
  10273. u8 len;
  10274. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10275. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10276. if (cnt < BNX2X_VPD_LEN)
  10277. goto out_not_found;
  10278. /* VPD RO tag should be first tag after identifier string, hence
  10279. * we should be able to find it in first BNX2X_VPD_LEN chars
  10280. */
  10281. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10282. PCI_VPD_LRDT_RO_DATA);
  10283. if (i < 0)
  10284. goto out_not_found;
  10285. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10286. pci_vpd_lrdt_size(&vpd_start[i]);
  10287. i += PCI_VPD_LRDT_TAG_SIZE;
  10288. if (block_end > BNX2X_VPD_LEN) {
  10289. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10290. if (vpd_extended_data == NULL)
  10291. goto out_not_found;
  10292. /* read rest of vpd image into vpd_extended_data */
  10293. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10294. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10295. block_end - BNX2X_VPD_LEN,
  10296. vpd_extended_data + BNX2X_VPD_LEN);
  10297. if (cnt < (block_end - BNX2X_VPD_LEN))
  10298. goto out_not_found;
  10299. vpd_data = vpd_extended_data;
  10300. } else
  10301. vpd_data = vpd_start;
  10302. /* now vpd_data holds full vpd content in both cases */
  10303. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10304. PCI_VPD_RO_KEYWORD_MFR_ID);
  10305. if (rodi < 0)
  10306. goto out_not_found;
  10307. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10308. if (len != VENDOR_ID_LEN)
  10309. goto out_not_found;
  10310. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10311. /* vendor specific info */
  10312. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10313. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10314. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10315. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10316. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10317. PCI_VPD_RO_KEYWORD_VENDOR0);
  10318. if (rodi >= 0) {
  10319. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10320. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10321. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10322. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10323. bp->fw_ver[len] = ' ';
  10324. }
  10325. }
  10326. kfree(vpd_extended_data);
  10327. return;
  10328. }
  10329. out_not_found:
  10330. kfree(vpd_extended_data);
  10331. return;
  10332. }
  10333. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10334. {
  10335. u32 flags = 0;
  10336. if (CHIP_REV_IS_FPGA(bp))
  10337. SET_FLAGS(flags, MODE_FPGA);
  10338. else if (CHIP_REV_IS_EMUL(bp))
  10339. SET_FLAGS(flags, MODE_EMUL);
  10340. else
  10341. SET_FLAGS(flags, MODE_ASIC);
  10342. if (CHIP_MODE_IS_4_PORT(bp))
  10343. SET_FLAGS(flags, MODE_PORT4);
  10344. else
  10345. SET_FLAGS(flags, MODE_PORT2);
  10346. if (CHIP_IS_E2(bp))
  10347. SET_FLAGS(flags, MODE_E2);
  10348. else if (CHIP_IS_E3(bp)) {
  10349. SET_FLAGS(flags, MODE_E3);
  10350. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10351. SET_FLAGS(flags, MODE_E3_A0);
  10352. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10353. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10354. }
  10355. if (IS_MF(bp)) {
  10356. SET_FLAGS(flags, MODE_MF);
  10357. switch (bp->mf_mode) {
  10358. case MULTI_FUNCTION_SD:
  10359. SET_FLAGS(flags, MODE_MF_SD);
  10360. break;
  10361. case MULTI_FUNCTION_SI:
  10362. SET_FLAGS(flags, MODE_MF_SI);
  10363. break;
  10364. case MULTI_FUNCTION_AFEX:
  10365. SET_FLAGS(flags, MODE_MF_AFEX);
  10366. break;
  10367. }
  10368. } else
  10369. SET_FLAGS(flags, MODE_SF);
  10370. #if defined(__LITTLE_ENDIAN)
  10371. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10372. #else /*(__BIG_ENDIAN)*/
  10373. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10374. #endif
  10375. INIT_MODE_FLAGS(bp) = flags;
  10376. }
  10377. static int bnx2x_init_bp(struct bnx2x *bp)
  10378. {
  10379. int func;
  10380. int rc;
  10381. mutex_init(&bp->port.phy_mutex);
  10382. mutex_init(&bp->fw_mb_mutex);
  10383. mutex_init(&bp->drv_info_mutex);
  10384. sema_init(&bp->stats_lock, 1);
  10385. bp->drv_info_mng_owner = false;
  10386. INIT_LIST_HEAD(&bp->vlan_reg);
  10387. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10388. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10389. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10390. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10391. if (IS_PF(bp)) {
  10392. rc = bnx2x_get_hwinfo(bp);
  10393. if (rc)
  10394. return rc;
  10395. } else {
  10396. eth_zero_addr(bp->dev->dev_addr);
  10397. }
  10398. bnx2x_set_modes_bitmap(bp);
  10399. rc = bnx2x_alloc_mem_bp(bp);
  10400. if (rc)
  10401. return rc;
  10402. bnx2x_read_fwinfo(bp);
  10403. func = BP_FUNC(bp);
  10404. /* need to reset chip if undi was active */
  10405. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10406. /* init fw_seq */
  10407. bp->fw_seq =
  10408. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10409. DRV_MSG_SEQ_NUMBER_MASK;
  10410. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10411. rc = bnx2x_prev_unload(bp);
  10412. if (rc) {
  10413. bnx2x_free_mem_bp(bp);
  10414. return rc;
  10415. }
  10416. }
  10417. if (CHIP_REV_IS_FPGA(bp))
  10418. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10419. if (BP_NOMCP(bp) && (func == 0))
  10420. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10421. bp->disable_tpa = disable_tpa;
  10422. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10423. /* Reduce memory usage in kdump environment by disabling TPA */
  10424. bp->disable_tpa |= is_kdump_kernel();
  10425. /* Set TPA flags */
  10426. if (bp->disable_tpa) {
  10427. bp->dev->hw_features &= ~NETIF_F_LRO;
  10428. bp->dev->features &= ~NETIF_F_LRO;
  10429. }
  10430. if (CHIP_IS_E1(bp))
  10431. bp->dropless_fc = 0;
  10432. else
  10433. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10434. bp->mrrs = mrrs;
  10435. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10436. if (IS_VF(bp))
  10437. bp->rx_ring_size = MAX_RX_AVAIL;
  10438. /* make sure that the numbers are in the right granularity */
  10439. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10440. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10441. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10442. init_timer(&bp->timer);
  10443. bp->timer.expires = jiffies + bp->current_interval;
  10444. bp->timer.data = (unsigned long) bp;
  10445. bp->timer.function = bnx2x_timer;
  10446. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10447. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10448. SHMEM2_HAS(bp, dcbx_en) &&
  10449. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10450. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset) &&
  10451. SHMEM2_RD(bp, dcbx_en[BP_PORT(bp)])) {
  10452. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10453. bnx2x_dcbx_init_params(bp);
  10454. } else {
  10455. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10456. }
  10457. if (CHIP_IS_E1x(bp))
  10458. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10459. else
  10460. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10461. /* multiple tx priority */
  10462. if (IS_VF(bp))
  10463. bp->max_cos = 1;
  10464. else if (CHIP_IS_E1x(bp))
  10465. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10466. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10467. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10468. else if (CHIP_IS_E3B0(bp))
  10469. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10470. else
  10471. BNX2X_ERR("unknown chip %x revision %x\n",
  10472. CHIP_NUM(bp), CHIP_REV(bp));
  10473. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10474. /* We need at least one default status block for slow-path events,
  10475. * second status block for the L2 queue, and a third status block for
  10476. * CNIC if supported.
  10477. */
  10478. if (IS_VF(bp))
  10479. bp->min_msix_vec_cnt = 1;
  10480. else if (CNIC_SUPPORT(bp))
  10481. bp->min_msix_vec_cnt = 3;
  10482. else /* PF w/o cnic */
  10483. bp->min_msix_vec_cnt = 2;
  10484. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10485. bp->dump_preset_idx = 1;
  10486. if (CHIP_IS_E3B0(bp))
  10487. bp->flags |= PTP_SUPPORTED;
  10488. return rc;
  10489. }
  10490. /****************************************************************************
  10491. * General service functions
  10492. ****************************************************************************/
  10493. /*
  10494. * net_device service functions
  10495. */
  10496. /* called with rtnl_lock */
  10497. static int bnx2x_open(struct net_device *dev)
  10498. {
  10499. struct bnx2x *bp = netdev_priv(dev);
  10500. int rc;
  10501. bp->stats_init = true;
  10502. netif_carrier_off(dev);
  10503. bnx2x_set_power_state(bp, PCI_D0);
  10504. /* If parity had happen during the unload, then attentions
  10505. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10506. * want the first function loaded on the current engine to
  10507. * complete the recovery.
  10508. * Parity recovery is only relevant for PF driver.
  10509. */
  10510. if (IS_PF(bp)) {
  10511. int other_engine = BP_PATH(bp) ? 0 : 1;
  10512. bool other_load_status, load_status;
  10513. bool global = false;
  10514. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10515. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10516. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10517. bnx2x_chk_parity_attn(bp, &global, true)) {
  10518. do {
  10519. /* If there are attentions and they are in a
  10520. * global blocks, set the GLOBAL_RESET bit
  10521. * regardless whether it will be this function
  10522. * that will complete the recovery or not.
  10523. */
  10524. if (global)
  10525. bnx2x_set_reset_global(bp);
  10526. /* Only the first function on the current
  10527. * engine should try to recover in open. In case
  10528. * of attentions in global blocks only the first
  10529. * in the chip should try to recover.
  10530. */
  10531. if ((!load_status &&
  10532. (!global || !other_load_status)) &&
  10533. bnx2x_trylock_leader_lock(bp) &&
  10534. !bnx2x_leader_reset(bp)) {
  10535. netdev_info(bp->dev,
  10536. "Recovered in open\n");
  10537. break;
  10538. }
  10539. /* recovery has failed... */
  10540. bnx2x_set_power_state(bp, PCI_D3hot);
  10541. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10542. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10543. "If you still see this message after a few retries then power cycle is required.\n");
  10544. return -EAGAIN;
  10545. } while (0);
  10546. }
  10547. }
  10548. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10549. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10550. if (rc)
  10551. return rc;
  10552. if (IS_PF(bp))
  10553. udp_tunnel_get_rx_info(dev);
  10554. return 0;
  10555. }
  10556. /* called with rtnl_lock */
  10557. static int bnx2x_close(struct net_device *dev)
  10558. {
  10559. struct bnx2x *bp = netdev_priv(dev);
  10560. /* Unload the driver, release IRQs */
  10561. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10562. return 0;
  10563. }
  10564. struct bnx2x_mcast_list_elem_group
  10565. {
  10566. struct list_head mcast_group_link;
  10567. struct bnx2x_mcast_list_elem mcast_elems[];
  10568. };
  10569. #define MCAST_ELEMS_PER_PG \
  10570. ((PAGE_SIZE - sizeof(struct bnx2x_mcast_list_elem_group)) / \
  10571. sizeof(struct bnx2x_mcast_list_elem))
  10572. static void bnx2x_free_mcast_macs_list(struct list_head *mcast_group_list)
  10573. {
  10574. struct bnx2x_mcast_list_elem_group *current_mcast_group;
  10575. while (!list_empty(mcast_group_list)) {
  10576. current_mcast_group = list_first_entry(mcast_group_list,
  10577. struct bnx2x_mcast_list_elem_group,
  10578. mcast_group_link);
  10579. list_del(&current_mcast_group->mcast_group_link);
  10580. free_page((unsigned long)current_mcast_group);
  10581. }
  10582. }
  10583. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10584. struct bnx2x_mcast_ramrod_params *p,
  10585. struct list_head *mcast_group_list)
  10586. {
  10587. struct bnx2x_mcast_list_elem *mc_mac;
  10588. struct netdev_hw_addr *ha;
  10589. struct bnx2x_mcast_list_elem_group *current_mcast_group = NULL;
  10590. int mc_count = netdev_mc_count(bp->dev);
  10591. int offset = 0;
  10592. INIT_LIST_HEAD(&p->mcast_list);
  10593. netdev_for_each_mc_addr(ha, bp->dev) {
  10594. if (!offset) {
  10595. current_mcast_group =
  10596. (struct bnx2x_mcast_list_elem_group *)
  10597. __get_free_page(GFP_ATOMIC);
  10598. if (!current_mcast_group) {
  10599. bnx2x_free_mcast_macs_list(mcast_group_list);
  10600. BNX2X_ERR("Failed to allocate mc MAC list\n");
  10601. return -ENOMEM;
  10602. }
  10603. list_add(&current_mcast_group->mcast_group_link,
  10604. mcast_group_list);
  10605. }
  10606. mc_mac = &current_mcast_group->mcast_elems[offset];
  10607. mc_mac->mac = bnx2x_mc_addr(ha);
  10608. list_add_tail(&mc_mac->link, &p->mcast_list);
  10609. offset++;
  10610. if (offset == MCAST_ELEMS_PER_PG)
  10611. offset = 0;
  10612. }
  10613. p->mcast_list_len = mc_count;
  10614. return 0;
  10615. }
  10616. /**
  10617. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10618. *
  10619. * @bp: driver handle
  10620. *
  10621. * We will use zero (0) as a MAC type for these MACs.
  10622. */
  10623. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10624. {
  10625. int rc;
  10626. struct net_device *dev = bp->dev;
  10627. struct netdev_hw_addr *ha;
  10628. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10629. unsigned long ramrod_flags = 0;
  10630. /* First schedule a cleanup up of old configuration */
  10631. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10632. if (rc < 0) {
  10633. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10634. return rc;
  10635. }
  10636. netdev_for_each_uc_addr(ha, dev) {
  10637. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10638. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10639. if (rc == -EEXIST) {
  10640. DP(BNX2X_MSG_SP,
  10641. "Failed to schedule ADD operations: %d\n", rc);
  10642. /* do not treat adding same MAC as error */
  10643. rc = 0;
  10644. } else if (rc < 0) {
  10645. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10646. rc);
  10647. return rc;
  10648. }
  10649. }
  10650. /* Execute the pending commands */
  10651. __set_bit(RAMROD_CONT, &ramrod_flags);
  10652. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10653. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10654. }
  10655. static int bnx2x_set_mc_list_e1x(struct bnx2x *bp)
  10656. {
  10657. LIST_HEAD(mcast_group_list);
  10658. struct net_device *dev = bp->dev;
  10659. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10660. int rc = 0;
  10661. rparam.mcast_obj = &bp->mcast_obj;
  10662. /* first, clear all configured multicast MACs */
  10663. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10664. if (rc < 0) {
  10665. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10666. return rc;
  10667. }
  10668. /* then, configure a new MACs list */
  10669. if (netdev_mc_count(dev)) {
  10670. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10671. if (rc)
  10672. return rc;
  10673. /* Now add the new MACs */
  10674. rc = bnx2x_config_mcast(bp, &rparam,
  10675. BNX2X_MCAST_CMD_ADD);
  10676. if (rc < 0)
  10677. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10678. rc);
  10679. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10680. }
  10681. return rc;
  10682. }
  10683. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10684. {
  10685. LIST_HEAD(mcast_group_list);
  10686. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10687. struct net_device *dev = bp->dev;
  10688. int rc = 0;
  10689. /* On older adapters, we need to flush and re-add filters */
  10690. if (CHIP_IS_E1x(bp))
  10691. return bnx2x_set_mc_list_e1x(bp);
  10692. rparam.mcast_obj = &bp->mcast_obj;
  10693. if (netdev_mc_count(dev)) {
  10694. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10695. if (rc)
  10696. return rc;
  10697. /* Override the curently configured set of mc filters */
  10698. rc = bnx2x_config_mcast(bp, &rparam,
  10699. BNX2X_MCAST_CMD_SET);
  10700. if (rc < 0)
  10701. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10702. rc);
  10703. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10704. } else {
  10705. /* If no mc addresses are required, flush the configuration */
  10706. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10707. if (rc)
  10708. BNX2X_ERR("Failed to clear multicast configuration %d\n",
  10709. rc);
  10710. }
  10711. return rc;
  10712. }
  10713. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10714. static void bnx2x_set_rx_mode(struct net_device *dev)
  10715. {
  10716. struct bnx2x *bp = netdev_priv(dev);
  10717. if (bp->state != BNX2X_STATE_OPEN) {
  10718. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10719. return;
  10720. } else {
  10721. /* Schedule an SP task to handle rest of change */
  10722. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10723. NETIF_MSG_IFUP);
  10724. }
  10725. }
  10726. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10727. {
  10728. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10729. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10730. netif_addr_lock_bh(bp->dev);
  10731. if (bp->dev->flags & IFF_PROMISC) {
  10732. rx_mode = BNX2X_RX_MODE_PROMISC;
  10733. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10734. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10735. CHIP_IS_E1(bp))) {
  10736. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10737. } else {
  10738. if (IS_PF(bp)) {
  10739. /* some multicasts */
  10740. if (bnx2x_set_mc_list(bp) < 0)
  10741. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10742. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10743. netif_addr_unlock_bh(bp->dev);
  10744. if (bnx2x_set_uc_list(bp) < 0)
  10745. rx_mode = BNX2X_RX_MODE_PROMISC;
  10746. netif_addr_lock_bh(bp->dev);
  10747. } else {
  10748. /* configuring mcast to a vf involves sleeping (when we
  10749. * wait for the pf's response).
  10750. */
  10751. bnx2x_schedule_sp_rtnl(bp,
  10752. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10753. }
  10754. }
  10755. bp->rx_mode = rx_mode;
  10756. /* handle ISCSI SD mode */
  10757. if (IS_MF_ISCSI_ONLY(bp))
  10758. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10759. /* Schedule the rx_mode command */
  10760. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10761. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10762. netif_addr_unlock_bh(bp->dev);
  10763. return;
  10764. }
  10765. if (IS_PF(bp)) {
  10766. bnx2x_set_storm_rx_mode(bp);
  10767. netif_addr_unlock_bh(bp->dev);
  10768. } else {
  10769. /* VF will need to request the PF to make this change, and so
  10770. * the VF needs to release the bottom-half lock prior to the
  10771. * request (as it will likely require sleep on the VF side)
  10772. */
  10773. netif_addr_unlock_bh(bp->dev);
  10774. bnx2x_vfpf_storm_rx_mode(bp);
  10775. }
  10776. }
  10777. /* called with rtnl_lock */
  10778. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10779. int devad, u16 addr)
  10780. {
  10781. struct bnx2x *bp = netdev_priv(netdev);
  10782. u16 value;
  10783. int rc;
  10784. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10785. prtad, devad, addr);
  10786. /* The HW expects different devad if CL22 is used */
  10787. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10788. bnx2x_acquire_phy_lock(bp);
  10789. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10790. bnx2x_release_phy_lock(bp);
  10791. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10792. if (!rc)
  10793. rc = value;
  10794. return rc;
  10795. }
  10796. /* called with rtnl_lock */
  10797. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10798. u16 addr, u16 value)
  10799. {
  10800. struct bnx2x *bp = netdev_priv(netdev);
  10801. int rc;
  10802. DP(NETIF_MSG_LINK,
  10803. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10804. prtad, devad, addr, value);
  10805. /* The HW expects different devad if CL22 is used */
  10806. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10807. bnx2x_acquire_phy_lock(bp);
  10808. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10809. bnx2x_release_phy_lock(bp);
  10810. return rc;
  10811. }
  10812. /* called with rtnl_lock */
  10813. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10814. {
  10815. struct bnx2x *bp = netdev_priv(dev);
  10816. struct mii_ioctl_data *mdio = if_mii(ifr);
  10817. if (!netif_running(dev))
  10818. return -EAGAIN;
  10819. switch (cmd) {
  10820. case SIOCSHWTSTAMP:
  10821. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10822. default:
  10823. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10824. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10825. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10826. }
  10827. }
  10828. #ifdef CONFIG_NET_POLL_CONTROLLER
  10829. static void poll_bnx2x(struct net_device *dev)
  10830. {
  10831. struct bnx2x *bp = netdev_priv(dev);
  10832. int i;
  10833. for_each_eth_queue(bp, i) {
  10834. struct bnx2x_fastpath *fp = &bp->fp[i];
  10835. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10836. }
  10837. }
  10838. #endif
  10839. static int bnx2x_validate_addr(struct net_device *dev)
  10840. {
  10841. struct bnx2x *bp = netdev_priv(dev);
  10842. /* query the bulletin board for mac address configured by the PF */
  10843. if (IS_VF(bp))
  10844. bnx2x_sample_bulletin(bp);
  10845. if (!is_valid_ether_addr(dev->dev_addr)) {
  10846. BNX2X_ERR("Non-valid Ethernet address\n");
  10847. return -EADDRNOTAVAIL;
  10848. }
  10849. return 0;
  10850. }
  10851. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10852. struct netdev_phys_item_id *ppid)
  10853. {
  10854. struct bnx2x *bp = netdev_priv(netdev);
  10855. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10856. return -EOPNOTSUPP;
  10857. ppid->id_len = sizeof(bp->phys_port_id);
  10858. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10859. return 0;
  10860. }
  10861. static netdev_features_t bnx2x_features_check(struct sk_buff *skb,
  10862. struct net_device *dev,
  10863. netdev_features_t features)
  10864. {
  10865. features = vlan_features_check(skb, features);
  10866. return vxlan_features_check(skb, features);
  10867. }
  10868. static int __bnx2x_vlan_configure_vid(struct bnx2x *bp, u16 vid, bool add)
  10869. {
  10870. int rc;
  10871. if (IS_PF(bp)) {
  10872. unsigned long ramrod_flags = 0;
  10873. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10874. rc = bnx2x_set_vlan_one(bp, vid, &bp->sp_objs->vlan_obj,
  10875. add, &ramrod_flags);
  10876. } else {
  10877. rc = bnx2x_vfpf_update_vlan(bp, vid, bp->fp->index, add);
  10878. }
  10879. return rc;
  10880. }
  10881. static int bnx2x_vlan_configure_vid_list(struct bnx2x *bp)
  10882. {
  10883. struct bnx2x_vlan_entry *vlan;
  10884. int rc = 0;
  10885. /* Configure all non-configured entries */
  10886. list_for_each_entry(vlan, &bp->vlan_reg, link) {
  10887. if (vlan->hw)
  10888. continue;
  10889. if (bp->vlan_cnt >= bp->vlan_credit)
  10890. return -ENOBUFS;
  10891. rc = __bnx2x_vlan_configure_vid(bp, vlan->vid, true);
  10892. if (rc) {
  10893. BNX2X_ERR("Unable to config VLAN %d\n", vlan->vid);
  10894. return rc;
  10895. }
  10896. DP(NETIF_MSG_IFUP, "HW configured for VLAN %d\n", vlan->vid);
  10897. vlan->hw = true;
  10898. bp->vlan_cnt++;
  10899. }
  10900. return 0;
  10901. }
  10902. static void bnx2x_vlan_configure(struct bnx2x *bp, bool set_rx_mode)
  10903. {
  10904. bool need_accept_any_vlan;
  10905. need_accept_any_vlan = !!bnx2x_vlan_configure_vid_list(bp);
  10906. if (bp->accept_any_vlan != need_accept_any_vlan) {
  10907. bp->accept_any_vlan = need_accept_any_vlan;
  10908. DP(NETIF_MSG_IFUP, "Accept all VLAN %s\n",
  10909. bp->accept_any_vlan ? "raised" : "cleared");
  10910. if (set_rx_mode) {
  10911. if (IS_PF(bp))
  10912. bnx2x_set_rx_mode_inner(bp);
  10913. else
  10914. bnx2x_vfpf_storm_rx_mode(bp);
  10915. }
  10916. }
  10917. }
  10918. int bnx2x_vlan_reconfigure_vid(struct bnx2x *bp)
  10919. {
  10920. struct bnx2x_vlan_entry *vlan;
  10921. /* The hw forgot all entries after reload */
  10922. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10923. vlan->hw = false;
  10924. bp->vlan_cnt = 0;
  10925. /* Don't set rx mode here. Our caller will do it. */
  10926. bnx2x_vlan_configure(bp, false);
  10927. return 0;
  10928. }
  10929. static int bnx2x_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
  10930. {
  10931. struct bnx2x *bp = netdev_priv(dev);
  10932. struct bnx2x_vlan_entry *vlan;
  10933. DP(NETIF_MSG_IFUP, "Adding VLAN %d\n", vid);
  10934. vlan = kmalloc(sizeof(*vlan), GFP_KERNEL);
  10935. if (!vlan)
  10936. return -ENOMEM;
  10937. vlan->vid = vid;
  10938. vlan->hw = false;
  10939. list_add_tail(&vlan->link, &bp->vlan_reg);
  10940. if (netif_running(dev))
  10941. bnx2x_vlan_configure(bp, true);
  10942. return 0;
  10943. }
  10944. static int bnx2x_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
  10945. {
  10946. struct bnx2x *bp = netdev_priv(dev);
  10947. struct bnx2x_vlan_entry *vlan;
  10948. bool found = false;
  10949. int rc = 0;
  10950. DP(NETIF_MSG_IFUP, "Removing VLAN %d\n", vid);
  10951. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10952. if (vlan->vid == vid) {
  10953. found = true;
  10954. break;
  10955. }
  10956. if (!found) {
  10957. BNX2X_ERR("Unable to kill VLAN %d - not found\n", vid);
  10958. return -EINVAL;
  10959. }
  10960. if (netif_running(dev) && vlan->hw) {
  10961. rc = __bnx2x_vlan_configure_vid(bp, vid, false);
  10962. DP(NETIF_MSG_IFUP, "HW deconfigured for VLAN %d\n", vid);
  10963. bp->vlan_cnt--;
  10964. }
  10965. list_del(&vlan->link);
  10966. kfree(vlan);
  10967. if (netif_running(dev))
  10968. bnx2x_vlan_configure(bp, true);
  10969. DP(NETIF_MSG_IFUP, "Removing VLAN result %d\n", rc);
  10970. return rc;
  10971. }
  10972. static const struct net_device_ops bnx2x_netdev_ops = {
  10973. .ndo_open = bnx2x_open,
  10974. .ndo_stop = bnx2x_close,
  10975. .ndo_start_xmit = bnx2x_start_xmit,
  10976. .ndo_select_queue = bnx2x_select_queue,
  10977. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10978. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10979. .ndo_validate_addr = bnx2x_validate_addr,
  10980. .ndo_do_ioctl = bnx2x_ioctl,
  10981. .ndo_change_mtu = bnx2x_change_mtu,
  10982. .ndo_fix_features = bnx2x_fix_features,
  10983. .ndo_set_features = bnx2x_set_features,
  10984. .ndo_tx_timeout = bnx2x_tx_timeout,
  10985. .ndo_vlan_rx_add_vid = bnx2x_vlan_rx_add_vid,
  10986. .ndo_vlan_rx_kill_vid = bnx2x_vlan_rx_kill_vid,
  10987. #ifdef CONFIG_NET_POLL_CONTROLLER
  10988. .ndo_poll_controller = poll_bnx2x,
  10989. #endif
  10990. .ndo_setup_tc = __bnx2x_setup_tc,
  10991. #ifdef CONFIG_BNX2X_SRIOV
  10992. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10993. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10994. .ndo_get_vf_config = bnx2x_get_vf_config,
  10995. #endif
  10996. #ifdef NETDEV_FCOE_WWNN
  10997. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10998. #endif
  10999. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  11000. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  11001. .ndo_features_check = bnx2x_features_check,
  11002. .ndo_udp_tunnel_add = bnx2x_udp_tunnel_add,
  11003. .ndo_udp_tunnel_del = bnx2x_udp_tunnel_del,
  11004. };
  11005. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  11006. {
  11007. struct device *dev = &bp->pdev->dev;
  11008. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  11009. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  11010. dev_err(dev, "System does not support DMA, aborting\n");
  11011. return -EIO;
  11012. }
  11013. return 0;
  11014. }
  11015. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  11016. {
  11017. if (bp->flags & AER_ENABLED) {
  11018. pci_disable_pcie_error_reporting(bp->pdev);
  11019. bp->flags &= ~AER_ENABLED;
  11020. }
  11021. }
  11022. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  11023. struct net_device *dev, unsigned long board_type)
  11024. {
  11025. int rc;
  11026. u32 pci_cfg_dword;
  11027. bool chip_is_e1x = (board_type == BCM57710 ||
  11028. board_type == BCM57711 ||
  11029. board_type == BCM57711E);
  11030. SET_NETDEV_DEV(dev, &pdev->dev);
  11031. bp->dev = dev;
  11032. bp->pdev = pdev;
  11033. rc = pci_enable_device(pdev);
  11034. if (rc) {
  11035. dev_err(&bp->pdev->dev,
  11036. "Cannot enable PCI device, aborting\n");
  11037. goto err_out;
  11038. }
  11039. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  11040. dev_err(&bp->pdev->dev,
  11041. "Cannot find PCI device base address, aborting\n");
  11042. rc = -ENODEV;
  11043. goto err_out_disable;
  11044. }
  11045. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  11046. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  11047. rc = -ENODEV;
  11048. goto err_out_disable;
  11049. }
  11050. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  11051. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  11052. PCICFG_REVESION_ID_ERROR_VAL) {
  11053. pr_err("PCI device error, probably due to fan failure, aborting\n");
  11054. rc = -ENODEV;
  11055. goto err_out_disable;
  11056. }
  11057. if (atomic_read(&pdev->enable_cnt) == 1) {
  11058. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  11059. if (rc) {
  11060. dev_err(&bp->pdev->dev,
  11061. "Cannot obtain PCI resources, aborting\n");
  11062. goto err_out_disable;
  11063. }
  11064. pci_set_master(pdev);
  11065. pci_save_state(pdev);
  11066. }
  11067. if (IS_PF(bp)) {
  11068. if (!pdev->pm_cap) {
  11069. dev_err(&bp->pdev->dev,
  11070. "Cannot find power management capability, aborting\n");
  11071. rc = -EIO;
  11072. goto err_out_release;
  11073. }
  11074. }
  11075. if (!pci_is_pcie(pdev)) {
  11076. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  11077. rc = -EIO;
  11078. goto err_out_release;
  11079. }
  11080. rc = bnx2x_set_coherency_mask(bp);
  11081. if (rc)
  11082. goto err_out_release;
  11083. dev->mem_start = pci_resource_start(pdev, 0);
  11084. dev->base_addr = dev->mem_start;
  11085. dev->mem_end = pci_resource_end(pdev, 0);
  11086. dev->irq = pdev->irq;
  11087. bp->regview = pci_ioremap_bar(pdev, 0);
  11088. if (!bp->regview) {
  11089. dev_err(&bp->pdev->dev,
  11090. "Cannot map register space, aborting\n");
  11091. rc = -ENOMEM;
  11092. goto err_out_release;
  11093. }
  11094. /* In E1/E1H use pci device function given by kernel.
  11095. * In E2/E3 read physical function from ME register since these chips
  11096. * support Physical Device Assignment where kernel BDF maybe arbitrary
  11097. * (depending on hypervisor).
  11098. */
  11099. if (chip_is_e1x) {
  11100. bp->pf_num = PCI_FUNC(pdev->devfn);
  11101. } else {
  11102. /* chip is E2/3*/
  11103. pci_read_config_dword(bp->pdev,
  11104. PCICFG_ME_REGISTER, &pci_cfg_dword);
  11105. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  11106. ME_REG_ABS_PF_NUM_SHIFT);
  11107. }
  11108. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  11109. /* clean indirect addresses */
  11110. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  11111. PCICFG_VENDOR_ID_OFFSET);
  11112. /* Set PCIe reset type to fundamental for EEH recovery */
  11113. pdev->needs_freset = 1;
  11114. /* AER (Advanced Error reporting) configuration */
  11115. rc = pci_enable_pcie_error_reporting(pdev);
  11116. if (!rc)
  11117. bp->flags |= AER_ENABLED;
  11118. else
  11119. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  11120. /*
  11121. * Clean the following indirect addresses for all functions since it
  11122. * is not used by the driver.
  11123. */
  11124. if (IS_PF(bp)) {
  11125. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  11126. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  11127. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  11128. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  11129. if (chip_is_e1x) {
  11130. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  11131. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  11132. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  11133. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  11134. }
  11135. /* Enable internal target-read (in case we are probed after PF
  11136. * FLR). Must be done prior to any BAR read access. Only for
  11137. * 57712 and up
  11138. */
  11139. if (!chip_is_e1x)
  11140. REG_WR(bp,
  11141. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  11142. }
  11143. dev->watchdog_timeo = TX_TIMEOUT;
  11144. dev->netdev_ops = &bnx2x_netdev_ops;
  11145. bnx2x_set_ethtool_ops(bp, dev);
  11146. dev->priv_flags |= IFF_UNICAST_FLT;
  11147. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11148. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11149. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  11150. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  11151. if (!chip_is_e1x) {
  11152. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11153. NETIF_F_GSO_IPXIP4 |
  11154. NETIF_F_GSO_UDP_TUNNEL |
  11155. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11156. NETIF_F_GSO_PARTIAL;
  11157. dev->hw_enc_features =
  11158. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  11159. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11160. NETIF_F_GSO_IPXIP4 |
  11161. NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11162. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11163. NETIF_F_GSO_PARTIAL;
  11164. dev->gso_partial_features = NETIF_F_GSO_GRE_CSUM |
  11165. NETIF_F_GSO_UDP_TUNNEL_CSUM;
  11166. }
  11167. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11168. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  11169. if (IS_PF(bp)) {
  11170. if (chip_is_e1x)
  11171. bp->accept_any_vlan = true;
  11172. else
  11173. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11174. }
  11175. /* For VF we'll know whether to enable VLAN filtering after
  11176. * getting a response to CHANNEL_TLV_ACQUIRE from PF.
  11177. */
  11178. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  11179. dev->features |= NETIF_F_HIGHDMA;
  11180. /* Add Loopback capability to the device */
  11181. dev->hw_features |= NETIF_F_LOOPBACK;
  11182. #ifdef BCM_DCBNL
  11183. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  11184. #endif
  11185. /* get_port_hwinfo() will set prtad and mmds properly */
  11186. bp->mdio.prtad = MDIO_PRTAD_NONE;
  11187. bp->mdio.mmds = 0;
  11188. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  11189. bp->mdio.dev = dev;
  11190. bp->mdio.mdio_read = bnx2x_mdio_read;
  11191. bp->mdio.mdio_write = bnx2x_mdio_write;
  11192. return 0;
  11193. err_out_release:
  11194. if (atomic_read(&pdev->enable_cnt) == 1)
  11195. pci_release_regions(pdev);
  11196. err_out_disable:
  11197. pci_disable_device(pdev);
  11198. err_out:
  11199. return rc;
  11200. }
  11201. /*(DEBLOBBED)*/
  11202. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11203. {
  11204. const __be32 *source = (const __be32 *)_source;
  11205. u32 *target = (u32 *)_target;
  11206. u32 i;
  11207. for (i = 0; i < n/4; i++)
  11208. target[i] = be32_to_cpu(source[i]);
  11209. }
  11210. /*
  11211. Ops array is stored in the following format:
  11212. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  11213. */
  11214. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  11215. {
  11216. const __be32 *source = (const __be32 *)_source;
  11217. struct raw_op *target = (struct raw_op *)_target;
  11218. u32 i, j, tmp;
  11219. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  11220. tmp = be32_to_cpu(source[j]);
  11221. target[i].op = (tmp >> 24) & 0xff;
  11222. target[i].offset = tmp & 0xffffff;
  11223. target[i].raw_data = be32_to_cpu(source[j + 1]);
  11224. }
  11225. }
  11226. /* IRO array is stored in the following format:
  11227. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  11228. */
  11229. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  11230. {
  11231. const __be32 *source = (const __be32 *)_source;
  11232. struct iro *target = (struct iro *)_target;
  11233. u32 i, j, tmp;
  11234. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  11235. target[i].base = be32_to_cpu(source[j]);
  11236. j++;
  11237. tmp = be32_to_cpu(source[j]);
  11238. target[i].m1 = (tmp >> 16) & 0xffff;
  11239. target[i].m2 = tmp & 0xffff;
  11240. j++;
  11241. tmp = be32_to_cpu(source[j]);
  11242. target[i].m3 = (tmp >> 16) & 0xffff;
  11243. target[i].size = tmp & 0xffff;
  11244. j++;
  11245. }
  11246. }
  11247. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11248. {
  11249. const __be16 *source = (const __be16 *)_source;
  11250. u16 *target = (u16 *)_target;
  11251. u32 i;
  11252. for (i = 0; i < n/2; i++)
  11253. target[i] = be16_to_cpu(source[i]);
  11254. }
  11255. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  11256. do { \
  11257. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  11258. bp->arr = kmalloc(len, GFP_KERNEL); \
  11259. if (!bp->arr) \
  11260. goto lbl; \
  11261. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  11262. (u8 *)bp->arr, len); \
  11263. } while (0)
  11264. static int bnx2x_init_firmware(struct bnx2x *bp)
  11265. {
  11266. const char *fw_file_name;
  11267. struct bnx2x_fw_file_hdr *fw_hdr;
  11268. int rc;
  11269. if (bp->firmware)
  11270. return 0;
  11271. if (CHIP_IS_E1(bp))
  11272. fw_file_name = FW_FILE_NAME_E1;
  11273. else if (CHIP_IS_E1H(bp))
  11274. fw_file_name = FW_FILE_NAME_E1H;
  11275. else if (!CHIP_IS_E1x(bp))
  11276. fw_file_name = FW_FILE_NAME_E2;
  11277. else {
  11278. BNX2X_ERR("Unsupported chip revision\n");
  11279. return -EINVAL;
  11280. }
  11281. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  11282. rc = reject_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  11283. if (rc) {
  11284. BNX2X_ERR("Can't load firmware file %s\n",
  11285. fw_file_name);
  11286. goto request_firmware_exit;
  11287. }
  11288. /*(DEBLOBBED)*/
  11289. if (rc) {
  11290. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  11291. goto request_firmware_exit;
  11292. }
  11293. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  11294. /* Initialize the pointers to the init arrays */
  11295. /* Blob */
  11296. rc = -ENOMEM;
  11297. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  11298. /* Opcodes */
  11299. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  11300. /* Offsets */
  11301. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  11302. be16_to_cpu_n);
  11303. /* STORMs firmware */
  11304. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11305. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  11306. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  11307. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  11308. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11309. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  11310. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  11311. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  11312. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11313. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  11314. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  11315. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  11316. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11317. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  11318. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  11319. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  11320. /* IRO */
  11321. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  11322. return 0;
  11323. iro_alloc_err:
  11324. kfree(bp->init_ops_offsets);
  11325. init_offsets_alloc_err:
  11326. kfree(bp->init_ops);
  11327. init_ops_alloc_err:
  11328. kfree(bp->init_data);
  11329. request_firmware_exit:
  11330. release_firmware(bp->firmware);
  11331. bp->firmware = NULL;
  11332. return rc;
  11333. }
  11334. static void bnx2x_release_firmware(struct bnx2x *bp)
  11335. {
  11336. kfree(bp->init_ops_offsets);
  11337. kfree(bp->init_ops);
  11338. kfree(bp->init_data);
  11339. release_firmware(bp->firmware);
  11340. bp->firmware = NULL;
  11341. }
  11342. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  11343. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  11344. .init_hw_cmn = bnx2x_init_hw_common,
  11345. .init_hw_port = bnx2x_init_hw_port,
  11346. .init_hw_func = bnx2x_init_hw_func,
  11347. .reset_hw_cmn = bnx2x_reset_common,
  11348. .reset_hw_port = bnx2x_reset_port,
  11349. .reset_hw_func = bnx2x_reset_func,
  11350. .gunzip_init = bnx2x_gunzip_init,
  11351. .gunzip_end = bnx2x_gunzip_end,
  11352. .init_fw = bnx2x_init_firmware,
  11353. .release_fw = bnx2x_release_firmware,
  11354. };
  11355. void bnx2x__init_func_obj(struct bnx2x *bp)
  11356. {
  11357. /* Prepare DMAE related driver resources */
  11358. bnx2x_setup_dmae(bp);
  11359. bnx2x_init_func_obj(bp, &bp->func_obj,
  11360. bnx2x_sp(bp, func_rdata),
  11361. bnx2x_sp_mapping(bp, func_rdata),
  11362. bnx2x_sp(bp, func_afex_rdata),
  11363. bnx2x_sp_mapping(bp, func_afex_rdata),
  11364. &bnx2x_func_sp_drv);
  11365. }
  11366. /* must be called after sriov-enable */
  11367. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  11368. {
  11369. int cid_count = BNX2X_L2_MAX_CID(bp);
  11370. if (IS_SRIOV(bp))
  11371. cid_count += BNX2X_VF_CIDS;
  11372. if (CNIC_SUPPORT(bp))
  11373. cid_count += CNIC_CID_MAX;
  11374. return roundup(cid_count, QM_CID_ROUND);
  11375. }
  11376. /**
  11377. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  11378. *
  11379. * @dev: pci device
  11380. *
  11381. */
  11382. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  11383. {
  11384. int index;
  11385. u16 control = 0;
  11386. /*
  11387. * If MSI-X is not supported - return number of SBs needed to support
  11388. * one fast path queue: one FP queue + SB for CNIC
  11389. */
  11390. if (!pdev->msix_cap) {
  11391. dev_info(&pdev->dev, "no msix capability found\n");
  11392. return 1 + cnic_cnt;
  11393. }
  11394. dev_info(&pdev->dev, "msix capability found\n");
  11395. /*
  11396. * The value in the PCI configuration space is the index of the last
  11397. * entry, namely one less than the actual size of the table, which is
  11398. * exactly what we want to return from this function: number of all SBs
  11399. * without the default SB.
  11400. * For VFs there is no default SB, then we return (index+1).
  11401. */
  11402. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11403. index = control & PCI_MSIX_FLAGS_QSIZE;
  11404. return index;
  11405. }
  11406. static int set_max_cos_est(int chip_id)
  11407. {
  11408. switch (chip_id) {
  11409. case BCM57710:
  11410. case BCM57711:
  11411. case BCM57711E:
  11412. return BNX2X_MULTI_TX_COS_E1X;
  11413. case BCM57712:
  11414. case BCM57712_MF:
  11415. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11416. case BCM57800:
  11417. case BCM57800_MF:
  11418. case BCM57810:
  11419. case BCM57810_MF:
  11420. case BCM57840_4_10:
  11421. case BCM57840_2_20:
  11422. case BCM57840_O:
  11423. case BCM57840_MFO:
  11424. case BCM57840_MF:
  11425. case BCM57811:
  11426. case BCM57811_MF:
  11427. return BNX2X_MULTI_TX_COS_E3B0;
  11428. case BCM57712_VF:
  11429. case BCM57800_VF:
  11430. case BCM57810_VF:
  11431. case BCM57840_VF:
  11432. case BCM57811_VF:
  11433. return 1;
  11434. default:
  11435. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11436. return -ENODEV;
  11437. }
  11438. }
  11439. static int set_is_vf(int chip_id)
  11440. {
  11441. switch (chip_id) {
  11442. case BCM57712_VF:
  11443. case BCM57800_VF:
  11444. case BCM57810_VF:
  11445. case BCM57840_VF:
  11446. case BCM57811_VF:
  11447. return true;
  11448. default:
  11449. return false;
  11450. }
  11451. }
  11452. /* nig_tsgen registers relative address */
  11453. #define tsgen_ctrl 0x0
  11454. #define tsgen_freecount 0x10
  11455. #define tsgen_synctime_t0 0x20
  11456. #define tsgen_offset_t0 0x28
  11457. #define tsgen_drift_t0 0x30
  11458. #define tsgen_synctime_t1 0x58
  11459. #define tsgen_offset_t1 0x60
  11460. #define tsgen_drift_t1 0x68
  11461. /* FW workaround for setting drift */
  11462. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11463. int best_val, int best_period)
  11464. {
  11465. struct bnx2x_func_state_params func_params = {NULL};
  11466. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11467. &func_params.params.set_timesync;
  11468. /* Prepare parameters for function state transitions */
  11469. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11470. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11471. func_params.f_obj = &bp->func_obj;
  11472. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11473. /* Function parameters */
  11474. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11475. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11476. set_timesync_params->add_sub_drift_adjust_value =
  11477. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11478. set_timesync_params->drift_adjust_value = best_val;
  11479. set_timesync_params->drift_adjust_period = best_period;
  11480. return bnx2x_func_state_change(bp, &func_params);
  11481. }
  11482. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11483. {
  11484. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11485. int rc;
  11486. int drift_dir = 1;
  11487. int val, period, period1, period2, dif, dif1, dif2;
  11488. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11489. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11490. if (!netif_running(bp->dev)) {
  11491. DP(BNX2X_MSG_PTP,
  11492. "PTP adjfreq called while the interface is down\n");
  11493. return -ENETDOWN;
  11494. }
  11495. if (ppb < 0) {
  11496. ppb = -ppb;
  11497. drift_dir = 0;
  11498. }
  11499. if (ppb == 0) {
  11500. best_val = 1;
  11501. best_period = 0x1FFFFFF;
  11502. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11503. best_val = 31;
  11504. best_period = 1;
  11505. } else {
  11506. /* Changed not to allow val = 8, 16, 24 as these values
  11507. * are not supported in workaround.
  11508. */
  11509. for (val = 0; val <= 31; val++) {
  11510. if ((val & 0x7) == 0)
  11511. continue;
  11512. period1 = val * 1000000 / ppb;
  11513. period2 = period1 + 1;
  11514. if (period1 != 0)
  11515. dif1 = ppb - (val * 1000000 / period1);
  11516. else
  11517. dif1 = BNX2X_MAX_PHC_DRIFT;
  11518. if (dif1 < 0)
  11519. dif1 = -dif1;
  11520. dif2 = ppb - (val * 1000000 / period2);
  11521. if (dif2 < 0)
  11522. dif2 = -dif2;
  11523. dif = (dif1 < dif2) ? dif1 : dif2;
  11524. period = (dif1 < dif2) ? period1 : period2;
  11525. if (dif < best_dif) {
  11526. best_dif = dif;
  11527. best_val = val;
  11528. best_period = period;
  11529. }
  11530. }
  11531. }
  11532. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11533. best_period);
  11534. if (rc) {
  11535. BNX2X_ERR("Failed to set drift\n");
  11536. return -EFAULT;
  11537. }
  11538. DP(BNX2X_MSG_PTP, "Configured val = %d, period = %d\n", best_val,
  11539. best_period);
  11540. return 0;
  11541. }
  11542. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11543. {
  11544. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11545. if (!netif_running(bp->dev)) {
  11546. DP(BNX2X_MSG_PTP,
  11547. "PTP adjtime called while the interface is down\n");
  11548. return -ENETDOWN;
  11549. }
  11550. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11551. timecounter_adjtime(&bp->timecounter, delta);
  11552. return 0;
  11553. }
  11554. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
  11555. {
  11556. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11557. u64 ns;
  11558. if (!netif_running(bp->dev)) {
  11559. DP(BNX2X_MSG_PTP,
  11560. "PTP gettime called while the interface is down\n");
  11561. return -ENETDOWN;
  11562. }
  11563. ns = timecounter_read(&bp->timecounter);
  11564. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11565. *ts = ns_to_timespec64(ns);
  11566. return 0;
  11567. }
  11568. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11569. const struct timespec64 *ts)
  11570. {
  11571. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11572. u64 ns;
  11573. if (!netif_running(bp->dev)) {
  11574. DP(BNX2X_MSG_PTP,
  11575. "PTP settime called while the interface is down\n");
  11576. return -ENETDOWN;
  11577. }
  11578. ns = timespec64_to_ns(ts);
  11579. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11580. /* Re-init the timecounter */
  11581. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11582. return 0;
  11583. }
  11584. /* Enable (or disable) ancillary features of the phc subsystem */
  11585. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11586. struct ptp_clock_request *rq, int on)
  11587. {
  11588. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11589. BNX2X_ERR("PHC ancillary features are not supported\n");
  11590. return -ENOTSUPP;
  11591. }
  11592. static void bnx2x_register_phc(struct bnx2x *bp)
  11593. {
  11594. /* Fill the ptp_clock_info struct and register PTP clock*/
  11595. bp->ptp_clock_info.owner = THIS_MODULE;
  11596. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11597. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11598. bp->ptp_clock_info.n_alarm = 0;
  11599. bp->ptp_clock_info.n_ext_ts = 0;
  11600. bp->ptp_clock_info.n_per_out = 0;
  11601. bp->ptp_clock_info.pps = 0;
  11602. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11603. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11604. bp->ptp_clock_info.gettime64 = bnx2x_ptp_gettime;
  11605. bp->ptp_clock_info.settime64 = bnx2x_ptp_settime;
  11606. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11607. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11608. if (IS_ERR(bp->ptp_clock)) {
  11609. bp->ptp_clock = NULL;
  11610. BNX2X_ERR("PTP clock registeration failed\n");
  11611. }
  11612. }
  11613. static int bnx2x_init_one(struct pci_dev *pdev,
  11614. const struct pci_device_id *ent)
  11615. {
  11616. struct net_device *dev = NULL;
  11617. struct bnx2x *bp;
  11618. enum pcie_link_width pcie_width;
  11619. enum pci_bus_speed pcie_speed;
  11620. int rc, max_non_def_sbs;
  11621. int rx_count, tx_count, rss_count, doorbell_size;
  11622. int max_cos_est;
  11623. bool is_vf;
  11624. int cnic_cnt;
  11625. /* Management FW 'remembers' living interfaces. Allow it some time
  11626. * to forget previously living interfaces, allowing a proper re-load.
  11627. */
  11628. if (is_kdump_kernel()) {
  11629. ktime_t now = ktime_get_boottime();
  11630. ktime_t fw_ready_time = ktime_set(5, 0);
  11631. if (ktime_before(now, fw_ready_time))
  11632. msleep(ktime_ms_delta(fw_ready_time, now));
  11633. }
  11634. /* An estimated maximum supported CoS number according to the chip
  11635. * version.
  11636. * We will try to roughly estimate the maximum number of CoSes this chip
  11637. * may support in order to minimize the memory allocated for Tx
  11638. * netdev_queue's. This number will be accurately calculated during the
  11639. * initialization of bp->max_cos based on the chip versions AND chip
  11640. * revision in the bnx2x_init_bp().
  11641. */
  11642. max_cos_est = set_max_cos_est(ent->driver_data);
  11643. if (max_cos_est < 0)
  11644. return max_cos_est;
  11645. is_vf = set_is_vf(ent->driver_data);
  11646. cnic_cnt = is_vf ? 0 : 1;
  11647. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11648. /* add another SB for VF as it has no default SB */
  11649. max_non_def_sbs += is_vf ? 1 : 0;
  11650. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11651. rss_count = max_non_def_sbs - cnic_cnt;
  11652. if (rss_count < 1)
  11653. return -EINVAL;
  11654. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11655. rx_count = rss_count + cnic_cnt;
  11656. /* Maximum number of netdev Tx queues:
  11657. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11658. */
  11659. tx_count = rss_count * max_cos_est + cnic_cnt;
  11660. /* dev zeroed in init_etherdev */
  11661. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11662. if (!dev)
  11663. return -ENOMEM;
  11664. bp = netdev_priv(dev);
  11665. bp->flags = 0;
  11666. if (is_vf)
  11667. bp->flags |= IS_VF_FLAG;
  11668. bp->igu_sb_cnt = max_non_def_sbs;
  11669. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11670. bp->msg_enable = debug;
  11671. bp->cnic_support = cnic_cnt;
  11672. bp->cnic_probe = bnx2x_cnic_probe;
  11673. pci_set_drvdata(pdev, dev);
  11674. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11675. if (rc < 0) {
  11676. free_netdev(dev);
  11677. return rc;
  11678. }
  11679. BNX2X_DEV_INFO("This is a %s function\n",
  11680. IS_PF(bp) ? "physical" : "virtual");
  11681. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11682. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11683. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11684. tx_count, rx_count);
  11685. rc = bnx2x_init_bp(bp);
  11686. if (rc)
  11687. goto init_one_exit;
  11688. /* Map doorbells here as we need the real value of bp->max_cos which
  11689. * is initialized in bnx2x_init_bp() to determine the number of
  11690. * l2 connections.
  11691. */
  11692. if (IS_VF(bp)) {
  11693. bp->doorbells = bnx2x_vf_doorbells(bp);
  11694. rc = bnx2x_vf_pci_alloc(bp);
  11695. if (rc)
  11696. goto init_one_freemem;
  11697. } else {
  11698. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11699. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11700. dev_err(&bp->pdev->dev,
  11701. "Cannot map doorbells, bar size too small, aborting\n");
  11702. rc = -ENOMEM;
  11703. goto init_one_freemem;
  11704. }
  11705. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11706. doorbell_size);
  11707. }
  11708. if (!bp->doorbells) {
  11709. dev_err(&bp->pdev->dev,
  11710. "Cannot map doorbell space, aborting\n");
  11711. rc = -ENOMEM;
  11712. goto init_one_freemem;
  11713. }
  11714. if (IS_VF(bp)) {
  11715. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11716. if (rc)
  11717. goto init_one_freemem;
  11718. #ifdef CONFIG_BNX2X_SRIOV
  11719. /* VF with OLD Hypervisor or old PF do not support filtering */
  11720. if (bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER) {
  11721. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11722. dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11723. }
  11724. #endif
  11725. }
  11726. /* Enable SRIOV if capability found in configuration space */
  11727. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11728. if (rc)
  11729. goto init_one_freemem;
  11730. /* calc qm_cid_count */
  11731. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11732. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11733. /* disable FCOE L2 queue for E1x*/
  11734. if (CHIP_IS_E1x(bp))
  11735. bp->flags |= NO_FCOE_FLAG;
  11736. /* Set bp->num_queues for MSI-X mode*/
  11737. bnx2x_set_num_queues(bp);
  11738. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11739. * needed.
  11740. */
  11741. rc = bnx2x_set_int_mode(bp);
  11742. if (rc) {
  11743. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11744. goto init_one_freemem;
  11745. }
  11746. BNX2X_DEV_INFO("set interrupts successfully\n");
  11747. /* register the net device */
  11748. rc = register_netdev(dev);
  11749. if (rc) {
  11750. dev_err(&pdev->dev, "Cannot register net device\n");
  11751. goto init_one_freemem;
  11752. }
  11753. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11754. if (!NO_FCOE(bp)) {
  11755. /* Add storage MAC address */
  11756. rtnl_lock();
  11757. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11758. rtnl_unlock();
  11759. }
  11760. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11761. pcie_speed == PCI_SPEED_UNKNOWN ||
  11762. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11763. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11764. else
  11765. BNX2X_DEV_INFO(
  11766. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11767. board_info[ent->driver_data].name,
  11768. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11769. pcie_width,
  11770. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11771. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11772. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11773. "Unknown",
  11774. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11775. bnx2x_register_phc(bp);
  11776. if (!IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp))
  11777. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_DISABLED);
  11778. return 0;
  11779. init_one_freemem:
  11780. bnx2x_free_mem_bp(bp);
  11781. init_one_exit:
  11782. bnx2x_disable_pcie_error_reporting(bp);
  11783. if (bp->regview)
  11784. iounmap(bp->regview);
  11785. if (IS_PF(bp) && bp->doorbells)
  11786. iounmap(bp->doorbells);
  11787. free_netdev(dev);
  11788. if (atomic_read(&pdev->enable_cnt) == 1)
  11789. pci_release_regions(pdev);
  11790. pci_disable_device(pdev);
  11791. return rc;
  11792. }
  11793. static void __bnx2x_remove(struct pci_dev *pdev,
  11794. struct net_device *dev,
  11795. struct bnx2x *bp,
  11796. bool remove_netdev)
  11797. {
  11798. if (bp->ptp_clock) {
  11799. ptp_clock_unregister(bp->ptp_clock);
  11800. bp->ptp_clock = NULL;
  11801. }
  11802. /* Delete storage MAC address */
  11803. if (!NO_FCOE(bp)) {
  11804. rtnl_lock();
  11805. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11806. rtnl_unlock();
  11807. }
  11808. #ifdef BCM_DCBNL
  11809. /* Delete app tlvs from dcbnl */
  11810. bnx2x_dcbnl_update_applist(bp, true);
  11811. #endif
  11812. if (IS_PF(bp) &&
  11813. !BP_NOMCP(bp) &&
  11814. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11815. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11816. /* Close the interface - either directly or implicitly */
  11817. if (remove_netdev) {
  11818. unregister_netdev(dev);
  11819. } else {
  11820. rtnl_lock();
  11821. dev_close(dev);
  11822. rtnl_unlock();
  11823. }
  11824. bnx2x_iov_remove_one(bp);
  11825. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11826. if (IS_PF(bp)) {
  11827. bnx2x_set_power_state(bp, PCI_D0);
  11828. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_NOT_LOADED);
  11829. /* Set endianity registers to reset values in case next driver
  11830. * boots in different endianty environment.
  11831. */
  11832. bnx2x_reset_endianity(bp);
  11833. }
  11834. /* Disable MSI/MSI-X */
  11835. bnx2x_disable_msi(bp);
  11836. /* Power off */
  11837. if (IS_PF(bp))
  11838. bnx2x_set_power_state(bp, PCI_D3hot);
  11839. /* Make sure RESET task is not scheduled before continuing */
  11840. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11841. /* send message via vfpf channel to release the resources of this vf */
  11842. if (IS_VF(bp))
  11843. bnx2x_vfpf_release(bp);
  11844. /* Assumes no further PCIe PM changes will occur */
  11845. if (system_state == SYSTEM_POWER_OFF) {
  11846. pci_wake_from_d3(pdev, bp->wol);
  11847. pci_set_power_state(pdev, PCI_D3hot);
  11848. }
  11849. bnx2x_disable_pcie_error_reporting(bp);
  11850. if (remove_netdev) {
  11851. if (bp->regview)
  11852. iounmap(bp->regview);
  11853. /* For vfs, doorbells are part of the regview and were unmapped
  11854. * along with it. FW is only loaded by PF.
  11855. */
  11856. if (IS_PF(bp)) {
  11857. if (bp->doorbells)
  11858. iounmap(bp->doorbells);
  11859. bnx2x_release_firmware(bp);
  11860. } else {
  11861. bnx2x_vf_pci_dealloc(bp);
  11862. }
  11863. bnx2x_free_mem_bp(bp);
  11864. free_netdev(dev);
  11865. if (atomic_read(&pdev->enable_cnt) == 1)
  11866. pci_release_regions(pdev);
  11867. pci_disable_device(pdev);
  11868. }
  11869. }
  11870. static void bnx2x_remove_one(struct pci_dev *pdev)
  11871. {
  11872. struct net_device *dev = pci_get_drvdata(pdev);
  11873. struct bnx2x *bp;
  11874. if (!dev) {
  11875. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11876. return;
  11877. }
  11878. bp = netdev_priv(dev);
  11879. __bnx2x_remove(pdev, dev, bp, true);
  11880. }
  11881. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11882. {
  11883. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11884. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11885. if (CNIC_LOADED(bp))
  11886. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11887. /* Stop Tx */
  11888. bnx2x_tx_disable(bp);
  11889. /* Delete all NAPI objects */
  11890. bnx2x_del_all_napi(bp);
  11891. if (CNIC_LOADED(bp))
  11892. bnx2x_del_all_napi_cnic(bp);
  11893. netdev_reset_tc(bp->dev);
  11894. del_timer_sync(&bp->timer);
  11895. cancel_delayed_work_sync(&bp->sp_task);
  11896. cancel_delayed_work_sync(&bp->period_task);
  11897. if (!down_timeout(&bp->stats_lock, HZ / 10)) {
  11898. bp->stats_state = STATS_STATE_DISABLED;
  11899. up(&bp->stats_lock);
  11900. }
  11901. bnx2x_save_statistics(bp);
  11902. netif_carrier_off(bp->dev);
  11903. return 0;
  11904. }
  11905. /**
  11906. * bnx2x_io_error_detected - called when PCI error is detected
  11907. * @pdev: Pointer to PCI device
  11908. * @state: The current pci connection state
  11909. *
  11910. * This function is called after a PCI bus error affecting
  11911. * this device has been detected.
  11912. */
  11913. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11914. pci_channel_state_t state)
  11915. {
  11916. struct net_device *dev = pci_get_drvdata(pdev);
  11917. struct bnx2x *bp = netdev_priv(dev);
  11918. rtnl_lock();
  11919. BNX2X_ERR("IO error detected\n");
  11920. netif_device_detach(dev);
  11921. if (state == pci_channel_io_perm_failure) {
  11922. rtnl_unlock();
  11923. return PCI_ERS_RESULT_DISCONNECT;
  11924. }
  11925. if (netif_running(dev))
  11926. bnx2x_eeh_nic_unload(bp);
  11927. bnx2x_prev_path_mark_eeh(bp);
  11928. pci_disable_device(pdev);
  11929. rtnl_unlock();
  11930. /* Request a slot reset */
  11931. return PCI_ERS_RESULT_NEED_RESET;
  11932. }
  11933. /**
  11934. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11935. * @pdev: Pointer to PCI device
  11936. *
  11937. * Restart the card from scratch, as if from a cold-boot.
  11938. */
  11939. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11940. {
  11941. struct net_device *dev = pci_get_drvdata(pdev);
  11942. struct bnx2x *bp = netdev_priv(dev);
  11943. int i;
  11944. rtnl_lock();
  11945. BNX2X_ERR("IO slot reset initializing...\n");
  11946. if (pci_enable_device(pdev)) {
  11947. dev_err(&pdev->dev,
  11948. "Cannot re-enable PCI device after reset\n");
  11949. rtnl_unlock();
  11950. return PCI_ERS_RESULT_DISCONNECT;
  11951. }
  11952. pci_set_master(pdev);
  11953. pci_restore_state(pdev);
  11954. pci_save_state(pdev);
  11955. if (netif_running(dev))
  11956. bnx2x_set_power_state(bp, PCI_D0);
  11957. if (netif_running(dev)) {
  11958. BNX2X_ERR("IO slot reset --> driver unload\n");
  11959. /* MCP should have been reset; Need to wait for validity */
  11960. if (bnx2x_init_shmem(bp)) {
  11961. rtnl_unlock();
  11962. return PCI_ERS_RESULT_DISCONNECT;
  11963. }
  11964. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11965. u32 v;
  11966. v = SHMEM2_RD(bp,
  11967. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11968. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11969. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11970. }
  11971. bnx2x_drain_tx_queues(bp);
  11972. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11973. bnx2x_netif_stop(bp, 1);
  11974. bnx2x_free_irq(bp);
  11975. /* Report UNLOAD_DONE to MCP */
  11976. bnx2x_send_unload_done(bp, true);
  11977. bp->sp_state = 0;
  11978. bp->port.pmf = 0;
  11979. bnx2x_prev_unload(bp);
  11980. /* We should have reseted the engine, so It's fair to
  11981. * assume the FW will no longer write to the bnx2x driver.
  11982. */
  11983. bnx2x_squeeze_objects(bp);
  11984. bnx2x_free_skbs(bp);
  11985. for_each_rx_queue(bp, i)
  11986. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11987. bnx2x_free_fp_mem(bp);
  11988. bnx2x_free_mem(bp);
  11989. bp->state = BNX2X_STATE_CLOSED;
  11990. }
  11991. rtnl_unlock();
  11992. /* If AER, perform cleanup of the PCIe registers */
  11993. if (bp->flags & AER_ENABLED) {
  11994. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11995. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11996. else
  11997. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11998. }
  11999. return PCI_ERS_RESULT_RECOVERED;
  12000. }
  12001. /**
  12002. * bnx2x_io_resume - called when traffic can start flowing again
  12003. * @pdev: Pointer to PCI device
  12004. *
  12005. * This callback is called when the error recovery driver tells us that
  12006. * its OK to resume normal operation.
  12007. */
  12008. static void bnx2x_io_resume(struct pci_dev *pdev)
  12009. {
  12010. struct net_device *dev = pci_get_drvdata(pdev);
  12011. struct bnx2x *bp = netdev_priv(dev);
  12012. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  12013. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  12014. return;
  12015. }
  12016. rtnl_lock();
  12017. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  12018. DRV_MSG_SEQ_NUMBER_MASK;
  12019. if (netif_running(dev))
  12020. bnx2x_nic_load(bp, LOAD_NORMAL);
  12021. netif_device_attach(dev);
  12022. rtnl_unlock();
  12023. }
  12024. static const struct pci_error_handlers bnx2x_err_handler = {
  12025. .error_detected = bnx2x_io_error_detected,
  12026. .slot_reset = bnx2x_io_slot_reset,
  12027. .resume = bnx2x_io_resume,
  12028. };
  12029. static void bnx2x_shutdown(struct pci_dev *pdev)
  12030. {
  12031. struct net_device *dev = pci_get_drvdata(pdev);
  12032. struct bnx2x *bp;
  12033. if (!dev)
  12034. return;
  12035. bp = netdev_priv(dev);
  12036. if (!bp)
  12037. return;
  12038. rtnl_lock();
  12039. netif_device_detach(dev);
  12040. rtnl_unlock();
  12041. /* Don't remove the netdevice, as there are scenarios which will cause
  12042. * the kernel to hang, e.g., when trying to remove bnx2i while the
  12043. * rootfs is mounted from SAN.
  12044. */
  12045. __bnx2x_remove(pdev, dev, bp, false);
  12046. }
  12047. static struct pci_driver bnx2x_pci_driver = {
  12048. .name = DRV_MODULE_NAME,
  12049. .id_table = bnx2x_pci_tbl,
  12050. .probe = bnx2x_init_one,
  12051. .remove = bnx2x_remove_one,
  12052. .suspend = bnx2x_suspend,
  12053. .resume = bnx2x_resume,
  12054. .err_handler = &bnx2x_err_handler,
  12055. #ifdef CONFIG_BNX2X_SRIOV
  12056. .sriov_configure = bnx2x_sriov_configure,
  12057. #endif
  12058. .shutdown = bnx2x_shutdown,
  12059. };
  12060. static int __init bnx2x_init(void)
  12061. {
  12062. int ret;
  12063. pr_info("%s", version);
  12064. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  12065. if (bnx2x_wq == NULL) {
  12066. pr_err("Cannot create workqueue\n");
  12067. return -ENOMEM;
  12068. }
  12069. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  12070. if (!bnx2x_iov_wq) {
  12071. pr_err("Cannot create iov workqueue\n");
  12072. destroy_workqueue(bnx2x_wq);
  12073. return -ENOMEM;
  12074. }
  12075. ret = pci_register_driver(&bnx2x_pci_driver);
  12076. if (ret) {
  12077. pr_err("Cannot register driver\n");
  12078. destroy_workqueue(bnx2x_wq);
  12079. destroy_workqueue(bnx2x_iov_wq);
  12080. }
  12081. return ret;
  12082. }
  12083. static void __exit bnx2x_cleanup(void)
  12084. {
  12085. struct list_head *pos, *q;
  12086. pci_unregister_driver(&bnx2x_pci_driver);
  12087. destroy_workqueue(bnx2x_wq);
  12088. destroy_workqueue(bnx2x_iov_wq);
  12089. /* Free globally allocated resources */
  12090. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  12091. struct bnx2x_prev_path_list *tmp =
  12092. list_entry(pos, struct bnx2x_prev_path_list, list);
  12093. list_del(pos);
  12094. kfree(tmp);
  12095. }
  12096. }
  12097. void bnx2x_notify_link_changed(struct bnx2x *bp)
  12098. {
  12099. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  12100. }
  12101. module_init(bnx2x_init);
  12102. module_exit(bnx2x_cleanup);
  12103. /**
  12104. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  12105. *
  12106. * @bp: driver handle
  12107. * @set: set or clear the CAM entry
  12108. *
  12109. * This function will wait until the ramrod completion returns.
  12110. * Return 0 if success, -ENODEV if ramrod doesn't return.
  12111. */
  12112. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  12113. {
  12114. unsigned long ramrod_flags = 0;
  12115. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  12116. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  12117. &bp->iscsi_l2_mac_obj, true,
  12118. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  12119. }
  12120. /* count denotes the number of new completions we have seen */
  12121. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  12122. {
  12123. struct eth_spe *spe;
  12124. int cxt_index, cxt_offset;
  12125. #ifdef BNX2X_STOP_ON_ERROR
  12126. if (unlikely(bp->panic))
  12127. return;
  12128. #endif
  12129. spin_lock_bh(&bp->spq_lock);
  12130. BUG_ON(bp->cnic_spq_pending < count);
  12131. bp->cnic_spq_pending -= count;
  12132. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  12133. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  12134. & SPE_HDR_CONN_TYPE) >>
  12135. SPE_HDR_CONN_TYPE_SHIFT;
  12136. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  12137. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  12138. /* Set validation for iSCSI L2 client before sending SETUP
  12139. * ramrod
  12140. */
  12141. if (type == ETH_CONNECTION_TYPE) {
  12142. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  12143. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  12144. ILT_PAGE_CIDS;
  12145. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  12146. (cxt_index * ILT_PAGE_CIDS);
  12147. bnx2x_set_ctx_validation(bp,
  12148. &bp->context[cxt_index].
  12149. vcxt[cxt_offset].eth,
  12150. BNX2X_ISCSI_ETH_CID(bp));
  12151. }
  12152. }
  12153. /*
  12154. * There may be not more than 8 L2, not more than 8 L5 SPEs
  12155. * and in the air. We also check that number of outstanding
  12156. * COMMON ramrods is not more than the EQ and SPQ can
  12157. * accommodate.
  12158. */
  12159. if (type == ETH_CONNECTION_TYPE) {
  12160. if (!atomic_read(&bp->cq_spq_left))
  12161. break;
  12162. else
  12163. atomic_dec(&bp->cq_spq_left);
  12164. } else if (type == NONE_CONNECTION_TYPE) {
  12165. if (!atomic_read(&bp->eq_spq_left))
  12166. break;
  12167. else
  12168. atomic_dec(&bp->eq_spq_left);
  12169. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  12170. (type == FCOE_CONNECTION_TYPE)) {
  12171. if (bp->cnic_spq_pending >=
  12172. bp->cnic_eth_dev.max_kwqe_pending)
  12173. break;
  12174. else
  12175. bp->cnic_spq_pending++;
  12176. } else {
  12177. BNX2X_ERR("Unknown SPE type: %d\n", type);
  12178. bnx2x_panic();
  12179. break;
  12180. }
  12181. spe = bnx2x_sp_get_next(bp);
  12182. *spe = *bp->cnic_kwq_cons;
  12183. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  12184. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  12185. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  12186. bp->cnic_kwq_cons = bp->cnic_kwq;
  12187. else
  12188. bp->cnic_kwq_cons++;
  12189. }
  12190. bnx2x_sp_prod_update(bp);
  12191. spin_unlock_bh(&bp->spq_lock);
  12192. }
  12193. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  12194. struct kwqe_16 *kwqes[], u32 count)
  12195. {
  12196. struct bnx2x *bp = netdev_priv(dev);
  12197. int i;
  12198. #ifdef BNX2X_STOP_ON_ERROR
  12199. if (unlikely(bp->panic)) {
  12200. BNX2X_ERR("Can't post to SP queue while panic\n");
  12201. return -EIO;
  12202. }
  12203. #endif
  12204. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  12205. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  12206. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  12207. return -EAGAIN;
  12208. }
  12209. spin_lock_bh(&bp->spq_lock);
  12210. for (i = 0; i < count; i++) {
  12211. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  12212. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  12213. break;
  12214. *bp->cnic_kwq_prod = *spe;
  12215. bp->cnic_kwq_pending++;
  12216. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  12217. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  12218. spe->data.update_data_addr.hi,
  12219. spe->data.update_data_addr.lo,
  12220. bp->cnic_kwq_pending);
  12221. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  12222. bp->cnic_kwq_prod = bp->cnic_kwq;
  12223. else
  12224. bp->cnic_kwq_prod++;
  12225. }
  12226. spin_unlock_bh(&bp->spq_lock);
  12227. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  12228. bnx2x_cnic_sp_post(bp, 0);
  12229. return i;
  12230. }
  12231. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12232. {
  12233. struct cnic_ops *c_ops;
  12234. int rc = 0;
  12235. mutex_lock(&bp->cnic_mutex);
  12236. c_ops = rcu_dereference_protected(bp->cnic_ops,
  12237. lockdep_is_held(&bp->cnic_mutex));
  12238. if (c_ops)
  12239. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12240. mutex_unlock(&bp->cnic_mutex);
  12241. return rc;
  12242. }
  12243. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12244. {
  12245. struct cnic_ops *c_ops;
  12246. int rc = 0;
  12247. rcu_read_lock();
  12248. c_ops = rcu_dereference(bp->cnic_ops);
  12249. if (c_ops)
  12250. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12251. rcu_read_unlock();
  12252. return rc;
  12253. }
  12254. /*
  12255. * for commands that have no data
  12256. */
  12257. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  12258. {
  12259. struct cnic_ctl_info ctl = {0};
  12260. ctl.cmd = cmd;
  12261. return bnx2x_cnic_ctl_send(bp, &ctl);
  12262. }
  12263. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  12264. {
  12265. struct cnic_ctl_info ctl = {0};
  12266. /* first we tell CNIC and only then we count this as a completion */
  12267. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  12268. ctl.data.comp.cid = cid;
  12269. ctl.data.comp.error = err;
  12270. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  12271. bnx2x_cnic_sp_post(bp, 0);
  12272. }
  12273. /* Called with netif_addr_lock_bh() taken.
  12274. * Sets an rx_mode config for an iSCSI ETH client.
  12275. * Doesn't block.
  12276. * Completion should be checked outside.
  12277. */
  12278. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  12279. {
  12280. unsigned long accept_flags = 0, ramrod_flags = 0;
  12281. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12282. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  12283. if (start) {
  12284. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  12285. * because it's the only way for UIO Queue to accept
  12286. * multicasts (in non-promiscuous mode only one Queue per
  12287. * function will receive multicast packets (leading in our
  12288. * case).
  12289. */
  12290. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  12291. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  12292. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  12293. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  12294. /* Clear STOP_PENDING bit if START is requested */
  12295. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  12296. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  12297. } else
  12298. /* Clear START_PENDING bit if STOP is requested */
  12299. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  12300. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  12301. set_bit(sched_state, &bp->sp_state);
  12302. else {
  12303. __set_bit(RAMROD_RX, &ramrod_flags);
  12304. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  12305. ramrod_flags);
  12306. }
  12307. }
  12308. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  12309. {
  12310. struct bnx2x *bp = netdev_priv(dev);
  12311. int rc = 0;
  12312. switch (ctl->cmd) {
  12313. case DRV_CTL_CTXTBL_WR_CMD: {
  12314. u32 index = ctl->data.io.offset;
  12315. dma_addr_t addr = ctl->data.io.dma_addr;
  12316. bnx2x_ilt_wr(bp, index, addr);
  12317. break;
  12318. }
  12319. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  12320. int count = ctl->data.credit.credit_count;
  12321. bnx2x_cnic_sp_post(bp, count);
  12322. break;
  12323. }
  12324. /* rtnl_lock is held. */
  12325. case DRV_CTL_START_L2_CMD: {
  12326. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12327. unsigned long sp_bits = 0;
  12328. /* Configure the iSCSI classification object */
  12329. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  12330. cp->iscsi_l2_client_id,
  12331. cp->iscsi_l2_cid, BP_FUNC(bp),
  12332. bnx2x_sp(bp, mac_rdata),
  12333. bnx2x_sp_mapping(bp, mac_rdata),
  12334. BNX2X_FILTER_MAC_PENDING,
  12335. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  12336. &bp->macs_pool);
  12337. /* Set iSCSI MAC address */
  12338. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  12339. if (rc)
  12340. break;
  12341. mmiowb();
  12342. barrier();
  12343. /* Start accepting on iSCSI L2 ring */
  12344. netif_addr_lock_bh(dev);
  12345. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  12346. netif_addr_unlock_bh(dev);
  12347. /* bits to wait on */
  12348. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12349. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  12350. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12351. BNX2X_ERR("rx_mode completion timed out!\n");
  12352. break;
  12353. }
  12354. /* rtnl_lock is held. */
  12355. case DRV_CTL_STOP_L2_CMD: {
  12356. unsigned long sp_bits = 0;
  12357. /* Stop accepting on iSCSI L2 ring */
  12358. netif_addr_lock_bh(dev);
  12359. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  12360. netif_addr_unlock_bh(dev);
  12361. /* bits to wait on */
  12362. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12363. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  12364. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12365. BNX2X_ERR("rx_mode completion timed out!\n");
  12366. mmiowb();
  12367. barrier();
  12368. /* Unset iSCSI L2 MAC */
  12369. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  12370. BNX2X_ISCSI_ETH_MAC, true);
  12371. break;
  12372. }
  12373. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  12374. int count = ctl->data.credit.credit_count;
  12375. smp_mb__before_atomic();
  12376. atomic_add(count, &bp->cq_spq_left);
  12377. smp_mb__after_atomic();
  12378. break;
  12379. }
  12380. case DRV_CTL_ULP_REGISTER_CMD: {
  12381. int ulp_type = ctl->data.register_data.ulp_type;
  12382. if (CHIP_IS_E3(bp)) {
  12383. int idx = BP_FW_MB_IDX(bp);
  12384. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12385. int path = BP_PATH(bp);
  12386. int port = BP_PORT(bp);
  12387. int i;
  12388. u32 scratch_offset;
  12389. u32 *host_addr;
  12390. /* first write capability to shmem2 */
  12391. if (ulp_type == CNIC_ULP_ISCSI)
  12392. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12393. else if (ulp_type == CNIC_ULP_FCOE)
  12394. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12395. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12396. if ((ulp_type != CNIC_ULP_FCOE) ||
  12397. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  12398. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  12399. break;
  12400. /* if reached here - should write fcoe capabilities */
  12401. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  12402. if (!scratch_offset)
  12403. break;
  12404. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  12405. fcoe_features[path][port]);
  12406. host_addr = (u32 *) &(ctl->data.register_data.
  12407. fcoe_features);
  12408. for (i = 0; i < sizeof(struct fcoe_capabilities);
  12409. i += 4)
  12410. REG_WR(bp, scratch_offset + i,
  12411. *(host_addr + i/4));
  12412. }
  12413. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12414. break;
  12415. }
  12416. case DRV_CTL_ULP_UNREGISTER_CMD: {
  12417. int ulp_type = ctl->data.ulp_type;
  12418. if (CHIP_IS_E3(bp)) {
  12419. int idx = BP_FW_MB_IDX(bp);
  12420. u32 cap;
  12421. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12422. if (ulp_type == CNIC_ULP_ISCSI)
  12423. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12424. else if (ulp_type == CNIC_ULP_FCOE)
  12425. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12426. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12427. }
  12428. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12429. break;
  12430. }
  12431. default:
  12432. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12433. rc = -EINVAL;
  12434. }
  12435. /* For storage-only interfaces, change driver state */
  12436. if (IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp)) {
  12437. switch (ctl->drv_state) {
  12438. case DRV_NOP:
  12439. break;
  12440. case DRV_ACTIVE:
  12441. bnx2x_set_os_driver_state(bp,
  12442. OS_DRIVER_STATE_ACTIVE);
  12443. break;
  12444. case DRV_INACTIVE:
  12445. bnx2x_set_os_driver_state(bp,
  12446. OS_DRIVER_STATE_DISABLED);
  12447. break;
  12448. case DRV_UNLOADED:
  12449. bnx2x_set_os_driver_state(bp,
  12450. OS_DRIVER_STATE_NOT_LOADED);
  12451. break;
  12452. default:
  12453. BNX2X_ERR("Unknown cnic driver state: %d\n", ctl->drv_state);
  12454. }
  12455. }
  12456. return rc;
  12457. }
  12458. static int bnx2x_get_fc_npiv(struct net_device *dev,
  12459. struct cnic_fc_npiv_tbl *cnic_tbl)
  12460. {
  12461. struct bnx2x *bp = netdev_priv(dev);
  12462. struct bdn_fc_npiv_tbl *tbl = NULL;
  12463. u32 offset, entries;
  12464. int rc = -EINVAL;
  12465. int i;
  12466. if (!SHMEM2_HAS(bp, fc_npiv_nvram_tbl_addr[0]))
  12467. goto out;
  12468. DP(BNX2X_MSG_MCP, "About to read the FC-NPIV table\n");
  12469. tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
  12470. if (!tbl) {
  12471. BNX2X_ERR("Failed to allocate fc_npiv table\n");
  12472. goto out;
  12473. }
  12474. offset = SHMEM2_RD(bp, fc_npiv_nvram_tbl_addr[BP_PORT(bp)]);
  12475. if (!offset) {
  12476. DP(BNX2X_MSG_MCP, "No FC-NPIV in NVRAM\n");
  12477. goto out;
  12478. }
  12479. DP(BNX2X_MSG_MCP, "Offset of FC-NPIV in NVRAM: %08x\n", offset);
  12480. /* Read the table contents from nvram */
  12481. if (bnx2x_nvram_read(bp, offset, (u8 *)tbl, sizeof(*tbl))) {
  12482. BNX2X_ERR("Failed to read FC-NPIV table\n");
  12483. goto out;
  12484. }
  12485. /* Since bnx2x_nvram_read() returns data in be32, we need to convert
  12486. * the number of entries back to cpu endianness.
  12487. */
  12488. entries = tbl->fc_npiv_cfg.num_of_npiv;
  12489. entries = (__force u32)be32_to_cpu((__force __be32)entries);
  12490. tbl->fc_npiv_cfg.num_of_npiv = entries;
  12491. if (!tbl->fc_npiv_cfg.num_of_npiv) {
  12492. DP(BNX2X_MSG_MCP,
  12493. "No FC-NPIV table [valid, simply not present]\n");
  12494. goto out;
  12495. } else if (tbl->fc_npiv_cfg.num_of_npiv > MAX_NUMBER_NPIV) {
  12496. BNX2X_ERR("FC-NPIV table with bad length 0x%08x\n",
  12497. tbl->fc_npiv_cfg.num_of_npiv);
  12498. goto out;
  12499. } else {
  12500. DP(BNX2X_MSG_MCP, "Read 0x%08x entries from NVRAM\n",
  12501. tbl->fc_npiv_cfg.num_of_npiv);
  12502. }
  12503. /* Copy the data into cnic-provided struct */
  12504. cnic_tbl->count = tbl->fc_npiv_cfg.num_of_npiv;
  12505. for (i = 0; i < cnic_tbl->count; i++) {
  12506. memcpy(cnic_tbl->wwpn[i], tbl->settings[i].npiv_wwpn, 8);
  12507. memcpy(cnic_tbl->wwnn[i], tbl->settings[i].npiv_wwnn, 8);
  12508. }
  12509. rc = 0;
  12510. out:
  12511. kfree(tbl);
  12512. return rc;
  12513. }
  12514. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12515. {
  12516. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12517. if (bp->flags & USING_MSIX_FLAG) {
  12518. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12519. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12520. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12521. } else {
  12522. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12523. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12524. }
  12525. if (!CHIP_IS_E1x(bp))
  12526. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12527. else
  12528. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12529. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12530. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12531. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12532. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12533. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12534. cp->num_irq = 2;
  12535. }
  12536. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12537. {
  12538. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12539. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12540. bnx2x_cid_ilt_lines(bp);
  12541. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12542. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12543. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12544. DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
  12545. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12546. cp->iscsi_l2_cid);
  12547. if (NO_ISCSI_OOO(bp))
  12548. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12549. }
  12550. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12551. void *data)
  12552. {
  12553. struct bnx2x *bp = netdev_priv(dev);
  12554. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12555. int rc;
  12556. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12557. if (ops == NULL) {
  12558. BNX2X_ERR("NULL ops received\n");
  12559. return -EINVAL;
  12560. }
  12561. if (!CNIC_SUPPORT(bp)) {
  12562. BNX2X_ERR("Can't register CNIC when not supported\n");
  12563. return -EOPNOTSUPP;
  12564. }
  12565. if (!CNIC_LOADED(bp)) {
  12566. rc = bnx2x_load_cnic(bp);
  12567. if (rc) {
  12568. BNX2X_ERR("CNIC-related load failed\n");
  12569. return rc;
  12570. }
  12571. }
  12572. bp->cnic_enabled = true;
  12573. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12574. if (!bp->cnic_kwq)
  12575. return -ENOMEM;
  12576. bp->cnic_kwq_cons = bp->cnic_kwq;
  12577. bp->cnic_kwq_prod = bp->cnic_kwq;
  12578. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12579. bp->cnic_spq_pending = 0;
  12580. bp->cnic_kwq_pending = 0;
  12581. bp->cnic_data = data;
  12582. cp->num_irq = 0;
  12583. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12584. cp->iro_arr = bp->iro_arr;
  12585. bnx2x_setup_cnic_irq_info(bp);
  12586. rcu_assign_pointer(bp->cnic_ops, ops);
  12587. /* Schedule driver to read CNIC driver versions */
  12588. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12589. return 0;
  12590. }
  12591. static int bnx2x_unregister_cnic(struct net_device *dev)
  12592. {
  12593. struct bnx2x *bp = netdev_priv(dev);
  12594. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12595. mutex_lock(&bp->cnic_mutex);
  12596. cp->drv_state = 0;
  12597. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12598. mutex_unlock(&bp->cnic_mutex);
  12599. synchronize_rcu();
  12600. bp->cnic_enabled = false;
  12601. kfree(bp->cnic_kwq);
  12602. bp->cnic_kwq = NULL;
  12603. return 0;
  12604. }
  12605. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12606. {
  12607. struct bnx2x *bp = netdev_priv(dev);
  12608. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12609. /* If both iSCSI and FCoE are disabled - return NULL in
  12610. * order to indicate CNIC that it should not try to work
  12611. * with this device.
  12612. */
  12613. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12614. return NULL;
  12615. cp->drv_owner = THIS_MODULE;
  12616. cp->chip_id = CHIP_ID(bp);
  12617. cp->pdev = bp->pdev;
  12618. cp->io_base = bp->regview;
  12619. cp->io_base2 = bp->doorbells;
  12620. cp->max_kwqe_pending = 8;
  12621. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12622. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12623. bnx2x_cid_ilt_lines(bp);
  12624. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12625. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12626. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12627. cp->drv_ctl = bnx2x_drv_ctl;
  12628. cp->drv_get_fc_npiv_tbl = bnx2x_get_fc_npiv;
  12629. cp->drv_register_cnic = bnx2x_register_cnic;
  12630. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12631. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12632. cp->iscsi_l2_client_id =
  12633. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12634. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12635. if (NO_ISCSI_OOO(bp))
  12636. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12637. if (NO_ISCSI(bp))
  12638. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12639. if (NO_FCOE(bp))
  12640. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12641. BNX2X_DEV_INFO(
  12642. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12643. cp->ctx_blk_size,
  12644. cp->ctx_tbl_offset,
  12645. cp->ctx_tbl_len,
  12646. cp->starting_cid);
  12647. return cp;
  12648. }
  12649. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12650. {
  12651. struct bnx2x *bp = fp->bp;
  12652. u32 offset = BAR_USTRORM_INTMEM;
  12653. if (IS_VF(bp))
  12654. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12655. else if (!CHIP_IS_E1x(bp))
  12656. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12657. else
  12658. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12659. return offset;
  12660. }
  12661. /* called only on E1H or E2.
  12662. * When pretending to be PF, the pretend value is the function number 0...7
  12663. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12664. * combination
  12665. */
  12666. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12667. {
  12668. u32 pretend_reg;
  12669. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12670. return -1;
  12671. /* get my own pretend register */
  12672. pretend_reg = bnx2x_get_pretend_reg(bp);
  12673. REG_WR(bp, pretend_reg, pretend_func_val);
  12674. REG_RD(bp, pretend_reg);
  12675. return 0;
  12676. }
  12677. static void bnx2x_ptp_task(struct work_struct *work)
  12678. {
  12679. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12680. int port = BP_PORT(bp);
  12681. u32 val_seq;
  12682. u64 timestamp, ns;
  12683. struct skb_shared_hwtstamps shhwtstamps;
  12684. /* Read Tx timestamp registers */
  12685. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12686. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12687. if (val_seq & 0x10000) {
  12688. /* There is a valid timestamp value */
  12689. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12690. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12691. timestamp <<= 32;
  12692. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12693. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12694. /* Reset timestamp register to allow new timestamp */
  12695. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12696. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12697. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12698. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12699. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12700. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12701. dev_kfree_skb_any(bp->ptp_tx_skb);
  12702. bp->ptp_tx_skb = NULL;
  12703. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12704. timestamp, ns);
  12705. } else {
  12706. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12707. /* Reschedule to keep checking for a valid timestamp value */
  12708. schedule_work(&bp->ptp_task);
  12709. }
  12710. }
  12711. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12712. {
  12713. int port = BP_PORT(bp);
  12714. u64 timestamp, ns;
  12715. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12716. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12717. timestamp <<= 32;
  12718. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12719. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12720. /* Reset timestamp register to allow new timestamp */
  12721. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12722. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12723. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12724. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12725. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12726. timestamp, ns);
  12727. }
  12728. /* Read the PHC */
  12729. static cycle_t bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12730. {
  12731. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12732. int port = BP_PORT(bp);
  12733. u32 wb_data[2];
  12734. u64 phc_cycles;
  12735. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12736. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12737. phc_cycles = wb_data[1];
  12738. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12739. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12740. return phc_cycles;
  12741. }
  12742. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12743. {
  12744. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12745. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12746. bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
  12747. bp->cyclecounter.shift = 0;
  12748. bp->cyclecounter.mult = 1;
  12749. }
  12750. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12751. {
  12752. struct bnx2x_func_state_params func_params = {NULL};
  12753. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12754. &func_params.params.set_timesync;
  12755. /* Prepare parameters for function state transitions */
  12756. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12757. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12758. func_params.f_obj = &bp->func_obj;
  12759. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12760. /* Function parameters */
  12761. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12762. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12763. return bnx2x_func_state_change(bp, &func_params);
  12764. }
  12765. static int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12766. {
  12767. struct bnx2x_queue_state_params q_params;
  12768. int rc, i;
  12769. /* send queue update ramrod to enable PTP packets */
  12770. memset(&q_params, 0, sizeof(q_params));
  12771. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12772. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12773. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12774. &q_params.params.update.update_flags);
  12775. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12776. &q_params.params.update.update_flags);
  12777. /* send the ramrod on all the queues of the PF */
  12778. for_each_eth_queue(bp, i) {
  12779. struct bnx2x_fastpath *fp = &bp->fp[i];
  12780. /* Set the appropriate Queue object */
  12781. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12782. /* Update the Queue state */
  12783. rc = bnx2x_queue_state_change(bp, &q_params);
  12784. if (rc) {
  12785. BNX2X_ERR("Failed to enable PTP packets\n");
  12786. return rc;
  12787. }
  12788. }
  12789. return 0;
  12790. }
  12791. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12792. {
  12793. int port = BP_PORT(bp);
  12794. int rc;
  12795. if (!bp->hwtstamp_ioctl_called)
  12796. return 0;
  12797. switch (bp->tx_type) {
  12798. case HWTSTAMP_TX_ON:
  12799. bp->flags |= TX_TIMESTAMPING_EN;
  12800. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12801. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12802. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12803. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12804. break;
  12805. case HWTSTAMP_TX_ONESTEP_SYNC:
  12806. BNX2X_ERR("One-step timestamping is not supported\n");
  12807. return -ERANGE;
  12808. }
  12809. switch (bp->rx_filter) {
  12810. case HWTSTAMP_FILTER_NONE:
  12811. break;
  12812. case HWTSTAMP_FILTER_ALL:
  12813. case HWTSTAMP_FILTER_SOME:
  12814. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12815. break;
  12816. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12817. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12818. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12819. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12820. /* Initialize PTP detection for UDP/IPv4 events */
  12821. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12822. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12823. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12824. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12825. break;
  12826. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12827. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12828. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12829. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12830. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12831. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12832. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12833. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12834. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12835. break;
  12836. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12837. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12838. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12839. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12840. /* Initialize PTP detection L2 events */
  12841. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12842. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12843. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12844. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12845. break;
  12846. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12847. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12848. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12849. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12850. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12851. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12852. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12853. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12854. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12855. break;
  12856. }
  12857. /* Indicate to FW that this PF expects recorded PTP packets */
  12858. rc = bnx2x_enable_ptp_packets(bp);
  12859. if (rc)
  12860. return rc;
  12861. /* Enable sending PTP packets to host */
  12862. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12863. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12864. return 0;
  12865. }
  12866. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12867. {
  12868. struct hwtstamp_config config;
  12869. int rc;
  12870. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12871. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12872. return -EFAULT;
  12873. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12874. config.tx_type, config.rx_filter);
  12875. if (config.flags) {
  12876. BNX2X_ERR("config.flags is reserved for future use\n");
  12877. return -EINVAL;
  12878. }
  12879. bp->hwtstamp_ioctl_called = 1;
  12880. bp->tx_type = config.tx_type;
  12881. bp->rx_filter = config.rx_filter;
  12882. rc = bnx2x_configure_ptp_filters(bp);
  12883. if (rc)
  12884. return rc;
  12885. config.rx_filter = bp->rx_filter;
  12886. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12887. -EFAULT : 0;
  12888. }
  12889. /* Configures HW for PTP */
  12890. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12891. {
  12892. int rc, port = BP_PORT(bp);
  12893. u32 wb_data[2];
  12894. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12895. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12896. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12897. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12898. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12899. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12900. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12901. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12902. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12903. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12904. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12905. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12906. /* Enable the PTP feature */
  12907. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12908. NIG_REG_P0_PTP_EN, 0x3F);
  12909. /* Enable the free-running counter */
  12910. wb_data[0] = 0;
  12911. wb_data[1] = 0;
  12912. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12913. /* Reset drift register (offset register is not reset) */
  12914. rc = bnx2x_send_reset_timesync_ramrod(bp);
  12915. if (rc) {
  12916. BNX2X_ERR("Failed to reset PHC drift register\n");
  12917. return -EFAULT;
  12918. }
  12919. /* Reset possibly old timestamps */
  12920. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12921. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12922. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12923. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12924. return 0;
  12925. }
  12926. /* Called during load, to initialize PTP-related stuff */
  12927. void bnx2x_init_ptp(struct bnx2x *bp)
  12928. {
  12929. int rc;
  12930. /* Configure PTP in HW */
  12931. rc = bnx2x_configure_ptp(bp);
  12932. if (rc) {
  12933. BNX2X_ERR("Stopping PTP initialization\n");
  12934. return;
  12935. }
  12936. /* Init work queue for Tx timestamping */
  12937. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  12938. /* Init cyclecounter and timecounter. This is done only in the first
  12939. * load. If done in every load, PTP application will fail when doing
  12940. * unload / load (e.g. MTU change) while it is running.
  12941. */
  12942. if (!bp->timecounter_init_done) {
  12943. bnx2x_init_cyclecounter(bp);
  12944. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  12945. ktime_to_ns(ktime_get_real()));
  12946. bp->timecounter_init_done = 1;
  12947. }
  12948. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  12949. }