bnx2x_main.c 403 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/aer.h>
  29. #include <linux/init.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/bitops.h>
  35. #include <linux/irq.h>
  36. #include <linux/delay.h>
  37. #include <asm/byteorder.h>
  38. #include <linux/time.h>
  39. #include <linux/ethtool.h>
  40. #include <linux/mii.h>
  41. #include <linux/if_vlan.h>
  42. #include <linux/crash_dump.h>
  43. #include <net/ip.h>
  44. #include <net/ipv6.h>
  45. #include <net/tcp.h>
  46. #include <net/vxlan.h>
  47. #include <net/checksum.h>
  48. #include <net/ip6_checksum.h>
  49. #include <linux/workqueue.h>
  50. #include <linux/crc32.h>
  51. #include <linux/crc32c.h>
  52. #include <linux/prefetch.h>
  53. #include <linux/zlib.h>
  54. #include <linux/io.h>
  55. #include <linux/semaphore.h>
  56. #include <linux/stringify.h>
  57. #include <linux/vmalloc.h>
  58. #include "bnx2x.h"
  59. #include "bnx2x_init.h"
  60. #include "bnx2x_init_ops.h"
  61. #include "bnx2x_cmn.h"
  62. #include "bnx2x_vfpf.h"
  63. #include "bnx2x_dcb.h"
  64. #include "bnx2x_sp.h"
  65. #include <linux/firmware.h>
  66. #include "bnx2x_fw_file_hdr.h"
  67. /* FW files */
  68. #define FW_FILE_VERSION \
  69. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  70. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  71. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  72. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  73. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  74. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  75. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  76. /* Time in jiffies before concluding the transmitter is hung */
  77. #define TX_TIMEOUT (5*HZ)
  78. static char version[] =
  79. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  80. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  81. MODULE_AUTHOR("Eliezer Tamir");
  82. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  83. "BCM57710/57711/57711E/"
  84. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  85. "57840/57840_MF Driver");
  86. MODULE_LICENSE("GPL");
  87. MODULE_VERSION(DRV_MODULE_VERSION);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  89. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  90. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  91. int bnx2x_num_queues;
  92. module_param_named(num_queues, bnx2x_num_queues, int, S_IRUGO);
  93. MODULE_PARM_DESC(num_queues,
  94. " Set number of queues (default is as a number of CPUs)");
  95. static int disable_tpa;
  96. module_param(disable_tpa, int, S_IRUGO);
  97. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  98. static int int_mode;
  99. module_param(int_mode, int, S_IRUGO);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, S_IRUGO);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int mrrs = -1;
  106. module_param(mrrs, int, S_IRUGO);
  107. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  108. static int debug;
  109. module_param(debug, int, S_IRUGO);
  110. MODULE_PARM_DESC(debug, " Default debug msglevel");
  111. static struct workqueue_struct *bnx2x_wq;
  112. struct workqueue_struct *bnx2x_iov_wq;
  113. struct bnx2x_mac_vals {
  114. u32 xmac_addr;
  115. u32 xmac_val;
  116. u32 emac_addr;
  117. u32 emac_val;
  118. u32 umac_addr;
  119. u32 umac_val;
  120. u32 bmac_addr;
  121. u32 bmac_val[2];
  122. };
  123. enum bnx2x_board_type {
  124. BCM57710 = 0,
  125. BCM57711,
  126. BCM57711E,
  127. BCM57712,
  128. BCM57712_MF,
  129. BCM57712_VF,
  130. BCM57800,
  131. BCM57800_MF,
  132. BCM57800_VF,
  133. BCM57810,
  134. BCM57810_MF,
  135. BCM57810_VF,
  136. BCM57840_4_10,
  137. BCM57840_2_20,
  138. BCM57840_MF,
  139. BCM57840_VF,
  140. BCM57811,
  141. BCM57811_MF,
  142. BCM57840_O,
  143. BCM57840_MFO,
  144. BCM57811_VF
  145. };
  146. /* indexed by board_type, above */
  147. static struct {
  148. char *name;
  149. } board_info[] = {
  150. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  151. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  152. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  153. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  154. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  155. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  156. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  157. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  158. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  159. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  160. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  161. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  162. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  163. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  164. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  165. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  166. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  167. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  168. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  169. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  170. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  171. };
  172. #ifndef PCI_DEVICE_ID_NX2_57710
  173. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  174. #endif
  175. #ifndef PCI_DEVICE_ID_NX2_57711
  176. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  177. #endif
  178. #ifndef PCI_DEVICE_ID_NX2_57711E
  179. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  180. #endif
  181. #ifndef PCI_DEVICE_ID_NX2_57712
  182. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  183. #endif
  184. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  185. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  186. #endif
  187. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  188. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  189. #endif
  190. #ifndef PCI_DEVICE_ID_NX2_57800
  191. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  192. #endif
  193. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  194. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  195. #endif
  196. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  197. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  198. #endif
  199. #ifndef PCI_DEVICE_ID_NX2_57810
  200. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  201. #endif
  202. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  203. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  204. #endif
  205. #ifndef PCI_DEVICE_ID_NX2_57840_O
  206. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  207. #endif
  208. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  209. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  210. #endif
  211. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  212. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  213. #endif
  214. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  215. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  216. #endif
  217. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  218. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  219. #endif
  220. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  221. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  222. #endif
  223. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  224. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  225. #endif
  226. #ifndef PCI_DEVICE_ID_NX2_57811
  227. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  228. #endif
  229. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  230. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  231. #endif
  232. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  233. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  234. #endif
  235. static const struct pci_device_id bnx2x_pci_tbl[] = {
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  256. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  257. { 0 }
  258. };
  259. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  260. /* Global resources for unloading a previously loaded device */
  261. #define BNX2X_PREV_WAIT_NEEDED 1
  262. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  263. static LIST_HEAD(bnx2x_prev_list);
  264. /* Forward declaration */
  265. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  266. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp);
  267. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  268. /****************************************************************************
  269. * General service functions
  270. ****************************************************************************/
  271. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr);
  272. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  273. u32 addr, dma_addr_t mapping)
  274. {
  275. REG_WR(bp, addr, U64_LO(mapping));
  276. REG_WR(bp, addr + 4, U64_HI(mapping));
  277. }
  278. static void storm_memset_spq_addr(struct bnx2x *bp,
  279. dma_addr_t mapping, u16 abs_fid)
  280. {
  281. u32 addr = XSEM_REG_FAST_MEMORY +
  282. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  283. __storm_memset_dma_mapping(bp, addr, mapping);
  284. }
  285. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  286. u16 pf_id)
  287. {
  288. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  291. pf_id);
  292. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  293. pf_id);
  294. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  295. pf_id);
  296. }
  297. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  298. u8 enable)
  299. {
  300. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  303. enable);
  304. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  305. enable);
  306. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  307. enable);
  308. }
  309. static void storm_memset_eq_data(struct bnx2x *bp,
  310. struct event_ring_data *eq_data,
  311. u16 pfid)
  312. {
  313. size_t size = sizeof(struct event_ring_data);
  314. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  315. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  316. }
  317. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  318. u16 pfid)
  319. {
  320. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  321. REG_WR16(bp, addr, eq_prod);
  322. }
  323. /* used only at init
  324. * locking is done by mcp
  325. */
  326. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  327. {
  328. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  331. PCICFG_VENDOR_ID_OFFSET);
  332. }
  333. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  334. {
  335. u32 val;
  336. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  337. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  338. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  339. PCICFG_VENDOR_ID_OFFSET);
  340. return val;
  341. }
  342. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  343. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  344. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  345. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  346. #define DMAE_DP_DST_NONE "dst_addr [none]"
  347. static void bnx2x_dp_dmae(struct bnx2x *bp,
  348. struct dmae_command *dmae, int msglvl)
  349. {
  350. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  351. int i;
  352. switch (dmae->opcode & DMAE_COMMAND_DST) {
  353. case DMAE_CMD_DST_PCI:
  354. if (src_type == DMAE_CMD_SRC_PCI)
  355. DP(msglvl, "DMAE: opcode 0x%08x\n"
  356. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  357. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  358. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  359. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  360. dmae->comp_addr_hi, dmae->comp_addr_lo,
  361. dmae->comp_val);
  362. else
  363. DP(msglvl, "DMAE: opcode 0x%08x\n"
  364. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  365. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  366. dmae->opcode, dmae->src_addr_lo >> 2,
  367. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  368. dmae->comp_addr_hi, dmae->comp_addr_lo,
  369. dmae->comp_val);
  370. break;
  371. case DMAE_CMD_DST_GRC:
  372. if (src_type == DMAE_CMD_SRC_PCI)
  373. DP(msglvl, "DMAE: opcode 0x%08x\n"
  374. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  375. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  376. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  377. dmae->len, dmae->dst_addr_lo >> 2,
  378. dmae->comp_addr_hi, dmae->comp_addr_lo,
  379. dmae->comp_val);
  380. else
  381. DP(msglvl, "DMAE: opcode 0x%08x\n"
  382. "src [%08x], len [%d*4], dst [%08x]\n"
  383. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  384. dmae->opcode, dmae->src_addr_lo >> 2,
  385. dmae->len, dmae->dst_addr_lo >> 2,
  386. dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. break;
  389. default:
  390. if (src_type == DMAE_CMD_SRC_PCI)
  391. DP(msglvl, "DMAE: opcode 0x%08x\n"
  392. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  393. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  394. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  395. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  396. dmae->comp_val);
  397. else
  398. DP(msglvl, "DMAE: opcode 0x%08x\n"
  399. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  400. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  401. dmae->opcode, dmae->src_addr_lo >> 2,
  402. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  403. dmae->comp_val);
  404. break;
  405. }
  406. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  407. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  408. i, *(((u32 *)dmae) + i));
  409. }
  410. /* copy command into DMAE command memory and set DMAE command go */
  411. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  412. {
  413. u32 cmd_offset;
  414. int i;
  415. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  416. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  417. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  418. }
  419. REG_WR(bp, dmae_reg_go_c[idx], 1);
  420. }
  421. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  422. {
  423. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  424. DMAE_CMD_C_ENABLE);
  425. }
  426. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  427. {
  428. return opcode & ~DMAE_CMD_SRC_RESET;
  429. }
  430. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  431. bool with_comp, u8 comp_type)
  432. {
  433. u32 opcode = 0;
  434. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  435. (dst_type << DMAE_COMMAND_DST_SHIFT));
  436. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  437. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  438. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  439. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  440. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  441. #ifdef __BIG_ENDIAN
  442. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  443. #else
  444. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  445. #endif
  446. if (with_comp)
  447. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  448. return opcode;
  449. }
  450. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  451. struct dmae_command *dmae,
  452. u8 src_type, u8 dst_type)
  453. {
  454. memset(dmae, 0, sizeof(struct dmae_command));
  455. /* set the opcode */
  456. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  457. true, DMAE_COMP_PCI);
  458. /* fill in the completion parameters */
  459. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  460. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  461. dmae->comp_val = DMAE_COMP_VAL;
  462. }
  463. /* issue a dmae command over the init-channel and wait for completion */
  464. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  465. u32 *comp)
  466. {
  467. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  468. int rc = 0;
  469. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  470. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  471. * as long as this code is called both from syscall context and
  472. * from ndo_set_rx_mode() flow that may be called from BH.
  473. */
  474. spin_lock_bh(&bp->dmae_lock);
  475. /* reset completion */
  476. *comp = 0;
  477. /* post the command on the channel used for initializations */
  478. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  479. /* wait for completion */
  480. udelay(5);
  481. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  482. if (!cnt ||
  483. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  484. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  485. BNX2X_ERR("DMAE timeout!\n");
  486. rc = DMAE_TIMEOUT;
  487. goto unlock;
  488. }
  489. cnt--;
  490. udelay(50);
  491. }
  492. if (*comp & DMAE_PCI_ERR_FLAG) {
  493. BNX2X_ERR("DMAE PCI error!\n");
  494. rc = DMAE_PCI_ERROR;
  495. }
  496. unlock:
  497. spin_unlock_bh(&bp->dmae_lock);
  498. return rc;
  499. }
  500. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  501. u32 len32)
  502. {
  503. int rc;
  504. struct dmae_command dmae;
  505. if (!bp->dmae_ready) {
  506. u32 *data = bnx2x_sp(bp, wb_data[0]);
  507. if (CHIP_IS_E1(bp))
  508. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  509. else
  510. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  511. return;
  512. }
  513. /* set opcode and fixed command fields */
  514. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  515. /* fill in addresses and len */
  516. dmae.src_addr_lo = U64_LO(dma_addr);
  517. dmae.src_addr_hi = U64_HI(dma_addr);
  518. dmae.dst_addr_lo = dst_addr >> 2;
  519. dmae.dst_addr_hi = 0;
  520. dmae.len = len32;
  521. /* issue the command and wait for completion */
  522. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  523. if (rc) {
  524. BNX2X_ERR("DMAE returned failure %d\n", rc);
  525. #ifdef BNX2X_STOP_ON_ERROR
  526. bnx2x_panic();
  527. #endif
  528. }
  529. }
  530. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  531. {
  532. int rc;
  533. struct dmae_command dmae;
  534. if (!bp->dmae_ready) {
  535. u32 *data = bnx2x_sp(bp, wb_data[0]);
  536. int i;
  537. if (CHIP_IS_E1(bp))
  538. for (i = 0; i < len32; i++)
  539. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  540. else
  541. for (i = 0; i < len32; i++)
  542. data[i] = REG_RD(bp, src_addr + i*4);
  543. return;
  544. }
  545. /* set opcode and fixed command fields */
  546. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  547. /* fill in addresses and len */
  548. dmae.src_addr_lo = src_addr >> 2;
  549. dmae.src_addr_hi = 0;
  550. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  551. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  552. dmae.len = len32;
  553. /* issue the command and wait for completion */
  554. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  555. if (rc) {
  556. BNX2X_ERR("DMAE returned failure %d\n", rc);
  557. #ifdef BNX2X_STOP_ON_ERROR
  558. bnx2x_panic();
  559. #endif
  560. }
  561. }
  562. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  563. u32 addr, u32 len)
  564. {
  565. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  566. int offset = 0;
  567. while (len > dmae_wr_max) {
  568. bnx2x_write_dmae(bp, phys_addr + offset,
  569. addr + offset, dmae_wr_max);
  570. offset += dmae_wr_max * 4;
  571. len -= dmae_wr_max;
  572. }
  573. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  574. }
  575. enum storms {
  576. XSTORM,
  577. TSTORM,
  578. CSTORM,
  579. USTORM,
  580. MAX_STORMS
  581. };
  582. #define STORMS_NUM 4
  583. #define REGS_IN_ENTRY 4
  584. static inline int bnx2x_get_assert_list_entry(struct bnx2x *bp,
  585. enum storms storm,
  586. int entry)
  587. {
  588. switch (storm) {
  589. case XSTORM:
  590. return XSTORM_ASSERT_LIST_OFFSET(entry);
  591. case TSTORM:
  592. return TSTORM_ASSERT_LIST_OFFSET(entry);
  593. case CSTORM:
  594. return CSTORM_ASSERT_LIST_OFFSET(entry);
  595. case USTORM:
  596. return USTORM_ASSERT_LIST_OFFSET(entry);
  597. case MAX_STORMS:
  598. default:
  599. BNX2X_ERR("unknown storm\n");
  600. }
  601. return -EINVAL;
  602. }
  603. static int bnx2x_mc_assert(struct bnx2x *bp)
  604. {
  605. char last_idx;
  606. int i, j, rc = 0;
  607. enum storms storm;
  608. u32 regs[REGS_IN_ENTRY];
  609. u32 bar_storm_intmem[STORMS_NUM] = {
  610. BAR_XSTRORM_INTMEM,
  611. BAR_TSTRORM_INTMEM,
  612. BAR_CSTRORM_INTMEM,
  613. BAR_USTRORM_INTMEM
  614. };
  615. u32 storm_assert_list_index[STORMS_NUM] = {
  616. XSTORM_ASSERT_LIST_INDEX_OFFSET,
  617. TSTORM_ASSERT_LIST_INDEX_OFFSET,
  618. CSTORM_ASSERT_LIST_INDEX_OFFSET,
  619. USTORM_ASSERT_LIST_INDEX_OFFSET
  620. };
  621. char *storms_string[STORMS_NUM] = {
  622. "XSTORM",
  623. "TSTORM",
  624. "CSTORM",
  625. "USTORM"
  626. };
  627. for (storm = XSTORM; storm < MAX_STORMS; storm++) {
  628. last_idx = REG_RD8(bp, bar_storm_intmem[storm] +
  629. storm_assert_list_index[storm]);
  630. if (last_idx)
  631. BNX2X_ERR("%s_ASSERT_LIST_INDEX 0x%x\n",
  632. storms_string[storm], last_idx);
  633. /* print the asserts */
  634. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  635. /* read a single assert entry */
  636. for (j = 0; j < REGS_IN_ENTRY; j++)
  637. regs[j] = REG_RD(bp, bar_storm_intmem[storm] +
  638. bnx2x_get_assert_list_entry(bp,
  639. storm,
  640. i) +
  641. sizeof(u32) * j);
  642. /* log entry if it contains a valid assert */
  643. if (regs[0] != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  644. BNX2X_ERR("%s_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  645. storms_string[storm], i, regs[3],
  646. regs[2], regs[1], regs[0]);
  647. rc++;
  648. } else {
  649. break;
  650. }
  651. }
  652. }
  653. BNX2X_ERR("Chip Revision: %s, FW Version: %d_%d_%d\n",
  654. CHIP_IS_E1(bp) ? "everest1" :
  655. CHIP_IS_E1H(bp) ? "everest1h" :
  656. CHIP_IS_E2(bp) ? "everest2" : "everest3",
  657. BCM_5710_FW_MAJOR_VERSION,
  658. BCM_5710_FW_MINOR_VERSION,
  659. BCM_5710_FW_REVISION_VERSION);
  660. return rc;
  661. }
  662. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  663. #define SCRATCH_BUFFER_SIZE(bp) \
  664. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  665. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  666. {
  667. u32 addr, val;
  668. u32 mark, offset;
  669. __be32 data[9];
  670. int word;
  671. u32 trace_shmem_base;
  672. if (BP_NOMCP(bp)) {
  673. BNX2X_ERR("NO MCP - can not dump\n");
  674. return;
  675. }
  676. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  677. (bp->common.bc_ver & 0xff0000) >> 16,
  678. (bp->common.bc_ver & 0xff00) >> 8,
  679. (bp->common.bc_ver & 0xff));
  680. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  681. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  682. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  683. if (BP_PATH(bp) == 0)
  684. trace_shmem_base = bp->common.shmem_base;
  685. else
  686. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  687. /* sanity */
  688. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  689. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  690. SCRATCH_BUFFER_SIZE(bp)) {
  691. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  692. trace_shmem_base);
  693. return;
  694. }
  695. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  696. /* validate TRCB signature */
  697. mark = REG_RD(bp, addr);
  698. if (mark != MFW_TRACE_SIGNATURE) {
  699. BNX2X_ERR("Trace buffer signature is missing.");
  700. return ;
  701. }
  702. /* read cyclic buffer pointer */
  703. addr += 4;
  704. mark = REG_RD(bp, addr);
  705. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  706. if (mark >= trace_shmem_base || mark < addr + 4) {
  707. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  708. return;
  709. }
  710. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  711. printk("%s", lvl);
  712. /* dump buffer after the mark */
  713. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  714. for (word = 0; word < 8; word++)
  715. data[word] = htonl(REG_RD(bp, offset + 4*word));
  716. data[8] = 0x0;
  717. pr_cont("%s", (char *)data);
  718. }
  719. /* dump buffer before the mark */
  720. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  721. for (word = 0; word < 8; word++)
  722. data[word] = htonl(REG_RD(bp, offset + 4*word));
  723. data[8] = 0x0;
  724. pr_cont("%s", (char *)data);
  725. }
  726. printk("%s" "end of fw dump\n", lvl);
  727. }
  728. static void bnx2x_fw_dump(struct bnx2x *bp)
  729. {
  730. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  731. }
  732. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  733. {
  734. int port = BP_PORT(bp);
  735. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  736. u32 val = REG_RD(bp, addr);
  737. /* in E1 we must use only PCI configuration space to disable
  738. * MSI/MSIX capability
  739. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  740. */
  741. if (CHIP_IS_E1(bp)) {
  742. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  743. * Use mask register to prevent from HC sending interrupts
  744. * after we exit the function
  745. */
  746. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  747. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  748. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  749. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  750. } else
  751. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  752. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  753. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  754. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  755. DP(NETIF_MSG_IFDOWN,
  756. "write %x to HC %d (addr 0x%x)\n",
  757. val, port, addr);
  758. /* flush all outstanding writes */
  759. mmiowb();
  760. REG_WR(bp, addr, val);
  761. if (REG_RD(bp, addr) != val)
  762. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  763. }
  764. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  765. {
  766. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  767. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  768. IGU_PF_CONF_INT_LINE_EN |
  769. IGU_PF_CONF_ATTN_BIT_EN);
  770. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  771. /* flush all outstanding writes */
  772. mmiowb();
  773. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  774. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  775. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  776. }
  777. static void bnx2x_int_disable(struct bnx2x *bp)
  778. {
  779. if (bp->common.int_block == INT_BLOCK_HC)
  780. bnx2x_hc_int_disable(bp);
  781. else
  782. bnx2x_igu_int_disable(bp);
  783. }
  784. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  785. {
  786. int i;
  787. u16 j;
  788. struct hc_sp_status_block_data sp_sb_data;
  789. int func = BP_FUNC(bp);
  790. #ifdef BNX2X_STOP_ON_ERROR
  791. u16 start = 0, end = 0;
  792. u8 cos;
  793. #endif
  794. if (IS_PF(bp) && disable_int)
  795. bnx2x_int_disable(bp);
  796. bp->stats_state = STATS_STATE_DISABLED;
  797. bp->eth_stats.unrecoverable_error++;
  798. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  799. BNX2X_ERR("begin crash dump -----------------\n");
  800. /* Indices */
  801. /* Common */
  802. if (IS_PF(bp)) {
  803. struct host_sp_status_block *def_sb = bp->def_status_blk;
  804. int data_size, cstorm_offset;
  805. 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",
  806. bp->def_idx, bp->def_att_idx, bp->attn_state,
  807. bp->spq_prod_idx, bp->stats_counter);
  808. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  809. def_sb->atten_status_block.attn_bits,
  810. def_sb->atten_status_block.attn_bits_ack,
  811. def_sb->atten_status_block.status_block_id,
  812. def_sb->atten_status_block.attn_bits_index);
  813. BNX2X_ERR(" def (");
  814. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  815. pr_cont("0x%x%s",
  816. def_sb->sp_sb.index_values[i],
  817. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  818. data_size = sizeof(struct hc_sp_status_block_data) /
  819. sizeof(u32);
  820. cstorm_offset = CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func);
  821. for (i = 0; i < data_size; i++)
  822. *((u32 *)&sp_sb_data + i) =
  823. REG_RD(bp, BAR_CSTRORM_INTMEM + cstorm_offset +
  824. i * sizeof(u32));
  825. 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",
  826. sp_sb_data.igu_sb_id,
  827. sp_sb_data.igu_seg_id,
  828. sp_sb_data.p_func.pf_id,
  829. sp_sb_data.p_func.vnic_id,
  830. sp_sb_data.p_func.vf_id,
  831. sp_sb_data.p_func.vf_valid,
  832. sp_sb_data.state);
  833. }
  834. for_each_eth_queue(bp, i) {
  835. struct bnx2x_fastpath *fp = &bp->fp[i];
  836. int loop;
  837. struct hc_status_block_data_e2 sb_data_e2;
  838. struct hc_status_block_data_e1x sb_data_e1x;
  839. struct hc_status_block_sm *hc_sm_p =
  840. CHIP_IS_E1x(bp) ?
  841. sb_data_e1x.common.state_machine :
  842. sb_data_e2.common.state_machine;
  843. struct hc_index_data *hc_index_p =
  844. CHIP_IS_E1x(bp) ?
  845. sb_data_e1x.index_data :
  846. sb_data_e2.index_data;
  847. u8 data_size, cos;
  848. u32 *sb_data_p;
  849. struct bnx2x_fp_txdata txdata;
  850. if (!bp->fp)
  851. break;
  852. if (!fp->rx_cons_sb)
  853. continue;
  854. /* Rx */
  855. 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",
  856. i, fp->rx_bd_prod, fp->rx_bd_cons,
  857. fp->rx_comp_prod,
  858. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  859. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  860. fp->rx_sge_prod, fp->last_max_sge,
  861. le16_to_cpu(fp->fp_hc_idx));
  862. /* Tx */
  863. for_each_cos_in_tx_queue(fp, cos)
  864. {
  865. if (!fp->txdata_ptr[cos])
  866. break;
  867. txdata = *fp->txdata_ptr[cos];
  868. if (!txdata.tx_cons_sb)
  869. continue;
  870. 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",
  871. i, txdata.tx_pkt_prod,
  872. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  873. txdata.tx_bd_cons,
  874. le16_to_cpu(*txdata.tx_cons_sb));
  875. }
  876. loop = CHIP_IS_E1x(bp) ?
  877. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  878. /* host sb data */
  879. if (IS_FCOE_FP(fp))
  880. continue;
  881. BNX2X_ERR(" run indexes (");
  882. for (j = 0; j < HC_SB_MAX_SM; j++)
  883. pr_cont("0x%x%s",
  884. fp->sb_running_index[j],
  885. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  886. BNX2X_ERR(" indexes (");
  887. for (j = 0; j < loop; j++)
  888. pr_cont("0x%x%s",
  889. fp->sb_index_values[j],
  890. (j == loop - 1) ? ")" : " ");
  891. /* VF cannot access FW refelection for status block */
  892. if (IS_VF(bp))
  893. continue;
  894. /* fw sb data */
  895. data_size = CHIP_IS_E1x(bp) ?
  896. sizeof(struct hc_status_block_data_e1x) :
  897. sizeof(struct hc_status_block_data_e2);
  898. data_size /= sizeof(u32);
  899. sb_data_p = CHIP_IS_E1x(bp) ?
  900. (u32 *)&sb_data_e1x :
  901. (u32 *)&sb_data_e2;
  902. /* copy sb data in here */
  903. for (j = 0; j < data_size; j++)
  904. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  905. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  906. j * sizeof(u32));
  907. if (!CHIP_IS_E1x(bp)) {
  908. 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",
  909. sb_data_e2.common.p_func.pf_id,
  910. sb_data_e2.common.p_func.vf_id,
  911. sb_data_e2.common.p_func.vf_valid,
  912. sb_data_e2.common.p_func.vnic_id,
  913. sb_data_e2.common.same_igu_sb_1b,
  914. sb_data_e2.common.state);
  915. } else {
  916. 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",
  917. sb_data_e1x.common.p_func.pf_id,
  918. sb_data_e1x.common.p_func.vf_id,
  919. sb_data_e1x.common.p_func.vf_valid,
  920. sb_data_e1x.common.p_func.vnic_id,
  921. sb_data_e1x.common.same_igu_sb_1b,
  922. sb_data_e1x.common.state);
  923. }
  924. /* SB_SMs data */
  925. for (j = 0; j < HC_SB_MAX_SM; j++) {
  926. 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",
  927. j, hc_sm_p[j].__flags,
  928. hc_sm_p[j].igu_sb_id,
  929. hc_sm_p[j].igu_seg_id,
  930. hc_sm_p[j].time_to_expire,
  931. hc_sm_p[j].timer_value);
  932. }
  933. /* Indices data */
  934. for (j = 0; j < loop; j++) {
  935. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  936. hc_index_p[j].flags,
  937. hc_index_p[j].timeout);
  938. }
  939. }
  940. #ifdef BNX2X_STOP_ON_ERROR
  941. if (IS_PF(bp)) {
  942. /* event queue */
  943. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  944. for (i = 0; i < NUM_EQ_DESC; i++) {
  945. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  946. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  947. i, bp->eq_ring[i].message.opcode,
  948. bp->eq_ring[i].message.error);
  949. BNX2X_ERR("data: %x %x %x\n",
  950. data[0], data[1], data[2]);
  951. }
  952. }
  953. /* Rings */
  954. /* Rx */
  955. for_each_valid_rx_queue(bp, i) {
  956. struct bnx2x_fastpath *fp = &bp->fp[i];
  957. if (!bp->fp)
  958. break;
  959. if (!fp->rx_cons_sb)
  960. continue;
  961. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  962. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  963. for (j = start; j != end; j = RX_BD(j + 1)) {
  964. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  965. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  966. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  967. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  968. }
  969. start = RX_SGE(fp->rx_sge_prod);
  970. end = RX_SGE(fp->last_max_sge);
  971. for (j = start; j != end; j = RX_SGE(j + 1)) {
  972. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  973. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  974. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  975. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  976. }
  977. start = RCQ_BD(fp->rx_comp_cons - 10);
  978. end = RCQ_BD(fp->rx_comp_cons + 503);
  979. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  980. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  981. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  982. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  983. }
  984. }
  985. /* Tx */
  986. for_each_valid_tx_queue(bp, i) {
  987. struct bnx2x_fastpath *fp = &bp->fp[i];
  988. if (!bp->fp)
  989. break;
  990. for_each_cos_in_tx_queue(fp, cos) {
  991. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  992. if (!fp->txdata_ptr[cos])
  993. break;
  994. if (!txdata->tx_cons_sb)
  995. continue;
  996. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  997. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  998. for (j = start; j != end; j = TX_BD(j + 1)) {
  999. struct sw_tx_bd *sw_bd =
  1000. &txdata->tx_buf_ring[j];
  1001. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  1002. i, cos, j, sw_bd->skb,
  1003. sw_bd->first_bd);
  1004. }
  1005. start = TX_BD(txdata->tx_bd_cons - 10);
  1006. end = TX_BD(txdata->tx_bd_cons + 254);
  1007. for (j = start; j != end; j = TX_BD(j + 1)) {
  1008. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  1009. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  1010. i, cos, j, tx_bd[0], tx_bd[1],
  1011. tx_bd[2], tx_bd[3]);
  1012. }
  1013. }
  1014. }
  1015. #endif
  1016. if (IS_PF(bp)) {
  1017. bnx2x_fw_dump(bp);
  1018. bnx2x_mc_assert(bp);
  1019. }
  1020. BNX2X_ERR("end crash dump -----------------\n");
  1021. }
  1022. /*
  1023. * FLR Support for E2
  1024. *
  1025. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  1026. * initialization.
  1027. */
  1028. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  1029. #define FLR_WAIT_INTERVAL 50 /* usec */
  1030. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  1031. struct pbf_pN_buf_regs {
  1032. int pN;
  1033. u32 init_crd;
  1034. u32 crd;
  1035. u32 crd_freed;
  1036. };
  1037. struct pbf_pN_cmd_regs {
  1038. int pN;
  1039. u32 lines_occup;
  1040. u32 lines_freed;
  1041. };
  1042. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1043. struct pbf_pN_buf_regs *regs,
  1044. u32 poll_count)
  1045. {
  1046. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1047. u32 cur_cnt = poll_count;
  1048. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1049. crd = crd_start = REG_RD(bp, regs->crd);
  1050. init_crd = REG_RD(bp, regs->init_crd);
  1051. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1052. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1053. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1054. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1055. (init_crd - crd_start))) {
  1056. if (cur_cnt--) {
  1057. udelay(FLR_WAIT_INTERVAL);
  1058. crd = REG_RD(bp, regs->crd);
  1059. crd_freed = REG_RD(bp, regs->crd_freed);
  1060. } else {
  1061. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1062. regs->pN);
  1063. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1064. regs->pN, crd);
  1065. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1066. regs->pN, crd_freed);
  1067. break;
  1068. }
  1069. }
  1070. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1071. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1072. }
  1073. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1074. struct pbf_pN_cmd_regs *regs,
  1075. u32 poll_count)
  1076. {
  1077. u32 occup, to_free, freed, freed_start;
  1078. u32 cur_cnt = poll_count;
  1079. occup = to_free = REG_RD(bp, regs->lines_occup);
  1080. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1081. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1082. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1083. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1084. if (cur_cnt--) {
  1085. udelay(FLR_WAIT_INTERVAL);
  1086. occup = REG_RD(bp, regs->lines_occup);
  1087. freed = REG_RD(bp, regs->lines_freed);
  1088. } else {
  1089. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1090. regs->pN);
  1091. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1092. regs->pN, occup);
  1093. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1094. regs->pN, freed);
  1095. break;
  1096. }
  1097. }
  1098. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1099. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1100. }
  1101. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1102. u32 expected, u32 poll_count)
  1103. {
  1104. u32 cur_cnt = poll_count;
  1105. u32 val;
  1106. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1107. udelay(FLR_WAIT_INTERVAL);
  1108. return val;
  1109. }
  1110. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1111. char *msg, u32 poll_cnt)
  1112. {
  1113. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1114. if (val != 0) {
  1115. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1116. return 1;
  1117. }
  1118. return 0;
  1119. }
  1120. /* Common routines with VF FLR cleanup */
  1121. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1122. {
  1123. /* adjust polling timeout */
  1124. if (CHIP_REV_IS_EMUL(bp))
  1125. return FLR_POLL_CNT * 2000;
  1126. if (CHIP_REV_IS_FPGA(bp))
  1127. return FLR_POLL_CNT * 120;
  1128. return FLR_POLL_CNT;
  1129. }
  1130. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1131. {
  1132. struct pbf_pN_cmd_regs cmd_regs[] = {
  1133. {0, (CHIP_IS_E3B0(bp)) ?
  1134. PBF_REG_TQ_OCCUPANCY_Q0 :
  1135. PBF_REG_P0_TQ_OCCUPANCY,
  1136. (CHIP_IS_E3B0(bp)) ?
  1137. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1138. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1139. {1, (CHIP_IS_E3B0(bp)) ?
  1140. PBF_REG_TQ_OCCUPANCY_Q1 :
  1141. PBF_REG_P1_TQ_OCCUPANCY,
  1142. (CHIP_IS_E3B0(bp)) ?
  1143. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1144. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1145. {4, (CHIP_IS_E3B0(bp)) ?
  1146. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1147. PBF_REG_P4_TQ_OCCUPANCY,
  1148. (CHIP_IS_E3B0(bp)) ?
  1149. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1150. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1151. };
  1152. struct pbf_pN_buf_regs buf_regs[] = {
  1153. {0, (CHIP_IS_E3B0(bp)) ?
  1154. PBF_REG_INIT_CRD_Q0 :
  1155. PBF_REG_P0_INIT_CRD ,
  1156. (CHIP_IS_E3B0(bp)) ?
  1157. PBF_REG_CREDIT_Q0 :
  1158. PBF_REG_P0_CREDIT,
  1159. (CHIP_IS_E3B0(bp)) ?
  1160. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1161. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1162. {1, (CHIP_IS_E3B0(bp)) ?
  1163. PBF_REG_INIT_CRD_Q1 :
  1164. PBF_REG_P1_INIT_CRD,
  1165. (CHIP_IS_E3B0(bp)) ?
  1166. PBF_REG_CREDIT_Q1 :
  1167. PBF_REG_P1_CREDIT,
  1168. (CHIP_IS_E3B0(bp)) ?
  1169. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1170. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1171. {4, (CHIP_IS_E3B0(bp)) ?
  1172. PBF_REG_INIT_CRD_LB_Q :
  1173. PBF_REG_P4_INIT_CRD,
  1174. (CHIP_IS_E3B0(bp)) ?
  1175. PBF_REG_CREDIT_LB_Q :
  1176. PBF_REG_P4_CREDIT,
  1177. (CHIP_IS_E3B0(bp)) ?
  1178. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1179. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1180. };
  1181. int i;
  1182. /* Verify the command queues are flushed P0, P1, P4 */
  1183. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1184. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1185. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1186. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1187. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1188. }
  1189. #define OP_GEN_PARAM(param) \
  1190. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1191. #define OP_GEN_TYPE(type) \
  1192. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1193. #define OP_GEN_AGG_VECT(index) \
  1194. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1195. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1196. {
  1197. u32 op_gen_command = 0;
  1198. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1199. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1200. int ret = 0;
  1201. if (REG_RD(bp, comp_addr)) {
  1202. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1203. return 1;
  1204. }
  1205. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1206. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1207. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1208. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1209. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1210. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1211. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1212. BNX2X_ERR("FW final cleanup did not succeed\n");
  1213. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1214. (REG_RD(bp, comp_addr)));
  1215. bnx2x_panic();
  1216. return 1;
  1217. }
  1218. /* Zero completion for next FLR */
  1219. REG_WR(bp, comp_addr, 0);
  1220. return ret;
  1221. }
  1222. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1223. {
  1224. u16 status;
  1225. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1226. return status & PCI_EXP_DEVSTA_TRPND;
  1227. }
  1228. /* PF FLR specific routines
  1229. */
  1230. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1231. {
  1232. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1233. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1234. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1235. "CFC PF usage counter timed out",
  1236. poll_cnt))
  1237. return 1;
  1238. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1239. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1240. DORQ_REG_PF_USAGE_CNT,
  1241. "DQ PF usage counter timed out",
  1242. poll_cnt))
  1243. return 1;
  1244. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1245. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1246. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1247. "QM PF usage counter timed out",
  1248. poll_cnt))
  1249. return 1;
  1250. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1251. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1252. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1253. "Timers VNIC usage counter timed out",
  1254. poll_cnt))
  1255. return 1;
  1256. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1257. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1258. "Timers NUM_SCANS usage counter timed out",
  1259. poll_cnt))
  1260. return 1;
  1261. /* Wait DMAE PF usage counter to zero */
  1262. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1263. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1264. "DMAE command register timed out",
  1265. poll_cnt))
  1266. return 1;
  1267. return 0;
  1268. }
  1269. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1270. {
  1271. u32 val;
  1272. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1273. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1274. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1275. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1276. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1277. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1278. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1279. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1280. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1281. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1282. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1283. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1284. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1285. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1286. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1287. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1288. val);
  1289. }
  1290. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1291. {
  1292. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1293. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1294. /* Re-enable PF target read access */
  1295. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1296. /* Poll HW usage counters */
  1297. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1298. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1299. return -EBUSY;
  1300. /* Zero the igu 'trailing edge' and 'leading edge' */
  1301. /* Send the FW cleanup command */
  1302. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1303. return -EBUSY;
  1304. /* ATC cleanup */
  1305. /* Verify TX hw is flushed */
  1306. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1307. /* Wait 100ms (not adjusted according to platform) */
  1308. msleep(100);
  1309. /* Verify no pending pci transactions */
  1310. if (bnx2x_is_pcie_pending(bp->pdev))
  1311. BNX2X_ERR("PCIE Transactions still pending\n");
  1312. /* Debug */
  1313. bnx2x_hw_enable_status(bp);
  1314. /*
  1315. * Master enable - Due to WB DMAE writes performed before this
  1316. * register is re-initialized as part of the regular function init
  1317. */
  1318. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1319. return 0;
  1320. }
  1321. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1322. {
  1323. int port = BP_PORT(bp);
  1324. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1325. u32 val = REG_RD(bp, addr);
  1326. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1327. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1328. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1329. if (msix) {
  1330. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1331. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1332. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1333. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1334. if (single_msix)
  1335. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1336. } else if (msi) {
  1337. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1338. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1339. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1340. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1341. } else {
  1342. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1343. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1344. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1345. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1346. if (!CHIP_IS_E1(bp)) {
  1347. DP(NETIF_MSG_IFUP,
  1348. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1349. REG_WR(bp, addr, val);
  1350. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1351. }
  1352. }
  1353. if (CHIP_IS_E1(bp))
  1354. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1355. DP(NETIF_MSG_IFUP,
  1356. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1357. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1358. REG_WR(bp, addr, val);
  1359. /*
  1360. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1361. */
  1362. mmiowb();
  1363. barrier();
  1364. if (!CHIP_IS_E1(bp)) {
  1365. /* init leading/trailing edge */
  1366. if (IS_MF(bp)) {
  1367. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1368. if (bp->port.pmf)
  1369. /* enable nig and gpio3 attention */
  1370. val |= 0x1100;
  1371. } else
  1372. val = 0xffff;
  1373. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1374. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1375. }
  1376. /* Make sure that interrupts are indeed enabled from here on */
  1377. mmiowb();
  1378. }
  1379. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1380. {
  1381. u32 val;
  1382. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1383. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1384. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1385. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1386. if (msix) {
  1387. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1388. IGU_PF_CONF_SINGLE_ISR_EN);
  1389. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1390. IGU_PF_CONF_ATTN_BIT_EN);
  1391. if (single_msix)
  1392. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1393. } else if (msi) {
  1394. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1395. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1396. IGU_PF_CONF_ATTN_BIT_EN |
  1397. IGU_PF_CONF_SINGLE_ISR_EN);
  1398. } else {
  1399. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1400. val |= (IGU_PF_CONF_INT_LINE_EN |
  1401. IGU_PF_CONF_ATTN_BIT_EN |
  1402. IGU_PF_CONF_SINGLE_ISR_EN);
  1403. }
  1404. /* Clean previous status - need to configure igu prior to ack*/
  1405. if ((!msix) || single_msix) {
  1406. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1407. bnx2x_ack_int(bp);
  1408. }
  1409. val |= IGU_PF_CONF_FUNC_EN;
  1410. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1411. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1412. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1413. if (val & IGU_PF_CONF_INT_LINE_EN)
  1414. pci_intx(bp->pdev, true);
  1415. barrier();
  1416. /* init leading/trailing edge */
  1417. if (IS_MF(bp)) {
  1418. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1419. if (bp->port.pmf)
  1420. /* enable nig and gpio3 attention */
  1421. val |= 0x1100;
  1422. } else
  1423. val = 0xffff;
  1424. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1425. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1426. /* Make sure that interrupts are indeed enabled from here on */
  1427. mmiowb();
  1428. }
  1429. void bnx2x_int_enable(struct bnx2x *bp)
  1430. {
  1431. if (bp->common.int_block == INT_BLOCK_HC)
  1432. bnx2x_hc_int_enable(bp);
  1433. else
  1434. bnx2x_igu_int_enable(bp);
  1435. }
  1436. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1437. {
  1438. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1439. int i, offset;
  1440. if (disable_hw)
  1441. /* prevent the HW from sending interrupts */
  1442. bnx2x_int_disable(bp);
  1443. /* make sure all ISRs are done */
  1444. if (msix) {
  1445. synchronize_irq(bp->msix_table[0].vector);
  1446. offset = 1;
  1447. if (CNIC_SUPPORT(bp))
  1448. offset++;
  1449. for_each_eth_queue(bp, i)
  1450. synchronize_irq(bp->msix_table[offset++].vector);
  1451. } else
  1452. synchronize_irq(bp->pdev->irq);
  1453. /* make sure sp_task is not running */
  1454. cancel_delayed_work(&bp->sp_task);
  1455. cancel_delayed_work(&bp->period_task);
  1456. flush_workqueue(bnx2x_wq);
  1457. }
  1458. /* fast path */
  1459. /*
  1460. * General service functions
  1461. */
  1462. /* Return true if succeeded to acquire the lock */
  1463. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1464. {
  1465. u32 lock_status;
  1466. u32 resource_bit = (1 << resource);
  1467. int func = BP_FUNC(bp);
  1468. u32 hw_lock_control_reg;
  1469. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1470. "Trying to take a lock on resource %d\n", resource);
  1471. /* Validating that the resource is within range */
  1472. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1473. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1474. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1475. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1476. return false;
  1477. }
  1478. if (func <= 5)
  1479. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1480. else
  1481. hw_lock_control_reg =
  1482. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1483. /* Try to acquire the lock */
  1484. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1485. lock_status = REG_RD(bp, hw_lock_control_reg);
  1486. if (lock_status & resource_bit)
  1487. return true;
  1488. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1489. "Failed to get a lock on resource %d\n", resource);
  1490. return false;
  1491. }
  1492. /**
  1493. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1494. *
  1495. * @bp: driver handle
  1496. *
  1497. * Returns the recovery leader resource id according to the engine this function
  1498. * belongs to. Currently only only 2 engines is supported.
  1499. */
  1500. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1501. {
  1502. if (BP_PATH(bp))
  1503. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1504. else
  1505. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1506. }
  1507. /**
  1508. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1509. *
  1510. * @bp: driver handle
  1511. *
  1512. * Tries to acquire a leader lock for current engine.
  1513. */
  1514. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1515. {
  1516. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1517. }
  1518. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1519. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1520. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1521. {
  1522. /* Set the interrupt occurred bit for the sp-task to recognize it
  1523. * must ack the interrupt and transition according to the IGU
  1524. * state machine.
  1525. */
  1526. atomic_set(&bp->interrupt_occurred, 1);
  1527. /* The sp_task must execute only after this bit
  1528. * is set, otherwise we will get out of sync and miss all
  1529. * further interrupts. Hence, the barrier.
  1530. */
  1531. smp_wmb();
  1532. /* schedule sp_task to workqueue */
  1533. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1534. }
  1535. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1536. {
  1537. struct bnx2x *bp = fp->bp;
  1538. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1539. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1540. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1541. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1542. DP(BNX2X_MSG_SP,
  1543. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1544. fp->index, cid, command, bp->state,
  1545. rr_cqe->ramrod_cqe.ramrod_type);
  1546. /* If cid is within VF range, replace the slowpath object with the
  1547. * one corresponding to this VF
  1548. */
  1549. if (cid >= BNX2X_FIRST_VF_CID &&
  1550. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1551. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1552. switch (command) {
  1553. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1554. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1555. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1556. break;
  1557. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1558. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1559. drv_cmd = BNX2X_Q_CMD_SETUP;
  1560. break;
  1561. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1562. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1563. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1564. break;
  1565. case (RAMROD_CMD_ID_ETH_HALT):
  1566. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1567. drv_cmd = BNX2X_Q_CMD_HALT;
  1568. break;
  1569. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1570. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1571. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1572. break;
  1573. case (RAMROD_CMD_ID_ETH_EMPTY):
  1574. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1575. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1576. break;
  1577. case (RAMROD_CMD_ID_ETH_TPA_UPDATE):
  1578. DP(BNX2X_MSG_SP, "got tpa update ramrod CID=%d\n", cid);
  1579. drv_cmd = BNX2X_Q_CMD_UPDATE_TPA;
  1580. break;
  1581. default:
  1582. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1583. command, fp->index);
  1584. return;
  1585. }
  1586. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1587. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1588. /* q_obj->complete_cmd() failure means that this was
  1589. * an unexpected completion.
  1590. *
  1591. * In this case we don't want to increase the bp->spq_left
  1592. * because apparently we haven't sent this command the first
  1593. * place.
  1594. */
  1595. #ifdef BNX2X_STOP_ON_ERROR
  1596. bnx2x_panic();
  1597. #else
  1598. return;
  1599. #endif
  1600. smp_mb__before_atomic();
  1601. atomic_inc(&bp->cq_spq_left);
  1602. /* push the change in bp->spq_left and towards the memory */
  1603. smp_mb__after_atomic();
  1604. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1605. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1606. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1607. /* if Q update ramrod is completed for last Q in AFEX vif set
  1608. * flow, then ACK MCP at the end
  1609. *
  1610. * mark pending ACK to MCP bit.
  1611. * prevent case that both bits are cleared.
  1612. * At the end of load/unload driver checks that
  1613. * sp_state is cleared, and this order prevents
  1614. * races
  1615. */
  1616. smp_mb__before_atomic();
  1617. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1618. wmb();
  1619. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1620. smp_mb__after_atomic();
  1621. /* schedule the sp task as mcp ack is required */
  1622. bnx2x_schedule_sp_task(bp);
  1623. }
  1624. return;
  1625. }
  1626. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1627. {
  1628. struct bnx2x *bp = netdev_priv(dev_instance);
  1629. u16 status = bnx2x_ack_int(bp);
  1630. u16 mask;
  1631. int i;
  1632. u8 cos;
  1633. /* Return here if interrupt is shared and it's not for us */
  1634. if (unlikely(status == 0)) {
  1635. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1636. return IRQ_NONE;
  1637. }
  1638. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1639. #ifdef BNX2X_STOP_ON_ERROR
  1640. if (unlikely(bp->panic))
  1641. return IRQ_HANDLED;
  1642. #endif
  1643. for_each_eth_queue(bp, i) {
  1644. struct bnx2x_fastpath *fp = &bp->fp[i];
  1645. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1646. if (status & mask) {
  1647. /* Handle Rx or Tx according to SB id */
  1648. for_each_cos_in_tx_queue(fp, cos)
  1649. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1650. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1651. napi_schedule_irqoff(&bnx2x_fp(bp, fp->index, napi));
  1652. status &= ~mask;
  1653. }
  1654. }
  1655. if (CNIC_SUPPORT(bp)) {
  1656. mask = 0x2;
  1657. if (status & (mask | 0x1)) {
  1658. struct cnic_ops *c_ops = NULL;
  1659. rcu_read_lock();
  1660. c_ops = rcu_dereference(bp->cnic_ops);
  1661. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1662. CNIC_DRV_STATE_HANDLES_IRQ))
  1663. c_ops->cnic_handler(bp->cnic_data, NULL);
  1664. rcu_read_unlock();
  1665. status &= ~mask;
  1666. }
  1667. }
  1668. if (unlikely(status & 0x1)) {
  1669. /* schedule sp task to perform default status block work, ack
  1670. * attentions and enable interrupts.
  1671. */
  1672. bnx2x_schedule_sp_task(bp);
  1673. status &= ~0x1;
  1674. if (!status)
  1675. return IRQ_HANDLED;
  1676. }
  1677. if (unlikely(status))
  1678. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1679. status);
  1680. return IRQ_HANDLED;
  1681. }
  1682. /* Link */
  1683. /*
  1684. * General service functions
  1685. */
  1686. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1687. {
  1688. u32 lock_status;
  1689. u32 resource_bit = (1 << resource);
  1690. int func = BP_FUNC(bp);
  1691. u32 hw_lock_control_reg;
  1692. int cnt;
  1693. /* Validating that the resource is within range */
  1694. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1695. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1696. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1697. return -EINVAL;
  1698. }
  1699. if (func <= 5) {
  1700. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1701. } else {
  1702. hw_lock_control_reg =
  1703. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1704. }
  1705. /* Validating that the resource is not already taken */
  1706. lock_status = REG_RD(bp, hw_lock_control_reg);
  1707. if (lock_status & resource_bit) {
  1708. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1709. lock_status, resource_bit);
  1710. return -EEXIST;
  1711. }
  1712. /* Try for 5 second every 5ms */
  1713. for (cnt = 0; cnt < 1000; cnt++) {
  1714. /* Try to acquire the lock */
  1715. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1716. lock_status = REG_RD(bp, hw_lock_control_reg);
  1717. if (lock_status & resource_bit)
  1718. return 0;
  1719. usleep_range(5000, 10000);
  1720. }
  1721. BNX2X_ERR("Timeout\n");
  1722. return -EAGAIN;
  1723. }
  1724. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1725. {
  1726. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1727. }
  1728. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1729. {
  1730. u32 lock_status;
  1731. u32 resource_bit = (1 << resource);
  1732. int func = BP_FUNC(bp);
  1733. u32 hw_lock_control_reg;
  1734. /* Validating that the resource is within range */
  1735. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1736. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1737. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1738. return -EINVAL;
  1739. }
  1740. if (func <= 5) {
  1741. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1742. } else {
  1743. hw_lock_control_reg =
  1744. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1745. }
  1746. /* Validating that the resource is currently taken */
  1747. lock_status = REG_RD(bp, hw_lock_control_reg);
  1748. if (!(lock_status & resource_bit)) {
  1749. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1750. lock_status, resource_bit);
  1751. return -EFAULT;
  1752. }
  1753. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1754. return 0;
  1755. }
  1756. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1757. {
  1758. /* The GPIO should be swapped if swap register is set and active */
  1759. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1760. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1761. int gpio_shift = gpio_num +
  1762. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1763. u32 gpio_mask = (1 << gpio_shift);
  1764. u32 gpio_reg;
  1765. int value;
  1766. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1767. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1768. return -EINVAL;
  1769. }
  1770. /* read GPIO value */
  1771. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1772. /* get the requested pin value */
  1773. if ((gpio_reg & gpio_mask) == gpio_mask)
  1774. value = 1;
  1775. else
  1776. value = 0;
  1777. return value;
  1778. }
  1779. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1780. {
  1781. /* The GPIO should be swapped if swap register is set and active */
  1782. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1783. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1784. int gpio_shift = gpio_num +
  1785. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1786. u32 gpio_mask = (1 << gpio_shift);
  1787. u32 gpio_reg;
  1788. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1789. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1790. return -EINVAL;
  1791. }
  1792. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1793. /* read GPIO and mask except the float bits */
  1794. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1795. switch (mode) {
  1796. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1797. DP(NETIF_MSG_LINK,
  1798. "Set GPIO %d (shift %d) -> output low\n",
  1799. gpio_num, gpio_shift);
  1800. /* clear FLOAT and set CLR */
  1801. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1802. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1803. break;
  1804. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1805. DP(NETIF_MSG_LINK,
  1806. "Set GPIO %d (shift %d) -> output high\n",
  1807. gpio_num, gpio_shift);
  1808. /* clear FLOAT and set SET */
  1809. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1810. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1811. break;
  1812. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1813. DP(NETIF_MSG_LINK,
  1814. "Set GPIO %d (shift %d) -> input\n",
  1815. gpio_num, gpio_shift);
  1816. /* set FLOAT */
  1817. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1818. break;
  1819. default:
  1820. break;
  1821. }
  1822. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1823. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1824. return 0;
  1825. }
  1826. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1827. {
  1828. u32 gpio_reg = 0;
  1829. int rc = 0;
  1830. /* Any port swapping should be handled by caller. */
  1831. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1832. /* read GPIO and mask except the float bits */
  1833. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1834. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1835. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1836. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1837. switch (mode) {
  1838. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1839. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1840. /* set CLR */
  1841. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1842. break;
  1843. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1844. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1845. /* set SET */
  1846. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1847. break;
  1848. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1849. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1850. /* set FLOAT */
  1851. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1852. break;
  1853. default:
  1854. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1855. rc = -EINVAL;
  1856. break;
  1857. }
  1858. if (rc == 0)
  1859. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1860. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1861. return rc;
  1862. }
  1863. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1864. {
  1865. /* The GPIO should be swapped if swap register is set and active */
  1866. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1867. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1868. int gpio_shift = gpio_num +
  1869. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1870. u32 gpio_mask = (1 << gpio_shift);
  1871. u32 gpio_reg;
  1872. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1873. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1874. return -EINVAL;
  1875. }
  1876. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1877. /* read GPIO int */
  1878. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1879. switch (mode) {
  1880. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1881. DP(NETIF_MSG_LINK,
  1882. "Clear GPIO INT %d (shift %d) -> output low\n",
  1883. gpio_num, gpio_shift);
  1884. /* clear SET and set CLR */
  1885. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1886. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1887. break;
  1888. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1889. DP(NETIF_MSG_LINK,
  1890. "Set GPIO INT %d (shift %d) -> output high\n",
  1891. gpio_num, gpio_shift);
  1892. /* clear CLR and set SET */
  1893. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1894. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1895. break;
  1896. default:
  1897. break;
  1898. }
  1899. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1900. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1901. return 0;
  1902. }
  1903. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1904. {
  1905. u32 spio_reg;
  1906. /* Only 2 SPIOs are configurable */
  1907. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1908. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1909. return -EINVAL;
  1910. }
  1911. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1912. /* read SPIO and mask except the float bits */
  1913. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1914. switch (mode) {
  1915. case MISC_SPIO_OUTPUT_LOW:
  1916. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1917. /* clear FLOAT and set CLR */
  1918. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1919. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1920. break;
  1921. case MISC_SPIO_OUTPUT_HIGH:
  1922. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1923. /* clear FLOAT and set SET */
  1924. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1925. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1926. break;
  1927. case MISC_SPIO_INPUT_HI_Z:
  1928. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1929. /* set FLOAT */
  1930. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1931. break;
  1932. default:
  1933. break;
  1934. }
  1935. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1936. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1937. return 0;
  1938. }
  1939. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1940. {
  1941. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1942. switch (bp->link_vars.ieee_fc &
  1943. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1944. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1945. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1946. ADVERTISED_Pause);
  1947. break;
  1948. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1949. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1950. ADVERTISED_Pause);
  1951. break;
  1952. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1953. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1954. break;
  1955. default:
  1956. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1957. ADVERTISED_Pause);
  1958. break;
  1959. }
  1960. }
  1961. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1962. {
  1963. /* Initialize link parameters structure variables
  1964. * It is recommended to turn off RX FC for jumbo frames
  1965. * for better performance
  1966. */
  1967. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1968. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1969. else
  1970. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1971. }
  1972. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1973. {
  1974. u32 pause_enabled = 0;
  1975. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1976. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1977. pause_enabled = 1;
  1978. REG_WR(bp, BAR_USTRORM_INTMEM +
  1979. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1980. pause_enabled);
  1981. }
  1982. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1983. pause_enabled ? "enabled" : "disabled");
  1984. }
  1985. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1986. {
  1987. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1988. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1989. if (!BP_NOMCP(bp)) {
  1990. bnx2x_set_requested_fc(bp);
  1991. bnx2x_acquire_phy_lock(bp);
  1992. if (load_mode == LOAD_DIAG) {
  1993. struct link_params *lp = &bp->link_params;
  1994. lp->loopback_mode = LOOPBACK_XGXS;
  1995. /* do PHY loopback at 10G speed, if possible */
  1996. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1997. if (lp->speed_cap_mask[cfx_idx] &
  1998. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1999. lp->req_line_speed[cfx_idx] =
  2000. SPEED_10000;
  2001. else
  2002. lp->req_line_speed[cfx_idx] =
  2003. SPEED_1000;
  2004. }
  2005. }
  2006. if (load_mode == LOAD_LOOPBACK_EXT) {
  2007. struct link_params *lp = &bp->link_params;
  2008. lp->loopback_mode = LOOPBACK_EXT;
  2009. }
  2010. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2011. bnx2x_release_phy_lock(bp);
  2012. bnx2x_init_dropless_fc(bp);
  2013. bnx2x_calc_fc_adv(bp);
  2014. if (bp->link_vars.link_up) {
  2015. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2016. bnx2x_link_report(bp);
  2017. }
  2018. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2019. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  2020. return rc;
  2021. }
  2022. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  2023. return -EINVAL;
  2024. }
  2025. void bnx2x_link_set(struct bnx2x *bp)
  2026. {
  2027. if (!BP_NOMCP(bp)) {
  2028. bnx2x_acquire_phy_lock(bp);
  2029. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  2030. bnx2x_release_phy_lock(bp);
  2031. bnx2x_init_dropless_fc(bp);
  2032. bnx2x_calc_fc_adv(bp);
  2033. } else
  2034. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2035. }
  2036. static void bnx2x__link_reset(struct bnx2x *bp)
  2037. {
  2038. if (!BP_NOMCP(bp)) {
  2039. bnx2x_acquire_phy_lock(bp);
  2040. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2041. bnx2x_release_phy_lock(bp);
  2042. } else
  2043. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2044. }
  2045. void bnx2x_force_link_reset(struct bnx2x *bp)
  2046. {
  2047. bnx2x_acquire_phy_lock(bp);
  2048. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2049. bnx2x_release_phy_lock(bp);
  2050. }
  2051. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2052. {
  2053. u8 rc = 0;
  2054. if (!BP_NOMCP(bp)) {
  2055. bnx2x_acquire_phy_lock(bp);
  2056. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2057. is_serdes);
  2058. bnx2x_release_phy_lock(bp);
  2059. } else
  2060. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2061. return rc;
  2062. }
  2063. /* Calculates the sum of vn_min_rates.
  2064. It's needed for further normalizing of the min_rates.
  2065. Returns:
  2066. sum of vn_min_rates.
  2067. or
  2068. 0 - if all the min_rates are 0.
  2069. In the later case fairness algorithm should be deactivated.
  2070. If not all min_rates are zero then those that are zeroes will be set to 1.
  2071. */
  2072. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2073. struct cmng_init_input *input)
  2074. {
  2075. int all_zero = 1;
  2076. int vn;
  2077. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2078. u32 vn_cfg = bp->mf_config[vn];
  2079. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2080. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2081. /* Skip hidden vns */
  2082. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2083. vn_min_rate = 0;
  2084. /* If min rate is zero - set it to 1 */
  2085. else if (!vn_min_rate)
  2086. vn_min_rate = DEF_MIN_RATE;
  2087. else
  2088. all_zero = 0;
  2089. input->vnic_min_rate[vn] = vn_min_rate;
  2090. }
  2091. /* if ETS or all min rates are zeros - disable fairness */
  2092. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2093. input->flags.cmng_enables &=
  2094. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2095. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2096. } else if (all_zero) {
  2097. input->flags.cmng_enables &=
  2098. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2099. DP(NETIF_MSG_IFUP,
  2100. "All MIN values are zeroes fairness will be disabled\n");
  2101. } else
  2102. input->flags.cmng_enables |=
  2103. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2104. }
  2105. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2106. struct cmng_init_input *input)
  2107. {
  2108. u16 vn_max_rate;
  2109. u32 vn_cfg = bp->mf_config[vn];
  2110. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2111. vn_max_rate = 0;
  2112. else {
  2113. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2114. if (IS_MF_SI(bp)) {
  2115. /* maxCfg in percents of linkspeed */
  2116. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2117. } else /* SD modes */
  2118. /* maxCfg is absolute in 100Mb units */
  2119. vn_max_rate = maxCfg * 100;
  2120. }
  2121. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2122. input->vnic_max_rate[vn] = vn_max_rate;
  2123. }
  2124. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2125. {
  2126. if (CHIP_REV_IS_SLOW(bp))
  2127. return CMNG_FNS_NONE;
  2128. if (IS_MF(bp))
  2129. return CMNG_FNS_MINMAX;
  2130. return CMNG_FNS_NONE;
  2131. }
  2132. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2133. {
  2134. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2135. if (BP_NOMCP(bp))
  2136. return; /* what should be the default value in this case */
  2137. /* For 2 port configuration the absolute function number formula
  2138. * is:
  2139. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2140. *
  2141. * and there are 4 functions per port
  2142. *
  2143. * For 4 port configuration it is
  2144. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2145. *
  2146. * and there are 2 functions per port
  2147. */
  2148. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2149. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2150. if (func >= E1H_FUNC_MAX)
  2151. break;
  2152. bp->mf_config[vn] =
  2153. MF_CFG_RD(bp, func_mf_config[func].config);
  2154. }
  2155. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2156. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2157. bp->flags |= MF_FUNC_DIS;
  2158. } else {
  2159. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2160. bp->flags &= ~MF_FUNC_DIS;
  2161. }
  2162. }
  2163. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2164. {
  2165. struct cmng_init_input input;
  2166. memset(&input, 0, sizeof(struct cmng_init_input));
  2167. input.port_rate = bp->link_vars.line_speed;
  2168. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2169. int vn;
  2170. /* read mf conf from shmem */
  2171. if (read_cfg)
  2172. bnx2x_read_mf_cfg(bp);
  2173. /* vn_weight_sum and enable fairness if not 0 */
  2174. bnx2x_calc_vn_min(bp, &input);
  2175. /* calculate and set min-max rate for each vn */
  2176. if (bp->port.pmf)
  2177. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2178. bnx2x_calc_vn_max(bp, vn, &input);
  2179. /* always enable rate shaping and fairness */
  2180. input.flags.cmng_enables |=
  2181. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2182. bnx2x_init_cmng(&input, &bp->cmng);
  2183. return;
  2184. }
  2185. /* rate shaping and fairness are disabled */
  2186. DP(NETIF_MSG_IFUP,
  2187. "rate shaping and fairness are disabled\n");
  2188. }
  2189. static void storm_memset_cmng(struct bnx2x *bp,
  2190. struct cmng_init *cmng,
  2191. u8 port)
  2192. {
  2193. int vn;
  2194. size_t size = sizeof(struct cmng_struct_per_port);
  2195. u32 addr = BAR_XSTRORM_INTMEM +
  2196. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2197. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2198. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2199. int func = func_by_vn(bp, vn);
  2200. addr = BAR_XSTRORM_INTMEM +
  2201. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2202. size = sizeof(struct rate_shaping_vars_per_vn);
  2203. __storm_memset_struct(bp, addr, size,
  2204. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2205. addr = BAR_XSTRORM_INTMEM +
  2206. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2207. size = sizeof(struct fairness_vars_per_vn);
  2208. __storm_memset_struct(bp, addr, size,
  2209. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2210. }
  2211. }
  2212. /* init cmng mode in HW according to local configuration */
  2213. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2214. {
  2215. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2216. if (cmng_fns != CMNG_FNS_NONE) {
  2217. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2218. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2219. } else {
  2220. /* rate shaping and fairness are disabled */
  2221. DP(NETIF_MSG_IFUP,
  2222. "single function mode without fairness\n");
  2223. }
  2224. }
  2225. /* This function is called upon link interrupt */
  2226. static void bnx2x_link_attn(struct bnx2x *bp)
  2227. {
  2228. /* Make sure that we are synced with the current statistics */
  2229. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2230. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2231. bnx2x_init_dropless_fc(bp);
  2232. if (bp->link_vars.link_up) {
  2233. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2234. struct host_port_stats *pstats;
  2235. pstats = bnx2x_sp(bp, port_stats);
  2236. /* reset old mac stats */
  2237. memset(&(pstats->mac_stx[0]), 0,
  2238. sizeof(struct mac_stx));
  2239. }
  2240. if (bp->state == BNX2X_STATE_OPEN)
  2241. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2242. }
  2243. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2244. bnx2x_set_local_cmng(bp);
  2245. __bnx2x_link_report(bp);
  2246. if (IS_MF(bp))
  2247. bnx2x_link_sync_notify(bp);
  2248. }
  2249. void bnx2x__link_status_update(struct bnx2x *bp)
  2250. {
  2251. if (bp->state != BNX2X_STATE_OPEN)
  2252. return;
  2253. /* read updated dcb configuration */
  2254. if (IS_PF(bp)) {
  2255. bnx2x_dcbx_pmf_update(bp);
  2256. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2257. if (bp->link_vars.link_up)
  2258. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2259. else
  2260. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2261. /* indicate link status */
  2262. bnx2x_link_report(bp);
  2263. } else { /* VF */
  2264. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2265. SUPPORTED_10baseT_Full |
  2266. SUPPORTED_100baseT_Half |
  2267. SUPPORTED_100baseT_Full |
  2268. SUPPORTED_1000baseT_Full |
  2269. SUPPORTED_2500baseX_Full |
  2270. SUPPORTED_10000baseT_Full |
  2271. SUPPORTED_TP |
  2272. SUPPORTED_FIBRE |
  2273. SUPPORTED_Autoneg |
  2274. SUPPORTED_Pause |
  2275. SUPPORTED_Asym_Pause);
  2276. bp->port.advertising[0] = bp->port.supported[0];
  2277. bp->link_params.bp = bp;
  2278. bp->link_params.port = BP_PORT(bp);
  2279. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2280. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2281. bp->link_params.req_line_speed[0] = SPEED_10000;
  2282. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2283. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2284. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2285. bp->link_vars.line_speed = SPEED_10000;
  2286. bp->link_vars.link_status =
  2287. (LINK_STATUS_LINK_UP |
  2288. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2289. bp->link_vars.link_up = 1;
  2290. bp->link_vars.duplex = DUPLEX_FULL;
  2291. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2292. __bnx2x_link_report(bp);
  2293. bnx2x_sample_bulletin(bp);
  2294. /* if bulletin board did not have an update for link status
  2295. * __bnx2x_link_report will report current status
  2296. * but it will NOT duplicate report in case of already reported
  2297. * during sampling bulletin board.
  2298. */
  2299. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2300. }
  2301. }
  2302. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2303. u16 vlan_val, u8 allowed_prio)
  2304. {
  2305. struct bnx2x_func_state_params func_params = {NULL};
  2306. struct bnx2x_func_afex_update_params *f_update_params =
  2307. &func_params.params.afex_update;
  2308. func_params.f_obj = &bp->func_obj;
  2309. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2310. /* no need to wait for RAMROD completion, so don't
  2311. * set RAMROD_COMP_WAIT flag
  2312. */
  2313. f_update_params->vif_id = vifid;
  2314. f_update_params->afex_default_vlan = vlan_val;
  2315. f_update_params->allowed_priorities = allowed_prio;
  2316. /* if ramrod can not be sent, response to MCP immediately */
  2317. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2318. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2319. return 0;
  2320. }
  2321. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2322. u16 vif_index, u8 func_bit_map)
  2323. {
  2324. struct bnx2x_func_state_params func_params = {NULL};
  2325. struct bnx2x_func_afex_viflists_params *update_params =
  2326. &func_params.params.afex_viflists;
  2327. int rc;
  2328. u32 drv_msg_code;
  2329. /* validate only LIST_SET and LIST_GET are received from switch */
  2330. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2331. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2332. cmd_type);
  2333. func_params.f_obj = &bp->func_obj;
  2334. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2335. /* set parameters according to cmd_type */
  2336. update_params->afex_vif_list_command = cmd_type;
  2337. update_params->vif_list_index = vif_index;
  2338. update_params->func_bit_map =
  2339. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2340. update_params->func_to_clear = 0;
  2341. drv_msg_code =
  2342. (cmd_type == VIF_LIST_RULE_GET) ?
  2343. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2344. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2345. /* if ramrod can not be sent, respond to MCP immediately for
  2346. * SET and GET requests (other are not triggered from MCP)
  2347. */
  2348. rc = bnx2x_func_state_change(bp, &func_params);
  2349. if (rc < 0)
  2350. bnx2x_fw_command(bp, drv_msg_code, 0);
  2351. return 0;
  2352. }
  2353. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2354. {
  2355. struct afex_stats afex_stats;
  2356. u32 func = BP_ABS_FUNC(bp);
  2357. u32 mf_config;
  2358. u16 vlan_val;
  2359. u32 vlan_prio;
  2360. u16 vif_id;
  2361. u8 allowed_prio;
  2362. u8 vlan_mode;
  2363. u32 addr_to_write, vifid, addrs, stats_type, i;
  2364. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2365. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2366. DP(BNX2X_MSG_MCP,
  2367. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2368. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2369. }
  2370. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2371. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2372. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2373. DP(BNX2X_MSG_MCP,
  2374. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2375. vifid, addrs);
  2376. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2377. addrs);
  2378. }
  2379. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2380. addr_to_write = SHMEM2_RD(bp,
  2381. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2382. stats_type = SHMEM2_RD(bp,
  2383. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2384. DP(BNX2X_MSG_MCP,
  2385. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2386. addr_to_write);
  2387. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2388. /* write response to scratchpad, for MCP */
  2389. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2390. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2391. *(((u32 *)(&afex_stats))+i));
  2392. /* send ack message to MCP */
  2393. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2394. }
  2395. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2396. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2397. bp->mf_config[BP_VN(bp)] = mf_config;
  2398. DP(BNX2X_MSG_MCP,
  2399. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2400. mf_config);
  2401. /* if VIF_SET is "enabled" */
  2402. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2403. /* set rate limit directly to internal RAM */
  2404. struct cmng_init_input cmng_input;
  2405. struct rate_shaping_vars_per_vn m_rs_vn;
  2406. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2407. u32 addr = BAR_XSTRORM_INTMEM +
  2408. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2409. bp->mf_config[BP_VN(bp)] = mf_config;
  2410. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2411. m_rs_vn.vn_counter.rate =
  2412. cmng_input.vnic_max_rate[BP_VN(bp)];
  2413. m_rs_vn.vn_counter.quota =
  2414. (m_rs_vn.vn_counter.rate *
  2415. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2416. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2417. /* read relevant values from mf_cfg struct in shmem */
  2418. vif_id =
  2419. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2420. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2421. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2422. vlan_val =
  2423. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2424. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2425. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2426. vlan_prio = (mf_config &
  2427. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2428. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2429. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2430. vlan_mode =
  2431. (MF_CFG_RD(bp,
  2432. func_mf_config[func].afex_config) &
  2433. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2434. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2435. allowed_prio =
  2436. (MF_CFG_RD(bp,
  2437. func_mf_config[func].afex_config) &
  2438. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2439. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2440. /* send ramrod to FW, return in case of failure */
  2441. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2442. allowed_prio))
  2443. return;
  2444. bp->afex_def_vlan_tag = vlan_val;
  2445. bp->afex_vlan_mode = vlan_mode;
  2446. } else {
  2447. /* notify link down because BP->flags is disabled */
  2448. bnx2x_link_report(bp);
  2449. /* send INVALID VIF ramrod to FW */
  2450. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2451. /* Reset the default afex VLAN */
  2452. bp->afex_def_vlan_tag = -1;
  2453. }
  2454. }
  2455. }
  2456. static void bnx2x_handle_update_svid_cmd(struct bnx2x *bp)
  2457. {
  2458. struct bnx2x_func_switch_update_params *switch_update_params;
  2459. struct bnx2x_func_state_params func_params;
  2460. memset(&func_params, 0, sizeof(struct bnx2x_func_state_params));
  2461. switch_update_params = &func_params.params.switch_update;
  2462. func_params.f_obj = &bp->func_obj;
  2463. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  2464. if (IS_MF_UFP(bp)) {
  2465. int func = BP_ABS_FUNC(bp);
  2466. u32 val;
  2467. /* Re-learn the S-tag from shmem */
  2468. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2469. FUNC_MF_CFG_E1HOV_TAG_MASK;
  2470. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  2471. bp->mf_ov = val;
  2472. } else {
  2473. BNX2X_ERR("Got an SVID event, but no tag is configured in shmem\n");
  2474. goto fail;
  2475. }
  2476. /* Configure new S-tag in LLH */
  2477. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + BP_PORT(bp) * 8,
  2478. bp->mf_ov);
  2479. /* Send Ramrod to update FW of change */
  2480. __set_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
  2481. &switch_update_params->changes);
  2482. switch_update_params->vlan = bp->mf_ov;
  2483. if (bnx2x_func_state_change(bp, &func_params) < 0) {
  2484. BNX2X_ERR("Failed to configure FW of S-tag Change to %02x\n",
  2485. bp->mf_ov);
  2486. goto fail;
  2487. }
  2488. DP(BNX2X_MSG_MCP, "Configured S-tag %02x\n", bp->mf_ov);
  2489. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_OK, 0);
  2490. return;
  2491. }
  2492. /* not supported by SW yet */
  2493. fail:
  2494. bnx2x_fw_command(bp, DRV_MSG_CODE_OEM_UPDATE_SVID_FAILURE, 0);
  2495. }
  2496. static void bnx2x_pmf_update(struct bnx2x *bp)
  2497. {
  2498. int port = BP_PORT(bp);
  2499. u32 val;
  2500. bp->port.pmf = 1;
  2501. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2502. /*
  2503. * We need the mb() to ensure the ordering between the writing to
  2504. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2505. */
  2506. smp_mb();
  2507. /* queue a periodic task */
  2508. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2509. bnx2x_dcbx_pmf_update(bp);
  2510. /* enable nig attention */
  2511. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2512. if (bp->common.int_block == INT_BLOCK_HC) {
  2513. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2514. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2515. } else if (!CHIP_IS_E1x(bp)) {
  2516. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2517. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2518. }
  2519. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2520. }
  2521. /* end of Link */
  2522. /* slow path */
  2523. /*
  2524. * General service functions
  2525. */
  2526. /* send the MCP a request, block until there is a reply */
  2527. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2528. {
  2529. int mb_idx = BP_FW_MB_IDX(bp);
  2530. u32 seq;
  2531. u32 rc = 0;
  2532. u32 cnt = 1;
  2533. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2534. mutex_lock(&bp->fw_mb_mutex);
  2535. seq = ++bp->fw_seq;
  2536. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2537. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2538. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2539. (command | seq), param);
  2540. do {
  2541. /* let the FW do it's magic ... */
  2542. msleep(delay);
  2543. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2544. /* Give the FW up to 5 second (500*10ms) */
  2545. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2546. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2547. cnt*delay, rc, seq);
  2548. /* is this a reply to our command? */
  2549. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2550. rc &= FW_MSG_CODE_MASK;
  2551. else {
  2552. /* FW BUG! */
  2553. BNX2X_ERR("FW failed to respond!\n");
  2554. bnx2x_fw_dump(bp);
  2555. rc = 0;
  2556. }
  2557. mutex_unlock(&bp->fw_mb_mutex);
  2558. return rc;
  2559. }
  2560. static void storm_memset_func_cfg(struct bnx2x *bp,
  2561. struct tstorm_eth_function_common_config *tcfg,
  2562. u16 abs_fid)
  2563. {
  2564. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2565. u32 addr = BAR_TSTRORM_INTMEM +
  2566. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2567. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2568. }
  2569. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2570. {
  2571. if (CHIP_IS_E1x(bp)) {
  2572. struct tstorm_eth_function_common_config tcfg = {0};
  2573. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2574. }
  2575. /* Enable the function in the FW */
  2576. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2577. storm_memset_func_en(bp, p->func_id, 1);
  2578. /* spq */
  2579. if (p->func_flgs & FUNC_FLG_SPQ) {
  2580. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2581. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2582. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2583. }
  2584. }
  2585. /**
  2586. * bnx2x_get_common_flags - Return common flags
  2587. *
  2588. * @bp device handle
  2589. * @fp queue handle
  2590. * @zero_stats TRUE if statistics zeroing is needed
  2591. *
  2592. * Return the flags that are common for the Tx-only and not normal connections.
  2593. */
  2594. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2595. struct bnx2x_fastpath *fp,
  2596. bool zero_stats)
  2597. {
  2598. unsigned long flags = 0;
  2599. /* PF driver will always initialize the Queue to an ACTIVE state */
  2600. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2601. /* tx only connections collect statistics (on the same index as the
  2602. * parent connection). The statistics are zeroed when the parent
  2603. * connection is initialized.
  2604. */
  2605. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2606. if (zero_stats)
  2607. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2608. if (bp->flags & TX_SWITCHING)
  2609. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &flags);
  2610. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2611. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2612. #ifdef BNX2X_STOP_ON_ERROR
  2613. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2614. #endif
  2615. return flags;
  2616. }
  2617. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2618. struct bnx2x_fastpath *fp,
  2619. bool leading)
  2620. {
  2621. unsigned long flags = 0;
  2622. /* calculate other queue flags */
  2623. if (IS_MF_SD(bp))
  2624. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2625. if (IS_FCOE_FP(fp)) {
  2626. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2627. /* For FCoE - force usage of default priority (for afex) */
  2628. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2629. }
  2630. if (!fp->disable_tpa) {
  2631. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2632. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2633. if (fp->mode == TPA_MODE_GRO)
  2634. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2635. }
  2636. if (leading) {
  2637. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2638. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2639. }
  2640. /* Always set HW VLAN stripping */
  2641. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2642. /* configure silent vlan removal */
  2643. if (IS_MF_AFEX(bp))
  2644. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2645. return flags | bnx2x_get_common_flags(bp, fp, true);
  2646. }
  2647. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2648. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2649. u8 cos)
  2650. {
  2651. gen_init->stat_id = bnx2x_stats_id(fp);
  2652. gen_init->spcl_id = fp->cl_id;
  2653. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2654. if (IS_FCOE_FP(fp))
  2655. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2656. else
  2657. gen_init->mtu = bp->dev->mtu;
  2658. gen_init->cos = cos;
  2659. gen_init->fp_hsi = ETH_FP_HSI_VERSION;
  2660. }
  2661. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2662. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2663. struct bnx2x_rxq_setup_params *rxq_init)
  2664. {
  2665. u8 max_sge = 0;
  2666. u16 sge_sz = 0;
  2667. u16 tpa_agg_size = 0;
  2668. if (!fp->disable_tpa) {
  2669. pause->sge_th_lo = SGE_TH_LO(bp);
  2670. pause->sge_th_hi = SGE_TH_HI(bp);
  2671. /* validate SGE ring has enough to cross high threshold */
  2672. WARN_ON(bp->dropless_fc &&
  2673. pause->sge_th_hi + FW_PREFETCH_CNT >
  2674. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2675. tpa_agg_size = TPA_AGG_SIZE;
  2676. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2677. SGE_PAGE_SHIFT;
  2678. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2679. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2680. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2681. }
  2682. /* pause - not for e1 */
  2683. if (!CHIP_IS_E1(bp)) {
  2684. pause->bd_th_lo = BD_TH_LO(bp);
  2685. pause->bd_th_hi = BD_TH_HI(bp);
  2686. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2687. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2688. /*
  2689. * validate that rings have enough entries to cross
  2690. * high thresholds
  2691. */
  2692. WARN_ON(bp->dropless_fc &&
  2693. pause->bd_th_hi + FW_PREFETCH_CNT >
  2694. bp->rx_ring_size);
  2695. WARN_ON(bp->dropless_fc &&
  2696. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2697. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2698. pause->pri_map = 1;
  2699. }
  2700. /* rxq setup */
  2701. rxq_init->dscr_map = fp->rx_desc_mapping;
  2702. rxq_init->sge_map = fp->rx_sge_mapping;
  2703. rxq_init->rcq_map = fp->rx_comp_mapping;
  2704. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2705. /* This should be a maximum number of data bytes that may be
  2706. * placed on the BD (not including paddings).
  2707. */
  2708. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2709. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2710. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2711. rxq_init->tpa_agg_sz = tpa_agg_size;
  2712. rxq_init->sge_buf_sz = sge_sz;
  2713. rxq_init->max_sges_pkt = max_sge;
  2714. rxq_init->rss_engine_id = BP_FUNC(bp);
  2715. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2716. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2717. *
  2718. * For PF Clients it should be the maximum available number.
  2719. * VF driver(s) may want to define it to a smaller value.
  2720. */
  2721. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2722. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2723. rxq_init->fw_sb_id = fp->fw_sb_id;
  2724. if (IS_FCOE_FP(fp))
  2725. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2726. else
  2727. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2728. /* configure silent vlan removal
  2729. * if multi function mode is afex, then mask default vlan
  2730. */
  2731. if (IS_MF_AFEX(bp)) {
  2732. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2733. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2734. }
  2735. }
  2736. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2737. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2738. u8 cos)
  2739. {
  2740. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2741. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2742. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2743. txq_init->fw_sb_id = fp->fw_sb_id;
  2744. /*
  2745. * set the tss leading client id for TX classification ==
  2746. * leading RSS client id
  2747. */
  2748. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2749. if (IS_FCOE_FP(fp)) {
  2750. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2751. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2752. }
  2753. }
  2754. static void bnx2x_pf_init(struct bnx2x *bp)
  2755. {
  2756. struct bnx2x_func_init_params func_init = {0};
  2757. struct event_ring_data eq_data = { {0} };
  2758. u16 flags;
  2759. if (!CHIP_IS_E1x(bp)) {
  2760. /* reset IGU PF statistics: MSIX + ATTN */
  2761. /* PF */
  2762. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2763. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2764. (CHIP_MODE_IS_4_PORT(bp) ?
  2765. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2766. /* ATTN */
  2767. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2768. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2769. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2770. (CHIP_MODE_IS_4_PORT(bp) ?
  2771. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2772. }
  2773. /* function setup flags */
  2774. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2775. /* This flag is relevant for E1x only.
  2776. * E2 doesn't have a TPA configuration in a function level.
  2777. */
  2778. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2779. func_init.func_flgs = flags;
  2780. func_init.pf_id = BP_FUNC(bp);
  2781. func_init.func_id = BP_FUNC(bp);
  2782. func_init.spq_map = bp->spq_mapping;
  2783. func_init.spq_prod = bp->spq_prod_idx;
  2784. bnx2x_func_init(bp, &func_init);
  2785. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2786. /*
  2787. * Congestion management values depend on the link rate
  2788. * There is no active link so initial link rate is set to 10 Gbps.
  2789. * When the link comes up The congestion management values are
  2790. * re-calculated according to the actual link rate.
  2791. */
  2792. bp->link_vars.line_speed = SPEED_10000;
  2793. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2794. /* Only the PMF sets the HW */
  2795. if (bp->port.pmf)
  2796. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2797. /* init Event Queue - PCI bus guarantees correct endianity*/
  2798. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2799. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2800. eq_data.producer = bp->eq_prod;
  2801. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2802. eq_data.sb_id = DEF_SB_ID;
  2803. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2804. }
  2805. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2806. {
  2807. int port = BP_PORT(bp);
  2808. bnx2x_tx_disable(bp);
  2809. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2810. }
  2811. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2812. {
  2813. int port = BP_PORT(bp);
  2814. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)))
  2815. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  2816. /* Tx queue should be only re-enabled */
  2817. netif_tx_wake_all_queues(bp->dev);
  2818. /*
  2819. * Should not call netif_carrier_on since it will be called if the link
  2820. * is up when checking for link state
  2821. */
  2822. }
  2823. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2824. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2825. {
  2826. struct eth_stats_info *ether_stat =
  2827. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2828. struct bnx2x_vlan_mac_obj *mac_obj =
  2829. &bp->sp_objs->mac_obj;
  2830. int i;
  2831. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2832. ETH_STAT_INFO_VERSION_LEN);
  2833. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2834. * mac_local field in ether_stat struct. The base address is offset by 2
  2835. * bytes to account for the field being 8 bytes but a mac address is
  2836. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2837. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2838. * allocated by the ether_stat struct, so the macs will land in their
  2839. * proper positions.
  2840. */
  2841. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2842. memset(ether_stat->mac_local + i, 0,
  2843. sizeof(ether_stat->mac_local[0]));
  2844. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2845. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2846. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2847. ETH_ALEN);
  2848. ether_stat->mtu_size = bp->dev->mtu;
  2849. if (bp->dev->features & NETIF_F_RXCSUM)
  2850. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2851. if (bp->dev->features & NETIF_F_TSO)
  2852. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2853. ether_stat->feature_flags |= bp->common.boot_mode;
  2854. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2855. ether_stat->txq_size = bp->tx_ring_size;
  2856. ether_stat->rxq_size = bp->rx_ring_size;
  2857. #ifdef CONFIG_BNX2X_SRIOV
  2858. ether_stat->vf_cnt = IS_SRIOV(bp) ? bp->vfdb->sriov.nr_virtfn : 0;
  2859. #endif
  2860. }
  2861. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2862. {
  2863. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2864. struct fcoe_stats_info *fcoe_stat =
  2865. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2866. if (!CNIC_LOADED(bp))
  2867. return;
  2868. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2869. fcoe_stat->qos_priority =
  2870. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2871. /* insert FCoE stats from ramrod response */
  2872. if (!NO_FCOE(bp)) {
  2873. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2874. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2875. tstorm_queue_statistics;
  2876. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2877. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2878. xstorm_queue_statistics;
  2879. struct fcoe_statistics_params *fw_fcoe_stat =
  2880. &bp->fw_stats_data->fcoe;
  2881. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2882. fcoe_stat->rx_bytes_lo,
  2883. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2884. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2885. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2886. fcoe_stat->rx_bytes_lo,
  2887. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2888. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2889. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2890. fcoe_stat->rx_bytes_lo,
  2891. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2892. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2893. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2894. fcoe_stat->rx_bytes_lo,
  2895. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2896. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2897. fcoe_stat->rx_frames_lo,
  2898. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2899. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2900. fcoe_stat->rx_frames_lo,
  2901. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2902. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2903. fcoe_stat->rx_frames_lo,
  2904. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2905. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2906. fcoe_stat->rx_frames_lo,
  2907. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2908. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2909. fcoe_stat->tx_bytes_lo,
  2910. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2911. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2912. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2913. fcoe_stat->tx_bytes_lo,
  2914. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2915. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2916. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2917. fcoe_stat->tx_bytes_lo,
  2918. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2919. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2920. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2921. fcoe_stat->tx_bytes_lo,
  2922. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2923. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2924. fcoe_stat->tx_frames_lo,
  2925. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2926. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2927. fcoe_stat->tx_frames_lo,
  2928. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2929. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2930. fcoe_stat->tx_frames_lo,
  2931. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2932. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2933. fcoe_stat->tx_frames_lo,
  2934. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2935. }
  2936. /* ask L5 driver to add data to the struct */
  2937. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2938. }
  2939. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2940. {
  2941. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2942. struct iscsi_stats_info *iscsi_stat =
  2943. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2944. if (!CNIC_LOADED(bp))
  2945. return;
  2946. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2947. ETH_ALEN);
  2948. iscsi_stat->qos_priority =
  2949. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2950. /* ask L5 driver to add data to the struct */
  2951. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2952. }
  2953. /* called due to MCP event (on pmf):
  2954. * reread new bandwidth configuration
  2955. * configure FW
  2956. * notify others function about the change
  2957. */
  2958. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2959. {
  2960. if (bp->link_vars.link_up) {
  2961. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2962. bnx2x_link_sync_notify(bp);
  2963. }
  2964. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2965. }
  2966. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2967. {
  2968. bnx2x_config_mf_bw(bp);
  2969. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2970. }
  2971. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2972. {
  2973. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2974. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2975. }
  2976. #define BNX2X_UPDATE_DRV_INFO_IND_LENGTH (20)
  2977. #define BNX2X_UPDATE_DRV_INFO_IND_COUNT (25)
  2978. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2979. {
  2980. enum drv_info_opcode op_code;
  2981. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2982. bool release = false;
  2983. int wait;
  2984. /* if drv_info version supported by MFW doesn't match - send NACK */
  2985. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2986. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2987. return;
  2988. }
  2989. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2990. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2991. /* Must prevent other flows from accessing drv_info_to_mcp */
  2992. mutex_lock(&bp->drv_info_mutex);
  2993. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2994. sizeof(union drv_info_to_mcp));
  2995. switch (op_code) {
  2996. case ETH_STATS_OPCODE:
  2997. bnx2x_drv_info_ether_stat(bp);
  2998. break;
  2999. case FCOE_STATS_OPCODE:
  3000. bnx2x_drv_info_fcoe_stat(bp);
  3001. break;
  3002. case ISCSI_STATS_OPCODE:
  3003. bnx2x_drv_info_iscsi_stat(bp);
  3004. break;
  3005. default:
  3006. /* if op code isn't supported - send NACK */
  3007. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  3008. goto out;
  3009. }
  3010. /* if we got drv_info attn from MFW then these fields are defined in
  3011. * shmem2 for sure
  3012. */
  3013. SHMEM2_WR(bp, drv_info_host_addr_lo,
  3014. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3015. SHMEM2_WR(bp, drv_info_host_addr_hi,
  3016. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  3017. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  3018. /* Since possible management wants both this and get_driver_version
  3019. * need to wait until management notifies us it finished utilizing
  3020. * the buffer.
  3021. */
  3022. if (!SHMEM2_HAS(bp, mfw_drv_indication)) {
  3023. DP(BNX2X_MSG_MCP, "Management does not support indication\n");
  3024. } else if (!bp->drv_info_mng_owner) {
  3025. u32 bit = MFW_DRV_IND_READ_DONE_OFFSET((BP_ABS_FUNC(bp) >> 1));
  3026. for (wait = 0; wait < BNX2X_UPDATE_DRV_INFO_IND_COUNT; wait++) {
  3027. u32 indication = SHMEM2_RD(bp, mfw_drv_indication);
  3028. /* Management is done; need to clear indication */
  3029. if (indication & bit) {
  3030. SHMEM2_WR(bp, mfw_drv_indication,
  3031. indication & ~bit);
  3032. release = true;
  3033. break;
  3034. }
  3035. msleep(BNX2X_UPDATE_DRV_INFO_IND_LENGTH);
  3036. }
  3037. }
  3038. if (!release) {
  3039. DP(BNX2X_MSG_MCP, "Management did not release indication\n");
  3040. bp->drv_info_mng_owner = true;
  3041. }
  3042. out:
  3043. mutex_unlock(&bp->drv_info_mutex);
  3044. }
  3045. static u32 bnx2x_update_mng_version_utility(u8 *version, bool bnx2x_format)
  3046. {
  3047. u8 vals[4];
  3048. int i = 0;
  3049. if (bnx2x_format) {
  3050. i = sscanf(version, "1.%c%hhd.%hhd.%hhd",
  3051. &vals[0], &vals[1], &vals[2], &vals[3]);
  3052. if (i > 0)
  3053. vals[0] -= '0';
  3054. } else {
  3055. i = sscanf(version, "%hhd.%hhd.%hhd.%hhd",
  3056. &vals[0], &vals[1], &vals[2], &vals[3]);
  3057. }
  3058. while (i < 4)
  3059. vals[i++] = 0;
  3060. return (vals[0] << 24) | (vals[1] << 16) | (vals[2] << 8) | vals[3];
  3061. }
  3062. void bnx2x_update_mng_version(struct bnx2x *bp)
  3063. {
  3064. u32 iscsiver = DRV_VER_NOT_LOADED;
  3065. u32 fcoever = DRV_VER_NOT_LOADED;
  3066. u32 ethver = DRV_VER_NOT_LOADED;
  3067. int idx = BP_FW_MB_IDX(bp);
  3068. u8 *version;
  3069. if (!SHMEM2_HAS(bp, func_os_drv_ver))
  3070. return;
  3071. mutex_lock(&bp->drv_info_mutex);
  3072. /* Must not proceed when `bnx2x_handle_drv_info_req' is feasible */
  3073. if (bp->drv_info_mng_owner)
  3074. goto out;
  3075. if (bp->state != BNX2X_STATE_OPEN)
  3076. goto out;
  3077. /* Parse ethernet driver version */
  3078. ethver = bnx2x_update_mng_version_utility(DRV_MODULE_VERSION, true);
  3079. if (!CNIC_LOADED(bp))
  3080. goto out;
  3081. /* Try getting storage driver version via cnic */
  3082. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3083. sizeof(union drv_info_to_mcp));
  3084. bnx2x_drv_info_iscsi_stat(bp);
  3085. version = bp->slowpath->drv_info_to_mcp.iscsi_stat.version;
  3086. iscsiver = bnx2x_update_mng_version_utility(version, false);
  3087. memset(&bp->slowpath->drv_info_to_mcp, 0,
  3088. sizeof(union drv_info_to_mcp));
  3089. bnx2x_drv_info_fcoe_stat(bp);
  3090. version = bp->slowpath->drv_info_to_mcp.fcoe_stat.version;
  3091. fcoever = bnx2x_update_mng_version_utility(version, false);
  3092. out:
  3093. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ETHERNET], ethver);
  3094. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_ISCSI], iscsiver);
  3095. SHMEM2_WR(bp, func_os_drv_ver[idx].versions[DRV_PERS_FCOE], fcoever);
  3096. mutex_unlock(&bp->drv_info_mutex);
  3097. DP(BNX2X_MSG_MCP, "Setting driver version: ETH [%08x] iSCSI [%08x] FCoE [%08x]\n",
  3098. ethver, iscsiver, fcoever);
  3099. }
  3100. static void bnx2x_oem_event(struct bnx2x *bp, u32 event)
  3101. {
  3102. u32 cmd_ok, cmd_fail;
  3103. /* sanity */
  3104. if (event & DRV_STATUS_DCC_EVENT_MASK &&
  3105. event & DRV_STATUS_OEM_EVENT_MASK) {
  3106. BNX2X_ERR("Received simultaneous events %08x\n", event);
  3107. return;
  3108. }
  3109. if (event & DRV_STATUS_DCC_EVENT_MASK) {
  3110. cmd_fail = DRV_MSG_CODE_DCC_FAILURE;
  3111. cmd_ok = DRV_MSG_CODE_DCC_OK;
  3112. } else /* if (event & DRV_STATUS_OEM_EVENT_MASK) */ {
  3113. cmd_fail = DRV_MSG_CODE_OEM_FAILURE;
  3114. cmd_ok = DRV_MSG_CODE_OEM_OK;
  3115. }
  3116. DP(BNX2X_MSG_MCP, "oem_event 0x%x\n", event);
  3117. if (event & (DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3118. DRV_STATUS_OEM_DISABLE_ENABLE_PF)) {
  3119. /* This is the only place besides the function initialization
  3120. * where the bp->flags can change so it is done without any
  3121. * locks
  3122. */
  3123. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  3124. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  3125. bp->flags |= MF_FUNC_DIS;
  3126. bnx2x_e1h_disable(bp);
  3127. } else {
  3128. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  3129. bp->flags &= ~MF_FUNC_DIS;
  3130. bnx2x_e1h_enable(bp);
  3131. }
  3132. event &= ~(DRV_STATUS_DCC_DISABLE_ENABLE_PF |
  3133. DRV_STATUS_OEM_DISABLE_ENABLE_PF);
  3134. }
  3135. if (event & (DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3136. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION)) {
  3137. bnx2x_config_mf_bw(bp);
  3138. event &= ~(DRV_STATUS_DCC_BANDWIDTH_ALLOCATION |
  3139. DRV_STATUS_OEM_BANDWIDTH_ALLOCATION);
  3140. }
  3141. /* Report results to MCP */
  3142. if (event)
  3143. bnx2x_fw_command(bp, cmd_fail, 0);
  3144. else
  3145. bnx2x_fw_command(bp, cmd_ok, 0);
  3146. }
  3147. /* must be called under the spq lock */
  3148. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  3149. {
  3150. struct eth_spe *next_spe = bp->spq_prod_bd;
  3151. if (bp->spq_prod_bd == bp->spq_last_bd) {
  3152. bp->spq_prod_bd = bp->spq;
  3153. bp->spq_prod_idx = 0;
  3154. DP(BNX2X_MSG_SP, "end of spq\n");
  3155. } else {
  3156. bp->spq_prod_bd++;
  3157. bp->spq_prod_idx++;
  3158. }
  3159. return next_spe;
  3160. }
  3161. /* must be called under the spq lock */
  3162. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  3163. {
  3164. int func = BP_FUNC(bp);
  3165. /*
  3166. * Make sure that BD data is updated before writing the producer:
  3167. * BD data is written to the memory, the producer is read from the
  3168. * memory, thus we need a full memory barrier to ensure the ordering.
  3169. */
  3170. mb();
  3171. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  3172. bp->spq_prod_idx);
  3173. mmiowb();
  3174. }
  3175. /**
  3176. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  3177. *
  3178. * @cmd: command to check
  3179. * @cmd_type: command type
  3180. */
  3181. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  3182. {
  3183. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  3184. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  3185. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  3186. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  3187. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  3188. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  3189. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  3190. return true;
  3191. else
  3192. return false;
  3193. }
  3194. /**
  3195. * bnx2x_sp_post - place a single command on an SP ring
  3196. *
  3197. * @bp: driver handle
  3198. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3199. * @cid: SW CID the command is related to
  3200. * @data_hi: command private data address (high 32 bits)
  3201. * @data_lo: command private data address (low 32 bits)
  3202. * @cmd_type: command type (e.g. NONE, ETH)
  3203. *
  3204. * SP data is handled as if it's always an address pair, thus data fields are
  3205. * not swapped to little endian in upper functions. Instead this function swaps
  3206. * data as if it's two u32 fields.
  3207. */
  3208. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3209. u32 data_hi, u32 data_lo, int cmd_type)
  3210. {
  3211. struct eth_spe *spe;
  3212. u16 type;
  3213. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3214. #ifdef BNX2X_STOP_ON_ERROR
  3215. if (unlikely(bp->panic)) {
  3216. BNX2X_ERR("Can't post SP when there is panic\n");
  3217. return -EIO;
  3218. }
  3219. #endif
  3220. spin_lock_bh(&bp->spq_lock);
  3221. if (common) {
  3222. if (!atomic_read(&bp->eq_spq_left)) {
  3223. BNX2X_ERR("BUG! EQ ring full!\n");
  3224. spin_unlock_bh(&bp->spq_lock);
  3225. bnx2x_panic();
  3226. return -EBUSY;
  3227. }
  3228. } else if (!atomic_read(&bp->cq_spq_left)) {
  3229. BNX2X_ERR("BUG! SPQ ring full!\n");
  3230. spin_unlock_bh(&bp->spq_lock);
  3231. bnx2x_panic();
  3232. return -EBUSY;
  3233. }
  3234. spe = bnx2x_sp_get_next(bp);
  3235. /* CID needs port number to be encoded int it */
  3236. spe->hdr.conn_and_cmd_data =
  3237. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3238. HW_CID(bp, cid));
  3239. /* In some cases, type may already contain the func-id
  3240. * mainly in SRIOV related use cases, so we add it here only
  3241. * if it's not already set.
  3242. */
  3243. if (!(cmd_type & SPE_HDR_FUNCTION_ID)) {
  3244. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) &
  3245. SPE_HDR_CONN_TYPE;
  3246. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3247. SPE_HDR_FUNCTION_ID);
  3248. } else {
  3249. type = cmd_type;
  3250. }
  3251. spe->hdr.type = cpu_to_le16(type);
  3252. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3253. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3254. /*
  3255. * It's ok if the actual decrement is issued towards the memory
  3256. * somewhere between the spin_lock and spin_unlock. Thus no
  3257. * more explicit memory barrier is needed.
  3258. */
  3259. if (common)
  3260. atomic_dec(&bp->eq_spq_left);
  3261. else
  3262. atomic_dec(&bp->cq_spq_left);
  3263. DP(BNX2X_MSG_SP,
  3264. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3265. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3266. (u32)(U64_LO(bp->spq_mapping) +
  3267. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3268. HW_CID(bp, cid), data_hi, data_lo, type,
  3269. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3270. bnx2x_sp_prod_update(bp);
  3271. spin_unlock_bh(&bp->spq_lock);
  3272. return 0;
  3273. }
  3274. /* acquire split MCP access lock register */
  3275. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3276. {
  3277. u32 j, val;
  3278. int rc = 0;
  3279. might_sleep();
  3280. for (j = 0; j < 1000; j++) {
  3281. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3282. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3283. if (val & MCPR_ACCESS_LOCK_LOCK)
  3284. break;
  3285. usleep_range(5000, 10000);
  3286. }
  3287. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3288. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3289. rc = -EBUSY;
  3290. }
  3291. return rc;
  3292. }
  3293. /* release split MCP access lock register */
  3294. static void bnx2x_release_alr(struct bnx2x *bp)
  3295. {
  3296. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3297. }
  3298. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3299. #define BNX2X_DEF_SB_IDX 0x0002
  3300. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3301. {
  3302. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3303. u16 rc = 0;
  3304. barrier(); /* status block is written to by the chip */
  3305. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3306. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3307. rc |= BNX2X_DEF_SB_ATT_IDX;
  3308. }
  3309. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3310. bp->def_idx = def_sb->sp_sb.running_index;
  3311. rc |= BNX2X_DEF_SB_IDX;
  3312. }
  3313. /* Do not reorder: indices reading should complete before handling */
  3314. barrier();
  3315. return rc;
  3316. }
  3317. /*
  3318. * slow path service functions
  3319. */
  3320. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3321. {
  3322. int port = BP_PORT(bp);
  3323. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3324. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3325. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3326. NIG_REG_MASK_INTERRUPT_PORT0;
  3327. u32 aeu_mask;
  3328. u32 nig_mask = 0;
  3329. u32 reg_addr;
  3330. if (bp->attn_state & asserted)
  3331. BNX2X_ERR("IGU ERROR\n");
  3332. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3333. aeu_mask = REG_RD(bp, aeu_addr);
  3334. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3335. aeu_mask, asserted);
  3336. aeu_mask &= ~(asserted & 0x3ff);
  3337. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3338. REG_WR(bp, aeu_addr, aeu_mask);
  3339. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3340. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3341. bp->attn_state |= asserted;
  3342. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3343. if (asserted & ATTN_HARD_WIRED_MASK) {
  3344. if (asserted & ATTN_NIG_FOR_FUNC) {
  3345. bnx2x_acquire_phy_lock(bp);
  3346. /* save nig interrupt mask */
  3347. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3348. /* If nig_mask is not set, no need to call the update
  3349. * function.
  3350. */
  3351. if (nig_mask) {
  3352. REG_WR(bp, nig_int_mask_addr, 0);
  3353. bnx2x_link_attn(bp);
  3354. }
  3355. /* handle unicore attn? */
  3356. }
  3357. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3358. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3359. if (asserted & GPIO_2_FUNC)
  3360. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3361. if (asserted & GPIO_3_FUNC)
  3362. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3363. if (asserted & GPIO_4_FUNC)
  3364. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3365. if (port == 0) {
  3366. if (asserted & ATTN_GENERAL_ATTN_1) {
  3367. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3368. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3369. }
  3370. if (asserted & ATTN_GENERAL_ATTN_2) {
  3371. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3372. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3373. }
  3374. if (asserted & ATTN_GENERAL_ATTN_3) {
  3375. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3376. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3377. }
  3378. } else {
  3379. if (asserted & ATTN_GENERAL_ATTN_4) {
  3380. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3381. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3382. }
  3383. if (asserted & ATTN_GENERAL_ATTN_5) {
  3384. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3385. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3386. }
  3387. if (asserted & ATTN_GENERAL_ATTN_6) {
  3388. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3389. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3390. }
  3391. }
  3392. } /* if hardwired */
  3393. if (bp->common.int_block == INT_BLOCK_HC)
  3394. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3395. COMMAND_REG_ATTN_BITS_SET);
  3396. else
  3397. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3398. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3399. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3400. REG_WR(bp, reg_addr, asserted);
  3401. /* now set back the mask */
  3402. if (asserted & ATTN_NIG_FOR_FUNC) {
  3403. /* Verify that IGU ack through BAR was written before restoring
  3404. * NIG mask. This loop should exit after 2-3 iterations max.
  3405. */
  3406. if (bp->common.int_block != INT_BLOCK_HC) {
  3407. u32 cnt = 0, igu_acked;
  3408. do {
  3409. igu_acked = REG_RD(bp,
  3410. IGU_REG_ATTENTION_ACK_BITS);
  3411. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3412. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3413. if (!igu_acked)
  3414. DP(NETIF_MSG_HW,
  3415. "Failed to verify IGU ack on time\n");
  3416. barrier();
  3417. }
  3418. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3419. bnx2x_release_phy_lock(bp);
  3420. }
  3421. }
  3422. static void bnx2x_fan_failure(struct bnx2x *bp)
  3423. {
  3424. int port = BP_PORT(bp);
  3425. u32 ext_phy_config;
  3426. /* mark the failure */
  3427. ext_phy_config =
  3428. SHMEM_RD(bp,
  3429. dev_info.port_hw_config[port].external_phy_config);
  3430. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3431. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3432. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3433. ext_phy_config);
  3434. /* log the failure */
  3435. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3436. "Please contact OEM Support for assistance\n");
  3437. /* Schedule device reset (unload)
  3438. * This is due to some boards consuming sufficient power when driver is
  3439. * up to overheat if fan fails.
  3440. */
  3441. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_FAN_FAILURE, 0);
  3442. }
  3443. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3444. {
  3445. int port = BP_PORT(bp);
  3446. int reg_offset;
  3447. u32 val;
  3448. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3449. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3450. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3451. val = REG_RD(bp, reg_offset);
  3452. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3453. REG_WR(bp, reg_offset, val);
  3454. BNX2X_ERR("SPIO5 hw attention\n");
  3455. /* Fan failure attention */
  3456. bnx2x_hw_reset_phy(&bp->link_params);
  3457. bnx2x_fan_failure(bp);
  3458. }
  3459. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3460. bnx2x_acquire_phy_lock(bp);
  3461. bnx2x_handle_module_detect_int(&bp->link_params);
  3462. bnx2x_release_phy_lock(bp);
  3463. }
  3464. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3465. val = REG_RD(bp, reg_offset);
  3466. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3467. REG_WR(bp, reg_offset, val);
  3468. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3469. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3470. bnx2x_panic();
  3471. }
  3472. }
  3473. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3474. {
  3475. u32 val;
  3476. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3477. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3478. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3479. /* DORQ discard attention */
  3480. if (val & 0x2)
  3481. BNX2X_ERR("FATAL error from DORQ\n");
  3482. }
  3483. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3484. int port = BP_PORT(bp);
  3485. int reg_offset;
  3486. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3487. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3488. val = REG_RD(bp, reg_offset);
  3489. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3490. REG_WR(bp, reg_offset, val);
  3491. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3492. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3493. bnx2x_panic();
  3494. }
  3495. }
  3496. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3497. {
  3498. u32 val;
  3499. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3500. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3501. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3502. /* CFC error attention */
  3503. if (val & 0x2)
  3504. BNX2X_ERR("FATAL error from CFC\n");
  3505. }
  3506. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3507. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3508. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3509. /* RQ_USDMDP_FIFO_OVERFLOW */
  3510. if (val & 0x18000)
  3511. BNX2X_ERR("FATAL error from PXP\n");
  3512. if (!CHIP_IS_E1x(bp)) {
  3513. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3514. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3515. }
  3516. }
  3517. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3518. int port = BP_PORT(bp);
  3519. int reg_offset;
  3520. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3521. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3522. val = REG_RD(bp, reg_offset);
  3523. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3524. REG_WR(bp, reg_offset, val);
  3525. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3526. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3527. bnx2x_panic();
  3528. }
  3529. }
  3530. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3531. {
  3532. u32 val;
  3533. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3534. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3535. int func = BP_FUNC(bp);
  3536. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3537. bnx2x_read_mf_cfg(bp);
  3538. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3539. func_mf_config[BP_ABS_FUNC(bp)].config);
  3540. val = SHMEM_RD(bp,
  3541. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3542. if (val & (DRV_STATUS_DCC_EVENT_MASK |
  3543. DRV_STATUS_OEM_EVENT_MASK))
  3544. bnx2x_oem_event(bp,
  3545. (val & (DRV_STATUS_DCC_EVENT_MASK |
  3546. DRV_STATUS_OEM_EVENT_MASK)));
  3547. if (val & DRV_STATUS_SET_MF_BW)
  3548. bnx2x_set_mf_bw(bp);
  3549. if (val & DRV_STATUS_DRV_INFO_REQ)
  3550. bnx2x_handle_drv_info_req(bp);
  3551. if (val & DRV_STATUS_VF_DISABLED)
  3552. bnx2x_schedule_iov_task(bp,
  3553. BNX2X_IOV_HANDLE_FLR);
  3554. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3555. bnx2x_pmf_update(bp);
  3556. if (bp->port.pmf &&
  3557. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3558. bp->dcbx_enabled > 0)
  3559. /* start dcbx state machine */
  3560. bnx2x_dcbx_set_params(bp,
  3561. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3562. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3563. bnx2x_handle_afex_cmd(bp,
  3564. val & DRV_STATUS_AFEX_EVENT_MASK);
  3565. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3566. bnx2x_handle_eee_event(bp);
  3567. if (val & DRV_STATUS_OEM_UPDATE_SVID)
  3568. bnx2x_handle_update_svid_cmd(bp);
  3569. if (bp->link_vars.periodic_flags &
  3570. PERIODIC_FLAGS_LINK_EVENT) {
  3571. /* sync with link */
  3572. bnx2x_acquire_phy_lock(bp);
  3573. bp->link_vars.periodic_flags &=
  3574. ~PERIODIC_FLAGS_LINK_EVENT;
  3575. bnx2x_release_phy_lock(bp);
  3576. if (IS_MF(bp))
  3577. bnx2x_link_sync_notify(bp);
  3578. bnx2x_link_report(bp);
  3579. }
  3580. /* Always call it here: bnx2x_link_report() will
  3581. * prevent the link indication duplication.
  3582. */
  3583. bnx2x__link_status_update(bp);
  3584. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3585. BNX2X_ERR("MC assert!\n");
  3586. bnx2x_mc_assert(bp);
  3587. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3588. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3589. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3590. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3591. bnx2x_panic();
  3592. } else if (attn & BNX2X_MCP_ASSERT) {
  3593. BNX2X_ERR("MCP assert!\n");
  3594. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3595. bnx2x_fw_dump(bp);
  3596. } else
  3597. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3598. }
  3599. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3600. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3601. if (attn & BNX2X_GRC_TIMEOUT) {
  3602. val = CHIP_IS_E1(bp) ? 0 :
  3603. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3604. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3605. }
  3606. if (attn & BNX2X_GRC_RSV) {
  3607. val = CHIP_IS_E1(bp) ? 0 :
  3608. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3609. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3610. }
  3611. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3612. }
  3613. }
  3614. /*
  3615. * Bits map:
  3616. * 0-7 - Engine0 load counter.
  3617. * 8-15 - Engine1 load counter.
  3618. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3619. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3620. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3621. * on the engine
  3622. * 19 - Engine1 ONE_IS_LOADED.
  3623. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3624. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3625. * just the one belonging to its engine).
  3626. *
  3627. */
  3628. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3629. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3630. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3631. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3632. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3633. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3634. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3635. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3636. /*
  3637. * Set the GLOBAL_RESET bit.
  3638. *
  3639. * Should be run under rtnl lock
  3640. */
  3641. void bnx2x_set_reset_global(struct bnx2x *bp)
  3642. {
  3643. u32 val;
  3644. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3645. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3646. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3647. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3648. }
  3649. /*
  3650. * Clear the GLOBAL_RESET bit.
  3651. *
  3652. * Should be run under rtnl lock
  3653. */
  3654. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3655. {
  3656. u32 val;
  3657. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3658. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3659. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3660. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3661. }
  3662. /*
  3663. * Checks the GLOBAL_RESET bit.
  3664. *
  3665. * should be run under rtnl lock
  3666. */
  3667. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3668. {
  3669. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3670. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3671. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3672. }
  3673. /*
  3674. * Clear RESET_IN_PROGRESS bit for the current engine.
  3675. *
  3676. * Should be run under rtnl lock
  3677. */
  3678. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3679. {
  3680. u32 val;
  3681. u32 bit = BP_PATH(bp) ?
  3682. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3683. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3684. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3685. /* Clear the bit */
  3686. val &= ~bit;
  3687. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3688. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3689. }
  3690. /*
  3691. * Set RESET_IN_PROGRESS for the current engine.
  3692. *
  3693. * should be run under rtnl lock
  3694. */
  3695. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3696. {
  3697. u32 val;
  3698. u32 bit = BP_PATH(bp) ?
  3699. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3700. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3701. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3702. /* Set the bit */
  3703. val |= bit;
  3704. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3705. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3706. }
  3707. /*
  3708. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3709. * should be run under rtnl lock
  3710. */
  3711. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3712. {
  3713. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3714. u32 bit = engine ?
  3715. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3716. /* return false if bit is set */
  3717. return (val & bit) ? false : true;
  3718. }
  3719. /*
  3720. * set pf load for the current pf.
  3721. *
  3722. * should be run under rtnl lock
  3723. */
  3724. void bnx2x_set_pf_load(struct bnx2x *bp)
  3725. {
  3726. u32 val1, val;
  3727. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3728. BNX2X_PATH0_LOAD_CNT_MASK;
  3729. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3730. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3731. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3732. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3733. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3734. /* get the current counter value */
  3735. val1 = (val & mask) >> shift;
  3736. /* set bit of that PF */
  3737. val1 |= (1 << bp->pf_num);
  3738. /* clear the old value */
  3739. val &= ~mask;
  3740. /* set the new one */
  3741. val |= ((val1 << shift) & mask);
  3742. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3743. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3744. }
  3745. /**
  3746. * bnx2x_clear_pf_load - clear pf load mark
  3747. *
  3748. * @bp: driver handle
  3749. *
  3750. * Should be run under rtnl lock.
  3751. * Decrements the load counter for the current engine. Returns
  3752. * whether other functions are still loaded
  3753. */
  3754. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3755. {
  3756. u32 val1, val;
  3757. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3758. BNX2X_PATH0_LOAD_CNT_MASK;
  3759. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3760. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3761. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3762. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3763. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3764. /* get the current counter value */
  3765. val1 = (val & mask) >> shift;
  3766. /* clear bit of that PF */
  3767. val1 &= ~(1 << bp->pf_num);
  3768. /* clear the old value */
  3769. val &= ~mask;
  3770. /* set the new one */
  3771. val |= ((val1 << shift) & mask);
  3772. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3773. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3774. return val1 != 0;
  3775. }
  3776. /*
  3777. * Read the load status for the current engine.
  3778. *
  3779. * should be run under rtnl lock
  3780. */
  3781. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3782. {
  3783. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3784. BNX2X_PATH0_LOAD_CNT_MASK);
  3785. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3786. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3787. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3788. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3789. val = (val & mask) >> shift;
  3790. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3791. engine, val);
  3792. return val != 0;
  3793. }
  3794. static void _print_parity(struct bnx2x *bp, u32 reg)
  3795. {
  3796. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3797. }
  3798. static void _print_next_block(int idx, const char *blk)
  3799. {
  3800. pr_cont("%s%s", idx ? ", " : "", blk);
  3801. }
  3802. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3803. int *par_num, bool print)
  3804. {
  3805. u32 cur_bit;
  3806. bool res;
  3807. int i;
  3808. res = false;
  3809. for (i = 0; sig; i++) {
  3810. cur_bit = (0x1UL << i);
  3811. if (sig & cur_bit) {
  3812. res |= true; /* Each bit is real error! */
  3813. if (print) {
  3814. switch (cur_bit) {
  3815. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3816. _print_next_block((*par_num)++, "BRB");
  3817. _print_parity(bp,
  3818. BRB1_REG_BRB1_PRTY_STS);
  3819. break;
  3820. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3821. _print_next_block((*par_num)++,
  3822. "PARSER");
  3823. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3824. break;
  3825. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3826. _print_next_block((*par_num)++, "TSDM");
  3827. _print_parity(bp,
  3828. TSDM_REG_TSDM_PRTY_STS);
  3829. break;
  3830. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3831. _print_next_block((*par_num)++,
  3832. "SEARCHER");
  3833. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3834. break;
  3835. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3836. _print_next_block((*par_num)++, "TCM");
  3837. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3838. break;
  3839. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3840. _print_next_block((*par_num)++,
  3841. "TSEMI");
  3842. _print_parity(bp,
  3843. TSEM_REG_TSEM_PRTY_STS_0);
  3844. _print_parity(bp,
  3845. TSEM_REG_TSEM_PRTY_STS_1);
  3846. break;
  3847. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3848. _print_next_block((*par_num)++, "XPB");
  3849. _print_parity(bp, GRCBASE_XPB +
  3850. PB_REG_PB_PRTY_STS);
  3851. break;
  3852. }
  3853. }
  3854. /* Clear the bit */
  3855. sig &= ~cur_bit;
  3856. }
  3857. }
  3858. return res;
  3859. }
  3860. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3861. int *par_num, bool *global,
  3862. bool print)
  3863. {
  3864. u32 cur_bit;
  3865. bool res;
  3866. int i;
  3867. res = false;
  3868. for (i = 0; sig; i++) {
  3869. cur_bit = (0x1UL << i);
  3870. if (sig & cur_bit) {
  3871. res |= true; /* Each bit is real error! */
  3872. switch (cur_bit) {
  3873. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3874. if (print) {
  3875. _print_next_block((*par_num)++, "PBF");
  3876. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3877. }
  3878. break;
  3879. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3880. if (print) {
  3881. _print_next_block((*par_num)++, "QM");
  3882. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3883. }
  3884. break;
  3885. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3886. if (print) {
  3887. _print_next_block((*par_num)++, "TM");
  3888. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3889. }
  3890. break;
  3891. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3892. if (print) {
  3893. _print_next_block((*par_num)++, "XSDM");
  3894. _print_parity(bp,
  3895. XSDM_REG_XSDM_PRTY_STS);
  3896. }
  3897. break;
  3898. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3899. if (print) {
  3900. _print_next_block((*par_num)++, "XCM");
  3901. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3902. }
  3903. break;
  3904. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3905. if (print) {
  3906. _print_next_block((*par_num)++,
  3907. "XSEMI");
  3908. _print_parity(bp,
  3909. XSEM_REG_XSEM_PRTY_STS_0);
  3910. _print_parity(bp,
  3911. XSEM_REG_XSEM_PRTY_STS_1);
  3912. }
  3913. break;
  3914. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3915. if (print) {
  3916. _print_next_block((*par_num)++,
  3917. "DOORBELLQ");
  3918. _print_parity(bp,
  3919. DORQ_REG_DORQ_PRTY_STS);
  3920. }
  3921. break;
  3922. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3923. if (print) {
  3924. _print_next_block((*par_num)++, "NIG");
  3925. if (CHIP_IS_E1x(bp)) {
  3926. _print_parity(bp,
  3927. NIG_REG_NIG_PRTY_STS);
  3928. } else {
  3929. _print_parity(bp,
  3930. NIG_REG_NIG_PRTY_STS_0);
  3931. _print_parity(bp,
  3932. NIG_REG_NIG_PRTY_STS_1);
  3933. }
  3934. }
  3935. break;
  3936. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3937. if (print)
  3938. _print_next_block((*par_num)++,
  3939. "VAUX PCI CORE");
  3940. *global = true;
  3941. break;
  3942. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3943. if (print) {
  3944. _print_next_block((*par_num)++,
  3945. "DEBUG");
  3946. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3947. }
  3948. break;
  3949. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3950. if (print) {
  3951. _print_next_block((*par_num)++, "USDM");
  3952. _print_parity(bp,
  3953. USDM_REG_USDM_PRTY_STS);
  3954. }
  3955. break;
  3956. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3957. if (print) {
  3958. _print_next_block((*par_num)++, "UCM");
  3959. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3960. }
  3961. break;
  3962. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3963. if (print) {
  3964. _print_next_block((*par_num)++,
  3965. "USEMI");
  3966. _print_parity(bp,
  3967. USEM_REG_USEM_PRTY_STS_0);
  3968. _print_parity(bp,
  3969. USEM_REG_USEM_PRTY_STS_1);
  3970. }
  3971. break;
  3972. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3973. if (print) {
  3974. _print_next_block((*par_num)++, "UPB");
  3975. _print_parity(bp, GRCBASE_UPB +
  3976. PB_REG_PB_PRTY_STS);
  3977. }
  3978. break;
  3979. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3980. if (print) {
  3981. _print_next_block((*par_num)++, "CSDM");
  3982. _print_parity(bp,
  3983. CSDM_REG_CSDM_PRTY_STS);
  3984. }
  3985. break;
  3986. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3987. if (print) {
  3988. _print_next_block((*par_num)++, "CCM");
  3989. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3990. }
  3991. break;
  3992. }
  3993. /* Clear the bit */
  3994. sig &= ~cur_bit;
  3995. }
  3996. }
  3997. return res;
  3998. }
  3999. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  4000. int *par_num, bool print)
  4001. {
  4002. u32 cur_bit;
  4003. bool res;
  4004. int i;
  4005. res = false;
  4006. for (i = 0; sig; i++) {
  4007. cur_bit = (0x1UL << i);
  4008. if (sig & cur_bit) {
  4009. res = true; /* Each bit is real error! */
  4010. if (print) {
  4011. switch (cur_bit) {
  4012. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  4013. _print_next_block((*par_num)++,
  4014. "CSEMI");
  4015. _print_parity(bp,
  4016. CSEM_REG_CSEM_PRTY_STS_0);
  4017. _print_parity(bp,
  4018. CSEM_REG_CSEM_PRTY_STS_1);
  4019. break;
  4020. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  4021. _print_next_block((*par_num)++, "PXP");
  4022. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  4023. _print_parity(bp,
  4024. PXP2_REG_PXP2_PRTY_STS_0);
  4025. _print_parity(bp,
  4026. PXP2_REG_PXP2_PRTY_STS_1);
  4027. break;
  4028. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  4029. _print_next_block((*par_num)++,
  4030. "PXPPCICLOCKCLIENT");
  4031. break;
  4032. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  4033. _print_next_block((*par_num)++, "CFC");
  4034. _print_parity(bp,
  4035. CFC_REG_CFC_PRTY_STS);
  4036. break;
  4037. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  4038. _print_next_block((*par_num)++, "CDU");
  4039. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  4040. break;
  4041. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  4042. _print_next_block((*par_num)++, "DMAE");
  4043. _print_parity(bp,
  4044. DMAE_REG_DMAE_PRTY_STS);
  4045. break;
  4046. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  4047. _print_next_block((*par_num)++, "IGU");
  4048. if (CHIP_IS_E1x(bp))
  4049. _print_parity(bp,
  4050. HC_REG_HC_PRTY_STS);
  4051. else
  4052. _print_parity(bp,
  4053. IGU_REG_IGU_PRTY_STS);
  4054. break;
  4055. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  4056. _print_next_block((*par_num)++, "MISC");
  4057. _print_parity(bp,
  4058. MISC_REG_MISC_PRTY_STS);
  4059. break;
  4060. }
  4061. }
  4062. /* Clear the bit */
  4063. sig &= ~cur_bit;
  4064. }
  4065. }
  4066. return res;
  4067. }
  4068. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  4069. int *par_num, bool *global,
  4070. bool print)
  4071. {
  4072. bool res = false;
  4073. u32 cur_bit;
  4074. int i;
  4075. for (i = 0; sig; i++) {
  4076. cur_bit = (0x1UL << i);
  4077. if (sig & cur_bit) {
  4078. switch (cur_bit) {
  4079. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  4080. if (print)
  4081. _print_next_block((*par_num)++,
  4082. "MCP ROM");
  4083. *global = true;
  4084. res = true;
  4085. break;
  4086. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  4087. if (print)
  4088. _print_next_block((*par_num)++,
  4089. "MCP UMP RX");
  4090. *global = true;
  4091. res = true;
  4092. break;
  4093. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  4094. if (print)
  4095. _print_next_block((*par_num)++,
  4096. "MCP UMP TX");
  4097. *global = true;
  4098. res = true;
  4099. break;
  4100. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  4101. if (print)
  4102. _print_next_block((*par_num)++,
  4103. "MCP SCPAD");
  4104. /* clear latched SCPAD PATIRY from MCP */
  4105. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  4106. 1UL << 10);
  4107. break;
  4108. }
  4109. /* Clear the bit */
  4110. sig &= ~cur_bit;
  4111. }
  4112. }
  4113. return res;
  4114. }
  4115. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  4116. int *par_num, bool print)
  4117. {
  4118. u32 cur_bit;
  4119. bool res;
  4120. int i;
  4121. res = false;
  4122. for (i = 0; sig; i++) {
  4123. cur_bit = (0x1UL << i);
  4124. if (sig & cur_bit) {
  4125. res = true; /* Each bit is real error! */
  4126. if (print) {
  4127. switch (cur_bit) {
  4128. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  4129. _print_next_block((*par_num)++,
  4130. "PGLUE_B");
  4131. _print_parity(bp,
  4132. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  4133. break;
  4134. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  4135. _print_next_block((*par_num)++, "ATC");
  4136. _print_parity(bp,
  4137. ATC_REG_ATC_PRTY_STS);
  4138. break;
  4139. }
  4140. }
  4141. /* Clear the bit */
  4142. sig &= ~cur_bit;
  4143. }
  4144. }
  4145. return res;
  4146. }
  4147. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  4148. u32 *sig)
  4149. {
  4150. bool res = false;
  4151. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  4152. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  4153. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  4154. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  4155. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  4156. int par_num = 0;
  4157. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  4158. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  4159. sig[0] & HW_PRTY_ASSERT_SET_0,
  4160. sig[1] & HW_PRTY_ASSERT_SET_1,
  4161. sig[2] & HW_PRTY_ASSERT_SET_2,
  4162. sig[3] & HW_PRTY_ASSERT_SET_3,
  4163. sig[4] & HW_PRTY_ASSERT_SET_4);
  4164. if (print)
  4165. netdev_err(bp->dev,
  4166. "Parity errors detected in blocks: ");
  4167. res |= bnx2x_check_blocks_with_parity0(bp,
  4168. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  4169. res |= bnx2x_check_blocks_with_parity1(bp,
  4170. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  4171. res |= bnx2x_check_blocks_with_parity2(bp,
  4172. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  4173. res |= bnx2x_check_blocks_with_parity3(bp,
  4174. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  4175. res |= bnx2x_check_blocks_with_parity4(bp,
  4176. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  4177. if (print)
  4178. pr_cont("\n");
  4179. }
  4180. return res;
  4181. }
  4182. /**
  4183. * bnx2x_chk_parity_attn - checks for parity attentions.
  4184. *
  4185. * @bp: driver handle
  4186. * @global: true if there was a global attention
  4187. * @print: show parity attention in syslog
  4188. */
  4189. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  4190. {
  4191. struct attn_route attn = { {0} };
  4192. int port = BP_PORT(bp);
  4193. attn.sig[0] = REG_RD(bp,
  4194. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  4195. port*4);
  4196. attn.sig[1] = REG_RD(bp,
  4197. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  4198. port*4);
  4199. attn.sig[2] = REG_RD(bp,
  4200. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  4201. port*4);
  4202. attn.sig[3] = REG_RD(bp,
  4203. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4204. port*4);
  4205. /* Since MCP attentions can't be disabled inside the block, we need to
  4206. * read AEU registers to see whether they're currently disabled
  4207. */
  4208. attn.sig[3] &= ((REG_RD(bp,
  4209. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4210. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4211. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4212. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4213. if (!CHIP_IS_E1x(bp))
  4214. attn.sig[4] = REG_RD(bp,
  4215. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4216. port*4);
  4217. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4218. }
  4219. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4220. {
  4221. u32 val;
  4222. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4223. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4224. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4225. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4226. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4227. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4228. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4229. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4230. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4231. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4232. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4233. if (val &
  4234. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4235. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4236. if (val &
  4237. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4238. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4239. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4240. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4241. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4242. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4243. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4244. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4245. }
  4246. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4247. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4248. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4249. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4250. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4251. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4252. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4253. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4254. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4255. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4256. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4257. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4258. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4259. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4260. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4261. }
  4262. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4263. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4264. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4265. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4266. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4267. }
  4268. }
  4269. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4270. {
  4271. struct attn_route attn, *group_mask;
  4272. int port = BP_PORT(bp);
  4273. int index;
  4274. u32 reg_addr;
  4275. u32 val;
  4276. u32 aeu_mask;
  4277. bool global = false;
  4278. /* need to take HW lock because MCP or other port might also
  4279. try to handle this event */
  4280. bnx2x_acquire_alr(bp);
  4281. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4282. #ifndef BNX2X_STOP_ON_ERROR
  4283. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4284. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4285. /* Disable HW interrupts */
  4286. bnx2x_int_disable(bp);
  4287. /* In case of parity errors don't handle attentions so that
  4288. * other function would "see" parity errors.
  4289. */
  4290. #else
  4291. bnx2x_panic();
  4292. #endif
  4293. bnx2x_release_alr(bp);
  4294. return;
  4295. }
  4296. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4297. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4298. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4299. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4300. if (!CHIP_IS_E1x(bp))
  4301. attn.sig[4] =
  4302. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4303. else
  4304. attn.sig[4] = 0;
  4305. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4306. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4307. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4308. if (deasserted & (1 << index)) {
  4309. group_mask = &bp->attn_group[index];
  4310. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4311. index,
  4312. group_mask->sig[0], group_mask->sig[1],
  4313. group_mask->sig[2], group_mask->sig[3],
  4314. group_mask->sig[4]);
  4315. bnx2x_attn_int_deasserted4(bp,
  4316. attn.sig[4] & group_mask->sig[4]);
  4317. bnx2x_attn_int_deasserted3(bp,
  4318. attn.sig[3] & group_mask->sig[3]);
  4319. bnx2x_attn_int_deasserted1(bp,
  4320. attn.sig[1] & group_mask->sig[1]);
  4321. bnx2x_attn_int_deasserted2(bp,
  4322. attn.sig[2] & group_mask->sig[2]);
  4323. bnx2x_attn_int_deasserted0(bp,
  4324. attn.sig[0] & group_mask->sig[0]);
  4325. }
  4326. }
  4327. bnx2x_release_alr(bp);
  4328. if (bp->common.int_block == INT_BLOCK_HC)
  4329. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4330. COMMAND_REG_ATTN_BITS_CLR);
  4331. else
  4332. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4333. val = ~deasserted;
  4334. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4335. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4336. REG_WR(bp, reg_addr, val);
  4337. if (~bp->attn_state & deasserted)
  4338. BNX2X_ERR("IGU ERROR\n");
  4339. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4340. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4341. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4342. aeu_mask = REG_RD(bp, reg_addr);
  4343. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4344. aeu_mask, deasserted);
  4345. aeu_mask |= (deasserted & 0x3ff);
  4346. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4347. REG_WR(bp, reg_addr, aeu_mask);
  4348. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4349. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4350. bp->attn_state &= ~deasserted;
  4351. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4352. }
  4353. static void bnx2x_attn_int(struct bnx2x *bp)
  4354. {
  4355. /* read local copy of bits */
  4356. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4357. attn_bits);
  4358. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4359. attn_bits_ack);
  4360. u32 attn_state = bp->attn_state;
  4361. /* look for changed bits */
  4362. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4363. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4364. DP(NETIF_MSG_HW,
  4365. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4366. attn_bits, attn_ack, asserted, deasserted);
  4367. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4368. BNX2X_ERR("BAD attention state\n");
  4369. /* handle bits that were raised */
  4370. if (asserted)
  4371. bnx2x_attn_int_asserted(bp, asserted);
  4372. if (deasserted)
  4373. bnx2x_attn_int_deasserted(bp, deasserted);
  4374. }
  4375. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4376. u16 index, u8 op, u8 update)
  4377. {
  4378. u32 igu_addr = bp->igu_base_addr;
  4379. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4380. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4381. igu_addr);
  4382. }
  4383. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4384. {
  4385. /* No memory barriers */
  4386. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4387. mmiowb(); /* keep prod updates ordered */
  4388. }
  4389. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4390. union event_ring_elem *elem)
  4391. {
  4392. u8 err = elem->message.error;
  4393. if (!bp->cnic_eth_dev.starting_cid ||
  4394. (cid < bp->cnic_eth_dev.starting_cid &&
  4395. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4396. return 1;
  4397. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4398. if (unlikely(err)) {
  4399. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4400. cid);
  4401. bnx2x_panic_dump(bp, false);
  4402. }
  4403. bnx2x_cnic_cfc_comp(bp, cid, err);
  4404. return 0;
  4405. }
  4406. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4407. {
  4408. struct bnx2x_mcast_ramrod_params rparam;
  4409. int rc;
  4410. memset(&rparam, 0, sizeof(rparam));
  4411. rparam.mcast_obj = &bp->mcast_obj;
  4412. netif_addr_lock_bh(bp->dev);
  4413. /* Clear pending state for the last command */
  4414. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4415. /* If there are pending mcast commands - send them */
  4416. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4417. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4418. if (rc < 0)
  4419. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4420. rc);
  4421. }
  4422. netif_addr_unlock_bh(bp->dev);
  4423. }
  4424. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4425. union event_ring_elem *elem)
  4426. {
  4427. unsigned long ramrod_flags = 0;
  4428. int rc = 0;
  4429. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4430. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4431. /* Always push next commands out, don't wait here */
  4432. __set_bit(RAMROD_CONT, &ramrod_flags);
  4433. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4434. >> BNX2X_SWCID_SHIFT) {
  4435. case BNX2X_FILTER_MAC_PENDING:
  4436. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4437. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4438. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4439. else
  4440. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4441. break;
  4442. case BNX2X_FILTER_MCAST_PENDING:
  4443. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4444. /* This is only relevant for 57710 where multicast MACs are
  4445. * configured as unicast MACs using the same ramrod.
  4446. */
  4447. bnx2x_handle_mcast_eqe(bp);
  4448. return;
  4449. default:
  4450. BNX2X_ERR("Unsupported classification command: %d\n",
  4451. elem->message.data.eth_event.echo);
  4452. return;
  4453. }
  4454. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4455. if (rc < 0)
  4456. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4457. else if (rc > 0)
  4458. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4459. }
  4460. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4461. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4462. {
  4463. netif_addr_lock_bh(bp->dev);
  4464. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4465. /* Send rx_mode command again if was requested */
  4466. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4467. bnx2x_set_storm_rx_mode(bp);
  4468. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4469. &bp->sp_state))
  4470. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4471. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4472. &bp->sp_state))
  4473. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4474. netif_addr_unlock_bh(bp->dev);
  4475. }
  4476. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4477. union event_ring_elem *elem)
  4478. {
  4479. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4480. DP(BNX2X_MSG_SP,
  4481. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4482. elem->message.data.vif_list_event.func_bit_map);
  4483. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4484. elem->message.data.vif_list_event.func_bit_map);
  4485. } else if (elem->message.data.vif_list_event.echo ==
  4486. VIF_LIST_RULE_SET) {
  4487. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4488. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4489. }
  4490. }
  4491. /* called with rtnl_lock */
  4492. static void bnx2x_after_function_update(struct bnx2x *bp)
  4493. {
  4494. int q, rc;
  4495. struct bnx2x_fastpath *fp;
  4496. struct bnx2x_queue_state_params queue_params = {NULL};
  4497. struct bnx2x_queue_update_params *q_update_params =
  4498. &queue_params.params.update;
  4499. /* Send Q update command with afex vlan removal values for all Qs */
  4500. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4501. /* set silent vlan removal values according to vlan mode */
  4502. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4503. &q_update_params->update_flags);
  4504. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4505. &q_update_params->update_flags);
  4506. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4507. /* in access mode mark mask and value are 0 to strip all vlans */
  4508. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4509. q_update_params->silent_removal_value = 0;
  4510. q_update_params->silent_removal_mask = 0;
  4511. } else {
  4512. q_update_params->silent_removal_value =
  4513. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4514. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4515. }
  4516. for_each_eth_queue(bp, q) {
  4517. /* Set the appropriate Queue object */
  4518. fp = &bp->fp[q];
  4519. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4520. /* send the ramrod */
  4521. rc = bnx2x_queue_state_change(bp, &queue_params);
  4522. if (rc < 0)
  4523. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4524. q);
  4525. }
  4526. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4527. fp = &bp->fp[FCOE_IDX(bp)];
  4528. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4529. /* clear pending completion bit */
  4530. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4531. /* mark latest Q bit */
  4532. smp_mb__before_atomic();
  4533. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4534. smp_mb__after_atomic();
  4535. /* send Q update ramrod for FCoE Q */
  4536. rc = bnx2x_queue_state_change(bp, &queue_params);
  4537. if (rc < 0)
  4538. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4539. q);
  4540. } else {
  4541. /* If no FCoE ring - ACK MCP now */
  4542. bnx2x_link_report(bp);
  4543. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4544. }
  4545. }
  4546. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4547. struct bnx2x *bp, u32 cid)
  4548. {
  4549. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4550. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4551. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4552. else
  4553. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4554. }
  4555. static void bnx2x_eq_int(struct bnx2x *bp)
  4556. {
  4557. u16 hw_cons, sw_cons, sw_prod;
  4558. union event_ring_elem *elem;
  4559. u8 echo;
  4560. u32 cid;
  4561. u8 opcode;
  4562. int rc, spqe_cnt = 0;
  4563. struct bnx2x_queue_sp_obj *q_obj;
  4564. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4565. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4566. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4567. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4568. * when we get the next-page we need to adjust so the loop
  4569. * condition below will be met. The next element is the size of a
  4570. * regular element and hence incrementing by 1
  4571. */
  4572. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4573. hw_cons++;
  4574. /* This function may never run in parallel with itself for a
  4575. * specific bp, thus there is no need in "paired" read memory
  4576. * barrier here.
  4577. */
  4578. sw_cons = bp->eq_cons;
  4579. sw_prod = bp->eq_prod;
  4580. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4581. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4582. for (; sw_cons != hw_cons;
  4583. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4584. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4585. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4586. if (!rc) {
  4587. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4588. rc);
  4589. goto next_spqe;
  4590. }
  4591. /* elem CID originates from FW; actually LE */
  4592. cid = SW_CID((__force __le32)
  4593. elem->message.data.cfc_del_event.cid);
  4594. opcode = elem->message.opcode;
  4595. /* handle eq element */
  4596. switch (opcode) {
  4597. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4598. bnx2x_vf_mbx_schedule(bp,
  4599. &elem->message.data.vf_pf_event);
  4600. continue;
  4601. case EVENT_RING_OPCODE_STAT_QUERY:
  4602. DP_AND((BNX2X_MSG_SP | BNX2X_MSG_STATS),
  4603. "got statistics comp event %d\n",
  4604. bp->stats_comp++);
  4605. /* nothing to do with stats comp */
  4606. goto next_spqe;
  4607. case EVENT_RING_OPCODE_CFC_DEL:
  4608. /* handle according to cid range */
  4609. /*
  4610. * we may want to verify here that the bp state is
  4611. * HALTING
  4612. */
  4613. DP(BNX2X_MSG_SP,
  4614. "got delete ramrod for MULTI[%d]\n", cid);
  4615. if (CNIC_LOADED(bp) &&
  4616. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4617. goto next_spqe;
  4618. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4619. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4620. break;
  4621. goto next_spqe;
  4622. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4623. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4624. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4625. if (f_obj->complete_cmd(bp, f_obj,
  4626. BNX2X_F_CMD_TX_STOP))
  4627. break;
  4628. goto next_spqe;
  4629. case EVENT_RING_OPCODE_START_TRAFFIC:
  4630. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4631. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4632. if (f_obj->complete_cmd(bp, f_obj,
  4633. BNX2X_F_CMD_TX_START))
  4634. break;
  4635. goto next_spqe;
  4636. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4637. echo = elem->message.data.function_update_event.echo;
  4638. if (echo == SWITCH_UPDATE) {
  4639. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4640. "got FUNC_SWITCH_UPDATE ramrod\n");
  4641. if (f_obj->complete_cmd(
  4642. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4643. break;
  4644. } else {
  4645. int cmd = BNX2X_SP_RTNL_AFEX_F_UPDATE;
  4646. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4647. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4648. f_obj->complete_cmd(bp, f_obj,
  4649. BNX2X_F_CMD_AFEX_UPDATE);
  4650. /* We will perform the Queues update from
  4651. * sp_rtnl task as all Queue SP operations
  4652. * should run under rtnl_lock.
  4653. */
  4654. bnx2x_schedule_sp_rtnl(bp, cmd, 0);
  4655. }
  4656. goto next_spqe;
  4657. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4658. f_obj->complete_cmd(bp, f_obj,
  4659. BNX2X_F_CMD_AFEX_VIFLISTS);
  4660. bnx2x_after_afex_vif_lists(bp, elem);
  4661. goto next_spqe;
  4662. case EVENT_RING_OPCODE_FUNCTION_START:
  4663. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4664. "got FUNC_START ramrod\n");
  4665. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4666. break;
  4667. goto next_spqe;
  4668. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4669. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4670. "got FUNC_STOP ramrod\n");
  4671. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4672. break;
  4673. goto next_spqe;
  4674. case EVENT_RING_OPCODE_SET_TIMESYNC:
  4675. DP(BNX2X_MSG_SP | BNX2X_MSG_PTP,
  4676. "got set_timesync ramrod completion\n");
  4677. if (f_obj->complete_cmd(bp, f_obj,
  4678. BNX2X_F_CMD_SET_TIMESYNC))
  4679. break;
  4680. goto next_spqe;
  4681. }
  4682. switch (opcode | bp->state) {
  4683. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4684. BNX2X_STATE_OPEN):
  4685. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4686. BNX2X_STATE_OPENING_WAIT4_PORT):
  4687. cid = elem->message.data.eth_event.echo &
  4688. BNX2X_SWCID_MASK;
  4689. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4690. cid);
  4691. rss_raw->clear_pending(rss_raw);
  4692. break;
  4693. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4694. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4695. case (EVENT_RING_OPCODE_SET_MAC |
  4696. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4697. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4698. BNX2X_STATE_OPEN):
  4699. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4700. BNX2X_STATE_DIAG):
  4701. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4702. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4703. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4704. bnx2x_handle_classification_eqe(bp, elem);
  4705. break;
  4706. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4707. BNX2X_STATE_OPEN):
  4708. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4709. BNX2X_STATE_DIAG):
  4710. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4711. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4712. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4713. bnx2x_handle_mcast_eqe(bp);
  4714. break;
  4715. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4716. BNX2X_STATE_OPEN):
  4717. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4718. BNX2X_STATE_DIAG):
  4719. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4720. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4721. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4722. bnx2x_handle_rx_mode_eqe(bp);
  4723. break;
  4724. default:
  4725. /* unknown event log error and continue */
  4726. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4727. elem->message.opcode, bp->state);
  4728. }
  4729. next_spqe:
  4730. spqe_cnt++;
  4731. } /* for */
  4732. smp_mb__before_atomic();
  4733. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4734. bp->eq_cons = sw_cons;
  4735. bp->eq_prod = sw_prod;
  4736. /* Make sure that above mem writes were issued towards the memory */
  4737. smp_wmb();
  4738. /* update producer */
  4739. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4740. }
  4741. static void bnx2x_sp_task(struct work_struct *work)
  4742. {
  4743. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4744. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4745. /* make sure the atomic interrupt_occurred has been written */
  4746. smp_rmb();
  4747. if (atomic_read(&bp->interrupt_occurred)) {
  4748. /* what work needs to be performed? */
  4749. u16 status = bnx2x_update_dsb_idx(bp);
  4750. DP(BNX2X_MSG_SP, "status %x\n", status);
  4751. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4752. atomic_set(&bp->interrupt_occurred, 0);
  4753. /* HW attentions */
  4754. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4755. bnx2x_attn_int(bp);
  4756. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4757. }
  4758. /* SP events: STAT_QUERY and others */
  4759. if (status & BNX2X_DEF_SB_IDX) {
  4760. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4761. if (FCOE_INIT(bp) &&
  4762. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4763. /* Prevent local bottom-halves from running as
  4764. * we are going to change the local NAPI list.
  4765. */
  4766. local_bh_disable();
  4767. napi_schedule(&bnx2x_fcoe(bp, napi));
  4768. local_bh_enable();
  4769. }
  4770. /* Handle EQ completions */
  4771. bnx2x_eq_int(bp);
  4772. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4773. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4774. status &= ~BNX2X_DEF_SB_IDX;
  4775. }
  4776. /* if status is non zero then perhaps something went wrong */
  4777. if (unlikely(status))
  4778. DP(BNX2X_MSG_SP,
  4779. "got an unknown interrupt! (status 0x%x)\n", status);
  4780. /* ack status block only if something was actually handled */
  4781. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4782. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4783. }
  4784. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4785. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4786. &bp->sp_state)) {
  4787. bnx2x_link_report(bp);
  4788. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4789. }
  4790. }
  4791. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4792. {
  4793. struct net_device *dev = dev_instance;
  4794. struct bnx2x *bp = netdev_priv(dev);
  4795. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4796. IGU_INT_DISABLE, 0);
  4797. #ifdef BNX2X_STOP_ON_ERROR
  4798. if (unlikely(bp->panic))
  4799. return IRQ_HANDLED;
  4800. #endif
  4801. if (CNIC_LOADED(bp)) {
  4802. struct cnic_ops *c_ops;
  4803. rcu_read_lock();
  4804. c_ops = rcu_dereference(bp->cnic_ops);
  4805. if (c_ops)
  4806. c_ops->cnic_handler(bp->cnic_data, NULL);
  4807. rcu_read_unlock();
  4808. }
  4809. /* schedule sp task to perform default status block work, ack
  4810. * attentions and enable interrupts.
  4811. */
  4812. bnx2x_schedule_sp_task(bp);
  4813. return IRQ_HANDLED;
  4814. }
  4815. /* end of slow path */
  4816. void bnx2x_drv_pulse(struct bnx2x *bp)
  4817. {
  4818. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4819. bp->fw_drv_pulse_wr_seq);
  4820. }
  4821. static void bnx2x_timer(unsigned long data)
  4822. {
  4823. struct bnx2x *bp = (struct bnx2x *) data;
  4824. if (!netif_running(bp->dev))
  4825. return;
  4826. if (IS_PF(bp) &&
  4827. !BP_NOMCP(bp)) {
  4828. int mb_idx = BP_FW_MB_IDX(bp);
  4829. u16 drv_pulse;
  4830. u16 mcp_pulse;
  4831. ++bp->fw_drv_pulse_wr_seq;
  4832. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4833. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4834. bnx2x_drv_pulse(bp);
  4835. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4836. MCP_PULSE_SEQ_MASK);
  4837. /* The delta between driver pulse and mcp response
  4838. * should not get too big. If the MFW is more than 5 pulses
  4839. * behind, we should worry about it enough to generate an error
  4840. * log.
  4841. */
  4842. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4843. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4844. drv_pulse, mcp_pulse);
  4845. }
  4846. if (bp->state == BNX2X_STATE_OPEN)
  4847. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4848. /* sample pf vf bulletin board for new posts from pf */
  4849. if (IS_VF(bp))
  4850. bnx2x_timer_sriov(bp);
  4851. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4852. }
  4853. /* end of Statistics */
  4854. /* nic init */
  4855. /*
  4856. * nic init service functions
  4857. */
  4858. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4859. {
  4860. u32 i;
  4861. if (!(len%4) && !(addr%4))
  4862. for (i = 0; i < len; i += 4)
  4863. REG_WR(bp, addr + i, fill);
  4864. else
  4865. for (i = 0; i < len; i++)
  4866. REG_WR8(bp, addr + i, fill);
  4867. }
  4868. /* helper: writes FP SP data to FW - data_size in dwords */
  4869. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4870. int fw_sb_id,
  4871. u32 *sb_data_p,
  4872. u32 data_size)
  4873. {
  4874. int index;
  4875. for (index = 0; index < data_size; index++)
  4876. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4877. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4878. sizeof(u32)*index,
  4879. *(sb_data_p + index));
  4880. }
  4881. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4882. {
  4883. u32 *sb_data_p;
  4884. u32 data_size = 0;
  4885. struct hc_status_block_data_e2 sb_data_e2;
  4886. struct hc_status_block_data_e1x sb_data_e1x;
  4887. /* disable the function first */
  4888. if (!CHIP_IS_E1x(bp)) {
  4889. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4890. sb_data_e2.common.state = SB_DISABLED;
  4891. sb_data_e2.common.p_func.vf_valid = false;
  4892. sb_data_p = (u32 *)&sb_data_e2;
  4893. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4894. } else {
  4895. memset(&sb_data_e1x, 0,
  4896. sizeof(struct hc_status_block_data_e1x));
  4897. sb_data_e1x.common.state = SB_DISABLED;
  4898. sb_data_e1x.common.p_func.vf_valid = false;
  4899. sb_data_p = (u32 *)&sb_data_e1x;
  4900. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4901. }
  4902. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4903. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4904. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4905. CSTORM_STATUS_BLOCK_SIZE);
  4906. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4907. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4908. CSTORM_SYNC_BLOCK_SIZE);
  4909. }
  4910. /* helper: writes SP SB data to FW */
  4911. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4912. struct hc_sp_status_block_data *sp_sb_data)
  4913. {
  4914. int func = BP_FUNC(bp);
  4915. int i;
  4916. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4917. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4918. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4919. i*sizeof(u32),
  4920. *((u32 *)sp_sb_data + i));
  4921. }
  4922. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4923. {
  4924. int func = BP_FUNC(bp);
  4925. struct hc_sp_status_block_data sp_sb_data;
  4926. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4927. sp_sb_data.state = SB_DISABLED;
  4928. sp_sb_data.p_func.vf_valid = false;
  4929. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4930. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4931. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4932. CSTORM_SP_STATUS_BLOCK_SIZE);
  4933. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4934. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4935. CSTORM_SP_SYNC_BLOCK_SIZE);
  4936. }
  4937. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4938. int igu_sb_id, int igu_seg_id)
  4939. {
  4940. hc_sm->igu_sb_id = igu_sb_id;
  4941. hc_sm->igu_seg_id = igu_seg_id;
  4942. hc_sm->timer_value = 0xFF;
  4943. hc_sm->time_to_expire = 0xFFFFFFFF;
  4944. }
  4945. /* allocates state machine ids. */
  4946. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4947. {
  4948. /* zero out state machine indices */
  4949. /* rx indices */
  4950. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4951. /* tx indices */
  4952. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4953. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4954. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4955. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4956. /* map indices */
  4957. /* rx indices */
  4958. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4959. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4960. /* tx indices */
  4961. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4962. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4963. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4964. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4965. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4966. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4967. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4968. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4969. }
  4970. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4971. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4972. {
  4973. int igu_seg_id;
  4974. struct hc_status_block_data_e2 sb_data_e2;
  4975. struct hc_status_block_data_e1x sb_data_e1x;
  4976. struct hc_status_block_sm *hc_sm_p;
  4977. int data_size;
  4978. u32 *sb_data_p;
  4979. if (CHIP_INT_MODE_IS_BC(bp))
  4980. igu_seg_id = HC_SEG_ACCESS_NORM;
  4981. else
  4982. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4983. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4984. if (!CHIP_IS_E1x(bp)) {
  4985. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4986. sb_data_e2.common.state = SB_ENABLED;
  4987. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4988. sb_data_e2.common.p_func.vf_id = vfid;
  4989. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4990. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4991. sb_data_e2.common.same_igu_sb_1b = true;
  4992. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4993. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4994. hc_sm_p = sb_data_e2.common.state_machine;
  4995. sb_data_p = (u32 *)&sb_data_e2;
  4996. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4997. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4998. } else {
  4999. memset(&sb_data_e1x, 0,
  5000. sizeof(struct hc_status_block_data_e1x));
  5001. sb_data_e1x.common.state = SB_ENABLED;
  5002. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  5003. sb_data_e1x.common.p_func.vf_id = 0xff;
  5004. sb_data_e1x.common.p_func.vf_valid = false;
  5005. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  5006. sb_data_e1x.common.same_igu_sb_1b = true;
  5007. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  5008. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  5009. hc_sm_p = sb_data_e1x.common.state_machine;
  5010. sb_data_p = (u32 *)&sb_data_e1x;
  5011. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  5012. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  5013. }
  5014. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  5015. igu_sb_id, igu_seg_id);
  5016. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  5017. igu_sb_id, igu_seg_id);
  5018. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  5019. /* write indices to HW - PCI guarantees endianity of regpairs */
  5020. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  5021. }
  5022. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  5023. u16 tx_usec, u16 rx_usec)
  5024. {
  5025. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  5026. false, rx_usec);
  5027. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5028. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  5029. tx_usec);
  5030. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5031. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  5032. tx_usec);
  5033. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  5034. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  5035. tx_usec);
  5036. }
  5037. static void bnx2x_init_def_sb(struct bnx2x *bp)
  5038. {
  5039. struct host_sp_status_block *def_sb = bp->def_status_blk;
  5040. dma_addr_t mapping = bp->def_status_blk_mapping;
  5041. int igu_sp_sb_index;
  5042. int igu_seg_id;
  5043. int port = BP_PORT(bp);
  5044. int func = BP_FUNC(bp);
  5045. int reg_offset, reg_offset_en5;
  5046. u64 section;
  5047. int index;
  5048. struct hc_sp_status_block_data sp_sb_data;
  5049. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  5050. if (CHIP_INT_MODE_IS_BC(bp)) {
  5051. igu_sp_sb_index = DEF_SB_IGU_ID;
  5052. igu_seg_id = HC_SEG_ACCESS_DEF;
  5053. } else {
  5054. igu_sp_sb_index = bp->igu_dsb_id;
  5055. igu_seg_id = IGU_SEG_ACCESS_DEF;
  5056. }
  5057. /* ATTN */
  5058. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5059. atten_status_block);
  5060. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  5061. bp->attn_state = 0;
  5062. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5063. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5064. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  5065. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  5066. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  5067. int sindex;
  5068. /* take care of sig[0]..sig[4] */
  5069. for (sindex = 0; sindex < 4; sindex++)
  5070. bp->attn_group[index].sig[sindex] =
  5071. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  5072. if (!CHIP_IS_E1x(bp))
  5073. /*
  5074. * enable5 is separate from the rest of the registers,
  5075. * and therefore the address skip is 4
  5076. * and not 16 between the different groups
  5077. */
  5078. bp->attn_group[index].sig[4] = REG_RD(bp,
  5079. reg_offset_en5 + 0x4*index);
  5080. else
  5081. bp->attn_group[index].sig[4] = 0;
  5082. }
  5083. if (bp->common.int_block == INT_BLOCK_HC) {
  5084. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  5085. HC_REG_ATTN_MSG0_ADDR_L);
  5086. REG_WR(bp, reg_offset, U64_LO(section));
  5087. REG_WR(bp, reg_offset + 4, U64_HI(section));
  5088. } else if (!CHIP_IS_E1x(bp)) {
  5089. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  5090. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  5091. }
  5092. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  5093. sp_sb);
  5094. bnx2x_zero_sp_sb(bp);
  5095. /* PCI guarantees endianity of regpairs */
  5096. sp_sb_data.state = SB_ENABLED;
  5097. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  5098. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  5099. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  5100. sp_sb_data.igu_seg_id = igu_seg_id;
  5101. sp_sb_data.p_func.pf_id = func;
  5102. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  5103. sp_sb_data.p_func.vf_id = 0xff;
  5104. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  5105. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  5106. }
  5107. void bnx2x_update_coalesce(struct bnx2x *bp)
  5108. {
  5109. int i;
  5110. for_each_eth_queue(bp, i)
  5111. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  5112. bp->tx_ticks, bp->rx_ticks);
  5113. }
  5114. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  5115. {
  5116. spin_lock_init(&bp->spq_lock);
  5117. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  5118. bp->spq_prod_idx = 0;
  5119. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  5120. bp->spq_prod_bd = bp->spq;
  5121. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  5122. }
  5123. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  5124. {
  5125. int i;
  5126. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  5127. union event_ring_elem *elem =
  5128. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  5129. elem->next_page.addr.hi =
  5130. cpu_to_le32(U64_HI(bp->eq_mapping +
  5131. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  5132. elem->next_page.addr.lo =
  5133. cpu_to_le32(U64_LO(bp->eq_mapping +
  5134. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  5135. }
  5136. bp->eq_cons = 0;
  5137. bp->eq_prod = NUM_EQ_DESC;
  5138. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  5139. /* we want a warning message before it gets wrought... */
  5140. atomic_set(&bp->eq_spq_left,
  5141. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  5142. }
  5143. /* called with netif_addr_lock_bh() */
  5144. static int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  5145. unsigned long rx_mode_flags,
  5146. unsigned long rx_accept_flags,
  5147. unsigned long tx_accept_flags,
  5148. unsigned long ramrod_flags)
  5149. {
  5150. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  5151. int rc;
  5152. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5153. /* Prepare ramrod parameters */
  5154. ramrod_param.cid = 0;
  5155. ramrod_param.cl_id = cl_id;
  5156. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  5157. ramrod_param.func_id = BP_FUNC(bp);
  5158. ramrod_param.pstate = &bp->sp_state;
  5159. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  5160. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  5161. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  5162. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  5163. ramrod_param.ramrod_flags = ramrod_flags;
  5164. ramrod_param.rx_mode_flags = rx_mode_flags;
  5165. ramrod_param.rx_accept_flags = rx_accept_flags;
  5166. ramrod_param.tx_accept_flags = tx_accept_flags;
  5167. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  5168. if (rc < 0) {
  5169. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  5170. return rc;
  5171. }
  5172. return 0;
  5173. }
  5174. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  5175. unsigned long *rx_accept_flags,
  5176. unsigned long *tx_accept_flags)
  5177. {
  5178. /* Clear the flags first */
  5179. *rx_accept_flags = 0;
  5180. *tx_accept_flags = 0;
  5181. switch (rx_mode) {
  5182. case BNX2X_RX_MODE_NONE:
  5183. /*
  5184. * 'drop all' supersedes any accept flags that may have been
  5185. * passed to the function.
  5186. */
  5187. break;
  5188. case BNX2X_RX_MODE_NORMAL:
  5189. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5190. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  5191. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5192. /* internal switching mode */
  5193. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5194. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  5195. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5196. break;
  5197. case BNX2X_RX_MODE_ALLMULTI:
  5198. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5199. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5200. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5201. /* internal switching mode */
  5202. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5203. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5204. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5205. break;
  5206. case BNX2X_RX_MODE_PROMISC:
  5207. /* According to definition of SI mode, iface in promisc mode
  5208. * should receive matched and unmatched (in resolution of port)
  5209. * unicast packets.
  5210. */
  5211. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5212. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5213. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5214. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5215. /* internal switching mode */
  5216. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5217. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5218. if (IS_MF_SI(bp))
  5219. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5220. else
  5221. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5222. break;
  5223. default:
  5224. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5225. return -EINVAL;
  5226. }
  5227. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5228. if (rx_mode != BNX2X_RX_MODE_NONE) {
  5229. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5230. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5231. }
  5232. return 0;
  5233. }
  5234. /* called with netif_addr_lock_bh() */
  5235. static int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5236. {
  5237. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5238. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5239. int rc;
  5240. if (!NO_FCOE(bp))
  5241. /* Configure rx_mode of FCoE Queue */
  5242. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5243. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5244. &tx_accept_flags);
  5245. if (rc)
  5246. return rc;
  5247. __set_bit(RAMROD_RX, &ramrod_flags);
  5248. __set_bit(RAMROD_TX, &ramrod_flags);
  5249. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5250. rx_accept_flags, tx_accept_flags,
  5251. ramrod_flags);
  5252. }
  5253. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5254. {
  5255. int i;
  5256. /* Zero this manually as its initialization is
  5257. currently missing in the initTool */
  5258. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5259. REG_WR(bp, BAR_USTRORM_INTMEM +
  5260. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5261. if (!CHIP_IS_E1x(bp)) {
  5262. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5263. CHIP_INT_MODE_IS_BC(bp) ?
  5264. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5265. }
  5266. }
  5267. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5268. {
  5269. switch (load_code) {
  5270. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5271. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5272. bnx2x_init_internal_common(bp);
  5273. /* no break */
  5274. case FW_MSG_CODE_DRV_LOAD_PORT:
  5275. /* nothing to do */
  5276. /* no break */
  5277. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5278. /* internal memory per function is
  5279. initialized inside bnx2x_pf_init */
  5280. break;
  5281. default:
  5282. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5283. break;
  5284. }
  5285. }
  5286. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5287. {
  5288. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5289. }
  5290. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5291. {
  5292. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5293. }
  5294. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5295. {
  5296. if (CHIP_IS_E1x(fp->bp))
  5297. return BP_L_ID(fp->bp) + fp->index;
  5298. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5299. return bnx2x_fp_igu_sb_id(fp);
  5300. }
  5301. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5302. {
  5303. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5304. u8 cos;
  5305. unsigned long q_type = 0;
  5306. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5307. fp->rx_queue = fp_idx;
  5308. fp->cid = fp_idx;
  5309. fp->cl_id = bnx2x_fp_cl_id(fp);
  5310. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5311. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5312. /* qZone id equals to FW (per path) client id */
  5313. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5314. /* init shortcut */
  5315. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5316. /* Setup SB indices */
  5317. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5318. /* Configure Queue State object */
  5319. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5320. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5321. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5322. /* init tx data */
  5323. for_each_cos_in_tx_queue(fp, cos) {
  5324. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5325. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5326. FP_COS_TO_TXQ(fp, cos, bp),
  5327. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5328. cids[cos] = fp->txdata_ptr[cos]->cid;
  5329. }
  5330. /* nothing more for vf to do here */
  5331. if (IS_VF(bp))
  5332. return;
  5333. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5334. fp->fw_sb_id, fp->igu_sb_id);
  5335. bnx2x_update_fpsb_idx(fp);
  5336. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5337. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5338. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5339. /**
  5340. * Configure classification DBs: Always enable Tx switching
  5341. */
  5342. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5343. DP(NETIF_MSG_IFUP,
  5344. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5345. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5346. fp->igu_sb_id);
  5347. }
  5348. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5349. {
  5350. int i;
  5351. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5352. struct eth_tx_next_bd *tx_next_bd =
  5353. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5354. tx_next_bd->addr_hi =
  5355. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5356. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5357. tx_next_bd->addr_lo =
  5358. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5359. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5360. }
  5361. *txdata->tx_cons_sb = cpu_to_le16(0);
  5362. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5363. txdata->tx_db.data.zero_fill1 = 0;
  5364. txdata->tx_db.data.prod = 0;
  5365. txdata->tx_pkt_prod = 0;
  5366. txdata->tx_pkt_cons = 0;
  5367. txdata->tx_bd_prod = 0;
  5368. txdata->tx_bd_cons = 0;
  5369. txdata->tx_pkt = 0;
  5370. }
  5371. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5372. {
  5373. int i;
  5374. for_each_tx_queue_cnic(bp, i)
  5375. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5376. }
  5377. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5378. {
  5379. int i;
  5380. u8 cos;
  5381. for_each_eth_queue(bp, i)
  5382. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5383. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5384. }
  5385. static void bnx2x_init_fcoe_fp(struct bnx2x *bp)
  5386. {
  5387. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  5388. unsigned long q_type = 0;
  5389. bnx2x_fcoe(bp, rx_queue) = BNX2X_NUM_ETH_QUEUES(bp);
  5390. bnx2x_fcoe(bp, cl_id) = bnx2x_cnic_eth_cl_id(bp,
  5391. BNX2X_FCOE_ETH_CL_ID_IDX);
  5392. bnx2x_fcoe(bp, cid) = BNX2X_FCOE_ETH_CID(bp);
  5393. bnx2x_fcoe(bp, fw_sb_id) = DEF_SB_ID;
  5394. bnx2x_fcoe(bp, igu_sb_id) = bp->igu_dsb_id;
  5395. bnx2x_fcoe(bp, rx_cons_sb) = BNX2X_FCOE_L2_RX_INDEX;
  5396. bnx2x_init_txdata(bp, bnx2x_fcoe(bp, txdata_ptr[0]),
  5397. fp->cid, FCOE_TXQ_IDX(bp), BNX2X_FCOE_L2_TX_INDEX,
  5398. fp);
  5399. DP(NETIF_MSG_IFUP, "created fcoe tx data (fp index %d)\n", fp->index);
  5400. /* qZone id equals to FW (per path) client id */
  5401. bnx2x_fcoe(bp, cl_qzone_id) = bnx2x_fp_qzone_id(fp);
  5402. /* init shortcut */
  5403. bnx2x_fcoe(bp, ustorm_rx_prods_offset) =
  5404. bnx2x_rx_ustorm_prods_offset(fp);
  5405. /* Configure Queue State object */
  5406. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5407. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5408. /* No multi-CoS for FCoE L2 client */
  5409. BUG_ON(fp->max_cos != 1);
  5410. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id,
  5411. &fp->cid, 1, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5412. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5413. DP(NETIF_MSG_IFUP,
  5414. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5415. fp->index, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5416. fp->igu_sb_id);
  5417. }
  5418. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5419. {
  5420. if (!NO_FCOE(bp))
  5421. bnx2x_init_fcoe_fp(bp);
  5422. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5423. BNX2X_VF_ID_INVALID, false,
  5424. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5425. /* ensure status block indices were read */
  5426. rmb();
  5427. bnx2x_init_rx_rings_cnic(bp);
  5428. bnx2x_init_tx_rings_cnic(bp);
  5429. /* flush all */
  5430. mb();
  5431. mmiowb();
  5432. }
  5433. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5434. {
  5435. int i;
  5436. /* Setup NIC internals and enable interrupts */
  5437. for_each_eth_queue(bp, i)
  5438. bnx2x_init_eth_fp(bp, i);
  5439. /* ensure status block indices were read */
  5440. rmb();
  5441. bnx2x_init_rx_rings(bp);
  5442. bnx2x_init_tx_rings(bp);
  5443. if (IS_PF(bp)) {
  5444. /* Initialize MOD_ABS interrupts */
  5445. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5446. bp->common.shmem_base,
  5447. bp->common.shmem2_base, BP_PORT(bp));
  5448. /* initialize the default status block and sp ring */
  5449. bnx2x_init_def_sb(bp);
  5450. bnx2x_update_dsb_idx(bp);
  5451. bnx2x_init_sp_ring(bp);
  5452. } else {
  5453. bnx2x_memset_stats(bp);
  5454. }
  5455. }
  5456. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5457. {
  5458. bnx2x_init_eq_ring(bp);
  5459. bnx2x_init_internal(bp, load_code);
  5460. bnx2x_pf_init(bp);
  5461. bnx2x_stats_init(bp);
  5462. /* flush all before enabling interrupts */
  5463. mb();
  5464. mmiowb();
  5465. bnx2x_int_enable(bp);
  5466. /* Check for SPIO5 */
  5467. bnx2x_attn_int_deasserted0(bp,
  5468. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5469. AEU_INPUTS_ATTN_BITS_SPIO5);
  5470. }
  5471. /* gzip service functions */
  5472. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5473. {
  5474. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5475. &bp->gunzip_mapping, GFP_KERNEL);
  5476. if (bp->gunzip_buf == NULL)
  5477. goto gunzip_nomem1;
  5478. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5479. if (bp->strm == NULL)
  5480. goto gunzip_nomem2;
  5481. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5482. if (bp->strm->workspace == NULL)
  5483. goto gunzip_nomem3;
  5484. return 0;
  5485. gunzip_nomem3:
  5486. kfree(bp->strm);
  5487. bp->strm = NULL;
  5488. gunzip_nomem2:
  5489. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5490. bp->gunzip_mapping);
  5491. bp->gunzip_buf = NULL;
  5492. gunzip_nomem1:
  5493. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5494. return -ENOMEM;
  5495. }
  5496. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5497. {
  5498. if (bp->strm) {
  5499. vfree(bp->strm->workspace);
  5500. kfree(bp->strm);
  5501. bp->strm = NULL;
  5502. }
  5503. if (bp->gunzip_buf) {
  5504. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5505. bp->gunzip_mapping);
  5506. bp->gunzip_buf = NULL;
  5507. }
  5508. }
  5509. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5510. {
  5511. int n, rc;
  5512. /* check gzip header */
  5513. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5514. BNX2X_ERR("Bad gzip header\n");
  5515. return -EINVAL;
  5516. }
  5517. n = 10;
  5518. #define FNAME 0x8
  5519. if (zbuf[3] & FNAME)
  5520. while ((zbuf[n++] != 0) && (n < len));
  5521. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5522. bp->strm->avail_in = len - n;
  5523. bp->strm->next_out = bp->gunzip_buf;
  5524. bp->strm->avail_out = FW_BUF_SIZE;
  5525. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5526. if (rc != Z_OK)
  5527. return rc;
  5528. rc = zlib_inflate(bp->strm, Z_FINISH);
  5529. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5530. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5531. bp->strm->msg);
  5532. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5533. if (bp->gunzip_outlen & 0x3)
  5534. netdev_err(bp->dev,
  5535. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5536. bp->gunzip_outlen);
  5537. bp->gunzip_outlen >>= 2;
  5538. zlib_inflateEnd(bp->strm);
  5539. if (rc == Z_STREAM_END)
  5540. return 0;
  5541. return rc;
  5542. }
  5543. /* nic load/unload */
  5544. /*
  5545. * General service functions
  5546. */
  5547. /* send a NIG loopback debug packet */
  5548. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5549. {
  5550. u32 wb_write[3];
  5551. /* Ethernet source and destination addresses */
  5552. wb_write[0] = 0x55555555;
  5553. wb_write[1] = 0x55555555;
  5554. wb_write[2] = 0x20; /* SOP */
  5555. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5556. /* NON-IP protocol */
  5557. wb_write[0] = 0x09000000;
  5558. wb_write[1] = 0x55555555;
  5559. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5560. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5561. }
  5562. /* some of the internal memories
  5563. * are not directly readable from the driver
  5564. * to test them we send debug packets
  5565. */
  5566. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5567. {
  5568. int factor;
  5569. int count, i;
  5570. u32 val = 0;
  5571. if (CHIP_REV_IS_FPGA(bp))
  5572. factor = 120;
  5573. else if (CHIP_REV_IS_EMUL(bp))
  5574. factor = 200;
  5575. else
  5576. factor = 1;
  5577. /* Disable inputs of parser neighbor blocks */
  5578. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5579. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5580. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5581. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5582. /* Write 0 to parser credits for CFC search request */
  5583. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5584. /* send Ethernet packet */
  5585. bnx2x_lb_pckt(bp);
  5586. /* TODO do i reset NIG statistic? */
  5587. /* Wait until NIG register shows 1 packet of size 0x10 */
  5588. count = 1000 * factor;
  5589. while (count) {
  5590. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5591. val = *bnx2x_sp(bp, wb_data[0]);
  5592. if (val == 0x10)
  5593. break;
  5594. usleep_range(10000, 20000);
  5595. count--;
  5596. }
  5597. if (val != 0x10) {
  5598. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5599. return -1;
  5600. }
  5601. /* Wait until PRS register shows 1 packet */
  5602. count = 1000 * factor;
  5603. while (count) {
  5604. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5605. if (val == 1)
  5606. break;
  5607. usleep_range(10000, 20000);
  5608. count--;
  5609. }
  5610. if (val != 0x1) {
  5611. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5612. return -2;
  5613. }
  5614. /* Reset and init BRB, PRS */
  5615. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5616. msleep(50);
  5617. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5618. msleep(50);
  5619. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5620. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5621. DP(NETIF_MSG_HW, "part2\n");
  5622. /* Disable inputs of parser neighbor blocks */
  5623. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5624. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5625. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5626. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5627. /* Write 0 to parser credits for CFC search request */
  5628. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5629. /* send 10 Ethernet packets */
  5630. for (i = 0; i < 10; i++)
  5631. bnx2x_lb_pckt(bp);
  5632. /* Wait until NIG register shows 10 + 1
  5633. packets of size 11*0x10 = 0xb0 */
  5634. count = 1000 * factor;
  5635. while (count) {
  5636. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5637. val = *bnx2x_sp(bp, wb_data[0]);
  5638. if (val == 0xb0)
  5639. break;
  5640. usleep_range(10000, 20000);
  5641. count--;
  5642. }
  5643. if (val != 0xb0) {
  5644. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5645. return -3;
  5646. }
  5647. /* Wait until PRS register shows 2 packets */
  5648. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5649. if (val != 2)
  5650. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5651. /* Write 1 to parser credits for CFC search request */
  5652. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5653. /* Wait until PRS register shows 3 packets */
  5654. msleep(10 * factor);
  5655. /* Wait until NIG register shows 1 packet of size 0x10 */
  5656. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5657. if (val != 3)
  5658. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5659. /* clear NIG EOP FIFO */
  5660. for (i = 0; i < 11; i++)
  5661. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5662. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5663. if (val != 1) {
  5664. BNX2X_ERR("clear of NIG failed\n");
  5665. return -4;
  5666. }
  5667. /* Reset and init BRB, PRS, NIG */
  5668. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5669. msleep(50);
  5670. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5671. msleep(50);
  5672. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5673. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5674. if (!CNIC_SUPPORT(bp))
  5675. /* set NIC mode */
  5676. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5677. /* Enable inputs of parser neighbor blocks */
  5678. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5679. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5680. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5681. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5682. DP(NETIF_MSG_HW, "done\n");
  5683. return 0; /* OK */
  5684. }
  5685. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5686. {
  5687. u32 val;
  5688. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5689. if (!CHIP_IS_E1x(bp))
  5690. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5691. else
  5692. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5693. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5694. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5695. /*
  5696. * mask read length error interrupts in brb for parser
  5697. * (parsing unit and 'checksum and crc' unit)
  5698. * these errors are legal (PU reads fixed length and CAC can cause
  5699. * read length error on truncated packets)
  5700. */
  5701. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5702. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5703. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5704. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5705. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5706. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5707. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5708. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5709. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5710. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5711. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5712. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5713. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5714. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5715. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5716. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5717. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5718. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5719. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5720. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5721. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5722. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5723. if (!CHIP_IS_E1x(bp))
  5724. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5725. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5726. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5727. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5728. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5729. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5730. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5731. if (!CHIP_IS_E1x(bp))
  5732. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5733. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5734. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5735. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5736. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5737. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5738. }
  5739. static void bnx2x_reset_common(struct bnx2x *bp)
  5740. {
  5741. u32 val = 0x1400;
  5742. /* reset_common */
  5743. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5744. 0xd3ffff7f);
  5745. if (CHIP_IS_E3(bp)) {
  5746. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5747. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5748. }
  5749. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5750. }
  5751. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5752. {
  5753. bp->dmae_ready = 0;
  5754. spin_lock_init(&bp->dmae_lock);
  5755. }
  5756. static void bnx2x_init_pxp(struct bnx2x *bp)
  5757. {
  5758. u16 devctl;
  5759. int r_order, w_order;
  5760. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5761. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5762. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5763. if (bp->mrrs == -1)
  5764. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5765. else {
  5766. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5767. r_order = bp->mrrs;
  5768. }
  5769. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5770. }
  5771. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5772. {
  5773. int is_required;
  5774. u32 val;
  5775. int port;
  5776. if (BP_NOMCP(bp))
  5777. return;
  5778. is_required = 0;
  5779. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5780. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5781. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5782. is_required = 1;
  5783. /*
  5784. * The fan failure mechanism is usually related to the PHY type since
  5785. * the power consumption of the board is affected by the PHY. Currently,
  5786. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5787. */
  5788. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5789. for (port = PORT_0; port < PORT_MAX; port++) {
  5790. is_required |=
  5791. bnx2x_fan_failure_det_req(
  5792. bp,
  5793. bp->common.shmem_base,
  5794. bp->common.shmem2_base,
  5795. port);
  5796. }
  5797. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5798. if (is_required == 0)
  5799. return;
  5800. /* Fan failure is indicated by SPIO 5 */
  5801. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5802. /* set to active low mode */
  5803. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5804. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5805. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5806. /* enable interrupt to signal the IGU */
  5807. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5808. val |= MISC_SPIO_SPIO5;
  5809. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5810. }
  5811. void bnx2x_pf_disable(struct bnx2x *bp)
  5812. {
  5813. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5814. val &= ~IGU_PF_CONF_FUNC_EN;
  5815. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5816. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5817. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5818. }
  5819. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5820. {
  5821. u32 shmem_base[2], shmem2_base[2];
  5822. /* Avoid common init in case MFW supports LFA */
  5823. if (SHMEM2_RD(bp, size) >
  5824. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5825. return;
  5826. shmem_base[0] = bp->common.shmem_base;
  5827. shmem2_base[0] = bp->common.shmem2_base;
  5828. if (!CHIP_IS_E1x(bp)) {
  5829. shmem_base[1] =
  5830. SHMEM2_RD(bp, other_shmem_base_addr);
  5831. shmem2_base[1] =
  5832. SHMEM2_RD(bp, other_shmem2_base_addr);
  5833. }
  5834. bnx2x_acquire_phy_lock(bp);
  5835. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5836. bp->common.chip_id);
  5837. bnx2x_release_phy_lock(bp);
  5838. }
  5839. static void bnx2x_config_endianity(struct bnx2x *bp, u32 val)
  5840. {
  5841. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, val);
  5842. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, val);
  5843. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, val);
  5844. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, val);
  5845. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, val);
  5846. /* make sure this value is 0 */
  5847. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5848. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, val);
  5849. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, val);
  5850. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, val);
  5851. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, val);
  5852. }
  5853. static void bnx2x_set_endianity(struct bnx2x *bp)
  5854. {
  5855. #ifdef __BIG_ENDIAN
  5856. bnx2x_config_endianity(bp, 1);
  5857. #else
  5858. bnx2x_config_endianity(bp, 0);
  5859. #endif
  5860. }
  5861. static void bnx2x_reset_endianity(struct bnx2x *bp)
  5862. {
  5863. bnx2x_config_endianity(bp, 0);
  5864. }
  5865. /**
  5866. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5867. *
  5868. * @bp: driver handle
  5869. */
  5870. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5871. {
  5872. u32 val;
  5873. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5874. /*
  5875. * take the RESET lock to protect undi_unload flow from accessing
  5876. * registers while we're resetting the chip
  5877. */
  5878. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5879. bnx2x_reset_common(bp);
  5880. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5881. val = 0xfffc;
  5882. if (CHIP_IS_E3(bp)) {
  5883. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5884. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5885. }
  5886. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5887. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5888. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5889. if (!CHIP_IS_E1x(bp)) {
  5890. u8 abs_func_id;
  5891. /**
  5892. * 4-port mode or 2-port mode we need to turn of master-enable
  5893. * for everyone, after that, turn it back on for self.
  5894. * so, we disregard multi-function or not, and always disable
  5895. * for all functions on the given path, this means 0,2,4,6 for
  5896. * path 0 and 1,3,5,7 for path 1
  5897. */
  5898. for (abs_func_id = BP_PATH(bp);
  5899. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5900. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5901. REG_WR(bp,
  5902. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5903. 1);
  5904. continue;
  5905. }
  5906. bnx2x_pretend_func(bp, abs_func_id);
  5907. /* clear pf enable */
  5908. bnx2x_pf_disable(bp);
  5909. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5910. }
  5911. }
  5912. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5913. if (CHIP_IS_E1(bp)) {
  5914. /* enable HW interrupt from PXP on USDM overflow
  5915. bit 16 on INT_MASK_0 */
  5916. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5917. }
  5918. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5919. bnx2x_init_pxp(bp);
  5920. bnx2x_set_endianity(bp);
  5921. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5922. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5923. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5924. /* let the HW do it's magic ... */
  5925. msleep(100);
  5926. /* finish PXP init */
  5927. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5928. if (val != 1) {
  5929. BNX2X_ERR("PXP2 CFG failed\n");
  5930. return -EBUSY;
  5931. }
  5932. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5933. if (val != 1) {
  5934. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5935. return -EBUSY;
  5936. }
  5937. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5938. * have entries with value "0" and valid bit on.
  5939. * This needs to be done by the first PF that is loaded in a path
  5940. * (i.e. common phase)
  5941. */
  5942. if (!CHIP_IS_E1x(bp)) {
  5943. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5944. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5945. * This occurs when a different function (func2,3) is being marked
  5946. * as "scan-off". Real-life scenario for example: if a driver is being
  5947. * load-unloaded while func6,7 are down. This will cause the timer to access
  5948. * the ilt, translate to a logical address and send a request to read/write.
  5949. * Since the ilt for the function that is down is not valid, this will cause
  5950. * a translation error which is unrecoverable.
  5951. * The Workaround is intended to make sure that when this happens nothing fatal
  5952. * will occur. The workaround:
  5953. * 1. First PF driver which loads on a path will:
  5954. * a. After taking the chip out of reset, by using pretend,
  5955. * it will write "0" to the following registers of
  5956. * the other vnics.
  5957. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5958. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5959. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5960. * And for itself it will write '1' to
  5961. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5962. * dmae-operations (writing to pram for example.)
  5963. * note: can be done for only function 6,7 but cleaner this
  5964. * way.
  5965. * b. Write zero+valid to the entire ILT.
  5966. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5967. * VNIC3 (of that port). The range allocated will be the
  5968. * entire ILT. This is needed to prevent ILT range error.
  5969. * 2. Any PF driver load flow:
  5970. * a. ILT update with the physical addresses of the allocated
  5971. * logical pages.
  5972. * b. Wait 20msec. - note that this timeout is needed to make
  5973. * sure there are no requests in one of the PXP internal
  5974. * queues with "old" ILT addresses.
  5975. * c. PF enable in the PGLC.
  5976. * d. Clear the was_error of the PF in the PGLC. (could have
  5977. * occurred while driver was down)
  5978. * e. PF enable in the CFC (WEAK + STRONG)
  5979. * f. Timers scan enable
  5980. * 3. PF driver unload flow:
  5981. * a. Clear the Timers scan_en.
  5982. * b. Polling for scan_on=0 for that PF.
  5983. * c. Clear the PF enable bit in the PXP.
  5984. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5985. * e. Write zero+valid to all ILT entries (The valid bit must
  5986. * stay set)
  5987. * f. If this is VNIC 3 of a port then also init
  5988. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5989. * to the last entry in the ILT.
  5990. *
  5991. * Notes:
  5992. * Currently the PF error in the PGLC is non recoverable.
  5993. * In the future the there will be a recovery routine for this error.
  5994. * Currently attention is masked.
  5995. * Having an MCP lock on the load/unload process does not guarantee that
  5996. * there is no Timer disable during Func6/7 enable. This is because the
  5997. * Timers scan is currently being cleared by the MCP on FLR.
  5998. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5999. * there is error before clearing it. But the flow above is simpler and
  6000. * more general.
  6001. * All ILT entries are written by zero+valid and not just PF6/7
  6002. * ILT entries since in the future the ILT entries allocation for
  6003. * PF-s might be dynamic.
  6004. */
  6005. struct ilt_client_info ilt_cli;
  6006. struct bnx2x_ilt ilt;
  6007. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6008. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  6009. /* initialize dummy TM client */
  6010. ilt_cli.start = 0;
  6011. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6012. ilt_cli.client_num = ILT_CLIENT_TM;
  6013. /* Step 1: set zeroes to all ilt page entries with valid bit on
  6014. * Step 2: set the timers first/last ilt entry to point
  6015. * to the entire range to prevent ILT range error for 3rd/4th
  6016. * vnic (this code assumes existence of the vnic)
  6017. *
  6018. * both steps performed by call to bnx2x_ilt_client_init_op()
  6019. * with dummy TM client
  6020. *
  6021. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  6022. * and his brother are split registers
  6023. */
  6024. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  6025. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  6026. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  6027. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  6028. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  6029. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  6030. }
  6031. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  6032. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  6033. if (!CHIP_IS_E1x(bp)) {
  6034. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  6035. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  6036. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  6037. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  6038. /* let the HW do it's magic ... */
  6039. do {
  6040. msleep(200);
  6041. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  6042. } while (factor-- && (val != 1));
  6043. if (val != 1) {
  6044. BNX2X_ERR("ATC_INIT failed\n");
  6045. return -EBUSY;
  6046. }
  6047. }
  6048. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  6049. bnx2x_iov_init_dmae(bp);
  6050. /* clean the DMAE memory */
  6051. bp->dmae_ready = 1;
  6052. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  6053. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  6054. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  6055. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  6056. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  6057. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  6058. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  6059. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  6060. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  6061. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  6062. /* QM queues pointers table */
  6063. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  6064. /* soft reset pulse */
  6065. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  6066. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  6067. if (CNIC_SUPPORT(bp))
  6068. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  6069. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  6070. if (!CHIP_REV_IS_SLOW(bp))
  6071. /* enable hw interrupt from doorbell Q */
  6072. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  6073. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  6074. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  6075. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  6076. if (!CHIP_IS_E1(bp))
  6077. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  6078. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  6079. if (IS_MF_AFEX(bp)) {
  6080. /* configure that VNTag and VLAN headers must be
  6081. * received in afex mode
  6082. */
  6083. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  6084. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  6085. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  6086. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  6087. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  6088. } else {
  6089. /* Bit-map indicating which L2 hdrs may appear
  6090. * after the basic Ethernet header
  6091. */
  6092. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  6093. bp->path_has_ovlan ? 7 : 6);
  6094. }
  6095. }
  6096. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  6097. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  6098. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  6099. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  6100. if (!CHIP_IS_E1x(bp)) {
  6101. /* reset VFC memories */
  6102. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6103. VFC_MEMORIES_RST_REG_CAM_RST |
  6104. VFC_MEMORIES_RST_REG_RAM_RST);
  6105. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  6106. VFC_MEMORIES_RST_REG_CAM_RST |
  6107. VFC_MEMORIES_RST_REG_RAM_RST);
  6108. msleep(20);
  6109. }
  6110. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  6111. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  6112. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  6113. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  6114. /* sync semi rtc */
  6115. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6116. 0x80000000);
  6117. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6118. 0x80000000);
  6119. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  6120. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  6121. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  6122. if (!CHIP_IS_E1x(bp)) {
  6123. if (IS_MF_AFEX(bp)) {
  6124. /* configure that VNTag and VLAN headers must be
  6125. * sent in afex mode
  6126. */
  6127. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  6128. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  6129. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  6130. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  6131. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  6132. } else {
  6133. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  6134. bp->path_has_ovlan ? 7 : 6);
  6135. }
  6136. }
  6137. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  6138. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  6139. if (CNIC_SUPPORT(bp)) {
  6140. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  6141. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  6142. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  6143. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  6144. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  6145. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  6146. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  6147. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  6148. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  6149. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  6150. }
  6151. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  6152. if (sizeof(union cdu_context) != 1024)
  6153. /* we currently assume that a context is 1024 bytes */
  6154. dev_alert(&bp->pdev->dev,
  6155. "please adjust the size of cdu_context(%ld)\n",
  6156. (long)sizeof(union cdu_context));
  6157. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  6158. val = (4 << 24) + (0 << 12) + 1024;
  6159. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  6160. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  6161. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  6162. /* enable context validation interrupt from CFC */
  6163. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  6164. /* set the thresholds to prevent CFC/CDU race */
  6165. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  6166. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  6167. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  6168. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  6169. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  6170. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  6171. /* Reset PCIE errors for debug */
  6172. REG_WR(bp, 0x2814, 0xffffffff);
  6173. REG_WR(bp, 0x3820, 0xffffffff);
  6174. if (!CHIP_IS_E1x(bp)) {
  6175. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  6176. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  6177. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  6178. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  6179. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  6180. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  6181. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  6182. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  6183. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  6184. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  6185. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  6186. }
  6187. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  6188. if (!CHIP_IS_E1(bp)) {
  6189. /* in E3 this done in per-port section */
  6190. if (!CHIP_IS_E3(bp))
  6191. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6192. }
  6193. if (CHIP_IS_E1H(bp))
  6194. /* not applicable for E2 (and above ...) */
  6195. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  6196. if (CHIP_REV_IS_SLOW(bp))
  6197. msleep(200);
  6198. /* finish CFC init */
  6199. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  6200. if (val != 1) {
  6201. BNX2X_ERR("CFC LL_INIT failed\n");
  6202. return -EBUSY;
  6203. }
  6204. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  6205. if (val != 1) {
  6206. BNX2X_ERR("CFC AC_INIT failed\n");
  6207. return -EBUSY;
  6208. }
  6209. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  6210. if (val != 1) {
  6211. BNX2X_ERR("CFC CAM_INIT failed\n");
  6212. return -EBUSY;
  6213. }
  6214. REG_WR(bp, CFC_REG_DEBUG0, 0);
  6215. if (CHIP_IS_E1(bp)) {
  6216. /* read NIG statistic
  6217. to see if this is our first up since powerup */
  6218. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  6219. val = *bnx2x_sp(bp, wb_data[0]);
  6220. /* do internal memory self test */
  6221. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  6222. BNX2X_ERR("internal mem self test failed\n");
  6223. return -EBUSY;
  6224. }
  6225. }
  6226. bnx2x_setup_fan_failure_detection(bp);
  6227. /* clear PXP2 attentions */
  6228. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  6229. bnx2x_enable_blocks_attention(bp);
  6230. bnx2x_enable_blocks_parity(bp);
  6231. if (!BP_NOMCP(bp)) {
  6232. if (CHIP_IS_E1x(bp))
  6233. bnx2x__common_init_phy(bp);
  6234. } else
  6235. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6236. return 0;
  6237. }
  6238. /**
  6239. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6240. *
  6241. * @bp: driver handle
  6242. */
  6243. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6244. {
  6245. int rc = bnx2x_init_hw_common(bp);
  6246. if (rc)
  6247. return rc;
  6248. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6249. if (!BP_NOMCP(bp))
  6250. bnx2x__common_init_phy(bp);
  6251. return 0;
  6252. }
  6253. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6254. {
  6255. int port = BP_PORT(bp);
  6256. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6257. u32 low, high;
  6258. u32 val, reg;
  6259. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6260. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6261. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6262. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6263. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6264. /* Timers bug workaround: disables the pf_master bit in pglue at
  6265. * common phase, we need to enable it here before any dmae access are
  6266. * attempted. Therefore we manually added the enable-master to the
  6267. * port phase (it also happens in the function phase)
  6268. */
  6269. if (!CHIP_IS_E1x(bp))
  6270. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6271. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6272. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6273. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6274. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6275. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6276. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6277. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6278. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6279. /* QM cid (connection) count */
  6280. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6281. if (CNIC_SUPPORT(bp)) {
  6282. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6283. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6284. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6285. }
  6286. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6287. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6288. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6289. if (IS_MF(bp))
  6290. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6291. else if (bp->dev->mtu > 4096) {
  6292. if (bp->flags & ONE_PORT_FLAG)
  6293. low = 160;
  6294. else {
  6295. val = bp->dev->mtu;
  6296. /* (24*1024 + val*4)/256 */
  6297. low = 96 + (val/64) +
  6298. ((val % 64) ? 1 : 0);
  6299. }
  6300. } else
  6301. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6302. high = low + 56; /* 14*1024/256 */
  6303. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6304. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6305. }
  6306. if (CHIP_MODE_IS_4_PORT(bp))
  6307. REG_WR(bp, (BP_PORT(bp) ?
  6308. BRB1_REG_MAC_GUARANTIED_1 :
  6309. BRB1_REG_MAC_GUARANTIED_0), 40);
  6310. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6311. if (CHIP_IS_E3B0(bp)) {
  6312. if (IS_MF_AFEX(bp)) {
  6313. /* configure headers for AFEX mode */
  6314. REG_WR(bp, BP_PORT(bp) ?
  6315. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6316. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6317. REG_WR(bp, BP_PORT(bp) ?
  6318. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6319. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6320. REG_WR(bp, BP_PORT(bp) ?
  6321. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6322. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6323. } else {
  6324. /* Ovlan exists only if we are in multi-function +
  6325. * switch-dependent mode, in switch-independent there
  6326. * is no ovlan headers
  6327. */
  6328. REG_WR(bp, BP_PORT(bp) ?
  6329. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6330. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6331. (bp->path_has_ovlan ? 7 : 6));
  6332. }
  6333. }
  6334. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6335. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6336. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6337. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6338. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6339. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6340. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6341. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6342. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6343. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6344. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6345. if (CHIP_IS_E1x(bp)) {
  6346. /* configure PBF to work without PAUSE mtu 9000 */
  6347. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6348. /* update threshold */
  6349. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6350. /* update init credit */
  6351. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6352. /* probe changes */
  6353. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6354. udelay(50);
  6355. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6356. }
  6357. if (CNIC_SUPPORT(bp))
  6358. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6359. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6360. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6361. if (CHIP_IS_E1(bp)) {
  6362. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6363. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6364. }
  6365. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6366. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6367. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6368. /* init aeu_mask_attn_func_0/1:
  6369. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6370. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6371. * bits 4-7 are used for "per vn group attention" */
  6372. val = IS_MF(bp) ? 0xF7 : 0x7;
  6373. /* Enable DCBX attention for all but E1 */
  6374. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6375. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6376. /* SCPAD_PARITY should NOT trigger close the gates */
  6377. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6378. REG_WR(bp, reg,
  6379. REG_RD(bp, reg) &
  6380. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6381. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6382. REG_WR(bp, reg,
  6383. REG_RD(bp, reg) &
  6384. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6385. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6386. if (!CHIP_IS_E1x(bp)) {
  6387. /* Bit-map indicating which L2 hdrs may appear after the
  6388. * basic Ethernet header
  6389. */
  6390. if (IS_MF_AFEX(bp))
  6391. REG_WR(bp, BP_PORT(bp) ?
  6392. NIG_REG_P1_HDRS_AFTER_BASIC :
  6393. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6394. else
  6395. REG_WR(bp, BP_PORT(bp) ?
  6396. NIG_REG_P1_HDRS_AFTER_BASIC :
  6397. NIG_REG_P0_HDRS_AFTER_BASIC,
  6398. IS_MF_SD(bp) ? 7 : 6);
  6399. if (CHIP_IS_E3(bp))
  6400. REG_WR(bp, BP_PORT(bp) ?
  6401. NIG_REG_LLH1_MF_MODE :
  6402. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6403. }
  6404. if (!CHIP_IS_E3(bp))
  6405. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6406. if (!CHIP_IS_E1(bp)) {
  6407. /* 0x2 disable mf_ov, 0x1 enable */
  6408. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6409. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6410. if (!CHIP_IS_E1x(bp)) {
  6411. val = 0;
  6412. switch (bp->mf_mode) {
  6413. case MULTI_FUNCTION_SD:
  6414. val = 1;
  6415. break;
  6416. case MULTI_FUNCTION_SI:
  6417. case MULTI_FUNCTION_AFEX:
  6418. val = 2;
  6419. break;
  6420. }
  6421. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6422. NIG_REG_LLH0_CLS_TYPE), val);
  6423. }
  6424. {
  6425. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6426. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6427. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6428. }
  6429. }
  6430. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6431. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6432. if (val & MISC_SPIO_SPIO5) {
  6433. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6434. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6435. val = REG_RD(bp, reg_addr);
  6436. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6437. REG_WR(bp, reg_addr, val);
  6438. }
  6439. return 0;
  6440. }
  6441. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6442. {
  6443. int reg;
  6444. u32 wb_write[2];
  6445. if (CHIP_IS_E1(bp))
  6446. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6447. else
  6448. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6449. wb_write[0] = ONCHIP_ADDR1(addr);
  6450. wb_write[1] = ONCHIP_ADDR2(addr);
  6451. REG_WR_DMAE(bp, reg, wb_write, 2);
  6452. }
  6453. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6454. {
  6455. u32 data, ctl, cnt = 100;
  6456. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6457. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6458. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6459. u32 sb_bit = 1 << (idu_sb_id%32);
  6460. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6461. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6462. /* Not supported in BC mode */
  6463. if (CHIP_INT_MODE_IS_BC(bp))
  6464. return;
  6465. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6466. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6467. IGU_REGULAR_CLEANUP_SET |
  6468. IGU_REGULAR_BCLEANUP;
  6469. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6470. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6471. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6472. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6473. data, igu_addr_data);
  6474. REG_WR(bp, igu_addr_data, data);
  6475. mmiowb();
  6476. barrier();
  6477. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6478. ctl, igu_addr_ctl);
  6479. REG_WR(bp, igu_addr_ctl, ctl);
  6480. mmiowb();
  6481. barrier();
  6482. /* wait for clean up to finish */
  6483. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6484. msleep(20);
  6485. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6486. DP(NETIF_MSG_HW,
  6487. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6488. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6489. }
  6490. }
  6491. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6492. {
  6493. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6494. }
  6495. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6496. {
  6497. u32 i, base = FUNC_ILT_BASE(func);
  6498. for (i = base; i < base + ILT_PER_FUNC; i++)
  6499. bnx2x_ilt_wr(bp, i, 0);
  6500. }
  6501. static void bnx2x_init_searcher(struct bnx2x *bp)
  6502. {
  6503. int port = BP_PORT(bp);
  6504. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6505. /* T1 hash bits value determines the T1 number of entries */
  6506. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6507. }
  6508. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6509. {
  6510. int rc;
  6511. struct bnx2x_func_state_params func_params = {NULL};
  6512. struct bnx2x_func_switch_update_params *switch_update_params =
  6513. &func_params.params.switch_update;
  6514. /* Prepare parameters for function state transitions */
  6515. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6516. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6517. func_params.f_obj = &bp->func_obj;
  6518. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6519. /* Function parameters */
  6520. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
  6521. &switch_update_params->changes);
  6522. if (suspend)
  6523. __set_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
  6524. &switch_update_params->changes);
  6525. rc = bnx2x_func_state_change(bp, &func_params);
  6526. return rc;
  6527. }
  6528. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6529. {
  6530. int rc, i, port = BP_PORT(bp);
  6531. int vlan_en = 0, mac_en[NUM_MACS];
  6532. /* Close input from network */
  6533. if (bp->mf_mode == SINGLE_FUNCTION) {
  6534. bnx2x_set_rx_filter(&bp->link_params, 0);
  6535. } else {
  6536. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6537. NIG_REG_LLH0_FUNC_EN);
  6538. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6539. NIG_REG_LLH0_FUNC_EN, 0);
  6540. for (i = 0; i < NUM_MACS; i++) {
  6541. mac_en[i] = REG_RD(bp, port ?
  6542. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6543. 4 * i) :
  6544. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6545. 4 * i));
  6546. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6547. 4 * i) :
  6548. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6549. }
  6550. }
  6551. /* Close BMC to host */
  6552. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6553. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6554. /* Suspend Tx switching to the PF. Completion of this ramrod
  6555. * further guarantees that all the packets of that PF / child
  6556. * VFs in BRB were processed by the Parser, so it is safe to
  6557. * change the NIC_MODE register.
  6558. */
  6559. rc = bnx2x_func_switch_update(bp, 1);
  6560. if (rc) {
  6561. BNX2X_ERR("Can't suspend tx-switching!\n");
  6562. return rc;
  6563. }
  6564. /* Change NIC_MODE register */
  6565. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6566. /* Open input from network */
  6567. if (bp->mf_mode == SINGLE_FUNCTION) {
  6568. bnx2x_set_rx_filter(&bp->link_params, 1);
  6569. } else {
  6570. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6571. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6572. for (i = 0; i < NUM_MACS; i++) {
  6573. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6574. 4 * i) :
  6575. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6576. mac_en[i]);
  6577. }
  6578. }
  6579. /* Enable BMC to host */
  6580. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6581. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6582. /* Resume Tx switching to the PF */
  6583. rc = bnx2x_func_switch_update(bp, 0);
  6584. if (rc) {
  6585. BNX2X_ERR("Can't resume tx-switching!\n");
  6586. return rc;
  6587. }
  6588. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6589. return 0;
  6590. }
  6591. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6592. {
  6593. int rc;
  6594. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6595. if (CONFIGURE_NIC_MODE(bp)) {
  6596. /* Configure searcher as part of function hw init */
  6597. bnx2x_init_searcher(bp);
  6598. /* Reset NIC mode */
  6599. rc = bnx2x_reset_nic_mode(bp);
  6600. if (rc)
  6601. BNX2X_ERR("Can't change NIC mode!\n");
  6602. return rc;
  6603. }
  6604. return 0;
  6605. }
  6606. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6607. {
  6608. int port = BP_PORT(bp);
  6609. int func = BP_FUNC(bp);
  6610. int init_phase = PHASE_PF0 + func;
  6611. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6612. u16 cdu_ilt_start;
  6613. u32 addr, val;
  6614. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6615. int i, main_mem_width, rc;
  6616. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6617. /* FLR cleanup - hmmm */
  6618. if (!CHIP_IS_E1x(bp)) {
  6619. rc = bnx2x_pf_flr_clnup(bp);
  6620. if (rc) {
  6621. bnx2x_fw_dump(bp);
  6622. return rc;
  6623. }
  6624. }
  6625. /* set MSI reconfigure capability */
  6626. if (bp->common.int_block == INT_BLOCK_HC) {
  6627. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6628. val = REG_RD(bp, addr);
  6629. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6630. REG_WR(bp, addr, val);
  6631. }
  6632. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6633. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6634. ilt = BP_ILT(bp);
  6635. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6636. if (IS_SRIOV(bp))
  6637. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6638. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6639. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6640. * those of the VFs, so start line should be reset
  6641. */
  6642. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6643. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6644. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6645. ilt->lines[cdu_ilt_start + i].page_mapping =
  6646. bp->context[i].cxt_mapping;
  6647. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6648. }
  6649. bnx2x_ilt_init_op(bp, INITOP_SET);
  6650. if (!CONFIGURE_NIC_MODE(bp)) {
  6651. bnx2x_init_searcher(bp);
  6652. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6653. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6654. } else {
  6655. /* Set NIC mode */
  6656. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6657. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6658. }
  6659. if (!CHIP_IS_E1x(bp)) {
  6660. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6661. /* Turn on a single ISR mode in IGU if driver is going to use
  6662. * INT#x or MSI
  6663. */
  6664. if (!(bp->flags & USING_MSIX_FLAG))
  6665. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6666. /*
  6667. * Timers workaround bug: function init part.
  6668. * Need to wait 20msec after initializing ILT,
  6669. * needed to make sure there are no requests in
  6670. * one of the PXP internal queues with "old" ILT addresses
  6671. */
  6672. msleep(20);
  6673. /*
  6674. * Master enable - Due to WB DMAE writes performed before this
  6675. * register is re-initialized as part of the regular function
  6676. * init
  6677. */
  6678. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6679. /* Enable the function in IGU */
  6680. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6681. }
  6682. bp->dmae_ready = 1;
  6683. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6684. if (!CHIP_IS_E1x(bp))
  6685. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6686. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6687. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6688. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6689. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6690. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6691. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6692. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6693. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6694. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6695. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6696. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6697. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6698. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6699. if (!CHIP_IS_E1x(bp))
  6700. REG_WR(bp, QM_REG_PF_EN, 1);
  6701. if (!CHIP_IS_E1x(bp)) {
  6702. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6703. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6704. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6705. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6706. }
  6707. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6708. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6709. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6710. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6711. bnx2x_iov_init_dq(bp);
  6712. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6713. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6714. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6715. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6716. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6717. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6718. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6719. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6720. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6721. if (!CHIP_IS_E1x(bp))
  6722. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6723. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6724. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6725. if (!CHIP_IS_E1x(bp))
  6726. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6727. if (IS_MF(bp)) {
  6728. if (!(IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp))) {
  6729. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port * 8, 1);
  6730. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port * 8,
  6731. bp->mf_ov);
  6732. }
  6733. }
  6734. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6735. /* HC init per function */
  6736. if (bp->common.int_block == INT_BLOCK_HC) {
  6737. if (CHIP_IS_E1H(bp)) {
  6738. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6739. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6740. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6741. }
  6742. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6743. } else {
  6744. int num_segs, sb_idx, prod_offset;
  6745. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6746. if (!CHIP_IS_E1x(bp)) {
  6747. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6748. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6749. }
  6750. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6751. if (!CHIP_IS_E1x(bp)) {
  6752. int dsb_idx = 0;
  6753. /**
  6754. * Producer memory:
  6755. * E2 mode: address 0-135 match to the mapping memory;
  6756. * 136 - PF0 default prod; 137 - PF1 default prod;
  6757. * 138 - PF2 default prod; 139 - PF3 default prod;
  6758. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6759. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6760. * 144-147 reserved.
  6761. *
  6762. * E1.5 mode - In backward compatible mode;
  6763. * for non default SB; each even line in the memory
  6764. * holds the U producer and each odd line hold
  6765. * the C producer. The first 128 producers are for
  6766. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6767. * producers are for the DSB for each PF.
  6768. * Each PF has five segments: (the order inside each
  6769. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6770. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6771. * 144-147 attn prods;
  6772. */
  6773. /* non-default-status-blocks */
  6774. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6775. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6776. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6777. prod_offset = (bp->igu_base_sb + sb_idx) *
  6778. num_segs;
  6779. for (i = 0; i < num_segs; i++) {
  6780. addr = IGU_REG_PROD_CONS_MEMORY +
  6781. (prod_offset + i) * 4;
  6782. REG_WR(bp, addr, 0);
  6783. }
  6784. /* send consumer update with value 0 */
  6785. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6786. USTORM_ID, 0, IGU_INT_NOP, 1);
  6787. bnx2x_igu_clear_sb(bp,
  6788. bp->igu_base_sb + sb_idx);
  6789. }
  6790. /* default-status-blocks */
  6791. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6792. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6793. if (CHIP_MODE_IS_4_PORT(bp))
  6794. dsb_idx = BP_FUNC(bp);
  6795. else
  6796. dsb_idx = BP_VN(bp);
  6797. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6798. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6799. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6800. /*
  6801. * igu prods come in chunks of E1HVN_MAX (4) -
  6802. * does not matters what is the current chip mode
  6803. */
  6804. for (i = 0; i < (num_segs * E1HVN_MAX);
  6805. i += E1HVN_MAX) {
  6806. addr = IGU_REG_PROD_CONS_MEMORY +
  6807. (prod_offset + i)*4;
  6808. REG_WR(bp, addr, 0);
  6809. }
  6810. /* send consumer update with 0 */
  6811. if (CHIP_INT_MODE_IS_BC(bp)) {
  6812. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6813. USTORM_ID, 0, IGU_INT_NOP, 1);
  6814. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6815. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6816. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6817. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6818. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6819. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6820. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6821. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6822. } else {
  6823. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6824. USTORM_ID, 0, IGU_INT_NOP, 1);
  6825. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6826. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6827. }
  6828. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6829. /* !!! These should become driver const once
  6830. rf-tool supports split-68 const */
  6831. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6832. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6833. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6834. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6835. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6836. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6837. }
  6838. }
  6839. /* Reset PCIE errors for debug */
  6840. REG_WR(bp, 0x2114, 0xffffffff);
  6841. REG_WR(bp, 0x2120, 0xffffffff);
  6842. if (CHIP_IS_E1x(bp)) {
  6843. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6844. main_mem_base = HC_REG_MAIN_MEMORY +
  6845. BP_PORT(bp) * (main_mem_size * 4);
  6846. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6847. main_mem_width = 8;
  6848. val = REG_RD(bp, main_mem_prty_clr);
  6849. if (val)
  6850. DP(NETIF_MSG_HW,
  6851. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6852. val);
  6853. /* Clear "false" parity errors in MSI-X table */
  6854. for (i = main_mem_base;
  6855. i < main_mem_base + main_mem_size * 4;
  6856. i += main_mem_width) {
  6857. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6858. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6859. i, main_mem_width / 4);
  6860. }
  6861. /* Clear HC parity attention */
  6862. REG_RD(bp, main_mem_prty_clr);
  6863. }
  6864. #ifdef BNX2X_STOP_ON_ERROR
  6865. /* Enable STORMs SP logging */
  6866. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6867. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6868. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6869. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6870. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6871. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6872. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6873. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6874. #endif
  6875. bnx2x_phy_probe(&bp->link_params);
  6876. return 0;
  6877. }
  6878. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6879. {
  6880. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6881. if (!CHIP_IS_E1x(bp))
  6882. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6883. sizeof(struct host_hc_status_block_e2));
  6884. else
  6885. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6886. sizeof(struct host_hc_status_block_e1x));
  6887. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6888. }
  6889. void bnx2x_free_mem(struct bnx2x *bp)
  6890. {
  6891. int i;
  6892. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6893. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6894. if (IS_VF(bp))
  6895. return;
  6896. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6897. sizeof(struct host_sp_status_block));
  6898. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6899. sizeof(struct bnx2x_slowpath));
  6900. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6901. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6902. bp->context[i].size);
  6903. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6904. BNX2X_FREE(bp->ilt->lines);
  6905. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6906. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6907. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6908. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6909. bnx2x_iov_free_mem(bp);
  6910. }
  6911. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6912. {
  6913. if (!CHIP_IS_E1x(bp)) {
  6914. /* size = the status block + ramrod buffers */
  6915. bp->cnic_sb.e2_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6916. sizeof(struct host_hc_status_block_e2));
  6917. if (!bp->cnic_sb.e2_sb)
  6918. goto alloc_mem_err;
  6919. } else {
  6920. bp->cnic_sb.e1x_sb = BNX2X_PCI_ALLOC(&bp->cnic_sb_mapping,
  6921. sizeof(struct host_hc_status_block_e1x));
  6922. if (!bp->cnic_sb.e1x_sb)
  6923. goto alloc_mem_err;
  6924. }
  6925. if (CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6926. /* allocate searcher T2 table, as it wasn't allocated before */
  6927. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6928. if (!bp->t2)
  6929. goto alloc_mem_err;
  6930. }
  6931. /* write address to which L5 should insert its values */
  6932. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6933. &bp->slowpath->drv_info_to_mcp;
  6934. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6935. goto alloc_mem_err;
  6936. return 0;
  6937. alloc_mem_err:
  6938. bnx2x_free_mem_cnic(bp);
  6939. BNX2X_ERR("Can't allocate memory\n");
  6940. return -ENOMEM;
  6941. }
  6942. int bnx2x_alloc_mem(struct bnx2x *bp)
  6943. {
  6944. int i, allocated, context_size;
  6945. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2) {
  6946. /* allocate searcher T2 table */
  6947. bp->t2 = BNX2X_PCI_ALLOC(&bp->t2_mapping, SRC_T2_SZ);
  6948. if (!bp->t2)
  6949. goto alloc_mem_err;
  6950. }
  6951. bp->def_status_blk = BNX2X_PCI_ALLOC(&bp->def_status_blk_mapping,
  6952. sizeof(struct host_sp_status_block));
  6953. if (!bp->def_status_blk)
  6954. goto alloc_mem_err;
  6955. bp->slowpath = BNX2X_PCI_ALLOC(&bp->slowpath_mapping,
  6956. sizeof(struct bnx2x_slowpath));
  6957. if (!bp->slowpath)
  6958. goto alloc_mem_err;
  6959. /* Allocate memory for CDU context:
  6960. * This memory is allocated separately and not in the generic ILT
  6961. * functions because CDU differs in few aspects:
  6962. * 1. There are multiple entities allocating memory for context -
  6963. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6964. * its own ILT lines.
  6965. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6966. * for the other ILT clients), to be efficient we want to support
  6967. * allocation of sub-page-size in the last entry.
  6968. * 3. Context pointers are used by the driver to pass to FW / update
  6969. * the context (for the other ILT clients the pointers are used just to
  6970. * free the memory during unload).
  6971. */
  6972. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6973. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6974. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6975. (context_size - allocated));
  6976. bp->context[i].vcxt = BNX2X_PCI_ALLOC(&bp->context[i].cxt_mapping,
  6977. bp->context[i].size);
  6978. if (!bp->context[i].vcxt)
  6979. goto alloc_mem_err;
  6980. allocated += bp->context[i].size;
  6981. }
  6982. bp->ilt->lines = kcalloc(ILT_MAX_LINES, sizeof(struct ilt_line),
  6983. GFP_KERNEL);
  6984. if (!bp->ilt->lines)
  6985. goto alloc_mem_err;
  6986. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6987. goto alloc_mem_err;
  6988. if (bnx2x_iov_alloc_mem(bp))
  6989. goto alloc_mem_err;
  6990. /* Slow path ring */
  6991. bp->spq = BNX2X_PCI_ALLOC(&bp->spq_mapping, BCM_PAGE_SIZE);
  6992. if (!bp->spq)
  6993. goto alloc_mem_err;
  6994. /* EQ */
  6995. bp->eq_ring = BNX2X_PCI_ALLOC(&bp->eq_mapping,
  6996. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6997. if (!bp->eq_ring)
  6998. goto alloc_mem_err;
  6999. return 0;
  7000. alloc_mem_err:
  7001. bnx2x_free_mem(bp);
  7002. BNX2X_ERR("Can't allocate memory\n");
  7003. return -ENOMEM;
  7004. }
  7005. /*
  7006. * Init service functions
  7007. */
  7008. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  7009. struct bnx2x_vlan_mac_obj *obj, bool set,
  7010. int mac_type, unsigned long *ramrod_flags)
  7011. {
  7012. int rc;
  7013. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  7014. memset(&ramrod_param, 0, sizeof(ramrod_param));
  7015. /* Fill general parameters */
  7016. ramrod_param.vlan_mac_obj = obj;
  7017. ramrod_param.ramrod_flags = *ramrod_flags;
  7018. /* Fill a user request section if needed */
  7019. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  7020. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  7021. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  7022. /* Set the command: ADD or DEL */
  7023. if (set)
  7024. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  7025. else
  7026. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  7027. }
  7028. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  7029. if (rc == -EEXIST) {
  7030. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  7031. /* do not treat adding same MAC as error */
  7032. rc = 0;
  7033. } else if (rc < 0)
  7034. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  7035. return rc;
  7036. }
  7037. int bnx2x_del_all_macs(struct bnx2x *bp,
  7038. struct bnx2x_vlan_mac_obj *mac_obj,
  7039. int mac_type, bool wait_for_comp)
  7040. {
  7041. int rc;
  7042. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  7043. /* Wait for completion of requested */
  7044. if (wait_for_comp)
  7045. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7046. /* Set the mac type of addresses we want to clear */
  7047. __set_bit(mac_type, &vlan_mac_flags);
  7048. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  7049. if (rc < 0)
  7050. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  7051. return rc;
  7052. }
  7053. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  7054. {
  7055. if (IS_PF(bp)) {
  7056. unsigned long ramrod_flags = 0;
  7057. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  7058. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  7059. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  7060. &bp->sp_objs->mac_obj, set,
  7061. BNX2X_ETH_MAC, &ramrod_flags);
  7062. } else { /* vf */
  7063. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  7064. bp->fp->index, true);
  7065. }
  7066. }
  7067. int bnx2x_setup_leading(struct bnx2x *bp)
  7068. {
  7069. if (IS_PF(bp))
  7070. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  7071. else /* VF */
  7072. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  7073. }
  7074. /**
  7075. * bnx2x_set_int_mode - configure interrupt mode
  7076. *
  7077. * @bp: driver handle
  7078. *
  7079. * In case of MSI-X it will also try to enable MSI-X.
  7080. */
  7081. int bnx2x_set_int_mode(struct bnx2x *bp)
  7082. {
  7083. int rc = 0;
  7084. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  7085. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  7086. return -EINVAL;
  7087. }
  7088. switch (int_mode) {
  7089. case BNX2X_INT_MODE_MSIX:
  7090. /* attempt to enable msix */
  7091. rc = bnx2x_enable_msix(bp);
  7092. /* msix attained */
  7093. if (!rc)
  7094. return 0;
  7095. /* vfs use only msix */
  7096. if (rc && IS_VF(bp))
  7097. return rc;
  7098. /* failed to enable multiple MSI-X */
  7099. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  7100. bp->num_queues,
  7101. 1 + bp->num_cnic_queues);
  7102. /* falling through... */
  7103. case BNX2X_INT_MODE_MSI:
  7104. bnx2x_enable_msi(bp);
  7105. /* falling through... */
  7106. case BNX2X_INT_MODE_INTX:
  7107. bp->num_ethernet_queues = 1;
  7108. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  7109. BNX2X_DEV_INFO("set number of queues to 1\n");
  7110. break;
  7111. default:
  7112. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  7113. return -EINVAL;
  7114. }
  7115. return 0;
  7116. }
  7117. /* must be called prior to any HW initializations */
  7118. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  7119. {
  7120. if (IS_SRIOV(bp))
  7121. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  7122. return L2_ILT_LINES(bp);
  7123. }
  7124. void bnx2x_ilt_set_info(struct bnx2x *bp)
  7125. {
  7126. struct ilt_client_info *ilt_client;
  7127. struct bnx2x_ilt *ilt = BP_ILT(bp);
  7128. u16 line = 0;
  7129. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  7130. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  7131. /* CDU */
  7132. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  7133. ilt_client->client_num = ILT_CLIENT_CDU;
  7134. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  7135. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  7136. ilt_client->start = line;
  7137. line += bnx2x_cid_ilt_lines(bp);
  7138. if (CNIC_SUPPORT(bp))
  7139. line += CNIC_ILT_LINES;
  7140. ilt_client->end = line - 1;
  7141. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7142. ilt_client->start,
  7143. ilt_client->end,
  7144. ilt_client->page_size,
  7145. ilt_client->flags,
  7146. ilog2(ilt_client->page_size >> 12));
  7147. /* QM */
  7148. if (QM_INIT(bp->qm_cid_count)) {
  7149. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  7150. ilt_client->client_num = ILT_CLIENT_QM;
  7151. ilt_client->page_size = QM_ILT_PAGE_SZ;
  7152. ilt_client->flags = 0;
  7153. ilt_client->start = line;
  7154. /* 4 bytes for each cid */
  7155. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  7156. QM_ILT_PAGE_SZ);
  7157. ilt_client->end = line - 1;
  7158. DP(NETIF_MSG_IFUP,
  7159. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7160. ilt_client->start,
  7161. ilt_client->end,
  7162. ilt_client->page_size,
  7163. ilt_client->flags,
  7164. ilog2(ilt_client->page_size >> 12));
  7165. }
  7166. if (CNIC_SUPPORT(bp)) {
  7167. /* SRC */
  7168. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  7169. ilt_client->client_num = ILT_CLIENT_SRC;
  7170. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  7171. ilt_client->flags = 0;
  7172. ilt_client->start = line;
  7173. line += SRC_ILT_LINES;
  7174. ilt_client->end = line - 1;
  7175. DP(NETIF_MSG_IFUP,
  7176. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7177. ilt_client->start,
  7178. ilt_client->end,
  7179. ilt_client->page_size,
  7180. ilt_client->flags,
  7181. ilog2(ilt_client->page_size >> 12));
  7182. /* TM */
  7183. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  7184. ilt_client->client_num = ILT_CLIENT_TM;
  7185. ilt_client->page_size = TM_ILT_PAGE_SZ;
  7186. ilt_client->flags = 0;
  7187. ilt_client->start = line;
  7188. line += TM_ILT_LINES;
  7189. ilt_client->end = line - 1;
  7190. DP(NETIF_MSG_IFUP,
  7191. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  7192. ilt_client->start,
  7193. ilt_client->end,
  7194. ilt_client->page_size,
  7195. ilt_client->flags,
  7196. ilog2(ilt_client->page_size >> 12));
  7197. }
  7198. BUG_ON(line > ILT_MAX_LINES);
  7199. }
  7200. /**
  7201. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  7202. *
  7203. * @bp: driver handle
  7204. * @fp: pointer to fastpath
  7205. * @init_params: pointer to parameters structure
  7206. *
  7207. * parameters configured:
  7208. * - HC configuration
  7209. * - Queue's CDU context
  7210. */
  7211. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  7212. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  7213. {
  7214. u8 cos;
  7215. int cxt_index, cxt_offset;
  7216. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  7217. if (!IS_FCOE_FP(fp)) {
  7218. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  7219. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  7220. /* If HC is supported, enable host coalescing in the transition
  7221. * to INIT state.
  7222. */
  7223. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  7224. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  7225. /* HC rate */
  7226. init_params->rx.hc_rate = bp->rx_ticks ?
  7227. (1000000 / bp->rx_ticks) : 0;
  7228. init_params->tx.hc_rate = bp->tx_ticks ?
  7229. (1000000 / bp->tx_ticks) : 0;
  7230. /* FW SB ID */
  7231. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  7232. fp->fw_sb_id;
  7233. /*
  7234. * CQ index among the SB indices: FCoE clients uses the default
  7235. * SB, therefore it's different.
  7236. */
  7237. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  7238. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  7239. }
  7240. /* set maximum number of COSs supported by this queue */
  7241. init_params->max_cos = fp->max_cos;
  7242. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  7243. fp->index, init_params->max_cos);
  7244. /* set the context pointers queue object */
  7245. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  7246. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  7247. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  7248. ILT_PAGE_CIDS);
  7249. init_params->cxts[cos] =
  7250. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  7251. }
  7252. }
  7253. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7254. struct bnx2x_queue_state_params *q_params,
  7255. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  7256. int tx_index, bool leading)
  7257. {
  7258. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7259. /* Set the command */
  7260. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7261. /* Set tx-only QUEUE flags: don't zero statistics */
  7262. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7263. /* choose the index of the cid to send the slow path on */
  7264. tx_only_params->cid_index = tx_index;
  7265. /* Set general TX_ONLY_SETUP parameters */
  7266. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7267. /* Set Tx TX_ONLY_SETUP parameters */
  7268. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7269. DP(NETIF_MSG_IFUP,
  7270. "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",
  7271. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7272. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7273. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7274. /* send the ramrod */
  7275. return bnx2x_queue_state_change(bp, q_params);
  7276. }
  7277. /**
  7278. * bnx2x_setup_queue - setup queue
  7279. *
  7280. * @bp: driver handle
  7281. * @fp: pointer to fastpath
  7282. * @leading: is leading
  7283. *
  7284. * This function performs 2 steps in a Queue state machine
  7285. * actually: 1) RESET->INIT 2) INIT->SETUP
  7286. */
  7287. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7288. bool leading)
  7289. {
  7290. struct bnx2x_queue_state_params q_params = {NULL};
  7291. struct bnx2x_queue_setup_params *setup_params =
  7292. &q_params.params.setup;
  7293. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7294. &q_params.params.tx_only;
  7295. int rc;
  7296. u8 tx_index;
  7297. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7298. /* reset IGU state skip FCoE L2 queue */
  7299. if (!IS_FCOE_FP(fp))
  7300. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7301. IGU_INT_ENABLE, 0);
  7302. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7303. /* We want to wait for completion in this context */
  7304. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7305. /* Prepare the INIT parameters */
  7306. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7307. /* Set the command */
  7308. q_params.cmd = BNX2X_Q_CMD_INIT;
  7309. /* Change the state to INIT */
  7310. rc = bnx2x_queue_state_change(bp, &q_params);
  7311. if (rc) {
  7312. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7313. return rc;
  7314. }
  7315. DP(NETIF_MSG_IFUP, "init complete\n");
  7316. /* Now move the Queue to the SETUP state... */
  7317. memset(setup_params, 0, sizeof(*setup_params));
  7318. /* Set QUEUE flags */
  7319. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7320. /* Set general SETUP parameters */
  7321. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7322. FIRST_TX_COS_INDEX);
  7323. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7324. &setup_params->rxq_params);
  7325. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7326. FIRST_TX_COS_INDEX);
  7327. /* Set the command */
  7328. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7329. if (IS_FCOE_FP(fp))
  7330. bp->fcoe_init = true;
  7331. /* Change the state to SETUP */
  7332. rc = bnx2x_queue_state_change(bp, &q_params);
  7333. if (rc) {
  7334. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7335. return rc;
  7336. }
  7337. /* loop through the relevant tx-only indices */
  7338. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7339. tx_index < fp->max_cos;
  7340. tx_index++) {
  7341. /* prepare and send tx-only ramrod*/
  7342. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7343. tx_only_params, tx_index, leading);
  7344. if (rc) {
  7345. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7346. fp->index, tx_index);
  7347. return rc;
  7348. }
  7349. }
  7350. return rc;
  7351. }
  7352. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7353. {
  7354. struct bnx2x_fastpath *fp = &bp->fp[index];
  7355. struct bnx2x_fp_txdata *txdata;
  7356. struct bnx2x_queue_state_params q_params = {NULL};
  7357. int rc, tx_index;
  7358. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7359. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7360. /* We want to wait for completion in this context */
  7361. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7362. /* close tx-only connections */
  7363. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7364. tx_index < fp->max_cos;
  7365. tx_index++){
  7366. /* ascertain this is a normal queue*/
  7367. txdata = fp->txdata_ptr[tx_index];
  7368. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7369. txdata->txq_index);
  7370. /* send halt terminate on tx-only connection */
  7371. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7372. memset(&q_params.params.terminate, 0,
  7373. sizeof(q_params.params.terminate));
  7374. q_params.params.terminate.cid_index = tx_index;
  7375. rc = bnx2x_queue_state_change(bp, &q_params);
  7376. if (rc)
  7377. return rc;
  7378. /* send halt terminate on tx-only connection */
  7379. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7380. memset(&q_params.params.cfc_del, 0,
  7381. sizeof(q_params.params.cfc_del));
  7382. q_params.params.cfc_del.cid_index = tx_index;
  7383. rc = bnx2x_queue_state_change(bp, &q_params);
  7384. if (rc)
  7385. return rc;
  7386. }
  7387. /* Stop the primary connection: */
  7388. /* ...halt the connection */
  7389. q_params.cmd = BNX2X_Q_CMD_HALT;
  7390. rc = bnx2x_queue_state_change(bp, &q_params);
  7391. if (rc)
  7392. return rc;
  7393. /* ...terminate the connection */
  7394. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7395. memset(&q_params.params.terminate, 0,
  7396. sizeof(q_params.params.terminate));
  7397. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7398. rc = bnx2x_queue_state_change(bp, &q_params);
  7399. if (rc)
  7400. return rc;
  7401. /* ...delete cfc entry */
  7402. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7403. memset(&q_params.params.cfc_del, 0,
  7404. sizeof(q_params.params.cfc_del));
  7405. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7406. return bnx2x_queue_state_change(bp, &q_params);
  7407. }
  7408. static void bnx2x_reset_func(struct bnx2x *bp)
  7409. {
  7410. int port = BP_PORT(bp);
  7411. int func = BP_FUNC(bp);
  7412. int i;
  7413. /* Disable the function in the FW */
  7414. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7415. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7416. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7417. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7418. /* FP SBs */
  7419. for_each_eth_queue(bp, i) {
  7420. struct bnx2x_fastpath *fp = &bp->fp[i];
  7421. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7422. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7423. SB_DISABLED);
  7424. }
  7425. if (CNIC_LOADED(bp))
  7426. /* CNIC SB */
  7427. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7428. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7429. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7430. /* SP SB */
  7431. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7432. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7433. SB_DISABLED);
  7434. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7435. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7436. 0);
  7437. /* Configure IGU */
  7438. if (bp->common.int_block == INT_BLOCK_HC) {
  7439. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7440. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7441. } else {
  7442. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7443. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7444. }
  7445. if (CNIC_LOADED(bp)) {
  7446. /* Disable Timer scan */
  7447. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7448. /*
  7449. * Wait for at least 10ms and up to 2 second for the timers
  7450. * scan to complete
  7451. */
  7452. for (i = 0; i < 200; i++) {
  7453. usleep_range(10000, 20000);
  7454. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7455. break;
  7456. }
  7457. }
  7458. /* Clear ILT */
  7459. bnx2x_clear_func_ilt(bp, func);
  7460. /* Timers workaround bug for E2: if this is vnic-3,
  7461. * we need to set the entire ilt range for this timers.
  7462. */
  7463. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7464. struct ilt_client_info ilt_cli;
  7465. /* use dummy TM client */
  7466. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7467. ilt_cli.start = 0;
  7468. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7469. ilt_cli.client_num = ILT_CLIENT_TM;
  7470. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7471. }
  7472. /* this assumes that reset_port() called before reset_func()*/
  7473. if (!CHIP_IS_E1x(bp))
  7474. bnx2x_pf_disable(bp);
  7475. bp->dmae_ready = 0;
  7476. }
  7477. static void bnx2x_reset_port(struct bnx2x *bp)
  7478. {
  7479. int port = BP_PORT(bp);
  7480. u32 val;
  7481. /* Reset physical Link */
  7482. bnx2x__link_reset(bp);
  7483. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7484. /* Do not rcv packets to BRB */
  7485. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7486. /* Do not direct rcv packets that are not for MCP to the BRB */
  7487. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7488. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7489. /* Configure AEU */
  7490. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7491. msleep(100);
  7492. /* Check for BRB port occupancy */
  7493. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7494. if (val)
  7495. DP(NETIF_MSG_IFDOWN,
  7496. "BRB1 is not empty %d blocks are occupied\n", val);
  7497. /* TODO: Close Doorbell port? */
  7498. }
  7499. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7500. {
  7501. struct bnx2x_func_state_params func_params = {NULL};
  7502. /* Prepare parameters for function state transitions */
  7503. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7504. func_params.f_obj = &bp->func_obj;
  7505. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7506. func_params.params.hw_init.load_phase = load_code;
  7507. return bnx2x_func_state_change(bp, &func_params);
  7508. }
  7509. static int bnx2x_func_stop(struct bnx2x *bp)
  7510. {
  7511. struct bnx2x_func_state_params func_params = {NULL};
  7512. int rc;
  7513. /* Prepare parameters for function state transitions */
  7514. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7515. func_params.f_obj = &bp->func_obj;
  7516. func_params.cmd = BNX2X_F_CMD_STOP;
  7517. /*
  7518. * Try to stop the function the 'good way'. If fails (in case
  7519. * of a parity error during bnx2x_chip_cleanup()) and we are
  7520. * not in a debug mode, perform a state transaction in order to
  7521. * enable further HW_RESET transaction.
  7522. */
  7523. rc = bnx2x_func_state_change(bp, &func_params);
  7524. if (rc) {
  7525. #ifdef BNX2X_STOP_ON_ERROR
  7526. return rc;
  7527. #else
  7528. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7529. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7530. return bnx2x_func_state_change(bp, &func_params);
  7531. #endif
  7532. }
  7533. return 0;
  7534. }
  7535. /**
  7536. * bnx2x_send_unload_req - request unload mode from the MCP.
  7537. *
  7538. * @bp: driver handle
  7539. * @unload_mode: requested function's unload mode
  7540. *
  7541. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7542. */
  7543. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7544. {
  7545. u32 reset_code = 0;
  7546. int port = BP_PORT(bp);
  7547. /* Select the UNLOAD request mode */
  7548. if (unload_mode == UNLOAD_NORMAL)
  7549. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7550. else if (bp->flags & NO_WOL_FLAG)
  7551. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7552. else if (bp->wol) {
  7553. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7554. u8 *mac_addr = bp->dev->dev_addr;
  7555. struct pci_dev *pdev = bp->pdev;
  7556. u32 val;
  7557. u16 pmc;
  7558. /* The mac address is written to entries 1-4 to
  7559. * preserve entry 0 which is used by the PMF
  7560. */
  7561. u8 entry = (BP_VN(bp) + 1)*8;
  7562. val = (mac_addr[0] << 8) | mac_addr[1];
  7563. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7564. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7565. (mac_addr[4] << 8) | mac_addr[5];
  7566. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7567. /* Enable the PME and clear the status */
  7568. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7569. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7570. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7571. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7572. } else
  7573. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7574. /* Send the request to the MCP */
  7575. if (!BP_NOMCP(bp))
  7576. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7577. else {
  7578. int path = BP_PATH(bp);
  7579. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7580. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7581. bnx2x_load_count[path][2]);
  7582. bnx2x_load_count[path][0]--;
  7583. bnx2x_load_count[path][1 + port]--;
  7584. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7585. path, bnx2x_load_count[path][0], bnx2x_load_count[path][1],
  7586. bnx2x_load_count[path][2]);
  7587. if (bnx2x_load_count[path][0] == 0)
  7588. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7589. else if (bnx2x_load_count[path][1 + port] == 0)
  7590. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7591. else
  7592. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7593. }
  7594. return reset_code;
  7595. }
  7596. /**
  7597. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7598. *
  7599. * @bp: driver handle
  7600. * @keep_link: true iff link should be kept up
  7601. */
  7602. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7603. {
  7604. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7605. /* Report UNLOAD_DONE to MCP */
  7606. if (!BP_NOMCP(bp))
  7607. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7608. }
  7609. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7610. {
  7611. int tout = 50;
  7612. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7613. if (!bp->port.pmf)
  7614. return 0;
  7615. /*
  7616. * (assumption: No Attention from MCP at this stage)
  7617. * PMF probably in the middle of TX disable/enable transaction
  7618. * 1. Sync IRS for default SB
  7619. * 2. Sync SP queue - this guarantees us that attention handling started
  7620. * 3. Wait, that TX disable/enable transaction completes
  7621. *
  7622. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7623. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7624. * received completion for the transaction the state is TX_STOPPED.
  7625. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7626. * transaction.
  7627. */
  7628. /* make sure default SB ISR is done */
  7629. if (msix)
  7630. synchronize_irq(bp->msix_table[0].vector);
  7631. else
  7632. synchronize_irq(bp->pdev->irq);
  7633. flush_workqueue(bnx2x_wq);
  7634. flush_workqueue(bnx2x_iov_wq);
  7635. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7636. BNX2X_F_STATE_STARTED && tout--)
  7637. msleep(20);
  7638. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7639. BNX2X_F_STATE_STARTED) {
  7640. #ifdef BNX2X_STOP_ON_ERROR
  7641. BNX2X_ERR("Wrong function state\n");
  7642. return -EBUSY;
  7643. #else
  7644. /*
  7645. * Failed to complete the transaction in a "good way"
  7646. * Force both transactions with CLR bit
  7647. */
  7648. struct bnx2x_func_state_params func_params = {NULL};
  7649. DP(NETIF_MSG_IFDOWN,
  7650. "Hmmm... Unexpected function state! Forcing STARTED-->TX_STOPPED-->STARTED\n");
  7651. func_params.f_obj = &bp->func_obj;
  7652. __set_bit(RAMROD_DRV_CLR_ONLY,
  7653. &func_params.ramrod_flags);
  7654. /* STARTED-->TX_ST0PPED */
  7655. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7656. bnx2x_func_state_change(bp, &func_params);
  7657. /* TX_ST0PPED-->STARTED */
  7658. func_params.cmd = BNX2X_F_CMD_TX_START;
  7659. return bnx2x_func_state_change(bp, &func_params);
  7660. #endif
  7661. }
  7662. return 0;
  7663. }
  7664. static void bnx2x_disable_ptp(struct bnx2x *bp)
  7665. {
  7666. int port = BP_PORT(bp);
  7667. /* Disable sending PTP packets to host */
  7668. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  7669. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  7670. /* Reset PTP event detection rules */
  7671. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  7672. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  7673. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  7674. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  7675. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  7676. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  7677. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  7678. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  7679. /* Disable the PTP feature */
  7680. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  7681. NIG_REG_P0_PTP_EN, 0x0);
  7682. }
  7683. /* Called during unload, to stop PTP-related stuff */
  7684. void bnx2x_stop_ptp(struct bnx2x *bp)
  7685. {
  7686. /* Cancel PTP work queue. Should be done after the Tx queues are
  7687. * drained to prevent additional scheduling.
  7688. */
  7689. cancel_work_sync(&bp->ptp_task);
  7690. if (bp->ptp_tx_skb) {
  7691. dev_kfree_skb_any(bp->ptp_tx_skb);
  7692. bp->ptp_tx_skb = NULL;
  7693. }
  7694. /* Disable PTP in HW */
  7695. bnx2x_disable_ptp(bp);
  7696. DP(BNX2X_MSG_PTP, "PTP stop ended successfully\n");
  7697. }
  7698. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7699. {
  7700. int port = BP_PORT(bp);
  7701. int i, rc = 0;
  7702. u8 cos;
  7703. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7704. u32 reset_code;
  7705. /* Wait until tx fastpath tasks complete */
  7706. for_each_tx_queue(bp, i) {
  7707. struct bnx2x_fastpath *fp = &bp->fp[i];
  7708. for_each_cos_in_tx_queue(fp, cos)
  7709. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7710. #ifdef BNX2X_STOP_ON_ERROR
  7711. if (rc)
  7712. return;
  7713. #endif
  7714. }
  7715. /* Give HW time to discard old tx messages */
  7716. usleep_range(1000, 2000);
  7717. /* Clean all ETH MACs */
  7718. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7719. false);
  7720. if (rc < 0)
  7721. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7722. /* Clean up UC list */
  7723. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7724. true);
  7725. if (rc < 0)
  7726. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7727. rc);
  7728. /* Disable LLH */
  7729. if (!CHIP_IS_E1(bp))
  7730. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7731. /* Set "drop all" (stop Rx).
  7732. * We need to take a netif_addr_lock() here in order to prevent
  7733. * a race between the completion code and this code.
  7734. */
  7735. netif_addr_lock_bh(bp->dev);
  7736. /* Schedule the rx_mode command */
  7737. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7738. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7739. else
  7740. bnx2x_set_storm_rx_mode(bp);
  7741. /* Cleanup multicast configuration */
  7742. rparam.mcast_obj = &bp->mcast_obj;
  7743. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7744. if (rc < 0)
  7745. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7746. netif_addr_unlock_bh(bp->dev);
  7747. bnx2x_iov_chip_cleanup(bp);
  7748. /*
  7749. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7750. * this function should perform FUNC, PORT or COMMON HW
  7751. * reset.
  7752. */
  7753. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7754. /*
  7755. * (assumption: No Attention from MCP at this stage)
  7756. * PMF probably in the middle of TX disable/enable transaction
  7757. */
  7758. rc = bnx2x_func_wait_started(bp);
  7759. if (rc) {
  7760. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7761. #ifdef BNX2X_STOP_ON_ERROR
  7762. return;
  7763. #endif
  7764. }
  7765. /* Close multi and leading connections
  7766. * Completions for ramrods are collected in a synchronous way
  7767. */
  7768. for_each_eth_queue(bp, i)
  7769. if (bnx2x_stop_queue(bp, i))
  7770. #ifdef BNX2X_STOP_ON_ERROR
  7771. return;
  7772. #else
  7773. goto unload_error;
  7774. #endif
  7775. if (CNIC_LOADED(bp)) {
  7776. for_each_cnic_queue(bp, i)
  7777. if (bnx2x_stop_queue(bp, i))
  7778. #ifdef BNX2X_STOP_ON_ERROR
  7779. return;
  7780. #else
  7781. goto unload_error;
  7782. #endif
  7783. }
  7784. /* If SP settings didn't get completed so far - something
  7785. * very wrong has happen.
  7786. */
  7787. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7788. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7789. #ifndef BNX2X_STOP_ON_ERROR
  7790. unload_error:
  7791. #endif
  7792. rc = bnx2x_func_stop(bp);
  7793. if (rc) {
  7794. BNX2X_ERR("Function stop failed!\n");
  7795. #ifdef BNX2X_STOP_ON_ERROR
  7796. return;
  7797. #endif
  7798. }
  7799. /* stop_ptp should be after the Tx queues are drained to prevent
  7800. * scheduling to the cancelled PTP work queue. It should also be after
  7801. * function stop ramrod is sent, since as part of this ramrod FW access
  7802. * PTP registers.
  7803. */
  7804. bnx2x_stop_ptp(bp);
  7805. /* Disable HW interrupts, NAPI */
  7806. bnx2x_netif_stop(bp, 1);
  7807. /* Delete all NAPI objects */
  7808. bnx2x_del_all_napi(bp);
  7809. if (CNIC_LOADED(bp))
  7810. bnx2x_del_all_napi_cnic(bp);
  7811. /* Release IRQs */
  7812. bnx2x_free_irq(bp);
  7813. /* Reset the chip */
  7814. rc = bnx2x_reset_hw(bp, reset_code);
  7815. if (rc)
  7816. BNX2X_ERR("HW_RESET failed\n");
  7817. /* Report UNLOAD_DONE to MCP */
  7818. bnx2x_send_unload_done(bp, keep_link);
  7819. }
  7820. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7821. {
  7822. u32 val;
  7823. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7824. if (CHIP_IS_E1(bp)) {
  7825. int port = BP_PORT(bp);
  7826. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7827. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7828. val = REG_RD(bp, addr);
  7829. val &= ~(0x300);
  7830. REG_WR(bp, addr, val);
  7831. } else {
  7832. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7833. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7834. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7835. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7836. }
  7837. }
  7838. /* Close gates #2, #3 and #4: */
  7839. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7840. {
  7841. u32 val;
  7842. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7843. if (!CHIP_IS_E1(bp)) {
  7844. /* #4 */
  7845. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7846. /* #2 */
  7847. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7848. }
  7849. /* #3 */
  7850. if (CHIP_IS_E1x(bp)) {
  7851. /* Prevent interrupts from HC on both ports */
  7852. val = REG_RD(bp, HC_REG_CONFIG_1);
  7853. REG_WR(bp, HC_REG_CONFIG_1,
  7854. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7855. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7856. val = REG_RD(bp, HC_REG_CONFIG_0);
  7857. REG_WR(bp, HC_REG_CONFIG_0,
  7858. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7859. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7860. } else {
  7861. /* Prevent incoming interrupts in IGU */
  7862. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7863. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7864. (!close) ?
  7865. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7866. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7867. }
  7868. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7869. close ? "closing" : "opening");
  7870. mmiowb();
  7871. }
  7872. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7873. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7874. {
  7875. /* Do some magic... */
  7876. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7877. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7878. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7879. }
  7880. /**
  7881. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7882. *
  7883. * @bp: driver handle
  7884. * @magic_val: old value of the `magic' bit.
  7885. */
  7886. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7887. {
  7888. /* Restore the `magic' bit value... */
  7889. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7890. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7891. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7892. }
  7893. /**
  7894. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7895. *
  7896. * @bp: driver handle
  7897. * @magic_val: old value of 'magic' bit.
  7898. *
  7899. * Takes care of CLP configurations.
  7900. */
  7901. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7902. {
  7903. u32 shmem;
  7904. u32 validity_offset;
  7905. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7906. /* Set `magic' bit in order to save MF config */
  7907. if (!CHIP_IS_E1(bp))
  7908. bnx2x_clp_reset_prep(bp, magic_val);
  7909. /* Get shmem offset */
  7910. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7911. validity_offset =
  7912. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7913. /* Clear validity map flags */
  7914. if (shmem > 0)
  7915. REG_WR(bp, shmem + validity_offset, 0);
  7916. }
  7917. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7918. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7919. /**
  7920. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7921. *
  7922. * @bp: driver handle
  7923. */
  7924. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7925. {
  7926. /* special handling for emulation and FPGA,
  7927. wait 10 times longer */
  7928. if (CHIP_REV_IS_SLOW(bp))
  7929. msleep(MCP_ONE_TIMEOUT*10);
  7930. else
  7931. msleep(MCP_ONE_TIMEOUT);
  7932. }
  7933. /*
  7934. * initializes bp->common.shmem_base and waits for validity signature to appear
  7935. */
  7936. static int bnx2x_init_shmem(struct bnx2x *bp)
  7937. {
  7938. int cnt = 0;
  7939. u32 val = 0;
  7940. do {
  7941. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7942. if (bp->common.shmem_base) {
  7943. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7944. if (val & SHR_MEM_VALIDITY_MB)
  7945. return 0;
  7946. }
  7947. bnx2x_mcp_wait_one(bp);
  7948. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7949. BNX2X_ERR("BAD MCP validity signature\n");
  7950. return -ENODEV;
  7951. }
  7952. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7953. {
  7954. int rc = bnx2x_init_shmem(bp);
  7955. /* Restore the `magic' bit value */
  7956. if (!CHIP_IS_E1(bp))
  7957. bnx2x_clp_reset_done(bp, magic_val);
  7958. return rc;
  7959. }
  7960. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7961. {
  7962. if (!CHIP_IS_E1(bp)) {
  7963. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7964. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7965. mmiowb();
  7966. }
  7967. }
  7968. /*
  7969. * Reset the whole chip except for:
  7970. * - PCIE core
  7971. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7972. * one reset bit)
  7973. * - IGU
  7974. * - MISC (including AEU)
  7975. * - GRC
  7976. * - RBCN, RBCP
  7977. */
  7978. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7979. {
  7980. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7981. u32 global_bits2, stay_reset2;
  7982. /*
  7983. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7984. * (per chip) blocks.
  7985. */
  7986. global_bits2 =
  7987. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7988. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7989. /* Don't reset the following blocks.
  7990. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7991. * reset, as in 4 port device they might still be owned
  7992. * by the MCP (there is only one leader per path).
  7993. */
  7994. not_reset_mask1 =
  7995. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7996. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7997. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7998. not_reset_mask2 =
  7999. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  8000. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  8001. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  8002. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  8003. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  8004. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  8005. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  8006. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  8007. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  8008. MISC_REGISTERS_RESET_REG_2_PGLC |
  8009. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  8010. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  8011. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  8012. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  8013. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  8014. MISC_REGISTERS_RESET_REG_2_UMAC1;
  8015. /*
  8016. * Keep the following blocks in reset:
  8017. * - all xxMACs are handled by the bnx2x_link code.
  8018. */
  8019. stay_reset2 =
  8020. MISC_REGISTERS_RESET_REG_2_XMAC |
  8021. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  8022. /* Full reset masks according to the chip */
  8023. reset_mask1 = 0xffffffff;
  8024. if (CHIP_IS_E1(bp))
  8025. reset_mask2 = 0xffff;
  8026. else if (CHIP_IS_E1H(bp))
  8027. reset_mask2 = 0x1ffff;
  8028. else if (CHIP_IS_E2(bp))
  8029. reset_mask2 = 0xfffff;
  8030. else /* CHIP_IS_E3 */
  8031. reset_mask2 = 0x3ffffff;
  8032. /* Don't reset global blocks unless we need to */
  8033. if (!global)
  8034. reset_mask2 &= ~global_bits2;
  8035. /*
  8036. * In case of attention in the QM, we need to reset PXP
  8037. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  8038. * because otherwise QM reset would release 'close the gates' shortly
  8039. * before resetting the PXP, then the PSWRQ would send a write
  8040. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  8041. * read the payload data from PSWWR, but PSWWR would not
  8042. * respond. The write queue in PGLUE would stuck, dmae commands
  8043. * would not return. Therefore it's important to reset the second
  8044. * reset register (containing the
  8045. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  8046. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  8047. * bit).
  8048. */
  8049. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  8050. reset_mask2 & (~not_reset_mask2));
  8051. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  8052. reset_mask1 & (~not_reset_mask1));
  8053. barrier();
  8054. mmiowb();
  8055. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  8056. reset_mask2 & (~stay_reset2));
  8057. barrier();
  8058. mmiowb();
  8059. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  8060. mmiowb();
  8061. }
  8062. /**
  8063. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  8064. * It should get cleared in no more than 1s.
  8065. *
  8066. * @bp: driver handle
  8067. *
  8068. * It should get cleared in no more than 1s. Returns 0 if
  8069. * pending writes bit gets cleared.
  8070. */
  8071. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  8072. {
  8073. u32 cnt = 1000;
  8074. u32 pend_bits = 0;
  8075. do {
  8076. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  8077. if (pend_bits == 0)
  8078. break;
  8079. usleep_range(1000, 2000);
  8080. } while (cnt-- > 0);
  8081. if (cnt <= 0) {
  8082. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  8083. pend_bits);
  8084. return -EBUSY;
  8085. }
  8086. return 0;
  8087. }
  8088. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  8089. {
  8090. int cnt = 1000;
  8091. u32 val = 0;
  8092. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  8093. u32 tags_63_32 = 0;
  8094. /* Empty the Tetris buffer, wait for 1s */
  8095. do {
  8096. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  8097. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  8098. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  8099. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  8100. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  8101. if (CHIP_IS_E3(bp))
  8102. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  8103. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  8104. ((port_is_idle_0 & 0x1) == 0x1) &&
  8105. ((port_is_idle_1 & 0x1) == 0x1) &&
  8106. (pgl_exp_rom2 == 0xffffffff) &&
  8107. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  8108. break;
  8109. usleep_range(1000, 2000);
  8110. } while (cnt-- > 0);
  8111. if (cnt <= 0) {
  8112. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  8113. 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",
  8114. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  8115. pgl_exp_rom2);
  8116. return -EAGAIN;
  8117. }
  8118. barrier();
  8119. /* Close gates #2, #3 and #4 */
  8120. bnx2x_set_234_gates(bp, true);
  8121. /* Poll for IGU VQs for 57712 and newer chips */
  8122. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  8123. return -EAGAIN;
  8124. /* TBD: Indicate that "process kill" is in progress to MCP */
  8125. /* Clear "unprepared" bit */
  8126. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  8127. barrier();
  8128. /* Make sure all is written to the chip before the reset */
  8129. mmiowb();
  8130. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  8131. * PSWHST, GRC and PSWRD Tetris buffer.
  8132. */
  8133. usleep_range(1000, 2000);
  8134. /* Prepare to chip reset: */
  8135. /* MCP */
  8136. if (global)
  8137. bnx2x_reset_mcp_prep(bp, &val);
  8138. /* PXP */
  8139. bnx2x_pxp_prep(bp);
  8140. barrier();
  8141. /* reset the chip */
  8142. bnx2x_process_kill_chip_reset(bp, global);
  8143. barrier();
  8144. /* clear errors in PGB */
  8145. if (!CHIP_IS_E1x(bp))
  8146. REG_WR(bp, PGLUE_B_REG_LATCHED_ERRORS_CLR, 0x7f);
  8147. /* Recover after reset: */
  8148. /* MCP */
  8149. if (global && bnx2x_reset_mcp_comp(bp, val))
  8150. return -EAGAIN;
  8151. /* TBD: Add resetting the NO_MCP mode DB here */
  8152. /* Open the gates #2, #3 and #4 */
  8153. bnx2x_set_234_gates(bp, false);
  8154. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  8155. * reset state, re-enable attentions. */
  8156. return 0;
  8157. }
  8158. static int bnx2x_leader_reset(struct bnx2x *bp)
  8159. {
  8160. int rc = 0;
  8161. bool global = bnx2x_reset_is_global(bp);
  8162. u32 load_code;
  8163. /* if not going to reset MCP - load "fake" driver to reset HW while
  8164. * driver is owner of the HW
  8165. */
  8166. if (!global && !BP_NOMCP(bp)) {
  8167. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  8168. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  8169. if (!load_code) {
  8170. BNX2X_ERR("MCP response failure, aborting\n");
  8171. rc = -EAGAIN;
  8172. goto exit_leader_reset;
  8173. }
  8174. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  8175. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  8176. BNX2X_ERR("MCP unexpected resp, aborting\n");
  8177. rc = -EAGAIN;
  8178. goto exit_leader_reset2;
  8179. }
  8180. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  8181. if (!load_code) {
  8182. BNX2X_ERR("MCP response failure, aborting\n");
  8183. rc = -EAGAIN;
  8184. goto exit_leader_reset2;
  8185. }
  8186. }
  8187. /* Try to recover after the failure */
  8188. if (bnx2x_process_kill(bp, global)) {
  8189. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  8190. BP_PATH(bp));
  8191. rc = -EAGAIN;
  8192. goto exit_leader_reset2;
  8193. }
  8194. /*
  8195. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  8196. * state.
  8197. */
  8198. bnx2x_set_reset_done(bp);
  8199. if (global)
  8200. bnx2x_clear_reset_global(bp);
  8201. exit_leader_reset2:
  8202. /* unload "fake driver" if it was loaded */
  8203. if (!global && !BP_NOMCP(bp)) {
  8204. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  8205. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  8206. }
  8207. exit_leader_reset:
  8208. bp->is_leader = 0;
  8209. bnx2x_release_leader_lock(bp);
  8210. smp_mb();
  8211. return rc;
  8212. }
  8213. static void bnx2x_recovery_failed(struct bnx2x *bp)
  8214. {
  8215. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  8216. /* Disconnect this device */
  8217. netif_device_detach(bp->dev);
  8218. /*
  8219. * Block ifup for all function on this engine until "process kill"
  8220. * or power cycle.
  8221. */
  8222. bnx2x_set_reset_in_progress(bp);
  8223. /* Shut down the power */
  8224. bnx2x_set_power_state(bp, PCI_D3hot);
  8225. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8226. smp_mb();
  8227. }
  8228. /*
  8229. * Assumption: runs under rtnl lock. This together with the fact
  8230. * that it's called only from bnx2x_sp_rtnl() ensure that it
  8231. * will never be called when netif_running(bp->dev) is false.
  8232. */
  8233. static void bnx2x_parity_recover(struct bnx2x *bp)
  8234. {
  8235. bool global = false;
  8236. u32 error_recovered, error_unrecovered;
  8237. bool is_parity;
  8238. DP(NETIF_MSG_HW, "Handling parity\n");
  8239. while (1) {
  8240. switch (bp->recovery_state) {
  8241. case BNX2X_RECOVERY_INIT:
  8242. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  8243. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  8244. WARN_ON(!is_parity);
  8245. /* Try to get a LEADER_LOCK HW lock */
  8246. if (bnx2x_trylock_leader_lock(bp)) {
  8247. bnx2x_set_reset_in_progress(bp);
  8248. /*
  8249. * Check if there is a global attention and if
  8250. * there was a global attention, set the global
  8251. * reset bit.
  8252. */
  8253. if (global)
  8254. bnx2x_set_reset_global(bp);
  8255. bp->is_leader = 1;
  8256. }
  8257. /* Stop the driver */
  8258. /* If interface has been removed - break */
  8259. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  8260. return;
  8261. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  8262. /* Ensure "is_leader", MCP command sequence and
  8263. * "recovery_state" update values are seen on other
  8264. * CPUs.
  8265. */
  8266. smp_mb();
  8267. break;
  8268. case BNX2X_RECOVERY_WAIT:
  8269. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  8270. if (bp->is_leader) {
  8271. int other_engine = BP_PATH(bp) ? 0 : 1;
  8272. bool other_load_status =
  8273. bnx2x_get_load_status(bp, other_engine);
  8274. bool load_status =
  8275. bnx2x_get_load_status(bp, BP_PATH(bp));
  8276. global = bnx2x_reset_is_global(bp);
  8277. /*
  8278. * In case of a parity in a global block, let
  8279. * the first leader that performs a
  8280. * leader_reset() reset the global blocks in
  8281. * order to clear global attentions. Otherwise
  8282. * the gates will remain closed for that
  8283. * engine.
  8284. */
  8285. if (load_status ||
  8286. (global && other_load_status)) {
  8287. /* Wait until all other functions get
  8288. * down.
  8289. */
  8290. schedule_delayed_work(&bp->sp_rtnl_task,
  8291. HZ/10);
  8292. return;
  8293. } else {
  8294. /* If all other functions got down -
  8295. * try to bring the chip back to
  8296. * normal. In any case it's an exit
  8297. * point for a leader.
  8298. */
  8299. if (bnx2x_leader_reset(bp)) {
  8300. bnx2x_recovery_failed(bp);
  8301. return;
  8302. }
  8303. /* If we are here, means that the
  8304. * leader has succeeded and doesn't
  8305. * want to be a leader any more. Try
  8306. * to continue as a none-leader.
  8307. */
  8308. break;
  8309. }
  8310. } else { /* non-leader */
  8311. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8312. /* Try to get a LEADER_LOCK HW lock as
  8313. * long as a former leader may have
  8314. * been unloaded by the user or
  8315. * released a leadership by another
  8316. * reason.
  8317. */
  8318. if (bnx2x_trylock_leader_lock(bp)) {
  8319. /* I'm a leader now! Restart a
  8320. * switch case.
  8321. */
  8322. bp->is_leader = 1;
  8323. break;
  8324. }
  8325. schedule_delayed_work(&bp->sp_rtnl_task,
  8326. HZ/10);
  8327. return;
  8328. } else {
  8329. /*
  8330. * If there was a global attention, wait
  8331. * for it to be cleared.
  8332. */
  8333. if (bnx2x_reset_is_global(bp)) {
  8334. schedule_delayed_work(
  8335. &bp->sp_rtnl_task,
  8336. HZ/10);
  8337. return;
  8338. }
  8339. error_recovered =
  8340. bp->eth_stats.recoverable_error;
  8341. error_unrecovered =
  8342. bp->eth_stats.unrecoverable_error;
  8343. bp->recovery_state =
  8344. BNX2X_RECOVERY_NIC_LOADING;
  8345. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8346. error_unrecovered++;
  8347. netdev_err(bp->dev,
  8348. "Recovery failed. Power cycle needed\n");
  8349. /* Disconnect this device */
  8350. netif_device_detach(bp->dev);
  8351. /* Shut down the power */
  8352. bnx2x_set_power_state(
  8353. bp, PCI_D3hot);
  8354. smp_mb();
  8355. } else {
  8356. bp->recovery_state =
  8357. BNX2X_RECOVERY_DONE;
  8358. error_recovered++;
  8359. smp_mb();
  8360. }
  8361. bp->eth_stats.recoverable_error =
  8362. error_recovered;
  8363. bp->eth_stats.unrecoverable_error =
  8364. error_unrecovered;
  8365. return;
  8366. }
  8367. }
  8368. default:
  8369. return;
  8370. }
  8371. }
  8372. }
  8373. static int bnx2x_close(struct net_device *dev);
  8374. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8375. * scheduled on a general queue in order to prevent a dead lock.
  8376. */
  8377. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8378. {
  8379. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8380. rtnl_lock();
  8381. if (!netif_running(bp->dev)) {
  8382. rtnl_unlock();
  8383. return;
  8384. }
  8385. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8386. #ifdef BNX2X_STOP_ON_ERROR
  8387. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8388. "you will need to reboot when done\n");
  8389. goto sp_rtnl_not_reset;
  8390. #endif
  8391. /*
  8392. * Clear all pending SP commands as we are going to reset the
  8393. * function anyway.
  8394. */
  8395. bp->sp_rtnl_state = 0;
  8396. smp_mb();
  8397. bnx2x_parity_recover(bp);
  8398. rtnl_unlock();
  8399. return;
  8400. }
  8401. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8402. #ifdef BNX2X_STOP_ON_ERROR
  8403. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8404. "you will need to reboot when done\n");
  8405. goto sp_rtnl_not_reset;
  8406. #endif
  8407. /*
  8408. * Clear all pending SP commands as we are going to reset the
  8409. * function anyway.
  8410. */
  8411. bp->sp_rtnl_state = 0;
  8412. smp_mb();
  8413. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8414. bnx2x_nic_load(bp, LOAD_NORMAL);
  8415. rtnl_unlock();
  8416. return;
  8417. }
  8418. #ifdef BNX2X_STOP_ON_ERROR
  8419. sp_rtnl_not_reset:
  8420. #endif
  8421. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8422. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8423. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8424. bnx2x_after_function_update(bp);
  8425. /*
  8426. * in case of fan failure we need to reset id if the "stop on error"
  8427. * debug flag is set, since we trying to prevent permanent overheating
  8428. * damage
  8429. */
  8430. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8431. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8432. netif_device_detach(bp->dev);
  8433. bnx2x_close(bp->dev);
  8434. rtnl_unlock();
  8435. return;
  8436. }
  8437. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8438. DP(BNX2X_MSG_SP,
  8439. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8440. bnx2x_vfpf_set_mcast(bp->dev);
  8441. }
  8442. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8443. &bp->sp_rtnl_state)){
  8444. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8445. bnx2x_tx_disable(bp);
  8446. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8447. }
  8448. }
  8449. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8450. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8451. bnx2x_set_rx_mode_inner(bp);
  8452. }
  8453. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8454. &bp->sp_rtnl_state))
  8455. bnx2x_pf_set_vfs_vlan(bp);
  8456. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state)) {
  8457. bnx2x_dcbx_stop_hw_tx(bp);
  8458. bnx2x_dcbx_resume_hw_tx(bp);
  8459. }
  8460. if (test_and_clear_bit(BNX2X_SP_RTNL_GET_DRV_VERSION,
  8461. &bp->sp_rtnl_state))
  8462. bnx2x_update_mng_version(bp);
  8463. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8464. * can be called from other contexts as well)
  8465. */
  8466. rtnl_unlock();
  8467. /* enable SR-IOV if applicable */
  8468. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8469. &bp->sp_rtnl_state)) {
  8470. bnx2x_disable_sriov(bp);
  8471. bnx2x_enable_sriov(bp);
  8472. }
  8473. }
  8474. static void bnx2x_period_task(struct work_struct *work)
  8475. {
  8476. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8477. if (!netif_running(bp->dev))
  8478. goto period_task_exit;
  8479. if (CHIP_REV_IS_SLOW(bp)) {
  8480. BNX2X_ERR("period task called on emulation, ignoring\n");
  8481. goto period_task_exit;
  8482. }
  8483. bnx2x_acquire_phy_lock(bp);
  8484. /*
  8485. * The barrier is needed to ensure the ordering between the writing to
  8486. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8487. * the reading here.
  8488. */
  8489. smp_mb();
  8490. if (bp->port.pmf) {
  8491. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8492. /* Re-queue task in 1 sec */
  8493. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8494. }
  8495. bnx2x_release_phy_lock(bp);
  8496. period_task_exit:
  8497. return;
  8498. }
  8499. /*
  8500. * Init service functions
  8501. */
  8502. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8503. {
  8504. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8505. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8506. return base + (BP_ABS_FUNC(bp)) * stride;
  8507. }
  8508. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8509. struct bnx2x_mac_vals *vals)
  8510. {
  8511. u32 val, base_addr, offset, mask, reset_reg;
  8512. bool mac_stopped = false;
  8513. u8 port = BP_PORT(bp);
  8514. /* reset addresses as they also mark which values were changed */
  8515. vals->bmac_addr = 0;
  8516. vals->umac_addr = 0;
  8517. vals->xmac_addr = 0;
  8518. vals->emac_addr = 0;
  8519. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8520. if (!CHIP_IS_E3(bp)) {
  8521. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8522. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8523. if ((mask & reset_reg) && val) {
  8524. u32 wb_data[2];
  8525. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8526. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8527. : NIG_REG_INGRESS_BMAC0_MEM;
  8528. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8529. : BIGMAC_REGISTER_BMAC_CONTROL;
  8530. /*
  8531. * use rd/wr since we cannot use dmae. This is safe
  8532. * since MCP won't access the bus due to the request
  8533. * to unload, and no function on the path can be
  8534. * loaded at this time.
  8535. */
  8536. wb_data[0] = REG_RD(bp, base_addr + offset);
  8537. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8538. vals->bmac_addr = base_addr + offset;
  8539. vals->bmac_val[0] = wb_data[0];
  8540. vals->bmac_val[1] = wb_data[1];
  8541. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8542. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8543. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8544. }
  8545. BNX2X_DEV_INFO("Disable emac Rx\n");
  8546. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8547. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8548. REG_WR(bp, vals->emac_addr, 0);
  8549. mac_stopped = true;
  8550. } else {
  8551. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8552. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8553. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8554. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8555. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8556. val & ~(1 << 1));
  8557. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8558. val | (1 << 1));
  8559. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8560. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8561. REG_WR(bp, vals->xmac_addr, 0);
  8562. mac_stopped = true;
  8563. }
  8564. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8565. if (mask & reset_reg) {
  8566. BNX2X_DEV_INFO("Disable umac Rx\n");
  8567. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8568. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8569. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8570. REG_WR(bp, vals->umac_addr, 0);
  8571. mac_stopped = true;
  8572. }
  8573. }
  8574. if (mac_stopped)
  8575. msleep(20);
  8576. }
  8577. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8578. #define BNX2X_PREV_UNDI_PROD_ADDR_H(f) (BAR_TSTRORM_INTMEM + \
  8579. 0x1848 + ((f) << 4))
  8580. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8581. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8582. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8583. #define BCM_5710_UNDI_FW_MF_MAJOR (0x07)
  8584. #define BCM_5710_UNDI_FW_MF_MINOR (0x08)
  8585. #define BCM_5710_UNDI_FW_MF_VERS (0x05)
  8586. static bool bnx2x_prev_is_after_undi(struct bnx2x *bp)
  8587. {
  8588. /* UNDI marks its presence in DORQ -
  8589. * it initializes CID offset for normal bell to 0x7
  8590. */
  8591. if (!(REG_RD(bp, MISC_REG_RESET_REG_1) &
  8592. MISC_REGISTERS_RESET_REG_1_RST_DORQ))
  8593. return false;
  8594. if (REG_RD(bp, DORQ_REG_NORM_CID_OFST) == 0x7) {
  8595. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8596. return true;
  8597. }
  8598. return false;
  8599. }
  8600. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 inc)
  8601. {
  8602. u16 rcq, bd;
  8603. u32 addr, tmp_reg;
  8604. if (BP_FUNC(bp) < 2)
  8605. addr = BNX2X_PREV_UNDI_PROD_ADDR(BP_PORT(bp));
  8606. else
  8607. addr = BNX2X_PREV_UNDI_PROD_ADDR_H(BP_FUNC(bp) - 2);
  8608. tmp_reg = REG_RD(bp, addr);
  8609. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8610. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8611. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8612. REG_WR(bp, addr, tmp_reg);
  8613. BNX2X_DEV_INFO("UNDI producer [%d/%d][%08x] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8614. BP_PORT(bp), BP_FUNC(bp), addr, bd, rcq);
  8615. }
  8616. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8617. {
  8618. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8619. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8620. if (!rc) {
  8621. BNX2X_ERR("MCP response failure, aborting\n");
  8622. return -EBUSY;
  8623. }
  8624. return 0;
  8625. }
  8626. static struct bnx2x_prev_path_list *
  8627. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8628. {
  8629. struct bnx2x_prev_path_list *tmp_list;
  8630. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8631. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8632. bp->pdev->bus->number == tmp_list->bus &&
  8633. BP_PATH(bp) == tmp_list->path)
  8634. return tmp_list;
  8635. return NULL;
  8636. }
  8637. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8638. {
  8639. struct bnx2x_prev_path_list *tmp_list;
  8640. int rc;
  8641. rc = down_interruptible(&bnx2x_prev_sem);
  8642. if (rc) {
  8643. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8644. return rc;
  8645. }
  8646. tmp_list = bnx2x_prev_path_get_entry(bp);
  8647. if (tmp_list) {
  8648. tmp_list->aer = 1;
  8649. rc = 0;
  8650. } else {
  8651. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8652. BP_PATH(bp));
  8653. }
  8654. up(&bnx2x_prev_sem);
  8655. return rc;
  8656. }
  8657. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8658. {
  8659. struct bnx2x_prev_path_list *tmp_list;
  8660. bool rc = false;
  8661. if (down_trylock(&bnx2x_prev_sem))
  8662. return false;
  8663. tmp_list = bnx2x_prev_path_get_entry(bp);
  8664. if (tmp_list) {
  8665. if (tmp_list->aer) {
  8666. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8667. BP_PATH(bp));
  8668. } else {
  8669. rc = true;
  8670. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8671. BP_PATH(bp));
  8672. }
  8673. }
  8674. up(&bnx2x_prev_sem);
  8675. return rc;
  8676. }
  8677. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8678. {
  8679. struct bnx2x_prev_path_list *entry;
  8680. bool val;
  8681. down(&bnx2x_prev_sem);
  8682. entry = bnx2x_prev_path_get_entry(bp);
  8683. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8684. up(&bnx2x_prev_sem);
  8685. return val;
  8686. }
  8687. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8688. {
  8689. struct bnx2x_prev_path_list *tmp_list;
  8690. int rc;
  8691. rc = down_interruptible(&bnx2x_prev_sem);
  8692. if (rc) {
  8693. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8694. return rc;
  8695. }
  8696. /* Check whether the entry for this path already exists */
  8697. tmp_list = bnx2x_prev_path_get_entry(bp);
  8698. if (tmp_list) {
  8699. if (!tmp_list->aer) {
  8700. BNX2X_ERR("Re-Marking the path.\n");
  8701. } else {
  8702. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8703. BP_PATH(bp));
  8704. tmp_list->aer = 0;
  8705. }
  8706. up(&bnx2x_prev_sem);
  8707. return 0;
  8708. }
  8709. up(&bnx2x_prev_sem);
  8710. /* Create an entry for this path and add it */
  8711. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8712. if (!tmp_list) {
  8713. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8714. return -ENOMEM;
  8715. }
  8716. tmp_list->bus = bp->pdev->bus->number;
  8717. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8718. tmp_list->path = BP_PATH(bp);
  8719. tmp_list->aer = 0;
  8720. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8721. rc = down_interruptible(&bnx2x_prev_sem);
  8722. if (rc) {
  8723. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8724. kfree(tmp_list);
  8725. } else {
  8726. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8727. BP_PATH(bp));
  8728. list_add(&tmp_list->list, &bnx2x_prev_list);
  8729. up(&bnx2x_prev_sem);
  8730. }
  8731. return rc;
  8732. }
  8733. static int bnx2x_do_flr(struct bnx2x *bp)
  8734. {
  8735. struct pci_dev *dev = bp->pdev;
  8736. if (CHIP_IS_E1x(bp)) {
  8737. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8738. return -EINVAL;
  8739. }
  8740. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8741. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8742. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8743. bp->common.bc_ver);
  8744. return -EINVAL;
  8745. }
  8746. if (!pci_wait_for_pending_transaction(dev))
  8747. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8748. BNX2X_DEV_INFO("Initiating FLR\n");
  8749. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8750. return 0;
  8751. }
  8752. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8753. {
  8754. int rc;
  8755. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8756. /* Test if previous unload process was already finished for this path */
  8757. if (bnx2x_prev_is_path_marked(bp))
  8758. return bnx2x_prev_mcp_done(bp);
  8759. BNX2X_DEV_INFO("Path is unmarked\n");
  8760. /* Cannot proceed with FLR if UNDI is loaded, since FW does not match */
  8761. if (bnx2x_prev_is_after_undi(bp))
  8762. goto out;
  8763. /* If function has FLR capabilities, and existing FW version matches
  8764. * the one required, then FLR will be sufficient to clean any residue
  8765. * left by previous driver
  8766. */
  8767. rc = bnx2x_compare_fw_ver(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION, false);
  8768. if (!rc) {
  8769. /* fw version is good */
  8770. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8771. rc = bnx2x_do_flr(bp);
  8772. }
  8773. if (!rc) {
  8774. /* FLR was performed */
  8775. BNX2X_DEV_INFO("FLR successful\n");
  8776. return 0;
  8777. }
  8778. BNX2X_DEV_INFO("Could not FLR\n");
  8779. out:
  8780. /* Close the MCP request, return failure*/
  8781. rc = bnx2x_prev_mcp_done(bp);
  8782. if (!rc)
  8783. rc = BNX2X_PREV_WAIT_NEEDED;
  8784. return rc;
  8785. }
  8786. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8787. {
  8788. u32 reset_reg, tmp_reg = 0, rc;
  8789. bool prev_undi = false;
  8790. struct bnx2x_mac_vals mac_vals;
  8791. /* It is possible a previous function received 'common' answer,
  8792. * but hasn't loaded yet, therefore creating a scenario of
  8793. * multiple functions receiving 'common' on the same path.
  8794. */
  8795. BNX2X_DEV_INFO("Common unload Flow\n");
  8796. memset(&mac_vals, 0, sizeof(mac_vals));
  8797. if (bnx2x_prev_is_path_marked(bp))
  8798. return bnx2x_prev_mcp_done(bp);
  8799. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8800. /* Reset should be performed after BRB is emptied */
  8801. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8802. u32 timer_count = 1000;
  8803. /* Close the MAC Rx to prevent BRB from filling up */
  8804. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8805. /* close LLH filters towards the BRB */
  8806. bnx2x_set_rx_filter(&bp->link_params, 0);
  8807. /* Check if the UNDI driver was previously loaded */
  8808. if (bnx2x_prev_is_after_undi(bp)) {
  8809. prev_undi = true;
  8810. /* clear the UNDI indication */
  8811. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8812. /* clear possible idle check errors */
  8813. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8814. }
  8815. if (!CHIP_IS_E1x(bp))
  8816. /* block FW from writing to host */
  8817. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8818. /* wait until BRB is empty */
  8819. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8820. while (timer_count) {
  8821. u32 prev_brb = tmp_reg;
  8822. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8823. if (!tmp_reg)
  8824. break;
  8825. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8826. /* reset timer as long as BRB actually gets emptied */
  8827. if (prev_brb > tmp_reg)
  8828. timer_count = 1000;
  8829. else
  8830. timer_count--;
  8831. /* If UNDI resides in memory, manually increment it */
  8832. if (prev_undi)
  8833. bnx2x_prev_unload_undi_inc(bp, 1);
  8834. udelay(10);
  8835. }
  8836. if (!timer_count)
  8837. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8838. }
  8839. /* No packets are in the pipeline, path is ready for reset */
  8840. bnx2x_reset_common(bp);
  8841. if (mac_vals.xmac_addr)
  8842. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8843. if (mac_vals.umac_addr)
  8844. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8845. if (mac_vals.emac_addr)
  8846. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8847. if (mac_vals.bmac_addr) {
  8848. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8849. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8850. }
  8851. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8852. if (rc) {
  8853. bnx2x_prev_mcp_done(bp);
  8854. return rc;
  8855. }
  8856. return bnx2x_prev_mcp_done(bp);
  8857. }
  8858. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8859. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8860. * the addresses of the transaction, resulting in was-error bit set in the pci
  8861. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8862. * to clear the interrupt which detected this from the pglueb and the was done
  8863. * bit
  8864. */
  8865. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8866. {
  8867. if (!CHIP_IS_E1x(bp)) {
  8868. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8869. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8870. DP(BNX2X_MSG_SP,
  8871. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8872. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8873. 1 << BP_FUNC(bp));
  8874. }
  8875. }
  8876. }
  8877. static int bnx2x_prev_unload(struct bnx2x *bp)
  8878. {
  8879. int time_counter = 10;
  8880. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8881. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8882. /* clear hw from errors which may have resulted from an interrupted
  8883. * dmae transaction.
  8884. */
  8885. bnx2x_prev_interrupted_dmae(bp);
  8886. /* Release previously held locks */
  8887. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8888. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8889. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8890. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8891. if (hw_lock_val) {
  8892. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8893. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8894. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8895. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8896. }
  8897. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8898. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8899. } else
  8900. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8901. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8902. BNX2X_DEV_INFO("Release previously held alr\n");
  8903. bnx2x_release_alr(bp);
  8904. }
  8905. do {
  8906. int aer = 0;
  8907. /* Lock MCP using an unload request */
  8908. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8909. if (!fw) {
  8910. BNX2X_ERR("MCP response failure, aborting\n");
  8911. rc = -EBUSY;
  8912. break;
  8913. }
  8914. rc = down_interruptible(&bnx2x_prev_sem);
  8915. if (rc) {
  8916. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8917. rc);
  8918. } else {
  8919. /* If Path is marked by EEH, ignore unload status */
  8920. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8921. bnx2x_prev_path_get_entry(bp)->aer);
  8922. up(&bnx2x_prev_sem);
  8923. }
  8924. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8925. rc = bnx2x_prev_unload_common(bp);
  8926. break;
  8927. }
  8928. /* non-common reply from MCP might require looping */
  8929. rc = bnx2x_prev_unload_uncommon(bp);
  8930. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8931. break;
  8932. msleep(20);
  8933. } while (--time_counter);
  8934. if (!time_counter || rc) {
  8935. BNX2X_DEV_INFO("Unloading previous driver did not occur, Possibly due to MF UNDI\n");
  8936. rc = -EPROBE_DEFER;
  8937. }
  8938. /* Mark function if its port was used to boot from SAN */
  8939. if (bnx2x_port_after_undi(bp))
  8940. bp->link_params.feature_config_flags |=
  8941. FEATURE_CONFIG_BOOT_FROM_SAN;
  8942. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8943. return rc;
  8944. }
  8945. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8946. {
  8947. u32 val, val2, val3, val4, id, boot_mode;
  8948. u16 pmc;
  8949. /* Get the chip revision id and number. */
  8950. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8951. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8952. id = ((val & 0xffff) << 16);
  8953. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8954. id |= ((val & 0xf) << 12);
  8955. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8956. * the configuration space (so we need to reg_rd)
  8957. */
  8958. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8959. id |= (((val >> 24) & 0xf) << 4);
  8960. val = REG_RD(bp, MISC_REG_BOND_ID);
  8961. id |= (val & 0xf);
  8962. bp->common.chip_id = id;
  8963. /* force 57811 according to MISC register */
  8964. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8965. if (CHIP_IS_57810(bp))
  8966. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8967. (bp->common.chip_id & 0x0000FFFF);
  8968. else if (CHIP_IS_57810_MF(bp))
  8969. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8970. (bp->common.chip_id & 0x0000FFFF);
  8971. bp->common.chip_id |= 0x1;
  8972. }
  8973. /* Set doorbell size */
  8974. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8975. if (!CHIP_IS_E1x(bp)) {
  8976. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8977. if ((val & 1) == 0)
  8978. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8979. else
  8980. val = (val >> 1) & 1;
  8981. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8982. "2_PORT_MODE");
  8983. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8984. CHIP_2_PORT_MODE;
  8985. if (CHIP_MODE_IS_4_PORT(bp))
  8986. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8987. else
  8988. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8989. } else {
  8990. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8991. bp->pfid = bp->pf_num; /* 0..7 */
  8992. }
  8993. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8994. bp->link_params.chip_id = bp->common.chip_id;
  8995. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8996. val = (REG_RD(bp, 0x2874) & 0x55);
  8997. if ((bp->common.chip_id & 0x1) ||
  8998. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8999. bp->flags |= ONE_PORT_FLAG;
  9000. BNX2X_DEV_INFO("single port device\n");
  9001. }
  9002. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  9003. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  9004. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  9005. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  9006. bp->common.flash_size, bp->common.flash_size);
  9007. bnx2x_init_shmem(bp);
  9008. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  9009. MISC_REG_GENERIC_CR_1 :
  9010. MISC_REG_GENERIC_CR_0));
  9011. bp->link_params.shmem_base = bp->common.shmem_base;
  9012. bp->link_params.shmem2_base = bp->common.shmem2_base;
  9013. if (SHMEM2_RD(bp, size) >
  9014. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  9015. bp->link_params.lfa_base =
  9016. REG_RD(bp, bp->common.shmem2_base +
  9017. (u32)offsetof(struct shmem2_region,
  9018. lfa_host_addr[BP_PORT(bp)]));
  9019. else
  9020. bp->link_params.lfa_base = 0;
  9021. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  9022. bp->common.shmem_base, bp->common.shmem2_base);
  9023. if (!bp->common.shmem_base) {
  9024. BNX2X_DEV_INFO("MCP not active\n");
  9025. bp->flags |= NO_MCP_FLAG;
  9026. return;
  9027. }
  9028. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  9029. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  9030. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  9031. SHARED_HW_CFG_LED_MODE_MASK) >>
  9032. SHARED_HW_CFG_LED_MODE_SHIFT);
  9033. bp->link_params.feature_config_flags = 0;
  9034. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  9035. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  9036. bp->link_params.feature_config_flags |=
  9037. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9038. else
  9039. bp->link_params.feature_config_flags &=
  9040. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  9041. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  9042. bp->common.bc_ver = val;
  9043. BNX2X_DEV_INFO("bc_ver %X\n", val);
  9044. if (val < BNX2X_BC_VER) {
  9045. /* for now only warn
  9046. * later we might need to enforce this */
  9047. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  9048. BNX2X_BC_VER, val);
  9049. }
  9050. bp->link_params.feature_config_flags |=
  9051. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  9052. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  9053. bp->link_params.feature_config_flags |=
  9054. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  9055. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  9056. bp->link_params.feature_config_flags |=
  9057. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  9058. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  9059. bp->link_params.feature_config_flags |=
  9060. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  9061. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  9062. bp->link_params.feature_config_flags |=
  9063. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  9064. FEATURE_CONFIG_MT_SUPPORT : 0;
  9065. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  9066. BC_SUPPORTS_PFC_STATS : 0;
  9067. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  9068. BC_SUPPORTS_FCOE_FEATURES : 0;
  9069. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  9070. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  9071. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  9072. BC_SUPPORTS_RMMOD_CMD : 0;
  9073. boot_mode = SHMEM_RD(bp,
  9074. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  9075. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  9076. switch (boot_mode) {
  9077. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  9078. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  9079. break;
  9080. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  9081. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  9082. break;
  9083. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  9084. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  9085. break;
  9086. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  9087. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  9088. break;
  9089. }
  9090. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  9091. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  9092. BNX2X_DEV_INFO("%sWoL capable\n",
  9093. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  9094. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  9095. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  9096. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  9097. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  9098. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  9099. val, val2, val3, val4);
  9100. }
  9101. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  9102. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  9103. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  9104. {
  9105. int pfid = BP_FUNC(bp);
  9106. int igu_sb_id;
  9107. u32 val;
  9108. u8 fid, igu_sb_cnt = 0;
  9109. bp->igu_base_sb = 0xff;
  9110. if (CHIP_INT_MODE_IS_BC(bp)) {
  9111. int vn = BP_VN(bp);
  9112. igu_sb_cnt = bp->igu_sb_cnt;
  9113. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  9114. FP_SB_MAX_E1x;
  9115. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  9116. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  9117. return 0;
  9118. }
  9119. /* IGU in normal mode - read CAM */
  9120. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  9121. igu_sb_id++) {
  9122. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  9123. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  9124. continue;
  9125. fid = IGU_FID(val);
  9126. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  9127. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  9128. continue;
  9129. if (IGU_VEC(val) == 0)
  9130. /* default status block */
  9131. bp->igu_dsb_id = igu_sb_id;
  9132. else {
  9133. if (bp->igu_base_sb == 0xff)
  9134. bp->igu_base_sb = igu_sb_id;
  9135. igu_sb_cnt++;
  9136. }
  9137. }
  9138. }
  9139. #ifdef CONFIG_PCI_MSI
  9140. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  9141. * optional that number of CAM entries will not be equal to the value
  9142. * advertised in PCI.
  9143. * Driver should use the minimal value of both as the actual status
  9144. * block count
  9145. */
  9146. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  9147. #endif
  9148. if (igu_sb_cnt == 0) {
  9149. BNX2X_ERR("CAM configuration error\n");
  9150. return -EINVAL;
  9151. }
  9152. return 0;
  9153. }
  9154. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  9155. {
  9156. int cfg_size = 0, idx, port = BP_PORT(bp);
  9157. /* Aggregation of supported attributes of all external phys */
  9158. bp->port.supported[0] = 0;
  9159. bp->port.supported[1] = 0;
  9160. switch (bp->link_params.num_phys) {
  9161. case 1:
  9162. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  9163. cfg_size = 1;
  9164. break;
  9165. case 2:
  9166. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  9167. cfg_size = 1;
  9168. break;
  9169. case 3:
  9170. if (bp->link_params.multi_phy_config &
  9171. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  9172. bp->port.supported[1] =
  9173. bp->link_params.phy[EXT_PHY1].supported;
  9174. bp->port.supported[0] =
  9175. bp->link_params.phy[EXT_PHY2].supported;
  9176. } else {
  9177. bp->port.supported[0] =
  9178. bp->link_params.phy[EXT_PHY1].supported;
  9179. bp->port.supported[1] =
  9180. bp->link_params.phy[EXT_PHY2].supported;
  9181. }
  9182. cfg_size = 2;
  9183. break;
  9184. }
  9185. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  9186. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  9187. SHMEM_RD(bp,
  9188. dev_info.port_hw_config[port].external_phy_config),
  9189. SHMEM_RD(bp,
  9190. dev_info.port_hw_config[port].external_phy_config2));
  9191. return;
  9192. }
  9193. if (CHIP_IS_E3(bp))
  9194. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  9195. else {
  9196. switch (switch_cfg) {
  9197. case SWITCH_CFG_1G:
  9198. bp->port.phy_addr = REG_RD(
  9199. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  9200. break;
  9201. case SWITCH_CFG_10G:
  9202. bp->port.phy_addr = REG_RD(
  9203. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  9204. break;
  9205. default:
  9206. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  9207. bp->port.link_config[0]);
  9208. return;
  9209. }
  9210. }
  9211. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  9212. /* mask what we support according to speed_cap_mask per configuration */
  9213. for (idx = 0; idx < cfg_size; idx++) {
  9214. if (!(bp->link_params.speed_cap_mask[idx] &
  9215. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  9216. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  9217. if (!(bp->link_params.speed_cap_mask[idx] &
  9218. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  9219. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  9220. if (!(bp->link_params.speed_cap_mask[idx] &
  9221. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  9222. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  9223. if (!(bp->link_params.speed_cap_mask[idx] &
  9224. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  9225. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  9226. if (!(bp->link_params.speed_cap_mask[idx] &
  9227. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  9228. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  9229. SUPPORTED_1000baseT_Full);
  9230. if (!(bp->link_params.speed_cap_mask[idx] &
  9231. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  9232. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  9233. if (!(bp->link_params.speed_cap_mask[idx] &
  9234. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  9235. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  9236. if (!(bp->link_params.speed_cap_mask[idx] &
  9237. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  9238. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  9239. }
  9240. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  9241. bp->port.supported[1]);
  9242. }
  9243. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  9244. {
  9245. u32 link_config, idx, cfg_size = 0;
  9246. bp->port.advertising[0] = 0;
  9247. bp->port.advertising[1] = 0;
  9248. switch (bp->link_params.num_phys) {
  9249. case 1:
  9250. case 2:
  9251. cfg_size = 1;
  9252. break;
  9253. case 3:
  9254. cfg_size = 2;
  9255. break;
  9256. }
  9257. for (idx = 0; idx < cfg_size; idx++) {
  9258. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  9259. link_config = bp->port.link_config[idx];
  9260. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  9261. case PORT_FEATURE_LINK_SPEED_AUTO:
  9262. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  9263. bp->link_params.req_line_speed[idx] =
  9264. SPEED_AUTO_NEG;
  9265. bp->port.advertising[idx] |=
  9266. bp->port.supported[idx];
  9267. if (bp->link_params.phy[EXT_PHY1].type ==
  9268. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  9269. bp->port.advertising[idx] |=
  9270. (SUPPORTED_100baseT_Half |
  9271. SUPPORTED_100baseT_Full);
  9272. } else {
  9273. /* force 10G, no AN */
  9274. bp->link_params.req_line_speed[idx] =
  9275. SPEED_10000;
  9276. bp->port.advertising[idx] |=
  9277. (ADVERTISED_10000baseT_Full |
  9278. ADVERTISED_FIBRE);
  9279. continue;
  9280. }
  9281. break;
  9282. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  9283. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  9284. bp->link_params.req_line_speed[idx] =
  9285. SPEED_10;
  9286. bp->port.advertising[idx] |=
  9287. (ADVERTISED_10baseT_Full |
  9288. ADVERTISED_TP);
  9289. } else {
  9290. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9291. link_config,
  9292. bp->link_params.speed_cap_mask[idx]);
  9293. return;
  9294. }
  9295. break;
  9296. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  9297. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  9298. bp->link_params.req_line_speed[idx] =
  9299. SPEED_10;
  9300. bp->link_params.req_duplex[idx] =
  9301. DUPLEX_HALF;
  9302. bp->port.advertising[idx] |=
  9303. (ADVERTISED_10baseT_Half |
  9304. ADVERTISED_TP);
  9305. } else {
  9306. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9307. link_config,
  9308. bp->link_params.speed_cap_mask[idx]);
  9309. return;
  9310. }
  9311. break;
  9312. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  9313. if (bp->port.supported[idx] &
  9314. SUPPORTED_100baseT_Full) {
  9315. bp->link_params.req_line_speed[idx] =
  9316. SPEED_100;
  9317. bp->port.advertising[idx] |=
  9318. (ADVERTISED_100baseT_Full |
  9319. ADVERTISED_TP);
  9320. } else {
  9321. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9322. link_config,
  9323. bp->link_params.speed_cap_mask[idx]);
  9324. return;
  9325. }
  9326. break;
  9327. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9328. if (bp->port.supported[idx] &
  9329. SUPPORTED_100baseT_Half) {
  9330. bp->link_params.req_line_speed[idx] =
  9331. SPEED_100;
  9332. bp->link_params.req_duplex[idx] =
  9333. DUPLEX_HALF;
  9334. bp->port.advertising[idx] |=
  9335. (ADVERTISED_100baseT_Half |
  9336. ADVERTISED_TP);
  9337. } else {
  9338. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9339. link_config,
  9340. bp->link_params.speed_cap_mask[idx]);
  9341. return;
  9342. }
  9343. break;
  9344. case PORT_FEATURE_LINK_SPEED_1G:
  9345. if (bp->port.supported[idx] &
  9346. SUPPORTED_1000baseT_Full) {
  9347. bp->link_params.req_line_speed[idx] =
  9348. SPEED_1000;
  9349. bp->port.advertising[idx] |=
  9350. (ADVERTISED_1000baseT_Full |
  9351. ADVERTISED_TP);
  9352. } else {
  9353. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9354. link_config,
  9355. bp->link_params.speed_cap_mask[idx]);
  9356. return;
  9357. }
  9358. break;
  9359. case PORT_FEATURE_LINK_SPEED_2_5G:
  9360. if (bp->port.supported[idx] &
  9361. SUPPORTED_2500baseX_Full) {
  9362. bp->link_params.req_line_speed[idx] =
  9363. SPEED_2500;
  9364. bp->port.advertising[idx] |=
  9365. (ADVERTISED_2500baseX_Full |
  9366. ADVERTISED_TP);
  9367. } else {
  9368. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9369. link_config,
  9370. bp->link_params.speed_cap_mask[idx]);
  9371. return;
  9372. }
  9373. break;
  9374. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9375. if (bp->port.supported[idx] &
  9376. SUPPORTED_10000baseT_Full) {
  9377. bp->link_params.req_line_speed[idx] =
  9378. SPEED_10000;
  9379. bp->port.advertising[idx] |=
  9380. (ADVERTISED_10000baseT_Full |
  9381. ADVERTISED_FIBRE);
  9382. } else {
  9383. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9384. link_config,
  9385. bp->link_params.speed_cap_mask[idx]);
  9386. return;
  9387. }
  9388. break;
  9389. case PORT_FEATURE_LINK_SPEED_20G:
  9390. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9391. break;
  9392. default:
  9393. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9394. link_config);
  9395. bp->link_params.req_line_speed[idx] =
  9396. SPEED_AUTO_NEG;
  9397. bp->port.advertising[idx] =
  9398. bp->port.supported[idx];
  9399. break;
  9400. }
  9401. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9402. PORT_FEATURE_FLOW_CONTROL_MASK);
  9403. if (bp->link_params.req_flow_ctrl[idx] ==
  9404. BNX2X_FLOW_CTRL_AUTO) {
  9405. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9406. bp->link_params.req_flow_ctrl[idx] =
  9407. BNX2X_FLOW_CTRL_NONE;
  9408. else
  9409. bnx2x_set_requested_fc(bp);
  9410. }
  9411. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9412. bp->link_params.req_line_speed[idx],
  9413. bp->link_params.req_duplex[idx],
  9414. bp->link_params.req_flow_ctrl[idx],
  9415. bp->port.advertising[idx]);
  9416. }
  9417. }
  9418. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9419. {
  9420. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9421. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9422. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9423. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9424. }
  9425. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9426. {
  9427. int port = BP_PORT(bp);
  9428. u32 config;
  9429. u32 ext_phy_type, ext_phy_config, eee_mode;
  9430. bp->link_params.bp = bp;
  9431. bp->link_params.port = port;
  9432. bp->link_params.lane_config =
  9433. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9434. bp->link_params.speed_cap_mask[0] =
  9435. SHMEM_RD(bp,
  9436. dev_info.port_hw_config[port].speed_capability_mask) &
  9437. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9438. bp->link_params.speed_cap_mask[1] =
  9439. SHMEM_RD(bp,
  9440. dev_info.port_hw_config[port].speed_capability_mask2) &
  9441. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9442. bp->port.link_config[0] =
  9443. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9444. bp->port.link_config[1] =
  9445. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9446. bp->link_params.multi_phy_config =
  9447. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9448. /* If the device is capable of WoL, set the default state according
  9449. * to the HW
  9450. */
  9451. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9452. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9453. (config & PORT_FEATURE_WOL_ENABLED));
  9454. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9455. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9456. bp->flags |= NO_ISCSI_FLAG;
  9457. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9458. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9459. bp->flags |= NO_FCOE_FLAG;
  9460. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9461. bp->link_params.lane_config,
  9462. bp->link_params.speed_cap_mask[0],
  9463. bp->port.link_config[0]);
  9464. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9465. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9466. bnx2x_phy_probe(&bp->link_params);
  9467. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9468. bnx2x_link_settings_requested(bp);
  9469. /*
  9470. * If connected directly, work with the internal PHY, otherwise, work
  9471. * with the external PHY
  9472. */
  9473. ext_phy_config =
  9474. SHMEM_RD(bp,
  9475. dev_info.port_hw_config[port].external_phy_config);
  9476. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9477. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9478. bp->mdio.prtad = bp->port.phy_addr;
  9479. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9480. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9481. bp->mdio.prtad =
  9482. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9483. /* Configure link feature according to nvram value */
  9484. eee_mode = (((SHMEM_RD(bp, dev_info.
  9485. port_feature_config[port].eee_power_mode)) &
  9486. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9487. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9488. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9489. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9490. EEE_MODE_ENABLE_LPI |
  9491. EEE_MODE_OUTPUT_TIME;
  9492. } else {
  9493. bp->link_params.eee_mode = 0;
  9494. }
  9495. }
  9496. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9497. {
  9498. u32 no_flags = NO_ISCSI_FLAG;
  9499. int port = BP_PORT(bp);
  9500. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9501. drv_lic_key[port].max_iscsi_conn);
  9502. if (!CNIC_SUPPORT(bp)) {
  9503. bp->flags |= no_flags;
  9504. return;
  9505. }
  9506. /* Get the number of maximum allowed iSCSI connections */
  9507. bp->cnic_eth_dev.max_iscsi_conn =
  9508. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9509. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9510. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9511. bp->cnic_eth_dev.max_iscsi_conn);
  9512. /*
  9513. * If maximum allowed number of connections is zero -
  9514. * disable the feature.
  9515. */
  9516. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9517. bp->flags |= no_flags;
  9518. }
  9519. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9520. {
  9521. /* Port info */
  9522. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9523. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9524. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9525. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9526. /* Node info */
  9527. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9528. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9529. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9530. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9531. }
  9532. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9533. {
  9534. u8 count = 0;
  9535. if (IS_MF(bp)) {
  9536. u8 fid;
  9537. /* iterate over absolute function ids for this path: */
  9538. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9539. if (IS_MF_SD(bp)) {
  9540. u32 cfg = MF_CFG_RD(bp,
  9541. func_mf_config[fid].config);
  9542. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9543. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9544. FUNC_MF_CFG_PROTOCOL_FCOE))
  9545. count++;
  9546. } else {
  9547. u32 cfg = MF_CFG_RD(bp,
  9548. func_ext_config[fid].
  9549. func_cfg);
  9550. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9551. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9552. count++;
  9553. }
  9554. }
  9555. } else { /* SF */
  9556. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9557. for (port = 0; port < port_cnt; port++) {
  9558. u32 lic = SHMEM_RD(bp,
  9559. drv_lic_key[port].max_fcoe_conn) ^
  9560. FW_ENCODE_32BIT_PATTERN;
  9561. if (lic)
  9562. count++;
  9563. }
  9564. }
  9565. return count;
  9566. }
  9567. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9568. {
  9569. int port = BP_PORT(bp);
  9570. int func = BP_ABS_FUNC(bp);
  9571. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9572. drv_lic_key[port].max_fcoe_conn);
  9573. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9574. if (!CNIC_SUPPORT(bp)) {
  9575. bp->flags |= NO_FCOE_FLAG;
  9576. return;
  9577. }
  9578. /* Get the number of maximum allowed FCoE connections */
  9579. bp->cnic_eth_dev.max_fcoe_conn =
  9580. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9581. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9582. /* Calculate the number of maximum allowed FCoE tasks */
  9583. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9584. /* check if FCoE resources must be shared between different functions */
  9585. if (num_fcoe_func)
  9586. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9587. /* Read the WWN: */
  9588. if (!IS_MF(bp)) {
  9589. /* Port info */
  9590. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9591. SHMEM_RD(bp,
  9592. dev_info.port_hw_config[port].
  9593. fcoe_wwn_port_name_upper);
  9594. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9595. SHMEM_RD(bp,
  9596. dev_info.port_hw_config[port].
  9597. fcoe_wwn_port_name_lower);
  9598. /* Node info */
  9599. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9600. SHMEM_RD(bp,
  9601. dev_info.port_hw_config[port].
  9602. fcoe_wwn_node_name_upper);
  9603. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9604. SHMEM_RD(bp,
  9605. dev_info.port_hw_config[port].
  9606. fcoe_wwn_node_name_lower);
  9607. } else if (!IS_MF_SD(bp)) {
  9608. /* Read the WWN info only if the FCoE feature is enabled for
  9609. * this function.
  9610. */
  9611. if (BNX2X_HAS_MF_EXT_PROTOCOL_FCOE(bp))
  9612. bnx2x_get_ext_wwn_info(bp, func);
  9613. } else {
  9614. if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9615. bnx2x_get_ext_wwn_info(bp, func);
  9616. }
  9617. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9618. /*
  9619. * If maximum allowed number of connections is zero -
  9620. * disable the feature.
  9621. */
  9622. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9623. bp->flags |= NO_FCOE_FLAG;
  9624. }
  9625. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9626. {
  9627. /*
  9628. * iSCSI may be dynamically disabled but reading
  9629. * info here we will decrease memory usage by driver
  9630. * if the feature is disabled for good
  9631. */
  9632. bnx2x_get_iscsi_info(bp);
  9633. bnx2x_get_fcoe_info(bp);
  9634. }
  9635. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9636. {
  9637. u32 val, val2;
  9638. int func = BP_ABS_FUNC(bp);
  9639. int port = BP_PORT(bp);
  9640. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9641. u8 *fip_mac = bp->fip_mac;
  9642. if (IS_MF(bp)) {
  9643. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9644. * FCoE MAC then the appropriate feature should be disabled.
  9645. * In non SD mode features configuration comes from struct
  9646. * func_ext_config.
  9647. */
  9648. if (!IS_MF_SD(bp)) {
  9649. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9650. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9651. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9652. iscsi_mac_addr_upper);
  9653. val = MF_CFG_RD(bp, func_ext_config[func].
  9654. iscsi_mac_addr_lower);
  9655. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9656. BNX2X_DEV_INFO
  9657. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9658. } else {
  9659. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9660. }
  9661. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9662. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9663. fcoe_mac_addr_upper);
  9664. val = MF_CFG_RD(bp, func_ext_config[func].
  9665. fcoe_mac_addr_lower);
  9666. bnx2x_set_mac_buf(fip_mac, val, val2);
  9667. BNX2X_DEV_INFO
  9668. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9669. } else {
  9670. bp->flags |= NO_FCOE_FLAG;
  9671. }
  9672. bp->mf_ext_config = cfg;
  9673. } else { /* SD MODE */
  9674. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9675. /* use primary mac as iscsi mac */
  9676. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9677. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9678. BNX2X_DEV_INFO
  9679. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9680. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9681. /* use primary mac as fip mac */
  9682. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9683. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9684. BNX2X_DEV_INFO
  9685. ("Read FIP MAC: %pM\n", fip_mac);
  9686. }
  9687. }
  9688. /* If this is a storage-only interface, use SAN mac as
  9689. * primary MAC. Notice that for SD this is already the case,
  9690. * as the SAN mac was copied from the primary MAC.
  9691. */
  9692. if (IS_MF_FCOE_AFEX(bp))
  9693. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9694. } else {
  9695. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9696. iscsi_mac_upper);
  9697. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9698. iscsi_mac_lower);
  9699. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9700. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9701. fcoe_fip_mac_upper);
  9702. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9703. fcoe_fip_mac_lower);
  9704. bnx2x_set_mac_buf(fip_mac, val, val2);
  9705. }
  9706. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9707. if (!is_valid_ether_addr(iscsi_mac)) {
  9708. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9709. memset(iscsi_mac, 0, ETH_ALEN);
  9710. }
  9711. /* Disable FCoE if MAC configuration is invalid. */
  9712. if (!is_valid_ether_addr(fip_mac)) {
  9713. bp->flags |= NO_FCOE_FLAG;
  9714. memset(bp->fip_mac, 0, ETH_ALEN);
  9715. }
  9716. }
  9717. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9718. {
  9719. u32 val, val2;
  9720. int func = BP_ABS_FUNC(bp);
  9721. int port = BP_PORT(bp);
  9722. /* Zero primary MAC configuration */
  9723. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9724. if (BP_NOMCP(bp)) {
  9725. BNX2X_ERROR("warning: random MAC workaround active\n");
  9726. eth_hw_addr_random(bp->dev);
  9727. } else if (IS_MF(bp)) {
  9728. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9729. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9730. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9731. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9732. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9733. if (CNIC_SUPPORT(bp))
  9734. bnx2x_get_cnic_mac_hwinfo(bp);
  9735. } else {
  9736. /* in SF read MACs from port configuration */
  9737. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9738. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9739. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9740. if (CNIC_SUPPORT(bp))
  9741. bnx2x_get_cnic_mac_hwinfo(bp);
  9742. }
  9743. if (!BP_NOMCP(bp)) {
  9744. /* Read physical port identifier from shmem */
  9745. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9746. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9747. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9748. bp->flags |= HAS_PHYS_PORT_ID;
  9749. }
  9750. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9751. if (!is_valid_ether_addr(bp->dev->dev_addr))
  9752. dev_err(&bp->pdev->dev,
  9753. "bad Ethernet MAC address configuration: %pM\n"
  9754. "change it manually before bringing up the appropriate network interface\n",
  9755. bp->dev->dev_addr);
  9756. }
  9757. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9758. {
  9759. int tmp;
  9760. u32 cfg;
  9761. if (IS_VF(bp))
  9762. return 0;
  9763. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9764. /* Take function: tmp = func */
  9765. tmp = BP_ABS_FUNC(bp);
  9766. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9767. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9768. } else {
  9769. /* Take port: tmp = port */
  9770. tmp = BP_PORT(bp);
  9771. cfg = SHMEM_RD(bp,
  9772. dev_info.port_hw_config[tmp].generic_features);
  9773. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9774. }
  9775. return cfg;
  9776. }
  9777. static void validate_set_si_mode(struct bnx2x *bp)
  9778. {
  9779. u8 func = BP_ABS_FUNC(bp);
  9780. u32 val;
  9781. val = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9782. /* check for legal mac (upper bytes) */
  9783. if (val != 0xffff) {
  9784. bp->mf_mode = MULTI_FUNCTION_SI;
  9785. bp->mf_config[BP_VN(bp)] =
  9786. MF_CFG_RD(bp, func_mf_config[func].config);
  9787. } else
  9788. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9789. }
  9790. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9791. {
  9792. int /*abs*/func = BP_ABS_FUNC(bp);
  9793. int vn;
  9794. u32 val = 0, val2 = 0;
  9795. int rc = 0;
  9796. bnx2x_get_common_hwinfo(bp);
  9797. /*
  9798. * initialize IGU parameters
  9799. */
  9800. if (CHIP_IS_E1x(bp)) {
  9801. bp->common.int_block = INT_BLOCK_HC;
  9802. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9803. bp->igu_base_sb = 0;
  9804. } else {
  9805. bp->common.int_block = INT_BLOCK_IGU;
  9806. /* do not allow device reset during IGU info processing */
  9807. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9808. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9809. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9810. int tout = 5000;
  9811. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9812. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9813. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9814. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9815. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9816. tout--;
  9817. usleep_range(1000, 2000);
  9818. }
  9819. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9820. dev_err(&bp->pdev->dev,
  9821. "FORCING Normal Mode failed!!!\n");
  9822. bnx2x_release_hw_lock(bp,
  9823. HW_LOCK_RESOURCE_RESET);
  9824. return -EPERM;
  9825. }
  9826. }
  9827. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9828. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9829. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9830. } else
  9831. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9832. rc = bnx2x_get_igu_cam_info(bp);
  9833. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9834. if (rc)
  9835. return rc;
  9836. }
  9837. /*
  9838. * set base FW non-default (fast path) status block id, this value is
  9839. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9840. * determine the id used by the FW.
  9841. */
  9842. if (CHIP_IS_E1x(bp))
  9843. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9844. else /*
  9845. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9846. * the same queue are indicated on the same IGU SB). So we prefer
  9847. * FW and IGU SBs to be the same value.
  9848. */
  9849. bp->base_fw_ndsb = bp->igu_base_sb;
  9850. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9851. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9852. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9853. /*
  9854. * Initialize MF configuration
  9855. */
  9856. bp->mf_ov = 0;
  9857. bp->mf_mode = 0;
  9858. bp->mf_sub_mode = 0;
  9859. vn = BP_VN(bp);
  9860. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9861. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9862. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9863. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9864. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9865. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9866. else
  9867. bp->common.mf_cfg_base = bp->common.shmem_base +
  9868. offsetof(struct shmem_region, func_mb) +
  9869. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9870. /*
  9871. * get mf configuration:
  9872. * 1. Existence of MF configuration
  9873. * 2. MAC address must be legal (check only upper bytes)
  9874. * for Switch-Independent mode;
  9875. * OVLAN must be legal for Switch-Dependent mode
  9876. * 3. SF_MODE configures specific MF mode
  9877. */
  9878. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9879. /* get mf configuration */
  9880. val = SHMEM_RD(bp,
  9881. dev_info.shared_feature_config.config);
  9882. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9883. switch (val) {
  9884. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9885. validate_set_si_mode(bp);
  9886. break;
  9887. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9888. if ((!CHIP_IS_E1x(bp)) &&
  9889. (MF_CFG_RD(bp, func_mf_config[func].
  9890. mac_upper) != 0xffff) &&
  9891. (SHMEM2_HAS(bp,
  9892. afex_driver_support))) {
  9893. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9894. bp->mf_config[vn] = MF_CFG_RD(bp,
  9895. func_mf_config[func].config);
  9896. } else {
  9897. BNX2X_DEV_INFO("can not configure afex mode\n");
  9898. }
  9899. break;
  9900. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9901. /* get OV configuration */
  9902. val = MF_CFG_RD(bp,
  9903. func_mf_config[FUNC_0].e1hov_tag);
  9904. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9905. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9906. bp->mf_mode = MULTI_FUNCTION_SD;
  9907. bp->mf_config[vn] = MF_CFG_RD(bp,
  9908. func_mf_config[func].config);
  9909. } else
  9910. BNX2X_DEV_INFO("illegal OV for SD\n");
  9911. break;
  9912. case SHARED_FEAT_CFG_FORCE_SF_MODE_UFP_MODE:
  9913. bp->mf_mode = MULTI_FUNCTION_SD;
  9914. bp->mf_sub_mode = SUB_MF_MODE_UFP;
  9915. bp->mf_config[vn] =
  9916. MF_CFG_RD(bp,
  9917. func_mf_config[func].config);
  9918. break;
  9919. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9920. bp->mf_config[vn] = 0;
  9921. break;
  9922. case SHARED_FEAT_CFG_FORCE_SF_MODE_EXTENDED_MODE:
  9923. val2 = SHMEM_RD(bp,
  9924. dev_info.shared_hw_config.config_3);
  9925. val2 &= SHARED_HW_CFG_EXTENDED_MF_MODE_MASK;
  9926. switch (val2) {
  9927. case SHARED_HW_CFG_EXTENDED_MF_MODE_NPAR1_DOT_5:
  9928. validate_set_si_mode(bp);
  9929. bp->mf_sub_mode =
  9930. SUB_MF_MODE_NPAR1_DOT_5;
  9931. break;
  9932. default:
  9933. /* Unknown configuration */
  9934. bp->mf_config[vn] = 0;
  9935. BNX2X_DEV_INFO("unknown extended MF mode 0x%x\n",
  9936. val);
  9937. }
  9938. break;
  9939. default:
  9940. /* Unknown configuration: reset mf_config */
  9941. bp->mf_config[vn] = 0;
  9942. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9943. }
  9944. }
  9945. BNX2X_DEV_INFO("%s function mode\n",
  9946. IS_MF(bp) ? "multi" : "single");
  9947. switch (bp->mf_mode) {
  9948. case MULTI_FUNCTION_SD:
  9949. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9950. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9951. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9952. bp->mf_ov = val;
  9953. bp->path_has_ovlan = true;
  9954. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9955. func, bp->mf_ov, bp->mf_ov);
  9956. } else if (bp->mf_sub_mode == SUB_MF_MODE_UFP) {
  9957. dev_err(&bp->pdev->dev,
  9958. "Unexpected - no valid MF OV for func %d in UFP mode\n",
  9959. func);
  9960. bp->path_has_ovlan = true;
  9961. } else {
  9962. dev_err(&bp->pdev->dev,
  9963. "No valid MF OV for func %d, aborting\n",
  9964. func);
  9965. return -EPERM;
  9966. }
  9967. break;
  9968. case MULTI_FUNCTION_AFEX:
  9969. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9970. break;
  9971. case MULTI_FUNCTION_SI:
  9972. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9973. func);
  9974. break;
  9975. default:
  9976. if (vn) {
  9977. dev_err(&bp->pdev->dev,
  9978. "VN %d is in a single function mode, aborting\n",
  9979. vn);
  9980. return -EPERM;
  9981. }
  9982. break;
  9983. }
  9984. /* check if other port on the path needs ovlan:
  9985. * Since MF configuration is shared between ports
  9986. * Possible mixed modes are only
  9987. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9988. */
  9989. if (CHIP_MODE_IS_4_PORT(bp) &&
  9990. !bp->path_has_ovlan &&
  9991. !IS_MF(bp) &&
  9992. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9993. u8 other_port = !BP_PORT(bp);
  9994. u8 other_func = BP_PATH(bp) + 2*other_port;
  9995. val = MF_CFG_RD(bp,
  9996. func_mf_config[other_func].e1hov_tag);
  9997. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9998. bp->path_has_ovlan = true;
  9999. }
  10000. }
  10001. /* adjust igu_sb_cnt to MF for E1H */
  10002. if (CHIP_IS_E1H(bp) && IS_MF(bp))
  10003. bp->igu_sb_cnt = min_t(u8, bp->igu_sb_cnt, E1H_MAX_MF_SB_COUNT);
  10004. /* port info */
  10005. bnx2x_get_port_hwinfo(bp);
  10006. /* Get MAC addresses */
  10007. bnx2x_get_mac_hwinfo(bp);
  10008. bnx2x_get_cnic_info(bp);
  10009. return rc;
  10010. }
  10011. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  10012. {
  10013. int cnt, i, block_end, rodi;
  10014. char vpd_start[BNX2X_VPD_LEN+1];
  10015. char str_id_reg[VENDOR_ID_LEN+1];
  10016. char str_id_cap[VENDOR_ID_LEN+1];
  10017. char *vpd_data;
  10018. char *vpd_extended_data = NULL;
  10019. u8 len;
  10020. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  10021. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  10022. if (cnt < BNX2X_VPD_LEN)
  10023. goto out_not_found;
  10024. /* VPD RO tag should be first tag after identifier string, hence
  10025. * we should be able to find it in first BNX2X_VPD_LEN chars
  10026. */
  10027. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  10028. PCI_VPD_LRDT_RO_DATA);
  10029. if (i < 0)
  10030. goto out_not_found;
  10031. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  10032. pci_vpd_lrdt_size(&vpd_start[i]);
  10033. i += PCI_VPD_LRDT_TAG_SIZE;
  10034. if (block_end > BNX2X_VPD_LEN) {
  10035. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  10036. if (vpd_extended_data == NULL)
  10037. goto out_not_found;
  10038. /* read rest of vpd image into vpd_extended_data */
  10039. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  10040. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  10041. block_end - BNX2X_VPD_LEN,
  10042. vpd_extended_data + BNX2X_VPD_LEN);
  10043. if (cnt < (block_end - BNX2X_VPD_LEN))
  10044. goto out_not_found;
  10045. vpd_data = vpd_extended_data;
  10046. } else
  10047. vpd_data = vpd_start;
  10048. /* now vpd_data holds full vpd content in both cases */
  10049. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10050. PCI_VPD_RO_KEYWORD_MFR_ID);
  10051. if (rodi < 0)
  10052. goto out_not_found;
  10053. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10054. if (len != VENDOR_ID_LEN)
  10055. goto out_not_found;
  10056. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10057. /* vendor specific info */
  10058. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  10059. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  10060. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  10061. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  10062. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  10063. PCI_VPD_RO_KEYWORD_VENDOR0);
  10064. if (rodi >= 0) {
  10065. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  10066. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  10067. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  10068. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  10069. bp->fw_ver[len] = ' ';
  10070. }
  10071. }
  10072. kfree(vpd_extended_data);
  10073. return;
  10074. }
  10075. out_not_found:
  10076. kfree(vpd_extended_data);
  10077. return;
  10078. }
  10079. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  10080. {
  10081. u32 flags = 0;
  10082. if (CHIP_REV_IS_FPGA(bp))
  10083. SET_FLAGS(flags, MODE_FPGA);
  10084. else if (CHIP_REV_IS_EMUL(bp))
  10085. SET_FLAGS(flags, MODE_EMUL);
  10086. else
  10087. SET_FLAGS(flags, MODE_ASIC);
  10088. if (CHIP_MODE_IS_4_PORT(bp))
  10089. SET_FLAGS(flags, MODE_PORT4);
  10090. else
  10091. SET_FLAGS(flags, MODE_PORT2);
  10092. if (CHIP_IS_E2(bp))
  10093. SET_FLAGS(flags, MODE_E2);
  10094. else if (CHIP_IS_E3(bp)) {
  10095. SET_FLAGS(flags, MODE_E3);
  10096. if (CHIP_REV(bp) == CHIP_REV_Ax)
  10097. SET_FLAGS(flags, MODE_E3_A0);
  10098. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  10099. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  10100. }
  10101. if (IS_MF(bp)) {
  10102. SET_FLAGS(flags, MODE_MF);
  10103. switch (bp->mf_mode) {
  10104. case MULTI_FUNCTION_SD:
  10105. SET_FLAGS(flags, MODE_MF_SD);
  10106. break;
  10107. case MULTI_FUNCTION_SI:
  10108. SET_FLAGS(flags, MODE_MF_SI);
  10109. break;
  10110. case MULTI_FUNCTION_AFEX:
  10111. SET_FLAGS(flags, MODE_MF_AFEX);
  10112. break;
  10113. }
  10114. } else
  10115. SET_FLAGS(flags, MODE_SF);
  10116. #if defined(__LITTLE_ENDIAN)
  10117. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  10118. #else /*(__BIG_ENDIAN)*/
  10119. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  10120. #endif
  10121. INIT_MODE_FLAGS(bp) = flags;
  10122. }
  10123. static int bnx2x_init_bp(struct bnx2x *bp)
  10124. {
  10125. int func;
  10126. int rc;
  10127. mutex_init(&bp->port.phy_mutex);
  10128. mutex_init(&bp->fw_mb_mutex);
  10129. mutex_init(&bp->drv_info_mutex);
  10130. bp->drv_info_mng_owner = false;
  10131. spin_lock_init(&bp->stats_lock);
  10132. sema_init(&bp->stats_sema, 1);
  10133. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  10134. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  10135. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  10136. INIT_DELAYED_WORK(&bp->iov_task, bnx2x_iov_task);
  10137. if (IS_PF(bp)) {
  10138. rc = bnx2x_get_hwinfo(bp);
  10139. if (rc)
  10140. return rc;
  10141. } else {
  10142. eth_zero_addr(bp->dev->dev_addr);
  10143. }
  10144. bnx2x_set_modes_bitmap(bp);
  10145. rc = bnx2x_alloc_mem_bp(bp);
  10146. if (rc)
  10147. return rc;
  10148. bnx2x_read_fwinfo(bp);
  10149. func = BP_FUNC(bp);
  10150. /* need to reset chip if undi was active */
  10151. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  10152. /* init fw_seq */
  10153. bp->fw_seq =
  10154. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10155. DRV_MSG_SEQ_NUMBER_MASK;
  10156. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10157. rc = bnx2x_prev_unload(bp);
  10158. if (rc) {
  10159. bnx2x_free_mem_bp(bp);
  10160. return rc;
  10161. }
  10162. }
  10163. if (CHIP_REV_IS_FPGA(bp))
  10164. dev_err(&bp->pdev->dev, "FPGA detected\n");
  10165. if (BP_NOMCP(bp) && (func == 0))
  10166. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  10167. bp->disable_tpa = disable_tpa;
  10168. bp->disable_tpa |= !!IS_MF_STORAGE_ONLY(bp);
  10169. /* Reduce memory usage in kdump environment by disabling TPA */
  10170. bp->disable_tpa |= is_kdump_kernel();
  10171. /* Set TPA flags */
  10172. if (bp->disable_tpa) {
  10173. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10174. bp->dev->features &= ~NETIF_F_LRO;
  10175. } else {
  10176. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  10177. bp->dev->features |= NETIF_F_LRO;
  10178. }
  10179. if (CHIP_IS_E1(bp))
  10180. bp->dropless_fc = 0;
  10181. else
  10182. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  10183. bp->mrrs = mrrs;
  10184. bp->tx_ring_size = IS_MF_STORAGE_ONLY(bp) ? 0 : MAX_TX_AVAIL;
  10185. if (IS_VF(bp))
  10186. bp->rx_ring_size = MAX_RX_AVAIL;
  10187. /* make sure that the numbers are in the right granularity */
  10188. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  10189. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  10190. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  10191. init_timer(&bp->timer);
  10192. bp->timer.expires = jiffies + bp->current_interval;
  10193. bp->timer.data = (unsigned long) bp;
  10194. bp->timer.function = bnx2x_timer;
  10195. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  10196. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  10197. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  10198. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  10199. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  10200. bnx2x_dcbx_init_params(bp);
  10201. } else {
  10202. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  10203. }
  10204. if (CHIP_IS_E1x(bp))
  10205. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  10206. else
  10207. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  10208. /* multiple tx priority */
  10209. if (IS_VF(bp))
  10210. bp->max_cos = 1;
  10211. else if (CHIP_IS_E1x(bp))
  10212. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  10213. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  10214. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  10215. else if (CHIP_IS_E3B0(bp))
  10216. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  10217. else
  10218. BNX2X_ERR("unknown chip %x revision %x\n",
  10219. CHIP_NUM(bp), CHIP_REV(bp));
  10220. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  10221. /* We need at least one default status block for slow-path events,
  10222. * second status block for the L2 queue, and a third status block for
  10223. * CNIC if supported.
  10224. */
  10225. if (IS_VF(bp))
  10226. bp->min_msix_vec_cnt = 1;
  10227. else if (CNIC_SUPPORT(bp))
  10228. bp->min_msix_vec_cnt = 3;
  10229. else /* PF w/o cnic */
  10230. bp->min_msix_vec_cnt = 2;
  10231. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  10232. bp->dump_preset_idx = 1;
  10233. if (CHIP_IS_E3B0(bp))
  10234. bp->flags |= PTP_SUPPORTED;
  10235. return rc;
  10236. }
  10237. /****************************************************************************
  10238. * General service functions
  10239. ****************************************************************************/
  10240. /*
  10241. * net_device service functions
  10242. */
  10243. /* called with rtnl_lock */
  10244. static int bnx2x_open(struct net_device *dev)
  10245. {
  10246. struct bnx2x *bp = netdev_priv(dev);
  10247. int rc;
  10248. bp->stats_init = true;
  10249. netif_carrier_off(dev);
  10250. bnx2x_set_power_state(bp, PCI_D0);
  10251. /* If parity had happen during the unload, then attentions
  10252. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  10253. * want the first function loaded on the current engine to
  10254. * complete the recovery.
  10255. * Parity recovery is only relevant for PF driver.
  10256. */
  10257. if (IS_PF(bp)) {
  10258. int other_engine = BP_PATH(bp) ? 0 : 1;
  10259. bool other_load_status, load_status;
  10260. bool global = false;
  10261. other_load_status = bnx2x_get_load_status(bp, other_engine);
  10262. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  10263. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  10264. bnx2x_chk_parity_attn(bp, &global, true)) {
  10265. do {
  10266. /* If there are attentions and they are in a
  10267. * global blocks, set the GLOBAL_RESET bit
  10268. * regardless whether it will be this function
  10269. * that will complete the recovery or not.
  10270. */
  10271. if (global)
  10272. bnx2x_set_reset_global(bp);
  10273. /* Only the first function on the current
  10274. * engine should try to recover in open. In case
  10275. * of attentions in global blocks only the first
  10276. * in the chip should try to recover.
  10277. */
  10278. if ((!load_status &&
  10279. (!global || !other_load_status)) &&
  10280. bnx2x_trylock_leader_lock(bp) &&
  10281. !bnx2x_leader_reset(bp)) {
  10282. netdev_info(bp->dev,
  10283. "Recovered in open\n");
  10284. break;
  10285. }
  10286. /* recovery has failed... */
  10287. bnx2x_set_power_state(bp, PCI_D3hot);
  10288. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  10289. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  10290. "If you still see this message after a few retries then power cycle is required.\n");
  10291. return -EAGAIN;
  10292. } while (0);
  10293. }
  10294. }
  10295. bp->recovery_state = BNX2X_RECOVERY_DONE;
  10296. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10297. if (rc)
  10298. return rc;
  10299. return 0;
  10300. }
  10301. /* called with rtnl_lock */
  10302. static int bnx2x_close(struct net_device *dev)
  10303. {
  10304. struct bnx2x *bp = netdev_priv(dev);
  10305. /* Unload the driver, release IRQs */
  10306. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  10307. return 0;
  10308. }
  10309. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  10310. struct bnx2x_mcast_ramrod_params *p)
  10311. {
  10312. int mc_count = netdev_mc_count(bp->dev);
  10313. struct bnx2x_mcast_list_elem *mc_mac =
  10314. kcalloc(mc_count, sizeof(*mc_mac), GFP_ATOMIC);
  10315. struct netdev_hw_addr *ha;
  10316. if (!mc_mac)
  10317. return -ENOMEM;
  10318. INIT_LIST_HEAD(&p->mcast_list);
  10319. netdev_for_each_mc_addr(ha, bp->dev) {
  10320. mc_mac->mac = bnx2x_mc_addr(ha);
  10321. list_add_tail(&mc_mac->link, &p->mcast_list);
  10322. mc_mac++;
  10323. }
  10324. p->mcast_list_len = mc_count;
  10325. return 0;
  10326. }
  10327. static void bnx2x_free_mcast_macs_list(
  10328. struct bnx2x_mcast_ramrod_params *p)
  10329. {
  10330. struct bnx2x_mcast_list_elem *mc_mac =
  10331. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  10332. link);
  10333. WARN_ON(!mc_mac);
  10334. kfree(mc_mac);
  10335. }
  10336. /**
  10337. * bnx2x_set_uc_list - configure a new unicast MACs list.
  10338. *
  10339. * @bp: driver handle
  10340. *
  10341. * We will use zero (0) as a MAC type for these MACs.
  10342. */
  10343. static int bnx2x_set_uc_list(struct bnx2x *bp)
  10344. {
  10345. int rc;
  10346. struct net_device *dev = bp->dev;
  10347. struct netdev_hw_addr *ha;
  10348. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  10349. unsigned long ramrod_flags = 0;
  10350. /* First schedule a cleanup up of old configuration */
  10351. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  10352. if (rc < 0) {
  10353. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  10354. return rc;
  10355. }
  10356. netdev_for_each_uc_addr(ha, dev) {
  10357. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  10358. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10359. if (rc == -EEXIST) {
  10360. DP(BNX2X_MSG_SP,
  10361. "Failed to schedule ADD operations: %d\n", rc);
  10362. /* do not treat adding same MAC as error */
  10363. rc = 0;
  10364. } else if (rc < 0) {
  10365. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  10366. rc);
  10367. return rc;
  10368. }
  10369. }
  10370. /* Execute the pending commands */
  10371. __set_bit(RAMROD_CONT, &ramrod_flags);
  10372. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10373. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10374. }
  10375. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10376. {
  10377. struct net_device *dev = bp->dev;
  10378. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10379. int rc = 0;
  10380. rparam.mcast_obj = &bp->mcast_obj;
  10381. /* first, clear all configured multicast MACs */
  10382. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10383. if (rc < 0) {
  10384. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10385. return rc;
  10386. }
  10387. /* then, configure a new MACs list */
  10388. if (netdev_mc_count(dev)) {
  10389. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10390. if (rc) {
  10391. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10392. rc);
  10393. return rc;
  10394. }
  10395. /* Now add the new MACs */
  10396. rc = bnx2x_config_mcast(bp, &rparam,
  10397. BNX2X_MCAST_CMD_ADD);
  10398. if (rc < 0)
  10399. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10400. rc);
  10401. bnx2x_free_mcast_macs_list(&rparam);
  10402. }
  10403. return rc;
  10404. }
  10405. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10406. static void bnx2x_set_rx_mode(struct net_device *dev)
  10407. {
  10408. struct bnx2x *bp = netdev_priv(dev);
  10409. if (bp->state != BNX2X_STATE_OPEN) {
  10410. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10411. return;
  10412. } else {
  10413. /* Schedule an SP task to handle rest of change */
  10414. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_RX_MODE,
  10415. NETIF_MSG_IFUP);
  10416. }
  10417. }
  10418. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10419. {
  10420. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10421. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10422. netif_addr_lock_bh(bp->dev);
  10423. if (bp->dev->flags & IFF_PROMISC) {
  10424. rx_mode = BNX2X_RX_MODE_PROMISC;
  10425. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10426. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10427. CHIP_IS_E1(bp))) {
  10428. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10429. } else {
  10430. if (IS_PF(bp)) {
  10431. /* some multicasts */
  10432. if (bnx2x_set_mc_list(bp) < 0)
  10433. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10434. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10435. netif_addr_unlock_bh(bp->dev);
  10436. if (bnx2x_set_uc_list(bp) < 0)
  10437. rx_mode = BNX2X_RX_MODE_PROMISC;
  10438. netif_addr_lock_bh(bp->dev);
  10439. } else {
  10440. /* configuring mcast to a vf involves sleeping (when we
  10441. * wait for the pf's response).
  10442. */
  10443. bnx2x_schedule_sp_rtnl(bp,
  10444. BNX2X_SP_RTNL_VFPF_MCAST, 0);
  10445. }
  10446. }
  10447. bp->rx_mode = rx_mode;
  10448. /* handle ISCSI SD mode */
  10449. if (IS_MF_ISCSI_ONLY(bp))
  10450. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10451. /* Schedule the rx_mode command */
  10452. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10453. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10454. netif_addr_unlock_bh(bp->dev);
  10455. return;
  10456. }
  10457. if (IS_PF(bp)) {
  10458. bnx2x_set_storm_rx_mode(bp);
  10459. netif_addr_unlock_bh(bp->dev);
  10460. } else {
  10461. /* VF will need to request the PF to make this change, and so
  10462. * the VF needs to release the bottom-half lock prior to the
  10463. * request (as it will likely require sleep on the VF side)
  10464. */
  10465. netif_addr_unlock_bh(bp->dev);
  10466. bnx2x_vfpf_storm_rx_mode(bp);
  10467. }
  10468. }
  10469. /* called with rtnl_lock */
  10470. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10471. int devad, u16 addr)
  10472. {
  10473. struct bnx2x *bp = netdev_priv(netdev);
  10474. u16 value;
  10475. int rc;
  10476. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10477. prtad, devad, addr);
  10478. /* The HW expects different devad if CL22 is used */
  10479. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10480. bnx2x_acquire_phy_lock(bp);
  10481. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10482. bnx2x_release_phy_lock(bp);
  10483. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10484. if (!rc)
  10485. rc = value;
  10486. return rc;
  10487. }
  10488. /* called with rtnl_lock */
  10489. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10490. u16 addr, u16 value)
  10491. {
  10492. struct bnx2x *bp = netdev_priv(netdev);
  10493. int rc;
  10494. DP(NETIF_MSG_LINK,
  10495. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10496. prtad, devad, addr, value);
  10497. /* The HW expects different devad if CL22 is used */
  10498. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10499. bnx2x_acquire_phy_lock(bp);
  10500. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10501. bnx2x_release_phy_lock(bp);
  10502. return rc;
  10503. }
  10504. /* called with rtnl_lock */
  10505. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10506. {
  10507. struct bnx2x *bp = netdev_priv(dev);
  10508. struct mii_ioctl_data *mdio = if_mii(ifr);
  10509. if (!netif_running(dev))
  10510. return -EAGAIN;
  10511. switch (cmd) {
  10512. case SIOCSHWTSTAMP:
  10513. return bnx2x_hwtstamp_ioctl(bp, ifr);
  10514. default:
  10515. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10516. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10517. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10518. }
  10519. }
  10520. #ifdef CONFIG_NET_POLL_CONTROLLER
  10521. static void poll_bnx2x(struct net_device *dev)
  10522. {
  10523. struct bnx2x *bp = netdev_priv(dev);
  10524. int i;
  10525. for_each_eth_queue(bp, i) {
  10526. struct bnx2x_fastpath *fp = &bp->fp[i];
  10527. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10528. }
  10529. }
  10530. #endif
  10531. static int bnx2x_validate_addr(struct net_device *dev)
  10532. {
  10533. struct bnx2x *bp = netdev_priv(dev);
  10534. /* query the bulletin board for mac address configured by the PF */
  10535. if (IS_VF(bp))
  10536. bnx2x_sample_bulletin(bp);
  10537. if (!is_valid_ether_addr(dev->dev_addr)) {
  10538. BNX2X_ERR("Non-valid Ethernet address\n");
  10539. return -EADDRNOTAVAIL;
  10540. }
  10541. return 0;
  10542. }
  10543. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10544. struct netdev_phys_item_id *ppid)
  10545. {
  10546. struct bnx2x *bp = netdev_priv(netdev);
  10547. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10548. return -EOPNOTSUPP;
  10549. ppid->id_len = sizeof(bp->phys_port_id);
  10550. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10551. return 0;
  10552. }
  10553. static netdev_features_t bnx2x_features_check(struct sk_buff *skb,
  10554. struct net_device *dev,
  10555. netdev_features_t features)
  10556. {
  10557. return vxlan_features_check(skb, features);
  10558. }
  10559. static const struct net_device_ops bnx2x_netdev_ops = {
  10560. .ndo_open = bnx2x_open,
  10561. .ndo_stop = bnx2x_close,
  10562. .ndo_start_xmit = bnx2x_start_xmit,
  10563. .ndo_select_queue = bnx2x_select_queue,
  10564. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10565. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10566. .ndo_validate_addr = bnx2x_validate_addr,
  10567. .ndo_do_ioctl = bnx2x_ioctl,
  10568. .ndo_change_mtu = bnx2x_change_mtu,
  10569. .ndo_fix_features = bnx2x_fix_features,
  10570. .ndo_set_features = bnx2x_set_features,
  10571. .ndo_tx_timeout = bnx2x_tx_timeout,
  10572. #ifdef CONFIG_NET_POLL_CONTROLLER
  10573. .ndo_poll_controller = poll_bnx2x,
  10574. #endif
  10575. .ndo_setup_tc = bnx2x_setup_tc,
  10576. #ifdef CONFIG_BNX2X_SRIOV
  10577. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10578. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10579. .ndo_get_vf_config = bnx2x_get_vf_config,
  10580. #endif
  10581. #ifdef NETDEV_FCOE_WWNN
  10582. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10583. #endif
  10584. #ifdef CONFIG_NET_RX_BUSY_POLL
  10585. .ndo_busy_poll = bnx2x_low_latency_recv,
  10586. #endif
  10587. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10588. .ndo_set_vf_link_state = bnx2x_set_vf_link_state,
  10589. .ndo_features_check = bnx2x_features_check,
  10590. };
  10591. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10592. {
  10593. struct device *dev = &bp->pdev->dev;
  10594. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10595. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10596. dev_err(dev, "System does not support DMA, aborting\n");
  10597. return -EIO;
  10598. }
  10599. return 0;
  10600. }
  10601. static void bnx2x_disable_pcie_error_reporting(struct bnx2x *bp)
  10602. {
  10603. if (bp->flags & AER_ENABLED) {
  10604. pci_disable_pcie_error_reporting(bp->pdev);
  10605. bp->flags &= ~AER_ENABLED;
  10606. }
  10607. }
  10608. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10609. struct net_device *dev, unsigned long board_type)
  10610. {
  10611. int rc;
  10612. u32 pci_cfg_dword;
  10613. bool chip_is_e1x = (board_type == BCM57710 ||
  10614. board_type == BCM57711 ||
  10615. board_type == BCM57711E);
  10616. SET_NETDEV_DEV(dev, &pdev->dev);
  10617. bp->dev = dev;
  10618. bp->pdev = pdev;
  10619. rc = pci_enable_device(pdev);
  10620. if (rc) {
  10621. dev_err(&bp->pdev->dev,
  10622. "Cannot enable PCI device, aborting\n");
  10623. goto err_out;
  10624. }
  10625. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10626. dev_err(&bp->pdev->dev,
  10627. "Cannot find PCI device base address, aborting\n");
  10628. rc = -ENODEV;
  10629. goto err_out_disable;
  10630. }
  10631. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10632. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10633. rc = -ENODEV;
  10634. goto err_out_disable;
  10635. }
  10636. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10637. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10638. PCICFG_REVESION_ID_ERROR_VAL) {
  10639. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10640. rc = -ENODEV;
  10641. goto err_out_disable;
  10642. }
  10643. if (atomic_read(&pdev->enable_cnt) == 1) {
  10644. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10645. if (rc) {
  10646. dev_err(&bp->pdev->dev,
  10647. "Cannot obtain PCI resources, aborting\n");
  10648. goto err_out_disable;
  10649. }
  10650. pci_set_master(pdev);
  10651. pci_save_state(pdev);
  10652. }
  10653. if (IS_PF(bp)) {
  10654. if (!pdev->pm_cap) {
  10655. dev_err(&bp->pdev->dev,
  10656. "Cannot find power management capability, aborting\n");
  10657. rc = -EIO;
  10658. goto err_out_release;
  10659. }
  10660. }
  10661. if (!pci_is_pcie(pdev)) {
  10662. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10663. rc = -EIO;
  10664. goto err_out_release;
  10665. }
  10666. rc = bnx2x_set_coherency_mask(bp);
  10667. if (rc)
  10668. goto err_out_release;
  10669. dev->mem_start = pci_resource_start(pdev, 0);
  10670. dev->base_addr = dev->mem_start;
  10671. dev->mem_end = pci_resource_end(pdev, 0);
  10672. dev->irq = pdev->irq;
  10673. bp->regview = pci_ioremap_bar(pdev, 0);
  10674. if (!bp->regview) {
  10675. dev_err(&bp->pdev->dev,
  10676. "Cannot map register space, aborting\n");
  10677. rc = -ENOMEM;
  10678. goto err_out_release;
  10679. }
  10680. /* In E1/E1H use pci device function given by kernel.
  10681. * In E2/E3 read physical function from ME register since these chips
  10682. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10683. * (depending on hypervisor).
  10684. */
  10685. if (chip_is_e1x) {
  10686. bp->pf_num = PCI_FUNC(pdev->devfn);
  10687. } else {
  10688. /* chip is E2/3*/
  10689. pci_read_config_dword(bp->pdev,
  10690. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10691. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10692. ME_REG_ABS_PF_NUM_SHIFT);
  10693. }
  10694. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10695. /* clean indirect addresses */
  10696. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10697. PCICFG_VENDOR_ID_OFFSET);
  10698. /* AER (Advanced Error reporting) configuration */
  10699. rc = pci_enable_pcie_error_reporting(pdev);
  10700. if (!rc)
  10701. bp->flags |= AER_ENABLED;
  10702. else
  10703. BNX2X_DEV_INFO("Failed To configure PCIe AER [%d]\n", rc);
  10704. /*
  10705. * Clean the following indirect addresses for all functions since it
  10706. * is not used by the driver.
  10707. */
  10708. if (IS_PF(bp)) {
  10709. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10710. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10711. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10712. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10713. if (chip_is_e1x) {
  10714. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10715. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10716. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10717. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10718. }
  10719. /* Enable internal target-read (in case we are probed after PF
  10720. * FLR). Must be done prior to any BAR read access. Only for
  10721. * 57712 and up
  10722. */
  10723. if (!chip_is_e1x)
  10724. REG_WR(bp,
  10725. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10726. }
  10727. dev->watchdog_timeo = TX_TIMEOUT;
  10728. dev->netdev_ops = &bnx2x_netdev_ops;
  10729. bnx2x_set_ethtool_ops(bp, dev);
  10730. dev->priv_flags |= IFF_UNICAST_FLT;
  10731. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10732. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10733. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10734. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10735. if (!CHIP_IS_E1x(bp)) {
  10736. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10737. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10738. dev->hw_enc_features =
  10739. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10740. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10741. NETIF_F_GSO_IPIP |
  10742. NETIF_F_GSO_SIT |
  10743. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10744. }
  10745. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10746. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10747. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10748. dev->features |= NETIF_F_HIGHDMA;
  10749. /* Add Loopback capability to the device */
  10750. dev->hw_features |= NETIF_F_LOOPBACK;
  10751. #ifdef BCM_DCBNL
  10752. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10753. #endif
  10754. /* get_port_hwinfo() will set prtad and mmds properly */
  10755. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10756. bp->mdio.mmds = 0;
  10757. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10758. bp->mdio.dev = dev;
  10759. bp->mdio.mdio_read = bnx2x_mdio_read;
  10760. bp->mdio.mdio_write = bnx2x_mdio_write;
  10761. return 0;
  10762. err_out_release:
  10763. if (atomic_read(&pdev->enable_cnt) == 1)
  10764. pci_release_regions(pdev);
  10765. err_out_disable:
  10766. pci_disable_device(pdev);
  10767. err_out:
  10768. return rc;
  10769. }
  10770. static int bnx2x_check_firmware(struct bnx2x *bp)
  10771. {
  10772. const struct firmware *firmware = bp->firmware;
  10773. struct bnx2x_fw_file_hdr *fw_hdr;
  10774. struct bnx2x_fw_file_section *sections;
  10775. u32 offset, len, num_ops;
  10776. __be16 *ops_offsets;
  10777. int i;
  10778. const u8 *fw_ver;
  10779. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10780. BNX2X_ERR("Wrong FW size\n");
  10781. return -EINVAL;
  10782. }
  10783. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10784. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10785. /* Make sure none of the offsets and sizes make us read beyond
  10786. * the end of the firmware data */
  10787. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10788. offset = be32_to_cpu(sections[i].offset);
  10789. len = be32_to_cpu(sections[i].len);
  10790. if (offset + len > firmware->size) {
  10791. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10792. return -EINVAL;
  10793. }
  10794. }
  10795. /* Likewise for the init_ops offsets */
  10796. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10797. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10798. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10799. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10800. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10801. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10802. return -EINVAL;
  10803. }
  10804. }
  10805. /* Check FW version */
  10806. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10807. fw_ver = firmware->data + offset;
  10808. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10809. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10810. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10811. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10812. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10813. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10814. BCM_5710_FW_MAJOR_VERSION,
  10815. BCM_5710_FW_MINOR_VERSION,
  10816. BCM_5710_FW_REVISION_VERSION,
  10817. BCM_5710_FW_ENGINEERING_VERSION);
  10818. return -EINVAL;
  10819. }
  10820. return 0;
  10821. }
  10822. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10823. {
  10824. const __be32 *source = (const __be32 *)_source;
  10825. u32 *target = (u32 *)_target;
  10826. u32 i;
  10827. for (i = 0; i < n/4; i++)
  10828. target[i] = be32_to_cpu(source[i]);
  10829. }
  10830. /*
  10831. Ops array is stored in the following format:
  10832. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10833. */
  10834. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10835. {
  10836. const __be32 *source = (const __be32 *)_source;
  10837. struct raw_op *target = (struct raw_op *)_target;
  10838. u32 i, j, tmp;
  10839. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10840. tmp = be32_to_cpu(source[j]);
  10841. target[i].op = (tmp >> 24) & 0xff;
  10842. target[i].offset = tmp & 0xffffff;
  10843. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10844. }
  10845. }
  10846. /* IRO array is stored in the following format:
  10847. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10848. */
  10849. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10850. {
  10851. const __be32 *source = (const __be32 *)_source;
  10852. struct iro *target = (struct iro *)_target;
  10853. u32 i, j, tmp;
  10854. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10855. target[i].base = be32_to_cpu(source[j]);
  10856. j++;
  10857. tmp = be32_to_cpu(source[j]);
  10858. target[i].m1 = (tmp >> 16) & 0xffff;
  10859. target[i].m2 = tmp & 0xffff;
  10860. j++;
  10861. tmp = be32_to_cpu(source[j]);
  10862. target[i].m3 = (tmp >> 16) & 0xffff;
  10863. target[i].size = tmp & 0xffff;
  10864. j++;
  10865. }
  10866. }
  10867. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10868. {
  10869. const __be16 *source = (const __be16 *)_source;
  10870. u16 *target = (u16 *)_target;
  10871. u32 i;
  10872. for (i = 0; i < n/2; i++)
  10873. target[i] = be16_to_cpu(source[i]);
  10874. }
  10875. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10876. do { \
  10877. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10878. bp->arr = kmalloc(len, GFP_KERNEL); \
  10879. if (!bp->arr) \
  10880. goto lbl; \
  10881. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10882. (u8 *)bp->arr, len); \
  10883. } while (0)
  10884. static int bnx2x_init_firmware(struct bnx2x *bp)
  10885. {
  10886. const char *fw_file_name;
  10887. struct bnx2x_fw_file_hdr *fw_hdr;
  10888. int rc;
  10889. if (bp->firmware)
  10890. return 0;
  10891. if (CHIP_IS_E1(bp))
  10892. fw_file_name = FW_FILE_NAME_E1;
  10893. else if (CHIP_IS_E1H(bp))
  10894. fw_file_name = FW_FILE_NAME_E1H;
  10895. else if (!CHIP_IS_E1x(bp))
  10896. fw_file_name = FW_FILE_NAME_E2;
  10897. else {
  10898. BNX2X_ERR("Unsupported chip revision\n");
  10899. return -EINVAL;
  10900. }
  10901. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10902. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10903. if (rc) {
  10904. BNX2X_ERR("Can't load firmware file %s\n",
  10905. fw_file_name);
  10906. goto request_firmware_exit;
  10907. }
  10908. rc = bnx2x_check_firmware(bp);
  10909. if (rc) {
  10910. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10911. goto request_firmware_exit;
  10912. }
  10913. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10914. /* Initialize the pointers to the init arrays */
  10915. /* Blob */
  10916. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10917. /* Opcodes */
  10918. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10919. /* Offsets */
  10920. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10921. be16_to_cpu_n);
  10922. /* STORMs firmware */
  10923. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10924. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10925. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10926. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10927. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10928. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10929. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10930. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10931. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10932. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10933. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10934. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10935. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10936. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10937. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10938. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10939. /* IRO */
  10940. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10941. return 0;
  10942. iro_alloc_err:
  10943. kfree(bp->init_ops_offsets);
  10944. init_offsets_alloc_err:
  10945. kfree(bp->init_ops);
  10946. init_ops_alloc_err:
  10947. kfree(bp->init_data);
  10948. request_firmware_exit:
  10949. release_firmware(bp->firmware);
  10950. bp->firmware = NULL;
  10951. return rc;
  10952. }
  10953. static void bnx2x_release_firmware(struct bnx2x *bp)
  10954. {
  10955. kfree(bp->init_ops_offsets);
  10956. kfree(bp->init_ops);
  10957. kfree(bp->init_data);
  10958. release_firmware(bp->firmware);
  10959. bp->firmware = NULL;
  10960. }
  10961. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10962. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10963. .init_hw_cmn = bnx2x_init_hw_common,
  10964. .init_hw_port = bnx2x_init_hw_port,
  10965. .init_hw_func = bnx2x_init_hw_func,
  10966. .reset_hw_cmn = bnx2x_reset_common,
  10967. .reset_hw_port = bnx2x_reset_port,
  10968. .reset_hw_func = bnx2x_reset_func,
  10969. .gunzip_init = bnx2x_gunzip_init,
  10970. .gunzip_end = bnx2x_gunzip_end,
  10971. .init_fw = bnx2x_init_firmware,
  10972. .release_fw = bnx2x_release_firmware,
  10973. };
  10974. void bnx2x__init_func_obj(struct bnx2x *bp)
  10975. {
  10976. /* Prepare DMAE related driver resources */
  10977. bnx2x_setup_dmae(bp);
  10978. bnx2x_init_func_obj(bp, &bp->func_obj,
  10979. bnx2x_sp(bp, func_rdata),
  10980. bnx2x_sp_mapping(bp, func_rdata),
  10981. bnx2x_sp(bp, func_afex_rdata),
  10982. bnx2x_sp_mapping(bp, func_afex_rdata),
  10983. &bnx2x_func_sp_drv);
  10984. }
  10985. /* must be called after sriov-enable */
  10986. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10987. {
  10988. int cid_count = BNX2X_L2_MAX_CID(bp);
  10989. if (IS_SRIOV(bp))
  10990. cid_count += BNX2X_VF_CIDS;
  10991. if (CNIC_SUPPORT(bp))
  10992. cid_count += CNIC_CID_MAX;
  10993. return roundup(cid_count, QM_CID_ROUND);
  10994. }
  10995. /**
  10996. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10997. *
  10998. * @dev: pci device
  10999. *
  11000. */
  11001. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  11002. {
  11003. int index;
  11004. u16 control = 0;
  11005. /*
  11006. * If MSI-X is not supported - return number of SBs needed to support
  11007. * one fast path queue: one FP queue + SB for CNIC
  11008. */
  11009. if (!pdev->msix_cap) {
  11010. dev_info(&pdev->dev, "no msix capability found\n");
  11011. return 1 + cnic_cnt;
  11012. }
  11013. dev_info(&pdev->dev, "msix capability found\n");
  11014. /*
  11015. * The value in the PCI configuration space is the index of the last
  11016. * entry, namely one less than the actual size of the table, which is
  11017. * exactly what we want to return from this function: number of all SBs
  11018. * without the default SB.
  11019. * For VFs there is no default SB, then we return (index+1).
  11020. */
  11021. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &control);
  11022. index = control & PCI_MSIX_FLAGS_QSIZE;
  11023. return index;
  11024. }
  11025. static int set_max_cos_est(int chip_id)
  11026. {
  11027. switch (chip_id) {
  11028. case BCM57710:
  11029. case BCM57711:
  11030. case BCM57711E:
  11031. return BNX2X_MULTI_TX_COS_E1X;
  11032. case BCM57712:
  11033. case BCM57712_MF:
  11034. return BNX2X_MULTI_TX_COS_E2_E3A0;
  11035. case BCM57800:
  11036. case BCM57800_MF:
  11037. case BCM57810:
  11038. case BCM57810_MF:
  11039. case BCM57840_4_10:
  11040. case BCM57840_2_20:
  11041. case BCM57840_O:
  11042. case BCM57840_MFO:
  11043. case BCM57840_MF:
  11044. case BCM57811:
  11045. case BCM57811_MF:
  11046. return BNX2X_MULTI_TX_COS_E3B0;
  11047. case BCM57712_VF:
  11048. case BCM57800_VF:
  11049. case BCM57810_VF:
  11050. case BCM57840_VF:
  11051. case BCM57811_VF:
  11052. return 1;
  11053. default:
  11054. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  11055. return -ENODEV;
  11056. }
  11057. }
  11058. static int set_is_vf(int chip_id)
  11059. {
  11060. switch (chip_id) {
  11061. case BCM57712_VF:
  11062. case BCM57800_VF:
  11063. case BCM57810_VF:
  11064. case BCM57840_VF:
  11065. case BCM57811_VF:
  11066. return true;
  11067. default:
  11068. return false;
  11069. }
  11070. }
  11071. /* nig_tsgen registers relative address */
  11072. #define tsgen_ctrl 0x0
  11073. #define tsgen_freecount 0x10
  11074. #define tsgen_synctime_t0 0x20
  11075. #define tsgen_offset_t0 0x28
  11076. #define tsgen_drift_t0 0x30
  11077. #define tsgen_synctime_t1 0x58
  11078. #define tsgen_offset_t1 0x60
  11079. #define tsgen_drift_t1 0x68
  11080. /* FW workaround for setting drift */
  11081. static int bnx2x_send_update_drift_ramrod(struct bnx2x *bp, int drift_dir,
  11082. int best_val, int best_period)
  11083. {
  11084. struct bnx2x_func_state_params func_params = {NULL};
  11085. struct bnx2x_func_set_timesync_params *set_timesync_params =
  11086. &func_params.params.set_timesync;
  11087. /* Prepare parameters for function state transitions */
  11088. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  11089. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  11090. func_params.f_obj = &bp->func_obj;
  11091. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  11092. /* Function parameters */
  11093. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_SET;
  11094. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  11095. set_timesync_params->add_sub_drift_adjust_value =
  11096. drift_dir ? TS_ADD_VALUE : TS_SUB_VALUE;
  11097. set_timesync_params->drift_adjust_value = best_val;
  11098. set_timesync_params->drift_adjust_period = best_period;
  11099. return bnx2x_func_state_change(bp, &func_params);
  11100. }
  11101. static int bnx2x_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
  11102. {
  11103. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11104. int rc;
  11105. int drift_dir = 1;
  11106. int val, period, period1, period2, dif, dif1, dif2;
  11107. int best_dif = BNX2X_MAX_PHC_DRIFT, best_period = 0, best_val = 0;
  11108. DP(BNX2X_MSG_PTP, "PTP adjfreq called, ppb = %d\n", ppb);
  11109. if (!netif_running(bp->dev)) {
  11110. DP(BNX2X_MSG_PTP,
  11111. "PTP adjfreq called while the interface is down\n");
  11112. return -EFAULT;
  11113. }
  11114. if (ppb < 0) {
  11115. ppb = -ppb;
  11116. drift_dir = 0;
  11117. }
  11118. if (ppb == 0) {
  11119. best_val = 1;
  11120. best_period = 0x1FFFFFF;
  11121. } else if (ppb >= BNX2X_MAX_PHC_DRIFT) {
  11122. best_val = 31;
  11123. best_period = 1;
  11124. } else {
  11125. /* Changed not to allow val = 8, 16, 24 as these values
  11126. * are not supported in workaround.
  11127. */
  11128. for (val = 0; val <= 31; val++) {
  11129. if ((val & 0x7) == 0)
  11130. continue;
  11131. period1 = val * 1000000 / ppb;
  11132. period2 = period1 + 1;
  11133. if (period1 != 0)
  11134. dif1 = ppb - (val * 1000000 / period1);
  11135. else
  11136. dif1 = BNX2X_MAX_PHC_DRIFT;
  11137. if (dif1 < 0)
  11138. dif1 = -dif1;
  11139. dif2 = ppb - (val * 1000000 / period2);
  11140. if (dif2 < 0)
  11141. dif2 = -dif2;
  11142. dif = (dif1 < dif2) ? dif1 : dif2;
  11143. period = (dif1 < dif2) ? period1 : period2;
  11144. if (dif < best_dif) {
  11145. best_dif = dif;
  11146. best_val = val;
  11147. best_period = period;
  11148. }
  11149. }
  11150. }
  11151. rc = bnx2x_send_update_drift_ramrod(bp, drift_dir, best_val,
  11152. best_period);
  11153. if (rc) {
  11154. BNX2X_ERR("Failed to set drift\n");
  11155. return -EFAULT;
  11156. }
  11157. DP(BNX2X_MSG_PTP, "Configured val = %d, period = %d\n", best_val,
  11158. best_period);
  11159. return 0;
  11160. }
  11161. static int bnx2x_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
  11162. {
  11163. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11164. u64 now;
  11165. DP(BNX2X_MSG_PTP, "PTP adjtime called, delta = %llx\n", delta);
  11166. now = timecounter_read(&bp->timecounter);
  11167. now += delta;
  11168. /* Re-init the timecounter */
  11169. timecounter_init(&bp->timecounter, &bp->cyclecounter, now);
  11170. return 0;
  11171. }
  11172. static int bnx2x_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts)
  11173. {
  11174. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11175. u64 ns;
  11176. u32 remainder;
  11177. ns = timecounter_read(&bp->timecounter);
  11178. DP(BNX2X_MSG_PTP, "PTP gettime called, ns = %llu\n", ns);
  11179. ts->tv_sec = div_u64_rem(ns, 1000000000ULL, &remainder);
  11180. ts->tv_nsec = remainder;
  11181. return 0;
  11182. }
  11183. static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
  11184. const struct timespec *ts)
  11185. {
  11186. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11187. u64 ns;
  11188. ns = ts->tv_sec * 1000000000ULL;
  11189. ns += ts->tv_nsec;
  11190. DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
  11191. /* Re-init the timecounter */
  11192. timecounter_init(&bp->timecounter, &bp->cyclecounter, ns);
  11193. return 0;
  11194. }
  11195. /* Enable (or disable) ancillary features of the phc subsystem */
  11196. static int bnx2x_ptp_enable(struct ptp_clock_info *ptp,
  11197. struct ptp_clock_request *rq, int on)
  11198. {
  11199. struct bnx2x *bp = container_of(ptp, struct bnx2x, ptp_clock_info);
  11200. BNX2X_ERR("PHC ancillary features are not supported\n");
  11201. return -ENOTSUPP;
  11202. }
  11203. void bnx2x_register_phc(struct bnx2x *bp)
  11204. {
  11205. /* Fill the ptp_clock_info struct and register PTP clock*/
  11206. bp->ptp_clock_info.owner = THIS_MODULE;
  11207. snprintf(bp->ptp_clock_info.name, 16, "%s", bp->dev->name);
  11208. bp->ptp_clock_info.max_adj = BNX2X_MAX_PHC_DRIFT; /* In PPB */
  11209. bp->ptp_clock_info.n_alarm = 0;
  11210. bp->ptp_clock_info.n_ext_ts = 0;
  11211. bp->ptp_clock_info.n_per_out = 0;
  11212. bp->ptp_clock_info.pps = 0;
  11213. bp->ptp_clock_info.adjfreq = bnx2x_ptp_adjfreq;
  11214. bp->ptp_clock_info.adjtime = bnx2x_ptp_adjtime;
  11215. bp->ptp_clock_info.gettime = bnx2x_ptp_gettime;
  11216. bp->ptp_clock_info.settime = bnx2x_ptp_settime;
  11217. bp->ptp_clock_info.enable = bnx2x_ptp_enable;
  11218. bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &bp->pdev->dev);
  11219. if (IS_ERR(bp->ptp_clock)) {
  11220. bp->ptp_clock = NULL;
  11221. BNX2X_ERR("PTP clock registeration failed\n");
  11222. }
  11223. }
  11224. static int bnx2x_init_one(struct pci_dev *pdev,
  11225. const struct pci_device_id *ent)
  11226. {
  11227. struct net_device *dev = NULL;
  11228. struct bnx2x *bp;
  11229. enum pcie_link_width pcie_width;
  11230. enum pci_bus_speed pcie_speed;
  11231. int rc, max_non_def_sbs;
  11232. int rx_count, tx_count, rss_count, doorbell_size;
  11233. int max_cos_est;
  11234. bool is_vf;
  11235. int cnic_cnt;
  11236. /* An estimated maximum supported CoS number according to the chip
  11237. * version.
  11238. * We will try to roughly estimate the maximum number of CoSes this chip
  11239. * may support in order to minimize the memory allocated for Tx
  11240. * netdev_queue's. This number will be accurately calculated during the
  11241. * initialization of bp->max_cos based on the chip versions AND chip
  11242. * revision in the bnx2x_init_bp().
  11243. */
  11244. max_cos_est = set_max_cos_est(ent->driver_data);
  11245. if (max_cos_est < 0)
  11246. return max_cos_est;
  11247. is_vf = set_is_vf(ent->driver_data);
  11248. cnic_cnt = is_vf ? 0 : 1;
  11249. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  11250. /* add another SB for VF as it has no default SB */
  11251. max_non_def_sbs += is_vf ? 1 : 0;
  11252. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  11253. rss_count = max_non_def_sbs - cnic_cnt;
  11254. if (rss_count < 1)
  11255. return -EINVAL;
  11256. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  11257. rx_count = rss_count + cnic_cnt;
  11258. /* Maximum number of netdev Tx queues:
  11259. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  11260. */
  11261. tx_count = rss_count * max_cos_est + cnic_cnt;
  11262. /* dev zeroed in init_etherdev */
  11263. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  11264. if (!dev)
  11265. return -ENOMEM;
  11266. bp = netdev_priv(dev);
  11267. bp->flags = 0;
  11268. if (is_vf)
  11269. bp->flags |= IS_VF_FLAG;
  11270. bp->igu_sb_cnt = max_non_def_sbs;
  11271. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  11272. bp->msg_enable = debug;
  11273. bp->cnic_support = cnic_cnt;
  11274. bp->cnic_probe = bnx2x_cnic_probe;
  11275. pci_set_drvdata(pdev, dev);
  11276. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  11277. if (rc < 0) {
  11278. free_netdev(dev);
  11279. return rc;
  11280. }
  11281. BNX2X_DEV_INFO("This is a %s function\n",
  11282. IS_PF(bp) ? "physical" : "virtual");
  11283. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  11284. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  11285. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  11286. tx_count, rx_count);
  11287. rc = bnx2x_init_bp(bp);
  11288. if (rc)
  11289. goto init_one_exit;
  11290. /* Map doorbells here as we need the real value of bp->max_cos which
  11291. * is initialized in bnx2x_init_bp() to determine the number of
  11292. * l2 connections.
  11293. */
  11294. if (IS_VF(bp)) {
  11295. bp->doorbells = bnx2x_vf_doorbells(bp);
  11296. rc = bnx2x_vf_pci_alloc(bp);
  11297. if (rc)
  11298. goto init_one_exit;
  11299. } else {
  11300. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  11301. if (doorbell_size > pci_resource_len(pdev, 2)) {
  11302. dev_err(&bp->pdev->dev,
  11303. "Cannot map doorbells, bar size too small, aborting\n");
  11304. rc = -ENOMEM;
  11305. goto init_one_exit;
  11306. }
  11307. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  11308. doorbell_size);
  11309. }
  11310. if (!bp->doorbells) {
  11311. dev_err(&bp->pdev->dev,
  11312. "Cannot map doorbell space, aborting\n");
  11313. rc = -ENOMEM;
  11314. goto init_one_exit;
  11315. }
  11316. if (IS_VF(bp)) {
  11317. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  11318. if (rc)
  11319. goto init_one_exit;
  11320. }
  11321. /* Enable SRIOV if capability found in configuration space */
  11322. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  11323. if (rc)
  11324. goto init_one_exit;
  11325. /* calc qm_cid_count */
  11326. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  11327. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  11328. /* disable FCOE L2 queue for E1x*/
  11329. if (CHIP_IS_E1x(bp))
  11330. bp->flags |= NO_FCOE_FLAG;
  11331. /* Set bp->num_queues for MSI-X mode*/
  11332. bnx2x_set_num_queues(bp);
  11333. /* Configure interrupt mode: try to enable MSI-X/MSI if
  11334. * needed.
  11335. */
  11336. rc = bnx2x_set_int_mode(bp);
  11337. if (rc) {
  11338. dev_err(&pdev->dev, "Cannot set interrupts\n");
  11339. goto init_one_exit;
  11340. }
  11341. BNX2X_DEV_INFO("set interrupts successfully\n");
  11342. /* register the net device */
  11343. rc = register_netdev(dev);
  11344. if (rc) {
  11345. dev_err(&pdev->dev, "Cannot register net device\n");
  11346. goto init_one_exit;
  11347. }
  11348. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  11349. if (!NO_FCOE(bp)) {
  11350. /* Add storage MAC address */
  11351. rtnl_lock();
  11352. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11353. rtnl_unlock();
  11354. }
  11355. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  11356. pcie_speed == PCI_SPEED_UNKNOWN ||
  11357. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  11358. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  11359. else
  11360. BNX2X_DEV_INFO(
  11361. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  11362. board_info[ent->driver_data].name,
  11363. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  11364. pcie_width,
  11365. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  11366. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  11367. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  11368. "Unknown",
  11369. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  11370. bnx2x_register_phc(bp);
  11371. return 0;
  11372. init_one_exit:
  11373. bnx2x_disable_pcie_error_reporting(bp);
  11374. if (bp->regview)
  11375. iounmap(bp->regview);
  11376. if (IS_PF(bp) && bp->doorbells)
  11377. iounmap(bp->doorbells);
  11378. free_netdev(dev);
  11379. if (atomic_read(&pdev->enable_cnt) == 1)
  11380. pci_release_regions(pdev);
  11381. pci_disable_device(pdev);
  11382. return rc;
  11383. }
  11384. static void __bnx2x_remove(struct pci_dev *pdev,
  11385. struct net_device *dev,
  11386. struct bnx2x *bp,
  11387. bool remove_netdev)
  11388. {
  11389. if (bp->ptp_clock) {
  11390. ptp_clock_unregister(bp->ptp_clock);
  11391. bp->ptp_clock = NULL;
  11392. }
  11393. /* Delete storage MAC address */
  11394. if (!NO_FCOE(bp)) {
  11395. rtnl_lock();
  11396. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  11397. rtnl_unlock();
  11398. }
  11399. #ifdef BCM_DCBNL
  11400. /* Delete app tlvs from dcbnl */
  11401. bnx2x_dcbnl_update_applist(bp, true);
  11402. #endif
  11403. if (IS_PF(bp) &&
  11404. !BP_NOMCP(bp) &&
  11405. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  11406. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  11407. /* Close the interface - either directly or implicitly */
  11408. if (remove_netdev) {
  11409. unregister_netdev(dev);
  11410. } else {
  11411. rtnl_lock();
  11412. dev_close(dev);
  11413. rtnl_unlock();
  11414. }
  11415. bnx2x_iov_remove_one(bp);
  11416. /* Power on: we can't let PCI layer write to us while we are in D3 */
  11417. if (IS_PF(bp)) {
  11418. bnx2x_set_power_state(bp, PCI_D0);
  11419. /* Set endianity registers to reset values in case next driver
  11420. * boots in different endianty environment.
  11421. */
  11422. bnx2x_reset_endianity(bp);
  11423. }
  11424. /* Disable MSI/MSI-X */
  11425. bnx2x_disable_msi(bp);
  11426. /* Power off */
  11427. if (IS_PF(bp))
  11428. bnx2x_set_power_state(bp, PCI_D3hot);
  11429. /* Make sure RESET task is not scheduled before continuing */
  11430. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  11431. /* send message via vfpf channel to release the resources of this vf */
  11432. if (IS_VF(bp))
  11433. bnx2x_vfpf_release(bp);
  11434. /* Assumes no further PCIe PM changes will occur */
  11435. if (system_state == SYSTEM_POWER_OFF) {
  11436. pci_wake_from_d3(pdev, bp->wol);
  11437. pci_set_power_state(pdev, PCI_D3hot);
  11438. }
  11439. bnx2x_disable_pcie_error_reporting(bp);
  11440. if (remove_netdev) {
  11441. if (bp->regview)
  11442. iounmap(bp->regview);
  11443. /* For vfs, doorbells are part of the regview and were unmapped
  11444. * along with it. FW is only loaded by PF.
  11445. */
  11446. if (IS_PF(bp)) {
  11447. if (bp->doorbells)
  11448. iounmap(bp->doorbells);
  11449. bnx2x_release_firmware(bp);
  11450. } else {
  11451. bnx2x_vf_pci_dealloc(bp);
  11452. }
  11453. bnx2x_free_mem_bp(bp);
  11454. free_netdev(dev);
  11455. if (atomic_read(&pdev->enable_cnt) == 1)
  11456. pci_release_regions(pdev);
  11457. pci_disable_device(pdev);
  11458. }
  11459. }
  11460. static void bnx2x_remove_one(struct pci_dev *pdev)
  11461. {
  11462. struct net_device *dev = pci_get_drvdata(pdev);
  11463. struct bnx2x *bp;
  11464. if (!dev) {
  11465. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  11466. return;
  11467. }
  11468. bp = netdev_priv(dev);
  11469. __bnx2x_remove(pdev, dev, bp, true);
  11470. }
  11471. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  11472. {
  11473. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  11474. bp->rx_mode = BNX2X_RX_MODE_NONE;
  11475. if (CNIC_LOADED(bp))
  11476. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  11477. /* Stop Tx */
  11478. bnx2x_tx_disable(bp);
  11479. /* Delete all NAPI objects */
  11480. bnx2x_del_all_napi(bp);
  11481. if (CNIC_LOADED(bp))
  11482. bnx2x_del_all_napi_cnic(bp);
  11483. netdev_reset_tc(bp->dev);
  11484. del_timer_sync(&bp->timer);
  11485. cancel_delayed_work_sync(&bp->sp_task);
  11486. cancel_delayed_work_sync(&bp->period_task);
  11487. spin_lock_bh(&bp->stats_lock);
  11488. bp->stats_state = STATS_STATE_DISABLED;
  11489. spin_unlock_bh(&bp->stats_lock);
  11490. bnx2x_save_statistics(bp);
  11491. netif_carrier_off(bp->dev);
  11492. return 0;
  11493. }
  11494. /**
  11495. * bnx2x_io_error_detected - called when PCI error is detected
  11496. * @pdev: Pointer to PCI device
  11497. * @state: The current pci connection state
  11498. *
  11499. * This function is called after a PCI bus error affecting
  11500. * this device has been detected.
  11501. */
  11502. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  11503. pci_channel_state_t state)
  11504. {
  11505. struct net_device *dev = pci_get_drvdata(pdev);
  11506. struct bnx2x *bp = netdev_priv(dev);
  11507. rtnl_lock();
  11508. BNX2X_ERR("IO error detected\n");
  11509. netif_device_detach(dev);
  11510. if (state == pci_channel_io_perm_failure) {
  11511. rtnl_unlock();
  11512. return PCI_ERS_RESULT_DISCONNECT;
  11513. }
  11514. if (netif_running(dev))
  11515. bnx2x_eeh_nic_unload(bp);
  11516. bnx2x_prev_path_mark_eeh(bp);
  11517. pci_disable_device(pdev);
  11518. rtnl_unlock();
  11519. /* Request a slot reset */
  11520. return PCI_ERS_RESULT_NEED_RESET;
  11521. }
  11522. /**
  11523. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  11524. * @pdev: Pointer to PCI device
  11525. *
  11526. * Restart the card from scratch, as if from a cold-boot.
  11527. */
  11528. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  11529. {
  11530. struct net_device *dev = pci_get_drvdata(pdev);
  11531. struct bnx2x *bp = netdev_priv(dev);
  11532. int i;
  11533. rtnl_lock();
  11534. BNX2X_ERR("IO slot reset initializing...\n");
  11535. if (pci_enable_device(pdev)) {
  11536. dev_err(&pdev->dev,
  11537. "Cannot re-enable PCI device after reset\n");
  11538. rtnl_unlock();
  11539. return PCI_ERS_RESULT_DISCONNECT;
  11540. }
  11541. pci_set_master(pdev);
  11542. pci_restore_state(pdev);
  11543. pci_save_state(pdev);
  11544. if (netif_running(dev))
  11545. bnx2x_set_power_state(bp, PCI_D0);
  11546. if (netif_running(dev)) {
  11547. BNX2X_ERR("IO slot reset --> driver unload\n");
  11548. /* MCP should have been reset; Need to wait for validity */
  11549. bnx2x_init_shmem(bp);
  11550. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  11551. u32 v;
  11552. v = SHMEM2_RD(bp,
  11553. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  11554. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  11555. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  11556. }
  11557. bnx2x_drain_tx_queues(bp);
  11558. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  11559. bnx2x_netif_stop(bp, 1);
  11560. bnx2x_free_irq(bp);
  11561. /* Report UNLOAD_DONE to MCP */
  11562. bnx2x_send_unload_done(bp, true);
  11563. bp->sp_state = 0;
  11564. bp->port.pmf = 0;
  11565. bnx2x_prev_unload(bp);
  11566. /* We should have reseted the engine, so It's fair to
  11567. * assume the FW will no longer write to the bnx2x driver.
  11568. */
  11569. bnx2x_squeeze_objects(bp);
  11570. bnx2x_free_skbs(bp);
  11571. for_each_rx_queue(bp, i)
  11572. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11573. bnx2x_free_fp_mem(bp);
  11574. bnx2x_free_mem(bp);
  11575. bp->state = BNX2X_STATE_CLOSED;
  11576. }
  11577. rtnl_unlock();
  11578. /* If AER, perform cleanup of the PCIe registers */
  11579. if (bp->flags & AER_ENABLED) {
  11580. if (pci_cleanup_aer_uncorrect_error_status(pdev))
  11581. BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status failed\n");
  11582. else
  11583. DP(NETIF_MSG_HW, "pci_cleanup_aer_uncorrect_error_status succeeded\n");
  11584. }
  11585. return PCI_ERS_RESULT_RECOVERED;
  11586. }
  11587. /**
  11588. * bnx2x_io_resume - called when traffic can start flowing again
  11589. * @pdev: Pointer to PCI device
  11590. *
  11591. * This callback is called when the error recovery driver tells us that
  11592. * its OK to resume normal operation.
  11593. */
  11594. static void bnx2x_io_resume(struct pci_dev *pdev)
  11595. {
  11596. struct net_device *dev = pci_get_drvdata(pdev);
  11597. struct bnx2x *bp = netdev_priv(dev);
  11598. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11599. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11600. return;
  11601. }
  11602. rtnl_lock();
  11603. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11604. DRV_MSG_SEQ_NUMBER_MASK;
  11605. if (netif_running(dev))
  11606. bnx2x_nic_load(bp, LOAD_NORMAL);
  11607. netif_device_attach(dev);
  11608. rtnl_unlock();
  11609. }
  11610. static const struct pci_error_handlers bnx2x_err_handler = {
  11611. .error_detected = bnx2x_io_error_detected,
  11612. .slot_reset = bnx2x_io_slot_reset,
  11613. .resume = bnx2x_io_resume,
  11614. };
  11615. static void bnx2x_shutdown(struct pci_dev *pdev)
  11616. {
  11617. struct net_device *dev = pci_get_drvdata(pdev);
  11618. struct bnx2x *bp;
  11619. if (!dev)
  11620. return;
  11621. bp = netdev_priv(dev);
  11622. if (!bp)
  11623. return;
  11624. rtnl_lock();
  11625. netif_device_detach(dev);
  11626. rtnl_unlock();
  11627. /* Don't remove the netdevice, as there are scenarios which will cause
  11628. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11629. * rootfs is mounted from SAN.
  11630. */
  11631. __bnx2x_remove(pdev, dev, bp, false);
  11632. }
  11633. static struct pci_driver bnx2x_pci_driver = {
  11634. .name = DRV_MODULE_NAME,
  11635. .id_table = bnx2x_pci_tbl,
  11636. .probe = bnx2x_init_one,
  11637. .remove = bnx2x_remove_one,
  11638. .suspend = bnx2x_suspend,
  11639. .resume = bnx2x_resume,
  11640. .err_handler = &bnx2x_err_handler,
  11641. #ifdef CONFIG_BNX2X_SRIOV
  11642. .sriov_configure = bnx2x_sriov_configure,
  11643. #endif
  11644. .shutdown = bnx2x_shutdown,
  11645. };
  11646. static int __init bnx2x_init(void)
  11647. {
  11648. int ret;
  11649. pr_info("%s", version);
  11650. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11651. if (bnx2x_wq == NULL) {
  11652. pr_err("Cannot create workqueue\n");
  11653. return -ENOMEM;
  11654. }
  11655. bnx2x_iov_wq = create_singlethread_workqueue("bnx2x_iov");
  11656. if (!bnx2x_iov_wq) {
  11657. pr_err("Cannot create iov workqueue\n");
  11658. destroy_workqueue(bnx2x_wq);
  11659. return -ENOMEM;
  11660. }
  11661. ret = pci_register_driver(&bnx2x_pci_driver);
  11662. if (ret) {
  11663. pr_err("Cannot register driver\n");
  11664. destroy_workqueue(bnx2x_wq);
  11665. destroy_workqueue(bnx2x_iov_wq);
  11666. }
  11667. return ret;
  11668. }
  11669. static void __exit bnx2x_cleanup(void)
  11670. {
  11671. struct list_head *pos, *q;
  11672. pci_unregister_driver(&bnx2x_pci_driver);
  11673. destroy_workqueue(bnx2x_wq);
  11674. destroy_workqueue(bnx2x_iov_wq);
  11675. /* Free globally allocated resources */
  11676. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11677. struct bnx2x_prev_path_list *tmp =
  11678. list_entry(pos, struct bnx2x_prev_path_list, list);
  11679. list_del(pos);
  11680. kfree(tmp);
  11681. }
  11682. }
  11683. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11684. {
  11685. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11686. }
  11687. module_init(bnx2x_init);
  11688. module_exit(bnx2x_cleanup);
  11689. /**
  11690. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11691. *
  11692. * @bp: driver handle
  11693. * @set: set or clear the CAM entry
  11694. *
  11695. * This function will wait until the ramrod completion returns.
  11696. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11697. */
  11698. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11699. {
  11700. unsigned long ramrod_flags = 0;
  11701. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11702. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11703. &bp->iscsi_l2_mac_obj, true,
  11704. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11705. }
  11706. /* count denotes the number of new completions we have seen */
  11707. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11708. {
  11709. struct eth_spe *spe;
  11710. int cxt_index, cxt_offset;
  11711. #ifdef BNX2X_STOP_ON_ERROR
  11712. if (unlikely(bp->panic))
  11713. return;
  11714. #endif
  11715. spin_lock_bh(&bp->spq_lock);
  11716. BUG_ON(bp->cnic_spq_pending < count);
  11717. bp->cnic_spq_pending -= count;
  11718. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11719. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11720. & SPE_HDR_CONN_TYPE) >>
  11721. SPE_HDR_CONN_TYPE_SHIFT;
  11722. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11723. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11724. /* Set validation for iSCSI L2 client before sending SETUP
  11725. * ramrod
  11726. */
  11727. if (type == ETH_CONNECTION_TYPE) {
  11728. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11729. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11730. ILT_PAGE_CIDS;
  11731. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11732. (cxt_index * ILT_PAGE_CIDS);
  11733. bnx2x_set_ctx_validation(bp,
  11734. &bp->context[cxt_index].
  11735. vcxt[cxt_offset].eth,
  11736. BNX2X_ISCSI_ETH_CID(bp));
  11737. }
  11738. }
  11739. /*
  11740. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11741. * and in the air. We also check that number of outstanding
  11742. * COMMON ramrods is not more than the EQ and SPQ can
  11743. * accommodate.
  11744. */
  11745. if (type == ETH_CONNECTION_TYPE) {
  11746. if (!atomic_read(&bp->cq_spq_left))
  11747. break;
  11748. else
  11749. atomic_dec(&bp->cq_spq_left);
  11750. } else if (type == NONE_CONNECTION_TYPE) {
  11751. if (!atomic_read(&bp->eq_spq_left))
  11752. break;
  11753. else
  11754. atomic_dec(&bp->eq_spq_left);
  11755. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11756. (type == FCOE_CONNECTION_TYPE)) {
  11757. if (bp->cnic_spq_pending >=
  11758. bp->cnic_eth_dev.max_kwqe_pending)
  11759. break;
  11760. else
  11761. bp->cnic_spq_pending++;
  11762. } else {
  11763. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11764. bnx2x_panic();
  11765. break;
  11766. }
  11767. spe = bnx2x_sp_get_next(bp);
  11768. *spe = *bp->cnic_kwq_cons;
  11769. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11770. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11771. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11772. bp->cnic_kwq_cons = bp->cnic_kwq;
  11773. else
  11774. bp->cnic_kwq_cons++;
  11775. }
  11776. bnx2x_sp_prod_update(bp);
  11777. spin_unlock_bh(&bp->spq_lock);
  11778. }
  11779. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11780. struct kwqe_16 *kwqes[], u32 count)
  11781. {
  11782. struct bnx2x *bp = netdev_priv(dev);
  11783. int i;
  11784. #ifdef BNX2X_STOP_ON_ERROR
  11785. if (unlikely(bp->panic)) {
  11786. BNX2X_ERR("Can't post to SP queue while panic\n");
  11787. return -EIO;
  11788. }
  11789. #endif
  11790. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11791. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11792. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11793. return -EAGAIN;
  11794. }
  11795. spin_lock_bh(&bp->spq_lock);
  11796. for (i = 0; i < count; i++) {
  11797. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11798. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11799. break;
  11800. *bp->cnic_kwq_prod = *spe;
  11801. bp->cnic_kwq_pending++;
  11802. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11803. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11804. spe->data.update_data_addr.hi,
  11805. spe->data.update_data_addr.lo,
  11806. bp->cnic_kwq_pending);
  11807. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11808. bp->cnic_kwq_prod = bp->cnic_kwq;
  11809. else
  11810. bp->cnic_kwq_prod++;
  11811. }
  11812. spin_unlock_bh(&bp->spq_lock);
  11813. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11814. bnx2x_cnic_sp_post(bp, 0);
  11815. return i;
  11816. }
  11817. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11818. {
  11819. struct cnic_ops *c_ops;
  11820. int rc = 0;
  11821. mutex_lock(&bp->cnic_mutex);
  11822. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11823. lockdep_is_held(&bp->cnic_mutex));
  11824. if (c_ops)
  11825. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11826. mutex_unlock(&bp->cnic_mutex);
  11827. return rc;
  11828. }
  11829. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11830. {
  11831. struct cnic_ops *c_ops;
  11832. int rc = 0;
  11833. rcu_read_lock();
  11834. c_ops = rcu_dereference(bp->cnic_ops);
  11835. if (c_ops)
  11836. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11837. rcu_read_unlock();
  11838. return rc;
  11839. }
  11840. /*
  11841. * for commands that have no data
  11842. */
  11843. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11844. {
  11845. struct cnic_ctl_info ctl = {0};
  11846. ctl.cmd = cmd;
  11847. return bnx2x_cnic_ctl_send(bp, &ctl);
  11848. }
  11849. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11850. {
  11851. struct cnic_ctl_info ctl = {0};
  11852. /* first we tell CNIC and only then we count this as a completion */
  11853. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11854. ctl.data.comp.cid = cid;
  11855. ctl.data.comp.error = err;
  11856. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11857. bnx2x_cnic_sp_post(bp, 0);
  11858. }
  11859. /* Called with netif_addr_lock_bh() taken.
  11860. * Sets an rx_mode config for an iSCSI ETH client.
  11861. * Doesn't block.
  11862. * Completion should be checked outside.
  11863. */
  11864. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11865. {
  11866. unsigned long accept_flags = 0, ramrod_flags = 0;
  11867. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11868. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11869. if (start) {
  11870. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11871. * because it's the only way for UIO Queue to accept
  11872. * multicasts (in non-promiscuous mode only one Queue per
  11873. * function will receive multicast packets (leading in our
  11874. * case).
  11875. */
  11876. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11877. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11878. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11879. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11880. /* Clear STOP_PENDING bit if START is requested */
  11881. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11882. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11883. } else
  11884. /* Clear START_PENDING bit if STOP is requested */
  11885. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11886. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11887. set_bit(sched_state, &bp->sp_state);
  11888. else {
  11889. __set_bit(RAMROD_RX, &ramrod_flags);
  11890. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11891. ramrod_flags);
  11892. }
  11893. }
  11894. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11895. {
  11896. struct bnx2x *bp = netdev_priv(dev);
  11897. int rc = 0;
  11898. switch (ctl->cmd) {
  11899. case DRV_CTL_CTXTBL_WR_CMD: {
  11900. u32 index = ctl->data.io.offset;
  11901. dma_addr_t addr = ctl->data.io.dma_addr;
  11902. bnx2x_ilt_wr(bp, index, addr);
  11903. break;
  11904. }
  11905. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11906. int count = ctl->data.credit.credit_count;
  11907. bnx2x_cnic_sp_post(bp, count);
  11908. break;
  11909. }
  11910. /* rtnl_lock is held. */
  11911. case DRV_CTL_START_L2_CMD: {
  11912. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11913. unsigned long sp_bits = 0;
  11914. /* Configure the iSCSI classification object */
  11915. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11916. cp->iscsi_l2_client_id,
  11917. cp->iscsi_l2_cid, BP_FUNC(bp),
  11918. bnx2x_sp(bp, mac_rdata),
  11919. bnx2x_sp_mapping(bp, mac_rdata),
  11920. BNX2X_FILTER_MAC_PENDING,
  11921. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11922. &bp->macs_pool);
  11923. /* Set iSCSI MAC address */
  11924. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11925. if (rc)
  11926. break;
  11927. mmiowb();
  11928. barrier();
  11929. /* Start accepting on iSCSI L2 ring */
  11930. netif_addr_lock_bh(dev);
  11931. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11932. netif_addr_unlock_bh(dev);
  11933. /* bits to wait on */
  11934. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11935. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11936. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11937. BNX2X_ERR("rx_mode completion timed out!\n");
  11938. break;
  11939. }
  11940. /* rtnl_lock is held. */
  11941. case DRV_CTL_STOP_L2_CMD: {
  11942. unsigned long sp_bits = 0;
  11943. /* Stop accepting on iSCSI L2 ring */
  11944. netif_addr_lock_bh(dev);
  11945. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11946. netif_addr_unlock_bh(dev);
  11947. /* bits to wait on */
  11948. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11949. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11950. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11951. BNX2X_ERR("rx_mode completion timed out!\n");
  11952. mmiowb();
  11953. barrier();
  11954. /* Unset iSCSI L2 MAC */
  11955. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11956. BNX2X_ISCSI_ETH_MAC, true);
  11957. break;
  11958. }
  11959. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11960. int count = ctl->data.credit.credit_count;
  11961. smp_mb__before_atomic();
  11962. atomic_add(count, &bp->cq_spq_left);
  11963. smp_mb__after_atomic();
  11964. break;
  11965. }
  11966. case DRV_CTL_ULP_REGISTER_CMD: {
  11967. int ulp_type = ctl->data.register_data.ulp_type;
  11968. if (CHIP_IS_E3(bp)) {
  11969. int idx = BP_FW_MB_IDX(bp);
  11970. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11971. int path = BP_PATH(bp);
  11972. int port = BP_PORT(bp);
  11973. int i;
  11974. u32 scratch_offset;
  11975. u32 *host_addr;
  11976. /* first write capability to shmem2 */
  11977. if (ulp_type == CNIC_ULP_ISCSI)
  11978. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11979. else if (ulp_type == CNIC_ULP_FCOE)
  11980. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11981. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11982. if ((ulp_type != CNIC_ULP_FCOE) ||
  11983. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11984. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11985. break;
  11986. /* if reached here - should write fcoe capabilities */
  11987. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11988. if (!scratch_offset)
  11989. break;
  11990. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11991. fcoe_features[path][port]);
  11992. host_addr = (u32 *) &(ctl->data.register_data.
  11993. fcoe_features);
  11994. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11995. i += 4)
  11996. REG_WR(bp, scratch_offset + i,
  11997. *(host_addr + i/4));
  11998. }
  11999. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12000. break;
  12001. }
  12002. case DRV_CTL_ULP_UNREGISTER_CMD: {
  12003. int ulp_type = ctl->data.ulp_type;
  12004. if (CHIP_IS_E3(bp)) {
  12005. int idx = BP_FW_MB_IDX(bp);
  12006. u32 cap;
  12007. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  12008. if (ulp_type == CNIC_ULP_ISCSI)
  12009. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  12010. else if (ulp_type == CNIC_ULP_FCOE)
  12011. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  12012. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  12013. }
  12014. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12015. break;
  12016. }
  12017. default:
  12018. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  12019. rc = -EINVAL;
  12020. }
  12021. return rc;
  12022. }
  12023. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  12024. {
  12025. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12026. if (bp->flags & USING_MSIX_FLAG) {
  12027. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  12028. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  12029. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  12030. } else {
  12031. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  12032. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  12033. }
  12034. if (!CHIP_IS_E1x(bp))
  12035. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  12036. else
  12037. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  12038. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  12039. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  12040. cp->irq_arr[1].status_blk = bp->def_status_blk;
  12041. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  12042. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  12043. cp->num_irq = 2;
  12044. }
  12045. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  12046. {
  12047. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12048. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12049. bnx2x_cid_ilt_lines(bp);
  12050. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12051. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12052. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12053. 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",
  12054. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  12055. cp->iscsi_l2_cid);
  12056. if (NO_ISCSI_OOO(bp))
  12057. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12058. }
  12059. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  12060. void *data)
  12061. {
  12062. struct bnx2x *bp = netdev_priv(dev);
  12063. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12064. int rc;
  12065. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  12066. if (ops == NULL) {
  12067. BNX2X_ERR("NULL ops received\n");
  12068. return -EINVAL;
  12069. }
  12070. if (!CNIC_SUPPORT(bp)) {
  12071. BNX2X_ERR("Can't register CNIC when not supported\n");
  12072. return -EOPNOTSUPP;
  12073. }
  12074. if (!CNIC_LOADED(bp)) {
  12075. rc = bnx2x_load_cnic(bp);
  12076. if (rc) {
  12077. BNX2X_ERR("CNIC-related load failed\n");
  12078. return rc;
  12079. }
  12080. }
  12081. bp->cnic_enabled = true;
  12082. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  12083. if (!bp->cnic_kwq)
  12084. return -ENOMEM;
  12085. bp->cnic_kwq_cons = bp->cnic_kwq;
  12086. bp->cnic_kwq_prod = bp->cnic_kwq;
  12087. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  12088. bp->cnic_spq_pending = 0;
  12089. bp->cnic_kwq_pending = 0;
  12090. bp->cnic_data = data;
  12091. cp->num_irq = 0;
  12092. cp->drv_state |= CNIC_DRV_STATE_REGD;
  12093. cp->iro_arr = bp->iro_arr;
  12094. bnx2x_setup_cnic_irq_info(bp);
  12095. rcu_assign_pointer(bp->cnic_ops, ops);
  12096. /* Schedule driver to read CNIC driver versions */
  12097. bnx2x_schedule_sp_rtnl(bp, BNX2X_SP_RTNL_GET_DRV_VERSION, 0);
  12098. return 0;
  12099. }
  12100. static int bnx2x_unregister_cnic(struct net_device *dev)
  12101. {
  12102. struct bnx2x *bp = netdev_priv(dev);
  12103. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12104. mutex_lock(&bp->cnic_mutex);
  12105. cp->drv_state = 0;
  12106. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  12107. mutex_unlock(&bp->cnic_mutex);
  12108. synchronize_rcu();
  12109. bp->cnic_enabled = false;
  12110. kfree(bp->cnic_kwq);
  12111. bp->cnic_kwq = NULL;
  12112. return 0;
  12113. }
  12114. static struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  12115. {
  12116. struct bnx2x *bp = netdev_priv(dev);
  12117. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  12118. /* If both iSCSI and FCoE are disabled - return NULL in
  12119. * order to indicate CNIC that it should not try to work
  12120. * with this device.
  12121. */
  12122. if (NO_ISCSI(bp) && NO_FCOE(bp))
  12123. return NULL;
  12124. cp->drv_owner = THIS_MODULE;
  12125. cp->chip_id = CHIP_ID(bp);
  12126. cp->pdev = bp->pdev;
  12127. cp->io_base = bp->regview;
  12128. cp->io_base2 = bp->doorbells;
  12129. cp->max_kwqe_pending = 8;
  12130. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  12131. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  12132. bnx2x_cid_ilt_lines(bp);
  12133. cp->ctx_tbl_len = CNIC_ILT_LINES;
  12134. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  12135. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  12136. cp->drv_ctl = bnx2x_drv_ctl;
  12137. cp->drv_register_cnic = bnx2x_register_cnic;
  12138. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  12139. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  12140. cp->iscsi_l2_client_id =
  12141. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  12142. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  12143. if (NO_ISCSI_OOO(bp))
  12144. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  12145. if (NO_ISCSI(bp))
  12146. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  12147. if (NO_FCOE(bp))
  12148. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  12149. BNX2X_DEV_INFO(
  12150. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  12151. cp->ctx_blk_size,
  12152. cp->ctx_tbl_offset,
  12153. cp->ctx_tbl_len,
  12154. cp->starting_cid);
  12155. return cp;
  12156. }
  12157. static u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  12158. {
  12159. struct bnx2x *bp = fp->bp;
  12160. u32 offset = BAR_USTRORM_INTMEM;
  12161. if (IS_VF(bp))
  12162. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  12163. else if (!CHIP_IS_E1x(bp))
  12164. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  12165. else
  12166. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  12167. return offset;
  12168. }
  12169. /* called only on E1H or E2.
  12170. * When pretending to be PF, the pretend value is the function number 0...7
  12171. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  12172. * combination
  12173. */
  12174. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  12175. {
  12176. u32 pretend_reg;
  12177. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  12178. return -1;
  12179. /* get my own pretend register */
  12180. pretend_reg = bnx2x_get_pretend_reg(bp);
  12181. REG_WR(bp, pretend_reg, pretend_func_val);
  12182. REG_RD(bp, pretend_reg);
  12183. return 0;
  12184. }
  12185. static void bnx2x_ptp_task(struct work_struct *work)
  12186. {
  12187. struct bnx2x *bp = container_of(work, struct bnx2x, ptp_task);
  12188. int port = BP_PORT(bp);
  12189. u32 val_seq;
  12190. u64 timestamp, ns;
  12191. struct skb_shared_hwtstamps shhwtstamps;
  12192. /* Read Tx timestamp registers */
  12193. val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12194. NIG_REG_P0_TLLH_PTP_BUF_SEQID);
  12195. if (val_seq & 0x10000) {
  12196. /* There is a valid timestamp value */
  12197. timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
  12198. NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
  12199. timestamp <<= 32;
  12200. timestamp |= REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_LSB :
  12201. NIG_REG_P0_TLLH_PTP_BUF_TS_LSB);
  12202. /* Reset timestamp register to allow new timestamp */
  12203. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12204. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12205. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12206. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  12207. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  12208. skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
  12209. dev_kfree_skb_any(bp->ptp_tx_skb);
  12210. bp->ptp_tx_skb = NULL;
  12211. DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12212. timestamp, ns);
  12213. } else {
  12214. DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
  12215. /* Reschedule to keep checking for a valid timestamp value */
  12216. schedule_work(&bp->ptp_task);
  12217. }
  12218. }
  12219. void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
  12220. {
  12221. int port = BP_PORT(bp);
  12222. u64 timestamp, ns;
  12223. timestamp = REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_MSB :
  12224. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_MSB);
  12225. timestamp <<= 32;
  12226. timestamp |= REG_RD(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_TS_LSB :
  12227. NIG_REG_P0_LLH_PTP_HOST_BUF_TS_LSB);
  12228. /* Reset timestamp register to allow new timestamp */
  12229. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12230. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12231. ns = timecounter_cyc2time(&bp->timecounter, timestamp);
  12232. skb_hwtstamps(skb)->hwtstamp = ns_to_ktime(ns);
  12233. DP(BNX2X_MSG_PTP, "Rx timestamp, timestamp cycles = %llu, ns = %llu\n",
  12234. timestamp, ns);
  12235. }
  12236. /* Read the PHC */
  12237. static cycle_t bnx2x_cyclecounter_read(const struct cyclecounter *cc)
  12238. {
  12239. struct bnx2x *bp = container_of(cc, struct bnx2x, cyclecounter);
  12240. int port = BP_PORT(bp);
  12241. u32 wb_data[2];
  12242. u64 phc_cycles;
  12243. REG_RD_DMAE(bp, port ? NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t1 :
  12244. NIG_REG_TIMESYNC_GEN_REG + tsgen_synctime_t0, wb_data, 2);
  12245. phc_cycles = wb_data[1];
  12246. phc_cycles = (phc_cycles << 32) + wb_data[0];
  12247. DP(BNX2X_MSG_PTP, "PHC read cycles = %llu\n", phc_cycles);
  12248. return phc_cycles;
  12249. }
  12250. static void bnx2x_init_cyclecounter(struct bnx2x *bp)
  12251. {
  12252. memset(&bp->cyclecounter, 0, sizeof(bp->cyclecounter));
  12253. bp->cyclecounter.read = bnx2x_cyclecounter_read;
  12254. bp->cyclecounter.mask = CLOCKSOURCE_MASK(64);
  12255. bp->cyclecounter.shift = 1;
  12256. bp->cyclecounter.mult = 1;
  12257. }
  12258. static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
  12259. {
  12260. struct bnx2x_func_state_params func_params = {NULL};
  12261. struct bnx2x_func_set_timesync_params *set_timesync_params =
  12262. &func_params.params.set_timesync;
  12263. /* Prepare parameters for function state transitions */
  12264. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  12265. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  12266. func_params.f_obj = &bp->func_obj;
  12267. func_params.cmd = BNX2X_F_CMD_SET_TIMESYNC;
  12268. /* Function parameters */
  12269. set_timesync_params->drift_adjust_cmd = TS_DRIFT_ADJUST_RESET;
  12270. set_timesync_params->offset_cmd = TS_OFFSET_KEEP;
  12271. return bnx2x_func_state_change(bp, &func_params);
  12272. }
  12273. int bnx2x_enable_ptp_packets(struct bnx2x *bp)
  12274. {
  12275. struct bnx2x_queue_state_params q_params;
  12276. int rc, i;
  12277. /* send queue update ramrod to enable PTP packets */
  12278. memset(&q_params, 0, sizeof(q_params));
  12279. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  12280. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  12281. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG,
  12282. &q_params.params.update.update_flags);
  12283. __set_bit(BNX2X_Q_UPDATE_PTP_PKTS,
  12284. &q_params.params.update.update_flags);
  12285. /* send the ramrod on all the queues of the PF */
  12286. for_each_eth_queue(bp, i) {
  12287. struct bnx2x_fastpath *fp = &bp->fp[i];
  12288. /* Set the appropriate Queue object */
  12289. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  12290. /* Update the Queue state */
  12291. rc = bnx2x_queue_state_change(bp, &q_params);
  12292. if (rc) {
  12293. BNX2X_ERR("Failed to enable PTP packets\n");
  12294. return rc;
  12295. }
  12296. }
  12297. return 0;
  12298. }
  12299. int bnx2x_configure_ptp_filters(struct bnx2x *bp)
  12300. {
  12301. int port = BP_PORT(bp);
  12302. int rc;
  12303. if (!bp->hwtstamp_ioctl_called)
  12304. return 0;
  12305. switch (bp->tx_type) {
  12306. case HWTSTAMP_TX_ON:
  12307. bp->flags |= TX_TIMESTAMPING_EN;
  12308. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12309. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x6AA);
  12310. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12311. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3EEE);
  12312. break;
  12313. case HWTSTAMP_TX_ONESTEP_SYNC:
  12314. BNX2X_ERR("One-step timestamping is not supported\n");
  12315. return -ERANGE;
  12316. }
  12317. switch (bp->rx_filter) {
  12318. case HWTSTAMP_FILTER_NONE:
  12319. break;
  12320. case HWTSTAMP_FILTER_ALL:
  12321. case HWTSTAMP_FILTER_SOME:
  12322. bp->rx_filter = HWTSTAMP_FILTER_NONE;
  12323. break;
  12324. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  12325. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  12326. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  12327. bp->rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
  12328. /* Initialize PTP detection for UDP/IPv4 events */
  12329. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12330. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EE);
  12331. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12332. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFE);
  12333. break;
  12334. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  12335. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  12336. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  12337. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L4_EVENT;
  12338. /* Initialize PTP detection for UDP/IPv4 or UDP/IPv6 events */
  12339. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12340. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7EA);
  12341. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12342. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FEE);
  12343. break;
  12344. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  12345. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  12346. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  12347. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT;
  12348. /* Initialize PTP detection L2 events */
  12349. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12350. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6BF);
  12351. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12352. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EFF);
  12353. break;
  12354. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  12355. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  12356. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  12357. bp->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  12358. /* Initialize PTP detection L2, UDP/IPv4 or UDP/IPv6 events */
  12359. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12360. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x6AA);
  12361. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12362. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3EEE);
  12363. break;
  12364. }
  12365. /* Indicate to FW that this PF expects recorded PTP packets */
  12366. rc = bnx2x_enable_ptp_packets(bp);
  12367. if (rc)
  12368. return rc;
  12369. /* Enable sending PTP packets to host */
  12370. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12371. NIG_REG_P0_LLH_PTP_TO_HOST, 0x1);
  12372. return 0;
  12373. }
  12374. static int bnx2x_hwtstamp_ioctl(struct bnx2x *bp, struct ifreq *ifr)
  12375. {
  12376. struct hwtstamp_config config;
  12377. int rc;
  12378. DP(BNX2X_MSG_PTP, "HWTSTAMP IOCTL called\n");
  12379. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  12380. return -EFAULT;
  12381. DP(BNX2X_MSG_PTP, "Requested tx_type: %d, requested rx_filters = %d\n",
  12382. config.tx_type, config.rx_filter);
  12383. if (config.flags) {
  12384. BNX2X_ERR("config.flags is reserved for future use\n");
  12385. return -EINVAL;
  12386. }
  12387. bp->hwtstamp_ioctl_called = 1;
  12388. bp->tx_type = config.tx_type;
  12389. bp->rx_filter = config.rx_filter;
  12390. rc = bnx2x_configure_ptp_filters(bp);
  12391. if (rc)
  12392. return rc;
  12393. config.rx_filter = bp->rx_filter;
  12394. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  12395. -EFAULT : 0;
  12396. }
  12397. /* Configures HW for PTP */
  12398. static int bnx2x_configure_ptp(struct bnx2x *bp)
  12399. {
  12400. int rc, port = BP_PORT(bp);
  12401. u32 wb_data[2];
  12402. /* Reset PTP event detection rules - will be configured in the IOCTL */
  12403. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_PARAM_MASK :
  12404. NIG_REG_P0_LLH_PTP_PARAM_MASK, 0x7FF);
  12405. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_RULE_MASK :
  12406. NIG_REG_P0_LLH_PTP_RULE_MASK, 0x3FFF);
  12407. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_PARAM_MASK :
  12408. NIG_REG_P0_TLLH_PTP_PARAM_MASK, 0x7FF);
  12409. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_RULE_MASK :
  12410. NIG_REG_P0_TLLH_PTP_RULE_MASK, 0x3FFF);
  12411. /* Disable PTP packets to host - will be configured in the IOCTL*/
  12412. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_TO_HOST :
  12413. NIG_REG_P0_LLH_PTP_TO_HOST, 0x0);
  12414. /* Enable the PTP feature */
  12415. REG_WR(bp, port ? NIG_REG_P1_PTP_EN :
  12416. NIG_REG_P0_PTP_EN, 0x3F);
  12417. /* Enable the free-running counter */
  12418. wb_data[0] = 0;
  12419. wb_data[1] = 0;
  12420. REG_WR_DMAE(bp, NIG_REG_TIMESYNC_GEN_REG + tsgen_ctrl, wb_data, 2);
  12421. /* Reset drift register (offset register is not reset) */
  12422. rc = bnx2x_send_reset_timesync_ramrod(bp);
  12423. if (rc) {
  12424. BNX2X_ERR("Failed to reset PHC drift register\n");
  12425. return -EFAULT;
  12426. }
  12427. /* Reset possibly old timestamps */
  12428. REG_WR(bp, port ? NIG_REG_P1_LLH_PTP_HOST_BUF_SEQID :
  12429. NIG_REG_P0_LLH_PTP_HOST_BUF_SEQID, 0x10000);
  12430. REG_WR(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
  12431. NIG_REG_P0_TLLH_PTP_BUF_SEQID, 0x10000);
  12432. return 0;
  12433. }
  12434. /* Called during load, to initialize PTP-related stuff */
  12435. void bnx2x_init_ptp(struct bnx2x *bp)
  12436. {
  12437. int rc;
  12438. /* Configure PTP in HW */
  12439. rc = bnx2x_configure_ptp(bp);
  12440. if (rc) {
  12441. BNX2X_ERR("Stopping PTP initialization\n");
  12442. return;
  12443. }
  12444. /* Init work queue for Tx timestamping */
  12445. INIT_WORK(&bp->ptp_task, bnx2x_ptp_task);
  12446. /* Init cyclecounter and timecounter. This is done only in the first
  12447. * load. If done in every load, PTP application will fail when doing
  12448. * unload / load (e.g. MTU change) while it is running.
  12449. */
  12450. if (!bp->timecounter_init_done) {
  12451. bnx2x_init_cyclecounter(bp);
  12452. timecounter_init(&bp->timecounter, &bp->cyclecounter,
  12453. ktime_to_ns(ktime_get_real()));
  12454. bp->timecounter_init_done = 1;
  12455. }
  12456. DP(BNX2X_MSG_PTP, "PTP initialization ended successfully\n");
  12457. }