bnx2x_main.c 416 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409
  1. /* bnx2x_main.c: QLogic Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. * Copyright (c) 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  12. * Written by: Eliezer Tamir
  13. * Based on code from Michael Chan's bnx2 driver
  14. * UDP CSUM errata workaround by Arik Gendelman
  15. * Slowpath and fastpath rework by Vladislav Zolotarov
  16. * Statistics and Link management by Yitchak Gertner
  17. *
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/kernel.h>
  23. #include <linux/device.h> /* for dev_info() */
  24. #include <linux/timer.h>
  25. #include <linux/errno.h>
  26. #include <linux/ioport.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/pci.h>
  30. #include <linux/aer.h>
  31. #include <linux/init.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/bitops.h>
  37. #include <linux/irq.h>
  38. #include <linux/delay.h>
  39. #include <asm/byteorder.h>
  40. #include <linux/time.h>
  41. #include <linux/ethtool.h>
  42. #include <linux/mii.h>
  43. #include <linux/if_vlan.h>
  44. #include <linux/crash_dump.h>
  45. #include <net/ip.h>
  46. #include <net/ipv6.h>
  47. #include <net/tcp.h>
  48. #include <net/vxlan.h>
  49. #include <net/checksum.h>
  50. #include <net/ip6_checksum.h>
  51. #include <linux/workqueue.h>
  52. #include <linux/crc32.h>
  53. #include <linux/crc32c.h>
  54. #include <linux/prefetch.h>
  55. #include <linux/zlib.h>
  56. #include <linux/io.h>
  57. #include <linux/semaphore.h>
  58. #include <linux/stringify.h>
  59. #include <linux/vmalloc.h>
  60. #include "bnx2x.h"
  61. #include "bnx2x_init.h"
  62. #include "bnx2x_init_ops.h"
  63. #include "bnx2x_cmn.h"
  64. #include "bnx2x_vfpf.h"
  65. #include "bnx2x_dcb.h"
  66. #include "bnx2x_sp.h"
  67. #include <linux/firmware.h>
  68. #include "bnx2x_fw_file_hdr.h"
  69. /* FW files */
  70. #define FW_FILE_VERSION \
  71. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  72. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  73. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  74. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  75. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  76. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  77. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  78. /* Time in jiffies before concluding the transmitter is hung */
  79. #define TX_TIMEOUT (5*HZ)
  80. static char version[] =
  81. "QLogic 5771x/578xx 10/20-Gigabit Ethernet Driver "
  82. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  83. MODULE_AUTHOR("Eliezer Tamir");
  84. MODULE_DESCRIPTION("QLogic "
  85. "BCM57710/57711/57711E/"
  86. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  87. "57840/57840_MF Driver");
  88. MODULE_LICENSE("GPL");
  89. MODULE_VERSION(DRV_MODULE_VERSION);
  90. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  91. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  92. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  93. int bnx2x_num_queues;
  94. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  95. MODULE_PARM_DESC(num_queues,
  96. " Set number of queues (default is as a number of CPUs)");
  97. static int disable_tpa;
  98. module_param(disable_tpa, int, S_IRUGO);
  99. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  100. static int int_mode;
  101. module_param(int_mode, int, S_IRUGO);
  102. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  103. "(1 INT#x; 2 MSI)");
  104. static int dropless_fc;
  105. module_param(dropless_fc, int, S_IRUGO);
  106. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  107. static int mrrs = -1;
  108. module_param(mrrs, int, S_IRUGO);
  109. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  110. static int debug;
  111. module_param(debug, int, S_IRUGO);
  112. MODULE_PARM_DESC(debug, " Default debug msglevel");
  113. static struct workqueue_struct *bnx2x_wq;
  114. struct workqueue_struct *bnx2x_iov_wq;
  115. struct bnx2x_mac_vals {
  116. u32 xmac_addr;
  117. u32 xmac_val;
  118. u32 emac_addr;
  119. u32 emac_val;
  120. u32 umac_addr[2];
  121. u32 umac_val[2];
  122. u32 bmac_addr;
  123. u32 bmac_val[2];
  124. };
  125. enum bnx2x_board_type {
  126. BCM57710 = 0,
  127. BCM57711,
  128. BCM57711E,
  129. BCM57712,
  130. BCM57712_MF,
  131. BCM57712_VF,
  132. BCM57800,
  133. BCM57800_MF,
  134. BCM57800_VF,
  135. BCM57810,
  136. BCM57810_MF,
  137. BCM57810_VF,
  138. BCM57840_4_10,
  139. BCM57840_2_20,
  140. BCM57840_MF,
  141. BCM57840_VF,
  142. BCM57811,
  143. BCM57811_MF,
  144. BCM57840_O,
  145. BCM57840_MFO,
  146. BCM57811_VF
  147. };
  148. /* indexed by board_type, above */
  149. static struct {
  150. char *name;
  151. } board_info[] = {
  152. [BCM57710] = { "QLogic BCM57710 10 Gigabit PCIe [Everest]" },
  153. [BCM57711] = { "QLogic BCM57711 10 Gigabit PCIe" },
  154. [BCM57711E] = { "QLogic BCM57711E 10 Gigabit PCIe" },
  155. [BCM57712] = { "QLogic BCM57712 10 Gigabit Ethernet" },
  156. [BCM57712_MF] = { "QLogic BCM57712 10 Gigabit Ethernet Multi Function" },
  157. [BCM57712_VF] = { "QLogic BCM57712 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57800] = { "QLogic BCM57800 10 Gigabit Ethernet" },
  159. [BCM57800_MF] = { "QLogic BCM57800 10 Gigabit Ethernet Multi Function" },
  160. [BCM57800_VF] = { "QLogic BCM57800 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57810] = { "QLogic BCM57810 10 Gigabit Ethernet" },
  162. [BCM57810_MF] = { "QLogic BCM57810 10 Gigabit Ethernet Multi Function" },
  163. [BCM57810_VF] = { "QLogic BCM57810 10 Gigabit Ethernet Virtual Function" },
  164. [BCM57840_4_10] = { "QLogic BCM57840 10 Gigabit Ethernet" },
  165. [BCM57840_2_20] = { "QLogic BCM57840 20 Gigabit Ethernet" },
  166. [BCM57840_MF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  167. [BCM57840_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  168. [BCM57811] = { "QLogic BCM57811 10 Gigabit Ethernet" },
  169. [BCM57811_MF] = { "QLogic BCM57811 10 Gigabit Ethernet Multi Function" },
  170. [BCM57840_O] = { "QLogic BCM57840 10/20 Gigabit Ethernet" },
  171. [BCM57840_MFO] = { "QLogic BCM57840 10/20 Gigabit Ethernet Multi Function" },
  172. [BCM57811_VF] = { "QLogic BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  173. };
  174. #ifndef PCI_DEVICE_ID_NX2_57710
  175. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711
  178. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57711E
  181. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712
  184. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  187. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  190. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800
  193. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  196. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  199. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810
  202. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  205. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_O
  208. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  211. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  214. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  217. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  220. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  223. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  226. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811
  229. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  232. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  233. #endif
  234. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  235. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  236. #endif
  237. static const struct pci_device_id bnx2x_pci_tbl[] = {
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  251. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  256. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  257. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  258. { PCI_VDEVICE(QLOGIC, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  259. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  260. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  261. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  262. { 0 }
  263. };
  264. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  265. /* Global resources for unloading a previously loaded device */
  266. #define BNX2X_PREV_WAIT_NEEDED 1
  267. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  268. static LIST_HEAD(bnx2x_prev_list);
  269. /* Forward declaration */
  270. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  271. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  272. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  273. /****************************************************************************
  274. * General service functions
  275. ****************************************************************************/
  276. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  277. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  278. u32 addr, dma_addr_t mapping)
  279. {
  280. REG_WR(bp, addr, U64_LO(mapping));
  281. REG_WR(bp, addr + 4, U64_HI(mapping));
  282. }
  283. static void storm_memset_spq_addr(struct bnx2x *bp,
  284. dma_addr_t mapping, u16 abs_fid)
  285. {
  286. u32 addr = XSEM_REG_FAST_MEMORY +
  287. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  288. __storm_memset_dma_mapping(bp, addr, mapping);
  289. }
  290. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  291. u16 pf_id)
  292. {
  293. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  294. pf_id);
  295. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  296. pf_id);
  297. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  298. pf_id);
  299. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  300. pf_id);
  301. }
  302. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  303. u8 enable)
  304. {
  305. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  306. enable);
  307. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  308. enable);
  309. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  310. enable);
  311. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  312. enable);
  313. }
  314. static void storm_memset_eq_data(struct bnx2x *bp,
  315. struct event_ring_data *eq_data,
  316. u16 pfid)
  317. {
  318. size_t size = sizeof(struct event_ring_data);
  319. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  320. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  321. }
  322. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  323. u16 pfid)
  324. {
  325. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  326. REG_WR16(bp, addr, eq_prod);
  327. }
  328. /* used only at init
  329. * locking is done by mcp
  330. */
  331. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  332. {
  333. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  334. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  335. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  336. PCICFG_VENDOR_ID_OFFSET);
  337. }
  338. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  339. {
  340. u32 val;
  341. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  342. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  343. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  344. PCICFG_VENDOR_ID_OFFSET);
  345. return val;
  346. }
  347. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  348. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  349. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  350. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  351. #define DMAE_DP_DST_NONE "dst_addr [none]"
  352. static void bnx2x_dp_dmae(struct bnx2x *bp,
  353. struct dmae_command *dmae, int msglvl)
  354. {
  355. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  356. int i;
  357. switch (dmae->opcode & DMAE_COMMAND_DST) {
  358. case DMAE_CMD_DST_PCI:
  359. if (src_type == DMAE_CMD_SRC_PCI)
  360. DP(msglvl, "DMAE: opcode 0x%08x\n"
  361. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  362. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  363. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  364. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  365. dmae->comp_addr_hi, dmae->comp_addr_lo,
  366. dmae->comp_val);
  367. else
  368. DP(msglvl, "DMAE: opcode 0x%08x\n"
  369. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  370. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  371. dmae->opcode, dmae->src_addr_lo >> 2,
  372. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  373. dmae->comp_addr_hi, dmae->comp_addr_lo,
  374. dmae->comp_val);
  375. break;
  376. case DMAE_CMD_DST_GRC:
  377. if (src_type == DMAE_CMD_SRC_PCI)
  378. DP(msglvl, "DMAE: opcode 0x%08x\n"
  379. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  380. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  381. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  382. dmae->len, dmae->dst_addr_lo >> 2,
  383. dmae->comp_addr_hi, dmae->comp_addr_lo,
  384. dmae->comp_val);
  385. else
  386. DP(msglvl, "DMAE: opcode 0x%08x\n"
  387. "src [%08x], len [%d*4], dst [%08x]\n"
  388. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  389. dmae->opcode, dmae->src_addr_lo >> 2,
  390. dmae->len, dmae->dst_addr_lo >> 2,
  391. dmae->comp_addr_hi, dmae->comp_addr_lo,
  392. dmae->comp_val);
  393. break;
  394. default:
  395. if (src_type == DMAE_CMD_SRC_PCI)
  396. DP(msglvl, "DMAE: opcode 0x%08x\n"
  397. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  398. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  399. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  400. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  401. dmae->comp_val);
  402. else
  403. DP(msglvl, "DMAE: opcode 0x%08x\n"
  404. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  405. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  406. dmae->opcode, dmae->src_addr_lo >> 2,
  407. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  408. dmae->comp_val);
  409. break;
  410. }
  411. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  412. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  413. i, *(((u32 *)dmae) + i));
  414. }
  415. /* copy command into DMAE command memory and set DMAE command go */
  416. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  417. {
  418. u32 cmd_offset;
  419. int i;
  420. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  421. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  422. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  423. }
  424. REG_WR(bp, dmae_reg_go_c[idx], 1);
  425. }
  426. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  427. {
  428. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  429. DMAE_CMD_C_ENABLE);
  430. }
  431. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  432. {
  433. return opcode & ~DMAE_CMD_SRC_RESET;
  434. }
  435. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  436. bool with_comp, u8 comp_type)
  437. {
  438. u32 opcode = 0;
  439. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  440. (dst_type << DMAE_COMMAND_DST_SHIFT));
  441. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  442. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  443. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  444. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  445. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  446. #ifdef __BIG_ENDIAN
  447. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  448. #else
  449. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  450. #endif
  451. if (with_comp)
  452. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  453. return opcode;
  454. }
  455. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  456. struct dmae_command *dmae,
  457. u8 src_type, u8 dst_type)
  458. {
  459. memset(dmae, 0, sizeof(struct dmae_command));
  460. /* set the opcode */
  461. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  462. true, DMAE_COMP_PCI);
  463. /* fill in the completion parameters */
  464. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  465. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  466. dmae->comp_val = DMAE_COMP_VAL;
  467. }
  468. /* issue a dmae command over the init-channel and wait for completion */
  469. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  470. u32 *comp)
  471. {
  472. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  473. int rc = 0;
  474. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  475. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  476. * as long as this code is called both from syscall context and
  477. * from ndo_set_rx_mode() flow that may be called from BH.
  478. */
  479. spin_lock_bh(&bp->dmae_lock);
  480. /* reset completion */
  481. *comp = 0;
  482. /* post the command on the channel used for initializations */
  483. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  484. /* wait for completion */
  485. udelay(5);
  486. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  487. if (!cnt ||
  488. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  489. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  490. BNX2X_ERR("DMAE timeout!\n");
  491. rc = DMAE_TIMEOUT;
  492. goto unlock;
  493. }
  494. cnt--;
  495. udelay(50);
  496. }
  497. if (*comp & DMAE_PCI_ERR_FLAG) {
  498. BNX2X_ERR("DMAE PCI error!\n");
  499. rc = DMAE_PCI_ERROR;
  500. }
  501. unlock:
  502. spin_unlock_bh(&bp->dmae_lock);
  503. return rc;
  504. }
  505. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  506. u32 len32)
  507. {
  508. int rc;
  509. struct dmae_command dmae;
  510. if (!bp->dmae_ready) {
  511. u32 *data = bnx2x_sp(bp, wb_data[0]);
  512. if (CHIP_IS_E1(bp))
  513. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  514. else
  515. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  516. return;
  517. }
  518. /* set opcode and fixed command fields */
  519. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  520. /* fill in addresses and len */
  521. dmae.src_addr_lo = U64_LO(dma_addr);
  522. dmae.src_addr_hi = U64_HI(dma_addr);
  523. dmae.dst_addr_lo = dst_addr >> 2;
  524. dmae.dst_addr_hi = 0;
  525. dmae.len = len32;
  526. /* issue the command and wait for completion */
  527. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  528. if (rc) {
  529. BNX2X_ERR("DMAE returned failure %d\n", rc);
  530. #ifdef BNX2X_STOP_ON_ERROR
  531. bnx2x_panic();
  532. #endif
  533. }
  534. }
  535. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  536. {
  537. int rc;
  538. struct dmae_command dmae;
  539. if (!bp->dmae_ready) {
  540. u32 *data = bnx2x_sp(bp, wb_data[0]);
  541. int i;
  542. if (CHIP_IS_E1(bp))
  543. for (i = 0; i < len32; i++)
  544. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  545. else
  546. for (i = 0; i < len32; i++)
  547. data[i] = REG_RD(bp, src_addr + i*4);
  548. return;
  549. }
  550. /* set opcode and fixed command fields */
  551. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  552. /* fill in addresses and len */
  553. dmae.src_addr_lo = src_addr >> 2;
  554. dmae.src_addr_hi = 0;
  555. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  556. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  557. dmae.len = len32;
  558. /* issue the command and wait for completion */
  559. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  560. if (rc) {
  561. BNX2X_ERR("DMAE returned failure %d\n", rc);
  562. #ifdef BNX2X_STOP_ON_ERROR
  563. bnx2x_panic();
  564. #endif
  565. }
  566. }
  567. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  568. u32 addr, u32 len)
  569. {
  570. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  571. int offset = 0;
  572. while (len > dmae_wr_max) {
  573. bnx2x_write_dmae(bp, phys_addr + offset,
  574. addr + offset, dmae_wr_max);
  575. offset += dmae_wr_max * 4;
  576. len -= dmae_wr_max;
  577. }
  578. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  579. }
  580. enum storms {
  581. XSTORM,
  582. TSTORM,
  583. CSTORM,
  584. USTORM,
  585. MAX_STORMS
  586. };
  587. #define STORMS_NUM 4
  588. #define REGS_IN_ENTRY 4
  589. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  590. enum storms storm,
  591. int entry)
  592. {
  593. switch (storm) {
  594. case XSTORM:
  595. return XSTORM_ASSERT_LIST_OFFSET(entry);
  596. case TSTORM:
  597. return TSTORM_ASSERT_LIST_OFFSET(entry);
  598. case CSTORM:
  599. return CSTORM_ASSERT_LIST_OFFSET(entry);
  600. case USTORM:
  601. return USTORM_ASSERT_LIST_OFFSET(entry);
  602. case MAX_STORMS:
  603. default:
  604. BNX2X_ERR("unknown storm\n");
  605. }
  606. return -EINVAL;
  607. }
  608. static int bnx2x_mc_assert(struct bnx2x *bp)
  609. {
  610. char last_idx;
  611. int i, j, rc = 0;
  612. enum storms storm;
  613. u32 regs[REGS_IN_ENTRY];
  614. u32 bar_storm_intmem[STORMS_NUM] = {
  615. BAR_XSTRORM_INTMEM,
  616. BAR_TSTRORM_INTMEM,
  617. BAR_CSTRORM_INTMEM,
  618. BAR_USTRORM_INTMEM
  619. };
  620. u32 storm_assert_list_index[STORMS_NUM] = {
  621. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  622. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  623. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  624. USTORM_ASSERT_LIST_INDEX_OFFSET
  625. };
  626. char *storms_string[STORMS_NUM] = {
  627. "XSTORM",
  628. "TSTORM",
  629. "CSTORM",
  630. "USTORM"
  631. };
  632. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  633. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  634. storm_assert_list_index[storm]);
  635. if (last_idx)
  636. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  637. storms_string[storm], last_idx);
  638. /* print the asserts */
  639. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  640. /* read a single assert entry */
  641. for (j = 0; j < REGS_IN_ENTRY; j++)
  642. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  643. bnx2x_get_assert_list_entry(bp,
  644. storm,
  645. i) +
  646. sizeof(u32) * j);
  647. /* log entry if it contains a valid assert */
  648. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  649. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  650. storms_string[storm], i, regs[3],
  651. regs[2], regs[1], regs[0]);
  652. rc++;
  653. } else {
  654. break;
  655. }
  656. }
  657. }
  658. BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
  659. CHIP_IS_E1(bp) ? "everest1" :
  660. CHIP_IS_E1H(bp) ? "everest1h" :
  661. CHIP_IS_E2(bp) ? "everest2" : "everest3",
  662. BCM_5710_FW_MAJOR_VERSION,
  663. BCM_5710_FW_MINOR_VERSION,
  664. BCM_5710_FW_REVISION_VERSION);
  665. return rc;
  666. }
  667. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  668. #define SCRATCH_BUFFER_SIZE(bp) \
  669. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  670. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  671. {
  672. u32 addr, val;
  673. u32 mark, offset;
  674. __be32 data[9];
  675. int word;
  676. u32 trace_shmem_base;
  677. if (BP_NOMCP(bp)) {
  678. BNX2X_ERR("NO MCP - can not dump\n");
  679. return;
  680. }
  681. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  682. (bp->common.bc_ver & 0xff0000) >> 16,
  683. (bp->common.bc_ver & 0xff00) >> 8,
  684. (bp->common.bc_ver & 0xff));
  685. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  686. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  687. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  688. if (BP_PATH(bp) == 0)
  689. trace_shmem_base = bp->common.shmem_base;
  690. else
  691. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  692. /* sanity */
  693. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  694. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  695. SCRATCH_BUFFER_SIZE(bp)) {
  696. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  697. trace_shmem_base);
  698. return;
  699. }
  700. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  701. /* validate TRCB signature */
  702. mark = REG_RD(bp, addr);
  703. if (mark != MFW_TRACE_SIGNATURE) {
  704. BNX2X_ERR("Trace buffer signature is missing.");
  705. return ;
  706. }
  707. /* read cyclic buffer pointer */
  708. addr += 4;
  709. mark = REG_RD(bp, addr);
  710. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  711. if (mark >= trace_shmem_base || mark < addr + 4) {
  712. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  713. return;
  714. }
  715. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  716. printk("%s", lvl);
  717. /* dump buffer after the mark */
  718. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  719. for (word = 0; word < 8; word++)
  720. data[word] = htonl(REG_RD(bp, offset + 4*word));
  721. data[8] = 0x0;
  722. pr_cont("%s", (char *)data);
  723. }
  724. /* dump buffer before the mark */
  725. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  726. for (word = 0; word < 8; word++)
  727. data[word] = htonl(REG_RD(bp, offset + 4*word));
  728. data[8] = 0x0;
  729. pr_cont("%s", (char *)data);
  730. }
  731. printk("%s" "end of fw dump\n", lvl);
  732. }
  733. static void bnx2x_fw_dump(struct bnx2x *bp)
  734. {
  735. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  736. }
  737. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  738. {
  739. int port = BP_PORT(bp);
  740. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  741. u32 val = REG_RD(bp, addr);
  742. /* in E1 we must use only PCI configuration space to disable
  743. * MSI/MSIX capability
  744. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  745. */
  746. if (CHIP_IS_E1(bp)) {
  747. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  748. * Use mask register to prevent from HC sending interrupts
  749. * after we exit the function
  750. */
  751. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  752. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  753. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  754. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  755. } else
  756. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  757. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  758. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  759. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  760. DP(NETIF_MSG_IFDOWN,
  761. "write %x to HC %d (addr 0x%x)\n",
  762. val, port, addr);
  763. /* flush all outstanding writes */
  764. mmiowb();
  765. REG_WR(bp, addr, val);
  766. if (REG_RD(bp, addr) != val)
  767. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  768. }
  769. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  770. {
  771. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  772. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  773. IGU_PF_CONF_INT_LINE_EN |
  774. IGU_PF_CONF_ATTN_BIT_EN);
  775. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  776. /* flush all outstanding writes */
  777. mmiowb();
  778. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  779. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  780. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  781. }
  782. static void bnx2x_int_disable(struct bnx2x *bp)
  783. {
  784. if (bp->common.int_block == INT_BLOCK_HC)
  785. bnx2x_hc_int_disable(bp);
  786. else
  787. bnx2x_igu_int_disable(bp);
  788. }
  789. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  790. {
  791. int i;
  792. u16 j;
  793. struct hc_sp_status_block_data sp_sb_data;
  794. int func = BP_FUNC(bp);
  795. #ifdef BNX2X_STOP_ON_ERROR
  796. u16 start = 0, end = 0;
  797. u8 cos;
  798. #endif
  799. if (IS_PF(bp) && disable_int)
  800. bnx2x_int_disable(bp);
  801. bp->stats_state = STATS_STATE_DISABLED;
  802. bp->eth_stats.unrecoverable_error++;
  803. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  804. BNX2X_ERR("begin crash dump -----------------\n");
  805. /* Indices */
  806. /* Common */
  807. if (IS_PF(bp)) {
  808. struct host_sp_status_block *def_sb = bp->def_status_blk;
  809. int data_size, cstorm_offset;
  810. 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",
  811. bp->def_idx, bp->def_att_idx, bp->attn_state,
  812. bp->spq_prod_idx, bp->stats_counter);
  813. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  814. def_sb->atten_status_block.attn_bits,
  815. def_sb->atten_status_block.attn_bits_ack,
  816. def_sb->atten_status_block.status_block_id,
  817. def_sb->atten_status_block.attn_bits_index);
  818. BNX2X_ERR(" def (");
  819. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  820. pr_cont("0x%x%s",
  821. def_sb->sp_sb.index_values[i],
  822. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  823. data_size = sizeof(struct hc_sp_status_block_data) /
  824. sizeof(u32);
  825. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  826. for (i = 0; i < data_size; i++)
  827. *((u32 *)&sp_sb_data + i) =
  828. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  829. i * sizeof(u32));
  830. 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",
  831. sp_sb_data.igu_sb_id,
  832. sp_sb_data.igu_seg_id,
  833. sp_sb_data.p_func.pf_id,
  834. sp_sb_data.p_func.vnic_id,
  835. sp_sb_data.p_func.vf_id,
  836. sp_sb_data.p_func.vf_valid,
  837. sp_sb_data.state);
  838. }
  839. for_each_eth_queue(bp, i) {
  840. struct bnx2x_fastpath *fp = &bp->fp[i];
  841. int loop;
  842. struct hc_status_block_data_e2 sb_data_e2;
  843. struct hc_status_block_data_e1x sb_data_e1x;
  844. struct hc_status_block_sm *hc_sm_p =
  845. CHIP_IS_E1x(bp) ?
  846. sb_data_e1x.common.state_machine :
  847. sb_data_e2.common.state_machine;
  848. struct hc_index_data *hc_index_p =
  849. CHIP_IS_E1x(bp) ?
  850. sb_data_e1x.index_data :
  851. sb_data_e2.index_data;
  852. u8 data_size, cos;
  853. u32 *sb_data_p;
  854. struct bnx2x_fp_txdata txdata;
  855. if (!bp->fp)
  856. break;
  857. if (!fp->rx_cons_sb)
  858. continue;
  859. /* Rx */
  860. 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",
  861. i, fp->rx_bd_prod, fp->rx_bd_cons,
  862. fp->rx_comp_prod,
  863. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  864. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  865. fp->rx_sge_prod, fp->last_max_sge,
  866. le16_to_cpu(fp->fp_hc_idx));
  867. /* Tx */
  868. for_each_cos_in_tx_queue(fp, cos)
  869. {
  870. if (!fp->txdata_ptr[cos])
  871. break;
  872. txdata = *fp->txdata_ptr[cos];
  873. if (!txdata.tx_cons_sb)
  874. continue;
  875. 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",
  876. i, txdata.tx_pkt_prod,
  877. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  878. txdata.tx_bd_cons,
  879. le16_to_cpu(*txdata.tx_cons_sb));
  880. }
  881. loop = CHIP_IS_E1x(bp) ?
  882. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  883. /* host sb data */
  884. if (IS_FCOE_FP(fp))
  885. continue;
  886. BNX2X_ERR(" run indexes (");
  887. for (j = 0; j < HC_SB_MAX_SM; j++)
  888. pr_cont("0x%x%s",
  889. fp->sb_running_index[j],
  890. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  891. BNX2X_ERR(" indexes (");
  892. for (j = 0; j < loop; j++)
  893. pr_cont("0x%x%s",
  894. fp->sb_index_values[j],
  895. (j == loop - 1) ? ")" : " ");
  896. /* VF cannot access FW refelection for status block */
  897. if (IS_VF(bp))
  898. continue;
  899. /* fw sb data */
  900. data_size = CHIP_IS_E1x(bp) ?
  901. sizeof(struct hc_status_block_data_e1x) :
  902. sizeof(struct hc_status_block_data_e2);
  903. data_size /= sizeof(u32);
  904. sb_data_p = CHIP_IS_E1x(bp) ?
  905. (u32 *)&sb_data_e1x :
  906. (u32 *)&sb_data_e2;
  907. /* copy sb data in here */
  908. for (j = 0; j < data_size; j++)
  909. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  910. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  911. j * sizeof(u32));
  912. if (!CHIP_IS_E1x(bp)) {
  913. 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",
  914. sb_data_e2.common.p_func.pf_id,
  915. sb_data_e2.common.p_func.vf_id,
  916. sb_data_e2.common.p_func.vf_valid,
  917. sb_data_e2.common.p_func.vnic_id,
  918. sb_data_e2.common.same_igu_sb_1b,
  919. sb_data_e2.common.state);
  920. } else {
  921. 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",
  922. sb_data_e1x.common.p_func.pf_id,
  923. sb_data_e1x.common.p_func.vf_id,
  924. sb_data_e1x.common.p_func.vf_valid,
  925. sb_data_e1x.common.p_func.vnic_id,
  926. sb_data_e1x.common.same_igu_sb_1b,
  927. sb_data_e1x.common.state);
  928. }
  929. /* SB_SMs data */
  930. for (j = 0; j < HC_SB_MAX_SM; j++) {
  931. 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",
  932. j, hc_sm_p[j].__flags,
  933. hc_sm_p[j].igu_sb_id,
  934. hc_sm_p[j].igu_seg_id,
  935. hc_sm_p[j].time_to_expire,
  936. hc_sm_p[j].timer_value);
  937. }
  938. /* Indices data */
  939. for (j = 0; j < loop; j++) {
  940. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  941. hc_index_p[j].flags,
  942. hc_index_p[j].timeout);
  943. }
  944. }
  945. #ifdef BNX2X_STOP_ON_ERROR
  946. if (IS_PF(bp)) {
  947. /* event queue */
  948. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  949. for (i = 0; i < NUM_EQ_DESC; i++) {
  950. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  951. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  952. i, bp->eq_ring[i].message.opcode,
  953. bp->eq_ring[i].message.error);
  954. BNX2X_ERR("data: %x %x %x\n",
  955. data[0], data[1], data[2]);
  956. }
  957. }
  958. /* Rings */
  959. /* Rx */
  960. for_each_valid_rx_queue(bp, i) {
  961. struct bnx2x_fastpath *fp = &bp->fp[i];
  962. if (!bp->fp)
  963. break;
  964. if (!fp->rx_cons_sb)
  965. continue;
  966. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  967. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  968. for (j = start; j != end; j = RX_BD(j + 1)) {
  969. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  970. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  971. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  972. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  973. }
  974. start = RX_SGE(fp->rx_sge_prod);
  975. end = RX_SGE(fp->last_max_sge);
  976. for (j = start; j != end; j = RX_SGE(j + 1)) {
  977. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  978. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  979. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  980. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  981. }
  982. start = RCQ_BD(fp->rx_comp_cons - 10);
  983. end = RCQ_BD(fp->rx_comp_cons + 503);
  984. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  985. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  986. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  987. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  988. }
  989. }
  990. /* Tx */
  991. for_each_valid_tx_queue(bp, i) {
  992. struct bnx2x_fastpath *fp = &bp->fp[i];
  993. if (!bp->fp)
  994. break;
  995. for_each_cos_in_tx_queue(fp, cos) {
  996. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  997. if (!fp->txdata_ptr[cos])
  998. break;
  999. if (!txdata->tx_cons_sb)
  1000. continue;
  1001. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  1002. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  1003. for (j = start; j != end; j = TX_BD(j + 1)) {
  1004. struct sw_tx_bd *sw_bd =
  1005. &txdata->tx_buf_ring[j];
  1006. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1007. i, cos, j, sw_bd->skb,
  1008. sw_bd->first_bd);
  1009. }
  1010. start = TX_BD(txdata->tx_bd_cons - 10);
  1011. end = TX_BD(txdata->tx_bd_cons + 254);
  1012. for (j = start; j != end; j = TX_BD(j + 1)) {
  1013. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1014. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1015. i, cos, j, tx_bd[0], tx_bd[1],
  1016. tx_bd[2], tx_bd[3]);
  1017. }
  1018. }
  1019. }
  1020. #endif
  1021. if (IS_PF(bp)) {
  1022. bnx2x_fw_dump(bp);
  1023. bnx2x_mc_assert(bp);
  1024. }
  1025. BNX2X_ERR("end crash dump -----------------\n");
  1026. }
  1027. /*
  1028. * FLR Support for E2
  1029. *
  1030. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1031. * initialization.
  1032. */
  1033. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1034. #define FLR_WAIT_INTERVAL 50 /* usec */
  1035. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1036. struct pbf_pN_buf_regs {
  1037. int pN;
  1038. u32 init_crd;
  1039. u32 crd;
  1040. u32 crd_freed;
  1041. };
  1042. struct pbf_pN_cmd_regs {
  1043. int pN;
  1044. u32 lines_occup;
  1045. u32 lines_freed;
  1046. };
  1047. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1048. struct pbf_pN_buf_regs *regs,
  1049. u32 poll_count)
  1050. {
  1051. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1052. u32 cur_cnt = poll_count;
  1053. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1054. crd = crd_start = REG_RD(bp, regs->crd);
  1055. init_crd = REG_RD(bp, regs->init_crd);
  1056. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1057. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1058. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1059. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1060. (init_crd - crd_start))) {
  1061. if (cur_cnt--) {
  1062. udelay(FLR_WAIT_INTERVAL);
  1063. crd = REG_RD(bp, regs->crd);
  1064. crd_freed = REG_RD(bp, regs->crd_freed);
  1065. } else {
  1066. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1067. regs->pN);
  1068. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1069. regs->pN, crd);
  1070. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1071. regs->pN, crd_freed);
  1072. break;
  1073. }
  1074. }
  1075. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1076. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1077. }
  1078. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1079. struct pbf_pN_cmd_regs *regs,
  1080. u32 poll_count)
  1081. {
  1082. u32 occup, to_free, freed, freed_start;
  1083. u32 cur_cnt = poll_count;
  1084. occup = to_free = REG_RD(bp, regs->lines_occup);
  1085. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1086. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1087. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1088. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1089. if (cur_cnt--) {
  1090. udelay(FLR_WAIT_INTERVAL);
  1091. occup = REG_RD(bp, regs->lines_occup);
  1092. freed = REG_RD(bp, regs->lines_freed);
  1093. } else {
  1094. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1095. regs->pN);
  1096. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1097. regs->pN, occup);
  1098. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1099. regs->pN, freed);
  1100. break;
  1101. }
  1102. }
  1103. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1104. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1105. }
  1106. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1107. u32 expected, u32 poll_count)
  1108. {
  1109. u32 cur_cnt = poll_count;
  1110. u32 val;
  1111. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1112. udelay(FLR_WAIT_INTERVAL);
  1113. return val;
  1114. }
  1115. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1116. char *msg, u32 poll_cnt)
  1117. {
  1118. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1119. if (val != 0) {
  1120. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1121. return 1;
  1122. }
  1123. return 0;
  1124. }
  1125. /* Common routines with VF FLR cleanup */
  1126. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1127. {
  1128. /* adjust polling timeout */
  1129. if (CHIP_REV_IS_EMUL(bp))
  1130. return FLR_POLL_CNT * 2000;
  1131. if (CHIP_REV_IS_FPGA(bp))
  1132. return FLR_POLL_CNT * 120;
  1133. return FLR_POLL_CNT;
  1134. }
  1135. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1136. {
  1137. struct pbf_pN_cmd_regs cmd_regs[] = {
  1138. {0, (CHIP_IS_E3B0(bp)) ?
  1139. PBF_REG_TQ_OCCUPANCY_Q0 :
  1140. PBF_REG_P0_TQ_OCCUPANCY,
  1141. (CHIP_IS_E3B0(bp)) ?
  1142. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1143. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1144. {1, (CHIP_IS_E3B0(bp)) ?
  1145. PBF_REG_TQ_OCCUPANCY_Q1 :
  1146. PBF_REG_P1_TQ_OCCUPANCY,
  1147. (CHIP_IS_E3B0(bp)) ?
  1148. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1149. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1150. {4, (CHIP_IS_E3B0(bp)) ?
  1151. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1152. PBF_REG_P4_TQ_OCCUPANCY,
  1153. (CHIP_IS_E3B0(bp)) ?
  1154. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1155. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1156. };
  1157. struct pbf_pN_buf_regs buf_regs[] = {
  1158. {0, (CHIP_IS_E3B0(bp)) ?
  1159. PBF_REG_INIT_CRD_Q0 :
  1160. PBF_REG_P0_INIT_CRD ,
  1161. (CHIP_IS_E3B0(bp)) ?
  1162. PBF_REG_CREDIT_Q0 :
  1163. PBF_REG_P0_CREDIT,
  1164. (CHIP_IS_E3B0(bp)) ?
  1165. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1166. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1167. {1, (CHIP_IS_E3B0(bp)) ?
  1168. PBF_REG_INIT_CRD_Q1 :
  1169. PBF_REG_P1_INIT_CRD,
  1170. (CHIP_IS_E3B0(bp)) ?
  1171. PBF_REG_CREDIT_Q1 :
  1172. PBF_REG_P1_CREDIT,
  1173. (CHIP_IS_E3B0(bp)) ?
  1174. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1175. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1176. {4, (CHIP_IS_E3B0(bp)) ?
  1177. PBF_REG_INIT_CRD_LB_Q :
  1178. PBF_REG_P4_INIT_CRD,
  1179. (CHIP_IS_E3B0(bp)) ?
  1180. PBF_REG_CREDIT_LB_Q :
  1181. PBF_REG_P4_CREDIT,
  1182. (CHIP_IS_E3B0(bp)) ?
  1183. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1184. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1185. };
  1186. int i;
  1187. /* Verify the command queues are flushed P0, P1, P4 */
  1188. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1189. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1190. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1191. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1192. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1193. }
  1194. #define OP_GEN_PARAM(param) \
  1195. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1196. #define OP_GEN_TYPE(type) \
  1197. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1198. #define OP_GEN_AGG_VECT(index) \
  1199. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1200. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1201. {
  1202. u32 op_gen_command = 0;
  1203. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1204. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1205. int ret = 0;
  1206. if (REG_RD(bp, comp_addr)) {
  1207. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1208. return 1;
  1209. }
  1210. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1211. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1212. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1213. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1214. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1215. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1216. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1217. BNX2X_ERR("FW final cleanup did not succeed\n");
  1218. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1219. (REG_RD(bp, comp_addr)));
  1220. bnx2x_panic();
  1221. return 1;
  1222. }
  1223. /* Zero completion for next FLR */
  1224. REG_WR(bp, comp_addr, 0);
  1225. return ret;
  1226. }
  1227. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1228. {
  1229. u16 status;
  1230. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1231. return status & PCI_EXP_DEVSTA_TRPND;
  1232. }
  1233. /* PF FLR specific routines
  1234. */
  1235. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1236. {
  1237. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1238. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1239. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1240. "CFC PF usage counter timed out",
  1241. poll_cnt))
  1242. return 1;
  1243. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1244. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1245. DORQ_REG_PF_USAGE_CNT,
  1246. "DQ PF usage counter timed out",
  1247. poll_cnt))
  1248. return 1;
  1249. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1250. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1251. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1252. "QM PF usage counter timed out",
  1253. poll_cnt))
  1254. return 1;
  1255. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1256. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1257. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1258. "Timers VNIC usage counter timed out",
  1259. poll_cnt))
  1260. return 1;
  1261. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1262. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1263. "Timers NUM_SCANS usage counter timed out",
  1264. poll_cnt))
  1265. return 1;
  1266. /* Wait DMAE PF usage counter to zero */
  1267. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1268. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1269. "DMAE command register timed out",
  1270. poll_cnt))
  1271. return 1;
  1272. return 0;
  1273. }
  1274. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1275. {
  1276. u32 val;
  1277. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1278. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1279. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1280. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1281. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1282. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1283. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1284. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1285. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1286. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1287. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1288. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1289. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1290. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1291. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1292. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1293. val);
  1294. }
  1295. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1296. {
  1297. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1298. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1299. /* Re-enable PF target read access */
  1300. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1301. /* Poll HW usage counters */
  1302. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1303. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1304. return -EBUSY;
  1305. /* Zero the igu 'trailing edge' and 'leading edge' */
  1306. /* Send the FW cleanup command */
  1307. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1308. return -EBUSY;
  1309. /* ATC cleanup */
  1310. /* Verify TX hw is flushed */
  1311. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1312. /* Wait 100ms (not adjusted according to platform) */
  1313. msleep(100);
  1314. /* Verify no pending pci transactions */
  1315. if (bnx2x_is_pcie_pending(bp->pdev))
  1316. BNX2X_ERR("PCIE Transactions still pending\n");
  1317. /* Debug */
  1318. bnx2x_hw_enable_status(bp);
  1319. /*
  1320. * Master enable - Due to WB DMAE writes performed before this
  1321. * register is re-initialized as part of the regular function init
  1322. */
  1323. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1324. return 0;
  1325. }
  1326. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1327. {
  1328. int port = BP_PORT(bp);
  1329. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1330. u32 val = REG_RD(bp, addr);
  1331. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1332. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1333. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1334. if (msix) {
  1335. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1336. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1337. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1338. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1339. if (single_msix)
  1340. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1341. } else if (msi) {
  1342. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1343. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1344. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1345. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1346. } else {
  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_INT_LINE_EN_0 |
  1350. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1351. if (!CHIP_IS_E1(bp)) {
  1352. DP(NETIF_MSG_IFUP,
  1353. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1354. REG_WR(bp, addr, val);
  1355. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1356. }
  1357. }
  1358. if (CHIP_IS_E1(bp))
  1359. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1360. DP(NETIF_MSG_IFUP,
  1361. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1362. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1363. REG_WR(bp, addr, val);
  1364. /*
  1365. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1366. */
  1367. mmiowb();
  1368. barrier();
  1369. if (!CHIP_IS_E1(bp)) {
  1370. /* init leading/trailing edge */
  1371. if (IS_MF(bp)) {
  1372. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1373. if (bp->port.pmf)
  1374. /* enable nig and gpio3 attention */
  1375. val |= 0x1100;
  1376. } else
  1377. val = 0xffff;
  1378. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1379. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1380. }
  1381. /* Make sure that interrupts are indeed enabled from here on */
  1382. mmiowb();
  1383. }
  1384. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1385. {
  1386. u32 val;
  1387. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1388. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1389. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1390. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1391. if (msix) {
  1392. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1393. IGU_PF_CONF_SINGLE_ISR_EN);
  1394. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1395. IGU_PF_CONF_ATTN_BIT_EN);
  1396. if (single_msix)
  1397. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1398. } else if (msi) {
  1399. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1400. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1401. IGU_PF_CONF_ATTN_BIT_EN |
  1402. IGU_PF_CONF_SINGLE_ISR_EN);
  1403. } else {
  1404. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1405. val |= (IGU_PF_CONF_INT_LINE_EN |
  1406. IGU_PF_CONF_ATTN_BIT_EN |
  1407. IGU_PF_CONF_SINGLE_ISR_EN);
  1408. }
  1409. /* Clean previous status - need to configure igu prior to ack*/
  1410. if ((!msix) || single_msix) {
  1411. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1412. bnx2x_ack_int(bp);
  1413. }
  1414. val |= IGU_PF_CONF_FUNC_EN;
  1415. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1416. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1417. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1418. if (val & IGU_PF_CONF_INT_LINE_EN)
  1419. pci_intx(bp->pdev, true);
  1420. barrier();
  1421. /* init leading/trailing edge */
  1422. if (IS_MF(bp)) {
  1423. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1424. if (bp->port.pmf)
  1425. /* enable nig and gpio3 attention */
  1426. val |= 0x1100;
  1427. } else
  1428. val = 0xffff;
  1429. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1430. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1431. /* Make sure that interrupts are indeed enabled from here on */
  1432. mmiowb();
  1433. }
  1434. void bnx2x_int_enable(struct bnx2x *bp)
  1435. {
  1436. if (bp->common.int_block == INT_BLOCK_HC)
  1437. bnx2x_hc_int_enable(bp);
  1438. else
  1439. bnx2x_igu_int_enable(bp);
  1440. }
  1441. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1442. {
  1443. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1444. int i, offset;
  1445. if (disable_hw)
  1446. /* prevent the HW from sending interrupts */
  1447. bnx2x_int_disable(bp);
  1448. /* make sure all ISRs are done */
  1449. if (msix) {
  1450. synchronize_irq(bp->msix_table[0].vector);
  1451. offset = 1;
  1452. if (CNIC_SUPPORT(bp))
  1453. offset++;
  1454. for_each_eth_queue(bp, i)
  1455. synchronize_irq(bp->msix_table[offset++].vector);
  1456. } else
  1457. synchronize_irq(bp->pdev->irq);
  1458. /* make sure sp_task is not running */
  1459. cancel_delayed_work(&bp->sp_task);
  1460. cancel_delayed_work(&bp->period_task);
  1461. flush_workqueue(bnx2x_wq);
  1462. }
  1463. /* fast path */
  1464. /*
  1465. * General service functions
  1466. */
  1467. /* Return true if succeeded to acquire the lock */
  1468. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1469. {
  1470. u32 lock_status;
  1471. u32 resource_bit = (1 << resource);
  1472. int func = BP_FUNC(bp);
  1473. u32 hw_lock_control_reg;
  1474. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1475. "Trying to take a lock on resource %d\n", resource);
  1476. /* Validating that the resource is within range */
  1477. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1478. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1479. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1480. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1481. return false;
  1482. }
  1483. if (func <= 5)
  1484. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1485. else
  1486. hw_lock_control_reg =
  1487. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1488. /* Try to acquire the lock */
  1489. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1490. lock_status = REG_RD(bp, hw_lock_control_reg);
  1491. if (lock_status & resource_bit)
  1492. return true;
  1493. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1494. "Failed to get a lock on resource %d\n", resource);
  1495. return false;
  1496. }
  1497. /**
  1498. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1499. *
  1500. * @bp: driver handle
  1501. *
  1502. * Returns the recovery leader resource id according to the engine this function
  1503. * belongs to. Currently only only 2 engines is supported.
  1504. */
  1505. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1506. {
  1507. if (BP_PATH(bp))
  1508. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1509. else
  1510. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1511. }
  1512. /**
  1513. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1514. *
  1515. * @bp: driver handle
  1516. *
  1517. * Tries to acquire a leader lock for current engine.
  1518. */
  1519. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1520. {
  1521. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1522. }
  1523. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1524. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1525. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1526. {
  1527. /* Set the interrupt occurred bit for the sp-task to recognize it
  1528. * must ack the interrupt and transition according to the IGU
  1529. * state machine.
  1530. */
  1531. atomic_set(&bp->interrupt_occurred, 1);
  1532. /* The sp_task must execute only after this bit
  1533. * is set, otherwise we will get out of sync and miss all
  1534. * further interrupts. Hence, the barrier.
  1535. */
  1536. smp_wmb();
  1537. /* schedule sp_task to workqueue */
  1538. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1539. }
  1540. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1541. {
  1542. struct bnx2x *bp = fp->bp;
  1543. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1544. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1545. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1546. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1547. DP(BNX2X_MSG_SP,
  1548. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1549. fp->index, cid, command, bp->state,
  1550. rr_cqe->ramrod_cqe.ramrod_type);
  1551. /* If cid is within VF range, replace the slowpath object with the
  1552. * one corresponding to this VF
  1553. */
  1554. if (cid >= BNX2X_FIRST_VF_CID &&
  1555. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1556. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1557. switch (command) {
  1558. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1559. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1560. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1561. break;
  1562. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1563. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1564. drv_cmd = BNX2X_Q_CMD_SETUP;
  1565. break;
  1566. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1567. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1568. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1569. break;
  1570. case (RAMROD_CMD_ID_ETH_HALT):
  1571. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1572. drv_cmd = BNX2X_Q_CMD_HALT;
  1573. break;
  1574. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1575. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1576. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1577. break;
  1578. case (RAMROD_CMD_ID_ETH_EMPTY):
  1579. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1580. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1581. break;
  1582. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1583. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1584. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1585. break;
  1586. default:
  1587. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1588. command, fp->index);
  1589. return;
  1590. }
  1591. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1592. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1593. /* q_obj->complete_cmd() failure means that this was
  1594. * an unexpected completion.
  1595. *
  1596. * In this case we don't want to increase the bp->spq_left
  1597. * because apparently we haven't sent this command the first
  1598. * place.
  1599. */
  1600. #ifdef BNX2X_STOP_ON_ERROR
  1601. bnx2x_panic();
  1602. #else
  1603. return;
  1604. #endif
  1605. smp_mb__before_atomic();
  1606. atomic_inc(&bp->cq_spq_left);
  1607. /* push the change in bp->spq_left and towards the memory */
  1608. smp_mb__after_atomic();
  1609. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1610. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1611. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1612. /* if Q update ramrod is completed for last Q in AFEX vif set
  1613. * flow, then ACK MCP at the end
  1614. *
  1615. * mark pending ACK to MCP bit.
  1616. * prevent case that both bits are cleared.
  1617. * At the end of load/unload driver checks that
  1618. * sp_state is cleared, and this order prevents
  1619. * races
  1620. */
  1621. smp_mb__before_atomic();
  1622. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1623. wmb();
  1624. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1625. smp_mb__after_atomic();
  1626. /* schedule the sp task as mcp ack is required */
  1627. bnx2x_schedule_sp_task(bp);
  1628. }
  1629. return;
  1630. }
  1631. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1632. {
  1633. struct bnx2x *bp = netdev_priv(dev_instance);
  1634. u16 status = bnx2x_ack_int(bp);
  1635. u16 mask;
  1636. int i;
  1637. u8 cos;
  1638. /* Return here if interrupt is shared and it's not for us */
  1639. if (unlikely(status == 0)) {
  1640. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1641. return IRQ_NONE;
  1642. }
  1643. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1644. #ifdef BNX2X_STOP_ON_ERROR
  1645. if (unlikely(bp->panic))
  1646. return IRQ_HANDLED;
  1647. #endif
  1648. for_each_eth_queue(bp, i) {
  1649. struct bnx2x_fastpath *fp = &bp->fp[i];
  1650. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1651. if (status & mask) {
  1652. /* Handle Rx or Tx according to SB id */
  1653. for_each_cos_in_tx_queue(fp, cos)
  1654. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1655. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1656. napi_schedule_irqoff(&bnx2x_fp(bp, fp->index, napi));
  1657. status &= ~mask;
  1658. }
  1659. }
  1660. if (CNIC_SUPPORT(bp)) {
  1661. mask = 0x2;
  1662. if (status & (mask | 0x1)) {
  1663. struct cnic_ops *c_ops = NULL;
  1664. rcu_read_lock();
  1665. c_ops = rcu_dereference(bp->cnic_ops);
  1666. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1667. CNIC_DRV_STATE_HANDLES_IRQ))
  1668. c_ops->cnic_handler(bp->cnic_data, NULL);
  1669. rcu_read_unlock();
  1670. status &= ~mask;
  1671. }
  1672. }
  1673. if (unlikely(status & 0x1)) {
  1674. /* schedule sp task to perform default status block work, ack
  1675. * attentions and enable interrupts.
  1676. */
  1677. bnx2x_schedule_sp_task(bp);
  1678. status &= ~0x1;
  1679. if (!status)
  1680. return IRQ_HANDLED;
  1681. }
  1682. if (unlikely(status))
  1683. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1684. status);
  1685. return IRQ_HANDLED;
  1686. }
  1687. /* Link */
  1688. /*
  1689. * General service functions
  1690. */
  1691. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1692. {
  1693. u32 lock_status;
  1694. u32 resource_bit = (1 << resource);
  1695. int func = BP_FUNC(bp);
  1696. u32 hw_lock_control_reg;
  1697. int cnt;
  1698. /* Validating that the resource is within range */
  1699. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1700. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1701. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1702. return -EINVAL;
  1703. }
  1704. if (func <= 5) {
  1705. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1706. } else {
  1707. hw_lock_control_reg =
  1708. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1709. }
  1710. /* Validating that the resource is not already taken */
  1711. lock_status = REG_RD(bp, hw_lock_control_reg);
  1712. if (lock_status & resource_bit) {
  1713. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1714. lock_status, resource_bit);
  1715. return -EEXIST;
  1716. }
  1717. /* Try for 5 second every 5ms */
  1718. for (cnt = 0; cnt < 1000; cnt++) {
  1719. /* Try to acquire the lock */
  1720. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1721. lock_status = REG_RD(bp, hw_lock_control_reg);
  1722. if (lock_status & resource_bit)
  1723. return 0;
  1724. usleep_range(5000, 10000);
  1725. }
  1726. BNX2X_ERR("Timeout\n");
  1727. return -EAGAIN;
  1728. }
  1729. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1730. {
  1731. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1732. }
  1733. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1734. {
  1735. u32 lock_status;
  1736. u32 resource_bit = (1 << resource);
  1737. int func = BP_FUNC(bp);
  1738. u32 hw_lock_control_reg;
  1739. /* Validating that the resource is within range */
  1740. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1741. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1742. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1743. return -EINVAL;
  1744. }
  1745. if (func <= 5) {
  1746. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1747. } else {
  1748. hw_lock_control_reg =
  1749. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1750. }
  1751. /* Validating that the resource is currently taken */
  1752. lock_status = REG_RD(bp, hw_lock_control_reg);
  1753. if (!(lock_status & resource_bit)) {
  1754. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1755. lock_status, resource_bit);
  1756. return -EFAULT;
  1757. }
  1758. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1759. return 0;
  1760. }
  1761. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1762. {
  1763. /* The GPIO should be swapped if swap register is set and active */
  1764. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1765. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1766. int gpio_shift = gpio_num +
  1767. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1768. u32 gpio_mask = (1 << gpio_shift);
  1769. u32 gpio_reg;
  1770. int value;
  1771. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1772. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1773. return -EINVAL;
  1774. }
  1775. /* read GPIO value */
  1776. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1777. /* get the requested pin value */
  1778. if ((gpio_reg & gpio_mask) == gpio_mask)
  1779. value = 1;
  1780. else
  1781. value = 0;
  1782. return value;
  1783. }
  1784. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1785. {
  1786. /* The GPIO should be swapped if swap register is set and active */
  1787. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1788. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1789. int gpio_shift = gpio_num +
  1790. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1791. u32 gpio_mask = (1 << gpio_shift);
  1792. u32 gpio_reg;
  1793. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1794. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1795. return -EINVAL;
  1796. }
  1797. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1798. /* read GPIO and mask except the float bits */
  1799. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1800. switch (mode) {
  1801. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1802. DP(NETIF_MSG_LINK,
  1803. "Set GPIO %d (shift %d) -> output low\n",
  1804. gpio_num, gpio_shift);
  1805. /* clear FLOAT and set CLR */
  1806. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1807. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1808. break;
  1809. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1810. DP(NETIF_MSG_LINK,
  1811. "Set GPIO %d (shift %d) -> output high\n",
  1812. gpio_num, gpio_shift);
  1813. /* clear FLOAT and set SET */
  1814. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1815. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1816. break;
  1817. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1818. DP(NETIF_MSG_LINK,
  1819. "Set GPIO %d (shift %d) -> input\n",
  1820. gpio_num, gpio_shift);
  1821. /* set FLOAT */
  1822. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1823. break;
  1824. default:
  1825. break;
  1826. }
  1827. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1828. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1829. return 0;
  1830. }
  1831. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1832. {
  1833. u32 gpio_reg = 0;
  1834. int rc = 0;
  1835. /* Any port swapping should be handled by caller. */
  1836. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1837. /* read GPIO and mask except the float bits */
  1838. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1839. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1840. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1841. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1842. switch (mode) {
  1843. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1844. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1845. /* set CLR */
  1846. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1847. break;
  1848. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1849. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1850. /* set SET */
  1851. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1852. break;
  1853. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1854. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1855. /* set FLOAT */
  1856. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1857. break;
  1858. default:
  1859. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1860. rc = -EINVAL;
  1861. break;
  1862. }
  1863. if (rc == 0)
  1864. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1865. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1866. return rc;
  1867. }
  1868. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1869. {
  1870. /* The GPIO should be swapped if swap register is set and active */
  1871. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1872. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1873. int gpio_shift = gpio_num +
  1874. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1875. u32 gpio_mask = (1 << gpio_shift);
  1876. u32 gpio_reg;
  1877. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1878. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1879. return -EINVAL;
  1880. }
  1881. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1882. /* read GPIO int */
  1883. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1884. switch (mode) {
  1885. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1886. DP(NETIF_MSG_LINK,
  1887. "Clear GPIO INT %d (shift %d) -> output low\n",
  1888. gpio_num, gpio_shift);
  1889. /* clear SET and set CLR */
  1890. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1891. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1892. break;
  1893. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1894. DP(NETIF_MSG_LINK,
  1895. "Set GPIO INT %d (shift %d) -> output high\n",
  1896. gpio_num, gpio_shift);
  1897. /* clear CLR and set SET */
  1898. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1899. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1900. break;
  1901. default:
  1902. break;
  1903. }
  1904. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1905. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1906. return 0;
  1907. }
  1908. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1909. {
  1910. u32 spio_reg;
  1911. /* Only 2 SPIOs are configurable */
  1912. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1913. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1914. return -EINVAL;
  1915. }
  1916. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1917. /* read SPIO and mask except the float bits */
  1918. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1919. switch (mode) {
  1920. case MISC_SPIO_OUTPUT_LOW:
  1921. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1922. /* clear FLOAT and set CLR */
  1923. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1924. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1925. break;
  1926. case MISC_SPIO_OUTPUT_HIGH:
  1927. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1928. /* clear FLOAT and set SET */
  1929. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1930. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1931. break;
  1932. case MISC_SPIO_INPUT_HI_Z:
  1933. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1934. /* set FLOAT */
  1935. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1936. break;
  1937. default:
  1938. break;
  1939. }
  1940. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1941. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1942. return 0;
  1943. }
  1944. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1945. {
  1946. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1947. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1948. ADVERTISED_Pause);
  1949. switch (bp->link_vars.ieee_fc &
  1950. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1951. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1952. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1953. ADVERTISED_Pause);
  1954. break;
  1955. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1956. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1957. break;
  1958. default:
  1959. break;
  1960. }
  1961. }
  1962. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1963. {
  1964. /* Initialize link parameters structure variables
  1965. * It is recommended to turn off RX FC for jumbo frames
  1966. * for better performance
  1967. */
  1968. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1969. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1970. else
  1971. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1972. }
  1973. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1974. {
  1975. u32 pause_enabled = 0;
  1976. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1977. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1978. pause_enabled = 1;
  1979. REG_WR(bp, BAR_USTRORM_INTMEM +
  1980. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1981. pause_enabled);
  1982. }
  1983. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1984. pause_enabled ? "enabled" : "disabled");
  1985. }
  1986. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1987. {
  1988. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1989. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1990. if (!BP_NOMCP(bp)) {
  1991. bnx2x_set_requested_fc(bp);
  1992. bnx2x_acquire_phy_lock(bp);
  1993. if (load_mode == LOAD_DIAG) {
  1994. struct link_params *lp = &bp->link_params;
  1995. lp->loopback_mode = LOOPBACK_XGXS;
  1996. /* Prefer doing PHY loopback at highest speed */
  1997. if (lp->req_line_speed[cfx_idx] < SPEED_20000) {
  1998. if (lp->speed_cap_mask[cfx_idx] &
  1999. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G)
  2000. lp->req_line_speed[cfx_idx] =
  2001. SPEED_20000;
  2002. else if (lp->speed_cap_mask[cfx_idx] &
  2003. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  2004. lp->req_line_speed[cfx_idx] =
  2005. SPEED_10000;
  2006. else
  2007. lp->req_line_speed[cfx_idx] =
  2008. SPEED_1000;
  2009. }
  2010. }
  2011. if (load_mode == LOAD_LOOPBACK_EXT) {
  2012. struct link_params *lp = &bp->link_params;
  2013. lp->loopback_mode = LOOPBACK_EXT;
  2014. }
  2015. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2016. bnx2x_release_phy_lock(bp);
  2017. bnx2x_init_dropless_fc(bp);
  2018. bnx2x_calc_fc_adv(bp);
  2019. if (bp->link_vars.link_up) {
  2020. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2021. bnx2x_link_report(bp);
  2022. }
  2023. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2024. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2025. return rc;
  2026. }
  2027. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2028. return -EINVAL;
  2029. }
  2030. void bnx2x_link_set(struct bnx2x *bp)
  2031. {
  2032. if (!BP_NOMCP(bp)) {
  2033. bnx2x_acquire_phy_lock(bp);
  2034. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2035. bnx2x_release_phy_lock(bp);
  2036. bnx2x_init_dropless_fc(bp);
  2037. bnx2x_calc_fc_adv(bp);
  2038. } else
  2039. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2040. }
  2041. static void bnx2x__link_reset(struct bnx2x *bp)
  2042. {
  2043. if (!BP_NOMCP(bp)) {
  2044. bnx2x_acquire_phy_lock(bp);
  2045. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2046. bnx2x_release_phy_lock(bp);
  2047. } else
  2048. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2049. }
  2050. void bnx2x_force_link_reset(struct bnx2x *bp)
  2051. {
  2052. bnx2x_acquire_phy_lock(bp);
  2053. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2054. bnx2x_release_phy_lock(bp);
  2055. }
  2056. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2057. {
  2058. u8 rc = 0;
  2059. if (!BP_NOMCP(bp)) {
  2060. bnx2x_acquire_phy_lock(bp);
  2061. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2062. is_serdes);
  2063. bnx2x_release_phy_lock(bp);
  2064. } else
  2065. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2066. return rc;
  2067. }
  2068. /* Calculates the sum of vn_min_rates.
  2069. It's needed for further normalizing of the min_rates.
  2070. Returns:
  2071. sum of vn_min_rates.
  2072. or
  2073. 0 - if all the min_rates are 0.
  2074. In the later case fairness algorithm should be deactivated.
  2075. If not all min_rates are zero then those that are zeroes will be set to 1.
  2076. */
  2077. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2078. struct cmng_init_input *input)
  2079. {
  2080. int all_zero = 1;
  2081. int vn;
  2082. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2083. u32 vn_cfg = bp->mf_config[vn];
  2084. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2085. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2086. /* Skip hidden vns */
  2087. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2088. vn_min_rate = 0;
  2089. /* If min rate is zero - set it to 1 */
  2090. else if (!vn_min_rate)
  2091. vn_min_rate = DEF_MIN_RATE;
  2092. else
  2093. all_zero = 0;
  2094. input->vnic_min_rate[vn] = vn_min_rate;
  2095. }
  2096. /* if ETS or all min rates are zeros - disable fairness */
  2097. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2098. input->flags.cmng_enables &=
  2099. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2100. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2101. } else if (all_zero) {
  2102. input->flags.cmng_enables &=
  2103. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2104. DP(NETIF_MSG_IFUP,
  2105. "All MIN values are zeroes fairness will be disabled\n");
  2106. } else
  2107. input->flags.cmng_enables |=
  2108. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2109. }
  2110. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2111. struct cmng_init_input *input)
  2112. {
  2113. u16 vn_max_rate;
  2114. u32 vn_cfg = bp->mf_config[vn];
  2115. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2116. vn_max_rate = 0;
  2117. else {
  2118. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2119. if (IS_MF_PERCENT_BW(bp)) {
  2120. /* maxCfg in percents of linkspeed */
  2121. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2122. } else /* SD modes */
  2123. /* maxCfg is absolute in 100Mb units */
  2124. vn_max_rate = maxCfg * 100;
  2125. }
  2126. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2127. input->vnic_max_rate[vn] = vn_max_rate;
  2128. }
  2129. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2130. {
  2131. if (CHIP_REV_IS_SLOW(bp))
  2132. return CMNG_FNS_NONE;
  2133. if (IS_MF(bp))
  2134. return CMNG_FNS_MINMAX;
  2135. return CMNG_FNS_NONE;
  2136. }
  2137. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2138. {
  2139. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2140. if (BP_NOMCP(bp))
  2141. return; /* what should be the default value in this case */
  2142. /* For 2 port configuration the absolute function number formula
  2143. * is:
  2144. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2145. *
  2146. * and there are 4 functions per port
  2147. *
  2148. * For 4 port configuration it is
  2149. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2150. *
  2151. * and there are 2 functions per port
  2152. */
  2153. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2154. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2155. if (func >= E1H_FUNC_MAX)
  2156. break;
  2157. bp->mf_config[vn] =
  2158. MF_CFG_RD(bp, func_mf_config[func].config);
  2159. }
  2160. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2161. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2162. bp->flags |= MF_FUNC_DIS;
  2163. } else {
  2164. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2165. bp->flags &= ~MF_FUNC_DIS;
  2166. }
  2167. }
  2168. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2169. {
  2170. struct cmng_init_input input;
  2171. memset(&input, 0, sizeof(struct cmng_init_input));
  2172. input.port_rate = bp->link_vars.line_speed;
  2173. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2174. int vn;
  2175. /* read mf conf from shmem */
  2176. if (read_cfg)
  2177. bnx2x_read_mf_cfg(bp);
  2178. /* vn_weight_sum and enable fairness if not 0 */
  2179. bnx2x_calc_vn_min(bp, &input);
  2180. /* calculate and set min-max rate for each vn */
  2181. if (bp->port.pmf)
  2182. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2183. bnx2x_calc_vn_max(bp, vn, &input);
  2184. /* always enable rate shaping and fairness */
  2185. input.flags.cmng_enables |=
  2186. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2187. bnx2x_init_cmng(&input, &bp->cmng);
  2188. return;
  2189. }
  2190. /* rate shaping and fairness are disabled */
  2191. DP(NETIF_MSG_IFUP,
  2192. "rate shaping and fairness are disabled\n");
  2193. }
  2194. static void storm_memset_cmng(struct bnx2x *bp,
  2195. struct cmng_init *cmng,
  2196. u8 port)
  2197. {
  2198. int vn;
  2199. size_t size = sizeof(struct cmng_struct_per_port);
  2200. u32 addr = BAR_XSTRORM_INTMEM +
  2201. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2202. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2203. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2204. int func = func_by_vn(bp, vn);
  2205. addr = BAR_XSTRORM_INTMEM +
  2206. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2207. size = sizeof(struct rate_shaping_vars_per_vn);
  2208. __storm_memset_struct(bp, addr, size,
  2209. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2210. addr = BAR_XSTRORM_INTMEM +
  2211. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2212. size = sizeof(struct fairness_vars_per_vn);
  2213. __storm_memset_struct(bp, addr, size,
  2214. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2215. }
  2216. }
  2217. /* init cmng mode in HW according to local configuration */
  2218. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2219. {
  2220. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2221. if (cmng_fns != CMNG_FNS_NONE) {
  2222. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2223. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2224. } else {
  2225. /* rate shaping and fairness are disabled */
  2226. DP(NETIF_MSG_IFUP,
  2227. "single function mode without fairness\n");
  2228. }
  2229. }
  2230. /* This function is called upon link interrupt */
  2231. static void bnx2x_link_attn(struct bnx2x *bp)
  2232. {
  2233. /* Make sure that we are synced with the current statistics */
  2234. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2235. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2236. bnx2x_init_dropless_fc(bp);
  2237. if (bp->link_vars.link_up) {
  2238. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2239. struct host_port_stats *pstats;
  2240. pstats = bnx2x_sp(bp, port_stats);
  2241. /* reset old mac stats */
  2242. memset(&(pstats->mac_stx[0]), 0,
  2243. sizeof(struct mac_stx));
  2244. }
  2245. if (bp->state == BNX2X_STATE_OPEN)
  2246. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2247. }
  2248. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2249. bnx2x_set_local_cmng(bp);
  2250. __bnx2x_link_report(bp);
  2251. if (IS_MF(bp))
  2252. bnx2x_link_sync_notify(bp);
  2253. }
  2254. void bnx2x__link_status_update(struct bnx2x *bp)
  2255. {
  2256. if (bp->state != BNX2X_STATE_OPEN)
  2257. return;
  2258. /* read updated dcb configuration */
  2259. if (IS_PF(bp)) {
  2260. bnx2x_dcbx_pmf_update(bp);
  2261. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2262. if (bp->link_vars.link_up)
  2263. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2264. else
  2265. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2266. /* indicate link status */
  2267. bnx2x_link_report(bp);
  2268. } else { /* VF */
  2269. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2270. SUPPORTED_10baseT_Full |
  2271. SUPPORTED_100baseT_Half |
  2272. SUPPORTED_100baseT_Full |
  2273. SUPPORTED_1000baseT_Full |
  2274. SUPPORTED_2500baseX_Full |
  2275. SUPPORTED_10000baseT_Full |
  2276. SUPPORTED_TP |
  2277. SUPPORTED_FIBRE |
  2278. SUPPORTED_Autoneg |
  2279. SUPPORTED_Pause |
  2280. SUPPORTED_Asym_Pause);
  2281. bp->port.advertising[0] = bp->port.supported[0];
  2282. bp->link_params.bp = bp;
  2283. bp->link_params.port = BP_PORT(bp);
  2284. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2285. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2286. bp->link_params.req_line_speed[0] = SPEED_10000;
  2287. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2288. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2289. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2290. bp->link_vars.line_speed = SPEED_10000;
  2291. bp->link_vars.link_status =
  2292. (LINK_STATUS_LINK_UP |
  2293. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2294. bp->link_vars.link_up = 1;
  2295. bp->link_vars.duplex = DUPLEX_FULL;
  2296. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2297. __bnx2x_link_report(bp);
  2298. bnx2x_sample_bulletin(bp);
  2299. /* if bulletin board did not have an update for link status
  2300. * __bnx2x_link_report will report current status
  2301. * but it will NOT duplicate report in case of already reported
  2302. * during sampling bulletin board.
  2303. */
  2304. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2305. }
  2306. }
  2307. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2308. u16 vlan_val, u8 allowed_prio)
  2309. {
  2310. struct bnx2x_func_state_params func_params = {NULL};
  2311. struct bnx2x_func_afex_update_params *f_update_params =
  2312. &func_params.params.afex_update;
  2313. func_params.f_obj = &bp->func_obj;
  2314. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2315. /* no need to wait for RAMROD completion, so don't
  2316. * set RAMROD_COMP_WAIT flag
  2317. */
  2318. f_update_params->vif_id = vifid;
  2319. f_update_params->afex_default_vlan = vlan_val;
  2320. f_update_params->allowed_priorities = allowed_prio;
  2321. /* if ramrod can not be sent, response to MCP immediately */
  2322. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2323. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2324. return 0;
  2325. }
  2326. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2327. u16 vif_index, u8 func_bit_map)
  2328. {
  2329. struct bnx2x_func_state_params func_params = {NULL};
  2330. struct bnx2x_func_afex_viflists_params *update_params =
  2331. &func_params.params.afex_viflists;
  2332. int rc;
  2333. u32 drv_msg_code;
  2334. /* validate only LIST_SET and LIST_GET are received from switch */
  2335. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2336. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2337. cmd_type);
  2338. func_params.f_obj = &bp->func_obj;
  2339. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2340. /* set parameters according to cmd_type */
  2341. update_params->afex_vif_list_command = cmd_type;
  2342. update_params->vif_list_index = vif_index;
  2343. update_params->func_bit_map =
  2344. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2345. update_params->func_to_clear = 0;
  2346. drv_msg_code =
  2347. (cmd_type == VIF_LIST_RULE_GET) ?
  2348. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2349. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2350. /* if ramrod can not be sent, respond to MCP immediately for
  2351. * SET and GET requests (other are not triggered from MCP)
  2352. */
  2353. rc = bnx2x_func_state_change(bp, &func_params);
  2354. if (rc < 0)
  2355. bnx2x_fw_command(bp, drv_msg_code, 0);
  2356. return 0;
  2357. }
  2358. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2359. {
  2360. struct afex_stats afex_stats;
  2361. u32 func = BP_ABS_FUNC(bp);
  2362. u32 mf_config;
  2363. u16 vlan_val;
  2364. u32 vlan_prio;
  2365. u16 vif_id;
  2366. u8 allowed_prio;
  2367. u8 vlan_mode;
  2368. u32 addr_to_write, vifid, addrs, stats_type, i;
  2369. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2370. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2371. DP(BNX2X_MSG_MCP,
  2372. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2373. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2374. }
  2375. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2376. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2377. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2378. DP(BNX2X_MSG_MCP,
  2379. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2380. vifid, addrs);
  2381. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2382. addrs);
  2383. }
  2384. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2385. addr_to_write = SHMEM2_RD(bp,
  2386. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2387. stats_type = SHMEM2_RD(bp,
  2388. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2389. DP(BNX2X_MSG_MCP,
  2390. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2391. addr_to_write);
  2392. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2393. /* write response to scratchpad, for MCP */
  2394. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2395. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2396. *(((u32 *)(&afex_stats))+i));
  2397. /* send ack message to MCP */
  2398. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2399. }
  2400. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2401. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2402. bp->mf_config[BP_VN(bp)] = mf_config;
  2403. DP(BNX2X_MSG_MCP,
  2404. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2405. mf_config);
  2406. /* if VIF_SET is "enabled" */
  2407. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2408. /* set rate limit directly to internal RAM */
  2409. struct cmng_init_input cmng_input;
  2410. struct rate_shaping_vars_per_vn m_rs_vn;
  2411. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2412. u32 addr = BAR_XSTRORM_INTMEM +
  2413. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2414. bp->mf_config[BP_VN(bp)] = mf_config;
  2415. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2416. m_rs_vn.vn_counter.rate =
  2417. cmng_input.vnic_max_rate[BP_VN(bp)];
  2418. m_rs_vn.vn_counter.quota =
  2419. (m_rs_vn.vn_counter.rate *
  2420. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2421. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2422. /* read relevant values from mf_cfg struct in shmem */
  2423. vif_id =
  2424. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2425. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2426. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2427. vlan_val =
  2428. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2429. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2430. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2431. vlan_prio = (mf_config &
  2432. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2433. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2434. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2435. vlan_mode =
  2436. (MF_CFG_RD(bp,
  2437. func_mf_config[func].afex_config) &
  2438. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2439. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2440. allowed_prio =
  2441. (MF_CFG_RD(bp,
  2442. func_mf_config[func].afex_config) &
  2443. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2444. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2445. /* send ramrod to FW, return in case of failure */
  2446. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2447. allowed_prio))
  2448. return;
  2449. bp->afex_def_vlan_tag = vlan_val;
  2450. bp->afex_vlan_mode = vlan_mode;
  2451. } else {
  2452. /* notify link down because BP->flags is disabled */
  2453. bnx2x_link_report(bp);
  2454. /* send INVALID VIF ramrod to FW */
  2455. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2456. /* Reset the default afex VLAN */
  2457. bp->afex_def_vlan_tag = -1;
  2458. }
  2459. }
  2460. }
  2461. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2462. {
  2463. struct bnx2x_func_switch_update_params *switch_update_params;
  2464. struct bnx2x_func_state_params func_params;
  2465. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2466. switch_update_params = &func_params.params.switch_update;
  2467. func_params.f_obj = &bp->func_obj;
  2468. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2469. if (IS_MF_UFP(bp) || IS_MF_BD(bp)) {
  2470. int func = BP_ABS_FUNC(bp);
  2471. u32 val;
  2472. /* Re-learn the S-tag from shmem */
  2473. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2474. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2475. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2476. bp->mf_ov = val;
  2477. } else {
  2478. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2479. goto fail;
  2480. }
  2481. /* Configure new S-tag in LLH */
  2482. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2483. bp->mf_ov);
  2484. /* Send Ramrod to update FW of change */
  2485. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2486. &switch_update_params->changes);
  2487. switch_update_params->vlan = bp->mf_ov;
  2488. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2489. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2490. bp->mf_ov);
  2491. goto fail;
  2492. } else {
  2493. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n",
  2494. bp->mf_ov);
  2495. }
  2496. } else {
  2497. goto fail;
  2498. }
  2499. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2500. return;
  2501. fail:
  2502. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2503. }
  2504. static void bnx2x_pmf_update(struct bnx2x *bp)
  2505. {
  2506. int port = BP_PORT(bp);
  2507. u32 val;
  2508. bp->port.pmf = 1;
  2509. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2510. /*
  2511. * We need the mb() to ensure the ordering between the writing to
  2512. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2513. */
  2514. smp_mb();
  2515. /* queue a periodic task */
  2516. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2517. bnx2x_dcbx_pmf_update(bp);
  2518. /* enable nig attention */
  2519. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2520. if (bp->common.int_block == INT_BLOCK_HC) {
  2521. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2522. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2523. } else if (!CHIP_IS_E1x(bp)) {
  2524. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2525. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2526. }
  2527. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2528. }
  2529. /* end of Link */
  2530. /* slow path */
  2531. /*
  2532. * General service functions
  2533. */
  2534. /* send the MCP a request, block until there is a reply */
  2535. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2536. {
  2537. int mb_idx = BP_FW_MB_IDX(bp);
  2538. u32 seq;
  2539. u32 rc = 0;
  2540. u32 cnt = 1;
  2541. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2542. mutex_lock(&bp->fw_mb_mutex);
  2543. seq = ++bp->fw_seq;
  2544. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2545. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2546. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2547. (command | seq), param);
  2548. do {
  2549. /* let the FW do it's magic ... */
  2550. msleep(delay);
  2551. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2552. /* Give the FW up to 5 second (500*10ms) */
  2553. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2554. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2555. cnt*delay, rc, seq);
  2556. /* is this a reply to our command? */
  2557. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2558. rc &= FW_MSG_CODE_MASK;
  2559. else {
  2560. /* FW BUG! */
  2561. BNX2X_ERR("FW failed to respond!\n");
  2562. bnx2x_fw_dump(bp);
  2563. rc = 0;
  2564. }
  2565. mutex_unlock(&bp->fw_mb_mutex);
  2566. return rc;
  2567. }
  2568. static void storm_memset_func_cfg(struct bnx2x *bp,
  2569. struct tstorm_eth_function_common_config *tcfg,
  2570. u16 abs_fid)
  2571. {
  2572. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2573. u32 addr = BAR_TSTRORM_INTMEM +
  2574. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2575. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2576. }
  2577. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2578. {
  2579. if (CHIP_IS_E1x(bp)) {
  2580. struct tstorm_eth_function_common_config tcfg = {0};
  2581. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2582. }
  2583. /* Enable the function in the FW */
  2584. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2585. storm_memset_func_en(bp, p->func_id, 1);
  2586. /* spq */
  2587. if (p->spq_active) {
  2588. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2589. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2590. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2591. }
  2592. }
  2593. /**
  2594. * bnx2x_get_common_flags - Return common flags
  2595. *
  2596. * @bp device handle
  2597. * @fp queue handle
  2598. * @zero_stats TRUE if statistics zeroing is needed
  2599. *
  2600. * Return the flags that are common for the Tx-only and not normal connections.
  2601. */
  2602. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2603. struct bnx2x_fastpath *fp,
  2604. bool zero_stats)
  2605. {
  2606. unsigned long flags = 0;
  2607. /* PF driver will always initialize the Queue to an ACTIVE state */
  2608. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2609. /* tx only connections collect statistics (on the same index as the
  2610. * parent connection). The statistics are zeroed when the parent
  2611. * connection is initialized.
  2612. */
  2613. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2614. if (zero_stats)
  2615. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2616. if (bp->flags & TX_SWITCHING)
  2617. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2618. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2619. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2620. #ifdef BNX2X_STOP_ON_ERROR
  2621. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2622. #endif
  2623. return flags;
  2624. }
  2625. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2626. struct bnx2x_fastpath *fp,
  2627. bool leading)
  2628. {
  2629. unsigned long flags = 0;
  2630. /* calculate other queue flags */
  2631. if (IS_MF_SD(bp))
  2632. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2633. if (IS_FCOE_FP(fp)) {
  2634. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2635. /* For FCoE - force usage of default priority (for afex) */
  2636. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2637. }
  2638. if (fp->mode != TPA_MODE_DISABLED) {
  2639. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2640. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2641. if (fp->mode == TPA_MODE_GRO)
  2642. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2643. }
  2644. if (leading) {
  2645. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2646. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2647. }
  2648. /* Always set HW VLAN stripping */
  2649. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2650. /* configure silent vlan removal */
  2651. if (IS_MF_AFEX(bp))
  2652. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2653. return flags | bnx2x_get_common_flags(bp, fp, true);
  2654. }
  2655. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2656. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2657. u8 cos)
  2658. {
  2659. gen_init->stat_id = bnx2x_stats_id(fp);
  2660. gen_init->spcl_id = fp->cl_id;
  2661. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2662. if (IS_FCOE_FP(fp))
  2663. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2664. else
  2665. gen_init->mtu = bp->dev->mtu;
  2666. gen_init->cos = cos;
  2667. gen_init->fp_hsi = ETH_FP_HSI_VERSION;
  2668. }
  2669. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2670. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2671. struct bnx2x_rxq_setup_params *rxq_init)
  2672. {
  2673. u8 max_sge = 0;
  2674. u16 sge_sz = 0;
  2675. u16 tpa_agg_size = 0;
  2676. if (fp->mode != TPA_MODE_DISABLED) {
  2677. pause->sge_th_lo = SGE_TH_LO(bp);
  2678. pause->sge_th_hi = SGE_TH_HI(bp);
  2679. /* validate SGE ring has enough to cross high threshold */
  2680. WARN_ON(bp->dropless_fc &&
  2681. pause->sge_th_hi + FW_PREFETCH_CNT >
  2682. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2683. tpa_agg_size = TPA_AGG_SIZE;
  2684. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2685. SGE_PAGE_SHIFT;
  2686. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2687. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2688. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2689. }
  2690. /* pause - not for e1 */
  2691. if (!CHIP_IS_E1(bp)) {
  2692. pause->bd_th_lo = BD_TH_LO(bp);
  2693. pause->bd_th_hi = BD_TH_HI(bp);
  2694. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2695. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2696. /*
  2697. * validate that rings have enough entries to cross
  2698. * high thresholds
  2699. */
  2700. WARN_ON(bp->dropless_fc &&
  2701. pause->bd_th_hi + FW_PREFETCH_CNT >
  2702. bp->rx_ring_size);
  2703. WARN_ON(bp->dropless_fc &&
  2704. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2705. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2706. pause->pri_map = 1;
  2707. }
  2708. /* rxq setup */
  2709. rxq_init->dscr_map = fp->rx_desc_mapping;
  2710. rxq_init->sge_map = fp->rx_sge_mapping;
  2711. rxq_init->rcq_map = fp->rx_comp_mapping;
  2712. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2713. /* This should be a maximum number of data bytes that may be
  2714. * placed on the BD (not including paddings).
  2715. */
  2716. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2717. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2718. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2719. rxq_init->tpa_agg_sz = tpa_agg_size;
  2720. rxq_init->sge_buf_sz = sge_sz;
  2721. rxq_init->max_sges_pkt = max_sge;
  2722. rxq_init->rss_engine_id = BP_FUNC(bp);
  2723. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2724. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2725. *
  2726. * For PF Clients it should be the maximum available number.
  2727. * VF driver(s) may want to define it to a smaller value.
  2728. */
  2729. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2730. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2731. rxq_init->fw_sb_id = fp->fw_sb_id;
  2732. if (IS_FCOE_FP(fp))
  2733. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2734. else
  2735. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2736. /* configure silent vlan removal
  2737. * if multi function mode is afex, then mask default vlan
  2738. */
  2739. if (IS_MF_AFEX(bp)) {
  2740. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2741. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2742. }
  2743. }
  2744. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2745. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2746. u8 cos)
  2747. {
  2748. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2749. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2750. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2751. txq_init->fw_sb_id = fp->fw_sb_id;
  2752. /*
  2753. * set the tss leading client id for TX classification ==
  2754. * leading RSS client id
  2755. */
  2756. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2757. if (IS_FCOE_FP(fp)) {
  2758. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2759. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2760. }
  2761. }
  2762. static void bnx2x_pf_init(struct bnx2x *bp)
  2763. {
  2764. struct bnx2x_func_init_params func_init = {0};
  2765. struct event_ring_data eq_data = { {0} };
  2766. if (!CHIP_IS_E1x(bp)) {
  2767. /* reset IGU PF statistics: MSIX + ATTN */
  2768. /* PF */
  2769. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2770. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2771. (CHIP_MODE_IS_4_PORT(bp) ?
  2772. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2773. /* ATTN */
  2774. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2775. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2776. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2777. (CHIP_MODE_IS_4_PORT(bp) ?
  2778. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2779. }
  2780. func_init.spq_active = true;
  2781. func_init.pf_id = BP_FUNC(bp);
  2782. func_init.func_id = BP_FUNC(bp);
  2783. func_init.spq_map = bp->spq_mapping;
  2784. func_init.spq_prod = bp->spq_prod_idx;
  2785. bnx2x_func_init(bp, &func_init);
  2786. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2787. /*
  2788. * Congestion management values depend on the link rate
  2789. * There is no active link so initial link rate is set to 10 Gbps.
  2790. * When the link comes up The congestion management values are
  2791. * re-calculated according to the actual link rate.
  2792. */
  2793. bp->link_vars.line_speed = SPEED_10000;
  2794. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2795. /* Only the PMF sets the HW */
  2796. if (bp->port.pmf)
  2797. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2798. /* init Event Queue - PCI bus guarantees correct endianity*/
  2799. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2800. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2801. eq_data.producer = bp->eq_prod;
  2802. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2803. eq_data.sb_id = DEF_SB_ID;
  2804. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2805. }
  2806. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2807. {
  2808. int port = BP_PORT(bp);
  2809. bnx2x_tx_disable(bp);
  2810. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2811. }
  2812. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2813. {
  2814. int port = BP_PORT(bp);
  2815. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2816. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2817. /* Tx queue should be only re-enabled */
  2818. netif_tx_wake_all_queues(bp->dev);
  2819. /*
  2820. * Should not call netif_carrier_on since it will be called if the link
  2821. * is up when checking for link state
  2822. */
  2823. }
  2824. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2825. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2826. {
  2827. struct eth_stats_info *ether_stat =
  2828. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2829. struct bnx2x_vlan_mac_obj *mac_obj =
  2830. &bp->sp_objs->mac_obj;
  2831. int i;
  2832. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2833. ETH_STAT_INFO_VERSION_LEN);
  2834. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2835. * mac_local field in ether_stat struct. The base address is offset by 2
  2836. * bytes to account for the field being 8 bytes but a mac address is
  2837. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2838. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2839. * allocated by the ether_stat struct, so the macs will land in their
  2840. * proper positions.
  2841. */
  2842. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2843. memset(ether_stat->mac_local + i, 0,
  2844. sizeof(ether_stat->mac_local[0]));
  2845. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2846. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2847. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2848. ETH_ALEN);
  2849. ether_stat->mtu_size = bp->dev->mtu;
  2850. if (bp->dev->features & NETIF_F_RXCSUM)
  2851. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2852. if (bp->dev->features & NETIF_F_TSO)
  2853. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2854. ether_stat->feature_flags |= bp->common.boot_mode;
  2855. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2856. ether_stat->txq_size = bp->tx_ring_size;
  2857. ether_stat->rxq_size = bp->rx_ring_size;
  2858. #ifdef CONFIG_BNX2X_SRIOV
  2859. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2860. #endif
  2861. }
  2862. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2863. {
  2864. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2865. struct fcoe_stats_info *fcoe_stat =
  2866. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2867. if (!CNIC_LOADED(bp))
  2868. return;
  2869. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2870. fcoe_stat->qos_priority =
  2871. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2872. /* insert FCoE stats from ramrod response */
  2873. if (!NO_FCOE(bp)) {
  2874. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2875. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2876. tstorm_queue_statistics;
  2877. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2878. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2879. xstorm_queue_statistics;
  2880. struct fcoe_statistics_params *fw_fcoe_stat =
  2881. &bp->fw_stats_data->fcoe;
  2882. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2883. fcoe_stat->rx_bytes_lo,
  2884. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2885. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2886. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2887. fcoe_stat->rx_bytes_lo,
  2888. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2889. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2890. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2891. fcoe_stat->rx_bytes_lo,
  2892. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2893. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2894. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2895. fcoe_stat->rx_bytes_lo,
  2896. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2897. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2898. fcoe_stat->rx_frames_lo,
  2899. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2900. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2901. fcoe_stat->rx_frames_lo,
  2902. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2903. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2904. fcoe_stat->rx_frames_lo,
  2905. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2906. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2907. fcoe_stat->rx_frames_lo,
  2908. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2909. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2910. fcoe_stat->tx_bytes_lo,
  2911. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2912. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2913. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2914. fcoe_stat->tx_bytes_lo,
  2915. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2916. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2917. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2918. fcoe_stat->tx_bytes_lo,
  2919. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2920. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2921. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2922. fcoe_stat->tx_bytes_lo,
  2923. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2924. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2925. fcoe_stat->tx_frames_lo,
  2926. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2927. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2928. fcoe_stat->tx_frames_lo,
  2929. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2930. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2931. fcoe_stat->tx_frames_lo,
  2932. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2933. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2934. fcoe_stat->tx_frames_lo,
  2935. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2936. }
  2937. /* ask L5 driver to add data to the struct */
  2938. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2939. }
  2940. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2941. {
  2942. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2943. struct iscsi_stats_info *iscsi_stat =
  2944. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2945. if (!CNIC_LOADED(bp))
  2946. return;
  2947. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2948. ETH_ALEN);
  2949. iscsi_stat->qos_priority =
  2950. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2951. /* ask L5 driver to add data to the struct */
  2952. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2953. }
  2954. /* called due to MCP event (on pmf):
  2955. * reread new bandwidth configuration
  2956. * configure FW
  2957. * notify others function about the change
  2958. */
  2959. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2960. {
  2961. if (bp->link_vars.link_up) {
  2962. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2963. bnx2x_link_sync_notify(bp);
  2964. }
  2965. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2966. }
  2967. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2968. {
  2969. bnx2x_config_mf_bw(bp);
  2970. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2971. }
  2972. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2973. {
  2974. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2975. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2976. }
  2977. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2978. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2979. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2980. {
  2981. enum drv_info_opcode op_code;
  2982. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2983. bool release = false;
  2984. int wait;
  2985. /* if drv_info version supported by MFW doesn't match - send NACK */
  2986. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2987. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2988. return;
  2989. }
  2990. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2991. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2992. /* Must prevent other flows from accessing drv_info_to_mcp */
  2993. mutex_lock(&bp->drv_info_mutex);
  2994. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2995. sizeof(union drv_info_to_mcp));
  2996. switch (op_code) {
  2997. case ETH_STATS_OPCODE:
  2998. bnx2x_drv_info_ether_stat(bp);
  2999. break;
  3000. case FCOE_STATS_OPCODE:
  3001. bnx2x_drv_info_fcoe_stat(bp);
  3002. break;
  3003. case ISCSI_STATS_OPCODE:
  3004. bnx2x_drv_info_iscsi_stat(bp);
  3005. break;
  3006. default:
  3007. /* if op code isn't supported - send NACK */
  3008. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3009. goto out;
  3010. }
  3011. /* if we got drv_info attn from MFW then these fields are defined in
  3012. * shmem2 for sure
  3013. */
  3014. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3015. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3016. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3017. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3018. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3019. /* Since possible management wants both this and get_driver_version
  3020. * need to wait until management notifies us it finished utilizing
  3021. * the buffer.
  3022. */
  3023. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3024. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3025. } else if (!bp->drv_info_mng_owner) {
  3026. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3027. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3028. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3029. /* Management is done; need to clear indication */
  3030. if (indication & bit) {
  3031. SHMEM2_WR(bp, mfw_drv_indication,
  3032. indication & ~bit);
  3033. release = true;
  3034. break;
  3035. }
  3036. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3037. }
  3038. }
  3039. if (!release) {
  3040. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3041. bp->drv_info_mng_owner = true;
  3042. }
  3043. out:
  3044. mutex_unlock(&bp->drv_info_mutex);
  3045. }
  3046. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3047. {
  3048. u8 vals[4];
  3049. int i = 0;
  3050. if (bnx2x_format) {
  3051. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3052. &vals[0], &vals[1], &vals[2], &vals[3]);
  3053. if (i > 0)
  3054. vals[0] -= '0';
  3055. } else {
  3056. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3057. &vals[0], &vals[1], &vals[2], &vals[3]);
  3058. }
  3059. while (i < 4)
  3060. vals[i++] = 0;
  3061. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3062. }
  3063. void bnx2x_update_mng_version(struct bnx2x *bp)
  3064. {
  3065. u32 iscsiver = DRV_VER_NOT_LOADED;
  3066. u32 fcoever = DRV_VER_NOT_LOADED;
  3067. u32 ethver = DRV_VER_NOT_LOADED;
  3068. int idx = BP_FW_MB_IDX(bp);
  3069. u8 *version;
  3070. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3071. return;
  3072. mutex_lock(&bp->drv_info_mutex);
  3073. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3074. if (bp->drv_info_mng_owner)
  3075. goto out;
  3076. if (bp->state != BNX2X_STATE_OPEN)
  3077. goto out;
  3078. /* Parse ethernet driver version */
  3079. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3080. if (!CNIC_LOADED(bp))
  3081. goto out;
  3082. /* Try getting storage driver version via cnic */
  3083. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3084. sizeof(union drv_info_to_mcp));
  3085. bnx2x_drv_info_iscsi_stat(bp);
  3086. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3087. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3088. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3089. sizeof(union drv_info_to_mcp));
  3090. bnx2x_drv_info_fcoe_stat(bp);
  3091. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3092. fcoever = bnx2x_update_mng_version_utility(version, false);
  3093. out:
  3094. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3095. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3096. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3097. mutex_unlock(&bp->drv_info_mutex);
  3098. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3099. ethver, iscsiver, fcoever);
  3100. }
  3101. void bnx2x_update_mfw_dump(struct bnx2x *bp)
  3102. {
  3103. u32 drv_ver;
  3104. u32 valid_dump;
  3105. if (!SHMEM2_HAS(bp, drv_info))
  3106. return;
  3107. /* Update Driver load time, possibly broken in y2038 */
  3108. SHMEM2_WR(bp, drv_info.epoc, (u32)ktime_get_real_seconds());
  3109. drv_ver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3110. SHMEM2_WR(bp, drv_info.drv_ver, drv_ver);
  3111. SHMEM2_WR(bp, drv_info.fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  3112. /* Check & notify On-Chip dump. */
  3113. valid_dump = SHMEM2_RD(bp, drv_info.valid_dump);
  3114. if (valid_dump & FIRST_DUMP_VALID)
  3115. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 1st partition\n");
  3116. if (valid_dump & SECOND_DUMP_VALID)
  3117. DP(NETIF_MSG_IFUP, "A valid On-Chip MFW dump found on 2nd partition\n");
  3118. }
  3119. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3120. {
  3121. u32 cmd_ok, cmd_fail;
  3122. /* sanity */
  3123. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3124. event & DRV_STATUS_OEM_EVENT_MASK) {
  3125. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3126. return;
  3127. }
  3128. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3129. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3130. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3131. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3132. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3133. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3134. }
  3135. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3136. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3137. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3138. /* This is the only place besides the function initialization
  3139. * where the bp->flags can change so it is done without any
  3140. * locks
  3141. */
  3142. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3143. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3144. bp->flags |= MF_FUNC_DIS;
  3145. bnx2x_e1h_disable(bp);
  3146. } else {
  3147. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3148. bp->flags &= ~MF_FUNC_DIS;
  3149. bnx2x_e1h_enable(bp);
  3150. }
  3151. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3152. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3153. }
  3154. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3155. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3156. bnx2x_config_mf_bw(bp);
  3157. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3158. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3159. }
  3160. /* Report results to MCP */
  3161. if (event)
  3162. bnx2x_fw_command(bp, cmd_fail, 0);
  3163. else
  3164. bnx2x_fw_command(bp, cmd_ok, 0);
  3165. }
  3166. /* must be called under the spq lock */
  3167. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3168. {
  3169. struct eth_spe *next_spe = bp->spq_prod_bd;
  3170. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3171. bp->spq_prod_bd = bp->spq;
  3172. bp->spq_prod_idx = 0;
  3173. DP(BNX2X_MSG_SP, "end of spq\n");
  3174. } else {
  3175. bp->spq_prod_bd++;
  3176. bp->spq_prod_idx++;
  3177. }
  3178. return next_spe;
  3179. }
  3180. /* must be called under the spq lock */
  3181. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3182. {
  3183. int func = BP_FUNC(bp);
  3184. /*
  3185. * Make sure that BD data is updated before writing the producer:
  3186. * BD data is written to the memory, the producer is read from the
  3187. * memory, thus we need a full memory barrier to ensure the ordering.
  3188. */
  3189. mb();
  3190. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3191. bp->spq_prod_idx);
  3192. mmiowb();
  3193. }
  3194. /**
  3195. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3196. *
  3197. * @cmd: command to check
  3198. * @cmd_type: command type
  3199. */
  3200. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3201. {
  3202. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3203. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3204. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3205. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3206. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3207. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3208. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3209. return true;
  3210. else
  3211. return false;
  3212. }
  3213. /**
  3214. * bnx2x_sp_post - place a single command on an SP ring
  3215. *
  3216. * @bp: driver handle
  3217. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3218. * @cid: SW CID the command is related to
  3219. * @data_hi: command private data address (high 32 bits)
  3220. * @data_lo: command private data address (low 32 bits)
  3221. * @cmd_type: command type (e.g. NONE, ETH)
  3222. *
  3223. * SP data is handled as if it's always an address pair, thus data fields are
  3224. * not swapped to little endian in upper functions. Instead this function swaps
  3225. * data as if it's two u32 fields.
  3226. */
  3227. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3228. u32 data_hi, u32 data_lo, int cmd_type)
  3229. {
  3230. struct eth_spe *spe;
  3231. u16 type;
  3232. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3233. #ifdef BNX2X_STOP_ON_ERROR
  3234. if (unlikely(bp->panic)) {
  3235. BNX2X_ERR("Can't post SP when there is panic\n");
  3236. return -EIO;
  3237. }
  3238. #endif
  3239. spin_lock_bh(&bp->spq_lock);
  3240. if (common) {
  3241. if (!atomic_read(&bp->eq_spq_left)) {
  3242. BNX2X_ERR("BUG! EQ ring full!\n");
  3243. spin_unlock_bh(&bp->spq_lock);
  3244. bnx2x_panic();
  3245. return -EBUSY;
  3246. }
  3247. } else if (!atomic_read(&bp->cq_spq_left)) {
  3248. BNX2X_ERR("BUG! SPQ ring full!\n");
  3249. spin_unlock_bh(&bp->spq_lock);
  3250. bnx2x_panic();
  3251. return -EBUSY;
  3252. }
  3253. spe = bnx2x_sp_get_next(bp);
  3254. /* CID needs port number to be encoded int it */
  3255. spe->hdr.conn_and_cmd_data =
  3256. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3257. HW_CID(bp, cid));
  3258. /* In some cases, type may already contain the func-id
  3259. * mainly in SRIOV related use cases, so we add it here only
  3260. * if it's not already set.
  3261. */
  3262. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3263. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3264. SPE_HDR_CONN_TYPE;
  3265. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3266. SPE_HDR_FUNCTION_ID);
  3267. } else {
  3268. type = cmd_type;
  3269. }
  3270. spe->hdr.type = cpu_to_le16(type);
  3271. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3272. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3273. /*
  3274. * It's ok if the actual decrement is issued towards the memory
  3275. * somewhere between the spin_lock and spin_unlock. Thus no
  3276. * more explicit memory barrier is needed.
  3277. */
  3278. if (common)
  3279. atomic_dec(&bp->eq_spq_left);
  3280. else
  3281. atomic_dec(&bp->cq_spq_left);
  3282. DP(BNX2X_MSG_SP,
  3283. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3284. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3285. (u32)(U64_LO(bp->spq_mapping) +
  3286. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3287. HW_CID(bp, cid), data_hi, data_lo, type,
  3288. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3289. bnx2x_sp_prod_update(bp);
  3290. spin_unlock_bh(&bp->spq_lock);
  3291. return 0;
  3292. }
  3293. /* acquire split MCP access lock register */
  3294. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3295. {
  3296. u32 j, val;
  3297. int rc = 0;
  3298. might_sleep();
  3299. for (j = 0; j < 1000; j++) {
  3300. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3301. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3302. if (val & MCPR_ACCESS_LOCK_LOCK)
  3303. break;
  3304. usleep_range(5000, 10000);
  3305. }
  3306. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3307. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3308. rc = -EBUSY;
  3309. }
  3310. return rc;
  3311. }
  3312. /* release split MCP access lock register */
  3313. static void bnx2x_release_alr(struct bnx2x *bp)
  3314. {
  3315. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3316. }
  3317. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3318. #define BNX2X_DEF_SB_IDX 0x0002
  3319. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3320. {
  3321. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3322. u16 rc = 0;
  3323. barrier(); /* status block is written to by the chip */
  3324. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3325. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3326. rc |= BNX2X_DEF_SB_ATT_IDX;
  3327. }
  3328. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3329. bp->def_idx = def_sb->sp_sb.running_index;
  3330. rc |= BNX2X_DEF_SB_IDX;
  3331. }
  3332. /* Do not reorder: indices reading should complete before handling */
  3333. barrier();
  3334. return rc;
  3335. }
  3336. /*
  3337. * slow path service functions
  3338. */
  3339. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3340. {
  3341. int port = BP_PORT(bp);
  3342. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3343. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3344. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3345. NIG_REG_MASK_INTERRUPT_PORT0;
  3346. u32 aeu_mask;
  3347. u32 nig_mask = 0;
  3348. u32 reg_addr;
  3349. if (bp->attn_state & asserted)
  3350. BNX2X_ERR("IGU ERROR\n");
  3351. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3352. aeu_mask = REG_RD(bp, aeu_addr);
  3353. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3354. aeu_mask, asserted);
  3355. aeu_mask &= ~(asserted & 0x3ff);
  3356. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3357. REG_WR(bp, aeu_addr, aeu_mask);
  3358. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3359. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3360. bp->attn_state |= asserted;
  3361. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3362. if (asserted & ATTN_HARD_WIRED_MASK) {
  3363. if (asserted & ATTN_NIG_FOR_FUNC) {
  3364. bnx2x_acquire_phy_lock(bp);
  3365. /* save nig interrupt mask */
  3366. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3367. /* If nig_mask is not set, no need to call the update
  3368. * function.
  3369. */
  3370. if (nig_mask) {
  3371. REG_WR(bp, nig_int_mask_addr, 0);
  3372. bnx2x_link_attn(bp);
  3373. }
  3374. /* handle unicore attn? */
  3375. }
  3376. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3377. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3378. if (asserted & GPIO_2_FUNC)
  3379. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3380. if (asserted & GPIO_3_FUNC)
  3381. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3382. if (asserted & GPIO_4_FUNC)
  3383. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3384. if (port == 0) {
  3385. if (asserted & ATTN_GENERAL_ATTN_1) {
  3386. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3387. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3388. }
  3389. if (asserted & ATTN_GENERAL_ATTN_2) {
  3390. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3391. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3392. }
  3393. if (asserted & ATTN_GENERAL_ATTN_3) {
  3394. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3395. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3396. }
  3397. } else {
  3398. if (asserted & ATTN_GENERAL_ATTN_4) {
  3399. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3400. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3401. }
  3402. if (asserted & ATTN_GENERAL_ATTN_5) {
  3403. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3404. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3405. }
  3406. if (asserted & ATTN_GENERAL_ATTN_6) {
  3407. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3408. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3409. }
  3410. }
  3411. } /* if hardwired */
  3412. if (bp->common.int_block == INT_BLOCK_HC)
  3413. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3414. COMMAND_REG_ATTN_BITS_SET);
  3415. else
  3416. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3417. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3418. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3419. REG_WR(bp, reg_addr, asserted);
  3420. /* now set back the mask */
  3421. if (asserted & ATTN_NIG_FOR_FUNC) {
  3422. /* Verify that IGU ack through BAR was written before restoring
  3423. * NIG mask. This loop should exit after 2-3 iterations max.
  3424. */
  3425. if (bp->common.int_block != INT_BLOCK_HC) {
  3426. u32 cnt = 0, igu_acked;
  3427. do {
  3428. igu_acked = REG_RD(bp,
  3429. IGU_REG_ATTENTION_ACK_BITS);
  3430. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3431. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3432. if (!igu_acked)
  3433. DP(NETIF_MSG_HW,
  3434. "Failed to verify IGU ack on time\n");
  3435. barrier();
  3436. }
  3437. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3438. bnx2x_release_phy_lock(bp);
  3439. }
  3440. }
  3441. static void bnx2x_fan_failure(struct bnx2x *bp)
  3442. {
  3443. int port = BP_PORT(bp);
  3444. u32 ext_phy_config;
  3445. /* mark the failure */
  3446. ext_phy_config =
  3447. SHMEM_RD(bp,
  3448. dev_info.port_hw_config[port].external_phy_config);
  3449. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3450. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3451. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3452. ext_phy_config);
  3453. /* log the failure */
  3454. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3455. "Please contact OEM Support for assistance\n");
  3456. /* Schedule device reset (unload)
  3457. * This is due to some boards consuming sufficient power when driver is
  3458. * up to overheat if fan fails.
  3459. */
  3460. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3461. }
  3462. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3463. {
  3464. int port = BP_PORT(bp);
  3465. int reg_offset;
  3466. u32 val;
  3467. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3468. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3469. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3470. val = REG_RD(bp, reg_offset);
  3471. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3472. REG_WR(bp, reg_offset, val);
  3473. BNX2X_ERR("SPIO5 hw attention\n");
  3474. /* Fan failure attention */
  3475. bnx2x_hw_reset_phy(&bp->link_params);
  3476. bnx2x_fan_failure(bp);
  3477. }
  3478. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3479. bnx2x_acquire_phy_lock(bp);
  3480. bnx2x_handle_module_detect_int(&bp->link_params);
  3481. bnx2x_release_phy_lock(bp);
  3482. }
  3483. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3484. val = REG_RD(bp, reg_offset);
  3485. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3486. REG_WR(bp, reg_offset, val);
  3487. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3488. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3489. bnx2x_panic();
  3490. }
  3491. }
  3492. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3493. {
  3494. u32 val;
  3495. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3496. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3497. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3498. /* DORQ discard attention */
  3499. if (val & 0x2)
  3500. BNX2X_ERR("FATAL error from DORQ\n");
  3501. }
  3502. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3503. int port = BP_PORT(bp);
  3504. int reg_offset;
  3505. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3506. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3507. val = REG_RD(bp, reg_offset);
  3508. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3509. REG_WR(bp, reg_offset, val);
  3510. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3511. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3512. bnx2x_panic();
  3513. }
  3514. }
  3515. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3516. {
  3517. u32 val;
  3518. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3519. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3520. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3521. /* CFC error attention */
  3522. if (val & 0x2)
  3523. BNX2X_ERR("FATAL error from CFC\n");
  3524. }
  3525. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3526. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3527. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3528. /* RQ_USDMDP_FIFO_OVERFLOW */
  3529. if (val & 0x18000)
  3530. BNX2X_ERR("FATAL error from PXP\n");
  3531. if (!CHIP_IS_E1x(bp)) {
  3532. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3533. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3534. }
  3535. }
  3536. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3537. int port = BP_PORT(bp);
  3538. int reg_offset;
  3539. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3540. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3541. val = REG_RD(bp, reg_offset);
  3542. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3543. REG_WR(bp, reg_offset, val);
  3544. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3545. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3546. bnx2x_panic();
  3547. }
  3548. }
  3549. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3550. {
  3551. u32 val;
  3552. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3553. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3554. int func = BP_FUNC(bp);
  3555. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3556. bnx2x_read_mf_cfg(bp);
  3557. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3558. func_mf_config[BP_ABS_FUNC(bp)].config);
  3559. val = SHMEM_RD(bp,
  3560. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3561. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3562. DRV_STATUS_OEM_EVENT_MASK))
  3563. bnx2x_oem_event(bp,
  3564. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3565. DRV_STATUS_OEM_EVENT_MASK)));
  3566. if (val & DRV_STATUS_SET_MF_BW)
  3567. bnx2x_set_mf_bw(bp);
  3568. if (val & DRV_STATUS_DRV_INFO_REQ)
  3569. bnx2x_handle_drv_info_req(bp);
  3570. if (val & DRV_STATUS_VF_DISABLED)
  3571. bnx2x_schedule_iov_task(bp,
  3572. BNX2X_IOV_HANDLE_FLR);
  3573. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3574. bnx2x_pmf_update(bp);
  3575. if (bp->port.pmf &&
  3576. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3577. bp->dcbx_enabled > 0)
  3578. /* start dcbx state machine */
  3579. bnx2x_dcbx_set_params(bp,
  3580. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3581. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3582. bnx2x_handle_afex_cmd(bp,
  3583. val & DRV_STATUS_AFEX_EVENT_MASK);
  3584. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3585. bnx2x_handle_eee_event(bp);
  3586. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3587. bnx2x_handle_update_svid_cmd(bp);
  3588. if (bp->link_vars.periodic_flags &
  3589. PERIODIC_FLAGS_LINK_EVENT) {
  3590. /* sync with link */
  3591. bnx2x_acquire_phy_lock(bp);
  3592. bp->link_vars.periodic_flags &=
  3593. ~PERIODIC_FLAGS_LINK_EVENT;
  3594. bnx2x_release_phy_lock(bp);
  3595. if (IS_MF(bp))
  3596. bnx2x_link_sync_notify(bp);
  3597. bnx2x_link_report(bp);
  3598. }
  3599. /* Always call it here: bnx2x_link_report() will
  3600. * prevent the link indication duplication.
  3601. */
  3602. bnx2x__link_status_update(bp);
  3603. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3604. BNX2X_ERR("MC assert!\n");
  3605. bnx2x_mc_assert(bp);
  3606. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3607. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3608. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3609. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3610. bnx2x_panic();
  3611. } else if (attn & BNX2X_MCP_ASSERT) {
  3612. BNX2X_ERR("MCP assert!\n");
  3613. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3614. bnx2x_fw_dump(bp);
  3615. } else
  3616. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3617. }
  3618. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3619. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3620. if (attn & BNX2X_GRC_TIMEOUT) {
  3621. val = CHIP_IS_E1(bp) ? 0 :
  3622. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3623. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3624. }
  3625. if (attn & BNX2X_GRC_RSV) {
  3626. val = CHIP_IS_E1(bp) ? 0 :
  3627. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3628. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3629. }
  3630. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3631. }
  3632. }
  3633. /*
  3634. * Bits map:
  3635. * 0-7 - Engine0 load counter.
  3636. * 8-15 - Engine1 load counter.
  3637. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3638. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3639. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3640. * on the engine
  3641. * 19 - Engine1 ONE_IS_LOADED.
  3642. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3643. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3644. * just the one belonging to its engine).
  3645. *
  3646. */
  3647. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3648. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3649. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3650. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3651. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3652. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3653. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3654. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3655. /*
  3656. * Set the GLOBAL_RESET bit.
  3657. *
  3658. * Should be run under rtnl lock
  3659. */
  3660. void bnx2x_set_reset_global(struct bnx2x *bp)
  3661. {
  3662. u32 val;
  3663. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3664. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3665. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3666. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3667. }
  3668. /*
  3669. * Clear the GLOBAL_RESET bit.
  3670. *
  3671. * Should be run under rtnl lock
  3672. */
  3673. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3674. {
  3675. u32 val;
  3676. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3677. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3678. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3679. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3680. }
  3681. /*
  3682. * Checks the GLOBAL_RESET bit.
  3683. *
  3684. * should be run under rtnl lock
  3685. */
  3686. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3687. {
  3688. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3689. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3690. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3691. }
  3692. /*
  3693. * Clear RESET_IN_PROGRESS bit for the current engine.
  3694. *
  3695. * Should be run under rtnl lock
  3696. */
  3697. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3698. {
  3699. u32 val;
  3700. u32 bit = BP_PATH(bp) ?
  3701. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3702. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3703. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3704. /* Clear the bit */
  3705. val &= ~bit;
  3706. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3707. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3708. }
  3709. /*
  3710. * Set RESET_IN_PROGRESS for the current engine.
  3711. *
  3712. * should be run under rtnl lock
  3713. */
  3714. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3715. {
  3716. u32 val;
  3717. u32 bit = BP_PATH(bp) ?
  3718. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3719. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3720. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3721. /* Set the bit */
  3722. val |= bit;
  3723. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3724. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3725. }
  3726. /*
  3727. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3728. * should be run under rtnl lock
  3729. */
  3730. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3731. {
  3732. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3733. u32 bit = engine ?
  3734. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3735. /* return false if bit is set */
  3736. return (val & bit) ? false : true;
  3737. }
  3738. /*
  3739. * set pf load for the current pf.
  3740. *
  3741. * should be run under rtnl lock
  3742. */
  3743. void bnx2x_set_pf_load(struct bnx2x *bp)
  3744. {
  3745. u32 val1, val;
  3746. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3747. BNX2X_PATH0_LOAD_CNT_MASK;
  3748. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3749. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3750. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3751. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3752. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3753. /* get the current counter value */
  3754. val1 = (val & mask) >> shift;
  3755. /* set bit of that PF */
  3756. val1 |= (1 << bp->pf_num);
  3757. /* clear the old value */
  3758. val &= ~mask;
  3759. /* set the new one */
  3760. val |= ((val1 << shift) & mask);
  3761. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3762. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3763. }
  3764. /**
  3765. * bnx2x_clear_pf_load - clear pf load mark
  3766. *
  3767. * @bp: driver handle
  3768. *
  3769. * Should be run under rtnl lock.
  3770. * Decrements the load counter for the current engine. Returns
  3771. * whether other functions are still loaded
  3772. */
  3773. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3774. {
  3775. u32 val1, val;
  3776. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3777. BNX2X_PATH0_LOAD_CNT_MASK;
  3778. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3779. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3780. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3781. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3782. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3783. /* get the current counter value */
  3784. val1 = (val & mask) >> shift;
  3785. /* clear bit of that PF */
  3786. val1 &= ~(1 << bp->pf_num);
  3787. /* clear the old value */
  3788. val &= ~mask;
  3789. /* set the new one */
  3790. val |= ((val1 << shift) & mask);
  3791. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3792. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3793. return val1 != 0;
  3794. }
  3795. /*
  3796. * Read the load status for the current engine.
  3797. *
  3798. * should be run under rtnl lock
  3799. */
  3800. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3801. {
  3802. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3803. BNX2X_PATH0_LOAD_CNT_MASK);
  3804. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3805. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3806. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3807. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3808. val = (val & mask) >> shift;
  3809. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3810. engine, val);
  3811. return val != 0;
  3812. }
  3813. static void _print_parity(struct bnx2x *bp, u32 reg)
  3814. {
  3815. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3816. }
  3817. static void _print_next_block(int idx, const char *blk)
  3818. {
  3819. pr_cont("%s%s", idx ? ", " : "", blk);
  3820. }
  3821. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3822. int *par_num, bool print)
  3823. {
  3824. u32 cur_bit;
  3825. bool res;
  3826. int i;
  3827. res = false;
  3828. for (i = 0; sig; i++) {
  3829. cur_bit = (0x1UL << i);
  3830. if (sig & cur_bit) {
  3831. res |= true; /* Each bit is real error! */
  3832. if (print) {
  3833. switch (cur_bit) {
  3834. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3835. _print_next_block((*par_num)++, "BRB");
  3836. _print_parity(bp,
  3837. BRB1_REG_BRB1_PRTY_STS);
  3838. break;
  3839. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3840. _print_next_block((*par_num)++,
  3841. "PARSER");
  3842. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3843. break;
  3844. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3845. _print_next_block((*par_num)++, "TSDM");
  3846. _print_parity(bp,
  3847. TSDM_REG_TSDM_PRTY_STS);
  3848. break;
  3849. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3850. _print_next_block((*par_num)++,
  3851. "SEARCHER");
  3852. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3853. break;
  3854. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3855. _print_next_block((*par_num)++, "TCM");
  3856. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3857. break;
  3858. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3859. _print_next_block((*par_num)++,
  3860. "TSEMI");
  3861. _print_parity(bp,
  3862. TSEM_REG_TSEM_PRTY_STS_0);
  3863. _print_parity(bp,
  3864. TSEM_REG_TSEM_PRTY_STS_1);
  3865. break;
  3866. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3867. _print_next_block((*par_num)++, "XPB");
  3868. _print_parity(bp, GRCBASE_XPB +
  3869. PB_REG_PB_PRTY_STS);
  3870. break;
  3871. }
  3872. }
  3873. /* Clear the bit */
  3874. sig &= ~cur_bit;
  3875. }
  3876. }
  3877. return res;
  3878. }
  3879. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3880. int *par_num, bool *global,
  3881. bool print)
  3882. {
  3883. u32 cur_bit;
  3884. bool res;
  3885. int i;
  3886. res = false;
  3887. for (i = 0; sig; i++) {
  3888. cur_bit = (0x1UL << i);
  3889. if (sig & cur_bit) {
  3890. res |= true; /* Each bit is real error! */
  3891. switch (cur_bit) {
  3892. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3893. if (print) {
  3894. _print_next_block((*par_num)++, "PBF");
  3895. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3896. }
  3897. break;
  3898. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3899. if (print) {
  3900. _print_next_block((*par_num)++, "QM");
  3901. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3902. }
  3903. break;
  3904. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3905. if (print) {
  3906. _print_next_block((*par_num)++, "TM");
  3907. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3908. }
  3909. break;
  3910. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3911. if (print) {
  3912. _print_next_block((*par_num)++, "XSDM");
  3913. _print_parity(bp,
  3914. XSDM_REG_XSDM_PRTY_STS);
  3915. }
  3916. break;
  3917. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3918. if (print) {
  3919. _print_next_block((*par_num)++, "XCM");
  3920. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3921. }
  3922. break;
  3923. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3924. if (print) {
  3925. _print_next_block((*par_num)++,
  3926. "XSEMI");
  3927. _print_parity(bp,
  3928. XSEM_REG_XSEM_PRTY_STS_0);
  3929. _print_parity(bp,
  3930. XSEM_REG_XSEM_PRTY_STS_1);
  3931. }
  3932. break;
  3933. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3934. if (print) {
  3935. _print_next_block((*par_num)++,
  3936. "DOORBELLQ");
  3937. _print_parity(bp,
  3938. DORQ_REG_DORQ_PRTY_STS);
  3939. }
  3940. break;
  3941. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3942. if (print) {
  3943. _print_next_block((*par_num)++, "NIG");
  3944. if (CHIP_IS_E1x(bp)) {
  3945. _print_parity(bp,
  3946. NIG_REG_NIG_PRTY_STS);
  3947. } else {
  3948. _print_parity(bp,
  3949. NIG_REG_NIG_PRTY_STS_0);
  3950. _print_parity(bp,
  3951. NIG_REG_NIG_PRTY_STS_1);
  3952. }
  3953. }
  3954. break;
  3955. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3956. if (print)
  3957. _print_next_block((*par_num)++,
  3958. "VAUX PCI CORE");
  3959. *global = true;
  3960. break;
  3961. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3962. if (print) {
  3963. _print_next_block((*par_num)++,
  3964. "DEBUG");
  3965. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3966. }
  3967. break;
  3968. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3969. if (print) {
  3970. _print_next_block((*par_num)++, "USDM");
  3971. _print_parity(bp,
  3972. USDM_REG_USDM_PRTY_STS);
  3973. }
  3974. break;
  3975. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3976. if (print) {
  3977. _print_next_block((*par_num)++, "UCM");
  3978. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3979. }
  3980. break;
  3981. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3982. if (print) {
  3983. _print_next_block((*par_num)++,
  3984. "USEMI");
  3985. _print_parity(bp,
  3986. USEM_REG_USEM_PRTY_STS_0);
  3987. _print_parity(bp,
  3988. USEM_REG_USEM_PRTY_STS_1);
  3989. }
  3990. break;
  3991. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3992. if (print) {
  3993. _print_next_block((*par_num)++, "UPB");
  3994. _print_parity(bp, GRCBASE_UPB +
  3995. PB_REG_PB_PRTY_STS);
  3996. }
  3997. break;
  3998. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3999. if (print) {
  4000. _print_next_block((*par_num)++, "CSDM");
  4001. _print_parity(bp,
  4002. CSDM_REG_CSDM_PRTY_STS);
  4003. }
  4004. break;
  4005. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  4006. if (print) {
  4007. _print_next_block((*par_num)++, "CCM");
  4008. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  4009. }
  4010. break;
  4011. }
  4012. /* Clear the bit */
  4013. sig &= ~cur_bit;
  4014. }
  4015. }
  4016. return res;
  4017. }
  4018. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  4019. int *par_num, bool print)
  4020. {
  4021. u32 cur_bit;
  4022. bool res;
  4023. int i;
  4024. res = false;
  4025. for (i = 0; sig; i++) {
  4026. cur_bit = (0x1UL << i);
  4027. if (sig & cur_bit) {
  4028. res = true; /* Each bit is real error! */
  4029. if (print) {
  4030. switch (cur_bit) {
  4031. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4032. _print_next_block((*par_num)++,
  4033. "CSEMI");
  4034. _print_parity(bp,
  4035. CSEM_REG_CSEM_PRTY_STS_0);
  4036. _print_parity(bp,
  4037. CSEM_REG_CSEM_PRTY_STS_1);
  4038. break;
  4039. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4040. _print_next_block((*par_num)++, "PXP");
  4041. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4042. _print_parity(bp,
  4043. PXP2_REG_PXP2_PRTY_STS_0);
  4044. _print_parity(bp,
  4045. PXP2_REG_PXP2_PRTY_STS_1);
  4046. break;
  4047. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4048. _print_next_block((*par_num)++,
  4049. "PXPPCICLOCKCLIENT");
  4050. break;
  4051. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4052. _print_next_block((*par_num)++, "CFC");
  4053. _print_parity(bp,
  4054. CFC_REG_CFC_PRTY_STS);
  4055. break;
  4056. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4057. _print_next_block((*par_num)++, "CDU");
  4058. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4059. break;
  4060. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4061. _print_next_block((*par_num)++, "DMAE");
  4062. _print_parity(bp,
  4063. DMAE_REG_DMAE_PRTY_STS);
  4064. break;
  4065. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4066. _print_next_block((*par_num)++, "IGU");
  4067. if (CHIP_IS_E1x(bp))
  4068. _print_parity(bp,
  4069. HC_REG_HC_PRTY_STS);
  4070. else
  4071. _print_parity(bp,
  4072. IGU_REG_IGU_PRTY_STS);
  4073. break;
  4074. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4075. _print_next_block((*par_num)++, "MISC");
  4076. _print_parity(bp,
  4077. MISC_REG_MISC_PRTY_STS);
  4078. break;
  4079. }
  4080. }
  4081. /* Clear the bit */
  4082. sig &= ~cur_bit;
  4083. }
  4084. }
  4085. return res;
  4086. }
  4087. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4088. int *par_num, bool *global,
  4089. bool print)
  4090. {
  4091. bool res = false;
  4092. u32 cur_bit;
  4093. int i;
  4094. for (i = 0; sig; i++) {
  4095. cur_bit = (0x1UL << i);
  4096. if (sig & cur_bit) {
  4097. switch (cur_bit) {
  4098. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4099. if (print)
  4100. _print_next_block((*par_num)++,
  4101. "MCP ROM");
  4102. *global = true;
  4103. res = true;
  4104. break;
  4105. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4106. if (print)
  4107. _print_next_block((*par_num)++,
  4108. "MCP UMP RX");
  4109. *global = true;
  4110. res = true;
  4111. break;
  4112. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4113. if (print)
  4114. _print_next_block((*par_num)++,
  4115. "MCP UMP TX");
  4116. *global = true;
  4117. res = true;
  4118. break;
  4119. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4120. (*par_num)++;
  4121. /* clear latched SCPAD PATIRY from MCP */
  4122. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4123. 1UL << 10);
  4124. break;
  4125. }
  4126. /* Clear the bit */
  4127. sig &= ~cur_bit;
  4128. }
  4129. }
  4130. return res;
  4131. }
  4132. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4133. int *par_num, bool print)
  4134. {
  4135. u32 cur_bit;
  4136. bool res;
  4137. int i;
  4138. res = false;
  4139. for (i = 0; sig; i++) {
  4140. cur_bit = (0x1UL << i);
  4141. if (sig & cur_bit) {
  4142. res = true; /* Each bit is real error! */
  4143. if (print) {
  4144. switch (cur_bit) {
  4145. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4146. _print_next_block((*par_num)++,
  4147. "PGLUE_B");
  4148. _print_parity(bp,
  4149. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4150. break;
  4151. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4152. _print_next_block((*par_num)++, "ATC");
  4153. _print_parity(bp,
  4154. ATC_REG_ATC_PRTY_STS);
  4155. break;
  4156. }
  4157. }
  4158. /* Clear the bit */
  4159. sig &= ~cur_bit;
  4160. }
  4161. }
  4162. return res;
  4163. }
  4164. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4165. u32 *sig)
  4166. {
  4167. bool res = false;
  4168. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4169. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4170. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4171. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4172. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4173. int par_num = 0;
  4174. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4175. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4176. sig[0] & HW_PRTY_ASSERT_SET_0,
  4177. sig[1] & HW_PRTY_ASSERT_SET_1,
  4178. sig[2] & HW_PRTY_ASSERT_SET_2,
  4179. sig[3] & HW_PRTY_ASSERT_SET_3,
  4180. sig[4] & HW_PRTY_ASSERT_SET_4);
  4181. if (print) {
  4182. if (((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4183. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4184. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4185. (sig[4] & HW_PRTY_ASSERT_SET_4)) ||
  4186. (sig[3] & HW_PRTY_ASSERT_SET_3_WITHOUT_SCPAD)) {
  4187. netdev_err(bp->dev,
  4188. "Parity errors detected in blocks: ");
  4189. } else {
  4190. print = false;
  4191. }
  4192. }
  4193. res |= bnx2x_check_blocks_with_parity0(bp,
  4194. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4195. res |= bnx2x_check_blocks_with_parity1(bp,
  4196. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4197. res |= bnx2x_check_blocks_with_parity2(bp,
  4198. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4199. res |= bnx2x_check_blocks_with_parity3(bp,
  4200. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4201. res |= bnx2x_check_blocks_with_parity4(bp,
  4202. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4203. if (print)
  4204. pr_cont("\n");
  4205. }
  4206. return res;
  4207. }
  4208. /**
  4209. * bnx2x_chk_parity_attn - checks for parity attentions.
  4210. *
  4211. * @bp: driver handle
  4212. * @global: true if there was a global attention
  4213. * @print: show parity attention in syslog
  4214. */
  4215. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4216. {
  4217. struct attn_route attn = { {0} };
  4218. int port = BP_PORT(bp);
  4219. attn.sig[0] = REG_RD(bp,
  4220. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4221. port*4);
  4222. attn.sig[1] = REG_RD(bp,
  4223. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4224. port*4);
  4225. attn.sig[2] = REG_RD(bp,
  4226. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4227. port*4);
  4228. attn.sig[3] = REG_RD(bp,
  4229. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4230. port*4);
  4231. /* Since MCP attentions can't be disabled inside the block, we need to
  4232. * read AEU registers to see whether they're currently disabled
  4233. */
  4234. attn.sig[3] &= ((REG_RD(bp,
  4235. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4236. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4237. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4238. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4239. if (!CHIP_IS_E1x(bp))
  4240. attn.sig[4] = REG_RD(bp,
  4241. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4242. port*4);
  4243. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4244. }
  4245. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4246. {
  4247. u32 val;
  4248. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4249. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4250. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4251. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4252. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4253. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4254. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4255. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4256. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4257. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4258. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4259. if (val &
  4260. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4261. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4262. if (val &
  4263. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4264. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4265. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4266. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4267. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4268. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4269. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4270. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4271. }
  4272. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4273. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4274. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4275. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4276. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4277. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4278. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4279. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4280. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4281. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4282. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4283. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4284. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4285. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4286. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4287. }
  4288. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4289. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4290. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4291. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4292. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4293. }
  4294. }
  4295. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4296. {
  4297. struct attn_route attn, *group_mask;
  4298. int port = BP_PORT(bp);
  4299. int index;
  4300. u32 reg_addr;
  4301. u32 val;
  4302. u32 aeu_mask;
  4303. bool global = false;
  4304. /* need to take HW lock because MCP or other port might also
  4305. try to handle this event */
  4306. bnx2x_acquire_alr(bp);
  4307. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4308. #ifndef BNX2X_STOP_ON_ERROR
  4309. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4310. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4311. /* Disable HW interrupts */
  4312. bnx2x_int_disable(bp);
  4313. /* In case of parity errors don't handle attentions so that
  4314. * other function would "see" parity errors.
  4315. */
  4316. #else
  4317. bnx2x_panic();
  4318. #endif
  4319. bnx2x_release_alr(bp);
  4320. return;
  4321. }
  4322. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4323. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4324. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4325. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4326. if (!CHIP_IS_E1x(bp))
  4327. attn.sig[4] =
  4328. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4329. else
  4330. attn.sig[4] = 0;
  4331. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4332. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4333. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4334. if (deasserted & (1 << index)) {
  4335. group_mask = &bp->attn_group[index];
  4336. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4337. index,
  4338. group_mask->sig[0], group_mask->sig[1],
  4339. group_mask->sig[2], group_mask->sig[3],
  4340. group_mask->sig[4]);
  4341. bnx2x_attn_int_deasserted4(bp,
  4342. attn.sig[4] & group_mask->sig[4]);
  4343. bnx2x_attn_int_deasserted3(bp,
  4344. attn.sig[3] & group_mask->sig[3]);
  4345. bnx2x_attn_int_deasserted1(bp,
  4346. attn.sig[1] & group_mask->sig[1]);
  4347. bnx2x_attn_int_deasserted2(bp,
  4348. attn.sig[2] & group_mask->sig[2]);
  4349. bnx2x_attn_int_deasserted0(bp,
  4350. attn.sig[0] & group_mask->sig[0]);
  4351. }
  4352. }
  4353. bnx2x_release_alr(bp);
  4354. if (bp->common.int_block == INT_BLOCK_HC)
  4355. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4356. COMMAND_REG_ATTN_BITS_CLR);
  4357. else
  4358. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4359. val = ~deasserted;
  4360. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4361. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4362. REG_WR(bp, reg_addr, val);
  4363. if (~bp->attn_state & deasserted)
  4364. BNX2X_ERR("IGU ERROR\n");
  4365. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4366. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4367. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4368. aeu_mask = REG_RD(bp, reg_addr);
  4369. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4370. aeu_mask, deasserted);
  4371. aeu_mask |= (deasserted & 0x3ff);
  4372. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4373. REG_WR(bp, reg_addr, aeu_mask);
  4374. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4375. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4376. bp->attn_state &= ~deasserted;
  4377. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4378. }
  4379. static void bnx2x_attn_int(struct bnx2x *bp)
  4380. {
  4381. /* read local copy of bits */
  4382. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4383. attn_bits);
  4384. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4385. attn_bits_ack);
  4386. u32 attn_state = bp->attn_state;
  4387. /* look for changed bits */
  4388. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4389. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4390. DP(NETIF_MSG_HW,
  4391. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4392. attn_bits, attn_ack, asserted, deasserted);
  4393. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4394. BNX2X_ERR("BAD attention state\n");
  4395. /* handle bits that were raised */
  4396. if (asserted)
  4397. bnx2x_attn_int_asserted(bp, asserted);
  4398. if (deasserted)
  4399. bnx2x_attn_int_deasserted(bp, deasserted);
  4400. }
  4401. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4402. u16 index, u8 op, u8 update)
  4403. {
  4404. u32 igu_addr = bp->igu_base_addr;
  4405. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4406. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4407. igu_addr);
  4408. }
  4409. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4410. {
  4411. /* No memory barriers */
  4412. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4413. mmiowb(); /* keep prod updates ordered */
  4414. }
  4415. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4416. union event_ring_elem *elem)
  4417. {
  4418. u8 err = elem->message.error;
  4419. if (!bp->cnic_eth_dev.starting_cid ||
  4420. (cid < bp->cnic_eth_dev.starting_cid &&
  4421. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4422. return 1;
  4423. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4424. if (unlikely(err)) {
  4425. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4426. cid);
  4427. bnx2x_panic_dump(bp, false);
  4428. }
  4429. bnx2x_cnic_cfc_comp(bp, cid, err);
  4430. return 0;
  4431. }
  4432. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4433. {
  4434. struct bnx2x_mcast_ramrod_params rparam;
  4435. int rc;
  4436. memset(&rparam, 0, sizeof(rparam));
  4437. rparam.mcast_obj = &bp->mcast_obj;
  4438. netif_addr_lock_bh(bp->dev);
  4439. /* Clear pending state for the last command */
  4440. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4441. /* If there are pending mcast commands - send them */
  4442. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4443. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4444. if (rc < 0)
  4445. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4446. rc);
  4447. }
  4448. netif_addr_unlock_bh(bp->dev);
  4449. }
  4450. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4451. union event_ring_elem *elem)
  4452. {
  4453. unsigned long ramrod_flags = 0;
  4454. int rc = 0;
  4455. u32 echo = le32_to_cpu(elem->message.data.eth_event.echo);
  4456. u32 cid = echo & BNX2X_SWCID_MASK;
  4457. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4458. /* Always push next commands out, don't wait here */
  4459. __set_bit(RAMROD_CONT, &ramrod_flags);
  4460. switch (echo >> BNX2X_SWCID_SHIFT) {
  4461. case BNX2X_FILTER_MAC_PENDING:
  4462. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4463. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4464. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4465. else
  4466. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4467. break;
  4468. case BNX2X_FILTER_VLAN_PENDING:
  4469. DP(BNX2X_MSG_SP, "Got SETUP_VLAN completions\n");
  4470. vlan_mac_obj = &bp->sp_objs[cid].vlan_obj;
  4471. break;
  4472. case BNX2X_FILTER_MCAST_PENDING:
  4473. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4474. /* This is only relevant for 57710 where multicast MACs are
  4475. * configured as unicast MACs using the same ramrod.
  4476. */
  4477. bnx2x_handle_mcast_eqe(bp);
  4478. return;
  4479. default:
  4480. BNX2X_ERR("Unsupported classification command: 0x%x\n", echo);
  4481. return;
  4482. }
  4483. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4484. if (rc < 0)
  4485. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4486. else if (rc > 0)
  4487. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4488. }
  4489. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4490. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4491. {
  4492. netif_addr_lock_bh(bp->dev);
  4493. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4494. /* Send rx_mode command again if was requested */
  4495. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4496. bnx2x_set_storm_rx_mode(bp);
  4497. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4498. &bp->sp_state))
  4499. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4500. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4501. &bp->sp_state))
  4502. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4503. netif_addr_unlock_bh(bp->dev);
  4504. }
  4505. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4506. union event_ring_elem *elem)
  4507. {
  4508. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4509. DP(BNX2X_MSG_SP,
  4510. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4511. elem->message.data.vif_list_event.func_bit_map);
  4512. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4513. elem->message.data.vif_list_event.func_bit_map);
  4514. } else if (elem->message.data.vif_list_event.echo ==
  4515. VIF_LIST_RULE_SET) {
  4516. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4517. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4518. }
  4519. }
  4520. /* called with rtnl_lock */
  4521. static void bnx2x_after_function_update(struct bnx2x *bp)
  4522. {
  4523. int q, rc;
  4524. struct bnx2x_fastpath *fp;
  4525. struct bnx2x_queue_state_params queue_params = {NULL};
  4526. struct bnx2x_queue_update_params *q_update_params =
  4527. &queue_params.params.update;
  4528. /* Send Q update command with afex vlan removal values for all Qs */
  4529. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4530. /* set silent vlan removal values according to vlan mode */
  4531. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4532. &q_update_params->update_flags);
  4533. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4534. &q_update_params->update_flags);
  4535. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4536. /* in access mode mark mask and value are 0 to strip all vlans */
  4537. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4538. q_update_params->silent_removal_value = 0;
  4539. q_update_params->silent_removal_mask = 0;
  4540. } else {
  4541. q_update_params->silent_removal_value =
  4542. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4543. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4544. }
  4545. for_each_eth_queue(bp, q) {
  4546. /* Set the appropriate Queue object */
  4547. fp = &bp->fp[q];
  4548. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4549. /* send the ramrod */
  4550. rc = bnx2x_queue_state_change(bp, &queue_params);
  4551. if (rc < 0)
  4552. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4553. q);
  4554. }
  4555. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4556. fp = &bp->fp[FCOE_IDX(bp)];
  4557. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4558. /* clear pending completion bit */
  4559. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4560. /* mark latest Q bit */
  4561. smp_mb__before_atomic();
  4562. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4563. smp_mb__after_atomic();
  4564. /* send Q update ramrod for FCoE Q */
  4565. rc = bnx2x_queue_state_change(bp, &queue_params);
  4566. if (rc < 0)
  4567. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4568. q);
  4569. } else {
  4570. /* If no FCoE ring - ACK MCP now */
  4571. bnx2x_link_report(bp);
  4572. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4573. }
  4574. }
  4575. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4576. struct bnx2x *bp, u32 cid)
  4577. {
  4578. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4579. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4580. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4581. else
  4582. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4583. }
  4584. static void bnx2x_eq_int(struct bnx2x *bp)
  4585. {
  4586. u16 hw_cons, sw_cons, sw_prod;
  4587. union event_ring_elem *elem;
  4588. u8 echo;
  4589. u32 cid;
  4590. u8 opcode;
  4591. int rc, spqe_cnt = 0;
  4592. struct bnx2x_queue_sp_obj *q_obj;
  4593. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4594. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4595. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4596. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4597. * when we get the next-page we need to adjust so the loop
  4598. * condition below will be met. The next element is the size of a
  4599. * regular element and hence incrementing by 1
  4600. */
  4601. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4602. hw_cons++;
  4603. /* This function may never run in parallel with itself for a
  4604. * specific bp, thus there is no need in "paired" read memory
  4605. * barrier here.
  4606. */
  4607. sw_cons = bp->eq_cons;
  4608. sw_prod = bp->eq_prod;
  4609. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4610. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4611. for (; sw_cons != hw_cons;
  4612. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4613. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4614. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4615. if (!rc) {
  4616. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4617. rc);
  4618. goto next_spqe;
  4619. }
  4620. opcode = elem->message.opcode;
  4621. /* handle eq element */
  4622. switch (opcode) {
  4623. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4624. bnx2x_vf_mbx_schedule(bp,
  4625. &elem->message.data.vf_pf_event);
  4626. continue;
  4627. case EVENT_RING_OPCODE_STAT_QUERY:
  4628. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4629. "got statistics comp event %d\n",
  4630. bp->stats_comp++);
  4631. /* nothing to do with stats comp */
  4632. goto next_spqe;
  4633. case EVENT_RING_OPCODE_CFC_DEL:
  4634. /* handle according to cid range */
  4635. /*
  4636. * we may want to verify here that the bp state is
  4637. * HALTING
  4638. */
  4639. /* elem CID originates from FW; actually LE */
  4640. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4641. DP(BNX2X_MSG_SP,
  4642. "got delete ramrod for MULTI[%d]\n", cid);
  4643. if (CNIC_LOADED(bp) &&
  4644. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4645. goto next_spqe;
  4646. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4647. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4648. break;
  4649. goto next_spqe;
  4650. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4651. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4652. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4653. if (f_obj->complete_cmd(bp, f_obj,
  4654. BNX2X_F_CMD_TX_STOP))
  4655. break;
  4656. goto next_spqe;
  4657. case EVENT_RING_OPCODE_START_TRAFFIC:
  4658. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4659. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4660. if (f_obj->complete_cmd(bp, f_obj,
  4661. BNX2X_F_CMD_TX_START))
  4662. break;
  4663. goto next_spqe;
  4664. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4665. echo = elem->message.data.function_update_event.echo;
  4666. if (echo == SWITCH_UPDATE) {
  4667. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4668. "got FUNC_SWITCH_UPDATE ramrod\n");
  4669. if (f_obj->complete_cmd(
  4670. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4671. break;
  4672. } else {
  4673. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4674. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4675. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4676. f_obj->complete_cmd(bp, f_obj,
  4677. BNX2X_F_CMD_AFEX_UPDATE);
  4678. /* We will perform the Queues update from
  4679. * sp_rtnl task as all Queue SP operations
  4680. * should run under rtnl_lock.
  4681. */
  4682. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4683. }
  4684. goto next_spqe;
  4685. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4686. f_obj->complete_cmd(bp, f_obj,
  4687. BNX2X_F_CMD_AFEX_VIFLISTS);
  4688. bnx2x_after_afex_vif_lists(bp, elem);
  4689. goto next_spqe;
  4690. case EVENT_RING_OPCODE_FUNCTION_START:
  4691. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4692. "got FUNC_START ramrod\n");
  4693. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4694. break;
  4695. goto next_spqe;
  4696. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4697. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4698. "got FUNC_STOP ramrod\n");
  4699. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4700. break;
  4701. goto next_spqe;
  4702. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4703. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4704. "got set_timesync ramrod completion\n");
  4705. if (f_obj->complete_cmd(bp, f_obj,
  4706. BNX2X_F_CMD_SET_TIMESYNC))
  4707. break;
  4708. goto next_spqe;
  4709. }
  4710. switch (opcode | bp->state) {
  4711. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4712. BNX2X_STATE_OPEN):
  4713. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4714. BNX2X_STATE_OPENING_WAIT4_PORT):
  4715. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4716. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4717. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4718. SW_CID(elem->message.data.eth_event.echo));
  4719. rss_raw->clear_pending(rss_raw);
  4720. break;
  4721. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4722. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4723. case (EVENT_RING_OPCODE_SET_MAC |
  4724. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4725. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4726. BNX2X_STATE_OPEN):
  4727. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4728. BNX2X_STATE_DIAG):
  4729. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4730. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4731. DP(BNX2X_MSG_SP, "got (un)set vlan/mac ramrod\n");
  4732. bnx2x_handle_classification_eqe(bp, elem);
  4733. break;
  4734. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4735. BNX2X_STATE_OPEN):
  4736. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4737. BNX2X_STATE_DIAG):
  4738. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4739. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4740. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4741. bnx2x_handle_mcast_eqe(bp);
  4742. break;
  4743. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4744. BNX2X_STATE_OPEN):
  4745. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4746. BNX2X_STATE_DIAG):
  4747. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4748. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4749. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4750. bnx2x_handle_rx_mode_eqe(bp);
  4751. break;
  4752. default:
  4753. /* unknown event log error and continue */
  4754. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4755. elem->message.opcode, bp->state);
  4756. }
  4757. next_spqe:
  4758. spqe_cnt++;
  4759. } /* for */
  4760. smp_mb__before_atomic();
  4761. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4762. bp->eq_cons = sw_cons;
  4763. bp->eq_prod = sw_prod;
  4764. /* Make sure that above mem writes were issued towards the memory */
  4765. smp_wmb();
  4766. /* update producer */
  4767. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4768. }
  4769. static void bnx2x_sp_task(struct work_struct *work)
  4770. {
  4771. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4772. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4773. /* make sure the atomic interrupt_occurred has been written */
  4774. smp_rmb();
  4775. if (atomic_read(&bp->interrupt_occurred)) {
  4776. /* what work needs to be performed? */
  4777. u16 status = bnx2x_update_dsb_idx(bp);
  4778. DP(BNX2X_MSG_SP, "status %x\n", status);
  4779. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4780. atomic_set(&bp->interrupt_occurred, 0);
  4781. /* HW attentions */
  4782. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4783. bnx2x_attn_int(bp);
  4784. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4785. }
  4786. /* SP events: STAT_QUERY and others */
  4787. if (status & BNX2X_DEF_SB_IDX) {
  4788. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4789. if (FCOE_INIT(bp) &&
  4790. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4791. /* Prevent local bottom-halves from running as
  4792. * we are going to change the local NAPI list.
  4793. */
  4794. local_bh_disable();
  4795. napi_schedule(&bnx2x_fcoe(bp, napi));
  4796. local_bh_enable();
  4797. }
  4798. /* Handle EQ completions */
  4799. bnx2x_eq_int(bp);
  4800. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4801. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4802. status &= ~BNX2X_DEF_SB_IDX;
  4803. }
  4804. /* if status is non zero then perhaps something went wrong */
  4805. if (unlikely(status))
  4806. DP(BNX2X_MSG_SP,
  4807. "got an unknown interrupt! (status 0x%x)\n", status);
  4808. /* ack status block only if something was actually handled */
  4809. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4810. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4811. }
  4812. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4813. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4814. &bp->sp_state)) {
  4815. bnx2x_link_report(bp);
  4816. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4817. }
  4818. }
  4819. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4820. {
  4821. struct net_device *dev = dev_instance;
  4822. struct bnx2x *bp = netdev_priv(dev);
  4823. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4824. IGU_INT_DISABLE, 0);
  4825. #ifdef BNX2X_STOP_ON_ERROR
  4826. if (unlikely(bp->panic))
  4827. return IRQ_HANDLED;
  4828. #endif
  4829. if (CNIC_LOADED(bp)) {
  4830. struct cnic_ops *c_ops;
  4831. rcu_read_lock();
  4832. c_ops = rcu_dereference(bp->cnic_ops);
  4833. if (c_ops)
  4834. c_ops->cnic_handler(bp->cnic_data, NULL);
  4835. rcu_read_unlock();
  4836. }
  4837. /* schedule sp task to perform default status block work, ack
  4838. * attentions and enable interrupts.
  4839. */
  4840. bnx2x_schedule_sp_task(bp);
  4841. return IRQ_HANDLED;
  4842. }
  4843. /* end of slow path */
  4844. void bnx2x_drv_pulse(struct bnx2x *bp)
  4845. {
  4846. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4847. bp->fw_drv_pulse_wr_seq);
  4848. }
  4849. static void bnx2x_timer(unsigned long data)
  4850. {
  4851. struct bnx2x *bp = (struct bnx2x *) data;
  4852. if (!netif_running(bp->dev))
  4853. return;
  4854. if (IS_PF(bp) &&
  4855. !BP_NOMCP(bp)) {
  4856. int mb_idx = BP_FW_MB_IDX(bp);
  4857. u16 drv_pulse;
  4858. u16 mcp_pulse;
  4859. ++bp->fw_drv_pulse_wr_seq;
  4860. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4861. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4862. bnx2x_drv_pulse(bp);
  4863. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4864. MCP_PULSE_SEQ_MASK);
  4865. /* The delta between driver pulse and mcp response
  4866. * should not get too big. If the MFW is more than 5 pulses
  4867. * behind, we should worry about it enough to generate an error
  4868. * log.
  4869. */
  4870. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4871. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4872. drv_pulse, mcp_pulse);
  4873. }
  4874. if (bp->state == BNX2X_STATE_OPEN)
  4875. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4876. /* sample pf vf bulletin board for new posts from pf */
  4877. if (IS_VF(bp))
  4878. bnx2x_timer_sriov(bp);
  4879. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4880. }
  4881. /* end of Statistics */
  4882. /* nic init */
  4883. /*
  4884. * nic init service functions
  4885. */
  4886. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4887. {
  4888. u32 i;
  4889. if (!(len%4) && !(addr%4))
  4890. for (i = 0; i < len; i += 4)
  4891. REG_WR(bp, addr + i, fill);
  4892. else
  4893. for (i = 0; i < len; i++)
  4894. REG_WR8(bp, addr + i, fill);
  4895. }
  4896. /* helper: writes FP SP data to FW - data_size in dwords */
  4897. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4898. int fw_sb_id,
  4899. u32 *sb_data_p,
  4900. u32 data_size)
  4901. {
  4902. int index;
  4903. for (index = 0; index < data_size; index++)
  4904. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4905. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4906. sizeof(u32)*index,
  4907. *(sb_data_p + index));
  4908. }
  4909. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4910. {
  4911. u32 *sb_data_p;
  4912. u32 data_size = 0;
  4913. struct hc_status_block_data_e2 sb_data_e2;
  4914. struct hc_status_block_data_e1x sb_data_e1x;
  4915. /* disable the function first */
  4916. if (!CHIP_IS_E1x(bp)) {
  4917. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4918. sb_data_e2.common.state = SB_DISABLED;
  4919. sb_data_e2.common.p_func.vf_valid = false;
  4920. sb_data_p = (u32 *)&sb_data_e2;
  4921. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4922. } else {
  4923. memset(&sb_data_e1x, 0,
  4924. sizeof(struct hc_status_block_data_e1x));
  4925. sb_data_e1x.common.state = SB_DISABLED;
  4926. sb_data_e1x.common.p_func.vf_valid = false;
  4927. sb_data_p = (u32 *)&sb_data_e1x;
  4928. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4929. }
  4930. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4931. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4932. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4933. CSTORM_STATUS_BLOCK_SIZE);
  4934. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4935. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4936. CSTORM_SYNC_BLOCK_SIZE);
  4937. }
  4938. /* helper: writes SP SB data to FW */
  4939. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4940. struct hc_sp_status_block_data *sp_sb_data)
  4941. {
  4942. int func = BP_FUNC(bp);
  4943. int i;
  4944. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4945. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4946. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4947. i*sizeof(u32),
  4948. *((u32 *)sp_sb_data + i));
  4949. }
  4950. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4951. {
  4952. int func = BP_FUNC(bp);
  4953. struct hc_sp_status_block_data sp_sb_data;
  4954. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4955. sp_sb_data.state = SB_DISABLED;
  4956. sp_sb_data.p_func.vf_valid = false;
  4957. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4958. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4959. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4960. CSTORM_SP_STATUS_BLOCK_SIZE);
  4961. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4962. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4963. CSTORM_SP_SYNC_BLOCK_SIZE);
  4964. }
  4965. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4966. int igu_sb_id, int igu_seg_id)
  4967. {
  4968. hc_sm->igu_sb_id = igu_sb_id;
  4969. hc_sm->igu_seg_id = igu_seg_id;
  4970. hc_sm->timer_value = 0xFF;
  4971. hc_sm->time_to_expire = 0xFFFFFFFF;
  4972. }
  4973. /* allocates state machine ids. */
  4974. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4975. {
  4976. /* zero out state machine indices */
  4977. /* rx indices */
  4978. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4979. /* tx indices */
  4980. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4981. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4982. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4983. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4984. /* map indices */
  4985. /* rx indices */
  4986. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4987. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4988. /* tx indices */
  4989. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4990. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4991. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4992. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4993. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4994. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4995. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4996. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4997. }
  4998. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4999. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  5000. {
  5001. int igu_seg_id;
  5002. struct hc_status_block_data_e2 sb_data_e2;
  5003. struct hc_status_block_data_e1x sb_data_e1x;
  5004. struct hc_status_block_sm *hc_sm_p;
  5005. int data_size;
  5006. u32 *sb_data_p;
  5007. if (CHIP_INT_MODE_IS_BC(bp))
  5008. igu_seg_id = HC_SEG_ACCESS_NORM;
  5009. else
  5010. igu_seg_id = IGU_SEG_ACCESS_NORM;
  5011. bnx2x_zero_fp_sb(bp, fw_sb_id);
  5012. if (!CHIP_IS_E1x(bp)) {
  5013. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  5014. sb_data_e2.common.state = SB_ENABLED;
  5015. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  5016. sb_data_e2.common.p_func.vf_id = vfid;
  5017. sb_data_e2.common.p_func.vf_valid = vf_valid;
  5018. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  5019. sb_data_e2.common.same_igu_sb_1b = true;
  5020. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  5021. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  5022. hc_sm_p = sb_data_e2.common.state_machine;
  5023. sb_data_p = (u32 *)&sb_data_e2;
  5024. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  5025. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  5026. } else {
  5027. memset(&sb_data_e1x, 0,
  5028. sizeof(struct hc_status_block_data_e1x));
  5029. sb_data_e1x.common.state = SB_ENABLED;
  5030. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5031. sb_data_e1x.common.p_func.vf_id = 0xff;
  5032. sb_data_e1x.common.p_func.vf_valid = false;
  5033. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5034. sb_data_e1x.common.same_igu_sb_1b = true;
  5035. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5036. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5037. hc_sm_p = sb_data_e1x.common.state_machine;
  5038. sb_data_p = (u32 *)&sb_data_e1x;
  5039. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5040. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5041. }
  5042. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5043. igu_sb_id, igu_seg_id);
  5044. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5045. igu_sb_id, igu_seg_id);
  5046. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5047. /* write indices to HW - PCI guarantees endianity of regpairs */
  5048. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5049. }
  5050. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5051. u16 tx_usec, u16 rx_usec)
  5052. {
  5053. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5054. false, rx_usec);
  5055. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5056. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5057. tx_usec);
  5058. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5059. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5060. tx_usec);
  5061. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5062. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5063. tx_usec);
  5064. }
  5065. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5066. {
  5067. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5068. dma_addr_t mapping = bp->def_status_blk_mapping;
  5069. int igu_sp_sb_index;
  5070. int igu_seg_id;
  5071. int port = BP_PORT(bp);
  5072. int func = BP_FUNC(bp);
  5073. int reg_offset, reg_offset_en5;
  5074. u64 section;
  5075. int index;
  5076. struct hc_sp_status_block_data sp_sb_data;
  5077. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5078. if (CHIP_INT_MODE_IS_BC(bp)) {
  5079. igu_sp_sb_index = DEF_SB_IGU_ID;
  5080. igu_seg_id = HC_SEG_ACCESS_DEF;
  5081. } else {
  5082. igu_sp_sb_index = bp->igu_dsb_id;
  5083. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5084. }
  5085. /* ATTN */
  5086. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5087. atten_status_block);
  5088. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5089. bp->attn_state = 0;
  5090. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5091. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5092. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5093. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5094. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5095. int sindex;
  5096. /* take care of sig[0]..sig[4] */
  5097. for (sindex = 0; sindex < 4; sindex++)
  5098. bp->attn_group[index].sig[sindex] =
  5099. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5100. if (!CHIP_IS_E1x(bp))
  5101. /*
  5102. * enable5 is separate from the rest of the registers,
  5103. * and therefore the address skip is 4
  5104. * and not 16 between the different groups
  5105. */
  5106. bp->attn_group[index].sig[4] = REG_RD(bp,
  5107. reg_offset_en5 + 0x4*index);
  5108. else
  5109. bp->attn_group[index].sig[4] = 0;
  5110. }
  5111. if (bp->common.int_block == INT_BLOCK_HC) {
  5112. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5113. HC_REG_ATTN_MSG0_ADDR_L);
  5114. REG_WR(bp, reg_offset, U64_LO(section));
  5115. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5116. } else if (!CHIP_IS_E1x(bp)) {
  5117. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5118. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5119. }
  5120. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5121. sp_sb);
  5122. bnx2x_zero_sp_sb(bp);
  5123. /* PCI guarantees endianity of regpairs */
  5124. sp_sb_data.state = SB_ENABLED;
  5125. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5126. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5127. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5128. sp_sb_data.igu_seg_id = igu_seg_id;
  5129. sp_sb_data.p_func.pf_id = func;
  5130. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5131. sp_sb_data.p_func.vf_id = 0xff;
  5132. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5133. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5134. }
  5135. void bnx2x_update_coalesce(struct bnx2x *bp)
  5136. {
  5137. int i;
  5138. for_each_eth_queue(bp, i)
  5139. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5140. bp->tx_ticks, bp->rx_ticks);
  5141. }
  5142. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5143. {
  5144. spin_lock_init(&bp->spq_lock);
  5145. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5146. bp->spq_prod_idx = 0;
  5147. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5148. bp->spq_prod_bd = bp->spq;
  5149. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5150. }
  5151. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5152. {
  5153. int i;
  5154. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5155. union event_ring_elem *elem =
  5156. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5157. elem->next_page.addr.hi =
  5158. cpu_to_le32(U64_HI(bp->eq_mapping +
  5159. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5160. elem->next_page.addr.lo =
  5161. cpu_to_le32(U64_LO(bp->eq_mapping +
  5162. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5163. }
  5164. bp->eq_cons = 0;
  5165. bp->eq_prod = NUM_EQ_DESC;
  5166. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5167. /* we want a warning message before it gets wrought... */
  5168. atomic_set(&bp->eq_spq_left,
  5169. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5170. }
  5171. /* called with netif_addr_lock_bh() */
  5172. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5173. unsigned long rx_mode_flags,
  5174. unsigned long rx_accept_flags,
  5175. unsigned long tx_accept_flags,
  5176. unsigned long ramrod_flags)
  5177. {
  5178. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5179. int rc;
  5180. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5181. /* Prepare ramrod parameters */
  5182. ramrod_param.cid = 0;
  5183. ramrod_param.cl_id = cl_id;
  5184. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5185. ramrod_param.func_id = BP_FUNC(bp);
  5186. ramrod_param.pstate = &bp->sp_state;
  5187. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5188. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5189. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5190. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5191. ramrod_param.ramrod_flags = ramrod_flags;
  5192. ramrod_param.rx_mode_flags = rx_mode_flags;
  5193. ramrod_param.rx_accept_flags = rx_accept_flags;
  5194. ramrod_param.tx_accept_flags = tx_accept_flags;
  5195. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5196. if (rc < 0) {
  5197. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5198. return rc;
  5199. }
  5200. return 0;
  5201. }
  5202. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5203. unsigned long *rx_accept_flags,
  5204. unsigned long *tx_accept_flags)
  5205. {
  5206. /* Clear the flags first */
  5207. *rx_accept_flags = 0;
  5208. *tx_accept_flags = 0;
  5209. switch (rx_mode) {
  5210. case BNX2X_RX_MODE_NONE:
  5211. /*
  5212. * 'drop all' supersedes any accept flags that may have been
  5213. * passed to the function.
  5214. */
  5215. break;
  5216. case BNX2X_RX_MODE_NORMAL:
  5217. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5218. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5219. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5220. /* internal switching mode */
  5221. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5222. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5223. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5224. if (bp->accept_any_vlan) {
  5225. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5226. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5227. }
  5228. break;
  5229. case BNX2X_RX_MODE_ALLMULTI:
  5230. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5231. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5232. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5233. /* internal switching mode */
  5234. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5235. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5236. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5237. if (bp->accept_any_vlan) {
  5238. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5239. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5240. }
  5241. break;
  5242. case BNX2X_RX_MODE_PROMISC:
  5243. /* According to definition of SI mode, iface in promisc mode
  5244. * should receive matched and unmatched (in resolution of port)
  5245. * unicast packets.
  5246. */
  5247. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5248. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5249. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5250. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5251. /* internal switching mode */
  5252. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5253. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5254. if (IS_MF_SI(bp))
  5255. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5256. else
  5257. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5258. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5259. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5260. break;
  5261. default:
  5262. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5263. return -EINVAL;
  5264. }
  5265. return 0;
  5266. }
  5267. /* called with netif_addr_lock_bh() */
  5268. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5269. {
  5270. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5271. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5272. int rc;
  5273. if (!NO_FCOE(bp))
  5274. /* Configure rx_mode of FCoE Queue */
  5275. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5276. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5277. &tx_accept_flags);
  5278. if (rc)
  5279. return rc;
  5280. __set_bit(RAMROD_RX, &ramrod_flags);
  5281. __set_bit(RAMROD_TX, &ramrod_flags);
  5282. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5283. rx_accept_flags, tx_accept_flags,
  5284. ramrod_flags);
  5285. }
  5286. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5287. {
  5288. int i;
  5289. /* Zero this manually as its initialization is
  5290. currently missing in the initTool */
  5291. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5292. REG_WR(bp, BAR_USTRORM_INTMEM +
  5293. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5294. if (!CHIP_IS_E1x(bp)) {
  5295. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5296. CHIP_INT_MODE_IS_BC(bp) ?
  5297. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5298. }
  5299. }
  5300. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5301. {
  5302. switch (load_code) {
  5303. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5304. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5305. bnx2x_init_internal_common(bp);
  5306. /* no break */
  5307. case FW_MSG_CODE_DRV_LOAD_PORT:
  5308. /* nothing to do */
  5309. /* no break */
  5310. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5311. /* internal memory per function is
  5312. initialized inside bnx2x_pf_init */
  5313. break;
  5314. default:
  5315. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5316. break;
  5317. }
  5318. }
  5319. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5320. {
  5321. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5322. }
  5323. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5324. {
  5325. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5326. }
  5327. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5328. {
  5329. if (CHIP_IS_E1x(fp->bp))
  5330. return BP_L_ID(fp->bp) + fp->index;
  5331. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5332. return bnx2x_fp_igu_sb_id(fp);
  5333. }
  5334. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5335. {
  5336. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5337. u8 cos;
  5338. unsigned long q_type = 0;
  5339. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5340. fp->rx_queue = fp_idx;
  5341. fp->cid = fp_idx;
  5342. fp->cl_id = bnx2x_fp_cl_id(fp);
  5343. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5344. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5345. /* qZone id equals to FW (per path) client id */
  5346. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5347. /* init shortcut */
  5348. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5349. /* Setup SB indices */
  5350. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5351. /* Configure Queue State object */
  5352. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5353. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5354. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5355. /* init tx data */
  5356. for_each_cos_in_tx_queue(fp, cos) {
  5357. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5358. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5359. FP_COS_TO_TXQ(fp, cos, bp),
  5360. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5361. cids[cos] = fp->txdata_ptr[cos]->cid;
  5362. }
  5363. /* nothing more for vf to do here */
  5364. if (IS_VF(bp))
  5365. return;
  5366. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5367. fp->fw_sb_id, fp->igu_sb_id);
  5368. bnx2x_update_fpsb_idx(fp);
  5369. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5370. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5371. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5372. /**
  5373. * Configure classification DBs: Always enable Tx switching
  5374. */
  5375. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5376. DP(NETIF_MSG_IFUP,
  5377. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5378. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5379. fp->igu_sb_id);
  5380. }
  5381. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5382. {
  5383. int i;
  5384. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5385. struct eth_tx_next_bd *tx_next_bd =
  5386. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5387. tx_next_bd->addr_hi =
  5388. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5389. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5390. tx_next_bd->addr_lo =
  5391. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5392. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5393. }
  5394. *txdata->tx_cons_sb = cpu_to_le16(0);
  5395. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5396. txdata->tx_db.data.zero_fill1 = 0;
  5397. txdata->tx_db.data.prod = 0;
  5398. txdata->tx_pkt_prod = 0;
  5399. txdata->tx_pkt_cons = 0;
  5400. txdata->tx_bd_prod = 0;
  5401. txdata->tx_bd_cons = 0;
  5402. txdata->tx_pkt = 0;
  5403. }
  5404. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5405. {
  5406. int i;
  5407. for_each_tx_queue_cnic(bp, i)
  5408. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5409. }
  5410. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5411. {
  5412. int i;
  5413. u8 cos;
  5414. for_each_eth_queue(bp, i)
  5415. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5416. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5417. }
  5418. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5419. {
  5420. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5421. unsigned long q_type = 0;
  5422. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5423. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5424. BNX2X_FCOE_ETH_CL_ID_IDX);
  5425. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5426. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5427. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5428. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5429. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5430. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5431. fp);
  5432. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5433. /* qZone id equals to FW (per path) client id */
  5434. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5435. /* init shortcut */
  5436. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5437. bnx2x_rx_ustorm_prods_offset(fp);
  5438. /* Configure Queue State object */
  5439. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5440. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5441. /* No multi-CoS for FCoE L2 client */
  5442. BUG_ON(fp->max_cos != 1);
  5443. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5444. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5445. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5446. DP(NETIF_MSG_IFUP,
  5447. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5448. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5449. fp->igu_sb_id);
  5450. }
  5451. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5452. {
  5453. if (!NO_FCOE(bp))
  5454. bnx2x_init_fcoe_fp(bp);
  5455. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5456. BNX2X_VF_ID_INVALID, false,
  5457. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5458. /* ensure status block indices were read */
  5459. rmb();
  5460. bnx2x_init_rx_rings_cnic(bp);
  5461. bnx2x_init_tx_rings_cnic(bp);
  5462. /* flush all */
  5463. mb();
  5464. mmiowb();
  5465. }
  5466. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5467. {
  5468. int i;
  5469. /* Setup NIC internals and enable interrupts */
  5470. for_each_eth_queue(bp, i)
  5471. bnx2x_init_eth_fp(bp, i);
  5472. /* ensure status block indices were read */
  5473. rmb();
  5474. bnx2x_init_rx_rings(bp);
  5475. bnx2x_init_tx_rings(bp);
  5476. if (IS_PF(bp)) {
  5477. /* Initialize MOD_ABS interrupts */
  5478. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5479. bp->common.shmem_base,
  5480. bp->common.shmem2_base, BP_PORT(bp));
  5481. /* initialize the default status block and sp ring */
  5482. bnx2x_init_def_sb(bp);
  5483. bnx2x_update_dsb_idx(bp);
  5484. bnx2x_init_sp_ring(bp);
  5485. } else {
  5486. bnx2x_memset_stats(bp);
  5487. }
  5488. }
  5489. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5490. {
  5491. bnx2x_init_eq_ring(bp);
  5492. bnx2x_init_internal(bp, load_code);
  5493. bnx2x_pf_init(bp);
  5494. bnx2x_stats_init(bp);
  5495. /* flush all before enabling interrupts */
  5496. mb();
  5497. mmiowb();
  5498. bnx2x_int_enable(bp);
  5499. /* Check for SPIO5 */
  5500. bnx2x_attn_int_deasserted0(bp,
  5501. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5502. AEU_INPUTS_ATTN_BITS_SPIO5);
  5503. }
  5504. /* gzip service functions */
  5505. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5506. {
  5507. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5508. &bp->gunzip_mapping, GFP_KERNEL);
  5509. if (bp->gunzip_buf == NULL)
  5510. goto gunzip_nomem1;
  5511. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5512. if (bp->strm == NULL)
  5513. goto gunzip_nomem2;
  5514. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5515. if (bp->strm->workspace == NULL)
  5516. goto gunzip_nomem3;
  5517. return 0;
  5518. gunzip_nomem3:
  5519. kfree(bp->strm);
  5520. bp->strm = NULL;
  5521. gunzip_nomem2:
  5522. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5523. bp->gunzip_mapping);
  5524. bp->gunzip_buf = NULL;
  5525. gunzip_nomem1:
  5526. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5527. return -ENOMEM;
  5528. }
  5529. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5530. {
  5531. if (bp->strm) {
  5532. vfree(bp->strm->workspace);
  5533. kfree(bp->strm);
  5534. bp->strm = NULL;
  5535. }
  5536. if (bp->gunzip_buf) {
  5537. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5538. bp->gunzip_mapping);
  5539. bp->gunzip_buf = NULL;
  5540. }
  5541. }
  5542. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5543. {
  5544. int n, rc;
  5545. /* check gzip header */
  5546. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5547. BNX2X_ERR("Bad gzip header\n");
  5548. return -EINVAL;
  5549. }
  5550. n = 10;
  5551. #define FNAME 0x8
  5552. if (zbuf[3] & FNAME)
  5553. while ((zbuf[n++] != 0) && (n < len));
  5554. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5555. bp->strm->avail_in = len - n;
  5556. bp->strm->next_out = bp->gunzip_buf;
  5557. bp->strm->avail_out = FW_BUF_SIZE;
  5558. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5559. if (rc != Z_OK)
  5560. return rc;
  5561. rc = zlib_inflate(bp->strm, Z_FINISH);
  5562. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5563. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5564. bp->strm->msg);
  5565. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5566. if (bp->gunzip_outlen & 0x3)
  5567. netdev_err(bp->dev,
  5568. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5569. bp->gunzip_outlen);
  5570. bp->gunzip_outlen >>= 2;
  5571. zlib_inflateEnd(bp->strm);
  5572. if (rc == Z_STREAM_END)
  5573. return 0;
  5574. return rc;
  5575. }
  5576. /* nic load/unload */
  5577. /*
  5578. * General service functions
  5579. */
  5580. /* send a NIG loopback debug packet */
  5581. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5582. {
  5583. u32 wb_write[3];
  5584. /* Ethernet source and destination addresses */
  5585. wb_write[0] = 0x55555555;
  5586. wb_write[1] = 0x55555555;
  5587. wb_write[2] = 0x20; /* SOP */
  5588. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5589. /* NON-IP protocol */
  5590. wb_write[0] = 0x09000000;
  5591. wb_write[1] = 0x55555555;
  5592. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5593. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5594. }
  5595. /* some of the internal memories
  5596. * are not directly readable from the driver
  5597. * to test them we send debug packets
  5598. */
  5599. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5600. {
  5601. int factor;
  5602. int count, i;
  5603. u32 val = 0;
  5604. if (CHIP_REV_IS_FPGA(bp))
  5605. factor = 120;
  5606. else if (CHIP_REV_IS_EMUL(bp))
  5607. factor = 200;
  5608. else
  5609. factor = 1;
  5610. /* Disable inputs of parser neighbor blocks */
  5611. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5612. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5613. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5614. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5615. /* Write 0 to parser credits for CFC search request */
  5616. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5617. /* send Ethernet packet */
  5618. bnx2x_lb_pckt(bp);
  5619. /* TODO do i reset NIG statistic? */
  5620. /* Wait until NIG register shows 1 packet of size 0x10 */
  5621. count = 1000 * factor;
  5622. while (count) {
  5623. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5624. val = *bnx2x_sp(bp, wb_data[0]);
  5625. if (val == 0x10)
  5626. break;
  5627. usleep_range(10000, 20000);
  5628. count--;
  5629. }
  5630. if (val != 0x10) {
  5631. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5632. return -1;
  5633. }
  5634. /* Wait until PRS register shows 1 packet */
  5635. count = 1000 * factor;
  5636. while (count) {
  5637. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5638. if (val == 1)
  5639. break;
  5640. usleep_range(10000, 20000);
  5641. count--;
  5642. }
  5643. if (val != 0x1) {
  5644. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5645. return -2;
  5646. }
  5647. /* Reset and init BRB, PRS */
  5648. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5649. msleep(50);
  5650. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5651. msleep(50);
  5652. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5653. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5654. DP(NETIF_MSG_HW, "part2\n");
  5655. /* Disable inputs of parser neighbor blocks */
  5656. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5657. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5658. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5659. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5660. /* Write 0 to parser credits for CFC search request */
  5661. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5662. /* send 10 Ethernet packets */
  5663. for (i = 0; i < 10; i++)
  5664. bnx2x_lb_pckt(bp);
  5665. /* Wait until NIG register shows 10 + 1
  5666. packets of size 11*0x10 = 0xb0 */
  5667. count = 1000 * factor;
  5668. while (count) {
  5669. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5670. val = *bnx2x_sp(bp, wb_data[0]);
  5671. if (val == 0xb0)
  5672. break;
  5673. usleep_range(10000, 20000);
  5674. count--;
  5675. }
  5676. if (val != 0xb0) {
  5677. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5678. return -3;
  5679. }
  5680. /* Wait until PRS register shows 2 packets */
  5681. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5682. if (val != 2)
  5683. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5684. /* Write 1 to parser credits for CFC search request */
  5685. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5686. /* Wait until PRS register shows 3 packets */
  5687. msleep(10 * factor);
  5688. /* Wait until NIG register shows 1 packet of size 0x10 */
  5689. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5690. if (val != 3)
  5691. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5692. /* clear NIG EOP FIFO */
  5693. for (i = 0; i < 11; i++)
  5694. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5695. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5696. if (val != 1) {
  5697. BNX2X_ERR("clear of NIG failed\n");
  5698. return -4;
  5699. }
  5700. /* Reset and init BRB, PRS, NIG */
  5701. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5702. msleep(50);
  5703. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5704. msleep(50);
  5705. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5706. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5707. if (!CNIC_SUPPORT(bp))
  5708. /* set NIC mode */
  5709. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5710. /* Enable inputs of parser neighbor blocks */
  5711. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5712. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5713. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5714. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5715. DP(NETIF_MSG_HW, "done\n");
  5716. return 0; /* OK */
  5717. }
  5718. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5719. {
  5720. u32 val;
  5721. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5722. if (!CHIP_IS_E1x(bp))
  5723. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5724. else
  5725. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5726. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5727. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5728. /*
  5729. * mask read length error interrupts in brb for parser
  5730. * (parsing unit and 'checksum and crc' unit)
  5731. * these errors are legal (PU reads fixed length and CAC can cause
  5732. * read length error on truncated packets)
  5733. */
  5734. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5735. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5736. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5737. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5738. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5739. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5740. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5741. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5742. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5743. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5744. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5745. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5746. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5747. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5748. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5749. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5750. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5751. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5752. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5753. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5754. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5755. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5756. if (!CHIP_IS_E1x(bp))
  5757. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5758. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5759. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5760. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5761. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5762. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5763. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5764. if (!CHIP_IS_E1x(bp))
  5765. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5766. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5767. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5768. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5769. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5770. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5771. }
  5772. static void bnx2x_reset_common(struct bnx2x *bp)
  5773. {
  5774. u32 val = 0x1400;
  5775. /* reset_common */
  5776. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5777. 0xd3ffff7f);
  5778. if (CHIP_IS_E3(bp)) {
  5779. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5780. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5781. }
  5782. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5783. }
  5784. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5785. {
  5786. bp->dmae_ready = 0;
  5787. spin_lock_init(&bp->dmae_lock);
  5788. }
  5789. static void bnx2x_init_pxp(struct bnx2x *bp)
  5790. {
  5791. u16 devctl;
  5792. int r_order, w_order;
  5793. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5794. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5795. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5796. if (bp->mrrs == -1)
  5797. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5798. else {
  5799. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5800. r_order = bp->mrrs;
  5801. }
  5802. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5803. }
  5804. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5805. {
  5806. int is_required;
  5807. u32 val;
  5808. int port;
  5809. if (BP_NOMCP(bp))
  5810. return;
  5811. is_required = 0;
  5812. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5813. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5814. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5815. is_required = 1;
  5816. /*
  5817. * The fan failure mechanism is usually related to the PHY type since
  5818. * the power consumption of the board is affected by the PHY. Currently,
  5819. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5820. */
  5821. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5822. for (port = PORT_0; port < PORT_MAX; port++) {
  5823. is_required |=
  5824. bnx2x_fan_failure_det_req(
  5825. bp,
  5826. bp->common.shmem_base,
  5827. bp->common.shmem2_base,
  5828. port);
  5829. }
  5830. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5831. if (is_required == 0)
  5832. return;
  5833. /* Fan failure is indicated by SPIO 5 */
  5834. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5835. /* set to active low mode */
  5836. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5837. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5838. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5839. /* enable interrupt to signal the IGU */
  5840. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5841. val |= MISC_SPIO_SPIO5;
  5842. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5843. }
  5844. void bnx2x_pf_disable(struct bnx2x *bp)
  5845. {
  5846. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5847. val &= ~IGU_PF_CONF_FUNC_EN;
  5848. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5849. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5850. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5851. }
  5852. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5853. {
  5854. u32 shmem_base[2], shmem2_base[2];
  5855. /* Avoid common init in case MFW supports LFA */
  5856. if (SHMEM2_RD(bp, size) >
  5857. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5858. return;
  5859. shmem_base[0] = bp->common.shmem_base;
  5860. shmem2_base[0] = bp->common.shmem2_base;
  5861. if (!CHIP_IS_E1x(bp)) {
  5862. shmem_base[1] =
  5863. SHMEM2_RD(bp, other_shmem_base_addr);
  5864. shmem2_base[1] =
  5865. SHMEM2_RD(bp, other_shmem2_base_addr);
  5866. }
  5867. bnx2x_acquire_phy_lock(bp);
  5868. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5869. bp->common.chip_id);
  5870. bnx2x_release_phy_lock(bp);
  5871. }
  5872. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5873. {
  5874. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5875. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5876. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5877. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5878. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5879. /* make sure this value is 0 */
  5880. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5881. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5882. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5883. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5884. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5885. }
  5886. static void bnx2x_set_endianity(struct bnx2x *bp)
  5887. {
  5888. #ifdef __BIG_ENDIAN
  5889. bnx2x_config_endianity(bp, 1);
  5890. #else
  5891. bnx2x_config_endianity(bp, 0);
  5892. #endif
  5893. }
  5894. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5895. {
  5896. bnx2x_config_endianity(bp, 0);
  5897. }
  5898. /**
  5899. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5900. *
  5901. * @bp: driver handle
  5902. */
  5903. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5904. {
  5905. u32 val;
  5906. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5907. /*
  5908. * take the RESET lock to protect undi_unload flow from accessing
  5909. * registers while we're resetting the chip
  5910. */
  5911. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5912. bnx2x_reset_common(bp);
  5913. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5914. val = 0xfffc;
  5915. if (CHIP_IS_E3(bp)) {
  5916. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5917. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5918. }
  5919. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5920. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5921. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5922. if (!CHIP_IS_E1x(bp)) {
  5923. u8 abs_func_id;
  5924. /**
  5925. * 4-port mode or 2-port mode we need to turn of master-enable
  5926. * for everyone, after that, turn it back on for self.
  5927. * so, we disregard multi-function or not, and always disable
  5928. * for all functions on the given path, this means 0,2,4,6 for
  5929. * path 0 and 1,3,5,7 for path 1
  5930. */
  5931. for (abs_func_id = BP_PATH(bp);
  5932. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5933. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5934. REG_WR(bp,
  5935. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5936. 1);
  5937. continue;
  5938. }
  5939. bnx2x_pretend_func(bp, abs_func_id);
  5940. /* clear pf enable */
  5941. bnx2x_pf_disable(bp);
  5942. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5943. }
  5944. }
  5945. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5946. if (CHIP_IS_E1(bp)) {
  5947. /* enable HW interrupt from PXP on USDM overflow
  5948. bit 16 on INT_MASK_0 */
  5949. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5950. }
  5951. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5952. bnx2x_init_pxp(bp);
  5953. bnx2x_set_endianity(bp);
  5954. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5955. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5956. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5957. /* let the HW do it's magic ... */
  5958. msleep(100);
  5959. /* finish PXP init */
  5960. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5961. if (val != 1) {
  5962. BNX2X_ERR("PXP2 CFG failed\n");
  5963. return -EBUSY;
  5964. }
  5965. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5966. if (val != 1) {
  5967. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5968. return -EBUSY;
  5969. }
  5970. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5971. * have entries with value "0" and valid bit on.
  5972. * This needs to be done by the first PF that is loaded in a path
  5973. * (i.e. common phase)
  5974. */
  5975. if (!CHIP_IS_E1x(bp)) {
  5976. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5977. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5978. * This occurs when a different function (func2,3) is being marked
  5979. * as "scan-off". Real-life scenario for example: if a driver is being
  5980. * load-unloaded while func6,7 are down. This will cause the timer to access
  5981. * the ilt, translate to a logical address and send a request to read/write.
  5982. * Since the ilt for the function that is down is not valid, this will cause
  5983. * a translation error which is unrecoverable.
  5984. * The Workaround is intended to make sure that when this happens nothing fatal
  5985. * will occur. The workaround:
  5986. * 1. First PF driver which loads on a path will:
  5987. * a. After taking the chip out of reset, by using pretend,
  5988. * it will write "0" to the following registers of
  5989. * the other vnics.
  5990. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5991. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5992. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5993. * And for itself it will write '1' to
  5994. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5995. * dmae-operations (writing to pram for example.)
  5996. * note: can be done for only function 6,7 but cleaner this
  5997. * way.
  5998. * b. Write zero+valid to the entire ILT.
  5999. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  6000. * VNIC3 (of that port). The range allocated will be the
  6001. * entire ILT. This is needed to prevent ILT range error.
  6002. * 2. Any PF driver load flow:
  6003. * a. ILT update with the physical addresses of the allocated
  6004. * logical pages.
  6005. * b. Wait 20msec. - note that this timeout is needed to make
  6006. * sure there are no requests in one of the PXP internal
  6007. * queues with "old" ILT addresses.
  6008. * c. PF enable in the PGLC.
  6009. * d. Clear the was_error of the PF in the PGLC. (could have
  6010. * occurred while driver was down)
  6011. * e. PF enable in the CFC (WEAK + STRONG)
  6012. * f. Timers scan enable
  6013. * 3. PF driver unload flow:
  6014. * a. Clear the Timers scan_en.
  6015. * b. Polling for scan_on=0 for that PF.
  6016. * c. Clear the PF enable bit in the PXP.
  6017. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  6018. * e. Write zero+valid to all ILT entries (The valid bit must
  6019. * stay set)
  6020. * f. If this is VNIC 3 of a port then also init
  6021. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  6022. * to the last entry in the ILT.
  6023. *
  6024. * Notes:
  6025. * Currently the PF error in the PGLC is non recoverable.
  6026. * In the future the there will be a recovery routine for this error.
  6027. * Currently attention is masked.
  6028. * Having an MCP lock on the load/unload process does not guarantee that
  6029. * there is no Timer disable during Func6/7 enable. This is because the
  6030. * Timers scan is currently being cleared by the MCP on FLR.
  6031. * Step 2.d can be done only for PF6/7 and the driver can also check if
  6032. * there is error before clearing it. But the flow above is simpler and
  6033. * more general.
  6034. * All ILT entries are written by zero+valid and not just PF6/7
  6035. * ILT entries since in the future the ILT entries allocation for
  6036. * PF-s might be dynamic.
  6037. */
  6038. struct ilt_client_info ilt_cli;
  6039. struct bnx2x_ilt ilt;
  6040. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6041. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6042. /* initialize dummy TM client */
  6043. ilt_cli.start = 0;
  6044. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6045. ilt_cli.client_num = ILT_CLIENT_TM;
  6046. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6047. * Step 2: set the timers first/last ilt entry to point
  6048. * to the entire range to prevent ILT range error for 3rd/4th
  6049. * vnic (this code assumes existence of the vnic)
  6050. *
  6051. * both steps performed by call to bnx2x_ilt_client_init_op()
  6052. * with dummy TM client
  6053. *
  6054. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6055. * and his brother are split registers
  6056. */
  6057. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6058. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6059. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6060. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6061. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6062. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6063. }
  6064. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6065. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6066. if (!CHIP_IS_E1x(bp)) {
  6067. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6068. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6069. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6070. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6071. /* let the HW do it's magic ... */
  6072. do {
  6073. msleep(200);
  6074. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6075. } while (factor-- && (val != 1));
  6076. if (val != 1) {
  6077. BNX2X_ERR("ATC_INIT failed\n");
  6078. return -EBUSY;
  6079. }
  6080. }
  6081. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6082. bnx2x_iov_init_dmae(bp);
  6083. /* clean the DMAE memory */
  6084. bp->dmae_ready = 1;
  6085. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6086. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6087. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6088. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6089. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6090. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6091. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6092. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6093. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6094. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6095. /* QM queues pointers table */
  6096. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6097. /* soft reset pulse */
  6098. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6099. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6100. if (CNIC_SUPPORT(bp))
  6101. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6102. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6103. if (!CHIP_REV_IS_SLOW(bp))
  6104. /* enable hw interrupt from doorbell Q */
  6105. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6106. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6107. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6108. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6109. if (!CHIP_IS_E1(bp))
  6110. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6111. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6112. if (IS_MF_AFEX(bp)) {
  6113. /* configure that VNTag and VLAN headers must be
  6114. * received in afex mode
  6115. */
  6116. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6117. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6118. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6119. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6120. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6121. } else {
  6122. /* Bit-map indicating which L2 hdrs may appear
  6123. * after the basic Ethernet header
  6124. */
  6125. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6126. bp->path_has_ovlan ? 7 : 6);
  6127. }
  6128. }
  6129. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6130. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6131. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6132. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6133. if (!CHIP_IS_E1x(bp)) {
  6134. /* reset VFC memories */
  6135. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6136. VFC_MEMORIES_RST_REG_CAM_RST |
  6137. VFC_MEMORIES_RST_REG_RAM_RST);
  6138. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6139. VFC_MEMORIES_RST_REG_CAM_RST |
  6140. VFC_MEMORIES_RST_REG_RAM_RST);
  6141. msleep(20);
  6142. }
  6143. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6144. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6145. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6146. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6147. /* sync semi rtc */
  6148. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6149. 0x80000000);
  6150. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6151. 0x80000000);
  6152. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6153. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6154. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6155. if (!CHIP_IS_E1x(bp)) {
  6156. if (IS_MF_AFEX(bp)) {
  6157. /* configure that VNTag and VLAN headers must be
  6158. * sent in afex mode
  6159. */
  6160. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6161. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6162. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6163. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6164. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6165. } else {
  6166. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6167. bp->path_has_ovlan ? 7 : 6);
  6168. }
  6169. }
  6170. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6171. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6172. if (CNIC_SUPPORT(bp)) {
  6173. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6174. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6175. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6176. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6177. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6178. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6179. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6180. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6181. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6182. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6183. }
  6184. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6185. if (sizeof(union cdu_context) != 1024)
  6186. /* we currently assume that a context is 1024 bytes */
  6187. dev_alert(&bp->pdev->dev,
  6188. "please adjust the size of cdu_context(%ld)\n",
  6189. (long)sizeof(union cdu_context));
  6190. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6191. val = (4 << 24) + (0 << 12) + 1024;
  6192. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6193. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6194. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6195. /* enable context validation interrupt from CFC */
  6196. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6197. /* set the thresholds to prevent CFC/CDU race */
  6198. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6199. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6200. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6201. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6202. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6203. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6204. /* Reset PCIE errors for debug */
  6205. REG_WR(bp, 0x2814, 0xffffffff);
  6206. REG_WR(bp, 0x3820, 0xffffffff);
  6207. if (!CHIP_IS_E1x(bp)) {
  6208. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6209. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6210. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6211. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6212. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6213. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6214. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6215. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6216. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6217. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6218. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6219. }
  6220. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6221. if (!CHIP_IS_E1(bp)) {
  6222. /* in E3 this done in per-port section */
  6223. if (!CHIP_IS_E3(bp))
  6224. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6225. }
  6226. if (CHIP_IS_E1H(bp))
  6227. /* not applicable for E2 (and above ...) */
  6228. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6229. if (CHIP_REV_IS_SLOW(bp))
  6230. msleep(200);
  6231. /* finish CFC init */
  6232. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6233. if (val != 1) {
  6234. BNX2X_ERR("CFC LL_INIT failed\n");
  6235. return -EBUSY;
  6236. }
  6237. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6238. if (val != 1) {
  6239. BNX2X_ERR("CFC AC_INIT failed\n");
  6240. return -EBUSY;
  6241. }
  6242. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6243. if (val != 1) {
  6244. BNX2X_ERR("CFC CAM_INIT failed\n");
  6245. return -EBUSY;
  6246. }
  6247. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6248. if (CHIP_IS_E1(bp)) {
  6249. /* read NIG statistic
  6250. to see if this is our first up since powerup */
  6251. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6252. val = *bnx2x_sp(bp, wb_data[0]);
  6253. /* do internal memory self test */
  6254. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6255. BNX2X_ERR("internal mem self test failed\n");
  6256. return -EBUSY;
  6257. }
  6258. }
  6259. bnx2x_setup_fan_failure_detection(bp);
  6260. /* clear PXP2 attentions */
  6261. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6262. bnx2x_enable_blocks_attention(bp);
  6263. bnx2x_enable_blocks_parity(bp);
  6264. if (!BP_NOMCP(bp)) {
  6265. if (CHIP_IS_E1x(bp))
  6266. bnx2x__common_init_phy(bp);
  6267. } else
  6268. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6269. if (SHMEM2_HAS(bp, netproc_fw_ver))
  6270. SHMEM2_WR(bp, netproc_fw_ver, REG_RD(bp, XSEM_REG_PRAM));
  6271. return 0;
  6272. }
  6273. /**
  6274. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6275. *
  6276. * @bp: driver handle
  6277. */
  6278. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6279. {
  6280. int rc = bnx2x_init_hw_common(bp);
  6281. if (rc)
  6282. return rc;
  6283. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6284. if (!BP_NOMCP(bp))
  6285. bnx2x__common_init_phy(bp);
  6286. return 0;
  6287. }
  6288. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6289. {
  6290. int port = BP_PORT(bp);
  6291. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6292. u32 low, high;
  6293. u32 val, reg;
  6294. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6295. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6296. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6297. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6298. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6299. /* Timers bug workaround: disables the pf_master bit in pglue at
  6300. * common phase, we need to enable it here before any dmae access are
  6301. * attempted. Therefore we manually added the enable-master to the
  6302. * port phase (it also happens in the function phase)
  6303. */
  6304. if (!CHIP_IS_E1x(bp))
  6305. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6306. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6307. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6308. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6309. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6310. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6311. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6312. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6313. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6314. /* QM cid (connection) count */
  6315. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6316. if (CNIC_SUPPORT(bp)) {
  6317. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6318. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6319. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6320. }
  6321. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6322. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6323. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6324. if (IS_MF(bp))
  6325. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6326. else if (bp->dev->mtu > 4096) {
  6327. if (bp->flags & ONE_PORT_FLAG)
  6328. low = 160;
  6329. else {
  6330. val = bp->dev->mtu;
  6331. /* (24*1024 + val*4)/256 */
  6332. low = 96 + (val/64) +
  6333. ((val % 64) ? 1 : 0);
  6334. }
  6335. } else
  6336. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6337. high = low + 56; /* 14*1024/256 */
  6338. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6339. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6340. }
  6341. if (CHIP_MODE_IS_4_PORT(bp))
  6342. REG_WR(bp, (BP_PORT(bp) ?
  6343. BRB1_REG_MAC_GUARANTIED_1 :
  6344. BRB1_REG_MAC_GUARANTIED_0), 40);
  6345. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6346. if (CHIP_IS_E3B0(bp)) {
  6347. if (IS_MF_AFEX(bp)) {
  6348. /* configure headers for AFEX mode */
  6349. REG_WR(bp, BP_PORT(bp) ?
  6350. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6351. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6352. REG_WR(bp, BP_PORT(bp) ?
  6353. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6354. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6355. REG_WR(bp, BP_PORT(bp) ?
  6356. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6357. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6358. } else {
  6359. /* Ovlan exists only if we are in multi-function +
  6360. * switch-dependent mode, in switch-independent there
  6361. * is no ovlan headers
  6362. */
  6363. REG_WR(bp, BP_PORT(bp) ?
  6364. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6365. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6366. (bp->path_has_ovlan ? 7 : 6));
  6367. }
  6368. }
  6369. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6370. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6371. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6372. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6373. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6374. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6375. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6376. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6377. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6378. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6379. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6380. if (CHIP_IS_E1x(bp)) {
  6381. /* configure PBF to work without PAUSE mtu 9000 */
  6382. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6383. /* update threshold */
  6384. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6385. /* update init credit */
  6386. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6387. /* probe changes */
  6388. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6389. udelay(50);
  6390. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6391. }
  6392. if (CNIC_SUPPORT(bp))
  6393. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6394. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6395. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6396. if (CHIP_IS_E1(bp)) {
  6397. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6398. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6399. }
  6400. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6401. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6402. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6403. /* init aeu_mask_attn_func_0/1:
  6404. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6405. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6406. * bits 4-7 are used for "per vn group attention" */
  6407. val = IS_MF(bp) ? 0xF7 : 0x7;
  6408. /* Enable DCBX attention for all but E1 */
  6409. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6410. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6411. /* SCPAD_PARITY should NOT trigger close the gates */
  6412. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6413. REG_WR(bp, reg,
  6414. REG_RD(bp, reg) &
  6415. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6416. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6417. REG_WR(bp, reg,
  6418. REG_RD(bp, reg) &
  6419. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6420. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6421. if (!CHIP_IS_E1x(bp)) {
  6422. /* Bit-map indicating which L2 hdrs may appear after the
  6423. * basic Ethernet header
  6424. */
  6425. if (IS_MF_AFEX(bp))
  6426. REG_WR(bp, BP_PORT(bp) ?
  6427. NIG_REG_P1_HDRS_AFTER_BASIC :
  6428. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6429. else
  6430. REG_WR(bp, BP_PORT(bp) ?
  6431. NIG_REG_P1_HDRS_AFTER_BASIC :
  6432. NIG_REG_P0_HDRS_AFTER_BASIC,
  6433. IS_MF_SD(bp) ? 7 : 6);
  6434. if (CHIP_IS_E3(bp))
  6435. REG_WR(bp, BP_PORT(bp) ?
  6436. NIG_REG_LLH1_MF_MODE :
  6437. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6438. }
  6439. if (!CHIP_IS_E3(bp))
  6440. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6441. if (!CHIP_IS_E1(bp)) {
  6442. /* 0x2 disable mf_ov, 0x1 enable */
  6443. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6444. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6445. if (!CHIP_IS_E1x(bp)) {
  6446. val = 0;
  6447. switch (bp->mf_mode) {
  6448. case MULTI_FUNCTION_SD:
  6449. val = 1;
  6450. break;
  6451. case MULTI_FUNCTION_SI:
  6452. case MULTI_FUNCTION_AFEX:
  6453. val = 2;
  6454. break;
  6455. }
  6456. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6457. NIG_REG_LLH0_CLS_TYPE), val);
  6458. }
  6459. {
  6460. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6461. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6462. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6463. }
  6464. }
  6465. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6466. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6467. if (val & MISC_SPIO_SPIO5) {
  6468. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6469. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6470. val = REG_RD(bp, reg_addr);
  6471. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6472. REG_WR(bp, reg_addr, val);
  6473. }
  6474. return 0;
  6475. }
  6476. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6477. {
  6478. int reg;
  6479. u32 wb_write[2];
  6480. if (CHIP_IS_E1(bp))
  6481. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6482. else
  6483. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6484. wb_write[0] = ONCHIP_ADDR1(addr);
  6485. wb_write[1] = ONCHIP_ADDR2(addr);
  6486. REG_WR_DMAE(bp, reg, wb_write, 2);
  6487. }
  6488. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6489. {
  6490. u32 data, ctl, cnt = 100;
  6491. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6492. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6493. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6494. u32 sb_bit = 1 << (idu_sb_id%32);
  6495. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6496. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6497. /* Not supported in BC mode */
  6498. if (CHIP_INT_MODE_IS_BC(bp))
  6499. return;
  6500. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6501. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6502. IGU_REGULAR_CLEANUP_SET |
  6503. IGU_REGULAR_BCLEANUP;
  6504. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6505. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6506. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6507. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6508. data, igu_addr_data);
  6509. REG_WR(bp, igu_addr_data, data);
  6510. mmiowb();
  6511. barrier();
  6512. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6513. ctl, igu_addr_ctl);
  6514. REG_WR(bp, igu_addr_ctl, ctl);
  6515. mmiowb();
  6516. barrier();
  6517. /* wait for clean up to finish */
  6518. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6519. msleep(20);
  6520. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6521. DP(NETIF_MSG_HW,
  6522. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6523. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6524. }
  6525. }
  6526. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6527. {
  6528. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6529. }
  6530. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6531. {
  6532. u32 i, base = FUNC_ILT_BASE(func);
  6533. for (i = base; i < base + ILT_PER_FUNC; i++)
  6534. bnx2x_ilt_wr(bp, i, 0);
  6535. }
  6536. static void bnx2x_init_searcher(struct bnx2x *bp)
  6537. {
  6538. int port = BP_PORT(bp);
  6539. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6540. /* T1 hash bits value determines the T1 number of entries */
  6541. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6542. }
  6543. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6544. {
  6545. int rc;
  6546. struct bnx2x_func_state_params func_params = {NULL};
  6547. struct bnx2x_func_switch_update_params *switch_update_params =
  6548. &func_params.params.switch_update;
  6549. /* Prepare parameters for function state transitions */
  6550. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6551. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6552. func_params.f_obj = &bp->func_obj;
  6553. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6554. /* Function parameters */
  6555. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6556. &switch_update_params->changes);
  6557. if (suspend)
  6558. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6559. &switch_update_params->changes);
  6560. rc = bnx2x_func_state_change(bp, &func_params);
  6561. return rc;
  6562. }
  6563. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6564. {
  6565. int rc, i, port = BP_PORT(bp);
  6566. int vlan_en = 0, mac_en[NUM_MACS];
  6567. /* Close input from network */
  6568. if (bp->mf_mode == SINGLE_FUNCTION) {
  6569. bnx2x_set_rx_filter(&bp->link_params, 0);
  6570. } else {
  6571. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6572. NIG_REG_LLH0_FUNC_EN);
  6573. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6574. NIG_REG_LLH0_FUNC_EN, 0);
  6575. for (i = 0; i < NUM_MACS; i++) {
  6576. mac_en[i] = REG_RD(bp, port ?
  6577. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6578. 4 * i) :
  6579. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6580. 4 * i));
  6581. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6582. 4 * i) :
  6583. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6584. }
  6585. }
  6586. /* Close BMC to host */
  6587. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6588. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6589. /* Suspend Tx switching to the PF. Completion of this ramrod
  6590. * further guarantees that all the packets of that PF / child
  6591. * VFs in BRB were processed by the Parser, so it is safe to
  6592. * change the NIC_MODE register.
  6593. */
  6594. rc = bnx2x_func_switch_update(bp, 1);
  6595. if (rc) {
  6596. BNX2X_ERR("Can't suspend tx-switching!\n");
  6597. return rc;
  6598. }
  6599. /* Change NIC_MODE register */
  6600. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6601. /* Open input from network */
  6602. if (bp->mf_mode == SINGLE_FUNCTION) {
  6603. bnx2x_set_rx_filter(&bp->link_params, 1);
  6604. } else {
  6605. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6606. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6607. for (i = 0; i < NUM_MACS; i++) {
  6608. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6609. 4 * i) :
  6610. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6611. mac_en[i]);
  6612. }
  6613. }
  6614. /* Enable BMC to host */
  6615. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6616. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6617. /* Resume Tx switching to the PF */
  6618. rc = bnx2x_func_switch_update(bp, 0);
  6619. if (rc) {
  6620. BNX2X_ERR("Can't resume tx-switching!\n");
  6621. return rc;
  6622. }
  6623. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6624. return 0;
  6625. }
  6626. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6627. {
  6628. int rc;
  6629. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6630. if (CONFIGURE_NIC_MODE(bp)) {
  6631. /* Configure searcher as part of function hw init */
  6632. bnx2x_init_searcher(bp);
  6633. /* Reset NIC mode */
  6634. rc = bnx2x_reset_nic_mode(bp);
  6635. if (rc)
  6636. BNX2X_ERR("Can't change NIC mode!\n");
  6637. return rc;
  6638. }
  6639. return 0;
  6640. }
  6641. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  6642. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  6643. * the addresses of the transaction, resulting in was-error bit set in the pci
  6644. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  6645. * to clear the interrupt which detected this from the pglueb and the was done
  6646. * bit
  6647. */
  6648. static void bnx2x_clean_pglue_errors(struct bnx2x *bp)
  6649. {
  6650. if (!CHIP_IS_E1x(bp))
  6651. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  6652. 1 << BP_ABS_FUNC(bp));
  6653. }
  6654. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6655. {
  6656. int port = BP_PORT(bp);
  6657. int func = BP_FUNC(bp);
  6658. int init_phase = PHASE_PF0 + func;
  6659. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6660. u16 cdu_ilt_start;
  6661. u32 addr, val;
  6662. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6663. int i, main_mem_width, rc;
  6664. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6665. /* FLR cleanup - hmmm */
  6666. if (!CHIP_IS_E1x(bp)) {
  6667. rc = bnx2x_pf_flr_clnup(bp);
  6668. if (rc) {
  6669. bnx2x_fw_dump(bp);
  6670. return rc;
  6671. }
  6672. }
  6673. /* set MSI reconfigure capability */
  6674. if (bp->common.int_block == INT_BLOCK_HC) {
  6675. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6676. val = REG_RD(bp, addr);
  6677. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6678. REG_WR(bp, addr, val);
  6679. }
  6680. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6681. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6682. ilt = BP_ILT(bp);
  6683. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6684. if (IS_SRIOV(bp))
  6685. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6686. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6687. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6688. * those of the VFs, so start line should be reset
  6689. */
  6690. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6691. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6692. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6693. ilt->lines[cdu_ilt_start + i].page_mapping =
  6694. bp->context[i].cxt_mapping;
  6695. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6696. }
  6697. bnx2x_ilt_init_op(bp, INITOP_SET);
  6698. if (!CONFIGURE_NIC_MODE(bp)) {
  6699. bnx2x_init_searcher(bp);
  6700. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6701. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6702. } else {
  6703. /* Set NIC mode */
  6704. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6705. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6706. }
  6707. if (!CHIP_IS_E1x(bp)) {
  6708. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6709. /* Turn on a single ISR mode in IGU if driver is going to use
  6710. * INT#x or MSI
  6711. */
  6712. if (!(bp->flags & USING_MSIX_FLAG))
  6713. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6714. /*
  6715. * Timers workaround bug: function init part.
  6716. * Need to wait 20msec after initializing ILT,
  6717. * needed to make sure there are no requests in
  6718. * one of the PXP internal queues with "old" ILT addresses
  6719. */
  6720. msleep(20);
  6721. /*
  6722. * Master enable - Due to WB DMAE writes performed before this
  6723. * register is re-initialized as part of the regular function
  6724. * init
  6725. */
  6726. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6727. /* Enable the function in IGU */
  6728. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6729. }
  6730. bp->dmae_ready = 1;
  6731. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6732. bnx2x_clean_pglue_errors(bp);
  6733. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6734. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6735. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6736. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6737. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6738. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6739. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6740. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6741. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6742. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6743. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6744. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6745. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6746. if (!CHIP_IS_E1x(bp))
  6747. REG_WR(bp, QM_REG_PF_EN, 1);
  6748. if (!CHIP_IS_E1x(bp)) {
  6749. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6750. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6751. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6752. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6753. }
  6754. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6755. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6756. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6757. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6758. bnx2x_iov_init_dq(bp);
  6759. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6760. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6761. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6762. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6763. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6764. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6765. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6766. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6767. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6768. if (!CHIP_IS_E1x(bp))
  6769. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6770. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6771. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6772. if (!CHIP_IS_E1x(bp))
  6773. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6774. if (IS_MF(bp)) {
  6775. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6776. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6777. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6778. bp->mf_ov);
  6779. }
  6780. }
  6781. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6782. /* HC init per function */
  6783. if (bp->common.int_block == INT_BLOCK_HC) {
  6784. if (CHIP_IS_E1H(bp)) {
  6785. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6786. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6787. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6788. }
  6789. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6790. } else {
  6791. int num_segs, sb_idx, prod_offset;
  6792. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6793. if (!CHIP_IS_E1x(bp)) {
  6794. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6795. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6796. }
  6797. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6798. if (!CHIP_IS_E1x(bp)) {
  6799. int dsb_idx = 0;
  6800. /**
  6801. * Producer memory:
  6802. * E2 mode: address 0-135 match to the mapping memory;
  6803. * 136 - PF0 default prod; 137 - PF1 default prod;
  6804. * 138 - PF2 default prod; 139 - PF3 default prod;
  6805. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6806. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6807. * 144-147 reserved.
  6808. *
  6809. * E1.5 mode - In backward compatible mode;
  6810. * for non default SB; each even line in the memory
  6811. * holds the U producer and each odd line hold
  6812. * the C producer. The first 128 producers are for
  6813. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6814. * producers are for the DSB for each PF.
  6815. * Each PF has five segments: (the order inside each
  6816. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6817. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6818. * 144-147 attn prods;
  6819. */
  6820. /* non-default-status-blocks */
  6821. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6822. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6823. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6824. prod_offset = (bp->igu_base_sb + sb_idx) *
  6825. num_segs;
  6826. for (i = 0; i < num_segs; i++) {
  6827. addr = IGU_REG_PROD_CONS_MEMORY +
  6828. (prod_offset + i) * 4;
  6829. REG_WR(bp, addr, 0);
  6830. }
  6831. /* send consumer update with value 0 */
  6832. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6833. USTORM_ID, 0, IGU_INT_NOP, 1);
  6834. bnx2x_igu_clear_sb(bp,
  6835. bp->igu_base_sb + sb_idx);
  6836. }
  6837. /* default-status-blocks */
  6838. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6839. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6840. if (CHIP_MODE_IS_4_PORT(bp))
  6841. dsb_idx = BP_FUNC(bp);
  6842. else
  6843. dsb_idx = BP_VN(bp);
  6844. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6845. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6846. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6847. /*
  6848. * igu prods come in chunks of E1HVN_MAX (4) -
  6849. * does not matters what is the current chip mode
  6850. */
  6851. for (i = 0; i < (num_segs * E1HVN_MAX);
  6852. i += E1HVN_MAX) {
  6853. addr = IGU_REG_PROD_CONS_MEMORY +
  6854. (prod_offset + i)*4;
  6855. REG_WR(bp, addr, 0);
  6856. }
  6857. /* send consumer update with 0 */
  6858. if (CHIP_INT_MODE_IS_BC(bp)) {
  6859. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6860. USTORM_ID, 0, IGU_INT_NOP, 1);
  6861. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6862. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6863. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6864. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6865. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6866. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6867. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6868. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6869. } else {
  6870. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6871. USTORM_ID, 0, IGU_INT_NOP, 1);
  6872. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6873. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6874. }
  6875. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6876. /* !!! These should become driver const once
  6877. rf-tool supports split-68 const */
  6878. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6879. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6880. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6881. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6882. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6883. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6884. }
  6885. }
  6886. /* Reset PCIE errors for debug */
  6887. REG_WR(bp, 0x2114, 0xffffffff);
  6888. REG_WR(bp, 0x2120, 0xffffffff);
  6889. if (CHIP_IS_E1x(bp)) {
  6890. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6891. main_mem_base = HC_REG_MAIN_MEMORY +
  6892. BP_PORT(bp) * (main_mem_size * 4);
  6893. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6894. main_mem_width = 8;
  6895. val = REG_RD(bp, main_mem_prty_clr);
  6896. if (val)
  6897. DP(NETIF_MSG_HW,
  6898. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6899. val);
  6900. /* Clear "false" parity errors in MSI-X table */
  6901. for (i = main_mem_base;
  6902. i < main_mem_base + main_mem_size * 4;
  6903. i += main_mem_width) {
  6904. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6905. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6906. i, main_mem_width / 4);
  6907. }
  6908. /* Clear HC parity attention */
  6909. REG_RD(bp, main_mem_prty_clr);
  6910. }
  6911. #ifdef BNX2X_STOP_ON_ERROR
  6912. /* Enable STORMs SP logging */
  6913. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6914. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6915. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6916. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6917. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6918. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6919. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6920. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6921. #endif
  6922. bnx2x_phy_probe(&bp->link_params);
  6923. return 0;
  6924. }
  6925. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6926. {
  6927. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6928. if (!CHIP_IS_E1x(bp))
  6929. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6930. sizeof(struct host_hc_status_block_e2));
  6931. else
  6932. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6933. sizeof(struct host_hc_status_block_e1x));
  6934. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6935. }
  6936. void bnx2x_free_mem(struct bnx2x *bp)
  6937. {
  6938. int i;
  6939. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6940. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6941. if (IS_VF(bp))
  6942. return;
  6943. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6944. sizeof(struct host_sp_status_block));
  6945. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6946. sizeof(struct bnx2x_slowpath));
  6947. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6948. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6949. bp->context[i].size);
  6950. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6951. BNX2X_FREE(bp->ilt->lines);
  6952. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6953. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6954. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6955. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6956. bnx2x_iov_free_mem(bp);
  6957. }
  6958. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6959. {
  6960. if (!CHIP_IS_E1x(bp)) {
  6961. /* size = the status block + ramrod buffers */
  6962. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6963. sizeof(struct host_hc_status_block_e2));
  6964. if (!bp->cnic_sb.e2_sb)
  6965. goto alloc_mem_err;
  6966. } else {
  6967. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6968. sizeof(struct host_hc_status_block_e1x));
  6969. if (!bp->cnic_sb.e1x_sb)
  6970. goto alloc_mem_err;
  6971. }
  6972. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6973. /* allocate searcher T2 table, as it wasn't allocated before */
  6974. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6975. if (!bp->t2)
  6976. goto alloc_mem_err;
  6977. }
  6978. /* write address to which L5 should insert its values */
  6979. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6980. &bp->slowpath->drv_info_to_mcp;
  6981. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6982. goto alloc_mem_err;
  6983. return 0;
  6984. alloc_mem_err:
  6985. bnx2x_free_mem_cnic(bp);
  6986. BNX2X_ERR("Can't allocate memory\n");
  6987. return -ENOMEM;
  6988. }
  6989. int bnx2x_alloc_mem(struct bnx2x *bp)
  6990. {
  6991. int i, allocated, context_size;
  6992. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6993. /* allocate searcher T2 table */
  6994. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6995. if (!bp->t2)
  6996. goto alloc_mem_err;
  6997. }
  6998. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6999. sizeof(struct host_sp_status_block));
  7000. if (!bp->def_status_blk)
  7001. goto alloc_mem_err;
  7002. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  7003. sizeof(struct bnx2x_slowpath));
  7004. if (!bp->slowpath)
  7005. goto alloc_mem_err;
  7006. /* Allocate memory for CDU context:
  7007. * This memory is allocated separately and not in the generic ILT
  7008. * functions because CDU differs in few aspects:
  7009. * 1. There are multiple entities allocating memory for context -
  7010. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  7011. * its own ILT lines.
  7012. * 2. Since CDU page-size is not a single 4KB page (which is the case
  7013. * for the other ILT clients), to be efficient we want to support
  7014. * allocation of sub-page-size in the last entry.
  7015. * 3. Context pointers are used by the driver to pass to FW / update
  7016. * the context (for the other ILT clients the pointers are used just to
  7017. * free the memory during unload).
  7018. */
  7019. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  7020. for (i = 0, allocated = 0; allocated < context_size; i++) {
  7021. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  7022. (context_size - allocated));
  7023. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  7024. bp->context[i].size);
  7025. if (!bp->context[i].vcxt)
  7026. goto alloc_mem_err;
  7027. allocated += bp->context[i].size;
  7028. }
  7029. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  7030. GFP_KERNEL);
  7031. if (!bp->ilt->lines)
  7032. goto alloc_mem_err;
  7033. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  7034. goto alloc_mem_err;
  7035. if (bnx2x_iov_alloc_mem(bp))
  7036. goto alloc_mem_err;
  7037. /* Slow path ring */
  7038. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  7039. if (!bp->spq)
  7040. goto alloc_mem_err;
  7041. /* EQ */
  7042. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  7043. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  7044. if (!bp->eq_ring)
  7045. goto alloc_mem_err;
  7046. return 0;
  7047. alloc_mem_err:
  7048. bnx2x_free_mem(bp);
  7049. BNX2X_ERR("Can't allocate memory\n");
  7050. return -ENOMEM;
  7051. }
  7052. /*
  7053. * Init service functions
  7054. */
  7055. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7056. struct bnx2x_vlan_mac_obj *obj, bool set,
  7057. int mac_type, unsigned long *ramrod_flags)
  7058. {
  7059. int rc;
  7060. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7061. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7062. /* Fill general parameters */
  7063. ramrod_param.vlan_mac_obj = obj;
  7064. ramrod_param.ramrod_flags = *ramrod_flags;
  7065. /* Fill a user request section if needed */
  7066. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7067. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7068. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7069. /* Set the command: ADD or DEL */
  7070. if (set)
  7071. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7072. else
  7073. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7074. }
  7075. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7076. if (rc == -EEXIST) {
  7077. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7078. /* do not treat adding same MAC as error */
  7079. rc = 0;
  7080. } else if (rc < 0)
  7081. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7082. return rc;
  7083. }
  7084. int bnx2x_set_vlan_one(struct bnx2x *bp, u16 vlan,
  7085. struct bnx2x_vlan_mac_obj *obj, bool set,
  7086. unsigned long *ramrod_flags)
  7087. {
  7088. int rc;
  7089. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7090. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7091. /* Fill general parameters */
  7092. ramrod_param.vlan_mac_obj = obj;
  7093. ramrod_param.ramrod_flags = *ramrod_flags;
  7094. /* Fill a user request section if needed */
  7095. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7096. ramrod_param.user_req.u.vlan.vlan = vlan;
  7097. /* Set the command: ADD or DEL */
  7098. if (set)
  7099. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7100. else
  7101. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7102. }
  7103. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7104. if (rc == -EEXIST) {
  7105. /* Do not treat adding same vlan as error. */
  7106. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7107. rc = 0;
  7108. } else if (rc < 0) {
  7109. BNX2X_ERR("%s VLAN failed\n", (set ? "Set" : "Del"));
  7110. }
  7111. return rc;
  7112. }
  7113. int bnx2x_del_all_macs(struct bnx2x *bp,
  7114. struct bnx2x_vlan_mac_obj *mac_obj,
  7115. int mac_type, bool wait_for_comp)
  7116. {
  7117. int rc;
  7118. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7119. /* Wait for completion of requested */
  7120. if (wait_for_comp)
  7121. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7122. /* Set the mac type of addresses we want to clear */
  7123. __set_bit(mac_type, &vlan_mac_flags);
  7124. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7125. if (rc < 0)
  7126. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7127. return rc;
  7128. }
  7129. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7130. {
  7131. if (IS_PF(bp)) {
  7132. unsigned long ramrod_flags = 0;
  7133. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7134. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7135. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7136. &bp->sp_objs->mac_obj, set,
  7137. BNX2X_ETH_MAC, &ramrod_flags);
  7138. } else { /* vf */
  7139. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7140. bp->fp->index, set);
  7141. }
  7142. }
  7143. int bnx2x_setup_leading(struct bnx2x *bp)
  7144. {
  7145. if (IS_PF(bp))
  7146. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7147. else /* VF */
  7148. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7149. }
  7150. /**
  7151. * bnx2x_set_int_mode - configure interrupt mode
  7152. *
  7153. * @bp: driver handle
  7154. *
  7155. * In case of MSI-X it will also try to enable MSI-X.
  7156. */
  7157. int bnx2x_set_int_mode(struct bnx2x *bp)
  7158. {
  7159. int rc = 0;
  7160. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7161. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7162. return -EINVAL;
  7163. }
  7164. switch (int_mode) {
  7165. case BNX2X_INT_MODE_MSIX:
  7166. /* attempt to enable msix */
  7167. rc = bnx2x_enable_msix(bp);
  7168. /* msix attained */
  7169. if (!rc)
  7170. return 0;
  7171. /* vfs use only msix */
  7172. if (rc && IS_VF(bp))
  7173. return rc;
  7174. /* failed to enable multiple MSI-X */
  7175. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7176. bp->num_queues,
  7177. 1 + bp->num_cnic_queues);
  7178. /* falling through... */
  7179. case BNX2X_INT_MODE_MSI:
  7180. bnx2x_enable_msi(bp);
  7181. /* falling through... */
  7182. case BNX2X_INT_MODE_INTX:
  7183. bp->num_ethernet_queues = 1;
  7184. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7185. BNX2X_DEV_INFO("set number of queues to 1\n");
  7186. break;
  7187. default:
  7188. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7189. return -EINVAL;
  7190. }
  7191. return 0;
  7192. }
  7193. /* must be called prior to any HW initializations */
  7194. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7195. {
  7196. if (IS_SRIOV(bp))
  7197. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7198. return L2_ILT_LINES(bp);
  7199. }
  7200. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7201. {
  7202. struct ilt_client_info *ilt_client;
  7203. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7204. u16 line = 0;
  7205. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7206. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7207. /* CDU */
  7208. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7209. ilt_client->client_num = ILT_CLIENT_CDU;
  7210. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7211. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7212. ilt_client->start = line;
  7213. line += bnx2x_cid_ilt_lines(bp);
  7214. if (CNIC_SUPPORT(bp))
  7215. line += CNIC_ILT_LINES;
  7216. ilt_client->end = line - 1;
  7217. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7218. ilt_client->start,
  7219. ilt_client->end,
  7220. ilt_client->page_size,
  7221. ilt_client->flags,
  7222. ilog2(ilt_client->page_size >> 12));
  7223. /* QM */
  7224. if (QM_INIT(bp->qm_cid_count)) {
  7225. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7226. ilt_client->client_num = ILT_CLIENT_QM;
  7227. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7228. ilt_client->flags = 0;
  7229. ilt_client->start = line;
  7230. /* 4 bytes for each cid */
  7231. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7232. QM_ILT_PAGE_SZ);
  7233. ilt_client->end = line - 1;
  7234. DP(NETIF_MSG_IFUP,
  7235. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7236. ilt_client->start,
  7237. ilt_client->end,
  7238. ilt_client->page_size,
  7239. ilt_client->flags,
  7240. ilog2(ilt_client->page_size >> 12));
  7241. }
  7242. if (CNIC_SUPPORT(bp)) {
  7243. /* SRC */
  7244. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7245. ilt_client->client_num = ILT_CLIENT_SRC;
  7246. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7247. ilt_client->flags = 0;
  7248. ilt_client->start = line;
  7249. line += SRC_ILT_LINES;
  7250. ilt_client->end = line - 1;
  7251. DP(NETIF_MSG_IFUP,
  7252. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7253. ilt_client->start,
  7254. ilt_client->end,
  7255. ilt_client->page_size,
  7256. ilt_client->flags,
  7257. ilog2(ilt_client->page_size >> 12));
  7258. /* TM */
  7259. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7260. ilt_client->client_num = ILT_CLIENT_TM;
  7261. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7262. ilt_client->flags = 0;
  7263. ilt_client->start = line;
  7264. line += TM_ILT_LINES;
  7265. ilt_client->end = line - 1;
  7266. DP(NETIF_MSG_IFUP,
  7267. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7268. ilt_client->start,
  7269. ilt_client->end,
  7270. ilt_client->page_size,
  7271. ilt_client->flags,
  7272. ilog2(ilt_client->page_size >> 12));
  7273. }
  7274. BUG_ON(line > ILT_MAX_LINES);
  7275. }
  7276. /**
  7277. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7278. *
  7279. * @bp: driver handle
  7280. * @fp: pointer to fastpath
  7281. * @init_params: pointer to parameters structure
  7282. *
  7283. * parameters configured:
  7284. * - HC configuration
  7285. * - Queue's CDU context
  7286. */
  7287. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7288. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7289. {
  7290. u8 cos;
  7291. int cxt_index, cxt_offset;
  7292. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7293. if (!IS_FCOE_FP(fp)) {
  7294. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7295. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7296. /* If HC is supported, enable host coalescing in the transition
  7297. * to INIT state.
  7298. */
  7299. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7300. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7301. /* HC rate */
  7302. init_params->rx.hc_rate = bp->rx_ticks ?
  7303. (1000000 / bp->rx_ticks) : 0;
  7304. init_params->tx.hc_rate = bp->tx_ticks ?
  7305. (1000000 / bp->tx_ticks) : 0;
  7306. /* FW SB ID */
  7307. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7308. fp->fw_sb_id;
  7309. /*
  7310. * CQ index among the SB indices: FCoE clients uses the default
  7311. * SB, therefore it's different.
  7312. */
  7313. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7314. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7315. }
  7316. /* set maximum number of COSs supported by this queue */
  7317. init_params->max_cos = fp->max_cos;
  7318. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7319. fp->index, init_params->max_cos);
  7320. /* set the context pointers queue object */
  7321. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7322. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7323. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7324. ILT_PAGE_CIDS);
  7325. init_params->cxts[cos] =
  7326. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7327. }
  7328. }
  7329. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7330. struct bnx2x_queue_state_params *q_params,
  7331. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7332. int tx_index, bool leading)
  7333. {
  7334. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7335. /* Set the command */
  7336. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7337. /* Set tx-only QUEUE flags: don't zero statistics */
  7338. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7339. /* choose the index of the cid to send the slow path on */
  7340. tx_only_params->cid_index = tx_index;
  7341. /* Set general TX_ONLY_SETUP parameters */
  7342. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7343. /* Set Tx TX_ONLY_SETUP parameters */
  7344. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7345. DP(NETIF_MSG_IFUP,
  7346. "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",
  7347. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7348. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7349. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7350. /* send the ramrod */
  7351. return bnx2x_queue_state_change(bp, q_params);
  7352. }
  7353. /**
  7354. * bnx2x_setup_queue - setup queue
  7355. *
  7356. * @bp: driver handle
  7357. * @fp: pointer to fastpath
  7358. * @leading: is leading
  7359. *
  7360. * This function performs 2 steps in a Queue state machine
  7361. * actually: 1) RESET->INIT 2) INIT->SETUP
  7362. */
  7363. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7364. bool leading)
  7365. {
  7366. struct bnx2x_queue_state_params q_params = {NULL};
  7367. struct bnx2x_queue_setup_params *setup_params =
  7368. &q_params.params.setup;
  7369. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7370. &q_params.params.tx_only;
  7371. int rc;
  7372. u8 tx_index;
  7373. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7374. /* reset IGU state skip FCoE L2 queue */
  7375. if (!IS_FCOE_FP(fp))
  7376. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7377. IGU_INT_ENABLE, 0);
  7378. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7379. /* We want to wait for completion in this context */
  7380. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7381. /* Prepare the INIT parameters */
  7382. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7383. /* Set the command */
  7384. q_params.cmd = BNX2X_Q_CMD_INIT;
  7385. /* Change the state to INIT */
  7386. rc = bnx2x_queue_state_change(bp, &q_params);
  7387. if (rc) {
  7388. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7389. return rc;
  7390. }
  7391. DP(NETIF_MSG_IFUP, "init complete\n");
  7392. /* Now move the Queue to the SETUP state... */
  7393. memset(setup_params, 0, sizeof(*setup_params));
  7394. /* Set QUEUE flags */
  7395. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7396. /* Set general SETUP parameters */
  7397. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7398. FIRST_TX_COS_INDEX);
  7399. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7400. &setup_params->rxq_params);
  7401. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7402. FIRST_TX_COS_INDEX);
  7403. /* Set the command */
  7404. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7405. if (IS_FCOE_FP(fp))
  7406. bp->fcoe_init = true;
  7407. /* Change the state to SETUP */
  7408. rc = bnx2x_queue_state_change(bp, &q_params);
  7409. if (rc) {
  7410. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7411. return rc;
  7412. }
  7413. /* loop through the relevant tx-only indices */
  7414. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7415. tx_index < fp->max_cos;
  7416. tx_index++) {
  7417. /* prepare and send tx-only ramrod*/
  7418. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7419. tx_only_params, tx_index, leading);
  7420. if (rc) {
  7421. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7422. fp->index, tx_index);
  7423. return rc;
  7424. }
  7425. }
  7426. return rc;
  7427. }
  7428. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7429. {
  7430. struct bnx2x_fastpath *fp = &bp->fp[index];
  7431. struct bnx2x_fp_txdata *txdata;
  7432. struct bnx2x_queue_state_params q_params = {NULL};
  7433. int rc, tx_index;
  7434. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7435. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7436. /* We want to wait for completion in this context */
  7437. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7438. /* close tx-only connections */
  7439. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7440. tx_index < fp->max_cos;
  7441. tx_index++){
  7442. /* ascertain this is a normal queue*/
  7443. txdata = fp->txdata_ptr[tx_index];
  7444. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7445. txdata->txq_index);
  7446. /* send halt terminate on tx-only connection */
  7447. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7448. memset(&q_params.params.terminate, 0,
  7449. sizeof(q_params.params.terminate));
  7450. q_params.params.terminate.cid_index = tx_index;
  7451. rc = bnx2x_queue_state_change(bp, &q_params);
  7452. if (rc)
  7453. return rc;
  7454. /* send halt terminate on tx-only connection */
  7455. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7456. memset(&q_params.params.cfc_del, 0,
  7457. sizeof(q_params.params.cfc_del));
  7458. q_params.params.cfc_del.cid_index = tx_index;
  7459. rc = bnx2x_queue_state_change(bp, &q_params);
  7460. if (rc)
  7461. return rc;
  7462. }
  7463. /* Stop the primary connection: */
  7464. /* ...halt the connection */
  7465. q_params.cmd = BNX2X_Q_CMD_HALT;
  7466. rc = bnx2x_queue_state_change(bp, &q_params);
  7467. if (rc)
  7468. return rc;
  7469. /* ...terminate the connection */
  7470. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7471. memset(&q_params.params.terminate, 0,
  7472. sizeof(q_params.params.terminate));
  7473. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7474. rc = bnx2x_queue_state_change(bp, &q_params);
  7475. if (rc)
  7476. return rc;
  7477. /* ...delete cfc entry */
  7478. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7479. memset(&q_params.params.cfc_del, 0,
  7480. sizeof(q_params.params.cfc_del));
  7481. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7482. return bnx2x_queue_state_change(bp, &q_params);
  7483. }
  7484. static void bnx2x_reset_func(struct bnx2x *bp)
  7485. {
  7486. int port = BP_PORT(bp);
  7487. int func = BP_FUNC(bp);
  7488. int i;
  7489. /* Disable the function in the FW */
  7490. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7491. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7492. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7493. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7494. /* FP SBs */
  7495. for_each_eth_queue(bp, i) {
  7496. struct bnx2x_fastpath *fp = &bp->fp[i];
  7497. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7498. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7499. SB_DISABLED);
  7500. }
  7501. if (CNIC_LOADED(bp))
  7502. /* CNIC SB */
  7503. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7504. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7505. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7506. /* SP SB */
  7507. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7508. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7509. SB_DISABLED);
  7510. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7511. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7512. 0);
  7513. /* Configure IGU */
  7514. if (bp->common.int_block == INT_BLOCK_HC) {
  7515. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7516. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7517. } else {
  7518. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7519. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7520. }
  7521. if (CNIC_LOADED(bp)) {
  7522. /* Disable Timer scan */
  7523. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7524. /*
  7525. * Wait for at least 10ms and up to 2 second for the timers
  7526. * scan to complete
  7527. */
  7528. for (i = 0; i < 200; i++) {
  7529. usleep_range(10000, 20000);
  7530. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7531. break;
  7532. }
  7533. }
  7534. /* Clear ILT */
  7535. bnx2x_clear_func_ilt(bp, func);
  7536. /* Timers workaround bug for E2: if this is vnic-3,
  7537. * we need to set the entire ilt range for this timers.
  7538. */
  7539. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7540. struct ilt_client_info ilt_cli;
  7541. /* use dummy TM client */
  7542. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7543. ilt_cli.start = 0;
  7544. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7545. ilt_cli.client_num = ILT_CLIENT_TM;
  7546. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7547. }
  7548. /* this assumes that reset_port() called before reset_func()*/
  7549. if (!CHIP_IS_E1x(bp))
  7550. bnx2x_pf_disable(bp);
  7551. bp->dmae_ready = 0;
  7552. }
  7553. static void bnx2x_reset_port(struct bnx2x *bp)
  7554. {
  7555. int port = BP_PORT(bp);
  7556. u32 val;
  7557. /* Reset physical Link */
  7558. bnx2x__link_reset(bp);
  7559. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7560. /* Do not rcv packets to BRB */
  7561. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7562. /* Do not direct rcv packets that are not for MCP to the BRB */
  7563. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7564. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7565. /* Configure AEU */
  7566. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7567. msleep(100);
  7568. /* Check for BRB port occupancy */
  7569. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7570. if (val)
  7571. DP(NETIF_MSG_IFDOWN,
  7572. "BRB1 is not empty %d blocks are occupied\n", val);
  7573. /* TODO: Close Doorbell port? */
  7574. }
  7575. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7576. {
  7577. struct bnx2x_func_state_params func_params = {NULL};
  7578. /* Prepare parameters for function state transitions */
  7579. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7580. func_params.f_obj = &bp->func_obj;
  7581. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7582. func_params.params.hw_init.load_phase = load_code;
  7583. return bnx2x_func_state_change(bp, &func_params);
  7584. }
  7585. static int bnx2x_func_stop(struct bnx2x *bp)
  7586. {
  7587. struct bnx2x_func_state_params func_params = {NULL};
  7588. int rc;
  7589. /* Prepare parameters for function state transitions */
  7590. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7591. func_params.f_obj = &bp->func_obj;
  7592. func_params.cmd = BNX2X_F_CMD_STOP;
  7593. /*
  7594. * Try to stop the function the 'good way'. If fails (in case
  7595. * of a parity error during bnx2x_chip_cleanup()) and we are
  7596. * not in a debug mode, perform a state transaction in order to
  7597. * enable further HW_RESET transaction.
  7598. */
  7599. rc = bnx2x_func_state_change(bp, &func_params);
  7600. if (rc) {
  7601. #ifdef BNX2X_STOP_ON_ERROR
  7602. return rc;
  7603. #else
  7604. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7605. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7606. return bnx2x_func_state_change(bp, &func_params);
  7607. #endif
  7608. }
  7609. return 0;
  7610. }
  7611. /**
  7612. * bnx2x_send_unload_req - request unload mode from the MCP.
  7613. *
  7614. * @bp: driver handle
  7615. * @unload_mode: requested function's unload mode
  7616. *
  7617. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7618. */
  7619. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7620. {
  7621. u32 reset_code = 0;
  7622. int port = BP_PORT(bp);
  7623. /* Select the UNLOAD request mode */
  7624. if (unload_mode == UNLOAD_NORMAL)
  7625. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7626. else if (bp->flags & NO_WOL_FLAG)
  7627. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7628. else if (bp->wol) {
  7629. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7630. u8 *mac_addr = bp->dev->dev_addr;
  7631. struct pci_dev *pdev = bp->pdev;
  7632. u32 val;
  7633. u16 pmc;
  7634. /* The mac address is written to entries 1-4 to
  7635. * preserve entry 0 which is used by the PMF
  7636. */
  7637. u8 entry = (BP_VN(bp) + 1)*8;
  7638. val = (mac_addr[0] << 8) | mac_addr[1];
  7639. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7640. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7641. (mac_addr[4] << 8) | mac_addr[5];
  7642. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7643. /* Enable the PME and clear the status */
  7644. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7645. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7646. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7647. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7648. } else
  7649. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7650. /* Send the request to the MCP */
  7651. if (!BP_NOMCP(bp))
  7652. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7653. else {
  7654. int path = BP_PATH(bp);
  7655. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7656. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7657. bnx2x_load_count[path][2]);
  7658. bnx2x_load_count[path][0]--;
  7659. bnx2x_load_count[path][1 + port]--;
  7660. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7661. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7662. bnx2x_load_count[path][2]);
  7663. if (bnx2x_load_count[path][0] == 0)
  7664. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7665. else if (bnx2x_load_count[path][1 + port] == 0)
  7666. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7667. else
  7668. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7669. }
  7670. return reset_code;
  7671. }
  7672. /**
  7673. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7674. *
  7675. * @bp: driver handle
  7676. * @keep_link: true iff link should be kept up
  7677. */
  7678. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7679. {
  7680. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7681. /* Report UNLOAD_DONE to MCP */
  7682. if (!BP_NOMCP(bp))
  7683. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7684. }
  7685. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7686. {
  7687. int tout = 50;
  7688. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7689. if (!bp->port.pmf)
  7690. return 0;
  7691. /*
  7692. * (assumption: No Attention from MCP at this stage)
  7693. * PMF probably in the middle of TX disable/enable transaction
  7694. * 1. Sync IRS for default SB
  7695. * 2. Sync SP queue - this guarantees us that attention handling started
  7696. * 3. Wait, that TX disable/enable transaction completes
  7697. *
  7698. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7699. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7700. * received completion for the transaction the state is TX_STOPPED.
  7701. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7702. * transaction.
  7703. */
  7704. /* make sure default SB ISR is done */
  7705. if (msix)
  7706. synchronize_irq(bp->msix_table[0].vector);
  7707. else
  7708. synchronize_irq(bp->pdev->irq);
  7709. flush_workqueue(bnx2x_wq);
  7710. flush_workqueue(bnx2x_iov_wq);
  7711. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7712. BNX2X_F_STATE_STARTED && tout--)
  7713. msleep(20);
  7714. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7715. BNX2X_F_STATE_STARTED) {
  7716. #ifdef BNX2X_STOP_ON_ERROR
  7717. BNX2X_ERR("Wrong function state\n");
  7718. return -EBUSY;
  7719. #else
  7720. /*
  7721. * Failed to complete the transaction in a "good way"
  7722. * Force both transactions with CLR bit
  7723. */
  7724. struct bnx2x_func_state_params func_params = {NULL};
  7725. DP(NETIF_MSG_IFDOWN,
  7726. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7727. func_params.f_obj = &bp->func_obj;
  7728. __set_bit(RAMROD_DRV_CLR_ONLY,
  7729. &func_params.ramrod_flags);
  7730. /* STARTED-->TX_ST0PPED */
  7731. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7732. bnx2x_func_state_change(bp, &func_params);
  7733. /* TX_ST0PPED-->STARTED */
  7734. func_params.cmd = BNX2X_F_CMD_TX_START;
  7735. return bnx2x_func_state_change(bp, &func_params);
  7736. #endif
  7737. }
  7738. return 0;
  7739. }
  7740. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7741. {
  7742. int port = BP_PORT(bp);
  7743. /* Disable sending PTP packets to host */
  7744. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7745. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7746. /* Reset PTP event detection rules */
  7747. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7748. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7749. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7750. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7751. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7752. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7753. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7754. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7755. /* Disable the PTP feature */
  7756. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7757. NIG_REG_P0_PTP_EN, 0x0);
  7758. }
  7759. /* Called during unload, to stop PTP-related stuff */
  7760. static void bnx2x_stop_ptp(struct bnx2x *bp)
  7761. {
  7762. /* Cancel PTP work queue. Should be done after the Tx queues are
  7763. * drained to prevent additional scheduling.
  7764. */
  7765. cancel_work_sync(&bp->ptp_task);
  7766. if (bp->ptp_tx_skb) {
  7767. dev_kfree_skb_any(bp->ptp_tx_skb);
  7768. bp->ptp_tx_skb = NULL;
  7769. }
  7770. /* Disable PTP in HW */
  7771. bnx2x_disable_ptp(bp);
  7772. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7773. }
  7774. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7775. {
  7776. int port = BP_PORT(bp);
  7777. int i, rc = 0;
  7778. u8 cos;
  7779. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7780. u32 reset_code;
  7781. /* Wait until tx fastpath tasks complete */
  7782. for_each_tx_queue(bp, i) {
  7783. struct bnx2x_fastpath *fp = &bp->fp[i];
  7784. for_each_cos_in_tx_queue(fp, cos)
  7785. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7786. #ifdef BNX2X_STOP_ON_ERROR
  7787. if (rc)
  7788. return;
  7789. #endif
  7790. }
  7791. /* Give HW time to discard old tx messages */
  7792. usleep_range(1000, 2000);
  7793. /* Clean all ETH MACs */
  7794. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7795. false);
  7796. if (rc < 0)
  7797. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7798. /* Clean up UC list */
  7799. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7800. true);
  7801. if (rc < 0)
  7802. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7803. rc);
  7804. /* Disable LLH */
  7805. if (!CHIP_IS_E1(bp))
  7806. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7807. /* Set "drop all" (stop Rx).
  7808. * We need to take a netif_addr_lock() here in order to prevent
  7809. * a race between the completion code and this code.
  7810. */
  7811. netif_addr_lock_bh(bp->dev);
  7812. /* Schedule the rx_mode command */
  7813. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7814. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7815. else
  7816. bnx2x_set_storm_rx_mode(bp);
  7817. /* Cleanup multicast configuration */
  7818. rparam.mcast_obj = &bp->mcast_obj;
  7819. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7820. if (rc < 0)
  7821. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7822. netif_addr_unlock_bh(bp->dev);
  7823. bnx2x_iov_chip_cleanup(bp);
  7824. /*
  7825. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7826. * this function should perform FUNC, PORT or COMMON HW
  7827. * reset.
  7828. */
  7829. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7830. /*
  7831. * (assumption: No Attention from MCP at this stage)
  7832. * PMF probably in the middle of TX disable/enable transaction
  7833. */
  7834. rc = bnx2x_func_wait_started(bp);
  7835. if (rc) {
  7836. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7837. #ifdef BNX2X_STOP_ON_ERROR
  7838. return;
  7839. #endif
  7840. }
  7841. /* Close multi and leading connections
  7842. * Completions for ramrods are collected in a synchronous way
  7843. */
  7844. for_each_eth_queue(bp, i)
  7845. if (bnx2x_stop_queue(bp, i))
  7846. #ifdef BNX2X_STOP_ON_ERROR
  7847. return;
  7848. #else
  7849. goto unload_error;
  7850. #endif
  7851. if (CNIC_LOADED(bp)) {
  7852. for_each_cnic_queue(bp, i)
  7853. if (bnx2x_stop_queue(bp, i))
  7854. #ifdef BNX2X_STOP_ON_ERROR
  7855. return;
  7856. #else
  7857. goto unload_error;
  7858. #endif
  7859. }
  7860. /* If SP settings didn't get completed so far - something
  7861. * very wrong has happen.
  7862. */
  7863. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7864. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7865. #ifndef BNX2X_STOP_ON_ERROR
  7866. unload_error:
  7867. #endif
  7868. rc = bnx2x_func_stop(bp);
  7869. if (rc) {
  7870. BNX2X_ERR("Function stop failed!\n");
  7871. #ifdef BNX2X_STOP_ON_ERROR
  7872. return;
  7873. #endif
  7874. }
  7875. /* stop_ptp should be after the Tx queues are drained to prevent
  7876. * scheduling to the cancelled PTP work queue. It should also be after
  7877. * function stop ramrod is sent, since as part of this ramrod FW access
  7878. * PTP registers.
  7879. */
  7880. if (bp->flags & PTP_SUPPORTED)
  7881. bnx2x_stop_ptp(bp);
  7882. /* Disable HW interrupts, NAPI */
  7883. bnx2x_netif_stop(bp, 1);
  7884. /* Delete all NAPI objects */
  7885. bnx2x_del_all_napi(bp);
  7886. if (CNIC_LOADED(bp))
  7887. bnx2x_del_all_napi_cnic(bp);
  7888. /* Release IRQs */
  7889. bnx2x_free_irq(bp);
  7890. /* Reset the chip */
  7891. rc = bnx2x_reset_hw(bp, reset_code);
  7892. if (rc)
  7893. BNX2X_ERR("HW_RESET failed\n");
  7894. /* Report UNLOAD_DONE to MCP */
  7895. bnx2x_send_unload_done(bp, keep_link);
  7896. }
  7897. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7898. {
  7899. u32 val;
  7900. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7901. if (CHIP_IS_E1(bp)) {
  7902. int port = BP_PORT(bp);
  7903. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7904. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7905. val = REG_RD(bp, addr);
  7906. val &= ~(0x300);
  7907. REG_WR(bp, addr, val);
  7908. } else {
  7909. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7910. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7911. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7912. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7913. }
  7914. }
  7915. /* Close gates #2, #3 and #4: */
  7916. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7917. {
  7918. u32 val;
  7919. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7920. if (!CHIP_IS_E1(bp)) {
  7921. /* #4 */
  7922. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7923. /* #2 */
  7924. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7925. }
  7926. /* #3 */
  7927. if (CHIP_IS_E1x(bp)) {
  7928. /* Prevent interrupts from HC on both ports */
  7929. val = REG_RD(bp, HC_REG_CONFIG_1);
  7930. REG_WR(bp, HC_REG_CONFIG_1,
  7931. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7932. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7933. val = REG_RD(bp, HC_REG_CONFIG_0);
  7934. REG_WR(bp, HC_REG_CONFIG_0,
  7935. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7936. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7937. } else {
  7938. /* Prevent incoming interrupts in IGU */
  7939. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7940. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7941. (!close) ?
  7942. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7943. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7944. }
  7945. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7946. close ? "closing" : "opening");
  7947. mmiowb();
  7948. }
  7949. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7950. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7951. {
  7952. /* Do some magic... */
  7953. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7954. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7955. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7956. }
  7957. /**
  7958. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7959. *
  7960. * @bp: driver handle
  7961. * @magic_val: old value of the `magic' bit.
  7962. */
  7963. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7964. {
  7965. /* Restore the `magic' bit value... */
  7966. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7967. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7968. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7969. }
  7970. /**
  7971. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7972. *
  7973. * @bp: driver handle
  7974. * @magic_val: old value of 'magic' bit.
  7975. *
  7976. * Takes care of CLP configurations.
  7977. */
  7978. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7979. {
  7980. u32 shmem;
  7981. u32 validity_offset;
  7982. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7983. /* Set `magic' bit in order to save MF config */
  7984. if (!CHIP_IS_E1(bp))
  7985. bnx2x_clp_reset_prep(bp, magic_val);
  7986. /* Get shmem offset */
  7987. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7988. validity_offset =
  7989. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7990. /* Clear validity map flags */
  7991. if (shmem > 0)
  7992. REG_WR(bp, shmem + validity_offset, 0);
  7993. }
  7994. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7995. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7996. /**
  7997. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7998. *
  7999. * @bp: driver handle
  8000. */
  8001. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  8002. {
  8003. /* special handling for emulation and FPGA,
  8004. wait 10 times longer */
  8005. if (CHIP_REV_IS_SLOW(bp))
  8006. msleep(MCP_ONE_TIMEOUT*10);
  8007. else
  8008. msleep(MCP_ONE_TIMEOUT);
  8009. }
  8010. /*
  8011. * initializes bp->common.shmem_base and waits for validity signature to appear
  8012. */
  8013. static int bnx2x_init_shmem(struct bnx2x *bp)
  8014. {
  8015. int cnt = 0;
  8016. u32 val = 0;
  8017. do {
  8018. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  8019. if (bp->common.shmem_base) {
  8020. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  8021. if (val & SHR_MEM_VALIDITY_MB)
  8022. return 0;
  8023. }
  8024. bnx2x_mcp_wait_one(bp);
  8025. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  8026. BNX2X_ERR("BAD MCP validity signature\n");
  8027. return -ENODEV;
  8028. }
  8029. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  8030. {
  8031. int rc = bnx2x_init_shmem(bp);
  8032. /* Restore the `magic' bit value */
  8033. if (!CHIP_IS_E1(bp))
  8034. bnx2x_clp_reset_done(bp, magic_val);
  8035. return rc;
  8036. }
  8037. static void bnx2x_pxp_prep(struct bnx2x *bp)
  8038. {
  8039. if (!CHIP_IS_E1(bp)) {
  8040. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  8041. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  8042. mmiowb();
  8043. }
  8044. }
  8045. /*
  8046. * Reset the whole chip except for:
  8047. * - PCIE core
  8048. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  8049. * one reset bit)
  8050. * - IGU
  8051. * - MISC (including AEU)
  8052. * - GRC
  8053. * - RBCN, RBCP
  8054. */
  8055. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  8056. {
  8057. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  8058. u32 global_bits2, stay_reset2;
  8059. /*
  8060. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  8061. * (per chip) blocks.
  8062. */
  8063. global_bits2 =
  8064. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  8065. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  8066. /* Don't reset the following blocks.
  8067. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  8068. * reset, as in 4 port device they might still be owned
  8069. * by the MCP (there is only one leader per path).
  8070. */
  8071. not_reset_mask1 =
  8072. MISC_REGISTERS_RESET_REG_1_RST_HC |
  8073. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  8074. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  8075. not_reset_mask2 =
  8076. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  8077. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8078. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8079. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8080. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8081. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8082. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8083. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8084. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8085. MISC_REGISTERS_RESET_REG_2_PGLC |
  8086. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8087. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8088. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8089. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8090. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8091. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8092. /*
  8093. * Keep the following blocks in reset:
  8094. * - all xxMACs are handled by the bnx2x_link code.
  8095. */
  8096. stay_reset2 =
  8097. MISC_REGISTERS_RESET_REG_2_XMAC |
  8098. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8099. /* Full reset masks according to the chip */
  8100. reset_mask1 = 0xffffffff;
  8101. if (CHIP_IS_E1(bp))
  8102. reset_mask2 = 0xffff;
  8103. else if (CHIP_IS_E1H(bp))
  8104. reset_mask2 = 0x1ffff;
  8105. else if (CHIP_IS_E2(bp))
  8106. reset_mask2 = 0xfffff;
  8107. else /* CHIP_IS_E3 */
  8108. reset_mask2 = 0x3ffffff;
  8109. /* Don't reset global blocks unless we need to */
  8110. if (!global)
  8111. reset_mask2 &= ~global_bits2;
  8112. /*
  8113. * In case of attention in the QM, we need to reset PXP
  8114. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8115. * because otherwise QM reset would release 'close the gates' shortly
  8116. * before resetting the PXP, then the PSWRQ would send a write
  8117. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8118. * read the payload data from PSWWR, but PSWWR would not
  8119. * respond. The write queue in PGLUE would stuck, dmae commands
  8120. * would not return. Therefore it's important to reset the second
  8121. * reset register (containing the
  8122. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8123. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8124. * bit).
  8125. */
  8126. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8127. reset_mask2 & (~not_reset_mask2));
  8128. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8129. reset_mask1 & (~not_reset_mask1));
  8130. barrier();
  8131. mmiowb();
  8132. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8133. reset_mask2 & (~stay_reset2));
  8134. barrier();
  8135. mmiowb();
  8136. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8137. mmiowb();
  8138. }
  8139. /**
  8140. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8141. * It should get cleared in no more than 1s.
  8142. *
  8143. * @bp: driver handle
  8144. *
  8145. * It should get cleared in no more than 1s. Returns 0 if
  8146. * pending writes bit gets cleared.
  8147. */
  8148. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8149. {
  8150. u32 cnt = 1000;
  8151. u32 pend_bits = 0;
  8152. do {
  8153. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8154. if (pend_bits == 0)
  8155. break;
  8156. usleep_range(1000, 2000);
  8157. } while (cnt-- > 0);
  8158. if (cnt <= 0) {
  8159. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8160. pend_bits);
  8161. return -EBUSY;
  8162. }
  8163. return 0;
  8164. }
  8165. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8166. {
  8167. int cnt = 1000;
  8168. u32 val = 0;
  8169. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8170. u32 tags_63_32 = 0;
  8171. /* Empty the Tetris buffer, wait for 1s */
  8172. do {
  8173. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8174. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8175. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8176. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8177. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8178. if (CHIP_IS_E3(bp))
  8179. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8180. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8181. ((port_is_idle_0 & 0x1) == 0x1) &&
  8182. ((port_is_idle_1 & 0x1) == 0x1) &&
  8183. (pgl_exp_rom2 == 0xffffffff) &&
  8184. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8185. break;
  8186. usleep_range(1000, 2000);
  8187. } while (cnt-- > 0);
  8188. if (cnt <= 0) {
  8189. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8190. 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",
  8191. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8192. pgl_exp_rom2);
  8193. return -EAGAIN;
  8194. }
  8195. barrier();
  8196. /* Close gates #2, #3 and #4 */
  8197. bnx2x_set_234_gates(bp, true);
  8198. /* Poll for IGU VQs for 57712 and newer chips */
  8199. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8200. return -EAGAIN;
  8201. /* TBD: Indicate that "process kill" is in progress to MCP */
  8202. /* Clear "unprepared" bit */
  8203. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8204. barrier();
  8205. /* Make sure all is written to the chip before the reset */
  8206. mmiowb();
  8207. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8208. * PSWHST, GRC and PSWRD Tetris buffer.
  8209. */
  8210. usleep_range(1000, 2000);
  8211. /* Prepare to chip reset: */
  8212. /* MCP */
  8213. if (global)
  8214. bnx2x_reset_mcp_prep(bp, &val);
  8215. /* PXP */
  8216. bnx2x_pxp_prep(bp);
  8217. barrier();
  8218. /* reset the chip */
  8219. bnx2x_process_kill_chip_reset(bp, global);
  8220. barrier();
  8221. /* clear errors in PGB */
  8222. if (!CHIP_IS_E1x(bp))
  8223. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8224. /* Recover after reset: */
  8225. /* MCP */
  8226. if (global && bnx2x_reset_mcp_comp(bp, val))
  8227. return -EAGAIN;
  8228. /* TBD: Add resetting the NO_MCP mode DB here */
  8229. /* Open the gates #2, #3 and #4 */
  8230. bnx2x_set_234_gates(bp, false);
  8231. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8232. * reset state, re-enable attentions. */
  8233. return 0;
  8234. }
  8235. static int bnx2x_leader_reset(struct bnx2x *bp)
  8236. {
  8237. int rc = 0;
  8238. bool global = bnx2x_reset_is_global(bp);
  8239. u32 load_code;
  8240. /* if not going to reset MCP - load "fake" driver to reset HW while
  8241. * driver is owner of the HW
  8242. */
  8243. if (!global && !BP_NOMCP(bp)) {
  8244. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8245. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8246. if (!load_code) {
  8247. BNX2X_ERR("MCP response failure, aborting\n");
  8248. rc = -EAGAIN;
  8249. goto exit_leader_reset;
  8250. }
  8251. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8252. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8253. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8254. rc = -EAGAIN;
  8255. goto exit_leader_reset2;
  8256. }
  8257. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8258. if (!load_code) {
  8259. BNX2X_ERR("MCP response failure, aborting\n");
  8260. rc = -EAGAIN;
  8261. goto exit_leader_reset2;
  8262. }
  8263. }
  8264. /* Try to recover after the failure */
  8265. if (bnx2x_process_kill(bp, global)) {
  8266. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8267. BP_PATH(bp));
  8268. rc = -EAGAIN;
  8269. goto exit_leader_reset2;
  8270. }
  8271. /*
  8272. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8273. * state.
  8274. */
  8275. bnx2x_set_reset_done(bp);
  8276. if (global)
  8277. bnx2x_clear_reset_global(bp);
  8278. exit_leader_reset2:
  8279. /* unload "fake driver" if it was loaded */
  8280. if (!global && !BP_NOMCP(bp)) {
  8281. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8282. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8283. }
  8284. exit_leader_reset:
  8285. bp->is_leader = 0;
  8286. bnx2x_release_leader_lock(bp);
  8287. smp_mb();
  8288. return rc;
  8289. }
  8290. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8291. {
  8292. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8293. /* Disconnect this device */
  8294. netif_device_detach(bp->dev);
  8295. /*
  8296. * Block ifup for all function on this engine until "process kill"
  8297. * or power cycle.
  8298. */
  8299. bnx2x_set_reset_in_progress(bp);
  8300. /* Shut down the power */
  8301. bnx2x_set_power_state(bp, PCI_D3hot);
  8302. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8303. smp_mb();
  8304. }
  8305. /*
  8306. * Assumption: runs under rtnl lock. This together with the fact
  8307. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8308. * will never be called when netif_running(bp->dev) is false.
  8309. */
  8310. static void bnx2x_parity_recover(struct bnx2x *bp)
  8311. {
  8312. bool global = false;
  8313. u32 error_recovered, error_unrecovered;
  8314. bool is_parity;
  8315. DP(NETIF_MSG_HW, "Handling parity\n");
  8316. while (1) {
  8317. switch (bp->recovery_state) {
  8318. case BNX2X_RECOVERY_INIT:
  8319. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8320. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8321. WARN_ON(!is_parity);
  8322. /* Try to get a LEADER_LOCK HW lock */
  8323. if (bnx2x_trylock_leader_lock(bp)) {
  8324. bnx2x_set_reset_in_progress(bp);
  8325. /*
  8326. * Check if there is a global attention and if
  8327. * there was a global attention, set the global
  8328. * reset bit.
  8329. */
  8330. if (global)
  8331. bnx2x_set_reset_global(bp);
  8332. bp->is_leader = 1;
  8333. }
  8334. /* Stop the driver */
  8335. /* If interface has been removed - break */
  8336. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8337. return;
  8338. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8339. /* Ensure "is_leader", MCP command sequence and
  8340. * "recovery_state" update values are seen on other
  8341. * CPUs.
  8342. */
  8343. smp_mb();
  8344. break;
  8345. case BNX2X_RECOVERY_WAIT:
  8346. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8347. if (bp->is_leader) {
  8348. int other_engine = BP_PATH(bp) ? 0 : 1;
  8349. bool other_load_status =
  8350. bnx2x_get_load_status(bp, other_engine);
  8351. bool load_status =
  8352. bnx2x_get_load_status(bp, BP_PATH(bp));
  8353. global = bnx2x_reset_is_global(bp);
  8354. /*
  8355. * In case of a parity in a global block, let
  8356. * the first leader that performs a
  8357. * leader_reset() reset the global blocks in
  8358. * order to clear global attentions. Otherwise
  8359. * the gates will remain closed for that
  8360. * engine.
  8361. */
  8362. if (load_status ||
  8363. (global && other_load_status)) {
  8364. /* Wait until all other functions get
  8365. * down.
  8366. */
  8367. schedule_delayed_work(&bp->sp_rtnl_task,
  8368. HZ/10);
  8369. return;
  8370. } else {
  8371. /* If all other functions got down -
  8372. * try to bring the chip back to
  8373. * normal. In any case it's an exit
  8374. * point for a leader.
  8375. */
  8376. if (bnx2x_leader_reset(bp)) {
  8377. bnx2x_recovery_failed(bp);
  8378. return;
  8379. }
  8380. /* If we are here, means that the
  8381. * leader has succeeded and doesn't
  8382. * want to be a leader any more. Try
  8383. * to continue as a none-leader.
  8384. */
  8385. break;
  8386. }
  8387. } else { /* non-leader */
  8388. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8389. /* Try to get a LEADER_LOCK HW lock as
  8390. * long as a former leader may have
  8391. * been unloaded by the user or
  8392. * released a leadership by another
  8393. * reason.
  8394. */
  8395. if (bnx2x_trylock_leader_lock(bp)) {
  8396. /* I'm a leader now! Restart a
  8397. * switch case.
  8398. */
  8399. bp->is_leader = 1;
  8400. break;
  8401. }
  8402. schedule_delayed_work(&bp->sp_rtnl_task,
  8403. HZ/10);
  8404. return;
  8405. } else {
  8406. /*
  8407. * If there was a global attention, wait
  8408. * for it to be cleared.
  8409. */
  8410. if (bnx2x_reset_is_global(bp)) {
  8411. schedule_delayed_work(
  8412. &bp->sp_rtnl_task,
  8413. HZ/10);
  8414. return;
  8415. }
  8416. error_recovered =
  8417. bp->eth_stats.recoverable_error;
  8418. error_unrecovered =
  8419. bp->eth_stats.unrecoverable_error;
  8420. bp->recovery_state =
  8421. BNX2X_RECOVERY_NIC_LOADING;
  8422. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8423. error_unrecovered++;
  8424. netdev_err(bp->dev,
  8425. "Recovery failed. Power cycle needed\n");
  8426. /* Disconnect this device */
  8427. netif_device_detach(bp->dev);
  8428. /* Shut down the power */
  8429. bnx2x_set_power_state(
  8430. bp, PCI_D3hot);
  8431. smp_mb();
  8432. } else {
  8433. bp->recovery_state =
  8434. BNX2X_RECOVERY_DONE;
  8435. error_recovered++;
  8436. smp_mb();
  8437. }
  8438. bp->eth_stats.recoverable_error =
  8439. error_recovered;
  8440. bp->eth_stats.unrecoverable_error =
  8441. error_unrecovered;
  8442. return;
  8443. }
  8444. }
  8445. default:
  8446. return;
  8447. }
  8448. }
  8449. }
  8450. static int bnx2x_udp_port_update(struct bnx2x *bp)
  8451. {
  8452. struct bnx2x_func_switch_update_params *switch_update_params;
  8453. struct bnx2x_func_state_params func_params = {NULL};
  8454. struct bnx2x_udp_tunnel *udp_tunnel;
  8455. u16 vxlan_port = 0, geneve_port = 0;
  8456. int rc;
  8457. switch_update_params = &func_params.params.switch_update;
  8458. /* Prepare parameters for function state transitions */
  8459. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  8460. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  8461. func_params.f_obj = &bp->func_obj;
  8462. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  8463. /* Function parameters */
  8464. __set_bit(BNX2X_F_UPDATE_TUNNEL_CFG_CHNG,
  8465. &switch_update_params->changes);
  8466. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count) {
  8467. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE];
  8468. geneve_port = udp_tunnel->dst_port;
  8469. switch_update_params->geneve_dst_port = geneve_port;
  8470. }
  8471. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count) {
  8472. udp_tunnel = &bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN];
  8473. vxlan_port = udp_tunnel->dst_port;
  8474. switch_update_params->vxlan_dst_port = vxlan_port;
  8475. }
  8476. /* Re-enable inner-rss for the offloaded UDP tunnels */
  8477. __set_bit(BNX2X_F_UPDATE_TUNNEL_INNER_RSS,
  8478. &switch_update_params->changes);
  8479. rc = bnx2x_func_state_change(bp, &func_params);
  8480. if (rc)
  8481. BNX2X_ERR("failed to set UDP dst port to %04x %04x (rc = 0x%x)\n",
  8482. vxlan_port, geneve_port, rc);
  8483. else
  8484. DP(BNX2X_MSG_SP,
  8485. "Configured UDP ports: Vxlan [%04x] Geneve [%04x]\n",
  8486. vxlan_port, geneve_port);
  8487. return rc;
  8488. }
  8489. static void __bnx2x_add_udp_port(struct bnx2x *bp, u16 port,
  8490. enum bnx2x_udp_port_type type)
  8491. {
  8492. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8493. if (!netif_running(bp->dev) || !IS_PF(bp))
  8494. return;
  8495. if (udp_port->count && udp_port->dst_port == port) {
  8496. udp_port->count++;
  8497. return;
  8498. }
  8499. if (udp_port->count) {
  8500. DP(BNX2X_MSG_SP,
  8501. "UDP tunnel [%d] - destination port limit reached\n",
  8502. type);
  8503. return;
  8504. }
  8505. udp_port->dst_port = port;
  8506. udp_port->count = 1;
  8507. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8508. }
  8509. static void __bnx2x_del_udp_port(struct bnx2x *bp, u16 port,
  8510. enum bnx2x_udp_port_type type)
  8511. {
  8512. struct bnx2x_udp_tunnel *udp_port = &bp->udp_tunnel_ports[type];
  8513. if (!IS_PF(bp))
  8514. return;
  8515. if (!udp_port->count || udp_port->dst_port != port) {
  8516. DP(BNX2X_MSG_SP, "Invalid UDP tunnel [%d] port\n",
  8517. type);
  8518. return;
  8519. }
  8520. /* Remove reference, and make certain it's no longer in use */
  8521. udp_port->count--;
  8522. if (udp_port->count)
  8523. return;
  8524. udp_port->dst_port = 0;
  8525. if (netif_running(bp->dev))
  8526. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_CHANGE_UDP_PORT, 0);
  8527. else
  8528. DP(BNX2X_MSG_SP, "Deleted UDP tunnel [%d] port %d\n",
  8529. type, port);
  8530. }
  8531. static void bnx2x_udp_tunnel_add(struct net_device *netdev,
  8532. struct udp_tunnel_info *ti)
  8533. {
  8534. struct bnx2x *bp = netdev_priv(netdev);
  8535. u16 t_port = ntohs(ti->port);
  8536. switch (ti->type) {
  8537. case UDP_TUNNEL_TYPE_VXLAN:
  8538. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8539. break;
  8540. case UDP_TUNNEL_TYPE_GENEVE:
  8541. __bnx2x_add_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8542. break;
  8543. default:
  8544. break;
  8545. }
  8546. }
  8547. static void bnx2x_udp_tunnel_del(struct net_device *netdev,
  8548. struct udp_tunnel_info *ti)
  8549. {
  8550. struct bnx2x *bp = netdev_priv(netdev);
  8551. u16 t_port = ntohs(ti->port);
  8552. switch (ti->type) {
  8553. case UDP_TUNNEL_TYPE_VXLAN:
  8554. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_VXLAN);
  8555. break;
  8556. case UDP_TUNNEL_TYPE_GENEVE:
  8557. __bnx2x_del_udp_port(bp, t_port, BNX2X_UDP_PORT_GENEVE);
  8558. break;
  8559. default:
  8560. break;
  8561. }
  8562. }
  8563. static int bnx2x_close(struct net_device *dev);
  8564. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8565. * scheduled on a general queue in order to prevent a dead lock.
  8566. */
  8567. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8568. {
  8569. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8570. rtnl_lock();
  8571. if (!netif_running(bp->dev)) {
  8572. rtnl_unlock();
  8573. return;
  8574. }
  8575. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8576. #ifdef BNX2X_STOP_ON_ERROR
  8577. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8578. "you will need to reboot when done\n");
  8579. goto sp_rtnl_not_reset;
  8580. #endif
  8581. /*
  8582. * Clear all pending SP commands as we are going to reset the
  8583. * function anyway.
  8584. */
  8585. bp->sp_rtnl_state = 0;
  8586. smp_mb();
  8587. bnx2x_parity_recover(bp);
  8588. rtnl_unlock();
  8589. return;
  8590. }
  8591. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8592. #ifdef BNX2X_STOP_ON_ERROR
  8593. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8594. "you will need to reboot when done\n");
  8595. goto sp_rtnl_not_reset;
  8596. #endif
  8597. /*
  8598. * Clear all pending SP commands as we are going to reset the
  8599. * function anyway.
  8600. */
  8601. bp->sp_rtnl_state = 0;
  8602. smp_mb();
  8603. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8604. bnx2x_nic_load(bp, LOAD_NORMAL);
  8605. rtnl_unlock();
  8606. return;
  8607. }
  8608. #ifdef BNX2X_STOP_ON_ERROR
  8609. sp_rtnl_not_reset:
  8610. #endif
  8611. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8612. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8613. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8614. bnx2x_after_function_update(bp);
  8615. /*
  8616. * in case of fan failure we need to reset id if the "stop on error"
  8617. * debug flag is set, since we trying to prevent permanent overheating
  8618. * damage
  8619. */
  8620. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8621. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8622. netif_device_detach(bp->dev);
  8623. bnx2x_close(bp->dev);
  8624. rtnl_unlock();
  8625. return;
  8626. }
  8627. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8628. DP(BNX2X_MSG_SP,
  8629. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8630. bnx2x_vfpf_set_mcast(bp->dev);
  8631. }
  8632. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8633. &bp->sp_rtnl_state)){
  8634. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8635. bnx2x_tx_disable(bp);
  8636. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8637. }
  8638. }
  8639. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8640. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8641. bnx2x_set_rx_mode_inner(bp);
  8642. }
  8643. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8644. &bp->sp_rtnl_state))
  8645. bnx2x_pf_set_vfs_vlan(bp);
  8646. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8647. bnx2x_dcbx_stop_hw_tx(bp);
  8648. bnx2x_dcbx_resume_hw_tx(bp);
  8649. }
  8650. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8651. &bp->sp_rtnl_state))
  8652. bnx2x_update_mng_version(bp);
  8653. if (test_and_clear_bit(BNX2X_SP_RTNL_CHANGE_UDP_PORT,
  8654. &bp->sp_rtnl_state)) {
  8655. if (bnx2x_udp_port_update(bp)) {
  8656. /* On error, forget configuration */
  8657. memset(bp->udp_tunnel_ports, 0,
  8658. sizeof(struct bnx2x_udp_tunnel) *
  8659. BNX2X_UDP_PORT_MAX);
  8660. } else {
  8661. /* Since we don't store additional port information,
  8662. * if no ports are configured for any feature ask for
  8663. * information about currently configured ports.
  8664. */
  8665. if (!bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count &&
  8666. !bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count)
  8667. udp_tunnel_get_rx_info(bp->dev);
  8668. }
  8669. }
  8670. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8671. * can be called from other contexts as well)
  8672. */
  8673. rtnl_unlock();
  8674. /* enable SR-IOV if applicable */
  8675. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8676. &bp->sp_rtnl_state)) {
  8677. bnx2x_disable_sriov(bp);
  8678. bnx2x_enable_sriov(bp);
  8679. }
  8680. }
  8681. static void bnx2x_period_task(struct work_struct *work)
  8682. {
  8683. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8684. if (!netif_running(bp->dev))
  8685. goto period_task_exit;
  8686. if (CHIP_REV_IS_SLOW(bp)) {
  8687. BNX2X_ERR("period task called on emulation, ignoring\n");
  8688. goto period_task_exit;
  8689. }
  8690. bnx2x_acquire_phy_lock(bp);
  8691. /*
  8692. * The barrier is needed to ensure the ordering between the writing to
  8693. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8694. * the reading here.
  8695. */
  8696. smp_mb();
  8697. if (bp->port.pmf) {
  8698. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8699. /* Re-queue task in 1 sec */
  8700. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8701. }
  8702. bnx2x_release_phy_lock(bp);
  8703. period_task_exit:
  8704. return;
  8705. }
  8706. /*
  8707. * Init service functions
  8708. */
  8709. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8710. {
  8711. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8712. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8713. return base + (BP_ABS_FUNC(bp)) * stride;
  8714. }
  8715. static bool bnx2x_prev_unload_close_umac(struct bnx2x *bp,
  8716. u8 port, u32 reset_reg,
  8717. struct bnx2x_mac_vals *vals)
  8718. {
  8719. u32 mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8720. u32 base_addr;
  8721. if (!(mask & reset_reg))
  8722. return false;
  8723. BNX2X_DEV_INFO("Disable umac Rx %02x\n", port);
  8724. base_addr = port ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8725. vals->umac_addr[port] = base_addr + UMAC_REG_COMMAND_CONFIG;
  8726. vals->umac_val[port] = REG_RD(bp, vals->umac_addr[port]);
  8727. REG_WR(bp, vals->umac_addr[port], 0);
  8728. return true;
  8729. }
  8730. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8731. struct bnx2x_mac_vals *vals)
  8732. {
  8733. u32 val, base_addr, offset, mask, reset_reg;
  8734. bool mac_stopped = false;
  8735. u8 port = BP_PORT(bp);
  8736. /* reset addresses as they also mark which values were changed */
  8737. memset(vals, 0, sizeof(*vals));
  8738. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8739. if (!CHIP_IS_E3(bp)) {
  8740. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8741. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8742. if ((mask & reset_reg) && val) {
  8743. u32 wb_data[2];
  8744. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8745. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8746. : NIG_REG_INGRESS_BMAC0_MEM;
  8747. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8748. : BIGMAC_REGISTER_BMAC_CONTROL;
  8749. /*
  8750. * use rd/wr since we cannot use dmae. This is safe
  8751. * since MCP won't access the bus due to the request
  8752. * to unload, and no function on the path can be
  8753. * loaded at this time.
  8754. */
  8755. wb_data[0] = REG_RD(bp, base_addr + offset);
  8756. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8757. vals->bmac_addr = base_addr + offset;
  8758. vals->bmac_val[0] = wb_data[0];
  8759. vals->bmac_val[1] = wb_data[1];
  8760. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8761. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8762. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8763. }
  8764. BNX2X_DEV_INFO("Disable emac Rx\n");
  8765. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8766. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8767. REG_WR(bp, vals->emac_addr, 0);
  8768. mac_stopped = true;
  8769. } else {
  8770. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8771. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8772. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8773. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8774. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8775. val & ~(1 << 1));
  8776. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8777. val | (1 << 1));
  8778. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8779. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8780. REG_WR(bp, vals->xmac_addr, 0);
  8781. mac_stopped = true;
  8782. }
  8783. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 0,
  8784. reset_reg, vals);
  8785. mac_stopped |= bnx2x_prev_unload_close_umac(bp, 1,
  8786. reset_reg, vals);
  8787. }
  8788. if (mac_stopped)
  8789. msleep(20);
  8790. }
  8791. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8792. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8793. 0x1848 + ((f) << 4))
  8794. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8795. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8796. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8797. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8798. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8799. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8800. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8801. {
  8802. /* UNDI marks its presence in DORQ -
  8803. * it initializes CID offset for normal bell to 0x7
  8804. */
  8805. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8806. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8807. return false;
  8808. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8809. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8810. return true;
  8811. }
  8812. return false;
  8813. }
  8814. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8815. {
  8816. u16 rcq, bd;
  8817. u32 addr, tmp_reg;
  8818. if (BP_FUNC(bp) < 2)
  8819. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8820. else
  8821. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8822. tmp_reg = REG_RD(bp, addr);
  8823. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8824. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8825. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8826. REG_WR(bp, addr, tmp_reg);
  8827. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8828. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8829. }
  8830. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8831. {
  8832. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8833. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8834. if (!rc) {
  8835. BNX2X_ERR("MCP response failure, aborting\n");
  8836. return -EBUSY;
  8837. }
  8838. return 0;
  8839. }
  8840. static struct bnx2x_prev_path_list *
  8841. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8842. {
  8843. struct bnx2x_prev_path_list *tmp_list;
  8844. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8845. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8846. bp->pdev->bus->number == tmp_list->bus &&
  8847. BP_PATH(bp) == tmp_list->path)
  8848. return tmp_list;
  8849. return NULL;
  8850. }
  8851. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8852. {
  8853. struct bnx2x_prev_path_list *tmp_list;
  8854. int rc;
  8855. rc = down_interruptible(&bnx2x_prev_sem);
  8856. if (rc) {
  8857. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8858. return rc;
  8859. }
  8860. tmp_list = bnx2x_prev_path_get_entry(bp);
  8861. if (tmp_list) {
  8862. tmp_list->aer = 1;
  8863. rc = 0;
  8864. } else {
  8865. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8866. BP_PATH(bp));
  8867. }
  8868. up(&bnx2x_prev_sem);
  8869. return rc;
  8870. }
  8871. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8872. {
  8873. struct bnx2x_prev_path_list *tmp_list;
  8874. bool rc = false;
  8875. if (down_trylock(&bnx2x_prev_sem))
  8876. return false;
  8877. tmp_list = bnx2x_prev_path_get_entry(bp);
  8878. if (tmp_list) {
  8879. if (tmp_list->aer) {
  8880. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8881. BP_PATH(bp));
  8882. } else {
  8883. rc = true;
  8884. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8885. BP_PATH(bp));
  8886. }
  8887. }
  8888. up(&bnx2x_prev_sem);
  8889. return rc;
  8890. }
  8891. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8892. {
  8893. struct bnx2x_prev_path_list *entry;
  8894. bool val;
  8895. down(&bnx2x_prev_sem);
  8896. entry = bnx2x_prev_path_get_entry(bp);
  8897. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8898. up(&bnx2x_prev_sem);
  8899. return val;
  8900. }
  8901. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8902. {
  8903. struct bnx2x_prev_path_list *tmp_list;
  8904. int rc;
  8905. rc = down_interruptible(&bnx2x_prev_sem);
  8906. if (rc) {
  8907. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8908. return rc;
  8909. }
  8910. /* Check whether the entry for this path already exists */
  8911. tmp_list = bnx2x_prev_path_get_entry(bp);
  8912. if (tmp_list) {
  8913. if (!tmp_list->aer) {
  8914. BNX2X_ERR("Re-Marking the path.\n");
  8915. } else {
  8916. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8917. BP_PATH(bp));
  8918. tmp_list->aer = 0;
  8919. }
  8920. up(&bnx2x_prev_sem);
  8921. return 0;
  8922. }
  8923. up(&bnx2x_prev_sem);
  8924. /* Create an entry for this path and add it */
  8925. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8926. if (!tmp_list) {
  8927. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8928. return -ENOMEM;
  8929. }
  8930. tmp_list->bus = bp->pdev->bus->number;
  8931. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8932. tmp_list->path = BP_PATH(bp);
  8933. tmp_list->aer = 0;
  8934. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8935. rc = down_interruptible(&bnx2x_prev_sem);
  8936. if (rc) {
  8937. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8938. kfree(tmp_list);
  8939. } else {
  8940. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8941. BP_PATH(bp));
  8942. list_add(&tmp_list->list, &bnx2x_prev_list);
  8943. up(&bnx2x_prev_sem);
  8944. }
  8945. return rc;
  8946. }
  8947. static int bnx2x_do_flr(struct bnx2x *bp)
  8948. {
  8949. struct pci_dev *dev = bp->pdev;
  8950. if (CHIP_IS_E1x(bp)) {
  8951. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8952. return -EINVAL;
  8953. }
  8954. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8955. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8956. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8957. bp->common.bc_ver);
  8958. return -EINVAL;
  8959. }
  8960. if (!pci_wait_for_pending_transaction(dev))
  8961. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8962. BNX2X_DEV_INFO("Initiating FLR\n");
  8963. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8964. return 0;
  8965. }
  8966. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8967. {
  8968. int rc;
  8969. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8970. /* Test if previous unload process was already finished for this path */
  8971. if (bnx2x_prev_is_path_marked(bp))
  8972. return bnx2x_prev_mcp_done(bp);
  8973. BNX2X_DEV_INFO("Path is unmarked\n");
  8974. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8975. if (bnx2x_prev_is_after_undi(bp))
  8976. goto out;
  8977. /* If function has FLR capabilities, and existing FW version matches
  8978. * the one required, then FLR will be sufficient to clean any residue
  8979. * left by previous driver
  8980. */
  8981. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8982. if (!rc) {
  8983. /* fw version is good */
  8984. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8985. rc = bnx2x_do_flr(bp);
  8986. }
  8987. if (!rc) {
  8988. /* FLR was performed */
  8989. BNX2X_DEV_INFO("FLR successful\n");
  8990. return 0;
  8991. }
  8992. BNX2X_DEV_INFO("Could not FLR\n");
  8993. out:
  8994. /* Close the MCP request, return failure*/
  8995. rc = bnx2x_prev_mcp_done(bp);
  8996. if (!rc)
  8997. rc = BNX2X_PREV_WAIT_NEEDED;
  8998. return rc;
  8999. }
  9000. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  9001. {
  9002. u32 reset_reg, tmp_reg = 0, rc;
  9003. bool prev_undi = false;
  9004. struct bnx2x_mac_vals mac_vals;
  9005. /* It is possible a previous function received 'common' answer,
  9006. * but hasn't loaded yet, therefore creating a scenario of
  9007. * multiple functions receiving 'common' on the same path.
  9008. */
  9009. BNX2X_DEV_INFO("Common unload Flow\n");
  9010. memset(&mac_vals, 0, sizeof(mac_vals));
  9011. if (bnx2x_prev_is_path_marked(bp))
  9012. return bnx2x_prev_mcp_done(bp);
  9013. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  9014. /* Reset should be performed after BRB is emptied */
  9015. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  9016. u32 timer_count = 1000;
  9017. /* Close the MAC Rx to prevent BRB from filling up */
  9018. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  9019. /* close LLH filters for both ports towards the BRB */
  9020. bnx2x_set_rx_filter(&bp->link_params, 0);
  9021. bp->link_params.port ^= 1;
  9022. bnx2x_set_rx_filter(&bp->link_params, 0);
  9023. bp->link_params.port ^= 1;
  9024. /* Check if the UNDI driver was previously loaded */
  9025. if (bnx2x_prev_is_after_undi(bp)) {
  9026. prev_undi = true;
  9027. /* clear the UNDI indication */
  9028. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  9029. /* clear possible idle check errors */
  9030. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  9031. }
  9032. if (!CHIP_IS_E1x(bp))
  9033. /* block FW from writing to host */
  9034. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  9035. /* wait until BRB is empty */
  9036. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9037. while (timer_count) {
  9038. u32 prev_brb = tmp_reg;
  9039. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  9040. if (!tmp_reg)
  9041. break;
  9042. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  9043. /* reset timer as long as BRB actually gets emptied */
  9044. if (prev_brb > tmp_reg)
  9045. timer_count = 1000;
  9046. else
  9047. timer_count--;
  9048. /* If UNDI resides in memory, manually increment it */
  9049. if (prev_undi)
  9050. bnx2x_prev_unload_undi_inc(bp, 1);
  9051. udelay(10);
  9052. }
  9053. if (!timer_count)
  9054. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  9055. }
  9056. /* No packets are in the pipeline, path is ready for reset */
  9057. bnx2x_reset_common(bp);
  9058. if (mac_vals.xmac_addr)
  9059. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  9060. if (mac_vals.umac_addr[0])
  9061. REG_WR(bp, mac_vals.umac_addr[0], mac_vals.umac_val[0]);
  9062. if (mac_vals.umac_addr[1])
  9063. REG_WR(bp, mac_vals.umac_addr[1], mac_vals.umac_val[1]);
  9064. if (mac_vals.emac_addr)
  9065. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  9066. if (mac_vals.bmac_addr) {
  9067. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  9068. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  9069. }
  9070. rc = bnx2x_prev_mark_path(bp, prev_undi);
  9071. if (rc) {
  9072. bnx2x_prev_mcp_done(bp);
  9073. return rc;
  9074. }
  9075. return bnx2x_prev_mcp_done(bp);
  9076. }
  9077. static int bnx2x_prev_unload(struct bnx2x *bp)
  9078. {
  9079. int time_counter = 10;
  9080. u32 rc, fw, hw_lock_reg, hw_lock_val;
  9081. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  9082. /* clear hw from errors which may have resulted from an interrupted
  9083. * dmae transaction.
  9084. */
  9085. bnx2x_clean_pglue_errors(bp);
  9086. /* Release previously held locks */
  9087. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  9088. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  9089. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  9090. hw_lock_val = REG_RD(bp, hw_lock_reg);
  9091. if (hw_lock_val) {
  9092. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  9093. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  9094. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  9095. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  9096. }
  9097. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  9098. REG_WR(bp, hw_lock_reg, 0xffffffff);
  9099. } else
  9100. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  9101. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  9102. BNX2X_DEV_INFO("Release previously held alr\n");
  9103. bnx2x_release_alr(bp);
  9104. }
  9105. do {
  9106. int aer = 0;
  9107. /* Lock MCP using an unload request */
  9108. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  9109. if (!fw) {
  9110. BNX2X_ERR("MCP response failure, aborting\n");
  9111. rc = -EBUSY;
  9112. break;
  9113. }
  9114. rc = down_interruptible(&bnx2x_prev_sem);
  9115. if (rc) {
  9116. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  9117. rc);
  9118. } else {
  9119. /* If Path is marked by EEH, ignore unload status */
  9120. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  9121. bnx2x_prev_path_get_entry(bp)->aer);
  9122. up(&bnx2x_prev_sem);
  9123. }
  9124. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  9125. rc = bnx2x_prev_unload_common(bp);
  9126. break;
  9127. }
  9128. /* non-common reply from MCP might require looping */
  9129. rc = bnx2x_prev_unload_uncommon(bp);
  9130. if (rc != BNX2X_PREV_WAIT_NEEDED)
  9131. break;
  9132. msleep(20);
  9133. } while (--time_counter);
  9134. if (!time_counter || rc) {
  9135. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  9136. rc = -EPROBE_DEFER;
  9137. }
  9138. /* Mark function if its port was used to boot from SAN */
  9139. if (bnx2x_port_after_undi(bp))
  9140. bp->link_params.feature_config_flags |=
  9141. FEATURE_CONFIG_BOOT_FROM_SAN;
  9142. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  9143. return rc;
  9144. }
  9145. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  9146. {
  9147. u32 val, val2, val3, val4, id, boot_mode;
  9148. u16 pmc;
  9149. /* Get the chip revision id and number. */
  9150. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  9151. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  9152. id = ((val & 0xffff) << 16);
  9153. val = REG_RD(bp, MISC_REG_CHIP_REV);
  9154. id |= ((val & 0xf) << 12);
  9155. /* Metal is read from PCI regs, but we can't access >=0x400 from
  9156. * the configuration space (so we need to reg_rd)
  9157. */
  9158. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  9159. id |= (((val >> 24) & 0xf) << 4);
  9160. val = REG_RD(bp, MISC_REG_BOND_ID);
  9161. id |= (val & 0xf);
  9162. bp->common.chip_id = id;
  9163. /* force 57811 according to MISC register */
  9164. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  9165. if (CHIP_IS_57810(bp))
  9166. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  9167. (bp->common.chip_id & 0x0000FFFF);
  9168. else if (CHIP_IS_57810_MF(bp))
  9169. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  9170. (bp->common.chip_id & 0x0000FFFF);
  9171. bp->common.chip_id |= 0x1;
  9172. }
  9173. /* Set doorbell size */
  9174. bp->db_size = (1 << BNX2X_DB_SHIFT);
  9175. if (!CHIP_IS_E1x(bp)) {
  9176. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  9177. if ((val & 1) == 0)
  9178. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  9179. else
  9180. val = (val >> 1) & 1;
  9181. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  9182. "2_PORT_MODE");
  9183. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  9184. CHIP_2_PORT_MODE;
  9185. if (CHIP_MODE_IS_4_PORT(bp))
  9186. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  9187. else
  9188. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  9189. } else {
  9190. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  9191. bp->pfid = bp->pf_num; /* 0..7 */
  9192. }
  9193. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  9194. bp->link_params.chip_id = bp->common.chip_id;
  9195. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  9196. val = (REG_RD(bp, 0x2874) & 0x55);
  9197. if ((bp->common.chip_id & 0x1) ||
  9198. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  9199. bp->flags |= ONE_PORT_FLAG;
  9200. BNX2X_DEV_INFO("single port device\n");
  9201. }
  9202. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9203. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9204. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9205. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9206. bp->common.flash_size, bp->common.flash_size);
  9207. bnx2x_init_shmem(bp);
  9208. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9209. MISC_REG_GENERIC_CR_1 :
  9210. MISC_REG_GENERIC_CR_0));
  9211. bp->link_params.shmem_base = bp->common.shmem_base;
  9212. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9213. if (SHMEM2_RD(bp, size) >
  9214. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9215. bp->link_params.lfa_base =
  9216. REG_RD(bp, bp->common.shmem2_base +
  9217. (u32)offsetof(struct shmem2_region,
  9218. lfa_host_addr[BP_PORT(bp)]));
  9219. else
  9220. bp->link_params.lfa_base = 0;
  9221. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9222. bp->common.shmem_base, bp->common.shmem2_base);
  9223. if (!bp->common.shmem_base) {
  9224. BNX2X_DEV_INFO("MCP not active\n");
  9225. bp->flags |= NO_MCP_FLAG;
  9226. return;
  9227. }
  9228. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9229. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9230. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9231. SHARED_HW_CFG_LED_MODE_MASK) >>
  9232. SHARED_HW_CFG_LED_MODE_SHIFT);
  9233. bp->link_params.feature_config_flags = 0;
  9234. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9235. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9236. bp->link_params.feature_config_flags |=
  9237. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9238. else
  9239. bp->link_params.feature_config_flags &=
  9240. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9241. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9242. bp->common.bc_ver = val;
  9243. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9244. if (val < BNX2X_BC_VER) {
  9245. /* for now only warn
  9246. * later we might need to enforce this */
  9247. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9248. BNX2X_BC_VER, val);
  9249. }
  9250. bp->link_params.feature_config_flags |=
  9251. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9252. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9253. bp->link_params.feature_config_flags |=
  9254. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9255. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9256. bp->link_params.feature_config_flags |=
  9257. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9258. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9259. bp->link_params.feature_config_flags |=
  9260. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9261. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9262. bp->link_params.feature_config_flags |=
  9263. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9264. FEATURE_CONFIG_MT_SUPPORT : 0;
  9265. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9266. BC_SUPPORTS_PFC_STATS : 0;
  9267. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9268. BC_SUPPORTS_FCOE_FEATURES : 0;
  9269. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9270. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9271. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9272. BC_SUPPORTS_RMMOD_CMD : 0;
  9273. boot_mode = SHMEM_RD(bp,
  9274. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9275. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9276. switch (boot_mode) {
  9277. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9278. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9279. break;
  9280. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9281. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9282. break;
  9283. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9284. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9285. break;
  9286. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9287. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9288. break;
  9289. }
  9290. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9291. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9292. BNX2X_DEV_INFO("%sWoL capable\n",
  9293. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9294. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9295. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9296. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9297. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9298. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9299. val, val2, val3, val4);
  9300. }
  9301. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9302. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9303. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9304. {
  9305. int pfid = BP_FUNC(bp);
  9306. int igu_sb_id;
  9307. u32 val;
  9308. u8 fid, igu_sb_cnt = 0;
  9309. bp->igu_base_sb = 0xff;
  9310. if (CHIP_INT_MODE_IS_BC(bp)) {
  9311. int vn = BP_VN(bp);
  9312. igu_sb_cnt = bp->igu_sb_cnt;
  9313. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9314. FP_SB_MAX_E1x;
  9315. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9316. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9317. return 0;
  9318. }
  9319. /* IGU in normal mode - read CAM */
  9320. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9321. igu_sb_id++) {
  9322. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9323. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9324. continue;
  9325. fid = IGU_FID(val);
  9326. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9327. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9328. continue;
  9329. if (IGU_VEC(val) == 0)
  9330. /* default status block */
  9331. bp->igu_dsb_id = igu_sb_id;
  9332. else {
  9333. if (bp->igu_base_sb == 0xff)
  9334. bp->igu_base_sb = igu_sb_id;
  9335. igu_sb_cnt++;
  9336. }
  9337. }
  9338. }
  9339. #ifdef CONFIG_PCI_MSI
  9340. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9341. * optional that number of CAM entries will not be equal to the value
  9342. * advertised in PCI.
  9343. * Driver should use the minimal value of both as the actual status
  9344. * block count
  9345. */
  9346. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9347. #endif
  9348. if (igu_sb_cnt == 0) {
  9349. BNX2X_ERR("CAM configuration error\n");
  9350. return -EINVAL;
  9351. }
  9352. return 0;
  9353. }
  9354. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9355. {
  9356. int cfg_size = 0, idx, port = BP_PORT(bp);
  9357. /* Aggregation of supported attributes of all external phys */
  9358. bp->port.supported[0] = 0;
  9359. bp->port.supported[1] = 0;
  9360. switch (bp->link_params.num_phys) {
  9361. case 1:
  9362. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9363. cfg_size = 1;
  9364. break;
  9365. case 2:
  9366. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9367. cfg_size = 1;
  9368. break;
  9369. case 3:
  9370. if (bp->link_params.multi_phy_config &
  9371. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9372. bp->port.supported[1] =
  9373. bp->link_params.phy[EXT_PHY1].supported;
  9374. bp->port.supported[0] =
  9375. bp->link_params.phy[EXT_PHY2].supported;
  9376. } else {
  9377. bp->port.supported[0] =
  9378. bp->link_params.phy[EXT_PHY1].supported;
  9379. bp->port.supported[1] =
  9380. bp->link_params.phy[EXT_PHY2].supported;
  9381. }
  9382. cfg_size = 2;
  9383. break;
  9384. }
  9385. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9386. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9387. SHMEM_RD(bp,
  9388. dev_info.port_hw_config[port].external_phy_config),
  9389. SHMEM_RD(bp,
  9390. dev_info.port_hw_config[port].external_phy_config2));
  9391. return;
  9392. }
  9393. if (CHIP_IS_E3(bp))
  9394. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9395. else {
  9396. switch (switch_cfg) {
  9397. case SWITCH_CFG_1G:
  9398. bp->port.phy_addr = REG_RD(
  9399. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9400. break;
  9401. case SWITCH_CFG_10G:
  9402. bp->port.phy_addr = REG_RD(
  9403. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9404. break;
  9405. default:
  9406. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9407. bp->port.link_config[0]);
  9408. return;
  9409. }
  9410. }
  9411. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9412. /* mask what we support according to speed_cap_mask per configuration */
  9413. for (idx = 0; idx < cfg_size; idx++) {
  9414. if (!(bp->link_params.speed_cap_mask[idx] &
  9415. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9416. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9417. if (!(bp->link_params.speed_cap_mask[idx] &
  9418. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9419. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9420. if (!(bp->link_params.speed_cap_mask[idx] &
  9421. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9422. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9423. if (!(bp->link_params.speed_cap_mask[idx] &
  9424. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9425. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9426. if (!(bp->link_params.speed_cap_mask[idx] &
  9427. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9428. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9429. SUPPORTED_1000baseT_Full);
  9430. if (!(bp->link_params.speed_cap_mask[idx] &
  9431. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9432. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9433. if (!(bp->link_params.speed_cap_mask[idx] &
  9434. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9435. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9436. if (!(bp->link_params.speed_cap_mask[idx] &
  9437. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9438. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9439. }
  9440. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9441. bp->port.supported[1]);
  9442. }
  9443. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9444. {
  9445. u32 link_config, idx, cfg_size = 0;
  9446. bp->port.advertising[0] = 0;
  9447. bp->port.advertising[1] = 0;
  9448. switch (bp->link_params.num_phys) {
  9449. case 1:
  9450. case 2:
  9451. cfg_size = 1;
  9452. break;
  9453. case 3:
  9454. cfg_size = 2;
  9455. break;
  9456. }
  9457. for (idx = 0; idx < cfg_size; idx++) {
  9458. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9459. link_config = bp->port.link_config[idx];
  9460. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9461. case PORT_FEATURE_LINK_SPEED_AUTO:
  9462. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9463. bp->link_params.req_line_speed[idx] =
  9464. SPEED_AUTO_NEG;
  9465. bp->port.advertising[idx] |=
  9466. bp->port.supported[idx];
  9467. if (bp->link_params.phy[EXT_PHY1].type ==
  9468. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9469. bp->port.advertising[idx] |=
  9470. (SUPPORTED_100baseT_Half |
  9471. SUPPORTED_100baseT_Full);
  9472. } else {
  9473. /* force 10G, no AN */
  9474. bp->link_params.req_line_speed[idx] =
  9475. SPEED_10000;
  9476. bp->port.advertising[idx] |=
  9477. (ADVERTISED_10000baseT_Full |
  9478. ADVERTISED_FIBRE);
  9479. continue;
  9480. }
  9481. break;
  9482. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9483. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9484. bp->link_params.req_line_speed[idx] =
  9485. SPEED_10;
  9486. bp->port.advertising[idx] |=
  9487. (ADVERTISED_10baseT_Full |
  9488. ADVERTISED_TP);
  9489. } else {
  9490. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9491. link_config,
  9492. bp->link_params.speed_cap_mask[idx]);
  9493. return;
  9494. }
  9495. break;
  9496. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9497. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9498. bp->link_params.req_line_speed[idx] =
  9499. SPEED_10;
  9500. bp->link_params.req_duplex[idx] =
  9501. DUPLEX_HALF;
  9502. bp->port.advertising[idx] |=
  9503. (ADVERTISED_10baseT_Half |
  9504. ADVERTISED_TP);
  9505. } else {
  9506. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9507. link_config,
  9508. bp->link_params.speed_cap_mask[idx]);
  9509. return;
  9510. }
  9511. break;
  9512. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9513. if (bp->port.supported[idx] &
  9514. SUPPORTED_100baseT_Full) {
  9515. bp->link_params.req_line_speed[idx] =
  9516. SPEED_100;
  9517. bp->port.advertising[idx] |=
  9518. (ADVERTISED_100baseT_Full |
  9519. ADVERTISED_TP);
  9520. } else {
  9521. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9522. link_config,
  9523. bp->link_params.speed_cap_mask[idx]);
  9524. return;
  9525. }
  9526. break;
  9527. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9528. if (bp->port.supported[idx] &
  9529. SUPPORTED_100baseT_Half) {
  9530. bp->link_params.req_line_speed[idx] =
  9531. SPEED_100;
  9532. bp->link_params.req_duplex[idx] =
  9533. DUPLEX_HALF;
  9534. bp->port.advertising[idx] |=
  9535. (ADVERTISED_100baseT_Half |
  9536. ADVERTISED_TP);
  9537. } else {
  9538. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9539. link_config,
  9540. bp->link_params.speed_cap_mask[idx]);
  9541. return;
  9542. }
  9543. break;
  9544. case PORT_FEATURE_LINK_SPEED_1G:
  9545. if (bp->port.supported[idx] &
  9546. SUPPORTED_1000baseT_Full) {
  9547. bp->link_params.req_line_speed[idx] =
  9548. SPEED_1000;
  9549. bp->port.advertising[idx] |=
  9550. (ADVERTISED_1000baseT_Full |
  9551. ADVERTISED_TP);
  9552. } else if (bp->port.supported[idx] &
  9553. SUPPORTED_1000baseKX_Full) {
  9554. bp->link_params.req_line_speed[idx] =
  9555. SPEED_1000;
  9556. bp->port.advertising[idx] |=
  9557. ADVERTISED_1000baseKX_Full;
  9558. } else {
  9559. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9560. link_config,
  9561. bp->link_params.speed_cap_mask[idx]);
  9562. return;
  9563. }
  9564. break;
  9565. case PORT_FEATURE_LINK_SPEED_2_5G:
  9566. if (bp->port.supported[idx] &
  9567. SUPPORTED_2500baseX_Full) {
  9568. bp->link_params.req_line_speed[idx] =
  9569. SPEED_2500;
  9570. bp->port.advertising[idx] |=
  9571. (ADVERTISED_2500baseX_Full |
  9572. ADVERTISED_TP);
  9573. } else {
  9574. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9575. link_config,
  9576. bp->link_params.speed_cap_mask[idx]);
  9577. return;
  9578. }
  9579. break;
  9580. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9581. if (bp->port.supported[idx] &
  9582. SUPPORTED_10000baseT_Full) {
  9583. bp->link_params.req_line_speed[idx] =
  9584. SPEED_10000;
  9585. bp->port.advertising[idx] |=
  9586. (ADVERTISED_10000baseT_Full |
  9587. ADVERTISED_FIBRE);
  9588. } else if (bp->port.supported[idx] &
  9589. SUPPORTED_10000baseKR_Full) {
  9590. bp->link_params.req_line_speed[idx] =
  9591. SPEED_10000;
  9592. bp->port.advertising[idx] |=
  9593. (ADVERTISED_10000baseKR_Full |
  9594. ADVERTISED_FIBRE);
  9595. } else {
  9596. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9597. link_config,
  9598. bp->link_params.speed_cap_mask[idx]);
  9599. return;
  9600. }
  9601. break;
  9602. case PORT_FEATURE_LINK_SPEED_20G:
  9603. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9604. break;
  9605. default:
  9606. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9607. link_config);
  9608. bp->link_params.req_line_speed[idx] =
  9609. SPEED_AUTO_NEG;
  9610. bp->port.advertising[idx] =
  9611. bp->port.supported[idx];
  9612. break;
  9613. }
  9614. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9615. PORT_FEATURE_FLOW_CONTROL_MASK);
  9616. if (bp->link_params.req_flow_ctrl[idx] ==
  9617. BNX2X_FLOW_CTRL_AUTO) {
  9618. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9619. bp->link_params.req_flow_ctrl[idx] =
  9620. BNX2X_FLOW_CTRL_NONE;
  9621. else
  9622. bnx2x_set_requested_fc(bp);
  9623. }
  9624. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9625. bp->link_params.req_line_speed[idx],
  9626. bp->link_params.req_duplex[idx],
  9627. bp->link_params.req_flow_ctrl[idx],
  9628. bp->port.advertising[idx]);
  9629. }
  9630. }
  9631. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9632. {
  9633. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9634. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9635. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9636. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9637. }
  9638. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9639. {
  9640. int port = BP_PORT(bp);
  9641. u32 config;
  9642. u32 ext_phy_type, ext_phy_config, eee_mode;
  9643. bp->link_params.bp = bp;
  9644. bp->link_params.port = port;
  9645. bp->link_params.lane_config =
  9646. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9647. bp->link_params.speed_cap_mask[0] =
  9648. SHMEM_RD(bp,
  9649. dev_info.port_hw_config[port].speed_capability_mask) &
  9650. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9651. bp->link_params.speed_cap_mask[1] =
  9652. SHMEM_RD(bp,
  9653. dev_info.port_hw_config[port].speed_capability_mask2) &
  9654. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9655. bp->port.link_config[0] =
  9656. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9657. bp->port.link_config[1] =
  9658. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9659. bp->link_params.multi_phy_config =
  9660. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9661. /* If the device is capable of WoL, set the default state according
  9662. * to the HW
  9663. */
  9664. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9665. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9666. (config & PORT_FEATURE_WOL_ENABLED));
  9667. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9668. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9669. bp->flags |= NO_ISCSI_FLAG;
  9670. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9671. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9672. bp->flags |= NO_FCOE_FLAG;
  9673. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9674. bp->link_params.lane_config,
  9675. bp->link_params.speed_cap_mask[0],
  9676. bp->port.link_config[0]);
  9677. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9678. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9679. bnx2x_phy_probe(&bp->link_params);
  9680. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9681. bnx2x_link_settings_requested(bp);
  9682. /*
  9683. * If connected directly, work with the internal PHY, otherwise, work
  9684. * with the external PHY
  9685. */
  9686. ext_phy_config =
  9687. SHMEM_RD(bp,
  9688. dev_info.port_hw_config[port].external_phy_config);
  9689. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9690. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9691. bp->mdio.prtad = bp->port.phy_addr;
  9692. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9693. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9694. bp->mdio.prtad =
  9695. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9696. /* Configure link feature according to nvram value */
  9697. eee_mode = (((SHMEM_RD(bp, dev_info.
  9698. port_feature_config[port].eee_power_mode)) &
  9699. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9700. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9701. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9702. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9703. EEE_MODE_ENABLE_LPI |
  9704. EEE_MODE_OUTPUT_TIME;
  9705. } else {
  9706. bp->link_params.eee_mode = 0;
  9707. }
  9708. }
  9709. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9710. {
  9711. u32 no_flags = NO_ISCSI_FLAG;
  9712. int port = BP_PORT(bp);
  9713. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9714. drv_lic_key[port].max_iscsi_conn);
  9715. if (!CNIC_SUPPORT(bp)) {
  9716. bp->flags |= no_flags;
  9717. return;
  9718. }
  9719. /* Get the number of maximum allowed iSCSI connections */
  9720. bp->cnic_eth_dev.max_iscsi_conn =
  9721. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9722. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9723. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9724. bp->cnic_eth_dev.max_iscsi_conn);
  9725. /*
  9726. * If maximum allowed number of connections is zero -
  9727. * disable the feature.
  9728. */
  9729. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9730. bp->flags |= no_flags;
  9731. }
  9732. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9733. {
  9734. /* Port info */
  9735. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9736. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9737. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9738. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9739. /* Node info */
  9740. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9741. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9742. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9743. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9744. }
  9745. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9746. {
  9747. u8 count = 0;
  9748. if (IS_MF(bp)) {
  9749. u8 fid;
  9750. /* iterate over absolute function ids for this path: */
  9751. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9752. if (IS_MF_SD(bp)) {
  9753. u32 cfg = MF_CFG_RD(bp,
  9754. func_mf_config[fid].config);
  9755. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9756. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9757. FUNC_MF_CFG_PROTOCOL_FCOE))
  9758. count++;
  9759. } else {
  9760. u32 cfg = MF_CFG_RD(bp,
  9761. func_ext_config[fid].
  9762. func_cfg);
  9763. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9764. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9765. count++;
  9766. }
  9767. }
  9768. } else { /* SF */
  9769. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9770. for (port = 0; port < port_cnt; port++) {
  9771. u32 lic = SHMEM_RD(bp,
  9772. drv_lic_key[port].max_fcoe_conn) ^
  9773. FW_ENCODE_32BIT_PATTERN;
  9774. if (lic)
  9775. count++;
  9776. }
  9777. }
  9778. return count;
  9779. }
  9780. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9781. {
  9782. int port = BP_PORT(bp);
  9783. int func = BP_ABS_FUNC(bp);
  9784. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9785. drv_lic_key[port].max_fcoe_conn);
  9786. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9787. if (!CNIC_SUPPORT(bp)) {
  9788. bp->flags |= NO_FCOE_FLAG;
  9789. return;
  9790. }
  9791. /* Get the number of maximum allowed FCoE connections */
  9792. bp->cnic_eth_dev.max_fcoe_conn =
  9793. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9794. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9795. /* Calculate the number of maximum allowed FCoE tasks */
  9796. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9797. /* check if FCoE resources must be shared between different functions */
  9798. if (num_fcoe_func)
  9799. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9800. /* Read the WWN: */
  9801. if (!IS_MF(bp)) {
  9802. /* Port info */
  9803. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9804. SHMEM_RD(bp,
  9805. dev_info.port_hw_config[port].
  9806. fcoe_wwn_port_name_upper);
  9807. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9808. SHMEM_RD(bp,
  9809. dev_info.port_hw_config[port].
  9810. fcoe_wwn_port_name_lower);
  9811. /* Node info */
  9812. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9813. SHMEM_RD(bp,
  9814. dev_info.port_hw_config[port].
  9815. fcoe_wwn_node_name_upper);
  9816. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9817. SHMEM_RD(bp,
  9818. dev_info.port_hw_config[port].
  9819. fcoe_wwn_node_name_lower);
  9820. } else if (!IS_MF_SD(bp)) {
  9821. /* Read the WWN info only if the FCoE feature is enabled for
  9822. * this function.
  9823. */
  9824. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9825. bnx2x_get_ext_wwn_info(bp, func);
  9826. } else {
  9827. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9828. bnx2x_get_ext_wwn_info(bp, func);
  9829. }
  9830. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9831. /*
  9832. * If maximum allowed number of connections is zero -
  9833. * disable the feature.
  9834. */
  9835. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9836. bp->flags |= NO_FCOE_FLAG;
  9837. }
  9838. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9839. {
  9840. /*
  9841. * iSCSI may be dynamically disabled but reading
  9842. * info here we will decrease memory usage by driver
  9843. * if the feature is disabled for good
  9844. */
  9845. bnx2x_get_iscsi_info(bp);
  9846. bnx2x_get_fcoe_info(bp);
  9847. }
  9848. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9849. {
  9850. u32 val, val2;
  9851. int func = BP_ABS_FUNC(bp);
  9852. int port = BP_PORT(bp);
  9853. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9854. u8 *fip_mac = bp->fip_mac;
  9855. if (IS_MF(bp)) {
  9856. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9857. * FCoE MAC then the appropriate feature should be disabled.
  9858. * In non SD mode features configuration comes from struct
  9859. * func_ext_config.
  9860. */
  9861. if (!IS_MF_SD(bp)) {
  9862. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9863. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9864. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9865. iscsi_mac_addr_upper);
  9866. val = MF_CFG_RD(bp, func_ext_config[func].
  9867. iscsi_mac_addr_lower);
  9868. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9869. BNX2X_DEV_INFO
  9870. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9871. } else {
  9872. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9873. }
  9874. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9875. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9876. fcoe_mac_addr_upper);
  9877. val = MF_CFG_RD(bp, func_ext_config[func].
  9878. fcoe_mac_addr_lower);
  9879. bnx2x_set_mac_buf(fip_mac, val, val2);
  9880. BNX2X_DEV_INFO
  9881. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9882. } else {
  9883. bp->flags |= NO_FCOE_FLAG;
  9884. }
  9885. bp->mf_ext_config = cfg;
  9886. } else { /* SD MODE */
  9887. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9888. /* use primary mac as iscsi mac */
  9889. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9890. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9891. BNX2X_DEV_INFO
  9892. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9893. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9894. /* use primary mac as fip mac */
  9895. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9896. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9897. BNX2X_DEV_INFO
  9898. ("Read FIP MAC: %pM\n", fip_mac);
  9899. }
  9900. }
  9901. /* If this is a storage-only interface, use SAN mac as
  9902. * primary MAC. Notice that for SD this is already the case,
  9903. * as the SAN mac was copied from the primary MAC.
  9904. */
  9905. if (IS_MF_FCOE_AFEX(bp))
  9906. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9907. } else {
  9908. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9909. iscsi_mac_upper);
  9910. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9911. iscsi_mac_lower);
  9912. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9913. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9914. fcoe_fip_mac_upper);
  9915. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9916. fcoe_fip_mac_lower);
  9917. bnx2x_set_mac_buf(fip_mac, val, val2);
  9918. }
  9919. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9920. if (!is_valid_ether_addr(iscsi_mac)) {
  9921. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9922. eth_zero_addr(iscsi_mac);
  9923. }
  9924. /* Disable FCoE if MAC configuration is invalid. */
  9925. if (!is_valid_ether_addr(fip_mac)) {
  9926. bp->flags |= NO_FCOE_FLAG;
  9927. eth_zero_addr(bp->fip_mac);
  9928. }
  9929. }
  9930. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9931. {
  9932. u32 val, val2;
  9933. int func = BP_ABS_FUNC(bp);
  9934. int port = BP_PORT(bp);
  9935. /* Zero primary MAC configuration */
  9936. eth_zero_addr(bp->dev->dev_addr);
  9937. if (BP_NOMCP(bp)) {
  9938. BNX2X_ERROR("warning: random MAC workaround active\n");
  9939. eth_hw_addr_random(bp->dev);
  9940. } else if (IS_MF(bp)) {
  9941. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9942. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9943. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9944. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9945. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9946. if (CNIC_SUPPORT(bp))
  9947. bnx2x_get_cnic_mac_hwinfo(bp);
  9948. } else {
  9949. /* in SF read MACs from port configuration */
  9950. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9951. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9952. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9953. if (CNIC_SUPPORT(bp))
  9954. bnx2x_get_cnic_mac_hwinfo(bp);
  9955. }
  9956. if (!BP_NOMCP(bp)) {
  9957. /* Read physical port identifier from shmem */
  9958. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9959. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9960. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9961. bp->flags |= HAS_PHYS_PORT_ID;
  9962. }
  9963. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9964. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9965. dev_err(&bp->pdev->dev,
  9966. "bad Ethernet MAC address configuration: %pM\n"
  9967. "change it manually before bringing up the appropriate network interface\n",
  9968. bp->dev->dev_addr);
  9969. }
  9970. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9971. {
  9972. int tmp;
  9973. u32 cfg;
  9974. if (IS_VF(bp))
  9975. return false;
  9976. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9977. /* Take function: tmp = func */
  9978. tmp = BP_ABS_FUNC(bp);
  9979. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9980. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9981. } else {
  9982. /* Take port: tmp = port */
  9983. tmp = BP_PORT(bp);
  9984. cfg = SHMEM_RD(bp,
  9985. dev_info.port_hw_config[tmp].generic_features);
  9986. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9987. }
  9988. return cfg;
  9989. }
  9990. static void validate_set_si_mode(struct bnx2x *bp)
  9991. {
  9992. u8 func = BP_ABS_FUNC(bp);
  9993. u32 val;
  9994. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9995. /* check for legal mac (upper bytes) */
  9996. if (val != 0xffff) {
  9997. bp->mf_mode = MULTI_FUNCTION_SI;
  9998. bp->mf_config[BP_VN(bp)] =
  9999. MF_CFG_RD(bp, func_mf_config[func].config);
  10000. } else
  10001. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  10002. }
  10003. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  10004. {
  10005. int /*abs*/func = BP_ABS_FUNC(bp);
  10006. int vn, mfw_vn;
  10007. u32 val = 0, val2 = 0;
  10008. int rc = 0;
  10009. /* Validate that chip access is feasible */
  10010. if (REG_RD(bp, MISC_REG_CHIP_NUM) == 0xffffffff) {
  10011. dev_err(&bp->pdev->dev,
  10012. "Chip read returns all Fs. Preventing probe from continuing\n");
  10013. return -EINVAL;
  10014. }
  10015. bnx2x_get_common_hwinfo(bp);
  10016. /*
  10017. * initialize IGU parameters
  10018. */
  10019. if (CHIP_IS_E1x(bp)) {
  10020. bp->common.int_block = INT_BLOCK_HC;
  10021. bp->igu_dsb_id = DEF_SB_IGU_ID;
  10022. bp->igu_base_sb = 0;
  10023. } else {
  10024. bp->common.int_block = INT_BLOCK_IGU;
  10025. /* do not allow device reset during IGU info processing */
  10026. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10027. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  10028. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10029. int tout = 5000;
  10030. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  10031. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  10032. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  10033. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  10034. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10035. tout--;
  10036. usleep_range(1000, 2000);
  10037. }
  10038. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  10039. dev_err(&bp->pdev->dev,
  10040. "FORCING Normal Mode failed!!!\n");
  10041. bnx2x_release_hw_lock(bp,
  10042. HW_LOCK_RESOURCE_RESET);
  10043. return -EPERM;
  10044. }
  10045. }
  10046. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  10047. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  10048. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  10049. } else
  10050. BNX2X_DEV_INFO("IGU Normal Mode\n");
  10051. rc = bnx2x_get_igu_cam_info(bp);
  10052. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  10053. if (rc)
  10054. return rc;
  10055. }
  10056. /*
  10057. * set base FW non-default (fast path) status block id, this value is
  10058. * used to initialize the fw_sb_id saved on the fp/queue structure to
  10059. * determine the id used by the FW.
  10060. */
  10061. if (CHIP_IS_E1x(bp))
  10062. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  10063. else /*
  10064. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  10065. * the same queue are indicated on the same IGU SB). So we prefer
  10066. * FW and IGU SBs to be the same value.
  10067. */
  10068. bp->base_fw_ndsb = bp->igu_base_sb;
  10069. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  10070. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  10071. bp->igu_sb_cnt, bp->base_fw_ndsb);
  10072. /*
  10073. * Initialize MF configuration
  10074. */
  10075. bp->mf_ov = 0;
  10076. bp->mf_mode = 0;
  10077. bp->mf_sub_mode = 0;
  10078. vn = BP_VN(bp);
  10079. mfw_vn = BP_FW_MB_IDX(bp);
  10080. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  10081. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  10082. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  10083. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  10084. if (SHMEM2_HAS(bp, mf_cfg_addr))
  10085. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  10086. else
  10087. bp->common.mf_cfg_base = bp->common.shmem_base +
  10088. offsetof(struct shmem_region, func_mb) +
  10089. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  10090. /*
  10091. * get mf configuration:
  10092. * 1. Existence of MF configuration
  10093. * 2. MAC address must be legal (check only upper bytes)
  10094. * for Switch-Independent mode;
  10095. * OVLAN must be legal for Switch-Dependent mode
  10096. * 3. SF_MODE configures specific MF mode
  10097. */
  10098. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10099. /* get mf configuration */
  10100. val = SHMEM_RD(bp,
  10101. dev_info.shared_feature_config.config);
  10102. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  10103. switch (val) {
  10104. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  10105. validate_set_si_mode(bp);
  10106. break;
  10107. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  10108. if ((!CHIP_IS_E1x(bp)) &&
  10109. (MF_CFG_RD(bp, func_mf_config[func].
  10110. mac_upper) != 0xffff) &&
  10111. (SHMEM2_HAS(bp,
  10112. afex_driver_support))) {
  10113. bp->mf_mode = MULTI_FUNCTION_AFEX;
  10114. bp->mf_config[vn] = MF_CFG_RD(bp,
  10115. func_mf_config[func].config);
  10116. } else {
  10117. BNX2X_DEV_INFO("can not configure afex mode\n");
  10118. }
  10119. break;
  10120. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  10121. /* get OV configuration */
  10122. val = MF_CFG_RD(bp,
  10123. func_mf_config[FUNC_0].e1hov_tag);
  10124. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  10125. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10126. bp->mf_mode = MULTI_FUNCTION_SD;
  10127. bp->mf_config[vn] = MF_CFG_RD(bp,
  10128. func_mf_config[func].config);
  10129. } else
  10130. BNX2X_DEV_INFO("illegal OV for SD\n");
  10131. break;
  10132. case SHARED_FEAT_CFG_FORCE_SF_MODE_BD_MODE:
  10133. bp->mf_mode = MULTI_FUNCTION_SD;
  10134. bp->mf_sub_mode = SUB_MF_MODE_BD;
  10135. bp->mf_config[vn] =
  10136. MF_CFG_RD(bp,
  10137. func_mf_config[func].config);
  10138. if (SHMEM2_HAS(bp, mtu_size)) {
  10139. int mtu_idx = BP_FW_MB_IDX(bp);
  10140. u16 mtu_size;
  10141. u32 mtu;
  10142. mtu = SHMEM2_RD(bp, mtu_size[mtu_idx]);
  10143. mtu_size = (u16)mtu;
  10144. DP(NETIF_MSG_IFUP, "Read MTU size %04x [%08x]\n",
  10145. mtu_size, mtu);
  10146. /* if valid: update device mtu */
  10147. if (((mtu_size + ETH_HLEN) >=
  10148. ETH_MIN_PACKET_SIZE) &&
  10149. (mtu_size <=
  10150. ETH_MAX_JUMBO_PACKET_SIZE))
  10151. bp->dev->mtu = mtu_size;
  10152. }
  10153. break;
  10154. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  10155. bp->mf_mode = MULTI_FUNCTION_SD;
  10156. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  10157. bp->mf_config[vn] =
  10158. MF_CFG_RD(bp,
  10159. func_mf_config[func].config);
  10160. break;
  10161. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  10162. bp->mf_config[vn] = 0;
  10163. break;
  10164. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  10165. val2 = SHMEM_RD(bp,
  10166. dev_info.shared_hw_config.config_3);
  10167. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  10168. switch (val2) {
  10169. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  10170. validate_set_si_mode(bp);
  10171. bp->mf_sub_mode =
  10172. SUB_MF_MODE_NPAR1_DOT_5;
  10173. break;
  10174. default:
  10175. /* Unknown configuration */
  10176. bp->mf_config[vn] = 0;
  10177. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  10178. val);
  10179. }
  10180. break;
  10181. default:
  10182. /* Unknown configuration: reset mf_config */
  10183. bp->mf_config[vn] = 0;
  10184. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  10185. }
  10186. }
  10187. BNX2X_DEV_INFO("%s function mode\n",
  10188. IS_MF(bp) ? "multi" : "single");
  10189. switch (bp->mf_mode) {
  10190. case MULTI_FUNCTION_SD:
  10191. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  10192. FUNC_MF_CFG_E1HOV_TAG_MASK;
  10193. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  10194. bp->mf_ov = val;
  10195. bp->path_has_ovlan = true;
  10196. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  10197. func, bp->mf_ov, bp->mf_ov);
  10198. } else if ((bp->mf_sub_mode == SUB_MF_MODE_UFP) ||
  10199. (bp->mf_sub_mode == SUB_MF_MODE_BD)) {
  10200. dev_err(&bp->pdev->dev,
  10201. "Unexpected - no valid MF OV for func %d in UFP/BD mode\n",
  10202. func);
  10203. bp->path_has_ovlan = true;
  10204. } else {
  10205. dev_err(&bp->pdev->dev,
  10206. "No valid MF OV for func %d, aborting\n",
  10207. func);
  10208. return -EPERM;
  10209. }
  10210. break;
  10211. case MULTI_FUNCTION_AFEX:
  10212. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  10213. break;
  10214. case MULTI_FUNCTION_SI:
  10215. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  10216. func);
  10217. break;
  10218. default:
  10219. if (vn) {
  10220. dev_err(&bp->pdev->dev,
  10221. "VN %d is in a single function mode, aborting\n",
  10222. vn);
  10223. return -EPERM;
  10224. }
  10225. break;
  10226. }
  10227. /* check if other port on the path needs ovlan:
  10228. * Since MF configuration is shared between ports
  10229. * Possible mixed modes are only
  10230. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  10231. */
  10232. if (CHIP_MODE_IS_4_PORT(bp) &&
  10233. !bp->path_has_ovlan &&
  10234. !IS_MF(bp) &&
  10235. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  10236. u8 other_port = !BP_PORT(bp);
  10237. u8 other_func = BP_PATH(bp) + 2*other_port;
  10238. val = MF_CFG_RD(bp,
  10239. func_mf_config[other_func].e1hov_tag);
  10240. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  10241. bp->path_has_ovlan = true;
  10242. }
  10243. }
  10244. /* adjust igu_sb_cnt to MF for E1H */
  10245. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10246. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10247. /* port info */
  10248. bnx2x_get_port_hwinfo(bp);
  10249. /* Get MAC addresses */
  10250. bnx2x_get_mac_hwinfo(bp);
  10251. bnx2x_get_cnic_info(bp);
  10252. return rc;
  10253. }
  10254. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10255. {
  10256. int cnt, i, block_end, rodi;
  10257. char vpd_start[BNX2X_VPD_LEN+1];
  10258. char str_id_reg[VENDOR_ID_LEN+1];
  10259. char str_id_cap[VENDOR_ID_LEN+1];
  10260. char *vpd_data;
  10261. char *vpd_extended_data = NULL;
  10262. u8 len;
  10263. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10264. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10265. if (cnt < BNX2X_VPD_LEN)
  10266. goto out_not_found;
  10267. /* VPD RO tag should be first tag after identifier string, hence
  10268. * we should be able to find it in first BNX2X_VPD_LEN chars
  10269. */
  10270. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10271. PCI_VPD_LRDT_RO_DATA);
  10272. if (i < 0)
  10273. goto out_not_found;
  10274. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10275. pci_vpd_lrdt_size(&vpd_start[i]);
  10276. i += PCI_VPD_LRDT_TAG_SIZE;
  10277. if (block_end > BNX2X_VPD_LEN) {
  10278. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10279. if (vpd_extended_data == NULL)
  10280. goto out_not_found;
  10281. /* read rest of vpd image into vpd_extended_data */
  10282. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10283. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10284. block_end - BNX2X_VPD_LEN,
  10285. vpd_extended_data + BNX2X_VPD_LEN);
  10286. if (cnt < (block_end - BNX2X_VPD_LEN))
  10287. goto out_not_found;
  10288. vpd_data = vpd_extended_data;
  10289. } else
  10290. vpd_data = vpd_start;
  10291. /* now vpd_data holds full vpd content in both cases */
  10292. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10293. PCI_VPD_RO_KEYWORD_MFR_ID);
  10294. if (rodi < 0)
  10295. goto out_not_found;
  10296. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10297. if (len != VENDOR_ID_LEN)
  10298. goto out_not_found;
  10299. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10300. /* vendor specific info */
  10301. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10302. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10303. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10304. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10305. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10306. PCI_VPD_RO_KEYWORD_VENDOR0);
  10307. if (rodi >= 0) {
  10308. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10309. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10310. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10311. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10312. bp->fw_ver[len] = ' ';
  10313. }
  10314. }
  10315. kfree(vpd_extended_data);
  10316. return;
  10317. }
  10318. out_not_found:
  10319. kfree(vpd_extended_data);
  10320. return;
  10321. }
  10322. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10323. {
  10324. u32 flags = 0;
  10325. if (CHIP_REV_IS_FPGA(bp))
  10326. SET_FLAGS(flags, MODE_FPGA);
  10327. else if (CHIP_REV_IS_EMUL(bp))
  10328. SET_FLAGS(flags, MODE_EMUL);
  10329. else
  10330. SET_FLAGS(flags, MODE_ASIC);
  10331. if (CHIP_MODE_IS_4_PORT(bp))
  10332. SET_FLAGS(flags, MODE_PORT4);
  10333. else
  10334. SET_FLAGS(flags, MODE_PORT2);
  10335. if (CHIP_IS_E2(bp))
  10336. SET_FLAGS(flags, MODE_E2);
  10337. else if (CHIP_IS_E3(bp)) {
  10338. SET_FLAGS(flags, MODE_E3);
  10339. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10340. SET_FLAGS(flags, MODE_E3_A0);
  10341. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10342. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10343. }
  10344. if (IS_MF(bp)) {
  10345. SET_FLAGS(flags, MODE_MF);
  10346. switch (bp->mf_mode) {
  10347. case MULTI_FUNCTION_SD:
  10348. SET_FLAGS(flags, MODE_MF_SD);
  10349. break;
  10350. case MULTI_FUNCTION_SI:
  10351. SET_FLAGS(flags, MODE_MF_SI);
  10352. break;
  10353. case MULTI_FUNCTION_AFEX:
  10354. SET_FLAGS(flags, MODE_MF_AFEX);
  10355. break;
  10356. }
  10357. } else
  10358. SET_FLAGS(flags, MODE_SF);
  10359. #if defined(__LITTLE_ENDIAN)
  10360. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10361. #else /*(__BIG_ENDIAN)*/
  10362. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10363. #endif
  10364. INIT_MODE_FLAGS(bp) = flags;
  10365. }
  10366. static int bnx2x_init_bp(struct bnx2x *bp)
  10367. {
  10368. int func;
  10369. int rc;
  10370. mutex_init(&bp->port.phy_mutex);
  10371. mutex_init(&bp->fw_mb_mutex);
  10372. mutex_init(&bp->drv_info_mutex);
  10373. sema_init(&bp->stats_lock, 1);
  10374. bp->drv_info_mng_owner = false;
  10375. INIT_LIST_HEAD(&bp->vlan_reg);
  10376. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10377. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10378. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10379. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10380. if (IS_PF(bp)) {
  10381. rc = bnx2x_get_hwinfo(bp);
  10382. if (rc)
  10383. return rc;
  10384. } else {
  10385. eth_zero_addr(bp->dev->dev_addr);
  10386. }
  10387. bnx2x_set_modes_bitmap(bp);
  10388. rc = bnx2x_alloc_mem_bp(bp);
  10389. if (rc)
  10390. return rc;
  10391. bnx2x_read_fwinfo(bp);
  10392. func = BP_FUNC(bp);
  10393. /* need to reset chip if undi was active */
  10394. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10395. /* init fw_seq */
  10396. bp->fw_seq =
  10397. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10398. DRV_MSG_SEQ_NUMBER_MASK;
  10399. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10400. rc = bnx2x_prev_unload(bp);
  10401. if (rc) {
  10402. bnx2x_free_mem_bp(bp);
  10403. return rc;
  10404. }
  10405. }
  10406. if (CHIP_REV_IS_FPGA(bp))
  10407. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10408. if (BP_NOMCP(bp) && (func == 0))
  10409. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10410. bp->disable_tpa = disable_tpa;
  10411. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10412. /* Reduce memory usage in kdump environment by disabling TPA */
  10413. bp->disable_tpa |= is_kdump_kernel();
  10414. /* Set TPA flags */
  10415. if (bp->disable_tpa) {
  10416. bp->dev->hw_features &= ~NETIF_F_LRO;
  10417. bp->dev->features &= ~NETIF_F_LRO;
  10418. }
  10419. if (CHIP_IS_E1(bp))
  10420. bp->dropless_fc = 0;
  10421. else
  10422. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10423. bp->mrrs = mrrs;
  10424. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10425. if (IS_VF(bp))
  10426. bp->rx_ring_size = MAX_RX_AVAIL;
  10427. /* make sure that the numbers are in the right granularity */
  10428. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10429. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10430. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10431. init_timer(&bp->timer);
  10432. bp->timer.expires = jiffies + bp->current_interval;
  10433. bp->timer.data = (unsigned long) bp;
  10434. bp->timer.function = bnx2x_timer;
  10435. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10436. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10437. SHMEM2_HAS(bp, dcbx_en) &&
  10438. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10439. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset) &&
  10440. SHMEM2_RD(bp, dcbx_en[BP_PORT(bp)])) {
  10441. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10442. bnx2x_dcbx_init_params(bp);
  10443. } else {
  10444. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10445. }
  10446. if (CHIP_IS_E1x(bp))
  10447. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10448. else
  10449. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10450. /* multiple tx priority */
  10451. if (IS_VF(bp))
  10452. bp->max_cos = 1;
  10453. else if (CHIP_IS_E1x(bp))
  10454. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10455. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10456. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10457. else if (CHIP_IS_E3B0(bp))
  10458. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10459. else
  10460. BNX2X_ERR("unknown chip %x revision %x\n",
  10461. CHIP_NUM(bp), CHIP_REV(bp));
  10462. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10463. /* We need at least one default status block for slow-path events,
  10464. * second status block for the L2 queue, and a third status block for
  10465. * CNIC if supported.
  10466. */
  10467. if (IS_VF(bp))
  10468. bp->min_msix_vec_cnt = 1;
  10469. else if (CNIC_SUPPORT(bp))
  10470. bp->min_msix_vec_cnt = 3;
  10471. else /* PF w/o cnic */
  10472. bp->min_msix_vec_cnt = 2;
  10473. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10474. bp->dump_preset_idx = 1;
  10475. if (CHIP_IS_E3B0(bp))
  10476. bp->flags |= PTP_SUPPORTED;
  10477. return rc;
  10478. }
  10479. /****************************************************************************
  10480. * General service functions
  10481. ****************************************************************************/
  10482. /*
  10483. * net_device service functions
  10484. */
  10485. /* called with rtnl_lock */
  10486. static int bnx2x_open(struct net_device *dev)
  10487. {
  10488. struct bnx2x *bp = netdev_priv(dev);
  10489. int rc;
  10490. bp->stats_init = true;
  10491. netif_carrier_off(dev);
  10492. bnx2x_set_power_state(bp, PCI_D0);
  10493. /* If parity had happen during the unload, then attentions
  10494. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10495. * want the first function loaded on the current engine to
  10496. * complete the recovery.
  10497. * Parity recovery is only relevant for PF driver.
  10498. */
  10499. if (IS_PF(bp)) {
  10500. int other_engine = BP_PATH(bp) ? 0 : 1;
  10501. bool other_load_status, load_status;
  10502. bool global = false;
  10503. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10504. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10505. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10506. bnx2x_chk_parity_attn(bp, &global, true)) {
  10507. do {
  10508. /* If there are attentions and they are in a
  10509. * global blocks, set the GLOBAL_RESET bit
  10510. * regardless whether it will be this function
  10511. * that will complete the recovery or not.
  10512. */
  10513. if (global)
  10514. bnx2x_set_reset_global(bp);
  10515. /* Only the first function on the current
  10516. * engine should try to recover in open. In case
  10517. * of attentions in global blocks only the first
  10518. * in the chip should try to recover.
  10519. */
  10520. if ((!load_status &&
  10521. (!global || !other_load_status)) &&
  10522. bnx2x_trylock_leader_lock(bp) &&
  10523. !bnx2x_leader_reset(bp)) {
  10524. netdev_info(bp->dev,
  10525. "Recovered in open\n");
  10526. break;
  10527. }
  10528. /* recovery has failed... */
  10529. bnx2x_set_power_state(bp, PCI_D3hot);
  10530. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10531. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10532. "If you still see this message after a few retries then power cycle is required.\n");
  10533. return -EAGAIN;
  10534. } while (0);
  10535. }
  10536. }
  10537. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10538. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10539. if (rc)
  10540. return rc;
  10541. if (IS_PF(bp))
  10542. udp_tunnel_get_rx_info(dev);
  10543. return 0;
  10544. }
  10545. /* called with rtnl_lock */
  10546. static int bnx2x_close(struct net_device *dev)
  10547. {
  10548. struct bnx2x *bp = netdev_priv(dev);
  10549. /* Unload the driver, release IRQs */
  10550. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10551. return 0;
  10552. }
  10553. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10554. struct bnx2x_mcast_ramrod_params *p)
  10555. {
  10556. int mc_count = netdev_mc_count(bp->dev);
  10557. struct bnx2x_mcast_list_elem *mc_mac =
  10558. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10559. struct netdev_hw_addr *ha;
  10560. if (!mc_mac)
  10561. return -ENOMEM;
  10562. INIT_LIST_HEAD(&p->mcast_list);
  10563. netdev_for_each_mc_addr(ha, bp->dev) {
  10564. mc_mac->mac = bnx2x_mc_addr(ha);
  10565. list_add_tail(&mc_mac->link, &p->mcast_list);
  10566. mc_mac++;
  10567. }
  10568. p->mcast_list_len = mc_count;
  10569. return 0;
  10570. }
  10571. static void bnx2x_free_mcast_macs_list(
  10572. struct bnx2x_mcast_ramrod_params *p)
  10573. {
  10574. struct bnx2x_mcast_list_elem *mc_mac =
  10575. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10576. link);
  10577. WARN_ON(!mc_mac);
  10578. kfree(mc_mac);
  10579. }
  10580. /**
  10581. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10582. *
  10583. * @bp: driver handle
  10584. *
  10585. * We will use zero (0) as a MAC type for these MACs.
  10586. */
  10587. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10588. {
  10589. int rc;
  10590. struct net_device *dev = bp->dev;
  10591. struct netdev_hw_addr *ha;
  10592. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10593. unsigned long ramrod_flags = 0;
  10594. /* First schedule a cleanup up of old configuration */
  10595. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10596. if (rc < 0) {
  10597. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10598. return rc;
  10599. }
  10600. netdev_for_each_uc_addr(ha, dev) {
  10601. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10602. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10603. if (rc == -EEXIST) {
  10604. DP(BNX2X_MSG_SP,
  10605. "Failed to schedule ADD operations: %d\n", rc);
  10606. /* do not treat adding same MAC as error */
  10607. rc = 0;
  10608. } else if (rc < 0) {
  10609. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10610. rc);
  10611. return rc;
  10612. }
  10613. }
  10614. /* Execute the pending commands */
  10615. __set_bit(RAMROD_CONT, &ramrod_flags);
  10616. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10617. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10618. }
  10619. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10620. {
  10621. struct net_device *dev = bp->dev;
  10622. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10623. int rc = 0;
  10624. rparam.mcast_obj = &bp->mcast_obj;
  10625. /* first, clear all configured multicast MACs */
  10626. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10627. if (rc < 0) {
  10628. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10629. return rc;
  10630. }
  10631. /* then, configure a new MACs list */
  10632. if (netdev_mc_count(dev)) {
  10633. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10634. if (rc) {
  10635. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10636. rc);
  10637. return rc;
  10638. }
  10639. /* Now add the new MACs */
  10640. rc = bnx2x_config_mcast(bp, &rparam,
  10641. BNX2X_MCAST_CMD_ADD);
  10642. if (rc < 0)
  10643. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10644. rc);
  10645. bnx2x_free_mcast_macs_list(&rparam);
  10646. }
  10647. return rc;
  10648. }
  10649. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10650. static void bnx2x_set_rx_mode(struct net_device *dev)
  10651. {
  10652. struct bnx2x *bp = netdev_priv(dev);
  10653. if (bp->state != BNX2X_STATE_OPEN) {
  10654. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10655. return;
  10656. } else {
  10657. /* Schedule an SP task to handle rest of change */
  10658. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10659. NETIF_MSG_IFUP);
  10660. }
  10661. }
  10662. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10663. {
  10664. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10665. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10666. netif_addr_lock_bh(bp->dev);
  10667. if (bp->dev->flags & IFF_PROMISC) {
  10668. rx_mode = BNX2X_RX_MODE_PROMISC;
  10669. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10670. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10671. CHIP_IS_E1(bp))) {
  10672. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10673. } else {
  10674. if (IS_PF(bp)) {
  10675. /* some multicasts */
  10676. if (bnx2x_set_mc_list(bp) < 0)
  10677. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10678. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10679. netif_addr_unlock_bh(bp->dev);
  10680. if (bnx2x_set_uc_list(bp) < 0)
  10681. rx_mode = BNX2X_RX_MODE_PROMISC;
  10682. netif_addr_lock_bh(bp->dev);
  10683. } else {
  10684. /* configuring mcast to a vf involves sleeping (when we
  10685. * wait for the pf's response).
  10686. */
  10687. bnx2x_schedule_sp_rtnl(bp,
  10688. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10689. }
  10690. }
  10691. bp->rx_mode = rx_mode;
  10692. /* handle ISCSI SD mode */
  10693. if (IS_MF_ISCSI_ONLY(bp))
  10694. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10695. /* Schedule the rx_mode command */
  10696. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10697. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10698. netif_addr_unlock_bh(bp->dev);
  10699. return;
  10700. }
  10701. if (IS_PF(bp)) {
  10702. bnx2x_set_storm_rx_mode(bp);
  10703. netif_addr_unlock_bh(bp->dev);
  10704. } else {
  10705. /* VF will need to request the PF to make this change, and so
  10706. * the VF needs to release the bottom-half lock prior to the
  10707. * request (as it will likely require sleep on the VF side)
  10708. */
  10709. netif_addr_unlock_bh(bp->dev);
  10710. bnx2x_vfpf_storm_rx_mode(bp);
  10711. }
  10712. }
  10713. /* called with rtnl_lock */
  10714. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10715. int devad, u16 addr)
  10716. {
  10717. struct bnx2x *bp = netdev_priv(netdev);
  10718. u16 value;
  10719. int rc;
  10720. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10721. prtad, devad, addr);
  10722. /* The HW expects different devad if CL22 is used */
  10723. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10724. bnx2x_acquire_phy_lock(bp);
  10725. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10726. bnx2x_release_phy_lock(bp);
  10727. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10728. if (!rc)
  10729. rc = value;
  10730. return rc;
  10731. }
  10732. /* called with rtnl_lock */
  10733. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10734. u16 addr, u16 value)
  10735. {
  10736. struct bnx2x *bp = netdev_priv(netdev);
  10737. int rc;
  10738. DP(NETIF_MSG_LINK,
  10739. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10740. prtad, devad, addr, value);
  10741. /* The HW expects different devad if CL22 is used */
  10742. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10743. bnx2x_acquire_phy_lock(bp);
  10744. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10745. bnx2x_release_phy_lock(bp);
  10746. return rc;
  10747. }
  10748. /* called with rtnl_lock */
  10749. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10750. {
  10751. struct bnx2x *bp = netdev_priv(dev);
  10752. struct mii_ioctl_data *mdio = if_mii(ifr);
  10753. if (!netif_running(dev))
  10754. return -EAGAIN;
  10755. switch (cmd) {
  10756. case SIOCSHWTSTAMP:
  10757. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10758. default:
  10759. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10760. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10761. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10762. }
  10763. }
  10764. #ifdef CONFIG_NET_POLL_CONTROLLER
  10765. static void poll_bnx2x(struct net_device *dev)
  10766. {
  10767. struct bnx2x *bp = netdev_priv(dev);
  10768. int i;
  10769. for_each_eth_queue(bp, i) {
  10770. struct bnx2x_fastpath *fp = &bp->fp[i];
  10771. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10772. }
  10773. }
  10774. #endif
  10775. static int bnx2x_validate_addr(struct net_device *dev)
  10776. {
  10777. struct bnx2x *bp = netdev_priv(dev);
  10778. /* query the bulletin board for mac address configured by the PF */
  10779. if (IS_VF(bp))
  10780. bnx2x_sample_bulletin(bp);
  10781. if (!is_valid_ether_addr(dev->dev_addr)) {
  10782. BNX2X_ERR("Non-valid Ethernet address\n");
  10783. return -EADDRNOTAVAIL;
  10784. }
  10785. return 0;
  10786. }
  10787. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10788. struct netdev_phys_item_id *ppid)
  10789. {
  10790. struct bnx2x *bp = netdev_priv(netdev);
  10791. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10792. return -EOPNOTSUPP;
  10793. ppid->id_len = sizeof(bp->phys_port_id);
  10794. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10795. return 0;
  10796. }
  10797. static netdev_features_t bnx2x_features_check(struct sk_buff *skb,
  10798. struct net_device *dev,
  10799. netdev_features_t features)
  10800. {
  10801. features = vlan_features_check(skb, features);
  10802. return vxlan_features_check(skb, features);
  10803. }
  10804. static int __bnx2x_vlan_configure_vid(struct bnx2x *bp, u16 vid, bool add)
  10805. {
  10806. int rc;
  10807. if (IS_PF(bp)) {
  10808. unsigned long ramrod_flags = 0;
  10809. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10810. rc = bnx2x_set_vlan_one(bp, vid, &bp->sp_objs->vlan_obj,
  10811. add, &ramrod_flags);
  10812. } else {
  10813. rc = bnx2x_vfpf_update_vlan(bp, vid, bp->fp->index, add);
  10814. }
  10815. return rc;
  10816. }
  10817. static int bnx2x_vlan_configure_vid_list(struct bnx2x *bp)
  10818. {
  10819. struct bnx2x_vlan_entry *vlan;
  10820. int rc = 0;
  10821. /* Configure all non-configured entries */
  10822. list_for_each_entry(vlan, &bp->vlan_reg, link) {
  10823. if (vlan->hw)
  10824. continue;
  10825. if (bp->vlan_cnt >= bp->vlan_credit)
  10826. return -ENOBUFS;
  10827. rc = __bnx2x_vlan_configure_vid(bp, vlan->vid, true);
  10828. if (rc) {
  10829. BNX2X_ERR("Unable to config VLAN %d\n", vlan->vid);
  10830. return rc;
  10831. }
  10832. DP(NETIF_MSG_IFUP, "HW configured for VLAN %d\n", vlan->vid);
  10833. vlan->hw = true;
  10834. bp->vlan_cnt++;
  10835. }
  10836. return 0;
  10837. }
  10838. static void bnx2x_vlan_configure(struct bnx2x *bp, bool set_rx_mode)
  10839. {
  10840. bool need_accept_any_vlan;
  10841. need_accept_any_vlan = !!bnx2x_vlan_configure_vid_list(bp);
  10842. if (bp->accept_any_vlan != need_accept_any_vlan) {
  10843. bp->accept_any_vlan = need_accept_any_vlan;
  10844. DP(NETIF_MSG_IFUP, "Accept all VLAN %s\n",
  10845. bp->accept_any_vlan ? "raised" : "cleared");
  10846. if (set_rx_mode) {
  10847. if (IS_PF(bp))
  10848. bnx2x_set_rx_mode_inner(bp);
  10849. else
  10850. bnx2x_vfpf_storm_rx_mode(bp);
  10851. }
  10852. }
  10853. }
  10854. int bnx2x_vlan_reconfigure_vid(struct bnx2x *bp)
  10855. {
  10856. struct bnx2x_vlan_entry *vlan;
  10857. /* The hw forgot all entries after reload */
  10858. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10859. vlan->hw = false;
  10860. bp->vlan_cnt = 0;
  10861. /* Don't set rx mode here. Our caller will do it. */
  10862. bnx2x_vlan_configure(bp, false);
  10863. return 0;
  10864. }
  10865. static int bnx2x_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
  10866. {
  10867. struct bnx2x *bp = netdev_priv(dev);
  10868. struct bnx2x_vlan_entry *vlan;
  10869. DP(NETIF_MSG_IFUP, "Adding VLAN %d\n", vid);
  10870. vlan = kmalloc(sizeof(*vlan), GFP_KERNEL);
  10871. if (!vlan)
  10872. return -ENOMEM;
  10873. vlan->vid = vid;
  10874. vlan->hw = false;
  10875. list_add_tail(&vlan->link, &bp->vlan_reg);
  10876. if (netif_running(dev))
  10877. bnx2x_vlan_configure(bp, true);
  10878. return 0;
  10879. }
  10880. static int bnx2x_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
  10881. {
  10882. struct bnx2x *bp = netdev_priv(dev);
  10883. struct bnx2x_vlan_entry *vlan;
  10884. bool found = false;
  10885. int rc = 0;
  10886. DP(NETIF_MSG_IFUP, "Removing VLAN %d\n", vid);
  10887. list_for_each_entry(vlan, &bp->vlan_reg, link)
  10888. if (vlan->vid == vid) {
  10889. found = true;
  10890. break;
  10891. }
  10892. if (!found) {
  10893. BNX2X_ERR("Unable to kill VLAN %d - not found\n", vid);
  10894. return -EINVAL;
  10895. }
  10896. if (netif_running(dev) && vlan->hw) {
  10897. rc = __bnx2x_vlan_configure_vid(bp, vid, false);
  10898. DP(NETIF_MSG_IFUP, "HW deconfigured for VLAN %d\n", vid);
  10899. bp->vlan_cnt--;
  10900. }
  10901. list_del(&vlan->link);
  10902. kfree(vlan);
  10903. if (netif_running(dev))
  10904. bnx2x_vlan_configure(bp, true);
  10905. DP(NETIF_MSG_IFUP, "Removing VLAN result %d\n", rc);
  10906. return rc;
  10907. }
  10908. static const struct net_device_ops bnx2x_netdev_ops = {
  10909. .ndo_open = bnx2x_open,
  10910. .ndo_stop = bnx2x_close,
  10911. .ndo_start_xmit = bnx2x_start_xmit,
  10912. .ndo_select_queue = bnx2x_select_queue,
  10913. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10914. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10915. .ndo_validate_addr = bnx2x_validate_addr,
  10916. .ndo_do_ioctl = bnx2x_ioctl,
  10917. .ndo_change_mtu = bnx2x_change_mtu,
  10918. .ndo_fix_features = bnx2x_fix_features,
  10919. .ndo_set_features = bnx2x_set_features,
  10920. .ndo_tx_timeout = bnx2x_tx_timeout,
  10921. .ndo_vlan_rx_add_vid = bnx2x_vlan_rx_add_vid,
  10922. .ndo_vlan_rx_kill_vid = bnx2x_vlan_rx_kill_vid,
  10923. #ifdef CONFIG_NET_POLL_CONTROLLER
  10924. .ndo_poll_controller = poll_bnx2x,
  10925. #endif
  10926. .ndo_setup_tc = __bnx2x_setup_tc,
  10927. #ifdef CONFIG_BNX2X_SRIOV
  10928. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10929. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10930. .ndo_get_vf_config = bnx2x_get_vf_config,
  10931. #endif
  10932. #ifdef NETDEV_FCOE_WWNN
  10933. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10934. #endif
  10935. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10936. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  10937. .ndo_features_check = bnx2x_features_check,
  10938. .ndo_udp_tunnel_add = bnx2x_udp_tunnel_add,
  10939. .ndo_udp_tunnel_del = bnx2x_udp_tunnel_del,
  10940. };
  10941. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10942. {
  10943. struct device *dev = &bp->pdev->dev;
  10944. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10945. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10946. dev_err(dev, "System does not support DMA, aborting\n");
  10947. return -EIO;
  10948. }
  10949. return 0;
  10950. }
  10951. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10952. {
  10953. if (bp->flags & AER_ENABLED) {
  10954. pci_disable_pcie_error_reporting(bp->pdev);
  10955. bp->flags &= ~AER_ENABLED;
  10956. }
  10957. }
  10958. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10959. struct net_device *dev, unsigned long board_type)
  10960. {
  10961. int rc;
  10962. u32 pci_cfg_dword;
  10963. bool chip_is_e1x = (board_type == BCM57710 ||
  10964. board_type == BCM57711 ||
  10965. board_type == BCM57711E);
  10966. SET_NETDEV_DEV(dev, &pdev->dev);
  10967. bp->dev = dev;
  10968. bp->pdev = pdev;
  10969. rc = pci_enable_device(pdev);
  10970. if (rc) {
  10971. dev_err(&bp->pdev->dev,
  10972. "Cannot enable PCI device, aborting\n");
  10973. goto err_out;
  10974. }
  10975. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10976. dev_err(&bp->pdev->dev,
  10977. "Cannot find PCI device base address, aborting\n");
  10978. rc = -ENODEV;
  10979. goto err_out_disable;
  10980. }
  10981. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10982. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10983. rc = -ENODEV;
  10984. goto err_out_disable;
  10985. }
  10986. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10987. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10988. PCICFG_REVESION_ID_ERROR_VAL) {
  10989. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10990. rc = -ENODEV;
  10991. goto err_out_disable;
  10992. }
  10993. if (atomic_read(&pdev->enable_cnt) == 1) {
  10994. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10995. if (rc) {
  10996. dev_err(&bp->pdev->dev,
  10997. "Cannot obtain PCI resources, aborting\n");
  10998. goto err_out_disable;
  10999. }
  11000. pci_set_master(pdev);
  11001. pci_save_state(pdev);
  11002. }
  11003. if (IS_PF(bp)) {
  11004. if (!pdev->pm_cap) {
  11005. dev_err(&bp->pdev->dev,
  11006. "Cannot find power management capability, aborting\n");
  11007. rc = -EIO;
  11008. goto err_out_release;
  11009. }
  11010. }
  11011. if (!pci_is_pcie(pdev)) {
  11012. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  11013. rc = -EIO;
  11014. goto err_out_release;
  11015. }
  11016. rc = bnx2x_set_coherency_mask(bp);
  11017. if (rc)
  11018. goto err_out_release;
  11019. dev->mem_start = pci_resource_start(pdev, 0);
  11020. dev->base_addr = dev->mem_start;
  11021. dev->mem_end = pci_resource_end(pdev, 0);
  11022. dev->irq = pdev->irq;
  11023. bp->regview = pci_ioremap_bar(pdev, 0);
  11024. if (!bp->regview) {
  11025. dev_err(&bp->pdev->dev,
  11026. "Cannot map register space, aborting\n");
  11027. rc = -ENOMEM;
  11028. goto err_out_release;
  11029. }
  11030. /* In E1/E1H use pci device function given by kernel.
  11031. * In E2/E3 read physical function from ME register since these chips
  11032. * support Physical Device Assignment where kernel BDF maybe arbitrary
  11033. * (depending on hypervisor).
  11034. */
  11035. if (chip_is_e1x) {
  11036. bp->pf_num = PCI_FUNC(pdev->devfn);
  11037. } else {
  11038. /* chip is E2/3*/
  11039. pci_read_config_dword(bp->pdev,
  11040. PCICFG_ME_REGISTER, &pci_cfg_dword);
  11041. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  11042. ME_REG_ABS_PF_NUM_SHIFT);
  11043. }
  11044. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  11045. /* clean indirect addresses */
  11046. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  11047. PCICFG_VENDOR_ID_OFFSET);
  11048. /* Set PCIe reset type to fundamental for EEH recovery */
  11049. pdev->needs_freset = 1;
  11050. /* AER (Advanced Error reporting) configuration */
  11051. rc = pci_enable_pcie_error_reporting(pdev);
  11052. if (!rc)
  11053. bp->flags |= AER_ENABLED;
  11054. else
  11055. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  11056. /*
  11057. * Clean the following indirect addresses for all functions since it
  11058. * is not used by the driver.
  11059. */
  11060. if (IS_PF(bp)) {
  11061. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  11062. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  11063. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  11064. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  11065. if (chip_is_e1x) {
  11066. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  11067. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  11068. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  11069. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  11070. }
  11071. /* Enable internal target-read (in case we are probed after PF
  11072. * FLR). Must be done prior to any BAR read access. Only for
  11073. * 57712 and up
  11074. */
  11075. if (!chip_is_e1x)
  11076. REG_WR(bp,
  11077. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  11078. }
  11079. dev->watchdog_timeo = TX_TIMEOUT;
  11080. dev->netdev_ops = &bnx2x_netdev_ops;
  11081. bnx2x_set_ethtool_ops(bp, dev);
  11082. dev->priv_flags |= IFF_UNICAST_FLT;
  11083. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11084. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11085. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  11086. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  11087. if (!chip_is_e1x) {
  11088. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  11089. NETIF_F_GSO_IPXIP4;
  11090. dev->hw_enc_features =
  11091. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  11092. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  11093. NETIF_F_GSO_IPXIP4 |
  11094. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  11095. }
  11096. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  11097. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  11098. /* VF with OLD Hypervisor or old PF do not support filtering */
  11099. if (IS_PF(bp)) {
  11100. if (chip_is_e1x)
  11101. bp->accept_any_vlan = true;
  11102. else
  11103. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11104. #ifdef CONFIG_BNX2X_SRIOV
  11105. } else if (bp->acquire_resp.pfdev_info.pf_cap & PFVF_CAP_VLAN_FILTER) {
  11106. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  11107. #endif
  11108. }
  11109. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  11110. dev->features |= NETIF_F_HIGHDMA;
  11111. /* Add Loopback capability to the device */
  11112. dev->hw_features |= NETIF_F_LOOPBACK;
  11113. #ifdef BCM_DCBNL
  11114. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  11115. #endif
  11116. /* get_port_hwinfo() will set prtad and mmds properly */
  11117. bp->mdio.prtad = MDIO_PRTAD_NONE;
  11118. bp->mdio.mmds = 0;
  11119. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  11120. bp->mdio.dev = dev;
  11121. bp->mdio.mdio_read = bnx2x_mdio_read;
  11122. bp->mdio.mdio_write = bnx2x_mdio_write;
  11123. return 0;
  11124. err_out_release:
  11125. if (atomic_read(&pdev->enable_cnt) == 1)
  11126. pci_release_regions(pdev);
  11127. err_out_disable:
  11128. pci_disable_device(pdev);
  11129. err_out:
  11130. return rc;
  11131. }
  11132. static int bnx2x_check_firmware(struct bnx2x *bp)
  11133. {
  11134. const struct firmware *firmware = bp->firmware;
  11135. struct bnx2x_fw_file_hdr *fw_hdr;
  11136. struct bnx2x_fw_file_section *sections;
  11137. u32 offset, len, num_ops;
  11138. __be16 *ops_offsets;
  11139. int i;
  11140. const u8 *fw_ver;
  11141. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  11142. BNX2X_ERR("Wrong FW size\n");
  11143. return -EINVAL;
  11144. }
  11145. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  11146. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  11147. /* Make sure none of the offsets and sizes make us read beyond
  11148. * the end of the firmware data */
  11149. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  11150. offset = be32_to_cpu(sections[i].offset);
  11151. len = be32_to_cpu(sections[i].len);
  11152. if (offset + len > firmware->size) {
  11153. BNX2X_ERR("Section %d length is out of bounds\n", i);
  11154. return -EINVAL;
  11155. }
  11156. }
  11157. /* Likewise for the init_ops offsets */
  11158. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  11159. ops_offsets = (__force __be16 *)(firmware->data + offset);
  11160. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  11161. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  11162. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  11163. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  11164. return -EINVAL;
  11165. }
  11166. }
  11167. /* Check FW version */
  11168. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  11169. fw_ver = firmware->data + offset;
  11170. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  11171. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  11172. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  11173. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  11174. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  11175. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  11176. BCM_5710_FW_MAJOR_VERSION,
  11177. BCM_5710_FW_MINOR_VERSION,
  11178. BCM_5710_FW_REVISION_VERSION,
  11179. BCM_5710_FW_ENGINEERING_VERSION);
  11180. return -EINVAL;
  11181. }
  11182. return 0;
  11183. }
  11184. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11185. {
  11186. const __be32 *source = (const __be32 *)_source;
  11187. u32 *target = (u32 *)_target;
  11188. u32 i;
  11189. for (i = 0; i < n/4; i++)
  11190. target[i] = be32_to_cpu(source[i]);
  11191. }
  11192. /*
  11193. Ops array is stored in the following format:
  11194. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  11195. */
  11196. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  11197. {
  11198. const __be32 *source = (const __be32 *)_source;
  11199. struct raw_op *target = (struct raw_op *)_target;
  11200. u32 i, j, tmp;
  11201. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  11202. tmp = be32_to_cpu(source[j]);
  11203. target[i].op = (tmp >> 24) & 0xff;
  11204. target[i].offset = tmp & 0xffffff;
  11205. target[i].raw_data = be32_to_cpu(source[j + 1]);
  11206. }
  11207. }
  11208. /* IRO array is stored in the following format:
  11209. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  11210. */
  11211. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  11212. {
  11213. const __be32 *source = (const __be32 *)_source;
  11214. struct iro *target = (struct iro *)_target;
  11215. u32 i, j, tmp;
  11216. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  11217. target[i].base = be32_to_cpu(source[j]);
  11218. j++;
  11219. tmp = be32_to_cpu(source[j]);
  11220. target[i].m1 = (tmp >> 16) & 0xffff;
  11221. target[i].m2 = tmp & 0xffff;
  11222. j++;
  11223. tmp = be32_to_cpu(source[j]);
  11224. target[i].m3 = (tmp >> 16) & 0xffff;
  11225. target[i].size = tmp & 0xffff;
  11226. j++;
  11227. }
  11228. }
  11229. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  11230. {
  11231. const __be16 *source = (const __be16 *)_source;
  11232. u16 *target = (u16 *)_target;
  11233. u32 i;
  11234. for (i = 0; i < n/2; i++)
  11235. target[i] = be16_to_cpu(source[i]);
  11236. }
  11237. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  11238. do { \
  11239. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  11240. bp->arr = kmalloc(len, GFP_KERNEL); \
  11241. if (!bp->arr) \
  11242. goto lbl; \
  11243. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  11244. (u8 *)bp->arr, len); \
  11245. } while (0)
  11246. static int bnx2x_init_firmware(struct bnx2x *bp)
  11247. {
  11248. const char *fw_file_name;
  11249. struct bnx2x_fw_file_hdr *fw_hdr;
  11250. int rc;
  11251. if (bp->firmware)
  11252. return 0;
  11253. if (CHIP_IS_E1(bp))
  11254. fw_file_name = FW_FILE_NAME_E1;
  11255. else if (CHIP_IS_E1H(bp))
  11256. fw_file_name = FW_FILE_NAME_E1H;
  11257. else if (!CHIP_IS_E1x(bp))
  11258. fw_file_name = FW_FILE_NAME_E2;
  11259. else {
  11260. BNX2X_ERR("Unsupported chip revision\n");
  11261. return -EINVAL;
  11262. }
  11263. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  11264. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  11265. if (rc) {
  11266. BNX2X_ERR("Can't load firmware file %s\n",
  11267. fw_file_name);
  11268. goto request_firmware_exit;
  11269. }
  11270. rc = bnx2x_check_firmware(bp);
  11271. if (rc) {
  11272. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  11273. goto request_firmware_exit;
  11274. }
  11275. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  11276. /* Initialize the pointers to the init arrays */
  11277. /* Blob */
  11278. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  11279. /* Opcodes */
  11280. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  11281. /* Offsets */
  11282. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  11283. be16_to_cpu_n);
  11284. /* STORMs firmware */
  11285. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11286. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  11287. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  11288. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  11289. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11290. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  11291. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  11292. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  11293. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11294. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  11295. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  11296. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  11297. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  11298. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  11299. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  11300. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  11301. /* IRO */
  11302. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  11303. return 0;
  11304. iro_alloc_err:
  11305. kfree(bp->init_ops_offsets);
  11306. init_offsets_alloc_err:
  11307. kfree(bp->init_ops);
  11308. init_ops_alloc_err:
  11309. kfree(bp->init_data);
  11310. request_firmware_exit:
  11311. release_firmware(bp->firmware);
  11312. bp->firmware = NULL;
  11313. return rc;
  11314. }
  11315. static void bnx2x_release_firmware(struct bnx2x *bp)
  11316. {
  11317. kfree(bp->init_ops_offsets);
  11318. kfree(bp->init_ops);
  11319. kfree(bp->init_data);
  11320. release_firmware(bp->firmware);
  11321. bp->firmware = NULL;
  11322. }
  11323. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  11324. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  11325. .init_hw_cmn = bnx2x_init_hw_common,
  11326. .init_hw_port = bnx2x_init_hw_port,
  11327. .init_hw_func = bnx2x_init_hw_func,
  11328. .reset_hw_cmn = bnx2x_reset_common,
  11329. .reset_hw_port = bnx2x_reset_port,
  11330. .reset_hw_func = bnx2x_reset_func,
  11331. .gunzip_init = bnx2x_gunzip_init,
  11332. .gunzip_end = bnx2x_gunzip_end,
  11333. .init_fw = bnx2x_init_firmware,
  11334. .release_fw = bnx2x_release_firmware,
  11335. };
  11336. void bnx2x__init_func_obj(struct bnx2x *bp)
  11337. {
  11338. /* Prepare DMAE related driver resources */
  11339. bnx2x_setup_dmae(bp);
  11340. bnx2x_init_func_obj(bp, &bp->func_obj,
  11341. bnx2x_sp(bp, func_rdata),
  11342. bnx2x_sp_mapping(bp, func_rdata),
  11343. bnx2x_sp(bp, func_afex_rdata),
  11344. bnx2x_sp_mapping(bp, func_afex_rdata),
  11345. &bnx2x_func_sp_drv);
  11346. }
  11347. /* must be called after sriov-enable */
  11348. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  11349. {
  11350. int cid_count = BNX2X_L2_MAX_CID(bp);
  11351. if (IS_SRIOV(bp))
  11352. cid_count += BNX2X_VF_CIDS;
  11353. if (CNIC_SUPPORT(bp))
  11354. cid_count += CNIC_CID_MAX;
  11355. return roundup(cid_count, QM_CID_ROUND);
  11356. }
  11357. /**
  11358. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  11359. *
  11360. * @dev: pci device
  11361. *
  11362. */
  11363. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  11364. {
  11365. int index;
  11366. u16 control = 0;
  11367. /*
  11368. * If MSI-X is not supported - return number of SBs needed to support
  11369. * one fast path queue: one FP queue + SB for CNIC
  11370. */
  11371. if (!pdev->msix_cap) {
  11372. dev_info(&pdev->dev, "no msix capability found\n");
  11373. return 1 + cnic_cnt;
  11374. }
  11375. dev_info(&pdev->dev, "msix capability found\n");
  11376. /*
  11377. * The value in the PCI configuration space is the index of the last
  11378. * entry, namely one less than the actual size of the table, which is
  11379. * exactly what we want to return from this function: number of all SBs
  11380. * without the default SB.
  11381. * For VFs there is no default SB, then we return (index+1).
  11382. */
  11383. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11384. index = control & PCI_MSIX_FLAGS_QSIZE;
  11385. return index;
  11386. }
  11387. static int set_max_cos_est(int chip_id)
  11388. {
  11389. switch (chip_id) {
  11390. case BCM57710:
  11391. case BCM57711:
  11392. case BCM57711E:
  11393. return BNX2X_MULTI_TX_COS_E1X;
  11394. case BCM57712:
  11395. case BCM57712_MF:
  11396. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11397. case BCM57800:
  11398. case BCM57800_MF:
  11399. case BCM57810:
  11400. case BCM57810_MF:
  11401. case BCM57840_4_10:
  11402. case BCM57840_2_20:
  11403. case BCM57840_O:
  11404. case BCM57840_MFO:
  11405. case BCM57840_MF:
  11406. case BCM57811:
  11407. case BCM57811_MF:
  11408. return BNX2X_MULTI_TX_COS_E3B0;
  11409. case BCM57712_VF:
  11410. case BCM57800_VF:
  11411. case BCM57810_VF:
  11412. case BCM57840_VF:
  11413. case BCM57811_VF:
  11414. return 1;
  11415. default:
  11416. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11417. return -ENODEV;
  11418. }
  11419. }
  11420. static int set_is_vf(int chip_id)
  11421. {
  11422. switch (chip_id) {
  11423. case BCM57712_VF:
  11424. case BCM57800_VF:
  11425. case BCM57810_VF:
  11426. case BCM57840_VF:
  11427. case BCM57811_VF:
  11428. return true;
  11429. default:
  11430. return false;
  11431. }
  11432. }
  11433. /* nig_tsgen registers relative address */
  11434. #define tsgen_ctrl 0x0
  11435. #define tsgen_freecount 0x10
  11436. #define tsgen_synctime_t0 0x20
  11437. #define tsgen_offset_t0 0x28
  11438. #define tsgen_drift_t0 0x30
  11439. #define tsgen_synctime_t1 0x58
  11440. #define tsgen_offset_t1 0x60
  11441. #define tsgen_drift_t1 0x68
  11442. /* FW workaround for setting drift */
  11443. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11444. int best_val, int best_period)
  11445. {
  11446. struct bnx2x_func_state_params func_params = {NULL};
  11447. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11448. &func_params.params.set_timesync;
  11449. /* Prepare parameters for function state transitions */
  11450. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11451. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11452. func_params.f_obj = &bp->func_obj;
  11453. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11454. /* Function parameters */
  11455. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11456. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11457. set_timesync_params->add_sub_drift_adjust_value =
  11458. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11459. set_timesync_params->drift_adjust_value = best_val;
  11460. set_timesync_params->drift_adjust_period = best_period;
  11461. return bnx2x_func_state_change(bp, &func_params);
  11462. }
  11463. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11464. {
  11465. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11466. int rc;
  11467. int drift_dir = 1;
  11468. int val, period, period1, period2, dif, dif1, dif2;
  11469. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11470. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11471. if (!netif_running(bp->dev)) {
  11472. DP(BNX2X_MSG_PTP,
  11473. "PTP adjfreq called while the interface is down\n");
  11474. return -EFAULT;
  11475. }
  11476. if (ppb < 0) {
  11477. ppb = -ppb;
  11478. drift_dir = 0;
  11479. }
  11480. if (ppb == 0) {
  11481. best_val = 1;
  11482. best_period = 0x1FFFFFF;
  11483. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11484. best_val = 31;
  11485. best_period = 1;
  11486. } else {
  11487. /* Changed not to allow val = 8, 16, 24 as these values
  11488. * are not supported in workaround.
  11489. */
  11490. for (val = 0; val <= 31; val++) {
  11491. if ((val & 0x7) == 0)
  11492. continue;
  11493. period1 = val * 1000000 / ppb;
  11494. period2 = period1 + 1;
  11495. if (period1 != 0)
  11496. dif1 = ppb - (val * 1000000 / period1);
  11497. else
  11498. dif1 = BNX2X_MAX_PHC_DRIFT;
  11499. if (dif1 < 0)
  11500. dif1 = -dif1;
  11501. dif2 = ppb - (val * 1000000 / period2);
  11502. if (dif2 < 0)
  11503. dif2 = -dif2;
  11504. dif = (dif1 < dif2) ? dif1 : dif2;
  11505. period = (dif1 < dif2) ? period1 : period2;
  11506. if (dif < best_dif) {
  11507. best_dif = dif;
  11508. best_val = val;
  11509. best_period = period;
  11510. }
  11511. }
  11512. }
  11513. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11514. best_period);
  11515. if (rc) {
  11516. BNX2X_ERR("Failed to set drift\n");
  11517. return -EFAULT;
  11518. }
  11519. DP(BNX2X_MSG_PTP, "Configured val = %d, period = %d\n", best_val,
  11520. best_period);
  11521. return 0;
  11522. }
  11523. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11524. {
  11525. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11526. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11527. timecounter_adjtime(&bp->timecounter, delta);
  11528. return 0;
  11529. }
  11530. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
  11531. {
  11532. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11533. u64 ns;
  11534. ns = timecounter_read(&bp->timecounter);
  11535. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11536. *ts = ns_to_timespec64(ns);
  11537. return 0;
  11538. }
  11539. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11540. const struct timespec64 *ts)
  11541. {
  11542. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11543. u64 ns;
  11544. ns = timespec64_to_ns(ts);
  11545. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11546. /* Re-init the timecounter */
  11547. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11548. return 0;
  11549. }
  11550. /* Enable (or disable) ancillary features of the phc subsystem */
  11551. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11552. struct ptp_clock_request *rq, int on)
  11553. {
  11554. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11555. BNX2X_ERR("PHC ancillary features are not supported\n");
  11556. return -ENOTSUPP;
  11557. }
  11558. static void bnx2x_register_phc(struct bnx2x *bp)
  11559. {
  11560. /* Fill the ptp_clock_info struct and register PTP clock*/
  11561. bp->ptp_clock_info.owner = THIS_MODULE;
  11562. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11563. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11564. bp->ptp_clock_info.n_alarm = 0;
  11565. bp->ptp_clock_info.n_ext_ts = 0;
  11566. bp->ptp_clock_info.n_per_out = 0;
  11567. bp->ptp_clock_info.pps = 0;
  11568. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11569. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11570. bp->ptp_clock_info.gettime64 = bnx2x_ptp_gettime;
  11571. bp->ptp_clock_info.settime64 = bnx2x_ptp_settime;
  11572. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11573. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11574. if (IS_ERR(bp->ptp_clock)) {
  11575. bp->ptp_clock = NULL;
  11576. BNX2X_ERR("PTP clock registeration failed\n");
  11577. }
  11578. }
  11579. static int bnx2x_init_one(struct pci_dev *pdev,
  11580. const struct pci_device_id *ent)
  11581. {
  11582. struct net_device *dev = NULL;
  11583. struct bnx2x *bp;
  11584. enum pcie_link_width pcie_width;
  11585. enum pci_bus_speed pcie_speed;
  11586. int rc, max_non_def_sbs;
  11587. int rx_count, tx_count, rss_count, doorbell_size;
  11588. int max_cos_est;
  11589. bool is_vf;
  11590. int cnic_cnt;
  11591. /* Management FW 'remembers' living interfaces. Allow it some time
  11592. * to forget previously living interfaces, allowing a proper re-load.
  11593. */
  11594. if (is_kdump_kernel()) {
  11595. ktime_t now = ktime_get_boottime();
  11596. ktime_t fw_ready_time = ktime_set(5, 0);
  11597. if (ktime_before(now, fw_ready_time))
  11598. msleep(ktime_ms_delta(fw_ready_time, now));
  11599. }
  11600. /* An estimated maximum supported CoS number according to the chip
  11601. * version.
  11602. * We will try to roughly estimate the maximum number of CoSes this chip
  11603. * may support in order to minimize the memory allocated for Tx
  11604. * netdev_queue's. This number will be accurately calculated during the
  11605. * initialization of bp->max_cos based on the chip versions AND chip
  11606. * revision in the bnx2x_init_bp().
  11607. */
  11608. max_cos_est = set_max_cos_est(ent->driver_data);
  11609. if (max_cos_est < 0)
  11610. return max_cos_est;
  11611. is_vf = set_is_vf(ent->driver_data);
  11612. cnic_cnt = is_vf ? 0 : 1;
  11613. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11614. /* add another SB for VF as it has no default SB */
  11615. max_non_def_sbs += is_vf ? 1 : 0;
  11616. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11617. rss_count = max_non_def_sbs - cnic_cnt;
  11618. if (rss_count < 1)
  11619. return -EINVAL;
  11620. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11621. rx_count = rss_count + cnic_cnt;
  11622. /* Maximum number of netdev Tx queues:
  11623. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11624. */
  11625. tx_count = rss_count * max_cos_est + cnic_cnt;
  11626. /* dev zeroed in init_etherdev */
  11627. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11628. if (!dev)
  11629. return -ENOMEM;
  11630. bp = netdev_priv(dev);
  11631. bp->flags = 0;
  11632. if (is_vf)
  11633. bp->flags |= IS_VF_FLAG;
  11634. bp->igu_sb_cnt = max_non_def_sbs;
  11635. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11636. bp->msg_enable = debug;
  11637. bp->cnic_support = cnic_cnt;
  11638. bp->cnic_probe = bnx2x_cnic_probe;
  11639. pci_set_drvdata(pdev, dev);
  11640. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11641. if (rc < 0) {
  11642. free_netdev(dev);
  11643. return rc;
  11644. }
  11645. BNX2X_DEV_INFO("This is a %s function\n",
  11646. IS_PF(bp) ? "physical" : "virtual");
  11647. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11648. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11649. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11650. tx_count, rx_count);
  11651. rc = bnx2x_init_bp(bp);
  11652. if (rc)
  11653. goto init_one_exit;
  11654. /* Map doorbells here as we need the real value of bp->max_cos which
  11655. * is initialized in bnx2x_init_bp() to determine the number of
  11656. * l2 connections.
  11657. */
  11658. if (IS_VF(bp)) {
  11659. bp->doorbells = bnx2x_vf_doorbells(bp);
  11660. rc = bnx2x_vf_pci_alloc(bp);
  11661. if (rc)
  11662. goto init_one_freemem;
  11663. } else {
  11664. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11665. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11666. dev_err(&bp->pdev->dev,
  11667. "Cannot map doorbells, bar size too small, aborting\n");
  11668. rc = -ENOMEM;
  11669. goto init_one_freemem;
  11670. }
  11671. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11672. doorbell_size);
  11673. }
  11674. if (!bp->doorbells) {
  11675. dev_err(&bp->pdev->dev,
  11676. "Cannot map doorbell space, aborting\n");
  11677. rc = -ENOMEM;
  11678. goto init_one_freemem;
  11679. }
  11680. if (IS_VF(bp)) {
  11681. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11682. if (rc)
  11683. goto init_one_freemem;
  11684. }
  11685. /* Enable SRIOV if capability found in configuration space */
  11686. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11687. if (rc)
  11688. goto init_one_freemem;
  11689. /* calc qm_cid_count */
  11690. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11691. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11692. /* disable FCOE L2 queue for E1x*/
  11693. if (CHIP_IS_E1x(bp))
  11694. bp->flags |= NO_FCOE_FLAG;
  11695. /* Set bp->num_queues for MSI-X mode*/
  11696. bnx2x_set_num_queues(bp);
  11697. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11698. * needed.
  11699. */
  11700. rc = bnx2x_set_int_mode(bp);
  11701. if (rc) {
  11702. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11703. goto init_one_freemem;
  11704. }
  11705. BNX2X_DEV_INFO("set interrupts successfully\n");
  11706. /* register the net device */
  11707. rc = register_netdev(dev);
  11708. if (rc) {
  11709. dev_err(&pdev->dev, "Cannot register net device\n");
  11710. goto init_one_freemem;
  11711. }
  11712. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11713. if (!NO_FCOE(bp)) {
  11714. /* Add storage MAC address */
  11715. rtnl_lock();
  11716. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11717. rtnl_unlock();
  11718. }
  11719. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11720. pcie_speed == PCI_SPEED_UNKNOWN ||
  11721. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11722. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11723. else
  11724. BNX2X_DEV_INFO(
  11725. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11726. board_info[ent->driver_data].name,
  11727. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11728. pcie_width,
  11729. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11730. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11731. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11732. "Unknown",
  11733. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11734. bnx2x_register_phc(bp);
  11735. if (!IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp))
  11736. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_DISABLED);
  11737. return 0;
  11738. init_one_freemem:
  11739. bnx2x_free_mem_bp(bp);
  11740. init_one_exit:
  11741. bnx2x_disable_pcie_error_reporting(bp);
  11742. if (bp->regview)
  11743. iounmap(bp->regview);
  11744. if (IS_PF(bp) && bp->doorbells)
  11745. iounmap(bp->doorbells);
  11746. free_netdev(dev);
  11747. if (atomic_read(&pdev->enable_cnt) == 1)
  11748. pci_release_regions(pdev);
  11749. pci_disable_device(pdev);
  11750. return rc;
  11751. }
  11752. static void __bnx2x_remove(struct pci_dev *pdev,
  11753. struct net_device *dev,
  11754. struct bnx2x *bp,
  11755. bool remove_netdev)
  11756. {
  11757. if (bp->ptp_clock) {
  11758. ptp_clock_unregister(bp->ptp_clock);
  11759. bp->ptp_clock = NULL;
  11760. }
  11761. /* Delete storage MAC address */
  11762. if (!NO_FCOE(bp)) {
  11763. rtnl_lock();
  11764. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11765. rtnl_unlock();
  11766. }
  11767. #ifdef BCM_DCBNL
  11768. /* Delete app tlvs from dcbnl */
  11769. bnx2x_dcbnl_update_applist(bp, true);
  11770. #endif
  11771. if (IS_PF(bp) &&
  11772. !BP_NOMCP(bp) &&
  11773. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11774. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11775. /* Close the interface - either directly or implicitly */
  11776. if (remove_netdev) {
  11777. unregister_netdev(dev);
  11778. } else {
  11779. rtnl_lock();
  11780. dev_close(dev);
  11781. rtnl_unlock();
  11782. }
  11783. bnx2x_iov_remove_one(bp);
  11784. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11785. if (IS_PF(bp)) {
  11786. bnx2x_set_power_state(bp, PCI_D0);
  11787. bnx2x_set_os_driver_state(bp, OS_DRIVER_STATE_NOT_LOADED);
  11788. /* Set endianity registers to reset values in case next driver
  11789. * boots in different endianty environment.
  11790. */
  11791. bnx2x_reset_endianity(bp);
  11792. }
  11793. /* Disable MSI/MSI-X */
  11794. bnx2x_disable_msi(bp);
  11795. /* Power off */
  11796. if (IS_PF(bp))
  11797. bnx2x_set_power_state(bp, PCI_D3hot);
  11798. /* Make sure RESET task is not scheduled before continuing */
  11799. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11800. /* send message via vfpf channel to release the resources of this vf */
  11801. if (IS_VF(bp))
  11802. bnx2x_vfpf_release(bp);
  11803. /* Assumes no further PCIe PM changes will occur */
  11804. if (system_state == SYSTEM_POWER_OFF) {
  11805. pci_wake_from_d3(pdev, bp->wol);
  11806. pci_set_power_state(pdev, PCI_D3hot);
  11807. }
  11808. bnx2x_disable_pcie_error_reporting(bp);
  11809. if (remove_netdev) {
  11810. if (bp->regview)
  11811. iounmap(bp->regview);
  11812. /* For vfs, doorbells are part of the regview and were unmapped
  11813. * along with it. FW is only loaded by PF.
  11814. */
  11815. if (IS_PF(bp)) {
  11816. if (bp->doorbells)
  11817. iounmap(bp->doorbells);
  11818. bnx2x_release_firmware(bp);
  11819. } else {
  11820. bnx2x_vf_pci_dealloc(bp);
  11821. }
  11822. bnx2x_free_mem_bp(bp);
  11823. free_netdev(dev);
  11824. if (atomic_read(&pdev->enable_cnt) == 1)
  11825. pci_release_regions(pdev);
  11826. pci_disable_device(pdev);
  11827. }
  11828. }
  11829. static void bnx2x_remove_one(struct pci_dev *pdev)
  11830. {
  11831. struct net_device *dev = pci_get_drvdata(pdev);
  11832. struct bnx2x *bp;
  11833. if (!dev) {
  11834. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11835. return;
  11836. }
  11837. bp = netdev_priv(dev);
  11838. __bnx2x_remove(pdev, dev, bp, true);
  11839. }
  11840. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11841. {
  11842. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11843. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11844. if (CNIC_LOADED(bp))
  11845. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11846. /* Stop Tx */
  11847. bnx2x_tx_disable(bp);
  11848. /* Delete all NAPI objects */
  11849. bnx2x_del_all_napi(bp);
  11850. if (CNIC_LOADED(bp))
  11851. bnx2x_del_all_napi_cnic(bp);
  11852. netdev_reset_tc(bp->dev);
  11853. del_timer_sync(&bp->timer);
  11854. cancel_delayed_work_sync(&bp->sp_task);
  11855. cancel_delayed_work_sync(&bp->period_task);
  11856. if (!down_timeout(&bp->stats_lock, HZ / 10)) {
  11857. bp->stats_state = STATS_STATE_DISABLED;
  11858. up(&bp->stats_lock);
  11859. }
  11860. bnx2x_save_statistics(bp);
  11861. netif_carrier_off(bp->dev);
  11862. return 0;
  11863. }
  11864. /**
  11865. * bnx2x_io_error_detected - called when PCI error is detected
  11866. * @pdev: Pointer to PCI device
  11867. * @state: The current pci connection state
  11868. *
  11869. * This function is called after a PCI bus error affecting
  11870. * this device has been detected.
  11871. */
  11872. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11873. pci_channel_state_t state)
  11874. {
  11875. struct net_device *dev = pci_get_drvdata(pdev);
  11876. struct bnx2x *bp = netdev_priv(dev);
  11877. rtnl_lock();
  11878. BNX2X_ERR("IO error detected\n");
  11879. netif_device_detach(dev);
  11880. if (state == pci_channel_io_perm_failure) {
  11881. rtnl_unlock();
  11882. return PCI_ERS_RESULT_DISCONNECT;
  11883. }
  11884. if (netif_running(dev))
  11885. bnx2x_eeh_nic_unload(bp);
  11886. bnx2x_prev_path_mark_eeh(bp);
  11887. pci_disable_device(pdev);
  11888. rtnl_unlock();
  11889. /* Request a slot reset */
  11890. return PCI_ERS_RESULT_NEED_RESET;
  11891. }
  11892. /**
  11893. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11894. * @pdev: Pointer to PCI device
  11895. *
  11896. * Restart the card from scratch, as if from a cold-boot.
  11897. */
  11898. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11899. {
  11900. struct net_device *dev = pci_get_drvdata(pdev);
  11901. struct bnx2x *bp = netdev_priv(dev);
  11902. int i;
  11903. rtnl_lock();
  11904. BNX2X_ERR("IO slot reset initializing...\n");
  11905. if (pci_enable_device(pdev)) {
  11906. dev_err(&pdev->dev,
  11907. "Cannot re-enable PCI device after reset\n");
  11908. rtnl_unlock();
  11909. return PCI_ERS_RESULT_DISCONNECT;
  11910. }
  11911. pci_set_master(pdev);
  11912. pci_restore_state(pdev);
  11913. pci_save_state(pdev);
  11914. if (netif_running(dev))
  11915. bnx2x_set_power_state(bp, PCI_D0);
  11916. if (netif_running(dev)) {
  11917. BNX2X_ERR("IO slot reset --> driver unload\n");
  11918. /* MCP should have been reset; Need to wait for validity */
  11919. bnx2x_init_shmem(bp);
  11920. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11921. u32 v;
  11922. v = SHMEM2_RD(bp,
  11923. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11924. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11925. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11926. }
  11927. bnx2x_drain_tx_queues(bp);
  11928. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11929. bnx2x_netif_stop(bp, 1);
  11930. bnx2x_free_irq(bp);
  11931. /* Report UNLOAD_DONE to MCP */
  11932. bnx2x_send_unload_done(bp, true);
  11933. bp->sp_state = 0;
  11934. bp->port.pmf = 0;
  11935. bnx2x_prev_unload(bp);
  11936. /* We should have reseted the engine, so It's fair to
  11937. * assume the FW will no longer write to the bnx2x driver.
  11938. */
  11939. bnx2x_squeeze_objects(bp);
  11940. bnx2x_free_skbs(bp);
  11941. for_each_rx_queue(bp, i)
  11942. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11943. bnx2x_free_fp_mem(bp);
  11944. bnx2x_free_mem(bp);
  11945. bp->state = BNX2X_STATE_CLOSED;
  11946. }
  11947. rtnl_unlock();
  11948. /* If AER, perform cleanup of the PCIe registers */
  11949. if (bp->flags & AER_ENABLED) {
  11950. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11951. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11952. else
  11953. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11954. }
  11955. return PCI_ERS_RESULT_RECOVERED;
  11956. }
  11957. /**
  11958. * bnx2x_io_resume - called when traffic can start flowing again
  11959. * @pdev: Pointer to PCI device
  11960. *
  11961. * This callback is called when the error recovery driver tells us that
  11962. * its OK to resume normal operation.
  11963. */
  11964. static void bnx2x_io_resume(struct pci_dev *pdev)
  11965. {
  11966. struct net_device *dev = pci_get_drvdata(pdev);
  11967. struct bnx2x *bp = netdev_priv(dev);
  11968. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11969. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11970. return;
  11971. }
  11972. rtnl_lock();
  11973. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11974. DRV_MSG_SEQ_NUMBER_MASK;
  11975. if (netif_running(dev))
  11976. bnx2x_nic_load(bp, LOAD_NORMAL);
  11977. netif_device_attach(dev);
  11978. rtnl_unlock();
  11979. }
  11980. static const struct pci_error_handlers bnx2x_err_handler = {
  11981. .error_detected = bnx2x_io_error_detected,
  11982. .slot_reset = bnx2x_io_slot_reset,
  11983. .resume = bnx2x_io_resume,
  11984. };
  11985. static void bnx2x_shutdown(struct pci_dev *pdev)
  11986. {
  11987. struct net_device *dev = pci_get_drvdata(pdev);
  11988. struct bnx2x *bp;
  11989. if (!dev)
  11990. return;
  11991. bp = netdev_priv(dev);
  11992. if (!bp)
  11993. return;
  11994. rtnl_lock();
  11995. netif_device_detach(dev);
  11996. rtnl_unlock();
  11997. /* Don't remove the netdevice, as there are scenarios which will cause
  11998. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11999. * rootfs is mounted from SAN.
  12000. */
  12001. __bnx2x_remove(pdev, dev, bp, false);
  12002. }
  12003. static struct pci_driver bnx2x_pci_driver = {
  12004. .name = DRV_MODULE_NAME,
  12005. .id_table = bnx2x_pci_tbl,
  12006. .probe = bnx2x_init_one,
  12007. .remove = bnx2x_remove_one,
  12008. .suspend = bnx2x_suspend,
  12009. .resume = bnx2x_resume,
  12010. .err_handler = &bnx2x_err_handler,
  12011. #ifdef CONFIG_BNX2X_SRIOV
  12012. .sriov_configure = bnx2x_sriov_configure,
  12013. #endif
  12014. .shutdown = bnx2x_shutdown,
  12015. };
  12016. static int __init bnx2x_init(void)
  12017. {
  12018. int ret;
  12019. pr_info("%s", version);
  12020. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  12021. if (bnx2x_wq == NULL) {
  12022. pr_err("Cannot create workqueue\n");
  12023. return -ENOMEM;
  12024. }
  12025. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  12026. if (!bnx2x_iov_wq) {
  12027. pr_err("Cannot create iov workqueue\n");
  12028. destroy_workqueue(bnx2x_wq);
  12029. return -ENOMEM;
  12030. }
  12031. ret = pci_register_driver(&bnx2x_pci_driver);
  12032. if (ret) {
  12033. pr_err("Cannot register driver\n");
  12034. destroy_workqueue(bnx2x_wq);
  12035. destroy_workqueue(bnx2x_iov_wq);
  12036. }
  12037. return ret;
  12038. }
  12039. static void __exit bnx2x_cleanup(void)
  12040. {
  12041. struct list_head *pos, *q;
  12042. pci_unregister_driver(&bnx2x_pci_driver);
  12043. destroy_workqueue(bnx2x_wq);
  12044. destroy_workqueue(bnx2x_iov_wq);
  12045. /* Free globally allocated resources */
  12046. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  12047. struct bnx2x_prev_path_list *tmp =
  12048. list_entry(pos, struct bnx2x_prev_path_list, list);
  12049. list_del(pos);
  12050. kfree(tmp);
  12051. }
  12052. }
  12053. void bnx2x_notify_link_changed(struct bnx2x *bp)
  12054. {
  12055. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  12056. }
  12057. module_init(bnx2x_init);
  12058. module_exit(bnx2x_cleanup);
  12059. /**
  12060. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  12061. *
  12062. * @bp: driver handle
  12063. * @set: set or clear the CAM entry
  12064. *
  12065. * This function will wait until the ramrod completion returns.
  12066. * Return 0 if success, -ENODEV if ramrod doesn't return.
  12067. */
  12068. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  12069. {
  12070. unsigned long ramrod_flags = 0;
  12071. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  12072. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  12073. &bp->iscsi_l2_mac_obj, true,
  12074. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  12075. }
  12076. /* count denotes the number of new completions we have seen */
  12077. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  12078. {
  12079. struct eth_spe *spe;
  12080. int cxt_index, cxt_offset;
  12081. #ifdef BNX2X_STOP_ON_ERROR
  12082. if (unlikely(bp->panic))
  12083. return;
  12084. #endif
  12085. spin_lock_bh(&bp->spq_lock);
  12086. BUG_ON(bp->cnic_spq_pending < count);
  12087. bp->cnic_spq_pending -= count;
  12088. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  12089. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  12090. & SPE_HDR_CONN_TYPE) >>
  12091. SPE_HDR_CONN_TYPE_SHIFT;
  12092. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  12093. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  12094. /* Set validation for iSCSI L2 client before sending SETUP
  12095. * ramrod
  12096. */
  12097. if (type == ETH_CONNECTION_TYPE) {
  12098. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  12099. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  12100. ILT_PAGE_CIDS;
  12101. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  12102. (cxt_index * ILT_PAGE_CIDS);
  12103. bnx2x_set_ctx_validation(bp,
  12104. &bp->context[cxt_index].
  12105. vcxt[cxt_offset].eth,
  12106. BNX2X_ISCSI_ETH_CID(bp));
  12107. }
  12108. }
  12109. /*
  12110. * There may be not more than 8 L2, not more than 8 L5 SPEs
  12111. * and in the air. We also check that number of outstanding
  12112. * COMMON ramrods is not more than the EQ and SPQ can
  12113. * accommodate.
  12114. */
  12115. if (type == ETH_CONNECTION_TYPE) {
  12116. if (!atomic_read(&bp->cq_spq_left))
  12117. break;
  12118. else
  12119. atomic_dec(&bp->cq_spq_left);
  12120. } else if (type == NONE_CONNECTION_TYPE) {
  12121. if (!atomic_read(&bp->eq_spq_left))
  12122. break;
  12123. else
  12124. atomic_dec(&bp->eq_spq_left);
  12125. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  12126. (type == FCOE_CONNECTION_TYPE)) {
  12127. if (bp->cnic_spq_pending >=
  12128. bp->cnic_eth_dev.max_kwqe_pending)
  12129. break;
  12130. else
  12131. bp->cnic_spq_pending++;
  12132. } else {
  12133. BNX2X_ERR("Unknown SPE type: %d\n", type);
  12134. bnx2x_panic();
  12135. break;
  12136. }
  12137. spe = bnx2x_sp_get_next(bp);
  12138. *spe = *bp->cnic_kwq_cons;
  12139. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  12140. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  12141. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  12142. bp->cnic_kwq_cons = bp->cnic_kwq;
  12143. else
  12144. bp->cnic_kwq_cons++;
  12145. }
  12146. bnx2x_sp_prod_update(bp);
  12147. spin_unlock_bh(&bp->spq_lock);
  12148. }
  12149. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  12150. struct kwqe_16 *kwqes[], u32 count)
  12151. {
  12152. struct bnx2x *bp = netdev_priv(dev);
  12153. int i;
  12154. #ifdef BNX2X_STOP_ON_ERROR
  12155. if (unlikely(bp->panic)) {
  12156. BNX2X_ERR("Can't post to SP queue while panic\n");
  12157. return -EIO;
  12158. }
  12159. #endif
  12160. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  12161. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  12162. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  12163. return -EAGAIN;
  12164. }
  12165. spin_lock_bh(&bp->spq_lock);
  12166. for (i = 0; i < count; i++) {
  12167. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  12168. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  12169. break;
  12170. *bp->cnic_kwq_prod = *spe;
  12171. bp->cnic_kwq_pending++;
  12172. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  12173. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  12174. spe->data.update_data_addr.hi,
  12175. spe->data.update_data_addr.lo,
  12176. bp->cnic_kwq_pending);
  12177. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  12178. bp->cnic_kwq_prod = bp->cnic_kwq;
  12179. else
  12180. bp->cnic_kwq_prod++;
  12181. }
  12182. spin_unlock_bh(&bp->spq_lock);
  12183. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  12184. bnx2x_cnic_sp_post(bp, 0);
  12185. return i;
  12186. }
  12187. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12188. {
  12189. struct cnic_ops *c_ops;
  12190. int rc = 0;
  12191. mutex_lock(&bp->cnic_mutex);
  12192. c_ops = rcu_dereference_protected(bp->cnic_ops,
  12193. lockdep_is_held(&bp->cnic_mutex));
  12194. if (c_ops)
  12195. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12196. mutex_unlock(&bp->cnic_mutex);
  12197. return rc;
  12198. }
  12199. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  12200. {
  12201. struct cnic_ops *c_ops;
  12202. int rc = 0;
  12203. rcu_read_lock();
  12204. c_ops = rcu_dereference(bp->cnic_ops);
  12205. if (c_ops)
  12206. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  12207. rcu_read_unlock();
  12208. return rc;
  12209. }
  12210. /*
  12211. * for commands that have no data
  12212. */
  12213. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  12214. {
  12215. struct cnic_ctl_info ctl = {0};
  12216. ctl.cmd = cmd;
  12217. return bnx2x_cnic_ctl_send(bp, &ctl);
  12218. }
  12219. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  12220. {
  12221. struct cnic_ctl_info ctl = {0};
  12222. /* first we tell CNIC and only then we count this as a completion */
  12223. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  12224. ctl.data.comp.cid = cid;
  12225. ctl.data.comp.error = err;
  12226. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  12227. bnx2x_cnic_sp_post(bp, 0);
  12228. }
  12229. /* Called with netif_addr_lock_bh() taken.
  12230. * Sets an rx_mode config for an iSCSI ETH client.
  12231. * Doesn't block.
  12232. * Completion should be checked outside.
  12233. */
  12234. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  12235. {
  12236. unsigned long accept_flags = 0, ramrod_flags = 0;
  12237. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12238. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  12239. if (start) {
  12240. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  12241. * because it's the only way for UIO Queue to accept
  12242. * multicasts (in non-promiscuous mode only one Queue per
  12243. * function will receive multicast packets (leading in our
  12244. * case).
  12245. */
  12246. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  12247. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  12248. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  12249. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  12250. /* Clear STOP_PENDING bit if START is requested */
  12251. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  12252. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  12253. } else
  12254. /* Clear START_PENDING bit if STOP is requested */
  12255. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  12256. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  12257. set_bit(sched_state, &bp->sp_state);
  12258. else {
  12259. __set_bit(RAMROD_RX, &ramrod_flags);
  12260. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  12261. ramrod_flags);
  12262. }
  12263. }
  12264. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  12265. {
  12266. struct bnx2x *bp = netdev_priv(dev);
  12267. int rc = 0;
  12268. switch (ctl->cmd) {
  12269. case DRV_CTL_CTXTBL_WR_CMD: {
  12270. u32 index = ctl->data.io.offset;
  12271. dma_addr_t addr = ctl->data.io.dma_addr;
  12272. bnx2x_ilt_wr(bp, index, addr);
  12273. break;
  12274. }
  12275. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  12276. int count = ctl->data.credit.credit_count;
  12277. bnx2x_cnic_sp_post(bp, count);
  12278. break;
  12279. }
  12280. /* rtnl_lock is held. */
  12281. case DRV_CTL_START_L2_CMD: {
  12282. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12283. unsigned long sp_bits = 0;
  12284. /* Configure the iSCSI classification object */
  12285. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  12286. cp->iscsi_l2_client_id,
  12287. cp->iscsi_l2_cid, BP_FUNC(bp),
  12288. bnx2x_sp(bp, mac_rdata),
  12289. bnx2x_sp_mapping(bp, mac_rdata),
  12290. BNX2X_FILTER_MAC_PENDING,
  12291. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  12292. &bp->macs_pool);
  12293. /* Set iSCSI MAC address */
  12294. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  12295. if (rc)
  12296. break;
  12297. mmiowb();
  12298. barrier();
  12299. /* Start accepting on iSCSI L2 ring */
  12300. netif_addr_lock_bh(dev);
  12301. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  12302. netif_addr_unlock_bh(dev);
  12303. /* bits to wait on */
  12304. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12305. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  12306. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12307. BNX2X_ERR("rx_mode completion timed out!\n");
  12308. break;
  12309. }
  12310. /* rtnl_lock is held. */
  12311. case DRV_CTL_STOP_L2_CMD: {
  12312. unsigned long sp_bits = 0;
  12313. /* Stop accepting on iSCSI L2 ring */
  12314. netif_addr_lock_bh(dev);
  12315. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  12316. netif_addr_unlock_bh(dev);
  12317. /* bits to wait on */
  12318. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  12319. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  12320. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  12321. BNX2X_ERR("rx_mode completion timed out!\n");
  12322. mmiowb();
  12323. barrier();
  12324. /* Unset iSCSI L2 MAC */
  12325. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  12326. BNX2X_ISCSI_ETH_MAC, true);
  12327. break;
  12328. }
  12329. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  12330. int count = ctl->data.credit.credit_count;
  12331. smp_mb__before_atomic();
  12332. atomic_add(count, &bp->cq_spq_left);
  12333. smp_mb__after_atomic();
  12334. break;
  12335. }
  12336. case DRV_CTL_ULP_REGISTER_CMD: {
  12337. int ulp_type = ctl->data.register_data.ulp_type;
  12338. if (CHIP_IS_E3(bp)) {
  12339. int idx = BP_FW_MB_IDX(bp);
  12340. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12341. int path = BP_PATH(bp);
  12342. int port = BP_PORT(bp);
  12343. int i;
  12344. u32 scratch_offset;
  12345. u32 *host_addr;
  12346. /* first write capability to shmem2 */
  12347. if (ulp_type == CNIC_ULP_ISCSI)
  12348. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12349. else if (ulp_type == CNIC_ULP_FCOE)
  12350. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12351. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12352. if ((ulp_type != CNIC_ULP_FCOE) ||
  12353. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  12354. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  12355. break;
  12356. /* if reached here - should write fcoe capabilities */
  12357. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  12358. if (!scratch_offset)
  12359. break;
  12360. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  12361. fcoe_features[path][port]);
  12362. host_addr = (u32 *) &(ctl->data.register_data.
  12363. fcoe_features);
  12364. for (i = 0; i < sizeof(struct fcoe_capabilities);
  12365. i += 4)
  12366. REG_WR(bp, scratch_offset + i,
  12367. *(host_addr + i/4));
  12368. }
  12369. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12370. break;
  12371. }
  12372. case DRV_CTL_ULP_UNREGISTER_CMD: {
  12373. int ulp_type = ctl->data.ulp_type;
  12374. if (CHIP_IS_E3(bp)) {
  12375. int idx = BP_FW_MB_IDX(bp);
  12376. u32 cap;
  12377. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12378. if (ulp_type == CNIC_ULP_ISCSI)
  12379. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12380. else if (ulp_type == CNIC_ULP_FCOE)
  12381. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12382. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12383. }
  12384. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12385. break;
  12386. }
  12387. default:
  12388. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12389. rc = -EINVAL;
  12390. }
  12391. /* For storage-only interfaces, change driver state */
  12392. if (IS_MF_SD_STORAGE_PERSONALITY_ONLY(bp)) {
  12393. switch (ctl->drv_state) {
  12394. case DRV_NOP:
  12395. break;
  12396. case DRV_ACTIVE:
  12397. bnx2x_set_os_driver_state(bp,
  12398. OS_DRIVER_STATE_ACTIVE);
  12399. break;
  12400. case DRV_INACTIVE:
  12401. bnx2x_set_os_driver_state(bp,
  12402. OS_DRIVER_STATE_DISABLED);
  12403. break;
  12404. case DRV_UNLOADED:
  12405. bnx2x_set_os_driver_state(bp,
  12406. OS_DRIVER_STATE_NOT_LOADED);
  12407. break;
  12408. default:
  12409. BNX2X_ERR("Unknown cnic driver state: %d\n", ctl->drv_state);
  12410. }
  12411. }
  12412. return rc;
  12413. }
  12414. static int bnx2x_get_fc_npiv(struct net_device *dev,
  12415. struct cnic_fc_npiv_tbl *cnic_tbl)
  12416. {
  12417. struct bnx2x *bp = netdev_priv(dev);
  12418. struct bdn_fc_npiv_tbl *tbl = NULL;
  12419. u32 offset, entries;
  12420. int rc = -EINVAL;
  12421. int i;
  12422. if (!SHMEM2_HAS(bp, fc_npiv_nvram_tbl_addr[0]))
  12423. goto out;
  12424. DP(BNX2X_MSG_MCP, "About to read the FC-NPIV table\n");
  12425. tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
  12426. if (!tbl) {
  12427. BNX2X_ERR("Failed to allocate fc_npiv table\n");
  12428. goto out;
  12429. }
  12430. offset = SHMEM2_RD(bp, fc_npiv_nvram_tbl_addr[BP_PORT(bp)]);
  12431. if (!offset) {
  12432. DP(BNX2X_MSG_MCP, "No FC-NPIV in NVRAM\n");
  12433. goto out;
  12434. }
  12435. DP(BNX2X_MSG_MCP, "Offset of FC-NPIV in NVRAM: %08x\n", offset);
  12436. /* Read the table contents from nvram */
  12437. if (bnx2x_nvram_read(bp, offset, (u8 *)tbl, sizeof(*tbl))) {
  12438. BNX2X_ERR("Failed to read FC-NPIV table\n");
  12439. goto out;
  12440. }
  12441. /* Since bnx2x_nvram_read() returns data in be32, we need to convert
  12442. * the number of entries back to cpu endianness.
  12443. */
  12444. entries = tbl->fc_npiv_cfg.num_of_npiv;
  12445. entries = (__force u32)be32_to_cpu((__force __be32)entries);
  12446. tbl->fc_npiv_cfg.num_of_npiv = entries;
  12447. if (!tbl->fc_npiv_cfg.num_of_npiv) {
  12448. DP(BNX2X_MSG_MCP,
  12449. "No FC-NPIV table [valid, simply not present]\n");
  12450. goto out;
  12451. } else if (tbl->fc_npiv_cfg.num_of_npiv > MAX_NUMBER_NPIV) {
  12452. BNX2X_ERR("FC-NPIV table with bad length 0x%08x\n",
  12453. tbl->fc_npiv_cfg.num_of_npiv);
  12454. goto out;
  12455. } else {
  12456. DP(BNX2X_MSG_MCP, "Read 0x%08x entries from NVRAM\n",
  12457. tbl->fc_npiv_cfg.num_of_npiv);
  12458. }
  12459. /* Copy the data into cnic-provided struct */
  12460. cnic_tbl->count = tbl->fc_npiv_cfg.num_of_npiv;
  12461. for (i = 0; i < cnic_tbl->count; i++) {
  12462. memcpy(cnic_tbl->wwpn[i], tbl->settings[i].npiv_wwpn, 8);
  12463. memcpy(cnic_tbl->wwnn[i], tbl->settings[i].npiv_wwnn, 8);
  12464. }
  12465. rc = 0;
  12466. out:
  12467. kfree(tbl);
  12468. return rc;
  12469. }
  12470. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12471. {
  12472. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12473. if (bp->flags & USING_MSIX_FLAG) {
  12474. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12475. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12476. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12477. } else {
  12478. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12479. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12480. }
  12481. if (!CHIP_IS_E1x(bp))
  12482. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12483. else
  12484. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12485. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12486. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12487. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12488. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12489. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12490. cp->num_irq = 2;
  12491. }
  12492. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12493. {
  12494. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12495. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12496. bnx2x_cid_ilt_lines(bp);
  12497. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12498. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12499. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12500. 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",
  12501. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12502. cp->iscsi_l2_cid);
  12503. if (NO_ISCSI_OOO(bp))
  12504. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12505. }
  12506. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12507. void *data)
  12508. {
  12509. struct bnx2x *bp = netdev_priv(dev);
  12510. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12511. int rc;
  12512. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12513. if (ops == NULL) {
  12514. BNX2X_ERR("NULL ops received\n");
  12515. return -EINVAL;
  12516. }
  12517. if (!CNIC_SUPPORT(bp)) {
  12518. BNX2X_ERR("Can't register CNIC when not supported\n");
  12519. return -EOPNOTSUPP;
  12520. }
  12521. if (!CNIC_LOADED(bp)) {
  12522. rc = bnx2x_load_cnic(bp);
  12523. if (rc) {
  12524. BNX2X_ERR("CNIC-related load failed\n");
  12525. return rc;
  12526. }
  12527. }
  12528. bp->cnic_enabled = true;
  12529. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12530. if (!bp->cnic_kwq)
  12531. return -ENOMEM;
  12532. bp->cnic_kwq_cons = bp->cnic_kwq;
  12533. bp->cnic_kwq_prod = bp->cnic_kwq;
  12534. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12535. bp->cnic_spq_pending = 0;
  12536. bp->cnic_kwq_pending = 0;
  12537. bp->cnic_data = data;
  12538. cp->num_irq = 0;
  12539. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12540. cp->iro_arr = bp->iro_arr;
  12541. bnx2x_setup_cnic_irq_info(bp);
  12542. rcu_assign_pointer(bp->cnic_ops, ops);
  12543. /* Schedule driver to read CNIC driver versions */
  12544. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12545. return 0;
  12546. }
  12547. static int bnx2x_unregister_cnic(struct net_device *dev)
  12548. {
  12549. struct bnx2x *bp = netdev_priv(dev);
  12550. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12551. mutex_lock(&bp->cnic_mutex);
  12552. cp->drv_state = 0;
  12553. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12554. mutex_unlock(&bp->cnic_mutex);
  12555. synchronize_rcu();
  12556. bp->cnic_enabled = false;
  12557. kfree(bp->cnic_kwq);
  12558. bp->cnic_kwq = NULL;
  12559. return 0;
  12560. }
  12561. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12562. {
  12563. struct bnx2x *bp = netdev_priv(dev);
  12564. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12565. /* If both iSCSI and FCoE are disabled - return NULL in
  12566. * order to indicate CNIC that it should not try to work
  12567. * with this device.
  12568. */
  12569. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12570. return NULL;
  12571. cp->drv_owner = THIS_MODULE;
  12572. cp->chip_id = CHIP_ID(bp);
  12573. cp->pdev = bp->pdev;
  12574. cp->io_base = bp->regview;
  12575. cp->io_base2 = bp->doorbells;
  12576. cp->max_kwqe_pending = 8;
  12577. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12578. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12579. bnx2x_cid_ilt_lines(bp);
  12580. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12581. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12582. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12583. cp->drv_ctl = bnx2x_drv_ctl;
  12584. cp->drv_get_fc_npiv_tbl = bnx2x_get_fc_npiv;
  12585. cp->drv_register_cnic = bnx2x_register_cnic;
  12586. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12587. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12588. cp->iscsi_l2_client_id =
  12589. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12590. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12591. if (NO_ISCSI_OOO(bp))
  12592. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12593. if (NO_ISCSI(bp))
  12594. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12595. if (NO_FCOE(bp))
  12596. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12597. BNX2X_DEV_INFO(
  12598. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12599. cp->ctx_blk_size,
  12600. cp->ctx_tbl_offset,
  12601. cp->ctx_tbl_len,
  12602. cp->starting_cid);
  12603. return cp;
  12604. }
  12605. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12606. {
  12607. struct bnx2x *bp = fp->bp;
  12608. u32 offset = BAR_USTRORM_INTMEM;
  12609. if (IS_VF(bp))
  12610. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12611. else if (!CHIP_IS_E1x(bp))
  12612. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12613. else
  12614. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12615. return offset;
  12616. }
  12617. /* called only on E1H or E2.
  12618. * When pretending to be PF, the pretend value is the function number 0...7
  12619. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12620. * combination
  12621. */
  12622. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12623. {
  12624. u32 pretend_reg;
  12625. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12626. return -1;
  12627. /* get my own pretend register */
  12628. pretend_reg = bnx2x_get_pretend_reg(bp);
  12629. REG_WR(bp, pretend_reg, pretend_func_val);
  12630. REG_RD(bp, pretend_reg);
  12631. return 0;
  12632. }
  12633. static void bnx2x_ptp_task(struct work_struct *work)
  12634. {
  12635. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12636. int port = BP_PORT(bp);
  12637. u32 val_seq;
  12638. u64 timestamp, ns;
  12639. struct skb_shared_hwtstamps shhwtstamps;
  12640. /* Read Tx timestamp registers */
  12641. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12642. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12643. if (val_seq & 0x10000) {
  12644. /* There is a valid timestamp value */
  12645. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12646. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12647. timestamp <<= 32;
  12648. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12649. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12650. /* Reset timestamp register to allow new timestamp */
  12651. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12652. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12653. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12654. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12655. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12656. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12657. dev_kfree_skb_any(bp->ptp_tx_skb);
  12658. bp->ptp_tx_skb = NULL;
  12659. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12660. timestamp, ns);
  12661. } else {
  12662. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12663. /* Reschedule to keep checking for a valid timestamp value */
  12664. schedule_work(&bp->ptp_task);
  12665. }
  12666. }
  12667. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12668. {
  12669. int port = BP_PORT(bp);
  12670. u64 timestamp, ns;
  12671. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12672. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12673. timestamp <<= 32;
  12674. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12675. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12676. /* Reset timestamp register to allow new timestamp */
  12677. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12678. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12679. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12680. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12681. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12682. timestamp, ns);
  12683. }
  12684. /* Read the PHC */
  12685. static cycle_t bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12686. {
  12687. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12688. int port = BP_PORT(bp);
  12689. u32 wb_data[2];
  12690. u64 phc_cycles;
  12691. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12692. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12693. phc_cycles = wb_data[1];
  12694. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12695. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12696. return phc_cycles;
  12697. }
  12698. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12699. {
  12700. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12701. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12702. bp->cyclecounter.mask = CYCLECOUNTER_MASK(64);
  12703. bp->cyclecounter.shift = 1;
  12704. bp->cyclecounter.mult = 1;
  12705. }
  12706. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12707. {
  12708. struct bnx2x_func_state_params func_params = {NULL};
  12709. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12710. &func_params.params.set_timesync;
  12711. /* Prepare parameters for function state transitions */
  12712. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12713. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12714. func_params.f_obj = &bp->func_obj;
  12715. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12716. /* Function parameters */
  12717. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12718. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12719. return bnx2x_func_state_change(bp, &func_params);
  12720. }
  12721. static int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12722. {
  12723. struct bnx2x_queue_state_params q_params;
  12724. int rc, i;
  12725. /* send queue update ramrod to enable PTP packets */
  12726. memset(&q_params, 0, sizeof(q_params));
  12727. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12728. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12729. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12730. &q_params.params.update.update_flags);
  12731. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12732. &q_params.params.update.update_flags);
  12733. /* send the ramrod on all the queues of the PF */
  12734. for_each_eth_queue(bp, i) {
  12735. struct bnx2x_fastpath *fp = &bp->fp[i];
  12736. /* Set the appropriate Queue object */
  12737. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12738. /* Update the Queue state */
  12739. rc = bnx2x_queue_state_change(bp, &q_params);
  12740. if (rc) {
  12741. BNX2X_ERR("Failed to enable PTP packets\n");
  12742. return rc;
  12743. }
  12744. }
  12745. return 0;
  12746. }
  12747. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12748. {
  12749. int port = BP_PORT(bp);
  12750. int rc;
  12751. if (!bp->hwtstamp_ioctl_called)
  12752. return 0;
  12753. switch (bp->tx_type) {
  12754. case HWTSTAMP_TX_ON:
  12755. bp->flags |= TX_TIMESTAMPING_EN;
  12756. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12757. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12758. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12759. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12760. break;
  12761. case HWTSTAMP_TX_ONESTEP_SYNC:
  12762. BNX2X_ERR("One-step timestamping is not supported\n");
  12763. return -ERANGE;
  12764. }
  12765. switch (bp->rx_filter) {
  12766. case HWTSTAMP_FILTER_NONE:
  12767. break;
  12768. case HWTSTAMP_FILTER_ALL:
  12769. case HWTSTAMP_FILTER_SOME:
  12770. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12771. break;
  12772. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12773. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12774. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12775. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12776. /* Initialize PTP detection for UDP/IPv4 events */
  12777. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12778. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12779. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12780. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12781. break;
  12782. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12783. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12784. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12785. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12786. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12787. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12788. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12789. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12790. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12791. break;
  12792. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12793. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12794. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12795. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12796. /* Initialize PTP detection L2 events */
  12797. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12798. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12799. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12800. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12801. break;
  12802. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12803. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12804. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12805. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12806. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12807. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12808. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12809. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12810. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12811. break;
  12812. }
  12813. /* Indicate to FW that this PF expects recorded PTP packets */
  12814. rc = bnx2x_enable_ptp_packets(bp);
  12815. if (rc)
  12816. return rc;
  12817. /* Enable sending PTP packets to host */
  12818. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12819. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12820. return 0;
  12821. }
  12822. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12823. {
  12824. struct hwtstamp_config config;
  12825. int rc;
  12826. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12827. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12828. return -EFAULT;
  12829. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12830. config.tx_type, config.rx_filter);
  12831. if (config.flags) {
  12832. BNX2X_ERR("config.flags is reserved for future use\n");
  12833. return -EINVAL;
  12834. }
  12835. bp->hwtstamp_ioctl_called = 1;
  12836. bp->tx_type = config.tx_type;
  12837. bp->rx_filter = config.rx_filter;
  12838. rc = bnx2x_configure_ptp_filters(bp);
  12839. if (rc)
  12840. return rc;
  12841. config.rx_filter = bp->rx_filter;
  12842. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12843. -EFAULT : 0;
  12844. }
  12845. /* Configures HW for PTP */
  12846. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12847. {
  12848. int rc, port = BP_PORT(bp);
  12849. u32 wb_data[2];
  12850. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12851. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12852. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12853. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12854. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12855. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12856. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12857. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12858. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12859. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12860. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12861. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12862. /* Enable the PTP feature */
  12863. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12864. NIG_REG_P0_PTP_EN, 0x3F);
  12865. /* Enable the free-running counter */
  12866. wb_data[0] = 0;
  12867. wb_data[1] = 0;
  12868. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12869. /* Reset drift register (offset register is not reset) */
  12870. rc = bnx2x_send_reset_timesync_ramrod(bp);
  12871. if (rc) {
  12872. BNX2X_ERR("Failed to reset PHC drift register\n");
  12873. return -EFAULT;
  12874. }
  12875. /* Reset possibly old timestamps */
  12876. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12877. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12878. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12879. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12880. return 0;
  12881. }
  12882. /* Called during load, to initialize PTP-related stuff */
  12883. void bnx2x_init_ptp(struct bnx2x *bp)
  12884. {
  12885. int rc;
  12886. /* Configure PTP in HW */
  12887. rc = bnx2x_configure_ptp(bp);
  12888. if (rc) {
  12889. BNX2X_ERR("Stopping PTP initialization\n");
  12890. return;
  12891. }
  12892. /* Init work queue for Tx timestamping */
  12893. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  12894. /* Init cyclecounter and timecounter. This is done only in the first
  12895. * load. If done in every load, PTP application will fail when doing
  12896. * unload / load (e.g. MTU change) while it is running.
  12897. */
  12898. if (!bp->timecounter_init_done) {
  12899. bnx2x_init_cyclecounter(bp);
  12900. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  12901. ktime_to_ns(ktime_get_real()));
  12902. bp->timecounter_init_done = 1;
  12903. }
  12904. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  12905. }