bnx2x_main.c 421 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553
  1. /* bnx2x_main.c: QLogic Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. * Copyright (c) 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  12. * Written by: Eliezer Tamir
  13. * Based on code from Michael Chan's bnx2 driver
  14. * UDP CSUM errata workaround by Arik Gendelman
  15. * Slowpath and fastpath rework by Vladislav Zolotarov
  16. * Statistics and Link management by Yitchak Gertner
  17. *
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/kernel.h>
  23. #include <linux/device.h> /* for dev_info() */
  24. #include <linux/timer.h>
  25. #include <linux/errno.h>
  26. #include <linux/ioport.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/pci.h>
  30. #include <linux/aer.h>
  31. #include <linux/init.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/bitops.h>
  37. #include <linux/irq.h>
  38. #include <linux/delay.h>
  39. #include <asm/byteorder.h>
  40. #include <linux/time.h>
  41. #include <linux/ethtool.h>
  42. #include <linux/mii.h>
  43. #include <linux/if_vlan.h>
  44. #include <linux/crash_dump.h>
  45. #include <net/ip.h>
  46. #include <net/ipv6.h>
  47. #include <net/tcp.h>
  48. #include <net/vxlan.h>
  49. #include <net/checksum.h>
  50. #include <net/ip6_checksum.h>
  51. #include <linux/workqueue.h>
  52. #include <linux/crc32.h>
  53. #include <linux/crc32c.h>
  54. #include <linux/prefetch.h>
  55. #include <linux/zlib.h>
  56. #include <linux/io.h>
  57. #include <linux/semaphore.h>
  58. #include <linux/stringify.h>
  59. #include <linux/vmalloc.h>
  60. #include "bnx2x.h"
  61. #include "bnx2x_init.h"
  62. #include "bnx2x_init_ops.h"
  63. #include "bnx2x_cmn.h"
  64. #include "bnx2x_vfpf.h"
  65. #include "bnx2x_dcb.h"
  66. #include "bnx2x_sp.h"
  67. #include <linux/firmware.h>
  68. #include "bnx2x_fw_file_hdr.h"
  69. /* FW files */
  70. #define FW_FILE_VERSION \
  71. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  72. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  73. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  74. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  75. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  76. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  77. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  78. /* Time in jiffies before concluding the transmitter is hung */
  79. #define TX_TIMEOUT (5*HZ)
  80. static char version[] =
  81. "QLogic 5771x/578xx 10/20-Gigabit Ethernet Driver "
  82. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  83. MODULE_AUTHOR("Eliezer Tamir");
  84. MODULE_DESCRIPTION("QLogic "
  85. "BCM57710/57711/57711E/"
  86. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  87. "57840/57840_MF Driver");
  88. MODULE_LICENSE("GPL");
  89. MODULE_VERSION(DRV_MODULE_VERSION);
  90. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  91. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  92. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  93. int bnx2x_num_queues;
  94. module_param_named(num_queues, bnx2x_num_queues, int, 0444);
  95. MODULE_PARM_DESC(num_queues,
  96. " Set number of queues (default is as a number of CPUs)");
  97. static int disable_tpa;
  98. module_param(disable_tpa, int, 0444);
  99. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  100. static int int_mode;
  101. module_param(int_mode, int, 0444);
  102. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  103. "(1 INT#x; 2 MSI)");
  104. static int dropless_fc;
  105. module_param(dropless_fc, int, 0444);
  106. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  107. static int mrrs = -1;
  108. module_param(mrrs, int, 0444);
  109. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  110. static int debug;
  111. module_param(debug, int, 0444);
  112. MODULE_PARM_DESC(debug, " Default debug msglevel");
  113. static struct workqueue_struct *bnx2x_wq;
  114. struct workqueue_struct *bnx2x_iov_wq;
  115. struct bnx2x_mac_vals {
  116. u32 xmac_addr;
  117. u32 xmac_val;
  118. u32 emac_addr;
  119. u32 emac_val;
  120. u32 umac_addr[2];
  121. u32 umac_val[2];
  122. u32 bmac_addr;
  123. u32 bmac_val[2];
  124. };
  125. enum bnx2x_board_type {
  126. BCM57710 = 0,
  127. BCM57711,
  128. BCM57711E,
  129. BCM57712,
  130. BCM57712_MF,
  131. BCM57712_VF,
  132. BCM57800,
  133. BCM57800_MF,
  134. BCM57800_VF,
  135. BCM57810,
  136. BCM57810_MF,
  137. BCM57810_VF,
  138. BCM57840_4_10,
  139. BCM57840_2_20,
  140. BCM57840_MF,
  141. BCM57840_VF,
  142. BCM57811,
  143. BCM57811_MF,
  144. BCM57840_O,
  145. BCM57840_MFO,
  146. BCM57811_VF
  147. };
  148. /* indexed by board_type, above */
  149. static struct {
  150. char *name;
  151. } board_info[] = {
  152. [BCM57710] = { "QLogic BCM57710 10 Gigabit PCIe [Everest]" },
  153. [BCM57711] = { "QLogic BCM57711 10 Gigabit PCIe" },
  154. [BCM57711E] = { "QLogic BCM57711E 10 Gigabit PCIe" },
  155. [BCM57712] = { "QLogic BCM57712 10 Gigabit Ethernet" },
  156. [BCM57712_MF] = { "QLogic BCM57712 10 Gigabit Ethernet Multi Function" },
  157. [BCM57712_VF] = { "QLogic BCM57712 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57800] = { "QLogic BCM57800 10 Gigabit Ethernet" },
  159. [BCM57800_MF] = { "QLogic BCM57800 10 Gigabit Ethernet Multi Function" },
  160. [BCM57800_VF] = { "QLogic BCM57800 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57810] = { "QLogic BCM57810 10 Gigabit Ethernet" },
  162. [BCM57810_MF] = { "QLogic BCM57810 10 Gigabit Ethernet Multi Function" },
  163. [BCM57810_VF] = { "QLogic BCM57810 10 Gigabit Ethernet Virtual Function" },
  164. [BCM57840_4_10] = { "QLogic BCM57840 10 Gigabit Ethernet" },
  165. [BCM57840_2_20] = { "QLogic BCM57840 20 Gigabit Ethernet" },
  166. [BCM57840_MF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  167. [BCM57840_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  168. [BCM57811] = { "QLogic BCM57811 10 Gigabit Ethernet" },
  169. [BCM57811_MF] = { "QLogic BCM57811 10 Gigabit Ethernet Multi Function" },
  170. [BCM57840_O] = { "QLogic BCM57840 10/20 Gigabit Ethernet" },
  171. [BCM57840_MFO] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  172. [BCM57811_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  173. };
  174. #ifndef PCI_DEVICE_ID_NX2_57710
  175. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711
  178. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57711E
  181. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712
  184. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  187. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  190. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800
  193. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  196. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  199. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810
  202. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  205. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_O
  208. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  211. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  214. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  217. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  220. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  223. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  226. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811
  229. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  232. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  233. #endif
  234. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  235. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  236. #endif
  237. static const struct pci_device_id bnx2x_pci_tbl[] = {
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  251. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  256. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  257. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  258. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  259. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  260. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  261. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  262. { 0 }
  263. };
  264. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  265. /* Global resources for unloading a previously loaded device */
  266. #define BNX2X_PREV_WAIT_NEEDED 1
  267. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  268. static LIST_HEAD(bnx2x_prev_list);
  269. /* Forward declaration */
  270. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  271. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  272. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  273. /****************************************************************************
  274. * General service functions
  275. ****************************************************************************/
  276. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  277. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  278. u32 addr, dma_addr_t mapping)
  279. {
  280. REG_WR(bp, addr, U64_LO(mapping));
  281. REG_WR(bp, addr + 4, U64_HI(mapping));
  282. }
  283. static void storm_memset_spq_addr(struct bnx2x *bp,
  284. dma_addr_t mapping, u16 abs_fid)
  285. {
  286. u32 addr = XSEM_REG_FAST_MEMORY +
  287. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  288. __storm_memset_dma_mapping(bp, addr, mapping);
  289. }
  290. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  291. u16 pf_id)
  292. {
  293. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  294. pf_id);
  295. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  296. pf_id);
  297. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  298. pf_id);
  299. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  300. pf_id);
  301. }
  302. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  303. u8 enable)
  304. {
  305. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  306. enable);
  307. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  308. enable);
  309. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  310. enable);
  311. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  312. enable);
  313. }
  314. static void storm_memset_eq_data(struct bnx2x *bp,
  315. struct event_ring_data *eq_data,
  316. u16 pfid)
  317. {
  318. size_t size = sizeof(struct event_ring_data);
  319. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  320. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  321. }
  322. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  323. u16 pfid)
  324. {
  325. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  326. REG_WR16(bp, addr, eq_prod);
  327. }
  328. /* used only at init
  329. * locking is done by mcp
  330. */
  331. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  332. {
  333. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  334. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  335. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  336. PCICFG_VENDOR_ID_OFFSET);
  337. }
  338. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  339. {
  340. u32 val;
  341. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  342. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  343. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  344. PCICFG_VENDOR_ID_OFFSET);
  345. return val;
  346. }
  347. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  348. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  349. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  350. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  351. #define DMAE_DP_DST_NONE "dst_addr [none]"
  352. static void bnx2x_dp_dmae(struct bnx2x *bp,
  353. struct dmae_command *dmae, int msglvl)
  354. {
  355. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  356. int i;
  357. switch (dmae->opcode & DMAE_COMMAND_DST) {
  358. case DMAE_CMD_DST_PCI:
  359. if (src_type == DMAE_CMD_SRC_PCI)
  360. DP(msglvl, "DMAE: opcode 0x%08x\n"
  361. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  362. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  363. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  364. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  365. dmae->comp_addr_hi, dmae->comp_addr_lo,
  366. dmae->comp_val);
  367. else
  368. DP(msglvl, "DMAE: opcode 0x%08x\n"
  369. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  370. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  371. dmae->opcode, dmae->src_addr_lo >> 2,
  372. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  373. dmae->comp_addr_hi, dmae->comp_addr_lo,
  374. dmae->comp_val);
  375. break;
  376. case DMAE_CMD_DST_GRC:
  377. if (src_type == DMAE_CMD_SRC_PCI)
  378. DP(msglvl, "DMAE: opcode 0x%08x\n"
  379. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  380. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  381. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  382. dmae->len, dmae->dst_addr_lo >> 2,
  383. dmae->comp_addr_hi, dmae->comp_addr_lo,
  384. dmae->comp_val);
  385. else
  386. DP(msglvl, "DMAE: opcode 0x%08x\n"
  387. "src [%08x], len [%d*4], dst [%08x]\n"
  388. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  389. dmae->opcode, dmae->src_addr_lo >> 2,
  390. dmae->len, dmae->dst_addr_lo >> 2,
  391. dmae->comp_addr_hi, dmae->comp_addr_lo,
  392. dmae->comp_val);
  393. break;
  394. default:
  395. if (src_type == DMAE_CMD_SRC_PCI)
  396. DP(msglvl, "DMAE: opcode 0x%08x\n"
  397. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  398. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  399. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  400. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  401. dmae->comp_val);
  402. else
  403. DP(msglvl, "DMAE: opcode 0x%08x\n"
  404. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  405. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  406. dmae->opcode, dmae->src_addr_lo >> 2,
  407. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  408. dmae->comp_val);
  409. break;
  410. }
  411. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  412. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  413. i, *(((u32 *)dmae) + i));
  414. }
  415. /* copy command into DMAE command memory and set DMAE command go */
  416. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  417. {
  418. u32 cmd_offset;
  419. int i;
  420. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  421. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  422. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  423. }
  424. REG_WR(bp, dmae_reg_go_c[idx], 1);
  425. }
  426. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  427. {
  428. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  429. DMAE_CMD_C_ENABLE);
  430. }
  431. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  432. {
  433. return opcode & ~DMAE_CMD_SRC_RESET;
  434. }
  435. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  436. bool with_comp, u8 comp_type)
  437. {
  438. u32 opcode = 0;
  439. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  440. (dst_type << DMAE_COMMAND_DST_SHIFT));
  441. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  442. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  443. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  444. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  445. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  446. #ifdef __BIG_ENDIAN
  447. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  448. #else
  449. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  450. #endif
  451. if (with_comp)
  452. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  453. return opcode;
  454. }
  455. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  456. struct dmae_command *dmae,
  457. u8 src_type, u8 dst_type)
  458. {
  459. memset(dmae, 0, sizeof(struct dmae_command));
  460. /* set the opcode */
  461. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  462. true, DMAE_COMP_PCI);
  463. /* fill in the completion parameters */
  464. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  465. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  466. dmae->comp_val = DMAE_COMP_VAL;
  467. }
  468. /* issue a dmae command over the init-channel and wait for completion */
  469. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  470. u32 *comp)
  471. {
  472. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  473. int rc = 0;
  474. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  475. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  476. * as long as this code is called both from syscall context and
  477. * from ndo_set_rx_mode() flow that may be called from BH.
  478. */
  479. spin_lock_bh(&bp->dmae_lock);
  480. /* reset completion */
  481. *comp = 0;
  482. /* post the command on the channel used for initializations */
  483. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  484. /* wait for completion */
  485. udelay(5);
  486. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  487. if (!cnt ||
  488. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  489. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  490. BNX2X_ERR("DMAE timeout!\n");
  491. rc = DMAE_TIMEOUT;
  492. goto unlock;
  493. }
  494. cnt--;
  495. udelay(50);
  496. }
  497. if (*comp & DMAE_PCI_ERR_FLAG) {
  498. BNX2X_ERR("DMAE PCI error!\n");
  499. rc = DMAE_PCI_ERROR;
  500. }
  501. unlock:
  502. spin_unlock_bh(&bp->dmae_lock);
  503. return rc;
  504. }
  505. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  506. u32 len32)
  507. {
  508. int rc;
  509. struct dmae_command dmae;
  510. if (!bp->dmae_ready) {
  511. u32 *data = bnx2x_sp(bp, wb_data[0]);
  512. if (CHIP_IS_E1(bp))
  513. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  514. else
  515. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  516. return;
  517. }
  518. /* set opcode and fixed command fields */
  519. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  520. /* fill in addresses and len */
  521. dmae.src_addr_lo = U64_LO(dma_addr);
  522. dmae.src_addr_hi = U64_HI(dma_addr);
  523. dmae.dst_addr_lo = dst_addr >> 2;
  524. dmae.dst_addr_hi = 0;
  525. dmae.len = len32;
  526. /* issue the command and wait for completion */
  527. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  528. if (rc) {
  529. BNX2X_ERR("DMAE returned failure %d\n", rc);
  530. #ifdef BNX2X_STOP_ON_ERROR
  531. bnx2x_panic();
  532. #endif
  533. }
  534. }
  535. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  536. {
  537. int rc;
  538. struct dmae_command dmae;
  539. if (!bp->dmae_ready) {
  540. u32 *data = bnx2x_sp(bp, wb_data[0]);
  541. int i;
  542. if (CHIP_IS_E1(bp))
  543. for (i = 0; i < len32; i++)
  544. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  545. else
  546. for (i = 0; i < len32; i++)
  547. data[i] = REG_RD(bp, src_addr + i*4);
  548. return;
  549. }
  550. /* set opcode and fixed command fields */
  551. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  552. /* fill in addresses and len */
  553. dmae.src_addr_lo = src_addr >> 2;
  554. dmae.src_addr_hi = 0;
  555. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  556. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  557. dmae.len = len32;
  558. /* issue the command and wait for completion */
  559. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  560. if (rc) {
  561. BNX2X_ERR("DMAE returned failure %d\n", rc);
  562. #ifdef BNX2X_STOP_ON_ERROR
  563. bnx2x_panic();
  564. #endif
  565. }
  566. }
  567. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  568. u32 addr, u32 len)
  569. {
  570. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  571. int offset = 0;
  572. while (len > dmae_wr_max) {
  573. bnx2x_write_dmae(bp, phys_addr + offset,
  574. addr + offset, dmae_wr_max);
  575. offset += dmae_wr_max * 4;
  576. len -= dmae_wr_max;
  577. }
  578. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  579. }
  580. enum storms {
  581. XSTORM,
  582. TSTORM,
  583. CSTORM,
  584. USTORM,
  585. MAX_STORMS
  586. };
  587. #define STORMS_NUM 4
  588. #define REGS_IN_ENTRY 4
  589. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  590. enum storms storm,
  591. int entry)
  592. {
  593. switch (storm) {
  594. case XSTORM:
  595. return XSTORM_ASSERT_LIST_OFFSET(entry);
  596. case TSTORM:
  597. return TSTORM_ASSERT_LIST_OFFSET(entry);
  598. case CSTORM:
  599. return CSTORM_ASSERT_LIST_OFFSET(entry);
  600. case USTORM:
  601. return USTORM_ASSERT_LIST_OFFSET(entry);
  602. case MAX_STORMS:
  603. default:
  604. BNX2X_ERR("unknown storm\n");
  605. }
  606. return -EINVAL;
  607. }
  608. static int bnx2x_mc_assert(struct bnx2x *bp)
  609. {
  610. char last_idx;
  611. int i, j, rc = 0;
  612. enum storms storm;
  613. u32 regs[REGS_IN_ENTRY];
  614. u32 bar_storm_intmem[STORMS_NUM] = {
  615. BAR_XSTRORM_INTMEM,
  616. BAR_TSTRORM_INTMEM,
  617. BAR_CSTRORM_INTMEM,
  618. BAR_USTRORM_INTMEM
  619. };
  620. u32 storm_assert_list_index[STORMS_NUM] = {
  621. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  622. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  623. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  624. USTORM_ASSERT_LIST_INDEX_OFFSET
  625. };
  626. char *storms_string[STORMS_NUM] = {
  627. "XSTORM",
  628. "TSTORM",
  629. "CSTORM",
  630. "USTORM"
  631. };
  632. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  633. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  634. storm_assert_list_index[storm]);
  635. if (last_idx)
  636. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  637. storms_string[storm], last_idx);
  638. /* print the asserts */
  639. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  640. /* read a single assert entry */
  641. for (j = 0; j < REGS_IN_ENTRY; j++)
  642. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  643. bnx2x_get_assert_list_entry(bp,
  644. storm,
  645. i) +
  646. sizeof(u32) * j);
  647. /* log entry if it contains a valid assert */
  648. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  649. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  650. storms_string[storm], i, regs[3],
  651. regs[2], regs[1], regs[0]);
  652. rc++;
  653. } else {
  654. break;
  655. }
  656. }
  657. }
  658. BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
  659. CHIP_IS_E1(bp) ? "everest1" :
  660. CHIP_IS_E1H(bp) ? "everest1h" :
  661. CHIP_IS_E2(bp) ? "everest2" : "everest3",
  662. BCM_5710_FW_MAJOR_VERSION,
  663. BCM_5710_FW_MINOR_VERSION,
  664. BCM_5710_FW_REVISION_VERSION);
  665. return rc;
  666. }
  667. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  668. #define SCRATCH_BUFFER_SIZE(bp) \
  669. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  670. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  671. {
  672. u32 addr, val;
  673. u32 mark, offset;
  674. __be32 data[9];
  675. int word;
  676. u32 trace_shmem_base;
  677. if (BP_NOMCP(bp)) {
  678. BNX2X_ERR("NO MCP - can not dump\n");
  679. return;
  680. }
  681. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  682. (bp->common.bc_ver & 0xff0000) >> 16,
  683. (bp->common.bc_ver & 0xff00) >> 8,
  684. (bp->common.bc_ver & 0xff));
  685. if (pci_channel_offline(bp->pdev)) {
  686. BNX2X_ERR("Cannot dump MCP info while in PCI error\n");
  687. return;
  688. }
  689. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  690. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  691. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  692. if (BP_PATH(bp) == 0)
  693. trace_shmem_base = bp->common.shmem_base;
  694. else
  695. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  696. /* sanity */
  697. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  698. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  699. SCRATCH_BUFFER_SIZE(bp)) {
  700. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  701. trace_shmem_base);
  702. return;
  703. }
  704. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  705. /* validate TRCB signature */
  706. mark = REG_RD(bp, addr);
  707. if (mark != MFW_TRACE_SIGNATURE) {
  708. BNX2X_ERR("Trace buffer signature is missing.");
  709. return ;
  710. }
  711. /* read cyclic buffer pointer */
  712. addr += 4;
  713. mark = REG_RD(bp, addr);
  714. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  715. if (mark >= trace_shmem_base || mark < addr + 4) {
  716. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  717. return;
  718. }
  719. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  720. printk("%s", lvl);
  721. /* dump buffer after the mark */
  722. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  723. for (word = 0; word < 8; word++)
  724. data[word] = htonl(REG_RD(bp, offset + 4*word));
  725. data[8] = 0x0;
  726. pr_cont("%s", (char *)data);
  727. }
  728. /* dump buffer before the mark */
  729. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  730. for (word = 0; word < 8; word++)
  731. data[word] = htonl(REG_RD(bp, offset + 4*word));
  732. data[8] = 0x0;
  733. pr_cont("%s", (char *)data);
  734. }
  735. printk("%s" "end of fw dump\n", lvl);
  736. }
  737. static void bnx2x_fw_dump(struct bnx2x *bp)
  738. {
  739. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  740. }
  741. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  742. {
  743. int port = BP_PORT(bp);
  744. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  745. u32 val = REG_RD(bp, addr);
  746. /* in E1 we must use only PCI configuration space to disable
  747. * MSI/MSIX capability
  748. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  749. */
  750. if (CHIP_IS_E1(bp)) {
  751. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  752. * Use mask register to prevent from HC sending interrupts
  753. * after we exit the function
  754. */
  755. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  756. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  757. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  758. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  759. } else
  760. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  761. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  762. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  763. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  764. DP(NETIF_MSG_IFDOWN,
  765. "write %x to HC %d (addr 0x%x)\n",
  766. val, port, addr);
  767. /* flush all outstanding writes */
  768. mmiowb();
  769. REG_WR(bp, addr, val);
  770. if (REG_RD(bp, addr) != val)
  771. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  772. }
  773. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  774. {
  775. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  776. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  777. IGU_PF_CONF_INT_LINE_EN |
  778. IGU_PF_CONF_ATTN_BIT_EN);
  779. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  780. /* flush all outstanding writes */
  781. mmiowb();
  782. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  783. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  784. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  785. }
  786. static void bnx2x_int_disable(struct bnx2x *bp)
  787. {
  788. if (bp->common.int_block == INT_BLOCK_HC)
  789. bnx2x_hc_int_disable(bp);
  790. else
  791. bnx2x_igu_int_disable(bp);
  792. }
  793. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  794. {
  795. int i;
  796. u16 j;
  797. struct hc_sp_status_block_data sp_sb_data;
  798. int func = BP_FUNC(bp);
  799. #ifdef BNX2X_STOP_ON_ERROR
  800. u16 start = 0, end = 0;
  801. u8 cos;
  802. #endif
  803. if (IS_PF(bp) && disable_int)
  804. bnx2x_int_disable(bp);
  805. bp->stats_state = STATS_STATE_DISABLED;
  806. bp->eth_stats.unrecoverable_error++;
  807. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  808. BNX2X_ERR("begin crash dump -----------------\n");
  809. /* Indices */
  810. /* Common */
  811. if (IS_PF(bp)) {
  812. struct host_sp_status_block *def_sb = bp->def_status_blk;
  813. int data_size, cstorm_offset;
  814. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  815. bp->def_idx, bp->def_att_idx, bp->attn_state,
  816. bp->spq_prod_idx, bp->stats_counter);
  817. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  818. def_sb->atten_status_block.attn_bits,
  819. def_sb->atten_status_block.attn_bits_ack,
  820. def_sb->atten_status_block.status_block_id,
  821. def_sb->atten_status_block.attn_bits_index);
  822. BNX2X_ERR(" def (");
  823. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  824. pr_cont("0x%x%s",
  825. def_sb->sp_sb.index_values[i],
  826. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  827. data_size = sizeof(struct hc_sp_status_block_data) /
  828. sizeof(u32);
  829. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  830. for (i = 0; i < data_size; i++)
  831. *((u32 *)&sp_sb_data + i) =
  832. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  833. i * sizeof(u32));
  834. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
  835. sp_sb_data.igu_sb_id,
  836. sp_sb_data.igu_seg_id,
  837. sp_sb_data.p_func.pf_id,
  838. sp_sb_data.p_func.vnic_id,
  839. sp_sb_data.p_func.vf_id,
  840. sp_sb_data.p_func.vf_valid,
  841. sp_sb_data.state);
  842. }
  843. for_each_eth_queue(bp, i) {
  844. struct bnx2x_fastpath *fp = &bp->fp[i];
  845. int loop;
  846. struct hc_status_block_data_e2 sb_data_e2;
  847. struct hc_status_block_data_e1x sb_data_e1x;
  848. struct hc_status_block_sm *hc_sm_p =
  849. CHIP_IS_E1x(bp) ?
  850. sb_data_e1x.common.state_machine :
  851. sb_data_e2.common.state_machine;
  852. struct hc_index_data *hc_index_p =
  853. CHIP_IS_E1x(bp) ?
  854. sb_data_e1x.index_data :
  855. sb_data_e2.index_data;
  856. u8 data_size, cos;
  857. u32 *sb_data_p;
  858. struct bnx2x_fp_txdata txdata;
  859. if (!bp->fp)
  860. break;
  861. if (!fp->rx_cons_sb)
  862. continue;
  863. /* Rx */
  864. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  865. i, fp->rx_bd_prod, fp->rx_bd_cons,
  866. fp->rx_comp_prod,
  867. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  868. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  869. fp->rx_sge_prod, fp->last_max_sge,
  870. le16_to_cpu(fp->fp_hc_idx));
  871. /* Tx */
  872. for_each_cos_in_tx_queue(fp, cos)
  873. {
  874. if (!fp->txdata_ptr[cos])
  875. break;
  876. txdata = *fp->txdata_ptr[cos];
  877. if (!txdata.tx_cons_sb)
  878. continue;
  879. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  880. i, txdata.tx_pkt_prod,
  881. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  882. txdata.tx_bd_cons,
  883. le16_to_cpu(*txdata.tx_cons_sb));
  884. }
  885. loop = CHIP_IS_E1x(bp) ?
  886. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  887. /* host sb data */
  888. if (IS_FCOE_FP(fp))
  889. continue;
  890. BNX2X_ERR(" run indexes (");
  891. for (j = 0; j < HC_SB_MAX_SM; j++)
  892. pr_cont("0x%x%s",
  893. fp->sb_running_index[j],
  894. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  895. BNX2X_ERR(" indexes (");
  896. for (j = 0; j < loop; j++)
  897. pr_cont("0x%x%s",
  898. fp->sb_index_values[j],
  899. (j == loop - 1) ? ")" : " ");
  900. /* VF cannot access FW refelection for status block */
  901. if (IS_VF(bp))
  902. continue;
  903. /* fw sb data */
  904. data_size = CHIP_IS_E1x(bp) ?
  905. sizeof(struct hc_status_block_data_e1x) :
  906. sizeof(struct hc_status_block_data_e2);
  907. data_size /= sizeof(u32);
  908. sb_data_p = CHIP_IS_E1x(bp) ?
  909. (u32 *)&sb_data_e1x :
  910. (u32 *)&sb_data_e2;
  911. /* copy sb data in here */
  912. for (j = 0; j < data_size; j++)
  913. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  914. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  915. j * sizeof(u32));
  916. if (!CHIP_IS_E1x(bp)) {
  917. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  918. sb_data_e2.common.p_func.pf_id,
  919. sb_data_e2.common.p_func.vf_id,
  920. sb_data_e2.common.p_func.vf_valid,
  921. sb_data_e2.common.p_func.vnic_id,
  922. sb_data_e2.common.same_igu_sb_1b,
  923. sb_data_e2.common.state);
  924. } else {
  925. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  926. sb_data_e1x.common.p_func.pf_id,
  927. sb_data_e1x.common.p_func.vf_id,
  928. sb_data_e1x.common.p_func.vf_valid,
  929. sb_data_e1x.common.p_func.vnic_id,
  930. sb_data_e1x.common.same_igu_sb_1b,
  931. sb_data_e1x.common.state);
  932. }
  933. /* SB_SMs data */
  934. for (j = 0; j < HC_SB_MAX_SM; j++) {
  935. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  936. j, hc_sm_p[j].__flags,
  937. hc_sm_p[j].igu_sb_id,
  938. hc_sm_p[j].igu_seg_id,
  939. hc_sm_p[j].time_to_expire,
  940. hc_sm_p[j].timer_value);
  941. }
  942. /* Indices data */
  943. for (j = 0; j < loop; j++) {
  944. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  945. hc_index_p[j].flags,
  946. hc_index_p[j].timeout);
  947. }
  948. }
  949. #ifdef BNX2X_STOP_ON_ERROR
  950. if (IS_PF(bp)) {
  951. /* event queue */
  952. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  953. for (i = 0; i < NUM_EQ_DESC; i++) {
  954. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  955. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  956. i, bp->eq_ring[i].message.opcode,
  957. bp->eq_ring[i].message.error);
  958. BNX2X_ERR("data: %x %x %x\n",
  959. data[0], data[1], data[2]);
  960. }
  961. }
  962. /* Rings */
  963. /* Rx */
  964. for_each_valid_rx_queue(bp, i) {
  965. struct bnx2x_fastpath *fp = &bp->fp[i];
  966. if (!bp->fp)
  967. break;
  968. if (!fp->rx_cons_sb)
  969. continue;
  970. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  971. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  972. for (j = start; j != end; j = RX_BD(j + 1)) {
  973. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  974. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  975. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  976. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  977. }
  978. start = RX_SGE(fp->rx_sge_prod);
  979. end = RX_SGE(fp->last_max_sge);
  980. for (j = start; j != end; j = RX_SGE(j + 1)) {
  981. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  982. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  983. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  984. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  985. }
  986. start = RCQ_BD(fp->rx_comp_cons - 10);
  987. end = RCQ_BD(fp->rx_comp_cons + 503);
  988. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  989. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  990. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  991. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  992. }
  993. }
  994. /* Tx */
  995. for_each_valid_tx_queue(bp, i) {
  996. struct bnx2x_fastpath *fp = &bp->fp[i];
  997. if (!bp->fp)
  998. break;
  999. for_each_cos_in_tx_queue(fp, cos) {
  1000. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  1001. if (!fp->txdata_ptr[cos])
  1002. break;
  1003. if (!txdata->tx_cons_sb)
  1004. continue;
  1005. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  1006. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  1007. for (j = start; j != end; j = TX_BD(j + 1)) {
  1008. struct sw_tx_bd *sw_bd =
  1009. &txdata->tx_buf_ring[j];
  1010. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1011. i, cos, j, sw_bd->skb,
  1012. sw_bd->first_bd);
  1013. }
  1014. start = TX_BD(txdata->tx_bd_cons - 10);
  1015. end = TX_BD(txdata->tx_bd_cons + 254);
  1016. for (j = start; j != end; j = TX_BD(j + 1)) {
  1017. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1018. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1019. i, cos, j, tx_bd[0], tx_bd[1],
  1020. tx_bd[2], tx_bd[3]);
  1021. }
  1022. }
  1023. }
  1024. #endif
  1025. if (IS_PF(bp)) {
  1026. bnx2x_fw_dump(bp);
  1027. bnx2x_mc_assert(bp);
  1028. }
  1029. BNX2X_ERR("end crash dump -----------------\n");
  1030. }
  1031. /*
  1032. * FLR Support for E2
  1033. *
  1034. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1035. * initialization.
  1036. */
  1037. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1038. #define FLR_WAIT_INTERVAL 50 /* usec */
  1039. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1040. struct pbf_pN_buf_regs {
  1041. int pN;
  1042. u32 init_crd;
  1043. u32 crd;
  1044. u32 crd_freed;
  1045. };
  1046. struct pbf_pN_cmd_regs {
  1047. int pN;
  1048. u32 lines_occup;
  1049. u32 lines_freed;
  1050. };
  1051. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1052. struct pbf_pN_buf_regs *regs,
  1053. u32 poll_count)
  1054. {
  1055. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1056. u32 cur_cnt = poll_count;
  1057. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1058. crd = crd_start = REG_RD(bp, regs->crd);
  1059. init_crd = REG_RD(bp, regs->init_crd);
  1060. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1061. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1062. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1063. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1064. (init_crd - crd_start))) {
  1065. if (cur_cnt--) {
  1066. udelay(FLR_WAIT_INTERVAL);
  1067. crd = REG_RD(bp, regs->crd);
  1068. crd_freed = REG_RD(bp, regs->crd_freed);
  1069. } else {
  1070. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1071. regs->pN);
  1072. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1073. regs->pN, crd);
  1074. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1075. regs->pN, crd_freed);
  1076. break;
  1077. }
  1078. }
  1079. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1080. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1081. }
  1082. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1083. struct pbf_pN_cmd_regs *regs,
  1084. u32 poll_count)
  1085. {
  1086. u32 occup, to_free, freed, freed_start;
  1087. u32 cur_cnt = poll_count;
  1088. occup = to_free = REG_RD(bp, regs->lines_occup);
  1089. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1090. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1091. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1092. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1093. if (cur_cnt--) {
  1094. udelay(FLR_WAIT_INTERVAL);
  1095. occup = REG_RD(bp, regs->lines_occup);
  1096. freed = REG_RD(bp, regs->lines_freed);
  1097. } else {
  1098. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1099. regs->pN);
  1100. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1101. regs->pN, occup);
  1102. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1103. regs->pN, freed);
  1104. break;
  1105. }
  1106. }
  1107. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1108. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1109. }
  1110. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1111. u32 expected, u32 poll_count)
  1112. {
  1113. u32 cur_cnt = poll_count;
  1114. u32 val;
  1115. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1116. udelay(FLR_WAIT_INTERVAL);
  1117. return val;
  1118. }
  1119. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1120. char *msg, u32 poll_cnt)
  1121. {
  1122. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1123. if (val != 0) {
  1124. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1125. return 1;
  1126. }
  1127. return 0;
  1128. }
  1129. /* Common routines with VF FLR cleanup */
  1130. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1131. {
  1132. /* adjust polling timeout */
  1133. if (CHIP_REV_IS_EMUL(bp))
  1134. return FLR_POLL_CNT * 2000;
  1135. if (CHIP_REV_IS_FPGA(bp))
  1136. return FLR_POLL_CNT * 120;
  1137. return FLR_POLL_CNT;
  1138. }
  1139. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1140. {
  1141. struct pbf_pN_cmd_regs cmd_regs[] = {
  1142. {0, (CHIP_IS_E3B0(bp)) ?
  1143. PBF_REG_TQ_OCCUPANCY_Q0 :
  1144. PBF_REG_P0_TQ_OCCUPANCY,
  1145. (CHIP_IS_E3B0(bp)) ?
  1146. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1147. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1148. {1, (CHIP_IS_E3B0(bp)) ?
  1149. PBF_REG_TQ_OCCUPANCY_Q1 :
  1150. PBF_REG_P1_TQ_OCCUPANCY,
  1151. (CHIP_IS_E3B0(bp)) ?
  1152. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1153. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1154. {4, (CHIP_IS_E3B0(bp)) ?
  1155. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1156. PBF_REG_P4_TQ_OCCUPANCY,
  1157. (CHIP_IS_E3B0(bp)) ?
  1158. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1159. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1160. };
  1161. struct pbf_pN_buf_regs buf_regs[] = {
  1162. {0, (CHIP_IS_E3B0(bp)) ?
  1163. PBF_REG_INIT_CRD_Q0 :
  1164. PBF_REG_P0_INIT_CRD ,
  1165. (CHIP_IS_E3B0(bp)) ?
  1166. PBF_REG_CREDIT_Q0 :
  1167. PBF_REG_P0_CREDIT,
  1168. (CHIP_IS_E3B0(bp)) ?
  1169. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1170. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1171. {1, (CHIP_IS_E3B0(bp)) ?
  1172. PBF_REG_INIT_CRD_Q1 :
  1173. PBF_REG_P1_INIT_CRD,
  1174. (CHIP_IS_E3B0(bp)) ?
  1175. PBF_REG_CREDIT_Q1 :
  1176. PBF_REG_P1_CREDIT,
  1177. (CHIP_IS_E3B0(bp)) ?
  1178. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1179. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1180. {4, (CHIP_IS_E3B0(bp)) ?
  1181. PBF_REG_INIT_CRD_LB_Q :
  1182. PBF_REG_P4_INIT_CRD,
  1183. (CHIP_IS_E3B0(bp)) ?
  1184. PBF_REG_CREDIT_LB_Q :
  1185. PBF_REG_P4_CREDIT,
  1186. (CHIP_IS_E3B0(bp)) ?
  1187. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1188. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1189. };
  1190. int i;
  1191. /* Verify the command queues are flushed P0, P1, P4 */
  1192. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1193. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1194. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1195. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1196. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1197. }
  1198. #define OP_GEN_PARAM(param) \
  1199. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1200. #define OP_GEN_TYPE(type) \
  1201. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1202. #define OP_GEN_AGG_VECT(index) \
  1203. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1204. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1205. {
  1206. u32 op_gen_command = 0;
  1207. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1208. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1209. int ret = 0;
  1210. if (REG_RD(bp, comp_addr)) {
  1211. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1212. return 1;
  1213. }
  1214. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1215. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1216. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1217. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1218. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1219. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1220. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1221. BNX2X_ERR("FW final cleanup did not succeed\n");
  1222. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1223. (REG_RD(bp, comp_addr)));
  1224. bnx2x_panic();
  1225. return 1;
  1226. }
  1227. /* Zero completion for next FLR */
  1228. REG_WR(bp, comp_addr, 0);
  1229. return ret;
  1230. }
  1231. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1232. {
  1233. u16 status;
  1234. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1235. return status & PCI_EXP_DEVSTA_TRPND;
  1236. }
  1237. /* PF FLR specific routines
  1238. */
  1239. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1240. {
  1241. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1242. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1243. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1244. "CFC PF usage counter timed out",
  1245. poll_cnt))
  1246. return 1;
  1247. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1248. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1249. DORQ_REG_PF_USAGE_CNT,
  1250. "DQ PF usage counter timed out",
  1251. poll_cnt))
  1252. return 1;
  1253. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1254. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1255. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1256. "QM PF usage counter timed out",
  1257. poll_cnt))
  1258. return 1;
  1259. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1260. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1261. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1262. "Timers VNIC usage counter timed out",
  1263. poll_cnt))
  1264. return 1;
  1265. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1266. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1267. "Timers NUM_SCANS usage counter timed out",
  1268. poll_cnt))
  1269. return 1;
  1270. /* Wait DMAE PF usage counter to zero */
  1271. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1272. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1273. "DMAE command register timed out",
  1274. poll_cnt))
  1275. return 1;
  1276. return 0;
  1277. }
  1278. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1279. {
  1280. u32 val;
  1281. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1282. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1283. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1284. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1285. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1286. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1287. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1288. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1289. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1290. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1291. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1292. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1293. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1294. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1295. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1296. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1297. val);
  1298. }
  1299. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1300. {
  1301. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1302. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1303. /* Re-enable PF target read access */
  1304. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1305. /* Poll HW usage counters */
  1306. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1307. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1308. return -EBUSY;
  1309. /* Zero the igu 'trailing edge' and 'leading edge' */
  1310. /* Send the FW cleanup command */
  1311. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1312. return -EBUSY;
  1313. /* ATC cleanup */
  1314. /* Verify TX hw is flushed */
  1315. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1316. /* Wait 100ms (not adjusted according to platform) */
  1317. msleep(100);
  1318. /* Verify no pending pci transactions */
  1319. if (bnx2x_is_pcie_pending(bp->pdev))
  1320. BNX2X_ERR("PCIE Transactions still pending\n");
  1321. /* Debug */
  1322. bnx2x_hw_enable_status(bp);
  1323. /*
  1324. * Master enable - Due to WB DMAE writes performed before this
  1325. * register is re-initialized as part of the regular function init
  1326. */
  1327. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1328. return 0;
  1329. }
  1330. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1331. {
  1332. int port = BP_PORT(bp);
  1333. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1334. u32 val = REG_RD(bp, addr);
  1335. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1336. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1337. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1338. if (msix) {
  1339. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1340. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1341. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1342. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1343. if (single_msix)
  1344. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1345. } else if (msi) {
  1346. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1347. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1348. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1349. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1350. } else {
  1351. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1352. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1353. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1354. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1355. if (!CHIP_IS_E1(bp)) {
  1356. DP(NETIF_MSG_IFUP,
  1357. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1358. REG_WR(bp, addr, val);
  1359. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1360. }
  1361. }
  1362. if (CHIP_IS_E1(bp))
  1363. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1364. DP(NETIF_MSG_IFUP,
  1365. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1366. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1367. REG_WR(bp, addr, val);
  1368. /*
  1369. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1370. */
  1371. mmiowb();
  1372. barrier();
  1373. if (!CHIP_IS_E1(bp)) {
  1374. /* init leading/trailing edge */
  1375. if (IS_MF(bp)) {
  1376. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1377. if (bp->port.pmf)
  1378. /* enable nig and gpio3 attention */
  1379. val |= 0x1100;
  1380. } else
  1381. val = 0xffff;
  1382. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1383. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1384. }
  1385. /* Make sure that interrupts are indeed enabled from here on */
  1386. mmiowb();
  1387. }
  1388. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1389. {
  1390. u32 val;
  1391. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1392. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1393. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1394. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1395. if (msix) {
  1396. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1397. IGU_PF_CONF_SINGLE_ISR_EN);
  1398. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1399. IGU_PF_CONF_ATTN_BIT_EN);
  1400. if (single_msix)
  1401. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1402. } else if (msi) {
  1403. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1404. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1405. IGU_PF_CONF_ATTN_BIT_EN |
  1406. IGU_PF_CONF_SINGLE_ISR_EN);
  1407. } else {
  1408. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1409. val |= (IGU_PF_CONF_INT_LINE_EN |
  1410. IGU_PF_CONF_ATTN_BIT_EN |
  1411. IGU_PF_CONF_SINGLE_ISR_EN);
  1412. }
  1413. /* Clean previous status - need to configure igu prior to ack*/
  1414. if ((!msix) || single_msix) {
  1415. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1416. bnx2x_ack_int(bp);
  1417. }
  1418. val |= IGU_PF_CONF_FUNC_EN;
  1419. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1420. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1421. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1422. if (val & IGU_PF_CONF_INT_LINE_EN)
  1423. pci_intx(bp->pdev, true);
  1424. barrier();
  1425. /* init leading/trailing edge */
  1426. if (IS_MF(bp)) {
  1427. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1428. if (bp->port.pmf)
  1429. /* enable nig and gpio3 attention */
  1430. val |= 0x1100;
  1431. } else
  1432. val = 0xffff;
  1433. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1434. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1435. /* Make sure that interrupts are indeed enabled from here on */
  1436. mmiowb();
  1437. }
  1438. void bnx2x_int_enable(struct bnx2x *bp)
  1439. {
  1440. if (bp->common.int_block == INT_BLOCK_HC)
  1441. bnx2x_hc_int_enable(bp);
  1442. else
  1443. bnx2x_igu_int_enable(bp);
  1444. }
  1445. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1446. {
  1447. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1448. int i, offset;
  1449. if (disable_hw)
  1450. /* prevent the HW from sending interrupts */
  1451. bnx2x_int_disable(bp);
  1452. /* make sure all ISRs are done */
  1453. if (msix) {
  1454. synchronize_irq(bp->msix_table[0].vector);
  1455. offset = 1;
  1456. if (CNIC_SUPPORT(bp))
  1457. offset++;
  1458. for_each_eth_queue(bp, i)
  1459. synchronize_irq(bp->msix_table[offset++].vector);
  1460. } else
  1461. synchronize_irq(bp->pdev->irq);
  1462. /* make sure sp_task is not running */
  1463. cancel_delayed_work(&bp->sp_task);
  1464. cancel_delayed_work(&bp->period_task);
  1465. flush_workqueue(bnx2x_wq);
  1466. }
  1467. /* fast path */
  1468. /*
  1469. * General service functions
  1470. */
  1471. /* Return true if succeeded to acquire the lock */
  1472. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1473. {
  1474. u32 lock_status;
  1475. u32 resource_bit = (1 << resource);
  1476. int func = BP_FUNC(bp);
  1477. u32 hw_lock_control_reg;
  1478. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1479. "Trying to take a lock on resource %d\n", resource);
  1480. /* Validating that the resource is within range */
  1481. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1482. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1483. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1484. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1485. return false;
  1486. }
  1487. if (func <= 5)
  1488. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1489. else
  1490. hw_lock_control_reg =
  1491. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1492. /* Try to acquire the lock */
  1493. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1494. lock_status = REG_RD(bp, hw_lock_control_reg);
  1495. if (lock_status & resource_bit)
  1496. return true;
  1497. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1498. "Failed to get a lock on resource %d\n", resource);
  1499. return false;
  1500. }
  1501. /**
  1502. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1503. *
  1504. * @bp: driver handle
  1505. *
  1506. * Returns the recovery leader resource id according to the engine this function
  1507. * belongs to. Currently only only 2 engines is supported.
  1508. */
  1509. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1510. {
  1511. if (BP_PATH(bp))
  1512. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1513. else
  1514. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1515. }
  1516. /**
  1517. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1518. *
  1519. * @bp: driver handle
  1520. *
  1521. * Tries to acquire a leader lock for current engine.
  1522. */
  1523. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1524. {
  1525. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1526. }
  1527. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1528. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1529. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1530. {
  1531. /* Set the interrupt occurred bit for the sp-task to recognize it
  1532. * must ack the interrupt and transition according to the IGU
  1533. * state machine.
  1534. */
  1535. atomic_set(&bp->interrupt_occurred, 1);
  1536. /* The sp_task must execute only after this bit
  1537. * is set, otherwise we will get out of sync and miss all
  1538. * further interrupts. Hence, the barrier.
  1539. */
  1540. smp_wmb();
  1541. /* schedule sp_task to workqueue */
  1542. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1543. }
  1544. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1545. {
  1546. struct bnx2x *bp = fp->bp;
  1547. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1548. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1549. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1550. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1551. DP(BNX2X_MSG_SP,
  1552. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1553. fp->index, cid, command, bp->state,
  1554. rr_cqe->ramrod_cqe.ramrod_type);
  1555. /* If cid is within VF range, replace the slowpath object with the
  1556. * one corresponding to this VF
  1557. */
  1558. if (cid >= BNX2X_FIRST_VF_CID &&
  1559. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1560. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1561. switch (command) {
  1562. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1563. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1564. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1565. break;
  1566. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1567. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1568. drv_cmd = BNX2X_Q_CMD_SETUP;
  1569. break;
  1570. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1571. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1572. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1573. break;
  1574. case (RAMROD_CMD_ID_ETH_HALT):
  1575. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1576. drv_cmd = BNX2X_Q_CMD_HALT;
  1577. break;
  1578. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1579. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1580. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1581. break;
  1582. case (RAMROD_CMD_ID_ETH_EMPTY):
  1583. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1584. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1585. break;
  1586. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1587. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1588. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1589. break;
  1590. default:
  1591. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1592. command, fp->index);
  1593. return;
  1594. }
  1595. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1596. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1597. /* q_obj->complete_cmd() failure means that this was
  1598. * an unexpected completion.
  1599. *
  1600. * In this case we don't want to increase the bp->spq_left
  1601. * because apparently we haven't sent this command the first
  1602. * place.
  1603. */
  1604. #ifdef BNX2X_STOP_ON_ERROR
  1605. bnx2x_panic();
  1606. #else
  1607. return;
  1608. #endif
  1609. smp_mb__before_atomic();
  1610. atomic_inc(&bp->cq_spq_left);
  1611. /* push the change in bp->spq_left and towards the memory */
  1612. smp_mb__after_atomic();
  1613. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1614. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1615. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1616. /* if Q update ramrod is completed for last Q in AFEX vif set
  1617. * flow, then ACK MCP at the end
  1618. *
  1619. * mark pending ACK to MCP bit.
  1620. * prevent case that both bits are cleared.
  1621. * At the end of load/unload driver checks that
  1622. * sp_state is cleared, and this order prevents
  1623. * races
  1624. */
  1625. smp_mb__before_atomic();
  1626. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1627. wmb();
  1628. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1629. smp_mb__after_atomic();
  1630. /* schedule the sp task as mcp ack is required */
  1631. bnx2x_schedule_sp_task(bp);
  1632. }
  1633. return;
  1634. }
  1635. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1636. {
  1637. struct bnx2x *bp = netdev_priv(dev_instance);
  1638. u16 status = bnx2x_ack_int(bp);
  1639. u16 mask;
  1640. int i;
  1641. u8 cos;
  1642. /* Return here if interrupt is shared and it's not for us */
  1643. if (unlikely(status == 0)) {
  1644. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1645. return IRQ_NONE;
  1646. }
  1647. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1648. #ifdef BNX2X_STOP_ON_ERROR
  1649. if (unlikely(bp->panic))
  1650. return IRQ_HANDLED;
  1651. #endif
  1652. for_each_eth_queue(bp, i) {
  1653. struct bnx2x_fastpath *fp = &bp->fp[i];
  1654. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1655. if (status & mask) {
  1656. /* Handle Rx or Tx according to SB id */
  1657. for_each_cos_in_tx_queue(fp, cos)
  1658. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1659. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1660. napi_schedule_irqoff(&bnx2x_fp(bp, fp->index, napi));
  1661. status &= ~mask;
  1662. }
  1663. }
  1664. if (CNIC_SUPPORT(bp)) {
  1665. mask = 0x2;
  1666. if (status & (mask | 0x1)) {
  1667. struct cnic_ops *c_ops = NULL;
  1668. rcu_read_lock();
  1669. c_ops = rcu_dereference(bp->cnic_ops);
  1670. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1671. CNIC_DRV_STATE_HANDLES_IRQ))
  1672. c_ops->cnic_handler(bp->cnic_data, NULL);
  1673. rcu_read_unlock();
  1674. status &= ~mask;
  1675. }
  1676. }
  1677. if (unlikely(status & 0x1)) {
  1678. /* schedule sp task to perform default status block work, ack
  1679. * attentions and enable interrupts.
  1680. */
  1681. bnx2x_schedule_sp_task(bp);
  1682. status &= ~0x1;
  1683. if (!status)
  1684. return IRQ_HANDLED;
  1685. }
  1686. if (unlikely(status))
  1687. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1688. status);
  1689. return IRQ_HANDLED;
  1690. }
  1691. /* Link */
  1692. /*
  1693. * General service functions
  1694. */
  1695. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1696. {
  1697. u32 lock_status;
  1698. u32 resource_bit = (1 << resource);
  1699. int func = BP_FUNC(bp);
  1700. u32 hw_lock_control_reg;
  1701. int cnt;
  1702. /* Validating that the resource is within range */
  1703. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1704. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1705. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1706. return -EINVAL;
  1707. }
  1708. if (func <= 5) {
  1709. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1710. } else {
  1711. hw_lock_control_reg =
  1712. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1713. }
  1714. /* Validating that the resource is not already taken */
  1715. lock_status = REG_RD(bp, hw_lock_control_reg);
  1716. if (lock_status & resource_bit) {
  1717. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1718. lock_status, resource_bit);
  1719. return -EEXIST;
  1720. }
  1721. /* Try for 5 second every 5ms */
  1722. for (cnt = 0; cnt < 1000; cnt++) {
  1723. /* Try to acquire the lock */
  1724. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1725. lock_status = REG_RD(bp, hw_lock_control_reg);
  1726. if (lock_status & resource_bit)
  1727. return 0;
  1728. usleep_range(5000, 10000);
  1729. }
  1730. BNX2X_ERR("Timeout\n");
  1731. return -EAGAIN;
  1732. }
  1733. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1734. {
  1735. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1736. }
  1737. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1738. {
  1739. u32 lock_status;
  1740. u32 resource_bit = (1 << resource);
  1741. int func = BP_FUNC(bp);
  1742. u32 hw_lock_control_reg;
  1743. /* Validating that the resource is within range */
  1744. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1745. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1746. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1747. return -EINVAL;
  1748. }
  1749. if (func <= 5) {
  1750. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1751. } else {
  1752. hw_lock_control_reg =
  1753. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1754. }
  1755. /* Validating that the resource is currently taken */
  1756. lock_status = REG_RD(bp, hw_lock_control_reg);
  1757. if (!(lock_status & resource_bit)) {
  1758. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1759. lock_status, resource_bit);
  1760. return -EFAULT;
  1761. }
  1762. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1763. return 0;
  1764. }
  1765. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1766. {
  1767. /* The GPIO should be swapped if swap register is set and active */
  1768. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1769. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1770. int gpio_shift = gpio_num +
  1771. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1772. u32 gpio_mask = (1 << gpio_shift);
  1773. u32 gpio_reg;
  1774. int value;
  1775. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1776. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1777. return -EINVAL;
  1778. }
  1779. /* read GPIO value */
  1780. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1781. /* get the requested pin value */
  1782. if ((gpio_reg & gpio_mask) == gpio_mask)
  1783. value = 1;
  1784. else
  1785. value = 0;
  1786. return value;
  1787. }
  1788. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1789. {
  1790. /* The GPIO should be swapped if swap register is set and active */
  1791. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1792. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1793. int gpio_shift = gpio_num +
  1794. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1795. u32 gpio_mask = (1 << gpio_shift);
  1796. u32 gpio_reg;
  1797. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1798. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1799. return -EINVAL;
  1800. }
  1801. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1802. /* read GPIO and mask except the float bits */
  1803. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1804. switch (mode) {
  1805. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1806. DP(NETIF_MSG_LINK,
  1807. "Set GPIO %d (shift %d) -> output low\n",
  1808. gpio_num, gpio_shift);
  1809. /* clear FLOAT and set CLR */
  1810. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1811. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1812. break;
  1813. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1814. DP(NETIF_MSG_LINK,
  1815. "Set GPIO %d (shift %d) -> output high\n",
  1816. gpio_num, gpio_shift);
  1817. /* clear FLOAT and set SET */
  1818. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1819. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1820. break;
  1821. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1822. DP(NETIF_MSG_LINK,
  1823. "Set GPIO %d (shift %d) -> input\n",
  1824. gpio_num, gpio_shift);
  1825. /* set FLOAT */
  1826. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1827. break;
  1828. default:
  1829. break;
  1830. }
  1831. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1832. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1833. return 0;
  1834. }
  1835. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1836. {
  1837. u32 gpio_reg = 0;
  1838. int rc = 0;
  1839. /* Any port swapping should be handled by caller. */
  1840. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1841. /* read GPIO and mask except the float bits */
  1842. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1843. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1844. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1845. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1846. switch (mode) {
  1847. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1848. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1849. /* set CLR */
  1850. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1851. break;
  1852. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1853. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1854. /* set SET */
  1855. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1856. break;
  1857. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1858. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1859. /* set FLOAT */
  1860. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1861. break;
  1862. default:
  1863. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1864. rc = -EINVAL;
  1865. break;
  1866. }
  1867. if (rc == 0)
  1868. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1869. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1870. return rc;
  1871. }
  1872. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1873. {
  1874. /* The GPIO should be swapped if swap register is set and active */
  1875. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1876. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1877. int gpio_shift = gpio_num +
  1878. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1879. u32 gpio_mask = (1 << gpio_shift);
  1880. u32 gpio_reg;
  1881. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1882. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1883. return -EINVAL;
  1884. }
  1885. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1886. /* read GPIO int */
  1887. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1888. switch (mode) {
  1889. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1890. DP(NETIF_MSG_LINK,
  1891. "Clear GPIO INT %d (shift %d) -> output low\n",
  1892. gpio_num, gpio_shift);
  1893. /* clear SET and set CLR */
  1894. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1895. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1896. break;
  1897. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1898. DP(NETIF_MSG_LINK,
  1899. "Set GPIO INT %d (shift %d) -> output high\n",
  1900. gpio_num, gpio_shift);
  1901. /* clear CLR and set SET */
  1902. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1903. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1904. break;
  1905. default:
  1906. break;
  1907. }
  1908. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1909. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1910. return 0;
  1911. }
  1912. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1913. {
  1914. u32 spio_reg;
  1915. /* Only 2 SPIOs are configurable */
  1916. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1917. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1918. return -EINVAL;
  1919. }
  1920. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1921. /* read SPIO and mask except the float bits */
  1922. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1923. switch (mode) {
  1924. case MISC_SPIO_OUTPUT_LOW:
  1925. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1926. /* clear FLOAT and set CLR */
  1927. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1928. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1929. break;
  1930. case MISC_SPIO_OUTPUT_HIGH:
  1931. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1932. /* clear FLOAT and set SET */
  1933. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1934. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1935. break;
  1936. case MISC_SPIO_INPUT_HI_Z:
  1937. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1938. /* set FLOAT */
  1939. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1940. break;
  1941. default:
  1942. break;
  1943. }
  1944. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1945. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1946. return 0;
  1947. }
  1948. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1949. {
  1950. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1951. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1952. ADVERTISED_Pause);
  1953. switch (bp->link_vars.ieee_fc &
  1954. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1955. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1956. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1957. ADVERTISED_Pause);
  1958. break;
  1959. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1960. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1961. break;
  1962. default:
  1963. break;
  1964. }
  1965. }
  1966. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1967. {
  1968. /* Initialize link parameters structure variables
  1969. * It is recommended to turn off RX FC for jumbo frames
  1970. * for better performance
  1971. */
  1972. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1973. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1974. else
  1975. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1976. }
  1977. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1978. {
  1979. u32 pause_enabled = 0;
  1980. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1981. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1982. pause_enabled = 1;
  1983. REG_WR(bp, BAR_USTRORM_INTMEM +
  1984. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1985. pause_enabled);
  1986. }
  1987. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1988. pause_enabled ? "enabled" : "disabled");
  1989. }
  1990. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1991. {
  1992. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1993. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1994. if (!BP_NOMCP(bp)) {
  1995. bnx2x_set_requested_fc(bp);
  1996. bnx2x_acquire_phy_lock(bp);
  1997. if (load_mode == LOAD_DIAG) {
  1998. struct link_params *lp = &bp->link_params;
  1999. lp->loopback_mode = LOOPBACK_XGXS;
  2000. /* Prefer doing PHY loopback at highest speed */
  2001. if (lp->req_line_speed[cfx_idx] < SPEED_20000) {
  2002. if (lp->speed_cap_mask[cfx_idx] &
  2003. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
  2004. lp->req_line_speed[cfx_idx] =
  2005. SPEED_20000;
  2006. else if (lp->speed_cap_mask[cfx_idx] &
  2007. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  2008. lp->req_line_speed[cfx_idx] =
  2009. SPEED_10000;
  2010. else
  2011. lp->req_line_speed[cfx_idx] =
  2012. SPEED_1000;
  2013. }
  2014. }
  2015. if (load_mode == LOAD_LOOPBACK_EXT) {
  2016. struct link_params *lp = &bp->link_params;
  2017. lp->loopback_mode = LOOPBACK_EXT;
  2018. }
  2019. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2020. bnx2x_release_phy_lock(bp);
  2021. bnx2x_init_dropless_fc(bp);
  2022. bnx2x_calc_fc_adv(bp);
  2023. if (bp->link_vars.link_up) {
  2024. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2025. bnx2x_link_report(bp);
  2026. }
  2027. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2028. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2029. return rc;
  2030. }
  2031. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2032. return -EINVAL;
  2033. }
  2034. void bnx2x_link_set(struct bnx2x *bp)
  2035. {
  2036. if (!BP_NOMCP(bp)) {
  2037. bnx2x_acquire_phy_lock(bp);
  2038. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2039. bnx2x_release_phy_lock(bp);
  2040. bnx2x_init_dropless_fc(bp);
  2041. bnx2x_calc_fc_adv(bp);
  2042. } else
  2043. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2044. }
  2045. static void bnx2x__link_reset(struct bnx2x *bp)
  2046. {
  2047. if (!BP_NOMCP(bp)) {
  2048. bnx2x_acquire_phy_lock(bp);
  2049. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2050. bnx2x_release_phy_lock(bp);
  2051. } else
  2052. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2053. }
  2054. void bnx2x_force_link_reset(struct bnx2x *bp)
  2055. {
  2056. bnx2x_acquire_phy_lock(bp);
  2057. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2058. bnx2x_release_phy_lock(bp);
  2059. }
  2060. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2061. {
  2062. u8 rc = 0;
  2063. if (!BP_NOMCP(bp)) {
  2064. bnx2x_acquire_phy_lock(bp);
  2065. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2066. is_serdes);
  2067. bnx2x_release_phy_lock(bp);
  2068. } else
  2069. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2070. return rc;
  2071. }
  2072. /* Calculates the sum of vn_min_rates.
  2073. It's needed for further normalizing of the min_rates.
  2074. Returns:
  2075. sum of vn_min_rates.
  2076. or
  2077. 0 - if all the min_rates are 0.
  2078. In the later case fairness algorithm should be deactivated.
  2079. If not all min_rates are zero then those that are zeroes will be set to 1.
  2080. */
  2081. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2082. struct cmng_init_input *input)
  2083. {
  2084. int all_zero = 1;
  2085. int vn;
  2086. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2087. u32 vn_cfg = bp->mf_config[vn];
  2088. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2089. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2090. /* Skip hidden vns */
  2091. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2092. vn_min_rate = 0;
  2093. /* If min rate is zero - set it to 1 */
  2094. else if (!vn_min_rate)
  2095. vn_min_rate = DEF_MIN_RATE;
  2096. else
  2097. all_zero = 0;
  2098. input->vnic_min_rate[vn] = vn_min_rate;
  2099. }
  2100. /* if ETS or all min rates are zeros - disable fairness */
  2101. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2102. input->flags.cmng_enables &=
  2103. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2104. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2105. } else if (all_zero) {
  2106. input->flags.cmng_enables &=
  2107. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2108. DP(NETIF_MSG_IFUP,
  2109. "All MIN values are zeroes fairness will be disabled\n");
  2110. } else
  2111. input->flags.cmng_enables |=
  2112. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2113. }
  2114. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2115. struct cmng_init_input *input)
  2116. {
  2117. u16 vn_max_rate;
  2118. u32 vn_cfg = bp->mf_config[vn];
  2119. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2120. vn_max_rate = 0;
  2121. else {
  2122. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2123. if (IS_MF_PERCENT_BW(bp)) {
  2124. /* maxCfg in percents of linkspeed */
  2125. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2126. } else /* SD modes */
  2127. /* maxCfg is absolute in 100Mb units */
  2128. vn_max_rate = maxCfg * 100;
  2129. }
  2130. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2131. input->vnic_max_rate[vn] = vn_max_rate;
  2132. }
  2133. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2134. {
  2135. if (CHIP_REV_IS_SLOW(bp))
  2136. return CMNG_FNS_NONE;
  2137. if (IS_MF(bp))
  2138. return CMNG_FNS_MINMAX;
  2139. return CMNG_FNS_NONE;
  2140. }
  2141. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2142. {
  2143. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2144. if (BP_NOMCP(bp))
  2145. return; /* what should be the default value in this case */
  2146. /* For 2 port configuration the absolute function number formula
  2147. * is:
  2148. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2149. *
  2150. * and there are 4 functions per port
  2151. *
  2152. * For 4 port configuration it is
  2153. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2154. *
  2155. * and there are 2 functions per port
  2156. */
  2157. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2158. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2159. if (func >= E1H_FUNC_MAX)
  2160. break;
  2161. bp->mf_config[vn] =
  2162. MF_CFG_RD(bp, func_mf_config[func].config);
  2163. }
  2164. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2165. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2166. bp->flags |= MF_FUNC_DIS;
  2167. } else {
  2168. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2169. bp->flags &= ~MF_FUNC_DIS;
  2170. }
  2171. }
  2172. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2173. {
  2174. struct cmng_init_input input;
  2175. memset(&input, 0, sizeof(struct cmng_init_input));
  2176. input.port_rate = bp->link_vars.line_speed;
  2177. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2178. int vn;
  2179. /* read mf conf from shmem */
  2180. if (read_cfg)
  2181. bnx2x_read_mf_cfg(bp);
  2182. /* vn_weight_sum and enable fairness if not 0 */
  2183. bnx2x_calc_vn_min(bp, &input);
  2184. /* calculate and set min-max rate for each vn */
  2185. if (bp->port.pmf)
  2186. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2187. bnx2x_calc_vn_max(bp, vn, &input);
  2188. /* always enable rate shaping and fairness */
  2189. input.flags.cmng_enables |=
  2190. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2191. bnx2x_init_cmng(&input, &bp->cmng);
  2192. return;
  2193. }
  2194. /* rate shaping and fairness are disabled */
  2195. DP(NETIF_MSG_IFUP,
  2196. "rate shaping and fairness are disabled\n");
  2197. }
  2198. static void storm_memset_cmng(struct bnx2x *bp,
  2199. struct cmng_init *cmng,
  2200. u8 port)
  2201. {
  2202. int vn;
  2203. size_t size = sizeof(struct cmng_struct_per_port);
  2204. u32 addr = BAR_XSTRORM_INTMEM +
  2205. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2206. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2207. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2208. int func = func_by_vn(bp, vn);
  2209. addr = BAR_XSTRORM_INTMEM +
  2210. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2211. size = sizeof(struct rate_shaping_vars_per_vn);
  2212. __storm_memset_struct(bp, addr, size,
  2213. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2214. addr = BAR_XSTRORM_INTMEM +
  2215. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2216. size = sizeof(struct fairness_vars_per_vn);
  2217. __storm_memset_struct(bp, addr, size,
  2218. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2219. }
  2220. }
  2221. /* init cmng mode in HW according to local configuration */
  2222. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2223. {
  2224. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2225. if (cmng_fns != CMNG_FNS_NONE) {
  2226. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2227. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2228. } else {
  2229. /* rate shaping and fairness are disabled */
  2230. DP(NETIF_MSG_IFUP,
  2231. "single function mode without fairness\n");
  2232. }
  2233. }
  2234. /* This function is called upon link interrupt */
  2235. static void bnx2x_link_attn(struct bnx2x *bp)
  2236. {
  2237. /* Make sure that we are synced with the current statistics */
  2238. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2239. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2240. bnx2x_init_dropless_fc(bp);
  2241. if (bp->link_vars.link_up) {
  2242. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2243. struct host_port_stats *pstats;
  2244. pstats = bnx2x_sp(bp, port_stats);
  2245. /* reset old mac stats */
  2246. memset(&(pstats->mac_stx[0]), 0,
  2247. sizeof(struct mac_stx));
  2248. }
  2249. if (bp->state == BNX2X_STATE_OPEN)
  2250. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2251. }
  2252. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2253. bnx2x_set_local_cmng(bp);
  2254. __bnx2x_link_report(bp);
  2255. if (IS_MF(bp))
  2256. bnx2x_link_sync_notify(bp);
  2257. }
  2258. void bnx2x__link_status_update(struct bnx2x *bp)
  2259. {
  2260. if (bp->state != BNX2X_STATE_OPEN)
  2261. return;
  2262. /* read updated dcb configuration */
  2263. if (IS_PF(bp)) {
  2264. bnx2x_dcbx_pmf_update(bp);
  2265. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2266. if (bp->link_vars.link_up)
  2267. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2268. else
  2269. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2270. /* indicate link status */
  2271. bnx2x_link_report(bp);
  2272. } else { /* VF */
  2273. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2274. SUPPORTED_10baseT_Full |
  2275. SUPPORTED_100baseT_Half |
  2276. SUPPORTED_100baseT_Full |
  2277. SUPPORTED_1000baseT_Full |
  2278. SUPPORTED_2500baseX_Full |
  2279. SUPPORTED_10000baseT_Full |
  2280. SUPPORTED_TP |
  2281. SUPPORTED_FIBRE |
  2282. SUPPORTED_Autoneg |
  2283. SUPPORTED_Pause |
  2284. SUPPORTED_Asym_Pause);
  2285. bp->port.advertising[0] = bp->port.supported[0];
  2286. bp->link_params.bp = bp;
  2287. bp->link_params.port = BP_PORT(bp);
  2288. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2289. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2290. bp->link_params.req_line_speed[0] = SPEED_10000;
  2291. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2292. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2293. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2294. bp->link_vars.line_speed = SPEED_10000;
  2295. bp->link_vars.link_status =
  2296. (LINK_STATUS_LINK_UP |
  2297. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2298. bp->link_vars.link_up = 1;
  2299. bp->link_vars.duplex = DUPLEX_FULL;
  2300. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2301. __bnx2x_link_report(bp);
  2302. bnx2x_sample_bulletin(bp);
  2303. /* if bulletin board did not have an update for link status
  2304. * __bnx2x_link_report will report current status
  2305. * but it will NOT duplicate report in case of already reported
  2306. * during sampling bulletin board.
  2307. */
  2308. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2309. }
  2310. }
  2311. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2312. u16 vlan_val, u8 allowed_prio)
  2313. {
  2314. struct bnx2x_func_state_params func_params = {NULL};
  2315. struct bnx2x_func_afex_update_params *f_update_params =
  2316. &func_params.params.afex_update;
  2317. func_params.f_obj = &bp->func_obj;
  2318. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2319. /* no need to wait for RAMROD completion, so don't
  2320. * set RAMROD_COMP_WAIT flag
  2321. */
  2322. f_update_params->vif_id = vifid;
  2323. f_update_params->afex_default_vlan = vlan_val;
  2324. f_update_params->allowed_priorities = allowed_prio;
  2325. /* if ramrod can not be sent, response to MCP immediately */
  2326. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2327. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2328. return 0;
  2329. }
  2330. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2331. u16 vif_index, u8 func_bit_map)
  2332. {
  2333. struct bnx2x_func_state_params func_params = {NULL};
  2334. struct bnx2x_func_afex_viflists_params *update_params =
  2335. &func_params.params.afex_viflists;
  2336. int rc;
  2337. u32 drv_msg_code;
  2338. /* validate only LIST_SET and LIST_GET are received from switch */
  2339. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2340. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2341. cmd_type);
  2342. func_params.f_obj = &bp->func_obj;
  2343. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2344. /* set parameters according to cmd_type */
  2345. update_params->afex_vif_list_command = cmd_type;
  2346. update_params->vif_list_index = vif_index;
  2347. update_params->func_bit_map =
  2348. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2349. update_params->func_to_clear = 0;
  2350. drv_msg_code =
  2351. (cmd_type == VIF_LIST_RULE_GET) ?
  2352. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2353. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2354. /* if ramrod can not be sent, respond to MCP immediately for
  2355. * SET and GET requests (other are not triggered from MCP)
  2356. */
  2357. rc = bnx2x_func_state_change(bp, &func_params);
  2358. if (rc < 0)
  2359. bnx2x_fw_command(bp, drv_msg_code, 0);
  2360. return 0;
  2361. }
  2362. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2363. {
  2364. struct afex_stats afex_stats;
  2365. u32 func = BP_ABS_FUNC(bp);
  2366. u32 mf_config;
  2367. u16 vlan_val;
  2368. u32 vlan_prio;
  2369. u16 vif_id;
  2370. u8 allowed_prio;
  2371. u8 vlan_mode;
  2372. u32 addr_to_write, vifid, addrs, stats_type, i;
  2373. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2374. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2375. DP(BNX2X_MSG_MCP,
  2376. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2377. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2378. }
  2379. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2380. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2381. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2382. DP(BNX2X_MSG_MCP,
  2383. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2384. vifid, addrs);
  2385. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2386. addrs);
  2387. }
  2388. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2389. addr_to_write = SHMEM2_RD(bp,
  2390. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2391. stats_type = SHMEM2_RD(bp,
  2392. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2393. DP(BNX2X_MSG_MCP,
  2394. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2395. addr_to_write);
  2396. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2397. /* write response to scratchpad, for MCP */
  2398. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2399. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2400. *(((u32 *)(&afex_stats))+i));
  2401. /* send ack message to MCP */
  2402. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2403. }
  2404. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2405. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2406. bp->mf_config[BP_VN(bp)] = mf_config;
  2407. DP(BNX2X_MSG_MCP,
  2408. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2409. mf_config);
  2410. /* if VIF_SET is "enabled" */
  2411. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2412. /* set rate limit directly to internal RAM */
  2413. struct cmng_init_input cmng_input;
  2414. struct rate_shaping_vars_per_vn m_rs_vn;
  2415. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2416. u32 addr = BAR_XSTRORM_INTMEM +
  2417. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2418. bp->mf_config[BP_VN(bp)] = mf_config;
  2419. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2420. m_rs_vn.vn_counter.rate =
  2421. cmng_input.vnic_max_rate[BP_VN(bp)];
  2422. m_rs_vn.vn_counter.quota =
  2423. (m_rs_vn.vn_counter.rate *
  2424. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2425. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2426. /* read relevant values from mf_cfg struct in shmem */
  2427. vif_id =
  2428. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2429. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2430. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2431. vlan_val =
  2432. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2433. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2434. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2435. vlan_prio = (mf_config &
  2436. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2437. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2438. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2439. vlan_mode =
  2440. (MF_CFG_RD(bp,
  2441. func_mf_config[func].afex_config) &
  2442. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2443. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2444. allowed_prio =
  2445. (MF_CFG_RD(bp,
  2446. func_mf_config[func].afex_config) &
  2447. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2448. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2449. /* send ramrod to FW, return in case of failure */
  2450. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2451. allowed_prio))
  2452. return;
  2453. bp->afex_def_vlan_tag = vlan_val;
  2454. bp->afex_vlan_mode = vlan_mode;
  2455. } else {
  2456. /* notify link down because BP->flags is disabled */
  2457. bnx2x_link_report(bp);
  2458. /* send INVALID VIF ramrod to FW */
  2459. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2460. /* Reset the default afex VLAN */
  2461. bp->afex_def_vlan_tag = -1;
  2462. }
  2463. }
  2464. }
  2465. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2466. {
  2467. struct bnx2x_func_switch_update_params *switch_update_params;
  2468. struct bnx2x_func_state_params func_params;
  2469. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2470. switch_update_params = &func_params.params.switch_update;
  2471. func_params.f_obj = &bp->func_obj;
  2472. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2473. 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_RELAXED(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 we read all 0xFFs, means we are in PCI error state and
  8030. * should bail out to avoid crashes on adapter's FW reads.
  8031. */
  8032. if (bp->common.shmem_base == 0xFFFFFFFF) {
  8033. bp->flags |= NO_MCP_FLAG;
  8034. return -ENODEV;
  8035. }
  8036. if (bp->common.shmem_base) {
  8037. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  8038. if (val & SHR_MEM_VALIDITY_MB)
  8039. return 0;
  8040. }
  8041. bnx2x_mcp_wait_one(bp);
  8042. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  8043. BNX2X_ERR("BAD MCP validity signature\n");
  8044. return -ENODEV;
  8045. }
  8046. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  8047. {
  8048. int rc = bnx2x_init_shmem(bp);
  8049. /* Restore the `magic' bit value */
  8050. if (!CHIP_IS_E1(bp))
  8051. bnx2x_clp_reset_done(bp, magic_val);
  8052. return rc;
  8053. }
  8054. static void bnx2x_pxp_prep(struct bnx2x *bp)
  8055. {
  8056. if (!CHIP_IS_E1(bp)) {
  8057. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  8058. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  8059. mmiowb();
  8060. }
  8061. }
  8062. /*
  8063. * Reset the whole chip except for:
  8064. * - PCIE core
  8065. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  8066. * one reset bit)
  8067. * - IGU
  8068. * - MISC (including AEU)
  8069. * - GRC
  8070. * - RBCN, RBCP
  8071. */
  8072. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  8073. {
  8074. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  8075. u32 global_bits2, stay_reset2;
  8076. /*
  8077. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  8078. * (per chip) blocks.
  8079. */
  8080. global_bits2 =
  8081. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  8082. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  8083. /* Don't reset the following blocks.
  8084. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  8085. * reset, as in 4 port device they might still be owned
  8086. * by the MCP (there is only one leader per path).
  8087. */
  8088. not_reset_mask1 =
  8089. MISC_REGISTERS_RESET_REG_1_RST_HC |
  8090. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  8091. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  8092. not_reset_mask2 =
  8093. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  8094. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8095. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8096. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8097. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8098. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8099. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8100. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8101. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8102. MISC_REGISTERS_RESET_REG_2_PGLC |
  8103. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8104. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8105. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8106. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8107. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8108. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8109. /*
  8110. * Keep the following blocks in reset:
  8111. * - all xxMACs are handled by the bnx2x_link code.
  8112. */
  8113. stay_reset2 =
  8114. MISC_REGISTERS_RESET_REG_2_XMAC |
  8115. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8116. /* Full reset masks according to the chip */
  8117. reset_mask1 = 0xffffffff;
  8118. if (CHIP_IS_E1(bp))
  8119. reset_mask2 = 0xffff;
  8120. else if (CHIP_IS_E1H(bp))
  8121. reset_mask2 = 0x1ffff;
  8122. else if (CHIP_IS_E2(bp))
  8123. reset_mask2 = 0xfffff;
  8124. else /* CHIP_IS_E3 */
  8125. reset_mask2 = 0x3ffffff;
  8126. /* Don't reset global blocks unless we need to */
  8127. if (!global)
  8128. reset_mask2 &= ~global_bits2;
  8129. /*
  8130. * In case of attention in the QM, we need to reset PXP
  8131. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8132. * because otherwise QM reset would release 'close the gates' shortly
  8133. * before resetting the PXP, then the PSWRQ would send a write
  8134. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8135. * read the payload data from PSWWR, but PSWWR would not
  8136. * respond. The write queue in PGLUE would stuck, dmae commands
  8137. * would not return. Therefore it's important to reset the second
  8138. * reset register (containing the
  8139. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8140. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8141. * bit).
  8142. */
  8143. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8144. reset_mask2 & (~not_reset_mask2));
  8145. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8146. reset_mask1 & (~not_reset_mask1));
  8147. barrier();
  8148. mmiowb();
  8149. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8150. reset_mask2 & (~stay_reset2));
  8151. barrier();
  8152. mmiowb();
  8153. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8154. mmiowb();
  8155. }
  8156. /**
  8157. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8158. * It should get cleared in no more than 1s.
  8159. *
  8160. * @bp: driver handle
  8161. *
  8162. * It should get cleared in no more than 1s. Returns 0 if
  8163. * pending writes bit gets cleared.
  8164. */
  8165. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8166. {
  8167. u32 cnt = 1000;
  8168. u32 pend_bits = 0;
  8169. do {
  8170. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8171. if (pend_bits == 0)
  8172. break;
  8173. usleep_range(1000, 2000);
  8174. } while (cnt-- > 0);
  8175. if (cnt <= 0) {
  8176. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8177. pend_bits);
  8178. return -EBUSY;
  8179. }
  8180. return 0;
  8181. }
  8182. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8183. {
  8184. int cnt = 1000;
  8185. u32 val = 0;
  8186. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8187. u32 tags_63_32 = 0;
  8188. /* Empty the Tetris buffer, wait for 1s */
  8189. do {
  8190. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8191. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8192. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8193. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8194. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8195. if (CHIP_IS_E3(bp))
  8196. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8197. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8198. ((port_is_idle_0 & 0x1) == 0x1) &&
  8199. ((port_is_idle_1 & 0x1) == 0x1) &&
  8200. (pgl_exp_rom2 == 0xffffffff) &&
  8201. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8202. break;
  8203. usleep_range(1000, 2000);
  8204. } while (cnt-- > 0);
  8205. if (cnt <= 0) {
  8206. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8207. 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",
  8208. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8209. pgl_exp_rom2);
  8210. return -EAGAIN;
  8211. }
  8212. barrier();
  8213. /* Close gates #2, #3 and #4 */
  8214. bnx2x_set_234_gates(bp, true);
  8215. /* Poll for IGU VQs for 57712 and newer chips */
  8216. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8217. return -EAGAIN;
  8218. /* TBD: Indicate that "process kill" is in progress to MCP */
  8219. /* Clear "unprepared" bit */
  8220. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8221. barrier();
  8222. /* Make sure all is written to the chip before the reset */
  8223. mmiowb();
  8224. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8225. * PSWHST, GRC and PSWRD Tetris buffer.
  8226. */
  8227. usleep_range(1000, 2000);
  8228. /* Prepare to chip reset: */
  8229. /* MCP */
  8230. if (global)
  8231. bnx2x_reset_mcp_prep(bp, &val);
  8232. /* PXP */
  8233. bnx2x_pxp_prep(bp);
  8234. barrier();
  8235. /* reset the chip */
  8236. bnx2x_process_kill_chip_reset(bp, global);
  8237. barrier();
  8238. /* clear errors in PGB */
  8239. if (!CHIP_IS_E1x(bp))
  8240. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8241. /* Recover after reset: */
  8242. /* MCP */
  8243. if (global && bnx2x_reset_mcp_comp(bp, val))
  8244. return -EAGAIN;
  8245. /* TBD: Add resetting the NO_MCP mode DB here */
  8246. /* Open the gates #2, #3 and #4 */
  8247. bnx2x_set_234_gates(bp, false);
  8248. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8249. * reset state, re-enable attentions. */
  8250. return 0;
  8251. }
  8252. static int bnx2x_leader_reset(struct bnx2x *bp)
  8253. {
  8254. int rc = 0;
  8255. bool global = bnx2x_reset_is_global(bp);
  8256. u32 load_code;
  8257. /* if not going to reset MCP - load "fake" driver to reset HW while
  8258. * driver is owner of the HW
  8259. */
  8260. if (!global && !BP_NOMCP(bp)) {
  8261. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8262. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8263. if (!load_code) {
  8264. BNX2X_ERR("MCP response failure, aborting\n");
  8265. rc = -EAGAIN;
  8266. goto exit_leader_reset;
  8267. }
  8268. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8269. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8270. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8271. rc = -EAGAIN;
  8272. goto exit_leader_reset2;
  8273. }
  8274. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8275. if (!load_code) {
  8276. BNX2X_ERR("MCP response failure, aborting\n");
  8277. rc = -EAGAIN;
  8278. goto exit_leader_reset2;
  8279. }
  8280. }
  8281. /* Try to recover after the failure */
  8282. if (bnx2x_process_kill(bp, global)) {
  8283. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8284. BP_PATH(bp));
  8285. rc = -EAGAIN;
  8286. goto exit_leader_reset2;
  8287. }
  8288. /*
  8289. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8290. * state.
  8291. */
  8292. bnx2x_set_reset_done(bp);
  8293. if (global)
  8294. bnx2x_clear_reset_global(bp);
  8295. exit_leader_reset2:
  8296. /* unload "fake driver" if it was loaded */
  8297. if (!global && !BP_NOMCP(bp)) {
  8298. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8299. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8300. }
  8301. exit_leader_reset:
  8302. bp->is_leader = 0;
  8303. bnx2x_release_leader_lock(bp);
  8304. smp_mb();
  8305. return rc;
  8306. }
  8307. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8308. {
  8309. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8310. /* Disconnect this device */
  8311. netif_device_detach(bp->dev);
  8312. /*
  8313. * Block ifup for all function on this engine until "process kill"
  8314. * or power cycle.
  8315. */
  8316. bnx2x_set_reset_in_progress(bp);
  8317. /* Shut down the power */
  8318. bnx2x_set_power_state(bp, PCI_D3hot);
  8319. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8320. smp_mb();
  8321. }
  8322. /*
  8323. * Assumption: runs under rtnl lock. This together with the fact
  8324. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8325. * will never be called when netif_running(bp->dev) is false.
  8326. */
  8327. static void bnx2x_parity_recover(struct bnx2x *bp)
  8328. {
  8329. bool global = false;
  8330. u32 error_recovered, error_unrecovered;
  8331. bool is_parity;
  8332. DP(NETIF_MSG_HW, "Handling parity\n");
  8333. while (1) {
  8334. switch (bp->recovery_state) {
  8335. case BNX2X_RECOVERY_INIT:
  8336. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8337. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8338. WARN_ON(!is_parity);
  8339. /* Try to get a LEADER_LOCK HW lock */
  8340. if (bnx2x_trylock_leader_lock(bp)) {
  8341. bnx2x_set_reset_in_progress(bp);
  8342. /*
  8343. * Check if there is a global attention and if
  8344. * there was a global attention, set the global
  8345. * reset bit.
  8346. */
  8347. if (global)
  8348. bnx2x_set_reset_global(bp);
  8349. bp->is_leader = 1;
  8350. }
  8351. /* Stop the driver */
  8352. /* If interface has been removed - break */
  8353. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8354. return;
  8355. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8356. /* Ensure "is_leader", MCP command sequence and
  8357. * "recovery_state" update values are seen on other
  8358. * CPUs.
  8359. */
  8360. smp_mb();
  8361. break;
  8362. case BNX2X_RECOVERY_WAIT:
  8363. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8364. if (bp->is_leader) {
  8365. int other_engine = BP_PATH(bp) ? 0 : 1;
  8366. bool other_load_status =
  8367. bnx2x_get_load_status(bp, other_engine);
  8368. bool load_status =
  8369. bnx2x_get_load_status(bp, BP_PATH(bp));
  8370. global = bnx2x_reset_is_global(bp);
  8371. /*
  8372. * In case of a parity in a global block, let
  8373. * the first leader that performs a
  8374. * leader_reset() reset the global blocks in
  8375. * order to clear global attentions. Otherwise
  8376. * the gates will remain closed for that
  8377. * engine.
  8378. */
  8379. if (load_status ||
  8380. (global && other_load_status)) {
  8381. /* Wait until all other functions get
  8382. * down.
  8383. */
  8384. schedule_delayed_work(&bp->sp_rtnl_task,
  8385. HZ/10);
  8386. return;
  8387. } else {
  8388. /* If all other functions got down -
  8389. * try to bring the chip back to
  8390. * normal. In any case it's an exit
  8391. * point for a leader.
  8392. */
  8393. if (bnx2x_leader_reset(bp)) {
  8394. bnx2x_recovery_failed(bp);
  8395. return;
  8396. }
  8397. /* If we are here, means that the
  8398. * leader has succeeded and doesn't
  8399. * want to be a leader any more. Try
  8400. * to continue as a none-leader.
  8401. */
  8402. break;
  8403. }
  8404. } else { /* non-leader */
  8405. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8406. /* Try to get a LEADER_LOCK HW lock as
  8407. * long as a former leader may have
  8408. * been unloaded by the user or
  8409. * released a leadership by another
  8410. * reason.
  8411. */
  8412. if (bnx2x_trylock_leader_lock(bp)) {
  8413. /* I'm a leader now! Restart a
  8414. * switch case.
  8415. */
  8416. bp->is_leader = 1;
  8417. break;
  8418. }
  8419. schedule_delayed_work(&bp->sp_rtnl_task,
  8420. HZ/10);
  8421. return;
  8422. } else {
  8423. /*
  8424. * If there was a global attention, wait
  8425. * for it to be cleared.
  8426. */
  8427. if (bnx2x_reset_is_global(bp)) {
  8428. schedule_delayed_work(
  8429. &bp->sp_rtnl_task,
  8430. HZ/10);
  8431. return;
  8432. }
  8433. error_recovered =
  8434. bp->eth_stats.recoverable_error;
  8435. error_unrecovered =
  8436. bp->eth_stats.unrecoverable_error;
  8437. bp->recovery_state =
  8438. BNX2X_RECOVERY_NIC_LOADING;
  8439. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8440. error_unrecovered++;
  8441. netdev_err(bp->dev,
  8442. "Recovery failed. Power cycle needed\n");
  8443. /* Disconnect this device */
  8444. netif_device_detach(bp->dev);
  8445. /* Shut down the power */
  8446. bnx2x_set_power_state(
  8447. bp, PCI_D3hot);
  8448. smp_mb();
  8449. } else {
  8450. bp->recovery_state =
  8451. BNX2X_RECOVERY_DONE;
  8452. error_recovered++;
  8453. smp_mb();
  8454. }
  8455. bp->eth_stats.recoverable_error =
  8456. error_recovered;
  8457. bp->eth_stats.unrecoverable_error =
  8458. error_unrecovered;
  8459. return;
  8460. }
  8461. }
  8462. default:
  8463. return;
  8464. }
  8465. }
  8466. }
  8467. static int bnx2x_udp_port_update(struct bnx2x *bp)
  8468. {
  8469. struct bnx2x_func_switch_update_params *switch_update_params;
  8470. struct bnx2x_func_state_params func_params = {NULL};
  8471. struct bnx2x_udp_tunnel *udp_tunnel;
  8472. u16 vxlan_port = 0, geneve_port = 0;
  8473. int rc;
  8474. switch_update_params = &func_params.params.switch_update;
  8475. /* Prepare parameters for function state transitions */
  8476. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  8477. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  8478. func_params.f_obj = &bp->func_obj;
  8479. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  8480. /* Function parameters */
  8481. __set_bit(BNX2X_F_UPDATE_TUNNEL_CFG_CHNG,
  8482. &switch_update_params->changes);
  8483. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count) {
  8484. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE];
  8485. geneve_port = udp_tunnel->dst_port;
  8486. switch_update_params->geneve_dst_port = geneve_port;
  8487. }
  8488. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count) {
  8489. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN];
  8490. vxlan_port = udp_tunnel->dst_port;
  8491. switch_update_params->vxlan_dst_port = vxlan_port;
  8492. }
  8493. /* Re-enable inner-rss for the offloaded UDP tunnels */
  8494. __set_bit(BNX2X_F_UPDATE_TUNNEL_INNER_RSS,
  8495. &switch_update_params->changes);
  8496. rc = bnx2x_func_state_change(bp, &func_params);
  8497. if (rc)
  8498. BNX2X_ERR("failed to set UDP dst port to %04x %04x (rc = 0x%x)\n",
  8499. vxlan_port, geneve_port, rc);
  8500. else
  8501. DP(BNX2X_MSG_SP,
  8502. "Configured UDP ports: Vxlan [%04x] Geneve [%04x]\n",
  8503. vxlan_port, geneve_port);
  8504. return rc;
  8505. }
  8506. static void __bnx2x_add_udp_port(struct bnx2x *bp, u16 port,
  8507. enum bnx2x_udp_port_type type)
  8508. {
  8509. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8510. if (!netif_running(bp->dev) || !IS_PF(bp) || CHIP_IS_E1x(bp))
  8511. return;
  8512. if (udp_port->count && udp_port->dst_port == port) {
  8513. udp_port->count++;
  8514. return;
  8515. }
  8516. if (udp_port->count) {
  8517. DP(BNX2X_MSG_SP,
  8518. "UDP tunnel [%d] - destination port limit reached\n",
  8519. type);
  8520. return;
  8521. }
  8522. udp_port->dst_port = port;
  8523. udp_port->count = 1;
  8524. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8525. }
  8526. static void __bnx2x_del_udp_port(struct bnx2x *bp, u16 port,
  8527. enum bnx2x_udp_port_type type)
  8528. {
  8529. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8530. if (!IS_PF(bp) || CHIP_IS_E1x(bp))
  8531. return;
  8532. if (!udp_port->count || udp_port->dst_port != port) {
  8533. DP(BNX2X_MSG_SP, "Invalid UDP tunnel [%d] port\n",
  8534. type);
  8535. return;
  8536. }
  8537. /* Remove reference, and make certain it's no longer in use */
  8538. udp_port->count--;
  8539. if (udp_port->count)
  8540. return;
  8541. udp_port->dst_port = 0;
  8542. if (netif_running(bp->dev))
  8543. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8544. else
  8545. DP(BNX2X_MSG_SP, "Deleted UDP tunnel [%d] port %d\n",
  8546. type, port);
  8547. }
  8548. static void bnx2x_udp_tunnel_add(struct net_device *netdev,
  8549. struct udp_tunnel_info *ti)
  8550. {
  8551. struct bnx2x *bp = netdev_priv(netdev);
  8552. u16 t_port = ntohs(ti->port);
  8553. switch (ti->type) {
  8554. case UDP_TUNNEL_TYPE_VXLAN:
  8555. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8556. break;
  8557. case UDP_TUNNEL_TYPE_GENEVE:
  8558. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8559. break;
  8560. default:
  8561. break;
  8562. }
  8563. }
  8564. static void bnx2x_udp_tunnel_del(struct net_device *netdev,
  8565. struct udp_tunnel_info *ti)
  8566. {
  8567. struct bnx2x *bp = netdev_priv(netdev);
  8568. u16 t_port = ntohs(ti->port);
  8569. switch (ti->type) {
  8570. case UDP_TUNNEL_TYPE_VXLAN:
  8571. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8572. break;
  8573. case UDP_TUNNEL_TYPE_GENEVE:
  8574. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8575. break;
  8576. default:
  8577. break;
  8578. }
  8579. }
  8580. static int bnx2x_close(struct net_device *dev);
  8581. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8582. * scheduled on a general queue in order to prevent a dead lock.
  8583. */
  8584. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8585. {
  8586. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8587. rtnl_lock();
  8588. if (!netif_running(bp->dev)) {
  8589. rtnl_unlock();
  8590. return;
  8591. }
  8592. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8593. #ifdef BNX2X_STOP_ON_ERROR
  8594. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8595. "you will need to reboot when done\n");
  8596. goto sp_rtnl_not_reset;
  8597. #endif
  8598. /*
  8599. * Clear all pending SP commands as we are going to reset the
  8600. * function anyway.
  8601. */
  8602. bp->sp_rtnl_state = 0;
  8603. smp_mb();
  8604. bnx2x_parity_recover(bp);
  8605. rtnl_unlock();
  8606. return;
  8607. }
  8608. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8609. #ifdef BNX2X_STOP_ON_ERROR
  8610. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8611. "you will need to reboot when done\n");
  8612. goto sp_rtnl_not_reset;
  8613. #endif
  8614. /*
  8615. * Clear all pending SP commands as we are going to reset the
  8616. * function anyway.
  8617. */
  8618. bp->sp_rtnl_state = 0;
  8619. smp_mb();
  8620. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8621. /* When ret value shows failure of allocation failure,
  8622. * the nic is rebooted again. If open still fails, a error
  8623. * message to notify the user.
  8624. */
  8625. if (bnx2x_nic_load(bp, LOAD_NORMAL) == -ENOMEM) {
  8626. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8627. if (bnx2x_nic_load(bp, LOAD_NORMAL))
  8628. BNX2X_ERR("Open the NIC fails again!\n");
  8629. }
  8630. rtnl_unlock();
  8631. return;
  8632. }
  8633. #ifdef BNX2X_STOP_ON_ERROR
  8634. sp_rtnl_not_reset:
  8635. #endif
  8636. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8637. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8638. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8639. bnx2x_after_function_update(bp);
  8640. /*
  8641. * in case of fan failure we need to reset id if the "stop on error"
  8642. * debug flag is set, since we trying to prevent permanent overheating
  8643. * damage
  8644. */
  8645. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8646. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8647. netif_device_detach(bp->dev);
  8648. bnx2x_close(bp->dev);
  8649. rtnl_unlock();
  8650. return;
  8651. }
  8652. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8653. DP(BNX2X_MSG_SP,
  8654. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8655. bnx2x_vfpf_set_mcast(bp->dev);
  8656. }
  8657. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8658. &bp->sp_rtnl_state)){
  8659. if (netif_carrier_ok(bp->dev)) {
  8660. bnx2x_tx_disable(bp);
  8661. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8662. }
  8663. }
  8664. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8665. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8666. bnx2x_set_rx_mode_inner(bp);
  8667. }
  8668. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8669. &bp->sp_rtnl_state))
  8670. bnx2x_pf_set_vfs_vlan(bp);
  8671. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8672. bnx2x_dcbx_stop_hw_tx(bp);
  8673. bnx2x_dcbx_resume_hw_tx(bp);
  8674. }
  8675. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8676. &bp->sp_rtnl_state))
  8677. bnx2x_update_mng_version(bp);
  8678. if (test_and_clear_bit(BNX2X_SP_RTNL_CHANGE_UDP_PORT,
  8679. &bp->sp_rtnl_state)) {
  8680. if (bnx2x_udp_port_update(bp)) {
  8681. /* On error, forget configuration */
  8682. memset(bp->udp_tunnel_ports, 0,
  8683. sizeof(struct bnx2x_udp_tunnel) *
  8684. BNX2X_UDP_PORT_MAX);
  8685. } else {
  8686. /* Since we don't store additional port information,
  8687. * if no ports are configured for any feature ask for
  8688. * information about currently configured ports.
  8689. */
  8690. if (!bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count &&
  8691. !bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count)
  8692. udp_tunnel_get_rx_info(bp->dev);
  8693. }
  8694. }
  8695. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8696. * can be called from other contexts as well)
  8697. */
  8698. rtnl_unlock();
  8699. /* enable SR-IOV if applicable */
  8700. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8701. &bp->sp_rtnl_state)) {
  8702. bnx2x_disable_sriov(bp);
  8703. bnx2x_enable_sriov(bp);
  8704. }
  8705. }
  8706. static void bnx2x_period_task(struct work_struct *work)
  8707. {
  8708. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8709. if (!netif_running(bp->dev))
  8710. goto period_task_exit;
  8711. if (CHIP_REV_IS_SLOW(bp)) {
  8712. BNX2X_ERR("period task called on emulation, ignoring\n");
  8713. goto period_task_exit;
  8714. }
  8715. bnx2x_acquire_phy_lock(bp);
  8716. /*
  8717. * The barrier is needed to ensure the ordering between the writing to
  8718. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8719. * the reading here.
  8720. */
  8721. smp_mb();
  8722. if (bp->port.pmf) {
  8723. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8724. /* Re-queue task in 1 sec */
  8725. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8726. }
  8727. bnx2x_release_phy_lock(bp);
  8728. period_task_exit:
  8729. return;
  8730. }
  8731. /*
  8732. * Init service functions
  8733. */
  8734. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8735. {
  8736. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8737. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8738. return base + (BP_ABS_FUNC(bp)) * stride;
  8739. }
  8740. static bool bnx2x_prev_unload_close_umac(struct bnx2x *bp,
  8741. u8 port, u32 reset_reg,
  8742. struct bnx2x_mac_vals *vals)
  8743. {
  8744. u32 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8745. u32 base_addr;
  8746. if (!(mask & reset_reg))
  8747. return false;
  8748. BNX2X_DEV_INFO("Disable umac Rx %02x\n", port);
  8749. base_addr = port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8750. vals->umac_addr[port] = base_addr + UMAC_REG_COMMAND_CONFIG;
  8751. vals->umac_val[port] = REG_RD(bp, vals->umac_addr[port]);
  8752. REG_WR(bp, vals->umac_addr[port], 0);
  8753. return true;
  8754. }
  8755. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8756. struct bnx2x_mac_vals *vals)
  8757. {
  8758. u32 val, base_addr, offset, mask, reset_reg;
  8759. bool mac_stopped = false;
  8760. u8 port = BP_PORT(bp);
  8761. /* reset addresses as they also mark which values were changed */
  8762. memset(vals, 0, sizeof(*vals));
  8763. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8764. if (!CHIP_IS_E3(bp)) {
  8765. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8766. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8767. if ((mask & reset_reg) && val) {
  8768. u32 wb_data[2];
  8769. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8770. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8771. : NIG_REG_INGRESS_BMAC0_MEM;
  8772. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8773. : BIGMAC_REGISTER_BMAC_CONTROL;
  8774. /*
  8775. * use rd/wr since we cannot use dmae. This is safe
  8776. * since MCP won't access the bus due to the request
  8777. * to unload, and no function on the path can be
  8778. * loaded at this time.
  8779. */
  8780. wb_data[0] = REG_RD(bp, base_addr + offset);
  8781. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8782. vals->bmac_addr = base_addr + offset;
  8783. vals->bmac_val[0] = wb_data[0];
  8784. vals->bmac_val[1] = wb_data[1];
  8785. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8786. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8787. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8788. }
  8789. BNX2X_DEV_INFO("Disable emac Rx\n");
  8790. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8791. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8792. REG_WR(bp, vals->emac_addr, 0);
  8793. mac_stopped = true;
  8794. } else {
  8795. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8796. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8797. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8798. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8799. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8800. val & ~(1 << 1));
  8801. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8802. val | (1 << 1));
  8803. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8804. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8805. REG_WR(bp, vals->xmac_addr, 0);
  8806. mac_stopped = true;
  8807. }
  8808. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 0,
  8809. reset_reg, vals);
  8810. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 1,
  8811. reset_reg, vals);
  8812. }
  8813. if (mac_stopped)
  8814. msleep(20);
  8815. }
  8816. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8817. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8818. 0x1848 + ((f) << 4))
  8819. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8820. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8821. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8822. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8823. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8824. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8825. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8826. {
  8827. /* UNDI marks its presence in DORQ -
  8828. * it initializes CID offset for normal bell to 0x7
  8829. */
  8830. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8831. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8832. return false;
  8833. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8834. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8835. return true;
  8836. }
  8837. return false;
  8838. }
  8839. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8840. {
  8841. u16 rcq, bd;
  8842. u32 addr, tmp_reg;
  8843. if (BP_FUNC(bp) < 2)
  8844. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8845. else
  8846. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8847. tmp_reg = REG_RD(bp, addr);
  8848. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8849. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8850. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8851. REG_WR(bp, addr, tmp_reg);
  8852. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8853. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8854. }
  8855. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8856. {
  8857. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8858. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8859. if (!rc) {
  8860. BNX2X_ERR("MCP response failure, aborting\n");
  8861. return -EBUSY;
  8862. }
  8863. return 0;
  8864. }
  8865. static struct bnx2x_prev_path_list *
  8866. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8867. {
  8868. struct bnx2x_prev_path_list *tmp_list;
  8869. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8870. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8871. bp->pdev->bus->number == tmp_list->bus &&
  8872. BP_PATH(bp) == tmp_list->path)
  8873. return tmp_list;
  8874. return NULL;
  8875. }
  8876. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8877. {
  8878. struct bnx2x_prev_path_list *tmp_list;
  8879. int rc;
  8880. rc = down_interruptible(&bnx2x_prev_sem);
  8881. if (rc) {
  8882. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8883. return rc;
  8884. }
  8885. tmp_list = bnx2x_prev_path_get_entry(bp);
  8886. if (tmp_list) {
  8887. tmp_list->aer = 1;
  8888. rc = 0;
  8889. } else {
  8890. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8891. BP_PATH(bp));
  8892. }
  8893. up(&bnx2x_prev_sem);
  8894. return rc;
  8895. }
  8896. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8897. {
  8898. struct bnx2x_prev_path_list *tmp_list;
  8899. bool rc = false;
  8900. if (down_trylock(&bnx2x_prev_sem))
  8901. return false;
  8902. tmp_list = bnx2x_prev_path_get_entry(bp);
  8903. if (tmp_list) {
  8904. if (tmp_list->aer) {
  8905. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8906. BP_PATH(bp));
  8907. } else {
  8908. rc = true;
  8909. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8910. BP_PATH(bp));
  8911. }
  8912. }
  8913. up(&bnx2x_prev_sem);
  8914. return rc;
  8915. }
  8916. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8917. {
  8918. struct bnx2x_prev_path_list *entry;
  8919. bool val;
  8920. down(&bnx2x_prev_sem);
  8921. entry = bnx2x_prev_path_get_entry(bp);
  8922. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8923. up(&bnx2x_prev_sem);
  8924. return val;
  8925. }
  8926. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8927. {
  8928. struct bnx2x_prev_path_list *tmp_list;
  8929. int rc;
  8930. rc = down_interruptible(&bnx2x_prev_sem);
  8931. if (rc) {
  8932. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8933. return rc;
  8934. }
  8935. /* Check whether the entry for this path already exists */
  8936. tmp_list = bnx2x_prev_path_get_entry(bp);
  8937. if (tmp_list) {
  8938. if (!tmp_list->aer) {
  8939. BNX2X_ERR("Re-Marking the path.\n");
  8940. } else {
  8941. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8942. BP_PATH(bp));
  8943. tmp_list->aer = 0;
  8944. }
  8945. up(&bnx2x_prev_sem);
  8946. return 0;
  8947. }
  8948. up(&bnx2x_prev_sem);
  8949. /* Create an entry for this path and add it */
  8950. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8951. if (!tmp_list) {
  8952. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8953. return -ENOMEM;
  8954. }
  8955. tmp_list->bus = bp->pdev->bus->number;
  8956. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8957. tmp_list->path = BP_PATH(bp);
  8958. tmp_list->aer = 0;
  8959. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8960. rc = down_interruptible(&bnx2x_prev_sem);
  8961. if (rc) {
  8962. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8963. kfree(tmp_list);
  8964. } else {
  8965. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8966. BP_PATH(bp));
  8967. list_add(&tmp_list->list, &bnx2x_prev_list);
  8968. up(&bnx2x_prev_sem);
  8969. }
  8970. return rc;
  8971. }
  8972. static int bnx2x_do_flr(struct bnx2x *bp)
  8973. {
  8974. struct pci_dev *dev = bp->pdev;
  8975. if (CHIP_IS_E1x(bp)) {
  8976. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8977. return -EINVAL;
  8978. }
  8979. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8980. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8981. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8982. bp->common.bc_ver);
  8983. return -EINVAL;
  8984. }
  8985. if (!pci_wait_for_pending_transaction(dev))
  8986. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8987. BNX2X_DEV_INFO("Initiating FLR\n");
  8988. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8989. return 0;
  8990. }
  8991. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8992. {
  8993. int rc;
  8994. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8995. /* Test if previous unload process was already finished for this path */
  8996. if (bnx2x_prev_is_path_marked(bp))
  8997. return bnx2x_prev_mcp_done(bp);
  8998. BNX2X_DEV_INFO("Path is unmarked\n");
  8999. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  9000. if (bnx2x_prev_is_after_undi(bp))
  9001. goto out;
  9002. /* If function has FLR capabilities, and existing FW version matches
  9003. * the one required, then FLR will be sufficient to clean any residue
  9004. * left by previous driver
  9005. */
  9006. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  9007. if (!rc) {
  9008. /* fw version is good */
  9009. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  9010. rc = bnx2x_do_flr(bp);
  9011. }
  9012. if (!rc) {
  9013. /* FLR was performed */
  9014. BNX2X_DEV_INFO("FLR successful\n");
  9015. return 0;
  9016. }
  9017. BNX2X_DEV_INFO("Could not FLR\n");
  9018. out:
  9019. /* Close the MCP request, return failure*/
  9020. rc = bnx2x_prev_mcp_done(bp);
  9021. if (!rc)
  9022. rc = BNX2X_PREV_WAIT_NEEDED;
  9023. return rc;
  9024. }
  9025. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  9026. {
  9027. u32 reset_reg, tmp_reg = 0, rc;
  9028. bool prev_undi = false;
  9029. struct bnx2x_mac_vals mac_vals;
  9030. /* It is possible a previous function received 'common' answer,
  9031. * but hasn't loaded yet, therefore creating a scenario of
  9032. * multiple functions receiving 'common' on the same path.
  9033. */
  9034. BNX2X_DEV_INFO("Common unload Flow\n");
  9035. memset(&mac_vals, 0, sizeof(mac_vals));
  9036. if (bnx2x_prev_is_path_marked(bp))
  9037. return bnx2x_prev_mcp_done(bp);
  9038. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  9039. /* Reset should be performed after BRB is emptied */
  9040. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  9041. u32 timer_count = 1000;
  9042. /* Close the MAC Rx to prevent BRB from filling up */
  9043. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  9044. /* close LLH filters for both ports towards the BRB */
  9045. bnx2x_set_rx_filter(&bp->link_params, 0);
  9046. bp->link_params.port ^= 1;
  9047. bnx2x_set_rx_filter(&bp->link_params, 0);
  9048. bp->link_params.port ^= 1;
  9049. /* Check if the UNDI driver was previously loaded */
  9050. if (bnx2x_prev_is_after_undi(bp)) {
  9051. prev_undi = true;
  9052. /* clear the UNDI indication */
  9053. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  9054. /* clear possible idle check errors */
  9055. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  9056. }
  9057. if (!CHIP_IS_E1x(bp))
  9058. /* block FW from writing to host */
  9059. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  9060. /* wait until BRB is empty */
  9061. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9062. while (timer_count) {
  9063. u32 prev_brb = tmp_reg;
  9064. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9065. if (!tmp_reg)
  9066. break;
  9067. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  9068. /* reset timer as long as BRB actually gets emptied */
  9069. if (prev_brb > tmp_reg)
  9070. timer_count = 1000;
  9071. else
  9072. timer_count--;
  9073. /* If UNDI resides in memory, manually increment it */
  9074. if (prev_undi)
  9075. bnx2x_prev_unload_undi_inc(bp, 1);
  9076. udelay(10);
  9077. }
  9078. if (!timer_count)
  9079. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  9080. }
  9081. /* No packets are in the pipeline, path is ready for reset */
  9082. bnx2x_reset_common(bp);
  9083. if (mac_vals.xmac_addr)
  9084. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  9085. if (mac_vals.umac_addr[0])
  9086. REG_WR(bp, mac_vals.umac_addr[0], mac_vals.umac_val[0]);
  9087. if (mac_vals.umac_addr[1])
  9088. REG_WR(bp, mac_vals.umac_addr[1], mac_vals.umac_val[1]);
  9089. if (mac_vals.emac_addr)
  9090. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  9091. if (mac_vals.bmac_addr) {
  9092. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  9093. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  9094. }
  9095. rc = bnx2x_prev_mark_path(bp, prev_undi);
  9096. if (rc) {
  9097. bnx2x_prev_mcp_done(bp);
  9098. return rc;
  9099. }
  9100. return bnx2x_prev_mcp_done(bp);
  9101. }
  9102. static int bnx2x_prev_unload(struct bnx2x *bp)
  9103. {
  9104. int time_counter = 10;
  9105. u32 rc, fw, hw_lock_reg, hw_lock_val;
  9106. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  9107. /* clear hw from errors which may have resulted from an interrupted
  9108. * dmae transaction.
  9109. */
  9110. bnx2x_clean_pglue_errors(bp);
  9111. /* Release previously held locks */
  9112. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  9113. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  9114. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  9115. hw_lock_val = REG_RD(bp, hw_lock_reg);
  9116. if (hw_lock_val) {
  9117. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  9118. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  9119. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  9120. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  9121. }
  9122. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  9123. REG_WR(bp, hw_lock_reg, 0xffffffff);
  9124. } else
  9125. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  9126. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  9127. BNX2X_DEV_INFO("Release previously held alr\n");
  9128. bnx2x_release_alr(bp);
  9129. }
  9130. do {
  9131. int aer = 0;
  9132. /* Lock MCP using an unload request */
  9133. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  9134. if (!fw) {
  9135. BNX2X_ERR("MCP response failure, aborting\n");
  9136. rc = -EBUSY;
  9137. break;
  9138. }
  9139. rc = down_interruptible(&bnx2x_prev_sem);
  9140. if (rc) {
  9141. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  9142. rc);
  9143. } else {
  9144. /* If Path is marked by EEH, ignore unload status */
  9145. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  9146. bnx2x_prev_path_get_entry(bp)->aer);
  9147. up(&bnx2x_prev_sem);
  9148. }
  9149. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  9150. rc = bnx2x_prev_unload_common(bp);
  9151. break;
  9152. }
  9153. /* non-common reply from MCP might require looping */
  9154. rc = bnx2x_prev_unload_uncommon(bp);
  9155. if (rc != BNX2X_PREV_WAIT_NEEDED)
  9156. break;
  9157. msleep(20);
  9158. } while (--time_counter);
  9159. if (!time_counter || rc) {
  9160. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  9161. rc = -EPROBE_DEFER;
  9162. }
  9163. /* Mark function if its port was used to boot from SAN */
  9164. if (bnx2x_port_after_undi(bp))
  9165. bp->link_params.feature_config_flags |=
  9166. FEATURE_CONFIG_BOOT_FROM_SAN;
  9167. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  9168. return rc;
  9169. }
  9170. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  9171. {
  9172. u32 val, val2, val3, val4, id, boot_mode;
  9173. u16 pmc;
  9174. /* Get the chip revision id and number. */
  9175. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  9176. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  9177. id = ((val & 0xffff) << 16);
  9178. val = REG_RD(bp, MISC_REG_CHIP_REV);
  9179. id |= ((val & 0xf) << 12);
  9180. /* Metal is read from PCI regs, but we can't access >=0x400 from
  9181. * the configuration space (so we need to reg_rd)
  9182. */
  9183. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  9184. id |= (((val >> 24) & 0xf) << 4);
  9185. val = REG_RD(bp, MISC_REG_BOND_ID);
  9186. id |= (val & 0xf);
  9187. bp->common.chip_id = id;
  9188. /* force 57811 according to MISC register */
  9189. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  9190. if (CHIP_IS_57810(bp))
  9191. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  9192. (bp->common.chip_id & 0x0000FFFF);
  9193. else if (CHIP_IS_57810_MF(bp))
  9194. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  9195. (bp->common.chip_id & 0x0000FFFF);
  9196. bp->common.chip_id |= 0x1;
  9197. }
  9198. /* Set doorbell size */
  9199. bp->db_size = (1 << BNX2X_DB_SHIFT);
  9200. if (!CHIP_IS_E1x(bp)) {
  9201. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  9202. if ((val & 1) == 0)
  9203. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  9204. else
  9205. val = (val >> 1) & 1;
  9206. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  9207. "2_PORT_MODE");
  9208. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  9209. CHIP_2_PORT_MODE;
  9210. if (CHIP_MODE_IS_4_PORT(bp))
  9211. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  9212. else
  9213. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  9214. } else {
  9215. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  9216. bp->pfid = bp->pf_num; /* 0..7 */
  9217. }
  9218. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  9219. bp->link_params.chip_id = bp->common.chip_id;
  9220. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  9221. val = (REG_RD(bp, 0x2874) & 0x55);
  9222. if ((bp->common.chip_id & 0x1) ||
  9223. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  9224. bp->flags |= ONE_PORT_FLAG;
  9225. BNX2X_DEV_INFO("single port device\n");
  9226. }
  9227. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9228. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9229. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9230. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9231. bp->common.flash_size, bp->common.flash_size);
  9232. bnx2x_init_shmem(bp);
  9233. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9234. MISC_REG_GENERIC_CR_1 :
  9235. MISC_REG_GENERIC_CR_0));
  9236. bp->link_params.shmem_base = bp->common.shmem_base;
  9237. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9238. if (SHMEM2_RD(bp, size) >
  9239. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9240. bp->link_params.lfa_base =
  9241. REG_RD(bp, bp->common.shmem2_base +
  9242. (u32)offsetof(struct shmem2_region,
  9243. lfa_host_addr[BP_PORT(bp)]));
  9244. else
  9245. bp->link_params.lfa_base = 0;
  9246. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9247. bp->common.shmem_base, bp->common.shmem2_base);
  9248. if (!bp->common.shmem_base) {
  9249. BNX2X_DEV_INFO("MCP not active\n");
  9250. bp->flags |= NO_MCP_FLAG;
  9251. return;
  9252. }
  9253. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9254. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9255. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9256. SHARED_HW_CFG_LED_MODE_MASK) >>
  9257. SHARED_HW_CFG_LED_MODE_SHIFT);
  9258. bp->link_params.feature_config_flags = 0;
  9259. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9260. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9261. bp->link_params.feature_config_flags |=
  9262. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9263. else
  9264. bp->link_params.feature_config_flags &=
  9265. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9266. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9267. bp->common.bc_ver = val;
  9268. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9269. if (val < BNX2X_BC_VER) {
  9270. /* for now only warn
  9271. * later we might need to enforce this */
  9272. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9273. BNX2X_BC_VER, val);
  9274. }
  9275. bp->link_params.feature_config_flags |=
  9276. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9277. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9278. bp->link_params.feature_config_flags |=
  9279. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9280. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9281. bp->link_params.feature_config_flags |=
  9282. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9283. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9284. bp->link_params.feature_config_flags |=
  9285. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9286. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9287. bp->link_params.feature_config_flags |=
  9288. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9289. FEATURE_CONFIG_MT_SUPPORT : 0;
  9290. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9291. BC_SUPPORTS_PFC_STATS : 0;
  9292. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9293. BC_SUPPORTS_FCOE_FEATURES : 0;
  9294. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9295. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9296. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9297. BC_SUPPORTS_RMMOD_CMD : 0;
  9298. boot_mode = SHMEM_RD(bp,
  9299. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9300. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9301. switch (boot_mode) {
  9302. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9303. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9304. break;
  9305. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9306. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9307. break;
  9308. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9309. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9310. break;
  9311. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9312. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9313. break;
  9314. }
  9315. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9316. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9317. BNX2X_DEV_INFO("%sWoL capable\n",
  9318. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9319. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9320. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9321. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9322. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9323. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9324. val, val2, val3, val4);
  9325. }
  9326. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9327. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9328. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9329. {
  9330. int pfid = BP_FUNC(bp);
  9331. int igu_sb_id;
  9332. u32 val;
  9333. u8 fid, igu_sb_cnt = 0;
  9334. bp->igu_base_sb = 0xff;
  9335. if (CHIP_INT_MODE_IS_BC(bp)) {
  9336. int vn = BP_VN(bp);
  9337. igu_sb_cnt = bp->igu_sb_cnt;
  9338. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9339. FP_SB_MAX_E1x;
  9340. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9341. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9342. return 0;
  9343. }
  9344. /* IGU in normal mode - read CAM */
  9345. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9346. igu_sb_id++) {
  9347. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9348. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9349. continue;
  9350. fid = IGU_FID(val);
  9351. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9352. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9353. continue;
  9354. if (IGU_VEC(val) == 0)
  9355. /* default status block */
  9356. bp->igu_dsb_id = igu_sb_id;
  9357. else {
  9358. if (bp->igu_base_sb == 0xff)
  9359. bp->igu_base_sb = igu_sb_id;
  9360. igu_sb_cnt++;
  9361. }
  9362. }
  9363. }
  9364. #ifdef CONFIG_PCI_MSI
  9365. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9366. * optional that number of CAM entries will not be equal to the value
  9367. * advertised in PCI.
  9368. * Driver should use the minimal value of both as the actual status
  9369. * block count
  9370. */
  9371. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9372. #endif
  9373. if (igu_sb_cnt == 0) {
  9374. BNX2X_ERR("CAM configuration error\n");
  9375. return -EINVAL;
  9376. }
  9377. return 0;
  9378. }
  9379. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9380. {
  9381. int cfg_size = 0, idx, port = BP_PORT(bp);
  9382. /* Aggregation of supported attributes of all external phys */
  9383. bp->port.supported[0] = 0;
  9384. bp->port.supported[1] = 0;
  9385. switch (bp->link_params.num_phys) {
  9386. case 1:
  9387. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9388. cfg_size = 1;
  9389. break;
  9390. case 2:
  9391. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9392. cfg_size = 1;
  9393. break;
  9394. case 3:
  9395. if (bp->link_params.multi_phy_config &
  9396. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9397. bp->port.supported[1] =
  9398. bp->link_params.phy[EXT_PHY1].supported;
  9399. bp->port.supported[0] =
  9400. bp->link_params.phy[EXT_PHY2].supported;
  9401. } else {
  9402. bp->port.supported[0] =
  9403. bp->link_params.phy[EXT_PHY1].supported;
  9404. bp->port.supported[1] =
  9405. bp->link_params.phy[EXT_PHY2].supported;
  9406. }
  9407. cfg_size = 2;
  9408. break;
  9409. }
  9410. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9411. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9412. SHMEM_RD(bp,
  9413. dev_info.port_hw_config[port].external_phy_config),
  9414. SHMEM_RD(bp,
  9415. dev_info.port_hw_config[port].external_phy_config2));
  9416. return;
  9417. }
  9418. if (CHIP_IS_E3(bp))
  9419. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9420. else {
  9421. switch (switch_cfg) {
  9422. case SWITCH_CFG_1G:
  9423. bp->port.phy_addr = REG_RD(
  9424. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9425. break;
  9426. case SWITCH_CFG_10G:
  9427. bp->port.phy_addr = REG_RD(
  9428. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9429. break;
  9430. default:
  9431. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9432. bp->port.link_config[0]);
  9433. return;
  9434. }
  9435. }
  9436. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9437. /* mask what we support according to speed_cap_mask per configuration */
  9438. for (idx = 0; idx < cfg_size; idx++) {
  9439. if (!(bp->link_params.speed_cap_mask[idx] &
  9440. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9441. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9442. if (!(bp->link_params.speed_cap_mask[idx] &
  9443. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9444. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9445. if (!(bp->link_params.speed_cap_mask[idx] &
  9446. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9447. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9448. if (!(bp->link_params.speed_cap_mask[idx] &
  9449. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9450. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9451. if (!(bp->link_params.speed_cap_mask[idx] &
  9452. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9453. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9454. SUPPORTED_1000baseT_Full);
  9455. if (!(bp->link_params.speed_cap_mask[idx] &
  9456. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9457. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9458. if (!(bp->link_params.speed_cap_mask[idx] &
  9459. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9460. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9461. if (!(bp->link_params.speed_cap_mask[idx] &
  9462. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9463. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9464. }
  9465. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9466. bp->port.supported[1]);
  9467. }
  9468. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9469. {
  9470. u32 link_config, idx, cfg_size = 0;
  9471. bp->port.advertising[0] = 0;
  9472. bp->port.advertising[1] = 0;
  9473. switch (bp->link_params.num_phys) {
  9474. case 1:
  9475. case 2:
  9476. cfg_size = 1;
  9477. break;
  9478. case 3:
  9479. cfg_size = 2;
  9480. break;
  9481. }
  9482. for (idx = 0; idx < cfg_size; idx++) {
  9483. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9484. link_config = bp->port.link_config[idx];
  9485. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9486. case PORT_FEATURE_LINK_SPEED_AUTO:
  9487. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9488. bp->link_params.req_line_speed[idx] =
  9489. SPEED_AUTO_NEG;
  9490. bp->port.advertising[idx] |=
  9491. bp->port.supported[idx];
  9492. if (bp->link_params.phy[EXT_PHY1].type ==
  9493. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9494. bp->port.advertising[idx] |=
  9495. (SUPPORTED_100baseT_Half |
  9496. SUPPORTED_100baseT_Full);
  9497. } else {
  9498. /* force 10G, no AN */
  9499. bp->link_params.req_line_speed[idx] =
  9500. SPEED_10000;
  9501. bp->port.advertising[idx] |=
  9502. (ADVERTISED_10000baseT_Full |
  9503. ADVERTISED_FIBRE);
  9504. continue;
  9505. }
  9506. break;
  9507. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9508. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9509. bp->link_params.req_line_speed[idx] =
  9510. SPEED_10;
  9511. bp->port.advertising[idx] |=
  9512. (ADVERTISED_10baseT_Full |
  9513. ADVERTISED_TP);
  9514. } else {
  9515. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9516. link_config,
  9517. bp->link_params.speed_cap_mask[idx]);
  9518. return;
  9519. }
  9520. break;
  9521. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9522. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9523. bp->link_params.req_line_speed[idx] =
  9524. SPEED_10;
  9525. bp->link_params.req_duplex[idx] =
  9526. DUPLEX_HALF;
  9527. bp->port.advertising[idx] |=
  9528. (ADVERTISED_10baseT_Half |
  9529. ADVERTISED_TP);
  9530. } else {
  9531. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9532. link_config,
  9533. bp->link_params.speed_cap_mask[idx]);
  9534. return;
  9535. }
  9536. break;
  9537. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9538. if (bp->port.supported[idx] &
  9539. SUPPORTED_100baseT_Full) {
  9540. bp->link_params.req_line_speed[idx] =
  9541. SPEED_100;
  9542. bp->port.advertising[idx] |=
  9543. (ADVERTISED_100baseT_Full |
  9544. ADVERTISED_TP);
  9545. } else {
  9546. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9547. link_config,
  9548. bp->link_params.speed_cap_mask[idx]);
  9549. return;
  9550. }
  9551. break;
  9552. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9553. if (bp->port.supported[idx] &
  9554. SUPPORTED_100baseT_Half) {
  9555. bp->link_params.req_line_speed[idx] =
  9556. SPEED_100;
  9557. bp->link_params.req_duplex[idx] =
  9558. DUPLEX_HALF;
  9559. bp->port.advertising[idx] |=
  9560. (ADVERTISED_100baseT_Half |
  9561. ADVERTISED_TP);
  9562. } else {
  9563. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9564. link_config,
  9565. bp->link_params.speed_cap_mask[idx]);
  9566. return;
  9567. }
  9568. break;
  9569. case PORT_FEATURE_LINK_SPEED_1G:
  9570. if (bp->port.supported[idx] &
  9571. SUPPORTED_1000baseT_Full) {
  9572. bp->link_params.req_line_speed[idx] =
  9573. SPEED_1000;
  9574. bp->port.advertising[idx] |=
  9575. (ADVERTISED_1000baseT_Full |
  9576. ADVERTISED_TP);
  9577. } else if (bp->port.supported[idx] &
  9578. SUPPORTED_1000baseKX_Full) {
  9579. bp->link_params.req_line_speed[idx] =
  9580. SPEED_1000;
  9581. bp->port.advertising[idx] |=
  9582. ADVERTISED_1000baseKX_Full;
  9583. } else {
  9584. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9585. link_config,
  9586. bp->link_params.speed_cap_mask[idx]);
  9587. return;
  9588. }
  9589. break;
  9590. case PORT_FEATURE_LINK_SPEED_2_5G:
  9591. if (bp->port.supported[idx] &
  9592. SUPPORTED_2500baseX_Full) {
  9593. bp->link_params.req_line_speed[idx] =
  9594. SPEED_2500;
  9595. bp->port.advertising[idx] |=
  9596. (ADVERTISED_2500baseX_Full |
  9597. ADVERTISED_TP);
  9598. } else {
  9599. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9600. link_config,
  9601. bp->link_params.speed_cap_mask[idx]);
  9602. return;
  9603. }
  9604. break;
  9605. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9606. if (bp->port.supported[idx] &
  9607. SUPPORTED_10000baseT_Full) {
  9608. bp->link_params.req_line_speed[idx] =
  9609. SPEED_10000;
  9610. bp->port.advertising[idx] |=
  9611. (ADVERTISED_10000baseT_Full |
  9612. ADVERTISED_FIBRE);
  9613. } else if (bp->port.supported[idx] &
  9614. SUPPORTED_10000baseKR_Full) {
  9615. bp->link_params.req_line_speed[idx] =
  9616. SPEED_10000;
  9617. bp->port.advertising[idx] |=
  9618. (ADVERTISED_10000baseKR_Full |
  9619. ADVERTISED_FIBRE);
  9620. } else {
  9621. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9622. link_config,
  9623. bp->link_params.speed_cap_mask[idx]);
  9624. return;
  9625. }
  9626. break;
  9627. case PORT_FEATURE_LINK_SPEED_20G:
  9628. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9629. break;
  9630. default:
  9631. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9632. link_config);
  9633. bp->link_params.req_line_speed[idx] =
  9634. SPEED_AUTO_NEG;
  9635. bp->port.advertising[idx] =
  9636. bp->port.supported[idx];
  9637. break;
  9638. }
  9639. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9640. PORT_FEATURE_FLOW_CONTROL_MASK);
  9641. if (bp->link_params.req_flow_ctrl[idx] ==
  9642. BNX2X_FLOW_CTRL_AUTO) {
  9643. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9644. bp->link_params.req_flow_ctrl[idx] =
  9645. BNX2X_FLOW_CTRL_NONE;
  9646. else
  9647. bnx2x_set_requested_fc(bp);
  9648. }
  9649. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9650. bp->link_params.req_line_speed[idx],
  9651. bp->link_params.req_duplex[idx],
  9652. bp->link_params.req_flow_ctrl[idx],
  9653. bp->port.advertising[idx]);
  9654. }
  9655. }
  9656. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9657. {
  9658. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9659. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9660. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9661. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9662. }
  9663. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9664. {
  9665. int port = BP_PORT(bp);
  9666. u32 config;
  9667. u32 ext_phy_type, ext_phy_config, eee_mode;
  9668. bp->link_params.bp = bp;
  9669. bp->link_params.port = port;
  9670. bp->link_params.lane_config =
  9671. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9672. bp->link_params.speed_cap_mask[0] =
  9673. SHMEM_RD(bp,
  9674. dev_info.port_hw_config[port].speed_capability_mask) &
  9675. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9676. bp->link_params.speed_cap_mask[1] =
  9677. SHMEM_RD(bp,
  9678. dev_info.port_hw_config[port].speed_capability_mask2) &
  9679. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9680. bp->port.link_config[0] =
  9681. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9682. bp->port.link_config[1] =
  9683. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9684. bp->link_params.multi_phy_config =
  9685. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9686. /* If the device is capable of WoL, set the default state according
  9687. * to the HW
  9688. */
  9689. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9690. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9691. (config & PORT_FEATURE_WOL_ENABLED));
  9692. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9693. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9694. bp->flags |= NO_ISCSI_FLAG;
  9695. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9696. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9697. bp->flags |= NO_FCOE_FLAG;
  9698. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9699. bp->link_params.lane_config,
  9700. bp->link_params.speed_cap_mask[0],
  9701. bp->port.link_config[0]);
  9702. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9703. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9704. bnx2x_phy_probe(&bp->link_params);
  9705. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9706. bnx2x_link_settings_requested(bp);
  9707. /*
  9708. * If connected directly, work with the internal PHY, otherwise, work
  9709. * with the external PHY
  9710. */
  9711. ext_phy_config =
  9712. SHMEM_RD(bp,
  9713. dev_info.port_hw_config[port].external_phy_config);
  9714. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9715. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9716. bp->mdio.prtad = bp->port.phy_addr;
  9717. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9718. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9719. bp->mdio.prtad =
  9720. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9721. /* Configure link feature according to nvram value */
  9722. eee_mode = (((SHMEM_RD(bp, dev_info.
  9723. port_feature_config[port].eee_power_mode)) &
  9724. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9725. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9726. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9727. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9728. EEE_MODE_ENABLE_LPI |
  9729. EEE_MODE_OUTPUT_TIME;
  9730. } else {
  9731. bp->link_params.eee_mode = 0;
  9732. }
  9733. }
  9734. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9735. {
  9736. u32 no_flags = NO_ISCSI_FLAG;
  9737. int port = BP_PORT(bp);
  9738. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9739. drv_lic_key[port].max_iscsi_conn);
  9740. if (!CNIC_SUPPORT(bp)) {
  9741. bp->flags |= no_flags;
  9742. return;
  9743. }
  9744. /* Get the number of maximum allowed iSCSI connections */
  9745. bp->cnic_eth_dev.max_iscsi_conn =
  9746. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9747. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9748. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9749. bp->cnic_eth_dev.max_iscsi_conn);
  9750. /*
  9751. * If maximum allowed number of connections is zero -
  9752. * disable the feature.
  9753. */
  9754. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9755. bp->flags |= no_flags;
  9756. }
  9757. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9758. {
  9759. /* Port info */
  9760. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9761. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9762. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9763. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9764. /* Node info */
  9765. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9766. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9767. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9768. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9769. }
  9770. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9771. {
  9772. u8 count = 0;
  9773. if (IS_MF(bp)) {
  9774. u8 fid;
  9775. /* iterate over absolute function ids for this path: */
  9776. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9777. if (IS_MF_SD(bp)) {
  9778. u32 cfg = MF_CFG_RD(bp,
  9779. func_mf_config[fid].config);
  9780. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9781. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9782. FUNC_MF_CFG_PROTOCOL_FCOE))
  9783. count++;
  9784. } else {
  9785. u32 cfg = MF_CFG_RD(bp,
  9786. func_ext_config[fid].
  9787. func_cfg);
  9788. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9789. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9790. count++;
  9791. }
  9792. }
  9793. } else { /* SF */
  9794. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9795. for (port = 0; port < port_cnt; port++) {
  9796. u32 lic = SHMEM_RD(bp,
  9797. drv_lic_key[port].max_fcoe_conn) ^
  9798. FW_ENCODE_32BIT_PATTERN;
  9799. if (lic)
  9800. count++;
  9801. }
  9802. }
  9803. return count;
  9804. }
  9805. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9806. {
  9807. int port = BP_PORT(bp);
  9808. int func = BP_ABS_FUNC(bp);
  9809. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9810. drv_lic_key[port].max_fcoe_conn);
  9811. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9812. if (!CNIC_SUPPORT(bp)) {
  9813. bp->flags |= NO_FCOE_FLAG;
  9814. return;
  9815. }
  9816. /* Get the number of maximum allowed FCoE connections */
  9817. bp->cnic_eth_dev.max_fcoe_conn =
  9818. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9819. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9820. /* Calculate the number of maximum allowed FCoE tasks */
  9821. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9822. /* check if FCoE resources must be shared between different functions */
  9823. if (num_fcoe_func)
  9824. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9825. /* Read the WWN: */
  9826. if (!IS_MF(bp)) {
  9827. /* Port info */
  9828. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9829. SHMEM_RD(bp,
  9830. dev_info.port_hw_config[port].
  9831. fcoe_wwn_port_name_upper);
  9832. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9833. SHMEM_RD(bp,
  9834. dev_info.port_hw_config[port].
  9835. fcoe_wwn_port_name_lower);
  9836. /* Node info */
  9837. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9838. SHMEM_RD(bp,
  9839. dev_info.port_hw_config[port].
  9840. fcoe_wwn_node_name_upper);
  9841. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9842. SHMEM_RD(bp,
  9843. dev_info.port_hw_config[port].
  9844. fcoe_wwn_node_name_lower);
  9845. } else if (!IS_MF_SD(bp)) {
  9846. /* Read the WWN info only if the FCoE feature is enabled for
  9847. * this function.
  9848. */
  9849. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9850. bnx2x_get_ext_wwn_info(bp, func);
  9851. } else {
  9852. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9853. bnx2x_get_ext_wwn_info(bp, func);
  9854. }
  9855. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9856. /*
  9857. * If maximum allowed number of connections is zero -
  9858. * disable the feature.
  9859. */
  9860. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9861. bp->flags |= NO_FCOE_FLAG;
  9862. }
  9863. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9864. {
  9865. /*
  9866. * iSCSI may be dynamically disabled but reading
  9867. * info here we will decrease memory usage by driver
  9868. * if the feature is disabled for good
  9869. */
  9870. bnx2x_get_iscsi_info(bp);
  9871. bnx2x_get_fcoe_info(bp);
  9872. }
  9873. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9874. {
  9875. u32 val, val2;
  9876. int func = BP_ABS_FUNC(bp);
  9877. int port = BP_PORT(bp);
  9878. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9879. u8 *fip_mac = bp->fip_mac;
  9880. if (IS_MF(bp)) {
  9881. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9882. * FCoE MAC then the appropriate feature should be disabled.
  9883. * In non SD mode features configuration comes from struct
  9884. * func_ext_config.
  9885. */
  9886. if (!IS_MF_SD(bp)) {
  9887. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9888. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9889. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9890. iscsi_mac_addr_upper);
  9891. val = MF_CFG_RD(bp, func_ext_config[func].
  9892. iscsi_mac_addr_lower);
  9893. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9894. BNX2X_DEV_INFO
  9895. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9896. } else {
  9897. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9898. }
  9899. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9900. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9901. fcoe_mac_addr_upper);
  9902. val = MF_CFG_RD(bp, func_ext_config[func].
  9903. fcoe_mac_addr_lower);
  9904. bnx2x_set_mac_buf(fip_mac, val, val2);
  9905. BNX2X_DEV_INFO
  9906. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9907. } else {
  9908. bp->flags |= NO_FCOE_FLAG;
  9909. }
  9910. bp->mf_ext_config = cfg;
  9911. } else { /* SD MODE */
  9912. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9913. /* use primary mac as iscsi mac */
  9914. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9915. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9916. BNX2X_DEV_INFO
  9917. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9918. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9919. /* use primary mac as fip mac */
  9920. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9921. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9922. BNX2X_DEV_INFO
  9923. ("Read FIP MAC: %pM\n", fip_mac);
  9924. }
  9925. }
  9926. /* If this is a storage-only interface, use SAN mac as
  9927. * primary MAC. Notice that for SD this is already the case,
  9928. * as the SAN mac was copied from the primary MAC.
  9929. */
  9930. if (IS_MF_FCOE_AFEX(bp))
  9931. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9932. } else {
  9933. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9934. iscsi_mac_upper);
  9935. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9936. iscsi_mac_lower);
  9937. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9938. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9939. fcoe_fip_mac_upper);
  9940. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9941. fcoe_fip_mac_lower);
  9942. bnx2x_set_mac_buf(fip_mac, val, val2);
  9943. }
  9944. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9945. if (!is_valid_ether_addr(iscsi_mac)) {
  9946. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9947. eth_zero_addr(iscsi_mac);
  9948. }
  9949. /* Disable FCoE if MAC configuration is invalid. */
  9950. if (!is_valid_ether_addr(fip_mac)) {
  9951. bp->flags |= NO_FCOE_FLAG;
  9952. eth_zero_addr(bp->fip_mac);
  9953. }
  9954. }
  9955. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9956. {
  9957. u32 val, val2;
  9958. int func = BP_ABS_FUNC(bp);
  9959. int port = BP_PORT(bp);
  9960. /* Zero primary MAC configuration */
  9961. eth_zero_addr(bp->dev->dev_addr);
  9962. if (BP_NOMCP(bp)) {
  9963. BNX2X_ERROR("warning: random MAC workaround active\n");
  9964. eth_hw_addr_random(bp->dev);
  9965. } else if (IS_MF(bp)) {
  9966. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9967. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9968. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9969. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9970. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9971. if (CNIC_SUPPORT(bp))
  9972. bnx2x_get_cnic_mac_hwinfo(bp);
  9973. } else {
  9974. /* in SF read MACs from port configuration */
  9975. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9976. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9977. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9978. if (CNIC_SUPPORT(bp))
  9979. bnx2x_get_cnic_mac_hwinfo(bp);
  9980. }
  9981. if (!BP_NOMCP(bp)) {
  9982. /* Read physical port identifier from shmem */
  9983. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9984. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9985. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9986. bp->flags |= HAS_PHYS_PORT_ID;
  9987. }
  9988. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9989. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9990. dev_err(&bp->pdev->dev,
  9991. "bad Ethernet MAC address configuration: %pM\n"
  9992. "change it manually before bringing up the appropriate network interface\n",
  9993. bp->dev->dev_addr);
  9994. }
  9995. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9996. {
  9997. int tmp;
  9998. u32 cfg;
  9999. if (IS_VF(bp))
  10000. return false;
  10001. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  10002. /* Take function: tmp = func */
  10003. tmp = BP_ABS_FUNC(bp);
  10004. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  10005. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  10006. } else {
  10007. /* Take port: tmp = port */
  10008. tmp = BP_PORT(bp);
  10009. cfg = SHMEM_RD(bp,
  10010. dev_info.port_hw_config[tmp].generic_features);
  10011. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  10012. }
  10013. return cfg;
  10014. }
  10015. static void validate_set_si_mode(struct bnx2x *bp)
  10016. {
  10017. u8 func = BP_ABS_FUNC(bp);
  10018. u32 val;
  10019. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  10020. /* check for legal mac (upper bytes) */
  10021. if (val != 0xffff) {
  10022. bp->mf_mode = MULTI_FUNCTION_SI;
  10023. bp->mf_config[BP_VN(bp)] =
  10024. MF_CFG_RD(bp, func_mf_config[func].config);
  10025. } else
  10026. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  10027. }
  10028. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  10029. {
  10030. int /*abs*/func = BP_ABS_FUNC(bp);
  10031. int vn, mfw_vn;
  10032. u32 val = 0, val2 = 0;
  10033. int rc = 0;
  10034. /* Validate that chip access is feasible */
  10035. if (REG_RD(bp, MISC_REG_CHIP_NUM) == 0xffffffff) {
  10036. dev_err(&bp->pdev->dev,
  10037. "Chip read returns all Fs. Preventing probe from continuing\n");
  10038. return -EINVAL;
  10039. }
  10040. bnx2x_get_common_hwinfo(bp);
  10041. /*
  10042. * initialize IGU parameters
  10043. */
  10044. if (CHIP_IS_E1x(bp)) {
  10045. bp->common.int_block = INT_BLOCK_HC;
  10046. bp->igu_dsb_id = DEF_SB_IGU_ID;
  10047. bp->igu_base_sb = 0;
  10048. } else {
  10049. bp->common.int_block = INT_BLOCK_IGU;
  10050. /* do not allow device reset during IGU info processing */
  10051. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10052. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  10053. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10054. int tout = 5000;
  10055. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  10056. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  10057. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  10058. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  10059. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10060. tout--;
  10061. usleep_range(1000, 2000);
  10062. }
  10063. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10064. dev_err(&bp->pdev->dev,
  10065. "FORCING Normal Mode failed!!!\n");
  10066. bnx2x_release_hw_lock(bp,
  10067. HW_LOCK_RESOURCE_RESET);
  10068. return -EPERM;
  10069. }
  10070. }
  10071. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10072. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  10073. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  10074. } else
  10075. BNX2X_DEV_INFO("IGU Normal Mode\n");
  10076. rc = bnx2x_get_igu_cam_info(bp);
  10077. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10078. if (rc)
  10079. return rc;
  10080. }
  10081. /*
  10082. * set base FW non-default (fast path) status block id, this value is
  10083. * used to initialize the fw_sb_id saved on the fp/queue structure to
  10084. * determine the id used by the FW.
  10085. */
  10086. if (CHIP_IS_E1x(bp))
  10087. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  10088. else /*
  10089. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  10090. * the same queue are indicated on the same IGU SB). So we prefer
  10091. * FW and IGU SBs to be the same value.
  10092. */
  10093. bp->base_fw_ndsb = bp->igu_base_sb;
  10094. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  10095. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  10096. bp->igu_sb_cnt, bp->base_fw_ndsb);
  10097. /*
  10098. * Initialize MF configuration
  10099. */
  10100. bp->mf_ov = 0;
  10101. bp->mf_mode = 0;
  10102. bp->mf_sub_mode = 0;
  10103. vn = BP_VN(bp);
  10104. mfw_vn = BP_FW_MB_IDX(bp);
  10105. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  10106. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  10107. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  10108. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  10109. if (SHMEM2_HAS(bp, mf_cfg_addr))
  10110. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  10111. else
  10112. bp->common.mf_cfg_base = bp->common.shmem_base +
  10113. offsetof(struct shmem_region, func_mb) +
  10114. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  10115. /*
  10116. * get mf configuration:
  10117. * 1. Existence of MF configuration
  10118. * 2. MAC address must be legal (check only upper bytes)
  10119. * for Switch-Independent mode;
  10120. * OVLAN must be legal for Switch-Dependent mode
  10121. * 3. SF_MODE configures specific MF mode
  10122. */
  10123. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10124. /* get mf configuration */
  10125. val = SHMEM_RD(bp,
  10126. dev_info.shared_feature_config.config);
  10127. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  10128. switch (val) {
  10129. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  10130. validate_set_si_mode(bp);
  10131. break;
  10132. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  10133. if ((!CHIP_IS_E1x(bp)) &&
  10134. (MF_CFG_RD(bp, func_mf_config[func].
  10135. mac_upper) != 0xffff) &&
  10136. (SHMEM2_HAS(bp,
  10137. afex_driver_support))) {
  10138. bp->mf_mode = MULTI_FUNCTION_AFEX;
  10139. bp->mf_config[vn] = MF_CFG_RD(bp,
  10140. func_mf_config[func].config);
  10141. } else {
  10142. BNX2X_DEV_INFO("can not configure afex mode\n");
  10143. }
  10144. break;
  10145. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  10146. /* get OV configuration */
  10147. val = MF_CFG_RD(bp,
  10148. func_mf_config[FUNC_0].e1hov_tag);
  10149. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  10150. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10151. bp->mf_mode = MULTI_FUNCTION_SD;
  10152. bp->mf_config[vn] = MF_CFG_RD(bp,
  10153. func_mf_config[func].config);
  10154. } else
  10155. BNX2X_DEV_INFO("illegal OV for SD\n");
  10156. break;
  10157. case SHARED_FEAT_CFG_FORCE_SF_MODE_BD_MODE:
  10158. bp->mf_mode = MULTI_FUNCTION_SD;
  10159. bp->mf_sub_mode = SUB_MF_MODE_BD;
  10160. bp->mf_config[vn] =
  10161. MF_CFG_RD(bp,
  10162. func_mf_config[func].config);
  10163. if (SHMEM2_HAS(bp, mtu_size)) {
  10164. int mtu_idx = BP_FW_MB_IDX(bp);
  10165. u16 mtu_size;
  10166. u32 mtu;
  10167. mtu = SHMEM2_RD(bp, mtu_size[mtu_idx]);
  10168. mtu_size = (u16)mtu;
  10169. DP(NETIF_MSG_IFUP, "Read MTU size %04x [%08x]\n",
  10170. mtu_size, mtu);
  10171. /* if valid: update device mtu */
  10172. if ((mtu_size >= ETH_MIN_PACKET_SIZE) &&
  10173. (mtu_size <=
  10174. ETH_MAX_JUMBO_PACKET_SIZE))
  10175. bp->dev->mtu = mtu_size;
  10176. }
  10177. break;
  10178. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  10179. bp->mf_mode = MULTI_FUNCTION_SD;
  10180. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  10181. bp->mf_config[vn] =
  10182. MF_CFG_RD(bp,
  10183. func_mf_config[func].config);
  10184. break;
  10185. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  10186. bp->mf_config[vn] = 0;
  10187. break;
  10188. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  10189. val2 = SHMEM_RD(bp,
  10190. dev_info.shared_hw_config.config_3);
  10191. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  10192. switch (val2) {
  10193. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  10194. validate_set_si_mode(bp);
  10195. bp->mf_sub_mode =
  10196. SUB_MF_MODE_NPAR1_DOT_5;
  10197. break;
  10198. default:
  10199. /* Unknown configuration */
  10200. bp->mf_config[vn] = 0;
  10201. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  10202. val);
  10203. }
  10204. break;
  10205. default:
  10206. /* Unknown configuration: reset mf_config */
  10207. bp->mf_config[vn] = 0;
  10208. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  10209. }
  10210. }
  10211. BNX2X_DEV_INFO("%s function mode\n",
  10212. IS_MF(bp) ? "multi" : "single");
  10213. switch (bp->mf_mode) {
  10214. case MULTI_FUNCTION_SD:
  10215. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  10216. FUNC_MF_CFG_E1HOV_TAG_MASK;
  10217. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10218. bp->mf_ov = val;
  10219. bp->path_has_ovlan = true;
  10220. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  10221. func, bp->mf_ov, bp->mf_ov);
  10222. } else if ((bp->mf_sub_mode == SUB_MF_MODE_UFP) ||
  10223. (bp->mf_sub_mode == SUB_MF_MODE_BD)) {
  10224. dev_err(&bp->pdev->dev,
  10225. "Unexpected - no valid MF OV for func %d in UFP/BD mode\n",
  10226. func);
  10227. bp->path_has_ovlan = true;
  10228. } else {
  10229. dev_err(&bp->pdev->dev,
  10230. "No valid MF OV for func %d, aborting\n",
  10231. func);
  10232. return -EPERM;
  10233. }
  10234. break;
  10235. case MULTI_FUNCTION_AFEX:
  10236. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  10237. break;
  10238. case MULTI_FUNCTION_SI:
  10239. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  10240. func);
  10241. break;
  10242. default:
  10243. if (vn) {
  10244. dev_err(&bp->pdev->dev,
  10245. "VN %d is in a single function mode, aborting\n",
  10246. vn);
  10247. return -EPERM;
  10248. }
  10249. break;
  10250. }
  10251. /* check if other port on the path needs ovlan:
  10252. * Since MF configuration is shared between ports
  10253. * Possible mixed modes are only
  10254. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  10255. */
  10256. if (CHIP_MODE_IS_4_PORT(bp) &&
  10257. !bp->path_has_ovlan &&
  10258. !IS_MF(bp) &&
  10259. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10260. u8 other_port = !BP_PORT(bp);
  10261. u8 other_func = BP_PATH(bp) + 2*other_port;
  10262. val = MF_CFG_RD(bp,
  10263. func_mf_config[other_func].e1hov_tag);
  10264. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  10265. bp->path_has_ovlan = true;
  10266. }
  10267. }
  10268. /* adjust igu_sb_cnt to MF for E1H */
  10269. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10270. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10271. /* port info */
  10272. bnx2x_get_port_hwinfo(bp);
  10273. /* Get MAC addresses */
  10274. bnx2x_get_mac_hwinfo(bp);
  10275. bnx2x_get_cnic_info(bp);
  10276. return rc;
  10277. }
  10278. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10279. {
  10280. int cnt, i, block_end, rodi;
  10281. char vpd_start[BNX2X_VPD_LEN+1];
  10282. char str_id_reg[VENDOR_ID_LEN+1];
  10283. char str_id_cap[VENDOR_ID_LEN+1];
  10284. char *vpd_data;
  10285. char *vpd_extended_data = NULL;
  10286. u8 len;
  10287. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10288. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10289. if (cnt < BNX2X_VPD_LEN)
  10290. goto out_not_found;
  10291. /* VPD RO tag should be first tag after identifier string, hence
  10292. * we should be able to find it in first BNX2X_VPD_LEN chars
  10293. */
  10294. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10295. PCI_VPD_LRDT_RO_DATA);
  10296. if (i < 0)
  10297. goto out_not_found;
  10298. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10299. pci_vpd_lrdt_size(&vpd_start[i]);
  10300. i += PCI_VPD_LRDT_TAG_SIZE;
  10301. if (block_end > BNX2X_VPD_LEN) {
  10302. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10303. if (vpd_extended_data == NULL)
  10304. goto out_not_found;
  10305. /* read rest of vpd image into vpd_extended_data */
  10306. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10307. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10308. block_end - BNX2X_VPD_LEN,
  10309. vpd_extended_data + BNX2X_VPD_LEN);
  10310. if (cnt < (block_end - BNX2X_VPD_LEN))
  10311. goto out_not_found;
  10312. vpd_data = vpd_extended_data;
  10313. } else
  10314. vpd_data = vpd_start;
  10315. /* now vpd_data holds full vpd content in both cases */
  10316. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10317. PCI_VPD_RO_KEYWORD_MFR_ID);
  10318. if (rodi < 0)
  10319. goto out_not_found;
  10320. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10321. if (len != VENDOR_ID_LEN)
  10322. goto out_not_found;
  10323. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10324. /* vendor specific info */
  10325. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10326. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10327. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10328. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10329. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10330. PCI_VPD_RO_KEYWORD_VENDOR0);
  10331. if (rodi >= 0) {
  10332. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10333. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10334. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10335. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10336. bp->fw_ver[len] = ' ';
  10337. }
  10338. }
  10339. kfree(vpd_extended_data);
  10340. return;
  10341. }
  10342. out_not_found:
  10343. kfree(vpd_extended_data);
  10344. return;
  10345. }
  10346. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10347. {
  10348. u32 flags = 0;
  10349. if (CHIP_REV_IS_FPGA(bp))
  10350. SET_FLAGS(flags, MODE_FPGA);
  10351. else if (CHIP_REV_IS_EMUL(bp))
  10352. SET_FLAGS(flags, MODE_EMUL);
  10353. else
  10354. SET_FLAGS(flags, MODE_ASIC);
  10355. if (CHIP_MODE_IS_4_PORT(bp))
  10356. SET_FLAGS(flags, MODE_PORT4);
  10357. else
  10358. SET_FLAGS(flags, MODE_PORT2);
  10359. if (CHIP_IS_E2(bp))
  10360. SET_FLAGS(flags, MODE_E2);
  10361. else if (CHIP_IS_E3(bp)) {
  10362. SET_FLAGS(flags, MODE_E3);
  10363. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10364. SET_FLAGS(flags, MODE_E3_A0);
  10365. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10366. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10367. }
  10368. if (IS_MF(bp)) {
  10369. SET_FLAGS(flags, MODE_MF);
  10370. switch (bp->mf_mode) {
  10371. case MULTI_FUNCTION_SD:
  10372. SET_FLAGS(flags, MODE_MF_SD);
  10373. break;
  10374. case MULTI_FUNCTION_SI:
  10375. SET_FLAGS(flags, MODE_MF_SI);
  10376. break;
  10377. case MULTI_FUNCTION_AFEX:
  10378. SET_FLAGS(flags, MODE_MF_AFEX);
  10379. break;
  10380. }
  10381. } else
  10382. SET_FLAGS(flags, MODE_SF);
  10383. #if defined(__LITTLE_ENDIAN)
  10384. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10385. #else /*(__BIG_ENDIAN)*/
  10386. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10387. #endif
  10388. INIT_MODE_FLAGS(bp) = flags;
  10389. }
  10390. static int bnx2x_init_bp(struct bnx2x *bp)
  10391. {
  10392. int func;
  10393. int rc;
  10394. mutex_init(&bp->port.phy_mutex);
  10395. mutex_init(&bp->fw_mb_mutex);
  10396. mutex_init(&bp->drv_info_mutex);
  10397. sema_init(&bp->stats_lock, 1);
  10398. bp->drv_info_mng_owner = false;
  10399. INIT_LIST_HEAD(&bp->vlan_reg);
  10400. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10401. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10402. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10403. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10404. if (IS_PF(bp)) {
  10405. rc = bnx2x_get_hwinfo(bp);
  10406. if (rc)
  10407. return rc;
  10408. } else {
  10409. eth_zero_addr(bp->dev->dev_addr);
  10410. }
  10411. bnx2x_set_modes_bitmap(bp);
  10412. rc = bnx2x_alloc_mem_bp(bp);
  10413. if (rc)
  10414. return rc;
  10415. bnx2x_read_fwinfo(bp);
  10416. func = BP_FUNC(bp);
  10417. /* need to reset chip if undi was active */
  10418. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10419. /* init fw_seq */
  10420. bp->fw_seq =
  10421. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10422. DRV_MSG_SEQ_NUMBER_MASK;
  10423. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10424. rc = bnx2x_prev_unload(bp);
  10425. if (rc) {
  10426. bnx2x_free_mem_bp(bp);
  10427. return rc;
  10428. }
  10429. }
  10430. if (CHIP_REV_IS_FPGA(bp))
  10431. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10432. if (BP_NOMCP(bp) && (func == 0))
  10433. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10434. bp->disable_tpa = disable_tpa;
  10435. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10436. /* Reduce memory usage in kdump environment by disabling TPA */
  10437. bp->disable_tpa |= is_kdump_kernel();
  10438. /* Set TPA flags */
  10439. if (bp->disable_tpa) {
  10440. bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
  10441. bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW);
  10442. }
  10443. if (CHIP_IS_E1(bp))
  10444. bp->dropless_fc = 0;
  10445. else
  10446. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10447. bp->mrrs = mrrs;
  10448. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10449. if (IS_VF(bp))
  10450. bp->rx_ring_size = MAX_RX_AVAIL;
  10451. /* make sure that the numbers are in the right granularity */
  10452. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10453. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10454. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10455. timer_setup(&bp->timer, bnx2x_timer, 0);
  10456. bp->timer.expires = jiffies + bp->current_interval;
  10457. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10458. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10459. SHMEM2_HAS(bp, dcbx_en) &&
  10460. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10461. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset) &&
  10462. SHMEM2_RD(bp, dcbx_en[BP_PORT(bp)])) {
  10463. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10464. bnx2x_dcbx_init_params(bp);
  10465. } else {
  10466. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10467. }
  10468. if (CHIP_IS_E1x(bp))
  10469. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10470. else
  10471. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10472. /* multiple tx priority */
  10473. if (IS_VF(bp))
  10474. bp->max_cos = 1;
  10475. else if (CHIP_IS_E1x(bp))
  10476. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10477. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10478. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10479. else if (CHIP_IS_E3B0(bp))
  10480. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10481. else
  10482. BNX2X_ERR("unknown chip %x revision %x\n",
  10483. CHIP_NUM(bp), CHIP_REV(bp));
  10484. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10485. /* We need at least one default status block for slow-path events,
  10486. * second status block for the L2 queue, and a third status block for
  10487. * CNIC if supported.
  10488. */
  10489. if (IS_VF(bp))
  10490. bp->min_msix_vec_cnt = 1;
  10491. else if (CNIC_SUPPORT(bp))
  10492. bp->min_msix_vec_cnt = 3;
  10493. else /* PF w/o cnic */
  10494. bp->min_msix_vec_cnt = 2;
  10495. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10496. bp->dump_preset_idx = 1;
  10497. if (CHIP_IS_E3B0(bp))
  10498. bp->flags |= PTP_SUPPORTED;
  10499. return rc;
  10500. }
  10501. /****************************************************************************
  10502. * General service functions
  10503. ****************************************************************************/
  10504. /*
  10505. * net_device service functions
  10506. */
  10507. /* called with rtnl_lock */
  10508. static int bnx2x_open(struct net_device *dev)
  10509. {
  10510. struct bnx2x *bp = netdev_priv(dev);
  10511. int rc;
  10512. bp->stats_init = true;
  10513. netif_carrier_off(dev);
  10514. bnx2x_set_power_state(bp, PCI_D0);
  10515. /* If parity had happen during the unload, then attentions
  10516. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10517. * want the first function loaded on the current engine to
  10518. * complete the recovery.
  10519. * Parity recovery is only relevant for PF driver.
  10520. */
  10521. if (IS_PF(bp)) {
  10522. int other_engine = BP_PATH(bp) ? 0 : 1;
  10523. bool other_load_status, load_status;
  10524. bool global = false;
  10525. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10526. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10527. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10528. bnx2x_chk_parity_attn(bp, &global, true)) {
  10529. do {
  10530. /* If there are attentions and they are in a
  10531. * global blocks, set the GLOBAL_RESET bit
  10532. * regardless whether it will be this function
  10533. * that will complete the recovery or not.
  10534. */
  10535. if (global)
  10536. bnx2x_set_reset_global(bp);
  10537. /* Only the first function on the current
  10538. * engine should try to recover in open. In case
  10539. * of attentions in global blocks only the first
  10540. * in the chip should try to recover.
  10541. */
  10542. if ((!load_status &&
  10543. (!global || !other_load_status)) &&
  10544. bnx2x_trylock_leader_lock(bp) &&
  10545. !bnx2x_leader_reset(bp)) {
  10546. netdev_info(bp->dev,
  10547. "Recovered in open\n");
  10548. break;
  10549. }
  10550. /* recovery has failed... */
  10551. bnx2x_set_power_state(bp, PCI_D3hot);
  10552. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10553. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10554. "If you still see this message after a few retries then power cycle is required.\n");
  10555. return -EAGAIN;
  10556. } while (0);
  10557. }
  10558. }
  10559. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10560. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10561. if (rc)
  10562. return rc;
  10563. if (IS_PF(bp))
  10564. udp_tunnel_get_rx_info(dev);
  10565. return 0;
  10566. }
  10567. /* called with rtnl_lock */
  10568. static int bnx2x_close(struct net_device *dev)
  10569. {
  10570. struct bnx2x *bp = netdev_priv(dev);
  10571. /* Unload the driver, release IRQs */
  10572. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10573. return 0;
  10574. }
  10575. struct bnx2x_mcast_list_elem_group
  10576. {
  10577. struct list_head mcast_group_link;
  10578. struct bnx2x_mcast_list_elem mcast_elems[];
  10579. };
  10580. #define MCAST_ELEMS_PER_PG \
  10581. ((PAGE_SIZE - sizeof(struct bnx2x_mcast_list_elem_group)) / \
  10582. sizeof(struct bnx2x_mcast_list_elem))
  10583. static void bnx2x_free_mcast_macs_list(struct list_head *mcast_group_list)
  10584. {
  10585. struct bnx2x_mcast_list_elem_group *current_mcast_group;
  10586. while (!list_empty(mcast_group_list)) {
  10587. current_mcast_group = list_first_entry(mcast_group_list,
  10588. struct bnx2x_mcast_list_elem_group,
  10589. mcast_group_link);
  10590. list_del(&current_mcast_group->mcast_group_link);
  10591. free_page((unsigned long)current_mcast_group);
  10592. }
  10593. }
  10594. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10595. struct bnx2x_mcast_ramrod_params *p,
  10596. struct list_head *mcast_group_list)
  10597. {
  10598. struct bnx2x_mcast_list_elem *mc_mac;
  10599. struct netdev_hw_addr *ha;
  10600. struct bnx2x_mcast_list_elem_group *current_mcast_group = NULL;
  10601. int mc_count = netdev_mc_count(bp->dev);
  10602. int offset = 0;
  10603. INIT_LIST_HEAD(&p->mcast_list);
  10604. netdev_for_each_mc_addr(ha, bp->dev) {
  10605. if (!offset) {
  10606. current_mcast_group =
  10607. (struct bnx2x_mcast_list_elem_group *)
  10608. __get_free_page(GFP_ATOMIC);
  10609. if (!current_mcast_group) {
  10610. bnx2x_free_mcast_macs_list(mcast_group_list);
  10611. BNX2X_ERR("Failed to allocate mc MAC list\n");
  10612. return -ENOMEM;
  10613. }
  10614. list_add(&current_mcast_group->mcast_group_link,
  10615. mcast_group_list);
  10616. }
  10617. mc_mac = &current_mcast_group->mcast_elems[offset];
  10618. mc_mac->mac = bnx2x_mc_addr(ha);
  10619. list_add_tail(&mc_mac->link, &p->mcast_list);
  10620. offset++;
  10621. if (offset == MCAST_ELEMS_PER_PG)
  10622. offset = 0;
  10623. }
  10624. p->mcast_list_len = mc_count;
  10625. return 0;
  10626. }
  10627. /**
  10628. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10629. *
  10630. * @bp: driver handle
  10631. *
  10632. * We will use zero (0) as a MAC type for these MACs.
  10633. */
  10634. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10635. {
  10636. int rc;
  10637. struct net_device *dev = bp->dev;
  10638. struct netdev_hw_addr *ha;
  10639. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10640. unsigned long ramrod_flags = 0;
  10641. /* First schedule a cleanup up of old configuration */
  10642. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10643. if (rc < 0) {
  10644. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10645. return rc;
  10646. }
  10647. netdev_for_each_uc_addr(ha, dev) {
  10648. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10649. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10650. if (rc == -EEXIST) {
  10651. DP(BNX2X_MSG_SP,
  10652. "Failed to schedule ADD operations: %d\n", rc);
  10653. /* do not treat adding same MAC as error */
  10654. rc = 0;
  10655. } else if (rc < 0) {
  10656. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10657. rc);
  10658. return rc;
  10659. }
  10660. }
  10661. /* Execute the pending commands */
  10662. __set_bit(RAMROD_CONT, &ramrod_flags);
  10663. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10664. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10665. }
  10666. static int bnx2x_set_mc_list_e1x(struct bnx2x *bp)
  10667. {
  10668. LIST_HEAD(mcast_group_list);
  10669. struct net_device *dev = bp->dev;
  10670. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10671. int rc = 0;
  10672. rparam.mcast_obj = &bp->mcast_obj;
  10673. /* first, clear all configured multicast MACs */
  10674. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10675. if (rc < 0) {
  10676. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10677. return rc;
  10678. }
  10679. /* then, configure a new MACs list */
  10680. if (netdev_mc_count(dev)) {
  10681. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10682. if (rc)
  10683. return rc;
  10684. /* Now add the new MACs */
  10685. rc = bnx2x_config_mcast(bp, &rparam,
  10686. BNX2X_MCAST_CMD_ADD);
  10687. if (rc < 0)
  10688. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10689. rc);
  10690. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10691. }
  10692. return rc;
  10693. }
  10694. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10695. {
  10696. LIST_HEAD(mcast_group_list);
  10697. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10698. struct net_device *dev = bp->dev;
  10699. int rc = 0;
  10700. /* On older adapters, we need to flush and re-add filters */
  10701. if (CHIP_IS_E1x(bp))
  10702. return bnx2x_set_mc_list_e1x(bp);
  10703. rparam.mcast_obj = &bp->mcast_obj;
  10704. if (netdev_mc_count(dev)) {
  10705. rc = bnx2x_init_mcast_macs_list(bp, &rparam, &mcast_group_list);
  10706. if (rc)
  10707. return rc;
  10708. /* Override the curently configured set of mc filters */
  10709. rc = bnx2x_config_mcast(bp, &rparam,
  10710. BNX2X_MCAST_CMD_SET);
  10711. if (rc < 0)
  10712. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10713. rc);
  10714. bnx2x_free_mcast_macs_list(&mcast_group_list);
  10715. } else {
  10716. /* If no mc addresses are required, flush the configuration */
  10717. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10718. if (rc < 0)
  10719. BNX2X_ERR("Failed to clear multicast configuration %d\n",
  10720. rc);
  10721. }
  10722. return rc;
  10723. }
  10724. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10725. static void bnx2x_set_rx_mode(struct net_device *dev)
  10726. {
  10727. struct bnx2x *bp = netdev_priv(dev);
  10728. if (bp->state != BNX2X_STATE_OPEN) {
  10729. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10730. return;
  10731. } else {
  10732. /* Schedule an SP task to handle rest of change */
  10733. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10734. NETIF_MSG_IFUP);
  10735. }
  10736. }
  10737. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10738. {
  10739. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10740. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10741. netif_addr_lock_bh(bp->dev);
  10742. if (bp->dev->flags & IFF_PROMISC) {
  10743. rx_mode = BNX2X_RX_MODE_PROMISC;
  10744. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10745. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10746. CHIP_IS_E1(bp))) {
  10747. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10748. } else {
  10749. if (IS_PF(bp)) {
  10750. /* some multicasts */
  10751. if (bnx2x_set_mc_list(bp) < 0)
  10752. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10753. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10754. netif_addr_unlock_bh(bp->dev);
  10755. if (bnx2x_set_uc_list(bp) < 0)
  10756. rx_mode = BNX2X_RX_MODE_PROMISC;
  10757. netif_addr_lock_bh(bp->dev);
  10758. } else {
  10759. /* configuring mcast to a vf involves sleeping (when we
  10760. * wait for the pf's response).
  10761. */
  10762. bnx2x_schedule_sp_rtnl(bp,
  10763. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10764. }
  10765. }
  10766. bp->rx_mode = rx_mode;
  10767. /* handle ISCSI SD mode */
  10768. if (IS_MF_ISCSI_ONLY(bp))
  10769. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10770. /* Schedule the rx_mode command */
  10771. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10772. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10773. netif_addr_unlock_bh(bp->dev);
  10774. return;
  10775. }
  10776. if (IS_PF(bp)) {
  10777. bnx2x_set_storm_rx_mode(bp);
  10778. netif_addr_unlock_bh(bp->dev);
  10779. } else {
  10780. /* VF will need to request the PF to make this change, and so
  10781. * the VF needs to release the bottom-half lock prior to the
  10782. * request (as it will likely require sleep on the VF side)
  10783. */
  10784. netif_addr_unlock_bh(bp->dev);
  10785. bnx2x_vfpf_storm_rx_mode(bp);
  10786. }
  10787. }
  10788. /* called with rtnl_lock */
  10789. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10790. int devad, u16 addr)
  10791. {
  10792. struct bnx2x *bp = netdev_priv(netdev);
  10793. u16 value;
  10794. int rc;
  10795. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10796. prtad, devad, addr);
  10797. /* The HW expects different devad if CL22 is used */
  10798. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10799. bnx2x_acquire_phy_lock(bp);
  10800. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10801. bnx2x_release_phy_lock(bp);
  10802. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10803. if (!rc)
  10804. rc = value;
  10805. return rc;
  10806. }
  10807. /* called with rtnl_lock */
  10808. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10809. u16 addr, u16 value)
  10810. {
  10811. struct bnx2x *bp = netdev_priv(netdev);
  10812. int rc;
  10813. DP(NETIF_MSG_LINK,
  10814. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10815. prtad, devad, addr, value);
  10816. /* The HW expects different devad if CL22 is used */
  10817. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10818. bnx2x_acquire_phy_lock(bp);
  10819. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10820. bnx2x_release_phy_lock(bp);
  10821. return rc;
  10822. }
  10823. /* called with rtnl_lock */
  10824. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10825. {
  10826. struct bnx2x *bp = netdev_priv(dev);
  10827. struct mii_ioctl_data *mdio = if_mii(ifr);
  10828. if (!netif_running(dev))
  10829. return -EAGAIN;
  10830. switch (cmd) {
  10831. case SIOCSHWTSTAMP:
  10832. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10833. default:
  10834. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10835. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10836. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10837. }
  10838. }
  10839. #ifdef CONFIG_NET_POLL_CONTROLLER
  10840. static void poll_bnx2x(struct net_device *dev)
  10841. {
  10842. struct bnx2x *bp = netdev_priv(dev);
  10843. int i;
  10844. for_each_eth_queue(bp, i) {
  10845. struct bnx2x_fastpath *fp = &bp->fp[i];
  10846. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10847. }
  10848. }
  10849. #endif
  10850. static int bnx2x_validate_addr(struct net_device *dev)
  10851. {
  10852. struct bnx2x *bp = netdev_priv(dev);
  10853. /* query the bulletin board for mac address configured by the PF */
  10854. if (IS_VF(bp))
  10855. bnx2x_sample_bulletin(bp);
  10856. if (!is_valid_ether_addr(dev->dev_addr)) {
  10857. BNX2X_ERR("Non-valid Ethernet address\n");
  10858. return -EADDRNOTAVAIL;
  10859. }
  10860. return 0;
  10861. }
  10862. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10863. struct netdev_phys_item_id *ppid)
  10864. {
  10865. struct bnx2x *bp = netdev_priv(netdev);
  10866. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10867. return -EOPNOTSUPP;
  10868. ppid->id_len = sizeof(bp->phys_port_id);
  10869. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10870. return 0;
  10871. }
  10872. static netdev_features_t bnx2x_features_check(struct sk_buff *skb,
  10873. struct net_device *dev,
  10874. netdev_features_t features)
  10875. {
  10876. /*
  10877. * A skb with gso_size + header length > 9700 will cause a
  10878. * firmware panic. Drop GSO support.
  10879. *
  10880. * Eventually the upper layer should not pass these packets down.
  10881. *
  10882. * For speed, if the gso_size is <= 9000, assume there will
  10883. * not be 700 bytes of headers and pass it through. Only do a
  10884. * full (slow) validation if the gso_size is > 9000.
  10885. *
  10886. * (Due to the way SKB_BY_FRAGS works this will also do a full
  10887. * validation in that case.)
  10888. */
  10889. if (unlikely(skb_is_gso(skb) &&
  10890. (skb_shinfo(skb)->gso_size > 9000) &&
  10891. !skb_gso_validate_mac_len(skb, 9700)))
  10892. features &= ~NETIF_F_GSO_MASK;
  10893. features = vlan_features_check(skb, features);
  10894. return vxlan_features_check(skb, features);
  10895. }
  10896. static int __bnx2x_vlan_configure_vid(struct bnx2x *bp, u16 vid, bool add)
  10897. {
  10898. int rc;
  10899. if (IS_PF(bp)) {
  10900. unsigned long ramrod_flags = 0;
  10901. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10902. rc = bnx2x_set_vlan_one(bp, vid, &bp->sp_objs->vlan_obj,
  10903. add, &ramrod_flags);
  10904. } else {
  10905. rc = bnx2x_vfpf_update_vlan(bp, vid, bp->fp->index, add);
  10906. }
  10907. return rc;
  10908. }
  10909. static int bnx2x_vlan_configure_vid_list(struct bnx2x *bp)
  10910. {
  10911. struct bnx2x_vlan_entry *vlan;
  10912. int rc = 0;
  10913. /* Configure all non-configured entries */
  10914. list_for_each_entry(vlan, &bp->vlan_reg, link) {
  10915. if (vlan->hw)
  10916. continue;
  10917. if (bp->vlan_cnt >= bp->vlan_credit)
  10918. return -ENOBUFS;
  10919. rc = __bnx2x_vlan_configure_vid(bp, vlan->vid, true);
  10920. if (rc) {
  10921. BNX2X_ERR("Unable to config VLAN %d\n", vlan->vid);
  10922. return rc;
  10923. }
  10924. DP(NETIF_MSG_IFUP, "HW configured for VLAN %d\n", vlan->vid);
  10925. vlan->hw = true;
  10926. bp->vlan_cnt++;
  10927. }
  10928. return 0;
  10929. }
  10930. static void bnx2x_vlan_configure(struct bnx2x *bp, bool set_rx_mode)
  10931. {
  10932. bool need_accept_any_vlan;
  10933. need_accept_any_vlan = !!bnx2x_vlan_configure_vid_list(bp);
  10934. if (bp->accept_any_vlan != need_accept_any_vlan) {
  10935. bp->accept_any_vlan = need_accept_any_vlan;
  10936. DP(NETIF_MSG_IFUP, "Accept all VLAN %s\n",
  10937. bp->accept_any_vlan ? "raised" : "cleared");
  10938. if (set_rx_mode) {
  10939. if (IS_PF(bp))
  10940. bnx2x_set_rx_mode_inner(bp);
  10941. else
  10942. bnx2x_vfpf_storm_rx_mode(bp);
  10943. }
  10944. }
  10945. }
  10946. int bnx2x_vlan_reconfigure_vid(struct bnx2x *bp)
  10947. {
  10948. struct bnx2x_vlan_entry *vlan;
  10949. /* The hw forgot all entries after reload */
  10950. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10951. vlan->hw = false;
  10952. bp->vlan_cnt = 0;
  10953. /* Don't set rx mode here. Our caller will do it. */
  10954. bnx2x_vlan_configure(bp, false);
  10955. return 0;
  10956. }
  10957. static int bnx2x_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
  10958. {
  10959. struct bnx2x *bp = netdev_priv(dev);
  10960. struct bnx2x_vlan_entry *vlan;
  10961. DP(NETIF_MSG_IFUP, "Adding VLAN %d\n", vid);
  10962. vlan = kmalloc(sizeof(*vlan), GFP_KERNEL);
  10963. if (!vlan)
  10964. return -ENOMEM;
  10965. vlan->vid = vid;
  10966. vlan->hw = false;
  10967. list_add_tail(&vlan->link, &bp->vlan_reg);
  10968. if (netif_running(dev))
  10969. bnx2x_vlan_configure(bp, true);
  10970. return 0;
  10971. }
  10972. static int bnx2x_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
  10973. {
  10974. struct bnx2x *bp = netdev_priv(dev);
  10975. struct bnx2x_vlan_entry *vlan;
  10976. bool found = false;
  10977. int rc = 0;
  10978. DP(NETIF_MSG_IFUP, "Removing VLAN %d\n", vid);
  10979. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10980. if (vlan->vid == vid) {
  10981. found = true;
  10982. break;
  10983. }
  10984. if (!found) {
  10985. BNX2X_ERR("Unable to kill VLAN %d - not found\n", vid);
  10986. return -EINVAL;
  10987. }
  10988. if (netif_running(dev) && vlan->hw) {
  10989. rc = __bnx2x_vlan_configure_vid(bp, vid, false);
  10990. DP(NETIF_MSG_IFUP, "HW deconfigured for VLAN %d\n", vid);
  10991. bp->vlan_cnt--;
  10992. }
  10993. list_del(&vlan->link);
  10994. kfree(vlan);
  10995. if (netif_running(dev))
  10996. bnx2x_vlan_configure(bp, true);
  10997. DP(NETIF_MSG_IFUP, "Removing VLAN result %d\n", rc);
  10998. return rc;
  10999. }
  11000. static const struct net_device_ops bnx2x_netdev_ops = {
  11001. .ndo_open = bnx2x_open,
  11002. .ndo_stop = bnx2x_close,
  11003. .ndo_start_xmit = bnx2x_start_xmit,
  11004. .ndo_select_queue = bnx2x_select_queue,
  11005. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  11006. .ndo_set_mac_address = bnx2x_change_mac_addr,
  11007. .ndo_validate_addr = bnx2x_validate_addr,
  11008. .ndo_do_ioctl = bnx2x_ioctl,
  11009. .ndo_change_mtu = bnx2x_change_mtu,
  11010. .ndo_fix_features = bnx2x_fix_features,
  11011. .ndo_set_features = bnx2x_set_features,
  11012. .ndo_tx_timeout = bnx2x_tx_timeout,
  11013. .ndo_vlan_rx_add_vid = bnx2x_vlan_rx_add_vid,
  11014. .ndo_vlan_rx_kill_vid = bnx2x_vlan_rx_kill_vid,
  11015. #ifdef CONFIG_NET_POLL_CONTROLLER
  11016. .ndo_poll_controller = poll_bnx2x,
  11017. #endif
  11018. .ndo_setup_tc = __bnx2x_setup_tc,
  11019. #ifdef CONFIG_BNX2X_SRIOV
  11020. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  11021. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  11022. .ndo_get_vf_config = bnx2x_get_vf_config,
  11023. #endif
  11024. #ifdef NETDEV_FCOE_WWNN
  11025. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  11026. #endif
  11027. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  11028. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  11029. .ndo_features_check = bnx2x_features_check,
  11030. .ndo_udp_tunnel_add = bnx2x_udp_tunnel_add,
  11031. .ndo_udp_tunnel_del = bnx2x_udp_tunnel_del,
  11032. };
  11033. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  11034. {
  11035. struct device *dev = &bp->pdev->dev;
  11036. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  11037. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  11038. dev_err(dev, "System does not support DMA, aborting\n");
  11039. return -EIO;
  11040. }
  11041. return 0;
  11042. }
  11043. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  11044. {
  11045. if (bp->flags & AER_ENABLED) {
  11046. pci_disable_pcie_error_reporting(bp->pdev);
  11047. bp->flags &= ~AER_ENABLED;
  11048. }
  11049. }
  11050. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  11051. struct net_device *dev, unsigned long board_type)
  11052. {
  11053. int rc;
  11054. u32 pci_cfg_dword;
  11055. bool chip_is_e1x = (board_type == BCM57710 ||
  11056. board_type == BCM57711 ||
  11057. board_type == BCM57711E);
  11058. SET_NETDEV_DEV(dev, &pdev->dev);
  11059. bp->dev = dev;
  11060. bp->pdev = pdev;
  11061. rc = pci_enable_device(pdev);
  11062. if (rc) {
  11063. dev_err(&bp->pdev->dev,
  11064. "Cannot enable PCI device, aborting\n");
  11065. goto err_out;
  11066. }
  11067. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  11068. dev_err(&bp->pdev->dev,
  11069. "Cannot find PCI device base address, aborting\n");
  11070. rc = -ENODEV;
  11071. goto err_out_disable;
  11072. }
  11073. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  11074. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  11075. rc = -ENODEV;
  11076. goto err_out_disable;
  11077. }
  11078. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  11079. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  11080. PCICFG_REVESION_ID_ERROR_VAL) {
  11081. pr_err("PCI device error, probably due to fan failure, aborting\n");
  11082. rc = -ENODEV;
  11083. goto err_out_disable;
  11084. }
  11085. if (atomic_read(&pdev->enable_cnt) == 1) {
  11086. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  11087. if (rc) {
  11088. dev_err(&bp->pdev->dev,
  11089. "Cannot obtain PCI resources, aborting\n");
  11090. goto err_out_disable;
  11091. }
  11092. pci_set_master(pdev);
  11093. pci_save_state(pdev);
  11094. }
  11095. if (IS_PF(bp)) {
  11096. if (!pdev->pm_cap) {
  11097. dev_err(&bp->pdev->dev,
  11098. "Cannot find power management capability, aborting\n");
  11099. rc = -EIO;
  11100. goto err_out_release;
  11101. }
  11102. }
  11103. if (!pci_is_pcie(pdev)) {
  11104. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  11105. rc = -EIO;
  11106. goto err_out_release;
  11107. }
  11108. rc = bnx2x_set_coherency_mask(bp);
  11109. if (rc)
  11110. goto err_out_release;
  11111. dev->mem_start = pci_resource_start(pdev, 0);
  11112. dev->base_addr = dev->mem_start;
  11113. dev->mem_end = pci_resource_end(pdev, 0);
  11114. dev->irq = pdev->irq;
  11115. bp->regview = pci_ioremap_bar(pdev, 0);
  11116. if (!bp->regview) {
  11117. dev_err(&bp->pdev->dev,
  11118. "Cannot map register space, aborting\n");
  11119. rc = -ENOMEM;
  11120. goto err_out_release;
  11121. }
  11122. /* In E1/E1H use pci device function given by kernel.
  11123. * In E2/E3 read physical function from ME register since these chips
  11124. * support Physical Device Assignment where kernel BDF maybe arbitrary
  11125. * (depending on hypervisor).
  11126. */
  11127. if (chip_is_e1x) {
  11128. bp->pf_num = PCI_FUNC(pdev->devfn);
  11129. } else {
  11130. /* chip is E2/3*/
  11131. pci_read_config_dword(bp->pdev,
  11132. PCICFG_ME_REGISTER, &pci_cfg_dword);
  11133. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  11134. ME_REG_ABS_PF_NUM_SHIFT);
  11135. }
  11136. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  11137. /* clean indirect addresses */
  11138. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  11139. PCICFG_VENDOR_ID_OFFSET);
  11140. /* Set PCIe reset type to fundamental for EEH recovery */
  11141. pdev->needs_freset = 1;
  11142. /* AER (Advanced Error reporting) configuration */
  11143. rc = pci_enable_pcie_error_reporting(pdev);
  11144. if (!rc)
  11145. bp->flags |= AER_ENABLED;
  11146. else
  11147. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  11148. /*
  11149. * Clean the following indirect addresses for all functions since it
  11150. * is not used by the driver.
  11151. */
  11152. if (IS_PF(bp)) {
  11153. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  11154. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  11155. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  11156. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  11157. if (chip_is_e1x) {
  11158. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  11159. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  11160. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  11161. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  11162. }
  11163. /* Enable internal target-read (in case we are probed after PF
  11164. * FLR). Must be done prior to any BAR read access. Only for
  11165. * 57712 and up
  11166. */
  11167. if (!chip_is_e1x)
  11168. REG_WR(bp,
  11169. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  11170. }
  11171. dev->watchdog_timeo = TX_TIMEOUT;
  11172. dev->netdev_ops = &bnx2x_netdev_ops;
  11173. bnx2x_set_ethtool_ops(bp, dev);
  11174. dev->priv_flags |= IFF_UNICAST_FLT;
  11175. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11176. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11177. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO | NETIF_F_GRO_HW |
  11178. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  11179. if (!chip_is_e1x) {
  11180. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11181. NETIF_F_GSO_IPXIP4 |
  11182. NETIF_F_GSO_UDP_TUNNEL |
  11183. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11184. NETIF_F_GSO_PARTIAL;
  11185. dev->hw_enc_features =
  11186. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  11187. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11188. NETIF_F_GSO_IPXIP4 |
  11189. NETIF_F_GSO_GRE | NETIF_F_GSO_GRE_CSUM |
  11190. NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_UDP_TUNNEL_CSUM |
  11191. NETIF_F_GSO_PARTIAL;
  11192. dev->gso_partial_features = NETIF_F_GSO_GRE_CSUM |
  11193. NETIF_F_GSO_UDP_TUNNEL_CSUM;
  11194. }
  11195. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11196. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  11197. if (IS_PF(bp)) {
  11198. if (chip_is_e1x)
  11199. bp->accept_any_vlan = true;
  11200. else
  11201. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11202. }
  11203. /* For VF we'll know whether to enable VLAN filtering after
  11204. * getting a response to CHANNEL_TLV_ACQUIRE from PF.
  11205. */
  11206. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  11207. dev->features |= NETIF_F_HIGHDMA;
  11208. if (dev->features & NETIF_F_LRO)
  11209. dev->features &= ~NETIF_F_GRO_HW;
  11210. /* Add Loopback capability to the device */
  11211. dev->hw_features |= NETIF_F_LOOPBACK;
  11212. #ifdef BCM_DCBNL
  11213. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  11214. #endif
  11215. /* MTU range, 46 - 9600 */
  11216. dev->min_mtu = ETH_MIN_PACKET_SIZE;
  11217. dev->max_mtu = ETH_MAX_JUMBO_PACKET_SIZE;
  11218. /* get_port_hwinfo() will set prtad and mmds properly */
  11219. bp->mdio.prtad = MDIO_PRTAD_NONE;
  11220. bp->mdio.mmds = 0;
  11221. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  11222. bp->mdio.dev = dev;
  11223. bp->mdio.mdio_read = bnx2x_mdio_read;
  11224. bp->mdio.mdio_write = bnx2x_mdio_write;
  11225. return 0;
  11226. err_out_release:
  11227. if (atomic_read(&pdev->enable_cnt) == 1)
  11228. pci_release_regions(pdev);
  11229. err_out_disable:
  11230. pci_disable_device(pdev);
  11231. err_out:
  11232. return rc;
  11233. }
  11234. static int bnx2x_check_firmware(struct bnx2x *bp)
  11235. {
  11236. const struct firmware *firmware = bp->firmware;
  11237. struct bnx2x_fw_file_hdr *fw_hdr;
  11238. struct bnx2x_fw_file_section *sections;
  11239. u32 offset, len, num_ops;
  11240. __be16 *ops_offsets;
  11241. int i;
  11242. const u8 *fw_ver;
  11243. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  11244. BNX2X_ERR("Wrong FW size\n");
  11245. return -EINVAL;
  11246. }
  11247. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  11248. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  11249. /* Make sure none of the offsets and sizes make us read beyond
  11250. * the end of the firmware data */
  11251. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  11252. offset = be32_to_cpu(sections[i].offset);
  11253. len = be32_to_cpu(sections[i].len);
  11254. if (offset + len > firmware->size) {
  11255. BNX2X_ERR("Section %d length is out of bounds\n", i);
  11256. return -EINVAL;
  11257. }
  11258. }
  11259. /* Likewise for the init_ops offsets */
  11260. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  11261. ops_offsets = (__force __be16 *)(firmware->data + offset);
  11262. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  11263. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  11264. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  11265. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  11266. return -EINVAL;
  11267. }
  11268. }
  11269. /* Check FW version */
  11270. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  11271. fw_ver = firmware->data + offset;
  11272. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  11273. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  11274. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  11275. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  11276. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  11277. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  11278. BCM_5710_FW_MAJOR_VERSION,
  11279. BCM_5710_FW_MINOR_VERSION,
  11280. BCM_5710_FW_REVISION_VERSION,
  11281. BCM_5710_FW_ENGINEERING_VERSION);
  11282. return -EINVAL;
  11283. }
  11284. return 0;
  11285. }
  11286. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11287. {
  11288. const __be32 *source = (const __be32 *)_source;
  11289. u32 *target = (u32 *)_target;
  11290. u32 i;
  11291. for (i = 0; i < n/4; i++)
  11292. target[i] = be32_to_cpu(source[i]);
  11293. }
  11294. /*
  11295. Ops array is stored in the following format:
  11296. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  11297. */
  11298. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  11299. {
  11300. const __be32 *source = (const __be32 *)_source;
  11301. struct raw_op *target = (struct raw_op *)_target;
  11302. u32 i, j, tmp;
  11303. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  11304. tmp = be32_to_cpu(source[j]);
  11305. target[i].op = (tmp >> 24) & 0xff;
  11306. target[i].offset = tmp & 0xffffff;
  11307. target[i].raw_data = be32_to_cpu(source[j + 1]);
  11308. }
  11309. }
  11310. /* IRO array is stored in the following format:
  11311. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  11312. */
  11313. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  11314. {
  11315. const __be32 *source = (const __be32 *)_source;
  11316. struct iro *target = (struct iro *)_target;
  11317. u32 i, j, tmp;
  11318. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  11319. target[i].base = be32_to_cpu(source[j]);
  11320. j++;
  11321. tmp = be32_to_cpu(source[j]);
  11322. target[i].m1 = (tmp >> 16) & 0xffff;
  11323. target[i].m2 = tmp & 0xffff;
  11324. j++;
  11325. tmp = be32_to_cpu(source[j]);
  11326. target[i].m3 = (tmp >> 16) & 0xffff;
  11327. target[i].size = tmp & 0xffff;
  11328. j++;
  11329. }
  11330. }
  11331. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11332. {
  11333. const __be16 *source = (const __be16 *)_source;
  11334. u16 *target = (u16 *)_target;
  11335. u32 i;
  11336. for (i = 0; i < n/2; i++)
  11337. target[i] = be16_to_cpu(source[i]);
  11338. }
  11339. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  11340. do { \
  11341. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  11342. bp->arr = kmalloc(len, GFP_KERNEL); \
  11343. if (!bp->arr) \
  11344. goto lbl; \
  11345. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  11346. (u8 *)bp->arr, len); \
  11347. } while (0)
  11348. static int bnx2x_init_firmware(struct bnx2x *bp)
  11349. {
  11350. const char *fw_file_name;
  11351. struct bnx2x_fw_file_hdr *fw_hdr;
  11352. int rc;
  11353. if (bp->firmware)
  11354. return 0;
  11355. if (CHIP_IS_E1(bp))
  11356. fw_file_name = FW_FILE_NAME_E1;
  11357. else if (CHIP_IS_E1H(bp))
  11358. fw_file_name = FW_FILE_NAME_E1H;
  11359. else if (!CHIP_IS_E1x(bp))
  11360. fw_file_name = FW_FILE_NAME_E2;
  11361. else {
  11362. BNX2X_ERR("Unsupported chip revision\n");
  11363. return -EINVAL;
  11364. }
  11365. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  11366. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  11367. if (rc) {
  11368. BNX2X_ERR("Can't load firmware file %s\n",
  11369. fw_file_name);
  11370. goto request_firmware_exit;
  11371. }
  11372. rc = bnx2x_check_firmware(bp);
  11373. if (rc) {
  11374. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  11375. goto request_firmware_exit;
  11376. }
  11377. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  11378. /* Initialize the pointers to the init arrays */
  11379. /* Blob */
  11380. rc = -ENOMEM;
  11381. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  11382. /* Opcodes */
  11383. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  11384. /* Offsets */
  11385. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  11386. be16_to_cpu_n);
  11387. /* STORMs firmware */
  11388. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11389. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  11390. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  11391. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  11392. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11393. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  11394. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  11395. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  11396. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11397. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  11398. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  11399. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  11400. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11401. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  11402. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  11403. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  11404. /* IRO */
  11405. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  11406. return 0;
  11407. iro_alloc_err:
  11408. kfree(bp->init_ops_offsets);
  11409. init_offsets_alloc_err:
  11410. kfree(bp->init_ops);
  11411. init_ops_alloc_err:
  11412. kfree(bp->init_data);
  11413. request_firmware_exit:
  11414. release_firmware(bp->firmware);
  11415. bp->firmware = NULL;
  11416. return rc;
  11417. }
  11418. static void bnx2x_release_firmware(struct bnx2x *bp)
  11419. {
  11420. kfree(bp->init_ops_offsets);
  11421. kfree(bp->init_ops);
  11422. kfree(bp->init_data);
  11423. release_firmware(bp->firmware);
  11424. bp->firmware = NULL;
  11425. }
  11426. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  11427. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  11428. .init_hw_cmn = bnx2x_init_hw_common,
  11429. .init_hw_port = bnx2x_init_hw_port,
  11430. .init_hw_func = bnx2x_init_hw_func,
  11431. .reset_hw_cmn = bnx2x_reset_common,
  11432. .reset_hw_port = bnx2x_reset_port,
  11433. .reset_hw_func = bnx2x_reset_func,
  11434. .gunzip_init = bnx2x_gunzip_init,
  11435. .gunzip_end = bnx2x_gunzip_end,
  11436. .init_fw = bnx2x_init_firmware,
  11437. .release_fw = bnx2x_release_firmware,
  11438. };
  11439. void bnx2x__init_func_obj(struct bnx2x *bp)
  11440. {
  11441. /* Prepare DMAE related driver resources */
  11442. bnx2x_setup_dmae(bp);
  11443. bnx2x_init_func_obj(bp, &bp->func_obj,
  11444. bnx2x_sp(bp, func_rdata),
  11445. bnx2x_sp_mapping(bp, func_rdata),
  11446. bnx2x_sp(bp, func_afex_rdata),
  11447. bnx2x_sp_mapping(bp, func_afex_rdata),
  11448. &bnx2x_func_sp_drv);
  11449. }
  11450. /* must be called after sriov-enable */
  11451. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  11452. {
  11453. int cid_count = BNX2X_L2_MAX_CID(bp);
  11454. if (IS_SRIOV(bp))
  11455. cid_count += BNX2X_VF_CIDS;
  11456. if (CNIC_SUPPORT(bp))
  11457. cid_count += CNIC_CID_MAX;
  11458. return roundup(cid_count, QM_CID_ROUND);
  11459. }
  11460. /**
  11461. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  11462. *
  11463. * @dev: pci device
  11464. *
  11465. */
  11466. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  11467. {
  11468. int index;
  11469. u16 control = 0;
  11470. /*
  11471. * If MSI-X is not supported - return number of SBs needed to support
  11472. * one fast path queue: one FP queue + SB for CNIC
  11473. */
  11474. if (!pdev->msix_cap) {
  11475. dev_info(&pdev->dev, "no msix capability found\n");
  11476. return 1 + cnic_cnt;
  11477. }
  11478. dev_info(&pdev->dev, "msix capability found\n");
  11479. /*
  11480. * The value in the PCI configuration space is the index of the last
  11481. * entry, namely one less than the actual size of the table, which is
  11482. * exactly what we want to return from this function: number of all SBs
  11483. * without the default SB.
  11484. * For VFs there is no default SB, then we return (index+1).
  11485. */
  11486. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11487. index = control & PCI_MSIX_FLAGS_QSIZE;
  11488. return index;
  11489. }
  11490. static int set_max_cos_est(int chip_id)
  11491. {
  11492. switch (chip_id) {
  11493. case BCM57710:
  11494. case BCM57711:
  11495. case BCM57711E:
  11496. return BNX2X_MULTI_TX_COS_E1X;
  11497. case BCM57712:
  11498. case BCM57712_MF:
  11499. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11500. case BCM57800:
  11501. case BCM57800_MF:
  11502. case BCM57810:
  11503. case BCM57810_MF:
  11504. case BCM57840_4_10:
  11505. case BCM57840_2_20:
  11506. case BCM57840_O:
  11507. case BCM57840_MFO:
  11508. case BCM57840_MF:
  11509. case BCM57811:
  11510. case BCM57811_MF:
  11511. return BNX2X_MULTI_TX_COS_E3B0;
  11512. case BCM57712_VF:
  11513. case BCM57800_VF:
  11514. case BCM57810_VF:
  11515. case BCM57840_VF:
  11516. case BCM57811_VF:
  11517. return 1;
  11518. default:
  11519. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11520. return -ENODEV;
  11521. }
  11522. }
  11523. static int set_is_vf(int chip_id)
  11524. {
  11525. switch (chip_id) {
  11526. case BCM57712_VF:
  11527. case BCM57800_VF:
  11528. case BCM57810_VF:
  11529. case BCM57840_VF:
  11530. case BCM57811_VF:
  11531. return true;
  11532. default:
  11533. return false;
  11534. }
  11535. }
  11536. /* nig_tsgen registers relative address */
  11537. #define tsgen_ctrl 0x0
  11538. #define tsgen_freecount 0x10
  11539. #define tsgen_synctime_t0 0x20
  11540. #define tsgen_offset_t0 0x28
  11541. #define tsgen_drift_t0 0x30
  11542. #define tsgen_synctime_t1 0x58
  11543. #define tsgen_offset_t1 0x60
  11544. #define tsgen_drift_t1 0x68
  11545. /* FW workaround for setting drift */
  11546. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11547. int best_val, int best_period)
  11548. {
  11549. struct bnx2x_func_state_params func_params = {NULL};
  11550. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11551. &func_params.params.set_timesync;
  11552. /* Prepare parameters for function state transitions */
  11553. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11554. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11555. func_params.f_obj = &bp->func_obj;
  11556. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11557. /* Function parameters */
  11558. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11559. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11560. set_timesync_params->add_sub_drift_adjust_value =
  11561. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11562. set_timesync_params->drift_adjust_value = best_val;
  11563. set_timesync_params->drift_adjust_period = best_period;
  11564. return bnx2x_func_state_change(bp, &func_params);
  11565. }
  11566. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11567. {
  11568. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11569. int rc;
  11570. int drift_dir = 1;
  11571. int val, period, period1, period2, dif, dif1, dif2;
  11572. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11573. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11574. if (!netif_running(bp->dev)) {
  11575. DP(BNX2X_MSG_PTP,
  11576. "PTP adjfreq called while the interface is down\n");
  11577. return -ENETDOWN;
  11578. }
  11579. if (ppb < 0) {
  11580. ppb = -ppb;
  11581. drift_dir = 0;
  11582. }
  11583. if (ppb == 0) {
  11584. best_val = 1;
  11585. best_period = 0x1FFFFFF;
  11586. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11587. best_val = 31;
  11588. best_period = 1;
  11589. } else {
  11590. /* Changed not to allow val = 8, 16, 24 as these values
  11591. * are not supported in workaround.
  11592. */
  11593. for (val = 0; val <= 31; val++) {
  11594. if ((val & 0x7) == 0)
  11595. continue;
  11596. period1 = val * 1000000 / ppb;
  11597. period2 = period1 + 1;
  11598. if (period1 != 0)
  11599. dif1 = ppb - (val * 1000000 / period1);
  11600. else
  11601. dif1 = BNX2X_MAX_PHC_DRIFT;
  11602. if (dif1 < 0)
  11603. dif1 = -dif1;
  11604. dif2 = ppb - (val * 1000000 / period2);
  11605. if (dif2 < 0)
  11606. dif2 = -dif2;
  11607. dif = (dif1 < dif2) ? dif1 : dif2;
  11608. period = (dif1 < dif2) ? period1 : period2;
  11609. if (dif < best_dif) {
  11610. best_dif = dif;
  11611. best_val = val;
  11612. best_period = period;
  11613. }
  11614. }
  11615. }
  11616. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11617. best_period);
  11618. if (rc) {
  11619. BNX2X_ERR("Failed to set drift\n");
  11620. return -EFAULT;
  11621. }
  11622. DP(BNX2X_MSG_PTP, "Configured val = %d, period = %d\n", best_val,
  11623. best_period);
  11624. return 0;
  11625. }
  11626. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11627. {
  11628. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11629. if (!netif_running(bp->dev)) {
  11630. DP(BNX2X_MSG_PTP,
  11631. "PTP adjtime called while the interface is down\n");
  11632. return -ENETDOWN;
  11633. }
  11634. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11635. timecounter_adjtime(&bp->timecounter, delta);
  11636. return 0;
  11637. }
  11638. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
  11639. {
  11640. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11641. u64 ns;
  11642. if (!netif_running(bp->dev)) {
  11643. DP(BNX2X_MSG_PTP,
  11644. "PTP gettime called while the interface is down\n");
  11645. return -ENETDOWN;
  11646. }
  11647. ns = timecounter_read(&bp->timecounter);
  11648. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11649. *ts = ns_to_timespec64(ns);
  11650. return 0;
  11651. }
  11652. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11653. const struct timespec64 *ts)
  11654. {
  11655. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11656. u64 ns;
  11657. if (!netif_running(bp->dev)) {
  11658. DP(BNX2X_MSG_PTP,
  11659. "PTP settime called while the interface is down\n");
  11660. return -ENETDOWN;
  11661. }
  11662. ns = timespec64_to_ns(ts);
  11663. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11664. /* Re-init the timecounter */
  11665. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11666. return 0;
  11667. }
  11668. /* Enable (or disable) ancillary features of the phc subsystem */
  11669. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11670. struct ptp_clock_request *rq, int on)
  11671. {
  11672. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11673. BNX2X_ERR("PHC ancillary features are not supported\n");
  11674. return -ENOTSUPP;
  11675. }
  11676. static void bnx2x_register_phc(struct bnx2x *bp)
  11677. {
  11678. /* Fill the ptp_clock_info struct and register PTP clock*/
  11679. bp->ptp_clock_info.owner = THIS_MODULE;
  11680. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11681. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11682. bp->ptp_clock_info.n_alarm = 0;
  11683. bp->ptp_clock_info.n_ext_ts = 0;
  11684. bp->ptp_clock_info.n_per_out = 0;
  11685. bp->ptp_clock_info.pps = 0;
  11686. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11687. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11688. bp->ptp_clock_info.gettime64 = bnx2x_ptp_gettime;
  11689. bp->ptp_clock_info.settime64 = bnx2x_ptp_settime;
  11690. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11691. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11692. if (IS_ERR(bp->ptp_clock)) {
  11693. bp->ptp_clock = NULL;
  11694. BNX2X_ERR("PTP clock registration failed\n");
  11695. }
  11696. }
  11697. static int bnx2x_init_one(struct pci_dev *pdev,
  11698. const struct pci_device_id *ent)
  11699. {
  11700. struct net_device *dev = NULL;
  11701. struct bnx2x *bp;
  11702. enum pcie_link_width pcie_width;
  11703. enum pci_bus_speed pcie_speed;
  11704. int rc, max_non_def_sbs;
  11705. int rx_count, tx_count, rss_count, doorbell_size;
  11706. int max_cos_est;
  11707. bool is_vf;
  11708. int cnic_cnt;
  11709. /* Management FW 'remembers' living interfaces. Allow it some time
  11710. * to forget previously living interfaces, allowing a proper re-load.
  11711. */
  11712. if (is_kdump_kernel()) {
  11713. ktime_t now = ktime_get_boottime();
  11714. ktime_t fw_ready_time = ktime_set(5, 0);
  11715. if (ktime_before(now, fw_ready_time))
  11716. msleep(ktime_ms_delta(fw_ready_time, now));
  11717. }
  11718. /* An estimated maximum supported CoS number according to the chip
  11719. * version.
  11720. * We will try to roughly estimate the maximum number of CoSes this chip
  11721. * may support in order to minimize the memory allocated for Tx
  11722. * netdev_queue's. This number will be accurately calculated during the
  11723. * initialization of bp->max_cos based on the chip versions AND chip
  11724. * revision in the bnx2x_init_bp().
  11725. */
  11726. max_cos_est = set_max_cos_est(ent->driver_data);
  11727. if (max_cos_est < 0)
  11728. return max_cos_est;
  11729. is_vf = set_is_vf(ent->driver_data);
  11730. cnic_cnt = is_vf ? 0 : 1;
  11731. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11732. /* add another SB for VF as it has no default SB */
  11733. max_non_def_sbs += is_vf ? 1 : 0;
  11734. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11735. rss_count = max_non_def_sbs - cnic_cnt;
  11736. if (rss_count < 1)
  11737. return -EINVAL;
  11738. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11739. rx_count = rss_count + cnic_cnt;
  11740. /* Maximum number of netdev Tx queues:
  11741. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11742. */
  11743. tx_count = rss_count * max_cos_est + cnic_cnt;
  11744. /* dev zeroed in init_etherdev */
  11745. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11746. if (!dev)
  11747. return -ENOMEM;
  11748. bp = netdev_priv(dev);
  11749. bp->flags = 0;
  11750. if (is_vf)
  11751. bp->flags |= IS_VF_FLAG;
  11752. bp->igu_sb_cnt = max_non_def_sbs;
  11753. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11754. bp->msg_enable = debug;
  11755. bp->cnic_support = cnic_cnt;
  11756. bp->cnic_probe = bnx2x_cnic_probe;
  11757. pci_set_drvdata(pdev, dev);
  11758. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11759. if (rc < 0) {
  11760. free_netdev(dev);
  11761. return rc;
  11762. }
  11763. BNX2X_DEV_INFO("This is a %s function\n",
  11764. IS_PF(bp) ? "physical" : "virtual");
  11765. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11766. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11767. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11768. tx_count, rx_count);
  11769. rc = bnx2x_init_bp(bp);
  11770. if (rc)
  11771. goto init_one_exit;
  11772. /* Map doorbells here as we need the real value of bp->max_cos which
  11773. * is initialized in bnx2x_init_bp() to determine the number of
  11774. * l2 connections.
  11775. */
  11776. if (IS_VF(bp)) {
  11777. bp->doorbells = bnx2x_vf_doorbells(bp);
  11778. rc = bnx2x_vf_pci_alloc(bp);
  11779. if (rc)
  11780. goto init_one_freemem;
  11781. } else {
  11782. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11783. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11784. dev_err(&bp->pdev->dev,
  11785. "Cannot map doorbells, bar size too small, aborting\n");
  11786. rc = -ENOMEM;
  11787. goto init_one_freemem;
  11788. }
  11789. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11790. doorbell_size);
  11791. }
  11792. if (!bp->doorbells) {
  11793. dev_err(&bp->pdev->dev,
  11794. "Cannot map doorbell space, aborting\n");
  11795. rc = -ENOMEM;
  11796. goto init_one_freemem;
  11797. }
  11798. if (IS_VF(bp)) {
  11799. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11800. if (rc)
  11801. goto init_one_freemem;
  11802. #ifdef CONFIG_BNX2X_SRIOV
  11803. /* VF with OLD Hypervisor or old PF do not support filtering */
  11804. if (bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER) {
  11805. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11806. dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11807. }
  11808. #endif
  11809. }
  11810. /* Enable SRIOV if capability found in configuration space */
  11811. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11812. if (rc)
  11813. goto init_one_freemem;
  11814. /* calc qm_cid_count */
  11815. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11816. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11817. /* disable FCOE L2 queue for E1x*/
  11818. if (CHIP_IS_E1x(bp))
  11819. bp->flags |= NO_FCOE_FLAG;
  11820. /* Set bp->num_queues for MSI-X mode*/
  11821. bnx2x_set_num_queues(bp);
  11822. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11823. * needed.
  11824. */
  11825. rc = bnx2x_set_int_mode(bp);
  11826. if (rc) {
  11827. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11828. goto init_one_freemem;
  11829. }
  11830. BNX2X_DEV_INFO("set interrupts successfully\n");
  11831. /* register the net device */
  11832. rc = register_netdev(dev);
  11833. if (rc) {
  11834. dev_err(&pdev->dev, "Cannot register net device\n");
  11835. goto init_one_freemem;
  11836. }
  11837. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11838. if (!NO_FCOE(bp)) {
  11839. /* Add storage MAC address */
  11840. rtnl_lock();
  11841. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11842. rtnl_unlock();
  11843. }
  11844. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11845. pcie_speed == PCI_SPEED_UNKNOWN ||
  11846. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11847. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11848. else
  11849. BNX2X_DEV_INFO(
  11850. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11851. board_info[ent->driver_data].name,
  11852. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11853. pcie_width,
  11854. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11855. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11856. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11857. "Unknown",
  11858. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11859. bnx2x_register_phc(bp);
  11860. if (!IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp))
  11861. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_DISABLED);
  11862. return 0;
  11863. init_one_freemem:
  11864. bnx2x_free_mem_bp(bp);
  11865. init_one_exit:
  11866. bnx2x_disable_pcie_error_reporting(bp);
  11867. if (bp->regview)
  11868. iounmap(bp->regview);
  11869. if (IS_PF(bp) && bp->doorbells)
  11870. iounmap(bp->doorbells);
  11871. free_netdev(dev);
  11872. if (atomic_read(&pdev->enable_cnt) == 1)
  11873. pci_release_regions(pdev);
  11874. pci_disable_device(pdev);
  11875. return rc;
  11876. }
  11877. static void __bnx2x_remove(struct pci_dev *pdev,
  11878. struct net_device *dev,
  11879. struct bnx2x *bp,
  11880. bool remove_netdev)
  11881. {
  11882. if (bp->ptp_clock) {
  11883. ptp_clock_unregister(bp->ptp_clock);
  11884. bp->ptp_clock = NULL;
  11885. }
  11886. /* Delete storage MAC address */
  11887. if (!NO_FCOE(bp)) {
  11888. rtnl_lock();
  11889. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11890. rtnl_unlock();
  11891. }
  11892. #ifdef BCM_DCBNL
  11893. /* Delete app tlvs from dcbnl */
  11894. bnx2x_dcbnl_update_applist(bp, true);
  11895. #endif
  11896. if (IS_PF(bp) &&
  11897. !BP_NOMCP(bp) &&
  11898. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11899. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11900. /* Close the interface - either directly or implicitly */
  11901. if (remove_netdev) {
  11902. unregister_netdev(dev);
  11903. } else {
  11904. rtnl_lock();
  11905. dev_close(dev);
  11906. rtnl_unlock();
  11907. }
  11908. bnx2x_iov_remove_one(bp);
  11909. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11910. if (IS_PF(bp)) {
  11911. bnx2x_set_power_state(bp, PCI_D0);
  11912. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_NOT_LOADED);
  11913. /* Set endianity registers to reset values in case next driver
  11914. * boots in different endianty environment.
  11915. */
  11916. bnx2x_reset_endianity(bp);
  11917. }
  11918. /* Disable MSI/MSI-X */
  11919. bnx2x_disable_msi(bp);
  11920. /* Power off */
  11921. if (IS_PF(bp))
  11922. bnx2x_set_power_state(bp, PCI_D3hot);
  11923. /* Make sure RESET task is not scheduled before continuing */
  11924. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11925. /* send message via vfpf channel to release the resources of this vf */
  11926. if (IS_VF(bp))
  11927. bnx2x_vfpf_release(bp);
  11928. /* Assumes no further PCIe PM changes will occur */
  11929. if (system_state == SYSTEM_POWER_OFF) {
  11930. pci_wake_from_d3(pdev, bp->wol);
  11931. pci_set_power_state(pdev, PCI_D3hot);
  11932. }
  11933. bnx2x_disable_pcie_error_reporting(bp);
  11934. if (remove_netdev) {
  11935. if (bp->regview)
  11936. iounmap(bp->regview);
  11937. /* For vfs, doorbells are part of the regview and were unmapped
  11938. * along with it. FW is only loaded by PF.
  11939. */
  11940. if (IS_PF(bp)) {
  11941. if (bp->doorbells)
  11942. iounmap(bp->doorbells);
  11943. bnx2x_release_firmware(bp);
  11944. } else {
  11945. bnx2x_vf_pci_dealloc(bp);
  11946. }
  11947. bnx2x_free_mem_bp(bp);
  11948. free_netdev(dev);
  11949. if (atomic_read(&pdev->enable_cnt) == 1)
  11950. pci_release_regions(pdev);
  11951. pci_disable_device(pdev);
  11952. }
  11953. }
  11954. static void bnx2x_remove_one(struct pci_dev *pdev)
  11955. {
  11956. struct net_device *dev = pci_get_drvdata(pdev);
  11957. struct bnx2x *bp;
  11958. if (!dev) {
  11959. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11960. return;
  11961. }
  11962. bp = netdev_priv(dev);
  11963. __bnx2x_remove(pdev, dev, bp, true);
  11964. }
  11965. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11966. {
  11967. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11968. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11969. if (CNIC_LOADED(bp))
  11970. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11971. /* Stop Tx */
  11972. bnx2x_tx_disable(bp);
  11973. /* Delete all NAPI objects */
  11974. bnx2x_del_all_napi(bp);
  11975. if (CNIC_LOADED(bp))
  11976. bnx2x_del_all_napi_cnic(bp);
  11977. netdev_reset_tc(bp->dev);
  11978. del_timer_sync(&bp->timer);
  11979. cancel_delayed_work_sync(&bp->sp_task);
  11980. cancel_delayed_work_sync(&bp->period_task);
  11981. if (!down_timeout(&bp->stats_lock, HZ / 10)) {
  11982. bp->stats_state = STATS_STATE_DISABLED;
  11983. up(&bp->stats_lock);
  11984. }
  11985. bnx2x_save_statistics(bp);
  11986. netif_carrier_off(bp->dev);
  11987. return 0;
  11988. }
  11989. /**
  11990. * bnx2x_io_error_detected - called when PCI error is detected
  11991. * @pdev: Pointer to PCI device
  11992. * @state: The current pci connection state
  11993. *
  11994. * This function is called after a PCI bus error affecting
  11995. * this device has been detected.
  11996. */
  11997. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11998. pci_channel_state_t state)
  11999. {
  12000. struct net_device *dev = pci_get_drvdata(pdev);
  12001. struct bnx2x *bp = netdev_priv(dev);
  12002. rtnl_lock();
  12003. BNX2X_ERR("IO error detected\n");
  12004. netif_device_detach(dev);
  12005. if (state == pci_channel_io_perm_failure) {
  12006. rtnl_unlock();
  12007. return PCI_ERS_RESULT_DISCONNECT;
  12008. }
  12009. if (netif_running(dev))
  12010. bnx2x_eeh_nic_unload(bp);
  12011. bnx2x_prev_path_mark_eeh(bp);
  12012. pci_disable_device(pdev);
  12013. rtnl_unlock();
  12014. /* Request a slot reset */
  12015. return PCI_ERS_RESULT_NEED_RESET;
  12016. }
  12017. /**
  12018. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  12019. * @pdev: Pointer to PCI device
  12020. *
  12021. * Restart the card from scratch, as if from a cold-boot.
  12022. */
  12023. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  12024. {
  12025. struct net_device *dev = pci_get_drvdata(pdev);
  12026. struct bnx2x *bp = netdev_priv(dev);
  12027. int i;
  12028. rtnl_lock();
  12029. BNX2X_ERR("IO slot reset initializing...\n");
  12030. if (pci_enable_device(pdev)) {
  12031. dev_err(&pdev->dev,
  12032. "Cannot re-enable PCI device after reset\n");
  12033. rtnl_unlock();
  12034. return PCI_ERS_RESULT_DISCONNECT;
  12035. }
  12036. pci_set_master(pdev);
  12037. pci_restore_state(pdev);
  12038. pci_save_state(pdev);
  12039. if (netif_running(dev))
  12040. bnx2x_set_power_state(bp, PCI_D0);
  12041. if (netif_running(dev)) {
  12042. BNX2X_ERR("IO slot reset --> driver unload\n");
  12043. /* MCP should have been reset; Need to wait for validity */
  12044. if (bnx2x_init_shmem(bp)) {
  12045. rtnl_unlock();
  12046. return PCI_ERS_RESULT_DISCONNECT;
  12047. }
  12048. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  12049. u32 v;
  12050. v = SHMEM2_RD(bp,
  12051. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  12052. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  12053. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  12054. }
  12055. bnx2x_drain_tx_queues(bp);
  12056. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  12057. bnx2x_netif_stop(bp, 1);
  12058. bnx2x_free_irq(bp);
  12059. /* Report UNLOAD_DONE to MCP */
  12060. bnx2x_send_unload_done(bp, true);
  12061. bp->sp_state = 0;
  12062. bp->port.pmf = 0;
  12063. bnx2x_prev_unload(bp);
  12064. /* We should have reseted the engine, so It's fair to
  12065. * assume the FW will no longer write to the bnx2x driver.
  12066. */
  12067. bnx2x_squeeze_objects(bp);
  12068. bnx2x_free_skbs(bp);
  12069. for_each_rx_queue(bp, i)
  12070. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  12071. bnx2x_free_fp_mem(bp);
  12072. bnx2x_free_mem(bp);
  12073. bp->state = BNX2X_STATE_CLOSED;
  12074. }
  12075. rtnl_unlock();
  12076. /* If AER, perform cleanup of the PCIe registers */
  12077. if (bp->flags & AER_ENABLED) {
  12078. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  12079. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  12080. else
  12081. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  12082. }
  12083. return PCI_ERS_RESULT_RECOVERED;
  12084. }
  12085. /**
  12086. * bnx2x_io_resume - called when traffic can start flowing again
  12087. * @pdev: Pointer to PCI device
  12088. *
  12089. * This callback is called when the error recovery driver tells us that
  12090. * its OK to resume normal operation.
  12091. */
  12092. static void bnx2x_io_resume(struct pci_dev *pdev)
  12093. {
  12094. struct net_device *dev = pci_get_drvdata(pdev);
  12095. struct bnx2x *bp = netdev_priv(dev);
  12096. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  12097. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  12098. return;
  12099. }
  12100. rtnl_lock();
  12101. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  12102. DRV_MSG_SEQ_NUMBER_MASK;
  12103. if (netif_running(dev))
  12104. bnx2x_nic_load(bp, LOAD_NORMAL);
  12105. netif_device_attach(dev);
  12106. rtnl_unlock();
  12107. }
  12108. static const struct pci_error_handlers bnx2x_err_handler = {
  12109. .error_detected = bnx2x_io_error_detected,
  12110. .slot_reset = bnx2x_io_slot_reset,
  12111. .resume = bnx2x_io_resume,
  12112. };
  12113. static void bnx2x_shutdown(struct pci_dev *pdev)
  12114. {
  12115. struct net_device *dev = pci_get_drvdata(pdev);
  12116. struct bnx2x *bp;
  12117. if (!dev)
  12118. return;
  12119. bp = netdev_priv(dev);
  12120. if (!bp)
  12121. return;
  12122. rtnl_lock();
  12123. netif_device_detach(dev);
  12124. rtnl_unlock();
  12125. /* Don't remove the netdevice, as there are scenarios which will cause
  12126. * the kernel to hang, e.g., when trying to remove bnx2i while the
  12127. * rootfs is mounted from SAN.
  12128. */
  12129. __bnx2x_remove(pdev, dev, bp, false);
  12130. }
  12131. static struct pci_driver bnx2x_pci_driver = {
  12132. .name = DRV_MODULE_NAME,
  12133. .id_table = bnx2x_pci_tbl,
  12134. .probe = bnx2x_init_one,
  12135. .remove = bnx2x_remove_one,
  12136. .suspend = bnx2x_suspend,
  12137. .resume = bnx2x_resume,
  12138. .err_handler = &bnx2x_err_handler,
  12139. #ifdef CONFIG_BNX2X_SRIOV
  12140. .sriov_configure = bnx2x_sriov_configure,
  12141. #endif
  12142. .shutdown = bnx2x_shutdown,
  12143. };
  12144. static int __init bnx2x_init(void)
  12145. {
  12146. int ret;
  12147. pr_info("%s", version);
  12148. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  12149. if (bnx2x_wq == NULL) {
  12150. pr_err("Cannot create workqueue\n");
  12151. return -ENOMEM;
  12152. }
  12153. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  12154. if (!bnx2x_iov_wq) {
  12155. pr_err("Cannot create iov workqueue\n");
  12156. destroy_workqueue(bnx2x_wq);
  12157. return -ENOMEM;
  12158. }
  12159. ret = pci_register_driver(&bnx2x_pci_driver);
  12160. if (ret) {
  12161. pr_err("Cannot register driver\n");
  12162. destroy_workqueue(bnx2x_wq);
  12163. destroy_workqueue(bnx2x_iov_wq);
  12164. }
  12165. return ret;
  12166. }
  12167. static void __exit bnx2x_cleanup(void)
  12168. {
  12169. struct list_head *pos, *q;
  12170. pci_unregister_driver(&bnx2x_pci_driver);
  12171. destroy_workqueue(bnx2x_wq);
  12172. destroy_workqueue(bnx2x_iov_wq);
  12173. /* Free globally allocated resources */
  12174. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  12175. struct bnx2x_prev_path_list *tmp =
  12176. list_entry(pos, struct bnx2x_prev_path_list, list);
  12177. list_del(pos);
  12178. kfree(tmp);
  12179. }
  12180. }
  12181. void bnx2x_notify_link_changed(struct bnx2x *bp)
  12182. {
  12183. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  12184. }
  12185. module_init(bnx2x_init);
  12186. module_exit(bnx2x_cleanup);
  12187. /**
  12188. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  12189. *
  12190. * @bp: driver handle
  12191. * @set: set or clear the CAM entry
  12192. *
  12193. * This function will wait until the ramrod completion returns.
  12194. * Return 0 if success, -ENODEV if ramrod doesn't return.
  12195. */
  12196. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  12197. {
  12198. unsigned long ramrod_flags = 0;
  12199. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  12200. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  12201. &bp->iscsi_l2_mac_obj, true,
  12202. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  12203. }
  12204. /* count denotes the number of new completions we have seen */
  12205. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  12206. {
  12207. struct eth_spe *spe;
  12208. int cxt_index, cxt_offset;
  12209. #ifdef BNX2X_STOP_ON_ERROR
  12210. if (unlikely(bp->panic))
  12211. return;
  12212. #endif
  12213. spin_lock_bh(&bp->spq_lock);
  12214. BUG_ON(bp->cnic_spq_pending < count);
  12215. bp->cnic_spq_pending -= count;
  12216. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  12217. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  12218. & SPE_HDR_CONN_TYPE) >>
  12219. SPE_HDR_CONN_TYPE_SHIFT;
  12220. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  12221. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  12222. /* Set validation for iSCSI L2 client before sending SETUP
  12223. * ramrod
  12224. */
  12225. if (type == ETH_CONNECTION_TYPE) {
  12226. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  12227. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  12228. ILT_PAGE_CIDS;
  12229. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  12230. (cxt_index * ILT_PAGE_CIDS);
  12231. bnx2x_set_ctx_validation(bp,
  12232. &bp->context[cxt_index].
  12233. vcxt[cxt_offset].eth,
  12234. BNX2X_ISCSI_ETH_CID(bp));
  12235. }
  12236. }
  12237. /*
  12238. * There may be not more than 8 L2, not more than 8 L5 SPEs
  12239. * and in the air. We also check that number of outstanding
  12240. * COMMON ramrods is not more than the EQ and SPQ can
  12241. * accommodate.
  12242. */
  12243. if (type == ETH_CONNECTION_TYPE) {
  12244. if (!atomic_read(&bp->cq_spq_left))
  12245. break;
  12246. else
  12247. atomic_dec(&bp->cq_spq_left);
  12248. } else if (type == NONE_CONNECTION_TYPE) {
  12249. if (!atomic_read(&bp->eq_spq_left))
  12250. break;
  12251. else
  12252. atomic_dec(&bp->eq_spq_left);
  12253. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  12254. (type == FCOE_CONNECTION_TYPE)) {
  12255. if (bp->cnic_spq_pending >=
  12256. bp->cnic_eth_dev.max_kwqe_pending)
  12257. break;
  12258. else
  12259. bp->cnic_spq_pending++;
  12260. } else {
  12261. BNX2X_ERR("Unknown SPE type: %d\n", type);
  12262. bnx2x_panic();
  12263. break;
  12264. }
  12265. spe = bnx2x_sp_get_next(bp);
  12266. *spe = *bp->cnic_kwq_cons;
  12267. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  12268. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  12269. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  12270. bp->cnic_kwq_cons = bp->cnic_kwq;
  12271. else
  12272. bp->cnic_kwq_cons++;
  12273. }
  12274. bnx2x_sp_prod_update(bp);
  12275. spin_unlock_bh(&bp->spq_lock);
  12276. }
  12277. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  12278. struct kwqe_16 *kwqes[], u32 count)
  12279. {
  12280. struct bnx2x *bp = netdev_priv(dev);
  12281. int i;
  12282. #ifdef BNX2X_STOP_ON_ERROR
  12283. if (unlikely(bp->panic)) {
  12284. BNX2X_ERR("Can't post to SP queue while panic\n");
  12285. return -EIO;
  12286. }
  12287. #endif
  12288. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  12289. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  12290. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  12291. return -EAGAIN;
  12292. }
  12293. spin_lock_bh(&bp->spq_lock);
  12294. for (i = 0; i < count; i++) {
  12295. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  12296. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  12297. break;
  12298. *bp->cnic_kwq_prod = *spe;
  12299. bp->cnic_kwq_pending++;
  12300. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  12301. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  12302. spe->data.update_data_addr.hi,
  12303. spe->data.update_data_addr.lo,
  12304. bp->cnic_kwq_pending);
  12305. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  12306. bp->cnic_kwq_prod = bp->cnic_kwq;
  12307. else
  12308. bp->cnic_kwq_prod++;
  12309. }
  12310. spin_unlock_bh(&bp->spq_lock);
  12311. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  12312. bnx2x_cnic_sp_post(bp, 0);
  12313. return i;
  12314. }
  12315. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12316. {
  12317. struct cnic_ops *c_ops;
  12318. int rc = 0;
  12319. mutex_lock(&bp->cnic_mutex);
  12320. c_ops = rcu_dereference_protected(bp->cnic_ops,
  12321. lockdep_is_held(&bp->cnic_mutex));
  12322. if (c_ops)
  12323. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12324. mutex_unlock(&bp->cnic_mutex);
  12325. return rc;
  12326. }
  12327. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12328. {
  12329. struct cnic_ops *c_ops;
  12330. int rc = 0;
  12331. rcu_read_lock();
  12332. c_ops = rcu_dereference(bp->cnic_ops);
  12333. if (c_ops)
  12334. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12335. rcu_read_unlock();
  12336. return rc;
  12337. }
  12338. /*
  12339. * for commands that have no data
  12340. */
  12341. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  12342. {
  12343. struct cnic_ctl_info ctl = {0};
  12344. ctl.cmd = cmd;
  12345. return bnx2x_cnic_ctl_send(bp, &ctl);
  12346. }
  12347. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  12348. {
  12349. struct cnic_ctl_info ctl = {0};
  12350. /* first we tell CNIC and only then we count this as a completion */
  12351. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  12352. ctl.data.comp.cid = cid;
  12353. ctl.data.comp.error = err;
  12354. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  12355. bnx2x_cnic_sp_post(bp, 0);
  12356. }
  12357. /* Called with netif_addr_lock_bh() taken.
  12358. * Sets an rx_mode config for an iSCSI ETH client.
  12359. * Doesn't block.
  12360. * Completion should be checked outside.
  12361. */
  12362. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  12363. {
  12364. unsigned long accept_flags = 0, ramrod_flags = 0;
  12365. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12366. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  12367. if (start) {
  12368. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  12369. * because it's the only way for UIO Queue to accept
  12370. * multicasts (in non-promiscuous mode only one Queue per
  12371. * function will receive multicast packets (leading in our
  12372. * case).
  12373. */
  12374. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  12375. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  12376. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  12377. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  12378. /* Clear STOP_PENDING bit if START is requested */
  12379. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  12380. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  12381. } else
  12382. /* Clear START_PENDING bit if STOP is requested */
  12383. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  12384. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  12385. set_bit(sched_state, &bp->sp_state);
  12386. else {
  12387. __set_bit(RAMROD_RX, &ramrod_flags);
  12388. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  12389. ramrod_flags);
  12390. }
  12391. }
  12392. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  12393. {
  12394. struct bnx2x *bp = netdev_priv(dev);
  12395. int rc = 0;
  12396. switch (ctl->cmd) {
  12397. case DRV_CTL_CTXTBL_WR_CMD: {
  12398. u32 index = ctl->data.io.offset;
  12399. dma_addr_t addr = ctl->data.io.dma_addr;
  12400. bnx2x_ilt_wr(bp, index, addr);
  12401. break;
  12402. }
  12403. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  12404. int count = ctl->data.credit.credit_count;
  12405. bnx2x_cnic_sp_post(bp, count);
  12406. break;
  12407. }
  12408. /* rtnl_lock is held. */
  12409. case DRV_CTL_START_L2_CMD: {
  12410. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12411. unsigned long sp_bits = 0;
  12412. /* Configure the iSCSI classification object */
  12413. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  12414. cp->iscsi_l2_client_id,
  12415. cp->iscsi_l2_cid, BP_FUNC(bp),
  12416. bnx2x_sp(bp, mac_rdata),
  12417. bnx2x_sp_mapping(bp, mac_rdata),
  12418. BNX2X_FILTER_MAC_PENDING,
  12419. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  12420. &bp->macs_pool);
  12421. /* Set iSCSI MAC address */
  12422. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  12423. if (rc)
  12424. break;
  12425. mmiowb();
  12426. barrier();
  12427. /* Start accepting on iSCSI L2 ring */
  12428. netif_addr_lock_bh(dev);
  12429. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  12430. netif_addr_unlock_bh(dev);
  12431. /* bits to wait on */
  12432. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12433. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  12434. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12435. BNX2X_ERR("rx_mode completion timed out!\n");
  12436. break;
  12437. }
  12438. /* rtnl_lock is held. */
  12439. case DRV_CTL_STOP_L2_CMD: {
  12440. unsigned long sp_bits = 0;
  12441. /* Stop accepting on iSCSI L2 ring */
  12442. netif_addr_lock_bh(dev);
  12443. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  12444. netif_addr_unlock_bh(dev);
  12445. /* bits to wait on */
  12446. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12447. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  12448. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12449. BNX2X_ERR("rx_mode completion timed out!\n");
  12450. mmiowb();
  12451. barrier();
  12452. /* Unset iSCSI L2 MAC */
  12453. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  12454. BNX2X_ISCSI_ETH_MAC, true);
  12455. break;
  12456. }
  12457. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  12458. int count = ctl->data.credit.credit_count;
  12459. smp_mb__before_atomic();
  12460. atomic_add(count, &bp->cq_spq_left);
  12461. smp_mb__after_atomic();
  12462. break;
  12463. }
  12464. case DRV_CTL_ULP_REGISTER_CMD: {
  12465. int ulp_type = ctl->data.register_data.ulp_type;
  12466. if (CHIP_IS_E3(bp)) {
  12467. int idx = BP_FW_MB_IDX(bp);
  12468. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12469. int path = BP_PATH(bp);
  12470. int port = BP_PORT(bp);
  12471. int i;
  12472. u32 scratch_offset;
  12473. u32 *host_addr;
  12474. /* first write capability to shmem2 */
  12475. if (ulp_type == CNIC_ULP_ISCSI)
  12476. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12477. else if (ulp_type == CNIC_ULP_FCOE)
  12478. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12479. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12480. if ((ulp_type != CNIC_ULP_FCOE) ||
  12481. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  12482. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  12483. break;
  12484. /* if reached here - should write fcoe capabilities */
  12485. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  12486. if (!scratch_offset)
  12487. break;
  12488. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  12489. fcoe_features[path][port]);
  12490. host_addr = (u32 *) &(ctl->data.register_data.
  12491. fcoe_features);
  12492. for (i = 0; i < sizeof(struct fcoe_capabilities);
  12493. i += 4)
  12494. REG_WR(bp, scratch_offset + i,
  12495. *(host_addr + i/4));
  12496. }
  12497. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12498. break;
  12499. }
  12500. case DRV_CTL_ULP_UNREGISTER_CMD: {
  12501. int ulp_type = ctl->data.ulp_type;
  12502. if (CHIP_IS_E3(bp)) {
  12503. int idx = BP_FW_MB_IDX(bp);
  12504. u32 cap;
  12505. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12506. if (ulp_type == CNIC_ULP_ISCSI)
  12507. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12508. else if (ulp_type == CNIC_ULP_FCOE)
  12509. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12510. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12511. }
  12512. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12513. break;
  12514. }
  12515. default:
  12516. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12517. rc = -EINVAL;
  12518. }
  12519. /* For storage-only interfaces, change driver state */
  12520. if (IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp)) {
  12521. switch (ctl->drv_state) {
  12522. case DRV_NOP:
  12523. break;
  12524. case DRV_ACTIVE:
  12525. bnx2x_set_os_driver_state(bp,
  12526. OS_DRIVER_STATE_ACTIVE);
  12527. break;
  12528. case DRV_INACTIVE:
  12529. bnx2x_set_os_driver_state(bp,
  12530. OS_DRIVER_STATE_DISABLED);
  12531. break;
  12532. case DRV_UNLOADED:
  12533. bnx2x_set_os_driver_state(bp,
  12534. OS_DRIVER_STATE_NOT_LOADED);
  12535. break;
  12536. default:
  12537. BNX2X_ERR("Unknown cnic driver state: %d\n", ctl->drv_state);
  12538. }
  12539. }
  12540. return rc;
  12541. }
  12542. static int bnx2x_get_fc_npiv(struct net_device *dev,
  12543. struct cnic_fc_npiv_tbl *cnic_tbl)
  12544. {
  12545. struct bnx2x *bp = netdev_priv(dev);
  12546. struct bdn_fc_npiv_tbl *tbl = NULL;
  12547. u32 offset, entries;
  12548. int rc = -EINVAL;
  12549. int i;
  12550. if (!SHMEM2_HAS(bp, fc_npiv_nvram_tbl_addr[0]))
  12551. goto out;
  12552. DP(BNX2X_MSG_MCP, "About to read the FC-NPIV table\n");
  12553. tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
  12554. if (!tbl) {
  12555. BNX2X_ERR("Failed to allocate fc_npiv table\n");
  12556. goto out;
  12557. }
  12558. offset = SHMEM2_RD(bp, fc_npiv_nvram_tbl_addr[BP_PORT(bp)]);
  12559. if (!offset) {
  12560. DP(BNX2X_MSG_MCP, "No FC-NPIV in NVRAM\n");
  12561. goto out;
  12562. }
  12563. DP(BNX2X_MSG_MCP, "Offset of FC-NPIV in NVRAM: %08x\n", offset);
  12564. /* Read the table contents from nvram */
  12565. if (bnx2x_nvram_read(bp, offset, (u8 *)tbl, sizeof(*tbl))) {
  12566. BNX2X_ERR("Failed to read FC-NPIV table\n");
  12567. goto out;
  12568. }
  12569. /* Since bnx2x_nvram_read() returns data in be32, we need to convert
  12570. * the number of entries back to cpu endianness.
  12571. */
  12572. entries = tbl->fc_npiv_cfg.num_of_npiv;
  12573. entries = (__force u32)be32_to_cpu((__force __be32)entries);
  12574. tbl->fc_npiv_cfg.num_of_npiv = entries;
  12575. if (!tbl->fc_npiv_cfg.num_of_npiv) {
  12576. DP(BNX2X_MSG_MCP,
  12577. "No FC-NPIV table [valid, simply not present]\n");
  12578. goto out;
  12579. } else if (tbl->fc_npiv_cfg.num_of_npiv > MAX_NUMBER_NPIV) {
  12580. BNX2X_ERR("FC-NPIV table with bad length 0x%08x\n",
  12581. tbl->fc_npiv_cfg.num_of_npiv);
  12582. goto out;
  12583. } else {
  12584. DP(BNX2X_MSG_MCP, "Read 0x%08x entries from NVRAM\n",
  12585. tbl->fc_npiv_cfg.num_of_npiv);
  12586. }
  12587. /* Copy the data into cnic-provided struct */
  12588. cnic_tbl->count = tbl->fc_npiv_cfg.num_of_npiv;
  12589. for (i = 0; i < cnic_tbl->count; i++) {
  12590. memcpy(cnic_tbl->wwpn[i], tbl->settings[i].npiv_wwpn, 8);
  12591. memcpy(cnic_tbl->wwnn[i], tbl->settings[i].npiv_wwnn, 8);
  12592. }
  12593. rc = 0;
  12594. out:
  12595. kfree(tbl);
  12596. return rc;
  12597. }
  12598. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12599. {
  12600. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12601. if (bp->flags & USING_MSIX_FLAG) {
  12602. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12603. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12604. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12605. } else {
  12606. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12607. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12608. }
  12609. if (!CHIP_IS_E1x(bp))
  12610. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12611. else
  12612. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12613. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12614. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12615. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12616. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12617. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12618. cp->num_irq = 2;
  12619. }
  12620. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12621. {
  12622. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12623. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12624. bnx2x_cid_ilt_lines(bp);
  12625. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12626. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12627. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12628. 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",
  12629. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12630. cp->iscsi_l2_cid);
  12631. if (NO_ISCSI_OOO(bp))
  12632. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12633. }
  12634. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12635. void *data)
  12636. {
  12637. struct bnx2x *bp = netdev_priv(dev);
  12638. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12639. int rc;
  12640. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12641. if (ops == NULL) {
  12642. BNX2X_ERR("NULL ops received\n");
  12643. return -EINVAL;
  12644. }
  12645. if (!CNIC_SUPPORT(bp)) {
  12646. BNX2X_ERR("Can't register CNIC when not supported\n");
  12647. return -EOPNOTSUPP;
  12648. }
  12649. if (!CNIC_LOADED(bp)) {
  12650. rc = bnx2x_load_cnic(bp);
  12651. if (rc) {
  12652. BNX2X_ERR("CNIC-related load failed\n");
  12653. return rc;
  12654. }
  12655. }
  12656. bp->cnic_enabled = true;
  12657. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12658. if (!bp->cnic_kwq)
  12659. return -ENOMEM;
  12660. bp->cnic_kwq_cons = bp->cnic_kwq;
  12661. bp->cnic_kwq_prod = bp->cnic_kwq;
  12662. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12663. bp->cnic_spq_pending = 0;
  12664. bp->cnic_kwq_pending = 0;
  12665. bp->cnic_data = data;
  12666. cp->num_irq = 0;
  12667. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12668. cp->iro_arr = bp->iro_arr;
  12669. bnx2x_setup_cnic_irq_info(bp);
  12670. rcu_assign_pointer(bp->cnic_ops, ops);
  12671. /* Schedule driver to read CNIC driver versions */
  12672. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12673. return 0;
  12674. }
  12675. static int bnx2x_unregister_cnic(struct net_device *dev)
  12676. {
  12677. struct bnx2x *bp = netdev_priv(dev);
  12678. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12679. mutex_lock(&bp->cnic_mutex);
  12680. cp->drv_state = 0;
  12681. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12682. mutex_unlock(&bp->cnic_mutex);
  12683. synchronize_rcu();
  12684. bp->cnic_enabled = false;
  12685. kfree(bp->cnic_kwq);
  12686. bp->cnic_kwq = NULL;
  12687. return 0;
  12688. }
  12689. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12690. {
  12691. struct bnx2x *bp = netdev_priv(dev);
  12692. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12693. /* If both iSCSI and FCoE are disabled - return NULL in
  12694. * order to indicate CNIC that it should not try to work
  12695. * with this device.
  12696. */
  12697. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12698. return NULL;
  12699. cp->drv_owner = THIS_MODULE;
  12700. cp->chip_id = CHIP_ID(bp);
  12701. cp->pdev = bp->pdev;
  12702. cp->io_base = bp->regview;
  12703. cp->io_base2 = bp->doorbells;
  12704. cp->max_kwqe_pending = 8;
  12705. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12706. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12707. bnx2x_cid_ilt_lines(bp);
  12708. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12709. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12710. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12711. cp->drv_ctl = bnx2x_drv_ctl;
  12712. cp->drv_get_fc_npiv_tbl = bnx2x_get_fc_npiv;
  12713. cp->drv_register_cnic = bnx2x_register_cnic;
  12714. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12715. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12716. cp->iscsi_l2_client_id =
  12717. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12718. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12719. if (NO_ISCSI_OOO(bp))
  12720. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12721. if (NO_ISCSI(bp))
  12722. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12723. if (NO_FCOE(bp))
  12724. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12725. BNX2X_DEV_INFO(
  12726. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12727. cp->ctx_blk_size,
  12728. cp->ctx_tbl_offset,
  12729. cp->ctx_tbl_len,
  12730. cp->starting_cid);
  12731. return cp;
  12732. }
  12733. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12734. {
  12735. struct bnx2x *bp = fp->bp;
  12736. u32 offset = BAR_USTRORM_INTMEM;
  12737. if (IS_VF(bp))
  12738. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12739. else if (!CHIP_IS_E1x(bp))
  12740. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12741. else
  12742. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12743. return offset;
  12744. }
  12745. /* called only on E1H or E2.
  12746. * When pretending to be PF, the pretend value is the function number 0...7
  12747. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12748. * combination
  12749. */
  12750. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12751. {
  12752. u32 pretend_reg;
  12753. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12754. return -1;
  12755. /* get my own pretend register */
  12756. pretend_reg = bnx2x_get_pretend_reg(bp);
  12757. REG_WR(bp, pretend_reg, pretend_func_val);
  12758. REG_RD(bp, pretend_reg);
  12759. return 0;
  12760. }
  12761. static void bnx2x_ptp_task(struct work_struct *work)
  12762. {
  12763. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12764. int port = BP_PORT(bp);
  12765. u32 val_seq;
  12766. u64 timestamp, ns;
  12767. struct skb_shared_hwtstamps shhwtstamps;
  12768. /* Read Tx timestamp registers */
  12769. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12770. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12771. if (val_seq & 0x10000) {
  12772. /* There is a valid timestamp value */
  12773. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12774. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12775. timestamp <<= 32;
  12776. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12777. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12778. /* Reset timestamp register to allow new timestamp */
  12779. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12780. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12781. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12782. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12783. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12784. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12785. dev_kfree_skb_any(bp->ptp_tx_skb);
  12786. bp->ptp_tx_skb = NULL;
  12787. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12788. timestamp, ns);
  12789. } else {
  12790. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12791. /* Reschedule to keep checking for a valid timestamp value */
  12792. schedule_work(&bp->ptp_task);
  12793. }
  12794. }
  12795. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12796. {
  12797. int port = BP_PORT(bp);
  12798. u64 timestamp, ns;
  12799. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12800. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12801. timestamp <<= 32;
  12802. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12803. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12804. /* Reset timestamp register to allow new timestamp */
  12805. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12806. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12807. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12808. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12809. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12810. timestamp, ns);
  12811. }
  12812. /* Read the PHC */
  12813. static u64 bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12814. {
  12815. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12816. int port = BP_PORT(bp);
  12817. u32 wb_data[2];
  12818. u64 phc_cycles;
  12819. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12820. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12821. phc_cycles = wb_data[1];
  12822. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12823. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12824. return phc_cycles;
  12825. }
  12826. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12827. {
  12828. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12829. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12830. bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
  12831. bp->cyclecounter.shift = 0;
  12832. bp->cyclecounter.mult = 1;
  12833. }
  12834. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12835. {
  12836. struct bnx2x_func_state_params func_params = {NULL};
  12837. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12838. &func_params.params.set_timesync;
  12839. /* Prepare parameters for function state transitions */
  12840. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12841. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12842. func_params.f_obj = &bp->func_obj;
  12843. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12844. /* Function parameters */
  12845. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12846. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12847. return bnx2x_func_state_change(bp, &func_params);
  12848. }
  12849. static int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12850. {
  12851. struct bnx2x_queue_state_params q_params;
  12852. int rc, i;
  12853. /* send queue update ramrod to enable PTP packets */
  12854. memset(&q_params, 0, sizeof(q_params));
  12855. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12856. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12857. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12858. &q_params.params.update.update_flags);
  12859. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12860. &q_params.params.update.update_flags);
  12861. /* send the ramrod on all the queues of the PF */
  12862. for_each_eth_queue(bp, i) {
  12863. struct bnx2x_fastpath *fp = &bp->fp[i];
  12864. /* Set the appropriate Queue object */
  12865. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12866. /* Update the Queue state */
  12867. rc = bnx2x_queue_state_change(bp, &q_params);
  12868. if (rc) {
  12869. BNX2X_ERR("Failed to enable PTP packets\n");
  12870. return rc;
  12871. }
  12872. }
  12873. return 0;
  12874. }
  12875. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12876. {
  12877. int port = BP_PORT(bp);
  12878. int rc;
  12879. if (!bp->hwtstamp_ioctl_called)
  12880. return 0;
  12881. switch (bp->tx_type) {
  12882. case HWTSTAMP_TX_ON:
  12883. bp->flags |= TX_TIMESTAMPING_EN;
  12884. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12885. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12886. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12887. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12888. break;
  12889. case HWTSTAMP_TX_ONESTEP_SYNC:
  12890. BNX2X_ERR("One-step timestamping is not supported\n");
  12891. return -ERANGE;
  12892. }
  12893. switch (bp->rx_filter) {
  12894. case HWTSTAMP_FILTER_NONE:
  12895. break;
  12896. case HWTSTAMP_FILTER_ALL:
  12897. case HWTSTAMP_FILTER_SOME:
  12898. case HWTSTAMP_FILTER_NTP_ALL:
  12899. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12900. break;
  12901. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12902. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12903. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12904. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12905. /* Initialize PTP detection for UDP/IPv4 events */
  12906. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12907. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12908. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12909. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12910. break;
  12911. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12912. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12913. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12914. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12915. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12916. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12917. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12918. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12919. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12920. break;
  12921. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12922. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12923. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12924. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12925. /* Initialize PTP detection L2 events */
  12926. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12927. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12928. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12929. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12930. break;
  12931. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12932. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12933. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12934. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12935. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12936. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12937. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12938. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12939. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12940. break;
  12941. }
  12942. /* Indicate to FW that this PF expects recorded PTP packets */
  12943. rc = bnx2x_enable_ptp_packets(bp);
  12944. if (rc)
  12945. return rc;
  12946. /* Enable sending PTP packets to host */
  12947. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12948. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12949. return 0;
  12950. }
  12951. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12952. {
  12953. struct hwtstamp_config config;
  12954. int rc;
  12955. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12956. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12957. return -EFAULT;
  12958. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12959. config.tx_type, config.rx_filter);
  12960. if (config.flags) {
  12961. BNX2X_ERR("config.flags is reserved for future use\n");
  12962. return -EINVAL;
  12963. }
  12964. bp->hwtstamp_ioctl_called = 1;
  12965. bp->tx_type = config.tx_type;
  12966. bp->rx_filter = config.rx_filter;
  12967. rc = bnx2x_configure_ptp_filters(bp);
  12968. if (rc)
  12969. return rc;
  12970. config.rx_filter = bp->rx_filter;
  12971. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12972. -EFAULT : 0;
  12973. }
  12974. /* Configures HW for PTP */
  12975. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12976. {
  12977. int rc, port = BP_PORT(bp);
  12978. u32 wb_data[2];
  12979. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12980. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12981. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12982. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12983. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12984. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12985. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12986. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12987. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12988. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12989. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12990. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12991. /* Enable the PTP feature */
  12992. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12993. NIG_REG_P0_PTP_EN, 0x3F);
  12994. /* Enable the free-running counter */
  12995. wb_data[0] = 0;
  12996. wb_data[1] = 0;
  12997. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12998. /* Reset drift register (offset register is not reset) */
  12999. rc = bnx2x_send_reset_timesync_ramrod(bp);
  13000. if (rc) {
  13001. BNX2X_ERR("Failed to reset PHC drift register\n");
  13002. return -EFAULT;
  13003. }
  13004. /* Reset possibly old timestamps */
  13005. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  13006. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  13007. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  13008. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  13009. return 0;
  13010. }
  13011. /* Called during load, to initialize PTP-related stuff */
  13012. void bnx2x_init_ptp(struct bnx2x *bp)
  13013. {
  13014. int rc;
  13015. /* Configure PTP in HW */
  13016. rc = bnx2x_configure_ptp(bp);
  13017. if (rc) {
  13018. BNX2X_ERR("Stopping PTP initialization\n");
  13019. return;
  13020. }
  13021. /* Init work queue for Tx timestamping */
  13022. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  13023. /* Init cyclecounter and timecounter. This is done only in the first
  13024. * load. If done in every load, PTP application will fail when doing
  13025. * unload / load (e.g. MTU change) while it is running.
  13026. */
  13027. if (!bp->timecounter_init_done) {
  13028. bnx2x_init_cyclecounter(bp);
  13029. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  13030. ktime_to_ns(ktime_get_real()));
  13031. bp->timecounter_init_done = 1;
  13032. }
  13033. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  13034. }