bnx2x_main.c 420 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521
  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, S_IRUGO);
  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, S_IRUGO);
  99. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  100. static int int_mode;
  101. module_param(int_mode, int, S_IRUGO);
  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, S_IRUGO);
  106. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  107. static int mrrs = -1;
  108. module_param(mrrs, int, S_IRUGO);
  109. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  110. static int debug;
  111. module_param(debug, int, S_IRUGO);
  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. if (IS_MF_UFP(bp) || IS_MF_BD(bp)) {
  2474. int func = BP_ABS_FUNC(bp);
  2475. u32 val;
  2476. /* Re-learn the S-tag from shmem */
  2477. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2478. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2479. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2480. bp->mf_ov = val;
  2481. } else {
  2482. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2483. goto fail;
  2484. }
  2485. /* Configure new S-tag in LLH */
  2486. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2487. bp->mf_ov);
  2488. /* Send Ramrod to update FW of change */
  2489. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2490. &switch_update_params->changes);
  2491. switch_update_params->vlan = bp->mf_ov;
  2492. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2493. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2494. bp->mf_ov);
  2495. goto fail;
  2496. } else {
  2497. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n",
  2498. bp->mf_ov);
  2499. }
  2500. } else {
  2501. goto fail;
  2502. }
  2503. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2504. return;
  2505. fail:
  2506. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2507. }
  2508. static void bnx2x_pmf_update(struct bnx2x *bp)
  2509. {
  2510. int port = BP_PORT(bp);
  2511. u32 val;
  2512. bp->port.pmf = 1;
  2513. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2514. /*
  2515. * We need the mb() to ensure the ordering between the writing to
  2516. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2517. */
  2518. smp_mb();
  2519. /* queue a periodic task */
  2520. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2521. bnx2x_dcbx_pmf_update(bp);
  2522. /* enable nig attention */
  2523. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2524. if (bp->common.int_block == INT_BLOCK_HC) {
  2525. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2526. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2527. } else if (!CHIP_IS_E1x(bp)) {
  2528. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2529. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2530. }
  2531. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2532. }
  2533. /* end of Link */
  2534. /* slow path */
  2535. /*
  2536. * General service functions
  2537. */
  2538. /* send the MCP a request, block until there is a reply */
  2539. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2540. {
  2541. int mb_idx = BP_FW_MB_IDX(bp);
  2542. u32 seq;
  2543. u32 rc = 0;
  2544. u32 cnt = 1;
  2545. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2546. mutex_lock(&bp->fw_mb_mutex);
  2547. seq = ++bp->fw_seq;
  2548. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2549. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2550. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2551. (command | seq), param);
  2552. do {
  2553. /* let the FW do it's magic ... */
  2554. msleep(delay);
  2555. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2556. /* Give the FW up to 5 second (500*10ms) */
  2557. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2558. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2559. cnt*delay, rc, seq);
  2560. /* is this a reply to our command? */
  2561. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2562. rc &= FW_MSG_CODE_MASK;
  2563. else {
  2564. /* FW BUG! */
  2565. BNX2X_ERR("FW failed to respond!\n");
  2566. bnx2x_fw_dump(bp);
  2567. rc = 0;
  2568. }
  2569. mutex_unlock(&bp->fw_mb_mutex);
  2570. return rc;
  2571. }
  2572. static void storm_memset_func_cfg(struct bnx2x *bp,
  2573. struct tstorm_eth_function_common_config *tcfg,
  2574. u16 abs_fid)
  2575. {
  2576. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2577. u32 addr = BAR_TSTRORM_INTMEM +
  2578. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2579. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2580. }
  2581. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2582. {
  2583. if (CHIP_IS_E1x(bp)) {
  2584. struct tstorm_eth_function_common_config tcfg = {0};
  2585. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2586. }
  2587. /* Enable the function in the FW */
  2588. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2589. storm_memset_func_en(bp, p->func_id, 1);
  2590. /* spq */
  2591. if (p->spq_active) {
  2592. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2593. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2594. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2595. }
  2596. }
  2597. /**
  2598. * bnx2x_get_common_flags - Return common flags
  2599. *
  2600. * @bp device handle
  2601. * @fp queue handle
  2602. * @zero_stats TRUE if statistics zeroing is needed
  2603. *
  2604. * Return the flags that are common for the Tx-only and not normal connections.
  2605. */
  2606. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2607. struct bnx2x_fastpath *fp,
  2608. bool zero_stats)
  2609. {
  2610. unsigned long flags = 0;
  2611. /* PF driver will always initialize the Queue to an ACTIVE state */
  2612. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2613. /* tx only connections collect statistics (on the same index as the
  2614. * parent connection). The statistics are zeroed when the parent
  2615. * connection is initialized.
  2616. */
  2617. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2618. if (zero_stats)
  2619. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2620. if (bp->flags & TX_SWITCHING)
  2621. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2622. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2623. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2624. #ifdef BNX2X_STOP_ON_ERROR
  2625. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2626. #endif
  2627. return flags;
  2628. }
  2629. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2630. struct bnx2x_fastpath *fp,
  2631. bool leading)
  2632. {
  2633. unsigned long flags = 0;
  2634. /* calculate other queue flags */
  2635. if (IS_MF_SD(bp))
  2636. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2637. if (IS_FCOE_FP(fp)) {
  2638. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2639. /* For FCoE - force usage of default priority (for afex) */
  2640. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2641. }
  2642. if (fp->mode != TPA_MODE_DISABLED) {
  2643. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2644. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2645. if (fp->mode == TPA_MODE_GRO)
  2646. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2647. }
  2648. if (leading) {
  2649. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2650. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2651. }
  2652. /* Always set HW VLAN stripping */
  2653. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2654. /* configure silent vlan removal */
  2655. if (IS_MF_AFEX(bp))
  2656. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2657. return flags | bnx2x_get_common_flags(bp, fp, true);
  2658. }
  2659. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2660. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2661. u8 cos)
  2662. {
  2663. gen_init->stat_id = bnx2x_stats_id(fp);
  2664. gen_init->spcl_id = fp->cl_id;
  2665. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2666. if (IS_FCOE_FP(fp))
  2667. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2668. else
  2669. gen_init->mtu = bp->dev->mtu;
  2670. gen_init->cos = cos;
  2671. gen_init->fp_hsi = ETH_FP_HSI_VERSION;
  2672. }
  2673. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2674. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2675. struct bnx2x_rxq_setup_params *rxq_init)
  2676. {
  2677. u8 max_sge = 0;
  2678. u16 sge_sz = 0;
  2679. u16 tpa_agg_size = 0;
  2680. if (fp->mode != TPA_MODE_DISABLED) {
  2681. pause->sge_th_lo = SGE_TH_LO(bp);
  2682. pause->sge_th_hi = SGE_TH_HI(bp);
  2683. /* validate SGE ring has enough to cross high threshold */
  2684. WARN_ON(bp->dropless_fc &&
  2685. pause->sge_th_hi + FW_PREFETCH_CNT >
  2686. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2687. tpa_agg_size = TPA_AGG_SIZE;
  2688. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2689. SGE_PAGE_SHIFT;
  2690. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2691. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2692. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2693. }
  2694. /* pause - not for e1 */
  2695. if (!CHIP_IS_E1(bp)) {
  2696. pause->bd_th_lo = BD_TH_LO(bp);
  2697. pause->bd_th_hi = BD_TH_HI(bp);
  2698. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2699. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2700. /*
  2701. * validate that rings have enough entries to cross
  2702. * high thresholds
  2703. */
  2704. WARN_ON(bp->dropless_fc &&
  2705. pause->bd_th_hi + FW_PREFETCH_CNT >
  2706. bp->rx_ring_size);
  2707. WARN_ON(bp->dropless_fc &&
  2708. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2709. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2710. pause->pri_map = 1;
  2711. }
  2712. /* rxq setup */
  2713. rxq_init->dscr_map = fp->rx_desc_mapping;
  2714. rxq_init->sge_map = fp->rx_sge_mapping;
  2715. rxq_init->rcq_map = fp->rx_comp_mapping;
  2716. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2717. /* This should be a maximum number of data bytes that may be
  2718. * placed on the BD (not including paddings).
  2719. */
  2720. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2721. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2722. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2723. rxq_init->tpa_agg_sz = tpa_agg_size;
  2724. rxq_init->sge_buf_sz = sge_sz;
  2725. rxq_init->max_sges_pkt = max_sge;
  2726. rxq_init->rss_engine_id = BP_FUNC(bp);
  2727. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2728. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2729. *
  2730. * For PF Clients it should be the maximum available number.
  2731. * VF driver(s) may want to define it to a smaller value.
  2732. */
  2733. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2734. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2735. rxq_init->fw_sb_id = fp->fw_sb_id;
  2736. if (IS_FCOE_FP(fp))
  2737. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2738. else
  2739. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2740. /* configure silent vlan removal
  2741. * if multi function mode is afex, then mask default vlan
  2742. */
  2743. if (IS_MF_AFEX(bp)) {
  2744. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2745. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2746. }
  2747. }
  2748. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2749. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2750. u8 cos)
  2751. {
  2752. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2753. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2754. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2755. txq_init->fw_sb_id = fp->fw_sb_id;
  2756. /*
  2757. * set the tss leading client id for TX classification ==
  2758. * leading RSS client id
  2759. */
  2760. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2761. if (IS_FCOE_FP(fp)) {
  2762. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2763. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2764. }
  2765. }
  2766. static void bnx2x_pf_init(struct bnx2x *bp)
  2767. {
  2768. struct bnx2x_func_init_params func_init = {0};
  2769. struct event_ring_data eq_data = { {0} };
  2770. if (!CHIP_IS_E1x(bp)) {
  2771. /* reset IGU PF statistics: MSIX + ATTN */
  2772. /* PF */
  2773. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2774. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2775. (CHIP_MODE_IS_4_PORT(bp) ?
  2776. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2777. /* ATTN */
  2778. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2779. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2780. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2781. (CHIP_MODE_IS_4_PORT(bp) ?
  2782. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2783. }
  2784. func_init.spq_active = true;
  2785. func_init.pf_id = BP_FUNC(bp);
  2786. func_init.func_id = BP_FUNC(bp);
  2787. func_init.spq_map = bp->spq_mapping;
  2788. func_init.spq_prod = bp->spq_prod_idx;
  2789. bnx2x_func_init(bp, &func_init);
  2790. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2791. /*
  2792. * Congestion management values depend on the link rate
  2793. * There is no active link so initial link rate is set to 10 Gbps.
  2794. * When the link comes up The congestion management values are
  2795. * re-calculated according to the actual link rate.
  2796. */
  2797. bp->link_vars.line_speed = SPEED_10000;
  2798. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2799. /* Only the PMF sets the HW */
  2800. if (bp->port.pmf)
  2801. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2802. /* init Event Queue - PCI bus guarantees correct endianity*/
  2803. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2804. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2805. eq_data.producer = bp->eq_prod;
  2806. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2807. eq_data.sb_id = DEF_SB_ID;
  2808. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2809. }
  2810. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2811. {
  2812. int port = BP_PORT(bp);
  2813. bnx2x_tx_disable(bp);
  2814. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2815. }
  2816. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2817. {
  2818. int port = BP_PORT(bp);
  2819. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2820. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2821. /* Tx queue should be only re-enabled */
  2822. netif_tx_wake_all_queues(bp->dev);
  2823. /*
  2824. * Should not call netif_carrier_on since it will be called if the link
  2825. * is up when checking for link state
  2826. */
  2827. }
  2828. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2829. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2830. {
  2831. struct eth_stats_info *ether_stat =
  2832. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2833. struct bnx2x_vlan_mac_obj *mac_obj =
  2834. &bp->sp_objs->mac_obj;
  2835. int i;
  2836. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2837. ETH_STAT_INFO_VERSION_LEN);
  2838. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2839. * mac_local field in ether_stat struct. The base address is offset by 2
  2840. * bytes to account for the field being 8 bytes but a mac address is
  2841. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2842. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2843. * allocated by the ether_stat struct, so the macs will land in their
  2844. * proper positions.
  2845. */
  2846. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2847. memset(ether_stat->mac_local + i, 0,
  2848. sizeof(ether_stat->mac_local[0]));
  2849. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2850. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2851. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2852. ETH_ALEN);
  2853. ether_stat->mtu_size = bp->dev->mtu;
  2854. if (bp->dev->features & NETIF_F_RXCSUM)
  2855. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2856. if (bp->dev->features & NETIF_F_TSO)
  2857. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2858. ether_stat->feature_flags |= bp->common.boot_mode;
  2859. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2860. ether_stat->txq_size = bp->tx_ring_size;
  2861. ether_stat->rxq_size = bp->rx_ring_size;
  2862. #ifdef CONFIG_BNX2X_SRIOV
  2863. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2864. #endif
  2865. }
  2866. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2867. {
  2868. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2869. struct fcoe_stats_info *fcoe_stat =
  2870. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2871. if (!CNIC_LOADED(bp))
  2872. return;
  2873. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2874. fcoe_stat->qos_priority =
  2875. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2876. /* insert FCoE stats from ramrod response */
  2877. if (!NO_FCOE(bp)) {
  2878. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2879. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2880. tstorm_queue_statistics;
  2881. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2882. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2883. xstorm_queue_statistics;
  2884. struct fcoe_statistics_params *fw_fcoe_stat =
  2885. &bp->fw_stats_data->fcoe;
  2886. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2887. fcoe_stat->rx_bytes_lo,
  2888. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2889. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2890. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2891. fcoe_stat->rx_bytes_lo,
  2892. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2893. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2894. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2895. fcoe_stat->rx_bytes_lo,
  2896. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2897. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2898. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2899. fcoe_stat->rx_bytes_lo,
  2900. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2901. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2902. fcoe_stat->rx_frames_lo,
  2903. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2904. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2905. fcoe_stat->rx_frames_lo,
  2906. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2907. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2908. fcoe_stat->rx_frames_lo,
  2909. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2910. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2911. fcoe_stat->rx_frames_lo,
  2912. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2913. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2914. fcoe_stat->tx_bytes_lo,
  2915. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2916. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2917. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2918. fcoe_stat->tx_bytes_lo,
  2919. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2920. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2921. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2922. fcoe_stat->tx_bytes_lo,
  2923. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2924. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2925. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2926. fcoe_stat->tx_bytes_lo,
  2927. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2928. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2929. fcoe_stat->tx_frames_lo,
  2930. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2931. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2932. fcoe_stat->tx_frames_lo,
  2933. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2934. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2935. fcoe_stat->tx_frames_lo,
  2936. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2937. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2938. fcoe_stat->tx_frames_lo,
  2939. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2940. }
  2941. /* ask L5 driver to add data to the struct */
  2942. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2943. }
  2944. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2945. {
  2946. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2947. struct iscsi_stats_info *iscsi_stat =
  2948. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2949. if (!CNIC_LOADED(bp))
  2950. return;
  2951. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2952. ETH_ALEN);
  2953. iscsi_stat->qos_priority =
  2954. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2955. /* ask L5 driver to add data to the struct */
  2956. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2957. }
  2958. /* called due to MCP event (on pmf):
  2959. * reread new bandwidth configuration
  2960. * configure FW
  2961. * notify others function about the change
  2962. */
  2963. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2964. {
  2965. if (bp->link_vars.link_up) {
  2966. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2967. bnx2x_link_sync_notify(bp);
  2968. }
  2969. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2970. }
  2971. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2972. {
  2973. bnx2x_config_mf_bw(bp);
  2974. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2975. }
  2976. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2977. {
  2978. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2979. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2980. }
  2981. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2982. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2983. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2984. {
  2985. enum drv_info_opcode op_code;
  2986. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2987. bool release = false;
  2988. int wait;
  2989. /* if drv_info version supported by MFW doesn't match - send NACK */
  2990. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2991. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2992. return;
  2993. }
  2994. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2995. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2996. /* Must prevent other flows from accessing drv_info_to_mcp */
  2997. mutex_lock(&bp->drv_info_mutex);
  2998. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2999. sizeof(union drv_info_to_mcp));
  3000. switch (op_code) {
  3001. case ETH_STATS_OPCODE:
  3002. bnx2x_drv_info_ether_stat(bp);
  3003. break;
  3004. case FCOE_STATS_OPCODE:
  3005. bnx2x_drv_info_fcoe_stat(bp);
  3006. break;
  3007. case ISCSI_STATS_OPCODE:
  3008. bnx2x_drv_info_iscsi_stat(bp);
  3009. break;
  3010. default:
  3011. /* if op code isn't supported - send NACK */
  3012. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3013. goto out;
  3014. }
  3015. /* if we got drv_info attn from MFW then these fields are defined in
  3016. * shmem2 for sure
  3017. */
  3018. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3019. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3020. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3021. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3022. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3023. /* Since possible management wants both this and get_driver_version
  3024. * need to wait until management notifies us it finished utilizing
  3025. * the buffer.
  3026. */
  3027. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3028. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3029. } else if (!bp->drv_info_mng_owner) {
  3030. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3031. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3032. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3033. /* Management is done; need to clear indication */
  3034. if (indication & bit) {
  3035. SHMEM2_WR(bp, mfw_drv_indication,
  3036. indication & ~bit);
  3037. release = true;
  3038. break;
  3039. }
  3040. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3041. }
  3042. }
  3043. if (!release) {
  3044. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3045. bp->drv_info_mng_owner = true;
  3046. }
  3047. out:
  3048. mutex_unlock(&bp->drv_info_mutex);
  3049. }
  3050. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3051. {
  3052. u8 vals[4];
  3053. int i = 0;
  3054. if (bnx2x_format) {
  3055. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3056. &vals[0], &vals[1], &vals[2], &vals[3]);
  3057. if (i > 0)
  3058. vals[0] -= '0';
  3059. } else {
  3060. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3061. &vals[0], &vals[1], &vals[2], &vals[3]);
  3062. }
  3063. while (i < 4)
  3064. vals[i++] = 0;
  3065. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3066. }
  3067. void bnx2x_update_mng_version(struct bnx2x *bp)
  3068. {
  3069. u32 iscsiver = DRV_VER_NOT_LOADED;
  3070. u32 fcoever = DRV_VER_NOT_LOADED;
  3071. u32 ethver = DRV_VER_NOT_LOADED;
  3072. int idx = BP_FW_MB_IDX(bp);
  3073. u8 *version;
  3074. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3075. return;
  3076. mutex_lock(&bp->drv_info_mutex);
  3077. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3078. if (bp->drv_info_mng_owner)
  3079. goto out;
  3080. if (bp->state != BNX2X_STATE_OPEN)
  3081. goto out;
  3082. /* Parse ethernet driver version */
  3083. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3084. if (!CNIC_LOADED(bp))
  3085. goto out;
  3086. /* Try getting storage driver version via cnic */
  3087. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3088. sizeof(union drv_info_to_mcp));
  3089. bnx2x_drv_info_iscsi_stat(bp);
  3090. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3091. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3092. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3093. sizeof(union drv_info_to_mcp));
  3094. bnx2x_drv_info_fcoe_stat(bp);
  3095. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3096. fcoever = bnx2x_update_mng_version_utility(version, false);
  3097. out:
  3098. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3099. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3100. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3101. mutex_unlock(&bp->drv_info_mutex);
  3102. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3103. ethver, iscsiver, fcoever);
  3104. }
  3105. void bnx2x_update_mfw_dump(struct bnx2x *bp)
  3106. {
  3107. u32 drv_ver;
  3108. u32 valid_dump;
  3109. if (!SHMEM2_HAS(bp, drv_info))
  3110. return;
  3111. /* Update Driver load time, possibly broken in y2038 */
  3112. SHMEM2_WR(bp, drv_info.epoc, (u32)ktime_get_real_seconds());
  3113. drv_ver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3114. SHMEM2_WR(bp, drv_info.drv_ver, drv_ver);
  3115. SHMEM2_WR(bp, drv_info.fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  3116. /* Check & notify On-Chip dump. */
  3117. valid_dump = SHMEM2_RD(bp, drv_info.valid_dump);
  3118. if (valid_dump & FIRST_DUMP_VALID)
  3119. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 1st partition\n");
  3120. if (valid_dump & SECOND_DUMP_VALID)
  3121. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 2nd partition\n");
  3122. }
  3123. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3124. {
  3125. u32 cmd_ok, cmd_fail;
  3126. /* sanity */
  3127. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3128. event & DRV_STATUS_OEM_EVENT_MASK) {
  3129. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3130. return;
  3131. }
  3132. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3133. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3134. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3135. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3136. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3137. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3138. }
  3139. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3140. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3141. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3142. /* This is the only place besides the function initialization
  3143. * where the bp->flags can change so it is done without any
  3144. * locks
  3145. */
  3146. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3147. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3148. bp->flags |= MF_FUNC_DIS;
  3149. bnx2x_e1h_disable(bp);
  3150. } else {
  3151. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3152. bp->flags &= ~MF_FUNC_DIS;
  3153. bnx2x_e1h_enable(bp);
  3154. }
  3155. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3156. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3157. }
  3158. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3159. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3160. bnx2x_config_mf_bw(bp);
  3161. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3162. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3163. }
  3164. /* Report results to MCP */
  3165. if (event)
  3166. bnx2x_fw_command(bp, cmd_fail, 0);
  3167. else
  3168. bnx2x_fw_command(bp, cmd_ok, 0);
  3169. }
  3170. /* must be called under the spq lock */
  3171. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3172. {
  3173. struct eth_spe *next_spe = bp->spq_prod_bd;
  3174. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3175. bp->spq_prod_bd = bp->spq;
  3176. bp->spq_prod_idx = 0;
  3177. DP(BNX2X_MSG_SP, "end of spq\n");
  3178. } else {
  3179. bp->spq_prod_bd++;
  3180. bp->spq_prod_idx++;
  3181. }
  3182. return next_spe;
  3183. }
  3184. /* must be called under the spq lock */
  3185. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3186. {
  3187. int func = BP_FUNC(bp);
  3188. /*
  3189. * Make sure that BD data is updated before writing the producer:
  3190. * BD data is written to the memory, the producer is read from the
  3191. * memory, thus we need a full memory barrier to ensure the ordering.
  3192. */
  3193. mb();
  3194. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3195. bp->spq_prod_idx);
  3196. mmiowb();
  3197. }
  3198. /**
  3199. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3200. *
  3201. * @cmd: command to check
  3202. * @cmd_type: command type
  3203. */
  3204. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3205. {
  3206. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3207. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3208. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3209. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3210. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3211. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3212. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3213. return true;
  3214. else
  3215. return false;
  3216. }
  3217. /**
  3218. * bnx2x_sp_post - place a single command on an SP ring
  3219. *
  3220. * @bp: driver handle
  3221. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3222. * @cid: SW CID the command is related to
  3223. * @data_hi: command private data address (high 32 bits)
  3224. * @data_lo: command private data address (low 32 bits)
  3225. * @cmd_type: command type (e.g. NONE, ETH)
  3226. *
  3227. * SP data is handled as if it's always an address pair, thus data fields are
  3228. * not swapped to little endian in upper functions. Instead this function swaps
  3229. * data as if it's two u32 fields.
  3230. */
  3231. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3232. u32 data_hi, u32 data_lo, int cmd_type)
  3233. {
  3234. struct eth_spe *spe;
  3235. u16 type;
  3236. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3237. #ifdef BNX2X_STOP_ON_ERROR
  3238. if (unlikely(bp->panic)) {
  3239. BNX2X_ERR("Can't post SP when there is panic\n");
  3240. return -EIO;
  3241. }
  3242. #endif
  3243. spin_lock_bh(&bp->spq_lock);
  3244. if (common) {
  3245. if (!atomic_read(&bp->eq_spq_left)) {
  3246. BNX2X_ERR("BUG! EQ ring full!\n");
  3247. spin_unlock_bh(&bp->spq_lock);
  3248. bnx2x_panic();
  3249. return -EBUSY;
  3250. }
  3251. } else if (!atomic_read(&bp->cq_spq_left)) {
  3252. BNX2X_ERR("BUG! SPQ ring full!\n");
  3253. spin_unlock_bh(&bp->spq_lock);
  3254. bnx2x_panic();
  3255. return -EBUSY;
  3256. }
  3257. spe = bnx2x_sp_get_next(bp);
  3258. /* CID needs port number to be encoded int it */
  3259. spe->hdr.conn_and_cmd_data =
  3260. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3261. HW_CID(bp, cid));
  3262. /* In some cases, type may already contain the func-id
  3263. * mainly in SRIOV related use cases, so we add it here only
  3264. * if it's not already set.
  3265. */
  3266. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3267. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3268. SPE_HDR_CONN_TYPE;
  3269. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3270. SPE_HDR_FUNCTION_ID);
  3271. } else {
  3272. type = cmd_type;
  3273. }
  3274. spe->hdr.type = cpu_to_le16(type);
  3275. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3276. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3277. /*
  3278. * It's ok if the actual decrement is issued towards the memory
  3279. * somewhere between the spin_lock and spin_unlock. Thus no
  3280. * more explicit memory barrier is needed.
  3281. */
  3282. if (common)
  3283. atomic_dec(&bp->eq_spq_left);
  3284. else
  3285. atomic_dec(&bp->cq_spq_left);
  3286. DP(BNX2X_MSG_SP,
  3287. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3288. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3289. (u32)(U64_LO(bp->spq_mapping) +
  3290. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3291. HW_CID(bp, cid), data_hi, data_lo, type,
  3292. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3293. bnx2x_sp_prod_update(bp);
  3294. spin_unlock_bh(&bp->spq_lock);
  3295. return 0;
  3296. }
  3297. /* acquire split MCP access lock register */
  3298. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3299. {
  3300. u32 j, val;
  3301. int rc = 0;
  3302. might_sleep();
  3303. for (j = 0; j < 1000; j++) {
  3304. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3305. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3306. if (val & MCPR_ACCESS_LOCK_LOCK)
  3307. break;
  3308. usleep_range(5000, 10000);
  3309. }
  3310. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3311. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3312. rc = -EBUSY;
  3313. }
  3314. return rc;
  3315. }
  3316. /* release split MCP access lock register */
  3317. static void bnx2x_release_alr(struct bnx2x *bp)
  3318. {
  3319. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3320. }
  3321. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3322. #define BNX2X_DEF_SB_IDX 0x0002
  3323. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3324. {
  3325. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3326. u16 rc = 0;
  3327. barrier(); /* status block is written to by the chip */
  3328. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3329. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3330. rc |= BNX2X_DEF_SB_ATT_IDX;
  3331. }
  3332. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3333. bp->def_idx = def_sb->sp_sb.running_index;
  3334. rc |= BNX2X_DEF_SB_IDX;
  3335. }
  3336. /* Do not reorder: indices reading should complete before handling */
  3337. barrier();
  3338. return rc;
  3339. }
  3340. /*
  3341. * slow path service functions
  3342. */
  3343. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3344. {
  3345. int port = BP_PORT(bp);
  3346. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3347. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3348. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3349. NIG_REG_MASK_INTERRUPT_PORT0;
  3350. u32 aeu_mask;
  3351. u32 nig_mask = 0;
  3352. u32 reg_addr;
  3353. if (bp->attn_state & asserted)
  3354. BNX2X_ERR("IGU ERROR\n");
  3355. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3356. aeu_mask = REG_RD(bp, aeu_addr);
  3357. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3358. aeu_mask, asserted);
  3359. aeu_mask &= ~(asserted & 0x3ff);
  3360. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3361. REG_WR(bp, aeu_addr, aeu_mask);
  3362. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3363. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3364. bp->attn_state |= asserted;
  3365. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3366. if (asserted & ATTN_HARD_WIRED_MASK) {
  3367. if (asserted & ATTN_NIG_FOR_FUNC) {
  3368. bnx2x_acquire_phy_lock(bp);
  3369. /* save nig interrupt mask */
  3370. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3371. /* If nig_mask is not set, no need to call the update
  3372. * function.
  3373. */
  3374. if (nig_mask) {
  3375. REG_WR(bp, nig_int_mask_addr, 0);
  3376. bnx2x_link_attn(bp);
  3377. }
  3378. /* handle unicore attn? */
  3379. }
  3380. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3381. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3382. if (asserted & GPIO_2_FUNC)
  3383. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3384. if (asserted & GPIO_3_FUNC)
  3385. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3386. if (asserted & GPIO_4_FUNC)
  3387. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3388. if (port == 0) {
  3389. if (asserted & ATTN_GENERAL_ATTN_1) {
  3390. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3391. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3392. }
  3393. if (asserted & ATTN_GENERAL_ATTN_2) {
  3394. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3395. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3396. }
  3397. if (asserted & ATTN_GENERAL_ATTN_3) {
  3398. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3399. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3400. }
  3401. } else {
  3402. if (asserted & ATTN_GENERAL_ATTN_4) {
  3403. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3404. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3405. }
  3406. if (asserted & ATTN_GENERAL_ATTN_5) {
  3407. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3408. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3409. }
  3410. if (asserted & ATTN_GENERAL_ATTN_6) {
  3411. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3412. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3413. }
  3414. }
  3415. } /* if hardwired */
  3416. if (bp->common.int_block == INT_BLOCK_HC)
  3417. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3418. COMMAND_REG_ATTN_BITS_SET);
  3419. else
  3420. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3421. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3422. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3423. REG_WR(bp, reg_addr, asserted);
  3424. /* now set back the mask */
  3425. if (asserted & ATTN_NIG_FOR_FUNC) {
  3426. /* Verify that IGU ack through BAR was written before restoring
  3427. * NIG mask. This loop should exit after 2-3 iterations max.
  3428. */
  3429. if (bp->common.int_block != INT_BLOCK_HC) {
  3430. u32 cnt = 0, igu_acked;
  3431. do {
  3432. igu_acked = REG_RD(bp,
  3433. IGU_REG_ATTENTION_ACK_BITS);
  3434. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3435. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3436. if (!igu_acked)
  3437. DP(NETIF_MSG_HW,
  3438. "Failed to verify IGU ack on time\n");
  3439. barrier();
  3440. }
  3441. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3442. bnx2x_release_phy_lock(bp);
  3443. }
  3444. }
  3445. static void bnx2x_fan_failure(struct bnx2x *bp)
  3446. {
  3447. int port = BP_PORT(bp);
  3448. u32 ext_phy_config;
  3449. /* mark the failure */
  3450. ext_phy_config =
  3451. SHMEM_RD(bp,
  3452. dev_info.port_hw_config[port].external_phy_config);
  3453. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3454. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3455. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3456. ext_phy_config);
  3457. /* log the failure */
  3458. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3459. "Please contact OEM Support for assistance\n");
  3460. /* Schedule device reset (unload)
  3461. * This is due to some boards consuming sufficient power when driver is
  3462. * up to overheat if fan fails.
  3463. */
  3464. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3465. }
  3466. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3467. {
  3468. int port = BP_PORT(bp);
  3469. int reg_offset;
  3470. u32 val;
  3471. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3472. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3473. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3474. val = REG_RD(bp, reg_offset);
  3475. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3476. REG_WR(bp, reg_offset, val);
  3477. BNX2X_ERR("SPIO5 hw attention\n");
  3478. /* Fan failure attention */
  3479. bnx2x_hw_reset_phy(&bp->link_params);
  3480. bnx2x_fan_failure(bp);
  3481. }
  3482. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3483. bnx2x_acquire_phy_lock(bp);
  3484. bnx2x_handle_module_detect_int(&bp->link_params);
  3485. bnx2x_release_phy_lock(bp);
  3486. }
  3487. if (attn & HW_INTERRUPT_ASSERT_SET_0) {
  3488. val = REG_RD(bp, reg_offset);
  3489. val &= ~(attn & HW_INTERRUPT_ASSERT_SET_0);
  3490. REG_WR(bp, reg_offset, val);
  3491. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3492. (u32)(attn & HW_INTERRUPT_ASSERT_SET_0));
  3493. bnx2x_panic();
  3494. }
  3495. }
  3496. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3497. {
  3498. u32 val;
  3499. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3500. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3501. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3502. /* DORQ discard attention */
  3503. if (val & 0x2)
  3504. BNX2X_ERR("FATAL error from DORQ\n");
  3505. }
  3506. if (attn & HW_INTERRUPT_ASSERT_SET_1) {
  3507. int port = BP_PORT(bp);
  3508. int reg_offset;
  3509. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3510. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3511. val = REG_RD(bp, reg_offset);
  3512. val &= ~(attn & HW_INTERRUPT_ASSERT_SET_1);
  3513. REG_WR(bp, reg_offset, val);
  3514. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3515. (u32)(attn & HW_INTERRUPT_ASSERT_SET_1));
  3516. bnx2x_panic();
  3517. }
  3518. }
  3519. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3520. {
  3521. u32 val;
  3522. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3523. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3524. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3525. /* CFC error attention */
  3526. if (val & 0x2)
  3527. BNX2X_ERR("FATAL error from CFC\n");
  3528. }
  3529. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3530. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3531. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3532. /* RQ_USDMDP_FIFO_OVERFLOW */
  3533. if (val & 0x18000)
  3534. BNX2X_ERR("FATAL error from PXP\n");
  3535. if (!CHIP_IS_E1x(bp)) {
  3536. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3537. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3538. }
  3539. }
  3540. if (attn & HW_INTERRUPT_ASSERT_SET_2) {
  3541. int port = BP_PORT(bp);
  3542. int reg_offset;
  3543. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3544. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3545. val = REG_RD(bp, reg_offset);
  3546. val &= ~(attn & HW_INTERRUPT_ASSERT_SET_2);
  3547. REG_WR(bp, reg_offset, val);
  3548. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3549. (u32)(attn & HW_INTERRUPT_ASSERT_SET_2));
  3550. bnx2x_panic();
  3551. }
  3552. }
  3553. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3554. {
  3555. u32 val;
  3556. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3557. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3558. int func = BP_FUNC(bp);
  3559. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3560. bnx2x_read_mf_cfg(bp);
  3561. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3562. func_mf_config[BP_ABS_FUNC(bp)].config);
  3563. val = SHMEM_RD(bp,
  3564. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3565. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3566. DRV_STATUS_OEM_EVENT_MASK))
  3567. bnx2x_oem_event(bp,
  3568. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3569. DRV_STATUS_OEM_EVENT_MASK)));
  3570. if (val & DRV_STATUS_SET_MF_BW)
  3571. bnx2x_set_mf_bw(bp);
  3572. if (val & DRV_STATUS_DRV_INFO_REQ)
  3573. bnx2x_handle_drv_info_req(bp);
  3574. if (val & DRV_STATUS_VF_DISABLED)
  3575. bnx2x_schedule_iov_task(bp,
  3576. BNX2X_IOV_HANDLE_FLR);
  3577. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3578. bnx2x_pmf_update(bp);
  3579. if (bp->port.pmf &&
  3580. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3581. bp->dcbx_enabled > 0)
  3582. /* start dcbx state machine */
  3583. bnx2x_dcbx_set_params(bp,
  3584. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3585. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3586. bnx2x_handle_afex_cmd(bp,
  3587. val & DRV_STATUS_AFEX_EVENT_MASK);
  3588. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3589. bnx2x_handle_eee_event(bp);
  3590. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3591. bnx2x_handle_update_svid_cmd(bp);
  3592. if (bp->link_vars.periodic_flags &
  3593. PERIODIC_FLAGS_LINK_EVENT) {
  3594. /* sync with link */
  3595. bnx2x_acquire_phy_lock(bp);
  3596. bp->link_vars.periodic_flags &=
  3597. ~PERIODIC_FLAGS_LINK_EVENT;
  3598. bnx2x_release_phy_lock(bp);
  3599. if (IS_MF(bp))
  3600. bnx2x_link_sync_notify(bp);
  3601. bnx2x_link_report(bp);
  3602. }
  3603. /* Always call it here: bnx2x_link_report() will
  3604. * prevent the link indication duplication.
  3605. */
  3606. bnx2x__link_status_update(bp);
  3607. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3608. BNX2X_ERR("MC assert!\n");
  3609. bnx2x_mc_assert(bp);
  3610. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3611. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3612. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3613. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3614. bnx2x_panic();
  3615. } else if (attn & BNX2X_MCP_ASSERT) {
  3616. BNX2X_ERR("MCP assert!\n");
  3617. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3618. bnx2x_fw_dump(bp);
  3619. } else
  3620. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3621. }
  3622. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3623. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3624. if (attn & BNX2X_GRC_TIMEOUT) {
  3625. val = CHIP_IS_E1(bp) ? 0 :
  3626. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3627. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3628. }
  3629. if (attn & BNX2X_GRC_RSV) {
  3630. val = CHIP_IS_E1(bp) ? 0 :
  3631. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3632. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3633. }
  3634. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3635. }
  3636. }
  3637. /*
  3638. * Bits map:
  3639. * 0-7 - Engine0 load counter.
  3640. * 8-15 - Engine1 load counter.
  3641. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3642. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3643. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3644. * on the engine
  3645. * 19 - Engine1 ONE_IS_LOADED.
  3646. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3647. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3648. * just the one belonging to its engine).
  3649. *
  3650. */
  3651. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3652. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3653. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3654. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3655. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3656. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3657. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3658. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3659. /*
  3660. * Set the GLOBAL_RESET bit.
  3661. *
  3662. * Should be run under rtnl lock
  3663. */
  3664. void bnx2x_set_reset_global(struct bnx2x *bp)
  3665. {
  3666. u32 val;
  3667. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3668. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3669. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3670. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3671. }
  3672. /*
  3673. * Clear the GLOBAL_RESET bit.
  3674. *
  3675. * Should be run under rtnl lock
  3676. */
  3677. static void bnx2x_clear_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. * Checks the GLOBAL_RESET bit.
  3687. *
  3688. * should be run under rtnl lock
  3689. */
  3690. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3691. {
  3692. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3693. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3694. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3695. }
  3696. /*
  3697. * Clear RESET_IN_PROGRESS bit for the current engine.
  3698. *
  3699. * Should be run under rtnl lock
  3700. */
  3701. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3702. {
  3703. u32 val;
  3704. u32 bit = BP_PATH(bp) ?
  3705. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3706. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3707. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3708. /* Clear the bit */
  3709. val &= ~bit;
  3710. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3711. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3712. }
  3713. /*
  3714. * Set RESET_IN_PROGRESS for the current engine.
  3715. *
  3716. * should be run under rtnl lock
  3717. */
  3718. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3719. {
  3720. u32 val;
  3721. u32 bit = BP_PATH(bp) ?
  3722. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3723. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3724. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3725. /* Set the bit */
  3726. val |= bit;
  3727. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3728. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3729. }
  3730. /*
  3731. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3732. * should be run under rtnl lock
  3733. */
  3734. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3735. {
  3736. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3737. u32 bit = engine ?
  3738. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3739. /* return false if bit is set */
  3740. return (val & bit) ? false : true;
  3741. }
  3742. /*
  3743. * set pf load for the current pf.
  3744. *
  3745. * should be run under rtnl lock
  3746. */
  3747. void bnx2x_set_pf_load(struct bnx2x *bp)
  3748. {
  3749. u32 val1, val;
  3750. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3751. BNX2X_PATH0_LOAD_CNT_MASK;
  3752. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3753. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3754. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3755. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3756. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3757. /* get the current counter value */
  3758. val1 = (val & mask) >> shift;
  3759. /* set bit of that PF */
  3760. val1 |= (1 << bp->pf_num);
  3761. /* clear the old value */
  3762. val &= ~mask;
  3763. /* set the new one */
  3764. val |= ((val1 << shift) & mask);
  3765. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3766. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3767. }
  3768. /**
  3769. * bnx2x_clear_pf_load - clear pf load mark
  3770. *
  3771. * @bp: driver handle
  3772. *
  3773. * Should be run under rtnl lock.
  3774. * Decrements the load counter for the current engine. Returns
  3775. * whether other functions are still loaded
  3776. */
  3777. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3778. {
  3779. u32 val1, val;
  3780. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3781. BNX2X_PATH0_LOAD_CNT_MASK;
  3782. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3783. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3784. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3785. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3786. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3787. /* get the current counter value */
  3788. val1 = (val & mask) >> shift;
  3789. /* clear bit of that PF */
  3790. val1 &= ~(1 << bp->pf_num);
  3791. /* clear the old value */
  3792. val &= ~mask;
  3793. /* set the new one */
  3794. val |= ((val1 << shift) & mask);
  3795. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3796. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3797. return val1 != 0;
  3798. }
  3799. /*
  3800. * Read the load status for the current engine.
  3801. *
  3802. * should be run under rtnl lock
  3803. */
  3804. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3805. {
  3806. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3807. BNX2X_PATH0_LOAD_CNT_MASK);
  3808. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3809. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3810. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3811. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3812. val = (val & mask) >> shift;
  3813. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3814. engine, val);
  3815. return val != 0;
  3816. }
  3817. static void _print_parity(struct bnx2x *bp, u32 reg)
  3818. {
  3819. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3820. }
  3821. static void _print_next_block(int idx, const char *blk)
  3822. {
  3823. pr_cont("%s%s", idx ? ", " : "", blk);
  3824. }
  3825. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3826. int *par_num, bool print)
  3827. {
  3828. u32 cur_bit;
  3829. bool res;
  3830. int i;
  3831. res = false;
  3832. for (i = 0; sig; i++) {
  3833. cur_bit = (0x1UL << i);
  3834. if (sig & cur_bit) {
  3835. res |= true; /* Each bit is real error! */
  3836. if (print) {
  3837. switch (cur_bit) {
  3838. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3839. _print_next_block((*par_num)++, "BRB");
  3840. _print_parity(bp,
  3841. BRB1_REG_BRB1_PRTY_STS);
  3842. break;
  3843. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3844. _print_next_block((*par_num)++,
  3845. "PARSER");
  3846. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3847. break;
  3848. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3849. _print_next_block((*par_num)++, "TSDM");
  3850. _print_parity(bp,
  3851. TSDM_REG_TSDM_PRTY_STS);
  3852. break;
  3853. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3854. _print_next_block((*par_num)++,
  3855. "SEARCHER");
  3856. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3857. break;
  3858. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3859. _print_next_block((*par_num)++, "TCM");
  3860. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3861. break;
  3862. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3863. _print_next_block((*par_num)++,
  3864. "TSEMI");
  3865. _print_parity(bp,
  3866. TSEM_REG_TSEM_PRTY_STS_0);
  3867. _print_parity(bp,
  3868. TSEM_REG_TSEM_PRTY_STS_1);
  3869. break;
  3870. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3871. _print_next_block((*par_num)++, "XPB");
  3872. _print_parity(bp, GRCBASE_XPB +
  3873. PB_REG_PB_PRTY_STS);
  3874. break;
  3875. }
  3876. }
  3877. /* Clear the bit */
  3878. sig &= ~cur_bit;
  3879. }
  3880. }
  3881. return res;
  3882. }
  3883. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3884. int *par_num, bool *global,
  3885. bool print)
  3886. {
  3887. u32 cur_bit;
  3888. bool res;
  3889. int i;
  3890. res = false;
  3891. for (i = 0; sig; i++) {
  3892. cur_bit = (0x1UL << i);
  3893. if (sig & cur_bit) {
  3894. res |= true; /* Each bit is real error! */
  3895. switch (cur_bit) {
  3896. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3897. if (print) {
  3898. _print_next_block((*par_num)++, "PBF");
  3899. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3900. }
  3901. break;
  3902. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3903. if (print) {
  3904. _print_next_block((*par_num)++, "QM");
  3905. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3906. }
  3907. break;
  3908. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3909. if (print) {
  3910. _print_next_block((*par_num)++, "TM");
  3911. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3912. }
  3913. break;
  3914. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3915. if (print) {
  3916. _print_next_block((*par_num)++, "XSDM");
  3917. _print_parity(bp,
  3918. XSDM_REG_XSDM_PRTY_STS);
  3919. }
  3920. break;
  3921. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3922. if (print) {
  3923. _print_next_block((*par_num)++, "XCM");
  3924. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3925. }
  3926. break;
  3927. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3928. if (print) {
  3929. _print_next_block((*par_num)++,
  3930. "XSEMI");
  3931. _print_parity(bp,
  3932. XSEM_REG_XSEM_PRTY_STS_0);
  3933. _print_parity(bp,
  3934. XSEM_REG_XSEM_PRTY_STS_1);
  3935. }
  3936. break;
  3937. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3938. if (print) {
  3939. _print_next_block((*par_num)++,
  3940. "DOORBELLQ");
  3941. _print_parity(bp,
  3942. DORQ_REG_DORQ_PRTY_STS);
  3943. }
  3944. break;
  3945. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3946. if (print) {
  3947. _print_next_block((*par_num)++, "NIG");
  3948. if (CHIP_IS_E1x(bp)) {
  3949. _print_parity(bp,
  3950. NIG_REG_NIG_PRTY_STS);
  3951. } else {
  3952. _print_parity(bp,
  3953. NIG_REG_NIG_PRTY_STS_0);
  3954. _print_parity(bp,
  3955. NIG_REG_NIG_PRTY_STS_1);
  3956. }
  3957. }
  3958. break;
  3959. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3960. if (print)
  3961. _print_next_block((*par_num)++,
  3962. "VAUX PCI CORE");
  3963. *global = true;
  3964. break;
  3965. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3966. if (print) {
  3967. _print_next_block((*par_num)++,
  3968. "DEBUG");
  3969. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3970. }
  3971. break;
  3972. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3973. if (print) {
  3974. _print_next_block((*par_num)++, "USDM");
  3975. _print_parity(bp,
  3976. USDM_REG_USDM_PRTY_STS);
  3977. }
  3978. break;
  3979. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3980. if (print) {
  3981. _print_next_block((*par_num)++, "UCM");
  3982. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3983. }
  3984. break;
  3985. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3986. if (print) {
  3987. _print_next_block((*par_num)++,
  3988. "USEMI");
  3989. _print_parity(bp,
  3990. USEM_REG_USEM_PRTY_STS_0);
  3991. _print_parity(bp,
  3992. USEM_REG_USEM_PRTY_STS_1);
  3993. }
  3994. break;
  3995. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3996. if (print) {
  3997. _print_next_block((*par_num)++, "UPB");
  3998. _print_parity(bp, GRCBASE_UPB +
  3999. PB_REG_PB_PRTY_STS);
  4000. }
  4001. break;
  4002. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  4003. if (print) {
  4004. _print_next_block((*par_num)++, "CSDM");
  4005. _print_parity(bp,
  4006. CSDM_REG_CSDM_PRTY_STS);
  4007. }
  4008. break;
  4009. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  4010. if (print) {
  4011. _print_next_block((*par_num)++, "CCM");
  4012. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  4013. }
  4014. break;
  4015. }
  4016. /* Clear the bit */
  4017. sig &= ~cur_bit;
  4018. }
  4019. }
  4020. return res;
  4021. }
  4022. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  4023. int *par_num, bool print)
  4024. {
  4025. u32 cur_bit;
  4026. bool res;
  4027. int i;
  4028. res = false;
  4029. for (i = 0; sig; i++) {
  4030. cur_bit = (0x1UL << i);
  4031. if (sig & cur_bit) {
  4032. res = true; /* Each bit is real error! */
  4033. if (print) {
  4034. switch (cur_bit) {
  4035. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4036. _print_next_block((*par_num)++,
  4037. "CSEMI");
  4038. _print_parity(bp,
  4039. CSEM_REG_CSEM_PRTY_STS_0);
  4040. _print_parity(bp,
  4041. CSEM_REG_CSEM_PRTY_STS_1);
  4042. break;
  4043. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4044. _print_next_block((*par_num)++, "PXP");
  4045. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4046. _print_parity(bp,
  4047. PXP2_REG_PXP2_PRTY_STS_0);
  4048. _print_parity(bp,
  4049. PXP2_REG_PXP2_PRTY_STS_1);
  4050. break;
  4051. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4052. _print_next_block((*par_num)++,
  4053. "PXPPCICLOCKCLIENT");
  4054. break;
  4055. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4056. _print_next_block((*par_num)++, "CFC");
  4057. _print_parity(bp,
  4058. CFC_REG_CFC_PRTY_STS);
  4059. break;
  4060. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4061. _print_next_block((*par_num)++, "CDU");
  4062. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4063. break;
  4064. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4065. _print_next_block((*par_num)++, "DMAE");
  4066. _print_parity(bp,
  4067. DMAE_REG_DMAE_PRTY_STS);
  4068. break;
  4069. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4070. _print_next_block((*par_num)++, "IGU");
  4071. if (CHIP_IS_E1x(bp))
  4072. _print_parity(bp,
  4073. HC_REG_HC_PRTY_STS);
  4074. else
  4075. _print_parity(bp,
  4076. IGU_REG_IGU_PRTY_STS);
  4077. break;
  4078. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4079. _print_next_block((*par_num)++, "MISC");
  4080. _print_parity(bp,
  4081. MISC_REG_MISC_PRTY_STS);
  4082. break;
  4083. }
  4084. }
  4085. /* Clear the bit */
  4086. sig &= ~cur_bit;
  4087. }
  4088. }
  4089. return res;
  4090. }
  4091. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4092. int *par_num, bool *global,
  4093. bool print)
  4094. {
  4095. bool res = false;
  4096. u32 cur_bit;
  4097. int i;
  4098. for (i = 0; sig; i++) {
  4099. cur_bit = (0x1UL << i);
  4100. if (sig & cur_bit) {
  4101. switch (cur_bit) {
  4102. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4103. if (print)
  4104. _print_next_block((*par_num)++,
  4105. "MCP ROM");
  4106. *global = true;
  4107. res = true;
  4108. break;
  4109. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4110. if (print)
  4111. _print_next_block((*par_num)++,
  4112. "MCP UMP RX");
  4113. *global = true;
  4114. res = true;
  4115. break;
  4116. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4117. if (print)
  4118. _print_next_block((*par_num)++,
  4119. "MCP UMP TX");
  4120. *global = true;
  4121. res = true;
  4122. break;
  4123. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4124. (*par_num)++;
  4125. /* clear latched SCPAD PATIRY from MCP */
  4126. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4127. 1UL << 10);
  4128. break;
  4129. }
  4130. /* Clear the bit */
  4131. sig &= ~cur_bit;
  4132. }
  4133. }
  4134. return res;
  4135. }
  4136. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4137. int *par_num, bool print)
  4138. {
  4139. u32 cur_bit;
  4140. bool res;
  4141. int i;
  4142. res = false;
  4143. for (i = 0; sig; i++) {
  4144. cur_bit = (0x1UL << i);
  4145. if (sig & cur_bit) {
  4146. res = true; /* Each bit is real error! */
  4147. if (print) {
  4148. switch (cur_bit) {
  4149. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4150. _print_next_block((*par_num)++,
  4151. "PGLUE_B");
  4152. _print_parity(bp,
  4153. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4154. break;
  4155. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4156. _print_next_block((*par_num)++, "ATC");
  4157. _print_parity(bp,
  4158. ATC_REG_ATC_PRTY_STS);
  4159. break;
  4160. }
  4161. }
  4162. /* Clear the bit */
  4163. sig &= ~cur_bit;
  4164. }
  4165. }
  4166. return res;
  4167. }
  4168. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4169. u32 *sig)
  4170. {
  4171. bool res = false;
  4172. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4173. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4174. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4175. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4176. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4177. int par_num = 0;
  4178. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4179. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4180. sig[0] & HW_PRTY_ASSERT_SET_0,
  4181. sig[1] & HW_PRTY_ASSERT_SET_1,
  4182. sig[2] & HW_PRTY_ASSERT_SET_2,
  4183. sig[3] & HW_PRTY_ASSERT_SET_3,
  4184. sig[4] & HW_PRTY_ASSERT_SET_4);
  4185. if (print) {
  4186. if (((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4187. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4188. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4189. (sig[4] & HW_PRTY_ASSERT_SET_4)) ||
  4190. (sig[3] & HW_PRTY_ASSERT_SET_3_WITHOUT_SCPAD)) {
  4191. netdev_err(bp->dev,
  4192. "Parity errors detected in blocks: ");
  4193. } else {
  4194. print = false;
  4195. }
  4196. }
  4197. res |= bnx2x_check_blocks_with_parity0(bp,
  4198. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4199. res |= bnx2x_check_blocks_with_parity1(bp,
  4200. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4201. res |= bnx2x_check_blocks_with_parity2(bp,
  4202. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4203. res |= bnx2x_check_blocks_with_parity3(bp,
  4204. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4205. res |= bnx2x_check_blocks_with_parity4(bp,
  4206. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4207. if (print)
  4208. pr_cont("\n");
  4209. }
  4210. return res;
  4211. }
  4212. /**
  4213. * bnx2x_chk_parity_attn - checks for parity attentions.
  4214. *
  4215. * @bp: driver handle
  4216. * @global: true if there was a global attention
  4217. * @print: show parity attention in syslog
  4218. */
  4219. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4220. {
  4221. struct attn_route attn = { {0} };
  4222. int port = BP_PORT(bp);
  4223. attn.sig[0] = REG_RD(bp,
  4224. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4225. port*4);
  4226. attn.sig[1] = REG_RD(bp,
  4227. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4228. port*4);
  4229. attn.sig[2] = REG_RD(bp,
  4230. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4231. port*4);
  4232. attn.sig[3] = REG_RD(bp,
  4233. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4234. port*4);
  4235. /* Since MCP attentions can't be disabled inside the block, we need to
  4236. * read AEU registers to see whether they're currently disabled
  4237. */
  4238. attn.sig[3] &= ((REG_RD(bp,
  4239. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4240. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4241. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4242. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4243. if (!CHIP_IS_E1x(bp))
  4244. attn.sig[4] = REG_RD(bp,
  4245. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4246. port*4);
  4247. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4248. }
  4249. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4250. {
  4251. u32 val;
  4252. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4253. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4254. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4255. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4256. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4257. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4258. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4259. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4260. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4261. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4262. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4263. if (val &
  4264. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4265. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4266. if (val &
  4267. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4268. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4269. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4270. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4271. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4272. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4273. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4274. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4275. }
  4276. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4277. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4278. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4279. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4280. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4281. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4282. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4283. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4284. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4285. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4286. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4287. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4288. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4289. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4290. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4291. }
  4292. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4293. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4294. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4295. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4296. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4297. }
  4298. }
  4299. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4300. {
  4301. struct attn_route attn, *group_mask;
  4302. int port = BP_PORT(bp);
  4303. int index;
  4304. u32 reg_addr;
  4305. u32 val;
  4306. u32 aeu_mask;
  4307. bool global = false;
  4308. /* need to take HW lock because MCP or other port might also
  4309. try to handle this event */
  4310. bnx2x_acquire_alr(bp);
  4311. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4312. #ifndef BNX2X_STOP_ON_ERROR
  4313. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4314. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4315. /* Disable HW interrupts */
  4316. bnx2x_int_disable(bp);
  4317. /* In case of parity errors don't handle attentions so that
  4318. * other function would "see" parity errors.
  4319. */
  4320. #else
  4321. bnx2x_panic();
  4322. #endif
  4323. bnx2x_release_alr(bp);
  4324. return;
  4325. }
  4326. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4327. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4328. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4329. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4330. if (!CHIP_IS_E1x(bp))
  4331. attn.sig[4] =
  4332. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4333. else
  4334. attn.sig[4] = 0;
  4335. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4336. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4337. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4338. if (deasserted & (1 << index)) {
  4339. group_mask = &bp->attn_group[index];
  4340. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4341. index,
  4342. group_mask->sig[0], group_mask->sig[1],
  4343. group_mask->sig[2], group_mask->sig[3],
  4344. group_mask->sig[4]);
  4345. bnx2x_attn_int_deasserted4(bp,
  4346. attn.sig[4] & group_mask->sig[4]);
  4347. bnx2x_attn_int_deasserted3(bp,
  4348. attn.sig[3] & group_mask->sig[3]);
  4349. bnx2x_attn_int_deasserted1(bp,
  4350. attn.sig[1] & group_mask->sig[1]);
  4351. bnx2x_attn_int_deasserted2(bp,
  4352. attn.sig[2] & group_mask->sig[2]);
  4353. bnx2x_attn_int_deasserted0(bp,
  4354. attn.sig[0] & group_mask->sig[0]);
  4355. }
  4356. }
  4357. bnx2x_release_alr(bp);
  4358. if (bp->common.int_block == INT_BLOCK_HC)
  4359. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4360. COMMAND_REG_ATTN_BITS_CLR);
  4361. else
  4362. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4363. val = ~deasserted;
  4364. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4365. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4366. REG_WR(bp, reg_addr, val);
  4367. if (~bp->attn_state & deasserted)
  4368. BNX2X_ERR("IGU ERROR\n");
  4369. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4370. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4371. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4372. aeu_mask = REG_RD(bp, reg_addr);
  4373. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4374. aeu_mask, deasserted);
  4375. aeu_mask |= (deasserted & 0x3ff);
  4376. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4377. REG_WR(bp, reg_addr, aeu_mask);
  4378. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4379. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4380. bp->attn_state &= ~deasserted;
  4381. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4382. }
  4383. static void bnx2x_attn_int(struct bnx2x *bp)
  4384. {
  4385. /* read local copy of bits */
  4386. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4387. attn_bits);
  4388. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4389. attn_bits_ack);
  4390. u32 attn_state = bp->attn_state;
  4391. /* look for changed bits */
  4392. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4393. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4394. DP(NETIF_MSG_HW,
  4395. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4396. attn_bits, attn_ack, asserted, deasserted);
  4397. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4398. BNX2X_ERR("BAD attention state\n");
  4399. /* handle bits that were raised */
  4400. if (asserted)
  4401. bnx2x_attn_int_asserted(bp, asserted);
  4402. if (deasserted)
  4403. bnx2x_attn_int_deasserted(bp, deasserted);
  4404. }
  4405. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4406. u16 index, u8 op, u8 update)
  4407. {
  4408. u32 igu_addr = bp->igu_base_addr;
  4409. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4410. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4411. igu_addr);
  4412. }
  4413. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4414. {
  4415. /* No memory barriers */
  4416. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4417. mmiowb(); /* keep prod updates ordered */
  4418. }
  4419. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4420. union event_ring_elem *elem)
  4421. {
  4422. u8 err = elem->message.error;
  4423. if (!bp->cnic_eth_dev.starting_cid ||
  4424. (cid < bp->cnic_eth_dev.starting_cid &&
  4425. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4426. return 1;
  4427. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4428. if (unlikely(err)) {
  4429. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4430. cid);
  4431. bnx2x_panic_dump(bp, false);
  4432. }
  4433. bnx2x_cnic_cfc_comp(bp, cid, err);
  4434. return 0;
  4435. }
  4436. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4437. {
  4438. struct bnx2x_mcast_ramrod_params rparam;
  4439. int rc;
  4440. memset(&rparam, 0, sizeof(rparam));
  4441. rparam.mcast_obj = &bp->mcast_obj;
  4442. netif_addr_lock_bh(bp->dev);
  4443. /* Clear pending state for the last command */
  4444. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4445. /* If there are pending mcast commands - send them */
  4446. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4447. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4448. if (rc < 0)
  4449. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4450. rc);
  4451. }
  4452. netif_addr_unlock_bh(bp->dev);
  4453. }
  4454. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4455. union event_ring_elem *elem)
  4456. {
  4457. unsigned long ramrod_flags = 0;
  4458. int rc = 0;
  4459. u32 echo = le32_to_cpu(elem->message.data.eth_event.echo);
  4460. u32 cid = echo & BNX2X_SWCID_MASK;
  4461. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4462. /* Always push next commands out, don't wait here */
  4463. __set_bit(RAMROD_CONT, &ramrod_flags);
  4464. switch (echo >> BNX2X_SWCID_SHIFT) {
  4465. case BNX2X_FILTER_MAC_PENDING:
  4466. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4467. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4468. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4469. else
  4470. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4471. break;
  4472. case BNX2X_FILTER_VLAN_PENDING:
  4473. DP(BNX2X_MSG_SP, "Got SETUP_VLAN completions\n");
  4474. vlan_mac_obj = &bp->sp_objs[cid].vlan_obj;
  4475. break;
  4476. case BNX2X_FILTER_MCAST_PENDING:
  4477. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4478. /* This is only relevant for 57710 where multicast MACs are
  4479. * configured as unicast MACs using the same ramrod.
  4480. */
  4481. bnx2x_handle_mcast_eqe(bp);
  4482. return;
  4483. default:
  4484. BNX2X_ERR("Unsupported classification command: 0x%x\n", echo);
  4485. return;
  4486. }
  4487. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4488. if (rc < 0)
  4489. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4490. else if (rc > 0)
  4491. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4492. }
  4493. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4494. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4495. {
  4496. netif_addr_lock_bh(bp->dev);
  4497. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4498. /* Send rx_mode command again if was requested */
  4499. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4500. bnx2x_set_storm_rx_mode(bp);
  4501. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4502. &bp->sp_state))
  4503. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4504. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4505. &bp->sp_state))
  4506. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4507. netif_addr_unlock_bh(bp->dev);
  4508. }
  4509. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4510. union event_ring_elem *elem)
  4511. {
  4512. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4513. DP(BNX2X_MSG_SP,
  4514. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4515. elem->message.data.vif_list_event.func_bit_map);
  4516. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4517. elem->message.data.vif_list_event.func_bit_map);
  4518. } else if (elem->message.data.vif_list_event.echo ==
  4519. VIF_LIST_RULE_SET) {
  4520. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4521. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4522. }
  4523. }
  4524. /* called with rtnl_lock */
  4525. static void bnx2x_after_function_update(struct bnx2x *bp)
  4526. {
  4527. int q, rc;
  4528. struct bnx2x_fastpath *fp;
  4529. struct bnx2x_queue_state_params queue_params = {NULL};
  4530. struct bnx2x_queue_update_params *q_update_params =
  4531. &queue_params.params.update;
  4532. /* Send Q update command with afex vlan removal values for all Qs */
  4533. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4534. /* set silent vlan removal values according to vlan mode */
  4535. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4536. &q_update_params->update_flags);
  4537. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4538. &q_update_params->update_flags);
  4539. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4540. /* in access mode mark mask and value are 0 to strip all vlans */
  4541. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4542. q_update_params->silent_removal_value = 0;
  4543. q_update_params->silent_removal_mask = 0;
  4544. } else {
  4545. q_update_params->silent_removal_value =
  4546. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4547. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4548. }
  4549. for_each_eth_queue(bp, q) {
  4550. /* Set the appropriate Queue object */
  4551. fp = &bp->fp[q];
  4552. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4553. /* send the ramrod */
  4554. rc = bnx2x_queue_state_change(bp, &queue_params);
  4555. if (rc < 0)
  4556. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4557. q);
  4558. }
  4559. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4560. fp = &bp->fp[FCOE_IDX(bp)];
  4561. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4562. /* clear pending completion bit */
  4563. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4564. /* mark latest Q bit */
  4565. smp_mb__before_atomic();
  4566. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4567. smp_mb__after_atomic();
  4568. /* send Q update ramrod for FCoE Q */
  4569. rc = bnx2x_queue_state_change(bp, &queue_params);
  4570. if (rc < 0)
  4571. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4572. q);
  4573. } else {
  4574. /* If no FCoE ring - ACK MCP now */
  4575. bnx2x_link_report(bp);
  4576. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4577. }
  4578. }
  4579. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4580. struct bnx2x *bp, u32 cid)
  4581. {
  4582. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4583. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4584. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4585. else
  4586. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4587. }
  4588. static void bnx2x_eq_int(struct bnx2x *bp)
  4589. {
  4590. u16 hw_cons, sw_cons, sw_prod;
  4591. union event_ring_elem *elem;
  4592. u8 echo;
  4593. u32 cid;
  4594. u8 opcode;
  4595. int rc, spqe_cnt = 0;
  4596. struct bnx2x_queue_sp_obj *q_obj;
  4597. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4598. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4599. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4600. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4601. * when we get the next-page we need to adjust so the loop
  4602. * condition below will be met. The next element is the size of a
  4603. * regular element and hence incrementing by 1
  4604. */
  4605. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4606. hw_cons++;
  4607. /* This function may never run in parallel with itself for a
  4608. * specific bp, thus there is no need in "paired" read memory
  4609. * barrier here.
  4610. */
  4611. sw_cons = bp->eq_cons;
  4612. sw_prod = bp->eq_prod;
  4613. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4614. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4615. for (; sw_cons != hw_cons;
  4616. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4617. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4618. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4619. if (!rc) {
  4620. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4621. rc);
  4622. goto next_spqe;
  4623. }
  4624. opcode = elem->message.opcode;
  4625. /* handle eq element */
  4626. switch (opcode) {
  4627. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4628. bnx2x_vf_mbx_schedule(bp,
  4629. &elem->message.data.vf_pf_event);
  4630. continue;
  4631. case EVENT_RING_OPCODE_STAT_QUERY:
  4632. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4633. "got statistics comp event %d\n",
  4634. bp->stats_comp++);
  4635. /* nothing to do with stats comp */
  4636. goto next_spqe;
  4637. case EVENT_RING_OPCODE_CFC_DEL:
  4638. /* handle according to cid range */
  4639. /*
  4640. * we may want to verify here that the bp state is
  4641. * HALTING
  4642. */
  4643. /* elem CID originates from FW; actually LE */
  4644. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4645. DP(BNX2X_MSG_SP,
  4646. "got delete ramrod for MULTI[%d]\n", cid);
  4647. if (CNIC_LOADED(bp) &&
  4648. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4649. goto next_spqe;
  4650. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4651. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4652. break;
  4653. goto next_spqe;
  4654. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4655. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4656. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4657. if (f_obj->complete_cmd(bp, f_obj,
  4658. BNX2X_F_CMD_TX_STOP))
  4659. break;
  4660. goto next_spqe;
  4661. case EVENT_RING_OPCODE_START_TRAFFIC:
  4662. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4663. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4664. if (f_obj->complete_cmd(bp, f_obj,
  4665. BNX2X_F_CMD_TX_START))
  4666. break;
  4667. goto next_spqe;
  4668. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4669. echo = elem->message.data.function_update_event.echo;
  4670. if (echo == SWITCH_UPDATE) {
  4671. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4672. "got FUNC_SWITCH_UPDATE ramrod\n");
  4673. if (f_obj->complete_cmd(
  4674. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4675. break;
  4676. } else {
  4677. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4678. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4679. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4680. f_obj->complete_cmd(bp, f_obj,
  4681. BNX2X_F_CMD_AFEX_UPDATE);
  4682. /* We will perform the Queues update from
  4683. * sp_rtnl task as all Queue SP operations
  4684. * should run under rtnl_lock.
  4685. */
  4686. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4687. }
  4688. goto next_spqe;
  4689. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4690. f_obj->complete_cmd(bp, f_obj,
  4691. BNX2X_F_CMD_AFEX_VIFLISTS);
  4692. bnx2x_after_afex_vif_lists(bp, elem);
  4693. goto next_spqe;
  4694. case EVENT_RING_OPCODE_FUNCTION_START:
  4695. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4696. "got FUNC_START ramrod\n");
  4697. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4698. break;
  4699. goto next_spqe;
  4700. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4701. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4702. "got FUNC_STOP ramrod\n");
  4703. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4704. break;
  4705. goto next_spqe;
  4706. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4707. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4708. "got set_timesync ramrod completion\n");
  4709. if (f_obj->complete_cmd(bp, f_obj,
  4710. BNX2X_F_CMD_SET_TIMESYNC))
  4711. break;
  4712. goto next_spqe;
  4713. }
  4714. switch (opcode | bp->state) {
  4715. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4716. BNX2X_STATE_OPEN):
  4717. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4718. BNX2X_STATE_OPENING_WAIT4_PORT):
  4719. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4720. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4721. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4722. SW_CID(elem->message.data.eth_event.echo));
  4723. rss_raw->clear_pending(rss_raw);
  4724. break;
  4725. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4726. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4727. case (EVENT_RING_OPCODE_SET_MAC |
  4728. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4729. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4730. BNX2X_STATE_OPEN):
  4731. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4732. BNX2X_STATE_DIAG):
  4733. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4734. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4735. DP(BNX2X_MSG_SP, "got (un)set vlan/mac ramrod\n");
  4736. bnx2x_handle_classification_eqe(bp, elem);
  4737. break;
  4738. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4739. BNX2X_STATE_OPEN):
  4740. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4741. BNX2X_STATE_DIAG):
  4742. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4743. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4744. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4745. bnx2x_handle_mcast_eqe(bp);
  4746. break;
  4747. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4748. BNX2X_STATE_OPEN):
  4749. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4750. BNX2X_STATE_DIAG):
  4751. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4752. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4753. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4754. bnx2x_handle_rx_mode_eqe(bp);
  4755. break;
  4756. default:
  4757. /* unknown event log error and continue */
  4758. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4759. elem->message.opcode, bp->state);
  4760. }
  4761. next_spqe:
  4762. spqe_cnt++;
  4763. } /* for */
  4764. smp_mb__before_atomic();
  4765. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4766. bp->eq_cons = sw_cons;
  4767. bp->eq_prod = sw_prod;
  4768. /* Make sure that above mem writes were issued towards the memory */
  4769. smp_wmb();
  4770. /* update producer */
  4771. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4772. }
  4773. static void bnx2x_sp_task(struct work_struct *work)
  4774. {
  4775. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4776. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4777. /* make sure the atomic interrupt_occurred has been written */
  4778. smp_rmb();
  4779. if (atomic_read(&bp->interrupt_occurred)) {
  4780. /* what work needs to be performed? */
  4781. u16 status = bnx2x_update_dsb_idx(bp);
  4782. DP(BNX2X_MSG_SP, "status %x\n", status);
  4783. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4784. atomic_set(&bp->interrupt_occurred, 0);
  4785. /* HW attentions */
  4786. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4787. bnx2x_attn_int(bp);
  4788. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4789. }
  4790. /* SP events: STAT_QUERY and others */
  4791. if (status & BNX2X_DEF_SB_IDX) {
  4792. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4793. if (FCOE_INIT(bp) &&
  4794. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4795. /* Prevent local bottom-halves from running as
  4796. * we are going to change the local NAPI list.
  4797. */
  4798. local_bh_disable();
  4799. napi_schedule(&bnx2x_fcoe(bp, napi));
  4800. local_bh_enable();
  4801. }
  4802. /* Handle EQ completions */
  4803. bnx2x_eq_int(bp);
  4804. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4805. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4806. status &= ~BNX2X_DEF_SB_IDX;
  4807. }
  4808. /* if status is non zero then perhaps something went wrong */
  4809. if (unlikely(status))
  4810. DP(BNX2X_MSG_SP,
  4811. "got an unknown interrupt! (status 0x%x)\n", status);
  4812. /* ack status block only if something was actually handled */
  4813. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4814. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4815. }
  4816. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4817. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4818. &bp->sp_state)) {
  4819. bnx2x_link_report(bp);
  4820. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4821. }
  4822. }
  4823. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4824. {
  4825. struct net_device *dev = dev_instance;
  4826. struct bnx2x *bp = netdev_priv(dev);
  4827. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4828. IGU_INT_DISABLE, 0);
  4829. #ifdef BNX2X_STOP_ON_ERROR
  4830. if (unlikely(bp->panic))
  4831. return IRQ_HANDLED;
  4832. #endif
  4833. if (CNIC_LOADED(bp)) {
  4834. struct cnic_ops *c_ops;
  4835. rcu_read_lock();
  4836. c_ops = rcu_dereference(bp->cnic_ops);
  4837. if (c_ops)
  4838. c_ops->cnic_handler(bp->cnic_data, NULL);
  4839. rcu_read_unlock();
  4840. }
  4841. /* schedule sp task to perform default status block work, ack
  4842. * attentions and enable interrupts.
  4843. */
  4844. bnx2x_schedule_sp_task(bp);
  4845. return IRQ_HANDLED;
  4846. }
  4847. /* end of slow path */
  4848. void bnx2x_drv_pulse(struct bnx2x *bp)
  4849. {
  4850. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4851. bp->fw_drv_pulse_wr_seq);
  4852. }
  4853. static void bnx2x_timer(struct timer_list *t)
  4854. {
  4855. struct bnx2x *bp = from_timer(bp, t, timer);
  4856. if (!netif_running(bp->dev))
  4857. return;
  4858. if (IS_PF(bp) &&
  4859. !BP_NOMCP(bp)) {
  4860. int mb_idx = BP_FW_MB_IDX(bp);
  4861. u16 drv_pulse;
  4862. u16 mcp_pulse;
  4863. ++bp->fw_drv_pulse_wr_seq;
  4864. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4865. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4866. bnx2x_drv_pulse(bp);
  4867. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4868. MCP_PULSE_SEQ_MASK);
  4869. /* The delta between driver pulse and mcp response
  4870. * should not get too big. If the MFW is more than 5 pulses
  4871. * behind, we should worry about it enough to generate an error
  4872. * log.
  4873. */
  4874. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4875. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4876. drv_pulse, mcp_pulse);
  4877. }
  4878. if (bp->state == BNX2X_STATE_OPEN)
  4879. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4880. /* sample pf vf bulletin board for new posts from pf */
  4881. if (IS_VF(bp))
  4882. bnx2x_timer_sriov(bp);
  4883. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4884. }
  4885. /* end of Statistics */
  4886. /* nic init */
  4887. /*
  4888. * nic init service functions
  4889. */
  4890. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4891. {
  4892. u32 i;
  4893. if (!(len%4) && !(addr%4))
  4894. for (i = 0; i < len; i += 4)
  4895. REG_WR(bp, addr + i, fill);
  4896. else
  4897. for (i = 0; i < len; i++)
  4898. REG_WR8(bp, addr + i, fill);
  4899. }
  4900. /* helper: writes FP SP data to FW - data_size in dwords */
  4901. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4902. int fw_sb_id,
  4903. u32 *sb_data_p,
  4904. u32 data_size)
  4905. {
  4906. int index;
  4907. for (index = 0; index < data_size; index++)
  4908. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4909. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4910. sizeof(u32)*index,
  4911. *(sb_data_p + index));
  4912. }
  4913. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4914. {
  4915. u32 *sb_data_p;
  4916. u32 data_size = 0;
  4917. struct hc_status_block_data_e2 sb_data_e2;
  4918. struct hc_status_block_data_e1x sb_data_e1x;
  4919. /* disable the function first */
  4920. if (!CHIP_IS_E1x(bp)) {
  4921. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4922. sb_data_e2.common.state = SB_DISABLED;
  4923. sb_data_e2.common.p_func.vf_valid = false;
  4924. sb_data_p = (u32 *)&sb_data_e2;
  4925. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4926. } else {
  4927. memset(&sb_data_e1x, 0,
  4928. sizeof(struct hc_status_block_data_e1x));
  4929. sb_data_e1x.common.state = SB_DISABLED;
  4930. sb_data_e1x.common.p_func.vf_valid = false;
  4931. sb_data_p = (u32 *)&sb_data_e1x;
  4932. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4933. }
  4934. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4935. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4936. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4937. CSTORM_STATUS_BLOCK_SIZE);
  4938. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4939. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4940. CSTORM_SYNC_BLOCK_SIZE);
  4941. }
  4942. /* helper: writes SP SB data to FW */
  4943. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4944. struct hc_sp_status_block_data *sp_sb_data)
  4945. {
  4946. int func = BP_FUNC(bp);
  4947. int i;
  4948. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4949. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4950. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4951. i*sizeof(u32),
  4952. *((u32 *)sp_sb_data + i));
  4953. }
  4954. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4955. {
  4956. int func = BP_FUNC(bp);
  4957. struct hc_sp_status_block_data sp_sb_data;
  4958. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4959. sp_sb_data.state = SB_DISABLED;
  4960. sp_sb_data.p_func.vf_valid = false;
  4961. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4962. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4963. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4964. CSTORM_SP_STATUS_BLOCK_SIZE);
  4965. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4966. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4967. CSTORM_SP_SYNC_BLOCK_SIZE);
  4968. }
  4969. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4970. int igu_sb_id, int igu_seg_id)
  4971. {
  4972. hc_sm->igu_sb_id = igu_sb_id;
  4973. hc_sm->igu_seg_id = igu_seg_id;
  4974. hc_sm->timer_value = 0xFF;
  4975. hc_sm->time_to_expire = 0xFFFFFFFF;
  4976. }
  4977. /* allocates state machine ids. */
  4978. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4979. {
  4980. /* zero out state machine indices */
  4981. /* rx indices */
  4982. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4983. /* tx indices */
  4984. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4985. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4986. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4987. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4988. /* map indices */
  4989. /* rx indices */
  4990. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4991. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4992. /* tx indices */
  4993. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4994. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4995. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4996. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4997. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4998. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4999. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  5000. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  5001. }
  5002. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  5003. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  5004. {
  5005. int igu_seg_id;
  5006. struct hc_status_block_data_e2 sb_data_e2;
  5007. struct hc_status_block_data_e1x sb_data_e1x;
  5008. struct hc_status_block_sm *hc_sm_p;
  5009. int data_size;
  5010. u32 *sb_data_p;
  5011. if (CHIP_INT_MODE_IS_BC(bp))
  5012. igu_seg_id = HC_SEG_ACCESS_NORM;
  5013. else
  5014. igu_seg_id = IGU_SEG_ACCESS_NORM;
  5015. bnx2x_zero_fp_sb(bp, fw_sb_id);
  5016. if (!CHIP_IS_E1x(bp)) {
  5017. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  5018. sb_data_e2.common.state = SB_ENABLED;
  5019. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  5020. sb_data_e2.common.p_func.vf_id = vfid;
  5021. sb_data_e2.common.p_func.vf_valid = vf_valid;
  5022. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  5023. sb_data_e2.common.same_igu_sb_1b = true;
  5024. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  5025. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  5026. hc_sm_p = sb_data_e2.common.state_machine;
  5027. sb_data_p = (u32 *)&sb_data_e2;
  5028. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  5029. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  5030. } else {
  5031. memset(&sb_data_e1x, 0,
  5032. sizeof(struct hc_status_block_data_e1x));
  5033. sb_data_e1x.common.state = SB_ENABLED;
  5034. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5035. sb_data_e1x.common.p_func.vf_id = 0xff;
  5036. sb_data_e1x.common.p_func.vf_valid = false;
  5037. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5038. sb_data_e1x.common.same_igu_sb_1b = true;
  5039. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5040. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5041. hc_sm_p = sb_data_e1x.common.state_machine;
  5042. sb_data_p = (u32 *)&sb_data_e1x;
  5043. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5044. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5045. }
  5046. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5047. igu_sb_id, igu_seg_id);
  5048. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5049. igu_sb_id, igu_seg_id);
  5050. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5051. /* write indices to HW - PCI guarantees endianity of regpairs */
  5052. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5053. }
  5054. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5055. u16 tx_usec, u16 rx_usec)
  5056. {
  5057. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5058. false, rx_usec);
  5059. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5060. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5061. tx_usec);
  5062. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5063. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5064. tx_usec);
  5065. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5066. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5067. tx_usec);
  5068. }
  5069. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5070. {
  5071. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5072. dma_addr_t mapping = bp->def_status_blk_mapping;
  5073. int igu_sp_sb_index;
  5074. int igu_seg_id;
  5075. int port = BP_PORT(bp);
  5076. int func = BP_FUNC(bp);
  5077. int reg_offset, reg_offset_en5;
  5078. u64 section;
  5079. int index;
  5080. struct hc_sp_status_block_data sp_sb_data;
  5081. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5082. if (CHIP_INT_MODE_IS_BC(bp)) {
  5083. igu_sp_sb_index = DEF_SB_IGU_ID;
  5084. igu_seg_id = HC_SEG_ACCESS_DEF;
  5085. } else {
  5086. igu_sp_sb_index = bp->igu_dsb_id;
  5087. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5088. }
  5089. /* ATTN */
  5090. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5091. atten_status_block);
  5092. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5093. bp->attn_state = 0;
  5094. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5095. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5096. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5097. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5098. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5099. int sindex;
  5100. /* take care of sig[0]..sig[4] */
  5101. for (sindex = 0; sindex < 4; sindex++)
  5102. bp->attn_group[index].sig[sindex] =
  5103. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5104. if (!CHIP_IS_E1x(bp))
  5105. /*
  5106. * enable5 is separate from the rest of the registers,
  5107. * and therefore the address skip is 4
  5108. * and not 16 between the different groups
  5109. */
  5110. bp->attn_group[index].sig[4] = REG_RD(bp,
  5111. reg_offset_en5 + 0x4*index);
  5112. else
  5113. bp->attn_group[index].sig[4] = 0;
  5114. }
  5115. if (bp->common.int_block == INT_BLOCK_HC) {
  5116. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5117. HC_REG_ATTN_MSG0_ADDR_L);
  5118. REG_WR(bp, reg_offset, U64_LO(section));
  5119. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5120. } else if (!CHIP_IS_E1x(bp)) {
  5121. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5122. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5123. }
  5124. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5125. sp_sb);
  5126. bnx2x_zero_sp_sb(bp);
  5127. /* PCI guarantees endianity of regpairs */
  5128. sp_sb_data.state = SB_ENABLED;
  5129. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5130. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5131. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5132. sp_sb_data.igu_seg_id = igu_seg_id;
  5133. sp_sb_data.p_func.pf_id = func;
  5134. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5135. sp_sb_data.p_func.vf_id = 0xff;
  5136. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5137. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5138. }
  5139. void bnx2x_update_coalesce(struct bnx2x *bp)
  5140. {
  5141. int i;
  5142. for_each_eth_queue(bp, i)
  5143. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5144. bp->tx_ticks, bp->rx_ticks);
  5145. }
  5146. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5147. {
  5148. spin_lock_init(&bp->spq_lock);
  5149. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5150. bp->spq_prod_idx = 0;
  5151. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5152. bp->spq_prod_bd = bp->spq;
  5153. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5154. }
  5155. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5156. {
  5157. int i;
  5158. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5159. union event_ring_elem *elem =
  5160. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5161. elem->next_page.addr.hi =
  5162. cpu_to_le32(U64_HI(bp->eq_mapping +
  5163. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5164. elem->next_page.addr.lo =
  5165. cpu_to_le32(U64_LO(bp->eq_mapping +
  5166. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5167. }
  5168. bp->eq_cons = 0;
  5169. bp->eq_prod = NUM_EQ_DESC;
  5170. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5171. /* we want a warning message before it gets wrought... */
  5172. atomic_set(&bp->eq_spq_left,
  5173. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5174. }
  5175. /* called with netif_addr_lock_bh() */
  5176. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5177. unsigned long rx_mode_flags,
  5178. unsigned long rx_accept_flags,
  5179. unsigned long tx_accept_flags,
  5180. unsigned long ramrod_flags)
  5181. {
  5182. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5183. int rc;
  5184. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5185. /* Prepare ramrod parameters */
  5186. ramrod_param.cid = 0;
  5187. ramrod_param.cl_id = cl_id;
  5188. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5189. ramrod_param.func_id = BP_FUNC(bp);
  5190. ramrod_param.pstate = &bp->sp_state;
  5191. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5192. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5193. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5194. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5195. ramrod_param.ramrod_flags = ramrod_flags;
  5196. ramrod_param.rx_mode_flags = rx_mode_flags;
  5197. ramrod_param.rx_accept_flags = rx_accept_flags;
  5198. ramrod_param.tx_accept_flags = tx_accept_flags;
  5199. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5200. if (rc < 0) {
  5201. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5202. return rc;
  5203. }
  5204. return 0;
  5205. }
  5206. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5207. unsigned long *rx_accept_flags,
  5208. unsigned long *tx_accept_flags)
  5209. {
  5210. /* Clear the flags first */
  5211. *rx_accept_flags = 0;
  5212. *tx_accept_flags = 0;
  5213. switch (rx_mode) {
  5214. case BNX2X_RX_MODE_NONE:
  5215. /*
  5216. * 'drop all' supersedes any accept flags that may have been
  5217. * passed to the function.
  5218. */
  5219. break;
  5220. case BNX2X_RX_MODE_NORMAL:
  5221. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5222. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5223. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5224. /* internal switching mode */
  5225. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5226. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5227. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5228. if (bp->accept_any_vlan) {
  5229. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5230. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5231. }
  5232. break;
  5233. case BNX2X_RX_MODE_ALLMULTI:
  5234. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5235. __set_bit(BNX2X_ACCEPT_ALL_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_ALL_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_PROMISC:
  5247. /* According to definition of SI mode, iface in promisc mode
  5248. * should receive matched and unmatched (in resolution of port)
  5249. * unicast packets.
  5250. */
  5251. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5252. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5253. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5254. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5255. /* internal switching mode */
  5256. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5257. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5258. if (IS_MF_SI(bp))
  5259. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5260. else
  5261. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5262. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5263. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5264. break;
  5265. default:
  5266. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5267. return -EINVAL;
  5268. }
  5269. return 0;
  5270. }
  5271. /* called with netif_addr_lock_bh() */
  5272. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5273. {
  5274. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5275. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5276. int rc;
  5277. if (!NO_FCOE(bp))
  5278. /* Configure rx_mode of FCoE Queue */
  5279. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5280. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5281. &tx_accept_flags);
  5282. if (rc)
  5283. return rc;
  5284. __set_bit(RAMROD_RX, &ramrod_flags);
  5285. __set_bit(RAMROD_TX, &ramrod_flags);
  5286. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5287. rx_accept_flags, tx_accept_flags,
  5288. ramrod_flags);
  5289. }
  5290. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5291. {
  5292. int i;
  5293. /* Zero this manually as its initialization is
  5294. currently missing in the initTool */
  5295. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5296. REG_WR(bp, BAR_USTRORM_INTMEM +
  5297. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5298. if (!CHIP_IS_E1x(bp)) {
  5299. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5300. CHIP_INT_MODE_IS_BC(bp) ?
  5301. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5302. }
  5303. }
  5304. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5305. {
  5306. switch (load_code) {
  5307. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5308. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5309. bnx2x_init_internal_common(bp);
  5310. /* no break */
  5311. case FW_MSG_CODE_DRV_LOAD_PORT:
  5312. /* nothing to do */
  5313. /* no break */
  5314. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5315. /* internal memory per function is
  5316. initialized inside bnx2x_pf_init */
  5317. break;
  5318. default:
  5319. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5320. break;
  5321. }
  5322. }
  5323. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5324. {
  5325. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5326. }
  5327. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5328. {
  5329. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5330. }
  5331. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5332. {
  5333. if (CHIP_IS_E1x(fp->bp))
  5334. return BP_L_ID(fp->bp) + fp->index;
  5335. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5336. return bnx2x_fp_igu_sb_id(fp);
  5337. }
  5338. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5339. {
  5340. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5341. u8 cos;
  5342. unsigned long q_type = 0;
  5343. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5344. fp->rx_queue = fp_idx;
  5345. fp->cid = fp_idx;
  5346. fp->cl_id = bnx2x_fp_cl_id(fp);
  5347. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5348. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5349. /* qZone id equals to FW (per path) client id */
  5350. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5351. /* init shortcut */
  5352. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5353. /* Setup SB indices */
  5354. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5355. /* Configure Queue State object */
  5356. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5357. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5358. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5359. /* init tx data */
  5360. for_each_cos_in_tx_queue(fp, cos) {
  5361. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5362. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5363. FP_COS_TO_TXQ(fp, cos, bp),
  5364. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5365. cids[cos] = fp->txdata_ptr[cos]->cid;
  5366. }
  5367. /* nothing more for vf to do here */
  5368. if (IS_VF(bp))
  5369. return;
  5370. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5371. fp->fw_sb_id, fp->igu_sb_id);
  5372. bnx2x_update_fpsb_idx(fp);
  5373. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5374. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5375. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5376. /**
  5377. * Configure classification DBs: Always enable Tx switching
  5378. */
  5379. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5380. DP(NETIF_MSG_IFUP,
  5381. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5382. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5383. fp->igu_sb_id);
  5384. }
  5385. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5386. {
  5387. int i;
  5388. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5389. struct eth_tx_next_bd *tx_next_bd =
  5390. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5391. tx_next_bd->addr_hi =
  5392. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5393. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5394. tx_next_bd->addr_lo =
  5395. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5396. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5397. }
  5398. *txdata->tx_cons_sb = cpu_to_le16(0);
  5399. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5400. txdata->tx_db.data.zero_fill1 = 0;
  5401. txdata->tx_db.data.prod = 0;
  5402. txdata->tx_pkt_prod = 0;
  5403. txdata->tx_pkt_cons = 0;
  5404. txdata->tx_bd_prod = 0;
  5405. txdata->tx_bd_cons = 0;
  5406. txdata->tx_pkt = 0;
  5407. }
  5408. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5409. {
  5410. int i;
  5411. for_each_tx_queue_cnic(bp, i)
  5412. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5413. }
  5414. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5415. {
  5416. int i;
  5417. u8 cos;
  5418. for_each_eth_queue(bp, i)
  5419. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5420. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5421. }
  5422. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5423. {
  5424. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5425. unsigned long q_type = 0;
  5426. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5427. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5428. BNX2X_FCOE_ETH_CL_ID_IDX);
  5429. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5430. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5431. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5432. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5433. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5434. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5435. fp);
  5436. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5437. /* qZone id equals to FW (per path) client id */
  5438. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5439. /* init shortcut */
  5440. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5441. bnx2x_rx_ustorm_prods_offset(fp);
  5442. /* Configure Queue State object */
  5443. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5444. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5445. /* No multi-CoS for FCoE L2 client */
  5446. BUG_ON(fp->max_cos != 1);
  5447. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5448. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5449. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5450. DP(NETIF_MSG_IFUP,
  5451. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5452. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5453. fp->igu_sb_id);
  5454. }
  5455. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5456. {
  5457. if (!NO_FCOE(bp))
  5458. bnx2x_init_fcoe_fp(bp);
  5459. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5460. BNX2X_VF_ID_INVALID, false,
  5461. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5462. /* ensure status block indices were read */
  5463. rmb();
  5464. bnx2x_init_rx_rings_cnic(bp);
  5465. bnx2x_init_tx_rings_cnic(bp);
  5466. /* flush all */
  5467. mb();
  5468. mmiowb();
  5469. }
  5470. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5471. {
  5472. int i;
  5473. /* Setup NIC internals and enable interrupts */
  5474. for_each_eth_queue(bp, i)
  5475. bnx2x_init_eth_fp(bp, i);
  5476. /* ensure status block indices were read */
  5477. rmb();
  5478. bnx2x_init_rx_rings(bp);
  5479. bnx2x_init_tx_rings(bp);
  5480. if (IS_PF(bp)) {
  5481. /* Initialize MOD_ABS interrupts */
  5482. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5483. bp->common.shmem_base,
  5484. bp->common.shmem2_base, BP_PORT(bp));
  5485. /* initialize the default status block and sp ring */
  5486. bnx2x_init_def_sb(bp);
  5487. bnx2x_update_dsb_idx(bp);
  5488. bnx2x_init_sp_ring(bp);
  5489. } else {
  5490. bnx2x_memset_stats(bp);
  5491. }
  5492. }
  5493. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5494. {
  5495. bnx2x_init_eq_ring(bp);
  5496. bnx2x_init_internal(bp, load_code);
  5497. bnx2x_pf_init(bp);
  5498. bnx2x_stats_init(bp);
  5499. /* flush all before enabling interrupts */
  5500. mb();
  5501. mmiowb();
  5502. bnx2x_int_enable(bp);
  5503. /* Check for SPIO5 */
  5504. bnx2x_attn_int_deasserted0(bp,
  5505. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5506. AEU_INPUTS_ATTN_BITS_SPIO5);
  5507. }
  5508. /* gzip service functions */
  5509. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5510. {
  5511. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5512. &bp->gunzip_mapping, GFP_KERNEL);
  5513. if (bp->gunzip_buf == NULL)
  5514. goto gunzip_nomem1;
  5515. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5516. if (bp->strm == NULL)
  5517. goto gunzip_nomem2;
  5518. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5519. if (bp->strm->workspace == NULL)
  5520. goto gunzip_nomem3;
  5521. return 0;
  5522. gunzip_nomem3:
  5523. kfree(bp->strm);
  5524. bp->strm = NULL;
  5525. gunzip_nomem2:
  5526. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5527. bp->gunzip_mapping);
  5528. bp->gunzip_buf = NULL;
  5529. gunzip_nomem1:
  5530. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5531. return -ENOMEM;
  5532. }
  5533. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5534. {
  5535. if (bp->strm) {
  5536. vfree(bp->strm->workspace);
  5537. kfree(bp->strm);
  5538. bp->strm = NULL;
  5539. }
  5540. if (bp->gunzip_buf) {
  5541. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5542. bp->gunzip_mapping);
  5543. bp->gunzip_buf = NULL;
  5544. }
  5545. }
  5546. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5547. {
  5548. int n, rc;
  5549. /* check gzip header */
  5550. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5551. BNX2X_ERR("Bad gzip header\n");
  5552. return -EINVAL;
  5553. }
  5554. n = 10;
  5555. #define FNAME 0x8
  5556. if (zbuf[3] & FNAME)
  5557. while ((zbuf[n++] != 0) && (n < len));
  5558. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5559. bp->strm->avail_in = len - n;
  5560. bp->strm->next_out = bp->gunzip_buf;
  5561. bp->strm->avail_out = FW_BUF_SIZE;
  5562. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5563. if (rc != Z_OK)
  5564. return rc;
  5565. rc = zlib_inflate(bp->strm, Z_FINISH);
  5566. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5567. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5568. bp->strm->msg);
  5569. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5570. if (bp->gunzip_outlen & 0x3)
  5571. netdev_err(bp->dev,
  5572. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5573. bp->gunzip_outlen);
  5574. bp->gunzip_outlen >>= 2;
  5575. zlib_inflateEnd(bp->strm);
  5576. if (rc == Z_STREAM_END)
  5577. return 0;
  5578. return rc;
  5579. }
  5580. /* nic load/unload */
  5581. /*
  5582. * General service functions
  5583. */
  5584. /* send a NIG loopback debug packet */
  5585. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5586. {
  5587. u32 wb_write[3];
  5588. /* Ethernet source and destination addresses */
  5589. wb_write[0] = 0x55555555;
  5590. wb_write[1] = 0x55555555;
  5591. wb_write[2] = 0x20; /* SOP */
  5592. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5593. /* NON-IP protocol */
  5594. wb_write[0] = 0x09000000;
  5595. wb_write[1] = 0x55555555;
  5596. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5597. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5598. }
  5599. /* some of the internal memories
  5600. * are not directly readable from the driver
  5601. * to test them we send debug packets
  5602. */
  5603. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5604. {
  5605. int factor;
  5606. int count, i;
  5607. u32 val = 0;
  5608. if (CHIP_REV_IS_FPGA(bp))
  5609. factor = 120;
  5610. else if (CHIP_REV_IS_EMUL(bp))
  5611. factor = 200;
  5612. else
  5613. factor = 1;
  5614. /* Disable inputs of parser neighbor blocks */
  5615. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5616. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5617. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5618. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5619. /* Write 0 to parser credits for CFC search request */
  5620. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5621. /* send Ethernet packet */
  5622. bnx2x_lb_pckt(bp);
  5623. /* TODO do i reset NIG statistic? */
  5624. /* Wait until NIG register shows 1 packet of size 0x10 */
  5625. count = 1000 * factor;
  5626. while (count) {
  5627. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5628. val = *bnx2x_sp(bp, wb_data[0]);
  5629. if (val == 0x10)
  5630. break;
  5631. usleep_range(10000, 20000);
  5632. count--;
  5633. }
  5634. if (val != 0x10) {
  5635. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5636. return -1;
  5637. }
  5638. /* Wait until PRS register shows 1 packet */
  5639. count = 1000 * factor;
  5640. while (count) {
  5641. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5642. if (val == 1)
  5643. break;
  5644. usleep_range(10000, 20000);
  5645. count--;
  5646. }
  5647. if (val != 0x1) {
  5648. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5649. return -2;
  5650. }
  5651. /* Reset and init BRB, PRS */
  5652. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5653. msleep(50);
  5654. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5655. msleep(50);
  5656. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5657. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5658. DP(NETIF_MSG_HW, "part2\n");
  5659. /* Disable inputs of parser neighbor blocks */
  5660. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5661. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5662. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5663. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5664. /* Write 0 to parser credits for CFC search request */
  5665. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5666. /* send 10 Ethernet packets */
  5667. for (i = 0; i < 10; i++)
  5668. bnx2x_lb_pckt(bp);
  5669. /* Wait until NIG register shows 10 + 1
  5670. packets of size 11*0x10 = 0xb0 */
  5671. count = 1000 * factor;
  5672. while (count) {
  5673. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5674. val = *bnx2x_sp(bp, wb_data[0]);
  5675. if (val == 0xb0)
  5676. break;
  5677. usleep_range(10000, 20000);
  5678. count--;
  5679. }
  5680. if (val != 0xb0) {
  5681. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5682. return -3;
  5683. }
  5684. /* Wait until PRS register shows 2 packets */
  5685. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5686. if (val != 2)
  5687. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5688. /* Write 1 to parser credits for CFC search request */
  5689. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5690. /* Wait until PRS register shows 3 packets */
  5691. msleep(10 * factor);
  5692. /* Wait until NIG register shows 1 packet of size 0x10 */
  5693. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5694. if (val != 3)
  5695. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5696. /* clear NIG EOP FIFO */
  5697. for (i = 0; i < 11; i++)
  5698. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5699. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5700. if (val != 1) {
  5701. BNX2X_ERR("clear of NIG failed\n");
  5702. return -4;
  5703. }
  5704. /* Reset and init BRB, PRS, NIG */
  5705. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5706. msleep(50);
  5707. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5708. msleep(50);
  5709. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5710. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5711. if (!CNIC_SUPPORT(bp))
  5712. /* set NIC mode */
  5713. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5714. /* Enable inputs of parser neighbor blocks */
  5715. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5716. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5717. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5718. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5719. DP(NETIF_MSG_HW, "done\n");
  5720. return 0; /* OK */
  5721. }
  5722. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5723. {
  5724. u32 val;
  5725. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5726. if (!CHIP_IS_E1x(bp))
  5727. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5728. else
  5729. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5730. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5731. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5732. /*
  5733. * mask read length error interrupts in brb for parser
  5734. * (parsing unit and 'checksum and crc' unit)
  5735. * these errors are legal (PU reads fixed length and CAC can cause
  5736. * read length error on truncated packets)
  5737. */
  5738. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5739. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5740. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5741. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5742. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5743. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5744. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5745. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5746. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5747. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5748. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5749. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5750. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5751. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5752. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5753. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5754. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5755. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5756. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5757. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5758. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5759. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5760. if (!CHIP_IS_E1x(bp))
  5761. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5762. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5763. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5764. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5765. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5766. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5767. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5768. if (!CHIP_IS_E1x(bp))
  5769. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5770. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5771. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5772. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5773. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5774. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5775. }
  5776. static void bnx2x_reset_common(struct bnx2x *bp)
  5777. {
  5778. u32 val = 0x1400;
  5779. /* reset_common */
  5780. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5781. 0xd3ffff7f);
  5782. if (CHIP_IS_E3(bp)) {
  5783. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5784. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5785. }
  5786. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5787. }
  5788. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5789. {
  5790. bp->dmae_ready = 0;
  5791. spin_lock_init(&bp->dmae_lock);
  5792. }
  5793. static void bnx2x_init_pxp(struct bnx2x *bp)
  5794. {
  5795. u16 devctl;
  5796. int r_order, w_order;
  5797. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5798. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5799. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5800. if (bp->mrrs == -1)
  5801. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5802. else {
  5803. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5804. r_order = bp->mrrs;
  5805. }
  5806. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5807. }
  5808. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5809. {
  5810. int is_required;
  5811. u32 val;
  5812. int port;
  5813. if (BP_NOMCP(bp))
  5814. return;
  5815. is_required = 0;
  5816. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5817. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5818. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5819. is_required = 1;
  5820. /*
  5821. * The fan failure mechanism is usually related to the PHY type since
  5822. * the power consumption of the board is affected by the PHY. Currently,
  5823. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5824. */
  5825. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5826. for (port = PORT_0; port < PORT_MAX; port++) {
  5827. is_required |=
  5828. bnx2x_fan_failure_det_req(
  5829. bp,
  5830. bp->common.shmem_base,
  5831. bp->common.shmem2_base,
  5832. port);
  5833. }
  5834. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5835. if (is_required == 0)
  5836. return;
  5837. /* Fan failure is indicated by SPIO 5 */
  5838. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5839. /* set to active low mode */
  5840. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5841. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5842. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5843. /* enable interrupt to signal the IGU */
  5844. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5845. val |= MISC_SPIO_SPIO5;
  5846. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5847. }
  5848. void bnx2x_pf_disable(struct bnx2x *bp)
  5849. {
  5850. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5851. val &= ~IGU_PF_CONF_FUNC_EN;
  5852. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5853. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5854. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5855. }
  5856. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5857. {
  5858. u32 shmem_base[2], shmem2_base[2];
  5859. /* Avoid common init in case MFW supports LFA */
  5860. if (SHMEM2_RD(bp, size) >
  5861. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5862. return;
  5863. shmem_base[0] = bp->common.shmem_base;
  5864. shmem2_base[0] = bp->common.shmem2_base;
  5865. if (!CHIP_IS_E1x(bp)) {
  5866. shmem_base[1] =
  5867. SHMEM2_RD(bp, other_shmem_base_addr);
  5868. shmem2_base[1] =
  5869. SHMEM2_RD(bp, other_shmem2_base_addr);
  5870. }
  5871. bnx2x_acquire_phy_lock(bp);
  5872. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5873. bp->common.chip_id);
  5874. bnx2x_release_phy_lock(bp);
  5875. }
  5876. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5877. {
  5878. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5879. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5880. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5881. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5882. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5883. /* make sure this value is 0 */
  5884. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5885. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5886. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5887. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5888. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5889. }
  5890. static void bnx2x_set_endianity(struct bnx2x *bp)
  5891. {
  5892. #ifdef __BIG_ENDIAN
  5893. bnx2x_config_endianity(bp, 1);
  5894. #else
  5895. bnx2x_config_endianity(bp, 0);
  5896. #endif
  5897. }
  5898. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5899. {
  5900. bnx2x_config_endianity(bp, 0);
  5901. }
  5902. /**
  5903. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5904. *
  5905. * @bp: driver handle
  5906. */
  5907. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5908. {
  5909. u32 val;
  5910. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5911. /*
  5912. * take the RESET lock to protect undi_unload flow from accessing
  5913. * registers while we're resetting the chip
  5914. */
  5915. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5916. bnx2x_reset_common(bp);
  5917. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5918. val = 0xfffc;
  5919. if (CHIP_IS_E3(bp)) {
  5920. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5921. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5922. }
  5923. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5924. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5925. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5926. if (!CHIP_IS_E1x(bp)) {
  5927. u8 abs_func_id;
  5928. /**
  5929. * 4-port mode or 2-port mode we need to turn of master-enable
  5930. * for everyone, after that, turn it back on for self.
  5931. * so, we disregard multi-function or not, and always disable
  5932. * for all functions on the given path, this means 0,2,4,6 for
  5933. * path 0 and 1,3,5,7 for path 1
  5934. */
  5935. for (abs_func_id = BP_PATH(bp);
  5936. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5937. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5938. REG_WR(bp,
  5939. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5940. 1);
  5941. continue;
  5942. }
  5943. bnx2x_pretend_func(bp, abs_func_id);
  5944. /* clear pf enable */
  5945. bnx2x_pf_disable(bp);
  5946. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5947. }
  5948. }
  5949. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5950. if (CHIP_IS_E1(bp)) {
  5951. /* enable HW interrupt from PXP on USDM overflow
  5952. bit 16 on INT_MASK_0 */
  5953. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5954. }
  5955. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5956. bnx2x_init_pxp(bp);
  5957. bnx2x_set_endianity(bp);
  5958. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5959. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5960. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5961. /* let the HW do it's magic ... */
  5962. msleep(100);
  5963. /* finish PXP init */
  5964. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5965. if (val != 1) {
  5966. BNX2X_ERR("PXP2 CFG failed\n");
  5967. return -EBUSY;
  5968. }
  5969. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5970. if (val != 1) {
  5971. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5972. return -EBUSY;
  5973. }
  5974. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5975. * have entries with value "0" and valid bit on.
  5976. * This needs to be done by the first PF that is loaded in a path
  5977. * (i.e. common phase)
  5978. */
  5979. if (!CHIP_IS_E1x(bp)) {
  5980. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5981. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5982. * This occurs when a different function (func2,3) is being marked
  5983. * as "scan-off". Real-life scenario for example: if a driver is being
  5984. * load-unloaded while func6,7 are down. This will cause the timer to access
  5985. * the ilt, translate to a logical address and send a request to read/write.
  5986. * Since the ilt for the function that is down is not valid, this will cause
  5987. * a translation error which is unrecoverable.
  5988. * The Workaround is intended to make sure that when this happens nothing fatal
  5989. * will occur. The workaround:
  5990. * 1. First PF driver which loads on a path will:
  5991. * a. After taking the chip out of reset, by using pretend,
  5992. * it will write "0" to the following registers of
  5993. * the other vnics.
  5994. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5995. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5996. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5997. * And for itself it will write '1' to
  5998. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5999. * dmae-operations (writing to pram for example.)
  6000. * note: can be done for only function 6,7 but cleaner this
  6001. * way.
  6002. * b. Write zero+valid to the entire ILT.
  6003. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  6004. * VNIC3 (of that port). The range allocated will be the
  6005. * entire ILT. This is needed to prevent ILT range error.
  6006. * 2. Any PF driver load flow:
  6007. * a. ILT update with the physical addresses of the allocated
  6008. * logical pages.
  6009. * b. Wait 20msec. - note that this timeout is needed to make
  6010. * sure there are no requests in one of the PXP internal
  6011. * queues with "old" ILT addresses.
  6012. * c. PF enable in the PGLC.
  6013. * d. Clear the was_error of the PF in the PGLC. (could have
  6014. * occurred while driver was down)
  6015. * e. PF enable in the CFC (WEAK + STRONG)
  6016. * f. Timers scan enable
  6017. * 3. PF driver unload flow:
  6018. * a. Clear the Timers scan_en.
  6019. * b. Polling for scan_on=0 for that PF.
  6020. * c. Clear the PF enable bit in the PXP.
  6021. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  6022. * e. Write zero+valid to all ILT entries (The valid bit must
  6023. * stay set)
  6024. * f. If this is VNIC 3 of a port then also init
  6025. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  6026. * to the last entry in the ILT.
  6027. *
  6028. * Notes:
  6029. * Currently the PF error in the PGLC is non recoverable.
  6030. * In the future the there will be a recovery routine for this error.
  6031. * Currently attention is masked.
  6032. * Having an MCP lock on the load/unload process does not guarantee that
  6033. * there is no Timer disable during Func6/7 enable. This is because the
  6034. * Timers scan is currently being cleared by the MCP on FLR.
  6035. * Step 2.d can be done only for PF6/7 and the driver can also check if
  6036. * there is error before clearing it. But the flow above is simpler and
  6037. * more general.
  6038. * All ILT entries are written by zero+valid and not just PF6/7
  6039. * ILT entries since in the future the ILT entries allocation for
  6040. * PF-s might be dynamic.
  6041. */
  6042. struct ilt_client_info ilt_cli;
  6043. struct bnx2x_ilt ilt;
  6044. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6045. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6046. /* initialize dummy TM client */
  6047. ilt_cli.start = 0;
  6048. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6049. ilt_cli.client_num = ILT_CLIENT_TM;
  6050. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6051. * Step 2: set the timers first/last ilt entry to point
  6052. * to the entire range to prevent ILT range error for 3rd/4th
  6053. * vnic (this code assumes existence of the vnic)
  6054. *
  6055. * both steps performed by call to bnx2x_ilt_client_init_op()
  6056. * with dummy TM client
  6057. *
  6058. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6059. * and his brother are split registers
  6060. */
  6061. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6062. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6063. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6064. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6065. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6066. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6067. }
  6068. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6069. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6070. if (!CHIP_IS_E1x(bp)) {
  6071. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6072. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6073. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6074. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6075. /* let the HW do it's magic ... */
  6076. do {
  6077. msleep(200);
  6078. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6079. } while (factor-- && (val != 1));
  6080. if (val != 1) {
  6081. BNX2X_ERR("ATC_INIT failed\n");
  6082. return -EBUSY;
  6083. }
  6084. }
  6085. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6086. bnx2x_iov_init_dmae(bp);
  6087. /* clean the DMAE memory */
  6088. bp->dmae_ready = 1;
  6089. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6090. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6091. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6092. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6093. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6094. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6095. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6096. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6097. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6098. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6099. /* QM queues pointers table */
  6100. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6101. /* soft reset pulse */
  6102. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6103. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6104. if (CNIC_SUPPORT(bp))
  6105. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6106. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6107. if (!CHIP_REV_IS_SLOW(bp))
  6108. /* enable hw interrupt from doorbell Q */
  6109. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6110. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6111. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6112. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6113. if (!CHIP_IS_E1(bp))
  6114. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6115. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6116. if (IS_MF_AFEX(bp)) {
  6117. /* configure that VNTag and VLAN headers must be
  6118. * received in afex mode
  6119. */
  6120. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6121. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6122. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6123. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6124. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6125. } else {
  6126. /* Bit-map indicating which L2 hdrs may appear
  6127. * after the basic Ethernet header
  6128. */
  6129. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6130. bp->path_has_ovlan ? 7 : 6);
  6131. }
  6132. }
  6133. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6134. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6135. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6136. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6137. if (!CHIP_IS_E1x(bp)) {
  6138. /* reset VFC memories */
  6139. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6140. VFC_MEMORIES_RST_REG_CAM_RST |
  6141. VFC_MEMORIES_RST_REG_RAM_RST);
  6142. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6143. VFC_MEMORIES_RST_REG_CAM_RST |
  6144. VFC_MEMORIES_RST_REG_RAM_RST);
  6145. msleep(20);
  6146. }
  6147. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6148. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6149. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6150. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6151. /* sync semi rtc */
  6152. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6153. 0x80000000);
  6154. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6155. 0x80000000);
  6156. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6157. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6158. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6159. if (!CHIP_IS_E1x(bp)) {
  6160. if (IS_MF_AFEX(bp)) {
  6161. /* configure that VNTag and VLAN headers must be
  6162. * sent in afex mode
  6163. */
  6164. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6165. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6166. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6167. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6168. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6169. } else {
  6170. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6171. bp->path_has_ovlan ? 7 : 6);
  6172. }
  6173. }
  6174. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6175. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6176. if (CNIC_SUPPORT(bp)) {
  6177. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6178. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6179. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6180. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6181. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6182. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6183. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6184. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6185. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6186. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6187. }
  6188. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6189. if (sizeof(union cdu_context) != 1024)
  6190. /* we currently assume that a context is 1024 bytes */
  6191. dev_alert(&bp->pdev->dev,
  6192. "please adjust the size of cdu_context(%ld)\n",
  6193. (long)sizeof(union cdu_context));
  6194. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6195. val = (4 << 24) + (0 << 12) + 1024;
  6196. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6197. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6198. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6199. /* enable context validation interrupt from CFC */
  6200. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6201. /* set the thresholds to prevent CFC/CDU race */
  6202. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6203. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6204. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6205. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6206. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6207. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6208. /* Reset PCIE errors for debug */
  6209. REG_WR(bp, 0x2814, 0xffffffff);
  6210. REG_WR(bp, 0x3820, 0xffffffff);
  6211. if (!CHIP_IS_E1x(bp)) {
  6212. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6213. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6214. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6215. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6216. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6217. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6218. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6219. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6220. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6221. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6222. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6223. }
  6224. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6225. if (!CHIP_IS_E1(bp)) {
  6226. /* in E3 this done in per-port section */
  6227. if (!CHIP_IS_E3(bp))
  6228. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6229. }
  6230. if (CHIP_IS_E1H(bp))
  6231. /* not applicable for E2 (and above ...) */
  6232. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6233. if (CHIP_REV_IS_SLOW(bp))
  6234. msleep(200);
  6235. /* finish CFC init */
  6236. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6237. if (val != 1) {
  6238. BNX2X_ERR("CFC LL_INIT failed\n");
  6239. return -EBUSY;
  6240. }
  6241. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6242. if (val != 1) {
  6243. BNX2X_ERR("CFC AC_INIT failed\n");
  6244. return -EBUSY;
  6245. }
  6246. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6247. if (val != 1) {
  6248. BNX2X_ERR("CFC CAM_INIT failed\n");
  6249. return -EBUSY;
  6250. }
  6251. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6252. if (CHIP_IS_E1(bp)) {
  6253. /* read NIG statistic
  6254. to see if this is our first up since powerup */
  6255. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6256. val = *bnx2x_sp(bp, wb_data[0]);
  6257. /* do internal memory self test */
  6258. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6259. BNX2X_ERR("internal mem self test failed\n");
  6260. return -EBUSY;
  6261. }
  6262. }
  6263. bnx2x_setup_fan_failure_detection(bp);
  6264. /* clear PXP2 attentions */
  6265. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6266. bnx2x_enable_blocks_attention(bp);
  6267. bnx2x_enable_blocks_parity(bp);
  6268. if (!BP_NOMCP(bp)) {
  6269. if (CHIP_IS_E1x(bp))
  6270. bnx2x__common_init_phy(bp);
  6271. } else
  6272. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6273. if (SHMEM2_HAS(bp, netproc_fw_ver))
  6274. SHMEM2_WR(bp, netproc_fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  6275. return 0;
  6276. }
  6277. /**
  6278. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6279. *
  6280. * @bp: driver handle
  6281. */
  6282. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6283. {
  6284. int rc = bnx2x_init_hw_common(bp);
  6285. if (rc)
  6286. return rc;
  6287. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6288. if (!BP_NOMCP(bp))
  6289. bnx2x__common_init_phy(bp);
  6290. return 0;
  6291. }
  6292. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6293. {
  6294. int port = BP_PORT(bp);
  6295. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6296. u32 low, high;
  6297. u32 val, reg;
  6298. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6299. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6300. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6301. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6302. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6303. /* Timers bug workaround: disables the pf_master bit in pglue at
  6304. * common phase, we need to enable it here before any dmae access are
  6305. * attempted. Therefore we manually added the enable-master to the
  6306. * port phase (it also happens in the function phase)
  6307. */
  6308. if (!CHIP_IS_E1x(bp))
  6309. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6310. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6311. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6312. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6313. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6314. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6315. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6316. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6317. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6318. /* QM cid (connection) count */
  6319. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6320. if (CNIC_SUPPORT(bp)) {
  6321. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6322. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6323. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6324. }
  6325. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6326. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6327. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6328. if (IS_MF(bp))
  6329. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6330. else if (bp->dev->mtu > 4096) {
  6331. if (bp->flags & ONE_PORT_FLAG)
  6332. low = 160;
  6333. else {
  6334. val = bp->dev->mtu;
  6335. /* (24*1024 + val*4)/256 */
  6336. low = 96 + (val/64) +
  6337. ((val % 64) ? 1 : 0);
  6338. }
  6339. } else
  6340. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6341. high = low + 56; /* 14*1024/256 */
  6342. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6343. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6344. }
  6345. if (CHIP_MODE_IS_4_PORT(bp))
  6346. REG_WR(bp, (BP_PORT(bp) ?
  6347. BRB1_REG_MAC_GUARANTIED_1 :
  6348. BRB1_REG_MAC_GUARANTIED_0), 40);
  6349. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6350. if (CHIP_IS_E3B0(bp)) {
  6351. if (IS_MF_AFEX(bp)) {
  6352. /* configure headers for AFEX mode */
  6353. REG_WR(bp, BP_PORT(bp) ?
  6354. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6355. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6356. REG_WR(bp, BP_PORT(bp) ?
  6357. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6358. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6359. REG_WR(bp, BP_PORT(bp) ?
  6360. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6361. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6362. } else {
  6363. /* Ovlan exists only if we are in multi-function +
  6364. * switch-dependent mode, in switch-independent there
  6365. * is no ovlan headers
  6366. */
  6367. REG_WR(bp, BP_PORT(bp) ?
  6368. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6369. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6370. (bp->path_has_ovlan ? 7 : 6));
  6371. }
  6372. }
  6373. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6374. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6375. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6376. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6377. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6378. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6379. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6380. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6381. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6382. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6383. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6384. if (CHIP_IS_E1x(bp)) {
  6385. /* configure PBF to work without PAUSE mtu 9000 */
  6386. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6387. /* update threshold */
  6388. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6389. /* update init credit */
  6390. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6391. /* probe changes */
  6392. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6393. udelay(50);
  6394. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6395. }
  6396. if (CNIC_SUPPORT(bp))
  6397. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6398. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6399. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6400. if (CHIP_IS_E1(bp)) {
  6401. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6402. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6403. }
  6404. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6405. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6406. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6407. /* init aeu_mask_attn_func_0/1:
  6408. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6409. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6410. * bits 4-7 are used for "per vn group attention" */
  6411. val = IS_MF(bp) ? 0xF7 : 0x7;
  6412. /* Enable DCBX attention for all but E1 */
  6413. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6414. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6415. /* SCPAD_PARITY should NOT trigger close the gates */
  6416. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6417. REG_WR(bp, reg,
  6418. REG_RD(bp, reg) &
  6419. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6420. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6421. REG_WR(bp, reg,
  6422. REG_RD(bp, reg) &
  6423. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6424. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6425. if (!CHIP_IS_E1x(bp)) {
  6426. /* Bit-map indicating which L2 hdrs may appear after the
  6427. * basic Ethernet header
  6428. */
  6429. if (IS_MF_AFEX(bp))
  6430. REG_WR(bp, BP_PORT(bp) ?
  6431. NIG_REG_P1_HDRS_AFTER_BASIC :
  6432. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6433. else
  6434. REG_WR(bp, BP_PORT(bp) ?
  6435. NIG_REG_P1_HDRS_AFTER_BASIC :
  6436. NIG_REG_P0_HDRS_AFTER_BASIC,
  6437. IS_MF_SD(bp) ? 7 : 6);
  6438. if (CHIP_IS_E3(bp))
  6439. REG_WR(bp, BP_PORT(bp) ?
  6440. NIG_REG_LLH1_MF_MODE :
  6441. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6442. }
  6443. if (!CHIP_IS_E3(bp))
  6444. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6445. if (!CHIP_IS_E1(bp)) {
  6446. /* 0x2 disable mf_ov, 0x1 enable */
  6447. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6448. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6449. if (!CHIP_IS_E1x(bp)) {
  6450. val = 0;
  6451. switch (bp->mf_mode) {
  6452. case MULTI_FUNCTION_SD:
  6453. val = 1;
  6454. break;
  6455. case MULTI_FUNCTION_SI:
  6456. case MULTI_FUNCTION_AFEX:
  6457. val = 2;
  6458. break;
  6459. }
  6460. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6461. NIG_REG_LLH0_CLS_TYPE), val);
  6462. }
  6463. {
  6464. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6465. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6466. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6467. }
  6468. }
  6469. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6470. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6471. if (val & MISC_SPIO_SPIO5) {
  6472. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6473. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6474. val = REG_RD(bp, reg_addr);
  6475. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6476. REG_WR(bp, reg_addr, val);
  6477. }
  6478. return 0;
  6479. }
  6480. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6481. {
  6482. int reg;
  6483. u32 wb_write[2];
  6484. if (CHIP_IS_E1(bp))
  6485. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6486. else
  6487. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6488. wb_write[0] = ONCHIP_ADDR1(addr);
  6489. wb_write[1] = ONCHIP_ADDR2(addr);
  6490. REG_WR_DMAE(bp, reg, wb_write, 2);
  6491. }
  6492. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6493. {
  6494. u32 data, ctl, cnt = 100;
  6495. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6496. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6497. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6498. u32 sb_bit = 1 << (idu_sb_id%32);
  6499. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6500. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6501. /* Not supported in BC mode */
  6502. if (CHIP_INT_MODE_IS_BC(bp))
  6503. return;
  6504. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6505. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6506. IGU_REGULAR_CLEANUP_SET |
  6507. IGU_REGULAR_BCLEANUP;
  6508. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6509. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6510. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6511. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6512. data, igu_addr_data);
  6513. REG_WR(bp, igu_addr_data, data);
  6514. mmiowb();
  6515. barrier();
  6516. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6517. ctl, igu_addr_ctl);
  6518. REG_WR(bp, igu_addr_ctl, ctl);
  6519. mmiowb();
  6520. barrier();
  6521. /* wait for clean up to finish */
  6522. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6523. msleep(20);
  6524. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6525. DP(NETIF_MSG_HW,
  6526. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6527. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6528. }
  6529. }
  6530. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6531. {
  6532. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6533. }
  6534. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6535. {
  6536. u32 i, base = FUNC_ILT_BASE(func);
  6537. for (i = base; i < base + ILT_PER_FUNC; i++)
  6538. bnx2x_ilt_wr(bp, i, 0);
  6539. }
  6540. static void bnx2x_init_searcher(struct bnx2x *bp)
  6541. {
  6542. int port = BP_PORT(bp);
  6543. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6544. /* T1 hash bits value determines the T1 number of entries */
  6545. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6546. }
  6547. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6548. {
  6549. int rc;
  6550. struct bnx2x_func_state_params func_params = {NULL};
  6551. struct bnx2x_func_switch_update_params *switch_update_params =
  6552. &func_params.params.switch_update;
  6553. /* Prepare parameters for function state transitions */
  6554. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6555. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6556. func_params.f_obj = &bp->func_obj;
  6557. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6558. /* Function parameters */
  6559. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6560. &switch_update_params->changes);
  6561. if (suspend)
  6562. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6563. &switch_update_params->changes);
  6564. rc = bnx2x_func_state_change(bp, &func_params);
  6565. return rc;
  6566. }
  6567. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6568. {
  6569. int rc, i, port = BP_PORT(bp);
  6570. int vlan_en = 0, mac_en[NUM_MACS];
  6571. /* Close input from network */
  6572. if (bp->mf_mode == SINGLE_FUNCTION) {
  6573. bnx2x_set_rx_filter(&bp->link_params, 0);
  6574. } else {
  6575. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6576. NIG_REG_LLH0_FUNC_EN);
  6577. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6578. NIG_REG_LLH0_FUNC_EN, 0);
  6579. for (i = 0; i < NUM_MACS; i++) {
  6580. mac_en[i] = REG_RD(bp, port ?
  6581. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6582. 4 * i) :
  6583. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6584. 4 * i));
  6585. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6586. 4 * i) :
  6587. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6588. }
  6589. }
  6590. /* Close BMC to host */
  6591. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6592. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6593. /* Suspend Tx switching to the PF. Completion of this ramrod
  6594. * further guarantees that all the packets of that PF / child
  6595. * VFs in BRB were processed by the Parser, so it is safe to
  6596. * change the NIC_MODE register.
  6597. */
  6598. rc = bnx2x_func_switch_update(bp, 1);
  6599. if (rc) {
  6600. BNX2X_ERR("Can't suspend tx-switching!\n");
  6601. return rc;
  6602. }
  6603. /* Change NIC_MODE register */
  6604. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6605. /* Open input from network */
  6606. if (bp->mf_mode == SINGLE_FUNCTION) {
  6607. bnx2x_set_rx_filter(&bp->link_params, 1);
  6608. } else {
  6609. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6610. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6611. for (i = 0; i < NUM_MACS; i++) {
  6612. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6613. 4 * i) :
  6614. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6615. mac_en[i]);
  6616. }
  6617. }
  6618. /* Enable BMC to host */
  6619. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6620. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6621. /* Resume Tx switching to the PF */
  6622. rc = bnx2x_func_switch_update(bp, 0);
  6623. if (rc) {
  6624. BNX2X_ERR("Can't resume tx-switching!\n");
  6625. return rc;
  6626. }
  6627. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6628. return 0;
  6629. }
  6630. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6631. {
  6632. int rc;
  6633. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6634. if (CONFIGURE_NIC_MODE(bp)) {
  6635. /* Configure searcher as part of function hw init */
  6636. bnx2x_init_searcher(bp);
  6637. /* Reset NIC mode */
  6638. rc = bnx2x_reset_nic_mode(bp);
  6639. if (rc)
  6640. BNX2X_ERR("Can't change NIC mode!\n");
  6641. return rc;
  6642. }
  6643. return 0;
  6644. }
  6645. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  6646. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  6647. * the addresses of the transaction, resulting in was-error bit set in the pci
  6648. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  6649. * to clear the interrupt which detected this from the pglueb and the was done
  6650. * bit
  6651. */
  6652. static void bnx2x_clean_pglue_errors(struct bnx2x *bp)
  6653. {
  6654. if (!CHIP_IS_E1x(bp))
  6655. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  6656. 1 << BP_ABS_FUNC(bp));
  6657. }
  6658. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6659. {
  6660. int port = BP_PORT(bp);
  6661. int func = BP_FUNC(bp);
  6662. int init_phase = PHASE_PF0 + func;
  6663. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6664. u16 cdu_ilt_start;
  6665. u32 addr, val;
  6666. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6667. int i, main_mem_width, rc;
  6668. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6669. /* FLR cleanup - hmmm */
  6670. if (!CHIP_IS_E1x(bp)) {
  6671. rc = bnx2x_pf_flr_clnup(bp);
  6672. if (rc) {
  6673. bnx2x_fw_dump(bp);
  6674. return rc;
  6675. }
  6676. }
  6677. /* set MSI reconfigure capability */
  6678. if (bp->common.int_block == INT_BLOCK_HC) {
  6679. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6680. val = REG_RD(bp, addr);
  6681. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6682. REG_WR(bp, addr, val);
  6683. }
  6684. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6685. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6686. ilt = BP_ILT(bp);
  6687. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6688. if (IS_SRIOV(bp))
  6689. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6690. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6691. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6692. * those of the VFs, so start line should be reset
  6693. */
  6694. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6695. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6696. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6697. ilt->lines[cdu_ilt_start + i].page_mapping =
  6698. bp->context[i].cxt_mapping;
  6699. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6700. }
  6701. bnx2x_ilt_init_op(bp, INITOP_SET);
  6702. if (!CONFIGURE_NIC_MODE(bp)) {
  6703. bnx2x_init_searcher(bp);
  6704. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6705. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6706. } else {
  6707. /* Set NIC mode */
  6708. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6709. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6710. }
  6711. if (!CHIP_IS_E1x(bp)) {
  6712. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6713. /* Turn on a single ISR mode in IGU if driver is going to use
  6714. * INT#x or MSI
  6715. */
  6716. if (!(bp->flags & USING_MSIX_FLAG))
  6717. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6718. /*
  6719. * Timers workaround bug: function init part.
  6720. * Need to wait 20msec after initializing ILT,
  6721. * needed to make sure there are no requests in
  6722. * one of the PXP internal queues with "old" ILT addresses
  6723. */
  6724. msleep(20);
  6725. /*
  6726. * Master enable - Due to WB DMAE writes performed before this
  6727. * register is re-initialized as part of the regular function
  6728. * init
  6729. */
  6730. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6731. /* Enable the function in IGU */
  6732. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6733. }
  6734. bp->dmae_ready = 1;
  6735. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6736. bnx2x_clean_pglue_errors(bp);
  6737. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6738. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6739. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6740. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6741. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6742. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6743. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6744. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6745. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6746. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6747. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6748. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6749. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6750. if (!CHIP_IS_E1x(bp))
  6751. REG_WR(bp, QM_REG_PF_EN, 1);
  6752. if (!CHIP_IS_E1x(bp)) {
  6753. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6754. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6755. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6756. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6757. }
  6758. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6759. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6760. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6761. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6762. bnx2x_iov_init_dq(bp);
  6763. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6764. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6765. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6766. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6767. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6768. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6769. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6770. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6771. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6772. if (!CHIP_IS_E1x(bp))
  6773. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6774. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6775. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6776. if (!CHIP_IS_E1x(bp))
  6777. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6778. if (IS_MF(bp)) {
  6779. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6780. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6781. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6782. bp->mf_ov);
  6783. }
  6784. }
  6785. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6786. /* HC init per function */
  6787. if (bp->common.int_block == INT_BLOCK_HC) {
  6788. if (CHIP_IS_E1H(bp)) {
  6789. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6790. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6791. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6792. }
  6793. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6794. } else {
  6795. int num_segs, sb_idx, prod_offset;
  6796. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6797. if (!CHIP_IS_E1x(bp)) {
  6798. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6799. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6800. }
  6801. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6802. if (!CHIP_IS_E1x(bp)) {
  6803. int dsb_idx = 0;
  6804. /**
  6805. * Producer memory:
  6806. * E2 mode: address 0-135 match to the mapping memory;
  6807. * 136 - PF0 default prod; 137 - PF1 default prod;
  6808. * 138 - PF2 default prod; 139 - PF3 default prod;
  6809. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6810. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6811. * 144-147 reserved.
  6812. *
  6813. * E1.5 mode - In backward compatible mode;
  6814. * for non default SB; each even line in the memory
  6815. * holds the U producer and each odd line hold
  6816. * the C producer. The first 128 producers are for
  6817. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6818. * producers are for the DSB for each PF.
  6819. * Each PF has five segments: (the order inside each
  6820. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6821. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6822. * 144-147 attn prods;
  6823. */
  6824. /* non-default-status-blocks */
  6825. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6826. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6827. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6828. prod_offset = (bp->igu_base_sb + sb_idx) *
  6829. num_segs;
  6830. for (i = 0; i < num_segs; i++) {
  6831. addr = IGU_REG_PROD_CONS_MEMORY +
  6832. (prod_offset + i) * 4;
  6833. REG_WR(bp, addr, 0);
  6834. }
  6835. /* send consumer update with value 0 */
  6836. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6837. USTORM_ID, 0, IGU_INT_NOP, 1);
  6838. bnx2x_igu_clear_sb(bp,
  6839. bp->igu_base_sb + sb_idx);
  6840. }
  6841. /* default-status-blocks */
  6842. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6843. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6844. if (CHIP_MODE_IS_4_PORT(bp))
  6845. dsb_idx = BP_FUNC(bp);
  6846. else
  6847. dsb_idx = BP_VN(bp);
  6848. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6849. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6850. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6851. /*
  6852. * igu prods come in chunks of E1HVN_MAX (4) -
  6853. * does not matters what is the current chip mode
  6854. */
  6855. for (i = 0; i < (num_segs * E1HVN_MAX);
  6856. i += E1HVN_MAX) {
  6857. addr = IGU_REG_PROD_CONS_MEMORY +
  6858. (prod_offset + i)*4;
  6859. REG_WR(bp, addr, 0);
  6860. }
  6861. /* send consumer update with 0 */
  6862. if (CHIP_INT_MODE_IS_BC(bp)) {
  6863. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6864. USTORM_ID, 0, IGU_INT_NOP, 1);
  6865. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6866. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6867. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6868. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6869. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6870. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6871. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6872. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6873. } else {
  6874. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6875. USTORM_ID, 0, IGU_INT_NOP, 1);
  6876. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6877. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6878. }
  6879. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6880. /* !!! These should become driver const once
  6881. rf-tool supports split-68 const */
  6882. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6883. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6884. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6885. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6886. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6887. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6888. }
  6889. }
  6890. /* Reset PCIE errors for debug */
  6891. REG_WR(bp, 0x2114, 0xffffffff);
  6892. REG_WR(bp, 0x2120, 0xffffffff);
  6893. if (CHIP_IS_E1x(bp)) {
  6894. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6895. main_mem_base = HC_REG_MAIN_MEMORY +
  6896. BP_PORT(bp) * (main_mem_size * 4);
  6897. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6898. main_mem_width = 8;
  6899. val = REG_RD(bp, main_mem_prty_clr);
  6900. if (val)
  6901. DP(NETIF_MSG_HW,
  6902. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6903. val);
  6904. /* Clear "false" parity errors in MSI-X table */
  6905. for (i = main_mem_base;
  6906. i < main_mem_base + main_mem_size * 4;
  6907. i += main_mem_width) {
  6908. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6909. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6910. i, main_mem_width / 4);
  6911. }
  6912. /* Clear HC parity attention */
  6913. REG_RD(bp, main_mem_prty_clr);
  6914. }
  6915. #ifdef BNX2X_STOP_ON_ERROR
  6916. /* Enable STORMs SP logging */
  6917. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6918. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6919. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6920. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6921. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6922. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6923. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6924. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6925. #endif
  6926. bnx2x_phy_probe(&bp->link_params);
  6927. return 0;
  6928. }
  6929. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6930. {
  6931. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6932. if (!CHIP_IS_E1x(bp))
  6933. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6934. sizeof(struct host_hc_status_block_e2));
  6935. else
  6936. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6937. sizeof(struct host_hc_status_block_e1x));
  6938. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6939. }
  6940. void bnx2x_free_mem(struct bnx2x *bp)
  6941. {
  6942. int i;
  6943. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6944. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6945. if (IS_VF(bp))
  6946. return;
  6947. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6948. sizeof(struct host_sp_status_block));
  6949. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6950. sizeof(struct bnx2x_slowpath));
  6951. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6952. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6953. bp->context[i].size);
  6954. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6955. BNX2X_FREE(bp->ilt->lines);
  6956. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6957. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6958. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6959. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6960. bnx2x_iov_free_mem(bp);
  6961. }
  6962. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6963. {
  6964. if (!CHIP_IS_E1x(bp)) {
  6965. /* size = the status block + ramrod buffers */
  6966. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6967. sizeof(struct host_hc_status_block_e2));
  6968. if (!bp->cnic_sb.e2_sb)
  6969. goto alloc_mem_err;
  6970. } else {
  6971. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6972. sizeof(struct host_hc_status_block_e1x));
  6973. if (!bp->cnic_sb.e1x_sb)
  6974. goto alloc_mem_err;
  6975. }
  6976. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6977. /* allocate searcher T2 table, as it wasn't allocated before */
  6978. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6979. if (!bp->t2)
  6980. goto alloc_mem_err;
  6981. }
  6982. /* write address to which L5 should insert its values */
  6983. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6984. &bp->slowpath->drv_info_to_mcp;
  6985. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6986. goto alloc_mem_err;
  6987. return 0;
  6988. alloc_mem_err:
  6989. bnx2x_free_mem_cnic(bp);
  6990. BNX2X_ERR("Can't allocate memory\n");
  6991. return -ENOMEM;
  6992. }
  6993. int bnx2x_alloc_mem(struct bnx2x *bp)
  6994. {
  6995. int i, allocated, context_size;
  6996. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6997. /* allocate searcher T2 table */
  6998. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6999. if (!bp->t2)
  7000. goto alloc_mem_err;
  7001. }
  7002. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  7003. sizeof(struct host_sp_status_block));
  7004. if (!bp->def_status_blk)
  7005. goto alloc_mem_err;
  7006. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  7007. sizeof(struct bnx2x_slowpath));
  7008. if (!bp->slowpath)
  7009. goto alloc_mem_err;
  7010. /* Allocate memory for CDU context:
  7011. * This memory is allocated separately and not in the generic ILT
  7012. * functions because CDU differs in few aspects:
  7013. * 1. There are multiple entities allocating memory for context -
  7014. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  7015. * its own ILT lines.
  7016. * 2. Since CDU page-size is not a single 4KB page (which is the case
  7017. * for the other ILT clients), to be efficient we want to support
  7018. * allocation of sub-page-size in the last entry.
  7019. * 3. Context pointers are used by the driver to pass to FW / update
  7020. * the context (for the other ILT clients the pointers are used just to
  7021. * free the memory during unload).
  7022. */
  7023. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  7024. for (i = 0, allocated = 0; allocated < context_size; i++) {
  7025. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  7026. (context_size - allocated));
  7027. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  7028. bp->context[i].size);
  7029. if (!bp->context[i].vcxt)
  7030. goto alloc_mem_err;
  7031. allocated += bp->context[i].size;
  7032. }
  7033. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  7034. GFP_KERNEL);
  7035. if (!bp->ilt->lines)
  7036. goto alloc_mem_err;
  7037. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  7038. goto alloc_mem_err;
  7039. if (bnx2x_iov_alloc_mem(bp))
  7040. goto alloc_mem_err;
  7041. /* Slow path ring */
  7042. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  7043. if (!bp->spq)
  7044. goto alloc_mem_err;
  7045. /* EQ */
  7046. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  7047. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  7048. if (!bp->eq_ring)
  7049. goto alloc_mem_err;
  7050. return 0;
  7051. alloc_mem_err:
  7052. bnx2x_free_mem(bp);
  7053. BNX2X_ERR("Can't allocate memory\n");
  7054. return -ENOMEM;
  7055. }
  7056. /*
  7057. * Init service functions
  7058. */
  7059. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7060. struct bnx2x_vlan_mac_obj *obj, bool set,
  7061. int mac_type, unsigned long *ramrod_flags)
  7062. {
  7063. int rc;
  7064. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7065. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7066. /* Fill general parameters */
  7067. ramrod_param.vlan_mac_obj = obj;
  7068. ramrod_param.ramrod_flags = *ramrod_flags;
  7069. /* Fill a user request section if needed */
  7070. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7071. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7072. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7073. /* Set the command: ADD or DEL */
  7074. if (set)
  7075. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7076. else
  7077. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7078. }
  7079. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7080. if (rc == -EEXIST) {
  7081. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7082. /* do not treat adding same MAC as error */
  7083. rc = 0;
  7084. } else if (rc < 0)
  7085. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7086. return rc;
  7087. }
  7088. int bnx2x_set_vlan_one(struct bnx2x *bp, u16 vlan,
  7089. struct bnx2x_vlan_mac_obj *obj, bool set,
  7090. unsigned long *ramrod_flags)
  7091. {
  7092. int rc;
  7093. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7094. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7095. /* Fill general parameters */
  7096. ramrod_param.vlan_mac_obj = obj;
  7097. ramrod_param.ramrod_flags = *ramrod_flags;
  7098. /* Fill a user request section if needed */
  7099. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7100. ramrod_param.user_req.u.vlan.vlan = vlan;
  7101. /* Set the command: ADD or DEL */
  7102. if (set)
  7103. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7104. else
  7105. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7106. }
  7107. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7108. if (rc == -EEXIST) {
  7109. /* Do not treat adding same vlan as error. */
  7110. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7111. rc = 0;
  7112. } else if (rc < 0) {
  7113. BNX2X_ERR("%s VLAN failed\n", (set ? "Set" : "Del"));
  7114. }
  7115. return rc;
  7116. }
  7117. int bnx2x_del_all_macs(struct bnx2x *bp,
  7118. struct bnx2x_vlan_mac_obj *mac_obj,
  7119. int mac_type, bool wait_for_comp)
  7120. {
  7121. int rc;
  7122. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7123. /* Wait for completion of requested */
  7124. if (wait_for_comp)
  7125. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7126. /* Set the mac type of addresses we want to clear */
  7127. __set_bit(mac_type, &vlan_mac_flags);
  7128. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7129. if (rc < 0)
  7130. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7131. return rc;
  7132. }
  7133. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7134. {
  7135. if (IS_PF(bp)) {
  7136. unsigned long ramrod_flags = 0;
  7137. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7138. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7139. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7140. &bp->sp_objs->mac_obj, set,
  7141. BNX2X_ETH_MAC, &ramrod_flags);
  7142. } else { /* vf */
  7143. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7144. bp->fp->index, set);
  7145. }
  7146. }
  7147. int bnx2x_setup_leading(struct bnx2x *bp)
  7148. {
  7149. if (IS_PF(bp))
  7150. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7151. else /* VF */
  7152. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7153. }
  7154. /**
  7155. * bnx2x_set_int_mode - configure interrupt mode
  7156. *
  7157. * @bp: driver handle
  7158. *
  7159. * In case of MSI-X it will also try to enable MSI-X.
  7160. */
  7161. int bnx2x_set_int_mode(struct bnx2x *bp)
  7162. {
  7163. int rc = 0;
  7164. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7165. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7166. return -EINVAL;
  7167. }
  7168. switch (int_mode) {
  7169. case BNX2X_INT_MODE_MSIX:
  7170. /* attempt to enable msix */
  7171. rc = bnx2x_enable_msix(bp);
  7172. /* msix attained */
  7173. if (!rc)
  7174. return 0;
  7175. /* vfs use only msix */
  7176. if (rc && IS_VF(bp))
  7177. return rc;
  7178. /* failed to enable multiple MSI-X */
  7179. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7180. bp->num_queues,
  7181. 1 + bp->num_cnic_queues);
  7182. /* falling through... */
  7183. case BNX2X_INT_MODE_MSI:
  7184. bnx2x_enable_msi(bp);
  7185. /* falling through... */
  7186. case BNX2X_INT_MODE_INTX:
  7187. bp->num_ethernet_queues = 1;
  7188. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7189. BNX2X_DEV_INFO("set number of queues to 1\n");
  7190. break;
  7191. default:
  7192. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7193. return -EINVAL;
  7194. }
  7195. return 0;
  7196. }
  7197. /* must be called prior to any HW initializations */
  7198. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7199. {
  7200. if (IS_SRIOV(bp))
  7201. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7202. return L2_ILT_LINES(bp);
  7203. }
  7204. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7205. {
  7206. struct ilt_client_info *ilt_client;
  7207. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7208. u16 line = 0;
  7209. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7210. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7211. /* CDU */
  7212. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7213. ilt_client->client_num = ILT_CLIENT_CDU;
  7214. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7215. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7216. ilt_client->start = line;
  7217. line += bnx2x_cid_ilt_lines(bp);
  7218. if (CNIC_SUPPORT(bp))
  7219. line += CNIC_ILT_LINES;
  7220. ilt_client->end = line - 1;
  7221. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7222. ilt_client->start,
  7223. ilt_client->end,
  7224. ilt_client->page_size,
  7225. ilt_client->flags,
  7226. ilog2(ilt_client->page_size >> 12));
  7227. /* QM */
  7228. if (QM_INIT(bp->qm_cid_count)) {
  7229. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7230. ilt_client->client_num = ILT_CLIENT_QM;
  7231. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7232. ilt_client->flags = 0;
  7233. ilt_client->start = line;
  7234. /* 4 bytes for each cid */
  7235. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7236. QM_ILT_PAGE_SZ);
  7237. ilt_client->end = line - 1;
  7238. DP(NETIF_MSG_IFUP,
  7239. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7240. ilt_client->start,
  7241. ilt_client->end,
  7242. ilt_client->page_size,
  7243. ilt_client->flags,
  7244. ilog2(ilt_client->page_size >> 12));
  7245. }
  7246. if (CNIC_SUPPORT(bp)) {
  7247. /* SRC */
  7248. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7249. ilt_client->client_num = ILT_CLIENT_SRC;
  7250. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7251. ilt_client->flags = 0;
  7252. ilt_client->start = line;
  7253. line += SRC_ILT_LINES;
  7254. ilt_client->end = line - 1;
  7255. DP(NETIF_MSG_IFUP,
  7256. "ilt client[SRC]: 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. /* TM */
  7263. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7264. ilt_client->client_num = ILT_CLIENT_TM;
  7265. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7266. ilt_client->flags = 0;
  7267. ilt_client->start = line;
  7268. line += TM_ILT_LINES;
  7269. ilt_client->end = line - 1;
  7270. DP(NETIF_MSG_IFUP,
  7271. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7272. ilt_client->start,
  7273. ilt_client->end,
  7274. ilt_client->page_size,
  7275. ilt_client->flags,
  7276. ilog2(ilt_client->page_size >> 12));
  7277. }
  7278. BUG_ON(line > ILT_MAX_LINES);
  7279. }
  7280. /**
  7281. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7282. *
  7283. * @bp: driver handle
  7284. * @fp: pointer to fastpath
  7285. * @init_params: pointer to parameters structure
  7286. *
  7287. * parameters configured:
  7288. * - HC configuration
  7289. * - Queue's CDU context
  7290. */
  7291. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7292. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7293. {
  7294. u8 cos;
  7295. int cxt_index, cxt_offset;
  7296. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7297. if (!IS_FCOE_FP(fp)) {
  7298. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7299. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7300. /* If HC is supported, enable host coalescing in the transition
  7301. * to INIT state.
  7302. */
  7303. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7304. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7305. /* HC rate */
  7306. init_params->rx.hc_rate = bp->rx_ticks ?
  7307. (1000000 / bp->rx_ticks) : 0;
  7308. init_params->tx.hc_rate = bp->tx_ticks ?
  7309. (1000000 / bp->tx_ticks) : 0;
  7310. /* FW SB ID */
  7311. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7312. fp->fw_sb_id;
  7313. /*
  7314. * CQ index among the SB indices: FCoE clients uses the default
  7315. * SB, therefore it's different.
  7316. */
  7317. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7318. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7319. }
  7320. /* set maximum number of COSs supported by this queue */
  7321. init_params->max_cos = fp->max_cos;
  7322. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7323. fp->index, init_params->max_cos);
  7324. /* set the context pointers queue object */
  7325. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7326. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7327. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7328. ILT_PAGE_CIDS);
  7329. init_params->cxts[cos] =
  7330. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7331. }
  7332. }
  7333. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7334. struct bnx2x_queue_state_params *q_params,
  7335. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7336. int tx_index, bool leading)
  7337. {
  7338. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7339. /* Set the command */
  7340. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7341. /* Set tx-only QUEUE flags: don't zero statistics */
  7342. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7343. /* choose the index of the cid to send the slow path on */
  7344. tx_only_params->cid_index = tx_index;
  7345. /* Set general TX_ONLY_SETUP parameters */
  7346. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7347. /* Set Tx TX_ONLY_SETUP parameters */
  7348. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7349. DP(NETIF_MSG_IFUP,
  7350. "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",
  7351. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7352. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7353. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7354. /* send the ramrod */
  7355. return bnx2x_queue_state_change(bp, q_params);
  7356. }
  7357. /**
  7358. * bnx2x_setup_queue - setup queue
  7359. *
  7360. * @bp: driver handle
  7361. * @fp: pointer to fastpath
  7362. * @leading: is leading
  7363. *
  7364. * This function performs 2 steps in a Queue state machine
  7365. * actually: 1) RESET->INIT 2) INIT->SETUP
  7366. */
  7367. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7368. bool leading)
  7369. {
  7370. struct bnx2x_queue_state_params q_params = {NULL};
  7371. struct bnx2x_queue_setup_params *setup_params =
  7372. &q_params.params.setup;
  7373. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7374. &q_params.params.tx_only;
  7375. int rc;
  7376. u8 tx_index;
  7377. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7378. /* reset IGU state skip FCoE L2 queue */
  7379. if (!IS_FCOE_FP(fp))
  7380. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7381. IGU_INT_ENABLE, 0);
  7382. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7383. /* We want to wait for completion in this context */
  7384. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7385. /* Prepare the INIT parameters */
  7386. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7387. /* Set the command */
  7388. q_params.cmd = BNX2X_Q_CMD_INIT;
  7389. /* Change the state to INIT */
  7390. rc = bnx2x_queue_state_change(bp, &q_params);
  7391. if (rc) {
  7392. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7393. return rc;
  7394. }
  7395. DP(NETIF_MSG_IFUP, "init complete\n");
  7396. /* Now move the Queue to the SETUP state... */
  7397. memset(setup_params, 0, sizeof(*setup_params));
  7398. /* Set QUEUE flags */
  7399. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7400. /* Set general SETUP parameters */
  7401. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7402. FIRST_TX_COS_INDEX);
  7403. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7404. &setup_params->rxq_params);
  7405. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7406. FIRST_TX_COS_INDEX);
  7407. /* Set the command */
  7408. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7409. if (IS_FCOE_FP(fp))
  7410. bp->fcoe_init = true;
  7411. /* Change the state to SETUP */
  7412. rc = bnx2x_queue_state_change(bp, &q_params);
  7413. if (rc) {
  7414. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7415. return rc;
  7416. }
  7417. /* loop through the relevant tx-only indices */
  7418. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7419. tx_index < fp->max_cos;
  7420. tx_index++) {
  7421. /* prepare and send tx-only ramrod*/
  7422. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7423. tx_only_params, tx_index, leading);
  7424. if (rc) {
  7425. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7426. fp->index, tx_index);
  7427. return rc;
  7428. }
  7429. }
  7430. return rc;
  7431. }
  7432. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7433. {
  7434. struct bnx2x_fastpath *fp = &bp->fp[index];
  7435. struct bnx2x_fp_txdata *txdata;
  7436. struct bnx2x_queue_state_params q_params = {NULL};
  7437. int rc, tx_index;
  7438. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7439. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7440. /* We want to wait for completion in this context */
  7441. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7442. /* close tx-only connections */
  7443. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7444. tx_index < fp->max_cos;
  7445. tx_index++){
  7446. /* ascertain this is a normal queue*/
  7447. txdata = fp->txdata_ptr[tx_index];
  7448. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7449. txdata->txq_index);
  7450. /* send halt terminate on tx-only connection */
  7451. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7452. memset(&q_params.params.terminate, 0,
  7453. sizeof(q_params.params.terminate));
  7454. q_params.params.terminate.cid_index = tx_index;
  7455. rc = bnx2x_queue_state_change(bp, &q_params);
  7456. if (rc)
  7457. return rc;
  7458. /* send halt terminate on tx-only connection */
  7459. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7460. memset(&q_params.params.cfc_del, 0,
  7461. sizeof(q_params.params.cfc_del));
  7462. q_params.params.cfc_del.cid_index = tx_index;
  7463. rc = bnx2x_queue_state_change(bp, &q_params);
  7464. if (rc)
  7465. return rc;
  7466. }
  7467. /* Stop the primary connection: */
  7468. /* ...halt the connection */
  7469. q_params.cmd = BNX2X_Q_CMD_HALT;
  7470. rc = bnx2x_queue_state_change(bp, &q_params);
  7471. if (rc)
  7472. return rc;
  7473. /* ...terminate the connection */
  7474. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7475. memset(&q_params.params.terminate, 0,
  7476. sizeof(q_params.params.terminate));
  7477. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7478. rc = bnx2x_queue_state_change(bp, &q_params);
  7479. if (rc)
  7480. return rc;
  7481. /* ...delete cfc entry */
  7482. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7483. memset(&q_params.params.cfc_del, 0,
  7484. sizeof(q_params.params.cfc_del));
  7485. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7486. return bnx2x_queue_state_change(bp, &q_params);
  7487. }
  7488. static void bnx2x_reset_func(struct bnx2x *bp)
  7489. {
  7490. int port = BP_PORT(bp);
  7491. int func = BP_FUNC(bp);
  7492. int i;
  7493. /* Disable the function in the FW */
  7494. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7495. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7496. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7497. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7498. /* FP SBs */
  7499. for_each_eth_queue(bp, i) {
  7500. struct bnx2x_fastpath *fp = &bp->fp[i];
  7501. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7502. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7503. SB_DISABLED);
  7504. }
  7505. if (CNIC_LOADED(bp))
  7506. /* CNIC SB */
  7507. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7508. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7509. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7510. /* SP SB */
  7511. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7512. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7513. SB_DISABLED);
  7514. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7515. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7516. 0);
  7517. /* Configure IGU */
  7518. if (bp->common.int_block == INT_BLOCK_HC) {
  7519. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7520. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7521. } else {
  7522. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7523. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7524. }
  7525. if (CNIC_LOADED(bp)) {
  7526. /* Disable Timer scan */
  7527. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7528. /*
  7529. * Wait for at least 10ms and up to 2 second for the timers
  7530. * scan to complete
  7531. */
  7532. for (i = 0; i < 200; i++) {
  7533. usleep_range(10000, 20000);
  7534. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7535. break;
  7536. }
  7537. }
  7538. /* Clear ILT */
  7539. bnx2x_clear_func_ilt(bp, func);
  7540. /* Timers workaround bug for E2: if this is vnic-3,
  7541. * we need to set the entire ilt range for this timers.
  7542. */
  7543. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7544. struct ilt_client_info ilt_cli;
  7545. /* use dummy TM client */
  7546. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7547. ilt_cli.start = 0;
  7548. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7549. ilt_cli.client_num = ILT_CLIENT_TM;
  7550. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7551. }
  7552. /* this assumes that reset_port() called before reset_func()*/
  7553. if (!CHIP_IS_E1x(bp))
  7554. bnx2x_pf_disable(bp);
  7555. bp->dmae_ready = 0;
  7556. }
  7557. static void bnx2x_reset_port(struct bnx2x *bp)
  7558. {
  7559. int port = BP_PORT(bp);
  7560. u32 val;
  7561. /* Reset physical Link */
  7562. bnx2x__link_reset(bp);
  7563. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7564. /* Do not rcv packets to BRB */
  7565. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7566. /* Do not direct rcv packets that are not for MCP to the BRB */
  7567. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7568. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7569. /* Configure AEU */
  7570. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7571. msleep(100);
  7572. /* Check for BRB port occupancy */
  7573. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7574. if (val)
  7575. DP(NETIF_MSG_IFDOWN,
  7576. "BRB1 is not empty %d blocks are occupied\n", val);
  7577. /* TODO: Close Doorbell port? */
  7578. }
  7579. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7580. {
  7581. struct bnx2x_func_state_params func_params = {NULL};
  7582. /* Prepare parameters for function state transitions */
  7583. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7584. func_params.f_obj = &bp->func_obj;
  7585. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7586. func_params.params.hw_init.load_phase = load_code;
  7587. return bnx2x_func_state_change(bp, &func_params);
  7588. }
  7589. static int bnx2x_func_stop(struct bnx2x *bp)
  7590. {
  7591. struct bnx2x_func_state_params func_params = {NULL};
  7592. int rc;
  7593. /* Prepare parameters for function state transitions */
  7594. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7595. func_params.f_obj = &bp->func_obj;
  7596. func_params.cmd = BNX2X_F_CMD_STOP;
  7597. /*
  7598. * Try to stop the function the 'good way'. If fails (in case
  7599. * of a parity error during bnx2x_chip_cleanup()) and we are
  7600. * not in a debug mode, perform a state transaction in order to
  7601. * enable further HW_RESET transaction.
  7602. */
  7603. rc = bnx2x_func_state_change(bp, &func_params);
  7604. if (rc) {
  7605. #ifdef BNX2X_STOP_ON_ERROR
  7606. return rc;
  7607. #else
  7608. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7609. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7610. return bnx2x_func_state_change(bp, &func_params);
  7611. #endif
  7612. }
  7613. return 0;
  7614. }
  7615. /**
  7616. * bnx2x_send_unload_req - request unload mode from the MCP.
  7617. *
  7618. * @bp: driver handle
  7619. * @unload_mode: requested function's unload mode
  7620. *
  7621. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7622. */
  7623. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7624. {
  7625. u32 reset_code = 0;
  7626. int port = BP_PORT(bp);
  7627. /* Select the UNLOAD request mode */
  7628. if (unload_mode == UNLOAD_NORMAL)
  7629. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7630. else if (bp->flags & NO_WOL_FLAG)
  7631. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7632. else if (bp->wol) {
  7633. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7634. u8 *mac_addr = bp->dev->dev_addr;
  7635. struct pci_dev *pdev = bp->pdev;
  7636. u32 val;
  7637. u16 pmc;
  7638. /* The mac address is written to entries 1-4 to
  7639. * preserve entry 0 which is used by the PMF
  7640. */
  7641. u8 entry = (BP_VN(bp) + 1)*8;
  7642. val = (mac_addr[0] << 8) | mac_addr[1];
  7643. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7644. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7645. (mac_addr[4] << 8) | mac_addr[5];
  7646. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7647. /* Enable the PME and clear the status */
  7648. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7649. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7650. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7651. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7652. } else
  7653. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7654. /* Send the request to the MCP */
  7655. if (!BP_NOMCP(bp))
  7656. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7657. else {
  7658. int path = BP_PATH(bp);
  7659. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7660. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7661. bnx2x_load_count[path][2]);
  7662. bnx2x_load_count[path][0]--;
  7663. bnx2x_load_count[path][1 + port]--;
  7664. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7665. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7666. bnx2x_load_count[path][2]);
  7667. if (bnx2x_load_count[path][0] == 0)
  7668. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7669. else if (bnx2x_load_count[path][1 + port] == 0)
  7670. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7671. else
  7672. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7673. }
  7674. return reset_code;
  7675. }
  7676. /**
  7677. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7678. *
  7679. * @bp: driver handle
  7680. * @keep_link: true iff link should be kept up
  7681. */
  7682. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7683. {
  7684. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7685. /* Report UNLOAD_DONE to MCP */
  7686. if (!BP_NOMCP(bp))
  7687. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7688. }
  7689. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7690. {
  7691. int tout = 50;
  7692. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7693. if (!bp->port.pmf)
  7694. return 0;
  7695. /*
  7696. * (assumption: No Attention from MCP at this stage)
  7697. * PMF probably in the middle of TX disable/enable transaction
  7698. * 1. Sync IRS for default SB
  7699. * 2. Sync SP queue - this guarantees us that attention handling started
  7700. * 3. Wait, that TX disable/enable transaction completes
  7701. *
  7702. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7703. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7704. * received completion for the transaction the state is TX_STOPPED.
  7705. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7706. * transaction.
  7707. */
  7708. /* make sure default SB ISR is done */
  7709. if (msix)
  7710. synchronize_irq(bp->msix_table[0].vector);
  7711. else
  7712. synchronize_irq(bp->pdev->irq);
  7713. flush_workqueue(bnx2x_wq);
  7714. flush_workqueue(bnx2x_iov_wq);
  7715. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7716. BNX2X_F_STATE_STARTED && tout--)
  7717. msleep(20);
  7718. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7719. BNX2X_F_STATE_STARTED) {
  7720. #ifdef BNX2X_STOP_ON_ERROR
  7721. BNX2X_ERR("Wrong function state\n");
  7722. return -EBUSY;
  7723. #else
  7724. /*
  7725. * Failed to complete the transaction in a "good way"
  7726. * Force both transactions with CLR bit
  7727. */
  7728. struct bnx2x_func_state_params func_params = {NULL};
  7729. DP(NETIF_MSG_IFDOWN,
  7730. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7731. func_params.f_obj = &bp->func_obj;
  7732. __set_bit(RAMROD_DRV_CLR_ONLY,
  7733. &func_params.ramrod_flags);
  7734. /* STARTED-->TX_ST0PPED */
  7735. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7736. bnx2x_func_state_change(bp, &func_params);
  7737. /* TX_ST0PPED-->STARTED */
  7738. func_params.cmd = BNX2X_F_CMD_TX_START;
  7739. return bnx2x_func_state_change(bp, &func_params);
  7740. #endif
  7741. }
  7742. return 0;
  7743. }
  7744. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7745. {
  7746. int port = BP_PORT(bp);
  7747. /* Disable sending PTP packets to host */
  7748. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7749. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7750. /* Reset PTP event detection rules */
  7751. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7752. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7753. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7754. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7755. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7756. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7757. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7758. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7759. /* Disable the PTP feature */
  7760. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7761. NIG_REG_P0_PTP_EN, 0x0);
  7762. }
  7763. /* Called during unload, to stop PTP-related stuff */
  7764. static void bnx2x_stop_ptp(struct bnx2x *bp)
  7765. {
  7766. /* Cancel PTP work queue. Should be done after the Tx queues are
  7767. * drained to prevent additional scheduling.
  7768. */
  7769. cancel_work_sync(&bp->ptp_task);
  7770. if (bp->ptp_tx_skb) {
  7771. dev_kfree_skb_any(bp->ptp_tx_skb);
  7772. bp->ptp_tx_skb = NULL;
  7773. }
  7774. /* Disable PTP in HW */
  7775. bnx2x_disable_ptp(bp);
  7776. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7777. }
  7778. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7779. {
  7780. int port = BP_PORT(bp);
  7781. int i, rc = 0;
  7782. u8 cos;
  7783. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7784. u32 reset_code;
  7785. /* Wait until tx fastpath tasks complete */
  7786. for_each_tx_queue(bp, i) {
  7787. struct bnx2x_fastpath *fp = &bp->fp[i];
  7788. for_each_cos_in_tx_queue(fp, cos)
  7789. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7790. #ifdef BNX2X_STOP_ON_ERROR
  7791. if (rc)
  7792. return;
  7793. #endif
  7794. }
  7795. /* Give HW time to discard old tx messages */
  7796. usleep_range(1000, 2000);
  7797. /* Clean all ETH MACs */
  7798. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7799. false);
  7800. if (rc < 0)
  7801. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7802. /* Clean up UC list */
  7803. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7804. true);
  7805. if (rc < 0)
  7806. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7807. rc);
  7808. /* Disable LLH */
  7809. if (!CHIP_IS_E1(bp))
  7810. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7811. /* Set "drop all" (stop Rx).
  7812. * We need to take a netif_addr_lock() here in order to prevent
  7813. * a race between the completion code and this code.
  7814. */
  7815. netif_addr_lock_bh(bp->dev);
  7816. /* Schedule the rx_mode command */
  7817. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7818. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7819. else if (bp->slowpath)
  7820. bnx2x_set_storm_rx_mode(bp);
  7821. /* Cleanup multicast configuration */
  7822. rparam.mcast_obj = &bp->mcast_obj;
  7823. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7824. if (rc < 0)
  7825. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7826. netif_addr_unlock_bh(bp->dev);
  7827. bnx2x_iov_chip_cleanup(bp);
  7828. /*
  7829. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7830. * this function should perform FUNC, PORT or COMMON HW
  7831. * reset.
  7832. */
  7833. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7834. /*
  7835. * (assumption: No Attention from MCP at this stage)
  7836. * PMF probably in the middle of TX disable/enable transaction
  7837. */
  7838. rc = bnx2x_func_wait_started(bp);
  7839. if (rc) {
  7840. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7841. #ifdef BNX2X_STOP_ON_ERROR
  7842. return;
  7843. #endif
  7844. }
  7845. /* Close multi and leading connections
  7846. * Completions for ramrods are collected in a synchronous way
  7847. */
  7848. for_each_eth_queue(bp, i)
  7849. if (bnx2x_stop_queue(bp, i))
  7850. #ifdef BNX2X_STOP_ON_ERROR
  7851. return;
  7852. #else
  7853. goto unload_error;
  7854. #endif
  7855. if (CNIC_LOADED(bp)) {
  7856. for_each_cnic_queue(bp, i)
  7857. if (bnx2x_stop_queue(bp, i))
  7858. #ifdef BNX2X_STOP_ON_ERROR
  7859. return;
  7860. #else
  7861. goto unload_error;
  7862. #endif
  7863. }
  7864. /* If SP settings didn't get completed so far - something
  7865. * very wrong has happen.
  7866. */
  7867. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7868. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7869. #ifndef BNX2X_STOP_ON_ERROR
  7870. unload_error:
  7871. #endif
  7872. rc = bnx2x_func_stop(bp);
  7873. if (rc) {
  7874. BNX2X_ERR("Function stop failed!\n");
  7875. #ifdef BNX2X_STOP_ON_ERROR
  7876. return;
  7877. #endif
  7878. }
  7879. /* stop_ptp should be after the Tx queues are drained to prevent
  7880. * scheduling to the cancelled PTP work queue. It should also be after
  7881. * function stop ramrod is sent, since as part of this ramrod FW access
  7882. * PTP registers.
  7883. */
  7884. if (bp->flags & PTP_SUPPORTED)
  7885. bnx2x_stop_ptp(bp);
  7886. /* Disable HW interrupts, NAPI */
  7887. bnx2x_netif_stop(bp, 1);
  7888. /* Delete all NAPI objects */
  7889. bnx2x_del_all_napi(bp);
  7890. if (CNIC_LOADED(bp))
  7891. bnx2x_del_all_napi_cnic(bp);
  7892. /* Release IRQs */
  7893. bnx2x_free_irq(bp);
  7894. /* Reset the chip, unless PCI function is offline. If we reach this
  7895. * point following a PCI error handling, it means device is really
  7896. * in a bad state and we're about to remove it, so reset the chip
  7897. * is not a good idea.
  7898. */
  7899. if (!pci_channel_offline(bp->pdev)) {
  7900. rc = bnx2x_reset_hw(bp, reset_code);
  7901. if (rc)
  7902. BNX2X_ERR("HW_RESET failed\n");
  7903. }
  7904. /* Report UNLOAD_DONE to MCP */
  7905. bnx2x_send_unload_done(bp, keep_link);
  7906. }
  7907. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7908. {
  7909. u32 val;
  7910. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7911. if (CHIP_IS_E1(bp)) {
  7912. int port = BP_PORT(bp);
  7913. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7914. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7915. val = REG_RD(bp, addr);
  7916. val &= ~(0x300);
  7917. REG_WR(bp, addr, val);
  7918. } else {
  7919. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7920. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7921. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7922. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7923. }
  7924. }
  7925. /* Close gates #2, #3 and #4: */
  7926. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7927. {
  7928. u32 val;
  7929. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7930. if (!CHIP_IS_E1(bp)) {
  7931. /* #4 */
  7932. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7933. /* #2 */
  7934. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7935. }
  7936. /* #3 */
  7937. if (CHIP_IS_E1x(bp)) {
  7938. /* Prevent interrupts from HC on both ports */
  7939. val = REG_RD(bp, HC_REG_CONFIG_1);
  7940. REG_WR(bp, HC_REG_CONFIG_1,
  7941. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7942. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7943. val = REG_RD(bp, HC_REG_CONFIG_0);
  7944. REG_WR(bp, HC_REG_CONFIG_0,
  7945. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7946. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7947. } else {
  7948. /* Prevent incoming interrupts in IGU */
  7949. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7950. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7951. (!close) ?
  7952. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7953. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7954. }
  7955. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7956. close ? "closing" : "opening");
  7957. mmiowb();
  7958. }
  7959. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7960. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7961. {
  7962. /* Do some magic... */
  7963. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7964. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7965. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7966. }
  7967. /**
  7968. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7969. *
  7970. * @bp: driver handle
  7971. * @magic_val: old value of the `magic' bit.
  7972. */
  7973. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7974. {
  7975. /* Restore the `magic' bit value... */
  7976. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7977. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7978. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7979. }
  7980. /**
  7981. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7982. *
  7983. * @bp: driver handle
  7984. * @magic_val: old value of 'magic' bit.
  7985. *
  7986. * Takes care of CLP configurations.
  7987. */
  7988. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7989. {
  7990. u32 shmem;
  7991. u32 validity_offset;
  7992. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7993. /* Set `magic' bit in order to save MF config */
  7994. if (!CHIP_IS_E1(bp))
  7995. bnx2x_clp_reset_prep(bp, magic_val);
  7996. /* Get shmem offset */
  7997. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7998. validity_offset =
  7999. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  8000. /* Clear validity map flags */
  8001. if (shmem > 0)
  8002. REG_WR(bp, shmem + validity_offset, 0);
  8003. }
  8004. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  8005. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  8006. /**
  8007. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  8008. *
  8009. * @bp: driver handle
  8010. */
  8011. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  8012. {
  8013. /* special handling for emulation and FPGA,
  8014. wait 10 times longer */
  8015. if (CHIP_REV_IS_SLOW(bp))
  8016. msleep(MCP_ONE_TIMEOUT*10);
  8017. else
  8018. msleep(MCP_ONE_TIMEOUT);
  8019. }
  8020. /*
  8021. * initializes bp->common.shmem_base and waits for validity signature to appear
  8022. */
  8023. static int bnx2x_init_shmem(struct bnx2x *bp)
  8024. {
  8025. int cnt = 0;
  8026. u32 val = 0;
  8027. do {
  8028. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  8029. if (bp->common.shmem_base) {
  8030. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  8031. if (val & SHR_MEM_VALIDITY_MB)
  8032. return 0;
  8033. }
  8034. bnx2x_mcp_wait_one(bp);
  8035. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  8036. BNX2X_ERR("BAD MCP validity signature\n");
  8037. return -ENODEV;
  8038. }
  8039. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  8040. {
  8041. int rc = bnx2x_init_shmem(bp);
  8042. /* Restore the `magic' bit value */
  8043. if (!CHIP_IS_E1(bp))
  8044. bnx2x_clp_reset_done(bp, magic_val);
  8045. return rc;
  8046. }
  8047. static void bnx2x_pxp_prep(struct bnx2x *bp)
  8048. {
  8049. if (!CHIP_IS_E1(bp)) {
  8050. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  8051. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  8052. mmiowb();
  8053. }
  8054. }
  8055. /*
  8056. * Reset the whole chip except for:
  8057. * - PCIE core
  8058. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  8059. * one reset bit)
  8060. * - IGU
  8061. * - MISC (including AEU)
  8062. * - GRC
  8063. * - RBCN, RBCP
  8064. */
  8065. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  8066. {
  8067. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  8068. u32 global_bits2, stay_reset2;
  8069. /*
  8070. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  8071. * (per chip) blocks.
  8072. */
  8073. global_bits2 =
  8074. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  8075. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  8076. /* Don't reset the following blocks.
  8077. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  8078. * reset, as in 4 port device they might still be owned
  8079. * by the MCP (there is only one leader per path).
  8080. */
  8081. not_reset_mask1 =
  8082. MISC_REGISTERS_RESET_REG_1_RST_HC |
  8083. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  8084. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  8085. not_reset_mask2 =
  8086. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  8087. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8088. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8089. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8090. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8091. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8092. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8093. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8094. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8095. MISC_REGISTERS_RESET_REG_2_PGLC |
  8096. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8097. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8098. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8099. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8100. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8101. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8102. /*
  8103. * Keep the following blocks in reset:
  8104. * - all xxMACs are handled by the bnx2x_link code.
  8105. */
  8106. stay_reset2 =
  8107. MISC_REGISTERS_RESET_REG_2_XMAC |
  8108. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8109. /* Full reset masks according to the chip */
  8110. reset_mask1 = 0xffffffff;
  8111. if (CHIP_IS_E1(bp))
  8112. reset_mask2 = 0xffff;
  8113. else if (CHIP_IS_E1H(bp))
  8114. reset_mask2 = 0x1ffff;
  8115. else if (CHIP_IS_E2(bp))
  8116. reset_mask2 = 0xfffff;
  8117. else /* CHIP_IS_E3 */
  8118. reset_mask2 = 0x3ffffff;
  8119. /* Don't reset global blocks unless we need to */
  8120. if (!global)
  8121. reset_mask2 &= ~global_bits2;
  8122. /*
  8123. * In case of attention in the QM, we need to reset PXP
  8124. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8125. * because otherwise QM reset would release 'close the gates' shortly
  8126. * before resetting the PXP, then the PSWRQ would send a write
  8127. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8128. * read the payload data from PSWWR, but PSWWR would not
  8129. * respond. The write queue in PGLUE would stuck, dmae commands
  8130. * would not return. Therefore it's important to reset the second
  8131. * reset register (containing the
  8132. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8133. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8134. * bit).
  8135. */
  8136. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8137. reset_mask2 & (~not_reset_mask2));
  8138. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8139. reset_mask1 & (~not_reset_mask1));
  8140. barrier();
  8141. mmiowb();
  8142. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8143. reset_mask2 & (~stay_reset2));
  8144. barrier();
  8145. mmiowb();
  8146. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8147. mmiowb();
  8148. }
  8149. /**
  8150. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8151. * It should get cleared in no more than 1s.
  8152. *
  8153. * @bp: driver handle
  8154. *
  8155. * It should get cleared in no more than 1s. Returns 0 if
  8156. * pending writes bit gets cleared.
  8157. */
  8158. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8159. {
  8160. u32 cnt = 1000;
  8161. u32 pend_bits = 0;
  8162. do {
  8163. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8164. if (pend_bits == 0)
  8165. break;
  8166. usleep_range(1000, 2000);
  8167. } while (cnt-- > 0);
  8168. if (cnt <= 0) {
  8169. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8170. pend_bits);
  8171. return -EBUSY;
  8172. }
  8173. return 0;
  8174. }
  8175. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8176. {
  8177. int cnt = 1000;
  8178. u32 val = 0;
  8179. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8180. u32 tags_63_32 = 0;
  8181. /* Empty the Tetris buffer, wait for 1s */
  8182. do {
  8183. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8184. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8185. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8186. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8187. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8188. if (CHIP_IS_E3(bp))
  8189. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8190. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8191. ((port_is_idle_0 & 0x1) == 0x1) &&
  8192. ((port_is_idle_1 & 0x1) == 0x1) &&
  8193. (pgl_exp_rom2 == 0xffffffff) &&
  8194. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8195. break;
  8196. usleep_range(1000, 2000);
  8197. } while (cnt-- > 0);
  8198. if (cnt <= 0) {
  8199. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8200. 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",
  8201. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8202. pgl_exp_rom2);
  8203. return -EAGAIN;
  8204. }
  8205. barrier();
  8206. /* Close gates #2, #3 and #4 */
  8207. bnx2x_set_234_gates(bp, true);
  8208. /* Poll for IGU VQs for 57712 and newer chips */
  8209. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8210. return -EAGAIN;
  8211. /* TBD: Indicate that "process kill" is in progress to MCP */
  8212. /* Clear "unprepared" bit */
  8213. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8214. barrier();
  8215. /* Make sure all is written to the chip before the reset */
  8216. mmiowb();
  8217. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8218. * PSWHST, GRC and PSWRD Tetris buffer.
  8219. */
  8220. usleep_range(1000, 2000);
  8221. /* Prepare to chip reset: */
  8222. /* MCP */
  8223. if (global)
  8224. bnx2x_reset_mcp_prep(bp, &val);
  8225. /* PXP */
  8226. bnx2x_pxp_prep(bp);
  8227. barrier();
  8228. /* reset the chip */
  8229. bnx2x_process_kill_chip_reset(bp, global);
  8230. barrier();
  8231. /* clear errors in PGB */
  8232. if (!CHIP_IS_E1x(bp))
  8233. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8234. /* Recover after reset: */
  8235. /* MCP */
  8236. if (global && bnx2x_reset_mcp_comp(bp, val))
  8237. return -EAGAIN;
  8238. /* TBD: Add resetting the NO_MCP mode DB here */
  8239. /* Open the gates #2, #3 and #4 */
  8240. bnx2x_set_234_gates(bp, false);
  8241. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8242. * reset state, re-enable attentions. */
  8243. return 0;
  8244. }
  8245. static int bnx2x_leader_reset(struct bnx2x *bp)
  8246. {
  8247. int rc = 0;
  8248. bool global = bnx2x_reset_is_global(bp);
  8249. u32 load_code;
  8250. /* if not going to reset MCP - load "fake" driver to reset HW while
  8251. * driver is owner of the HW
  8252. */
  8253. if (!global && !BP_NOMCP(bp)) {
  8254. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8255. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8256. if (!load_code) {
  8257. BNX2X_ERR("MCP response failure, aborting\n");
  8258. rc = -EAGAIN;
  8259. goto exit_leader_reset;
  8260. }
  8261. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8262. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8263. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8264. rc = -EAGAIN;
  8265. goto exit_leader_reset2;
  8266. }
  8267. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8268. if (!load_code) {
  8269. BNX2X_ERR("MCP response failure, aborting\n");
  8270. rc = -EAGAIN;
  8271. goto exit_leader_reset2;
  8272. }
  8273. }
  8274. /* Try to recover after the failure */
  8275. if (bnx2x_process_kill(bp, global)) {
  8276. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8277. BP_PATH(bp));
  8278. rc = -EAGAIN;
  8279. goto exit_leader_reset2;
  8280. }
  8281. /*
  8282. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8283. * state.
  8284. */
  8285. bnx2x_set_reset_done(bp);
  8286. if (global)
  8287. bnx2x_clear_reset_global(bp);
  8288. exit_leader_reset2:
  8289. /* unload "fake driver" if it was loaded */
  8290. if (!global && !BP_NOMCP(bp)) {
  8291. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8292. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8293. }
  8294. exit_leader_reset:
  8295. bp->is_leader = 0;
  8296. bnx2x_release_leader_lock(bp);
  8297. smp_mb();
  8298. return rc;
  8299. }
  8300. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8301. {
  8302. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8303. /* Disconnect this device */
  8304. netif_device_detach(bp->dev);
  8305. /*
  8306. * Block ifup for all function on this engine until "process kill"
  8307. * or power cycle.
  8308. */
  8309. bnx2x_set_reset_in_progress(bp);
  8310. /* Shut down the power */
  8311. bnx2x_set_power_state(bp, PCI_D3hot);
  8312. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8313. smp_mb();
  8314. }
  8315. /*
  8316. * Assumption: runs under rtnl lock. This together with the fact
  8317. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8318. * will never be called when netif_running(bp->dev) is false.
  8319. */
  8320. static void bnx2x_parity_recover(struct bnx2x *bp)
  8321. {
  8322. bool global = false;
  8323. u32 error_recovered, error_unrecovered;
  8324. bool is_parity;
  8325. DP(NETIF_MSG_HW, "Handling parity\n");
  8326. while (1) {
  8327. switch (bp->recovery_state) {
  8328. case BNX2X_RECOVERY_INIT:
  8329. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8330. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8331. WARN_ON(!is_parity);
  8332. /* Try to get a LEADER_LOCK HW lock */
  8333. if (bnx2x_trylock_leader_lock(bp)) {
  8334. bnx2x_set_reset_in_progress(bp);
  8335. /*
  8336. * Check if there is a global attention and if
  8337. * there was a global attention, set the global
  8338. * reset bit.
  8339. */
  8340. if (global)
  8341. bnx2x_set_reset_global(bp);
  8342. bp->is_leader = 1;
  8343. }
  8344. /* Stop the driver */
  8345. /* If interface has been removed - break */
  8346. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8347. return;
  8348. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8349. /* Ensure "is_leader", MCP command sequence and
  8350. * "recovery_state" update values are seen on other
  8351. * CPUs.
  8352. */
  8353. smp_mb();
  8354. break;
  8355. case BNX2X_RECOVERY_WAIT:
  8356. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8357. if (bp->is_leader) {
  8358. int other_engine = BP_PATH(bp) ? 0 : 1;
  8359. bool other_load_status =
  8360. bnx2x_get_load_status(bp, other_engine);
  8361. bool load_status =
  8362. bnx2x_get_load_status(bp, BP_PATH(bp));
  8363. global = bnx2x_reset_is_global(bp);
  8364. /*
  8365. * In case of a parity in a global block, let
  8366. * the first leader that performs a
  8367. * leader_reset() reset the global blocks in
  8368. * order to clear global attentions. Otherwise
  8369. * the gates will remain closed for that
  8370. * engine.
  8371. */
  8372. if (load_status ||
  8373. (global && other_load_status)) {
  8374. /* Wait until all other functions get
  8375. * down.
  8376. */
  8377. schedule_delayed_work(&bp->sp_rtnl_task,
  8378. HZ/10);
  8379. return;
  8380. } else {
  8381. /* If all other functions got down -
  8382. * try to bring the chip back to
  8383. * normal. In any case it's an exit
  8384. * point for a leader.
  8385. */
  8386. if (bnx2x_leader_reset(bp)) {
  8387. bnx2x_recovery_failed(bp);
  8388. return;
  8389. }
  8390. /* If we are here, means that the
  8391. * leader has succeeded and doesn't
  8392. * want to be a leader any more. Try
  8393. * to continue as a none-leader.
  8394. */
  8395. break;
  8396. }
  8397. } else { /* non-leader */
  8398. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8399. /* Try to get a LEADER_LOCK HW lock as
  8400. * long as a former leader may have
  8401. * been unloaded by the user or
  8402. * released a leadership by another
  8403. * reason.
  8404. */
  8405. if (bnx2x_trylock_leader_lock(bp)) {
  8406. /* I'm a leader now! Restart a
  8407. * switch case.
  8408. */
  8409. bp->is_leader = 1;
  8410. break;
  8411. }
  8412. schedule_delayed_work(&bp->sp_rtnl_task,
  8413. HZ/10);
  8414. return;
  8415. } else {
  8416. /*
  8417. * If there was a global attention, wait
  8418. * for it to be cleared.
  8419. */
  8420. if (bnx2x_reset_is_global(bp)) {
  8421. schedule_delayed_work(
  8422. &bp->sp_rtnl_task,
  8423. HZ/10);
  8424. return;
  8425. }
  8426. error_recovered =
  8427. bp->eth_stats.recoverable_error;
  8428. error_unrecovered =
  8429. bp->eth_stats.unrecoverable_error;
  8430. bp->recovery_state =
  8431. BNX2X_RECOVERY_NIC_LOADING;
  8432. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8433. error_unrecovered++;
  8434. netdev_err(bp->dev,
  8435. "Recovery failed. Power cycle needed\n");
  8436. /* Disconnect this device */
  8437. netif_device_detach(bp->dev);
  8438. /* Shut down the power */
  8439. bnx2x_set_power_state(
  8440. bp, PCI_D3hot);
  8441. smp_mb();
  8442. } else {
  8443. bp->recovery_state =
  8444. BNX2X_RECOVERY_DONE;
  8445. error_recovered++;
  8446. smp_mb();
  8447. }
  8448. bp->eth_stats.recoverable_error =
  8449. error_recovered;
  8450. bp->eth_stats.unrecoverable_error =
  8451. error_unrecovered;
  8452. return;
  8453. }
  8454. }
  8455. default:
  8456. return;
  8457. }
  8458. }
  8459. }
  8460. static int bnx2x_udp_port_update(struct bnx2x *bp)
  8461. {
  8462. struct bnx2x_func_switch_update_params *switch_update_params;
  8463. struct bnx2x_func_state_params func_params = {NULL};
  8464. struct bnx2x_udp_tunnel *udp_tunnel;
  8465. u16 vxlan_port = 0, geneve_port = 0;
  8466. int rc;
  8467. switch_update_params = &func_params.params.switch_update;
  8468. /* Prepare parameters for function state transitions */
  8469. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  8470. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  8471. func_params.f_obj = &bp->func_obj;
  8472. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  8473. /* Function parameters */
  8474. __set_bit(BNX2X_F_UPDATE_TUNNEL_CFG_CHNG,
  8475. &switch_update_params->changes);
  8476. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count) {
  8477. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE];
  8478. geneve_port = udp_tunnel->dst_port;
  8479. switch_update_params->geneve_dst_port = geneve_port;
  8480. }
  8481. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count) {
  8482. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN];
  8483. vxlan_port = udp_tunnel->dst_port;
  8484. switch_update_params->vxlan_dst_port = vxlan_port;
  8485. }
  8486. /* Re-enable inner-rss for the offloaded UDP tunnels */
  8487. __set_bit(BNX2X_F_UPDATE_TUNNEL_INNER_RSS,
  8488. &switch_update_params->changes);
  8489. rc = bnx2x_func_state_change(bp, &func_params);
  8490. if (rc)
  8491. BNX2X_ERR("failed to set UDP dst port to %04x %04x (rc = 0x%x)\n",
  8492. vxlan_port, geneve_port, rc);
  8493. else
  8494. DP(BNX2X_MSG_SP,
  8495. "Configured UDP ports: Vxlan [%04x] Geneve [%04x]\n",
  8496. vxlan_port, geneve_port);
  8497. return rc;
  8498. }
  8499. static void __bnx2x_add_udp_port(struct bnx2x *bp, u16 port,
  8500. enum bnx2x_udp_port_type type)
  8501. {
  8502. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8503. if (!netif_running(bp->dev) || !IS_PF(bp) || CHIP_IS_E1x(bp))
  8504. return;
  8505. if (udp_port->count && udp_port->dst_port == port) {
  8506. udp_port->count++;
  8507. return;
  8508. }
  8509. if (udp_port->count) {
  8510. DP(BNX2X_MSG_SP,
  8511. "UDP tunnel [%d] - destination port limit reached\n",
  8512. type);
  8513. return;
  8514. }
  8515. udp_port->dst_port = port;
  8516. udp_port->count = 1;
  8517. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8518. }
  8519. static void __bnx2x_del_udp_port(struct bnx2x *bp, u16 port,
  8520. enum bnx2x_udp_port_type type)
  8521. {
  8522. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8523. if (!IS_PF(bp) || CHIP_IS_E1x(bp))
  8524. return;
  8525. if (!udp_port->count || udp_port->dst_port != port) {
  8526. DP(BNX2X_MSG_SP, "Invalid UDP tunnel [%d] port\n",
  8527. type);
  8528. return;
  8529. }
  8530. /* Remove reference, and make certain it's no longer in use */
  8531. udp_port->count--;
  8532. if (udp_port->count)
  8533. return;
  8534. udp_port->dst_port = 0;
  8535. if (netif_running(bp->dev))
  8536. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8537. else
  8538. DP(BNX2X_MSG_SP, "Deleted UDP tunnel [%d] port %d\n",
  8539. type, port);
  8540. }
  8541. static void bnx2x_udp_tunnel_add(struct net_device *netdev,
  8542. struct udp_tunnel_info *ti)
  8543. {
  8544. struct bnx2x *bp = netdev_priv(netdev);
  8545. u16 t_port = ntohs(ti->port);
  8546. switch (ti->type) {
  8547. case UDP_TUNNEL_TYPE_VXLAN:
  8548. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8549. break;
  8550. case UDP_TUNNEL_TYPE_GENEVE:
  8551. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8552. break;
  8553. default:
  8554. break;
  8555. }
  8556. }
  8557. static void bnx2x_udp_tunnel_del(struct net_device *netdev,
  8558. struct udp_tunnel_info *ti)
  8559. {
  8560. struct bnx2x *bp = netdev_priv(netdev);
  8561. u16 t_port = ntohs(ti->port);
  8562. switch (ti->type) {
  8563. case UDP_TUNNEL_TYPE_VXLAN:
  8564. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8565. break;
  8566. case UDP_TUNNEL_TYPE_GENEVE:
  8567. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8568. break;
  8569. default:
  8570. break;
  8571. }
  8572. }
  8573. static int bnx2x_close(struct net_device *dev);
  8574. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8575. * scheduled on a general queue in order to prevent a dead lock.
  8576. */
  8577. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8578. {
  8579. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8580. rtnl_lock();
  8581. if (!netif_running(bp->dev)) {
  8582. rtnl_unlock();
  8583. return;
  8584. }
  8585. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8586. #ifdef BNX2X_STOP_ON_ERROR
  8587. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8588. "you will need to reboot when done\n");
  8589. goto sp_rtnl_not_reset;
  8590. #endif
  8591. /*
  8592. * Clear all pending SP commands as we are going to reset the
  8593. * function anyway.
  8594. */
  8595. bp->sp_rtnl_state = 0;
  8596. smp_mb();
  8597. bnx2x_parity_recover(bp);
  8598. rtnl_unlock();
  8599. return;
  8600. }
  8601. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8602. #ifdef BNX2X_STOP_ON_ERROR
  8603. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8604. "you will need to reboot when done\n");
  8605. goto sp_rtnl_not_reset;
  8606. #endif
  8607. /*
  8608. * Clear all pending SP commands as we are going to reset the
  8609. * function anyway.
  8610. */
  8611. bp->sp_rtnl_state = 0;
  8612. smp_mb();
  8613. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8614. /* When ret value shows failure of allocation failure,
  8615. * the nic is rebooted again. If open still fails, a error
  8616. * message to notify the user.
  8617. */
  8618. if (bnx2x_nic_load(bp, LOAD_NORMAL) == -ENOMEM) {
  8619. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8620. if (bnx2x_nic_load(bp, LOAD_NORMAL))
  8621. BNX2X_ERR("Open the NIC fails again!\n");
  8622. }
  8623. rtnl_unlock();
  8624. return;
  8625. }
  8626. #ifdef BNX2X_STOP_ON_ERROR
  8627. sp_rtnl_not_reset:
  8628. #endif
  8629. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8630. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8631. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8632. bnx2x_after_function_update(bp);
  8633. /*
  8634. * in case of fan failure we need to reset id if the "stop on error"
  8635. * debug flag is set, since we trying to prevent permanent overheating
  8636. * damage
  8637. */
  8638. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8639. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8640. netif_device_detach(bp->dev);
  8641. bnx2x_close(bp->dev);
  8642. rtnl_unlock();
  8643. return;
  8644. }
  8645. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8646. DP(BNX2X_MSG_SP,
  8647. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8648. bnx2x_vfpf_set_mcast(bp->dev);
  8649. }
  8650. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8651. &bp->sp_rtnl_state)){
  8652. if (netif_carrier_ok(bp->dev)) {
  8653. bnx2x_tx_disable(bp);
  8654. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8655. }
  8656. }
  8657. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8658. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8659. bnx2x_set_rx_mode_inner(bp);
  8660. }
  8661. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8662. &bp->sp_rtnl_state))
  8663. bnx2x_pf_set_vfs_vlan(bp);
  8664. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8665. bnx2x_dcbx_stop_hw_tx(bp);
  8666. bnx2x_dcbx_resume_hw_tx(bp);
  8667. }
  8668. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8669. &bp->sp_rtnl_state))
  8670. bnx2x_update_mng_version(bp);
  8671. if (test_and_clear_bit(BNX2X_SP_RTNL_CHANGE_UDP_PORT,
  8672. &bp->sp_rtnl_state)) {
  8673. if (bnx2x_udp_port_update(bp)) {
  8674. /* On error, forget configuration */
  8675. memset(bp->udp_tunnel_ports, 0,
  8676. sizeof(struct bnx2x_udp_tunnel) *
  8677. BNX2X_UDP_PORT_MAX);
  8678. } else {
  8679. /* Since we don't store additional port information,
  8680. * if no ports are configured for any feature ask for
  8681. * information about currently configured ports.
  8682. */
  8683. if (!bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count &&
  8684. !bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count)
  8685. udp_tunnel_get_rx_info(bp->dev);
  8686. }
  8687. }
  8688. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8689. * can be called from other contexts as well)
  8690. */
  8691. rtnl_unlock();
  8692. /* enable SR-IOV if applicable */
  8693. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8694. &bp->sp_rtnl_state)) {
  8695. bnx2x_disable_sriov(bp);
  8696. bnx2x_enable_sriov(bp);
  8697. }
  8698. }
  8699. static void bnx2x_period_task(struct work_struct *work)
  8700. {
  8701. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8702. if (!netif_running(bp->dev))
  8703. goto period_task_exit;
  8704. if (CHIP_REV_IS_SLOW(bp)) {
  8705. BNX2X_ERR("period task called on emulation, ignoring\n");
  8706. goto period_task_exit;
  8707. }
  8708. bnx2x_acquire_phy_lock(bp);
  8709. /*
  8710. * The barrier is needed to ensure the ordering between the writing to
  8711. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8712. * the reading here.
  8713. */
  8714. smp_mb();
  8715. if (bp->port.pmf) {
  8716. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8717. /* Re-queue task in 1 sec */
  8718. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8719. }
  8720. bnx2x_release_phy_lock(bp);
  8721. period_task_exit:
  8722. return;
  8723. }
  8724. /*
  8725. * Init service functions
  8726. */
  8727. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8728. {
  8729. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8730. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8731. return base + (BP_ABS_FUNC(bp)) * stride;
  8732. }
  8733. static bool bnx2x_prev_unload_close_umac(struct bnx2x *bp,
  8734. u8 port, u32 reset_reg,
  8735. struct bnx2x_mac_vals *vals)
  8736. {
  8737. u32 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8738. u32 base_addr;
  8739. if (!(mask & reset_reg))
  8740. return false;
  8741. BNX2X_DEV_INFO("Disable umac Rx %02x\n", port);
  8742. base_addr = port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8743. vals->umac_addr[port] = base_addr + UMAC_REG_COMMAND_CONFIG;
  8744. vals->umac_val[port] = REG_RD(bp, vals->umac_addr[port]);
  8745. REG_WR(bp, vals->umac_addr[port], 0);
  8746. return true;
  8747. }
  8748. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8749. struct bnx2x_mac_vals *vals)
  8750. {
  8751. u32 val, base_addr, offset, mask, reset_reg;
  8752. bool mac_stopped = false;
  8753. u8 port = BP_PORT(bp);
  8754. /* reset addresses as they also mark which values were changed */
  8755. memset(vals, 0, sizeof(*vals));
  8756. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8757. if (!CHIP_IS_E3(bp)) {
  8758. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8759. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8760. if ((mask & reset_reg) && val) {
  8761. u32 wb_data[2];
  8762. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8763. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8764. : NIG_REG_INGRESS_BMAC0_MEM;
  8765. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8766. : BIGMAC_REGISTER_BMAC_CONTROL;
  8767. /*
  8768. * use rd/wr since we cannot use dmae. This is safe
  8769. * since MCP won't access the bus due to the request
  8770. * to unload, and no function on the path can be
  8771. * loaded at this time.
  8772. */
  8773. wb_data[0] = REG_RD(bp, base_addr + offset);
  8774. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8775. vals->bmac_addr = base_addr + offset;
  8776. vals->bmac_val[0] = wb_data[0];
  8777. vals->bmac_val[1] = wb_data[1];
  8778. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8779. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8780. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8781. }
  8782. BNX2X_DEV_INFO("Disable emac Rx\n");
  8783. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8784. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8785. REG_WR(bp, vals->emac_addr, 0);
  8786. mac_stopped = true;
  8787. } else {
  8788. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8789. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8790. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8791. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8792. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8793. val & ~(1 << 1));
  8794. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8795. val | (1 << 1));
  8796. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8797. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8798. REG_WR(bp, vals->xmac_addr, 0);
  8799. mac_stopped = true;
  8800. }
  8801. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 0,
  8802. reset_reg, vals);
  8803. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 1,
  8804. reset_reg, vals);
  8805. }
  8806. if (mac_stopped)
  8807. msleep(20);
  8808. }
  8809. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8810. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8811. 0x1848 + ((f) << 4))
  8812. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8813. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8814. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8815. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8816. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8817. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8818. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8819. {
  8820. /* UNDI marks its presence in DORQ -
  8821. * it initializes CID offset for normal bell to 0x7
  8822. */
  8823. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8824. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8825. return false;
  8826. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8827. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8828. return true;
  8829. }
  8830. return false;
  8831. }
  8832. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8833. {
  8834. u16 rcq, bd;
  8835. u32 addr, tmp_reg;
  8836. if (BP_FUNC(bp) < 2)
  8837. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8838. else
  8839. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8840. tmp_reg = REG_RD(bp, addr);
  8841. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8842. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8843. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8844. REG_WR(bp, addr, tmp_reg);
  8845. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8846. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8847. }
  8848. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8849. {
  8850. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8851. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8852. if (!rc) {
  8853. BNX2X_ERR("MCP response failure, aborting\n");
  8854. return -EBUSY;
  8855. }
  8856. return 0;
  8857. }
  8858. static struct bnx2x_prev_path_list *
  8859. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8860. {
  8861. struct bnx2x_prev_path_list *tmp_list;
  8862. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8863. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8864. bp->pdev->bus->number == tmp_list->bus &&
  8865. BP_PATH(bp) == tmp_list->path)
  8866. return tmp_list;
  8867. return NULL;
  8868. }
  8869. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8870. {
  8871. struct bnx2x_prev_path_list *tmp_list;
  8872. int rc;
  8873. rc = down_interruptible(&bnx2x_prev_sem);
  8874. if (rc) {
  8875. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8876. return rc;
  8877. }
  8878. tmp_list = bnx2x_prev_path_get_entry(bp);
  8879. if (tmp_list) {
  8880. tmp_list->aer = 1;
  8881. rc = 0;
  8882. } else {
  8883. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8884. BP_PATH(bp));
  8885. }
  8886. up(&bnx2x_prev_sem);
  8887. return rc;
  8888. }
  8889. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8890. {
  8891. struct bnx2x_prev_path_list *tmp_list;
  8892. bool rc = false;
  8893. if (down_trylock(&bnx2x_prev_sem))
  8894. return false;
  8895. tmp_list = bnx2x_prev_path_get_entry(bp);
  8896. if (tmp_list) {
  8897. if (tmp_list->aer) {
  8898. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8899. BP_PATH(bp));
  8900. } else {
  8901. rc = true;
  8902. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8903. BP_PATH(bp));
  8904. }
  8905. }
  8906. up(&bnx2x_prev_sem);
  8907. return rc;
  8908. }
  8909. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8910. {
  8911. struct bnx2x_prev_path_list *entry;
  8912. bool val;
  8913. down(&bnx2x_prev_sem);
  8914. entry = bnx2x_prev_path_get_entry(bp);
  8915. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8916. up(&bnx2x_prev_sem);
  8917. return val;
  8918. }
  8919. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8920. {
  8921. struct bnx2x_prev_path_list *tmp_list;
  8922. int rc;
  8923. rc = down_interruptible(&bnx2x_prev_sem);
  8924. if (rc) {
  8925. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8926. return rc;
  8927. }
  8928. /* Check whether the entry for this path already exists */
  8929. tmp_list = bnx2x_prev_path_get_entry(bp);
  8930. if (tmp_list) {
  8931. if (!tmp_list->aer) {
  8932. BNX2X_ERR("Re-Marking the path.\n");
  8933. } else {
  8934. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8935. BP_PATH(bp));
  8936. tmp_list->aer = 0;
  8937. }
  8938. up(&bnx2x_prev_sem);
  8939. return 0;
  8940. }
  8941. up(&bnx2x_prev_sem);
  8942. /* Create an entry for this path and add it */
  8943. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8944. if (!tmp_list) {
  8945. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8946. return -ENOMEM;
  8947. }
  8948. tmp_list->bus = bp->pdev->bus->number;
  8949. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8950. tmp_list->path = BP_PATH(bp);
  8951. tmp_list->aer = 0;
  8952. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8953. rc = down_interruptible(&bnx2x_prev_sem);
  8954. if (rc) {
  8955. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8956. kfree(tmp_list);
  8957. } else {
  8958. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8959. BP_PATH(bp));
  8960. list_add(&tmp_list->list, &bnx2x_prev_list);
  8961. up(&bnx2x_prev_sem);
  8962. }
  8963. return rc;
  8964. }
  8965. static int bnx2x_do_flr(struct bnx2x *bp)
  8966. {
  8967. struct pci_dev *dev = bp->pdev;
  8968. if (CHIP_IS_E1x(bp)) {
  8969. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8970. return -EINVAL;
  8971. }
  8972. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8973. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8974. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8975. bp->common.bc_ver);
  8976. return -EINVAL;
  8977. }
  8978. if (!pci_wait_for_pending_transaction(dev))
  8979. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8980. BNX2X_DEV_INFO("Initiating FLR\n");
  8981. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8982. return 0;
  8983. }
  8984. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8985. {
  8986. int rc;
  8987. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8988. /* Test if previous unload process was already finished for this path */
  8989. if (bnx2x_prev_is_path_marked(bp))
  8990. return bnx2x_prev_mcp_done(bp);
  8991. BNX2X_DEV_INFO("Path is unmarked\n");
  8992. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8993. if (bnx2x_prev_is_after_undi(bp))
  8994. goto out;
  8995. /* If function has FLR capabilities, and existing FW version matches
  8996. * the one required, then FLR will be sufficient to clean any residue
  8997. * left by previous driver
  8998. */
  8999. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  9000. if (!rc) {
  9001. /* fw version is good */
  9002. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  9003. rc = bnx2x_do_flr(bp);
  9004. }
  9005. if (!rc) {
  9006. /* FLR was performed */
  9007. BNX2X_DEV_INFO("FLR successful\n");
  9008. return 0;
  9009. }
  9010. BNX2X_DEV_INFO("Could not FLR\n");
  9011. out:
  9012. /* Close the MCP request, return failure*/
  9013. rc = bnx2x_prev_mcp_done(bp);
  9014. if (!rc)
  9015. rc = BNX2X_PREV_WAIT_NEEDED;
  9016. return rc;
  9017. }
  9018. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  9019. {
  9020. u32 reset_reg, tmp_reg = 0, rc;
  9021. bool prev_undi = false;
  9022. struct bnx2x_mac_vals mac_vals;
  9023. /* It is possible a previous function received 'common' answer,
  9024. * but hasn't loaded yet, therefore creating a scenario of
  9025. * multiple functions receiving 'common' on the same path.
  9026. */
  9027. BNX2X_DEV_INFO("Common unload Flow\n");
  9028. memset(&mac_vals, 0, sizeof(mac_vals));
  9029. if (bnx2x_prev_is_path_marked(bp))
  9030. return bnx2x_prev_mcp_done(bp);
  9031. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  9032. /* Reset should be performed after BRB is emptied */
  9033. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  9034. u32 timer_count = 1000;
  9035. /* Close the MAC Rx to prevent BRB from filling up */
  9036. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  9037. /* close LLH filters for both ports towards the BRB */
  9038. bnx2x_set_rx_filter(&bp->link_params, 0);
  9039. bp->link_params.port ^= 1;
  9040. bnx2x_set_rx_filter(&bp->link_params, 0);
  9041. bp->link_params.port ^= 1;
  9042. /* Check if the UNDI driver was previously loaded */
  9043. if (bnx2x_prev_is_after_undi(bp)) {
  9044. prev_undi = true;
  9045. /* clear the UNDI indication */
  9046. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  9047. /* clear possible idle check errors */
  9048. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  9049. }
  9050. if (!CHIP_IS_E1x(bp))
  9051. /* block FW from writing to host */
  9052. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  9053. /* wait until BRB is empty */
  9054. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9055. while (timer_count) {
  9056. u32 prev_brb = tmp_reg;
  9057. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9058. if (!tmp_reg)
  9059. break;
  9060. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  9061. /* reset timer as long as BRB actually gets emptied */
  9062. if (prev_brb > tmp_reg)
  9063. timer_count = 1000;
  9064. else
  9065. timer_count--;
  9066. /* If UNDI resides in memory, manually increment it */
  9067. if (prev_undi)
  9068. bnx2x_prev_unload_undi_inc(bp, 1);
  9069. udelay(10);
  9070. }
  9071. if (!timer_count)
  9072. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  9073. }
  9074. /* No packets are in the pipeline, path is ready for reset */
  9075. bnx2x_reset_common(bp);
  9076. if (mac_vals.xmac_addr)
  9077. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  9078. if (mac_vals.umac_addr[0])
  9079. REG_WR(bp, mac_vals.umac_addr[0], mac_vals.umac_val[0]);
  9080. if (mac_vals.umac_addr[1])
  9081. REG_WR(bp, mac_vals.umac_addr[1], mac_vals.umac_val[1]);
  9082. if (mac_vals.emac_addr)
  9083. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  9084. if (mac_vals.bmac_addr) {
  9085. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  9086. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  9087. }
  9088. rc = bnx2x_prev_mark_path(bp, prev_undi);
  9089. if (rc) {
  9090. bnx2x_prev_mcp_done(bp);
  9091. return rc;
  9092. }
  9093. return bnx2x_prev_mcp_done(bp);
  9094. }
  9095. static int bnx2x_prev_unload(struct bnx2x *bp)
  9096. {
  9097. int time_counter = 10;
  9098. u32 rc, fw, hw_lock_reg, hw_lock_val;
  9099. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  9100. /* clear hw from errors which may have resulted from an interrupted
  9101. * dmae transaction.
  9102. */
  9103. bnx2x_clean_pglue_errors(bp);
  9104. /* Release previously held locks */
  9105. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  9106. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  9107. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  9108. hw_lock_val = REG_RD(bp, hw_lock_reg);
  9109. if (hw_lock_val) {
  9110. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  9111. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  9112. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  9113. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  9114. }
  9115. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  9116. REG_WR(bp, hw_lock_reg, 0xffffffff);
  9117. } else
  9118. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  9119. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  9120. BNX2X_DEV_INFO("Release previously held alr\n");
  9121. bnx2x_release_alr(bp);
  9122. }
  9123. do {
  9124. int aer = 0;
  9125. /* Lock MCP using an unload request */
  9126. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  9127. if (!fw) {
  9128. BNX2X_ERR("MCP response failure, aborting\n");
  9129. rc = -EBUSY;
  9130. break;
  9131. }
  9132. rc = down_interruptible(&bnx2x_prev_sem);
  9133. if (rc) {
  9134. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  9135. rc);
  9136. } else {
  9137. /* If Path is marked by EEH, ignore unload status */
  9138. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  9139. bnx2x_prev_path_get_entry(bp)->aer);
  9140. up(&bnx2x_prev_sem);
  9141. }
  9142. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  9143. rc = bnx2x_prev_unload_common(bp);
  9144. break;
  9145. }
  9146. /* non-common reply from MCP might require looping */
  9147. rc = bnx2x_prev_unload_uncommon(bp);
  9148. if (rc != BNX2X_PREV_WAIT_NEEDED)
  9149. break;
  9150. msleep(20);
  9151. } while (--time_counter);
  9152. if (!time_counter || rc) {
  9153. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  9154. rc = -EPROBE_DEFER;
  9155. }
  9156. /* Mark function if its port was used to boot from SAN */
  9157. if (bnx2x_port_after_undi(bp))
  9158. bp->link_params.feature_config_flags |=
  9159. FEATURE_CONFIG_BOOT_FROM_SAN;
  9160. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  9161. return rc;
  9162. }
  9163. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  9164. {
  9165. u32 val, val2, val3, val4, id, boot_mode;
  9166. u16 pmc;
  9167. /* Get the chip revision id and number. */
  9168. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  9169. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  9170. id = ((val & 0xffff) << 16);
  9171. val = REG_RD(bp, MISC_REG_CHIP_REV);
  9172. id |= ((val & 0xf) << 12);
  9173. /* Metal is read from PCI regs, but we can't access >=0x400 from
  9174. * the configuration space (so we need to reg_rd)
  9175. */
  9176. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  9177. id |= (((val >> 24) & 0xf) << 4);
  9178. val = REG_RD(bp, MISC_REG_BOND_ID);
  9179. id |= (val & 0xf);
  9180. bp->common.chip_id = id;
  9181. /* force 57811 according to MISC register */
  9182. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  9183. if (CHIP_IS_57810(bp))
  9184. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  9185. (bp->common.chip_id & 0x0000FFFF);
  9186. else if (CHIP_IS_57810_MF(bp))
  9187. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  9188. (bp->common.chip_id & 0x0000FFFF);
  9189. bp->common.chip_id |= 0x1;
  9190. }
  9191. /* Set doorbell size */
  9192. bp->db_size = (1 << BNX2X_DB_SHIFT);
  9193. if (!CHIP_IS_E1x(bp)) {
  9194. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  9195. if ((val & 1) == 0)
  9196. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  9197. else
  9198. val = (val >> 1) & 1;
  9199. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  9200. "2_PORT_MODE");
  9201. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  9202. CHIP_2_PORT_MODE;
  9203. if (CHIP_MODE_IS_4_PORT(bp))
  9204. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  9205. else
  9206. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  9207. } else {
  9208. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  9209. bp->pfid = bp->pf_num; /* 0..7 */
  9210. }
  9211. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  9212. bp->link_params.chip_id = bp->common.chip_id;
  9213. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  9214. val = (REG_RD(bp, 0x2874) & 0x55);
  9215. if ((bp->common.chip_id & 0x1) ||
  9216. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  9217. bp->flags |= ONE_PORT_FLAG;
  9218. BNX2X_DEV_INFO("single port device\n");
  9219. }
  9220. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9221. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9222. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9223. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9224. bp->common.flash_size, bp->common.flash_size);
  9225. bnx2x_init_shmem(bp);
  9226. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9227. MISC_REG_GENERIC_CR_1 :
  9228. MISC_REG_GENERIC_CR_0));
  9229. bp->link_params.shmem_base = bp->common.shmem_base;
  9230. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9231. if (SHMEM2_RD(bp, size) >
  9232. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9233. bp->link_params.lfa_base =
  9234. REG_RD(bp, bp->common.shmem2_base +
  9235. (u32)offsetof(struct shmem2_region,
  9236. lfa_host_addr[BP_PORT(bp)]));
  9237. else
  9238. bp->link_params.lfa_base = 0;
  9239. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9240. bp->common.shmem_base, bp->common.shmem2_base);
  9241. if (!bp->common.shmem_base) {
  9242. BNX2X_DEV_INFO("MCP not active\n");
  9243. bp->flags |= NO_MCP_FLAG;
  9244. return;
  9245. }
  9246. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9247. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9248. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9249. SHARED_HW_CFG_LED_MODE_MASK) >>
  9250. SHARED_HW_CFG_LED_MODE_SHIFT);
  9251. bp->link_params.feature_config_flags = 0;
  9252. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9253. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9254. bp->link_params.feature_config_flags |=
  9255. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9256. else
  9257. bp->link_params.feature_config_flags &=
  9258. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9259. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9260. bp->common.bc_ver = val;
  9261. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9262. if (val < BNX2X_BC_VER) {
  9263. /* for now only warn
  9264. * later we might need to enforce this */
  9265. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9266. BNX2X_BC_VER, val);
  9267. }
  9268. bp->link_params.feature_config_flags |=
  9269. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9270. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9271. bp->link_params.feature_config_flags |=
  9272. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9273. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9274. bp->link_params.feature_config_flags |=
  9275. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9276. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9277. bp->link_params.feature_config_flags |=
  9278. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9279. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9280. bp->link_params.feature_config_flags |=
  9281. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9282. FEATURE_CONFIG_MT_SUPPORT : 0;
  9283. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9284. BC_SUPPORTS_PFC_STATS : 0;
  9285. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9286. BC_SUPPORTS_FCOE_FEATURES : 0;
  9287. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9288. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9289. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9290. BC_SUPPORTS_RMMOD_CMD : 0;
  9291. boot_mode = SHMEM_RD(bp,
  9292. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9293. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9294. switch (boot_mode) {
  9295. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9296. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9297. break;
  9298. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9299. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9300. break;
  9301. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9302. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9303. break;
  9304. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9305. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9306. break;
  9307. }
  9308. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9309. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9310. BNX2X_DEV_INFO("%sWoL capable\n",
  9311. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9312. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9313. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9314. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9315. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9316. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9317. val, val2, val3, val4);
  9318. }
  9319. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9320. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9321. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9322. {
  9323. int pfid = BP_FUNC(bp);
  9324. int igu_sb_id;
  9325. u32 val;
  9326. u8 fid, igu_sb_cnt = 0;
  9327. bp->igu_base_sb = 0xff;
  9328. if (CHIP_INT_MODE_IS_BC(bp)) {
  9329. int vn = BP_VN(bp);
  9330. igu_sb_cnt = bp->igu_sb_cnt;
  9331. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9332. FP_SB_MAX_E1x;
  9333. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9334. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9335. return 0;
  9336. }
  9337. /* IGU in normal mode - read CAM */
  9338. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9339. igu_sb_id++) {
  9340. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9341. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9342. continue;
  9343. fid = IGU_FID(val);
  9344. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9345. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9346. continue;
  9347. if (IGU_VEC(val) == 0)
  9348. /* default status block */
  9349. bp->igu_dsb_id = igu_sb_id;
  9350. else {
  9351. if (bp->igu_base_sb == 0xff)
  9352. bp->igu_base_sb = igu_sb_id;
  9353. igu_sb_cnt++;
  9354. }
  9355. }
  9356. }
  9357. #ifdef CONFIG_PCI_MSI
  9358. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9359. * optional that number of CAM entries will not be equal to the value
  9360. * advertised in PCI.
  9361. * Driver should use the minimal value of both as the actual status
  9362. * block count
  9363. */
  9364. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9365. #endif
  9366. if (igu_sb_cnt == 0) {
  9367. BNX2X_ERR("CAM configuration error\n");
  9368. return -EINVAL;
  9369. }
  9370. return 0;
  9371. }
  9372. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9373. {
  9374. int cfg_size = 0, idx, port = BP_PORT(bp);
  9375. /* Aggregation of supported attributes of all external phys */
  9376. bp->port.supported[0] = 0;
  9377. bp->port.supported[1] = 0;
  9378. switch (bp->link_params.num_phys) {
  9379. case 1:
  9380. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9381. cfg_size = 1;
  9382. break;
  9383. case 2:
  9384. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9385. cfg_size = 1;
  9386. break;
  9387. case 3:
  9388. if (bp->link_params.multi_phy_config &
  9389. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9390. bp->port.supported[1] =
  9391. bp->link_params.phy[EXT_PHY1].supported;
  9392. bp->port.supported[0] =
  9393. bp->link_params.phy[EXT_PHY2].supported;
  9394. } else {
  9395. bp->port.supported[0] =
  9396. bp->link_params.phy[EXT_PHY1].supported;
  9397. bp->port.supported[1] =
  9398. bp->link_params.phy[EXT_PHY2].supported;
  9399. }
  9400. cfg_size = 2;
  9401. break;
  9402. }
  9403. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9404. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9405. SHMEM_RD(bp,
  9406. dev_info.port_hw_config[port].external_phy_config),
  9407. SHMEM_RD(bp,
  9408. dev_info.port_hw_config[port].external_phy_config2));
  9409. return;
  9410. }
  9411. if (CHIP_IS_E3(bp))
  9412. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9413. else {
  9414. switch (switch_cfg) {
  9415. case SWITCH_CFG_1G:
  9416. bp->port.phy_addr = REG_RD(
  9417. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9418. break;
  9419. case SWITCH_CFG_10G:
  9420. bp->port.phy_addr = REG_RD(
  9421. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9422. break;
  9423. default:
  9424. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9425. bp->port.link_config[0]);
  9426. return;
  9427. }
  9428. }
  9429. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9430. /* mask what we support according to speed_cap_mask per configuration */
  9431. for (idx = 0; idx < cfg_size; idx++) {
  9432. if (!(bp->link_params.speed_cap_mask[idx] &
  9433. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9434. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9435. if (!(bp->link_params.speed_cap_mask[idx] &
  9436. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9437. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9438. if (!(bp->link_params.speed_cap_mask[idx] &
  9439. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9440. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9441. if (!(bp->link_params.speed_cap_mask[idx] &
  9442. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9443. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9444. if (!(bp->link_params.speed_cap_mask[idx] &
  9445. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9446. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9447. SUPPORTED_1000baseT_Full);
  9448. if (!(bp->link_params.speed_cap_mask[idx] &
  9449. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9450. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9451. if (!(bp->link_params.speed_cap_mask[idx] &
  9452. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9453. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9454. if (!(bp->link_params.speed_cap_mask[idx] &
  9455. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9456. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9457. }
  9458. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9459. bp->port.supported[1]);
  9460. }
  9461. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9462. {
  9463. u32 link_config, idx, cfg_size = 0;
  9464. bp->port.advertising[0] = 0;
  9465. bp->port.advertising[1] = 0;
  9466. switch (bp->link_params.num_phys) {
  9467. case 1:
  9468. case 2:
  9469. cfg_size = 1;
  9470. break;
  9471. case 3:
  9472. cfg_size = 2;
  9473. break;
  9474. }
  9475. for (idx = 0; idx < cfg_size; idx++) {
  9476. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9477. link_config = bp->port.link_config[idx];
  9478. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9479. case PORT_FEATURE_LINK_SPEED_AUTO:
  9480. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9481. bp->link_params.req_line_speed[idx] =
  9482. SPEED_AUTO_NEG;
  9483. bp->port.advertising[idx] |=
  9484. bp->port.supported[idx];
  9485. if (bp->link_params.phy[EXT_PHY1].type ==
  9486. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9487. bp->port.advertising[idx] |=
  9488. (SUPPORTED_100baseT_Half |
  9489. SUPPORTED_100baseT_Full);
  9490. } else {
  9491. /* force 10G, no AN */
  9492. bp->link_params.req_line_speed[idx] =
  9493. SPEED_10000;
  9494. bp->port.advertising[idx] |=
  9495. (ADVERTISED_10000baseT_Full |
  9496. ADVERTISED_FIBRE);
  9497. continue;
  9498. }
  9499. break;
  9500. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9501. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9502. bp->link_params.req_line_speed[idx] =
  9503. SPEED_10;
  9504. bp->port.advertising[idx] |=
  9505. (ADVERTISED_10baseT_Full |
  9506. ADVERTISED_TP);
  9507. } else {
  9508. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9509. link_config,
  9510. bp->link_params.speed_cap_mask[idx]);
  9511. return;
  9512. }
  9513. break;
  9514. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9515. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9516. bp->link_params.req_line_speed[idx] =
  9517. SPEED_10;
  9518. bp->link_params.req_duplex[idx] =
  9519. DUPLEX_HALF;
  9520. bp->port.advertising[idx] |=
  9521. (ADVERTISED_10baseT_Half |
  9522. ADVERTISED_TP);
  9523. } else {
  9524. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9525. link_config,
  9526. bp->link_params.speed_cap_mask[idx]);
  9527. return;
  9528. }
  9529. break;
  9530. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9531. if (bp->port.supported[idx] &
  9532. SUPPORTED_100baseT_Full) {
  9533. bp->link_params.req_line_speed[idx] =
  9534. SPEED_100;
  9535. bp->port.advertising[idx] |=
  9536. (ADVERTISED_100baseT_Full |
  9537. ADVERTISED_TP);
  9538. } else {
  9539. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9540. link_config,
  9541. bp->link_params.speed_cap_mask[idx]);
  9542. return;
  9543. }
  9544. break;
  9545. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9546. if (bp->port.supported[idx] &
  9547. SUPPORTED_100baseT_Half) {
  9548. bp->link_params.req_line_speed[idx] =
  9549. SPEED_100;
  9550. bp->link_params.req_duplex[idx] =
  9551. DUPLEX_HALF;
  9552. bp->port.advertising[idx] |=
  9553. (ADVERTISED_100baseT_Half |
  9554. ADVERTISED_TP);
  9555. } else {
  9556. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9557. link_config,
  9558. bp->link_params.speed_cap_mask[idx]);
  9559. return;
  9560. }
  9561. break;
  9562. case PORT_FEATURE_LINK_SPEED_1G:
  9563. if (bp->port.supported[idx] &
  9564. SUPPORTED_1000baseT_Full) {
  9565. bp->link_params.req_line_speed[idx] =
  9566. SPEED_1000;
  9567. bp->port.advertising[idx] |=
  9568. (ADVERTISED_1000baseT_Full |
  9569. ADVERTISED_TP);
  9570. } else if (bp->port.supported[idx] &
  9571. SUPPORTED_1000baseKX_Full) {
  9572. bp->link_params.req_line_speed[idx] =
  9573. SPEED_1000;
  9574. bp->port.advertising[idx] |=
  9575. ADVERTISED_1000baseKX_Full;
  9576. } else {
  9577. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9578. link_config,
  9579. bp->link_params.speed_cap_mask[idx]);
  9580. return;
  9581. }
  9582. break;
  9583. case PORT_FEATURE_LINK_SPEED_2_5G:
  9584. if (bp->port.supported[idx] &
  9585. SUPPORTED_2500baseX_Full) {
  9586. bp->link_params.req_line_speed[idx] =
  9587. SPEED_2500;
  9588. bp->port.advertising[idx] |=
  9589. (ADVERTISED_2500baseX_Full |
  9590. ADVERTISED_TP);
  9591. } else {
  9592. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9593. link_config,
  9594. bp->link_params.speed_cap_mask[idx]);
  9595. return;
  9596. }
  9597. break;
  9598. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9599. if (bp->port.supported[idx] &
  9600. SUPPORTED_10000baseT_Full) {
  9601. bp->link_params.req_line_speed[idx] =
  9602. SPEED_10000;
  9603. bp->port.advertising[idx] |=
  9604. (ADVERTISED_10000baseT_Full |
  9605. ADVERTISED_FIBRE);
  9606. } else if (bp->port.supported[idx] &
  9607. SUPPORTED_10000baseKR_Full) {
  9608. bp->link_params.req_line_speed[idx] =
  9609. SPEED_10000;
  9610. bp->port.advertising[idx] |=
  9611. (ADVERTISED_10000baseKR_Full |
  9612. ADVERTISED_FIBRE);
  9613. } else {
  9614. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9615. link_config,
  9616. bp->link_params.speed_cap_mask[idx]);
  9617. return;
  9618. }
  9619. break;
  9620. case PORT_FEATURE_LINK_SPEED_20G:
  9621. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9622. break;
  9623. default:
  9624. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9625. link_config);
  9626. bp->link_params.req_line_speed[idx] =
  9627. SPEED_AUTO_NEG;
  9628. bp->port.advertising[idx] =
  9629. bp->port.supported[idx];
  9630. break;
  9631. }
  9632. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9633. PORT_FEATURE_FLOW_CONTROL_MASK);
  9634. if (bp->link_params.req_flow_ctrl[idx] ==
  9635. BNX2X_FLOW_CTRL_AUTO) {
  9636. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9637. bp->link_params.req_flow_ctrl[idx] =
  9638. BNX2X_FLOW_CTRL_NONE;
  9639. else
  9640. bnx2x_set_requested_fc(bp);
  9641. }
  9642. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9643. bp->link_params.req_line_speed[idx],
  9644. bp->link_params.req_duplex[idx],
  9645. bp->link_params.req_flow_ctrl[idx],
  9646. bp->port.advertising[idx]);
  9647. }
  9648. }
  9649. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9650. {
  9651. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9652. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9653. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9654. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9655. }
  9656. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9657. {
  9658. int port = BP_PORT(bp);
  9659. u32 config;
  9660. u32 ext_phy_type, ext_phy_config, eee_mode;
  9661. bp->link_params.bp = bp;
  9662. bp->link_params.port = port;
  9663. bp->link_params.lane_config =
  9664. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9665. bp->link_params.speed_cap_mask[0] =
  9666. SHMEM_RD(bp,
  9667. dev_info.port_hw_config[port].speed_capability_mask) &
  9668. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9669. bp->link_params.speed_cap_mask[1] =
  9670. SHMEM_RD(bp,
  9671. dev_info.port_hw_config[port].speed_capability_mask2) &
  9672. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9673. bp->port.link_config[0] =
  9674. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9675. bp->port.link_config[1] =
  9676. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9677. bp->link_params.multi_phy_config =
  9678. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9679. /* If the device is capable of WoL, set the default state according
  9680. * to the HW
  9681. */
  9682. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9683. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9684. (config & PORT_FEATURE_WOL_ENABLED));
  9685. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9686. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9687. bp->flags |= NO_ISCSI_FLAG;
  9688. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9689. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9690. bp->flags |= NO_FCOE_FLAG;
  9691. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9692. bp->link_params.lane_config,
  9693. bp->link_params.speed_cap_mask[0],
  9694. bp->port.link_config[0]);
  9695. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9696. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9697. bnx2x_phy_probe(&bp->link_params);
  9698. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9699. bnx2x_link_settings_requested(bp);
  9700. /*
  9701. * If connected directly, work with the internal PHY, otherwise, work
  9702. * with the external PHY
  9703. */
  9704. ext_phy_config =
  9705. SHMEM_RD(bp,
  9706. dev_info.port_hw_config[port].external_phy_config);
  9707. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9708. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9709. bp->mdio.prtad = bp->port.phy_addr;
  9710. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9711. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9712. bp->mdio.prtad =
  9713. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9714. /* Configure link feature according to nvram value */
  9715. eee_mode = (((SHMEM_RD(bp, dev_info.
  9716. port_feature_config[port].eee_power_mode)) &
  9717. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9718. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9719. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9720. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9721. EEE_MODE_ENABLE_LPI |
  9722. EEE_MODE_OUTPUT_TIME;
  9723. } else {
  9724. bp->link_params.eee_mode = 0;
  9725. }
  9726. }
  9727. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9728. {
  9729. u32 no_flags = NO_ISCSI_FLAG;
  9730. int port = BP_PORT(bp);
  9731. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9732. drv_lic_key[port].max_iscsi_conn);
  9733. if (!CNIC_SUPPORT(bp)) {
  9734. bp->flags |= no_flags;
  9735. return;
  9736. }
  9737. /* Get the number of maximum allowed iSCSI connections */
  9738. bp->cnic_eth_dev.max_iscsi_conn =
  9739. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9740. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9741. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9742. bp->cnic_eth_dev.max_iscsi_conn);
  9743. /*
  9744. * If maximum allowed number of connections is zero -
  9745. * disable the feature.
  9746. */
  9747. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9748. bp->flags |= no_flags;
  9749. }
  9750. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9751. {
  9752. /* Port info */
  9753. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9754. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9755. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9756. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9757. /* Node info */
  9758. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9759. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9760. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9761. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9762. }
  9763. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9764. {
  9765. u8 count = 0;
  9766. if (IS_MF(bp)) {
  9767. u8 fid;
  9768. /* iterate over absolute function ids for this path: */
  9769. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9770. if (IS_MF_SD(bp)) {
  9771. u32 cfg = MF_CFG_RD(bp,
  9772. func_mf_config[fid].config);
  9773. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9774. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9775. FUNC_MF_CFG_PROTOCOL_FCOE))
  9776. count++;
  9777. } else {
  9778. u32 cfg = MF_CFG_RD(bp,
  9779. func_ext_config[fid].
  9780. func_cfg);
  9781. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9782. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9783. count++;
  9784. }
  9785. }
  9786. } else { /* SF */
  9787. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9788. for (port = 0; port < port_cnt; port++) {
  9789. u32 lic = SHMEM_RD(bp,
  9790. drv_lic_key[port].max_fcoe_conn) ^
  9791. FW_ENCODE_32BIT_PATTERN;
  9792. if (lic)
  9793. count++;
  9794. }
  9795. }
  9796. return count;
  9797. }
  9798. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9799. {
  9800. int port = BP_PORT(bp);
  9801. int func = BP_ABS_FUNC(bp);
  9802. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9803. drv_lic_key[port].max_fcoe_conn);
  9804. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9805. if (!CNIC_SUPPORT(bp)) {
  9806. bp->flags |= NO_FCOE_FLAG;
  9807. return;
  9808. }
  9809. /* Get the number of maximum allowed FCoE connections */
  9810. bp->cnic_eth_dev.max_fcoe_conn =
  9811. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9812. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9813. /* Calculate the number of maximum allowed FCoE tasks */
  9814. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9815. /* check if FCoE resources must be shared between different functions */
  9816. if (num_fcoe_func)
  9817. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9818. /* Read the WWN: */
  9819. if (!IS_MF(bp)) {
  9820. /* Port info */
  9821. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9822. SHMEM_RD(bp,
  9823. dev_info.port_hw_config[port].
  9824. fcoe_wwn_port_name_upper);
  9825. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9826. SHMEM_RD(bp,
  9827. dev_info.port_hw_config[port].
  9828. fcoe_wwn_port_name_lower);
  9829. /* Node info */
  9830. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9831. SHMEM_RD(bp,
  9832. dev_info.port_hw_config[port].
  9833. fcoe_wwn_node_name_upper);
  9834. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9835. SHMEM_RD(bp,
  9836. dev_info.port_hw_config[port].
  9837. fcoe_wwn_node_name_lower);
  9838. } else if (!IS_MF_SD(bp)) {
  9839. /* Read the WWN info only if the FCoE feature is enabled for
  9840. * this function.
  9841. */
  9842. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9843. bnx2x_get_ext_wwn_info(bp, func);
  9844. } else {
  9845. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9846. bnx2x_get_ext_wwn_info(bp, func);
  9847. }
  9848. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9849. /*
  9850. * If maximum allowed number of connections is zero -
  9851. * disable the feature.
  9852. */
  9853. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9854. bp->flags |= NO_FCOE_FLAG;
  9855. }
  9856. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9857. {
  9858. /*
  9859. * iSCSI may be dynamically disabled but reading
  9860. * info here we will decrease memory usage by driver
  9861. * if the feature is disabled for good
  9862. */
  9863. bnx2x_get_iscsi_info(bp);
  9864. bnx2x_get_fcoe_info(bp);
  9865. }
  9866. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9867. {
  9868. u32 val, val2;
  9869. int func = BP_ABS_FUNC(bp);
  9870. int port = BP_PORT(bp);
  9871. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9872. u8 *fip_mac = bp->fip_mac;
  9873. if (IS_MF(bp)) {
  9874. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9875. * FCoE MAC then the appropriate feature should be disabled.
  9876. * In non SD mode features configuration comes from struct
  9877. * func_ext_config.
  9878. */
  9879. if (!IS_MF_SD(bp)) {
  9880. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9881. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9882. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9883. iscsi_mac_addr_upper);
  9884. val = MF_CFG_RD(bp, func_ext_config[func].
  9885. iscsi_mac_addr_lower);
  9886. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9887. BNX2X_DEV_INFO
  9888. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9889. } else {
  9890. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9891. }
  9892. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9893. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9894. fcoe_mac_addr_upper);
  9895. val = MF_CFG_RD(bp, func_ext_config[func].
  9896. fcoe_mac_addr_lower);
  9897. bnx2x_set_mac_buf(fip_mac, val, val2);
  9898. BNX2X_DEV_INFO
  9899. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9900. } else {
  9901. bp->flags |= NO_FCOE_FLAG;
  9902. }
  9903. bp->mf_ext_config = cfg;
  9904. } else { /* SD MODE */
  9905. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9906. /* use primary mac as iscsi mac */
  9907. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9908. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9909. BNX2X_DEV_INFO
  9910. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9911. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9912. /* use primary mac as fip mac */
  9913. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9914. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9915. BNX2X_DEV_INFO
  9916. ("Read FIP MAC: %pM\n", fip_mac);
  9917. }
  9918. }
  9919. /* If this is a storage-only interface, use SAN mac as
  9920. * primary MAC. Notice that for SD this is already the case,
  9921. * as the SAN mac was copied from the primary MAC.
  9922. */
  9923. if (IS_MF_FCOE_AFEX(bp))
  9924. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9925. } else {
  9926. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9927. iscsi_mac_upper);
  9928. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9929. iscsi_mac_lower);
  9930. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9931. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9932. fcoe_fip_mac_upper);
  9933. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9934. fcoe_fip_mac_lower);
  9935. bnx2x_set_mac_buf(fip_mac, val, val2);
  9936. }
  9937. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9938. if (!is_valid_ether_addr(iscsi_mac)) {
  9939. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9940. eth_zero_addr(iscsi_mac);
  9941. }
  9942. /* Disable FCoE if MAC configuration is invalid. */
  9943. if (!is_valid_ether_addr(fip_mac)) {
  9944. bp->flags |= NO_FCOE_FLAG;
  9945. eth_zero_addr(bp->fip_mac);
  9946. }
  9947. }
  9948. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9949. {
  9950. u32 val, val2;
  9951. int func = BP_ABS_FUNC(bp);
  9952. int port = BP_PORT(bp);
  9953. /* Zero primary MAC configuration */
  9954. eth_zero_addr(bp->dev->dev_addr);
  9955. if (BP_NOMCP(bp)) {
  9956. BNX2X_ERROR("warning: random MAC workaround active\n");
  9957. eth_hw_addr_random(bp->dev);
  9958. } else if (IS_MF(bp)) {
  9959. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9960. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9961. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9962. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9963. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9964. if (CNIC_SUPPORT(bp))
  9965. bnx2x_get_cnic_mac_hwinfo(bp);
  9966. } else {
  9967. /* in SF read MACs from port configuration */
  9968. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9969. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9970. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9971. if (CNIC_SUPPORT(bp))
  9972. bnx2x_get_cnic_mac_hwinfo(bp);
  9973. }
  9974. if (!BP_NOMCP(bp)) {
  9975. /* Read physical port identifier from shmem */
  9976. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9977. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9978. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9979. bp->flags |= HAS_PHYS_PORT_ID;
  9980. }
  9981. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9982. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9983. dev_err(&bp->pdev->dev,
  9984. "bad Ethernet MAC address configuration: %pM\n"
  9985. "change it manually before bringing up the appropriate network interface\n",
  9986. bp->dev->dev_addr);
  9987. }
  9988. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9989. {
  9990. int tmp;
  9991. u32 cfg;
  9992. if (IS_VF(bp))
  9993. return false;
  9994. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9995. /* Take function: tmp = func */
  9996. tmp = BP_ABS_FUNC(bp);
  9997. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9998. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9999. } else {
  10000. /* Take port: tmp = port */
  10001. tmp = BP_PORT(bp);
  10002. cfg = SHMEM_RD(bp,
  10003. dev_info.port_hw_config[tmp].generic_features);
  10004. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  10005. }
  10006. return cfg;
  10007. }
  10008. static void validate_set_si_mode(struct bnx2x *bp)
  10009. {
  10010. u8 func = BP_ABS_FUNC(bp);
  10011. u32 val;
  10012. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  10013. /* check for legal mac (upper bytes) */
  10014. if (val != 0xffff) {
  10015. bp->mf_mode = MULTI_FUNCTION_SI;
  10016. bp->mf_config[BP_VN(bp)] =
  10017. MF_CFG_RD(bp, func_mf_config[func].config);
  10018. } else
  10019. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  10020. }
  10021. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  10022. {
  10023. int /*abs*/func = BP_ABS_FUNC(bp);
  10024. int vn, mfw_vn;
  10025. u32 val = 0, val2 = 0;
  10026. int rc = 0;
  10027. /* Validate that chip access is feasible */
  10028. if (REG_RD(bp, MISC_REG_CHIP_NUM) == 0xffffffff) {
  10029. dev_err(&bp->pdev->dev,
  10030. "Chip read returns all Fs. Preventing probe from continuing\n");
  10031. return -EINVAL;
  10032. }
  10033. bnx2x_get_common_hwinfo(bp);
  10034. /*
  10035. * initialize IGU parameters
  10036. */
  10037. if (CHIP_IS_E1x(bp)) {
  10038. bp->common.int_block = INT_BLOCK_HC;
  10039. bp->igu_dsb_id = DEF_SB_IGU_ID;
  10040. bp->igu_base_sb = 0;
  10041. } else {
  10042. bp->common.int_block = INT_BLOCK_IGU;
  10043. /* do not allow device reset during IGU info processing */
  10044. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10045. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  10046. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10047. int tout = 5000;
  10048. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  10049. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  10050. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  10051. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  10052. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10053. tout--;
  10054. usleep_range(1000, 2000);
  10055. }
  10056. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10057. dev_err(&bp->pdev->dev,
  10058. "FORCING Normal Mode failed!!!\n");
  10059. bnx2x_release_hw_lock(bp,
  10060. HW_LOCK_RESOURCE_RESET);
  10061. return -EPERM;
  10062. }
  10063. }
  10064. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10065. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  10066. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  10067. } else
  10068. BNX2X_DEV_INFO("IGU Normal Mode\n");
  10069. rc = bnx2x_get_igu_cam_info(bp);
  10070. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10071. if (rc)
  10072. return rc;
  10073. }
  10074. /*
  10075. * set base FW non-default (fast path) status block id, this value is
  10076. * used to initialize the fw_sb_id saved on the fp/queue structure to
  10077. * determine the id used by the FW.
  10078. */
  10079. if (CHIP_IS_E1x(bp))
  10080. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  10081. else /*
  10082. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  10083. * the same queue are indicated on the same IGU SB). So we prefer
  10084. * FW and IGU SBs to be the same value.
  10085. */
  10086. bp->base_fw_ndsb = bp->igu_base_sb;
  10087. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  10088. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  10089. bp->igu_sb_cnt, bp->base_fw_ndsb);
  10090. /*
  10091. * Initialize MF configuration
  10092. */
  10093. bp->mf_ov = 0;
  10094. bp->mf_mode = 0;
  10095. bp->mf_sub_mode = 0;
  10096. vn = BP_VN(bp);
  10097. mfw_vn = BP_FW_MB_IDX(bp);
  10098. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  10099. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  10100. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  10101. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  10102. if (SHMEM2_HAS(bp, mf_cfg_addr))
  10103. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  10104. else
  10105. bp->common.mf_cfg_base = bp->common.shmem_base +
  10106. offsetof(struct shmem_region, func_mb) +
  10107. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  10108. /*
  10109. * get mf configuration:
  10110. * 1. Existence of MF configuration
  10111. * 2. MAC address must be legal (check only upper bytes)
  10112. * for Switch-Independent mode;
  10113. * OVLAN must be legal for Switch-Dependent mode
  10114. * 3. SF_MODE configures specific MF mode
  10115. */
  10116. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10117. /* get mf configuration */
  10118. val = SHMEM_RD(bp,
  10119. dev_info.shared_feature_config.config);
  10120. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  10121. switch (val) {
  10122. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  10123. validate_set_si_mode(bp);
  10124. break;
  10125. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  10126. if ((!CHIP_IS_E1x(bp)) &&
  10127. (MF_CFG_RD(bp, func_mf_config[func].
  10128. mac_upper) != 0xffff) &&
  10129. (SHMEM2_HAS(bp,
  10130. afex_driver_support))) {
  10131. bp->mf_mode = MULTI_FUNCTION_AFEX;
  10132. bp->mf_config[vn] = MF_CFG_RD(bp,
  10133. func_mf_config[func].config);
  10134. } else {
  10135. BNX2X_DEV_INFO("can not configure afex mode\n");
  10136. }
  10137. break;
  10138. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  10139. /* get OV configuration */
  10140. val = MF_CFG_RD(bp,
  10141. func_mf_config[FUNC_0].e1hov_tag);
  10142. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  10143. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10144. bp->mf_mode = MULTI_FUNCTION_SD;
  10145. bp->mf_config[vn] = MF_CFG_RD(bp,
  10146. func_mf_config[func].config);
  10147. } else
  10148. BNX2X_DEV_INFO("illegal OV for SD\n");
  10149. break;
  10150. case SHARED_FEAT_CFG_FORCE_SF_MODE_BD_MODE:
  10151. bp->mf_mode = MULTI_FUNCTION_SD;
  10152. bp->mf_sub_mode = SUB_MF_MODE_BD;
  10153. bp->mf_config[vn] =
  10154. MF_CFG_RD(bp,
  10155. func_mf_config[func].config);
  10156. if (SHMEM2_HAS(bp, mtu_size)) {
  10157. int mtu_idx = BP_FW_MB_IDX(bp);
  10158. u16 mtu_size;
  10159. u32 mtu;
  10160. mtu = SHMEM2_RD(bp, mtu_size[mtu_idx]);
  10161. mtu_size = (u16)mtu;
  10162. DP(NETIF_MSG_IFUP, "Read MTU size %04x [%08x]\n",
  10163. mtu_size, mtu);
  10164. /* if valid: update device mtu */
  10165. if ((mtu_size >= ETH_MIN_PACKET_SIZE) &&
  10166. (mtu_size <=
  10167. ETH_MAX_JUMBO_PACKET_SIZE))
  10168. bp->dev->mtu = mtu_size;
  10169. }
  10170. break;
  10171. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  10172. bp->mf_mode = MULTI_FUNCTION_SD;
  10173. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  10174. bp->mf_config[vn] =
  10175. MF_CFG_RD(bp,
  10176. func_mf_config[func].config);
  10177. break;
  10178. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  10179. bp->mf_config[vn] = 0;
  10180. break;
  10181. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  10182. val2 = SHMEM_RD(bp,
  10183. dev_info.shared_hw_config.config_3);
  10184. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  10185. switch (val2) {
  10186. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  10187. validate_set_si_mode(bp);
  10188. bp->mf_sub_mode =
  10189. SUB_MF_MODE_NPAR1_DOT_5;
  10190. break;
  10191. default:
  10192. /* Unknown configuration */
  10193. bp->mf_config[vn] = 0;
  10194. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  10195. val);
  10196. }
  10197. break;
  10198. default:
  10199. /* Unknown configuration: reset mf_config */
  10200. bp->mf_config[vn] = 0;
  10201. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  10202. }
  10203. }
  10204. BNX2X_DEV_INFO("%s function mode\n",
  10205. IS_MF(bp) ? "multi" : "single");
  10206. switch (bp->mf_mode) {
  10207. case MULTI_FUNCTION_SD:
  10208. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  10209. FUNC_MF_CFG_E1HOV_TAG_MASK;
  10210. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10211. bp->mf_ov = val;
  10212. bp->path_has_ovlan = true;
  10213. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  10214. func, bp->mf_ov, bp->mf_ov);
  10215. } else if ((bp->mf_sub_mode == SUB_MF_MODE_UFP) ||
  10216. (bp->mf_sub_mode == SUB_MF_MODE_BD)) {
  10217. dev_err(&bp->pdev->dev,
  10218. "Unexpected - no valid MF OV for func %d in UFP/BD mode\n",
  10219. func);
  10220. bp->path_has_ovlan = true;
  10221. } else {
  10222. dev_err(&bp->pdev->dev,
  10223. "No valid MF OV for func %d, aborting\n",
  10224. func);
  10225. return -EPERM;
  10226. }
  10227. break;
  10228. case MULTI_FUNCTION_AFEX:
  10229. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  10230. break;
  10231. case MULTI_FUNCTION_SI:
  10232. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  10233. func);
  10234. break;
  10235. default:
  10236. if (vn) {
  10237. dev_err(&bp->pdev->dev,
  10238. "VN %d is in a single function mode, aborting\n",
  10239. vn);
  10240. return -EPERM;
  10241. }
  10242. break;
  10243. }
  10244. /* check if other port on the path needs ovlan:
  10245. * Since MF configuration is shared between ports
  10246. * Possible mixed modes are only
  10247. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  10248. */
  10249. if (CHIP_MODE_IS_4_PORT(bp) &&
  10250. !bp->path_has_ovlan &&
  10251. !IS_MF(bp) &&
  10252. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10253. u8 other_port = !BP_PORT(bp);
  10254. u8 other_func = BP_PATH(bp) + 2*other_port;
  10255. val = MF_CFG_RD(bp,
  10256. func_mf_config[other_func].e1hov_tag);
  10257. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  10258. bp->path_has_ovlan = true;
  10259. }
  10260. }
  10261. /* adjust igu_sb_cnt to MF for E1H */
  10262. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10263. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10264. /* port info */
  10265. bnx2x_get_port_hwinfo(bp);
  10266. /* Get MAC addresses */
  10267. bnx2x_get_mac_hwinfo(bp);
  10268. bnx2x_get_cnic_info(bp);
  10269. return rc;
  10270. }
  10271. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10272. {
  10273. int cnt, i, block_end, rodi;
  10274. char vpd_start[BNX2X_VPD_LEN+1];
  10275. char str_id_reg[VENDOR_ID_LEN+1];
  10276. char str_id_cap[VENDOR_ID_LEN+1];
  10277. char *vpd_data;
  10278. char *vpd_extended_data = NULL;
  10279. u8 len;
  10280. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10281. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10282. if (cnt < BNX2X_VPD_LEN)
  10283. goto out_not_found;
  10284. /* VPD RO tag should be first tag after identifier string, hence
  10285. * we should be able to find it in first BNX2X_VPD_LEN chars
  10286. */
  10287. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10288. PCI_VPD_LRDT_RO_DATA);
  10289. if (i < 0)
  10290. goto out_not_found;
  10291. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10292. pci_vpd_lrdt_size(&vpd_start[i]);
  10293. i += PCI_VPD_LRDT_TAG_SIZE;
  10294. if (block_end > BNX2X_VPD_LEN) {
  10295. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10296. if (vpd_extended_data == NULL)
  10297. goto out_not_found;
  10298. /* read rest of vpd image into vpd_extended_data */
  10299. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10300. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10301. block_end - BNX2X_VPD_LEN,
  10302. vpd_extended_data + BNX2X_VPD_LEN);
  10303. if (cnt < (block_end - BNX2X_VPD_LEN))
  10304. goto out_not_found;
  10305. vpd_data = vpd_extended_data;
  10306. } else
  10307. vpd_data = vpd_start;
  10308. /* now vpd_data holds full vpd content in both cases */
  10309. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10310. PCI_VPD_RO_KEYWORD_MFR_ID);
  10311. if (rodi < 0)
  10312. goto out_not_found;
  10313. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10314. if (len != VENDOR_ID_LEN)
  10315. goto out_not_found;
  10316. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10317. /* vendor specific info */
  10318. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10319. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10320. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10321. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10322. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10323. PCI_VPD_RO_KEYWORD_VENDOR0);
  10324. if (rodi >= 0) {
  10325. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10326. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10327. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10328. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10329. bp->fw_ver[len] = ' ';
  10330. }
  10331. }
  10332. kfree(vpd_extended_data);
  10333. return;
  10334. }
  10335. out_not_found:
  10336. kfree(vpd_extended_data);
  10337. return;
  10338. }
  10339. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10340. {
  10341. u32 flags = 0;
  10342. if (CHIP_REV_IS_FPGA(bp))
  10343. SET_FLAGS(flags, MODE_FPGA);
  10344. else if (CHIP_REV_IS_EMUL(bp))
  10345. SET_FLAGS(flags, MODE_EMUL);
  10346. else
  10347. SET_FLAGS(flags, MODE_ASIC);
  10348. if (CHIP_MODE_IS_4_PORT(bp))
  10349. SET_FLAGS(flags, MODE_PORT4);
  10350. else
  10351. SET_FLAGS(flags, MODE_PORT2);
  10352. if (CHIP_IS_E2(bp))
  10353. SET_FLAGS(flags, MODE_E2);
  10354. else if (CHIP_IS_E3(bp)) {
  10355. SET_FLAGS(flags, MODE_E3);
  10356. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10357. SET_FLAGS(flags, MODE_E3_A0);
  10358. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10359. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10360. }
  10361. if (IS_MF(bp)) {
  10362. SET_FLAGS(flags, MODE_MF);
  10363. switch (bp->mf_mode) {
  10364. case MULTI_FUNCTION_SD:
  10365. SET_FLAGS(flags, MODE_MF_SD);
  10366. break;
  10367. case MULTI_FUNCTION_SI:
  10368. SET_FLAGS(flags, MODE_MF_SI);
  10369. break;
  10370. case MULTI_FUNCTION_AFEX:
  10371. SET_FLAGS(flags, MODE_MF_AFEX);
  10372. break;
  10373. }
  10374. } else
  10375. SET_FLAGS(flags, MODE_SF);
  10376. #if defined(__LITTLE_ENDIAN)
  10377. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10378. #else /*(__BIG_ENDIAN)*/
  10379. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10380. #endif
  10381. INIT_MODE_FLAGS(bp) = flags;
  10382. }
  10383. static int bnx2x_init_bp(struct bnx2x *bp)
  10384. {
  10385. int func;
  10386. int rc;
  10387. mutex_init(&bp->port.phy_mutex);
  10388. mutex_init(&bp->fw_mb_mutex);
  10389. mutex_init(&bp->drv_info_mutex);
  10390. sema_init(&bp->stats_lock, 1);
  10391. bp->drv_info_mng_owner = false;
  10392. INIT_LIST_HEAD(&bp->vlan_reg);
  10393. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10394. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10395. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10396. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10397. if (IS_PF(bp)) {
  10398. rc = bnx2x_get_hwinfo(bp);
  10399. if (rc)
  10400. return rc;
  10401. } else {
  10402. eth_zero_addr(bp->dev->dev_addr);
  10403. }
  10404. bnx2x_set_modes_bitmap(bp);
  10405. rc = bnx2x_alloc_mem_bp(bp);
  10406. if (rc)
  10407. return rc;
  10408. bnx2x_read_fwinfo(bp);
  10409. func = BP_FUNC(bp);
  10410. /* need to reset chip if undi was active */
  10411. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10412. /* init fw_seq */
  10413. bp->fw_seq =
  10414. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10415. DRV_MSG_SEQ_NUMBER_MASK;
  10416. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10417. rc = bnx2x_prev_unload(bp);
  10418. if (rc) {
  10419. bnx2x_free_mem_bp(bp);
  10420. return rc;
  10421. }
  10422. }
  10423. if (CHIP_REV_IS_FPGA(bp))
  10424. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10425. if (BP_NOMCP(bp) && (func == 0))
  10426. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10427. bp->disable_tpa = disable_tpa;
  10428. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10429. /* Reduce memory usage in kdump environment by disabling TPA */
  10430. bp->disable_tpa |= is_kdump_kernel();
  10431. /* Set TPA flags */
  10432. if (bp->disable_tpa) {
  10433. bp->dev->hw_features &= ~NETIF_F_LRO;
  10434. bp->dev->features &= ~NETIF_F_LRO;
  10435. }
  10436. if (CHIP_IS_E1(bp))
  10437. bp->dropless_fc = 0;
  10438. else
  10439. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10440. bp->mrrs = mrrs;
  10441. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10442. if (IS_VF(bp))
  10443. bp->rx_ring_size = MAX_RX_AVAIL;
  10444. /* make sure that the numbers are in the right granularity */
  10445. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10446. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10447. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10448. timer_setup(&bp->timer, bnx2x_timer, 0);
  10449. bp->timer.expires = jiffies + bp->current_interval;
  10450. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10451. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10452. SHMEM2_HAS(bp, dcbx_en) &&
  10453. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10454. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset) &&
  10455. SHMEM2_RD(bp, dcbx_en[BP_PORT(bp)])) {
  10456. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10457. bnx2x_dcbx_init_params(bp);
  10458. } else {
  10459. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10460. }
  10461. if (CHIP_IS_E1x(bp))
  10462. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10463. else
  10464. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10465. /* multiple tx priority */
  10466. if (IS_VF(bp))
  10467. bp->max_cos = 1;
  10468. else if (CHIP_IS_E1x(bp))
  10469. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10470. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10471. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10472. else if (CHIP_IS_E3B0(bp))
  10473. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10474. else
  10475. BNX2X_ERR("unknown chip %x revision %x\n",
  10476. CHIP_NUM(bp), CHIP_REV(bp));
  10477. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10478. /* We need at least one default status block for slow-path events,
  10479. * second status block for the L2 queue, and a third status block for
  10480. * CNIC if supported.
  10481. */
  10482. if (IS_VF(bp))
  10483. bp->min_msix_vec_cnt = 1;
  10484. else if (CNIC_SUPPORT(bp))
  10485. bp->min_msix_vec_cnt = 3;
  10486. else /* PF w/o cnic */
  10487. bp->min_msix_vec_cnt = 2;
  10488. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10489. bp->dump_preset_idx = 1;
  10490. if (CHIP_IS_E3B0(bp))
  10491. bp->flags |= PTP_SUPPORTED;
  10492. return rc;
  10493. }
  10494. /****************************************************************************
  10495. * General service functions
  10496. ****************************************************************************/
  10497. /*
  10498. * net_device service functions
  10499. */
  10500. /* called with rtnl_lock */
  10501. static int bnx2x_open(struct net_device *dev)
  10502. {
  10503. struct bnx2x *bp = netdev_priv(dev);
  10504. int rc;
  10505. bp->stats_init = true;
  10506. netif_carrier_off(dev);
  10507. bnx2x_set_power_state(bp, PCI_D0);
  10508. /* If parity had happen during the unload, then attentions
  10509. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10510. * want the first function loaded on the current engine to
  10511. * complete the recovery.
  10512. * Parity recovery is only relevant for PF driver.
  10513. */
  10514. if (IS_PF(bp)) {
  10515. int other_engine = BP_PATH(bp) ? 0 : 1;
  10516. bool other_load_status, load_status;
  10517. bool global = false;
  10518. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10519. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10520. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10521. bnx2x_chk_parity_attn(bp, &global, true)) {
  10522. do {
  10523. /* If there are attentions and they are in a
  10524. * global blocks, set the GLOBAL_RESET bit
  10525. * regardless whether it will be this function
  10526. * that will complete the recovery or not.
  10527. */
  10528. if (global)
  10529. bnx2x_set_reset_global(bp);
  10530. /* Only the first function on the current
  10531. * engine should try to recover in open. In case
  10532. * of attentions in global blocks only the first
  10533. * in the chip should try to recover.
  10534. */
  10535. if ((!load_status &&
  10536. (!global || !other_load_status)) &&
  10537. bnx2x_trylock_leader_lock(bp) &&
  10538. !bnx2x_leader_reset(bp)) {
  10539. netdev_info(bp->dev,
  10540. "Recovered in open\n");
  10541. break;
  10542. }
  10543. /* recovery has failed... */
  10544. bnx2x_set_power_state(bp, PCI_D3hot);
  10545. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10546. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10547. "If you still see this message after a few retries then power cycle is required.\n");
  10548. return -EAGAIN;
  10549. } while (0);
  10550. }
  10551. }
  10552. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10553. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10554. if (rc)
  10555. return rc;
  10556. if (IS_PF(bp))
  10557. udp_tunnel_get_rx_info(dev);
  10558. return 0;
  10559. }
  10560. /* called with rtnl_lock */
  10561. static int bnx2x_close(struct net_device *dev)
  10562. {
  10563. struct bnx2x *bp = netdev_priv(dev);
  10564. /* Unload the driver, release IRQs */
  10565. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10566. return 0;
  10567. }
  10568. struct bnx2x_mcast_list_elem_group
  10569. {
  10570. struct list_head mcast_group_link;
  10571. struct bnx2x_mcast_list_elem mcast_elems[];
  10572. };
  10573. #define MCAST_ELEMS_PER_PG \
  10574. ((PAGE_SIZE - sizeof(struct bnx2x_mcast_list_elem_group)) / \
  10575. sizeof(struct bnx2x_mcast_list_elem))
  10576. static void bnx2x_free_mcast_macs_list(struct list_head *mcast_group_list)
  10577. {
  10578. struct bnx2x_mcast_list_elem_group *current_mcast_group;
  10579. while (!list_empty(mcast_group_list)) {
  10580. current_mcast_group = list_first_entry(mcast_group_list,
  10581. struct bnx2x_mcast_list_elem_group,
  10582. mcast_group_link);
  10583. list_del(&current_mcast_group->mcast_group_link);
  10584. free_page((unsigned long)current_mcast_group);
  10585. }
  10586. }
  10587. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10588. struct bnx2x_mcast_ramrod_params *p,
  10589. struct list_head *mcast_group_list)
  10590. {
  10591. struct bnx2x_mcast_list_elem *mc_mac;
  10592. struct netdev_hw_addr *ha;
  10593. struct bnx2x_mcast_list_elem_group *current_mcast_group = NULL;
  10594. int mc_count = netdev_mc_count(bp->dev);
  10595. int offset = 0;
  10596. INIT_LIST_HEAD(&p->mcast_list);
  10597. netdev_for_each_mc_addr(ha, bp->dev) {
  10598. if (!offset) {
  10599. current_mcast_group =
  10600. (struct bnx2x_mcast_list_elem_group *)
  10601. __get_free_page(GFP_ATOMIC);
  10602. if (!current_mcast_group) {
  10603. bnx2x_free_mcast_macs_list(mcast_group_list);
  10604. BNX2X_ERR("Failed to allocate mc MAC list\n");
  10605. return -ENOMEM;
  10606. }
  10607. list_add(&current_mcast_group->mcast_group_link,
  10608. mcast_group_list);
  10609. }
  10610. mc_mac = &current_mcast_group->mcast_elems[offset];
  10611. mc_mac->mac = bnx2x_mc_addr(ha);
  10612. list_add_tail(&mc_mac->link, &p->mcast_list);
  10613. offset++;
  10614. if (offset == MCAST_ELEMS_PER_PG)
  10615. offset = 0;
  10616. }
  10617. p->mcast_list_len = mc_count;
  10618. return 0;
  10619. }
  10620. /**
  10621. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10622. *
  10623. * @bp: driver handle
  10624. *
  10625. * We will use zero (0) as a MAC type for these MACs.
  10626. */
  10627. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10628. {
  10629. int rc;
  10630. struct net_device *dev = bp->dev;
  10631. struct netdev_hw_addr *ha;
  10632. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10633. unsigned long ramrod_flags = 0;
  10634. /* First schedule a cleanup up of old configuration */
  10635. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10636. if (rc < 0) {
  10637. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10638. return rc;
  10639. }
  10640. netdev_for_each_uc_addr(ha, dev) {
  10641. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10642. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10643. if (rc == -EEXIST) {
  10644. DP(BNX2X_MSG_SP,
  10645. "Failed to schedule ADD operations: %d\n", rc);
  10646. /* do not treat adding same MAC as error */
  10647. rc = 0;
  10648. } else if (rc < 0) {
  10649. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10650. rc);
  10651. return rc;
  10652. }
  10653. }
  10654. /* Execute the pending commands */
  10655. __set_bit(RAMROD_CONT, &ramrod_flags);
  10656. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10657. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10658. }
  10659. static int bnx2x_set_mc_list_e1x(struct bnx2x *bp)
  10660. {
  10661. LIST_HEAD(mcast_group_list);
  10662. struct net_device *dev = bp->dev;
  10663. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10664. int rc = 0;
  10665. rparam.mcast_obj = &bp->mcast_obj;
  10666. /* first, clear all configured multicast MACs */
  10667. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10668. if (rc < 0) {
  10669. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10670. return rc;
  10671. }
  10672. /* then, configure a new MACs list */
  10673. if (netdev_mc_count(dev)) {
  10674. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10675. if (rc)
  10676. return rc;
  10677. /* Now add the new MACs */
  10678. rc = bnx2x_config_mcast(bp, &rparam,
  10679. BNX2X_MCAST_CMD_ADD);
  10680. if (rc < 0)
  10681. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10682. rc);
  10683. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10684. }
  10685. return rc;
  10686. }
  10687. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10688. {
  10689. LIST_HEAD(mcast_group_list);
  10690. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10691. struct net_device *dev = bp->dev;
  10692. int rc = 0;
  10693. /* On older adapters, we need to flush and re-add filters */
  10694. if (CHIP_IS_E1x(bp))
  10695. return bnx2x_set_mc_list_e1x(bp);
  10696. rparam.mcast_obj = &bp->mcast_obj;
  10697. if (netdev_mc_count(dev)) {
  10698. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10699. if (rc)
  10700. return rc;
  10701. /* Override the curently configured set of mc filters */
  10702. rc = bnx2x_config_mcast(bp, &rparam,
  10703. BNX2X_MCAST_CMD_SET);
  10704. if (rc < 0)
  10705. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10706. rc);
  10707. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10708. } else {
  10709. /* If no mc addresses are required, flush the configuration */
  10710. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10711. if (rc < 0)
  10712. BNX2X_ERR("Failed to clear multicast configuration %d\n",
  10713. rc);
  10714. }
  10715. return rc;
  10716. }
  10717. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10718. static void bnx2x_set_rx_mode(struct net_device *dev)
  10719. {
  10720. struct bnx2x *bp = netdev_priv(dev);
  10721. if (bp->state != BNX2X_STATE_OPEN) {
  10722. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10723. return;
  10724. } else {
  10725. /* Schedule an SP task to handle rest of change */
  10726. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10727. NETIF_MSG_IFUP);
  10728. }
  10729. }
  10730. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10731. {
  10732. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10733. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10734. netif_addr_lock_bh(bp->dev);
  10735. if (bp->dev->flags & IFF_PROMISC) {
  10736. rx_mode = BNX2X_RX_MODE_PROMISC;
  10737. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10738. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10739. CHIP_IS_E1(bp))) {
  10740. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10741. } else {
  10742. if (IS_PF(bp)) {
  10743. /* some multicasts */
  10744. if (bnx2x_set_mc_list(bp) < 0)
  10745. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10746. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10747. netif_addr_unlock_bh(bp->dev);
  10748. if (bnx2x_set_uc_list(bp) < 0)
  10749. rx_mode = BNX2X_RX_MODE_PROMISC;
  10750. netif_addr_lock_bh(bp->dev);
  10751. } else {
  10752. /* configuring mcast to a vf involves sleeping (when we
  10753. * wait for the pf's response).
  10754. */
  10755. bnx2x_schedule_sp_rtnl(bp,
  10756. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10757. }
  10758. }
  10759. bp->rx_mode = rx_mode;
  10760. /* handle ISCSI SD mode */
  10761. if (IS_MF_ISCSI_ONLY(bp))
  10762. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10763. /* Schedule the rx_mode command */
  10764. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10765. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10766. netif_addr_unlock_bh(bp->dev);
  10767. return;
  10768. }
  10769. if (IS_PF(bp)) {
  10770. bnx2x_set_storm_rx_mode(bp);
  10771. netif_addr_unlock_bh(bp->dev);
  10772. } else {
  10773. /* VF will need to request the PF to make this change, and so
  10774. * the VF needs to release the bottom-half lock prior to the
  10775. * request (as it will likely require sleep on the VF side)
  10776. */
  10777. netif_addr_unlock_bh(bp->dev);
  10778. bnx2x_vfpf_storm_rx_mode(bp);
  10779. }
  10780. }
  10781. /* called with rtnl_lock */
  10782. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10783. int devad, u16 addr)
  10784. {
  10785. struct bnx2x *bp = netdev_priv(netdev);
  10786. u16 value;
  10787. int rc;
  10788. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10789. prtad, devad, addr);
  10790. /* The HW expects different devad if CL22 is used */
  10791. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10792. bnx2x_acquire_phy_lock(bp);
  10793. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10794. bnx2x_release_phy_lock(bp);
  10795. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10796. if (!rc)
  10797. rc = value;
  10798. return rc;
  10799. }
  10800. /* called with rtnl_lock */
  10801. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10802. u16 addr, u16 value)
  10803. {
  10804. struct bnx2x *bp = netdev_priv(netdev);
  10805. int rc;
  10806. DP(NETIF_MSG_LINK,
  10807. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10808. prtad, devad, addr, value);
  10809. /* The HW expects different devad if CL22 is used */
  10810. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10811. bnx2x_acquire_phy_lock(bp);
  10812. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10813. bnx2x_release_phy_lock(bp);
  10814. return rc;
  10815. }
  10816. /* called with rtnl_lock */
  10817. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10818. {
  10819. struct bnx2x *bp = netdev_priv(dev);
  10820. struct mii_ioctl_data *mdio = if_mii(ifr);
  10821. if (!netif_running(dev))
  10822. return -EAGAIN;
  10823. switch (cmd) {
  10824. case SIOCSHWTSTAMP:
  10825. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10826. default:
  10827. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10828. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10829. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10830. }
  10831. }
  10832. #ifdef CONFIG_NET_POLL_CONTROLLER
  10833. static void poll_bnx2x(struct net_device *dev)
  10834. {
  10835. struct bnx2x *bp = netdev_priv(dev);
  10836. int i;
  10837. for_each_eth_queue(bp, i) {
  10838. struct bnx2x_fastpath *fp = &bp->fp[i];
  10839. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10840. }
  10841. }
  10842. #endif
  10843. static int bnx2x_validate_addr(struct net_device *dev)
  10844. {
  10845. struct bnx2x *bp = netdev_priv(dev);
  10846. /* query the bulletin board for mac address configured by the PF */
  10847. if (IS_VF(bp))
  10848. bnx2x_sample_bulletin(bp);
  10849. if (!is_valid_ether_addr(dev->dev_addr)) {
  10850. BNX2X_ERR("Non-valid Ethernet address\n");
  10851. return -EADDRNOTAVAIL;
  10852. }
  10853. return 0;
  10854. }
  10855. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10856. struct netdev_phys_item_id *ppid)
  10857. {
  10858. struct bnx2x *bp = netdev_priv(netdev);
  10859. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10860. return -EOPNOTSUPP;
  10861. ppid->id_len = sizeof(bp->phys_port_id);
  10862. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10863. return 0;
  10864. }
  10865. static netdev_features_t bnx2x_features_check(struct sk_buff *skb,
  10866. struct net_device *dev,
  10867. netdev_features_t features)
  10868. {
  10869. features = vlan_features_check(skb, features);
  10870. return vxlan_features_check(skb, features);
  10871. }
  10872. static int __bnx2x_vlan_configure_vid(struct bnx2x *bp, u16 vid, bool add)
  10873. {
  10874. int rc;
  10875. if (IS_PF(bp)) {
  10876. unsigned long ramrod_flags = 0;
  10877. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10878. rc = bnx2x_set_vlan_one(bp, vid, &bp->sp_objs->vlan_obj,
  10879. add, &ramrod_flags);
  10880. } else {
  10881. rc = bnx2x_vfpf_update_vlan(bp, vid, bp->fp->index, add);
  10882. }
  10883. return rc;
  10884. }
  10885. static int bnx2x_vlan_configure_vid_list(struct bnx2x *bp)
  10886. {
  10887. struct bnx2x_vlan_entry *vlan;
  10888. int rc = 0;
  10889. /* Configure all non-configured entries */
  10890. list_for_each_entry(vlan, &bp->vlan_reg, link) {
  10891. if (vlan->hw)
  10892. continue;
  10893. if (bp->vlan_cnt >= bp->vlan_credit)
  10894. return -ENOBUFS;
  10895. rc = __bnx2x_vlan_configure_vid(bp, vlan->vid, true);
  10896. if (rc) {
  10897. BNX2X_ERR("Unable to config VLAN %d\n", vlan->vid);
  10898. return rc;
  10899. }
  10900. DP(NETIF_MSG_IFUP, "HW configured for VLAN %d\n", vlan->vid);
  10901. vlan->hw = true;
  10902. bp->vlan_cnt++;
  10903. }
  10904. return 0;
  10905. }
  10906. static void bnx2x_vlan_configure(struct bnx2x *bp, bool set_rx_mode)
  10907. {
  10908. bool need_accept_any_vlan;
  10909. need_accept_any_vlan = !!bnx2x_vlan_configure_vid_list(bp);
  10910. if (bp->accept_any_vlan != need_accept_any_vlan) {
  10911. bp->accept_any_vlan = need_accept_any_vlan;
  10912. DP(NETIF_MSG_IFUP, "Accept all VLAN %s\n",
  10913. bp->accept_any_vlan ? "raised" : "cleared");
  10914. if (set_rx_mode) {
  10915. if (IS_PF(bp))
  10916. bnx2x_set_rx_mode_inner(bp);
  10917. else
  10918. bnx2x_vfpf_storm_rx_mode(bp);
  10919. }
  10920. }
  10921. }
  10922. int bnx2x_vlan_reconfigure_vid(struct bnx2x *bp)
  10923. {
  10924. struct bnx2x_vlan_entry *vlan;
  10925. /* The hw forgot all entries after reload */
  10926. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10927. vlan->hw = false;
  10928. bp->vlan_cnt = 0;
  10929. /* Don't set rx mode here. Our caller will do it. */
  10930. bnx2x_vlan_configure(bp, false);
  10931. return 0;
  10932. }
  10933. static int bnx2x_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
  10934. {
  10935. struct bnx2x *bp = netdev_priv(dev);
  10936. struct bnx2x_vlan_entry *vlan;
  10937. DP(NETIF_MSG_IFUP, "Adding VLAN %d\n", vid);
  10938. vlan = kmalloc(sizeof(*vlan), GFP_KERNEL);
  10939. if (!vlan)
  10940. return -ENOMEM;
  10941. vlan->vid = vid;
  10942. vlan->hw = false;
  10943. list_add_tail(&vlan->link, &bp->vlan_reg);
  10944. if (netif_running(dev))
  10945. bnx2x_vlan_configure(bp, true);
  10946. return 0;
  10947. }
  10948. static int bnx2x_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
  10949. {
  10950. struct bnx2x *bp = netdev_priv(dev);
  10951. struct bnx2x_vlan_entry *vlan;
  10952. bool found = false;
  10953. int rc = 0;
  10954. DP(NETIF_MSG_IFUP, "Removing VLAN %d\n", vid);
  10955. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10956. if (vlan->vid == vid) {
  10957. found = true;
  10958. break;
  10959. }
  10960. if (!found) {
  10961. BNX2X_ERR("Unable to kill VLAN %d - not found\n", vid);
  10962. return -EINVAL;
  10963. }
  10964. if (netif_running(dev) && vlan->hw) {
  10965. rc = __bnx2x_vlan_configure_vid(bp, vid, false);
  10966. DP(NETIF_MSG_IFUP, "HW deconfigured for VLAN %d\n", vid);
  10967. bp->vlan_cnt--;
  10968. }
  10969. list_del(&vlan->link);
  10970. kfree(vlan);
  10971. if (netif_running(dev))
  10972. bnx2x_vlan_configure(bp, true);
  10973. DP(NETIF_MSG_IFUP, "Removing VLAN result %d\n", rc);
  10974. return rc;
  10975. }
  10976. static const struct net_device_ops bnx2x_netdev_ops = {
  10977. .ndo_open = bnx2x_open,
  10978. .ndo_stop = bnx2x_close,
  10979. .ndo_start_xmit = bnx2x_start_xmit,
  10980. .ndo_select_queue = bnx2x_select_queue,
  10981. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10982. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10983. .ndo_validate_addr = bnx2x_validate_addr,
  10984. .ndo_do_ioctl = bnx2x_ioctl,
  10985. .ndo_change_mtu = bnx2x_change_mtu,
  10986. .ndo_fix_features = bnx2x_fix_features,
  10987. .ndo_set_features = bnx2x_set_features,
  10988. .ndo_tx_timeout = bnx2x_tx_timeout,
  10989. .ndo_vlan_rx_add_vid = bnx2x_vlan_rx_add_vid,
  10990. .ndo_vlan_rx_kill_vid = bnx2x_vlan_rx_kill_vid,
  10991. #ifdef CONFIG_NET_POLL_CONTROLLER
  10992. .ndo_poll_controller = poll_bnx2x,
  10993. #endif
  10994. .ndo_setup_tc = __bnx2x_setup_tc,
  10995. #ifdef CONFIG_BNX2X_SRIOV
  10996. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10997. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10998. .ndo_get_vf_config = bnx2x_get_vf_config,
  10999. #endif
  11000. #ifdef NETDEV_FCOE_WWNN
  11001. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  11002. #endif
  11003. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  11004. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  11005. .ndo_features_check = bnx2x_features_check,
  11006. .ndo_udp_tunnel_add = bnx2x_udp_tunnel_add,
  11007. .ndo_udp_tunnel_del = bnx2x_udp_tunnel_del,
  11008. };
  11009. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  11010. {
  11011. struct device *dev = &bp->pdev->dev;
  11012. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  11013. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  11014. dev_err(dev, "System does not support DMA, aborting\n");
  11015. return -EIO;
  11016. }
  11017. return 0;
  11018. }
  11019. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  11020. {
  11021. if (bp->flags & AER_ENABLED) {
  11022. pci_disable_pcie_error_reporting(bp->pdev);
  11023. bp->flags &= ~AER_ENABLED;
  11024. }
  11025. }
  11026. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  11027. struct net_device *dev, unsigned long board_type)
  11028. {
  11029. int rc;
  11030. u32 pci_cfg_dword;
  11031. bool chip_is_e1x = (board_type == BCM57710 ||
  11032. board_type == BCM57711 ||
  11033. board_type == BCM57711E);
  11034. SET_NETDEV_DEV(dev, &pdev->dev);
  11035. bp->dev = dev;
  11036. bp->pdev = pdev;
  11037. rc = pci_enable_device(pdev);
  11038. if (rc) {
  11039. dev_err(&bp->pdev->dev,
  11040. "Cannot enable PCI device, aborting\n");
  11041. goto err_out;
  11042. }
  11043. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  11044. dev_err(&bp->pdev->dev,
  11045. "Cannot find PCI device base address, aborting\n");
  11046. rc = -ENODEV;
  11047. goto err_out_disable;
  11048. }
  11049. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  11050. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  11051. rc = -ENODEV;
  11052. goto err_out_disable;
  11053. }
  11054. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  11055. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  11056. PCICFG_REVESION_ID_ERROR_VAL) {
  11057. pr_err("PCI device error, probably due to fan failure, aborting\n");
  11058. rc = -ENODEV;
  11059. goto err_out_disable;
  11060. }
  11061. if (atomic_read(&pdev->enable_cnt) == 1) {
  11062. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  11063. if (rc) {
  11064. dev_err(&bp->pdev->dev,
  11065. "Cannot obtain PCI resources, aborting\n");
  11066. goto err_out_disable;
  11067. }
  11068. pci_set_master(pdev);
  11069. pci_save_state(pdev);
  11070. }
  11071. if (IS_PF(bp)) {
  11072. if (!pdev->pm_cap) {
  11073. dev_err(&bp->pdev->dev,
  11074. "Cannot find power management capability, aborting\n");
  11075. rc = -EIO;
  11076. goto err_out_release;
  11077. }
  11078. }
  11079. if (!pci_is_pcie(pdev)) {
  11080. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  11081. rc = -EIO;
  11082. goto err_out_release;
  11083. }
  11084. rc = bnx2x_set_coherency_mask(bp);
  11085. if (rc)
  11086. goto err_out_release;
  11087. dev->mem_start = pci_resource_start(pdev, 0);
  11088. dev->base_addr = dev->mem_start;
  11089. dev->mem_end = pci_resource_end(pdev, 0);
  11090. dev->irq = pdev->irq;
  11091. bp->regview = pci_ioremap_bar(pdev, 0);
  11092. if (!bp->regview) {
  11093. dev_err(&bp->pdev->dev,
  11094. "Cannot map register space, aborting\n");
  11095. rc = -ENOMEM;
  11096. goto err_out_release;
  11097. }
  11098. /* In E1/E1H use pci device function given by kernel.
  11099. * In E2/E3 read physical function from ME register since these chips
  11100. * support Physical Device Assignment where kernel BDF maybe arbitrary
  11101. * (depending on hypervisor).
  11102. */
  11103. if (chip_is_e1x) {
  11104. bp->pf_num = PCI_FUNC(pdev->devfn);
  11105. } else {
  11106. /* chip is E2/3*/
  11107. pci_read_config_dword(bp->pdev,
  11108. PCICFG_ME_REGISTER, &pci_cfg_dword);
  11109. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  11110. ME_REG_ABS_PF_NUM_SHIFT);
  11111. }
  11112. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  11113. /* clean indirect addresses */
  11114. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  11115. PCICFG_VENDOR_ID_OFFSET);
  11116. /* Set PCIe reset type to fundamental for EEH recovery */
  11117. pdev->needs_freset = 1;
  11118. /* AER (Advanced Error reporting) configuration */
  11119. rc = pci_enable_pcie_error_reporting(pdev);
  11120. if (!rc)
  11121. bp->flags |= AER_ENABLED;
  11122. else
  11123. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  11124. /*
  11125. * Clean the following indirect addresses for all functions since it
  11126. * is not used by the driver.
  11127. */
  11128. if (IS_PF(bp)) {
  11129. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  11130. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  11131. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  11132. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  11133. if (chip_is_e1x) {
  11134. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  11135. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  11136. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  11137. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  11138. }
  11139. /* Enable internal target-read (in case we are probed after PF
  11140. * FLR). Must be done prior to any BAR read access. Only for
  11141. * 57712 and up
  11142. */
  11143. if (!chip_is_e1x)
  11144. REG_WR(bp,
  11145. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  11146. }
  11147. dev->watchdog_timeo = TX_TIMEOUT;
  11148. dev->netdev_ops = &bnx2x_netdev_ops;
  11149. bnx2x_set_ethtool_ops(bp, dev);
  11150. dev->priv_flags |= IFF_UNICAST_FLT;
  11151. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11152. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11153. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  11154. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  11155. if (!chip_is_e1x) {
  11156. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11157. NETIF_F_GSO_IPXIP4 |
  11158. NETIF_F_GSO_UDP_TUNNEL |
  11159. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11160. NETIF_F_GSO_PARTIAL;
  11161. dev->hw_enc_features =
  11162. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  11163. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11164. NETIF_F_GSO_IPXIP4 |
  11165. NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11166. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11167. NETIF_F_GSO_PARTIAL;
  11168. dev->gso_partial_features = NETIF_F_GSO_GRE_CSUM |
  11169. NETIF_F_GSO_UDP_TUNNEL_CSUM;
  11170. }
  11171. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11172. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  11173. if (IS_PF(bp)) {
  11174. if (chip_is_e1x)
  11175. bp->accept_any_vlan = true;
  11176. else
  11177. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11178. }
  11179. /* For VF we'll know whether to enable VLAN filtering after
  11180. * getting a response to CHANNEL_TLV_ACQUIRE from PF.
  11181. */
  11182. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  11183. dev->features |= NETIF_F_HIGHDMA;
  11184. /* Add Loopback capability to the device */
  11185. dev->hw_features |= NETIF_F_LOOPBACK;
  11186. #ifdef BCM_DCBNL
  11187. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  11188. #endif
  11189. /* MTU range, 46 - 9600 */
  11190. dev->min_mtu = ETH_MIN_PACKET_SIZE;
  11191. dev->max_mtu = ETH_MAX_JUMBO_PACKET_SIZE;
  11192. /* get_port_hwinfo() will set prtad and mmds properly */
  11193. bp->mdio.prtad = MDIO_PRTAD_NONE;
  11194. bp->mdio.mmds = 0;
  11195. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  11196. bp->mdio.dev = dev;
  11197. bp->mdio.mdio_read = bnx2x_mdio_read;
  11198. bp->mdio.mdio_write = bnx2x_mdio_write;
  11199. return 0;
  11200. err_out_release:
  11201. if (atomic_read(&pdev->enable_cnt) == 1)
  11202. pci_release_regions(pdev);
  11203. err_out_disable:
  11204. pci_disable_device(pdev);
  11205. err_out:
  11206. return rc;
  11207. }
  11208. static int bnx2x_check_firmware(struct bnx2x *bp)
  11209. {
  11210. const struct firmware *firmware = bp->firmware;
  11211. struct bnx2x_fw_file_hdr *fw_hdr;
  11212. struct bnx2x_fw_file_section *sections;
  11213. u32 offset, len, num_ops;
  11214. __be16 *ops_offsets;
  11215. int i;
  11216. const u8 *fw_ver;
  11217. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  11218. BNX2X_ERR("Wrong FW size\n");
  11219. return -EINVAL;
  11220. }
  11221. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  11222. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  11223. /* Make sure none of the offsets and sizes make us read beyond
  11224. * the end of the firmware data */
  11225. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  11226. offset = be32_to_cpu(sections[i].offset);
  11227. len = be32_to_cpu(sections[i].len);
  11228. if (offset + len > firmware->size) {
  11229. BNX2X_ERR("Section %d length is out of bounds\n", i);
  11230. return -EINVAL;
  11231. }
  11232. }
  11233. /* Likewise for the init_ops offsets */
  11234. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  11235. ops_offsets = (__force __be16 *)(firmware->data + offset);
  11236. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  11237. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  11238. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  11239. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  11240. return -EINVAL;
  11241. }
  11242. }
  11243. /* Check FW version */
  11244. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  11245. fw_ver = firmware->data + offset;
  11246. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  11247. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  11248. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  11249. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  11250. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  11251. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  11252. BCM_5710_FW_MAJOR_VERSION,
  11253. BCM_5710_FW_MINOR_VERSION,
  11254. BCM_5710_FW_REVISION_VERSION,
  11255. BCM_5710_FW_ENGINEERING_VERSION);
  11256. return -EINVAL;
  11257. }
  11258. return 0;
  11259. }
  11260. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11261. {
  11262. const __be32 *source = (const __be32 *)_source;
  11263. u32 *target = (u32 *)_target;
  11264. u32 i;
  11265. for (i = 0; i < n/4; i++)
  11266. target[i] = be32_to_cpu(source[i]);
  11267. }
  11268. /*
  11269. Ops array is stored in the following format:
  11270. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  11271. */
  11272. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  11273. {
  11274. const __be32 *source = (const __be32 *)_source;
  11275. struct raw_op *target = (struct raw_op *)_target;
  11276. u32 i, j, tmp;
  11277. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  11278. tmp = be32_to_cpu(source[j]);
  11279. target[i].op = (tmp >> 24) & 0xff;
  11280. target[i].offset = tmp & 0xffffff;
  11281. target[i].raw_data = be32_to_cpu(source[j + 1]);
  11282. }
  11283. }
  11284. /* IRO array is stored in the following format:
  11285. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  11286. */
  11287. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  11288. {
  11289. const __be32 *source = (const __be32 *)_source;
  11290. struct iro *target = (struct iro *)_target;
  11291. u32 i, j, tmp;
  11292. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  11293. target[i].base = be32_to_cpu(source[j]);
  11294. j++;
  11295. tmp = be32_to_cpu(source[j]);
  11296. target[i].m1 = (tmp >> 16) & 0xffff;
  11297. target[i].m2 = tmp & 0xffff;
  11298. j++;
  11299. tmp = be32_to_cpu(source[j]);
  11300. target[i].m3 = (tmp >> 16) & 0xffff;
  11301. target[i].size = tmp & 0xffff;
  11302. j++;
  11303. }
  11304. }
  11305. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11306. {
  11307. const __be16 *source = (const __be16 *)_source;
  11308. u16 *target = (u16 *)_target;
  11309. u32 i;
  11310. for (i = 0; i < n/2; i++)
  11311. target[i] = be16_to_cpu(source[i]);
  11312. }
  11313. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  11314. do { \
  11315. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  11316. bp->arr = kmalloc(len, GFP_KERNEL); \
  11317. if (!bp->arr) \
  11318. goto lbl; \
  11319. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  11320. (u8 *)bp->arr, len); \
  11321. } while (0)
  11322. static int bnx2x_init_firmware(struct bnx2x *bp)
  11323. {
  11324. const char *fw_file_name;
  11325. struct bnx2x_fw_file_hdr *fw_hdr;
  11326. int rc;
  11327. if (bp->firmware)
  11328. return 0;
  11329. if (CHIP_IS_E1(bp))
  11330. fw_file_name = FW_FILE_NAME_E1;
  11331. else if (CHIP_IS_E1H(bp))
  11332. fw_file_name = FW_FILE_NAME_E1H;
  11333. else if (!CHIP_IS_E1x(bp))
  11334. fw_file_name = FW_FILE_NAME_E2;
  11335. else {
  11336. BNX2X_ERR("Unsupported chip revision\n");
  11337. return -EINVAL;
  11338. }
  11339. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  11340. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  11341. if (rc) {
  11342. BNX2X_ERR("Can't load firmware file %s\n",
  11343. fw_file_name);
  11344. goto request_firmware_exit;
  11345. }
  11346. rc = bnx2x_check_firmware(bp);
  11347. if (rc) {
  11348. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  11349. goto request_firmware_exit;
  11350. }
  11351. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  11352. /* Initialize the pointers to the init arrays */
  11353. /* Blob */
  11354. rc = -ENOMEM;
  11355. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  11356. /* Opcodes */
  11357. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  11358. /* Offsets */
  11359. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  11360. be16_to_cpu_n);
  11361. /* STORMs firmware */
  11362. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11363. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  11364. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  11365. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  11366. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11367. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  11368. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  11369. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  11370. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11371. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  11372. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  11373. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  11374. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11375. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  11376. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  11377. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  11378. /* IRO */
  11379. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  11380. return 0;
  11381. iro_alloc_err:
  11382. kfree(bp->init_ops_offsets);
  11383. init_offsets_alloc_err:
  11384. kfree(bp->init_ops);
  11385. init_ops_alloc_err:
  11386. kfree(bp->init_data);
  11387. request_firmware_exit:
  11388. release_firmware(bp->firmware);
  11389. bp->firmware = NULL;
  11390. return rc;
  11391. }
  11392. static void bnx2x_release_firmware(struct bnx2x *bp)
  11393. {
  11394. kfree(bp->init_ops_offsets);
  11395. kfree(bp->init_ops);
  11396. kfree(bp->init_data);
  11397. release_firmware(bp->firmware);
  11398. bp->firmware = NULL;
  11399. }
  11400. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  11401. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  11402. .init_hw_cmn = bnx2x_init_hw_common,
  11403. .init_hw_port = bnx2x_init_hw_port,
  11404. .init_hw_func = bnx2x_init_hw_func,
  11405. .reset_hw_cmn = bnx2x_reset_common,
  11406. .reset_hw_port = bnx2x_reset_port,
  11407. .reset_hw_func = bnx2x_reset_func,
  11408. .gunzip_init = bnx2x_gunzip_init,
  11409. .gunzip_end = bnx2x_gunzip_end,
  11410. .init_fw = bnx2x_init_firmware,
  11411. .release_fw = bnx2x_release_firmware,
  11412. };
  11413. void bnx2x__init_func_obj(struct bnx2x *bp)
  11414. {
  11415. /* Prepare DMAE related driver resources */
  11416. bnx2x_setup_dmae(bp);
  11417. bnx2x_init_func_obj(bp, &bp->func_obj,
  11418. bnx2x_sp(bp, func_rdata),
  11419. bnx2x_sp_mapping(bp, func_rdata),
  11420. bnx2x_sp(bp, func_afex_rdata),
  11421. bnx2x_sp_mapping(bp, func_afex_rdata),
  11422. &bnx2x_func_sp_drv);
  11423. }
  11424. /* must be called after sriov-enable */
  11425. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  11426. {
  11427. int cid_count = BNX2X_L2_MAX_CID(bp);
  11428. if (IS_SRIOV(bp))
  11429. cid_count += BNX2X_VF_CIDS;
  11430. if (CNIC_SUPPORT(bp))
  11431. cid_count += CNIC_CID_MAX;
  11432. return roundup(cid_count, QM_CID_ROUND);
  11433. }
  11434. /**
  11435. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  11436. *
  11437. * @dev: pci device
  11438. *
  11439. */
  11440. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  11441. {
  11442. int index;
  11443. u16 control = 0;
  11444. /*
  11445. * If MSI-X is not supported - return number of SBs needed to support
  11446. * one fast path queue: one FP queue + SB for CNIC
  11447. */
  11448. if (!pdev->msix_cap) {
  11449. dev_info(&pdev->dev, "no msix capability found\n");
  11450. return 1 + cnic_cnt;
  11451. }
  11452. dev_info(&pdev->dev, "msix capability found\n");
  11453. /*
  11454. * The value in the PCI configuration space is the index of the last
  11455. * entry, namely one less than the actual size of the table, which is
  11456. * exactly what we want to return from this function: number of all SBs
  11457. * without the default SB.
  11458. * For VFs there is no default SB, then we return (index+1).
  11459. */
  11460. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11461. index = control & PCI_MSIX_FLAGS_QSIZE;
  11462. return index;
  11463. }
  11464. static int set_max_cos_est(int chip_id)
  11465. {
  11466. switch (chip_id) {
  11467. case BCM57710:
  11468. case BCM57711:
  11469. case BCM57711E:
  11470. return BNX2X_MULTI_TX_COS_E1X;
  11471. case BCM57712:
  11472. case BCM57712_MF:
  11473. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11474. case BCM57800:
  11475. case BCM57800_MF:
  11476. case BCM57810:
  11477. case BCM57810_MF:
  11478. case BCM57840_4_10:
  11479. case BCM57840_2_20:
  11480. case BCM57840_O:
  11481. case BCM57840_MFO:
  11482. case BCM57840_MF:
  11483. case BCM57811:
  11484. case BCM57811_MF:
  11485. return BNX2X_MULTI_TX_COS_E3B0;
  11486. case BCM57712_VF:
  11487. case BCM57800_VF:
  11488. case BCM57810_VF:
  11489. case BCM57840_VF:
  11490. case BCM57811_VF:
  11491. return 1;
  11492. default:
  11493. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11494. return -ENODEV;
  11495. }
  11496. }
  11497. static int set_is_vf(int chip_id)
  11498. {
  11499. switch (chip_id) {
  11500. case BCM57712_VF:
  11501. case BCM57800_VF:
  11502. case BCM57810_VF:
  11503. case BCM57840_VF:
  11504. case BCM57811_VF:
  11505. return true;
  11506. default:
  11507. return false;
  11508. }
  11509. }
  11510. /* nig_tsgen registers relative address */
  11511. #define tsgen_ctrl 0x0
  11512. #define tsgen_freecount 0x10
  11513. #define tsgen_synctime_t0 0x20
  11514. #define tsgen_offset_t0 0x28
  11515. #define tsgen_drift_t0 0x30
  11516. #define tsgen_synctime_t1 0x58
  11517. #define tsgen_offset_t1 0x60
  11518. #define tsgen_drift_t1 0x68
  11519. /* FW workaround for setting drift */
  11520. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11521. int best_val, int best_period)
  11522. {
  11523. struct bnx2x_func_state_params func_params = {NULL};
  11524. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11525. &func_params.params.set_timesync;
  11526. /* Prepare parameters for function state transitions */
  11527. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11528. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11529. func_params.f_obj = &bp->func_obj;
  11530. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11531. /* Function parameters */
  11532. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11533. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11534. set_timesync_params->add_sub_drift_adjust_value =
  11535. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11536. set_timesync_params->drift_adjust_value = best_val;
  11537. set_timesync_params->drift_adjust_period = best_period;
  11538. return bnx2x_func_state_change(bp, &func_params);
  11539. }
  11540. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11541. {
  11542. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11543. int rc;
  11544. int drift_dir = 1;
  11545. int val, period, period1, period2, dif, dif1, dif2;
  11546. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11547. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11548. if (!netif_running(bp->dev)) {
  11549. DP(BNX2X_MSG_PTP,
  11550. "PTP adjfreq called while the interface is down\n");
  11551. return -ENETDOWN;
  11552. }
  11553. if (ppb < 0) {
  11554. ppb = -ppb;
  11555. drift_dir = 0;
  11556. }
  11557. if (ppb == 0) {
  11558. best_val = 1;
  11559. best_period = 0x1FFFFFF;
  11560. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11561. best_val = 31;
  11562. best_period = 1;
  11563. } else {
  11564. /* Changed not to allow val = 8, 16, 24 as these values
  11565. * are not supported in workaround.
  11566. */
  11567. for (val = 0; val <= 31; val++) {
  11568. if ((val & 0x7) == 0)
  11569. continue;
  11570. period1 = val * 1000000 / ppb;
  11571. period2 = period1 + 1;
  11572. if (period1 != 0)
  11573. dif1 = ppb - (val * 1000000 / period1);
  11574. else
  11575. dif1 = BNX2X_MAX_PHC_DRIFT;
  11576. if (dif1 < 0)
  11577. dif1 = -dif1;
  11578. dif2 = ppb - (val * 1000000 / period2);
  11579. if (dif2 < 0)
  11580. dif2 = -dif2;
  11581. dif = (dif1 < dif2) ? dif1 : dif2;
  11582. period = (dif1 < dif2) ? period1 : period2;
  11583. if (dif < best_dif) {
  11584. best_dif = dif;
  11585. best_val = val;
  11586. best_period = period;
  11587. }
  11588. }
  11589. }
  11590. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11591. best_period);
  11592. if (rc) {
  11593. BNX2X_ERR("Failed to set drift\n");
  11594. return -EFAULT;
  11595. }
  11596. DP(BNX2X_MSG_PTP, "Configured val = %d, period = %d\n", best_val,
  11597. best_period);
  11598. return 0;
  11599. }
  11600. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11601. {
  11602. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11603. if (!netif_running(bp->dev)) {
  11604. DP(BNX2X_MSG_PTP,
  11605. "PTP adjtime called while the interface is down\n");
  11606. return -ENETDOWN;
  11607. }
  11608. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11609. timecounter_adjtime(&bp->timecounter, delta);
  11610. return 0;
  11611. }
  11612. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
  11613. {
  11614. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11615. u64 ns;
  11616. if (!netif_running(bp->dev)) {
  11617. DP(BNX2X_MSG_PTP,
  11618. "PTP gettime called while the interface is down\n");
  11619. return -ENETDOWN;
  11620. }
  11621. ns = timecounter_read(&bp->timecounter);
  11622. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11623. *ts = ns_to_timespec64(ns);
  11624. return 0;
  11625. }
  11626. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11627. const struct timespec64 *ts)
  11628. {
  11629. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11630. u64 ns;
  11631. if (!netif_running(bp->dev)) {
  11632. DP(BNX2X_MSG_PTP,
  11633. "PTP settime called while the interface is down\n");
  11634. return -ENETDOWN;
  11635. }
  11636. ns = timespec64_to_ns(ts);
  11637. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11638. /* Re-init the timecounter */
  11639. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11640. return 0;
  11641. }
  11642. /* Enable (or disable) ancillary features of the phc subsystem */
  11643. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11644. struct ptp_clock_request *rq, int on)
  11645. {
  11646. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11647. BNX2X_ERR("PHC ancillary features are not supported\n");
  11648. return -ENOTSUPP;
  11649. }
  11650. static void bnx2x_register_phc(struct bnx2x *bp)
  11651. {
  11652. /* Fill the ptp_clock_info struct and register PTP clock*/
  11653. bp->ptp_clock_info.owner = THIS_MODULE;
  11654. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11655. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11656. bp->ptp_clock_info.n_alarm = 0;
  11657. bp->ptp_clock_info.n_ext_ts = 0;
  11658. bp->ptp_clock_info.n_per_out = 0;
  11659. bp->ptp_clock_info.pps = 0;
  11660. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11661. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11662. bp->ptp_clock_info.gettime64 = bnx2x_ptp_gettime;
  11663. bp->ptp_clock_info.settime64 = bnx2x_ptp_settime;
  11664. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11665. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11666. if (IS_ERR(bp->ptp_clock)) {
  11667. bp->ptp_clock = NULL;
  11668. BNX2X_ERR("PTP clock registeration failed\n");
  11669. }
  11670. }
  11671. static int bnx2x_init_one(struct pci_dev *pdev,
  11672. const struct pci_device_id *ent)
  11673. {
  11674. struct net_device *dev = NULL;
  11675. struct bnx2x *bp;
  11676. enum pcie_link_width pcie_width;
  11677. enum pci_bus_speed pcie_speed;
  11678. int rc, max_non_def_sbs;
  11679. int rx_count, tx_count, rss_count, doorbell_size;
  11680. int max_cos_est;
  11681. bool is_vf;
  11682. int cnic_cnt;
  11683. /* Management FW 'remembers' living interfaces. Allow it some time
  11684. * to forget previously living interfaces, allowing a proper re-load.
  11685. */
  11686. if (is_kdump_kernel()) {
  11687. ktime_t now = ktime_get_boottime();
  11688. ktime_t fw_ready_time = ktime_set(5, 0);
  11689. if (ktime_before(now, fw_ready_time))
  11690. msleep(ktime_ms_delta(fw_ready_time, now));
  11691. }
  11692. /* An estimated maximum supported CoS number according to the chip
  11693. * version.
  11694. * We will try to roughly estimate the maximum number of CoSes this chip
  11695. * may support in order to minimize the memory allocated for Tx
  11696. * netdev_queue's. This number will be accurately calculated during the
  11697. * initialization of bp->max_cos based on the chip versions AND chip
  11698. * revision in the bnx2x_init_bp().
  11699. */
  11700. max_cos_est = set_max_cos_est(ent->driver_data);
  11701. if (max_cos_est < 0)
  11702. return max_cos_est;
  11703. is_vf = set_is_vf(ent->driver_data);
  11704. cnic_cnt = is_vf ? 0 : 1;
  11705. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11706. /* add another SB for VF as it has no default SB */
  11707. max_non_def_sbs += is_vf ? 1 : 0;
  11708. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11709. rss_count = max_non_def_sbs - cnic_cnt;
  11710. if (rss_count < 1)
  11711. return -EINVAL;
  11712. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11713. rx_count = rss_count + cnic_cnt;
  11714. /* Maximum number of netdev Tx queues:
  11715. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11716. */
  11717. tx_count = rss_count * max_cos_est + cnic_cnt;
  11718. /* dev zeroed in init_etherdev */
  11719. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11720. if (!dev)
  11721. return -ENOMEM;
  11722. bp = netdev_priv(dev);
  11723. bp->flags = 0;
  11724. if (is_vf)
  11725. bp->flags |= IS_VF_FLAG;
  11726. bp->igu_sb_cnt = max_non_def_sbs;
  11727. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11728. bp->msg_enable = debug;
  11729. bp->cnic_support = cnic_cnt;
  11730. bp->cnic_probe = bnx2x_cnic_probe;
  11731. pci_set_drvdata(pdev, dev);
  11732. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11733. if (rc < 0) {
  11734. free_netdev(dev);
  11735. return rc;
  11736. }
  11737. BNX2X_DEV_INFO("This is a %s function\n",
  11738. IS_PF(bp) ? "physical" : "virtual");
  11739. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11740. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11741. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11742. tx_count, rx_count);
  11743. rc = bnx2x_init_bp(bp);
  11744. if (rc)
  11745. goto init_one_exit;
  11746. /* Map doorbells here as we need the real value of bp->max_cos which
  11747. * is initialized in bnx2x_init_bp() to determine the number of
  11748. * l2 connections.
  11749. */
  11750. if (IS_VF(bp)) {
  11751. bp->doorbells = bnx2x_vf_doorbells(bp);
  11752. rc = bnx2x_vf_pci_alloc(bp);
  11753. if (rc)
  11754. goto init_one_freemem;
  11755. } else {
  11756. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11757. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11758. dev_err(&bp->pdev->dev,
  11759. "Cannot map doorbells, bar size too small, aborting\n");
  11760. rc = -ENOMEM;
  11761. goto init_one_freemem;
  11762. }
  11763. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11764. doorbell_size);
  11765. }
  11766. if (!bp->doorbells) {
  11767. dev_err(&bp->pdev->dev,
  11768. "Cannot map doorbell space, aborting\n");
  11769. rc = -ENOMEM;
  11770. goto init_one_freemem;
  11771. }
  11772. if (IS_VF(bp)) {
  11773. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11774. if (rc)
  11775. goto init_one_freemem;
  11776. #ifdef CONFIG_BNX2X_SRIOV
  11777. /* VF with OLD Hypervisor or old PF do not support filtering */
  11778. if (bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER) {
  11779. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11780. dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11781. }
  11782. #endif
  11783. }
  11784. /* Enable SRIOV if capability found in configuration space */
  11785. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11786. if (rc)
  11787. goto init_one_freemem;
  11788. /* calc qm_cid_count */
  11789. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11790. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11791. /* disable FCOE L2 queue for E1x*/
  11792. if (CHIP_IS_E1x(bp))
  11793. bp->flags |= NO_FCOE_FLAG;
  11794. /* Set bp->num_queues for MSI-X mode*/
  11795. bnx2x_set_num_queues(bp);
  11796. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11797. * needed.
  11798. */
  11799. rc = bnx2x_set_int_mode(bp);
  11800. if (rc) {
  11801. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11802. goto init_one_freemem;
  11803. }
  11804. BNX2X_DEV_INFO("set interrupts successfully\n");
  11805. /* register the net device */
  11806. rc = register_netdev(dev);
  11807. if (rc) {
  11808. dev_err(&pdev->dev, "Cannot register net device\n");
  11809. goto init_one_freemem;
  11810. }
  11811. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11812. if (!NO_FCOE(bp)) {
  11813. /* Add storage MAC address */
  11814. rtnl_lock();
  11815. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11816. rtnl_unlock();
  11817. }
  11818. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11819. pcie_speed == PCI_SPEED_UNKNOWN ||
  11820. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11821. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11822. else
  11823. BNX2X_DEV_INFO(
  11824. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11825. board_info[ent->driver_data].name,
  11826. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11827. pcie_width,
  11828. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11829. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11830. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11831. "Unknown",
  11832. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11833. bnx2x_register_phc(bp);
  11834. if (!IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp))
  11835. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_DISABLED);
  11836. return 0;
  11837. init_one_freemem:
  11838. bnx2x_free_mem_bp(bp);
  11839. init_one_exit:
  11840. bnx2x_disable_pcie_error_reporting(bp);
  11841. if (bp->regview)
  11842. iounmap(bp->regview);
  11843. if (IS_PF(bp) && bp->doorbells)
  11844. iounmap(bp->doorbells);
  11845. free_netdev(dev);
  11846. if (atomic_read(&pdev->enable_cnt) == 1)
  11847. pci_release_regions(pdev);
  11848. pci_disable_device(pdev);
  11849. return rc;
  11850. }
  11851. static void __bnx2x_remove(struct pci_dev *pdev,
  11852. struct net_device *dev,
  11853. struct bnx2x *bp,
  11854. bool remove_netdev)
  11855. {
  11856. if (bp->ptp_clock) {
  11857. ptp_clock_unregister(bp->ptp_clock);
  11858. bp->ptp_clock = NULL;
  11859. }
  11860. /* Delete storage MAC address */
  11861. if (!NO_FCOE(bp)) {
  11862. rtnl_lock();
  11863. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11864. rtnl_unlock();
  11865. }
  11866. #ifdef BCM_DCBNL
  11867. /* Delete app tlvs from dcbnl */
  11868. bnx2x_dcbnl_update_applist(bp, true);
  11869. #endif
  11870. if (IS_PF(bp) &&
  11871. !BP_NOMCP(bp) &&
  11872. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11873. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11874. /* Close the interface - either directly or implicitly */
  11875. if (remove_netdev) {
  11876. unregister_netdev(dev);
  11877. } else {
  11878. rtnl_lock();
  11879. dev_close(dev);
  11880. rtnl_unlock();
  11881. }
  11882. bnx2x_iov_remove_one(bp);
  11883. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11884. if (IS_PF(bp)) {
  11885. bnx2x_set_power_state(bp, PCI_D0);
  11886. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_NOT_LOADED);
  11887. /* Set endianity registers to reset values in case next driver
  11888. * boots in different endianty environment.
  11889. */
  11890. bnx2x_reset_endianity(bp);
  11891. }
  11892. /* Disable MSI/MSI-X */
  11893. bnx2x_disable_msi(bp);
  11894. /* Power off */
  11895. if (IS_PF(bp))
  11896. bnx2x_set_power_state(bp, PCI_D3hot);
  11897. /* Make sure RESET task is not scheduled before continuing */
  11898. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11899. /* send message via vfpf channel to release the resources of this vf */
  11900. if (IS_VF(bp))
  11901. bnx2x_vfpf_release(bp);
  11902. /* Assumes no further PCIe PM changes will occur */
  11903. if (system_state == SYSTEM_POWER_OFF) {
  11904. pci_wake_from_d3(pdev, bp->wol);
  11905. pci_set_power_state(pdev, PCI_D3hot);
  11906. }
  11907. bnx2x_disable_pcie_error_reporting(bp);
  11908. if (remove_netdev) {
  11909. if (bp->regview)
  11910. iounmap(bp->regview);
  11911. /* For vfs, doorbells are part of the regview and were unmapped
  11912. * along with it. FW is only loaded by PF.
  11913. */
  11914. if (IS_PF(bp)) {
  11915. if (bp->doorbells)
  11916. iounmap(bp->doorbells);
  11917. bnx2x_release_firmware(bp);
  11918. } else {
  11919. bnx2x_vf_pci_dealloc(bp);
  11920. }
  11921. bnx2x_free_mem_bp(bp);
  11922. free_netdev(dev);
  11923. if (atomic_read(&pdev->enable_cnt) == 1)
  11924. pci_release_regions(pdev);
  11925. pci_disable_device(pdev);
  11926. }
  11927. }
  11928. static void bnx2x_remove_one(struct pci_dev *pdev)
  11929. {
  11930. struct net_device *dev = pci_get_drvdata(pdev);
  11931. struct bnx2x *bp;
  11932. if (!dev) {
  11933. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11934. return;
  11935. }
  11936. bp = netdev_priv(dev);
  11937. __bnx2x_remove(pdev, dev, bp, true);
  11938. }
  11939. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11940. {
  11941. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11942. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11943. if (CNIC_LOADED(bp))
  11944. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11945. /* Stop Tx */
  11946. bnx2x_tx_disable(bp);
  11947. /* Delete all NAPI objects */
  11948. bnx2x_del_all_napi(bp);
  11949. if (CNIC_LOADED(bp))
  11950. bnx2x_del_all_napi_cnic(bp);
  11951. netdev_reset_tc(bp->dev);
  11952. del_timer_sync(&bp->timer);
  11953. cancel_delayed_work_sync(&bp->sp_task);
  11954. cancel_delayed_work_sync(&bp->period_task);
  11955. if (!down_timeout(&bp->stats_lock, HZ / 10)) {
  11956. bp->stats_state = STATS_STATE_DISABLED;
  11957. up(&bp->stats_lock);
  11958. }
  11959. bnx2x_save_statistics(bp);
  11960. netif_carrier_off(bp->dev);
  11961. return 0;
  11962. }
  11963. /**
  11964. * bnx2x_io_error_detected - called when PCI error is detected
  11965. * @pdev: Pointer to PCI device
  11966. * @state: The current pci connection state
  11967. *
  11968. * This function is called after a PCI bus error affecting
  11969. * this device has been detected.
  11970. */
  11971. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11972. pci_channel_state_t state)
  11973. {
  11974. struct net_device *dev = pci_get_drvdata(pdev);
  11975. struct bnx2x *bp = netdev_priv(dev);
  11976. rtnl_lock();
  11977. BNX2X_ERR("IO error detected\n");
  11978. netif_device_detach(dev);
  11979. if (state == pci_channel_io_perm_failure) {
  11980. rtnl_unlock();
  11981. return PCI_ERS_RESULT_DISCONNECT;
  11982. }
  11983. if (netif_running(dev))
  11984. bnx2x_eeh_nic_unload(bp);
  11985. bnx2x_prev_path_mark_eeh(bp);
  11986. pci_disable_device(pdev);
  11987. rtnl_unlock();
  11988. /* Request a slot reset */
  11989. return PCI_ERS_RESULT_NEED_RESET;
  11990. }
  11991. /**
  11992. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11993. * @pdev: Pointer to PCI device
  11994. *
  11995. * Restart the card from scratch, as if from a cold-boot.
  11996. */
  11997. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11998. {
  11999. struct net_device *dev = pci_get_drvdata(pdev);
  12000. struct bnx2x *bp = netdev_priv(dev);
  12001. int i;
  12002. rtnl_lock();
  12003. BNX2X_ERR("IO slot reset initializing...\n");
  12004. if (pci_enable_device(pdev)) {
  12005. dev_err(&pdev->dev,
  12006. "Cannot re-enable PCI device after reset\n");
  12007. rtnl_unlock();
  12008. return PCI_ERS_RESULT_DISCONNECT;
  12009. }
  12010. pci_set_master(pdev);
  12011. pci_restore_state(pdev);
  12012. pci_save_state(pdev);
  12013. if (netif_running(dev))
  12014. bnx2x_set_power_state(bp, PCI_D0);
  12015. if (netif_running(dev)) {
  12016. BNX2X_ERR("IO slot reset --> driver unload\n");
  12017. /* MCP should have been reset; Need to wait for validity */
  12018. bnx2x_init_shmem(bp);
  12019. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  12020. u32 v;
  12021. v = SHMEM2_RD(bp,
  12022. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  12023. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  12024. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  12025. }
  12026. bnx2x_drain_tx_queues(bp);
  12027. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  12028. bnx2x_netif_stop(bp, 1);
  12029. bnx2x_free_irq(bp);
  12030. /* Report UNLOAD_DONE to MCP */
  12031. bnx2x_send_unload_done(bp, true);
  12032. bp->sp_state = 0;
  12033. bp->port.pmf = 0;
  12034. bnx2x_prev_unload(bp);
  12035. /* We should have reseted the engine, so It's fair to
  12036. * assume the FW will no longer write to the bnx2x driver.
  12037. */
  12038. bnx2x_squeeze_objects(bp);
  12039. bnx2x_free_skbs(bp);
  12040. for_each_rx_queue(bp, i)
  12041. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  12042. bnx2x_free_fp_mem(bp);
  12043. bnx2x_free_mem(bp);
  12044. bp->state = BNX2X_STATE_CLOSED;
  12045. }
  12046. rtnl_unlock();
  12047. /* If AER, perform cleanup of the PCIe registers */
  12048. if (bp->flags & AER_ENABLED) {
  12049. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  12050. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  12051. else
  12052. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  12053. }
  12054. return PCI_ERS_RESULT_RECOVERED;
  12055. }
  12056. /**
  12057. * bnx2x_io_resume - called when traffic can start flowing again
  12058. * @pdev: Pointer to PCI device
  12059. *
  12060. * This callback is called when the error recovery driver tells us that
  12061. * its OK to resume normal operation.
  12062. */
  12063. static void bnx2x_io_resume(struct pci_dev *pdev)
  12064. {
  12065. struct net_device *dev = pci_get_drvdata(pdev);
  12066. struct bnx2x *bp = netdev_priv(dev);
  12067. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  12068. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  12069. return;
  12070. }
  12071. rtnl_lock();
  12072. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  12073. DRV_MSG_SEQ_NUMBER_MASK;
  12074. if (netif_running(dev))
  12075. bnx2x_nic_load(bp, LOAD_NORMAL);
  12076. netif_device_attach(dev);
  12077. rtnl_unlock();
  12078. }
  12079. static const struct pci_error_handlers bnx2x_err_handler = {
  12080. .error_detected = bnx2x_io_error_detected,
  12081. .slot_reset = bnx2x_io_slot_reset,
  12082. .resume = bnx2x_io_resume,
  12083. };
  12084. static void bnx2x_shutdown(struct pci_dev *pdev)
  12085. {
  12086. struct net_device *dev = pci_get_drvdata(pdev);
  12087. struct bnx2x *bp;
  12088. if (!dev)
  12089. return;
  12090. bp = netdev_priv(dev);
  12091. if (!bp)
  12092. return;
  12093. rtnl_lock();
  12094. netif_device_detach(dev);
  12095. rtnl_unlock();
  12096. /* Don't remove the netdevice, as there are scenarios which will cause
  12097. * the kernel to hang, e.g., when trying to remove bnx2i while the
  12098. * rootfs is mounted from SAN.
  12099. */
  12100. __bnx2x_remove(pdev, dev, bp, false);
  12101. }
  12102. static struct pci_driver bnx2x_pci_driver = {
  12103. .name = DRV_MODULE_NAME,
  12104. .id_table = bnx2x_pci_tbl,
  12105. .probe = bnx2x_init_one,
  12106. .remove = bnx2x_remove_one,
  12107. .suspend = bnx2x_suspend,
  12108. .resume = bnx2x_resume,
  12109. .err_handler = &bnx2x_err_handler,
  12110. #ifdef CONFIG_BNX2X_SRIOV
  12111. .sriov_configure = bnx2x_sriov_configure,
  12112. #endif
  12113. .shutdown = bnx2x_shutdown,
  12114. };
  12115. static int __init bnx2x_init(void)
  12116. {
  12117. int ret;
  12118. pr_info("%s", version);
  12119. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  12120. if (bnx2x_wq == NULL) {
  12121. pr_err("Cannot create workqueue\n");
  12122. return -ENOMEM;
  12123. }
  12124. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  12125. if (!bnx2x_iov_wq) {
  12126. pr_err("Cannot create iov workqueue\n");
  12127. destroy_workqueue(bnx2x_wq);
  12128. return -ENOMEM;
  12129. }
  12130. ret = pci_register_driver(&bnx2x_pci_driver);
  12131. if (ret) {
  12132. pr_err("Cannot register driver\n");
  12133. destroy_workqueue(bnx2x_wq);
  12134. destroy_workqueue(bnx2x_iov_wq);
  12135. }
  12136. return ret;
  12137. }
  12138. static void __exit bnx2x_cleanup(void)
  12139. {
  12140. struct list_head *pos, *q;
  12141. pci_unregister_driver(&bnx2x_pci_driver);
  12142. destroy_workqueue(bnx2x_wq);
  12143. destroy_workqueue(bnx2x_iov_wq);
  12144. /* Free globally allocated resources */
  12145. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  12146. struct bnx2x_prev_path_list *tmp =
  12147. list_entry(pos, struct bnx2x_prev_path_list, list);
  12148. list_del(pos);
  12149. kfree(tmp);
  12150. }
  12151. }
  12152. void bnx2x_notify_link_changed(struct bnx2x *bp)
  12153. {
  12154. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  12155. }
  12156. module_init(bnx2x_init);
  12157. module_exit(bnx2x_cleanup);
  12158. /**
  12159. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  12160. *
  12161. * @bp: driver handle
  12162. * @set: set or clear the CAM entry
  12163. *
  12164. * This function will wait until the ramrod completion returns.
  12165. * Return 0 if success, -ENODEV if ramrod doesn't return.
  12166. */
  12167. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  12168. {
  12169. unsigned long ramrod_flags = 0;
  12170. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  12171. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  12172. &bp->iscsi_l2_mac_obj, true,
  12173. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  12174. }
  12175. /* count denotes the number of new completions we have seen */
  12176. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  12177. {
  12178. struct eth_spe *spe;
  12179. int cxt_index, cxt_offset;
  12180. #ifdef BNX2X_STOP_ON_ERROR
  12181. if (unlikely(bp->panic))
  12182. return;
  12183. #endif
  12184. spin_lock_bh(&bp->spq_lock);
  12185. BUG_ON(bp->cnic_spq_pending < count);
  12186. bp->cnic_spq_pending -= count;
  12187. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  12188. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  12189. & SPE_HDR_CONN_TYPE) >>
  12190. SPE_HDR_CONN_TYPE_SHIFT;
  12191. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  12192. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  12193. /* Set validation for iSCSI L2 client before sending SETUP
  12194. * ramrod
  12195. */
  12196. if (type == ETH_CONNECTION_TYPE) {
  12197. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  12198. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  12199. ILT_PAGE_CIDS;
  12200. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  12201. (cxt_index * ILT_PAGE_CIDS);
  12202. bnx2x_set_ctx_validation(bp,
  12203. &bp->context[cxt_index].
  12204. vcxt[cxt_offset].eth,
  12205. BNX2X_ISCSI_ETH_CID(bp));
  12206. }
  12207. }
  12208. /*
  12209. * There may be not more than 8 L2, not more than 8 L5 SPEs
  12210. * and in the air. We also check that number of outstanding
  12211. * COMMON ramrods is not more than the EQ and SPQ can
  12212. * accommodate.
  12213. */
  12214. if (type == ETH_CONNECTION_TYPE) {
  12215. if (!atomic_read(&bp->cq_spq_left))
  12216. break;
  12217. else
  12218. atomic_dec(&bp->cq_spq_left);
  12219. } else if (type == NONE_CONNECTION_TYPE) {
  12220. if (!atomic_read(&bp->eq_spq_left))
  12221. break;
  12222. else
  12223. atomic_dec(&bp->eq_spq_left);
  12224. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  12225. (type == FCOE_CONNECTION_TYPE)) {
  12226. if (bp->cnic_spq_pending >=
  12227. bp->cnic_eth_dev.max_kwqe_pending)
  12228. break;
  12229. else
  12230. bp->cnic_spq_pending++;
  12231. } else {
  12232. BNX2X_ERR("Unknown SPE type: %d\n", type);
  12233. bnx2x_panic();
  12234. break;
  12235. }
  12236. spe = bnx2x_sp_get_next(bp);
  12237. *spe = *bp->cnic_kwq_cons;
  12238. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  12239. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  12240. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  12241. bp->cnic_kwq_cons = bp->cnic_kwq;
  12242. else
  12243. bp->cnic_kwq_cons++;
  12244. }
  12245. bnx2x_sp_prod_update(bp);
  12246. spin_unlock_bh(&bp->spq_lock);
  12247. }
  12248. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  12249. struct kwqe_16 *kwqes[], u32 count)
  12250. {
  12251. struct bnx2x *bp = netdev_priv(dev);
  12252. int i;
  12253. #ifdef BNX2X_STOP_ON_ERROR
  12254. if (unlikely(bp->panic)) {
  12255. BNX2X_ERR("Can't post to SP queue while panic\n");
  12256. return -EIO;
  12257. }
  12258. #endif
  12259. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  12260. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  12261. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  12262. return -EAGAIN;
  12263. }
  12264. spin_lock_bh(&bp->spq_lock);
  12265. for (i = 0; i < count; i++) {
  12266. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  12267. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  12268. break;
  12269. *bp->cnic_kwq_prod = *spe;
  12270. bp->cnic_kwq_pending++;
  12271. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  12272. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  12273. spe->data.update_data_addr.hi,
  12274. spe->data.update_data_addr.lo,
  12275. bp->cnic_kwq_pending);
  12276. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  12277. bp->cnic_kwq_prod = bp->cnic_kwq;
  12278. else
  12279. bp->cnic_kwq_prod++;
  12280. }
  12281. spin_unlock_bh(&bp->spq_lock);
  12282. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  12283. bnx2x_cnic_sp_post(bp, 0);
  12284. return i;
  12285. }
  12286. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12287. {
  12288. struct cnic_ops *c_ops;
  12289. int rc = 0;
  12290. mutex_lock(&bp->cnic_mutex);
  12291. c_ops = rcu_dereference_protected(bp->cnic_ops,
  12292. lockdep_is_held(&bp->cnic_mutex));
  12293. if (c_ops)
  12294. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12295. mutex_unlock(&bp->cnic_mutex);
  12296. return rc;
  12297. }
  12298. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12299. {
  12300. struct cnic_ops *c_ops;
  12301. int rc = 0;
  12302. rcu_read_lock();
  12303. c_ops = rcu_dereference(bp->cnic_ops);
  12304. if (c_ops)
  12305. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12306. rcu_read_unlock();
  12307. return rc;
  12308. }
  12309. /*
  12310. * for commands that have no data
  12311. */
  12312. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  12313. {
  12314. struct cnic_ctl_info ctl = {0};
  12315. ctl.cmd = cmd;
  12316. return bnx2x_cnic_ctl_send(bp, &ctl);
  12317. }
  12318. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  12319. {
  12320. struct cnic_ctl_info ctl = {0};
  12321. /* first we tell CNIC and only then we count this as a completion */
  12322. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  12323. ctl.data.comp.cid = cid;
  12324. ctl.data.comp.error = err;
  12325. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  12326. bnx2x_cnic_sp_post(bp, 0);
  12327. }
  12328. /* Called with netif_addr_lock_bh() taken.
  12329. * Sets an rx_mode config for an iSCSI ETH client.
  12330. * Doesn't block.
  12331. * Completion should be checked outside.
  12332. */
  12333. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  12334. {
  12335. unsigned long accept_flags = 0, ramrod_flags = 0;
  12336. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12337. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  12338. if (start) {
  12339. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  12340. * because it's the only way for UIO Queue to accept
  12341. * multicasts (in non-promiscuous mode only one Queue per
  12342. * function will receive multicast packets (leading in our
  12343. * case).
  12344. */
  12345. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  12346. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  12347. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  12348. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  12349. /* Clear STOP_PENDING bit if START is requested */
  12350. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  12351. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  12352. } else
  12353. /* Clear START_PENDING bit if STOP is requested */
  12354. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  12355. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  12356. set_bit(sched_state, &bp->sp_state);
  12357. else {
  12358. __set_bit(RAMROD_RX, &ramrod_flags);
  12359. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  12360. ramrod_flags);
  12361. }
  12362. }
  12363. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  12364. {
  12365. struct bnx2x *bp = netdev_priv(dev);
  12366. int rc = 0;
  12367. switch (ctl->cmd) {
  12368. case DRV_CTL_CTXTBL_WR_CMD: {
  12369. u32 index = ctl->data.io.offset;
  12370. dma_addr_t addr = ctl->data.io.dma_addr;
  12371. bnx2x_ilt_wr(bp, index, addr);
  12372. break;
  12373. }
  12374. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  12375. int count = ctl->data.credit.credit_count;
  12376. bnx2x_cnic_sp_post(bp, count);
  12377. break;
  12378. }
  12379. /* rtnl_lock is held. */
  12380. case DRV_CTL_START_L2_CMD: {
  12381. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12382. unsigned long sp_bits = 0;
  12383. /* Configure the iSCSI classification object */
  12384. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  12385. cp->iscsi_l2_client_id,
  12386. cp->iscsi_l2_cid, BP_FUNC(bp),
  12387. bnx2x_sp(bp, mac_rdata),
  12388. bnx2x_sp_mapping(bp, mac_rdata),
  12389. BNX2X_FILTER_MAC_PENDING,
  12390. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  12391. &bp->macs_pool);
  12392. /* Set iSCSI MAC address */
  12393. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  12394. if (rc)
  12395. break;
  12396. mmiowb();
  12397. barrier();
  12398. /* Start accepting on iSCSI L2 ring */
  12399. netif_addr_lock_bh(dev);
  12400. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  12401. netif_addr_unlock_bh(dev);
  12402. /* bits to wait on */
  12403. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12404. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  12405. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12406. BNX2X_ERR("rx_mode completion timed out!\n");
  12407. break;
  12408. }
  12409. /* rtnl_lock is held. */
  12410. case DRV_CTL_STOP_L2_CMD: {
  12411. unsigned long sp_bits = 0;
  12412. /* Stop accepting on iSCSI L2 ring */
  12413. netif_addr_lock_bh(dev);
  12414. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  12415. netif_addr_unlock_bh(dev);
  12416. /* bits to wait on */
  12417. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12418. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  12419. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12420. BNX2X_ERR("rx_mode completion timed out!\n");
  12421. mmiowb();
  12422. barrier();
  12423. /* Unset iSCSI L2 MAC */
  12424. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  12425. BNX2X_ISCSI_ETH_MAC, true);
  12426. break;
  12427. }
  12428. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  12429. int count = ctl->data.credit.credit_count;
  12430. smp_mb__before_atomic();
  12431. atomic_add(count, &bp->cq_spq_left);
  12432. smp_mb__after_atomic();
  12433. break;
  12434. }
  12435. case DRV_CTL_ULP_REGISTER_CMD: {
  12436. int ulp_type = ctl->data.register_data.ulp_type;
  12437. if (CHIP_IS_E3(bp)) {
  12438. int idx = BP_FW_MB_IDX(bp);
  12439. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12440. int path = BP_PATH(bp);
  12441. int port = BP_PORT(bp);
  12442. int i;
  12443. u32 scratch_offset;
  12444. u32 *host_addr;
  12445. /* first write capability to shmem2 */
  12446. if (ulp_type == CNIC_ULP_ISCSI)
  12447. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12448. else if (ulp_type == CNIC_ULP_FCOE)
  12449. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12450. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12451. if ((ulp_type != CNIC_ULP_FCOE) ||
  12452. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  12453. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  12454. break;
  12455. /* if reached here - should write fcoe capabilities */
  12456. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  12457. if (!scratch_offset)
  12458. break;
  12459. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  12460. fcoe_features[path][port]);
  12461. host_addr = (u32 *) &(ctl->data.register_data.
  12462. fcoe_features);
  12463. for (i = 0; i < sizeof(struct fcoe_capabilities);
  12464. i += 4)
  12465. REG_WR(bp, scratch_offset + i,
  12466. *(host_addr + i/4));
  12467. }
  12468. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12469. break;
  12470. }
  12471. case DRV_CTL_ULP_UNREGISTER_CMD: {
  12472. int ulp_type = ctl->data.ulp_type;
  12473. if (CHIP_IS_E3(bp)) {
  12474. int idx = BP_FW_MB_IDX(bp);
  12475. u32 cap;
  12476. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12477. if (ulp_type == CNIC_ULP_ISCSI)
  12478. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12479. else if (ulp_type == CNIC_ULP_FCOE)
  12480. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12481. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12482. }
  12483. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12484. break;
  12485. }
  12486. default:
  12487. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12488. rc = -EINVAL;
  12489. }
  12490. /* For storage-only interfaces, change driver state */
  12491. if (IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp)) {
  12492. switch (ctl->drv_state) {
  12493. case DRV_NOP:
  12494. break;
  12495. case DRV_ACTIVE:
  12496. bnx2x_set_os_driver_state(bp,
  12497. OS_DRIVER_STATE_ACTIVE);
  12498. break;
  12499. case DRV_INACTIVE:
  12500. bnx2x_set_os_driver_state(bp,
  12501. OS_DRIVER_STATE_DISABLED);
  12502. break;
  12503. case DRV_UNLOADED:
  12504. bnx2x_set_os_driver_state(bp,
  12505. OS_DRIVER_STATE_NOT_LOADED);
  12506. break;
  12507. default:
  12508. BNX2X_ERR("Unknown cnic driver state: %d\n", ctl->drv_state);
  12509. }
  12510. }
  12511. return rc;
  12512. }
  12513. static int bnx2x_get_fc_npiv(struct net_device *dev,
  12514. struct cnic_fc_npiv_tbl *cnic_tbl)
  12515. {
  12516. struct bnx2x *bp = netdev_priv(dev);
  12517. struct bdn_fc_npiv_tbl *tbl = NULL;
  12518. u32 offset, entries;
  12519. int rc = -EINVAL;
  12520. int i;
  12521. if (!SHMEM2_HAS(bp, fc_npiv_nvram_tbl_addr[0]))
  12522. goto out;
  12523. DP(BNX2X_MSG_MCP, "About to read the FC-NPIV table\n");
  12524. tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
  12525. if (!tbl) {
  12526. BNX2X_ERR("Failed to allocate fc_npiv table\n");
  12527. goto out;
  12528. }
  12529. offset = SHMEM2_RD(bp, fc_npiv_nvram_tbl_addr[BP_PORT(bp)]);
  12530. if (!offset) {
  12531. DP(BNX2X_MSG_MCP, "No FC-NPIV in NVRAM\n");
  12532. goto out;
  12533. }
  12534. DP(BNX2X_MSG_MCP, "Offset of FC-NPIV in NVRAM: %08x\n", offset);
  12535. /* Read the table contents from nvram */
  12536. if (bnx2x_nvram_read(bp, offset, (u8 *)tbl, sizeof(*tbl))) {
  12537. BNX2X_ERR("Failed to read FC-NPIV table\n");
  12538. goto out;
  12539. }
  12540. /* Since bnx2x_nvram_read() returns data in be32, we need to convert
  12541. * the number of entries back to cpu endianness.
  12542. */
  12543. entries = tbl->fc_npiv_cfg.num_of_npiv;
  12544. entries = (__force u32)be32_to_cpu((__force __be32)entries);
  12545. tbl->fc_npiv_cfg.num_of_npiv = entries;
  12546. if (!tbl->fc_npiv_cfg.num_of_npiv) {
  12547. DP(BNX2X_MSG_MCP,
  12548. "No FC-NPIV table [valid, simply not present]\n");
  12549. goto out;
  12550. } else if (tbl->fc_npiv_cfg.num_of_npiv > MAX_NUMBER_NPIV) {
  12551. BNX2X_ERR("FC-NPIV table with bad length 0x%08x\n",
  12552. tbl->fc_npiv_cfg.num_of_npiv);
  12553. goto out;
  12554. } else {
  12555. DP(BNX2X_MSG_MCP, "Read 0x%08x entries from NVRAM\n",
  12556. tbl->fc_npiv_cfg.num_of_npiv);
  12557. }
  12558. /* Copy the data into cnic-provided struct */
  12559. cnic_tbl->count = tbl->fc_npiv_cfg.num_of_npiv;
  12560. for (i = 0; i < cnic_tbl->count; i++) {
  12561. memcpy(cnic_tbl->wwpn[i], tbl->settings[i].npiv_wwpn, 8);
  12562. memcpy(cnic_tbl->wwnn[i], tbl->settings[i].npiv_wwnn, 8);
  12563. }
  12564. rc = 0;
  12565. out:
  12566. kfree(tbl);
  12567. return rc;
  12568. }
  12569. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12570. {
  12571. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12572. if (bp->flags & USING_MSIX_FLAG) {
  12573. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12574. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12575. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12576. } else {
  12577. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12578. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12579. }
  12580. if (!CHIP_IS_E1x(bp))
  12581. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12582. else
  12583. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12584. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12585. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12586. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12587. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12588. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12589. cp->num_irq = 2;
  12590. }
  12591. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12592. {
  12593. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12594. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12595. bnx2x_cid_ilt_lines(bp);
  12596. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12597. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12598. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12599. 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",
  12600. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12601. cp->iscsi_l2_cid);
  12602. if (NO_ISCSI_OOO(bp))
  12603. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12604. }
  12605. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12606. void *data)
  12607. {
  12608. struct bnx2x *bp = netdev_priv(dev);
  12609. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12610. int rc;
  12611. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12612. if (ops == NULL) {
  12613. BNX2X_ERR("NULL ops received\n");
  12614. return -EINVAL;
  12615. }
  12616. if (!CNIC_SUPPORT(bp)) {
  12617. BNX2X_ERR("Can't register CNIC when not supported\n");
  12618. return -EOPNOTSUPP;
  12619. }
  12620. if (!CNIC_LOADED(bp)) {
  12621. rc = bnx2x_load_cnic(bp);
  12622. if (rc) {
  12623. BNX2X_ERR("CNIC-related load failed\n");
  12624. return rc;
  12625. }
  12626. }
  12627. bp->cnic_enabled = true;
  12628. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12629. if (!bp->cnic_kwq)
  12630. return -ENOMEM;
  12631. bp->cnic_kwq_cons = bp->cnic_kwq;
  12632. bp->cnic_kwq_prod = bp->cnic_kwq;
  12633. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12634. bp->cnic_spq_pending = 0;
  12635. bp->cnic_kwq_pending = 0;
  12636. bp->cnic_data = data;
  12637. cp->num_irq = 0;
  12638. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12639. cp->iro_arr = bp->iro_arr;
  12640. bnx2x_setup_cnic_irq_info(bp);
  12641. rcu_assign_pointer(bp->cnic_ops, ops);
  12642. /* Schedule driver to read CNIC driver versions */
  12643. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12644. return 0;
  12645. }
  12646. static int bnx2x_unregister_cnic(struct net_device *dev)
  12647. {
  12648. struct bnx2x *bp = netdev_priv(dev);
  12649. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12650. mutex_lock(&bp->cnic_mutex);
  12651. cp->drv_state = 0;
  12652. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12653. mutex_unlock(&bp->cnic_mutex);
  12654. synchronize_rcu();
  12655. bp->cnic_enabled = false;
  12656. kfree(bp->cnic_kwq);
  12657. bp->cnic_kwq = NULL;
  12658. return 0;
  12659. }
  12660. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12661. {
  12662. struct bnx2x *bp = netdev_priv(dev);
  12663. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12664. /* If both iSCSI and FCoE are disabled - return NULL in
  12665. * order to indicate CNIC that it should not try to work
  12666. * with this device.
  12667. */
  12668. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12669. return NULL;
  12670. cp->drv_owner = THIS_MODULE;
  12671. cp->chip_id = CHIP_ID(bp);
  12672. cp->pdev = bp->pdev;
  12673. cp->io_base = bp->regview;
  12674. cp->io_base2 = bp->doorbells;
  12675. cp->max_kwqe_pending = 8;
  12676. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12677. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12678. bnx2x_cid_ilt_lines(bp);
  12679. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12680. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12681. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12682. cp->drv_ctl = bnx2x_drv_ctl;
  12683. cp->drv_get_fc_npiv_tbl = bnx2x_get_fc_npiv;
  12684. cp->drv_register_cnic = bnx2x_register_cnic;
  12685. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12686. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12687. cp->iscsi_l2_client_id =
  12688. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12689. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12690. if (NO_ISCSI_OOO(bp))
  12691. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12692. if (NO_ISCSI(bp))
  12693. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12694. if (NO_FCOE(bp))
  12695. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12696. BNX2X_DEV_INFO(
  12697. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12698. cp->ctx_blk_size,
  12699. cp->ctx_tbl_offset,
  12700. cp->ctx_tbl_len,
  12701. cp->starting_cid);
  12702. return cp;
  12703. }
  12704. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12705. {
  12706. struct bnx2x *bp = fp->bp;
  12707. u32 offset = BAR_USTRORM_INTMEM;
  12708. if (IS_VF(bp))
  12709. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12710. else if (!CHIP_IS_E1x(bp))
  12711. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12712. else
  12713. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12714. return offset;
  12715. }
  12716. /* called only on E1H or E2.
  12717. * When pretending to be PF, the pretend value is the function number 0...7
  12718. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12719. * combination
  12720. */
  12721. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12722. {
  12723. u32 pretend_reg;
  12724. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12725. return -1;
  12726. /* get my own pretend register */
  12727. pretend_reg = bnx2x_get_pretend_reg(bp);
  12728. REG_WR(bp, pretend_reg, pretend_func_val);
  12729. REG_RD(bp, pretend_reg);
  12730. return 0;
  12731. }
  12732. static void bnx2x_ptp_task(struct work_struct *work)
  12733. {
  12734. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12735. int port = BP_PORT(bp);
  12736. u32 val_seq;
  12737. u64 timestamp, ns;
  12738. struct skb_shared_hwtstamps shhwtstamps;
  12739. /* Read Tx timestamp registers */
  12740. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12741. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12742. if (val_seq & 0x10000) {
  12743. /* There is a valid timestamp value */
  12744. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12745. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12746. timestamp <<= 32;
  12747. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12748. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12749. /* Reset timestamp register to allow new timestamp */
  12750. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12751. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12752. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12753. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12754. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12755. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12756. dev_kfree_skb_any(bp->ptp_tx_skb);
  12757. bp->ptp_tx_skb = NULL;
  12758. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12759. timestamp, ns);
  12760. } else {
  12761. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12762. /* Reschedule to keep checking for a valid timestamp value */
  12763. schedule_work(&bp->ptp_task);
  12764. }
  12765. }
  12766. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12767. {
  12768. int port = BP_PORT(bp);
  12769. u64 timestamp, ns;
  12770. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12771. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12772. timestamp <<= 32;
  12773. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12774. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12775. /* Reset timestamp register to allow new timestamp */
  12776. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12777. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12778. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12779. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12780. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12781. timestamp, ns);
  12782. }
  12783. /* Read the PHC */
  12784. static u64 bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12785. {
  12786. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12787. int port = BP_PORT(bp);
  12788. u32 wb_data[2];
  12789. u64 phc_cycles;
  12790. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12791. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12792. phc_cycles = wb_data[1];
  12793. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12794. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12795. return phc_cycles;
  12796. }
  12797. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12798. {
  12799. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12800. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12801. bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
  12802. bp->cyclecounter.shift = 0;
  12803. bp->cyclecounter.mult = 1;
  12804. }
  12805. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12806. {
  12807. struct bnx2x_func_state_params func_params = {NULL};
  12808. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12809. &func_params.params.set_timesync;
  12810. /* Prepare parameters for function state transitions */
  12811. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12812. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12813. func_params.f_obj = &bp->func_obj;
  12814. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12815. /* Function parameters */
  12816. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12817. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12818. return bnx2x_func_state_change(bp, &func_params);
  12819. }
  12820. static int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12821. {
  12822. struct bnx2x_queue_state_params q_params;
  12823. int rc, i;
  12824. /* send queue update ramrod to enable PTP packets */
  12825. memset(&q_params, 0, sizeof(q_params));
  12826. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12827. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12828. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12829. &q_params.params.update.update_flags);
  12830. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12831. &q_params.params.update.update_flags);
  12832. /* send the ramrod on all the queues of the PF */
  12833. for_each_eth_queue(bp, i) {
  12834. struct bnx2x_fastpath *fp = &bp->fp[i];
  12835. /* Set the appropriate Queue object */
  12836. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12837. /* Update the Queue state */
  12838. rc = bnx2x_queue_state_change(bp, &q_params);
  12839. if (rc) {
  12840. BNX2X_ERR("Failed to enable PTP packets\n");
  12841. return rc;
  12842. }
  12843. }
  12844. return 0;
  12845. }
  12846. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12847. {
  12848. int port = BP_PORT(bp);
  12849. int rc;
  12850. if (!bp->hwtstamp_ioctl_called)
  12851. return 0;
  12852. switch (bp->tx_type) {
  12853. case HWTSTAMP_TX_ON:
  12854. bp->flags |= TX_TIMESTAMPING_EN;
  12855. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12856. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12857. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12858. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12859. break;
  12860. case HWTSTAMP_TX_ONESTEP_SYNC:
  12861. BNX2X_ERR("One-step timestamping is not supported\n");
  12862. return -ERANGE;
  12863. }
  12864. switch (bp->rx_filter) {
  12865. case HWTSTAMP_FILTER_NONE:
  12866. break;
  12867. case HWTSTAMP_FILTER_ALL:
  12868. case HWTSTAMP_FILTER_SOME:
  12869. case HWTSTAMP_FILTER_NTP_ALL:
  12870. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12871. break;
  12872. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12873. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12874. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12875. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12876. /* Initialize PTP detection for UDP/IPv4 events */
  12877. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12878. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12879. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12880. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12881. break;
  12882. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12883. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12884. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12885. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12886. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12887. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12888. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12889. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12890. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12891. break;
  12892. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12893. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12894. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12895. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12896. /* Initialize PTP detection L2 events */
  12897. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12898. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12899. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12900. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12901. break;
  12902. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12903. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12904. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12905. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12906. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12907. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12908. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12909. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12910. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12911. break;
  12912. }
  12913. /* Indicate to FW that this PF expects recorded PTP packets */
  12914. rc = bnx2x_enable_ptp_packets(bp);
  12915. if (rc)
  12916. return rc;
  12917. /* Enable sending PTP packets to host */
  12918. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12919. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12920. return 0;
  12921. }
  12922. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12923. {
  12924. struct hwtstamp_config config;
  12925. int rc;
  12926. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12927. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12928. return -EFAULT;
  12929. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12930. config.tx_type, config.rx_filter);
  12931. if (config.flags) {
  12932. BNX2X_ERR("config.flags is reserved for future use\n");
  12933. return -EINVAL;
  12934. }
  12935. bp->hwtstamp_ioctl_called = 1;
  12936. bp->tx_type = config.tx_type;
  12937. bp->rx_filter = config.rx_filter;
  12938. rc = bnx2x_configure_ptp_filters(bp);
  12939. if (rc)
  12940. return rc;
  12941. config.rx_filter = bp->rx_filter;
  12942. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12943. -EFAULT : 0;
  12944. }
  12945. /* Configures HW for PTP */
  12946. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12947. {
  12948. int rc, port = BP_PORT(bp);
  12949. u32 wb_data[2];
  12950. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12951. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12952. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12953. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12954. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12955. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12956. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12957. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12958. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12959. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12960. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12961. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12962. /* Enable the PTP feature */
  12963. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12964. NIG_REG_P0_PTP_EN, 0x3F);
  12965. /* Enable the free-running counter */
  12966. wb_data[0] = 0;
  12967. wb_data[1] = 0;
  12968. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12969. /* Reset drift register (offset register is not reset) */
  12970. rc = bnx2x_send_reset_timesync_ramrod(bp);
  12971. if (rc) {
  12972. BNX2X_ERR("Failed to reset PHC drift register\n");
  12973. return -EFAULT;
  12974. }
  12975. /* Reset possibly old timestamps */
  12976. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12977. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12978. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12979. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12980. return 0;
  12981. }
  12982. /* Called during load, to initialize PTP-related stuff */
  12983. void bnx2x_init_ptp(struct bnx2x *bp)
  12984. {
  12985. int rc;
  12986. /* Configure PTP in HW */
  12987. rc = bnx2x_configure_ptp(bp);
  12988. if (rc) {
  12989. BNX2X_ERR("Stopping PTP initialization\n");
  12990. return;
  12991. }
  12992. /* Init work queue for Tx timestamping */
  12993. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  12994. /* Init cyclecounter and timecounter. This is done only in the first
  12995. * load. If done in every load, PTP application will fail when doing
  12996. * unload / load (e.g. MTU change) while it is running.
  12997. */
  12998. if (!bp->timecounter_init_done) {
  12999. bnx2x_init_cyclecounter(bp);
  13000. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  13001. ktime_to_ns(ktime_get_real()));
  13002. bp->timecounter_init_done = 1;
  13003. }
  13004. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  13005. }