bnx2x_main.c 422 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606
  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. #define FW_FILE_VERSION \
  71. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  72. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  73. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  74. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  75. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  76. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  77. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  78. /* Time in jiffies before concluding the transmitter is hung */
  79. #define TX_TIMEOUT (5*HZ)
  80. static char version[] =
  81. "QLogic 5771x/578xx 10/20-Gigabit Ethernet Driver "
  82. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  83. MODULE_AUTHOR("Eliezer Tamir");
  84. MODULE_DESCRIPTION("QLogic "
  85. "BCM57710/57711/57711E/"
  86. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  87. "57840/57840_MF Driver");
  88. MODULE_LICENSE("GPL");
  89. MODULE_VERSION(DRV_MODULE_VERSION);
  90. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  91. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  92. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  93. int bnx2x_num_queues;
  94. module_param_named(num_queues, bnx2x_num_queues, int, 0444);
  95. MODULE_PARM_DESC(num_queues,
  96. " Set number of queues (default is as a number of CPUs)");
  97. static int disable_tpa;
  98. module_param(disable_tpa, int, 0444);
  99. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  100. static int int_mode;
  101. module_param(int_mode, int, 0444);
  102. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  103. "(1 INT#x; 2 MSI)");
  104. static int dropless_fc;
  105. module_param(dropless_fc, int, 0444);
  106. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  107. static int mrrs = -1;
  108. module_param(mrrs, int, 0444);
  109. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  110. static int debug;
  111. module_param(debug, int, 0444);
  112. MODULE_PARM_DESC(debug, " Default debug msglevel");
  113. static struct workqueue_struct *bnx2x_wq;
  114. struct workqueue_struct *bnx2x_iov_wq;
  115. struct bnx2x_mac_vals {
  116. u32 xmac_addr;
  117. u32 xmac_val;
  118. u32 emac_addr;
  119. u32 emac_val;
  120. u32 umac_addr[2];
  121. u32 umac_val[2];
  122. u32 bmac_addr;
  123. u32 bmac_val[2];
  124. };
  125. enum bnx2x_board_type {
  126. BCM57710 = 0,
  127. BCM57711,
  128. BCM57711E,
  129. BCM57712,
  130. BCM57712_MF,
  131. BCM57712_VF,
  132. BCM57800,
  133. BCM57800_MF,
  134. BCM57800_VF,
  135. BCM57810,
  136. BCM57810_MF,
  137. BCM57810_VF,
  138. BCM57840_4_10,
  139. BCM57840_2_20,
  140. BCM57840_MF,
  141. BCM57840_VF,
  142. BCM57811,
  143. BCM57811_MF,
  144. BCM57840_O,
  145. BCM57840_MFO,
  146. BCM57811_VF
  147. };
  148. /* indexed by board_type, above */
  149. static struct {
  150. char *name;
  151. } board_info[] = {
  152. [BCM57710] = { "QLogic BCM57710 10 Gigabit PCIe [Everest]" },
  153. [BCM57711] = { "QLogic BCM57711 10 Gigabit PCIe" },
  154. [BCM57711E] = { "QLogic BCM57711E 10 Gigabit PCIe" },
  155. [BCM57712] = { "QLogic BCM57712 10 Gigabit Ethernet" },
  156. [BCM57712_MF] = { "QLogic BCM57712 10 Gigabit Ethernet Multi Function" },
  157. [BCM57712_VF] = { "QLogic BCM57712 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57800] = { "QLogic BCM57800 10 Gigabit Ethernet" },
  159. [BCM57800_MF] = { "QLogic BCM57800 10 Gigabit Ethernet Multi Function" },
  160. [BCM57800_VF] = { "QLogic BCM57800 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57810] = { "QLogic BCM57810 10 Gigabit Ethernet" },
  162. [BCM57810_MF] = { "QLogic BCM57810 10 Gigabit Ethernet Multi Function" },
  163. [BCM57810_VF] = { "QLogic BCM57810 10 Gigabit Ethernet Virtual Function" },
  164. [BCM57840_4_10] = { "QLogic BCM57840 10 Gigabit Ethernet" },
  165. [BCM57840_2_20] = { "QLogic BCM57840 20 Gigabit Ethernet" },
  166. [BCM57840_MF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  167. [BCM57840_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  168. [BCM57811] = { "QLogic BCM57811 10 Gigabit Ethernet" },
  169. [BCM57811_MF] = { "QLogic BCM57811 10 Gigabit Ethernet Multi Function" },
  170. [BCM57840_O] = { "QLogic BCM57840 10/20 Gigabit Ethernet" },
  171. [BCM57840_MFO] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  172. [BCM57811_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  173. };
  174. #ifndef PCI_DEVICE_ID_NX2_57710
  175. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711
  178. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57711E
  181. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712
  184. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  187. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  190. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800
  193. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  196. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  199. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810
  202. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  205. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_O
  208. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  211. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  214. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  217. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  220. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  223. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  226. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811
  229. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  232. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  233. #endif
  234. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  235. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  236. #endif
  237. static const struct pci_device_id bnx2x_pci_tbl[] = {
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  251. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  256. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  257. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  258. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  259. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  260. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  261. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  262. { 0 }
  263. };
  264. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  265. /* Global resources for unloading a previously loaded device */
  266. #define BNX2X_PREV_WAIT_NEEDED 1
  267. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  268. static LIST_HEAD(bnx2x_prev_list);
  269. /* Forward declaration */
  270. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  271. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  272. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  273. /****************************************************************************
  274. * General service functions
  275. ****************************************************************************/
  276. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  277. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  278. u32 addr, dma_addr_t mapping)
  279. {
  280. REG_WR(bp, addr, U64_LO(mapping));
  281. REG_WR(bp, addr + 4, U64_HI(mapping));
  282. }
  283. static void storm_memset_spq_addr(struct bnx2x *bp,
  284. dma_addr_t mapping, u16 abs_fid)
  285. {
  286. u32 addr = XSEM_REG_FAST_MEMORY +
  287. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  288. __storm_memset_dma_mapping(bp, addr, mapping);
  289. }
  290. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  291. u16 pf_id)
  292. {
  293. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  294. pf_id);
  295. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  296. pf_id);
  297. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  298. pf_id);
  299. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  300. pf_id);
  301. }
  302. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  303. u8 enable)
  304. {
  305. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  306. enable);
  307. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  308. enable);
  309. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  310. enable);
  311. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  312. enable);
  313. }
  314. static void storm_memset_eq_data(struct bnx2x *bp,
  315. struct event_ring_data *eq_data,
  316. u16 pfid)
  317. {
  318. size_t size = sizeof(struct event_ring_data);
  319. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  320. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  321. }
  322. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  323. u16 pfid)
  324. {
  325. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  326. REG_WR16(bp, addr, eq_prod);
  327. }
  328. /* used only at init
  329. * locking is done by mcp
  330. */
  331. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  332. {
  333. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  334. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  335. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  336. PCICFG_VENDOR_ID_OFFSET);
  337. }
  338. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  339. {
  340. u32 val;
  341. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  342. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  343. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  344. PCICFG_VENDOR_ID_OFFSET);
  345. return val;
  346. }
  347. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  348. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  349. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  350. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  351. #define DMAE_DP_DST_NONE "dst_addr [none]"
  352. static void bnx2x_dp_dmae(struct bnx2x *bp,
  353. struct dmae_command *dmae, int msglvl)
  354. {
  355. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  356. int i;
  357. switch (dmae->opcode & DMAE_COMMAND_DST) {
  358. case DMAE_CMD_DST_PCI:
  359. if (src_type == DMAE_CMD_SRC_PCI)
  360. DP(msglvl, "DMAE: opcode 0x%08x\n"
  361. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  362. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  363. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  364. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  365. dmae->comp_addr_hi, dmae->comp_addr_lo,
  366. dmae->comp_val);
  367. else
  368. DP(msglvl, "DMAE: opcode 0x%08x\n"
  369. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  370. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  371. dmae->opcode, dmae->src_addr_lo >> 2,
  372. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  373. dmae->comp_addr_hi, dmae->comp_addr_lo,
  374. dmae->comp_val);
  375. break;
  376. case DMAE_CMD_DST_GRC:
  377. if (src_type == DMAE_CMD_SRC_PCI)
  378. DP(msglvl, "DMAE: opcode 0x%08x\n"
  379. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  380. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  381. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  382. dmae->len, dmae->dst_addr_lo >> 2,
  383. dmae->comp_addr_hi, dmae->comp_addr_lo,
  384. dmae->comp_val);
  385. else
  386. DP(msglvl, "DMAE: opcode 0x%08x\n"
  387. "src [%08x], len [%d*4], dst [%08x]\n"
  388. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  389. dmae->opcode, dmae->src_addr_lo >> 2,
  390. dmae->len, dmae->dst_addr_lo >> 2,
  391. dmae->comp_addr_hi, dmae->comp_addr_lo,
  392. dmae->comp_val);
  393. break;
  394. default:
  395. if (src_type == DMAE_CMD_SRC_PCI)
  396. DP(msglvl, "DMAE: opcode 0x%08x\n"
  397. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  398. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  399. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  400. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  401. dmae->comp_val);
  402. else
  403. DP(msglvl, "DMAE: opcode 0x%08x\n"
  404. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  405. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  406. dmae->opcode, dmae->src_addr_lo >> 2,
  407. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  408. dmae->comp_val);
  409. break;
  410. }
  411. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  412. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  413. i, *(((u32 *)dmae) + i));
  414. }
  415. /* copy command into DMAE command memory and set DMAE command go */
  416. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  417. {
  418. u32 cmd_offset;
  419. int i;
  420. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  421. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  422. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  423. }
  424. REG_WR(bp, dmae_reg_go_c[idx], 1);
  425. }
  426. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  427. {
  428. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  429. DMAE_CMD_C_ENABLE);
  430. }
  431. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  432. {
  433. return opcode & ~DMAE_CMD_SRC_RESET;
  434. }
  435. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  436. bool with_comp, u8 comp_type)
  437. {
  438. u32 opcode = 0;
  439. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  440. (dst_type << DMAE_COMMAND_DST_SHIFT));
  441. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  442. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  443. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  444. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  445. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  446. #ifdef __BIG_ENDIAN
  447. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  448. #else
  449. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  450. #endif
  451. if (with_comp)
  452. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  453. return opcode;
  454. }
  455. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  456. struct dmae_command *dmae,
  457. u8 src_type, u8 dst_type)
  458. {
  459. memset(dmae, 0, sizeof(struct dmae_command));
  460. /* set the opcode */
  461. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  462. true, DMAE_COMP_PCI);
  463. /* fill in the completion parameters */
  464. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  465. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  466. dmae->comp_val = DMAE_COMP_VAL;
  467. }
  468. /* issue a dmae command over the init-channel and wait for completion */
  469. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  470. u32 *comp)
  471. {
  472. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  473. int rc = 0;
  474. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  475. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  476. * as long as this code is called both from syscall context and
  477. * from ndo_set_rx_mode() flow that may be called from BH.
  478. */
  479. spin_lock_bh(&bp->dmae_lock);
  480. /* reset completion */
  481. *comp = 0;
  482. /* post the command on the channel used for initializations */
  483. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  484. /* wait for completion */
  485. udelay(5);
  486. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  487. if (!cnt ||
  488. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  489. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  490. BNX2X_ERR("DMAE timeout!\n");
  491. rc = DMAE_TIMEOUT;
  492. goto unlock;
  493. }
  494. cnt--;
  495. udelay(50);
  496. }
  497. if (*comp & DMAE_PCI_ERR_FLAG) {
  498. BNX2X_ERR("DMAE PCI error!\n");
  499. rc = DMAE_PCI_ERROR;
  500. }
  501. unlock:
  502. spin_unlock_bh(&bp->dmae_lock);
  503. return rc;
  504. }
  505. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  506. u32 len32)
  507. {
  508. int rc;
  509. struct dmae_command dmae;
  510. if (!bp->dmae_ready) {
  511. u32 *data = bnx2x_sp(bp, wb_data[0]);
  512. if (CHIP_IS_E1(bp))
  513. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  514. else
  515. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  516. return;
  517. }
  518. /* set opcode and fixed command fields */
  519. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  520. /* fill in addresses and len */
  521. dmae.src_addr_lo = U64_LO(dma_addr);
  522. dmae.src_addr_hi = U64_HI(dma_addr);
  523. dmae.dst_addr_lo = dst_addr >> 2;
  524. dmae.dst_addr_hi = 0;
  525. dmae.len = len32;
  526. /* issue the command and wait for completion */
  527. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  528. if (rc) {
  529. BNX2X_ERR("DMAE returned failure %d\n", rc);
  530. #ifdef BNX2X_STOP_ON_ERROR
  531. bnx2x_panic();
  532. #endif
  533. }
  534. }
  535. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  536. {
  537. int rc;
  538. struct dmae_command dmae;
  539. if (!bp->dmae_ready) {
  540. u32 *data = bnx2x_sp(bp, wb_data[0]);
  541. int i;
  542. if (CHIP_IS_E1(bp))
  543. for (i = 0; i < len32; i++)
  544. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  545. else
  546. for (i = 0; i < len32; i++)
  547. data[i] = REG_RD(bp, src_addr + i*4);
  548. return;
  549. }
  550. /* set opcode and fixed command fields */
  551. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  552. /* fill in addresses and len */
  553. dmae.src_addr_lo = src_addr >> 2;
  554. dmae.src_addr_hi = 0;
  555. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  556. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  557. dmae.len = len32;
  558. /* issue the command and wait for completion */
  559. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  560. if (rc) {
  561. BNX2X_ERR("DMAE returned failure %d\n", rc);
  562. #ifdef BNX2X_STOP_ON_ERROR
  563. bnx2x_panic();
  564. #endif
  565. }
  566. }
  567. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  568. u32 addr, u32 len)
  569. {
  570. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  571. int offset = 0;
  572. while (len > dmae_wr_max) {
  573. bnx2x_write_dmae(bp, phys_addr + offset,
  574. addr + offset, dmae_wr_max);
  575. offset += dmae_wr_max * 4;
  576. len -= dmae_wr_max;
  577. }
  578. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  579. }
  580. enum storms {
  581. XSTORM,
  582. TSTORM,
  583. CSTORM,
  584. USTORM,
  585. MAX_STORMS
  586. };
  587. #define STORMS_NUM 4
  588. #define REGS_IN_ENTRY 4
  589. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  590. enum storms storm,
  591. int entry)
  592. {
  593. switch (storm) {
  594. case XSTORM:
  595. return XSTORM_ASSERT_LIST_OFFSET(entry);
  596. case TSTORM:
  597. return TSTORM_ASSERT_LIST_OFFSET(entry);
  598. case CSTORM:
  599. return CSTORM_ASSERT_LIST_OFFSET(entry);
  600. case USTORM:
  601. return USTORM_ASSERT_LIST_OFFSET(entry);
  602. case MAX_STORMS:
  603. default:
  604. BNX2X_ERR("unknown storm\n");
  605. }
  606. return -EINVAL;
  607. }
  608. static int bnx2x_mc_assert(struct bnx2x *bp)
  609. {
  610. char last_idx;
  611. int i, j, rc = 0;
  612. enum storms storm;
  613. u32 regs[REGS_IN_ENTRY];
  614. u32 bar_storm_intmem[STORMS_NUM] = {
  615. BAR_XSTRORM_INTMEM,
  616. BAR_TSTRORM_INTMEM,
  617. BAR_CSTRORM_INTMEM,
  618. BAR_USTRORM_INTMEM
  619. };
  620. u32 storm_assert_list_index[STORMS_NUM] = {
  621. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  622. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  623. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  624. USTORM_ASSERT_LIST_INDEX_OFFSET
  625. };
  626. char *storms_string[STORMS_NUM] = {
  627. "XSTORM",
  628. "TSTORM",
  629. "CSTORM",
  630. "USTORM"
  631. };
  632. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  633. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  634. storm_assert_list_index[storm]);
  635. if (last_idx)
  636. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  637. storms_string[storm], last_idx);
  638. /* print the asserts */
  639. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  640. /* read a single assert entry */
  641. for (j = 0; j < REGS_IN_ENTRY; j++)
  642. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  643. bnx2x_get_assert_list_entry(bp,
  644. storm,
  645. i) +
  646. sizeof(u32) * j);
  647. /* log entry if it contains a valid assert */
  648. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  649. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  650. storms_string[storm], i, regs[3],
  651. regs[2], regs[1], regs[0]);
  652. rc++;
  653. } else {
  654. break;
  655. }
  656. }
  657. }
  658. BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
  659. CHIP_IS_E1(bp) ? "everest1" :
  660. CHIP_IS_E1H(bp) ? "everest1h" :
  661. CHIP_IS_E2(bp) ? "everest2" : "everest3",
  662. BCM_5710_FW_MAJOR_VERSION,
  663. BCM_5710_FW_MINOR_VERSION,
  664. BCM_5710_FW_REVISION_VERSION);
  665. return rc;
  666. }
  667. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  668. #define SCRATCH_BUFFER_SIZE(bp) \
  669. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  670. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  671. {
  672. u32 addr, val;
  673. u32 mark, offset;
  674. __be32 data[9];
  675. int word;
  676. u32 trace_shmem_base;
  677. if (BP_NOMCP(bp)) {
  678. BNX2X_ERR("NO MCP - can not dump\n");
  679. return;
  680. }
  681. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  682. (bp->common.bc_ver & 0xff0000) >> 16,
  683. (bp->common.bc_ver & 0xff00) >> 8,
  684. (bp->common.bc_ver & 0xff));
  685. if (pci_channel_offline(bp->pdev)) {
  686. BNX2X_ERR("Cannot dump MCP info while in PCI error\n");
  687. return;
  688. }
  689. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  690. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  691. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  692. if (BP_PATH(bp) == 0)
  693. trace_shmem_base = bp->common.shmem_base;
  694. else
  695. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  696. /* sanity */
  697. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  698. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  699. SCRATCH_BUFFER_SIZE(bp)) {
  700. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  701. trace_shmem_base);
  702. return;
  703. }
  704. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  705. /* validate TRCB signature */
  706. mark = REG_RD(bp, addr);
  707. if (mark != MFW_TRACE_SIGNATURE) {
  708. BNX2X_ERR("Trace buffer signature is missing.");
  709. return ;
  710. }
  711. /* read cyclic buffer pointer */
  712. addr += 4;
  713. mark = REG_RD(bp, addr);
  714. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  715. if (mark >= trace_shmem_base || mark < addr + 4) {
  716. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  717. return;
  718. }
  719. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  720. printk("%s", lvl);
  721. /* dump buffer after the mark */
  722. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  723. for (word = 0; word < 8; word++)
  724. data[word] = htonl(REG_RD(bp, offset + 4*word));
  725. data[8] = 0x0;
  726. pr_cont("%s", (char *)data);
  727. }
  728. /* dump buffer before the mark */
  729. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  730. for (word = 0; word < 8; word++)
  731. data[word] = htonl(REG_RD(bp, offset + 4*word));
  732. data[8] = 0x0;
  733. pr_cont("%s", (char *)data);
  734. }
  735. printk("%s" "end of fw dump\n", lvl);
  736. }
  737. static void bnx2x_fw_dump(struct bnx2x *bp)
  738. {
  739. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  740. }
  741. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  742. {
  743. int port = BP_PORT(bp);
  744. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  745. u32 val = REG_RD(bp, addr);
  746. /* in E1 we must use only PCI configuration space to disable
  747. * MSI/MSIX capability
  748. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  749. */
  750. if (CHIP_IS_E1(bp)) {
  751. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  752. * Use mask register to prevent from HC sending interrupts
  753. * after we exit the function
  754. */
  755. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  756. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  757. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  758. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  759. } else
  760. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  761. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  762. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  763. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  764. DP(NETIF_MSG_IFDOWN,
  765. "write %x to HC %d (addr 0x%x)\n",
  766. val, port, addr);
  767. /* flush all outstanding writes */
  768. mmiowb();
  769. REG_WR(bp, addr, val);
  770. if (REG_RD(bp, addr) != val)
  771. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  772. }
  773. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  774. {
  775. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  776. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  777. IGU_PF_CONF_INT_LINE_EN |
  778. IGU_PF_CONF_ATTN_BIT_EN);
  779. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  780. /* flush all outstanding writes */
  781. mmiowb();
  782. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  783. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  784. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  785. }
  786. static void bnx2x_int_disable(struct bnx2x *bp)
  787. {
  788. if (bp->common.int_block == INT_BLOCK_HC)
  789. bnx2x_hc_int_disable(bp);
  790. else
  791. bnx2x_igu_int_disable(bp);
  792. }
  793. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  794. {
  795. int i;
  796. u16 j;
  797. struct hc_sp_status_block_data sp_sb_data;
  798. int func = BP_FUNC(bp);
  799. #ifdef BNX2X_STOP_ON_ERROR
  800. u16 start = 0, end = 0;
  801. u8 cos;
  802. #endif
  803. if (IS_PF(bp) && disable_int)
  804. bnx2x_int_disable(bp);
  805. bp->stats_state = STATS_STATE_DISABLED;
  806. bp->eth_stats.unrecoverable_error++;
  807. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  808. BNX2X_ERR("begin crash dump -----------------\n");
  809. /* Indices */
  810. /* Common */
  811. if (IS_PF(bp)) {
  812. struct host_sp_status_block *def_sb = bp->def_status_blk;
  813. int data_size, cstorm_offset;
  814. 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",
  815. bp->def_idx, bp->def_att_idx, bp->attn_state,
  816. bp->spq_prod_idx, bp->stats_counter);
  817. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  818. def_sb->atten_status_block.attn_bits,
  819. def_sb->atten_status_block.attn_bits_ack,
  820. def_sb->atten_status_block.status_block_id,
  821. def_sb->atten_status_block.attn_bits_index);
  822. BNX2X_ERR(" def (");
  823. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  824. pr_cont("0x%x%s",
  825. def_sb->sp_sb.index_values[i],
  826. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  827. data_size = sizeof(struct hc_sp_status_block_data) /
  828. sizeof(u32);
  829. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  830. for (i = 0; i < data_size; i++)
  831. *((u32 *)&sp_sb_data + i) =
  832. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  833. i * sizeof(u32));
  834. 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",
  835. sp_sb_data.igu_sb_id,
  836. sp_sb_data.igu_seg_id,
  837. sp_sb_data.p_func.pf_id,
  838. sp_sb_data.p_func.vnic_id,
  839. sp_sb_data.p_func.vf_id,
  840. sp_sb_data.p_func.vf_valid,
  841. sp_sb_data.state);
  842. }
  843. for_each_eth_queue(bp, i) {
  844. struct bnx2x_fastpath *fp = &bp->fp[i];
  845. int loop;
  846. struct hc_status_block_data_e2 sb_data_e2;
  847. struct hc_status_block_data_e1x sb_data_e1x;
  848. struct hc_status_block_sm *hc_sm_p =
  849. CHIP_IS_E1x(bp) ?
  850. sb_data_e1x.common.state_machine :
  851. sb_data_e2.common.state_machine;
  852. struct hc_index_data *hc_index_p =
  853. CHIP_IS_E1x(bp) ?
  854. sb_data_e1x.index_data :
  855. sb_data_e2.index_data;
  856. u8 data_size, cos;
  857. u32 *sb_data_p;
  858. struct bnx2x_fp_txdata txdata;
  859. if (!bp->fp)
  860. break;
  861. if (!fp->rx_cons_sb)
  862. continue;
  863. /* Rx */
  864. 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",
  865. i, fp->rx_bd_prod, fp->rx_bd_cons,
  866. fp->rx_comp_prod,
  867. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  868. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  869. fp->rx_sge_prod, fp->last_max_sge,
  870. le16_to_cpu(fp->fp_hc_idx));
  871. /* Tx */
  872. for_each_cos_in_tx_queue(fp, cos)
  873. {
  874. if (!fp->txdata_ptr[cos])
  875. break;
  876. txdata = *fp->txdata_ptr[cos];
  877. if (!txdata.tx_cons_sb)
  878. continue;
  879. 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",
  880. i, txdata.tx_pkt_prod,
  881. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  882. txdata.tx_bd_cons,
  883. le16_to_cpu(*txdata.tx_cons_sb));
  884. }
  885. loop = CHIP_IS_E1x(bp) ?
  886. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  887. /* host sb data */
  888. if (IS_FCOE_FP(fp))
  889. continue;
  890. BNX2X_ERR(" run indexes (");
  891. for (j = 0; j < HC_SB_MAX_SM; j++)
  892. pr_cont("0x%x%s",
  893. fp->sb_running_index[j],
  894. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  895. BNX2X_ERR(" indexes (");
  896. for (j = 0; j < loop; j++)
  897. pr_cont("0x%x%s",
  898. fp->sb_index_values[j],
  899. (j == loop - 1) ? ")" : " ");
  900. /* VF cannot access FW refelection for status block */
  901. if (IS_VF(bp))
  902. continue;
  903. /* fw sb data */
  904. data_size = CHIP_IS_E1x(bp) ?
  905. sizeof(struct hc_status_block_data_e1x) :
  906. sizeof(struct hc_status_block_data_e2);
  907. data_size /= sizeof(u32);
  908. sb_data_p = CHIP_IS_E1x(bp) ?
  909. (u32 *)&sb_data_e1x :
  910. (u32 *)&sb_data_e2;
  911. /* copy sb data in here */
  912. for (j = 0; j < data_size; j++)
  913. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  914. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  915. j * sizeof(u32));
  916. if (!CHIP_IS_E1x(bp)) {
  917. 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",
  918. sb_data_e2.common.p_func.pf_id,
  919. sb_data_e2.common.p_func.vf_id,
  920. sb_data_e2.common.p_func.vf_valid,
  921. sb_data_e2.common.p_func.vnic_id,
  922. sb_data_e2.common.same_igu_sb_1b,
  923. sb_data_e2.common.state);
  924. } else {
  925. 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",
  926. sb_data_e1x.common.p_func.pf_id,
  927. sb_data_e1x.common.p_func.vf_id,
  928. sb_data_e1x.common.p_func.vf_valid,
  929. sb_data_e1x.common.p_func.vnic_id,
  930. sb_data_e1x.common.same_igu_sb_1b,
  931. sb_data_e1x.common.state);
  932. }
  933. /* SB_SMs data */
  934. for (j = 0; j < HC_SB_MAX_SM; j++) {
  935. 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",
  936. j, hc_sm_p[j].__flags,
  937. hc_sm_p[j].igu_sb_id,
  938. hc_sm_p[j].igu_seg_id,
  939. hc_sm_p[j].time_to_expire,
  940. hc_sm_p[j].timer_value);
  941. }
  942. /* Indices data */
  943. for (j = 0; j < loop; j++) {
  944. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  945. hc_index_p[j].flags,
  946. hc_index_p[j].timeout);
  947. }
  948. }
  949. #ifdef BNX2X_STOP_ON_ERROR
  950. if (IS_PF(bp)) {
  951. /* event queue */
  952. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  953. for (i = 0; i < NUM_EQ_DESC; i++) {
  954. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  955. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  956. i, bp->eq_ring[i].message.opcode,
  957. bp->eq_ring[i].message.error);
  958. BNX2X_ERR("data: %x %x %x\n",
  959. data[0], data[1], data[2]);
  960. }
  961. }
  962. /* Rings */
  963. /* Rx */
  964. for_each_valid_rx_queue(bp, i) {
  965. struct bnx2x_fastpath *fp = &bp->fp[i];
  966. if (!bp->fp)
  967. break;
  968. if (!fp->rx_cons_sb)
  969. continue;
  970. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  971. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  972. for (j = start; j != end; j = RX_BD(j + 1)) {
  973. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  974. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  975. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  976. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  977. }
  978. start = RX_SGE(fp->rx_sge_prod);
  979. end = RX_SGE(fp->last_max_sge);
  980. for (j = start; j != end; j = RX_SGE(j + 1)) {
  981. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  982. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  983. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  984. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  985. }
  986. start = RCQ_BD(fp->rx_comp_cons - 10);
  987. end = RCQ_BD(fp->rx_comp_cons + 503);
  988. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  989. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  990. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  991. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  992. }
  993. }
  994. /* Tx */
  995. for_each_valid_tx_queue(bp, i) {
  996. struct bnx2x_fastpath *fp = &bp->fp[i];
  997. if (!bp->fp)
  998. break;
  999. for_each_cos_in_tx_queue(fp, cos) {
  1000. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  1001. if (!fp->txdata_ptr[cos])
  1002. break;
  1003. if (!txdata->tx_cons_sb)
  1004. continue;
  1005. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  1006. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  1007. for (j = start; j != end; j = TX_BD(j + 1)) {
  1008. struct sw_tx_bd *sw_bd =
  1009. &txdata->tx_buf_ring[j];
  1010. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1011. i, cos, j, sw_bd->skb,
  1012. sw_bd->first_bd);
  1013. }
  1014. start = TX_BD(txdata->tx_bd_cons - 10);
  1015. end = TX_BD(txdata->tx_bd_cons + 254);
  1016. for (j = start; j != end; j = TX_BD(j + 1)) {
  1017. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1018. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1019. i, cos, j, tx_bd[0], tx_bd[1],
  1020. tx_bd[2], tx_bd[3]);
  1021. }
  1022. }
  1023. }
  1024. #endif
  1025. if (IS_PF(bp)) {
  1026. bnx2x_fw_dump(bp);
  1027. bnx2x_mc_assert(bp);
  1028. }
  1029. BNX2X_ERR("end crash dump -----------------\n");
  1030. }
  1031. /*
  1032. * FLR Support for E2
  1033. *
  1034. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1035. * initialization.
  1036. */
  1037. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1038. #define FLR_WAIT_INTERVAL 50 /* usec */
  1039. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1040. struct pbf_pN_buf_regs {
  1041. int pN;
  1042. u32 init_crd;
  1043. u32 crd;
  1044. u32 crd_freed;
  1045. };
  1046. struct pbf_pN_cmd_regs {
  1047. int pN;
  1048. u32 lines_occup;
  1049. u32 lines_freed;
  1050. };
  1051. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1052. struct pbf_pN_buf_regs *regs,
  1053. u32 poll_count)
  1054. {
  1055. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1056. u32 cur_cnt = poll_count;
  1057. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1058. crd = crd_start = REG_RD(bp, regs->crd);
  1059. init_crd = REG_RD(bp, regs->init_crd);
  1060. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1061. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1062. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1063. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1064. (init_crd - crd_start))) {
  1065. if (cur_cnt--) {
  1066. udelay(FLR_WAIT_INTERVAL);
  1067. crd = REG_RD(bp, regs->crd);
  1068. crd_freed = REG_RD(bp, regs->crd_freed);
  1069. } else {
  1070. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1071. regs->pN);
  1072. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1073. regs->pN, crd);
  1074. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1075. regs->pN, crd_freed);
  1076. break;
  1077. }
  1078. }
  1079. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1080. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1081. }
  1082. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1083. struct pbf_pN_cmd_regs *regs,
  1084. u32 poll_count)
  1085. {
  1086. u32 occup, to_free, freed, freed_start;
  1087. u32 cur_cnt = poll_count;
  1088. occup = to_free = REG_RD(bp, regs->lines_occup);
  1089. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1090. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1091. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1092. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1093. if (cur_cnt--) {
  1094. udelay(FLR_WAIT_INTERVAL);
  1095. occup = REG_RD(bp, regs->lines_occup);
  1096. freed = REG_RD(bp, regs->lines_freed);
  1097. } else {
  1098. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1099. regs->pN);
  1100. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1101. regs->pN, occup);
  1102. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1103. regs->pN, freed);
  1104. break;
  1105. }
  1106. }
  1107. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1108. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1109. }
  1110. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1111. u32 expected, u32 poll_count)
  1112. {
  1113. u32 cur_cnt = poll_count;
  1114. u32 val;
  1115. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1116. udelay(FLR_WAIT_INTERVAL);
  1117. return val;
  1118. }
  1119. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1120. char *msg, u32 poll_cnt)
  1121. {
  1122. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1123. if (val != 0) {
  1124. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1125. return 1;
  1126. }
  1127. return 0;
  1128. }
  1129. /* Common routines with VF FLR cleanup */
  1130. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1131. {
  1132. /* adjust polling timeout */
  1133. if (CHIP_REV_IS_EMUL(bp))
  1134. return FLR_POLL_CNT * 2000;
  1135. if (CHIP_REV_IS_FPGA(bp))
  1136. return FLR_POLL_CNT * 120;
  1137. return FLR_POLL_CNT;
  1138. }
  1139. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1140. {
  1141. struct pbf_pN_cmd_regs cmd_regs[] = {
  1142. {0, (CHIP_IS_E3B0(bp)) ?
  1143. PBF_REG_TQ_OCCUPANCY_Q0 :
  1144. PBF_REG_P0_TQ_OCCUPANCY,
  1145. (CHIP_IS_E3B0(bp)) ?
  1146. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1147. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1148. {1, (CHIP_IS_E3B0(bp)) ?
  1149. PBF_REG_TQ_OCCUPANCY_Q1 :
  1150. PBF_REG_P1_TQ_OCCUPANCY,
  1151. (CHIP_IS_E3B0(bp)) ?
  1152. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1153. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1154. {4, (CHIP_IS_E3B0(bp)) ?
  1155. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1156. PBF_REG_P4_TQ_OCCUPANCY,
  1157. (CHIP_IS_E3B0(bp)) ?
  1158. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1159. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1160. };
  1161. struct pbf_pN_buf_regs buf_regs[] = {
  1162. {0, (CHIP_IS_E3B0(bp)) ?
  1163. PBF_REG_INIT_CRD_Q0 :
  1164. PBF_REG_P0_INIT_CRD ,
  1165. (CHIP_IS_E3B0(bp)) ?
  1166. PBF_REG_CREDIT_Q0 :
  1167. PBF_REG_P0_CREDIT,
  1168. (CHIP_IS_E3B0(bp)) ?
  1169. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1170. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1171. {1, (CHIP_IS_E3B0(bp)) ?
  1172. PBF_REG_INIT_CRD_Q1 :
  1173. PBF_REG_P1_INIT_CRD,
  1174. (CHIP_IS_E3B0(bp)) ?
  1175. PBF_REG_CREDIT_Q1 :
  1176. PBF_REG_P1_CREDIT,
  1177. (CHIP_IS_E3B0(bp)) ?
  1178. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1179. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1180. {4, (CHIP_IS_E3B0(bp)) ?
  1181. PBF_REG_INIT_CRD_LB_Q :
  1182. PBF_REG_P4_INIT_CRD,
  1183. (CHIP_IS_E3B0(bp)) ?
  1184. PBF_REG_CREDIT_LB_Q :
  1185. PBF_REG_P4_CREDIT,
  1186. (CHIP_IS_E3B0(bp)) ?
  1187. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1188. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1189. };
  1190. int i;
  1191. /* Verify the command queues are flushed P0, P1, P4 */
  1192. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1193. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1194. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1195. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1196. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1197. }
  1198. #define OP_GEN_PARAM(param) \
  1199. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1200. #define OP_GEN_TYPE(type) \
  1201. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1202. #define OP_GEN_AGG_VECT(index) \
  1203. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1204. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1205. {
  1206. u32 op_gen_command = 0;
  1207. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1208. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1209. int ret = 0;
  1210. if (REG_RD(bp, comp_addr)) {
  1211. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1212. return 1;
  1213. }
  1214. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1215. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1216. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1217. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1218. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1219. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1220. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1221. BNX2X_ERR("FW final cleanup did not succeed\n");
  1222. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1223. (REG_RD(bp, comp_addr)));
  1224. bnx2x_panic();
  1225. return 1;
  1226. }
  1227. /* Zero completion for next FLR */
  1228. REG_WR(bp, comp_addr, 0);
  1229. return ret;
  1230. }
  1231. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1232. {
  1233. u16 status;
  1234. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1235. return status & PCI_EXP_DEVSTA_TRPND;
  1236. }
  1237. /* PF FLR specific routines
  1238. */
  1239. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1240. {
  1241. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1242. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1243. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1244. "CFC PF usage counter timed out",
  1245. poll_cnt))
  1246. return 1;
  1247. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1248. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1249. DORQ_REG_PF_USAGE_CNT,
  1250. "DQ PF usage counter timed out",
  1251. poll_cnt))
  1252. return 1;
  1253. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1254. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1255. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1256. "QM PF usage counter timed out",
  1257. poll_cnt))
  1258. return 1;
  1259. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1260. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1261. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1262. "Timers VNIC usage counter timed out",
  1263. poll_cnt))
  1264. return 1;
  1265. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1266. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1267. "Timers NUM_SCANS usage counter timed out",
  1268. poll_cnt))
  1269. return 1;
  1270. /* Wait DMAE PF usage counter to zero */
  1271. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1272. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1273. "DMAE command register timed out",
  1274. poll_cnt))
  1275. return 1;
  1276. return 0;
  1277. }
  1278. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1279. {
  1280. u32 val;
  1281. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1282. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1283. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1284. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1285. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1286. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1287. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1288. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1289. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1290. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1291. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1292. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1293. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1294. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1295. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1296. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1297. val);
  1298. }
  1299. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1300. {
  1301. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1302. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1303. /* Re-enable PF target read access */
  1304. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1305. /* Poll HW usage counters */
  1306. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1307. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1308. return -EBUSY;
  1309. /* Zero the igu 'trailing edge' and 'leading edge' */
  1310. /* Send the FW cleanup command */
  1311. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1312. return -EBUSY;
  1313. /* ATC cleanup */
  1314. /* Verify TX hw is flushed */
  1315. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1316. /* Wait 100ms (not adjusted according to platform) */
  1317. msleep(100);
  1318. /* Verify no pending pci transactions */
  1319. if (bnx2x_is_pcie_pending(bp->pdev))
  1320. BNX2X_ERR("PCIE Transactions still pending\n");
  1321. /* Debug */
  1322. bnx2x_hw_enable_status(bp);
  1323. /*
  1324. * Master enable - Due to WB DMAE writes performed before this
  1325. * register is re-initialized as part of the regular function init
  1326. */
  1327. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1328. return 0;
  1329. }
  1330. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1331. {
  1332. int port = BP_PORT(bp);
  1333. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1334. u32 val = REG_RD(bp, addr);
  1335. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1336. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1337. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1338. if (msix) {
  1339. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1340. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1341. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1342. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1343. if (single_msix)
  1344. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1345. } else if (msi) {
  1346. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1347. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1348. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1349. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1350. } else {
  1351. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1352. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1353. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1354. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1355. if (!CHIP_IS_E1(bp)) {
  1356. DP(NETIF_MSG_IFUP,
  1357. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1358. REG_WR(bp, addr, val);
  1359. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1360. }
  1361. }
  1362. if (CHIP_IS_E1(bp))
  1363. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1364. DP(NETIF_MSG_IFUP,
  1365. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1366. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1367. REG_WR(bp, addr, val);
  1368. /*
  1369. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1370. */
  1371. mmiowb();
  1372. barrier();
  1373. if (!CHIP_IS_E1(bp)) {
  1374. /* init leading/trailing edge */
  1375. if (IS_MF(bp)) {
  1376. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1377. if (bp->port.pmf)
  1378. /* enable nig and gpio3 attention */
  1379. val |= 0x1100;
  1380. } else
  1381. val = 0xffff;
  1382. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1383. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1384. }
  1385. /* Make sure that interrupts are indeed enabled from here on */
  1386. mmiowb();
  1387. }
  1388. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1389. {
  1390. u32 val;
  1391. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1392. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1393. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1394. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1395. if (msix) {
  1396. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1397. IGU_PF_CONF_SINGLE_ISR_EN);
  1398. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1399. IGU_PF_CONF_ATTN_BIT_EN);
  1400. if (single_msix)
  1401. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1402. } else if (msi) {
  1403. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1404. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1405. IGU_PF_CONF_ATTN_BIT_EN |
  1406. IGU_PF_CONF_SINGLE_ISR_EN);
  1407. } else {
  1408. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1409. val |= (IGU_PF_CONF_INT_LINE_EN |
  1410. IGU_PF_CONF_ATTN_BIT_EN |
  1411. IGU_PF_CONF_SINGLE_ISR_EN);
  1412. }
  1413. /* Clean previous status - need to configure igu prior to ack*/
  1414. if ((!msix) || single_msix) {
  1415. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1416. bnx2x_ack_int(bp);
  1417. }
  1418. val |= IGU_PF_CONF_FUNC_EN;
  1419. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1420. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1421. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1422. if (val & IGU_PF_CONF_INT_LINE_EN)
  1423. pci_intx(bp->pdev, true);
  1424. barrier();
  1425. /* init leading/trailing edge */
  1426. if (IS_MF(bp)) {
  1427. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1428. if (bp->port.pmf)
  1429. /* enable nig and gpio3 attention */
  1430. val |= 0x1100;
  1431. } else
  1432. val = 0xffff;
  1433. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1434. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1435. /* Make sure that interrupts are indeed enabled from here on */
  1436. mmiowb();
  1437. }
  1438. void bnx2x_int_enable(struct bnx2x *bp)
  1439. {
  1440. if (bp->common.int_block == INT_BLOCK_HC)
  1441. bnx2x_hc_int_enable(bp);
  1442. else
  1443. bnx2x_igu_int_enable(bp);
  1444. }
  1445. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1446. {
  1447. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1448. int i, offset;
  1449. if (disable_hw)
  1450. /* prevent the HW from sending interrupts */
  1451. bnx2x_int_disable(bp);
  1452. /* make sure all ISRs are done */
  1453. if (msix) {
  1454. synchronize_irq(bp->msix_table[0].vector);
  1455. offset = 1;
  1456. if (CNIC_SUPPORT(bp))
  1457. offset++;
  1458. for_each_eth_queue(bp, i)
  1459. synchronize_irq(bp->msix_table[offset++].vector);
  1460. } else
  1461. synchronize_irq(bp->pdev->irq);
  1462. /* make sure sp_task is not running */
  1463. cancel_delayed_work(&bp->sp_task);
  1464. cancel_delayed_work(&bp->period_task);
  1465. flush_workqueue(bnx2x_wq);
  1466. }
  1467. /* fast path */
  1468. /*
  1469. * General service functions
  1470. */
  1471. /* Return true if succeeded to acquire the lock */
  1472. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1473. {
  1474. u32 lock_status;
  1475. u32 resource_bit = (1 << resource);
  1476. int func = BP_FUNC(bp);
  1477. u32 hw_lock_control_reg;
  1478. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1479. "Trying to take a lock on resource %d\n", resource);
  1480. /* Validating that the resource is within range */
  1481. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1482. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1483. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1484. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1485. return false;
  1486. }
  1487. if (func <= 5)
  1488. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1489. else
  1490. hw_lock_control_reg =
  1491. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1492. /* Try to acquire the lock */
  1493. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1494. lock_status = REG_RD(bp, hw_lock_control_reg);
  1495. if (lock_status & resource_bit)
  1496. return true;
  1497. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1498. "Failed to get a lock on resource %d\n", resource);
  1499. return false;
  1500. }
  1501. /**
  1502. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1503. *
  1504. * @bp: driver handle
  1505. *
  1506. * Returns the recovery leader resource id according to the engine this function
  1507. * belongs to. Currently only only 2 engines is supported.
  1508. */
  1509. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1510. {
  1511. if (BP_PATH(bp))
  1512. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1513. else
  1514. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1515. }
  1516. /**
  1517. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1518. *
  1519. * @bp: driver handle
  1520. *
  1521. * Tries to acquire a leader lock for current engine.
  1522. */
  1523. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1524. {
  1525. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1526. }
  1527. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1528. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1529. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1530. {
  1531. /* Set the interrupt occurred bit for the sp-task to recognize it
  1532. * must ack the interrupt and transition according to the IGU
  1533. * state machine.
  1534. */
  1535. atomic_set(&bp->interrupt_occurred, 1);
  1536. /* The sp_task must execute only after this bit
  1537. * is set, otherwise we will get out of sync and miss all
  1538. * further interrupts. Hence, the barrier.
  1539. */
  1540. smp_wmb();
  1541. /* schedule sp_task to workqueue */
  1542. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1543. }
  1544. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1545. {
  1546. struct bnx2x *bp = fp->bp;
  1547. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1548. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1549. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1550. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1551. DP(BNX2X_MSG_SP,
  1552. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1553. fp->index, cid, command, bp->state,
  1554. rr_cqe->ramrod_cqe.ramrod_type);
  1555. /* If cid is within VF range, replace the slowpath object with the
  1556. * one corresponding to this VF
  1557. */
  1558. if (cid >= BNX2X_FIRST_VF_CID &&
  1559. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1560. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1561. switch (command) {
  1562. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1563. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1564. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1565. break;
  1566. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1567. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1568. drv_cmd = BNX2X_Q_CMD_SETUP;
  1569. break;
  1570. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1571. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1572. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1573. break;
  1574. case (RAMROD_CMD_ID_ETH_HALT):
  1575. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1576. drv_cmd = BNX2X_Q_CMD_HALT;
  1577. break;
  1578. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1579. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1580. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1581. break;
  1582. case (RAMROD_CMD_ID_ETH_EMPTY):
  1583. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1584. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1585. break;
  1586. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1587. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1588. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1589. break;
  1590. default:
  1591. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1592. command, fp->index);
  1593. return;
  1594. }
  1595. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1596. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1597. /* q_obj->complete_cmd() failure means that this was
  1598. * an unexpected completion.
  1599. *
  1600. * In this case we don't want to increase the bp->spq_left
  1601. * because apparently we haven't sent this command the first
  1602. * place.
  1603. */
  1604. #ifdef BNX2X_STOP_ON_ERROR
  1605. bnx2x_panic();
  1606. #else
  1607. return;
  1608. #endif
  1609. smp_mb__before_atomic();
  1610. atomic_inc(&bp->cq_spq_left);
  1611. /* push the change in bp->spq_left and towards the memory */
  1612. smp_mb__after_atomic();
  1613. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1614. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1615. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1616. /* if Q update ramrod is completed for last Q in AFEX vif set
  1617. * flow, then ACK MCP at the end
  1618. *
  1619. * mark pending ACK to MCP bit.
  1620. * prevent case that both bits are cleared.
  1621. * At the end of load/unload driver checks that
  1622. * sp_state is cleared, and this order prevents
  1623. * races
  1624. */
  1625. smp_mb__before_atomic();
  1626. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1627. wmb();
  1628. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1629. smp_mb__after_atomic();
  1630. /* schedule the sp task as mcp ack is required */
  1631. bnx2x_schedule_sp_task(bp);
  1632. }
  1633. return;
  1634. }
  1635. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1636. {
  1637. struct bnx2x *bp = netdev_priv(dev_instance);
  1638. u16 status = bnx2x_ack_int(bp);
  1639. u16 mask;
  1640. int i;
  1641. u8 cos;
  1642. /* Return here if interrupt is shared and it's not for us */
  1643. if (unlikely(status == 0)) {
  1644. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1645. return IRQ_NONE;
  1646. }
  1647. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1648. #ifdef BNX2X_STOP_ON_ERROR
  1649. if (unlikely(bp->panic))
  1650. return IRQ_HANDLED;
  1651. #endif
  1652. for_each_eth_queue(bp, i) {
  1653. struct bnx2x_fastpath *fp = &bp->fp[i];
  1654. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1655. if (status & mask) {
  1656. /* Handle Rx or Tx according to SB id */
  1657. for_each_cos_in_tx_queue(fp, cos)
  1658. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1659. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1660. napi_schedule_irqoff(&bnx2x_fp(bp, fp->index, napi));
  1661. status &= ~mask;
  1662. }
  1663. }
  1664. if (CNIC_SUPPORT(bp)) {
  1665. mask = 0x2;
  1666. if (status & (mask | 0x1)) {
  1667. struct cnic_ops *c_ops = NULL;
  1668. rcu_read_lock();
  1669. c_ops = rcu_dereference(bp->cnic_ops);
  1670. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1671. CNIC_DRV_STATE_HANDLES_IRQ))
  1672. c_ops->cnic_handler(bp->cnic_data, NULL);
  1673. rcu_read_unlock();
  1674. status &= ~mask;
  1675. }
  1676. }
  1677. if (unlikely(status & 0x1)) {
  1678. /* schedule sp task to perform default status block work, ack
  1679. * attentions and enable interrupts.
  1680. */
  1681. bnx2x_schedule_sp_task(bp);
  1682. status &= ~0x1;
  1683. if (!status)
  1684. return IRQ_HANDLED;
  1685. }
  1686. if (unlikely(status))
  1687. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1688. status);
  1689. return IRQ_HANDLED;
  1690. }
  1691. /* Link */
  1692. /*
  1693. * General service functions
  1694. */
  1695. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1696. {
  1697. u32 lock_status;
  1698. u32 resource_bit = (1 << resource);
  1699. int func = BP_FUNC(bp);
  1700. u32 hw_lock_control_reg;
  1701. int cnt;
  1702. /* Validating that the resource is within range */
  1703. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1704. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1705. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1706. return -EINVAL;
  1707. }
  1708. if (func <= 5) {
  1709. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1710. } else {
  1711. hw_lock_control_reg =
  1712. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1713. }
  1714. /* Validating that the resource is not already taken */
  1715. lock_status = REG_RD(bp, hw_lock_control_reg);
  1716. if (lock_status & resource_bit) {
  1717. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1718. lock_status, resource_bit);
  1719. return -EEXIST;
  1720. }
  1721. /* Try for 5 second every 5ms */
  1722. for (cnt = 0; cnt < 1000; cnt++) {
  1723. /* Try to acquire the lock */
  1724. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1725. lock_status = REG_RD(bp, hw_lock_control_reg);
  1726. if (lock_status & resource_bit)
  1727. return 0;
  1728. usleep_range(5000, 10000);
  1729. }
  1730. BNX2X_ERR("Timeout\n");
  1731. return -EAGAIN;
  1732. }
  1733. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1734. {
  1735. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1736. }
  1737. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1738. {
  1739. u32 lock_status;
  1740. u32 resource_bit = (1 << resource);
  1741. int func = BP_FUNC(bp);
  1742. u32 hw_lock_control_reg;
  1743. /* Validating that the resource is within range */
  1744. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1745. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1746. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1747. return -EINVAL;
  1748. }
  1749. if (func <= 5) {
  1750. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1751. } else {
  1752. hw_lock_control_reg =
  1753. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1754. }
  1755. /* Validating that the resource is currently taken */
  1756. lock_status = REG_RD(bp, hw_lock_control_reg);
  1757. if (!(lock_status & resource_bit)) {
  1758. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1759. lock_status, resource_bit);
  1760. return -EFAULT;
  1761. }
  1762. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1763. return 0;
  1764. }
  1765. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1766. {
  1767. /* The GPIO should be swapped if swap register is set and active */
  1768. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1769. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1770. int gpio_shift = gpio_num +
  1771. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1772. u32 gpio_mask = (1 << gpio_shift);
  1773. u32 gpio_reg;
  1774. int value;
  1775. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1776. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1777. return -EINVAL;
  1778. }
  1779. /* read GPIO value */
  1780. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1781. /* get the requested pin value */
  1782. if ((gpio_reg & gpio_mask) == gpio_mask)
  1783. value = 1;
  1784. else
  1785. value = 0;
  1786. return value;
  1787. }
  1788. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1789. {
  1790. /* The GPIO should be swapped if swap register is set and active */
  1791. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1792. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1793. int gpio_shift = gpio_num +
  1794. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1795. u32 gpio_mask = (1 << gpio_shift);
  1796. u32 gpio_reg;
  1797. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1798. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1799. return -EINVAL;
  1800. }
  1801. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1802. /* read GPIO and mask except the float bits */
  1803. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1804. switch (mode) {
  1805. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1806. DP(NETIF_MSG_LINK,
  1807. "Set GPIO %d (shift %d) -> output low\n",
  1808. gpio_num, gpio_shift);
  1809. /* clear FLOAT and set CLR */
  1810. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1811. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1812. break;
  1813. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1814. DP(NETIF_MSG_LINK,
  1815. "Set GPIO %d (shift %d) -> output high\n",
  1816. gpio_num, gpio_shift);
  1817. /* clear FLOAT and set SET */
  1818. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1819. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1820. break;
  1821. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1822. DP(NETIF_MSG_LINK,
  1823. "Set GPIO %d (shift %d) -> input\n",
  1824. gpio_num, gpio_shift);
  1825. /* set FLOAT */
  1826. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1827. break;
  1828. default:
  1829. break;
  1830. }
  1831. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1832. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1833. return 0;
  1834. }
  1835. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1836. {
  1837. u32 gpio_reg = 0;
  1838. int rc = 0;
  1839. /* Any port swapping should be handled by caller. */
  1840. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1841. /* read GPIO and mask except the float bits */
  1842. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1843. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1844. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1845. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1846. switch (mode) {
  1847. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1848. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1849. /* set CLR */
  1850. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1851. break;
  1852. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1853. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1854. /* set SET */
  1855. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1856. break;
  1857. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1858. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1859. /* set FLOAT */
  1860. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1861. break;
  1862. default:
  1863. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1864. rc = -EINVAL;
  1865. break;
  1866. }
  1867. if (rc == 0)
  1868. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1869. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1870. return rc;
  1871. }
  1872. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1873. {
  1874. /* The GPIO should be swapped if swap register is set and active */
  1875. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1876. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1877. int gpio_shift = gpio_num +
  1878. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1879. u32 gpio_mask = (1 << gpio_shift);
  1880. u32 gpio_reg;
  1881. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1882. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1883. return -EINVAL;
  1884. }
  1885. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1886. /* read GPIO int */
  1887. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1888. switch (mode) {
  1889. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1890. DP(NETIF_MSG_LINK,
  1891. "Clear GPIO INT %d (shift %d) -> output low\n",
  1892. gpio_num, gpio_shift);
  1893. /* clear SET and set CLR */
  1894. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1895. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1896. break;
  1897. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1898. DP(NETIF_MSG_LINK,
  1899. "Set GPIO INT %d (shift %d) -> output high\n",
  1900. gpio_num, gpio_shift);
  1901. /* clear CLR and set SET */
  1902. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1903. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1904. break;
  1905. default:
  1906. break;
  1907. }
  1908. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1909. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1910. return 0;
  1911. }
  1912. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1913. {
  1914. u32 spio_reg;
  1915. /* Only 2 SPIOs are configurable */
  1916. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1917. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1918. return -EINVAL;
  1919. }
  1920. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1921. /* read SPIO and mask except the float bits */
  1922. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1923. switch (mode) {
  1924. case MISC_SPIO_OUTPUT_LOW:
  1925. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1926. /* clear FLOAT and set CLR */
  1927. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1928. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1929. break;
  1930. case MISC_SPIO_OUTPUT_HIGH:
  1931. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1932. /* clear FLOAT and set SET */
  1933. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1934. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1935. break;
  1936. case MISC_SPIO_INPUT_HI_Z:
  1937. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1938. /* set FLOAT */
  1939. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1940. break;
  1941. default:
  1942. break;
  1943. }
  1944. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1945. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1946. return 0;
  1947. }
  1948. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1949. {
  1950. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1951. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1952. ADVERTISED_Pause);
  1953. switch (bp->link_vars.ieee_fc &
  1954. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1955. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1956. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1957. ADVERTISED_Pause);
  1958. break;
  1959. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1960. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1961. break;
  1962. default:
  1963. break;
  1964. }
  1965. }
  1966. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1967. {
  1968. /* Initialize link parameters structure variables
  1969. * It is recommended to turn off RX FC for jumbo frames
  1970. * for better performance
  1971. */
  1972. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1973. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1974. else
  1975. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1976. }
  1977. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1978. {
  1979. u32 pause_enabled = 0;
  1980. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1981. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1982. pause_enabled = 1;
  1983. REG_WR(bp, BAR_USTRORM_INTMEM +
  1984. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1985. pause_enabled);
  1986. }
  1987. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1988. pause_enabled ? "enabled" : "disabled");
  1989. }
  1990. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1991. {
  1992. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1993. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1994. if (!BP_NOMCP(bp)) {
  1995. bnx2x_set_requested_fc(bp);
  1996. bnx2x_acquire_phy_lock(bp);
  1997. if (load_mode == LOAD_DIAG) {
  1998. struct link_params *lp = &bp->link_params;
  1999. lp->loopback_mode = LOOPBACK_XGXS;
  2000. /* Prefer doing PHY loopback at highest speed */
  2001. if (lp->req_line_speed[cfx_idx] < SPEED_20000) {
  2002. if (lp->speed_cap_mask[cfx_idx] &
  2003. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
  2004. lp->req_line_speed[cfx_idx] =
  2005. SPEED_20000;
  2006. else if (lp->speed_cap_mask[cfx_idx] &
  2007. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  2008. lp->req_line_speed[cfx_idx] =
  2009. SPEED_10000;
  2010. else
  2011. lp->req_line_speed[cfx_idx] =
  2012. SPEED_1000;
  2013. }
  2014. }
  2015. if (load_mode == LOAD_LOOPBACK_EXT) {
  2016. struct link_params *lp = &bp->link_params;
  2017. lp->loopback_mode = LOOPBACK_EXT;
  2018. }
  2019. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2020. bnx2x_release_phy_lock(bp);
  2021. bnx2x_init_dropless_fc(bp);
  2022. bnx2x_calc_fc_adv(bp);
  2023. if (bp->link_vars.link_up) {
  2024. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2025. bnx2x_link_report(bp);
  2026. }
  2027. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2028. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2029. return rc;
  2030. }
  2031. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2032. return -EINVAL;
  2033. }
  2034. void bnx2x_link_set(struct bnx2x *bp)
  2035. {
  2036. if (!BP_NOMCP(bp)) {
  2037. bnx2x_acquire_phy_lock(bp);
  2038. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2039. bnx2x_release_phy_lock(bp);
  2040. bnx2x_init_dropless_fc(bp);
  2041. bnx2x_calc_fc_adv(bp);
  2042. } else
  2043. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2044. }
  2045. static void bnx2x__link_reset(struct bnx2x *bp)
  2046. {
  2047. if (!BP_NOMCP(bp)) {
  2048. bnx2x_acquire_phy_lock(bp);
  2049. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2050. bnx2x_release_phy_lock(bp);
  2051. } else
  2052. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2053. }
  2054. void bnx2x_force_link_reset(struct bnx2x *bp)
  2055. {
  2056. bnx2x_acquire_phy_lock(bp);
  2057. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2058. bnx2x_release_phy_lock(bp);
  2059. }
  2060. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2061. {
  2062. u8 rc = 0;
  2063. if (!BP_NOMCP(bp)) {
  2064. bnx2x_acquire_phy_lock(bp);
  2065. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2066. is_serdes);
  2067. bnx2x_release_phy_lock(bp);
  2068. } else
  2069. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2070. return rc;
  2071. }
  2072. /* Calculates the sum of vn_min_rates.
  2073. It's needed for further normalizing of the min_rates.
  2074. Returns:
  2075. sum of vn_min_rates.
  2076. or
  2077. 0 - if all the min_rates are 0.
  2078. In the later case fairness algorithm should be deactivated.
  2079. If not all min_rates are zero then those that are zeroes will be set to 1.
  2080. */
  2081. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2082. struct cmng_init_input *input)
  2083. {
  2084. int all_zero = 1;
  2085. int vn;
  2086. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2087. u32 vn_cfg = bp->mf_config[vn];
  2088. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2089. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2090. /* Skip hidden vns */
  2091. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2092. vn_min_rate = 0;
  2093. /* If min rate is zero - set it to 1 */
  2094. else if (!vn_min_rate)
  2095. vn_min_rate = DEF_MIN_RATE;
  2096. else
  2097. all_zero = 0;
  2098. input->vnic_min_rate[vn] = vn_min_rate;
  2099. }
  2100. /* if ETS or all min rates are zeros - disable fairness */
  2101. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2102. input->flags.cmng_enables &=
  2103. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2104. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2105. } else if (all_zero) {
  2106. input->flags.cmng_enables &=
  2107. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2108. DP(NETIF_MSG_IFUP,
  2109. "All MIN values are zeroes fairness will be disabled\n");
  2110. } else
  2111. input->flags.cmng_enables |=
  2112. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2113. }
  2114. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2115. struct cmng_init_input *input)
  2116. {
  2117. u16 vn_max_rate;
  2118. u32 vn_cfg = bp->mf_config[vn];
  2119. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2120. vn_max_rate = 0;
  2121. else {
  2122. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2123. if (IS_MF_PERCENT_BW(bp)) {
  2124. /* maxCfg in percents of linkspeed */
  2125. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2126. } else /* SD modes */
  2127. /* maxCfg is absolute in 100Mb units */
  2128. vn_max_rate = maxCfg * 100;
  2129. }
  2130. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2131. input->vnic_max_rate[vn] = vn_max_rate;
  2132. }
  2133. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2134. {
  2135. if (CHIP_REV_IS_SLOW(bp))
  2136. return CMNG_FNS_NONE;
  2137. if (IS_MF(bp))
  2138. return CMNG_FNS_MINMAX;
  2139. return CMNG_FNS_NONE;
  2140. }
  2141. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2142. {
  2143. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2144. if (BP_NOMCP(bp))
  2145. return; /* what should be the default value in this case */
  2146. /* For 2 port configuration the absolute function number formula
  2147. * is:
  2148. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2149. *
  2150. * and there are 4 functions per port
  2151. *
  2152. * For 4 port configuration it is
  2153. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2154. *
  2155. * and there are 2 functions per port
  2156. */
  2157. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2158. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2159. if (func >= E1H_FUNC_MAX)
  2160. break;
  2161. bp->mf_config[vn] =
  2162. MF_CFG_RD(bp, func_mf_config[func].config);
  2163. }
  2164. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2165. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2166. bp->flags |= MF_FUNC_DIS;
  2167. } else {
  2168. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2169. bp->flags &= ~MF_FUNC_DIS;
  2170. }
  2171. }
  2172. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2173. {
  2174. struct cmng_init_input input;
  2175. memset(&input, 0, sizeof(struct cmng_init_input));
  2176. input.port_rate = bp->link_vars.line_speed;
  2177. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2178. int vn;
  2179. /* read mf conf from shmem */
  2180. if (read_cfg)
  2181. bnx2x_read_mf_cfg(bp);
  2182. /* vn_weight_sum and enable fairness if not 0 */
  2183. bnx2x_calc_vn_min(bp, &input);
  2184. /* calculate and set min-max rate for each vn */
  2185. if (bp->port.pmf)
  2186. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2187. bnx2x_calc_vn_max(bp, vn, &input);
  2188. /* always enable rate shaping and fairness */
  2189. input.flags.cmng_enables |=
  2190. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2191. bnx2x_init_cmng(&input, &bp->cmng);
  2192. return;
  2193. }
  2194. /* rate shaping and fairness are disabled */
  2195. DP(NETIF_MSG_IFUP,
  2196. "rate shaping and fairness are disabled\n");
  2197. }
  2198. static void storm_memset_cmng(struct bnx2x *bp,
  2199. struct cmng_init *cmng,
  2200. u8 port)
  2201. {
  2202. int vn;
  2203. size_t size = sizeof(struct cmng_struct_per_port);
  2204. u32 addr = BAR_XSTRORM_INTMEM +
  2205. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2206. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2207. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2208. int func = func_by_vn(bp, vn);
  2209. addr = BAR_XSTRORM_INTMEM +
  2210. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2211. size = sizeof(struct rate_shaping_vars_per_vn);
  2212. __storm_memset_struct(bp, addr, size,
  2213. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2214. addr = BAR_XSTRORM_INTMEM +
  2215. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2216. size = sizeof(struct fairness_vars_per_vn);
  2217. __storm_memset_struct(bp, addr, size,
  2218. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2219. }
  2220. }
  2221. /* init cmng mode in HW according to local configuration */
  2222. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2223. {
  2224. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2225. if (cmng_fns != CMNG_FNS_NONE) {
  2226. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2227. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2228. } else {
  2229. /* rate shaping and fairness are disabled */
  2230. DP(NETIF_MSG_IFUP,
  2231. "single function mode without fairness\n");
  2232. }
  2233. }
  2234. /* This function is called upon link interrupt */
  2235. static void bnx2x_link_attn(struct bnx2x *bp)
  2236. {
  2237. /* Make sure that we are synced with the current statistics */
  2238. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2239. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2240. bnx2x_init_dropless_fc(bp);
  2241. if (bp->link_vars.link_up) {
  2242. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2243. struct host_port_stats *pstats;
  2244. pstats = bnx2x_sp(bp, port_stats);
  2245. /* reset old mac stats */
  2246. memset(&(pstats->mac_stx[0]), 0,
  2247. sizeof(struct mac_stx));
  2248. }
  2249. if (bp->state == BNX2X_STATE_OPEN)
  2250. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2251. }
  2252. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2253. bnx2x_set_local_cmng(bp);
  2254. __bnx2x_link_report(bp);
  2255. if (IS_MF(bp))
  2256. bnx2x_link_sync_notify(bp);
  2257. }
  2258. void bnx2x__link_status_update(struct bnx2x *bp)
  2259. {
  2260. if (bp->state != BNX2X_STATE_OPEN)
  2261. return;
  2262. /* read updated dcb configuration */
  2263. if (IS_PF(bp)) {
  2264. bnx2x_dcbx_pmf_update(bp);
  2265. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2266. if (bp->link_vars.link_up)
  2267. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2268. else
  2269. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2270. /* indicate link status */
  2271. bnx2x_link_report(bp);
  2272. } else { /* VF */
  2273. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2274. SUPPORTED_10baseT_Full |
  2275. SUPPORTED_100baseT_Half |
  2276. SUPPORTED_100baseT_Full |
  2277. SUPPORTED_1000baseT_Full |
  2278. SUPPORTED_2500baseX_Full |
  2279. SUPPORTED_10000baseT_Full |
  2280. SUPPORTED_TP |
  2281. SUPPORTED_FIBRE |
  2282. SUPPORTED_Autoneg |
  2283. SUPPORTED_Pause |
  2284. SUPPORTED_Asym_Pause);
  2285. bp->port.advertising[0] = bp->port.supported[0];
  2286. bp->link_params.bp = bp;
  2287. bp->link_params.port = BP_PORT(bp);
  2288. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2289. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2290. bp->link_params.req_line_speed[0] = SPEED_10000;
  2291. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2292. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2293. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2294. bp->link_vars.line_speed = SPEED_10000;
  2295. bp->link_vars.link_status =
  2296. (LINK_STATUS_LINK_UP |
  2297. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2298. bp->link_vars.link_up = 1;
  2299. bp->link_vars.duplex = DUPLEX_FULL;
  2300. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2301. __bnx2x_link_report(bp);
  2302. bnx2x_sample_bulletin(bp);
  2303. /* if bulletin board did not have an update for link status
  2304. * __bnx2x_link_report will report current status
  2305. * but it will NOT duplicate report in case of already reported
  2306. * during sampling bulletin board.
  2307. */
  2308. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2309. }
  2310. }
  2311. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2312. u16 vlan_val, u8 allowed_prio)
  2313. {
  2314. struct bnx2x_func_state_params func_params = {NULL};
  2315. struct bnx2x_func_afex_update_params *f_update_params =
  2316. &func_params.params.afex_update;
  2317. func_params.f_obj = &bp->func_obj;
  2318. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2319. /* no need to wait for RAMROD completion, so don't
  2320. * set RAMROD_COMP_WAIT flag
  2321. */
  2322. f_update_params->vif_id = vifid;
  2323. f_update_params->afex_default_vlan = vlan_val;
  2324. f_update_params->allowed_priorities = allowed_prio;
  2325. /* if ramrod can not be sent, response to MCP immediately */
  2326. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2327. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2328. return 0;
  2329. }
  2330. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2331. u16 vif_index, u8 func_bit_map)
  2332. {
  2333. struct bnx2x_func_state_params func_params = {NULL};
  2334. struct bnx2x_func_afex_viflists_params *update_params =
  2335. &func_params.params.afex_viflists;
  2336. int rc;
  2337. u32 drv_msg_code;
  2338. /* validate only LIST_SET and LIST_GET are received from switch */
  2339. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2340. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2341. cmd_type);
  2342. func_params.f_obj = &bp->func_obj;
  2343. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2344. /* set parameters according to cmd_type */
  2345. update_params->afex_vif_list_command = cmd_type;
  2346. update_params->vif_list_index = vif_index;
  2347. update_params->func_bit_map =
  2348. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2349. update_params->func_to_clear = 0;
  2350. drv_msg_code =
  2351. (cmd_type == VIF_LIST_RULE_GET) ?
  2352. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2353. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2354. /* if ramrod can not be sent, respond to MCP immediately for
  2355. * SET and GET requests (other are not triggered from MCP)
  2356. */
  2357. rc = bnx2x_func_state_change(bp, &func_params);
  2358. if (rc < 0)
  2359. bnx2x_fw_command(bp, drv_msg_code, 0);
  2360. return 0;
  2361. }
  2362. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2363. {
  2364. struct afex_stats afex_stats;
  2365. u32 func = BP_ABS_FUNC(bp);
  2366. u32 mf_config;
  2367. u16 vlan_val;
  2368. u32 vlan_prio;
  2369. u16 vif_id;
  2370. u8 allowed_prio;
  2371. u8 vlan_mode;
  2372. u32 addr_to_write, vifid, addrs, stats_type, i;
  2373. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2374. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2375. DP(BNX2X_MSG_MCP,
  2376. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2377. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2378. }
  2379. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2380. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2381. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2382. DP(BNX2X_MSG_MCP,
  2383. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2384. vifid, addrs);
  2385. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2386. addrs);
  2387. }
  2388. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2389. addr_to_write = SHMEM2_RD(bp,
  2390. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2391. stats_type = SHMEM2_RD(bp,
  2392. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2393. DP(BNX2X_MSG_MCP,
  2394. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2395. addr_to_write);
  2396. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2397. /* write response to scratchpad, for MCP */
  2398. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2399. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2400. *(((u32 *)(&afex_stats))+i));
  2401. /* send ack message to MCP */
  2402. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2403. }
  2404. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2405. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2406. bp->mf_config[BP_VN(bp)] = mf_config;
  2407. DP(BNX2X_MSG_MCP,
  2408. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2409. mf_config);
  2410. /* if VIF_SET is "enabled" */
  2411. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2412. /* set rate limit directly to internal RAM */
  2413. struct cmng_init_input cmng_input;
  2414. struct rate_shaping_vars_per_vn m_rs_vn;
  2415. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2416. u32 addr = BAR_XSTRORM_INTMEM +
  2417. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2418. bp->mf_config[BP_VN(bp)] = mf_config;
  2419. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2420. m_rs_vn.vn_counter.rate =
  2421. cmng_input.vnic_max_rate[BP_VN(bp)];
  2422. m_rs_vn.vn_counter.quota =
  2423. (m_rs_vn.vn_counter.rate *
  2424. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2425. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2426. /* read relevant values from mf_cfg struct in shmem */
  2427. vif_id =
  2428. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2429. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2430. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2431. vlan_val =
  2432. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2433. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2434. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2435. vlan_prio = (mf_config &
  2436. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2437. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2438. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2439. vlan_mode =
  2440. (MF_CFG_RD(bp,
  2441. func_mf_config[func].afex_config) &
  2442. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2443. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2444. allowed_prio =
  2445. (MF_CFG_RD(bp,
  2446. func_mf_config[func].afex_config) &
  2447. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2448. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2449. /* send ramrod to FW, return in case of failure */
  2450. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2451. allowed_prio))
  2452. return;
  2453. bp->afex_def_vlan_tag = vlan_val;
  2454. bp->afex_vlan_mode = vlan_mode;
  2455. } else {
  2456. /* notify link down because BP->flags is disabled */
  2457. bnx2x_link_report(bp);
  2458. /* send INVALID VIF ramrod to FW */
  2459. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2460. /* Reset the default afex VLAN */
  2461. bp->afex_def_vlan_tag = -1;
  2462. }
  2463. }
  2464. }
  2465. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2466. {
  2467. struct bnx2x_func_switch_update_params *switch_update_params;
  2468. struct bnx2x_func_state_params func_params;
  2469. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2470. switch_update_params = &func_params.params.switch_update;
  2471. func_params.f_obj = &bp->func_obj;
  2472. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2473. /* Prepare parameters for function state transitions */
  2474. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  2475. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  2476. if (IS_MF_UFP(bp) || IS_MF_BD(bp)) {
  2477. int func = BP_ABS_FUNC(bp);
  2478. u32 val;
  2479. /* Re-learn the S-tag from shmem */
  2480. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2481. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2482. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2483. bp->mf_ov = val;
  2484. } else {
  2485. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2486. goto fail;
  2487. }
  2488. /* Configure new S-tag in LLH */
  2489. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2490. bp->mf_ov);
  2491. /* Send Ramrod to update FW of change */
  2492. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2493. &switch_update_params->changes);
  2494. switch_update_params->vlan = bp->mf_ov;
  2495. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2496. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2497. bp->mf_ov);
  2498. goto fail;
  2499. } else {
  2500. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n",
  2501. bp->mf_ov);
  2502. }
  2503. } else {
  2504. goto fail;
  2505. }
  2506. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2507. return;
  2508. fail:
  2509. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2510. }
  2511. static void bnx2x_pmf_update(struct bnx2x *bp)
  2512. {
  2513. int port = BP_PORT(bp);
  2514. u32 val;
  2515. bp->port.pmf = 1;
  2516. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2517. /*
  2518. * We need the mb() to ensure the ordering between the writing to
  2519. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2520. */
  2521. smp_mb();
  2522. /* queue a periodic task */
  2523. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2524. bnx2x_dcbx_pmf_update(bp);
  2525. /* enable nig attention */
  2526. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2527. if (bp->common.int_block == INT_BLOCK_HC) {
  2528. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2529. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2530. } else if (!CHIP_IS_E1x(bp)) {
  2531. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2532. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2533. }
  2534. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2535. }
  2536. /* end of Link */
  2537. /* slow path */
  2538. /*
  2539. * General service functions
  2540. */
  2541. /* send the MCP a request, block until there is a reply */
  2542. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2543. {
  2544. int mb_idx = BP_FW_MB_IDX(bp);
  2545. u32 seq;
  2546. u32 rc = 0;
  2547. u32 cnt = 1;
  2548. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2549. mutex_lock(&bp->fw_mb_mutex);
  2550. seq = ++bp->fw_seq;
  2551. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2552. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2553. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2554. (command | seq), param);
  2555. do {
  2556. /* let the FW do it's magic ... */
  2557. msleep(delay);
  2558. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2559. /* Give the FW up to 5 second (500*10ms) */
  2560. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2561. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2562. cnt*delay, rc, seq);
  2563. /* is this a reply to our command? */
  2564. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2565. rc &= FW_MSG_CODE_MASK;
  2566. else {
  2567. /* FW BUG! */
  2568. BNX2X_ERR("FW failed to respond!\n");
  2569. bnx2x_fw_dump(bp);
  2570. rc = 0;
  2571. }
  2572. mutex_unlock(&bp->fw_mb_mutex);
  2573. return rc;
  2574. }
  2575. static void storm_memset_func_cfg(struct bnx2x *bp,
  2576. struct tstorm_eth_function_common_config *tcfg,
  2577. u16 abs_fid)
  2578. {
  2579. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2580. u32 addr = BAR_TSTRORM_INTMEM +
  2581. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2582. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2583. }
  2584. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2585. {
  2586. if (CHIP_IS_E1x(bp)) {
  2587. struct tstorm_eth_function_common_config tcfg = {0};
  2588. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2589. }
  2590. /* Enable the function in the FW */
  2591. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2592. storm_memset_func_en(bp, p->func_id, 1);
  2593. /* spq */
  2594. if (p->spq_active) {
  2595. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2596. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2597. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2598. }
  2599. }
  2600. /**
  2601. * bnx2x_get_common_flags - Return common flags
  2602. *
  2603. * @bp device handle
  2604. * @fp queue handle
  2605. * @zero_stats TRUE if statistics zeroing is needed
  2606. *
  2607. * Return the flags that are common for the Tx-only and not normal connections.
  2608. */
  2609. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2610. struct bnx2x_fastpath *fp,
  2611. bool zero_stats)
  2612. {
  2613. unsigned long flags = 0;
  2614. /* PF driver will always initialize the Queue to an ACTIVE state */
  2615. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2616. /* tx only connections collect statistics (on the same index as the
  2617. * parent connection). The statistics are zeroed when the parent
  2618. * connection is initialized.
  2619. */
  2620. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2621. if (zero_stats)
  2622. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2623. if (bp->flags & TX_SWITCHING)
  2624. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2625. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2626. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2627. #ifdef BNX2X_STOP_ON_ERROR
  2628. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2629. #endif
  2630. return flags;
  2631. }
  2632. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2633. struct bnx2x_fastpath *fp,
  2634. bool leading)
  2635. {
  2636. unsigned long flags = 0;
  2637. /* calculate other queue flags */
  2638. if (IS_MF_SD(bp))
  2639. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2640. if (IS_FCOE_FP(fp)) {
  2641. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2642. /* For FCoE - force usage of default priority (for afex) */
  2643. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2644. }
  2645. if (fp->mode != TPA_MODE_DISABLED) {
  2646. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2647. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2648. if (fp->mode == TPA_MODE_GRO)
  2649. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2650. }
  2651. if (leading) {
  2652. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2653. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2654. }
  2655. /* Always set HW VLAN stripping */
  2656. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2657. /* configure silent vlan removal */
  2658. if (IS_MF_AFEX(bp))
  2659. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2660. return flags | bnx2x_get_common_flags(bp, fp, true);
  2661. }
  2662. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2663. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2664. u8 cos)
  2665. {
  2666. gen_init->stat_id = bnx2x_stats_id(fp);
  2667. gen_init->spcl_id = fp->cl_id;
  2668. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2669. if (IS_FCOE_FP(fp))
  2670. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2671. else
  2672. gen_init->mtu = bp->dev->mtu;
  2673. gen_init->cos = cos;
  2674. gen_init->fp_hsi = ETH_FP_HSI_VERSION;
  2675. }
  2676. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2677. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2678. struct bnx2x_rxq_setup_params *rxq_init)
  2679. {
  2680. u8 max_sge = 0;
  2681. u16 sge_sz = 0;
  2682. u16 tpa_agg_size = 0;
  2683. if (fp->mode != TPA_MODE_DISABLED) {
  2684. pause->sge_th_lo = SGE_TH_LO(bp);
  2685. pause->sge_th_hi = SGE_TH_HI(bp);
  2686. /* validate SGE ring has enough to cross high threshold */
  2687. WARN_ON(bp->dropless_fc &&
  2688. pause->sge_th_hi + FW_PREFETCH_CNT >
  2689. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2690. tpa_agg_size = TPA_AGG_SIZE;
  2691. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2692. SGE_PAGE_SHIFT;
  2693. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2694. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2695. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2696. }
  2697. /* pause - not for e1 */
  2698. if (!CHIP_IS_E1(bp)) {
  2699. pause->bd_th_lo = BD_TH_LO(bp);
  2700. pause->bd_th_hi = BD_TH_HI(bp);
  2701. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2702. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2703. /*
  2704. * validate that rings have enough entries to cross
  2705. * high thresholds
  2706. */
  2707. WARN_ON(bp->dropless_fc &&
  2708. pause->bd_th_hi + FW_PREFETCH_CNT >
  2709. bp->rx_ring_size);
  2710. WARN_ON(bp->dropless_fc &&
  2711. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2712. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2713. pause->pri_map = 1;
  2714. }
  2715. /* rxq setup */
  2716. rxq_init->dscr_map = fp->rx_desc_mapping;
  2717. rxq_init->sge_map = fp->rx_sge_mapping;
  2718. rxq_init->rcq_map = fp->rx_comp_mapping;
  2719. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2720. /* This should be a maximum number of data bytes that may be
  2721. * placed on the BD (not including paddings).
  2722. */
  2723. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2724. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2725. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2726. rxq_init->tpa_agg_sz = tpa_agg_size;
  2727. rxq_init->sge_buf_sz = sge_sz;
  2728. rxq_init->max_sges_pkt = max_sge;
  2729. rxq_init->rss_engine_id = BP_FUNC(bp);
  2730. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2731. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2732. *
  2733. * For PF Clients it should be the maximum available number.
  2734. * VF driver(s) may want to define it to a smaller value.
  2735. */
  2736. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2737. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2738. rxq_init->fw_sb_id = fp->fw_sb_id;
  2739. if (IS_FCOE_FP(fp))
  2740. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2741. else
  2742. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2743. /* configure silent vlan removal
  2744. * if multi function mode is afex, then mask default vlan
  2745. */
  2746. if (IS_MF_AFEX(bp)) {
  2747. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2748. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2749. }
  2750. }
  2751. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2752. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2753. u8 cos)
  2754. {
  2755. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2756. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2757. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2758. txq_init->fw_sb_id = fp->fw_sb_id;
  2759. /*
  2760. * set the tss leading client id for TX classification ==
  2761. * leading RSS client id
  2762. */
  2763. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2764. if (IS_FCOE_FP(fp)) {
  2765. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2766. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2767. }
  2768. }
  2769. static void bnx2x_pf_init(struct bnx2x *bp)
  2770. {
  2771. struct bnx2x_func_init_params func_init = {0};
  2772. struct event_ring_data eq_data = { {0} };
  2773. if (!CHIP_IS_E1x(bp)) {
  2774. /* reset IGU PF statistics: MSIX + ATTN */
  2775. /* PF */
  2776. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2777. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2778. (CHIP_MODE_IS_4_PORT(bp) ?
  2779. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2780. /* ATTN */
  2781. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2782. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2783. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2784. (CHIP_MODE_IS_4_PORT(bp) ?
  2785. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2786. }
  2787. func_init.spq_active = true;
  2788. func_init.pf_id = BP_FUNC(bp);
  2789. func_init.func_id = BP_FUNC(bp);
  2790. func_init.spq_map = bp->spq_mapping;
  2791. func_init.spq_prod = bp->spq_prod_idx;
  2792. bnx2x_func_init(bp, &func_init);
  2793. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2794. /*
  2795. * Congestion management values depend on the link rate
  2796. * There is no active link so initial link rate is set to 10 Gbps.
  2797. * When the link comes up The congestion management values are
  2798. * re-calculated according to the actual link rate.
  2799. */
  2800. bp->link_vars.line_speed = SPEED_10000;
  2801. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2802. /* Only the PMF sets the HW */
  2803. if (bp->port.pmf)
  2804. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2805. /* init Event Queue - PCI bus guarantees correct endianity*/
  2806. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2807. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2808. eq_data.producer = bp->eq_prod;
  2809. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2810. eq_data.sb_id = DEF_SB_ID;
  2811. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2812. }
  2813. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2814. {
  2815. int port = BP_PORT(bp);
  2816. bnx2x_tx_disable(bp);
  2817. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2818. }
  2819. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2820. {
  2821. int port = BP_PORT(bp);
  2822. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2823. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2824. /* Tx queue should be only re-enabled */
  2825. netif_tx_wake_all_queues(bp->dev);
  2826. /*
  2827. * Should not call netif_carrier_on since it will be called if the link
  2828. * is up when checking for link state
  2829. */
  2830. }
  2831. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2832. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2833. {
  2834. struct eth_stats_info *ether_stat =
  2835. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2836. struct bnx2x_vlan_mac_obj *mac_obj =
  2837. &bp->sp_objs->mac_obj;
  2838. int i;
  2839. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2840. ETH_STAT_INFO_VERSION_LEN);
  2841. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2842. * mac_local field in ether_stat struct. The base address is offset by 2
  2843. * bytes to account for the field being 8 bytes but a mac address is
  2844. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2845. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2846. * allocated by the ether_stat struct, so the macs will land in their
  2847. * proper positions.
  2848. */
  2849. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2850. memset(ether_stat->mac_local + i, 0,
  2851. sizeof(ether_stat->mac_local[0]));
  2852. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2853. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2854. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2855. ETH_ALEN);
  2856. ether_stat->mtu_size = bp->dev->mtu;
  2857. if (bp->dev->features & NETIF_F_RXCSUM)
  2858. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2859. if (bp->dev->features & NETIF_F_TSO)
  2860. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2861. ether_stat->feature_flags |= bp->common.boot_mode;
  2862. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2863. ether_stat->txq_size = bp->tx_ring_size;
  2864. ether_stat->rxq_size = bp->rx_ring_size;
  2865. #ifdef CONFIG_BNX2X_SRIOV
  2866. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2867. #endif
  2868. }
  2869. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2870. {
  2871. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2872. struct fcoe_stats_info *fcoe_stat =
  2873. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2874. if (!CNIC_LOADED(bp))
  2875. return;
  2876. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2877. fcoe_stat->qos_priority =
  2878. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2879. /* insert FCoE stats from ramrod response */
  2880. if (!NO_FCOE(bp)) {
  2881. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2882. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2883. tstorm_queue_statistics;
  2884. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2885. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2886. xstorm_queue_statistics;
  2887. struct fcoe_statistics_params *fw_fcoe_stat =
  2888. &bp->fw_stats_data->fcoe;
  2889. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2890. fcoe_stat->rx_bytes_lo,
  2891. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2892. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2893. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2894. fcoe_stat->rx_bytes_lo,
  2895. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2896. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2897. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2898. fcoe_stat->rx_bytes_lo,
  2899. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2900. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2901. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2902. fcoe_stat->rx_bytes_lo,
  2903. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2904. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2905. fcoe_stat->rx_frames_lo,
  2906. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2907. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2908. fcoe_stat->rx_frames_lo,
  2909. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2910. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2911. fcoe_stat->rx_frames_lo,
  2912. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2913. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2914. fcoe_stat->rx_frames_lo,
  2915. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2916. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2917. fcoe_stat->tx_bytes_lo,
  2918. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2919. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2920. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2921. fcoe_stat->tx_bytes_lo,
  2922. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2923. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2924. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2925. fcoe_stat->tx_bytes_lo,
  2926. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2927. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2928. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2929. fcoe_stat->tx_bytes_lo,
  2930. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2931. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2932. fcoe_stat->tx_frames_lo,
  2933. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2934. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2935. fcoe_stat->tx_frames_lo,
  2936. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2937. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2938. fcoe_stat->tx_frames_lo,
  2939. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2940. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2941. fcoe_stat->tx_frames_lo,
  2942. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2943. }
  2944. /* ask L5 driver to add data to the struct */
  2945. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2946. }
  2947. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2948. {
  2949. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2950. struct iscsi_stats_info *iscsi_stat =
  2951. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2952. if (!CNIC_LOADED(bp))
  2953. return;
  2954. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2955. ETH_ALEN);
  2956. iscsi_stat->qos_priority =
  2957. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2958. /* ask L5 driver to add data to the struct */
  2959. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2960. }
  2961. /* called due to MCP event (on pmf):
  2962. * reread new bandwidth configuration
  2963. * configure FW
  2964. * notify others function about the change
  2965. */
  2966. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2967. {
  2968. /* Workaround for MFW bug.
  2969. * MFW is not supposed to generate BW attention in
  2970. * single function mode.
  2971. */
  2972. if (!IS_MF(bp)) {
  2973. DP(BNX2X_MSG_MCP,
  2974. "Ignoring MF BW config in single function mode\n");
  2975. return;
  2976. }
  2977. if (bp->link_vars.link_up) {
  2978. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2979. bnx2x_link_sync_notify(bp);
  2980. }
  2981. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2982. }
  2983. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2984. {
  2985. bnx2x_config_mf_bw(bp);
  2986. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2987. }
  2988. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2989. {
  2990. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2991. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2992. }
  2993. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2994. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2995. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2996. {
  2997. enum drv_info_opcode op_code;
  2998. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2999. bool release = false;
  3000. int wait;
  3001. /* if drv_info version supported by MFW doesn't match - send NACK */
  3002. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  3003. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3004. return;
  3005. }
  3006. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  3007. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  3008. /* Must prevent other flows from accessing drv_info_to_mcp */
  3009. mutex_lock(&bp->drv_info_mutex);
  3010. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3011. sizeof(union drv_info_to_mcp));
  3012. switch (op_code) {
  3013. case ETH_STATS_OPCODE:
  3014. bnx2x_drv_info_ether_stat(bp);
  3015. break;
  3016. case FCOE_STATS_OPCODE:
  3017. bnx2x_drv_info_fcoe_stat(bp);
  3018. break;
  3019. case ISCSI_STATS_OPCODE:
  3020. bnx2x_drv_info_iscsi_stat(bp);
  3021. break;
  3022. default:
  3023. /* if op code isn't supported - send NACK */
  3024. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3025. goto out;
  3026. }
  3027. /* if we got drv_info attn from MFW then these fields are defined in
  3028. * shmem2 for sure
  3029. */
  3030. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3031. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3032. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3033. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3034. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3035. /* Since possible management wants both this and get_driver_version
  3036. * need to wait until management notifies us it finished utilizing
  3037. * the buffer.
  3038. */
  3039. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3040. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3041. } else if (!bp->drv_info_mng_owner) {
  3042. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3043. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3044. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3045. /* Management is done; need to clear indication */
  3046. if (indication & bit) {
  3047. SHMEM2_WR(bp, mfw_drv_indication,
  3048. indication & ~bit);
  3049. release = true;
  3050. break;
  3051. }
  3052. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3053. }
  3054. }
  3055. if (!release) {
  3056. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3057. bp->drv_info_mng_owner = true;
  3058. }
  3059. out:
  3060. mutex_unlock(&bp->drv_info_mutex);
  3061. }
  3062. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3063. {
  3064. u8 vals[4];
  3065. int i = 0;
  3066. if (bnx2x_format) {
  3067. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3068. &vals[0], &vals[1], &vals[2], &vals[3]);
  3069. if (i > 0)
  3070. vals[0] -= '0';
  3071. } else {
  3072. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3073. &vals[0], &vals[1], &vals[2], &vals[3]);
  3074. }
  3075. while (i < 4)
  3076. vals[i++] = 0;
  3077. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3078. }
  3079. void bnx2x_update_mng_version(struct bnx2x *bp)
  3080. {
  3081. u32 iscsiver = DRV_VER_NOT_LOADED;
  3082. u32 fcoever = DRV_VER_NOT_LOADED;
  3083. u32 ethver = DRV_VER_NOT_LOADED;
  3084. int idx = BP_FW_MB_IDX(bp);
  3085. u8 *version;
  3086. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3087. return;
  3088. mutex_lock(&bp->drv_info_mutex);
  3089. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3090. if (bp->drv_info_mng_owner)
  3091. goto out;
  3092. if (bp->state != BNX2X_STATE_OPEN)
  3093. goto out;
  3094. /* Parse ethernet driver version */
  3095. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3096. if (!CNIC_LOADED(bp))
  3097. goto out;
  3098. /* Try getting storage driver version via cnic */
  3099. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3100. sizeof(union drv_info_to_mcp));
  3101. bnx2x_drv_info_iscsi_stat(bp);
  3102. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3103. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3104. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3105. sizeof(union drv_info_to_mcp));
  3106. bnx2x_drv_info_fcoe_stat(bp);
  3107. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3108. fcoever = bnx2x_update_mng_version_utility(version, false);
  3109. out:
  3110. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3111. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3112. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3113. mutex_unlock(&bp->drv_info_mutex);
  3114. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3115. ethver, iscsiver, fcoever);
  3116. }
  3117. void bnx2x_update_mfw_dump(struct bnx2x *bp)
  3118. {
  3119. u32 drv_ver;
  3120. u32 valid_dump;
  3121. if (!SHMEM2_HAS(bp, drv_info))
  3122. return;
  3123. /* Update Driver load time, possibly broken in y2038 */
  3124. SHMEM2_WR(bp, drv_info.epoc, (u32)ktime_get_real_seconds());
  3125. drv_ver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3126. SHMEM2_WR(bp, drv_info.drv_ver, drv_ver);
  3127. SHMEM2_WR(bp, drv_info.fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  3128. /* Check & notify On-Chip dump. */
  3129. valid_dump = SHMEM2_RD(bp, drv_info.valid_dump);
  3130. if (valid_dump & FIRST_DUMP_VALID)
  3131. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 1st partition\n");
  3132. if (valid_dump & SECOND_DUMP_VALID)
  3133. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 2nd partition\n");
  3134. }
  3135. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3136. {
  3137. u32 cmd_ok, cmd_fail;
  3138. /* sanity */
  3139. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3140. event & DRV_STATUS_OEM_EVENT_MASK) {
  3141. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3142. return;
  3143. }
  3144. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3145. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3146. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3147. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3148. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3149. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3150. }
  3151. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3152. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3153. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3154. /* This is the only place besides the function initialization
  3155. * where the bp->flags can change so it is done without any
  3156. * locks
  3157. */
  3158. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3159. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3160. bp->flags |= MF_FUNC_DIS;
  3161. bnx2x_e1h_disable(bp);
  3162. } else {
  3163. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3164. bp->flags &= ~MF_FUNC_DIS;
  3165. bnx2x_e1h_enable(bp);
  3166. }
  3167. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3168. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3169. }
  3170. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3171. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3172. bnx2x_config_mf_bw(bp);
  3173. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3174. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3175. }
  3176. /* Report results to MCP */
  3177. if (event)
  3178. bnx2x_fw_command(bp, cmd_fail, 0);
  3179. else
  3180. bnx2x_fw_command(bp, cmd_ok, 0);
  3181. }
  3182. /* must be called under the spq lock */
  3183. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3184. {
  3185. struct eth_spe *next_spe = bp->spq_prod_bd;
  3186. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3187. bp->spq_prod_bd = bp->spq;
  3188. bp->spq_prod_idx = 0;
  3189. DP(BNX2X_MSG_SP, "end of spq\n");
  3190. } else {
  3191. bp->spq_prod_bd++;
  3192. bp->spq_prod_idx++;
  3193. }
  3194. return next_spe;
  3195. }
  3196. /* must be called under the spq lock */
  3197. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3198. {
  3199. int func = BP_FUNC(bp);
  3200. /*
  3201. * Make sure that BD data is updated before writing the producer:
  3202. * BD data is written to the memory, the producer is read from the
  3203. * memory, thus we need a full memory barrier to ensure the ordering.
  3204. */
  3205. mb();
  3206. REG_WR16_RELAXED(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3207. bp->spq_prod_idx);
  3208. mmiowb();
  3209. }
  3210. /**
  3211. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3212. *
  3213. * @cmd: command to check
  3214. * @cmd_type: command type
  3215. */
  3216. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3217. {
  3218. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3219. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3220. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3221. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3222. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3223. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3224. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3225. return true;
  3226. else
  3227. return false;
  3228. }
  3229. /**
  3230. * bnx2x_sp_post - place a single command on an SP ring
  3231. *
  3232. * @bp: driver handle
  3233. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3234. * @cid: SW CID the command is related to
  3235. * @data_hi: command private data address (high 32 bits)
  3236. * @data_lo: command private data address (low 32 bits)
  3237. * @cmd_type: command type (e.g. NONE, ETH)
  3238. *
  3239. * SP data is handled as if it's always an address pair, thus data fields are
  3240. * not swapped to little endian in upper functions. Instead this function swaps
  3241. * data as if it's two u32 fields.
  3242. */
  3243. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3244. u32 data_hi, u32 data_lo, int cmd_type)
  3245. {
  3246. struct eth_spe *spe;
  3247. u16 type;
  3248. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3249. #ifdef BNX2X_STOP_ON_ERROR
  3250. if (unlikely(bp->panic)) {
  3251. BNX2X_ERR("Can't post SP when there is panic\n");
  3252. return -EIO;
  3253. }
  3254. #endif
  3255. spin_lock_bh(&bp->spq_lock);
  3256. if (common) {
  3257. if (!atomic_read(&bp->eq_spq_left)) {
  3258. BNX2X_ERR("BUG! EQ ring full!\n");
  3259. spin_unlock_bh(&bp->spq_lock);
  3260. bnx2x_panic();
  3261. return -EBUSY;
  3262. }
  3263. } else if (!atomic_read(&bp->cq_spq_left)) {
  3264. BNX2X_ERR("BUG! SPQ ring full!\n");
  3265. spin_unlock_bh(&bp->spq_lock);
  3266. bnx2x_panic();
  3267. return -EBUSY;
  3268. }
  3269. spe = bnx2x_sp_get_next(bp);
  3270. /* CID needs port number to be encoded int it */
  3271. spe->hdr.conn_and_cmd_data =
  3272. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3273. HW_CID(bp, cid));
  3274. /* In some cases, type may already contain the func-id
  3275. * mainly in SRIOV related use cases, so we add it here only
  3276. * if it's not already set.
  3277. */
  3278. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3279. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3280. SPE_HDR_CONN_TYPE;
  3281. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3282. SPE_HDR_FUNCTION_ID);
  3283. } else {
  3284. type = cmd_type;
  3285. }
  3286. spe->hdr.type = cpu_to_le16(type);
  3287. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3288. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3289. /*
  3290. * It's ok if the actual decrement is issued towards the memory
  3291. * somewhere between the spin_lock and spin_unlock. Thus no
  3292. * more explicit memory barrier is needed.
  3293. */
  3294. if (common)
  3295. atomic_dec(&bp->eq_spq_left);
  3296. else
  3297. atomic_dec(&bp->cq_spq_left);
  3298. DP(BNX2X_MSG_SP,
  3299. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3300. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3301. (u32)(U64_LO(bp->spq_mapping) +
  3302. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3303. HW_CID(bp, cid), data_hi, data_lo, type,
  3304. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3305. bnx2x_sp_prod_update(bp);
  3306. spin_unlock_bh(&bp->spq_lock);
  3307. return 0;
  3308. }
  3309. /* acquire split MCP access lock register */
  3310. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3311. {
  3312. u32 j, val;
  3313. int rc = 0;
  3314. might_sleep();
  3315. for (j = 0; j < 1000; j++) {
  3316. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3317. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3318. if (val & MCPR_ACCESS_LOCK_LOCK)
  3319. break;
  3320. usleep_range(5000, 10000);
  3321. }
  3322. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3323. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3324. rc = -EBUSY;
  3325. }
  3326. return rc;
  3327. }
  3328. /* release split MCP access lock register */
  3329. static void bnx2x_release_alr(struct bnx2x *bp)
  3330. {
  3331. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3332. }
  3333. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3334. #define BNX2X_DEF_SB_IDX 0x0002
  3335. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3336. {
  3337. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3338. u16 rc = 0;
  3339. barrier(); /* status block is written to by the chip */
  3340. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3341. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3342. rc |= BNX2X_DEF_SB_ATT_IDX;
  3343. }
  3344. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3345. bp->def_idx = def_sb->sp_sb.running_index;
  3346. rc |= BNX2X_DEF_SB_IDX;
  3347. }
  3348. /* Do not reorder: indices reading should complete before handling */
  3349. barrier();
  3350. return rc;
  3351. }
  3352. /*
  3353. * slow path service functions
  3354. */
  3355. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3356. {
  3357. int port = BP_PORT(bp);
  3358. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3359. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3360. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3361. NIG_REG_MASK_INTERRUPT_PORT0;
  3362. u32 aeu_mask;
  3363. u32 nig_mask = 0;
  3364. u32 reg_addr;
  3365. if (bp->attn_state & asserted)
  3366. BNX2X_ERR("IGU ERROR\n");
  3367. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3368. aeu_mask = REG_RD(bp, aeu_addr);
  3369. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3370. aeu_mask, asserted);
  3371. aeu_mask &= ~(asserted & 0x3ff);
  3372. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3373. REG_WR(bp, aeu_addr, aeu_mask);
  3374. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3375. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3376. bp->attn_state |= asserted;
  3377. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3378. if (asserted & ATTN_HARD_WIRED_MASK) {
  3379. if (asserted & ATTN_NIG_FOR_FUNC) {
  3380. bnx2x_acquire_phy_lock(bp);
  3381. /* save nig interrupt mask */
  3382. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3383. /* If nig_mask is not set, no need to call the update
  3384. * function.
  3385. */
  3386. if (nig_mask) {
  3387. REG_WR(bp, nig_int_mask_addr, 0);
  3388. bnx2x_link_attn(bp);
  3389. }
  3390. /* handle unicore attn? */
  3391. }
  3392. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3393. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3394. if (asserted & GPIO_2_FUNC)
  3395. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3396. if (asserted & GPIO_3_FUNC)
  3397. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3398. if (asserted & GPIO_4_FUNC)
  3399. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3400. if (port == 0) {
  3401. if (asserted & ATTN_GENERAL_ATTN_1) {
  3402. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3403. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3404. }
  3405. if (asserted & ATTN_GENERAL_ATTN_2) {
  3406. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3407. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3408. }
  3409. if (asserted & ATTN_GENERAL_ATTN_3) {
  3410. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3411. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3412. }
  3413. } else {
  3414. if (asserted & ATTN_GENERAL_ATTN_4) {
  3415. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3416. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3417. }
  3418. if (asserted & ATTN_GENERAL_ATTN_5) {
  3419. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3420. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3421. }
  3422. if (asserted & ATTN_GENERAL_ATTN_6) {
  3423. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3424. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3425. }
  3426. }
  3427. } /* if hardwired */
  3428. if (bp->common.int_block == INT_BLOCK_HC)
  3429. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3430. COMMAND_REG_ATTN_BITS_SET);
  3431. else
  3432. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3433. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3434. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3435. REG_WR(bp, reg_addr, asserted);
  3436. /* now set back the mask */
  3437. if (asserted & ATTN_NIG_FOR_FUNC) {
  3438. /* Verify that IGU ack through BAR was written before restoring
  3439. * NIG mask. This loop should exit after 2-3 iterations max.
  3440. */
  3441. if (bp->common.int_block != INT_BLOCK_HC) {
  3442. u32 cnt = 0, igu_acked;
  3443. do {
  3444. igu_acked = REG_RD(bp,
  3445. IGU_REG_ATTENTION_ACK_BITS);
  3446. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3447. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3448. if (!igu_acked)
  3449. DP(NETIF_MSG_HW,
  3450. "Failed to verify IGU ack on time\n");
  3451. barrier();
  3452. }
  3453. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3454. bnx2x_release_phy_lock(bp);
  3455. }
  3456. }
  3457. static void bnx2x_fan_failure(struct bnx2x *bp)
  3458. {
  3459. int port = BP_PORT(bp);
  3460. u32 ext_phy_config;
  3461. /* mark the failure */
  3462. ext_phy_config =
  3463. SHMEM_RD(bp,
  3464. dev_info.port_hw_config[port].external_phy_config);
  3465. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3466. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3467. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3468. ext_phy_config);
  3469. /* log the failure */
  3470. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3471. "Please contact OEM Support for assistance\n");
  3472. /* Schedule device reset (unload)
  3473. * This is due to some boards consuming sufficient power when driver is
  3474. * up to overheat if fan fails.
  3475. */
  3476. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3477. }
  3478. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3479. {
  3480. int port = BP_PORT(bp);
  3481. int reg_offset;
  3482. u32 val;
  3483. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3484. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3485. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3486. val = REG_RD(bp, reg_offset);
  3487. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3488. REG_WR(bp, reg_offset, val);
  3489. BNX2X_ERR("SPIO5 hw attention\n");
  3490. /* Fan failure attention */
  3491. bnx2x_hw_reset_phy(&bp->link_params);
  3492. bnx2x_fan_failure(bp);
  3493. }
  3494. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3495. bnx2x_acquire_phy_lock(bp);
  3496. bnx2x_handle_module_detect_int(&bp->link_params);
  3497. bnx2x_release_phy_lock(bp);
  3498. }
  3499. if (attn & HW_INTERRUPT_ASSERT_SET_0) {
  3500. val = REG_RD(bp, reg_offset);
  3501. val &= ~(attn & HW_INTERRUPT_ASSERT_SET_0);
  3502. REG_WR(bp, reg_offset, val);
  3503. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3504. (u32)(attn & HW_INTERRUPT_ASSERT_SET_0));
  3505. bnx2x_panic();
  3506. }
  3507. }
  3508. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3509. {
  3510. u32 val;
  3511. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3512. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3513. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3514. /* DORQ discard attention */
  3515. if (val & 0x2)
  3516. BNX2X_ERR("FATAL error from DORQ\n");
  3517. }
  3518. if (attn & HW_INTERRUPT_ASSERT_SET_1) {
  3519. int port = BP_PORT(bp);
  3520. int reg_offset;
  3521. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3522. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3523. val = REG_RD(bp, reg_offset);
  3524. val &= ~(attn & HW_INTERRUPT_ASSERT_SET_1);
  3525. REG_WR(bp, reg_offset, val);
  3526. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3527. (u32)(attn & HW_INTERRUPT_ASSERT_SET_1));
  3528. bnx2x_panic();
  3529. }
  3530. }
  3531. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3532. {
  3533. u32 val;
  3534. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3535. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3536. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3537. /* CFC error attention */
  3538. if (val & 0x2)
  3539. BNX2X_ERR("FATAL error from CFC\n");
  3540. }
  3541. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3542. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3543. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3544. /* RQ_USDMDP_FIFO_OVERFLOW */
  3545. if (val & 0x18000)
  3546. BNX2X_ERR("FATAL error from PXP\n");
  3547. if (!CHIP_IS_E1x(bp)) {
  3548. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3549. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3550. }
  3551. }
  3552. if (attn & HW_INTERRUPT_ASSERT_SET_2) {
  3553. int port = BP_PORT(bp);
  3554. int reg_offset;
  3555. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3556. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3557. val = REG_RD(bp, reg_offset);
  3558. val &= ~(attn & HW_INTERRUPT_ASSERT_SET_2);
  3559. REG_WR(bp, reg_offset, val);
  3560. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3561. (u32)(attn & HW_INTERRUPT_ASSERT_SET_2));
  3562. bnx2x_panic();
  3563. }
  3564. }
  3565. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3566. {
  3567. u32 val;
  3568. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3569. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3570. int func = BP_FUNC(bp);
  3571. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3572. bnx2x_read_mf_cfg(bp);
  3573. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3574. func_mf_config[BP_ABS_FUNC(bp)].config);
  3575. val = SHMEM_RD(bp,
  3576. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3577. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3578. DRV_STATUS_OEM_EVENT_MASK))
  3579. bnx2x_oem_event(bp,
  3580. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3581. DRV_STATUS_OEM_EVENT_MASK)));
  3582. if (val & DRV_STATUS_SET_MF_BW)
  3583. bnx2x_set_mf_bw(bp);
  3584. if (val & DRV_STATUS_DRV_INFO_REQ)
  3585. bnx2x_handle_drv_info_req(bp);
  3586. if (val & DRV_STATUS_VF_DISABLED)
  3587. bnx2x_schedule_iov_task(bp,
  3588. BNX2X_IOV_HANDLE_FLR);
  3589. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3590. bnx2x_pmf_update(bp);
  3591. if (bp->port.pmf &&
  3592. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3593. bp->dcbx_enabled > 0)
  3594. /* start dcbx state machine */
  3595. bnx2x_dcbx_set_params(bp,
  3596. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3597. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3598. bnx2x_handle_afex_cmd(bp,
  3599. val & DRV_STATUS_AFEX_EVENT_MASK);
  3600. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3601. bnx2x_handle_eee_event(bp);
  3602. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3603. bnx2x_schedule_sp_rtnl(bp,
  3604. BNX2X_SP_RTNL_UPDATE_SVID, 0);
  3605. if (bp->link_vars.periodic_flags &
  3606. PERIODIC_FLAGS_LINK_EVENT) {
  3607. /* sync with link */
  3608. bnx2x_acquire_phy_lock(bp);
  3609. bp->link_vars.periodic_flags &=
  3610. ~PERIODIC_FLAGS_LINK_EVENT;
  3611. bnx2x_release_phy_lock(bp);
  3612. if (IS_MF(bp))
  3613. bnx2x_link_sync_notify(bp);
  3614. bnx2x_link_report(bp);
  3615. }
  3616. /* Always call it here: bnx2x_link_report() will
  3617. * prevent the link indication duplication.
  3618. */
  3619. bnx2x__link_status_update(bp);
  3620. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3621. BNX2X_ERR("MC assert!\n");
  3622. bnx2x_mc_assert(bp);
  3623. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3624. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3625. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3626. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3627. bnx2x_panic();
  3628. } else if (attn & BNX2X_MCP_ASSERT) {
  3629. BNX2X_ERR("MCP assert!\n");
  3630. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3631. bnx2x_fw_dump(bp);
  3632. } else
  3633. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3634. }
  3635. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3636. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3637. if (attn & BNX2X_GRC_TIMEOUT) {
  3638. val = CHIP_IS_E1(bp) ? 0 :
  3639. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3640. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3641. }
  3642. if (attn & BNX2X_GRC_RSV) {
  3643. val = CHIP_IS_E1(bp) ? 0 :
  3644. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3645. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3646. }
  3647. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3648. }
  3649. }
  3650. /*
  3651. * Bits map:
  3652. * 0-7 - Engine0 load counter.
  3653. * 8-15 - Engine1 load counter.
  3654. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3655. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3656. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3657. * on the engine
  3658. * 19 - Engine1 ONE_IS_LOADED.
  3659. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3660. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3661. * just the one belonging to its engine).
  3662. *
  3663. */
  3664. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3665. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3666. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3667. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3668. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3669. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3670. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3671. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3672. /*
  3673. * Set the GLOBAL_RESET bit.
  3674. *
  3675. * Should be run under rtnl lock
  3676. */
  3677. void bnx2x_set_reset_global(struct bnx2x *bp)
  3678. {
  3679. u32 val;
  3680. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3681. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3682. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3683. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3684. }
  3685. /*
  3686. * Clear the GLOBAL_RESET bit.
  3687. *
  3688. * Should be run under rtnl lock
  3689. */
  3690. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3691. {
  3692. u32 val;
  3693. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3694. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3695. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3696. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3697. }
  3698. /*
  3699. * Checks the GLOBAL_RESET bit.
  3700. *
  3701. * should be run under rtnl lock
  3702. */
  3703. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3704. {
  3705. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3706. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3707. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3708. }
  3709. /*
  3710. * Clear RESET_IN_PROGRESS bit for the current engine.
  3711. *
  3712. * Should be run under rtnl lock
  3713. */
  3714. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3715. {
  3716. u32 val;
  3717. u32 bit = BP_PATH(bp) ?
  3718. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3719. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3720. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3721. /* Clear the bit */
  3722. val &= ~bit;
  3723. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3724. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3725. }
  3726. /*
  3727. * Set RESET_IN_PROGRESS for the current engine.
  3728. *
  3729. * should be run under rtnl lock
  3730. */
  3731. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3732. {
  3733. u32 val;
  3734. u32 bit = BP_PATH(bp) ?
  3735. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3736. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3737. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3738. /* Set the bit */
  3739. val |= bit;
  3740. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3741. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3742. }
  3743. /*
  3744. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3745. * should be run under rtnl lock
  3746. */
  3747. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3748. {
  3749. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3750. u32 bit = engine ?
  3751. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3752. /* return false if bit is set */
  3753. return (val & bit) ? false : true;
  3754. }
  3755. /*
  3756. * set pf load for the current pf.
  3757. *
  3758. * should be run under rtnl lock
  3759. */
  3760. void bnx2x_set_pf_load(struct bnx2x *bp)
  3761. {
  3762. u32 val1, val;
  3763. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3764. BNX2X_PATH0_LOAD_CNT_MASK;
  3765. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3766. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3767. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3768. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3769. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3770. /* get the current counter value */
  3771. val1 = (val & mask) >> shift;
  3772. /* set bit of that PF */
  3773. val1 |= (1 << bp->pf_num);
  3774. /* clear the old value */
  3775. val &= ~mask;
  3776. /* set the new one */
  3777. val |= ((val1 << shift) & mask);
  3778. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3779. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3780. }
  3781. /**
  3782. * bnx2x_clear_pf_load - clear pf load mark
  3783. *
  3784. * @bp: driver handle
  3785. *
  3786. * Should be run under rtnl lock.
  3787. * Decrements the load counter for the current engine. Returns
  3788. * whether other functions are still loaded
  3789. */
  3790. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3791. {
  3792. u32 val1, val;
  3793. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3794. BNX2X_PATH0_LOAD_CNT_MASK;
  3795. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3796. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3797. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3798. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3799. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3800. /* get the current counter value */
  3801. val1 = (val & mask) >> shift;
  3802. /* clear bit of that PF */
  3803. val1 &= ~(1 << bp->pf_num);
  3804. /* clear the old value */
  3805. val &= ~mask;
  3806. /* set the new one */
  3807. val |= ((val1 << shift) & mask);
  3808. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3809. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3810. return val1 != 0;
  3811. }
  3812. /*
  3813. * Read the load status for the current engine.
  3814. *
  3815. * should be run under rtnl lock
  3816. */
  3817. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3818. {
  3819. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3820. BNX2X_PATH0_LOAD_CNT_MASK);
  3821. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3822. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3823. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3824. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3825. val = (val & mask) >> shift;
  3826. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3827. engine, val);
  3828. return val != 0;
  3829. }
  3830. static void _print_parity(struct bnx2x *bp, u32 reg)
  3831. {
  3832. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3833. }
  3834. static void _print_next_block(int idx, const char *blk)
  3835. {
  3836. pr_cont("%s%s", idx ? ", " : "", blk);
  3837. }
  3838. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3839. int *par_num, bool print)
  3840. {
  3841. u32 cur_bit;
  3842. bool res;
  3843. int i;
  3844. res = false;
  3845. for (i = 0; sig; i++) {
  3846. cur_bit = (0x1UL << i);
  3847. if (sig & cur_bit) {
  3848. res |= true; /* Each bit is real error! */
  3849. if (print) {
  3850. switch (cur_bit) {
  3851. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3852. _print_next_block((*par_num)++, "BRB");
  3853. _print_parity(bp,
  3854. BRB1_REG_BRB1_PRTY_STS);
  3855. break;
  3856. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3857. _print_next_block((*par_num)++,
  3858. "PARSER");
  3859. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3860. break;
  3861. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3862. _print_next_block((*par_num)++, "TSDM");
  3863. _print_parity(bp,
  3864. TSDM_REG_TSDM_PRTY_STS);
  3865. break;
  3866. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3867. _print_next_block((*par_num)++,
  3868. "SEARCHER");
  3869. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3870. break;
  3871. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3872. _print_next_block((*par_num)++, "TCM");
  3873. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3874. break;
  3875. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3876. _print_next_block((*par_num)++,
  3877. "TSEMI");
  3878. _print_parity(bp,
  3879. TSEM_REG_TSEM_PRTY_STS_0);
  3880. _print_parity(bp,
  3881. TSEM_REG_TSEM_PRTY_STS_1);
  3882. break;
  3883. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3884. _print_next_block((*par_num)++, "XPB");
  3885. _print_parity(bp, GRCBASE_XPB +
  3886. PB_REG_PB_PRTY_STS);
  3887. break;
  3888. }
  3889. }
  3890. /* Clear the bit */
  3891. sig &= ~cur_bit;
  3892. }
  3893. }
  3894. return res;
  3895. }
  3896. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3897. int *par_num, bool *global,
  3898. bool print)
  3899. {
  3900. u32 cur_bit;
  3901. bool res;
  3902. int i;
  3903. res = false;
  3904. for (i = 0; sig; i++) {
  3905. cur_bit = (0x1UL << i);
  3906. if (sig & cur_bit) {
  3907. res |= true; /* Each bit is real error! */
  3908. switch (cur_bit) {
  3909. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3910. if (print) {
  3911. _print_next_block((*par_num)++, "PBF");
  3912. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3913. }
  3914. break;
  3915. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3916. if (print) {
  3917. _print_next_block((*par_num)++, "QM");
  3918. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3919. }
  3920. break;
  3921. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3922. if (print) {
  3923. _print_next_block((*par_num)++, "TM");
  3924. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3925. }
  3926. break;
  3927. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3928. if (print) {
  3929. _print_next_block((*par_num)++, "XSDM");
  3930. _print_parity(bp,
  3931. XSDM_REG_XSDM_PRTY_STS);
  3932. }
  3933. break;
  3934. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3935. if (print) {
  3936. _print_next_block((*par_num)++, "XCM");
  3937. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3938. }
  3939. break;
  3940. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3941. if (print) {
  3942. _print_next_block((*par_num)++,
  3943. "XSEMI");
  3944. _print_parity(bp,
  3945. XSEM_REG_XSEM_PRTY_STS_0);
  3946. _print_parity(bp,
  3947. XSEM_REG_XSEM_PRTY_STS_1);
  3948. }
  3949. break;
  3950. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3951. if (print) {
  3952. _print_next_block((*par_num)++,
  3953. "DOORBELLQ");
  3954. _print_parity(bp,
  3955. DORQ_REG_DORQ_PRTY_STS);
  3956. }
  3957. break;
  3958. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3959. if (print) {
  3960. _print_next_block((*par_num)++, "NIG");
  3961. if (CHIP_IS_E1x(bp)) {
  3962. _print_parity(bp,
  3963. NIG_REG_NIG_PRTY_STS);
  3964. } else {
  3965. _print_parity(bp,
  3966. NIG_REG_NIG_PRTY_STS_0);
  3967. _print_parity(bp,
  3968. NIG_REG_NIG_PRTY_STS_1);
  3969. }
  3970. }
  3971. break;
  3972. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3973. if (print)
  3974. _print_next_block((*par_num)++,
  3975. "VAUX PCI CORE");
  3976. *global = true;
  3977. break;
  3978. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3979. if (print) {
  3980. _print_next_block((*par_num)++,
  3981. "DEBUG");
  3982. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3983. }
  3984. break;
  3985. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3986. if (print) {
  3987. _print_next_block((*par_num)++, "USDM");
  3988. _print_parity(bp,
  3989. USDM_REG_USDM_PRTY_STS);
  3990. }
  3991. break;
  3992. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3993. if (print) {
  3994. _print_next_block((*par_num)++, "UCM");
  3995. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3996. }
  3997. break;
  3998. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3999. if (print) {
  4000. _print_next_block((*par_num)++,
  4001. "USEMI");
  4002. _print_parity(bp,
  4003. USEM_REG_USEM_PRTY_STS_0);
  4004. _print_parity(bp,
  4005. USEM_REG_USEM_PRTY_STS_1);
  4006. }
  4007. break;
  4008. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  4009. if (print) {
  4010. _print_next_block((*par_num)++, "UPB");
  4011. _print_parity(bp, GRCBASE_UPB +
  4012. PB_REG_PB_PRTY_STS);
  4013. }
  4014. break;
  4015. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  4016. if (print) {
  4017. _print_next_block((*par_num)++, "CSDM");
  4018. _print_parity(bp,
  4019. CSDM_REG_CSDM_PRTY_STS);
  4020. }
  4021. break;
  4022. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  4023. if (print) {
  4024. _print_next_block((*par_num)++, "CCM");
  4025. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  4026. }
  4027. break;
  4028. }
  4029. /* Clear the bit */
  4030. sig &= ~cur_bit;
  4031. }
  4032. }
  4033. return res;
  4034. }
  4035. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  4036. int *par_num, bool print)
  4037. {
  4038. u32 cur_bit;
  4039. bool res;
  4040. int i;
  4041. res = false;
  4042. for (i = 0; sig; i++) {
  4043. cur_bit = (0x1UL << i);
  4044. if (sig & cur_bit) {
  4045. res = true; /* Each bit is real error! */
  4046. if (print) {
  4047. switch (cur_bit) {
  4048. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4049. _print_next_block((*par_num)++,
  4050. "CSEMI");
  4051. _print_parity(bp,
  4052. CSEM_REG_CSEM_PRTY_STS_0);
  4053. _print_parity(bp,
  4054. CSEM_REG_CSEM_PRTY_STS_1);
  4055. break;
  4056. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4057. _print_next_block((*par_num)++, "PXP");
  4058. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4059. _print_parity(bp,
  4060. PXP2_REG_PXP2_PRTY_STS_0);
  4061. _print_parity(bp,
  4062. PXP2_REG_PXP2_PRTY_STS_1);
  4063. break;
  4064. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4065. _print_next_block((*par_num)++,
  4066. "PXPPCICLOCKCLIENT");
  4067. break;
  4068. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4069. _print_next_block((*par_num)++, "CFC");
  4070. _print_parity(bp,
  4071. CFC_REG_CFC_PRTY_STS);
  4072. break;
  4073. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4074. _print_next_block((*par_num)++, "CDU");
  4075. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4076. break;
  4077. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4078. _print_next_block((*par_num)++, "DMAE");
  4079. _print_parity(bp,
  4080. DMAE_REG_DMAE_PRTY_STS);
  4081. break;
  4082. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4083. _print_next_block((*par_num)++, "IGU");
  4084. if (CHIP_IS_E1x(bp))
  4085. _print_parity(bp,
  4086. HC_REG_HC_PRTY_STS);
  4087. else
  4088. _print_parity(bp,
  4089. IGU_REG_IGU_PRTY_STS);
  4090. break;
  4091. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4092. _print_next_block((*par_num)++, "MISC");
  4093. _print_parity(bp,
  4094. MISC_REG_MISC_PRTY_STS);
  4095. break;
  4096. }
  4097. }
  4098. /* Clear the bit */
  4099. sig &= ~cur_bit;
  4100. }
  4101. }
  4102. return res;
  4103. }
  4104. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4105. int *par_num, bool *global,
  4106. bool print)
  4107. {
  4108. bool res = false;
  4109. u32 cur_bit;
  4110. int i;
  4111. for (i = 0; sig; i++) {
  4112. cur_bit = (0x1UL << i);
  4113. if (sig & cur_bit) {
  4114. switch (cur_bit) {
  4115. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4116. if (print)
  4117. _print_next_block((*par_num)++,
  4118. "MCP ROM");
  4119. *global = true;
  4120. res = true;
  4121. break;
  4122. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4123. if (print)
  4124. _print_next_block((*par_num)++,
  4125. "MCP UMP RX");
  4126. *global = true;
  4127. res = true;
  4128. break;
  4129. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4130. if (print)
  4131. _print_next_block((*par_num)++,
  4132. "MCP UMP TX");
  4133. *global = true;
  4134. res = true;
  4135. break;
  4136. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4137. (*par_num)++;
  4138. /* clear latched SCPAD PATIRY from MCP */
  4139. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4140. 1UL << 10);
  4141. break;
  4142. }
  4143. /* Clear the bit */
  4144. sig &= ~cur_bit;
  4145. }
  4146. }
  4147. return res;
  4148. }
  4149. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4150. int *par_num, bool print)
  4151. {
  4152. u32 cur_bit;
  4153. bool res;
  4154. int i;
  4155. res = false;
  4156. for (i = 0; sig; i++) {
  4157. cur_bit = (0x1UL << i);
  4158. if (sig & cur_bit) {
  4159. res = true; /* Each bit is real error! */
  4160. if (print) {
  4161. switch (cur_bit) {
  4162. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4163. _print_next_block((*par_num)++,
  4164. "PGLUE_B");
  4165. _print_parity(bp,
  4166. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4167. break;
  4168. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4169. _print_next_block((*par_num)++, "ATC");
  4170. _print_parity(bp,
  4171. ATC_REG_ATC_PRTY_STS);
  4172. break;
  4173. }
  4174. }
  4175. /* Clear the bit */
  4176. sig &= ~cur_bit;
  4177. }
  4178. }
  4179. return res;
  4180. }
  4181. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4182. u32 *sig)
  4183. {
  4184. bool res = false;
  4185. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4186. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4187. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4188. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4189. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4190. int par_num = 0;
  4191. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4192. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4193. sig[0] & HW_PRTY_ASSERT_SET_0,
  4194. sig[1] & HW_PRTY_ASSERT_SET_1,
  4195. sig[2] & HW_PRTY_ASSERT_SET_2,
  4196. sig[3] & HW_PRTY_ASSERT_SET_3,
  4197. sig[4] & HW_PRTY_ASSERT_SET_4);
  4198. if (print) {
  4199. if (((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4200. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4201. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4202. (sig[4] & HW_PRTY_ASSERT_SET_4)) ||
  4203. (sig[3] & HW_PRTY_ASSERT_SET_3_WITHOUT_SCPAD)) {
  4204. netdev_err(bp->dev,
  4205. "Parity errors detected in blocks: ");
  4206. } else {
  4207. print = false;
  4208. }
  4209. }
  4210. res |= bnx2x_check_blocks_with_parity0(bp,
  4211. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4212. res |= bnx2x_check_blocks_with_parity1(bp,
  4213. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4214. res |= bnx2x_check_blocks_with_parity2(bp,
  4215. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4216. res |= bnx2x_check_blocks_with_parity3(bp,
  4217. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4218. res |= bnx2x_check_blocks_with_parity4(bp,
  4219. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4220. if (print)
  4221. pr_cont("\n");
  4222. }
  4223. return res;
  4224. }
  4225. /**
  4226. * bnx2x_chk_parity_attn - checks for parity attentions.
  4227. *
  4228. * @bp: driver handle
  4229. * @global: true if there was a global attention
  4230. * @print: show parity attention in syslog
  4231. */
  4232. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4233. {
  4234. struct attn_route attn = { {0} };
  4235. int port = BP_PORT(bp);
  4236. attn.sig[0] = REG_RD(bp,
  4237. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4238. port*4);
  4239. attn.sig[1] = REG_RD(bp,
  4240. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4241. port*4);
  4242. attn.sig[2] = REG_RD(bp,
  4243. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4244. port*4);
  4245. attn.sig[3] = REG_RD(bp,
  4246. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4247. port*4);
  4248. /* Since MCP attentions can't be disabled inside the block, we need to
  4249. * read AEU registers to see whether they're currently disabled
  4250. */
  4251. attn.sig[3] &= ((REG_RD(bp,
  4252. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4253. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4254. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4255. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4256. if (!CHIP_IS_E1x(bp))
  4257. attn.sig[4] = REG_RD(bp,
  4258. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4259. port*4);
  4260. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4261. }
  4262. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4263. {
  4264. u32 val;
  4265. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4266. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4267. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4268. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4269. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4270. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4271. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4272. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4273. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4274. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4275. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4276. if (val &
  4277. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4278. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4279. if (val &
  4280. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4281. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4282. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4283. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4284. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4285. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4286. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4287. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4288. }
  4289. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4290. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4291. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4292. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4293. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4294. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4295. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4296. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4297. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4298. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4299. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4300. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4301. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4302. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4303. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4304. }
  4305. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4306. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4307. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4308. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4309. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4310. }
  4311. }
  4312. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4313. {
  4314. struct attn_route attn, *group_mask;
  4315. int port = BP_PORT(bp);
  4316. int index;
  4317. u32 reg_addr;
  4318. u32 val;
  4319. u32 aeu_mask;
  4320. bool global = false;
  4321. /* need to take HW lock because MCP or other port might also
  4322. try to handle this event */
  4323. bnx2x_acquire_alr(bp);
  4324. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4325. #ifndef BNX2X_STOP_ON_ERROR
  4326. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4327. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4328. /* Disable HW interrupts */
  4329. bnx2x_int_disable(bp);
  4330. /* In case of parity errors don't handle attentions so that
  4331. * other function would "see" parity errors.
  4332. */
  4333. #else
  4334. bnx2x_panic();
  4335. #endif
  4336. bnx2x_release_alr(bp);
  4337. return;
  4338. }
  4339. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4340. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4341. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4342. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4343. if (!CHIP_IS_E1x(bp))
  4344. attn.sig[4] =
  4345. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4346. else
  4347. attn.sig[4] = 0;
  4348. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4349. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4350. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4351. if (deasserted & (1 << index)) {
  4352. group_mask = &bp->attn_group[index];
  4353. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4354. index,
  4355. group_mask->sig[0], group_mask->sig[1],
  4356. group_mask->sig[2], group_mask->sig[3],
  4357. group_mask->sig[4]);
  4358. bnx2x_attn_int_deasserted4(bp,
  4359. attn.sig[4] & group_mask->sig[4]);
  4360. bnx2x_attn_int_deasserted3(bp,
  4361. attn.sig[3] & group_mask->sig[3]);
  4362. bnx2x_attn_int_deasserted1(bp,
  4363. attn.sig[1] & group_mask->sig[1]);
  4364. bnx2x_attn_int_deasserted2(bp,
  4365. attn.sig[2] & group_mask->sig[2]);
  4366. bnx2x_attn_int_deasserted0(bp,
  4367. attn.sig[0] & group_mask->sig[0]);
  4368. }
  4369. }
  4370. bnx2x_release_alr(bp);
  4371. if (bp->common.int_block == INT_BLOCK_HC)
  4372. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4373. COMMAND_REG_ATTN_BITS_CLR);
  4374. else
  4375. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4376. val = ~deasserted;
  4377. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4378. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4379. REG_WR(bp, reg_addr, val);
  4380. if (~bp->attn_state & deasserted)
  4381. BNX2X_ERR("IGU ERROR\n");
  4382. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4383. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4384. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4385. aeu_mask = REG_RD(bp, reg_addr);
  4386. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4387. aeu_mask, deasserted);
  4388. aeu_mask |= (deasserted & 0x3ff);
  4389. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4390. REG_WR(bp, reg_addr, aeu_mask);
  4391. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4392. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4393. bp->attn_state &= ~deasserted;
  4394. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4395. }
  4396. static void bnx2x_attn_int(struct bnx2x *bp)
  4397. {
  4398. /* read local copy of bits */
  4399. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4400. attn_bits);
  4401. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4402. attn_bits_ack);
  4403. u32 attn_state = bp->attn_state;
  4404. /* look for changed bits */
  4405. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4406. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4407. DP(NETIF_MSG_HW,
  4408. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4409. attn_bits, attn_ack, asserted, deasserted);
  4410. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4411. BNX2X_ERR("BAD attention state\n");
  4412. /* handle bits that were raised */
  4413. if (asserted)
  4414. bnx2x_attn_int_asserted(bp, asserted);
  4415. if (deasserted)
  4416. bnx2x_attn_int_deasserted(bp, deasserted);
  4417. }
  4418. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4419. u16 index, u8 op, u8 update)
  4420. {
  4421. u32 igu_addr = bp->igu_base_addr;
  4422. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4423. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4424. igu_addr);
  4425. }
  4426. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4427. {
  4428. /* No memory barriers */
  4429. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4430. mmiowb(); /* keep prod updates ordered */
  4431. }
  4432. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4433. union event_ring_elem *elem)
  4434. {
  4435. u8 err = elem->message.error;
  4436. if (!bp->cnic_eth_dev.starting_cid ||
  4437. (cid < bp->cnic_eth_dev.starting_cid &&
  4438. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4439. return 1;
  4440. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4441. if (unlikely(err)) {
  4442. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4443. cid);
  4444. bnx2x_panic_dump(bp, false);
  4445. }
  4446. bnx2x_cnic_cfc_comp(bp, cid, err);
  4447. return 0;
  4448. }
  4449. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4450. {
  4451. struct bnx2x_mcast_ramrod_params rparam;
  4452. int rc;
  4453. memset(&rparam, 0, sizeof(rparam));
  4454. rparam.mcast_obj = &bp->mcast_obj;
  4455. netif_addr_lock_bh(bp->dev);
  4456. /* Clear pending state for the last command */
  4457. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4458. /* If there are pending mcast commands - send them */
  4459. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4460. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4461. if (rc < 0)
  4462. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4463. rc);
  4464. }
  4465. netif_addr_unlock_bh(bp->dev);
  4466. }
  4467. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4468. union event_ring_elem *elem)
  4469. {
  4470. unsigned long ramrod_flags = 0;
  4471. int rc = 0;
  4472. u32 echo = le32_to_cpu(elem->message.data.eth_event.echo);
  4473. u32 cid = echo & BNX2X_SWCID_MASK;
  4474. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4475. /* Always push next commands out, don't wait here */
  4476. __set_bit(RAMROD_CONT, &ramrod_flags);
  4477. switch (echo >> BNX2X_SWCID_SHIFT) {
  4478. case BNX2X_FILTER_MAC_PENDING:
  4479. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4480. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4481. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4482. else
  4483. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4484. break;
  4485. case BNX2X_FILTER_VLAN_PENDING:
  4486. DP(BNX2X_MSG_SP, "Got SETUP_VLAN completions\n");
  4487. vlan_mac_obj = &bp->sp_objs[cid].vlan_obj;
  4488. break;
  4489. case BNX2X_FILTER_MCAST_PENDING:
  4490. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4491. /* This is only relevant for 57710 where multicast MACs are
  4492. * configured as unicast MACs using the same ramrod.
  4493. */
  4494. bnx2x_handle_mcast_eqe(bp);
  4495. return;
  4496. default:
  4497. BNX2X_ERR("Unsupported classification command: 0x%x\n", echo);
  4498. return;
  4499. }
  4500. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4501. if (rc < 0)
  4502. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4503. else if (rc > 0)
  4504. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4505. }
  4506. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4507. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4508. {
  4509. netif_addr_lock_bh(bp->dev);
  4510. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4511. /* Send rx_mode command again if was requested */
  4512. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4513. bnx2x_set_storm_rx_mode(bp);
  4514. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4515. &bp->sp_state))
  4516. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4517. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4518. &bp->sp_state))
  4519. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4520. netif_addr_unlock_bh(bp->dev);
  4521. }
  4522. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4523. union event_ring_elem *elem)
  4524. {
  4525. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4526. DP(BNX2X_MSG_SP,
  4527. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4528. elem->message.data.vif_list_event.func_bit_map);
  4529. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4530. elem->message.data.vif_list_event.func_bit_map);
  4531. } else if (elem->message.data.vif_list_event.echo ==
  4532. VIF_LIST_RULE_SET) {
  4533. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4534. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4535. }
  4536. }
  4537. /* called with rtnl_lock */
  4538. static void bnx2x_after_function_update(struct bnx2x *bp)
  4539. {
  4540. int q, rc;
  4541. struct bnx2x_fastpath *fp;
  4542. struct bnx2x_queue_state_params queue_params = {NULL};
  4543. struct bnx2x_queue_update_params *q_update_params =
  4544. &queue_params.params.update;
  4545. /* Send Q update command with afex vlan removal values for all Qs */
  4546. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4547. /* set silent vlan removal values according to vlan mode */
  4548. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4549. &q_update_params->update_flags);
  4550. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4551. &q_update_params->update_flags);
  4552. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4553. /* in access mode mark mask and value are 0 to strip all vlans */
  4554. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4555. q_update_params->silent_removal_value = 0;
  4556. q_update_params->silent_removal_mask = 0;
  4557. } else {
  4558. q_update_params->silent_removal_value =
  4559. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4560. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4561. }
  4562. for_each_eth_queue(bp, q) {
  4563. /* Set the appropriate Queue object */
  4564. fp = &bp->fp[q];
  4565. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4566. /* send the ramrod */
  4567. rc = bnx2x_queue_state_change(bp, &queue_params);
  4568. if (rc < 0)
  4569. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4570. q);
  4571. }
  4572. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4573. fp = &bp->fp[FCOE_IDX(bp)];
  4574. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4575. /* clear pending completion bit */
  4576. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4577. /* mark latest Q bit */
  4578. smp_mb__before_atomic();
  4579. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4580. smp_mb__after_atomic();
  4581. /* send Q update ramrod for FCoE Q */
  4582. rc = bnx2x_queue_state_change(bp, &queue_params);
  4583. if (rc < 0)
  4584. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4585. q);
  4586. } else {
  4587. /* If no FCoE ring - ACK MCP now */
  4588. bnx2x_link_report(bp);
  4589. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4590. }
  4591. }
  4592. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4593. struct bnx2x *bp, u32 cid)
  4594. {
  4595. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4596. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4597. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4598. else
  4599. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4600. }
  4601. static void bnx2x_eq_int(struct bnx2x *bp)
  4602. {
  4603. u16 hw_cons, sw_cons, sw_prod;
  4604. union event_ring_elem *elem;
  4605. u8 echo;
  4606. u32 cid;
  4607. u8 opcode;
  4608. int rc, spqe_cnt = 0;
  4609. struct bnx2x_queue_sp_obj *q_obj;
  4610. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4611. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4612. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4613. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4614. * when we get the next-page we need to adjust so the loop
  4615. * condition below will be met. The next element is the size of a
  4616. * regular element and hence incrementing by 1
  4617. */
  4618. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4619. hw_cons++;
  4620. /* This function may never run in parallel with itself for a
  4621. * specific bp, thus there is no need in "paired" read memory
  4622. * barrier here.
  4623. */
  4624. sw_cons = bp->eq_cons;
  4625. sw_prod = bp->eq_prod;
  4626. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4627. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4628. for (; sw_cons != hw_cons;
  4629. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4630. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4631. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4632. if (!rc) {
  4633. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4634. rc);
  4635. goto next_spqe;
  4636. }
  4637. opcode = elem->message.opcode;
  4638. /* handle eq element */
  4639. switch (opcode) {
  4640. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4641. bnx2x_vf_mbx_schedule(bp,
  4642. &elem->message.data.vf_pf_event);
  4643. continue;
  4644. case EVENT_RING_OPCODE_STAT_QUERY:
  4645. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4646. "got statistics comp event %d\n",
  4647. bp->stats_comp++);
  4648. /* nothing to do with stats comp */
  4649. goto next_spqe;
  4650. case EVENT_RING_OPCODE_CFC_DEL:
  4651. /* handle according to cid range */
  4652. /*
  4653. * we may want to verify here that the bp state is
  4654. * HALTING
  4655. */
  4656. /* elem CID originates from FW; actually LE */
  4657. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4658. DP(BNX2X_MSG_SP,
  4659. "got delete ramrod for MULTI[%d]\n", cid);
  4660. if (CNIC_LOADED(bp) &&
  4661. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4662. goto next_spqe;
  4663. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4664. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4665. break;
  4666. goto next_spqe;
  4667. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4668. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4669. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4670. if (f_obj->complete_cmd(bp, f_obj,
  4671. BNX2X_F_CMD_TX_STOP))
  4672. break;
  4673. goto next_spqe;
  4674. case EVENT_RING_OPCODE_START_TRAFFIC:
  4675. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4676. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4677. if (f_obj->complete_cmd(bp, f_obj,
  4678. BNX2X_F_CMD_TX_START))
  4679. break;
  4680. goto next_spqe;
  4681. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4682. echo = elem->message.data.function_update_event.echo;
  4683. if (echo == SWITCH_UPDATE) {
  4684. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4685. "got FUNC_SWITCH_UPDATE ramrod\n");
  4686. if (f_obj->complete_cmd(
  4687. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4688. break;
  4689. } else {
  4690. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4691. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4692. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4693. f_obj->complete_cmd(bp, f_obj,
  4694. BNX2X_F_CMD_AFEX_UPDATE);
  4695. /* We will perform the Queues update from
  4696. * sp_rtnl task as all Queue SP operations
  4697. * should run under rtnl_lock.
  4698. */
  4699. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4700. }
  4701. goto next_spqe;
  4702. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4703. f_obj->complete_cmd(bp, f_obj,
  4704. BNX2X_F_CMD_AFEX_VIFLISTS);
  4705. bnx2x_after_afex_vif_lists(bp, elem);
  4706. goto next_spqe;
  4707. case EVENT_RING_OPCODE_FUNCTION_START:
  4708. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4709. "got FUNC_START ramrod\n");
  4710. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4711. break;
  4712. goto next_spqe;
  4713. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4714. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4715. "got FUNC_STOP ramrod\n");
  4716. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4717. break;
  4718. goto next_spqe;
  4719. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4720. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4721. "got set_timesync ramrod completion\n");
  4722. if (f_obj->complete_cmd(bp, f_obj,
  4723. BNX2X_F_CMD_SET_TIMESYNC))
  4724. break;
  4725. goto next_spqe;
  4726. }
  4727. switch (opcode | bp->state) {
  4728. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4729. BNX2X_STATE_OPEN):
  4730. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4731. BNX2X_STATE_OPENING_WAIT4_PORT):
  4732. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4733. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4734. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4735. SW_CID(elem->message.data.eth_event.echo));
  4736. rss_raw->clear_pending(rss_raw);
  4737. break;
  4738. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4739. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4740. case (EVENT_RING_OPCODE_SET_MAC |
  4741. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4742. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4743. BNX2X_STATE_OPEN):
  4744. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4745. BNX2X_STATE_DIAG):
  4746. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4747. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4748. DP(BNX2X_MSG_SP, "got (un)set vlan/mac ramrod\n");
  4749. bnx2x_handle_classification_eqe(bp, elem);
  4750. break;
  4751. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4752. BNX2X_STATE_OPEN):
  4753. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4754. BNX2X_STATE_DIAG):
  4755. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4756. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4757. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4758. bnx2x_handle_mcast_eqe(bp);
  4759. break;
  4760. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4761. BNX2X_STATE_OPEN):
  4762. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4763. BNX2X_STATE_DIAG):
  4764. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4765. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4766. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4767. bnx2x_handle_rx_mode_eqe(bp);
  4768. break;
  4769. default:
  4770. /* unknown event log error and continue */
  4771. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4772. elem->message.opcode, bp->state);
  4773. }
  4774. next_spqe:
  4775. spqe_cnt++;
  4776. } /* for */
  4777. smp_mb__before_atomic();
  4778. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4779. bp->eq_cons = sw_cons;
  4780. bp->eq_prod = sw_prod;
  4781. /* Make sure that above mem writes were issued towards the memory */
  4782. smp_wmb();
  4783. /* update producer */
  4784. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4785. }
  4786. static void bnx2x_sp_task(struct work_struct *work)
  4787. {
  4788. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4789. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4790. /* make sure the atomic interrupt_occurred has been written */
  4791. smp_rmb();
  4792. if (atomic_read(&bp->interrupt_occurred)) {
  4793. /* what work needs to be performed? */
  4794. u16 status = bnx2x_update_dsb_idx(bp);
  4795. DP(BNX2X_MSG_SP, "status %x\n", status);
  4796. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4797. atomic_set(&bp->interrupt_occurred, 0);
  4798. /* HW attentions */
  4799. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4800. bnx2x_attn_int(bp);
  4801. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4802. }
  4803. /* SP events: STAT_QUERY and others */
  4804. if (status & BNX2X_DEF_SB_IDX) {
  4805. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4806. if (FCOE_INIT(bp) &&
  4807. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4808. /* Prevent local bottom-halves from running as
  4809. * we are going to change the local NAPI list.
  4810. */
  4811. local_bh_disable();
  4812. napi_schedule(&bnx2x_fcoe(bp, napi));
  4813. local_bh_enable();
  4814. }
  4815. /* Handle EQ completions */
  4816. bnx2x_eq_int(bp);
  4817. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4818. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4819. status &= ~BNX2X_DEF_SB_IDX;
  4820. }
  4821. /* if status is non zero then perhaps something went wrong */
  4822. if (unlikely(status))
  4823. DP(BNX2X_MSG_SP,
  4824. "got an unknown interrupt! (status 0x%x)\n", status);
  4825. /* ack status block only if something was actually handled */
  4826. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4827. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4828. }
  4829. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4830. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4831. &bp->sp_state)) {
  4832. bnx2x_link_report(bp);
  4833. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4834. }
  4835. }
  4836. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4837. {
  4838. struct net_device *dev = dev_instance;
  4839. struct bnx2x *bp = netdev_priv(dev);
  4840. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4841. IGU_INT_DISABLE, 0);
  4842. #ifdef BNX2X_STOP_ON_ERROR
  4843. if (unlikely(bp->panic))
  4844. return IRQ_HANDLED;
  4845. #endif
  4846. if (CNIC_LOADED(bp)) {
  4847. struct cnic_ops *c_ops;
  4848. rcu_read_lock();
  4849. c_ops = rcu_dereference(bp->cnic_ops);
  4850. if (c_ops)
  4851. c_ops->cnic_handler(bp->cnic_data, NULL);
  4852. rcu_read_unlock();
  4853. }
  4854. /* schedule sp task to perform default status block work, ack
  4855. * attentions and enable interrupts.
  4856. */
  4857. bnx2x_schedule_sp_task(bp);
  4858. return IRQ_HANDLED;
  4859. }
  4860. /* end of slow path */
  4861. void bnx2x_drv_pulse(struct bnx2x *bp)
  4862. {
  4863. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4864. bp->fw_drv_pulse_wr_seq);
  4865. }
  4866. static void bnx2x_timer(struct timer_list *t)
  4867. {
  4868. struct bnx2x *bp = from_timer(bp, t, timer);
  4869. if (!netif_running(bp->dev))
  4870. return;
  4871. if (IS_PF(bp) &&
  4872. !BP_NOMCP(bp)) {
  4873. int mb_idx = BP_FW_MB_IDX(bp);
  4874. u16 drv_pulse;
  4875. u16 mcp_pulse;
  4876. ++bp->fw_drv_pulse_wr_seq;
  4877. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4878. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4879. bnx2x_drv_pulse(bp);
  4880. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4881. MCP_PULSE_SEQ_MASK);
  4882. /* The delta between driver pulse and mcp response
  4883. * should not get too big. If the MFW is more than 5 pulses
  4884. * behind, we should worry about it enough to generate an error
  4885. * log.
  4886. */
  4887. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4888. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4889. drv_pulse, mcp_pulse);
  4890. }
  4891. if (bp->state == BNX2X_STATE_OPEN)
  4892. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4893. /* sample pf vf bulletin board for new posts from pf */
  4894. if (IS_VF(bp))
  4895. bnx2x_timer_sriov(bp);
  4896. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4897. }
  4898. /* end of Statistics */
  4899. /* nic init */
  4900. /*
  4901. * nic init service functions
  4902. */
  4903. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4904. {
  4905. u32 i;
  4906. if (!(len%4) && !(addr%4))
  4907. for (i = 0; i < len; i += 4)
  4908. REG_WR(bp, addr + i, fill);
  4909. else
  4910. for (i = 0; i < len; i++)
  4911. REG_WR8(bp, addr + i, fill);
  4912. }
  4913. /* helper: writes FP SP data to FW - data_size in dwords */
  4914. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4915. int fw_sb_id,
  4916. u32 *sb_data_p,
  4917. u32 data_size)
  4918. {
  4919. int index;
  4920. for (index = 0; index < data_size; index++)
  4921. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4922. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4923. sizeof(u32)*index,
  4924. *(sb_data_p + index));
  4925. }
  4926. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4927. {
  4928. u32 *sb_data_p;
  4929. u32 data_size = 0;
  4930. struct hc_status_block_data_e2 sb_data_e2;
  4931. struct hc_status_block_data_e1x sb_data_e1x;
  4932. /* disable the function first */
  4933. if (!CHIP_IS_E1x(bp)) {
  4934. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4935. sb_data_e2.common.state = SB_DISABLED;
  4936. sb_data_e2.common.p_func.vf_valid = false;
  4937. sb_data_p = (u32 *)&sb_data_e2;
  4938. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4939. } else {
  4940. memset(&sb_data_e1x, 0,
  4941. sizeof(struct hc_status_block_data_e1x));
  4942. sb_data_e1x.common.state = SB_DISABLED;
  4943. sb_data_e1x.common.p_func.vf_valid = false;
  4944. sb_data_p = (u32 *)&sb_data_e1x;
  4945. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4946. }
  4947. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4948. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4949. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4950. CSTORM_STATUS_BLOCK_SIZE);
  4951. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4952. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4953. CSTORM_SYNC_BLOCK_SIZE);
  4954. }
  4955. /* helper: writes SP SB data to FW */
  4956. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4957. struct hc_sp_status_block_data *sp_sb_data)
  4958. {
  4959. int func = BP_FUNC(bp);
  4960. int i;
  4961. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4962. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4963. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4964. i*sizeof(u32),
  4965. *((u32 *)sp_sb_data + i));
  4966. }
  4967. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4968. {
  4969. int func = BP_FUNC(bp);
  4970. struct hc_sp_status_block_data sp_sb_data;
  4971. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4972. sp_sb_data.state = SB_DISABLED;
  4973. sp_sb_data.p_func.vf_valid = false;
  4974. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4975. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4976. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4977. CSTORM_SP_STATUS_BLOCK_SIZE);
  4978. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4979. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4980. CSTORM_SP_SYNC_BLOCK_SIZE);
  4981. }
  4982. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4983. int igu_sb_id, int igu_seg_id)
  4984. {
  4985. hc_sm->igu_sb_id = igu_sb_id;
  4986. hc_sm->igu_seg_id = igu_seg_id;
  4987. hc_sm->timer_value = 0xFF;
  4988. hc_sm->time_to_expire = 0xFFFFFFFF;
  4989. }
  4990. /* allocates state machine ids. */
  4991. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4992. {
  4993. /* zero out state machine indices */
  4994. /* rx indices */
  4995. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4996. /* tx indices */
  4997. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4998. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4999. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  5000. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  5001. /* map indices */
  5002. /* rx indices */
  5003. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  5004. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  5005. /* tx indices */
  5006. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  5007. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  5008. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  5009. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  5010. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  5011. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  5012. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  5013. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  5014. }
  5015. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  5016. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  5017. {
  5018. int igu_seg_id;
  5019. struct hc_status_block_data_e2 sb_data_e2;
  5020. struct hc_status_block_data_e1x sb_data_e1x;
  5021. struct hc_status_block_sm *hc_sm_p;
  5022. int data_size;
  5023. u32 *sb_data_p;
  5024. if (CHIP_INT_MODE_IS_BC(bp))
  5025. igu_seg_id = HC_SEG_ACCESS_NORM;
  5026. else
  5027. igu_seg_id = IGU_SEG_ACCESS_NORM;
  5028. bnx2x_zero_fp_sb(bp, fw_sb_id);
  5029. if (!CHIP_IS_E1x(bp)) {
  5030. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  5031. sb_data_e2.common.state = SB_ENABLED;
  5032. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  5033. sb_data_e2.common.p_func.vf_id = vfid;
  5034. sb_data_e2.common.p_func.vf_valid = vf_valid;
  5035. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  5036. sb_data_e2.common.same_igu_sb_1b = true;
  5037. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  5038. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  5039. hc_sm_p = sb_data_e2.common.state_machine;
  5040. sb_data_p = (u32 *)&sb_data_e2;
  5041. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  5042. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  5043. } else {
  5044. memset(&sb_data_e1x, 0,
  5045. sizeof(struct hc_status_block_data_e1x));
  5046. sb_data_e1x.common.state = SB_ENABLED;
  5047. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5048. sb_data_e1x.common.p_func.vf_id = 0xff;
  5049. sb_data_e1x.common.p_func.vf_valid = false;
  5050. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5051. sb_data_e1x.common.same_igu_sb_1b = true;
  5052. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5053. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5054. hc_sm_p = sb_data_e1x.common.state_machine;
  5055. sb_data_p = (u32 *)&sb_data_e1x;
  5056. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5057. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5058. }
  5059. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5060. igu_sb_id, igu_seg_id);
  5061. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5062. igu_sb_id, igu_seg_id);
  5063. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5064. /* write indices to HW - PCI guarantees endianity of regpairs */
  5065. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5066. }
  5067. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5068. u16 tx_usec, u16 rx_usec)
  5069. {
  5070. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5071. false, rx_usec);
  5072. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5073. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5074. tx_usec);
  5075. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5076. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5077. tx_usec);
  5078. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5079. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5080. tx_usec);
  5081. }
  5082. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5083. {
  5084. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5085. dma_addr_t mapping = bp->def_status_blk_mapping;
  5086. int igu_sp_sb_index;
  5087. int igu_seg_id;
  5088. int port = BP_PORT(bp);
  5089. int func = BP_FUNC(bp);
  5090. int reg_offset, reg_offset_en5;
  5091. u64 section;
  5092. int index;
  5093. struct hc_sp_status_block_data sp_sb_data;
  5094. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5095. if (CHIP_INT_MODE_IS_BC(bp)) {
  5096. igu_sp_sb_index = DEF_SB_IGU_ID;
  5097. igu_seg_id = HC_SEG_ACCESS_DEF;
  5098. } else {
  5099. igu_sp_sb_index = bp->igu_dsb_id;
  5100. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5101. }
  5102. /* ATTN */
  5103. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5104. atten_status_block);
  5105. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5106. bp->attn_state = 0;
  5107. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5108. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5109. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5110. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5111. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5112. int sindex;
  5113. /* take care of sig[0]..sig[4] */
  5114. for (sindex = 0; sindex < 4; sindex++)
  5115. bp->attn_group[index].sig[sindex] =
  5116. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5117. if (!CHIP_IS_E1x(bp))
  5118. /*
  5119. * enable5 is separate from the rest of the registers,
  5120. * and therefore the address skip is 4
  5121. * and not 16 between the different groups
  5122. */
  5123. bp->attn_group[index].sig[4] = REG_RD(bp,
  5124. reg_offset_en5 + 0x4*index);
  5125. else
  5126. bp->attn_group[index].sig[4] = 0;
  5127. }
  5128. if (bp->common.int_block == INT_BLOCK_HC) {
  5129. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5130. HC_REG_ATTN_MSG0_ADDR_L);
  5131. REG_WR(bp, reg_offset, U64_LO(section));
  5132. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5133. } else if (!CHIP_IS_E1x(bp)) {
  5134. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5135. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5136. }
  5137. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5138. sp_sb);
  5139. bnx2x_zero_sp_sb(bp);
  5140. /* PCI guarantees endianity of regpairs */
  5141. sp_sb_data.state = SB_ENABLED;
  5142. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5143. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5144. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5145. sp_sb_data.igu_seg_id = igu_seg_id;
  5146. sp_sb_data.p_func.pf_id = func;
  5147. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5148. sp_sb_data.p_func.vf_id = 0xff;
  5149. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5150. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5151. }
  5152. void bnx2x_update_coalesce(struct bnx2x *bp)
  5153. {
  5154. int i;
  5155. for_each_eth_queue(bp, i)
  5156. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5157. bp->tx_ticks, bp->rx_ticks);
  5158. }
  5159. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5160. {
  5161. spin_lock_init(&bp->spq_lock);
  5162. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5163. bp->spq_prod_idx = 0;
  5164. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5165. bp->spq_prod_bd = bp->spq;
  5166. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5167. }
  5168. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5169. {
  5170. int i;
  5171. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5172. union event_ring_elem *elem =
  5173. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5174. elem->next_page.addr.hi =
  5175. cpu_to_le32(U64_HI(bp->eq_mapping +
  5176. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5177. elem->next_page.addr.lo =
  5178. cpu_to_le32(U64_LO(bp->eq_mapping +
  5179. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5180. }
  5181. bp->eq_cons = 0;
  5182. bp->eq_prod = NUM_EQ_DESC;
  5183. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5184. /* we want a warning message before it gets wrought... */
  5185. atomic_set(&bp->eq_spq_left,
  5186. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5187. }
  5188. /* called with netif_addr_lock_bh() */
  5189. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5190. unsigned long rx_mode_flags,
  5191. unsigned long rx_accept_flags,
  5192. unsigned long tx_accept_flags,
  5193. unsigned long ramrod_flags)
  5194. {
  5195. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5196. int rc;
  5197. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5198. /* Prepare ramrod parameters */
  5199. ramrod_param.cid = 0;
  5200. ramrod_param.cl_id = cl_id;
  5201. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5202. ramrod_param.func_id = BP_FUNC(bp);
  5203. ramrod_param.pstate = &bp->sp_state;
  5204. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5205. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5206. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5207. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5208. ramrod_param.ramrod_flags = ramrod_flags;
  5209. ramrod_param.rx_mode_flags = rx_mode_flags;
  5210. ramrod_param.rx_accept_flags = rx_accept_flags;
  5211. ramrod_param.tx_accept_flags = tx_accept_flags;
  5212. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5213. if (rc < 0) {
  5214. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5215. return rc;
  5216. }
  5217. return 0;
  5218. }
  5219. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5220. unsigned long *rx_accept_flags,
  5221. unsigned long *tx_accept_flags)
  5222. {
  5223. /* Clear the flags first */
  5224. *rx_accept_flags = 0;
  5225. *tx_accept_flags = 0;
  5226. switch (rx_mode) {
  5227. case BNX2X_RX_MODE_NONE:
  5228. /*
  5229. * 'drop all' supersedes any accept flags that may have been
  5230. * passed to the function.
  5231. */
  5232. break;
  5233. case BNX2X_RX_MODE_NORMAL:
  5234. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5235. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5236. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5237. /* internal switching mode */
  5238. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5239. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5240. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5241. if (bp->accept_any_vlan) {
  5242. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5243. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5244. }
  5245. break;
  5246. case BNX2X_RX_MODE_ALLMULTI:
  5247. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5248. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5249. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5250. /* internal switching mode */
  5251. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5252. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5253. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5254. if (bp->accept_any_vlan) {
  5255. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5256. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5257. }
  5258. break;
  5259. case BNX2X_RX_MODE_PROMISC:
  5260. /* According to definition of SI mode, iface in promisc mode
  5261. * should receive matched and unmatched (in resolution of port)
  5262. * unicast packets.
  5263. */
  5264. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5265. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5266. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5267. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5268. /* internal switching mode */
  5269. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5270. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5271. if (IS_MF_SI(bp))
  5272. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5273. else
  5274. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5275. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5276. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5277. break;
  5278. default:
  5279. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5280. return -EINVAL;
  5281. }
  5282. return 0;
  5283. }
  5284. /* called with netif_addr_lock_bh() */
  5285. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5286. {
  5287. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5288. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5289. int rc;
  5290. if (!NO_FCOE(bp))
  5291. /* Configure rx_mode of FCoE Queue */
  5292. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5293. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5294. &tx_accept_flags);
  5295. if (rc)
  5296. return rc;
  5297. __set_bit(RAMROD_RX, &ramrod_flags);
  5298. __set_bit(RAMROD_TX, &ramrod_flags);
  5299. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5300. rx_accept_flags, tx_accept_flags,
  5301. ramrod_flags);
  5302. }
  5303. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5304. {
  5305. int i;
  5306. /* Zero this manually as its initialization is
  5307. currently missing in the initTool */
  5308. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5309. REG_WR(bp, BAR_USTRORM_INTMEM +
  5310. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5311. if (!CHIP_IS_E1x(bp)) {
  5312. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5313. CHIP_INT_MODE_IS_BC(bp) ?
  5314. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5315. }
  5316. }
  5317. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5318. {
  5319. switch (load_code) {
  5320. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5321. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5322. bnx2x_init_internal_common(bp);
  5323. /* no break */
  5324. case FW_MSG_CODE_DRV_LOAD_PORT:
  5325. /* nothing to do */
  5326. /* no break */
  5327. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5328. /* internal memory per function is
  5329. initialized inside bnx2x_pf_init */
  5330. break;
  5331. default:
  5332. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5333. break;
  5334. }
  5335. }
  5336. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5337. {
  5338. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5339. }
  5340. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5341. {
  5342. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5343. }
  5344. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5345. {
  5346. if (CHIP_IS_E1x(fp->bp))
  5347. return BP_L_ID(fp->bp) + fp->index;
  5348. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5349. return bnx2x_fp_igu_sb_id(fp);
  5350. }
  5351. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5352. {
  5353. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5354. u8 cos;
  5355. unsigned long q_type = 0;
  5356. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5357. fp->rx_queue = fp_idx;
  5358. fp->cid = fp_idx;
  5359. fp->cl_id = bnx2x_fp_cl_id(fp);
  5360. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5361. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5362. /* qZone id equals to FW (per path) client id */
  5363. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5364. /* init shortcut */
  5365. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5366. /* Setup SB indices */
  5367. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5368. /* Configure Queue State object */
  5369. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5370. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5371. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5372. /* init tx data */
  5373. for_each_cos_in_tx_queue(fp, cos) {
  5374. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5375. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5376. FP_COS_TO_TXQ(fp, cos, bp),
  5377. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5378. cids[cos] = fp->txdata_ptr[cos]->cid;
  5379. }
  5380. /* nothing more for vf to do here */
  5381. if (IS_VF(bp))
  5382. return;
  5383. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5384. fp->fw_sb_id, fp->igu_sb_id);
  5385. bnx2x_update_fpsb_idx(fp);
  5386. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5387. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5388. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5389. /**
  5390. * Configure classification DBs: Always enable Tx switching
  5391. */
  5392. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5393. DP(NETIF_MSG_IFUP,
  5394. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5395. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5396. fp->igu_sb_id);
  5397. }
  5398. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5399. {
  5400. int i;
  5401. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5402. struct eth_tx_next_bd *tx_next_bd =
  5403. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5404. tx_next_bd->addr_hi =
  5405. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5406. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5407. tx_next_bd->addr_lo =
  5408. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5409. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5410. }
  5411. *txdata->tx_cons_sb = cpu_to_le16(0);
  5412. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5413. txdata->tx_db.data.zero_fill1 = 0;
  5414. txdata->tx_db.data.prod = 0;
  5415. txdata->tx_pkt_prod = 0;
  5416. txdata->tx_pkt_cons = 0;
  5417. txdata->tx_bd_prod = 0;
  5418. txdata->tx_bd_cons = 0;
  5419. txdata->tx_pkt = 0;
  5420. }
  5421. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5422. {
  5423. int i;
  5424. for_each_tx_queue_cnic(bp, i)
  5425. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5426. }
  5427. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5428. {
  5429. int i;
  5430. u8 cos;
  5431. for_each_eth_queue(bp, i)
  5432. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5433. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5434. }
  5435. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5436. {
  5437. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5438. unsigned long q_type = 0;
  5439. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5440. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5441. BNX2X_FCOE_ETH_CL_ID_IDX);
  5442. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5443. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5444. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5445. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5446. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5447. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5448. fp);
  5449. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5450. /* qZone id equals to FW (per path) client id */
  5451. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5452. /* init shortcut */
  5453. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5454. bnx2x_rx_ustorm_prods_offset(fp);
  5455. /* Configure Queue State object */
  5456. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5457. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5458. /* No multi-CoS for FCoE L2 client */
  5459. BUG_ON(fp->max_cos != 1);
  5460. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5461. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5462. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5463. DP(NETIF_MSG_IFUP,
  5464. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5465. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5466. fp->igu_sb_id);
  5467. }
  5468. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5469. {
  5470. if (!NO_FCOE(bp))
  5471. bnx2x_init_fcoe_fp(bp);
  5472. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5473. BNX2X_VF_ID_INVALID, false,
  5474. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5475. /* ensure status block indices were read */
  5476. rmb();
  5477. bnx2x_init_rx_rings_cnic(bp);
  5478. bnx2x_init_tx_rings_cnic(bp);
  5479. /* flush all */
  5480. mb();
  5481. mmiowb();
  5482. }
  5483. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5484. {
  5485. int i;
  5486. /* Setup NIC internals and enable interrupts */
  5487. for_each_eth_queue(bp, i)
  5488. bnx2x_init_eth_fp(bp, i);
  5489. /* ensure status block indices were read */
  5490. rmb();
  5491. bnx2x_init_rx_rings(bp);
  5492. bnx2x_init_tx_rings(bp);
  5493. if (IS_PF(bp)) {
  5494. /* Initialize MOD_ABS interrupts */
  5495. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5496. bp->common.shmem_base,
  5497. bp->common.shmem2_base, BP_PORT(bp));
  5498. /* initialize the default status block and sp ring */
  5499. bnx2x_init_def_sb(bp);
  5500. bnx2x_update_dsb_idx(bp);
  5501. bnx2x_init_sp_ring(bp);
  5502. } else {
  5503. bnx2x_memset_stats(bp);
  5504. }
  5505. }
  5506. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5507. {
  5508. bnx2x_init_eq_ring(bp);
  5509. bnx2x_init_internal(bp, load_code);
  5510. bnx2x_pf_init(bp);
  5511. bnx2x_stats_init(bp);
  5512. /* flush all before enabling interrupts */
  5513. mb();
  5514. mmiowb();
  5515. bnx2x_int_enable(bp);
  5516. /* Check for SPIO5 */
  5517. bnx2x_attn_int_deasserted0(bp,
  5518. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5519. AEU_INPUTS_ATTN_BITS_SPIO5);
  5520. }
  5521. /* gzip service functions */
  5522. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5523. {
  5524. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5525. &bp->gunzip_mapping, GFP_KERNEL);
  5526. if (bp->gunzip_buf == NULL)
  5527. goto gunzip_nomem1;
  5528. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5529. if (bp->strm == NULL)
  5530. goto gunzip_nomem2;
  5531. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5532. if (bp->strm->workspace == NULL)
  5533. goto gunzip_nomem3;
  5534. return 0;
  5535. gunzip_nomem3:
  5536. kfree(bp->strm);
  5537. bp->strm = NULL;
  5538. gunzip_nomem2:
  5539. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5540. bp->gunzip_mapping);
  5541. bp->gunzip_buf = NULL;
  5542. gunzip_nomem1:
  5543. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5544. return -ENOMEM;
  5545. }
  5546. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5547. {
  5548. if (bp->strm) {
  5549. vfree(bp->strm->workspace);
  5550. kfree(bp->strm);
  5551. bp->strm = NULL;
  5552. }
  5553. if (bp->gunzip_buf) {
  5554. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5555. bp->gunzip_mapping);
  5556. bp->gunzip_buf = NULL;
  5557. }
  5558. }
  5559. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5560. {
  5561. int n, rc;
  5562. /* check gzip header */
  5563. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5564. BNX2X_ERR("Bad gzip header\n");
  5565. return -EINVAL;
  5566. }
  5567. n = 10;
  5568. #define FNAME 0x8
  5569. if (zbuf[3] & FNAME)
  5570. while ((zbuf[n++] != 0) && (n < len));
  5571. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5572. bp->strm->avail_in = len - n;
  5573. bp->strm->next_out = bp->gunzip_buf;
  5574. bp->strm->avail_out = FW_BUF_SIZE;
  5575. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5576. if (rc != Z_OK)
  5577. return rc;
  5578. rc = zlib_inflate(bp->strm, Z_FINISH);
  5579. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5580. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5581. bp->strm->msg);
  5582. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5583. if (bp->gunzip_outlen & 0x3)
  5584. netdev_err(bp->dev,
  5585. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5586. bp->gunzip_outlen);
  5587. bp->gunzip_outlen >>= 2;
  5588. zlib_inflateEnd(bp->strm);
  5589. if (rc == Z_STREAM_END)
  5590. return 0;
  5591. return rc;
  5592. }
  5593. /* nic load/unload */
  5594. /*
  5595. * General service functions
  5596. */
  5597. /* send a NIG loopback debug packet */
  5598. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5599. {
  5600. u32 wb_write[3];
  5601. /* Ethernet source and destination addresses */
  5602. wb_write[0] = 0x55555555;
  5603. wb_write[1] = 0x55555555;
  5604. wb_write[2] = 0x20; /* SOP */
  5605. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5606. /* NON-IP protocol */
  5607. wb_write[0] = 0x09000000;
  5608. wb_write[1] = 0x55555555;
  5609. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5610. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5611. }
  5612. /* some of the internal memories
  5613. * are not directly readable from the driver
  5614. * to test them we send debug packets
  5615. */
  5616. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5617. {
  5618. int factor;
  5619. int count, i;
  5620. u32 val = 0;
  5621. if (CHIP_REV_IS_FPGA(bp))
  5622. factor = 120;
  5623. else if (CHIP_REV_IS_EMUL(bp))
  5624. factor = 200;
  5625. else
  5626. factor = 1;
  5627. /* Disable inputs of parser neighbor blocks */
  5628. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5629. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5630. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5631. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5632. /* Write 0 to parser credits for CFC search request */
  5633. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5634. /* send Ethernet packet */
  5635. bnx2x_lb_pckt(bp);
  5636. /* TODO do i reset NIG statistic? */
  5637. /* Wait until NIG register shows 1 packet of size 0x10 */
  5638. count = 1000 * factor;
  5639. while (count) {
  5640. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5641. val = *bnx2x_sp(bp, wb_data[0]);
  5642. if (val == 0x10)
  5643. break;
  5644. usleep_range(10000, 20000);
  5645. count--;
  5646. }
  5647. if (val != 0x10) {
  5648. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5649. return -1;
  5650. }
  5651. /* Wait until PRS register shows 1 packet */
  5652. count = 1000 * factor;
  5653. while (count) {
  5654. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5655. if (val == 1)
  5656. break;
  5657. usleep_range(10000, 20000);
  5658. count--;
  5659. }
  5660. if (val != 0x1) {
  5661. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5662. return -2;
  5663. }
  5664. /* Reset and init BRB, PRS */
  5665. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5666. msleep(50);
  5667. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5668. msleep(50);
  5669. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5670. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5671. DP(NETIF_MSG_HW, "part2\n");
  5672. /* Disable inputs of parser neighbor blocks */
  5673. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5674. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5675. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5676. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5677. /* Write 0 to parser credits for CFC search request */
  5678. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5679. /* send 10 Ethernet packets */
  5680. for (i = 0; i < 10; i++)
  5681. bnx2x_lb_pckt(bp);
  5682. /* Wait until NIG register shows 10 + 1
  5683. packets of size 11*0x10 = 0xb0 */
  5684. count = 1000 * factor;
  5685. while (count) {
  5686. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5687. val = *bnx2x_sp(bp, wb_data[0]);
  5688. if (val == 0xb0)
  5689. break;
  5690. usleep_range(10000, 20000);
  5691. count--;
  5692. }
  5693. if (val != 0xb0) {
  5694. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5695. return -3;
  5696. }
  5697. /* Wait until PRS register shows 2 packets */
  5698. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5699. if (val != 2)
  5700. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5701. /* Write 1 to parser credits for CFC search request */
  5702. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5703. /* Wait until PRS register shows 3 packets */
  5704. msleep(10 * factor);
  5705. /* Wait until NIG register shows 1 packet of size 0x10 */
  5706. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5707. if (val != 3)
  5708. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5709. /* clear NIG EOP FIFO */
  5710. for (i = 0; i < 11; i++)
  5711. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5712. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5713. if (val != 1) {
  5714. BNX2X_ERR("clear of NIG failed\n");
  5715. return -4;
  5716. }
  5717. /* Reset and init BRB, PRS, NIG */
  5718. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5719. msleep(50);
  5720. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5721. msleep(50);
  5722. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5723. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5724. if (!CNIC_SUPPORT(bp))
  5725. /* set NIC mode */
  5726. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5727. /* Enable inputs of parser neighbor blocks */
  5728. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5729. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5730. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5731. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5732. DP(NETIF_MSG_HW, "done\n");
  5733. return 0; /* OK */
  5734. }
  5735. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5736. {
  5737. u32 val;
  5738. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5739. if (!CHIP_IS_E1x(bp))
  5740. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5741. else
  5742. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5743. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5744. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5745. /*
  5746. * mask read length error interrupts in brb for parser
  5747. * (parsing unit and 'checksum and crc' unit)
  5748. * these errors are legal (PU reads fixed length and CAC can cause
  5749. * read length error on truncated packets)
  5750. */
  5751. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5752. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5753. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5754. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5755. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5756. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5757. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5758. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5759. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5760. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5761. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5762. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5763. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5764. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5765. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5766. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5767. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5768. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5769. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5770. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5771. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5772. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5773. if (!CHIP_IS_E1x(bp))
  5774. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5775. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5776. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5777. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5778. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5779. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5780. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5781. if (!CHIP_IS_E1x(bp))
  5782. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5783. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5784. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5785. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5786. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5787. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5788. }
  5789. static void bnx2x_reset_common(struct bnx2x *bp)
  5790. {
  5791. u32 val = 0x1400;
  5792. /* reset_common */
  5793. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5794. 0xd3ffff7f);
  5795. if (CHIP_IS_E3(bp)) {
  5796. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5797. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5798. }
  5799. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5800. }
  5801. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5802. {
  5803. bp->dmae_ready = 0;
  5804. spin_lock_init(&bp->dmae_lock);
  5805. }
  5806. static void bnx2x_init_pxp(struct bnx2x *bp)
  5807. {
  5808. u16 devctl;
  5809. int r_order, w_order;
  5810. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5811. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5812. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5813. if (bp->mrrs == -1)
  5814. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5815. else {
  5816. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5817. r_order = bp->mrrs;
  5818. }
  5819. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5820. }
  5821. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5822. {
  5823. int is_required;
  5824. u32 val;
  5825. int port;
  5826. if (BP_NOMCP(bp))
  5827. return;
  5828. is_required = 0;
  5829. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5830. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5831. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5832. is_required = 1;
  5833. /*
  5834. * The fan failure mechanism is usually related to the PHY type since
  5835. * the power consumption of the board is affected by the PHY. Currently,
  5836. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5837. */
  5838. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5839. for (port = PORT_0; port < PORT_MAX; port++) {
  5840. is_required |=
  5841. bnx2x_fan_failure_det_req(
  5842. bp,
  5843. bp->common.shmem_base,
  5844. bp->common.shmem2_base,
  5845. port);
  5846. }
  5847. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5848. if (is_required == 0)
  5849. return;
  5850. /* Fan failure is indicated by SPIO 5 */
  5851. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5852. /* set to active low mode */
  5853. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5854. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5855. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5856. /* enable interrupt to signal the IGU */
  5857. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5858. val |= MISC_SPIO_SPIO5;
  5859. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5860. }
  5861. void bnx2x_pf_disable(struct bnx2x *bp)
  5862. {
  5863. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5864. val &= ~IGU_PF_CONF_FUNC_EN;
  5865. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5866. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5867. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5868. }
  5869. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5870. {
  5871. u32 shmem_base[2], shmem2_base[2];
  5872. /* Avoid common init in case MFW supports LFA */
  5873. if (SHMEM2_RD(bp, size) >
  5874. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5875. return;
  5876. shmem_base[0] = bp->common.shmem_base;
  5877. shmem2_base[0] = bp->common.shmem2_base;
  5878. if (!CHIP_IS_E1x(bp)) {
  5879. shmem_base[1] =
  5880. SHMEM2_RD(bp, other_shmem_base_addr);
  5881. shmem2_base[1] =
  5882. SHMEM2_RD(bp, other_shmem2_base_addr);
  5883. }
  5884. bnx2x_acquire_phy_lock(bp);
  5885. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5886. bp->common.chip_id);
  5887. bnx2x_release_phy_lock(bp);
  5888. }
  5889. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5890. {
  5891. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5892. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5893. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5894. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5895. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5896. /* make sure this value is 0 */
  5897. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5898. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5899. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5900. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5901. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5902. }
  5903. static void bnx2x_set_endianity(struct bnx2x *bp)
  5904. {
  5905. #ifdef __BIG_ENDIAN
  5906. bnx2x_config_endianity(bp, 1);
  5907. #else
  5908. bnx2x_config_endianity(bp, 0);
  5909. #endif
  5910. }
  5911. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5912. {
  5913. bnx2x_config_endianity(bp, 0);
  5914. }
  5915. /**
  5916. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5917. *
  5918. * @bp: driver handle
  5919. */
  5920. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5921. {
  5922. u32 val;
  5923. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5924. /*
  5925. * take the RESET lock to protect undi_unload flow from accessing
  5926. * registers while we're resetting the chip
  5927. */
  5928. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5929. bnx2x_reset_common(bp);
  5930. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5931. val = 0xfffc;
  5932. if (CHIP_IS_E3(bp)) {
  5933. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5934. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5935. }
  5936. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5937. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5938. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5939. if (!CHIP_IS_E1x(bp)) {
  5940. u8 abs_func_id;
  5941. /**
  5942. * 4-port mode or 2-port mode we need to turn of master-enable
  5943. * for everyone, after that, turn it back on for self.
  5944. * so, we disregard multi-function or not, and always disable
  5945. * for all functions on the given path, this means 0,2,4,6 for
  5946. * path 0 and 1,3,5,7 for path 1
  5947. */
  5948. for (abs_func_id = BP_PATH(bp);
  5949. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5950. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5951. REG_WR(bp,
  5952. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5953. 1);
  5954. continue;
  5955. }
  5956. bnx2x_pretend_func(bp, abs_func_id);
  5957. /* clear pf enable */
  5958. bnx2x_pf_disable(bp);
  5959. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5960. }
  5961. }
  5962. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5963. if (CHIP_IS_E1(bp)) {
  5964. /* enable HW interrupt from PXP on USDM overflow
  5965. bit 16 on INT_MASK_0 */
  5966. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5967. }
  5968. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5969. bnx2x_init_pxp(bp);
  5970. bnx2x_set_endianity(bp);
  5971. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5972. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5973. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5974. /* let the HW do it's magic ... */
  5975. msleep(100);
  5976. /* finish PXP init */
  5977. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5978. if (val != 1) {
  5979. BNX2X_ERR("PXP2 CFG failed\n");
  5980. return -EBUSY;
  5981. }
  5982. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5983. if (val != 1) {
  5984. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5985. return -EBUSY;
  5986. }
  5987. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5988. * have entries with value "0" and valid bit on.
  5989. * This needs to be done by the first PF that is loaded in a path
  5990. * (i.e. common phase)
  5991. */
  5992. if (!CHIP_IS_E1x(bp)) {
  5993. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5994. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5995. * This occurs when a different function (func2,3) is being marked
  5996. * as "scan-off". Real-life scenario for example: if a driver is being
  5997. * load-unloaded while func6,7 are down. This will cause the timer to access
  5998. * the ilt, translate to a logical address and send a request to read/write.
  5999. * Since the ilt for the function that is down is not valid, this will cause
  6000. * a translation error which is unrecoverable.
  6001. * The Workaround is intended to make sure that when this happens nothing fatal
  6002. * will occur. The workaround:
  6003. * 1. First PF driver which loads on a path will:
  6004. * a. After taking the chip out of reset, by using pretend,
  6005. * it will write "0" to the following registers of
  6006. * the other vnics.
  6007. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  6008. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  6009. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  6010. * And for itself it will write '1' to
  6011. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  6012. * dmae-operations (writing to pram for example.)
  6013. * note: can be done for only function 6,7 but cleaner this
  6014. * way.
  6015. * b. Write zero+valid to the entire ILT.
  6016. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  6017. * VNIC3 (of that port). The range allocated will be the
  6018. * entire ILT. This is needed to prevent ILT range error.
  6019. * 2. Any PF driver load flow:
  6020. * a. ILT update with the physical addresses of the allocated
  6021. * logical pages.
  6022. * b. Wait 20msec. - note that this timeout is needed to make
  6023. * sure there are no requests in one of the PXP internal
  6024. * queues with "old" ILT addresses.
  6025. * c. PF enable in the PGLC.
  6026. * d. Clear the was_error of the PF in the PGLC. (could have
  6027. * occurred while driver was down)
  6028. * e. PF enable in the CFC (WEAK + STRONG)
  6029. * f. Timers scan enable
  6030. * 3. PF driver unload flow:
  6031. * a. Clear the Timers scan_en.
  6032. * b. Polling for scan_on=0 for that PF.
  6033. * c. Clear the PF enable bit in the PXP.
  6034. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  6035. * e. Write zero+valid to all ILT entries (The valid bit must
  6036. * stay set)
  6037. * f. If this is VNIC 3 of a port then also init
  6038. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  6039. * to the last entry in the ILT.
  6040. *
  6041. * Notes:
  6042. * Currently the PF error in the PGLC is non recoverable.
  6043. * In the future the there will be a recovery routine for this error.
  6044. * Currently attention is masked.
  6045. * Having an MCP lock on the load/unload process does not guarantee that
  6046. * there is no Timer disable during Func6/7 enable. This is because the
  6047. * Timers scan is currently being cleared by the MCP on FLR.
  6048. * Step 2.d can be done only for PF6/7 and the driver can also check if
  6049. * there is error before clearing it. But the flow above is simpler and
  6050. * more general.
  6051. * All ILT entries are written by zero+valid and not just PF6/7
  6052. * ILT entries since in the future the ILT entries allocation for
  6053. * PF-s might be dynamic.
  6054. */
  6055. struct ilt_client_info ilt_cli;
  6056. struct bnx2x_ilt ilt;
  6057. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6058. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6059. /* initialize dummy TM client */
  6060. ilt_cli.start = 0;
  6061. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6062. ilt_cli.client_num = ILT_CLIENT_TM;
  6063. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6064. * Step 2: set the timers first/last ilt entry to point
  6065. * to the entire range to prevent ILT range error for 3rd/4th
  6066. * vnic (this code assumes existence of the vnic)
  6067. *
  6068. * both steps performed by call to bnx2x_ilt_client_init_op()
  6069. * with dummy TM client
  6070. *
  6071. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6072. * and his brother are split registers
  6073. */
  6074. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6075. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6076. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6077. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6078. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6079. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6080. }
  6081. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6082. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6083. if (!CHIP_IS_E1x(bp)) {
  6084. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6085. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6086. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6087. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6088. /* let the HW do it's magic ... */
  6089. do {
  6090. msleep(200);
  6091. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6092. } while (factor-- && (val != 1));
  6093. if (val != 1) {
  6094. BNX2X_ERR("ATC_INIT failed\n");
  6095. return -EBUSY;
  6096. }
  6097. }
  6098. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6099. bnx2x_iov_init_dmae(bp);
  6100. /* clean the DMAE memory */
  6101. bp->dmae_ready = 1;
  6102. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6103. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6104. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6105. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6106. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6107. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6108. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6109. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6110. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6111. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6112. /* QM queues pointers table */
  6113. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6114. /* soft reset pulse */
  6115. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6116. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6117. if (CNIC_SUPPORT(bp))
  6118. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6119. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6120. if (!CHIP_REV_IS_SLOW(bp))
  6121. /* enable hw interrupt from doorbell Q */
  6122. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6123. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6124. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6125. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6126. if (!CHIP_IS_E1(bp))
  6127. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6128. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6129. if (IS_MF_AFEX(bp)) {
  6130. /* configure that VNTag and VLAN headers must be
  6131. * received in afex mode
  6132. */
  6133. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6134. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6135. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6136. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6137. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6138. } else {
  6139. /* Bit-map indicating which L2 hdrs may appear
  6140. * after the basic Ethernet header
  6141. */
  6142. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6143. bp->path_has_ovlan ? 7 : 6);
  6144. }
  6145. }
  6146. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6147. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6148. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6149. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6150. if (!CHIP_IS_E1x(bp)) {
  6151. /* reset VFC memories */
  6152. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6153. VFC_MEMORIES_RST_REG_CAM_RST |
  6154. VFC_MEMORIES_RST_REG_RAM_RST);
  6155. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6156. VFC_MEMORIES_RST_REG_CAM_RST |
  6157. VFC_MEMORIES_RST_REG_RAM_RST);
  6158. msleep(20);
  6159. }
  6160. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6161. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6162. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6163. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6164. /* sync semi rtc */
  6165. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6166. 0x80000000);
  6167. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6168. 0x80000000);
  6169. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6170. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6171. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6172. if (!CHIP_IS_E1x(bp)) {
  6173. if (IS_MF_AFEX(bp)) {
  6174. /* configure that VNTag and VLAN headers must be
  6175. * sent in afex mode
  6176. */
  6177. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6178. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6179. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6180. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6181. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6182. } else {
  6183. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6184. bp->path_has_ovlan ? 7 : 6);
  6185. }
  6186. }
  6187. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6188. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6189. if (CNIC_SUPPORT(bp)) {
  6190. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6191. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6192. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6193. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6194. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6195. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6196. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6197. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6198. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6199. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6200. }
  6201. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6202. if (sizeof(union cdu_context) != 1024)
  6203. /* we currently assume that a context is 1024 bytes */
  6204. dev_alert(&bp->pdev->dev,
  6205. "please adjust the size of cdu_context(%ld)\n",
  6206. (long)sizeof(union cdu_context));
  6207. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6208. val = (4 << 24) + (0 << 12) + 1024;
  6209. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6210. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6211. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6212. /* enable context validation interrupt from CFC */
  6213. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6214. /* set the thresholds to prevent CFC/CDU race */
  6215. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6216. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6217. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6218. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6219. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6220. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6221. /* Reset PCIE errors for debug */
  6222. REG_WR(bp, 0x2814, 0xffffffff);
  6223. REG_WR(bp, 0x3820, 0xffffffff);
  6224. if (!CHIP_IS_E1x(bp)) {
  6225. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6226. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6227. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6228. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6229. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6230. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6231. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6232. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6233. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6234. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6235. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6236. }
  6237. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6238. if (!CHIP_IS_E1(bp)) {
  6239. /* in E3 this done in per-port section */
  6240. if (!CHIP_IS_E3(bp))
  6241. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6242. }
  6243. if (CHIP_IS_E1H(bp))
  6244. /* not applicable for E2 (and above ...) */
  6245. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6246. if (CHIP_REV_IS_SLOW(bp))
  6247. msleep(200);
  6248. /* finish CFC init */
  6249. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6250. if (val != 1) {
  6251. BNX2X_ERR("CFC LL_INIT failed\n");
  6252. return -EBUSY;
  6253. }
  6254. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6255. if (val != 1) {
  6256. BNX2X_ERR("CFC AC_INIT failed\n");
  6257. return -EBUSY;
  6258. }
  6259. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6260. if (val != 1) {
  6261. BNX2X_ERR("CFC CAM_INIT failed\n");
  6262. return -EBUSY;
  6263. }
  6264. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6265. if (CHIP_IS_E1(bp)) {
  6266. /* read NIG statistic
  6267. to see if this is our first up since powerup */
  6268. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6269. val = *bnx2x_sp(bp, wb_data[0]);
  6270. /* do internal memory self test */
  6271. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6272. BNX2X_ERR("internal mem self test failed\n");
  6273. return -EBUSY;
  6274. }
  6275. }
  6276. bnx2x_setup_fan_failure_detection(bp);
  6277. /* clear PXP2 attentions */
  6278. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6279. bnx2x_enable_blocks_attention(bp);
  6280. bnx2x_enable_blocks_parity(bp);
  6281. if (!BP_NOMCP(bp)) {
  6282. if (CHIP_IS_E1x(bp))
  6283. bnx2x__common_init_phy(bp);
  6284. } else
  6285. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6286. if (SHMEM2_HAS(bp, netproc_fw_ver))
  6287. SHMEM2_WR(bp, netproc_fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  6288. return 0;
  6289. }
  6290. /**
  6291. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6292. *
  6293. * @bp: driver handle
  6294. */
  6295. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6296. {
  6297. int rc = bnx2x_init_hw_common(bp);
  6298. if (rc)
  6299. return rc;
  6300. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6301. if (!BP_NOMCP(bp))
  6302. bnx2x__common_init_phy(bp);
  6303. return 0;
  6304. }
  6305. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6306. {
  6307. int port = BP_PORT(bp);
  6308. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6309. u32 low, high;
  6310. u32 val, reg;
  6311. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6312. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6313. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6314. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6315. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6316. /* Timers bug workaround: disables the pf_master bit in pglue at
  6317. * common phase, we need to enable it here before any dmae access are
  6318. * attempted. Therefore we manually added the enable-master to the
  6319. * port phase (it also happens in the function phase)
  6320. */
  6321. if (!CHIP_IS_E1x(bp))
  6322. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6323. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6324. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6325. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6326. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6327. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6328. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6329. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6330. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6331. /* QM cid (connection) count */
  6332. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6333. if (CNIC_SUPPORT(bp)) {
  6334. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6335. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6336. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6337. }
  6338. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6339. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6340. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6341. if (IS_MF(bp))
  6342. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6343. else if (bp->dev->mtu > 4096) {
  6344. if (bp->flags & ONE_PORT_FLAG)
  6345. low = 160;
  6346. else {
  6347. val = bp->dev->mtu;
  6348. /* (24*1024 + val*4)/256 */
  6349. low = 96 + (val/64) +
  6350. ((val % 64) ? 1 : 0);
  6351. }
  6352. } else
  6353. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6354. high = low + 56; /* 14*1024/256 */
  6355. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6356. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6357. }
  6358. if (CHIP_MODE_IS_4_PORT(bp))
  6359. REG_WR(bp, (BP_PORT(bp) ?
  6360. BRB1_REG_MAC_GUARANTIED_1 :
  6361. BRB1_REG_MAC_GUARANTIED_0), 40);
  6362. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6363. if (CHIP_IS_E3B0(bp)) {
  6364. if (IS_MF_AFEX(bp)) {
  6365. /* configure headers for AFEX mode */
  6366. REG_WR(bp, BP_PORT(bp) ?
  6367. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6368. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6369. REG_WR(bp, BP_PORT(bp) ?
  6370. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6371. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6372. REG_WR(bp, BP_PORT(bp) ?
  6373. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6374. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6375. } else {
  6376. /* Ovlan exists only if we are in multi-function +
  6377. * switch-dependent mode, in switch-independent there
  6378. * is no ovlan headers
  6379. */
  6380. REG_WR(bp, BP_PORT(bp) ?
  6381. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6382. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6383. (bp->path_has_ovlan ? 7 : 6));
  6384. }
  6385. }
  6386. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6387. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6388. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6389. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6390. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6391. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6392. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6393. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6394. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6395. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6396. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6397. if (CHIP_IS_E1x(bp)) {
  6398. /* configure PBF to work without PAUSE mtu 9000 */
  6399. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6400. /* update threshold */
  6401. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6402. /* update init credit */
  6403. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6404. /* probe changes */
  6405. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6406. udelay(50);
  6407. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6408. }
  6409. if (CNIC_SUPPORT(bp))
  6410. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6411. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6412. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6413. if (CHIP_IS_E1(bp)) {
  6414. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6415. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6416. }
  6417. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6418. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6419. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6420. /* init aeu_mask_attn_func_0/1:
  6421. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6422. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6423. * bits 4-7 are used for "per vn group attention" */
  6424. val = IS_MF(bp) ? 0xF7 : 0x7;
  6425. /* Enable DCBX attention for all but E1 */
  6426. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6427. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6428. /* SCPAD_PARITY should NOT trigger close the gates */
  6429. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6430. REG_WR(bp, reg,
  6431. REG_RD(bp, reg) &
  6432. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6433. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6434. REG_WR(bp, reg,
  6435. REG_RD(bp, reg) &
  6436. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6437. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6438. if (!CHIP_IS_E1x(bp)) {
  6439. /* Bit-map indicating which L2 hdrs may appear after the
  6440. * basic Ethernet header
  6441. */
  6442. if (IS_MF_AFEX(bp))
  6443. REG_WR(bp, BP_PORT(bp) ?
  6444. NIG_REG_P1_HDRS_AFTER_BASIC :
  6445. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6446. else
  6447. REG_WR(bp, BP_PORT(bp) ?
  6448. NIG_REG_P1_HDRS_AFTER_BASIC :
  6449. NIG_REG_P0_HDRS_AFTER_BASIC,
  6450. IS_MF_SD(bp) ? 7 : 6);
  6451. if (CHIP_IS_E3(bp))
  6452. REG_WR(bp, BP_PORT(bp) ?
  6453. NIG_REG_LLH1_MF_MODE :
  6454. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6455. }
  6456. if (!CHIP_IS_E3(bp))
  6457. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6458. if (!CHIP_IS_E1(bp)) {
  6459. /* 0x2 disable mf_ov, 0x1 enable */
  6460. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6461. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6462. if (!CHIP_IS_E1x(bp)) {
  6463. val = 0;
  6464. switch (bp->mf_mode) {
  6465. case MULTI_FUNCTION_SD:
  6466. val = 1;
  6467. break;
  6468. case MULTI_FUNCTION_SI:
  6469. case MULTI_FUNCTION_AFEX:
  6470. val = 2;
  6471. break;
  6472. }
  6473. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6474. NIG_REG_LLH0_CLS_TYPE), val);
  6475. }
  6476. {
  6477. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6478. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6479. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6480. }
  6481. }
  6482. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6483. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6484. if (val & MISC_SPIO_SPIO5) {
  6485. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6486. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6487. val = REG_RD(bp, reg_addr);
  6488. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6489. REG_WR(bp, reg_addr, val);
  6490. }
  6491. return 0;
  6492. }
  6493. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6494. {
  6495. int reg;
  6496. u32 wb_write[2];
  6497. if (CHIP_IS_E1(bp))
  6498. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6499. else
  6500. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6501. wb_write[0] = ONCHIP_ADDR1(addr);
  6502. wb_write[1] = ONCHIP_ADDR2(addr);
  6503. REG_WR_DMAE(bp, reg, wb_write, 2);
  6504. }
  6505. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6506. {
  6507. u32 data, ctl, cnt = 100;
  6508. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6509. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6510. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6511. u32 sb_bit = 1 << (idu_sb_id%32);
  6512. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6513. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6514. /* Not supported in BC mode */
  6515. if (CHIP_INT_MODE_IS_BC(bp))
  6516. return;
  6517. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6518. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6519. IGU_REGULAR_CLEANUP_SET |
  6520. IGU_REGULAR_BCLEANUP;
  6521. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6522. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6523. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6524. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6525. data, igu_addr_data);
  6526. REG_WR(bp, igu_addr_data, data);
  6527. mmiowb();
  6528. barrier();
  6529. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6530. ctl, igu_addr_ctl);
  6531. REG_WR(bp, igu_addr_ctl, ctl);
  6532. mmiowb();
  6533. barrier();
  6534. /* wait for clean up to finish */
  6535. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6536. msleep(20);
  6537. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6538. DP(NETIF_MSG_HW,
  6539. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6540. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6541. }
  6542. }
  6543. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6544. {
  6545. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6546. }
  6547. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6548. {
  6549. u32 i, base = FUNC_ILT_BASE(func);
  6550. for (i = base; i < base + ILT_PER_FUNC; i++)
  6551. bnx2x_ilt_wr(bp, i, 0);
  6552. }
  6553. static void bnx2x_init_searcher(struct bnx2x *bp)
  6554. {
  6555. int port = BP_PORT(bp);
  6556. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6557. /* T1 hash bits value determines the T1 number of entries */
  6558. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6559. }
  6560. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6561. {
  6562. int rc;
  6563. struct bnx2x_func_state_params func_params = {NULL};
  6564. struct bnx2x_func_switch_update_params *switch_update_params =
  6565. &func_params.params.switch_update;
  6566. /* Prepare parameters for function state transitions */
  6567. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6568. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6569. func_params.f_obj = &bp->func_obj;
  6570. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6571. /* Function parameters */
  6572. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6573. &switch_update_params->changes);
  6574. if (suspend)
  6575. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6576. &switch_update_params->changes);
  6577. rc = bnx2x_func_state_change(bp, &func_params);
  6578. return rc;
  6579. }
  6580. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6581. {
  6582. int rc, i, port = BP_PORT(bp);
  6583. int vlan_en = 0, mac_en[NUM_MACS];
  6584. /* Close input from network */
  6585. if (bp->mf_mode == SINGLE_FUNCTION) {
  6586. bnx2x_set_rx_filter(&bp->link_params, 0);
  6587. } else {
  6588. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6589. NIG_REG_LLH0_FUNC_EN);
  6590. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6591. NIG_REG_LLH0_FUNC_EN, 0);
  6592. for (i = 0; i < NUM_MACS; i++) {
  6593. mac_en[i] = REG_RD(bp, port ?
  6594. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6595. 4 * i) :
  6596. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6597. 4 * i));
  6598. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6599. 4 * i) :
  6600. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6601. }
  6602. }
  6603. /* Close BMC to host */
  6604. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6605. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6606. /* Suspend Tx switching to the PF. Completion of this ramrod
  6607. * further guarantees that all the packets of that PF / child
  6608. * VFs in BRB were processed by the Parser, so it is safe to
  6609. * change the NIC_MODE register.
  6610. */
  6611. rc = bnx2x_func_switch_update(bp, 1);
  6612. if (rc) {
  6613. BNX2X_ERR("Can't suspend tx-switching!\n");
  6614. return rc;
  6615. }
  6616. /* Change NIC_MODE register */
  6617. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6618. /* Open input from network */
  6619. if (bp->mf_mode == SINGLE_FUNCTION) {
  6620. bnx2x_set_rx_filter(&bp->link_params, 1);
  6621. } else {
  6622. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6623. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6624. for (i = 0; i < NUM_MACS; i++) {
  6625. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6626. 4 * i) :
  6627. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6628. mac_en[i]);
  6629. }
  6630. }
  6631. /* Enable BMC to host */
  6632. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6633. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6634. /* Resume Tx switching to the PF */
  6635. rc = bnx2x_func_switch_update(bp, 0);
  6636. if (rc) {
  6637. BNX2X_ERR("Can't resume tx-switching!\n");
  6638. return rc;
  6639. }
  6640. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6641. return 0;
  6642. }
  6643. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6644. {
  6645. int rc;
  6646. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6647. if (CONFIGURE_NIC_MODE(bp)) {
  6648. /* Configure searcher as part of function hw init */
  6649. bnx2x_init_searcher(bp);
  6650. /* Reset NIC mode */
  6651. rc = bnx2x_reset_nic_mode(bp);
  6652. if (rc)
  6653. BNX2X_ERR("Can't change NIC mode!\n");
  6654. return rc;
  6655. }
  6656. return 0;
  6657. }
  6658. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  6659. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  6660. * the addresses of the transaction, resulting in was-error bit set in the pci
  6661. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  6662. * to clear the interrupt which detected this from the pglueb and the was done
  6663. * bit
  6664. */
  6665. static void bnx2x_clean_pglue_errors(struct bnx2x *bp)
  6666. {
  6667. if (!CHIP_IS_E1x(bp))
  6668. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  6669. 1 << BP_ABS_FUNC(bp));
  6670. }
  6671. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6672. {
  6673. int port = BP_PORT(bp);
  6674. int func = BP_FUNC(bp);
  6675. int init_phase = PHASE_PF0 + func;
  6676. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6677. u16 cdu_ilt_start;
  6678. u32 addr, val;
  6679. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6680. int i, main_mem_width, rc;
  6681. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6682. /* FLR cleanup - hmmm */
  6683. if (!CHIP_IS_E1x(bp)) {
  6684. rc = bnx2x_pf_flr_clnup(bp);
  6685. if (rc) {
  6686. bnx2x_fw_dump(bp);
  6687. return rc;
  6688. }
  6689. }
  6690. /* set MSI reconfigure capability */
  6691. if (bp->common.int_block == INT_BLOCK_HC) {
  6692. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6693. val = REG_RD(bp, addr);
  6694. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6695. REG_WR(bp, addr, val);
  6696. }
  6697. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6698. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6699. ilt = BP_ILT(bp);
  6700. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6701. if (IS_SRIOV(bp))
  6702. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6703. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6704. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6705. * those of the VFs, so start line should be reset
  6706. */
  6707. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6708. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6709. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6710. ilt->lines[cdu_ilt_start + i].page_mapping =
  6711. bp->context[i].cxt_mapping;
  6712. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6713. }
  6714. bnx2x_ilt_init_op(bp, INITOP_SET);
  6715. if (!CONFIGURE_NIC_MODE(bp)) {
  6716. bnx2x_init_searcher(bp);
  6717. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6718. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6719. } else {
  6720. /* Set NIC mode */
  6721. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6722. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6723. }
  6724. if (!CHIP_IS_E1x(bp)) {
  6725. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6726. /* Turn on a single ISR mode in IGU if driver is going to use
  6727. * INT#x or MSI
  6728. */
  6729. if (!(bp->flags & USING_MSIX_FLAG))
  6730. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6731. /*
  6732. * Timers workaround bug: function init part.
  6733. * Need to wait 20msec after initializing ILT,
  6734. * needed to make sure there are no requests in
  6735. * one of the PXP internal queues with "old" ILT addresses
  6736. */
  6737. msleep(20);
  6738. /*
  6739. * Master enable - Due to WB DMAE writes performed before this
  6740. * register is re-initialized as part of the regular function
  6741. * init
  6742. */
  6743. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6744. /* Enable the function in IGU */
  6745. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6746. }
  6747. bp->dmae_ready = 1;
  6748. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6749. bnx2x_clean_pglue_errors(bp);
  6750. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6751. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6752. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6753. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6754. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6755. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6756. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6757. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6758. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6759. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6760. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6761. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6762. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6763. if (!CHIP_IS_E1x(bp))
  6764. REG_WR(bp, QM_REG_PF_EN, 1);
  6765. if (!CHIP_IS_E1x(bp)) {
  6766. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6767. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6768. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6769. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6770. }
  6771. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6772. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6773. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6774. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6775. bnx2x_iov_init_dq(bp);
  6776. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6777. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6778. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6779. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6780. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6781. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6782. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6783. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6784. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6785. if (!CHIP_IS_E1x(bp))
  6786. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6787. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6788. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6789. if (!CHIP_IS_E1x(bp))
  6790. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6791. if (IS_MF(bp)) {
  6792. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6793. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6794. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6795. bp->mf_ov);
  6796. }
  6797. }
  6798. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6799. /* HC init per function */
  6800. if (bp->common.int_block == INT_BLOCK_HC) {
  6801. if (CHIP_IS_E1H(bp)) {
  6802. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6803. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6804. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6805. }
  6806. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6807. } else {
  6808. int num_segs, sb_idx, prod_offset;
  6809. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6810. if (!CHIP_IS_E1x(bp)) {
  6811. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6812. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6813. }
  6814. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6815. if (!CHIP_IS_E1x(bp)) {
  6816. int dsb_idx = 0;
  6817. /**
  6818. * Producer memory:
  6819. * E2 mode: address 0-135 match to the mapping memory;
  6820. * 136 - PF0 default prod; 137 - PF1 default prod;
  6821. * 138 - PF2 default prod; 139 - PF3 default prod;
  6822. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6823. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6824. * 144-147 reserved.
  6825. *
  6826. * E1.5 mode - In backward compatible mode;
  6827. * for non default SB; each even line in the memory
  6828. * holds the U producer and each odd line hold
  6829. * the C producer. The first 128 producers are for
  6830. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6831. * producers are for the DSB for each PF.
  6832. * Each PF has five segments: (the order inside each
  6833. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6834. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6835. * 144-147 attn prods;
  6836. */
  6837. /* non-default-status-blocks */
  6838. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6839. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6840. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6841. prod_offset = (bp->igu_base_sb + sb_idx) *
  6842. num_segs;
  6843. for (i = 0; i < num_segs; i++) {
  6844. addr = IGU_REG_PROD_CONS_MEMORY +
  6845. (prod_offset + i) * 4;
  6846. REG_WR(bp, addr, 0);
  6847. }
  6848. /* send consumer update with value 0 */
  6849. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6850. USTORM_ID, 0, IGU_INT_NOP, 1);
  6851. bnx2x_igu_clear_sb(bp,
  6852. bp->igu_base_sb + sb_idx);
  6853. }
  6854. /* default-status-blocks */
  6855. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6856. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6857. if (CHIP_MODE_IS_4_PORT(bp))
  6858. dsb_idx = BP_FUNC(bp);
  6859. else
  6860. dsb_idx = BP_VN(bp);
  6861. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6862. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6863. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6864. /*
  6865. * igu prods come in chunks of E1HVN_MAX (4) -
  6866. * does not matters what is the current chip mode
  6867. */
  6868. for (i = 0; i < (num_segs * E1HVN_MAX);
  6869. i += E1HVN_MAX) {
  6870. addr = IGU_REG_PROD_CONS_MEMORY +
  6871. (prod_offset + i)*4;
  6872. REG_WR(bp, addr, 0);
  6873. }
  6874. /* send consumer update with 0 */
  6875. if (CHIP_INT_MODE_IS_BC(bp)) {
  6876. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6877. USTORM_ID, 0, IGU_INT_NOP, 1);
  6878. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6879. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6880. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6881. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6882. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6883. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6884. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6885. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6886. } else {
  6887. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6888. USTORM_ID, 0, IGU_INT_NOP, 1);
  6889. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6890. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6891. }
  6892. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6893. /* !!! These should become driver const once
  6894. rf-tool supports split-68 const */
  6895. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6896. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6897. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6898. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6899. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6900. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6901. }
  6902. }
  6903. /* Reset PCIE errors for debug */
  6904. REG_WR(bp, 0x2114, 0xffffffff);
  6905. REG_WR(bp, 0x2120, 0xffffffff);
  6906. if (CHIP_IS_E1x(bp)) {
  6907. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6908. main_mem_base = HC_REG_MAIN_MEMORY +
  6909. BP_PORT(bp) * (main_mem_size * 4);
  6910. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6911. main_mem_width = 8;
  6912. val = REG_RD(bp, main_mem_prty_clr);
  6913. if (val)
  6914. DP(NETIF_MSG_HW,
  6915. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6916. val);
  6917. /* Clear "false" parity errors in MSI-X table */
  6918. for (i = main_mem_base;
  6919. i < main_mem_base + main_mem_size * 4;
  6920. i += main_mem_width) {
  6921. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6922. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6923. i, main_mem_width / 4);
  6924. }
  6925. /* Clear HC parity attention */
  6926. REG_RD(bp, main_mem_prty_clr);
  6927. }
  6928. #ifdef BNX2X_STOP_ON_ERROR
  6929. /* Enable STORMs SP logging */
  6930. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6931. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6932. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6933. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6934. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6935. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6936. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6937. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6938. #endif
  6939. bnx2x_phy_probe(&bp->link_params);
  6940. return 0;
  6941. }
  6942. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6943. {
  6944. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6945. if (!CHIP_IS_E1x(bp))
  6946. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6947. sizeof(struct host_hc_status_block_e2));
  6948. else
  6949. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6950. sizeof(struct host_hc_status_block_e1x));
  6951. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6952. }
  6953. void bnx2x_free_mem(struct bnx2x *bp)
  6954. {
  6955. int i;
  6956. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6957. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6958. if (IS_VF(bp))
  6959. return;
  6960. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6961. sizeof(struct host_sp_status_block));
  6962. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6963. sizeof(struct bnx2x_slowpath));
  6964. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6965. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6966. bp->context[i].size);
  6967. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6968. BNX2X_FREE(bp->ilt->lines);
  6969. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6970. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6971. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6972. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6973. bnx2x_iov_free_mem(bp);
  6974. }
  6975. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6976. {
  6977. if (!CHIP_IS_E1x(bp)) {
  6978. /* size = the status block + ramrod buffers */
  6979. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6980. sizeof(struct host_hc_status_block_e2));
  6981. if (!bp->cnic_sb.e2_sb)
  6982. goto alloc_mem_err;
  6983. } else {
  6984. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6985. sizeof(struct host_hc_status_block_e1x));
  6986. if (!bp->cnic_sb.e1x_sb)
  6987. goto alloc_mem_err;
  6988. }
  6989. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6990. /* allocate searcher T2 table, as it wasn't allocated before */
  6991. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6992. if (!bp->t2)
  6993. goto alloc_mem_err;
  6994. }
  6995. /* write address to which L5 should insert its values */
  6996. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6997. &bp->slowpath->drv_info_to_mcp;
  6998. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6999. goto alloc_mem_err;
  7000. return 0;
  7001. alloc_mem_err:
  7002. bnx2x_free_mem_cnic(bp);
  7003. BNX2X_ERR("Can't allocate memory\n");
  7004. return -ENOMEM;
  7005. }
  7006. int bnx2x_alloc_mem(struct bnx2x *bp)
  7007. {
  7008. int i, allocated, context_size;
  7009. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  7010. /* allocate searcher T2 table */
  7011. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  7012. if (!bp->t2)
  7013. goto alloc_mem_err;
  7014. }
  7015. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  7016. sizeof(struct host_sp_status_block));
  7017. if (!bp->def_status_blk)
  7018. goto alloc_mem_err;
  7019. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  7020. sizeof(struct bnx2x_slowpath));
  7021. if (!bp->slowpath)
  7022. goto alloc_mem_err;
  7023. /* Allocate memory for CDU context:
  7024. * This memory is allocated separately and not in the generic ILT
  7025. * functions because CDU differs in few aspects:
  7026. * 1. There are multiple entities allocating memory for context -
  7027. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  7028. * its own ILT lines.
  7029. * 2. Since CDU page-size is not a single 4KB page (which is the case
  7030. * for the other ILT clients), to be efficient we want to support
  7031. * allocation of sub-page-size in the last entry.
  7032. * 3. Context pointers are used by the driver to pass to FW / update
  7033. * the context (for the other ILT clients the pointers are used just to
  7034. * free the memory during unload).
  7035. */
  7036. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  7037. for (i = 0, allocated = 0; allocated < context_size; i++) {
  7038. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  7039. (context_size - allocated));
  7040. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  7041. bp->context[i].size);
  7042. if (!bp->context[i].vcxt)
  7043. goto alloc_mem_err;
  7044. allocated += bp->context[i].size;
  7045. }
  7046. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  7047. GFP_KERNEL);
  7048. if (!bp->ilt->lines)
  7049. goto alloc_mem_err;
  7050. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  7051. goto alloc_mem_err;
  7052. if (bnx2x_iov_alloc_mem(bp))
  7053. goto alloc_mem_err;
  7054. /* Slow path ring */
  7055. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  7056. if (!bp->spq)
  7057. goto alloc_mem_err;
  7058. /* EQ */
  7059. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  7060. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  7061. if (!bp->eq_ring)
  7062. goto alloc_mem_err;
  7063. return 0;
  7064. alloc_mem_err:
  7065. bnx2x_free_mem(bp);
  7066. BNX2X_ERR("Can't allocate memory\n");
  7067. return -ENOMEM;
  7068. }
  7069. /*
  7070. * Init service functions
  7071. */
  7072. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7073. struct bnx2x_vlan_mac_obj *obj, bool set,
  7074. int mac_type, unsigned long *ramrod_flags)
  7075. {
  7076. int rc;
  7077. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7078. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7079. /* Fill general parameters */
  7080. ramrod_param.vlan_mac_obj = obj;
  7081. ramrod_param.ramrod_flags = *ramrod_flags;
  7082. /* Fill a user request section if needed */
  7083. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7084. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7085. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7086. /* Set the command: ADD or DEL */
  7087. if (set)
  7088. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7089. else
  7090. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7091. }
  7092. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7093. if (rc == -EEXIST) {
  7094. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7095. /* do not treat adding same MAC as error */
  7096. rc = 0;
  7097. } else if (rc < 0)
  7098. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7099. return rc;
  7100. }
  7101. int bnx2x_set_vlan_one(struct bnx2x *bp, u16 vlan,
  7102. struct bnx2x_vlan_mac_obj *obj, bool set,
  7103. unsigned long *ramrod_flags)
  7104. {
  7105. int rc;
  7106. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7107. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7108. /* Fill general parameters */
  7109. ramrod_param.vlan_mac_obj = obj;
  7110. ramrod_param.ramrod_flags = *ramrod_flags;
  7111. /* Fill a user request section if needed */
  7112. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7113. ramrod_param.user_req.u.vlan.vlan = vlan;
  7114. __set_bit(BNX2X_VLAN, &ramrod_param.user_req.vlan_mac_flags);
  7115. /* Set the command: ADD or DEL */
  7116. if (set)
  7117. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7118. else
  7119. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7120. }
  7121. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7122. if (rc == -EEXIST) {
  7123. /* Do not treat adding same vlan as error. */
  7124. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7125. rc = 0;
  7126. } else if (rc < 0) {
  7127. BNX2X_ERR("%s VLAN failed\n", (set ? "Set" : "Del"));
  7128. }
  7129. return rc;
  7130. }
  7131. void bnx2x_clear_vlan_info(struct bnx2x *bp)
  7132. {
  7133. struct bnx2x_vlan_entry *vlan;
  7134. /* Mark that hw forgot all entries */
  7135. list_for_each_entry(vlan, &bp->vlan_reg, link)
  7136. vlan->hw = false;
  7137. bp->vlan_cnt = 0;
  7138. }
  7139. static int bnx2x_del_all_vlans(struct bnx2x *bp)
  7140. {
  7141. struct bnx2x_vlan_mac_obj *vlan_obj = &bp->sp_objs[0].vlan_obj;
  7142. unsigned long ramrod_flags = 0, vlan_flags = 0;
  7143. int rc;
  7144. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7145. __set_bit(BNX2X_VLAN, &vlan_flags);
  7146. rc = vlan_obj->delete_all(bp, vlan_obj, &vlan_flags, &ramrod_flags);
  7147. if (rc)
  7148. return rc;
  7149. bnx2x_clear_vlan_info(bp);
  7150. return 0;
  7151. }
  7152. int bnx2x_del_all_macs(struct bnx2x *bp,
  7153. struct bnx2x_vlan_mac_obj *mac_obj,
  7154. int mac_type, bool wait_for_comp)
  7155. {
  7156. int rc;
  7157. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7158. /* Wait for completion of requested */
  7159. if (wait_for_comp)
  7160. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7161. /* Set the mac type of addresses we want to clear */
  7162. __set_bit(mac_type, &vlan_mac_flags);
  7163. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7164. if (rc < 0)
  7165. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7166. return rc;
  7167. }
  7168. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7169. {
  7170. if (IS_PF(bp)) {
  7171. unsigned long ramrod_flags = 0;
  7172. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7173. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7174. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7175. &bp->sp_objs->mac_obj, set,
  7176. BNX2X_ETH_MAC, &ramrod_flags);
  7177. } else { /* vf */
  7178. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7179. bp->fp->index, set);
  7180. }
  7181. }
  7182. int bnx2x_setup_leading(struct bnx2x *bp)
  7183. {
  7184. if (IS_PF(bp))
  7185. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7186. else /* VF */
  7187. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7188. }
  7189. /**
  7190. * bnx2x_set_int_mode - configure interrupt mode
  7191. *
  7192. * @bp: driver handle
  7193. *
  7194. * In case of MSI-X it will also try to enable MSI-X.
  7195. */
  7196. int bnx2x_set_int_mode(struct bnx2x *bp)
  7197. {
  7198. int rc = 0;
  7199. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7200. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7201. return -EINVAL;
  7202. }
  7203. switch (int_mode) {
  7204. case BNX2X_INT_MODE_MSIX:
  7205. /* attempt to enable msix */
  7206. rc = bnx2x_enable_msix(bp);
  7207. /* msix attained */
  7208. if (!rc)
  7209. return 0;
  7210. /* vfs use only msix */
  7211. if (rc && IS_VF(bp))
  7212. return rc;
  7213. /* failed to enable multiple MSI-X */
  7214. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7215. bp->num_queues,
  7216. 1 + bp->num_cnic_queues);
  7217. /* fall through */
  7218. case BNX2X_INT_MODE_MSI:
  7219. bnx2x_enable_msi(bp);
  7220. /* fall through */
  7221. case BNX2X_INT_MODE_INTX:
  7222. bp->num_ethernet_queues = 1;
  7223. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7224. BNX2X_DEV_INFO("set number of queues to 1\n");
  7225. break;
  7226. default:
  7227. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7228. return -EINVAL;
  7229. }
  7230. return 0;
  7231. }
  7232. /* must be called prior to any HW initializations */
  7233. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7234. {
  7235. if (IS_SRIOV(bp))
  7236. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7237. return L2_ILT_LINES(bp);
  7238. }
  7239. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7240. {
  7241. struct ilt_client_info *ilt_client;
  7242. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7243. u16 line = 0;
  7244. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7245. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7246. /* CDU */
  7247. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7248. ilt_client->client_num = ILT_CLIENT_CDU;
  7249. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7250. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7251. ilt_client->start = line;
  7252. line += bnx2x_cid_ilt_lines(bp);
  7253. if (CNIC_SUPPORT(bp))
  7254. line += CNIC_ILT_LINES;
  7255. ilt_client->end = line - 1;
  7256. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7257. ilt_client->start,
  7258. ilt_client->end,
  7259. ilt_client->page_size,
  7260. ilt_client->flags,
  7261. ilog2(ilt_client->page_size >> 12));
  7262. /* QM */
  7263. if (QM_INIT(bp->qm_cid_count)) {
  7264. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7265. ilt_client->client_num = ILT_CLIENT_QM;
  7266. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7267. ilt_client->flags = 0;
  7268. ilt_client->start = line;
  7269. /* 4 bytes for each cid */
  7270. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7271. QM_ILT_PAGE_SZ);
  7272. ilt_client->end = line - 1;
  7273. DP(NETIF_MSG_IFUP,
  7274. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7275. ilt_client->start,
  7276. ilt_client->end,
  7277. ilt_client->page_size,
  7278. ilt_client->flags,
  7279. ilog2(ilt_client->page_size >> 12));
  7280. }
  7281. if (CNIC_SUPPORT(bp)) {
  7282. /* SRC */
  7283. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7284. ilt_client->client_num = ILT_CLIENT_SRC;
  7285. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7286. ilt_client->flags = 0;
  7287. ilt_client->start = line;
  7288. line += SRC_ILT_LINES;
  7289. ilt_client->end = line - 1;
  7290. DP(NETIF_MSG_IFUP,
  7291. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7292. ilt_client->start,
  7293. ilt_client->end,
  7294. ilt_client->page_size,
  7295. ilt_client->flags,
  7296. ilog2(ilt_client->page_size >> 12));
  7297. /* TM */
  7298. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7299. ilt_client->client_num = ILT_CLIENT_TM;
  7300. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7301. ilt_client->flags = 0;
  7302. ilt_client->start = line;
  7303. line += TM_ILT_LINES;
  7304. ilt_client->end = line - 1;
  7305. DP(NETIF_MSG_IFUP,
  7306. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7307. ilt_client->start,
  7308. ilt_client->end,
  7309. ilt_client->page_size,
  7310. ilt_client->flags,
  7311. ilog2(ilt_client->page_size >> 12));
  7312. }
  7313. BUG_ON(line > ILT_MAX_LINES);
  7314. }
  7315. /**
  7316. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7317. *
  7318. * @bp: driver handle
  7319. * @fp: pointer to fastpath
  7320. * @init_params: pointer to parameters structure
  7321. *
  7322. * parameters configured:
  7323. * - HC configuration
  7324. * - Queue's CDU context
  7325. */
  7326. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7327. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7328. {
  7329. u8 cos;
  7330. int cxt_index, cxt_offset;
  7331. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7332. if (!IS_FCOE_FP(fp)) {
  7333. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7334. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7335. /* If HC is supported, enable host coalescing in the transition
  7336. * to INIT state.
  7337. */
  7338. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7339. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7340. /* HC rate */
  7341. init_params->rx.hc_rate = bp->rx_ticks ?
  7342. (1000000 / bp->rx_ticks) : 0;
  7343. init_params->tx.hc_rate = bp->tx_ticks ?
  7344. (1000000 / bp->tx_ticks) : 0;
  7345. /* FW SB ID */
  7346. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7347. fp->fw_sb_id;
  7348. /*
  7349. * CQ index among the SB indices: FCoE clients uses the default
  7350. * SB, therefore it's different.
  7351. */
  7352. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7353. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7354. }
  7355. /* set maximum number of COSs supported by this queue */
  7356. init_params->max_cos = fp->max_cos;
  7357. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7358. fp->index, init_params->max_cos);
  7359. /* set the context pointers queue object */
  7360. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7361. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7362. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7363. ILT_PAGE_CIDS);
  7364. init_params->cxts[cos] =
  7365. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7366. }
  7367. }
  7368. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7369. struct bnx2x_queue_state_params *q_params,
  7370. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7371. int tx_index, bool leading)
  7372. {
  7373. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7374. /* Set the command */
  7375. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7376. /* Set tx-only QUEUE flags: don't zero statistics */
  7377. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7378. /* choose the index of the cid to send the slow path on */
  7379. tx_only_params->cid_index = tx_index;
  7380. /* Set general TX_ONLY_SETUP parameters */
  7381. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7382. /* Set Tx TX_ONLY_SETUP parameters */
  7383. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7384. DP(NETIF_MSG_IFUP,
  7385. "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",
  7386. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7387. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7388. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7389. /* send the ramrod */
  7390. return bnx2x_queue_state_change(bp, q_params);
  7391. }
  7392. /**
  7393. * bnx2x_setup_queue - setup queue
  7394. *
  7395. * @bp: driver handle
  7396. * @fp: pointer to fastpath
  7397. * @leading: is leading
  7398. *
  7399. * This function performs 2 steps in a Queue state machine
  7400. * actually: 1) RESET->INIT 2) INIT->SETUP
  7401. */
  7402. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7403. bool leading)
  7404. {
  7405. struct bnx2x_queue_state_params q_params = {NULL};
  7406. struct bnx2x_queue_setup_params *setup_params =
  7407. &q_params.params.setup;
  7408. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7409. &q_params.params.tx_only;
  7410. int rc;
  7411. u8 tx_index;
  7412. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7413. /* reset IGU state skip FCoE L2 queue */
  7414. if (!IS_FCOE_FP(fp))
  7415. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7416. IGU_INT_ENABLE, 0);
  7417. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7418. /* We want to wait for completion in this context */
  7419. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7420. /* Prepare the INIT parameters */
  7421. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7422. /* Set the command */
  7423. q_params.cmd = BNX2X_Q_CMD_INIT;
  7424. /* Change the state to INIT */
  7425. rc = bnx2x_queue_state_change(bp, &q_params);
  7426. if (rc) {
  7427. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7428. return rc;
  7429. }
  7430. DP(NETIF_MSG_IFUP, "init complete\n");
  7431. /* Now move the Queue to the SETUP state... */
  7432. memset(setup_params, 0, sizeof(*setup_params));
  7433. /* Set QUEUE flags */
  7434. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7435. /* Set general SETUP parameters */
  7436. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7437. FIRST_TX_COS_INDEX);
  7438. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7439. &setup_params->rxq_params);
  7440. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7441. FIRST_TX_COS_INDEX);
  7442. /* Set the command */
  7443. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7444. if (IS_FCOE_FP(fp))
  7445. bp->fcoe_init = true;
  7446. /* Change the state to SETUP */
  7447. rc = bnx2x_queue_state_change(bp, &q_params);
  7448. if (rc) {
  7449. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7450. return rc;
  7451. }
  7452. /* loop through the relevant tx-only indices */
  7453. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7454. tx_index < fp->max_cos;
  7455. tx_index++) {
  7456. /* prepare and send tx-only ramrod*/
  7457. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7458. tx_only_params, tx_index, leading);
  7459. if (rc) {
  7460. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7461. fp->index, tx_index);
  7462. return rc;
  7463. }
  7464. }
  7465. return rc;
  7466. }
  7467. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7468. {
  7469. struct bnx2x_fastpath *fp = &bp->fp[index];
  7470. struct bnx2x_fp_txdata *txdata;
  7471. struct bnx2x_queue_state_params q_params = {NULL};
  7472. int rc, tx_index;
  7473. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7474. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7475. /* We want to wait for completion in this context */
  7476. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7477. /* close tx-only connections */
  7478. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7479. tx_index < fp->max_cos;
  7480. tx_index++){
  7481. /* ascertain this is a normal queue*/
  7482. txdata = fp->txdata_ptr[tx_index];
  7483. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7484. txdata->txq_index);
  7485. /* send halt terminate on tx-only connection */
  7486. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7487. memset(&q_params.params.terminate, 0,
  7488. sizeof(q_params.params.terminate));
  7489. q_params.params.terminate.cid_index = tx_index;
  7490. rc = bnx2x_queue_state_change(bp, &q_params);
  7491. if (rc)
  7492. return rc;
  7493. /* send halt terminate on tx-only connection */
  7494. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7495. memset(&q_params.params.cfc_del, 0,
  7496. sizeof(q_params.params.cfc_del));
  7497. q_params.params.cfc_del.cid_index = tx_index;
  7498. rc = bnx2x_queue_state_change(bp, &q_params);
  7499. if (rc)
  7500. return rc;
  7501. }
  7502. /* Stop the primary connection: */
  7503. /* ...halt the connection */
  7504. q_params.cmd = BNX2X_Q_CMD_HALT;
  7505. rc = bnx2x_queue_state_change(bp, &q_params);
  7506. if (rc)
  7507. return rc;
  7508. /* ...terminate the connection */
  7509. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7510. memset(&q_params.params.terminate, 0,
  7511. sizeof(q_params.params.terminate));
  7512. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7513. rc = bnx2x_queue_state_change(bp, &q_params);
  7514. if (rc)
  7515. return rc;
  7516. /* ...delete cfc entry */
  7517. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7518. memset(&q_params.params.cfc_del, 0,
  7519. sizeof(q_params.params.cfc_del));
  7520. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7521. return bnx2x_queue_state_change(bp, &q_params);
  7522. }
  7523. static void bnx2x_reset_func(struct bnx2x *bp)
  7524. {
  7525. int port = BP_PORT(bp);
  7526. int func = BP_FUNC(bp);
  7527. int i;
  7528. /* Disable the function in the FW */
  7529. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7530. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7531. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7532. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7533. /* FP SBs */
  7534. for_each_eth_queue(bp, i) {
  7535. struct bnx2x_fastpath *fp = &bp->fp[i];
  7536. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7537. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7538. SB_DISABLED);
  7539. }
  7540. if (CNIC_LOADED(bp))
  7541. /* CNIC SB */
  7542. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7543. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7544. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7545. /* SP SB */
  7546. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7547. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7548. SB_DISABLED);
  7549. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7550. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7551. 0);
  7552. /* Configure IGU */
  7553. if (bp->common.int_block == INT_BLOCK_HC) {
  7554. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7555. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7556. } else {
  7557. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7558. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7559. }
  7560. if (CNIC_LOADED(bp)) {
  7561. /* Disable Timer scan */
  7562. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7563. /*
  7564. * Wait for at least 10ms and up to 2 second for the timers
  7565. * scan to complete
  7566. */
  7567. for (i = 0; i < 200; i++) {
  7568. usleep_range(10000, 20000);
  7569. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7570. break;
  7571. }
  7572. }
  7573. /* Clear ILT */
  7574. bnx2x_clear_func_ilt(bp, func);
  7575. /* Timers workaround bug for E2: if this is vnic-3,
  7576. * we need to set the entire ilt range for this timers.
  7577. */
  7578. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7579. struct ilt_client_info ilt_cli;
  7580. /* use dummy TM client */
  7581. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7582. ilt_cli.start = 0;
  7583. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7584. ilt_cli.client_num = ILT_CLIENT_TM;
  7585. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7586. }
  7587. /* this assumes that reset_port() called before reset_func()*/
  7588. if (!CHIP_IS_E1x(bp))
  7589. bnx2x_pf_disable(bp);
  7590. bp->dmae_ready = 0;
  7591. }
  7592. static void bnx2x_reset_port(struct bnx2x *bp)
  7593. {
  7594. int port = BP_PORT(bp);
  7595. u32 val;
  7596. /* Reset physical Link */
  7597. bnx2x__link_reset(bp);
  7598. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7599. /* Do not rcv packets to BRB */
  7600. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7601. /* Do not direct rcv packets that are not for MCP to the BRB */
  7602. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7603. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7604. /* Configure AEU */
  7605. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7606. msleep(100);
  7607. /* Check for BRB port occupancy */
  7608. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7609. if (val)
  7610. DP(NETIF_MSG_IFDOWN,
  7611. "BRB1 is not empty %d blocks are occupied\n", val);
  7612. /* TODO: Close Doorbell port? */
  7613. }
  7614. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7615. {
  7616. struct bnx2x_func_state_params func_params = {NULL};
  7617. /* Prepare parameters for function state transitions */
  7618. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7619. func_params.f_obj = &bp->func_obj;
  7620. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7621. func_params.params.hw_init.load_phase = load_code;
  7622. return bnx2x_func_state_change(bp, &func_params);
  7623. }
  7624. static int bnx2x_func_stop(struct bnx2x *bp)
  7625. {
  7626. struct bnx2x_func_state_params func_params = {NULL};
  7627. int rc;
  7628. /* Prepare parameters for function state transitions */
  7629. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7630. func_params.f_obj = &bp->func_obj;
  7631. func_params.cmd = BNX2X_F_CMD_STOP;
  7632. /*
  7633. * Try to stop the function the 'good way'. If fails (in case
  7634. * of a parity error during bnx2x_chip_cleanup()) and we are
  7635. * not in a debug mode, perform a state transaction in order to
  7636. * enable further HW_RESET transaction.
  7637. */
  7638. rc = bnx2x_func_state_change(bp, &func_params);
  7639. if (rc) {
  7640. #ifdef BNX2X_STOP_ON_ERROR
  7641. return rc;
  7642. #else
  7643. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7644. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7645. return bnx2x_func_state_change(bp, &func_params);
  7646. #endif
  7647. }
  7648. return 0;
  7649. }
  7650. /**
  7651. * bnx2x_send_unload_req - request unload mode from the MCP.
  7652. *
  7653. * @bp: driver handle
  7654. * @unload_mode: requested function's unload mode
  7655. *
  7656. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7657. */
  7658. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7659. {
  7660. u32 reset_code = 0;
  7661. int port = BP_PORT(bp);
  7662. /* Select the UNLOAD request mode */
  7663. if (unload_mode == UNLOAD_NORMAL)
  7664. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7665. else if (bp->flags & NO_WOL_FLAG)
  7666. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7667. else if (bp->wol) {
  7668. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7669. u8 *mac_addr = bp->dev->dev_addr;
  7670. struct pci_dev *pdev = bp->pdev;
  7671. u32 val;
  7672. u16 pmc;
  7673. /* The mac address is written to entries 1-4 to
  7674. * preserve entry 0 which is used by the PMF
  7675. */
  7676. u8 entry = (BP_VN(bp) + 1)*8;
  7677. val = (mac_addr[0] << 8) | mac_addr[1];
  7678. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7679. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7680. (mac_addr[4] << 8) | mac_addr[5];
  7681. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7682. /* Enable the PME and clear the status */
  7683. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7684. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7685. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7686. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7687. } else
  7688. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7689. /* Send the request to the MCP */
  7690. if (!BP_NOMCP(bp))
  7691. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7692. else {
  7693. int path = BP_PATH(bp);
  7694. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7695. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7696. bnx2x_load_count[path][2]);
  7697. bnx2x_load_count[path][0]--;
  7698. bnx2x_load_count[path][1 + port]--;
  7699. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7700. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7701. bnx2x_load_count[path][2]);
  7702. if (bnx2x_load_count[path][0] == 0)
  7703. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7704. else if (bnx2x_load_count[path][1 + port] == 0)
  7705. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7706. else
  7707. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7708. }
  7709. return reset_code;
  7710. }
  7711. /**
  7712. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7713. *
  7714. * @bp: driver handle
  7715. * @keep_link: true iff link should be kept up
  7716. */
  7717. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7718. {
  7719. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7720. /* Report UNLOAD_DONE to MCP */
  7721. if (!BP_NOMCP(bp))
  7722. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7723. }
  7724. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7725. {
  7726. int tout = 50;
  7727. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7728. if (!bp->port.pmf)
  7729. return 0;
  7730. /*
  7731. * (assumption: No Attention from MCP at this stage)
  7732. * PMF probably in the middle of TX disable/enable transaction
  7733. * 1. Sync IRS for default SB
  7734. * 2. Sync SP queue - this guarantees us that attention handling started
  7735. * 3. Wait, that TX disable/enable transaction completes
  7736. *
  7737. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7738. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7739. * received completion for the transaction the state is TX_STOPPED.
  7740. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7741. * transaction.
  7742. */
  7743. /* make sure default SB ISR is done */
  7744. if (msix)
  7745. synchronize_irq(bp->msix_table[0].vector);
  7746. else
  7747. synchronize_irq(bp->pdev->irq);
  7748. flush_workqueue(bnx2x_wq);
  7749. flush_workqueue(bnx2x_iov_wq);
  7750. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7751. BNX2X_F_STATE_STARTED && tout--)
  7752. msleep(20);
  7753. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7754. BNX2X_F_STATE_STARTED) {
  7755. #ifdef BNX2X_STOP_ON_ERROR
  7756. BNX2X_ERR("Wrong function state\n");
  7757. return -EBUSY;
  7758. #else
  7759. /*
  7760. * Failed to complete the transaction in a "good way"
  7761. * Force both transactions with CLR bit
  7762. */
  7763. struct bnx2x_func_state_params func_params = {NULL};
  7764. DP(NETIF_MSG_IFDOWN,
  7765. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7766. func_params.f_obj = &bp->func_obj;
  7767. __set_bit(RAMROD_DRV_CLR_ONLY,
  7768. &func_params.ramrod_flags);
  7769. /* STARTED-->TX_ST0PPED */
  7770. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7771. bnx2x_func_state_change(bp, &func_params);
  7772. /* TX_ST0PPED-->STARTED */
  7773. func_params.cmd = BNX2X_F_CMD_TX_START;
  7774. return bnx2x_func_state_change(bp, &func_params);
  7775. #endif
  7776. }
  7777. return 0;
  7778. }
  7779. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7780. {
  7781. int port = BP_PORT(bp);
  7782. /* Disable sending PTP packets to host */
  7783. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7784. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7785. /* Reset PTP event detection rules */
  7786. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7787. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7788. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7789. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7790. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7791. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7792. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7793. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7794. /* Disable the PTP feature */
  7795. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7796. NIG_REG_P0_PTP_EN, 0x0);
  7797. }
  7798. /* Called during unload, to stop PTP-related stuff */
  7799. static void bnx2x_stop_ptp(struct bnx2x *bp)
  7800. {
  7801. /* Cancel PTP work queue. Should be done after the Tx queues are
  7802. * drained to prevent additional scheduling.
  7803. */
  7804. cancel_work_sync(&bp->ptp_task);
  7805. if (bp->ptp_tx_skb) {
  7806. dev_kfree_skb_any(bp->ptp_tx_skb);
  7807. bp->ptp_tx_skb = NULL;
  7808. }
  7809. /* Disable PTP in HW */
  7810. bnx2x_disable_ptp(bp);
  7811. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7812. }
  7813. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7814. {
  7815. int port = BP_PORT(bp);
  7816. int i, rc = 0;
  7817. u8 cos;
  7818. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7819. u32 reset_code;
  7820. /* Wait until tx fastpath tasks complete */
  7821. for_each_tx_queue(bp, i) {
  7822. struct bnx2x_fastpath *fp = &bp->fp[i];
  7823. for_each_cos_in_tx_queue(fp, cos)
  7824. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7825. #ifdef BNX2X_STOP_ON_ERROR
  7826. if (rc)
  7827. return;
  7828. #endif
  7829. }
  7830. /* Give HW time to discard old tx messages */
  7831. usleep_range(1000, 2000);
  7832. /* Clean all ETH MACs */
  7833. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7834. false);
  7835. if (rc < 0)
  7836. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7837. /* Clean up UC list */
  7838. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7839. true);
  7840. if (rc < 0)
  7841. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7842. rc);
  7843. /* The whole *vlan_obj structure may be not initialized if VLAN
  7844. * filtering offload is not supported by hardware. Currently this is
  7845. * true for all hardware covered by CHIP_IS_E1x().
  7846. */
  7847. if (!CHIP_IS_E1x(bp)) {
  7848. /* Remove all currently configured VLANs */
  7849. rc = bnx2x_del_all_vlans(bp);
  7850. if (rc < 0)
  7851. BNX2X_ERR("Failed to delete all VLANs\n");
  7852. }
  7853. /* Disable LLH */
  7854. if (!CHIP_IS_E1(bp))
  7855. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7856. /* Set "drop all" (stop Rx).
  7857. * We need to take a netif_addr_lock() here in order to prevent
  7858. * a race between the completion code and this code.
  7859. */
  7860. netif_addr_lock_bh(bp->dev);
  7861. /* Schedule the rx_mode command */
  7862. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7863. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7864. else if (bp->slowpath)
  7865. bnx2x_set_storm_rx_mode(bp);
  7866. /* Cleanup multicast configuration */
  7867. rparam.mcast_obj = &bp->mcast_obj;
  7868. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7869. if (rc < 0)
  7870. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7871. netif_addr_unlock_bh(bp->dev);
  7872. bnx2x_iov_chip_cleanup(bp);
  7873. /*
  7874. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7875. * this function should perform FUNC, PORT or COMMON HW
  7876. * reset.
  7877. */
  7878. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7879. /*
  7880. * (assumption: No Attention from MCP at this stage)
  7881. * PMF probably in the middle of TX disable/enable transaction
  7882. */
  7883. rc = bnx2x_func_wait_started(bp);
  7884. if (rc) {
  7885. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7886. #ifdef BNX2X_STOP_ON_ERROR
  7887. return;
  7888. #endif
  7889. }
  7890. /* Close multi and leading connections
  7891. * Completions for ramrods are collected in a synchronous way
  7892. */
  7893. for_each_eth_queue(bp, i)
  7894. if (bnx2x_stop_queue(bp, i))
  7895. #ifdef BNX2X_STOP_ON_ERROR
  7896. return;
  7897. #else
  7898. goto unload_error;
  7899. #endif
  7900. if (CNIC_LOADED(bp)) {
  7901. for_each_cnic_queue(bp, i)
  7902. if (bnx2x_stop_queue(bp, i))
  7903. #ifdef BNX2X_STOP_ON_ERROR
  7904. return;
  7905. #else
  7906. goto unload_error;
  7907. #endif
  7908. }
  7909. /* If SP settings didn't get completed so far - something
  7910. * very wrong has happen.
  7911. */
  7912. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7913. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7914. #ifndef BNX2X_STOP_ON_ERROR
  7915. unload_error:
  7916. #endif
  7917. rc = bnx2x_func_stop(bp);
  7918. if (rc) {
  7919. BNX2X_ERR("Function stop failed!\n");
  7920. #ifdef BNX2X_STOP_ON_ERROR
  7921. return;
  7922. #endif
  7923. }
  7924. /* stop_ptp should be after the Tx queues are drained to prevent
  7925. * scheduling to the cancelled PTP work queue. It should also be after
  7926. * function stop ramrod is sent, since as part of this ramrod FW access
  7927. * PTP registers.
  7928. */
  7929. if (bp->flags & PTP_SUPPORTED)
  7930. bnx2x_stop_ptp(bp);
  7931. /* Disable HW interrupts, NAPI */
  7932. bnx2x_netif_stop(bp, 1);
  7933. /* Delete all NAPI objects */
  7934. bnx2x_del_all_napi(bp);
  7935. if (CNIC_LOADED(bp))
  7936. bnx2x_del_all_napi_cnic(bp);
  7937. /* Release IRQs */
  7938. bnx2x_free_irq(bp);
  7939. /* Reset the chip, unless PCI function is offline. If we reach this
  7940. * point following a PCI error handling, it means device is really
  7941. * in a bad state and we're about to remove it, so reset the chip
  7942. * is not a good idea.
  7943. */
  7944. if (!pci_channel_offline(bp->pdev)) {
  7945. rc = bnx2x_reset_hw(bp, reset_code);
  7946. if (rc)
  7947. BNX2X_ERR("HW_RESET failed\n");
  7948. }
  7949. /* Report UNLOAD_DONE to MCP */
  7950. bnx2x_send_unload_done(bp, keep_link);
  7951. }
  7952. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7953. {
  7954. u32 val;
  7955. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7956. if (CHIP_IS_E1(bp)) {
  7957. int port = BP_PORT(bp);
  7958. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7959. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7960. val = REG_RD(bp, addr);
  7961. val &= ~(0x300);
  7962. REG_WR(bp, addr, val);
  7963. } else {
  7964. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7965. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7966. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7967. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7968. }
  7969. }
  7970. /* Close gates #2, #3 and #4: */
  7971. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7972. {
  7973. u32 val;
  7974. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7975. if (!CHIP_IS_E1(bp)) {
  7976. /* #4 */
  7977. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7978. /* #2 */
  7979. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7980. }
  7981. /* #3 */
  7982. if (CHIP_IS_E1x(bp)) {
  7983. /* Prevent interrupts from HC on both ports */
  7984. val = REG_RD(bp, HC_REG_CONFIG_1);
  7985. REG_WR(bp, HC_REG_CONFIG_1,
  7986. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7987. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7988. val = REG_RD(bp, HC_REG_CONFIG_0);
  7989. REG_WR(bp, HC_REG_CONFIG_0,
  7990. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7991. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7992. } else {
  7993. /* Prevent incoming interrupts in IGU */
  7994. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7995. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7996. (!close) ?
  7997. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7998. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7999. }
  8000. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  8001. close ? "closing" : "opening");
  8002. mmiowb();
  8003. }
  8004. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  8005. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  8006. {
  8007. /* Do some magic... */
  8008. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  8009. *magic_val = val & SHARED_MF_CLP_MAGIC;
  8010. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  8011. }
  8012. /**
  8013. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  8014. *
  8015. * @bp: driver handle
  8016. * @magic_val: old value of the `magic' bit.
  8017. */
  8018. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  8019. {
  8020. /* Restore the `magic' bit value... */
  8021. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  8022. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  8023. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  8024. }
  8025. /**
  8026. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  8027. *
  8028. * @bp: driver handle
  8029. * @magic_val: old value of 'magic' bit.
  8030. *
  8031. * Takes care of CLP configurations.
  8032. */
  8033. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  8034. {
  8035. u32 shmem;
  8036. u32 validity_offset;
  8037. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  8038. /* Set `magic' bit in order to save MF config */
  8039. if (!CHIP_IS_E1(bp))
  8040. bnx2x_clp_reset_prep(bp, magic_val);
  8041. /* Get shmem offset */
  8042. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  8043. validity_offset =
  8044. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  8045. /* Clear validity map flags */
  8046. if (shmem > 0)
  8047. REG_WR(bp, shmem + validity_offset, 0);
  8048. }
  8049. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  8050. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  8051. /**
  8052. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  8053. *
  8054. * @bp: driver handle
  8055. */
  8056. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  8057. {
  8058. /* special handling for emulation and FPGA,
  8059. wait 10 times longer */
  8060. if (CHIP_REV_IS_SLOW(bp))
  8061. msleep(MCP_ONE_TIMEOUT*10);
  8062. else
  8063. msleep(MCP_ONE_TIMEOUT);
  8064. }
  8065. /*
  8066. * initializes bp->common.shmem_base and waits for validity signature to appear
  8067. */
  8068. static int bnx2x_init_shmem(struct bnx2x *bp)
  8069. {
  8070. int cnt = 0;
  8071. u32 val = 0;
  8072. do {
  8073. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  8074. /* If we read all 0xFFs, means we are in PCI error state and
  8075. * should bail out to avoid crashes on adapter's FW reads.
  8076. */
  8077. if (bp->common.shmem_base == 0xFFFFFFFF) {
  8078. bp->flags |= NO_MCP_FLAG;
  8079. return -ENODEV;
  8080. }
  8081. if (bp->common.shmem_base) {
  8082. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  8083. if (val & SHR_MEM_VALIDITY_MB)
  8084. return 0;
  8085. }
  8086. bnx2x_mcp_wait_one(bp);
  8087. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  8088. BNX2X_ERR("BAD MCP validity signature\n");
  8089. return -ENODEV;
  8090. }
  8091. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  8092. {
  8093. int rc = bnx2x_init_shmem(bp);
  8094. /* Restore the `magic' bit value */
  8095. if (!CHIP_IS_E1(bp))
  8096. bnx2x_clp_reset_done(bp, magic_val);
  8097. return rc;
  8098. }
  8099. static void bnx2x_pxp_prep(struct bnx2x *bp)
  8100. {
  8101. if (!CHIP_IS_E1(bp)) {
  8102. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  8103. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  8104. mmiowb();
  8105. }
  8106. }
  8107. /*
  8108. * Reset the whole chip except for:
  8109. * - PCIE core
  8110. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  8111. * one reset bit)
  8112. * - IGU
  8113. * - MISC (including AEU)
  8114. * - GRC
  8115. * - RBCN, RBCP
  8116. */
  8117. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  8118. {
  8119. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  8120. u32 global_bits2, stay_reset2;
  8121. /*
  8122. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  8123. * (per chip) blocks.
  8124. */
  8125. global_bits2 =
  8126. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  8127. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  8128. /* Don't reset the following blocks.
  8129. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  8130. * reset, as in 4 port device they might still be owned
  8131. * by the MCP (there is only one leader per path).
  8132. */
  8133. not_reset_mask1 =
  8134. MISC_REGISTERS_RESET_REG_1_RST_HC |
  8135. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  8136. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  8137. not_reset_mask2 =
  8138. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  8139. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8140. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8141. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8142. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8143. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8144. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8145. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8146. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8147. MISC_REGISTERS_RESET_REG_2_PGLC |
  8148. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8149. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8150. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8151. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8152. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8153. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8154. /*
  8155. * Keep the following blocks in reset:
  8156. * - all xxMACs are handled by the bnx2x_link code.
  8157. */
  8158. stay_reset2 =
  8159. MISC_REGISTERS_RESET_REG_2_XMAC |
  8160. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8161. /* Full reset masks according to the chip */
  8162. reset_mask1 = 0xffffffff;
  8163. if (CHIP_IS_E1(bp))
  8164. reset_mask2 = 0xffff;
  8165. else if (CHIP_IS_E1H(bp))
  8166. reset_mask2 = 0x1ffff;
  8167. else if (CHIP_IS_E2(bp))
  8168. reset_mask2 = 0xfffff;
  8169. else /* CHIP_IS_E3 */
  8170. reset_mask2 = 0x3ffffff;
  8171. /* Don't reset global blocks unless we need to */
  8172. if (!global)
  8173. reset_mask2 &= ~global_bits2;
  8174. /*
  8175. * In case of attention in the QM, we need to reset PXP
  8176. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8177. * because otherwise QM reset would release 'close the gates' shortly
  8178. * before resetting the PXP, then the PSWRQ would send a write
  8179. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8180. * read the payload data from PSWWR, but PSWWR would not
  8181. * respond. The write queue in PGLUE would stuck, dmae commands
  8182. * would not return. Therefore it's important to reset the second
  8183. * reset register (containing the
  8184. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8185. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8186. * bit).
  8187. */
  8188. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8189. reset_mask2 & (~not_reset_mask2));
  8190. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8191. reset_mask1 & (~not_reset_mask1));
  8192. barrier();
  8193. mmiowb();
  8194. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8195. reset_mask2 & (~stay_reset2));
  8196. barrier();
  8197. mmiowb();
  8198. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8199. mmiowb();
  8200. }
  8201. /**
  8202. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8203. * It should get cleared in no more than 1s.
  8204. *
  8205. * @bp: driver handle
  8206. *
  8207. * It should get cleared in no more than 1s. Returns 0 if
  8208. * pending writes bit gets cleared.
  8209. */
  8210. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8211. {
  8212. u32 cnt = 1000;
  8213. u32 pend_bits = 0;
  8214. do {
  8215. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8216. if (pend_bits == 0)
  8217. break;
  8218. usleep_range(1000, 2000);
  8219. } while (cnt-- > 0);
  8220. if (cnt <= 0) {
  8221. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8222. pend_bits);
  8223. return -EBUSY;
  8224. }
  8225. return 0;
  8226. }
  8227. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8228. {
  8229. int cnt = 1000;
  8230. u32 val = 0;
  8231. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8232. u32 tags_63_32 = 0;
  8233. /* Empty the Tetris buffer, wait for 1s */
  8234. do {
  8235. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8236. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8237. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8238. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8239. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8240. if (CHIP_IS_E3(bp))
  8241. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8242. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8243. ((port_is_idle_0 & 0x1) == 0x1) &&
  8244. ((port_is_idle_1 & 0x1) == 0x1) &&
  8245. (pgl_exp_rom2 == 0xffffffff) &&
  8246. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8247. break;
  8248. usleep_range(1000, 2000);
  8249. } while (cnt-- > 0);
  8250. if (cnt <= 0) {
  8251. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8252. 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",
  8253. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8254. pgl_exp_rom2);
  8255. return -EAGAIN;
  8256. }
  8257. barrier();
  8258. /* Close gates #2, #3 and #4 */
  8259. bnx2x_set_234_gates(bp, true);
  8260. /* Poll for IGU VQs for 57712 and newer chips */
  8261. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8262. return -EAGAIN;
  8263. /* TBD: Indicate that "process kill" is in progress to MCP */
  8264. /* Clear "unprepared" bit */
  8265. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8266. barrier();
  8267. /* Make sure all is written to the chip before the reset */
  8268. mmiowb();
  8269. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8270. * PSWHST, GRC and PSWRD Tetris buffer.
  8271. */
  8272. usleep_range(1000, 2000);
  8273. /* Prepare to chip reset: */
  8274. /* MCP */
  8275. if (global)
  8276. bnx2x_reset_mcp_prep(bp, &val);
  8277. /* PXP */
  8278. bnx2x_pxp_prep(bp);
  8279. barrier();
  8280. /* reset the chip */
  8281. bnx2x_process_kill_chip_reset(bp, global);
  8282. barrier();
  8283. /* clear errors in PGB */
  8284. if (!CHIP_IS_E1x(bp))
  8285. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8286. /* Recover after reset: */
  8287. /* MCP */
  8288. if (global && bnx2x_reset_mcp_comp(bp, val))
  8289. return -EAGAIN;
  8290. /* TBD: Add resetting the NO_MCP mode DB here */
  8291. /* Open the gates #2, #3 and #4 */
  8292. bnx2x_set_234_gates(bp, false);
  8293. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8294. * reset state, re-enable attentions. */
  8295. return 0;
  8296. }
  8297. static int bnx2x_leader_reset(struct bnx2x *bp)
  8298. {
  8299. int rc = 0;
  8300. bool global = bnx2x_reset_is_global(bp);
  8301. u32 load_code;
  8302. /* if not going to reset MCP - load "fake" driver to reset HW while
  8303. * driver is owner of the HW
  8304. */
  8305. if (!global && !BP_NOMCP(bp)) {
  8306. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8307. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8308. if (!load_code) {
  8309. BNX2X_ERR("MCP response failure, aborting\n");
  8310. rc = -EAGAIN;
  8311. goto exit_leader_reset;
  8312. }
  8313. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8314. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8315. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8316. rc = -EAGAIN;
  8317. goto exit_leader_reset2;
  8318. }
  8319. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8320. if (!load_code) {
  8321. BNX2X_ERR("MCP response failure, aborting\n");
  8322. rc = -EAGAIN;
  8323. goto exit_leader_reset2;
  8324. }
  8325. }
  8326. /* Try to recover after the failure */
  8327. if (bnx2x_process_kill(bp, global)) {
  8328. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8329. BP_PATH(bp));
  8330. rc = -EAGAIN;
  8331. goto exit_leader_reset2;
  8332. }
  8333. /*
  8334. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8335. * state.
  8336. */
  8337. bnx2x_set_reset_done(bp);
  8338. if (global)
  8339. bnx2x_clear_reset_global(bp);
  8340. exit_leader_reset2:
  8341. /* unload "fake driver" if it was loaded */
  8342. if (!global && !BP_NOMCP(bp)) {
  8343. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8344. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8345. }
  8346. exit_leader_reset:
  8347. bp->is_leader = 0;
  8348. bnx2x_release_leader_lock(bp);
  8349. smp_mb();
  8350. return rc;
  8351. }
  8352. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8353. {
  8354. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8355. /* Disconnect this device */
  8356. netif_device_detach(bp->dev);
  8357. /*
  8358. * Block ifup for all function on this engine until "process kill"
  8359. * or power cycle.
  8360. */
  8361. bnx2x_set_reset_in_progress(bp);
  8362. /* Shut down the power */
  8363. bnx2x_set_power_state(bp, PCI_D3hot);
  8364. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8365. smp_mb();
  8366. }
  8367. /*
  8368. * Assumption: runs under rtnl lock. This together with the fact
  8369. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8370. * will never be called when netif_running(bp->dev) is false.
  8371. */
  8372. static void bnx2x_parity_recover(struct bnx2x *bp)
  8373. {
  8374. u32 error_recovered, error_unrecovered;
  8375. bool is_parity, global = false;
  8376. #ifdef CONFIG_BNX2X_SRIOV
  8377. int vf_idx;
  8378. for (vf_idx = 0; vf_idx < bp->requested_nr_virtfn; vf_idx++) {
  8379. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  8380. if (vf)
  8381. vf->state = VF_LOST;
  8382. }
  8383. #endif
  8384. DP(NETIF_MSG_HW, "Handling parity\n");
  8385. while (1) {
  8386. switch (bp->recovery_state) {
  8387. case BNX2X_RECOVERY_INIT:
  8388. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8389. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8390. WARN_ON(!is_parity);
  8391. /* Try to get a LEADER_LOCK HW lock */
  8392. if (bnx2x_trylock_leader_lock(bp)) {
  8393. bnx2x_set_reset_in_progress(bp);
  8394. /*
  8395. * Check if there is a global attention and if
  8396. * there was a global attention, set the global
  8397. * reset bit.
  8398. */
  8399. if (global)
  8400. bnx2x_set_reset_global(bp);
  8401. bp->is_leader = 1;
  8402. }
  8403. /* Stop the driver */
  8404. /* If interface has been removed - break */
  8405. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8406. return;
  8407. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8408. /* Ensure "is_leader", MCP command sequence and
  8409. * "recovery_state" update values are seen on other
  8410. * CPUs.
  8411. */
  8412. smp_mb();
  8413. break;
  8414. case BNX2X_RECOVERY_WAIT:
  8415. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8416. if (bp->is_leader) {
  8417. int other_engine = BP_PATH(bp) ? 0 : 1;
  8418. bool other_load_status =
  8419. bnx2x_get_load_status(bp, other_engine);
  8420. bool load_status =
  8421. bnx2x_get_load_status(bp, BP_PATH(bp));
  8422. global = bnx2x_reset_is_global(bp);
  8423. /*
  8424. * In case of a parity in a global block, let
  8425. * the first leader that performs a
  8426. * leader_reset() reset the global blocks in
  8427. * order to clear global attentions. Otherwise
  8428. * the gates will remain closed for that
  8429. * engine.
  8430. */
  8431. if (load_status ||
  8432. (global && other_load_status)) {
  8433. /* Wait until all other functions get
  8434. * down.
  8435. */
  8436. schedule_delayed_work(&bp->sp_rtnl_task,
  8437. HZ/10);
  8438. return;
  8439. } else {
  8440. /* If all other functions got down -
  8441. * try to bring the chip back to
  8442. * normal. In any case it's an exit
  8443. * point for a leader.
  8444. */
  8445. if (bnx2x_leader_reset(bp)) {
  8446. bnx2x_recovery_failed(bp);
  8447. return;
  8448. }
  8449. /* If we are here, means that the
  8450. * leader has succeeded and doesn't
  8451. * want to be a leader any more. Try
  8452. * to continue as a none-leader.
  8453. */
  8454. break;
  8455. }
  8456. } else { /* non-leader */
  8457. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8458. /* Try to get a LEADER_LOCK HW lock as
  8459. * long as a former leader may have
  8460. * been unloaded by the user or
  8461. * released a leadership by another
  8462. * reason.
  8463. */
  8464. if (bnx2x_trylock_leader_lock(bp)) {
  8465. /* I'm a leader now! Restart a
  8466. * switch case.
  8467. */
  8468. bp->is_leader = 1;
  8469. break;
  8470. }
  8471. schedule_delayed_work(&bp->sp_rtnl_task,
  8472. HZ/10);
  8473. return;
  8474. } else {
  8475. /*
  8476. * If there was a global attention, wait
  8477. * for it to be cleared.
  8478. */
  8479. if (bnx2x_reset_is_global(bp)) {
  8480. schedule_delayed_work(
  8481. &bp->sp_rtnl_task,
  8482. HZ/10);
  8483. return;
  8484. }
  8485. error_recovered =
  8486. bp->eth_stats.recoverable_error;
  8487. error_unrecovered =
  8488. bp->eth_stats.unrecoverable_error;
  8489. bp->recovery_state =
  8490. BNX2X_RECOVERY_NIC_LOADING;
  8491. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8492. error_unrecovered++;
  8493. netdev_err(bp->dev,
  8494. "Recovery failed. Power cycle needed\n");
  8495. /* Disconnect this device */
  8496. netif_device_detach(bp->dev);
  8497. /* Shut down the power */
  8498. bnx2x_set_power_state(
  8499. bp, PCI_D3hot);
  8500. smp_mb();
  8501. } else {
  8502. bp->recovery_state =
  8503. BNX2X_RECOVERY_DONE;
  8504. error_recovered++;
  8505. smp_mb();
  8506. }
  8507. bp->eth_stats.recoverable_error =
  8508. error_recovered;
  8509. bp->eth_stats.unrecoverable_error =
  8510. error_unrecovered;
  8511. return;
  8512. }
  8513. }
  8514. default:
  8515. return;
  8516. }
  8517. }
  8518. }
  8519. static int bnx2x_udp_port_update(struct bnx2x *bp)
  8520. {
  8521. struct bnx2x_func_switch_update_params *switch_update_params;
  8522. struct bnx2x_func_state_params func_params = {NULL};
  8523. struct bnx2x_udp_tunnel *udp_tunnel;
  8524. u16 vxlan_port = 0, geneve_port = 0;
  8525. int rc;
  8526. switch_update_params = &func_params.params.switch_update;
  8527. /* Prepare parameters for function state transitions */
  8528. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  8529. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  8530. func_params.f_obj = &bp->func_obj;
  8531. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  8532. /* Function parameters */
  8533. __set_bit(BNX2X_F_UPDATE_TUNNEL_CFG_CHNG,
  8534. &switch_update_params->changes);
  8535. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count) {
  8536. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE];
  8537. geneve_port = udp_tunnel->dst_port;
  8538. switch_update_params->geneve_dst_port = geneve_port;
  8539. }
  8540. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count) {
  8541. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN];
  8542. vxlan_port = udp_tunnel->dst_port;
  8543. switch_update_params->vxlan_dst_port = vxlan_port;
  8544. }
  8545. /* Re-enable inner-rss for the offloaded UDP tunnels */
  8546. __set_bit(BNX2X_F_UPDATE_TUNNEL_INNER_RSS,
  8547. &switch_update_params->changes);
  8548. rc = bnx2x_func_state_change(bp, &func_params);
  8549. if (rc)
  8550. BNX2X_ERR("failed to set UDP dst port to %04x %04x (rc = 0x%x)\n",
  8551. vxlan_port, geneve_port, rc);
  8552. else
  8553. DP(BNX2X_MSG_SP,
  8554. "Configured UDP ports: Vxlan [%04x] Geneve [%04x]\n",
  8555. vxlan_port, geneve_port);
  8556. return rc;
  8557. }
  8558. static void __bnx2x_add_udp_port(struct bnx2x *bp, u16 port,
  8559. enum bnx2x_udp_port_type type)
  8560. {
  8561. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8562. if (!netif_running(bp->dev) || !IS_PF(bp) || CHIP_IS_E1x(bp))
  8563. return;
  8564. if (udp_port->count && udp_port->dst_port == port) {
  8565. udp_port->count++;
  8566. return;
  8567. }
  8568. if (udp_port->count) {
  8569. DP(BNX2X_MSG_SP,
  8570. "UDP tunnel [%d] - destination port limit reached\n",
  8571. type);
  8572. return;
  8573. }
  8574. udp_port->dst_port = port;
  8575. udp_port->count = 1;
  8576. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8577. }
  8578. static void __bnx2x_del_udp_port(struct bnx2x *bp, u16 port,
  8579. enum bnx2x_udp_port_type type)
  8580. {
  8581. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8582. if (!IS_PF(bp) || CHIP_IS_E1x(bp))
  8583. return;
  8584. if (!udp_port->count || udp_port->dst_port != port) {
  8585. DP(BNX2X_MSG_SP, "Invalid UDP tunnel [%d] port\n",
  8586. type);
  8587. return;
  8588. }
  8589. /* Remove reference, and make certain it's no longer in use */
  8590. udp_port->count--;
  8591. if (udp_port->count)
  8592. return;
  8593. udp_port->dst_port = 0;
  8594. if (netif_running(bp->dev))
  8595. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8596. else
  8597. DP(BNX2X_MSG_SP, "Deleted UDP tunnel [%d] port %d\n",
  8598. type, port);
  8599. }
  8600. static void bnx2x_udp_tunnel_add(struct net_device *netdev,
  8601. struct udp_tunnel_info *ti)
  8602. {
  8603. struct bnx2x *bp = netdev_priv(netdev);
  8604. u16 t_port = ntohs(ti->port);
  8605. switch (ti->type) {
  8606. case UDP_TUNNEL_TYPE_VXLAN:
  8607. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8608. break;
  8609. case UDP_TUNNEL_TYPE_GENEVE:
  8610. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8611. break;
  8612. default:
  8613. break;
  8614. }
  8615. }
  8616. static void bnx2x_udp_tunnel_del(struct net_device *netdev,
  8617. struct udp_tunnel_info *ti)
  8618. {
  8619. struct bnx2x *bp = netdev_priv(netdev);
  8620. u16 t_port = ntohs(ti->port);
  8621. switch (ti->type) {
  8622. case UDP_TUNNEL_TYPE_VXLAN:
  8623. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8624. break;
  8625. case UDP_TUNNEL_TYPE_GENEVE:
  8626. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8627. break;
  8628. default:
  8629. break;
  8630. }
  8631. }
  8632. static int bnx2x_close(struct net_device *dev);
  8633. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8634. * scheduled on a general queue in order to prevent a dead lock.
  8635. */
  8636. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8637. {
  8638. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8639. rtnl_lock();
  8640. if (!netif_running(bp->dev)) {
  8641. rtnl_unlock();
  8642. return;
  8643. }
  8644. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8645. #ifdef BNX2X_STOP_ON_ERROR
  8646. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8647. "you will need to reboot when done\n");
  8648. goto sp_rtnl_not_reset;
  8649. #endif
  8650. /*
  8651. * Clear all pending SP commands as we are going to reset the
  8652. * function anyway.
  8653. */
  8654. bp->sp_rtnl_state = 0;
  8655. smp_mb();
  8656. bnx2x_parity_recover(bp);
  8657. rtnl_unlock();
  8658. return;
  8659. }
  8660. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8661. #ifdef BNX2X_STOP_ON_ERROR
  8662. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8663. "you will need to reboot when done\n");
  8664. goto sp_rtnl_not_reset;
  8665. #endif
  8666. /*
  8667. * Clear all pending SP commands as we are going to reset the
  8668. * function anyway.
  8669. */
  8670. bp->sp_rtnl_state = 0;
  8671. smp_mb();
  8672. /* Immediately indicate link as down */
  8673. bp->link_vars.link_up = 0;
  8674. bp->force_link_down = true;
  8675. netif_carrier_off(bp->dev);
  8676. BNX2X_ERR("Indicating link is down due to Tx-timeout\n");
  8677. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8678. /* When ret value shows failure of allocation failure,
  8679. * the nic is rebooted again. If open still fails, a error
  8680. * message to notify the user.
  8681. */
  8682. if (bnx2x_nic_load(bp, LOAD_NORMAL) == -ENOMEM) {
  8683. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8684. if (bnx2x_nic_load(bp, LOAD_NORMAL))
  8685. BNX2X_ERR("Open the NIC fails again!\n");
  8686. }
  8687. rtnl_unlock();
  8688. return;
  8689. }
  8690. #ifdef BNX2X_STOP_ON_ERROR
  8691. sp_rtnl_not_reset:
  8692. #endif
  8693. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8694. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8695. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8696. bnx2x_after_function_update(bp);
  8697. /*
  8698. * in case of fan failure we need to reset id if the "stop on error"
  8699. * debug flag is set, since we trying to prevent permanent overheating
  8700. * damage
  8701. */
  8702. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8703. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8704. netif_device_detach(bp->dev);
  8705. bnx2x_close(bp->dev);
  8706. rtnl_unlock();
  8707. return;
  8708. }
  8709. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8710. DP(BNX2X_MSG_SP,
  8711. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8712. bnx2x_vfpf_set_mcast(bp->dev);
  8713. }
  8714. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8715. &bp->sp_rtnl_state)){
  8716. if (netif_carrier_ok(bp->dev)) {
  8717. bnx2x_tx_disable(bp);
  8718. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8719. }
  8720. }
  8721. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8722. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8723. bnx2x_set_rx_mode_inner(bp);
  8724. }
  8725. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8726. &bp->sp_rtnl_state))
  8727. bnx2x_pf_set_vfs_vlan(bp);
  8728. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8729. bnx2x_dcbx_stop_hw_tx(bp);
  8730. bnx2x_dcbx_resume_hw_tx(bp);
  8731. }
  8732. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8733. &bp->sp_rtnl_state))
  8734. bnx2x_update_mng_version(bp);
  8735. if (test_and_clear_bit(BNX2X_SP_RTNL_UPDATE_SVID, &bp->sp_rtnl_state))
  8736. bnx2x_handle_update_svid_cmd(bp);
  8737. if (test_and_clear_bit(BNX2X_SP_RTNL_CHANGE_UDP_PORT,
  8738. &bp->sp_rtnl_state)) {
  8739. if (bnx2x_udp_port_update(bp)) {
  8740. /* On error, forget configuration */
  8741. memset(bp->udp_tunnel_ports, 0,
  8742. sizeof(struct bnx2x_udp_tunnel) *
  8743. BNX2X_UDP_PORT_MAX);
  8744. } else {
  8745. /* Since we don't store additional port information,
  8746. * if no ports are configured for any feature ask for
  8747. * information about currently configured ports.
  8748. */
  8749. if (!bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count &&
  8750. !bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count)
  8751. udp_tunnel_get_rx_info(bp->dev);
  8752. }
  8753. }
  8754. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8755. * can be called from other contexts as well)
  8756. */
  8757. rtnl_unlock();
  8758. /* enable SR-IOV if applicable */
  8759. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8760. &bp->sp_rtnl_state)) {
  8761. bnx2x_disable_sriov(bp);
  8762. bnx2x_enable_sriov(bp);
  8763. }
  8764. }
  8765. static void bnx2x_period_task(struct work_struct *work)
  8766. {
  8767. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8768. if (!netif_running(bp->dev))
  8769. goto period_task_exit;
  8770. if (CHIP_REV_IS_SLOW(bp)) {
  8771. BNX2X_ERR("period task called on emulation, ignoring\n");
  8772. goto period_task_exit;
  8773. }
  8774. bnx2x_acquire_phy_lock(bp);
  8775. /*
  8776. * The barrier is needed to ensure the ordering between the writing to
  8777. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8778. * the reading here.
  8779. */
  8780. smp_mb();
  8781. if (bp->port.pmf) {
  8782. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8783. /* Re-queue task in 1 sec */
  8784. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8785. }
  8786. bnx2x_release_phy_lock(bp);
  8787. period_task_exit:
  8788. return;
  8789. }
  8790. /*
  8791. * Init service functions
  8792. */
  8793. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8794. {
  8795. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8796. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8797. return base + (BP_ABS_FUNC(bp)) * stride;
  8798. }
  8799. static bool bnx2x_prev_unload_close_umac(struct bnx2x *bp,
  8800. u8 port, u32 reset_reg,
  8801. struct bnx2x_mac_vals *vals)
  8802. {
  8803. u32 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8804. u32 base_addr;
  8805. if (!(mask & reset_reg))
  8806. return false;
  8807. BNX2X_DEV_INFO("Disable umac Rx %02x\n", port);
  8808. base_addr = port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8809. vals->umac_addr[port] = base_addr + UMAC_REG_COMMAND_CONFIG;
  8810. vals->umac_val[port] = REG_RD(bp, vals->umac_addr[port]);
  8811. REG_WR(bp, vals->umac_addr[port], 0);
  8812. return true;
  8813. }
  8814. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8815. struct bnx2x_mac_vals *vals)
  8816. {
  8817. u32 val, base_addr, offset, mask, reset_reg;
  8818. bool mac_stopped = false;
  8819. u8 port = BP_PORT(bp);
  8820. /* reset addresses as they also mark which values were changed */
  8821. memset(vals, 0, sizeof(*vals));
  8822. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8823. if (!CHIP_IS_E3(bp)) {
  8824. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8825. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8826. if ((mask & reset_reg) && val) {
  8827. u32 wb_data[2];
  8828. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8829. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8830. : NIG_REG_INGRESS_BMAC0_MEM;
  8831. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8832. : BIGMAC_REGISTER_BMAC_CONTROL;
  8833. /*
  8834. * use rd/wr since we cannot use dmae. This is safe
  8835. * since MCP won't access the bus due to the request
  8836. * to unload, and no function on the path can be
  8837. * loaded at this time.
  8838. */
  8839. wb_data[0] = REG_RD(bp, base_addr + offset);
  8840. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8841. vals->bmac_addr = base_addr + offset;
  8842. vals->bmac_val[0] = wb_data[0];
  8843. vals->bmac_val[1] = wb_data[1];
  8844. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8845. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8846. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8847. }
  8848. BNX2X_DEV_INFO("Disable emac Rx\n");
  8849. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8850. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8851. REG_WR(bp, vals->emac_addr, 0);
  8852. mac_stopped = true;
  8853. } else {
  8854. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8855. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8856. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8857. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8858. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8859. val & ~(1 << 1));
  8860. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8861. val | (1 << 1));
  8862. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8863. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8864. REG_WR(bp, vals->xmac_addr, 0);
  8865. mac_stopped = true;
  8866. }
  8867. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 0,
  8868. reset_reg, vals);
  8869. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 1,
  8870. reset_reg, vals);
  8871. }
  8872. if (mac_stopped)
  8873. msleep(20);
  8874. }
  8875. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8876. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8877. 0x1848 + ((f) << 4))
  8878. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8879. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8880. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8881. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8882. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8883. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8884. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8885. {
  8886. /* UNDI marks its presence in DORQ -
  8887. * it initializes CID offset for normal bell to 0x7
  8888. */
  8889. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8890. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8891. return false;
  8892. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8893. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8894. return true;
  8895. }
  8896. return false;
  8897. }
  8898. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8899. {
  8900. u16 rcq, bd;
  8901. u32 addr, tmp_reg;
  8902. if (BP_FUNC(bp) < 2)
  8903. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8904. else
  8905. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8906. tmp_reg = REG_RD(bp, addr);
  8907. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8908. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8909. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8910. REG_WR(bp, addr, tmp_reg);
  8911. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8912. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8913. }
  8914. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8915. {
  8916. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8917. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8918. if (!rc) {
  8919. BNX2X_ERR("MCP response failure, aborting\n");
  8920. return -EBUSY;
  8921. }
  8922. return 0;
  8923. }
  8924. static struct bnx2x_prev_path_list *
  8925. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8926. {
  8927. struct bnx2x_prev_path_list *tmp_list;
  8928. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8929. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8930. bp->pdev->bus->number == tmp_list->bus &&
  8931. BP_PATH(bp) == tmp_list->path)
  8932. return tmp_list;
  8933. return NULL;
  8934. }
  8935. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8936. {
  8937. struct bnx2x_prev_path_list *tmp_list;
  8938. int rc;
  8939. rc = down_interruptible(&bnx2x_prev_sem);
  8940. if (rc) {
  8941. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8942. return rc;
  8943. }
  8944. tmp_list = bnx2x_prev_path_get_entry(bp);
  8945. if (tmp_list) {
  8946. tmp_list->aer = 1;
  8947. rc = 0;
  8948. } else {
  8949. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8950. BP_PATH(bp));
  8951. }
  8952. up(&bnx2x_prev_sem);
  8953. return rc;
  8954. }
  8955. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8956. {
  8957. struct bnx2x_prev_path_list *tmp_list;
  8958. bool rc = false;
  8959. if (down_trylock(&bnx2x_prev_sem))
  8960. return false;
  8961. tmp_list = bnx2x_prev_path_get_entry(bp);
  8962. if (tmp_list) {
  8963. if (tmp_list->aer) {
  8964. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8965. BP_PATH(bp));
  8966. } else {
  8967. rc = true;
  8968. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8969. BP_PATH(bp));
  8970. }
  8971. }
  8972. up(&bnx2x_prev_sem);
  8973. return rc;
  8974. }
  8975. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8976. {
  8977. struct bnx2x_prev_path_list *entry;
  8978. bool val;
  8979. down(&bnx2x_prev_sem);
  8980. entry = bnx2x_prev_path_get_entry(bp);
  8981. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8982. up(&bnx2x_prev_sem);
  8983. return val;
  8984. }
  8985. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8986. {
  8987. struct bnx2x_prev_path_list *tmp_list;
  8988. int rc;
  8989. rc = down_interruptible(&bnx2x_prev_sem);
  8990. if (rc) {
  8991. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8992. return rc;
  8993. }
  8994. /* Check whether the entry for this path already exists */
  8995. tmp_list = bnx2x_prev_path_get_entry(bp);
  8996. if (tmp_list) {
  8997. if (!tmp_list->aer) {
  8998. BNX2X_ERR("Re-Marking the path.\n");
  8999. } else {
  9000. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  9001. BP_PATH(bp));
  9002. tmp_list->aer = 0;
  9003. }
  9004. up(&bnx2x_prev_sem);
  9005. return 0;
  9006. }
  9007. up(&bnx2x_prev_sem);
  9008. /* Create an entry for this path and add it */
  9009. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  9010. if (!tmp_list) {
  9011. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  9012. return -ENOMEM;
  9013. }
  9014. tmp_list->bus = bp->pdev->bus->number;
  9015. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  9016. tmp_list->path = BP_PATH(bp);
  9017. tmp_list->aer = 0;
  9018. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  9019. rc = down_interruptible(&bnx2x_prev_sem);
  9020. if (rc) {
  9021. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  9022. kfree(tmp_list);
  9023. } else {
  9024. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  9025. BP_PATH(bp));
  9026. list_add(&tmp_list->list, &bnx2x_prev_list);
  9027. up(&bnx2x_prev_sem);
  9028. }
  9029. return rc;
  9030. }
  9031. static int bnx2x_do_flr(struct bnx2x *bp)
  9032. {
  9033. struct pci_dev *dev = bp->pdev;
  9034. if (CHIP_IS_E1x(bp)) {
  9035. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  9036. return -EINVAL;
  9037. }
  9038. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  9039. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  9040. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  9041. bp->common.bc_ver);
  9042. return -EINVAL;
  9043. }
  9044. if (!pci_wait_for_pending_transaction(dev))
  9045. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  9046. BNX2X_DEV_INFO("Initiating FLR\n");
  9047. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  9048. return 0;
  9049. }
  9050. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  9051. {
  9052. int rc;
  9053. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  9054. /* Test if previous unload process was already finished for this path */
  9055. if (bnx2x_prev_is_path_marked(bp))
  9056. return bnx2x_prev_mcp_done(bp);
  9057. BNX2X_DEV_INFO("Path is unmarked\n");
  9058. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  9059. if (bnx2x_prev_is_after_undi(bp))
  9060. goto out;
  9061. /* If function has FLR capabilities, and existing FW version matches
  9062. * the one required, then FLR will be sufficient to clean any residue
  9063. * left by previous driver
  9064. */
  9065. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  9066. if (!rc) {
  9067. /* fw version is good */
  9068. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  9069. rc = bnx2x_do_flr(bp);
  9070. }
  9071. if (!rc) {
  9072. /* FLR was performed */
  9073. BNX2X_DEV_INFO("FLR successful\n");
  9074. return 0;
  9075. }
  9076. BNX2X_DEV_INFO("Could not FLR\n");
  9077. out:
  9078. /* Close the MCP request, return failure*/
  9079. rc = bnx2x_prev_mcp_done(bp);
  9080. if (!rc)
  9081. rc = BNX2X_PREV_WAIT_NEEDED;
  9082. return rc;
  9083. }
  9084. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  9085. {
  9086. u32 reset_reg, tmp_reg = 0, rc;
  9087. bool prev_undi = false;
  9088. struct bnx2x_mac_vals mac_vals;
  9089. /* It is possible a previous function received 'common' answer,
  9090. * but hasn't loaded yet, therefore creating a scenario of
  9091. * multiple functions receiving 'common' on the same path.
  9092. */
  9093. BNX2X_DEV_INFO("Common unload Flow\n");
  9094. memset(&mac_vals, 0, sizeof(mac_vals));
  9095. if (bnx2x_prev_is_path_marked(bp))
  9096. return bnx2x_prev_mcp_done(bp);
  9097. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  9098. /* Reset should be performed after BRB is emptied */
  9099. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  9100. u32 timer_count = 1000;
  9101. /* Close the MAC Rx to prevent BRB from filling up */
  9102. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  9103. /* close LLH filters for both ports towards the BRB */
  9104. bnx2x_set_rx_filter(&bp->link_params, 0);
  9105. bp->link_params.port ^= 1;
  9106. bnx2x_set_rx_filter(&bp->link_params, 0);
  9107. bp->link_params.port ^= 1;
  9108. /* Check if the UNDI driver was previously loaded */
  9109. if (bnx2x_prev_is_after_undi(bp)) {
  9110. prev_undi = true;
  9111. /* clear the UNDI indication */
  9112. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  9113. /* clear possible idle check errors */
  9114. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  9115. }
  9116. if (!CHIP_IS_E1x(bp))
  9117. /* block FW from writing to host */
  9118. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  9119. /* wait until BRB is empty */
  9120. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9121. while (timer_count) {
  9122. u32 prev_brb = tmp_reg;
  9123. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9124. if (!tmp_reg)
  9125. break;
  9126. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  9127. /* reset timer as long as BRB actually gets emptied */
  9128. if (prev_brb > tmp_reg)
  9129. timer_count = 1000;
  9130. else
  9131. timer_count--;
  9132. /* If UNDI resides in memory, manually increment it */
  9133. if (prev_undi)
  9134. bnx2x_prev_unload_undi_inc(bp, 1);
  9135. udelay(10);
  9136. }
  9137. if (!timer_count)
  9138. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  9139. }
  9140. /* No packets are in the pipeline, path is ready for reset */
  9141. bnx2x_reset_common(bp);
  9142. if (mac_vals.xmac_addr)
  9143. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  9144. if (mac_vals.umac_addr[0])
  9145. REG_WR(bp, mac_vals.umac_addr[0], mac_vals.umac_val[0]);
  9146. if (mac_vals.umac_addr[1])
  9147. REG_WR(bp, mac_vals.umac_addr[1], mac_vals.umac_val[1]);
  9148. if (mac_vals.emac_addr)
  9149. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  9150. if (mac_vals.bmac_addr) {
  9151. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  9152. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  9153. }
  9154. rc = bnx2x_prev_mark_path(bp, prev_undi);
  9155. if (rc) {
  9156. bnx2x_prev_mcp_done(bp);
  9157. return rc;
  9158. }
  9159. return bnx2x_prev_mcp_done(bp);
  9160. }
  9161. static int bnx2x_prev_unload(struct bnx2x *bp)
  9162. {
  9163. int time_counter = 10;
  9164. u32 rc, fw, hw_lock_reg, hw_lock_val;
  9165. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  9166. /* clear hw from errors which may have resulted from an interrupted
  9167. * dmae transaction.
  9168. */
  9169. bnx2x_clean_pglue_errors(bp);
  9170. /* Release previously held locks */
  9171. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  9172. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  9173. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  9174. hw_lock_val = REG_RD(bp, hw_lock_reg);
  9175. if (hw_lock_val) {
  9176. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  9177. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  9178. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  9179. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  9180. }
  9181. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  9182. REG_WR(bp, hw_lock_reg, 0xffffffff);
  9183. } else
  9184. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  9185. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  9186. BNX2X_DEV_INFO("Release previously held alr\n");
  9187. bnx2x_release_alr(bp);
  9188. }
  9189. do {
  9190. int aer = 0;
  9191. /* Lock MCP using an unload request */
  9192. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  9193. if (!fw) {
  9194. BNX2X_ERR("MCP response failure, aborting\n");
  9195. rc = -EBUSY;
  9196. break;
  9197. }
  9198. rc = down_interruptible(&bnx2x_prev_sem);
  9199. if (rc) {
  9200. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  9201. rc);
  9202. } else {
  9203. /* If Path is marked by EEH, ignore unload status */
  9204. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  9205. bnx2x_prev_path_get_entry(bp)->aer);
  9206. up(&bnx2x_prev_sem);
  9207. }
  9208. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  9209. rc = bnx2x_prev_unload_common(bp);
  9210. break;
  9211. }
  9212. /* non-common reply from MCP might require looping */
  9213. rc = bnx2x_prev_unload_uncommon(bp);
  9214. if (rc != BNX2X_PREV_WAIT_NEEDED)
  9215. break;
  9216. msleep(20);
  9217. } while (--time_counter);
  9218. if (!time_counter || rc) {
  9219. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  9220. rc = -EPROBE_DEFER;
  9221. }
  9222. /* Mark function if its port was used to boot from SAN */
  9223. if (bnx2x_port_after_undi(bp))
  9224. bp->link_params.feature_config_flags |=
  9225. FEATURE_CONFIG_BOOT_FROM_SAN;
  9226. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  9227. return rc;
  9228. }
  9229. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  9230. {
  9231. u32 val, val2, val3, val4, id, boot_mode;
  9232. u16 pmc;
  9233. /* Get the chip revision id and number. */
  9234. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  9235. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  9236. id = ((val & 0xffff) << 16);
  9237. val = REG_RD(bp, MISC_REG_CHIP_REV);
  9238. id |= ((val & 0xf) << 12);
  9239. /* Metal is read from PCI regs, but we can't access >=0x400 from
  9240. * the configuration space (so we need to reg_rd)
  9241. */
  9242. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  9243. id |= (((val >> 24) & 0xf) << 4);
  9244. val = REG_RD(bp, MISC_REG_BOND_ID);
  9245. id |= (val & 0xf);
  9246. bp->common.chip_id = id;
  9247. /* force 57811 according to MISC register */
  9248. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  9249. if (CHIP_IS_57810(bp))
  9250. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  9251. (bp->common.chip_id & 0x0000FFFF);
  9252. else if (CHIP_IS_57810_MF(bp))
  9253. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  9254. (bp->common.chip_id & 0x0000FFFF);
  9255. bp->common.chip_id |= 0x1;
  9256. }
  9257. /* Set doorbell size */
  9258. bp->db_size = (1 << BNX2X_DB_SHIFT);
  9259. if (!CHIP_IS_E1x(bp)) {
  9260. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  9261. if ((val & 1) == 0)
  9262. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  9263. else
  9264. val = (val >> 1) & 1;
  9265. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  9266. "2_PORT_MODE");
  9267. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  9268. CHIP_2_PORT_MODE;
  9269. if (CHIP_MODE_IS_4_PORT(bp))
  9270. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  9271. else
  9272. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  9273. } else {
  9274. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  9275. bp->pfid = bp->pf_num; /* 0..7 */
  9276. }
  9277. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  9278. bp->link_params.chip_id = bp->common.chip_id;
  9279. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  9280. val = (REG_RD(bp, 0x2874) & 0x55);
  9281. if ((bp->common.chip_id & 0x1) ||
  9282. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  9283. bp->flags |= ONE_PORT_FLAG;
  9284. BNX2X_DEV_INFO("single port device\n");
  9285. }
  9286. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9287. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9288. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9289. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9290. bp->common.flash_size, bp->common.flash_size);
  9291. bnx2x_init_shmem(bp);
  9292. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9293. MISC_REG_GENERIC_CR_1 :
  9294. MISC_REG_GENERIC_CR_0));
  9295. bp->link_params.shmem_base = bp->common.shmem_base;
  9296. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9297. if (SHMEM2_RD(bp, size) >
  9298. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9299. bp->link_params.lfa_base =
  9300. REG_RD(bp, bp->common.shmem2_base +
  9301. (u32)offsetof(struct shmem2_region,
  9302. lfa_host_addr[BP_PORT(bp)]));
  9303. else
  9304. bp->link_params.lfa_base = 0;
  9305. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9306. bp->common.shmem_base, bp->common.shmem2_base);
  9307. if (!bp->common.shmem_base) {
  9308. BNX2X_DEV_INFO("MCP not active\n");
  9309. bp->flags |= NO_MCP_FLAG;
  9310. return;
  9311. }
  9312. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9313. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9314. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9315. SHARED_HW_CFG_LED_MODE_MASK) >>
  9316. SHARED_HW_CFG_LED_MODE_SHIFT);
  9317. bp->link_params.feature_config_flags = 0;
  9318. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9319. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9320. bp->link_params.feature_config_flags |=
  9321. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9322. else
  9323. bp->link_params.feature_config_flags &=
  9324. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9325. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9326. bp->common.bc_ver = val;
  9327. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9328. if (val < BNX2X_BC_VER) {
  9329. /* for now only warn
  9330. * later we might need to enforce this */
  9331. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9332. BNX2X_BC_VER, val);
  9333. }
  9334. bp->link_params.feature_config_flags |=
  9335. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9336. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9337. bp->link_params.feature_config_flags |=
  9338. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9339. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9340. bp->link_params.feature_config_flags |=
  9341. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9342. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9343. bp->link_params.feature_config_flags |=
  9344. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9345. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9346. bp->link_params.feature_config_flags |=
  9347. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9348. FEATURE_CONFIG_MT_SUPPORT : 0;
  9349. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9350. BC_SUPPORTS_PFC_STATS : 0;
  9351. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9352. BC_SUPPORTS_FCOE_FEATURES : 0;
  9353. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9354. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9355. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9356. BC_SUPPORTS_RMMOD_CMD : 0;
  9357. boot_mode = SHMEM_RD(bp,
  9358. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9359. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9360. switch (boot_mode) {
  9361. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9362. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9363. break;
  9364. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9365. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9366. break;
  9367. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9368. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9369. break;
  9370. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9371. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9372. break;
  9373. }
  9374. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9375. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9376. BNX2X_DEV_INFO("%sWoL capable\n",
  9377. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9378. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9379. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9380. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9381. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9382. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9383. val, val2, val3, val4);
  9384. }
  9385. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9386. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9387. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9388. {
  9389. int pfid = BP_FUNC(bp);
  9390. int igu_sb_id;
  9391. u32 val;
  9392. u8 fid, igu_sb_cnt = 0;
  9393. bp->igu_base_sb = 0xff;
  9394. if (CHIP_INT_MODE_IS_BC(bp)) {
  9395. int vn = BP_VN(bp);
  9396. igu_sb_cnt = bp->igu_sb_cnt;
  9397. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9398. FP_SB_MAX_E1x;
  9399. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9400. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9401. return 0;
  9402. }
  9403. /* IGU in normal mode - read CAM */
  9404. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9405. igu_sb_id++) {
  9406. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9407. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9408. continue;
  9409. fid = IGU_FID(val);
  9410. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9411. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9412. continue;
  9413. if (IGU_VEC(val) == 0)
  9414. /* default status block */
  9415. bp->igu_dsb_id = igu_sb_id;
  9416. else {
  9417. if (bp->igu_base_sb == 0xff)
  9418. bp->igu_base_sb = igu_sb_id;
  9419. igu_sb_cnt++;
  9420. }
  9421. }
  9422. }
  9423. #ifdef CONFIG_PCI_MSI
  9424. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9425. * optional that number of CAM entries will not be equal to the value
  9426. * advertised in PCI.
  9427. * Driver should use the minimal value of both as the actual status
  9428. * block count
  9429. */
  9430. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9431. #endif
  9432. if (igu_sb_cnt == 0) {
  9433. BNX2X_ERR("CAM configuration error\n");
  9434. return -EINVAL;
  9435. }
  9436. return 0;
  9437. }
  9438. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9439. {
  9440. int cfg_size = 0, idx, port = BP_PORT(bp);
  9441. /* Aggregation of supported attributes of all external phys */
  9442. bp->port.supported[0] = 0;
  9443. bp->port.supported[1] = 0;
  9444. switch (bp->link_params.num_phys) {
  9445. case 1:
  9446. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9447. cfg_size = 1;
  9448. break;
  9449. case 2:
  9450. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9451. cfg_size = 1;
  9452. break;
  9453. case 3:
  9454. if (bp->link_params.multi_phy_config &
  9455. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9456. bp->port.supported[1] =
  9457. bp->link_params.phy[EXT_PHY1].supported;
  9458. bp->port.supported[0] =
  9459. bp->link_params.phy[EXT_PHY2].supported;
  9460. } else {
  9461. bp->port.supported[0] =
  9462. bp->link_params.phy[EXT_PHY1].supported;
  9463. bp->port.supported[1] =
  9464. bp->link_params.phy[EXT_PHY2].supported;
  9465. }
  9466. cfg_size = 2;
  9467. break;
  9468. }
  9469. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9470. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9471. SHMEM_RD(bp,
  9472. dev_info.port_hw_config[port].external_phy_config),
  9473. SHMEM_RD(bp,
  9474. dev_info.port_hw_config[port].external_phy_config2));
  9475. return;
  9476. }
  9477. if (CHIP_IS_E3(bp))
  9478. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9479. else {
  9480. switch (switch_cfg) {
  9481. case SWITCH_CFG_1G:
  9482. bp->port.phy_addr = REG_RD(
  9483. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9484. break;
  9485. case SWITCH_CFG_10G:
  9486. bp->port.phy_addr = REG_RD(
  9487. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9488. break;
  9489. default:
  9490. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9491. bp->port.link_config[0]);
  9492. return;
  9493. }
  9494. }
  9495. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9496. /* mask what we support according to speed_cap_mask per configuration */
  9497. for (idx = 0; idx < cfg_size; idx++) {
  9498. if (!(bp->link_params.speed_cap_mask[idx] &
  9499. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9500. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9501. if (!(bp->link_params.speed_cap_mask[idx] &
  9502. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9503. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9504. if (!(bp->link_params.speed_cap_mask[idx] &
  9505. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9506. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9507. if (!(bp->link_params.speed_cap_mask[idx] &
  9508. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9509. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9510. if (!(bp->link_params.speed_cap_mask[idx] &
  9511. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9512. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9513. SUPPORTED_1000baseT_Full);
  9514. if (!(bp->link_params.speed_cap_mask[idx] &
  9515. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9516. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9517. if (!(bp->link_params.speed_cap_mask[idx] &
  9518. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9519. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9520. if (!(bp->link_params.speed_cap_mask[idx] &
  9521. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9522. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9523. }
  9524. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9525. bp->port.supported[1]);
  9526. }
  9527. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9528. {
  9529. u32 link_config, idx, cfg_size = 0;
  9530. bp->port.advertising[0] = 0;
  9531. bp->port.advertising[1] = 0;
  9532. switch (bp->link_params.num_phys) {
  9533. case 1:
  9534. case 2:
  9535. cfg_size = 1;
  9536. break;
  9537. case 3:
  9538. cfg_size = 2;
  9539. break;
  9540. }
  9541. for (idx = 0; idx < cfg_size; idx++) {
  9542. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9543. link_config = bp->port.link_config[idx];
  9544. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9545. case PORT_FEATURE_LINK_SPEED_AUTO:
  9546. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9547. bp->link_params.req_line_speed[idx] =
  9548. SPEED_AUTO_NEG;
  9549. bp->port.advertising[idx] |=
  9550. bp->port.supported[idx];
  9551. if (bp->link_params.phy[EXT_PHY1].type ==
  9552. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9553. bp->port.advertising[idx] |=
  9554. (SUPPORTED_100baseT_Half |
  9555. SUPPORTED_100baseT_Full);
  9556. } else {
  9557. /* force 10G, no AN */
  9558. bp->link_params.req_line_speed[idx] =
  9559. SPEED_10000;
  9560. bp->port.advertising[idx] |=
  9561. (ADVERTISED_10000baseT_Full |
  9562. ADVERTISED_FIBRE);
  9563. continue;
  9564. }
  9565. break;
  9566. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9567. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9568. bp->link_params.req_line_speed[idx] =
  9569. SPEED_10;
  9570. bp->port.advertising[idx] |=
  9571. (ADVERTISED_10baseT_Full |
  9572. ADVERTISED_TP);
  9573. } else {
  9574. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9575. link_config,
  9576. bp->link_params.speed_cap_mask[idx]);
  9577. return;
  9578. }
  9579. break;
  9580. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9581. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9582. bp->link_params.req_line_speed[idx] =
  9583. SPEED_10;
  9584. bp->link_params.req_duplex[idx] =
  9585. DUPLEX_HALF;
  9586. bp->port.advertising[idx] |=
  9587. (ADVERTISED_10baseT_Half |
  9588. ADVERTISED_TP);
  9589. } else {
  9590. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9591. link_config,
  9592. bp->link_params.speed_cap_mask[idx]);
  9593. return;
  9594. }
  9595. break;
  9596. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9597. if (bp->port.supported[idx] &
  9598. SUPPORTED_100baseT_Full) {
  9599. bp->link_params.req_line_speed[idx] =
  9600. SPEED_100;
  9601. bp->port.advertising[idx] |=
  9602. (ADVERTISED_100baseT_Full |
  9603. ADVERTISED_TP);
  9604. } else {
  9605. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9606. link_config,
  9607. bp->link_params.speed_cap_mask[idx]);
  9608. return;
  9609. }
  9610. break;
  9611. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9612. if (bp->port.supported[idx] &
  9613. SUPPORTED_100baseT_Half) {
  9614. bp->link_params.req_line_speed[idx] =
  9615. SPEED_100;
  9616. bp->link_params.req_duplex[idx] =
  9617. DUPLEX_HALF;
  9618. bp->port.advertising[idx] |=
  9619. (ADVERTISED_100baseT_Half |
  9620. ADVERTISED_TP);
  9621. } else {
  9622. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9623. link_config,
  9624. bp->link_params.speed_cap_mask[idx]);
  9625. return;
  9626. }
  9627. break;
  9628. case PORT_FEATURE_LINK_SPEED_1G:
  9629. if (bp->port.supported[idx] &
  9630. SUPPORTED_1000baseT_Full) {
  9631. bp->link_params.req_line_speed[idx] =
  9632. SPEED_1000;
  9633. bp->port.advertising[idx] |=
  9634. (ADVERTISED_1000baseT_Full |
  9635. ADVERTISED_TP);
  9636. } else if (bp->port.supported[idx] &
  9637. SUPPORTED_1000baseKX_Full) {
  9638. bp->link_params.req_line_speed[idx] =
  9639. SPEED_1000;
  9640. bp->port.advertising[idx] |=
  9641. ADVERTISED_1000baseKX_Full;
  9642. } else {
  9643. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9644. link_config,
  9645. bp->link_params.speed_cap_mask[idx]);
  9646. return;
  9647. }
  9648. break;
  9649. case PORT_FEATURE_LINK_SPEED_2_5G:
  9650. if (bp->port.supported[idx] &
  9651. SUPPORTED_2500baseX_Full) {
  9652. bp->link_params.req_line_speed[idx] =
  9653. SPEED_2500;
  9654. bp->port.advertising[idx] |=
  9655. (ADVERTISED_2500baseX_Full |
  9656. ADVERTISED_TP);
  9657. } else {
  9658. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9659. link_config,
  9660. bp->link_params.speed_cap_mask[idx]);
  9661. return;
  9662. }
  9663. break;
  9664. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9665. if (bp->port.supported[idx] &
  9666. SUPPORTED_10000baseT_Full) {
  9667. bp->link_params.req_line_speed[idx] =
  9668. SPEED_10000;
  9669. bp->port.advertising[idx] |=
  9670. (ADVERTISED_10000baseT_Full |
  9671. ADVERTISED_FIBRE);
  9672. } else if (bp->port.supported[idx] &
  9673. SUPPORTED_10000baseKR_Full) {
  9674. bp->link_params.req_line_speed[idx] =
  9675. SPEED_10000;
  9676. bp->port.advertising[idx] |=
  9677. (ADVERTISED_10000baseKR_Full |
  9678. ADVERTISED_FIBRE);
  9679. } else {
  9680. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9681. link_config,
  9682. bp->link_params.speed_cap_mask[idx]);
  9683. return;
  9684. }
  9685. break;
  9686. case PORT_FEATURE_LINK_SPEED_20G:
  9687. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9688. break;
  9689. default:
  9690. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9691. link_config);
  9692. bp->link_params.req_line_speed[idx] =
  9693. SPEED_AUTO_NEG;
  9694. bp->port.advertising[idx] =
  9695. bp->port.supported[idx];
  9696. break;
  9697. }
  9698. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9699. PORT_FEATURE_FLOW_CONTROL_MASK);
  9700. if (bp->link_params.req_flow_ctrl[idx] ==
  9701. BNX2X_FLOW_CTRL_AUTO) {
  9702. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9703. bp->link_params.req_flow_ctrl[idx] =
  9704. BNX2X_FLOW_CTRL_NONE;
  9705. else
  9706. bnx2x_set_requested_fc(bp);
  9707. }
  9708. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9709. bp->link_params.req_line_speed[idx],
  9710. bp->link_params.req_duplex[idx],
  9711. bp->link_params.req_flow_ctrl[idx],
  9712. bp->port.advertising[idx]);
  9713. }
  9714. }
  9715. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9716. {
  9717. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9718. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9719. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9720. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9721. }
  9722. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9723. {
  9724. int port = BP_PORT(bp);
  9725. u32 config;
  9726. u32 ext_phy_type, ext_phy_config, eee_mode;
  9727. bp->link_params.bp = bp;
  9728. bp->link_params.port = port;
  9729. bp->link_params.lane_config =
  9730. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9731. bp->link_params.speed_cap_mask[0] =
  9732. SHMEM_RD(bp,
  9733. dev_info.port_hw_config[port].speed_capability_mask) &
  9734. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9735. bp->link_params.speed_cap_mask[1] =
  9736. SHMEM_RD(bp,
  9737. dev_info.port_hw_config[port].speed_capability_mask2) &
  9738. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9739. bp->port.link_config[0] =
  9740. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9741. bp->port.link_config[1] =
  9742. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9743. bp->link_params.multi_phy_config =
  9744. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9745. /* If the device is capable of WoL, set the default state according
  9746. * to the HW
  9747. */
  9748. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9749. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9750. (config & PORT_FEATURE_WOL_ENABLED));
  9751. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9752. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9753. bp->flags |= NO_ISCSI_FLAG;
  9754. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9755. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9756. bp->flags |= NO_FCOE_FLAG;
  9757. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9758. bp->link_params.lane_config,
  9759. bp->link_params.speed_cap_mask[0],
  9760. bp->port.link_config[0]);
  9761. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9762. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9763. bnx2x_phy_probe(&bp->link_params);
  9764. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9765. bnx2x_link_settings_requested(bp);
  9766. /*
  9767. * If connected directly, work with the internal PHY, otherwise, work
  9768. * with the external PHY
  9769. */
  9770. ext_phy_config =
  9771. SHMEM_RD(bp,
  9772. dev_info.port_hw_config[port].external_phy_config);
  9773. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9774. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9775. bp->mdio.prtad = bp->port.phy_addr;
  9776. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9777. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9778. bp->mdio.prtad =
  9779. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9780. /* Configure link feature according to nvram value */
  9781. eee_mode = (((SHMEM_RD(bp, dev_info.
  9782. port_feature_config[port].eee_power_mode)) &
  9783. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9784. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9785. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9786. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9787. EEE_MODE_ENABLE_LPI |
  9788. EEE_MODE_OUTPUT_TIME;
  9789. } else {
  9790. bp->link_params.eee_mode = 0;
  9791. }
  9792. }
  9793. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9794. {
  9795. u32 no_flags = NO_ISCSI_FLAG;
  9796. int port = BP_PORT(bp);
  9797. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9798. drv_lic_key[port].max_iscsi_conn);
  9799. if (!CNIC_SUPPORT(bp)) {
  9800. bp->flags |= no_flags;
  9801. return;
  9802. }
  9803. /* Get the number of maximum allowed iSCSI connections */
  9804. bp->cnic_eth_dev.max_iscsi_conn =
  9805. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9806. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9807. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9808. bp->cnic_eth_dev.max_iscsi_conn);
  9809. /*
  9810. * If maximum allowed number of connections is zero -
  9811. * disable the feature.
  9812. */
  9813. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9814. bp->flags |= no_flags;
  9815. }
  9816. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9817. {
  9818. /* Port info */
  9819. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9820. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9821. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9822. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9823. /* Node info */
  9824. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9825. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9826. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9827. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9828. }
  9829. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9830. {
  9831. u8 count = 0;
  9832. if (IS_MF(bp)) {
  9833. u8 fid;
  9834. /* iterate over absolute function ids for this path: */
  9835. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9836. if (IS_MF_SD(bp)) {
  9837. u32 cfg = MF_CFG_RD(bp,
  9838. func_mf_config[fid].config);
  9839. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9840. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9841. FUNC_MF_CFG_PROTOCOL_FCOE))
  9842. count++;
  9843. } else {
  9844. u32 cfg = MF_CFG_RD(bp,
  9845. func_ext_config[fid].
  9846. func_cfg);
  9847. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9848. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9849. count++;
  9850. }
  9851. }
  9852. } else { /* SF */
  9853. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9854. for (port = 0; port < port_cnt; port++) {
  9855. u32 lic = SHMEM_RD(bp,
  9856. drv_lic_key[port].max_fcoe_conn) ^
  9857. FW_ENCODE_32BIT_PATTERN;
  9858. if (lic)
  9859. count++;
  9860. }
  9861. }
  9862. return count;
  9863. }
  9864. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9865. {
  9866. int port = BP_PORT(bp);
  9867. int func = BP_ABS_FUNC(bp);
  9868. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9869. drv_lic_key[port].max_fcoe_conn);
  9870. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9871. if (!CNIC_SUPPORT(bp)) {
  9872. bp->flags |= NO_FCOE_FLAG;
  9873. return;
  9874. }
  9875. /* Get the number of maximum allowed FCoE connections */
  9876. bp->cnic_eth_dev.max_fcoe_conn =
  9877. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9878. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9879. /* Calculate the number of maximum allowed FCoE tasks */
  9880. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9881. /* check if FCoE resources must be shared between different functions */
  9882. if (num_fcoe_func)
  9883. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9884. /* Read the WWN: */
  9885. if (!IS_MF(bp)) {
  9886. /* Port info */
  9887. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9888. SHMEM_RD(bp,
  9889. dev_info.port_hw_config[port].
  9890. fcoe_wwn_port_name_upper);
  9891. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9892. SHMEM_RD(bp,
  9893. dev_info.port_hw_config[port].
  9894. fcoe_wwn_port_name_lower);
  9895. /* Node info */
  9896. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9897. SHMEM_RD(bp,
  9898. dev_info.port_hw_config[port].
  9899. fcoe_wwn_node_name_upper);
  9900. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9901. SHMEM_RD(bp,
  9902. dev_info.port_hw_config[port].
  9903. fcoe_wwn_node_name_lower);
  9904. } else if (!IS_MF_SD(bp)) {
  9905. /* Read the WWN info only if the FCoE feature is enabled for
  9906. * this function.
  9907. */
  9908. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9909. bnx2x_get_ext_wwn_info(bp, func);
  9910. } else {
  9911. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9912. bnx2x_get_ext_wwn_info(bp, func);
  9913. }
  9914. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9915. /*
  9916. * If maximum allowed number of connections is zero -
  9917. * disable the feature.
  9918. */
  9919. if (!bp->cnic_eth_dev.max_fcoe_conn) {
  9920. bp->flags |= NO_FCOE_FLAG;
  9921. eth_zero_addr(bp->fip_mac);
  9922. }
  9923. }
  9924. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9925. {
  9926. /*
  9927. * iSCSI may be dynamically disabled but reading
  9928. * info here we will decrease memory usage by driver
  9929. * if the feature is disabled for good
  9930. */
  9931. bnx2x_get_iscsi_info(bp);
  9932. bnx2x_get_fcoe_info(bp);
  9933. }
  9934. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9935. {
  9936. u32 val, val2;
  9937. int func = BP_ABS_FUNC(bp);
  9938. int port = BP_PORT(bp);
  9939. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9940. u8 *fip_mac = bp->fip_mac;
  9941. if (IS_MF(bp)) {
  9942. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9943. * FCoE MAC then the appropriate feature should be disabled.
  9944. * In non SD mode features configuration comes from struct
  9945. * func_ext_config.
  9946. */
  9947. if (!IS_MF_SD(bp)) {
  9948. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9949. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9950. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9951. iscsi_mac_addr_upper);
  9952. val = MF_CFG_RD(bp, func_ext_config[func].
  9953. iscsi_mac_addr_lower);
  9954. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9955. BNX2X_DEV_INFO
  9956. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9957. } else {
  9958. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9959. }
  9960. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9961. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9962. fcoe_mac_addr_upper);
  9963. val = MF_CFG_RD(bp, func_ext_config[func].
  9964. fcoe_mac_addr_lower);
  9965. bnx2x_set_mac_buf(fip_mac, val, val2);
  9966. BNX2X_DEV_INFO
  9967. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9968. } else {
  9969. bp->flags |= NO_FCOE_FLAG;
  9970. }
  9971. bp->mf_ext_config = cfg;
  9972. } else { /* SD MODE */
  9973. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9974. /* use primary mac as iscsi mac */
  9975. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9976. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9977. BNX2X_DEV_INFO
  9978. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9979. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9980. /* use primary mac as fip mac */
  9981. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9982. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9983. BNX2X_DEV_INFO
  9984. ("Read FIP MAC: %pM\n", fip_mac);
  9985. }
  9986. }
  9987. /* If this is a storage-only interface, use SAN mac as
  9988. * primary MAC. Notice that for SD this is already the case,
  9989. * as the SAN mac was copied from the primary MAC.
  9990. */
  9991. if (IS_MF_FCOE_AFEX(bp))
  9992. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9993. } else {
  9994. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9995. iscsi_mac_upper);
  9996. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9997. iscsi_mac_lower);
  9998. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9999. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  10000. fcoe_fip_mac_upper);
  10001. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  10002. fcoe_fip_mac_lower);
  10003. bnx2x_set_mac_buf(fip_mac, val, val2);
  10004. }
  10005. /* Disable iSCSI OOO if MAC configuration is invalid. */
  10006. if (!is_valid_ether_addr(iscsi_mac)) {
  10007. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  10008. eth_zero_addr(iscsi_mac);
  10009. }
  10010. /* Disable FCoE if MAC configuration is invalid. */
  10011. if (!is_valid_ether_addr(fip_mac)) {
  10012. bp->flags |= NO_FCOE_FLAG;
  10013. eth_zero_addr(bp->fip_mac);
  10014. }
  10015. }
  10016. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  10017. {
  10018. u32 val, val2;
  10019. int func = BP_ABS_FUNC(bp);
  10020. int port = BP_PORT(bp);
  10021. /* Zero primary MAC configuration */
  10022. eth_zero_addr(bp->dev->dev_addr);
  10023. if (BP_NOMCP(bp)) {
  10024. BNX2X_ERROR("warning: random MAC workaround active\n");
  10025. eth_hw_addr_random(bp->dev);
  10026. } else if (IS_MF(bp)) {
  10027. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  10028. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  10029. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  10030. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  10031. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  10032. if (CNIC_SUPPORT(bp))
  10033. bnx2x_get_cnic_mac_hwinfo(bp);
  10034. } else {
  10035. /* in SF read MACs from port configuration */
  10036. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  10037. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  10038. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  10039. if (CNIC_SUPPORT(bp))
  10040. bnx2x_get_cnic_mac_hwinfo(bp);
  10041. }
  10042. if (!BP_NOMCP(bp)) {
  10043. /* Read physical port identifier from shmem */
  10044. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  10045. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  10046. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  10047. bp->flags |= HAS_PHYS_PORT_ID;
  10048. }
  10049. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  10050. if (!is_valid_ether_addr(bp->dev->dev_addr))
  10051. dev_err(&bp->pdev->dev,
  10052. "bad Ethernet MAC address configuration: %pM\n"
  10053. "change it manually before bringing up the appropriate network interface\n",
  10054. bp->dev->dev_addr);
  10055. }
  10056. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  10057. {
  10058. int tmp;
  10059. u32 cfg;
  10060. if (IS_VF(bp))
  10061. return false;
  10062. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  10063. /* Take function: tmp = func */
  10064. tmp = BP_ABS_FUNC(bp);
  10065. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  10066. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  10067. } else {
  10068. /* Take port: tmp = port */
  10069. tmp = BP_PORT(bp);
  10070. cfg = SHMEM_RD(bp,
  10071. dev_info.port_hw_config[tmp].generic_features);
  10072. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  10073. }
  10074. return cfg;
  10075. }
  10076. static void validate_set_si_mode(struct bnx2x *bp)
  10077. {
  10078. u8 func = BP_ABS_FUNC(bp);
  10079. u32 val;
  10080. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  10081. /* check for legal mac (upper bytes) */
  10082. if (val != 0xffff) {
  10083. bp->mf_mode = MULTI_FUNCTION_SI;
  10084. bp->mf_config[BP_VN(bp)] =
  10085. MF_CFG_RD(bp, func_mf_config[func].config);
  10086. } else
  10087. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  10088. }
  10089. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  10090. {
  10091. int /*abs*/func = BP_ABS_FUNC(bp);
  10092. int vn, mfw_vn;
  10093. u32 val = 0, val2 = 0;
  10094. int rc = 0;
  10095. /* Validate that chip access is feasible */
  10096. if (REG_RD(bp, MISC_REG_CHIP_NUM) == 0xffffffff) {
  10097. dev_err(&bp->pdev->dev,
  10098. "Chip read returns all Fs. Preventing probe from continuing\n");
  10099. return -EINVAL;
  10100. }
  10101. bnx2x_get_common_hwinfo(bp);
  10102. /*
  10103. * initialize IGU parameters
  10104. */
  10105. if (CHIP_IS_E1x(bp)) {
  10106. bp->common.int_block = INT_BLOCK_HC;
  10107. bp->igu_dsb_id = DEF_SB_IGU_ID;
  10108. bp->igu_base_sb = 0;
  10109. } else {
  10110. bp->common.int_block = INT_BLOCK_IGU;
  10111. /* do not allow device reset during IGU info processing */
  10112. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10113. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  10114. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10115. int tout = 5000;
  10116. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  10117. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  10118. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  10119. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  10120. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10121. tout--;
  10122. usleep_range(1000, 2000);
  10123. }
  10124. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10125. dev_err(&bp->pdev->dev,
  10126. "FORCING Normal Mode failed!!!\n");
  10127. bnx2x_release_hw_lock(bp,
  10128. HW_LOCK_RESOURCE_RESET);
  10129. return -EPERM;
  10130. }
  10131. }
  10132. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10133. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  10134. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  10135. } else
  10136. BNX2X_DEV_INFO("IGU Normal Mode\n");
  10137. rc = bnx2x_get_igu_cam_info(bp);
  10138. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10139. if (rc)
  10140. return rc;
  10141. }
  10142. /*
  10143. * set base FW non-default (fast path) status block id, this value is
  10144. * used to initialize the fw_sb_id saved on the fp/queue structure to
  10145. * determine the id used by the FW.
  10146. */
  10147. if (CHIP_IS_E1x(bp))
  10148. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  10149. else /*
  10150. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  10151. * the same queue are indicated on the same IGU SB). So we prefer
  10152. * FW and IGU SBs to be the same value.
  10153. */
  10154. bp->base_fw_ndsb = bp->igu_base_sb;
  10155. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  10156. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  10157. bp->igu_sb_cnt, bp->base_fw_ndsb);
  10158. /*
  10159. * Initialize MF configuration
  10160. */
  10161. bp->mf_ov = 0;
  10162. bp->mf_mode = 0;
  10163. bp->mf_sub_mode = 0;
  10164. vn = BP_VN(bp);
  10165. mfw_vn = BP_FW_MB_IDX(bp);
  10166. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  10167. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  10168. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  10169. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  10170. if (SHMEM2_HAS(bp, mf_cfg_addr))
  10171. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  10172. else
  10173. bp->common.mf_cfg_base = bp->common.shmem_base +
  10174. offsetof(struct shmem_region, func_mb) +
  10175. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  10176. /*
  10177. * get mf configuration:
  10178. * 1. Existence of MF configuration
  10179. * 2. MAC address must be legal (check only upper bytes)
  10180. * for Switch-Independent mode;
  10181. * OVLAN must be legal for Switch-Dependent mode
  10182. * 3. SF_MODE configures specific MF mode
  10183. */
  10184. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10185. /* get mf configuration */
  10186. val = SHMEM_RD(bp,
  10187. dev_info.shared_feature_config.config);
  10188. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  10189. switch (val) {
  10190. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  10191. validate_set_si_mode(bp);
  10192. break;
  10193. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  10194. if ((!CHIP_IS_E1x(bp)) &&
  10195. (MF_CFG_RD(bp, func_mf_config[func].
  10196. mac_upper) != 0xffff) &&
  10197. (SHMEM2_HAS(bp,
  10198. afex_driver_support))) {
  10199. bp->mf_mode = MULTI_FUNCTION_AFEX;
  10200. bp->mf_config[vn] = MF_CFG_RD(bp,
  10201. func_mf_config[func].config);
  10202. } else {
  10203. BNX2X_DEV_INFO("can not configure afex mode\n");
  10204. }
  10205. break;
  10206. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  10207. /* get OV configuration */
  10208. val = MF_CFG_RD(bp,
  10209. func_mf_config[FUNC_0].e1hov_tag);
  10210. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  10211. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10212. bp->mf_mode = MULTI_FUNCTION_SD;
  10213. bp->mf_config[vn] = MF_CFG_RD(bp,
  10214. func_mf_config[func].config);
  10215. } else
  10216. BNX2X_DEV_INFO("illegal OV for SD\n");
  10217. break;
  10218. case SHARED_FEAT_CFG_FORCE_SF_MODE_BD_MODE:
  10219. bp->mf_mode = MULTI_FUNCTION_SD;
  10220. bp->mf_sub_mode = SUB_MF_MODE_BD;
  10221. bp->mf_config[vn] =
  10222. MF_CFG_RD(bp,
  10223. func_mf_config[func].config);
  10224. if (SHMEM2_HAS(bp, mtu_size)) {
  10225. int mtu_idx = BP_FW_MB_IDX(bp);
  10226. u16 mtu_size;
  10227. u32 mtu;
  10228. mtu = SHMEM2_RD(bp, mtu_size[mtu_idx]);
  10229. mtu_size = (u16)mtu;
  10230. DP(NETIF_MSG_IFUP, "Read MTU size %04x [%08x]\n",
  10231. mtu_size, mtu);
  10232. /* if valid: update device mtu */
  10233. if ((mtu_size >= ETH_MIN_PACKET_SIZE) &&
  10234. (mtu_size <=
  10235. ETH_MAX_JUMBO_PACKET_SIZE))
  10236. bp->dev->mtu = mtu_size;
  10237. }
  10238. break;
  10239. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  10240. bp->mf_mode = MULTI_FUNCTION_SD;
  10241. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  10242. bp->mf_config[vn] =
  10243. MF_CFG_RD(bp,
  10244. func_mf_config[func].config);
  10245. break;
  10246. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  10247. bp->mf_config[vn] = 0;
  10248. break;
  10249. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  10250. val2 = SHMEM_RD(bp,
  10251. dev_info.shared_hw_config.config_3);
  10252. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  10253. switch (val2) {
  10254. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  10255. validate_set_si_mode(bp);
  10256. bp->mf_sub_mode =
  10257. SUB_MF_MODE_NPAR1_DOT_5;
  10258. break;
  10259. default:
  10260. /* Unknown configuration */
  10261. bp->mf_config[vn] = 0;
  10262. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  10263. val);
  10264. }
  10265. break;
  10266. default:
  10267. /* Unknown configuration: reset mf_config */
  10268. bp->mf_config[vn] = 0;
  10269. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  10270. }
  10271. }
  10272. BNX2X_DEV_INFO("%s function mode\n",
  10273. IS_MF(bp) ? "multi" : "single");
  10274. switch (bp->mf_mode) {
  10275. case MULTI_FUNCTION_SD:
  10276. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  10277. FUNC_MF_CFG_E1HOV_TAG_MASK;
  10278. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10279. bp->mf_ov = val;
  10280. bp->path_has_ovlan = true;
  10281. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  10282. func, bp->mf_ov, bp->mf_ov);
  10283. } else if ((bp->mf_sub_mode == SUB_MF_MODE_UFP) ||
  10284. (bp->mf_sub_mode == SUB_MF_MODE_BD)) {
  10285. dev_err(&bp->pdev->dev,
  10286. "Unexpected - no valid MF OV for func %d in UFP/BD mode\n",
  10287. func);
  10288. bp->path_has_ovlan = true;
  10289. } else {
  10290. dev_err(&bp->pdev->dev,
  10291. "No valid MF OV for func %d, aborting\n",
  10292. func);
  10293. return -EPERM;
  10294. }
  10295. break;
  10296. case MULTI_FUNCTION_AFEX:
  10297. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  10298. break;
  10299. case MULTI_FUNCTION_SI:
  10300. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  10301. func);
  10302. break;
  10303. default:
  10304. if (vn) {
  10305. dev_err(&bp->pdev->dev,
  10306. "VN %d is in a single function mode, aborting\n",
  10307. vn);
  10308. return -EPERM;
  10309. }
  10310. break;
  10311. }
  10312. /* check if other port on the path needs ovlan:
  10313. * Since MF configuration is shared between ports
  10314. * Possible mixed modes are only
  10315. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  10316. */
  10317. if (CHIP_MODE_IS_4_PORT(bp) &&
  10318. !bp->path_has_ovlan &&
  10319. !IS_MF(bp) &&
  10320. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10321. u8 other_port = !BP_PORT(bp);
  10322. u8 other_func = BP_PATH(bp) + 2*other_port;
  10323. val = MF_CFG_RD(bp,
  10324. func_mf_config[other_func].e1hov_tag);
  10325. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  10326. bp->path_has_ovlan = true;
  10327. }
  10328. }
  10329. /* adjust igu_sb_cnt to MF for E1H */
  10330. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10331. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10332. /* port info */
  10333. bnx2x_get_port_hwinfo(bp);
  10334. /* Get MAC addresses */
  10335. bnx2x_get_mac_hwinfo(bp);
  10336. bnx2x_get_cnic_info(bp);
  10337. return rc;
  10338. }
  10339. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10340. {
  10341. int cnt, i, block_end, rodi;
  10342. char vpd_start[BNX2X_VPD_LEN+1];
  10343. char str_id_reg[VENDOR_ID_LEN+1];
  10344. char str_id_cap[VENDOR_ID_LEN+1];
  10345. char *vpd_data;
  10346. char *vpd_extended_data = NULL;
  10347. u8 len;
  10348. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10349. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10350. if (cnt < BNX2X_VPD_LEN)
  10351. goto out_not_found;
  10352. /* VPD RO tag should be first tag after identifier string, hence
  10353. * we should be able to find it in first BNX2X_VPD_LEN chars
  10354. */
  10355. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10356. PCI_VPD_LRDT_RO_DATA);
  10357. if (i < 0)
  10358. goto out_not_found;
  10359. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10360. pci_vpd_lrdt_size(&vpd_start[i]);
  10361. i += PCI_VPD_LRDT_TAG_SIZE;
  10362. if (block_end > BNX2X_VPD_LEN) {
  10363. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10364. if (vpd_extended_data == NULL)
  10365. goto out_not_found;
  10366. /* read rest of vpd image into vpd_extended_data */
  10367. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10368. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10369. block_end - BNX2X_VPD_LEN,
  10370. vpd_extended_data + BNX2X_VPD_LEN);
  10371. if (cnt < (block_end - BNX2X_VPD_LEN))
  10372. goto out_not_found;
  10373. vpd_data = vpd_extended_data;
  10374. } else
  10375. vpd_data = vpd_start;
  10376. /* now vpd_data holds full vpd content in both cases */
  10377. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10378. PCI_VPD_RO_KEYWORD_MFR_ID);
  10379. if (rodi < 0)
  10380. goto out_not_found;
  10381. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10382. if (len != VENDOR_ID_LEN)
  10383. goto out_not_found;
  10384. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10385. /* vendor specific info */
  10386. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10387. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10388. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10389. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10390. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10391. PCI_VPD_RO_KEYWORD_VENDOR0);
  10392. if (rodi >= 0) {
  10393. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10394. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10395. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10396. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10397. bp->fw_ver[len] = ' ';
  10398. }
  10399. }
  10400. kfree(vpd_extended_data);
  10401. return;
  10402. }
  10403. out_not_found:
  10404. kfree(vpd_extended_data);
  10405. return;
  10406. }
  10407. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10408. {
  10409. u32 flags = 0;
  10410. if (CHIP_REV_IS_FPGA(bp))
  10411. SET_FLAGS(flags, MODE_FPGA);
  10412. else if (CHIP_REV_IS_EMUL(bp))
  10413. SET_FLAGS(flags, MODE_EMUL);
  10414. else
  10415. SET_FLAGS(flags, MODE_ASIC);
  10416. if (CHIP_MODE_IS_4_PORT(bp))
  10417. SET_FLAGS(flags, MODE_PORT4);
  10418. else
  10419. SET_FLAGS(flags, MODE_PORT2);
  10420. if (CHIP_IS_E2(bp))
  10421. SET_FLAGS(flags, MODE_E2);
  10422. else if (CHIP_IS_E3(bp)) {
  10423. SET_FLAGS(flags, MODE_E3);
  10424. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10425. SET_FLAGS(flags, MODE_E3_A0);
  10426. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10427. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10428. }
  10429. if (IS_MF(bp)) {
  10430. SET_FLAGS(flags, MODE_MF);
  10431. switch (bp->mf_mode) {
  10432. case MULTI_FUNCTION_SD:
  10433. SET_FLAGS(flags, MODE_MF_SD);
  10434. break;
  10435. case MULTI_FUNCTION_SI:
  10436. SET_FLAGS(flags, MODE_MF_SI);
  10437. break;
  10438. case MULTI_FUNCTION_AFEX:
  10439. SET_FLAGS(flags, MODE_MF_AFEX);
  10440. break;
  10441. }
  10442. } else
  10443. SET_FLAGS(flags, MODE_SF);
  10444. #if defined(__LITTLE_ENDIAN)
  10445. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10446. #else /*(__BIG_ENDIAN)*/
  10447. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10448. #endif
  10449. INIT_MODE_FLAGS(bp) = flags;
  10450. }
  10451. static int bnx2x_init_bp(struct bnx2x *bp)
  10452. {
  10453. int func;
  10454. int rc;
  10455. mutex_init(&bp->port.phy_mutex);
  10456. mutex_init(&bp->fw_mb_mutex);
  10457. mutex_init(&bp->drv_info_mutex);
  10458. sema_init(&bp->stats_lock, 1);
  10459. bp->drv_info_mng_owner = false;
  10460. INIT_LIST_HEAD(&bp->vlan_reg);
  10461. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10462. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10463. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10464. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10465. if (IS_PF(bp)) {
  10466. rc = bnx2x_get_hwinfo(bp);
  10467. if (rc)
  10468. return rc;
  10469. } else {
  10470. eth_zero_addr(bp->dev->dev_addr);
  10471. }
  10472. bnx2x_set_modes_bitmap(bp);
  10473. rc = bnx2x_alloc_mem_bp(bp);
  10474. if (rc)
  10475. return rc;
  10476. bnx2x_read_fwinfo(bp);
  10477. func = BP_FUNC(bp);
  10478. /* need to reset chip if undi was active */
  10479. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10480. /* init fw_seq */
  10481. bp->fw_seq =
  10482. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10483. DRV_MSG_SEQ_NUMBER_MASK;
  10484. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10485. rc = bnx2x_prev_unload(bp);
  10486. if (rc) {
  10487. bnx2x_free_mem_bp(bp);
  10488. return rc;
  10489. }
  10490. }
  10491. if (CHIP_REV_IS_FPGA(bp))
  10492. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10493. if (BP_NOMCP(bp) && (func == 0))
  10494. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10495. bp->disable_tpa = disable_tpa;
  10496. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10497. /* Reduce memory usage in kdump environment by disabling TPA */
  10498. bp->disable_tpa |= is_kdump_kernel();
  10499. /* Set TPA flags */
  10500. if (bp->disable_tpa) {
  10501. bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
  10502. bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
  10503. }
  10504. if (CHIP_IS_E1(bp))
  10505. bp->dropless_fc = 0;
  10506. else
  10507. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10508. bp->mrrs = mrrs;
  10509. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10510. if (IS_VF(bp))
  10511. bp->rx_ring_size = MAX_RX_AVAIL;
  10512. /* make sure that the numbers are in the right granularity */
  10513. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10514. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10515. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10516. timer_setup(&bp->timer, bnx2x_timer, 0);
  10517. bp->timer.expires = jiffies + bp->current_interval;
  10518. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10519. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10520. SHMEM2_HAS(bp, dcbx_en) &&
  10521. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10522. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset) &&
  10523. SHMEM2_RD(bp, dcbx_en[BP_PORT(bp)])) {
  10524. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10525. bnx2x_dcbx_init_params(bp);
  10526. } else {
  10527. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10528. }
  10529. if (CHIP_IS_E1x(bp))
  10530. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10531. else
  10532. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10533. /* multiple tx priority */
  10534. if (IS_VF(bp))
  10535. bp->max_cos = 1;
  10536. else if (CHIP_IS_E1x(bp))
  10537. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10538. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10539. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10540. else if (CHIP_IS_E3B0(bp))
  10541. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10542. else
  10543. BNX2X_ERR("unknown chip %x revision %x\n",
  10544. CHIP_NUM(bp), CHIP_REV(bp));
  10545. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10546. /* We need at least one default status block for slow-path events,
  10547. * second status block for the L2 queue, and a third status block for
  10548. * CNIC if supported.
  10549. */
  10550. if (IS_VF(bp))
  10551. bp->min_msix_vec_cnt = 1;
  10552. else if (CNIC_SUPPORT(bp))
  10553. bp->min_msix_vec_cnt = 3;
  10554. else /* PF w/o cnic */
  10555. bp->min_msix_vec_cnt = 2;
  10556. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10557. bp->dump_preset_idx = 1;
  10558. if (CHIP_IS_E3B0(bp))
  10559. bp->flags |= PTP_SUPPORTED;
  10560. return rc;
  10561. }
  10562. /****************************************************************************
  10563. * General service functions
  10564. ****************************************************************************/
  10565. /*
  10566. * net_device service functions
  10567. */
  10568. /* called with rtnl_lock */
  10569. static int bnx2x_open(struct net_device *dev)
  10570. {
  10571. struct bnx2x *bp = netdev_priv(dev);
  10572. int rc;
  10573. bp->stats_init = true;
  10574. netif_carrier_off(dev);
  10575. bnx2x_set_power_state(bp, PCI_D0);
  10576. /* If parity had happen during the unload, then attentions
  10577. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10578. * want the first function loaded on the current engine to
  10579. * complete the recovery.
  10580. * Parity recovery is only relevant for PF driver.
  10581. */
  10582. if (IS_PF(bp)) {
  10583. int other_engine = BP_PATH(bp) ? 0 : 1;
  10584. bool other_load_status, load_status;
  10585. bool global = false;
  10586. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10587. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10588. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10589. bnx2x_chk_parity_attn(bp, &global, true)) {
  10590. do {
  10591. /* If there are attentions and they are in a
  10592. * global blocks, set the GLOBAL_RESET bit
  10593. * regardless whether it will be this function
  10594. * that will complete the recovery or not.
  10595. */
  10596. if (global)
  10597. bnx2x_set_reset_global(bp);
  10598. /* Only the first function on the current
  10599. * engine should try to recover in open. In case
  10600. * of attentions in global blocks only the first
  10601. * in the chip should try to recover.
  10602. */
  10603. if ((!load_status &&
  10604. (!global || !other_load_status)) &&
  10605. bnx2x_trylock_leader_lock(bp) &&
  10606. !bnx2x_leader_reset(bp)) {
  10607. netdev_info(bp->dev,
  10608. "Recovered in open\n");
  10609. break;
  10610. }
  10611. /* recovery has failed... */
  10612. bnx2x_set_power_state(bp, PCI_D3hot);
  10613. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10614. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10615. "If you still see this message after a few retries then power cycle is required.\n");
  10616. return -EAGAIN;
  10617. } while (0);
  10618. }
  10619. }
  10620. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10621. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10622. if (rc)
  10623. return rc;
  10624. if (IS_PF(bp))
  10625. udp_tunnel_get_rx_info(dev);
  10626. return 0;
  10627. }
  10628. /* called with rtnl_lock */
  10629. static int bnx2x_close(struct net_device *dev)
  10630. {
  10631. struct bnx2x *bp = netdev_priv(dev);
  10632. /* Unload the driver, release IRQs */
  10633. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10634. return 0;
  10635. }
  10636. struct bnx2x_mcast_list_elem_group
  10637. {
  10638. struct list_head mcast_group_link;
  10639. struct bnx2x_mcast_list_elem mcast_elems[];
  10640. };
  10641. #define MCAST_ELEMS_PER_PG \
  10642. ((PAGE_SIZE - sizeof(struct bnx2x_mcast_list_elem_group)) / \
  10643. sizeof(struct bnx2x_mcast_list_elem))
  10644. static void bnx2x_free_mcast_macs_list(struct list_head *mcast_group_list)
  10645. {
  10646. struct bnx2x_mcast_list_elem_group *current_mcast_group;
  10647. while (!list_empty(mcast_group_list)) {
  10648. current_mcast_group = list_first_entry(mcast_group_list,
  10649. struct bnx2x_mcast_list_elem_group,
  10650. mcast_group_link);
  10651. list_del(&current_mcast_group->mcast_group_link);
  10652. free_page((unsigned long)current_mcast_group);
  10653. }
  10654. }
  10655. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10656. struct bnx2x_mcast_ramrod_params *p,
  10657. struct list_head *mcast_group_list)
  10658. {
  10659. struct bnx2x_mcast_list_elem *mc_mac;
  10660. struct netdev_hw_addr *ha;
  10661. struct bnx2x_mcast_list_elem_group *current_mcast_group = NULL;
  10662. int mc_count = netdev_mc_count(bp->dev);
  10663. int offset = 0;
  10664. INIT_LIST_HEAD(&p->mcast_list);
  10665. netdev_for_each_mc_addr(ha, bp->dev) {
  10666. if (!offset) {
  10667. current_mcast_group =
  10668. (struct bnx2x_mcast_list_elem_group *)
  10669. __get_free_page(GFP_ATOMIC);
  10670. if (!current_mcast_group) {
  10671. bnx2x_free_mcast_macs_list(mcast_group_list);
  10672. BNX2X_ERR("Failed to allocate mc MAC list\n");
  10673. return -ENOMEM;
  10674. }
  10675. list_add(&current_mcast_group->mcast_group_link,
  10676. mcast_group_list);
  10677. }
  10678. mc_mac = &current_mcast_group->mcast_elems[offset];
  10679. mc_mac->mac = bnx2x_mc_addr(ha);
  10680. list_add_tail(&mc_mac->link, &p->mcast_list);
  10681. offset++;
  10682. if (offset == MCAST_ELEMS_PER_PG)
  10683. offset = 0;
  10684. }
  10685. p->mcast_list_len = mc_count;
  10686. return 0;
  10687. }
  10688. /**
  10689. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10690. *
  10691. * @bp: driver handle
  10692. *
  10693. * We will use zero (0) as a MAC type for these MACs.
  10694. */
  10695. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10696. {
  10697. int rc;
  10698. struct net_device *dev = bp->dev;
  10699. struct netdev_hw_addr *ha;
  10700. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10701. unsigned long ramrod_flags = 0;
  10702. /* First schedule a cleanup up of old configuration */
  10703. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10704. if (rc < 0) {
  10705. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10706. return rc;
  10707. }
  10708. netdev_for_each_uc_addr(ha, dev) {
  10709. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10710. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10711. if (rc == -EEXIST) {
  10712. DP(BNX2X_MSG_SP,
  10713. "Failed to schedule ADD operations: %d\n", rc);
  10714. /* do not treat adding same MAC as error */
  10715. rc = 0;
  10716. } else if (rc < 0) {
  10717. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10718. rc);
  10719. return rc;
  10720. }
  10721. }
  10722. /* Execute the pending commands */
  10723. __set_bit(RAMROD_CONT, &ramrod_flags);
  10724. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10725. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10726. }
  10727. static int bnx2x_set_mc_list_e1x(struct bnx2x *bp)
  10728. {
  10729. LIST_HEAD(mcast_group_list);
  10730. struct net_device *dev = bp->dev;
  10731. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10732. int rc = 0;
  10733. rparam.mcast_obj = &bp->mcast_obj;
  10734. /* first, clear all configured multicast MACs */
  10735. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10736. if (rc < 0) {
  10737. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10738. return rc;
  10739. }
  10740. /* then, configure a new MACs list */
  10741. if (netdev_mc_count(dev)) {
  10742. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10743. if (rc)
  10744. return rc;
  10745. /* Now add the new MACs */
  10746. rc = bnx2x_config_mcast(bp, &rparam,
  10747. BNX2X_MCAST_CMD_ADD);
  10748. if (rc < 0)
  10749. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10750. rc);
  10751. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10752. }
  10753. return rc;
  10754. }
  10755. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10756. {
  10757. LIST_HEAD(mcast_group_list);
  10758. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10759. struct net_device *dev = bp->dev;
  10760. int rc = 0;
  10761. /* On older adapters, we need to flush and re-add filters */
  10762. if (CHIP_IS_E1x(bp))
  10763. return bnx2x_set_mc_list_e1x(bp);
  10764. rparam.mcast_obj = &bp->mcast_obj;
  10765. if (netdev_mc_count(dev)) {
  10766. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10767. if (rc)
  10768. return rc;
  10769. /* Override the curently configured set of mc filters */
  10770. rc = bnx2x_config_mcast(bp, &rparam,
  10771. BNX2X_MCAST_CMD_SET);
  10772. if (rc < 0)
  10773. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10774. rc);
  10775. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10776. } else {
  10777. /* If no mc addresses are required, flush the configuration */
  10778. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10779. if (rc < 0)
  10780. BNX2X_ERR("Failed to clear multicast configuration %d\n",
  10781. rc);
  10782. }
  10783. return rc;
  10784. }
  10785. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10786. static void bnx2x_set_rx_mode(struct net_device *dev)
  10787. {
  10788. struct bnx2x *bp = netdev_priv(dev);
  10789. if (bp->state != BNX2X_STATE_OPEN) {
  10790. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10791. return;
  10792. } else {
  10793. /* Schedule an SP task to handle rest of change */
  10794. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10795. NETIF_MSG_IFUP);
  10796. }
  10797. }
  10798. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10799. {
  10800. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10801. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10802. netif_addr_lock_bh(bp->dev);
  10803. if (bp->dev->flags & IFF_PROMISC) {
  10804. rx_mode = BNX2X_RX_MODE_PROMISC;
  10805. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10806. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10807. CHIP_IS_E1(bp))) {
  10808. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10809. } else {
  10810. if (IS_PF(bp)) {
  10811. /* some multicasts */
  10812. if (bnx2x_set_mc_list(bp) < 0)
  10813. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10814. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10815. netif_addr_unlock_bh(bp->dev);
  10816. if (bnx2x_set_uc_list(bp) < 0)
  10817. rx_mode = BNX2X_RX_MODE_PROMISC;
  10818. netif_addr_lock_bh(bp->dev);
  10819. } else {
  10820. /* configuring mcast to a vf involves sleeping (when we
  10821. * wait for the pf's response).
  10822. */
  10823. bnx2x_schedule_sp_rtnl(bp,
  10824. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10825. }
  10826. }
  10827. bp->rx_mode = rx_mode;
  10828. /* handle ISCSI SD mode */
  10829. if (IS_MF_ISCSI_ONLY(bp))
  10830. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10831. /* Schedule the rx_mode command */
  10832. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10833. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10834. netif_addr_unlock_bh(bp->dev);
  10835. return;
  10836. }
  10837. if (IS_PF(bp)) {
  10838. bnx2x_set_storm_rx_mode(bp);
  10839. netif_addr_unlock_bh(bp->dev);
  10840. } else {
  10841. /* VF will need to request the PF to make this change, and so
  10842. * the VF needs to release the bottom-half lock prior to the
  10843. * request (as it will likely require sleep on the VF side)
  10844. */
  10845. netif_addr_unlock_bh(bp->dev);
  10846. bnx2x_vfpf_storm_rx_mode(bp);
  10847. }
  10848. }
  10849. /* called with rtnl_lock */
  10850. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10851. int devad, u16 addr)
  10852. {
  10853. struct bnx2x *bp = netdev_priv(netdev);
  10854. u16 value;
  10855. int rc;
  10856. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10857. prtad, devad, addr);
  10858. /* The HW expects different devad if CL22 is used */
  10859. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10860. bnx2x_acquire_phy_lock(bp);
  10861. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10862. bnx2x_release_phy_lock(bp);
  10863. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10864. if (!rc)
  10865. rc = value;
  10866. return rc;
  10867. }
  10868. /* called with rtnl_lock */
  10869. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10870. u16 addr, u16 value)
  10871. {
  10872. struct bnx2x *bp = netdev_priv(netdev);
  10873. int rc;
  10874. DP(NETIF_MSG_LINK,
  10875. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10876. prtad, devad, addr, value);
  10877. /* The HW expects different devad if CL22 is used */
  10878. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10879. bnx2x_acquire_phy_lock(bp);
  10880. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10881. bnx2x_release_phy_lock(bp);
  10882. return rc;
  10883. }
  10884. /* called with rtnl_lock */
  10885. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10886. {
  10887. struct bnx2x *bp = netdev_priv(dev);
  10888. struct mii_ioctl_data *mdio = if_mii(ifr);
  10889. if (!netif_running(dev))
  10890. return -EAGAIN;
  10891. switch (cmd) {
  10892. case SIOCSHWTSTAMP:
  10893. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10894. default:
  10895. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10896. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10897. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10898. }
  10899. }
  10900. static int bnx2x_validate_addr(struct net_device *dev)
  10901. {
  10902. struct bnx2x *bp = netdev_priv(dev);
  10903. /* query the bulletin board for mac address configured by the PF */
  10904. if (IS_VF(bp))
  10905. bnx2x_sample_bulletin(bp);
  10906. if (!is_valid_ether_addr(dev->dev_addr)) {
  10907. BNX2X_ERR("Non-valid Ethernet address\n");
  10908. return -EADDRNOTAVAIL;
  10909. }
  10910. return 0;
  10911. }
  10912. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10913. struct netdev_phys_item_id *ppid)
  10914. {
  10915. struct bnx2x *bp = netdev_priv(netdev);
  10916. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10917. return -EOPNOTSUPP;
  10918. ppid->id_len = sizeof(bp->phys_port_id);
  10919. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10920. return 0;
  10921. }
  10922. static netdev_features_t bnx2x_features_check(struct sk_buff *skb,
  10923. struct net_device *dev,
  10924. netdev_features_t features)
  10925. {
  10926. /*
  10927. * A skb with gso_size + header length > 9700 will cause a
  10928. * firmware panic. Drop GSO support.
  10929. *
  10930. * Eventually the upper layer should not pass these packets down.
  10931. *
  10932. * For speed, if the gso_size is <= 9000, assume there will
  10933. * not be 700 bytes of headers and pass it through. Only do a
  10934. * full (slow) validation if the gso_size is > 9000.
  10935. *
  10936. * (Due to the way SKB_BY_FRAGS works this will also do a full
  10937. * validation in that case.)
  10938. */
  10939. if (unlikely(skb_is_gso(skb) &&
  10940. (skb_shinfo(skb)->gso_size > 9000) &&
  10941. !skb_gso_validate_mac_len(skb, 9700)))
  10942. features &= ~NETIF_F_GSO_MASK;
  10943. features = vlan_features_check(skb, features);
  10944. return vxlan_features_check(skb, features);
  10945. }
  10946. static int __bnx2x_vlan_configure_vid(struct bnx2x *bp, u16 vid, bool add)
  10947. {
  10948. int rc;
  10949. if (IS_PF(bp)) {
  10950. unsigned long ramrod_flags = 0;
  10951. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10952. rc = bnx2x_set_vlan_one(bp, vid, &bp->sp_objs->vlan_obj,
  10953. add, &ramrod_flags);
  10954. } else {
  10955. rc = bnx2x_vfpf_update_vlan(bp, vid, bp->fp->index, add);
  10956. }
  10957. return rc;
  10958. }
  10959. static int bnx2x_vlan_configure_vid_list(struct bnx2x *bp)
  10960. {
  10961. struct bnx2x_vlan_entry *vlan;
  10962. int rc = 0;
  10963. /* Configure all non-configured entries */
  10964. list_for_each_entry(vlan, &bp->vlan_reg, link) {
  10965. if (vlan->hw)
  10966. continue;
  10967. if (bp->vlan_cnt >= bp->vlan_credit)
  10968. return -ENOBUFS;
  10969. rc = __bnx2x_vlan_configure_vid(bp, vlan->vid, true);
  10970. if (rc) {
  10971. BNX2X_ERR("Unable to config VLAN %d\n", vlan->vid);
  10972. return rc;
  10973. }
  10974. DP(NETIF_MSG_IFUP, "HW configured for VLAN %d\n", vlan->vid);
  10975. vlan->hw = true;
  10976. bp->vlan_cnt++;
  10977. }
  10978. return 0;
  10979. }
  10980. static void bnx2x_vlan_configure(struct bnx2x *bp, bool set_rx_mode)
  10981. {
  10982. bool need_accept_any_vlan;
  10983. need_accept_any_vlan = !!bnx2x_vlan_configure_vid_list(bp);
  10984. if (bp->accept_any_vlan != need_accept_any_vlan) {
  10985. bp->accept_any_vlan = need_accept_any_vlan;
  10986. DP(NETIF_MSG_IFUP, "Accept all VLAN %s\n",
  10987. bp->accept_any_vlan ? "raised" : "cleared");
  10988. if (set_rx_mode) {
  10989. if (IS_PF(bp))
  10990. bnx2x_set_rx_mode_inner(bp);
  10991. else
  10992. bnx2x_vfpf_storm_rx_mode(bp);
  10993. }
  10994. }
  10995. }
  10996. int bnx2x_vlan_reconfigure_vid(struct bnx2x *bp)
  10997. {
  10998. /* Don't set rx mode here. Our caller will do it. */
  10999. bnx2x_vlan_configure(bp, false);
  11000. return 0;
  11001. }
  11002. static int bnx2x_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
  11003. {
  11004. struct bnx2x *bp = netdev_priv(dev);
  11005. struct bnx2x_vlan_entry *vlan;
  11006. DP(NETIF_MSG_IFUP, "Adding VLAN %d\n", vid);
  11007. vlan = kmalloc(sizeof(*vlan), GFP_KERNEL);
  11008. if (!vlan)
  11009. return -ENOMEM;
  11010. vlan->vid = vid;
  11011. vlan->hw = false;
  11012. list_add_tail(&vlan->link, &bp->vlan_reg);
  11013. if (netif_running(dev))
  11014. bnx2x_vlan_configure(bp, true);
  11015. return 0;
  11016. }
  11017. static int bnx2x_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
  11018. {
  11019. struct bnx2x *bp = netdev_priv(dev);
  11020. struct bnx2x_vlan_entry *vlan;
  11021. bool found = false;
  11022. int rc = 0;
  11023. DP(NETIF_MSG_IFUP, "Removing VLAN %d\n", vid);
  11024. list_for_each_entry(vlan, &bp->vlan_reg, link)
  11025. if (vlan->vid == vid) {
  11026. found = true;
  11027. break;
  11028. }
  11029. if (!found) {
  11030. BNX2X_ERR("Unable to kill VLAN %d - not found\n", vid);
  11031. return -EINVAL;
  11032. }
  11033. if (netif_running(dev) && vlan->hw) {
  11034. rc = __bnx2x_vlan_configure_vid(bp, vid, false);
  11035. DP(NETIF_MSG_IFUP, "HW deconfigured for VLAN %d\n", vid);
  11036. bp->vlan_cnt--;
  11037. }
  11038. list_del(&vlan->link);
  11039. kfree(vlan);
  11040. if (netif_running(dev))
  11041. bnx2x_vlan_configure(bp, true);
  11042. DP(NETIF_MSG_IFUP, "Removing VLAN result %d\n", rc);
  11043. return rc;
  11044. }
  11045. static const struct net_device_ops bnx2x_netdev_ops = {
  11046. .ndo_open = bnx2x_open,
  11047. .ndo_stop = bnx2x_close,
  11048. .ndo_start_xmit = bnx2x_start_xmit,
  11049. .ndo_select_queue = bnx2x_select_queue,
  11050. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  11051. .ndo_set_mac_address = bnx2x_change_mac_addr,
  11052. .ndo_validate_addr = bnx2x_validate_addr,
  11053. .ndo_do_ioctl = bnx2x_ioctl,
  11054. .ndo_change_mtu = bnx2x_change_mtu,
  11055. .ndo_fix_features = bnx2x_fix_features,
  11056. .ndo_set_features = bnx2x_set_features,
  11057. .ndo_tx_timeout = bnx2x_tx_timeout,
  11058. .ndo_vlan_rx_add_vid = bnx2x_vlan_rx_add_vid,
  11059. .ndo_vlan_rx_kill_vid = bnx2x_vlan_rx_kill_vid,
  11060. .ndo_setup_tc = __bnx2x_setup_tc,
  11061. #ifdef CONFIG_BNX2X_SRIOV
  11062. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  11063. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  11064. .ndo_get_vf_config = bnx2x_get_vf_config,
  11065. #endif
  11066. #ifdef NETDEV_FCOE_WWNN
  11067. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  11068. #endif
  11069. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  11070. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  11071. .ndo_features_check = bnx2x_features_check,
  11072. .ndo_udp_tunnel_add = bnx2x_udp_tunnel_add,
  11073. .ndo_udp_tunnel_del = bnx2x_udp_tunnel_del,
  11074. };
  11075. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  11076. {
  11077. struct device *dev = &bp->pdev->dev;
  11078. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  11079. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  11080. dev_err(dev, "System does not support DMA, aborting\n");
  11081. return -EIO;
  11082. }
  11083. return 0;
  11084. }
  11085. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  11086. {
  11087. if (bp->flags & AER_ENABLED) {
  11088. pci_disable_pcie_error_reporting(bp->pdev);
  11089. bp->flags &= ~AER_ENABLED;
  11090. }
  11091. }
  11092. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  11093. struct net_device *dev, unsigned long board_type)
  11094. {
  11095. int rc;
  11096. u32 pci_cfg_dword;
  11097. bool chip_is_e1x = (board_type == BCM57710 ||
  11098. board_type == BCM57711 ||
  11099. board_type == BCM57711E);
  11100. SET_NETDEV_DEV(dev, &pdev->dev);
  11101. bp->dev = dev;
  11102. bp->pdev = pdev;
  11103. rc = pci_enable_device(pdev);
  11104. if (rc) {
  11105. dev_err(&bp->pdev->dev,
  11106. "Cannot enable PCI device, aborting\n");
  11107. goto err_out;
  11108. }
  11109. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  11110. dev_err(&bp->pdev->dev,
  11111. "Cannot find PCI device base address, aborting\n");
  11112. rc = -ENODEV;
  11113. goto err_out_disable;
  11114. }
  11115. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  11116. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  11117. rc = -ENODEV;
  11118. goto err_out_disable;
  11119. }
  11120. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  11121. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  11122. PCICFG_REVESION_ID_ERROR_VAL) {
  11123. pr_err("PCI device error, probably due to fan failure, aborting\n");
  11124. rc = -ENODEV;
  11125. goto err_out_disable;
  11126. }
  11127. if (atomic_read(&pdev->enable_cnt) == 1) {
  11128. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  11129. if (rc) {
  11130. dev_err(&bp->pdev->dev,
  11131. "Cannot obtain PCI resources, aborting\n");
  11132. goto err_out_disable;
  11133. }
  11134. pci_set_master(pdev);
  11135. pci_save_state(pdev);
  11136. }
  11137. if (IS_PF(bp)) {
  11138. if (!pdev->pm_cap) {
  11139. dev_err(&bp->pdev->dev,
  11140. "Cannot find power management capability, aborting\n");
  11141. rc = -EIO;
  11142. goto err_out_release;
  11143. }
  11144. }
  11145. if (!pci_is_pcie(pdev)) {
  11146. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  11147. rc = -EIO;
  11148. goto err_out_release;
  11149. }
  11150. rc = bnx2x_set_coherency_mask(bp);
  11151. if (rc)
  11152. goto err_out_release;
  11153. dev->mem_start = pci_resource_start(pdev, 0);
  11154. dev->base_addr = dev->mem_start;
  11155. dev->mem_end = pci_resource_end(pdev, 0);
  11156. dev->irq = pdev->irq;
  11157. bp->regview = pci_ioremap_bar(pdev, 0);
  11158. if (!bp->regview) {
  11159. dev_err(&bp->pdev->dev,
  11160. "Cannot map register space, aborting\n");
  11161. rc = -ENOMEM;
  11162. goto err_out_release;
  11163. }
  11164. /* In E1/E1H use pci device function given by kernel.
  11165. * In E2/E3 read physical function from ME register since these chips
  11166. * support Physical Device Assignment where kernel BDF maybe arbitrary
  11167. * (depending on hypervisor).
  11168. */
  11169. if (chip_is_e1x) {
  11170. bp->pf_num = PCI_FUNC(pdev->devfn);
  11171. } else {
  11172. /* chip is E2/3*/
  11173. pci_read_config_dword(bp->pdev,
  11174. PCICFG_ME_REGISTER, &pci_cfg_dword);
  11175. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  11176. ME_REG_ABS_PF_NUM_SHIFT);
  11177. }
  11178. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  11179. /* clean indirect addresses */
  11180. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  11181. PCICFG_VENDOR_ID_OFFSET);
  11182. /* Set PCIe reset type to fundamental for EEH recovery */
  11183. pdev->needs_freset = 1;
  11184. /* AER (Advanced Error reporting) configuration */
  11185. rc = pci_enable_pcie_error_reporting(pdev);
  11186. if (!rc)
  11187. bp->flags |= AER_ENABLED;
  11188. else
  11189. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  11190. /*
  11191. * Clean the following indirect addresses for all functions since it
  11192. * is not used by the driver.
  11193. */
  11194. if (IS_PF(bp)) {
  11195. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  11196. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  11197. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  11198. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  11199. if (chip_is_e1x) {
  11200. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  11201. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  11202. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  11203. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  11204. }
  11205. /* Enable internal target-read (in case we are probed after PF
  11206. * FLR). Must be done prior to any BAR read access. Only for
  11207. * 57712 and up
  11208. */
  11209. if (!chip_is_e1x)
  11210. REG_WR(bp,
  11211. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  11212. }
  11213. dev->watchdog_timeo = TX_TIMEOUT;
  11214. dev->netdev_ops = &bnx2x_netdev_ops;
  11215. bnx2x_set_ethtool_ops(bp, dev);
  11216. dev->priv_flags |= IFF_UNICAST_FLT;
  11217. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11218. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11219. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO | NETIF_F_GRO_HW |
  11220. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  11221. if (!chip_is_e1x) {
  11222. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11223. NETIF_F_GSO_IPXIP4 |
  11224. NETIF_F_GSO_UDP_TUNNEL |
  11225. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11226. NETIF_F_GSO_PARTIAL;
  11227. dev->hw_enc_features =
  11228. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  11229. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11230. NETIF_F_GSO_IPXIP4 |
  11231. NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11232. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11233. NETIF_F_GSO_PARTIAL;
  11234. dev->gso_partial_features = NETIF_F_GSO_GRE_CSUM |
  11235. NETIF_F_GSO_UDP_TUNNEL_CSUM;
  11236. }
  11237. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11238. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  11239. if (IS_PF(bp)) {
  11240. if (chip_is_e1x)
  11241. bp->accept_any_vlan = true;
  11242. else
  11243. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11244. }
  11245. /* For VF we'll know whether to enable VLAN filtering after
  11246. * getting a response to CHANNEL_TLV_ACQUIRE from PF.
  11247. */
  11248. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  11249. dev->features |= NETIF_F_HIGHDMA;
  11250. if (dev->features & NETIF_F_LRO)
  11251. dev->features &= ~NETIF_F_GRO_HW;
  11252. /* Add Loopback capability to the device */
  11253. dev->hw_features |= NETIF_F_LOOPBACK;
  11254. #ifdef BCM_DCBNL
  11255. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  11256. #endif
  11257. /* MTU range, 46 - 9600 */
  11258. dev->min_mtu = ETH_MIN_PACKET_SIZE;
  11259. dev->max_mtu = ETH_MAX_JUMBO_PACKET_SIZE;
  11260. /* get_port_hwinfo() will set prtad and mmds properly */
  11261. bp->mdio.prtad = MDIO_PRTAD_NONE;
  11262. bp->mdio.mmds = 0;
  11263. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  11264. bp->mdio.dev = dev;
  11265. bp->mdio.mdio_read = bnx2x_mdio_read;
  11266. bp->mdio.mdio_write = bnx2x_mdio_write;
  11267. return 0;
  11268. err_out_release:
  11269. if (atomic_read(&pdev->enable_cnt) == 1)
  11270. pci_release_regions(pdev);
  11271. err_out_disable:
  11272. pci_disable_device(pdev);
  11273. err_out:
  11274. return rc;
  11275. }
  11276. static int bnx2x_check_firmware(struct bnx2x *bp)
  11277. {
  11278. const struct firmware *firmware = bp->firmware;
  11279. struct bnx2x_fw_file_hdr *fw_hdr;
  11280. struct bnx2x_fw_file_section *sections;
  11281. u32 offset, len, num_ops;
  11282. __be16 *ops_offsets;
  11283. int i;
  11284. const u8 *fw_ver;
  11285. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  11286. BNX2X_ERR("Wrong FW size\n");
  11287. return -EINVAL;
  11288. }
  11289. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  11290. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  11291. /* Make sure none of the offsets and sizes make us read beyond
  11292. * the end of the firmware data */
  11293. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  11294. offset = be32_to_cpu(sections[i].offset);
  11295. len = be32_to_cpu(sections[i].len);
  11296. if (offset + len > firmware->size) {
  11297. BNX2X_ERR("Section %d length is out of bounds\n", i);
  11298. return -EINVAL;
  11299. }
  11300. }
  11301. /* Likewise for the init_ops offsets */
  11302. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  11303. ops_offsets = (__force __be16 *)(firmware->data + offset);
  11304. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  11305. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  11306. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  11307. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  11308. return -EINVAL;
  11309. }
  11310. }
  11311. /* Check FW version */
  11312. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  11313. fw_ver = firmware->data + offset;
  11314. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  11315. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  11316. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  11317. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  11318. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  11319. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  11320. BCM_5710_FW_MAJOR_VERSION,
  11321. BCM_5710_FW_MINOR_VERSION,
  11322. BCM_5710_FW_REVISION_VERSION,
  11323. BCM_5710_FW_ENGINEERING_VERSION);
  11324. return -EINVAL;
  11325. }
  11326. return 0;
  11327. }
  11328. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11329. {
  11330. const __be32 *source = (const __be32 *)_source;
  11331. u32 *target = (u32 *)_target;
  11332. u32 i;
  11333. for (i = 0; i < n/4; i++)
  11334. target[i] = be32_to_cpu(source[i]);
  11335. }
  11336. /*
  11337. Ops array is stored in the following format:
  11338. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  11339. */
  11340. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  11341. {
  11342. const __be32 *source = (const __be32 *)_source;
  11343. struct raw_op *target = (struct raw_op *)_target;
  11344. u32 i, j, tmp;
  11345. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  11346. tmp = be32_to_cpu(source[j]);
  11347. target[i].op = (tmp >> 24) & 0xff;
  11348. target[i].offset = tmp & 0xffffff;
  11349. target[i].raw_data = be32_to_cpu(source[j + 1]);
  11350. }
  11351. }
  11352. /* IRO array is stored in the following format:
  11353. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  11354. */
  11355. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  11356. {
  11357. const __be32 *source = (const __be32 *)_source;
  11358. struct iro *target = (struct iro *)_target;
  11359. u32 i, j, tmp;
  11360. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  11361. target[i].base = be32_to_cpu(source[j]);
  11362. j++;
  11363. tmp = be32_to_cpu(source[j]);
  11364. target[i].m1 = (tmp >> 16) & 0xffff;
  11365. target[i].m2 = tmp & 0xffff;
  11366. j++;
  11367. tmp = be32_to_cpu(source[j]);
  11368. target[i].m3 = (tmp >> 16) & 0xffff;
  11369. target[i].size = tmp & 0xffff;
  11370. j++;
  11371. }
  11372. }
  11373. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11374. {
  11375. const __be16 *source = (const __be16 *)_source;
  11376. u16 *target = (u16 *)_target;
  11377. u32 i;
  11378. for (i = 0; i < n/2; i++)
  11379. target[i] = be16_to_cpu(source[i]);
  11380. }
  11381. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  11382. do { \
  11383. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  11384. bp->arr = kmalloc(len, GFP_KERNEL); \
  11385. if (!bp->arr) \
  11386. goto lbl; \
  11387. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  11388. (u8 *)bp->arr, len); \
  11389. } while (0)
  11390. static int bnx2x_init_firmware(struct bnx2x *bp)
  11391. {
  11392. const char *fw_file_name;
  11393. struct bnx2x_fw_file_hdr *fw_hdr;
  11394. int rc;
  11395. if (bp->firmware)
  11396. return 0;
  11397. if (CHIP_IS_E1(bp))
  11398. fw_file_name = FW_FILE_NAME_E1;
  11399. else if (CHIP_IS_E1H(bp))
  11400. fw_file_name = FW_FILE_NAME_E1H;
  11401. else if (!CHIP_IS_E1x(bp))
  11402. fw_file_name = FW_FILE_NAME_E2;
  11403. else {
  11404. BNX2X_ERR("Unsupported chip revision\n");
  11405. return -EINVAL;
  11406. }
  11407. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  11408. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  11409. if (rc)
  11410. goto request_firmware_exit;
  11411. rc = bnx2x_check_firmware(bp);
  11412. if (rc) {
  11413. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  11414. goto request_firmware_exit;
  11415. }
  11416. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  11417. /* Initialize the pointers to the init arrays */
  11418. /* Blob */
  11419. rc = -ENOMEM;
  11420. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  11421. /* Opcodes */
  11422. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  11423. /* Offsets */
  11424. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  11425. be16_to_cpu_n);
  11426. /* STORMs firmware */
  11427. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11428. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  11429. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  11430. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  11431. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11432. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  11433. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  11434. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  11435. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11436. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  11437. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  11438. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  11439. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11440. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  11441. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  11442. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  11443. /* IRO */
  11444. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  11445. return 0;
  11446. iro_alloc_err:
  11447. kfree(bp->init_ops_offsets);
  11448. init_offsets_alloc_err:
  11449. kfree(bp->init_ops);
  11450. init_ops_alloc_err:
  11451. kfree(bp->init_data);
  11452. request_firmware_exit:
  11453. release_firmware(bp->firmware);
  11454. bp->firmware = NULL;
  11455. return rc;
  11456. }
  11457. static void bnx2x_release_firmware(struct bnx2x *bp)
  11458. {
  11459. kfree(bp->init_ops_offsets);
  11460. kfree(bp->init_ops);
  11461. kfree(bp->init_data);
  11462. release_firmware(bp->firmware);
  11463. bp->firmware = NULL;
  11464. }
  11465. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  11466. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  11467. .init_hw_cmn = bnx2x_init_hw_common,
  11468. .init_hw_port = bnx2x_init_hw_port,
  11469. .init_hw_func = bnx2x_init_hw_func,
  11470. .reset_hw_cmn = bnx2x_reset_common,
  11471. .reset_hw_port = bnx2x_reset_port,
  11472. .reset_hw_func = bnx2x_reset_func,
  11473. .gunzip_init = bnx2x_gunzip_init,
  11474. .gunzip_end = bnx2x_gunzip_end,
  11475. .init_fw = bnx2x_init_firmware,
  11476. .release_fw = bnx2x_release_firmware,
  11477. };
  11478. void bnx2x__init_func_obj(struct bnx2x *bp)
  11479. {
  11480. /* Prepare DMAE related driver resources */
  11481. bnx2x_setup_dmae(bp);
  11482. bnx2x_init_func_obj(bp, &bp->func_obj,
  11483. bnx2x_sp(bp, func_rdata),
  11484. bnx2x_sp_mapping(bp, func_rdata),
  11485. bnx2x_sp(bp, func_afex_rdata),
  11486. bnx2x_sp_mapping(bp, func_afex_rdata),
  11487. &bnx2x_func_sp_drv);
  11488. }
  11489. /* must be called after sriov-enable */
  11490. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  11491. {
  11492. int cid_count = BNX2X_L2_MAX_CID(bp);
  11493. if (IS_SRIOV(bp))
  11494. cid_count += BNX2X_VF_CIDS;
  11495. if (CNIC_SUPPORT(bp))
  11496. cid_count += CNIC_CID_MAX;
  11497. return roundup(cid_count, QM_CID_ROUND);
  11498. }
  11499. /**
  11500. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  11501. *
  11502. * @dev: pci device
  11503. *
  11504. */
  11505. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  11506. {
  11507. int index;
  11508. u16 control = 0;
  11509. /*
  11510. * If MSI-X is not supported - return number of SBs needed to support
  11511. * one fast path queue: one FP queue + SB for CNIC
  11512. */
  11513. if (!pdev->msix_cap) {
  11514. dev_info(&pdev->dev, "no msix capability found\n");
  11515. return 1 + cnic_cnt;
  11516. }
  11517. dev_info(&pdev->dev, "msix capability found\n");
  11518. /*
  11519. * The value in the PCI configuration space is the index of the last
  11520. * entry, namely one less than the actual size of the table, which is
  11521. * exactly what we want to return from this function: number of all SBs
  11522. * without the default SB.
  11523. * For VFs there is no default SB, then we return (index+1).
  11524. */
  11525. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11526. index = control & PCI_MSIX_FLAGS_QSIZE;
  11527. return index;
  11528. }
  11529. static int set_max_cos_est(int chip_id)
  11530. {
  11531. switch (chip_id) {
  11532. case BCM57710:
  11533. case BCM57711:
  11534. case BCM57711E:
  11535. return BNX2X_MULTI_TX_COS_E1X;
  11536. case BCM57712:
  11537. case BCM57712_MF:
  11538. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11539. case BCM57800:
  11540. case BCM57800_MF:
  11541. case BCM57810:
  11542. case BCM57810_MF:
  11543. case BCM57840_4_10:
  11544. case BCM57840_2_20:
  11545. case BCM57840_O:
  11546. case BCM57840_MFO:
  11547. case BCM57840_MF:
  11548. case BCM57811:
  11549. case BCM57811_MF:
  11550. return BNX2X_MULTI_TX_COS_E3B0;
  11551. case BCM57712_VF:
  11552. case BCM57800_VF:
  11553. case BCM57810_VF:
  11554. case BCM57840_VF:
  11555. case BCM57811_VF:
  11556. return 1;
  11557. default:
  11558. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11559. return -ENODEV;
  11560. }
  11561. }
  11562. static int set_is_vf(int chip_id)
  11563. {
  11564. switch (chip_id) {
  11565. case BCM57712_VF:
  11566. case BCM57800_VF:
  11567. case BCM57810_VF:
  11568. case BCM57840_VF:
  11569. case BCM57811_VF:
  11570. return true;
  11571. default:
  11572. return false;
  11573. }
  11574. }
  11575. /* nig_tsgen registers relative address */
  11576. #define tsgen_ctrl 0x0
  11577. #define tsgen_freecount 0x10
  11578. #define tsgen_synctime_t0 0x20
  11579. #define tsgen_offset_t0 0x28
  11580. #define tsgen_drift_t0 0x30
  11581. #define tsgen_synctime_t1 0x58
  11582. #define tsgen_offset_t1 0x60
  11583. #define tsgen_drift_t1 0x68
  11584. /* FW workaround for setting drift */
  11585. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11586. int best_val, int best_period)
  11587. {
  11588. struct bnx2x_func_state_params func_params = {NULL};
  11589. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11590. &func_params.params.set_timesync;
  11591. /* Prepare parameters for function state transitions */
  11592. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11593. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11594. func_params.f_obj = &bp->func_obj;
  11595. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11596. /* Function parameters */
  11597. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11598. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11599. set_timesync_params->add_sub_drift_adjust_value =
  11600. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11601. set_timesync_params->drift_adjust_value = best_val;
  11602. set_timesync_params->drift_adjust_period = best_period;
  11603. return bnx2x_func_state_change(bp, &func_params);
  11604. }
  11605. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11606. {
  11607. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11608. int rc;
  11609. int drift_dir = 1;
  11610. int val, period, period1, period2, dif, dif1, dif2;
  11611. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11612. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11613. if (!netif_running(bp->dev)) {
  11614. DP(BNX2X_MSG_PTP,
  11615. "PTP adjfreq called while the interface is down\n");
  11616. return -ENETDOWN;
  11617. }
  11618. if (ppb < 0) {
  11619. ppb = -ppb;
  11620. drift_dir = 0;
  11621. }
  11622. if (ppb == 0) {
  11623. best_val = 1;
  11624. best_period = 0x1FFFFFF;
  11625. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11626. best_val = 31;
  11627. best_period = 1;
  11628. } else {
  11629. /* Changed not to allow val = 8, 16, 24 as these values
  11630. * are not supported in workaround.
  11631. */
  11632. for (val = 0; val <= 31; val++) {
  11633. if ((val & 0x7) == 0)
  11634. continue;
  11635. period1 = val * 1000000 / ppb;
  11636. period2 = period1 + 1;
  11637. if (period1 != 0)
  11638. dif1 = ppb - (val * 1000000 / period1);
  11639. else
  11640. dif1 = BNX2X_MAX_PHC_DRIFT;
  11641. if (dif1 < 0)
  11642. dif1 = -dif1;
  11643. dif2 = ppb - (val * 1000000 / period2);
  11644. if (dif2 < 0)
  11645. dif2 = -dif2;
  11646. dif = (dif1 < dif2) ? dif1 : dif2;
  11647. period = (dif1 < dif2) ? period1 : period2;
  11648. if (dif < best_dif) {
  11649. best_dif = dif;
  11650. best_val = val;
  11651. best_period = period;
  11652. }
  11653. }
  11654. }
  11655. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11656. best_period);
  11657. if (rc) {
  11658. BNX2X_ERR("Failed to set drift\n");
  11659. return -EFAULT;
  11660. }
  11661. DP(BNX2X_MSG_PTP, "Configured val = %d, period = %d\n", best_val,
  11662. best_period);
  11663. return 0;
  11664. }
  11665. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11666. {
  11667. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11668. if (!netif_running(bp->dev)) {
  11669. DP(BNX2X_MSG_PTP,
  11670. "PTP adjtime called while the interface is down\n");
  11671. return -ENETDOWN;
  11672. }
  11673. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11674. timecounter_adjtime(&bp->timecounter, delta);
  11675. return 0;
  11676. }
  11677. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
  11678. {
  11679. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11680. u64 ns;
  11681. if (!netif_running(bp->dev)) {
  11682. DP(BNX2X_MSG_PTP,
  11683. "PTP gettime called while the interface is down\n");
  11684. return -ENETDOWN;
  11685. }
  11686. ns = timecounter_read(&bp->timecounter);
  11687. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11688. *ts = ns_to_timespec64(ns);
  11689. return 0;
  11690. }
  11691. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11692. const struct timespec64 *ts)
  11693. {
  11694. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11695. u64 ns;
  11696. if (!netif_running(bp->dev)) {
  11697. DP(BNX2X_MSG_PTP,
  11698. "PTP settime called while the interface is down\n");
  11699. return -ENETDOWN;
  11700. }
  11701. ns = timespec64_to_ns(ts);
  11702. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11703. /* Re-init the timecounter */
  11704. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11705. return 0;
  11706. }
  11707. /* Enable (or disable) ancillary features of the phc subsystem */
  11708. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11709. struct ptp_clock_request *rq, int on)
  11710. {
  11711. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11712. BNX2X_ERR("PHC ancillary features are not supported\n");
  11713. return -ENOTSUPP;
  11714. }
  11715. static void bnx2x_register_phc(struct bnx2x *bp)
  11716. {
  11717. /* Fill the ptp_clock_info struct and register PTP clock*/
  11718. bp->ptp_clock_info.owner = THIS_MODULE;
  11719. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11720. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11721. bp->ptp_clock_info.n_alarm = 0;
  11722. bp->ptp_clock_info.n_ext_ts = 0;
  11723. bp->ptp_clock_info.n_per_out = 0;
  11724. bp->ptp_clock_info.pps = 0;
  11725. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11726. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11727. bp->ptp_clock_info.gettime64 = bnx2x_ptp_gettime;
  11728. bp->ptp_clock_info.settime64 = bnx2x_ptp_settime;
  11729. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11730. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11731. if (IS_ERR(bp->ptp_clock)) {
  11732. bp->ptp_clock = NULL;
  11733. BNX2X_ERR("PTP clock registration failed\n");
  11734. }
  11735. }
  11736. static int bnx2x_init_one(struct pci_dev *pdev,
  11737. const struct pci_device_id *ent)
  11738. {
  11739. struct net_device *dev = NULL;
  11740. struct bnx2x *bp;
  11741. int rc, max_non_def_sbs;
  11742. int rx_count, tx_count, rss_count, doorbell_size;
  11743. int max_cos_est;
  11744. bool is_vf;
  11745. int cnic_cnt;
  11746. /* Management FW 'remembers' living interfaces. Allow it some time
  11747. * to forget previously living interfaces, allowing a proper re-load.
  11748. */
  11749. if (is_kdump_kernel()) {
  11750. ktime_t now = ktime_get_boottime();
  11751. ktime_t fw_ready_time = ktime_set(5, 0);
  11752. if (ktime_before(now, fw_ready_time))
  11753. msleep(ktime_ms_delta(fw_ready_time, now));
  11754. }
  11755. /* An estimated maximum supported CoS number according to the chip
  11756. * version.
  11757. * We will try to roughly estimate the maximum number of CoSes this chip
  11758. * may support in order to minimize the memory allocated for Tx
  11759. * netdev_queue's. This number will be accurately calculated during the
  11760. * initialization of bp->max_cos based on the chip versions AND chip
  11761. * revision in the bnx2x_init_bp().
  11762. */
  11763. max_cos_est = set_max_cos_est(ent->driver_data);
  11764. if (max_cos_est < 0)
  11765. return max_cos_est;
  11766. is_vf = set_is_vf(ent->driver_data);
  11767. cnic_cnt = is_vf ? 0 : 1;
  11768. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11769. /* add another SB for VF as it has no default SB */
  11770. max_non_def_sbs += is_vf ? 1 : 0;
  11771. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11772. rss_count = max_non_def_sbs - cnic_cnt;
  11773. if (rss_count < 1)
  11774. return -EINVAL;
  11775. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11776. rx_count = rss_count + cnic_cnt;
  11777. /* Maximum number of netdev Tx queues:
  11778. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11779. */
  11780. tx_count = rss_count * max_cos_est + cnic_cnt;
  11781. /* dev zeroed in init_etherdev */
  11782. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11783. if (!dev)
  11784. return -ENOMEM;
  11785. bp = netdev_priv(dev);
  11786. bp->flags = 0;
  11787. if (is_vf)
  11788. bp->flags |= IS_VF_FLAG;
  11789. bp->igu_sb_cnt = max_non_def_sbs;
  11790. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11791. bp->msg_enable = debug;
  11792. bp->cnic_support = cnic_cnt;
  11793. bp->cnic_probe = bnx2x_cnic_probe;
  11794. pci_set_drvdata(pdev, dev);
  11795. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11796. if (rc < 0) {
  11797. free_netdev(dev);
  11798. return rc;
  11799. }
  11800. BNX2X_DEV_INFO("This is a %s function\n",
  11801. IS_PF(bp) ? "physical" : "virtual");
  11802. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11803. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11804. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11805. tx_count, rx_count);
  11806. rc = bnx2x_init_bp(bp);
  11807. if (rc)
  11808. goto init_one_exit;
  11809. /* Map doorbells here as we need the real value of bp->max_cos which
  11810. * is initialized in bnx2x_init_bp() to determine the number of
  11811. * l2 connections.
  11812. */
  11813. if (IS_VF(bp)) {
  11814. bp->doorbells = bnx2x_vf_doorbells(bp);
  11815. rc = bnx2x_vf_pci_alloc(bp);
  11816. if (rc)
  11817. goto init_one_freemem;
  11818. } else {
  11819. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11820. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11821. dev_err(&bp->pdev->dev,
  11822. "Cannot map doorbells, bar size too small, aborting\n");
  11823. rc = -ENOMEM;
  11824. goto init_one_freemem;
  11825. }
  11826. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11827. doorbell_size);
  11828. }
  11829. if (!bp->doorbells) {
  11830. dev_err(&bp->pdev->dev,
  11831. "Cannot map doorbell space, aborting\n");
  11832. rc = -ENOMEM;
  11833. goto init_one_freemem;
  11834. }
  11835. if (IS_VF(bp)) {
  11836. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11837. if (rc)
  11838. goto init_one_freemem;
  11839. #ifdef CONFIG_BNX2X_SRIOV
  11840. /* VF with OLD Hypervisor or old PF do not support filtering */
  11841. if (bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER) {
  11842. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11843. dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11844. }
  11845. #endif
  11846. }
  11847. /* Enable SRIOV if capability found in configuration space */
  11848. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11849. if (rc)
  11850. goto init_one_freemem;
  11851. /* calc qm_cid_count */
  11852. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11853. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11854. /* disable FCOE L2 queue for E1x*/
  11855. if (CHIP_IS_E1x(bp))
  11856. bp->flags |= NO_FCOE_FLAG;
  11857. /* Set bp->num_queues for MSI-X mode*/
  11858. bnx2x_set_num_queues(bp);
  11859. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11860. * needed.
  11861. */
  11862. rc = bnx2x_set_int_mode(bp);
  11863. if (rc) {
  11864. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11865. goto init_one_freemem;
  11866. }
  11867. BNX2X_DEV_INFO("set interrupts successfully\n");
  11868. /* register the net device */
  11869. rc = register_netdev(dev);
  11870. if (rc) {
  11871. dev_err(&pdev->dev, "Cannot register net device\n");
  11872. goto init_one_freemem;
  11873. }
  11874. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11875. if (!NO_FCOE(bp)) {
  11876. /* Add storage MAC address */
  11877. rtnl_lock();
  11878. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11879. rtnl_unlock();
  11880. }
  11881. BNX2X_DEV_INFO(
  11882. "%s (%c%d) PCI-E found at mem %lx, IRQ %d, node addr %pM\n",
  11883. board_info[ent->driver_data].name,
  11884. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11885. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11886. pcie_print_link_status(bp->pdev);
  11887. bnx2x_register_phc(bp);
  11888. if (!IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp))
  11889. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_DISABLED);
  11890. return 0;
  11891. init_one_freemem:
  11892. bnx2x_free_mem_bp(bp);
  11893. init_one_exit:
  11894. bnx2x_disable_pcie_error_reporting(bp);
  11895. if (bp->regview)
  11896. iounmap(bp->regview);
  11897. if (IS_PF(bp) && bp->doorbells)
  11898. iounmap(bp->doorbells);
  11899. free_netdev(dev);
  11900. if (atomic_read(&pdev->enable_cnt) == 1)
  11901. pci_release_regions(pdev);
  11902. pci_disable_device(pdev);
  11903. return rc;
  11904. }
  11905. static void __bnx2x_remove(struct pci_dev *pdev,
  11906. struct net_device *dev,
  11907. struct bnx2x *bp,
  11908. bool remove_netdev)
  11909. {
  11910. if (bp->ptp_clock) {
  11911. ptp_clock_unregister(bp->ptp_clock);
  11912. bp->ptp_clock = NULL;
  11913. }
  11914. /* Delete storage MAC address */
  11915. if (!NO_FCOE(bp)) {
  11916. rtnl_lock();
  11917. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11918. rtnl_unlock();
  11919. }
  11920. #ifdef BCM_DCBNL
  11921. /* Delete app tlvs from dcbnl */
  11922. bnx2x_dcbnl_update_applist(bp, true);
  11923. #endif
  11924. if (IS_PF(bp) &&
  11925. !BP_NOMCP(bp) &&
  11926. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11927. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11928. /* Close the interface - either directly or implicitly */
  11929. if (remove_netdev) {
  11930. unregister_netdev(dev);
  11931. } else {
  11932. rtnl_lock();
  11933. dev_close(dev);
  11934. rtnl_unlock();
  11935. }
  11936. bnx2x_iov_remove_one(bp);
  11937. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11938. if (IS_PF(bp)) {
  11939. bnx2x_set_power_state(bp, PCI_D0);
  11940. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_NOT_LOADED);
  11941. /* Set endianity registers to reset values in case next driver
  11942. * boots in different endianty environment.
  11943. */
  11944. bnx2x_reset_endianity(bp);
  11945. }
  11946. /* Disable MSI/MSI-X */
  11947. bnx2x_disable_msi(bp);
  11948. /* Power off */
  11949. if (IS_PF(bp))
  11950. bnx2x_set_power_state(bp, PCI_D3hot);
  11951. /* Make sure RESET task is not scheduled before continuing */
  11952. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11953. /* send message via vfpf channel to release the resources of this vf */
  11954. if (IS_VF(bp))
  11955. bnx2x_vfpf_release(bp);
  11956. /* Assumes no further PCIe PM changes will occur */
  11957. if (system_state == SYSTEM_POWER_OFF) {
  11958. pci_wake_from_d3(pdev, bp->wol);
  11959. pci_set_power_state(pdev, PCI_D3hot);
  11960. }
  11961. bnx2x_disable_pcie_error_reporting(bp);
  11962. if (remove_netdev) {
  11963. if (bp->regview)
  11964. iounmap(bp->regview);
  11965. /* For vfs, doorbells are part of the regview and were unmapped
  11966. * along with it. FW is only loaded by PF.
  11967. */
  11968. if (IS_PF(bp)) {
  11969. if (bp->doorbells)
  11970. iounmap(bp->doorbells);
  11971. bnx2x_release_firmware(bp);
  11972. } else {
  11973. bnx2x_vf_pci_dealloc(bp);
  11974. }
  11975. bnx2x_free_mem_bp(bp);
  11976. free_netdev(dev);
  11977. if (atomic_read(&pdev->enable_cnt) == 1)
  11978. pci_release_regions(pdev);
  11979. pci_disable_device(pdev);
  11980. }
  11981. }
  11982. static void bnx2x_remove_one(struct pci_dev *pdev)
  11983. {
  11984. struct net_device *dev = pci_get_drvdata(pdev);
  11985. struct bnx2x *bp;
  11986. if (!dev) {
  11987. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11988. return;
  11989. }
  11990. bp = netdev_priv(dev);
  11991. __bnx2x_remove(pdev, dev, bp, true);
  11992. }
  11993. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11994. {
  11995. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11996. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11997. if (CNIC_LOADED(bp))
  11998. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11999. /* Stop Tx */
  12000. bnx2x_tx_disable(bp);
  12001. /* Delete all NAPI objects */
  12002. bnx2x_del_all_napi(bp);
  12003. if (CNIC_LOADED(bp))
  12004. bnx2x_del_all_napi_cnic(bp);
  12005. netdev_reset_tc(bp->dev);
  12006. del_timer_sync(&bp->timer);
  12007. cancel_delayed_work_sync(&bp->sp_task);
  12008. cancel_delayed_work_sync(&bp->period_task);
  12009. if (!down_timeout(&bp->stats_lock, HZ / 10)) {
  12010. bp->stats_state = STATS_STATE_DISABLED;
  12011. up(&bp->stats_lock);
  12012. }
  12013. bnx2x_save_statistics(bp);
  12014. netif_carrier_off(bp->dev);
  12015. return 0;
  12016. }
  12017. /**
  12018. * bnx2x_io_error_detected - called when PCI error is detected
  12019. * @pdev: Pointer to PCI device
  12020. * @state: The current pci connection state
  12021. *
  12022. * This function is called after a PCI bus error affecting
  12023. * this device has been detected.
  12024. */
  12025. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  12026. pci_channel_state_t state)
  12027. {
  12028. struct net_device *dev = pci_get_drvdata(pdev);
  12029. struct bnx2x *bp = netdev_priv(dev);
  12030. rtnl_lock();
  12031. BNX2X_ERR("IO error detected\n");
  12032. netif_device_detach(dev);
  12033. if (state == pci_channel_io_perm_failure) {
  12034. rtnl_unlock();
  12035. return PCI_ERS_RESULT_DISCONNECT;
  12036. }
  12037. if (netif_running(dev))
  12038. bnx2x_eeh_nic_unload(bp);
  12039. bnx2x_prev_path_mark_eeh(bp);
  12040. pci_disable_device(pdev);
  12041. rtnl_unlock();
  12042. /* Request a slot reset */
  12043. return PCI_ERS_RESULT_NEED_RESET;
  12044. }
  12045. /**
  12046. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  12047. * @pdev: Pointer to PCI device
  12048. *
  12049. * Restart the card from scratch, as if from a cold-boot.
  12050. */
  12051. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  12052. {
  12053. struct net_device *dev = pci_get_drvdata(pdev);
  12054. struct bnx2x *bp = netdev_priv(dev);
  12055. int i;
  12056. rtnl_lock();
  12057. BNX2X_ERR("IO slot reset initializing...\n");
  12058. if (pci_enable_device(pdev)) {
  12059. dev_err(&pdev->dev,
  12060. "Cannot re-enable PCI device after reset\n");
  12061. rtnl_unlock();
  12062. return PCI_ERS_RESULT_DISCONNECT;
  12063. }
  12064. pci_set_master(pdev);
  12065. pci_restore_state(pdev);
  12066. pci_save_state(pdev);
  12067. if (netif_running(dev))
  12068. bnx2x_set_power_state(bp, PCI_D0);
  12069. if (netif_running(dev)) {
  12070. BNX2X_ERR("IO slot reset --> driver unload\n");
  12071. /* MCP should have been reset; Need to wait for validity */
  12072. if (bnx2x_init_shmem(bp)) {
  12073. rtnl_unlock();
  12074. return PCI_ERS_RESULT_DISCONNECT;
  12075. }
  12076. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  12077. u32 v;
  12078. v = SHMEM2_RD(bp,
  12079. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  12080. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  12081. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  12082. }
  12083. bnx2x_drain_tx_queues(bp);
  12084. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  12085. bnx2x_netif_stop(bp, 1);
  12086. bnx2x_free_irq(bp);
  12087. /* Report UNLOAD_DONE to MCP */
  12088. bnx2x_send_unload_done(bp, true);
  12089. bp->sp_state = 0;
  12090. bp->port.pmf = 0;
  12091. bnx2x_prev_unload(bp);
  12092. /* We should have reseted the engine, so It's fair to
  12093. * assume the FW will no longer write to the bnx2x driver.
  12094. */
  12095. bnx2x_squeeze_objects(bp);
  12096. bnx2x_free_skbs(bp);
  12097. for_each_rx_queue(bp, i)
  12098. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  12099. bnx2x_free_fp_mem(bp);
  12100. bnx2x_free_mem(bp);
  12101. bp->state = BNX2X_STATE_CLOSED;
  12102. }
  12103. rtnl_unlock();
  12104. /* If AER, perform cleanup of the PCIe registers */
  12105. if (bp->flags & AER_ENABLED) {
  12106. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  12107. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  12108. else
  12109. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  12110. }
  12111. return PCI_ERS_RESULT_RECOVERED;
  12112. }
  12113. /**
  12114. * bnx2x_io_resume - called when traffic can start flowing again
  12115. * @pdev: Pointer to PCI device
  12116. *
  12117. * This callback is called when the error recovery driver tells us that
  12118. * its OK to resume normal operation.
  12119. */
  12120. static void bnx2x_io_resume(struct pci_dev *pdev)
  12121. {
  12122. struct net_device *dev = pci_get_drvdata(pdev);
  12123. struct bnx2x *bp = netdev_priv(dev);
  12124. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  12125. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  12126. return;
  12127. }
  12128. rtnl_lock();
  12129. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  12130. DRV_MSG_SEQ_NUMBER_MASK;
  12131. if (netif_running(dev))
  12132. bnx2x_nic_load(bp, LOAD_NORMAL);
  12133. netif_device_attach(dev);
  12134. rtnl_unlock();
  12135. }
  12136. static const struct pci_error_handlers bnx2x_err_handler = {
  12137. .error_detected = bnx2x_io_error_detected,
  12138. .slot_reset = bnx2x_io_slot_reset,
  12139. .resume = bnx2x_io_resume,
  12140. };
  12141. static void bnx2x_shutdown(struct pci_dev *pdev)
  12142. {
  12143. struct net_device *dev = pci_get_drvdata(pdev);
  12144. struct bnx2x *bp;
  12145. if (!dev)
  12146. return;
  12147. bp = netdev_priv(dev);
  12148. if (!bp)
  12149. return;
  12150. rtnl_lock();
  12151. netif_device_detach(dev);
  12152. rtnl_unlock();
  12153. /* Don't remove the netdevice, as there are scenarios which will cause
  12154. * the kernel to hang, e.g., when trying to remove bnx2i while the
  12155. * rootfs is mounted from SAN.
  12156. */
  12157. __bnx2x_remove(pdev, dev, bp, false);
  12158. }
  12159. static struct pci_driver bnx2x_pci_driver = {
  12160. .name = DRV_MODULE_NAME,
  12161. .id_table = bnx2x_pci_tbl,
  12162. .probe = bnx2x_init_one,
  12163. .remove = bnx2x_remove_one,
  12164. .suspend = bnx2x_suspend,
  12165. .resume = bnx2x_resume,
  12166. .err_handler = &bnx2x_err_handler,
  12167. #ifdef CONFIG_BNX2X_SRIOV
  12168. .sriov_configure = bnx2x_sriov_configure,
  12169. #endif
  12170. .shutdown = bnx2x_shutdown,
  12171. };
  12172. static int __init bnx2x_init(void)
  12173. {
  12174. int ret;
  12175. pr_info("%s", version);
  12176. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  12177. if (bnx2x_wq == NULL) {
  12178. pr_err("Cannot create workqueue\n");
  12179. return -ENOMEM;
  12180. }
  12181. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  12182. if (!bnx2x_iov_wq) {
  12183. pr_err("Cannot create iov workqueue\n");
  12184. destroy_workqueue(bnx2x_wq);
  12185. return -ENOMEM;
  12186. }
  12187. ret = pci_register_driver(&bnx2x_pci_driver);
  12188. if (ret) {
  12189. pr_err("Cannot register driver\n");
  12190. destroy_workqueue(bnx2x_wq);
  12191. destroy_workqueue(bnx2x_iov_wq);
  12192. }
  12193. return ret;
  12194. }
  12195. static void __exit bnx2x_cleanup(void)
  12196. {
  12197. struct list_head *pos, *q;
  12198. pci_unregister_driver(&bnx2x_pci_driver);
  12199. destroy_workqueue(bnx2x_wq);
  12200. destroy_workqueue(bnx2x_iov_wq);
  12201. /* Free globally allocated resources */
  12202. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  12203. struct bnx2x_prev_path_list *tmp =
  12204. list_entry(pos, struct bnx2x_prev_path_list, list);
  12205. list_del(pos);
  12206. kfree(tmp);
  12207. }
  12208. }
  12209. void bnx2x_notify_link_changed(struct bnx2x *bp)
  12210. {
  12211. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  12212. }
  12213. module_init(bnx2x_init);
  12214. module_exit(bnx2x_cleanup);
  12215. /**
  12216. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  12217. *
  12218. * @bp: driver handle
  12219. * @set: set or clear the CAM entry
  12220. *
  12221. * This function will wait until the ramrod completion returns.
  12222. * Return 0 if success, -ENODEV if ramrod doesn't return.
  12223. */
  12224. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  12225. {
  12226. unsigned long ramrod_flags = 0;
  12227. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  12228. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  12229. &bp->iscsi_l2_mac_obj, true,
  12230. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  12231. }
  12232. /* count denotes the number of new completions we have seen */
  12233. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  12234. {
  12235. struct eth_spe *spe;
  12236. int cxt_index, cxt_offset;
  12237. #ifdef BNX2X_STOP_ON_ERROR
  12238. if (unlikely(bp->panic))
  12239. return;
  12240. #endif
  12241. spin_lock_bh(&bp->spq_lock);
  12242. BUG_ON(bp->cnic_spq_pending < count);
  12243. bp->cnic_spq_pending -= count;
  12244. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  12245. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  12246. & SPE_HDR_CONN_TYPE) >>
  12247. SPE_HDR_CONN_TYPE_SHIFT;
  12248. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  12249. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  12250. /* Set validation for iSCSI L2 client before sending SETUP
  12251. * ramrod
  12252. */
  12253. if (type == ETH_CONNECTION_TYPE) {
  12254. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  12255. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  12256. ILT_PAGE_CIDS;
  12257. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  12258. (cxt_index * ILT_PAGE_CIDS);
  12259. bnx2x_set_ctx_validation(bp,
  12260. &bp->context[cxt_index].
  12261. vcxt[cxt_offset].eth,
  12262. BNX2X_ISCSI_ETH_CID(bp));
  12263. }
  12264. }
  12265. /*
  12266. * There may be not more than 8 L2, not more than 8 L5 SPEs
  12267. * and in the air. We also check that number of outstanding
  12268. * COMMON ramrods is not more than the EQ and SPQ can
  12269. * accommodate.
  12270. */
  12271. if (type == ETH_CONNECTION_TYPE) {
  12272. if (!atomic_read(&bp->cq_spq_left))
  12273. break;
  12274. else
  12275. atomic_dec(&bp->cq_spq_left);
  12276. } else if (type == NONE_CONNECTION_TYPE) {
  12277. if (!atomic_read(&bp->eq_spq_left))
  12278. break;
  12279. else
  12280. atomic_dec(&bp->eq_spq_left);
  12281. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  12282. (type == FCOE_CONNECTION_TYPE)) {
  12283. if (bp->cnic_spq_pending >=
  12284. bp->cnic_eth_dev.max_kwqe_pending)
  12285. break;
  12286. else
  12287. bp->cnic_spq_pending++;
  12288. } else {
  12289. BNX2X_ERR("Unknown SPE type: %d\n", type);
  12290. bnx2x_panic();
  12291. break;
  12292. }
  12293. spe = bnx2x_sp_get_next(bp);
  12294. *spe = *bp->cnic_kwq_cons;
  12295. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  12296. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  12297. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  12298. bp->cnic_kwq_cons = bp->cnic_kwq;
  12299. else
  12300. bp->cnic_kwq_cons++;
  12301. }
  12302. bnx2x_sp_prod_update(bp);
  12303. spin_unlock_bh(&bp->spq_lock);
  12304. }
  12305. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  12306. struct kwqe_16 *kwqes[], u32 count)
  12307. {
  12308. struct bnx2x *bp = netdev_priv(dev);
  12309. int i;
  12310. #ifdef BNX2X_STOP_ON_ERROR
  12311. if (unlikely(bp->panic)) {
  12312. BNX2X_ERR("Can't post to SP queue while panic\n");
  12313. return -EIO;
  12314. }
  12315. #endif
  12316. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  12317. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  12318. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  12319. return -EAGAIN;
  12320. }
  12321. spin_lock_bh(&bp->spq_lock);
  12322. for (i = 0; i < count; i++) {
  12323. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  12324. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  12325. break;
  12326. *bp->cnic_kwq_prod = *spe;
  12327. bp->cnic_kwq_pending++;
  12328. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  12329. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  12330. spe->data.update_data_addr.hi,
  12331. spe->data.update_data_addr.lo,
  12332. bp->cnic_kwq_pending);
  12333. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  12334. bp->cnic_kwq_prod = bp->cnic_kwq;
  12335. else
  12336. bp->cnic_kwq_prod++;
  12337. }
  12338. spin_unlock_bh(&bp->spq_lock);
  12339. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  12340. bnx2x_cnic_sp_post(bp, 0);
  12341. return i;
  12342. }
  12343. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12344. {
  12345. struct cnic_ops *c_ops;
  12346. int rc = 0;
  12347. mutex_lock(&bp->cnic_mutex);
  12348. c_ops = rcu_dereference_protected(bp->cnic_ops,
  12349. lockdep_is_held(&bp->cnic_mutex));
  12350. if (c_ops)
  12351. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12352. mutex_unlock(&bp->cnic_mutex);
  12353. return rc;
  12354. }
  12355. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12356. {
  12357. struct cnic_ops *c_ops;
  12358. int rc = 0;
  12359. rcu_read_lock();
  12360. c_ops = rcu_dereference(bp->cnic_ops);
  12361. if (c_ops)
  12362. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12363. rcu_read_unlock();
  12364. return rc;
  12365. }
  12366. /*
  12367. * for commands that have no data
  12368. */
  12369. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  12370. {
  12371. struct cnic_ctl_info ctl = {0};
  12372. ctl.cmd = cmd;
  12373. return bnx2x_cnic_ctl_send(bp, &ctl);
  12374. }
  12375. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  12376. {
  12377. struct cnic_ctl_info ctl = {0};
  12378. /* first we tell CNIC and only then we count this as a completion */
  12379. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  12380. ctl.data.comp.cid = cid;
  12381. ctl.data.comp.error = err;
  12382. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  12383. bnx2x_cnic_sp_post(bp, 0);
  12384. }
  12385. /* Called with netif_addr_lock_bh() taken.
  12386. * Sets an rx_mode config for an iSCSI ETH client.
  12387. * Doesn't block.
  12388. * Completion should be checked outside.
  12389. */
  12390. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  12391. {
  12392. unsigned long accept_flags = 0, ramrod_flags = 0;
  12393. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12394. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  12395. if (start) {
  12396. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  12397. * because it's the only way for UIO Queue to accept
  12398. * multicasts (in non-promiscuous mode only one Queue per
  12399. * function will receive multicast packets (leading in our
  12400. * case).
  12401. */
  12402. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  12403. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  12404. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  12405. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  12406. /* Clear STOP_PENDING bit if START is requested */
  12407. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  12408. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  12409. } else
  12410. /* Clear START_PENDING bit if STOP is requested */
  12411. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  12412. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  12413. set_bit(sched_state, &bp->sp_state);
  12414. else {
  12415. __set_bit(RAMROD_RX, &ramrod_flags);
  12416. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  12417. ramrod_flags);
  12418. }
  12419. }
  12420. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  12421. {
  12422. struct bnx2x *bp = netdev_priv(dev);
  12423. int rc = 0;
  12424. switch (ctl->cmd) {
  12425. case DRV_CTL_CTXTBL_WR_CMD: {
  12426. u32 index = ctl->data.io.offset;
  12427. dma_addr_t addr = ctl->data.io.dma_addr;
  12428. bnx2x_ilt_wr(bp, index, addr);
  12429. break;
  12430. }
  12431. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  12432. int count = ctl->data.credit.credit_count;
  12433. bnx2x_cnic_sp_post(bp, count);
  12434. break;
  12435. }
  12436. /* rtnl_lock is held. */
  12437. case DRV_CTL_START_L2_CMD: {
  12438. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12439. unsigned long sp_bits = 0;
  12440. /* Configure the iSCSI classification object */
  12441. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  12442. cp->iscsi_l2_client_id,
  12443. cp->iscsi_l2_cid, BP_FUNC(bp),
  12444. bnx2x_sp(bp, mac_rdata),
  12445. bnx2x_sp_mapping(bp, mac_rdata),
  12446. BNX2X_FILTER_MAC_PENDING,
  12447. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  12448. &bp->macs_pool);
  12449. /* Set iSCSI MAC address */
  12450. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  12451. if (rc)
  12452. break;
  12453. mmiowb();
  12454. barrier();
  12455. /* Start accepting on iSCSI L2 ring */
  12456. netif_addr_lock_bh(dev);
  12457. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  12458. netif_addr_unlock_bh(dev);
  12459. /* bits to wait on */
  12460. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12461. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  12462. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12463. BNX2X_ERR("rx_mode completion timed out!\n");
  12464. break;
  12465. }
  12466. /* rtnl_lock is held. */
  12467. case DRV_CTL_STOP_L2_CMD: {
  12468. unsigned long sp_bits = 0;
  12469. /* Stop accepting on iSCSI L2 ring */
  12470. netif_addr_lock_bh(dev);
  12471. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  12472. netif_addr_unlock_bh(dev);
  12473. /* bits to wait on */
  12474. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12475. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  12476. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12477. BNX2X_ERR("rx_mode completion timed out!\n");
  12478. mmiowb();
  12479. barrier();
  12480. /* Unset iSCSI L2 MAC */
  12481. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  12482. BNX2X_ISCSI_ETH_MAC, true);
  12483. break;
  12484. }
  12485. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  12486. int count = ctl->data.credit.credit_count;
  12487. smp_mb__before_atomic();
  12488. atomic_add(count, &bp->cq_spq_left);
  12489. smp_mb__after_atomic();
  12490. break;
  12491. }
  12492. case DRV_CTL_ULP_REGISTER_CMD: {
  12493. int ulp_type = ctl->data.register_data.ulp_type;
  12494. if (CHIP_IS_E3(bp)) {
  12495. int idx = BP_FW_MB_IDX(bp);
  12496. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12497. int path = BP_PATH(bp);
  12498. int port = BP_PORT(bp);
  12499. int i;
  12500. u32 scratch_offset;
  12501. u32 *host_addr;
  12502. /* first write capability to shmem2 */
  12503. if (ulp_type == CNIC_ULP_ISCSI)
  12504. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12505. else if (ulp_type == CNIC_ULP_FCOE)
  12506. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12507. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12508. if ((ulp_type != CNIC_ULP_FCOE) ||
  12509. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  12510. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  12511. break;
  12512. /* if reached here - should write fcoe capabilities */
  12513. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  12514. if (!scratch_offset)
  12515. break;
  12516. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  12517. fcoe_features[path][port]);
  12518. host_addr = (u32 *) &(ctl->data.register_data.
  12519. fcoe_features);
  12520. for (i = 0; i < sizeof(struct fcoe_capabilities);
  12521. i += 4)
  12522. REG_WR(bp, scratch_offset + i,
  12523. *(host_addr + i/4));
  12524. }
  12525. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12526. break;
  12527. }
  12528. case DRV_CTL_ULP_UNREGISTER_CMD: {
  12529. int ulp_type = ctl->data.ulp_type;
  12530. if (CHIP_IS_E3(bp)) {
  12531. int idx = BP_FW_MB_IDX(bp);
  12532. u32 cap;
  12533. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12534. if (ulp_type == CNIC_ULP_ISCSI)
  12535. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12536. else if (ulp_type == CNIC_ULP_FCOE)
  12537. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12538. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12539. }
  12540. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12541. break;
  12542. }
  12543. default:
  12544. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12545. rc = -EINVAL;
  12546. }
  12547. /* For storage-only interfaces, change driver state */
  12548. if (IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp)) {
  12549. switch (ctl->drv_state) {
  12550. case DRV_NOP:
  12551. break;
  12552. case DRV_ACTIVE:
  12553. bnx2x_set_os_driver_state(bp,
  12554. OS_DRIVER_STATE_ACTIVE);
  12555. break;
  12556. case DRV_INACTIVE:
  12557. bnx2x_set_os_driver_state(bp,
  12558. OS_DRIVER_STATE_DISABLED);
  12559. break;
  12560. case DRV_UNLOADED:
  12561. bnx2x_set_os_driver_state(bp,
  12562. OS_DRIVER_STATE_NOT_LOADED);
  12563. break;
  12564. default:
  12565. BNX2X_ERR("Unknown cnic driver state: %d\n", ctl->drv_state);
  12566. }
  12567. }
  12568. return rc;
  12569. }
  12570. static int bnx2x_get_fc_npiv(struct net_device *dev,
  12571. struct cnic_fc_npiv_tbl *cnic_tbl)
  12572. {
  12573. struct bnx2x *bp = netdev_priv(dev);
  12574. struct bdn_fc_npiv_tbl *tbl = NULL;
  12575. u32 offset, entries;
  12576. int rc = -EINVAL;
  12577. int i;
  12578. if (!SHMEM2_HAS(bp, fc_npiv_nvram_tbl_addr[0]))
  12579. goto out;
  12580. DP(BNX2X_MSG_MCP, "About to read the FC-NPIV table\n");
  12581. tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
  12582. if (!tbl) {
  12583. BNX2X_ERR("Failed to allocate fc_npiv table\n");
  12584. goto out;
  12585. }
  12586. offset = SHMEM2_RD(bp, fc_npiv_nvram_tbl_addr[BP_PORT(bp)]);
  12587. if (!offset) {
  12588. DP(BNX2X_MSG_MCP, "No FC-NPIV in NVRAM\n");
  12589. goto out;
  12590. }
  12591. DP(BNX2X_MSG_MCP, "Offset of FC-NPIV in NVRAM: %08x\n", offset);
  12592. /* Read the table contents from nvram */
  12593. if (bnx2x_nvram_read(bp, offset, (u8 *)tbl, sizeof(*tbl))) {
  12594. BNX2X_ERR("Failed to read FC-NPIV table\n");
  12595. goto out;
  12596. }
  12597. /* Since bnx2x_nvram_read() returns data in be32, we need to convert
  12598. * the number of entries back to cpu endianness.
  12599. */
  12600. entries = tbl->fc_npiv_cfg.num_of_npiv;
  12601. entries = (__force u32)be32_to_cpu((__force __be32)entries);
  12602. tbl->fc_npiv_cfg.num_of_npiv = entries;
  12603. if (!tbl->fc_npiv_cfg.num_of_npiv) {
  12604. DP(BNX2X_MSG_MCP,
  12605. "No FC-NPIV table [valid, simply not present]\n");
  12606. goto out;
  12607. } else if (tbl->fc_npiv_cfg.num_of_npiv > MAX_NUMBER_NPIV) {
  12608. BNX2X_ERR("FC-NPIV table with bad length 0x%08x\n",
  12609. tbl->fc_npiv_cfg.num_of_npiv);
  12610. goto out;
  12611. } else {
  12612. DP(BNX2X_MSG_MCP, "Read 0x%08x entries from NVRAM\n",
  12613. tbl->fc_npiv_cfg.num_of_npiv);
  12614. }
  12615. /* Copy the data into cnic-provided struct */
  12616. cnic_tbl->count = tbl->fc_npiv_cfg.num_of_npiv;
  12617. for (i = 0; i < cnic_tbl->count; i++) {
  12618. memcpy(cnic_tbl->wwpn[i], tbl->settings[i].npiv_wwpn, 8);
  12619. memcpy(cnic_tbl->wwnn[i], tbl->settings[i].npiv_wwnn, 8);
  12620. }
  12621. rc = 0;
  12622. out:
  12623. kfree(tbl);
  12624. return rc;
  12625. }
  12626. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12627. {
  12628. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12629. if (bp->flags & USING_MSIX_FLAG) {
  12630. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12631. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12632. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12633. } else {
  12634. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12635. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12636. }
  12637. if (!CHIP_IS_E1x(bp))
  12638. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12639. else
  12640. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12641. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12642. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12643. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12644. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12645. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12646. cp->num_irq = 2;
  12647. }
  12648. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12649. {
  12650. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12651. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12652. bnx2x_cid_ilt_lines(bp);
  12653. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12654. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12655. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12656. 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",
  12657. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12658. cp->iscsi_l2_cid);
  12659. if (NO_ISCSI_OOO(bp))
  12660. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12661. }
  12662. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12663. void *data)
  12664. {
  12665. struct bnx2x *bp = netdev_priv(dev);
  12666. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12667. int rc;
  12668. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12669. if (ops == NULL) {
  12670. BNX2X_ERR("NULL ops received\n");
  12671. return -EINVAL;
  12672. }
  12673. if (!CNIC_SUPPORT(bp)) {
  12674. BNX2X_ERR("Can't register CNIC when not supported\n");
  12675. return -EOPNOTSUPP;
  12676. }
  12677. if (!CNIC_LOADED(bp)) {
  12678. rc = bnx2x_load_cnic(bp);
  12679. if (rc) {
  12680. BNX2X_ERR("CNIC-related load failed\n");
  12681. return rc;
  12682. }
  12683. }
  12684. bp->cnic_enabled = true;
  12685. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12686. if (!bp->cnic_kwq)
  12687. return -ENOMEM;
  12688. bp->cnic_kwq_cons = bp->cnic_kwq;
  12689. bp->cnic_kwq_prod = bp->cnic_kwq;
  12690. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12691. bp->cnic_spq_pending = 0;
  12692. bp->cnic_kwq_pending = 0;
  12693. bp->cnic_data = data;
  12694. cp->num_irq = 0;
  12695. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12696. cp->iro_arr = bp->iro_arr;
  12697. bnx2x_setup_cnic_irq_info(bp);
  12698. rcu_assign_pointer(bp->cnic_ops, ops);
  12699. /* Schedule driver to read CNIC driver versions */
  12700. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12701. return 0;
  12702. }
  12703. static int bnx2x_unregister_cnic(struct net_device *dev)
  12704. {
  12705. struct bnx2x *bp = netdev_priv(dev);
  12706. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12707. mutex_lock(&bp->cnic_mutex);
  12708. cp->drv_state = 0;
  12709. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12710. mutex_unlock(&bp->cnic_mutex);
  12711. synchronize_rcu();
  12712. bp->cnic_enabled = false;
  12713. kfree(bp->cnic_kwq);
  12714. bp->cnic_kwq = NULL;
  12715. return 0;
  12716. }
  12717. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12718. {
  12719. struct bnx2x *bp = netdev_priv(dev);
  12720. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12721. /* If both iSCSI and FCoE are disabled - return NULL in
  12722. * order to indicate CNIC that it should not try to work
  12723. * with this device.
  12724. */
  12725. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12726. return NULL;
  12727. cp->drv_owner = THIS_MODULE;
  12728. cp->chip_id = CHIP_ID(bp);
  12729. cp->pdev = bp->pdev;
  12730. cp->io_base = bp->regview;
  12731. cp->io_base2 = bp->doorbells;
  12732. cp->max_kwqe_pending = 8;
  12733. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12734. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12735. bnx2x_cid_ilt_lines(bp);
  12736. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12737. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12738. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12739. cp->drv_ctl = bnx2x_drv_ctl;
  12740. cp->drv_get_fc_npiv_tbl = bnx2x_get_fc_npiv;
  12741. cp->drv_register_cnic = bnx2x_register_cnic;
  12742. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12743. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12744. cp->iscsi_l2_client_id =
  12745. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12746. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12747. if (NO_ISCSI_OOO(bp))
  12748. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12749. if (NO_ISCSI(bp))
  12750. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12751. if (NO_FCOE(bp))
  12752. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12753. BNX2X_DEV_INFO(
  12754. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12755. cp->ctx_blk_size,
  12756. cp->ctx_tbl_offset,
  12757. cp->ctx_tbl_len,
  12758. cp->starting_cid);
  12759. return cp;
  12760. }
  12761. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12762. {
  12763. struct bnx2x *bp = fp->bp;
  12764. u32 offset = BAR_USTRORM_INTMEM;
  12765. if (IS_VF(bp))
  12766. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12767. else if (!CHIP_IS_E1x(bp))
  12768. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12769. else
  12770. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12771. return offset;
  12772. }
  12773. /* called only on E1H or E2.
  12774. * When pretending to be PF, the pretend value is the function number 0...7
  12775. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12776. * combination
  12777. */
  12778. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12779. {
  12780. u32 pretend_reg;
  12781. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12782. return -1;
  12783. /* get my own pretend register */
  12784. pretend_reg = bnx2x_get_pretend_reg(bp);
  12785. REG_WR(bp, pretend_reg, pretend_func_val);
  12786. REG_RD(bp, pretend_reg);
  12787. return 0;
  12788. }
  12789. static void bnx2x_ptp_task(struct work_struct *work)
  12790. {
  12791. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12792. int port = BP_PORT(bp);
  12793. u32 val_seq;
  12794. u64 timestamp, ns;
  12795. struct skb_shared_hwtstamps shhwtstamps;
  12796. bool bail = true;
  12797. int i;
  12798. /* FW may take a while to complete timestamping; try a bit and if it's
  12799. * still not complete, may indicate an error state - bail out then.
  12800. */
  12801. for (i = 0; i < 10; i++) {
  12802. /* Read Tx timestamp registers */
  12803. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12804. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12805. if (val_seq & 0x10000) {
  12806. bail = false;
  12807. break;
  12808. }
  12809. msleep(1 << i);
  12810. }
  12811. if (!bail) {
  12812. /* There is a valid timestamp value */
  12813. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12814. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12815. timestamp <<= 32;
  12816. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12817. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12818. /* Reset timestamp register to allow new timestamp */
  12819. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12820. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12821. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12822. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12823. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12824. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12825. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12826. timestamp, ns);
  12827. } else {
  12828. DP(BNX2X_MSG_PTP,
  12829. "Tx timestamp is not recorded (register read=%u)\n",
  12830. val_seq);
  12831. bp->eth_stats.ptp_skip_tx_ts++;
  12832. }
  12833. dev_kfree_skb_any(bp->ptp_tx_skb);
  12834. bp->ptp_tx_skb = NULL;
  12835. }
  12836. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12837. {
  12838. int port = BP_PORT(bp);
  12839. u64 timestamp, ns;
  12840. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12841. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12842. timestamp <<= 32;
  12843. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12844. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12845. /* Reset timestamp register to allow new timestamp */
  12846. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12847. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12848. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12849. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12850. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12851. timestamp, ns);
  12852. }
  12853. /* Read the PHC */
  12854. static u64 bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12855. {
  12856. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12857. int port = BP_PORT(bp);
  12858. u32 wb_data[2];
  12859. u64 phc_cycles;
  12860. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12861. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12862. phc_cycles = wb_data[1];
  12863. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12864. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12865. return phc_cycles;
  12866. }
  12867. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12868. {
  12869. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12870. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12871. bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
  12872. bp->cyclecounter.shift = 0;
  12873. bp->cyclecounter.mult = 1;
  12874. }
  12875. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12876. {
  12877. struct bnx2x_func_state_params func_params = {NULL};
  12878. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12879. &func_params.params.set_timesync;
  12880. /* Prepare parameters for function state transitions */
  12881. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12882. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12883. func_params.f_obj = &bp->func_obj;
  12884. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12885. /* Function parameters */
  12886. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12887. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12888. return bnx2x_func_state_change(bp, &func_params);
  12889. }
  12890. static int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12891. {
  12892. struct bnx2x_queue_state_params q_params;
  12893. int rc, i;
  12894. /* send queue update ramrod to enable PTP packets */
  12895. memset(&q_params, 0, sizeof(q_params));
  12896. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12897. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12898. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12899. &q_params.params.update.update_flags);
  12900. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12901. &q_params.params.update.update_flags);
  12902. /* send the ramrod on all the queues of the PF */
  12903. for_each_eth_queue(bp, i) {
  12904. struct bnx2x_fastpath *fp = &bp->fp[i];
  12905. /* Set the appropriate Queue object */
  12906. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12907. /* Update the Queue state */
  12908. rc = bnx2x_queue_state_change(bp, &q_params);
  12909. if (rc) {
  12910. BNX2X_ERR("Failed to enable PTP packets\n");
  12911. return rc;
  12912. }
  12913. }
  12914. return 0;
  12915. }
  12916. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12917. {
  12918. int port = BP_PORT(bp);
  12919. int rc;
  12920. if (!bp->hwtstamp_ioctl_called)
  12921. return 0;
  12922. switch (bp->tx_type) {
  12923. case HWTSTAMP_TX_ON:
  12924. bp->flags |= TX_TIMESTAMPING_EN;
  12925. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12926. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12927. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12928. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12929. break;
  12930. case HWTSTAMP_TX_ONESTEP_SYNC:
  12931. BNX2X_ERR("One-step timestamping is not supported\n");
  12932. return -ERANGE;
  12933. }
  12934. switch (bp->rx_filter) {
  12935. case HWTSTAMP_FILTER_NONE:
  12936. break;
  12937. case HWTSTAMP_FILTER_ALL:
  12938. case HWTSTAMP_FILTER_SOME:
  12939. case HWTSTAMP_FILTER_NTP_ALL:
  12940. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12941. break;
  12942. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12943. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12944. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12945. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12946. /* Initialize PTP detection for UDP/IPv4 events */
  12947. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12948. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12949. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12950. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12951. break;
  12952. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12953. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12954. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12955. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12956. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12957. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12958. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12959. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12960. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12961. break;
  12962. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12963. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12964. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12965. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12966. /* Initialize PTP detection L2 events */
  12967. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12968. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12969. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12970. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12971. break;
  12972. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12973. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12974. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12975. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12976. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12977. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12978. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12979. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12980. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12981. break;
  12982. }
  12983. /* Indicate to FW that this PF expects recorded PTP packets */
  12984. rc = bnx2x_enable_ptp_packets(bp);
  12985. if (rc)
  12986. return rc;
  12987. /* Enable sending PTP packets to host */
  12988. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12989. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12990. return 0;
  12991. }
  12992. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12993. {
  12994. struct hwtstamp_config config;
  12995. int rc;
  12996. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12997. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12998. return -EFAULT;
  12999. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  13000. config.tx_type, config.rx_filter);
  13001. if (config.flags) {
  13002. BNX2X_ERR("config.flags is reserved for future use\n");
  13003. return -EINVAL;
  13004. }
  13005. bp->hwtstamp_ioctl_called = 1;
  13006. bp->tx_type = config.tx_type;
  13007. bp->rx_filter = config.rx_filter;
  13008. rc = bnx2x_configure_ptp_filters(bp);
  13009. if (rc)
  13010. return rc;
  13011. config.rx_filter = bp->rx_filter;
  13012. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  13013. -EFAULT : 0;
  13014. }
  13015. /* Configures HW for PTP */
  13016. static int bnx2x_configure_ptp(struct bnx2x *bp)
  13017. {
  13018. int rc, port = BP_PORT(bp);
  13019. u32 wb_data[2];
  13020. /* Reset PTP event detection rules - will be configured in the IOCTL */
  13021. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  13022. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  13023. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  13024. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  13025. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  13026. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  13027. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  13028. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  13029. /* Disable PTP packets to host - will be configured in the IOCTL*/
  13030. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  13031. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  13032. /* Enable the PTP feature */
  13033. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  13034. NIG_REG_P0_PTP_EN, 0x3F);
  13035. /* Enable the free-running counter */
  13036. wb_data[0] = 0;
  13037. wb_data[1] = 0;
  13038. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  13039. /* Reset drift register (offset register is not reset) */
  13040. rc = bnx2x_send_reset_timesync_ramrod(bp);
  13041. if (rc) {
  13042. BNX2X_ERR("Failed to reset PHC drift register\n");
  13043. return -EFAULT;
  13044. }
  13045. /* Reset possibly old timestamps */
  13046. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  13047. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  13048. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  13049. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  13050. return 0;
  13051. }
  13052. /* Called during load, to initialize PTP-related stuff */
  13053. void bnx2x_init_ptp(struct bnx2x *bp)
  13054. {
  13055. int rc;
  13056. /* Configure PTP in HW */
  13057. rc = bnx2x_configure_ptp(bp);
  13058. if (rc) {
  13059. BNX2X_ERR("Stopping PTP initialization\n");
  13060. return;
  13061. }
  13062. /* Init work queue for Tx timestamping */
  13063. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  13064. /* Init cyclecounter and timecounter. This is done only in the first
  13065. * load. If done in every load, PTP application will fail when doing
  13066. * unload / load (e.g. MTU change) while it is running.
  13067. */
  13068. if (!bp->timecounter_init_done) {
  13069. bnx2x_init_cyclecounter(bp);
  13070. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  13071. ktime_to_ns(ktime_get_real()));
  13072. bp->timecounter_init_done = 1;
  13073. }
  13074. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  13075. }