bnx2x_main.c 361 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 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: Eilon Greenstein <eilong@broadcom.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/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_vfpf.h"
  60. #include "bnx2x_sriov.h"
  61. #include "bnx2x_dcb.h"
  62. #include "bnx2x_sp.h"
  63. #include <linux/firmware.h>
  64. #include "bnx2x_fw_file_hdr.h"
  65. /* FW files */
  66. #define FW_FILE_VERSION \
  67. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  69. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  70. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  71. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  73. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  74. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  75. /* Time in jiffies before concluding the transmitter is hung */
  76. #define TX_TIMEOUT (5*HZ)
  77. static char version[] =
  78. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  79. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  80. MODULE_AUTHOR("Eliezer Tamir");
  81. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  82. "BCM57710/57711/57711E/"
  83. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  84. "57840/57840_MF Driver");
  85. MODULE_LICENSE("GPL");
  86. MODULE_VERSION(DRV_MODULE_VERSION);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  89. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  90. int num_queues;
  91. module_param(num_queues, int, 0);
  92. MODULE_PARM_DESC(num_queues,
  93. " Set number of queues (default is as a number of CPUs)");
  94. static int disable_tpa;
  95. module_param(disable_tpa, int, 0);
  96. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  97. #define INT_MODE_INTx 1
  98. #define INT_MODE_MSI 2
  99. int int_mode;
  100. module_param(int_mode, int, 0);
  101. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  102. "(1 INT#x; 2 MSI)");
  103. static int dropless_fc;
  104. module_param(dropless_fc, int, 0);
  105. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  106. static int mrrs = -1;
  107. module_param(mrrs, int, 0);
  108. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  109. static int debug;
  110. module_param(debug, int, 0);
  111. MODULE_PARM_DESC(debug, " Default debug msglevel");
  112. struct workqueue_struct *bnx2x_wq;
  113. enum bnx2x_board_type {
  114. BCM57710 = 0,
  115. BCM57711,
  116. BCM57711E,
  117. BCM57712,
  118. BCM57712_MF,
  119. BCM57712_VF,
  120. BCM57800,
  121. BCM57800_MF,
  122. BCM57800_VF,
  123. BCM57810,
  124. BCM57810_MF,
  125. BCM57810_VF,
  126. BCM57840_4_10,
  127. BCM57840_2_20,
  128. BCM57840_MF,
  129. BCM57840_VF,
  130. BCM57811,
  131. BCM57811_MF,
  132. BCM57840_O,
  133. BCM57840_MFO,
  134. BCM57811_VF
  135. };
  136. /* indexed by board_type, above */
  137. static struct {
  138. char *name;
  139. } board_info[] = {
  140. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  141. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  142. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  143. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  144. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  145. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  146. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  147. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  148. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  149. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  150. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  151. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  152. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  153. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  154. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  155. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  156. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  157. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  158. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  159. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  160. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  161. };
  162. #ifndef PCI_DEVICE_ID_NX2_57710
  163. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57711
  166. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57711E
  169. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57712
  172. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  175. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57800
  178. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  181. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57810
  184. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  187. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57840_O
  190. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  193. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  196. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  199. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  202. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57811
  205. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  208. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  209. #endif
  210. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  211. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  212. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  213. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  214. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  215. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  216. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  217. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  218. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  219. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  220. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  221. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  222. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  223. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  224. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  225. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  226. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  227. { 0 }
  228. };
  229. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  230. /* Global resources for unloading a previously loaded device */
  231. #define BNX2X_PREV_WAIT_NEEDED 1
  232. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  233. static LIST_HEAD(bnx2x_prev_list);
  234. /****************************************************************************
  235. * General service functions
  236. ****************************************************************************/
  237. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  238. u32 addr, dma_addr_t mapping)
  239. {
  240. REG_WR(bp, addr, U64_LO(mapping));
  241. REG_WR(bp, addr + 4, U64_HI(mapping));
  242. }
  243. static void storm_memset_spq_addr(struct bnx2x *bp,
  244. dma_addr_t mapping, u16 abs_fid)
  245. {
  246. u32 addr = XSEM_REG_FAST_MEMORY +
  247. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  248. __storm_memset_dma_mapping(bp, addr, mapping);
  249. }
  250. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  251. u16 pf_id)
  252. {
  253. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  254. pf_id);
  255. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  256. pf_id);
  257. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  258. pf_id);
  259. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  260. pf_id);
  261. }
  262. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  263. u8 enable)
  264. {
  265. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  266. enable);
  267. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  268. enable);
  269. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  270. enable);
  271. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  272. enable);
  273. }
  274. static void storm_memset_eq_data(struct bnx2x *bp,
  275. struct event_ring_data *eq_data,
  276. u16 pfid)
  277. {
  278. size_t size = sizeof(struct event_ring_data);
  279. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  280. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  281. }
  282. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  283. u16 pfid)
  284. {
  285. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  286. REG_WR16(bp, addr, eq_prod);
  287. }
  288. /* used only at init
  289. * locking is done by mcp
  290. */
  291. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  292. {
  293. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  294. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  295. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  296. PCICFG_VENDOR_ID_OFFSET);
  297. }
  298. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  299. {
  300. u32 val;
  301. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  302. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  303. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  304. PCICFG_VENDOR_ID_OFFSET);
  305. return val;
  306. }
  307. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  308. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  309. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  310. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  311. #define DMAE_DP_DST_NONE "dst_addr [none]"
  312. /* copy command into DMAE command memory and set DMAE command go */
  313. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  314. {
  315. u32 cmd_offset;
  316. int i;
  317. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  318. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  319. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  320. }
  321. REG_WR(bp, dmae_reg_go_c[idx], 1);
  322. }
  323. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  324. {
  325. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  326. DMAE_CMD_C_ENABLE);
  327. }
  328. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  329. {
  330. return opcode & ~DMAE_CMD_SRC_RESET;
  331. }
  332. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  333. bool with_comp, u8 comp_type)
  334. {
  335. u32 opcode = 0;
  336. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  337. (dst_type << DMAE_COMMAND_DST_SHIFT));
  338. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  339. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  340. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  341. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  342. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  343. #ifdef __BIG_ENDIAN
  344. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  345. #else
  346. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  347. #endif
  348. if (with_comp)
  349. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  350. return opcode;
  351. }
  352. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  353. struct dmae_command *dmae,
  354. u8 src_type, u8 dst_type)
  355. {
  356. memset(dmae, 0, sizeof(struct dmae_command));
  357. /* set the opcode */
  358. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  359. true, DMAE_COMP_PCI);
  360. /* fill in the completion parameters */
  361. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  362. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  363. dmae->comp_val = DMAE_COMP_VAL;
  364. }
  365. /* issue a dmae command over the init-channel and wailt for completion */
  366. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  367. struct dmae_command *dmae)
  368. {
  369. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  370. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  371. int rc = 0;
  372. /*
  373. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  374. * as long as this code is called both from syscall context and
  375. * from ndo_set_rx_mode() flow that may be called from BH.
  376. */
  377. spin_lock_bh(&bp->dmae_lock);
  378. /* reset completion */
  379. *wb_comp = 0;
  380. /* post the command on the channel used for initializations */
  381. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  382. /* wait for completion */
  383. udelay(5);
  384. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  385. if (!cnt ||
  386. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  387. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  388. BNX2X_ERR("DMAE timeout!\n");
  389. rc = DMAE_TIMEOUT;
  390. goto unlock;
  391. }
  392. cnt--;
  393. udelay(50);
  394. }
  395. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  396. BNX2X_ERR("DMAE PCI error!\n");
  397. rc = DMAE_PCI_ERROR;
  398. }
  399. unlock:
  400. spin_unlock_bh(&bp->dmae_lock);
  401. return rc;
  402. }
  403. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  404. u32 len32)
  405. {
  406. struct dmae_command dmae;
  407. if (!bp->dmae_ready) {
  408. u32 *data = bnx2x_sp(bp, wb_data[0]);
  409. if (CHIP_IS_E1(bp))
  410. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  411. else
  412. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  413. return;
  414. }
  415. /* set opcode and fixed command fields */
  416. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  417. /* fill in addresses and len */
  418. dmae.src_addr_lo = U64_LO(dma_addr);
  419. dmae.src_addr_hi = U64_HI(dma_addr);
  420. dmae.dst_addr_lo = dst_addr >> 2;
  421. dmae.dst_addr_hi = 0;
  422. dmae.len = len32;
  423. /* issue the command and wait for completion */
  424. bnx2x_issue_dmae_with_comp(bp, &dmae);
  425. }
  426. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  427. {
  428. struct dmae_command dmae;
  429. if (!bp->dmae_ready) {
  430. u32 *data = bnx2x_sp(bp, wb_data[0]);
  431. int i;
  432. if (CHIP_IS_E1(bp))
  433. for (i = 0; i < len32; i++)
  434. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  435. else
  436. for (i = 0; i < len32; i++)
  437. data[i] = REG_RD(bp, src_addr + i*4);
  438. return;
  439. }
  440. /* set opcode and fixed command fields */
  441. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  442. /* fill in addresses and len */
  443. dmae.src_addr_lo = src_addr >> 2;
  444. dmae.src_addr_hi = 0;
  445. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  446. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  447. dmae.len = len32;
  448. /* issue the command and wait for completion */
  449. bnx2x_issue_dmae_with_comp(bp, &dmae);
  450. }
  451. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  452. u32 addr, u32 len)
  453. {
  454. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  455. int offset = 0;
  456. while (len > dmae_wr_max) {
  457. bnx2x_write_dmae(bp, phys_addr + offset,
  458. addr + offset, dmae_wr_max);
  459. offset += dmae_wr_max * 4;
  460. len -= dmae_wr_max;
  461. }
  462. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  463. }
  464. static int bnx2x_mc_assert(struct bnx2x *bp)
  465. {
  466. char last_idx;
  467. int i, rc = 0;
  468. u32 row0, row1, row2, row3;
  469. /* XSTORM */
  470. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  471. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  472. if (last_idx)
  473. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  474. /* print the asserts */
  475. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  476. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  477. XSTORM_ASSERT_LIST_OFFSET(i));
  478. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  479. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  480. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  481. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  482. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  483. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  484. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  485. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  486. i, row3, row2, row1, row0);
  487. rc++;
  488. } else {
  489. break;
  490. }
  491. }
  492. /* TSTORM */
  493. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  494. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  495. if (last_idx)
  496. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  497. /* print the asserts */
  498. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  499. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  500. TSTORM_ASSERT_LIST_OFFSET(i));
  501. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  502. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  503. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  504. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  505. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  506. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  507. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  508. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  509. i, row3, row2, row1, row0);
  510. rc++;
  511. } else {
  512. break;
  513. }
  514. }
  515. /* CSTORM */
  516. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  517. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  518. if (last_idx)
  519. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  520. /* print the asserts */
  521. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  522. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  523. CSTORM_ASSERT_LIST_OFFSET(i));
  524. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  525. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  526. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  527. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  528. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  529. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  530. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  531. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  532. i, row3, row2, row1, row0);
  533. rc++;
  534. } else {
  535. break;
  536. }
  537. }
  538. /* USTORM */
  539. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  540. USTORM_ASSERT_LIST_INDEX_OFFSET);
  541. if (last_idx)
  542. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  543. /* print the asserts */
  544. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  545. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  546. USTORM_ASSERT_LIST_OFFSET(i));
  547. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  548. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  549. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  550. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  551. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  552. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  553. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  554. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  555. i, row3, row2, row1, row0);
  556. rc++;
  557. } else {
  558. break;
  559. }
  560. }
  561. return rc;
  562. }
  563. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  564. {
  565. u32 addr, val;
  566. u32 mark, offset;
  567. __be32 data[9];
  568. int word;
  569. u32 trace_shmem_base;
  570. if (BP_NOMCP(bp)) {
  571. BNX2X_ERR("NO MCP - can not dump\n");
  572. return;
  573. }
  574. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  575. (bp->common.bc_ver & 0xff0000) >> 16,
  576. (bp->common.bc_ver & 0xff00) >> 8,
  577. (bp->common.bc_ver & 0xff));
  578. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  579. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  580. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  581. if (BP_PATH(bp) == 0)
  582. trace_shmem_base = bp->common.shmem_base;
  583. else
  584. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  585. addr = trace_shmem_base - 0x800;
  586. /* validate TRCB signature */
  587. mark = REG_RD(bp, addr);
  588. if (mark != MFW_TRACE_SIGNATURE) {
  589. BNX2X_ERR("Trace buffer signature is missing.");
  590. return ;
  591. }
  592. /* read cyclic buffer pointer */
  593. addr += 4;
  594. mark = REG_RD(bp, addr);
  595. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  596. + ((mark + 0x3) & ~0x3) - 0x08000000;
  597. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  598. printk("%s", lvl);
  599. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  600. for (word = 0; word < 8; word++)
  601. data[word] = htonl(REG_RD(bp, offset + 4*word));
  602. data[8] = 0x0;
  603. pr_cont("%s", (char *)data);
  604. }
  605. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  606. for (word = 0; word < 8; word++)
  607. data[word] = htonl(REG_RD(bp, offset + 4*word));
  608. data[8] = 0x0;
  609. pr_cont("%s", (char *)data);
  610. }
  611. printk("%s" "end of fw dump\n", lvl);
  612. }
  613. static void bnx2x_fw_dump(struct bnx2x *bp)
  614. {
  615. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  616. }
  617. void bnx2x_panic_dump(struct bnx2x *bp)
  618. {
  619. int i;
  620. u16 j;
  621. struct hc_sp_status_block_data sp_sb_data;
  622. int func = BP_FUNC(bp);
  623. #ifdef BNX2X_STOP_ON_ERROR
  624. u16 start = 0, end = 0;
  625. u8 cos;
  626. #endif
  627. bp->stats_state = STATS_STATE_DISABLED;
  628. bp->eth_stats.unrecoverable_error++;
  629. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  630. BNX2X_ERR("begin crash dump -----------------\n");
  631. /* Indices */
  632. /* Common */
  633. 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",
  634. bp->def_idx, bp->def_att_idx, bp->attn_state,
  635. bp->spq_prod_idx, bp->stats_counter);
  636. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  637. bp->def_status_blk->atten_status_block.attn_bits,
  638. bp->def_status_blk->atten_status_block.attn_bits_ack,
  639. bp->def_status_blk->atten_status_block.status_block_id,
  640. bp->def_status_blk->atten_status_block.attn_bits_index);
  641. BNX2X_ERR(" def (");
  642. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  643. pr_cont("0x%x%s",
  644. bp->def_status_blk->sp_sb.index_values[i],
  645. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  646. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  647. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  648. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  649. i*sizeof(u32));
  650. 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",
  651. sp_sb_data.igu_sb_id,
  652. sp_sb_data.igu_seg_id,
  653. sp_sb_data.p_func.pf_id,
  654. sp_sb_data.p_func.vnic_id,
  655. sp_sb_data.p_func.vf_id,
  656. sp_sb_data.p_func.vf_valid,
  657. sp_sb_data.state);
  658. for_each_eth_queue(bp, i) {
  659. struct bnx2x_fastpath *fp = &bp->fp[i];
  660. int loop;
  661. struct hc_status_block_data_e2 sb_data_e2;
  662. struct hc_status_block_data_e1x sb_data_e1x;
  663. struct hc_status_block_sm *hc_sm_p =
  664. CHIP_IS_E1x(bp) ?
  665. sb_data_e1x.common.state_machine :
  666. sb_data_e2.common.state_machine;
  667. struct hc_index_data *hc_index_p =
  668. CHIP_IS_E1x(bp) ?
  669. sb_data_e1x.index_data :
  670. sb_data_e2.index_data;
  671. u8 data_size, cos;
  672. u32 *sb_data_p;
  673. struct bnx2x_fp_txdata txdata;
  674. /* Rx */
  675. 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",
  676. i, fp->rx_bd_prod, fp->rx_bd_cons,
  677. fp->rx_comp_prod,
  678. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  679. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  680. fp->rx_sge_prod, fp->last_max_sge,
  681. le16_to_cpu(fp->fp_hc_idx));
  682. /* Tx */
  683. for_each_cos_in_tx_queue(fp, cos)
  684. {
  685. txdata = *fp->txdata_ptr[cos];
  686. 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",
  687. i, txdata.tx_pkt_prod,
  688. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  689. txdata.tx_bd_cons,
  690. le16_to_cpu(*txdata.tx_cons_sb));
  691. }
  692. loop = CHIP_IS_E1x(bp) ?
  693. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  694. /* host sb data */
  695. if (IS_FCOE_FP(fp))
  696. continue;
  697. BNX2X_ERR(" run indexes (");
  698. for (j = 0; j < HC_SB_MAX_SM; j++)
  699. pr_cont("0x%x%s",
  700. fp->sb_running_index[j],
  701. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  702. BNX2X_ERR(" indexes (");
  703. for (j = 0; j < loop; j++)
  704. pr_cont("0x%x%s",
  705. fp->sb_index_values[j],
  706. (j == loop - 1) ? ")" : " ");
  707. /* fw sb data */
  708. data_size = CHIP_IS_E1x(bp) ?
  709. sizeof(struct hc_status_block_data_e1x) :
  710. sizeof(struct hc_status_block_data_e2);
  711. data_size /= sizeof(u32);
  712. sb_data_p = CHIP_IS_E1x(bp) ?
  713. (u32 *)&sb_data_e1x :
  714. (u32 *)&sb_data_e2;
  715. /* copy sb data in here */
  716. for (j = 0; j < data_size; j++)
  717. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  718. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  719. j * sizeof(u32));
  720. if (!CHIP_IS_E1x(bp)) {
  721. 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",
  722. sb_data_e2.common.p_func.pf_id,
  723. sb_data_e2.common.p_func.vf_id,
  724. sb_data_e2.common.p_func.vf_valid,
  725. sb_data_e2.common.p_func.vnic_id,
  726. sb_data_e2.common.same_igu_sb_1b,
  727. sb_data_e2.common.state);
  728. } else {
  729. 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",
  730. sb_data_e1x.common.p_func.pf_id,
  731. sb_data_e1x.common.p_func.vf_id,
  732. sb_data_e1x.common.p_func.vf_valid,
  733. sb_data_e1x.common.p_func.vnic_id,
  734. sb_data_e1x.common.same_igu_sb_1b,
  735. sb_data_e1x.common.state);
  736. }
  737. /* SB_SMs data */
  738. for (j = 0; j < HC_SB_MAX_SM; j++) {
  739. 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",
  740. j, hc_sm_p[j].__flags,
  741. hc_sm_p[j].igu_sb_id,
  742. hc_sm_p[j].igu_seg_id,
  743. hc_sm_p[j].time_to_expire,
  744. hc_sm_p[j].timer_value);
  745. }
  746. /* Indecies data */
  747. for (j = 0; j < loop; j++) {
  748. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  749. hc_index_p[j].flags,
  750. hc_index_p[j].timeout);
  751. }
  752. }
  753. #ifdef BNX2X_STOP_ON_ERROR
  754. /* Rings */
  755. /* Rx */
  756. for_each_valid_rx_queue(bp, i) {
  757. struct bnx2x_fastpath *fp = &bp->fp[i];
  758. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  759. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  760. for (j = start; j != end; j = RX_BD(j + 1)) {
  761. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  762. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  763. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  764. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  765. }
  766. start = RX_SGE(fp->rx_sge_prod);
  767. end = RX_SGE(fp->last_max_sge);
  768. for (j = start; j != end; j = RX_SGE(j + 1)) {
  769. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  770. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  771. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  772. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  773. }
  774. start = RCQ_BD(fp->rx_comp_cons - 10);
  775. end = RCQ_BD(fp->rx_comp_cons + 503);
  776. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  777. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  778. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  779. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  780. }
  781. }
  782. /* Tx */
  783. for_each_valid_tx_queue(bp, i) {
  784. struct bnx2x_fastpath *fp = &bp->fp[i];
  785. for_each_cos_in_tx_queue(fp, cos) {
  786. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  787. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  788. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  789. for (j = start; j != end; j = TX_BD(j + 1)) {
  790. struct sw_tx_bd *sw_bd =
  791. &txdata->tx_buf_ring[j];
  792. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  793. i, cos, j, sw_bd->skb,
  794. sw_bd->first_bd);
  795. }
  796. start = TX_BD(txdata->tx_bd_cons - 10);
  797. end = TX_BD(txdata->tx_bd_cons + 254);
  798. for (j = start; j != end; j = TX_BD(j + 1)) {
  799. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  800. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  801. i, cos, j, tx_bd[0], tx_bd[1],
  802. tx_bd[2], tx_bd[3]);
  803. }
  804. }
  805. }
  806. #endif
  807. bnx2x_fw_dump(bp);
  808. bnx2x_mc_assert(bp);
  809. BNX2X_ERR("end crash dump -----------------\n");
  810. }
  811. /*
  812. * FLR Support for E2
  813. *
  814. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  815. * initialization.
  816. */
  817. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  818. #define FLR_WAIT_INTERVAL 50 /* usec */
  819. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  820. struct pbf_pN_buf_regs {
  821. int pN;
  822. u32 init_crd;
  823. u32 crd;
  824. u32 crd_freed;
  825. };
  826. struct pbf_pN_cmd_regs {
  827. int pN;
  828. u32 lines_occup;
  829. u32 lines_freed;
  830. };
  831. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  832. struct pbf_pN_buf_regs *regs,
  833. u32 poll_count)
  834. {
  835. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  836. u32 cur_cnt = poll_count;
  837. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  838. crd = crd_start = REG_RD(bp, regs->crd);
  839. init_crd = REG_RD(bp, regs->init_crd);
  840. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  841. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  842. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  843. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  844. (init_crd - crd_start))) {
  845. if (cur_cnt--) {
  846. udelay(FLR_WAIT_INTERVAL);
  847. crd = REG_RD(bp, regs->crd);
  848. crd_freed = REG_RD(bp, regs->crd_freed);
  849. } else {
  850. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  851. regs->pN);
  852. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  853. regs->pN, crd);
  854. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  855. regs->pN, crd_freed);
  856. break;
  857. }
  858. }
  859. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  860. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  861. }
  862. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  863. struct pbf_pN_cmd_regs *regs,
  864. u32 poll_count)
  865. {
  866. u32 occup, to_free, freed, freed_start;
  867. u32 cur_cnt = poll_count;
  868. occup = to_free = REG_RD(bp, regs->lines_occup);
  869. freed = freed_start = REG_RD(bp, regs->lines_freed);
  870. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  871. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  872. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  873. if (cur_cnt--) {
  874. udelay(FLR_WAIT_INTERVAL);
  875. occup = REG_RD(bp, regs->lines_occup);
  876. freed = REG_RD(bp, regs->lines_freed);
  877. } else {
  878. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  879. regs->pN);
  880. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  881. regs->pN, occup);
  882. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  883. regs->pN, freed);
  884. break;
  885. }
  886. }
  887. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  888. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  889. }
  890. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  891. u32 expected, u32 poll_count)
  892. {
  893. u32 cur_cnt = poll_count;
  894. u32 val;
  895. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  896. udelay(FLR_WAIT_INTERVAL);
  897. return val;
  898. }
  899. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  900. char *msg, u32 poll_cnt)
  901. {
  902. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  903. if (val != 0) {
  904. BNX2X_ERR("%s usage count=%d\n", msg, val);
  905. return 1;
  906. }
  907. return 0;
  908. }
  909. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  910. {
  911. /* adjust polling timeout */
  912. if (CHIP_REV_IS_EMUL(bp))
  913. return FLR_POLL_CNT * 2000;
  914. if (CHIP_REV_IS_FPGA(bp))
  915. return FLR_POLL_CNT * 120;
  916. return FLR_POLL_CNT;
  917. }
  918. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  919. {
  920. struct pbf_pN_cmd_regs cmd_regs[] = {
  921. {0, (CHIP_IS_E3B0(bp)) ?
  922. PBF_REG_TQ_OCCUPANCY_Q0 :
  923. PBF_REG_P0_TQ_OCCUPANCY,
  924. (CHIP_IS_E3B0(bp)) ?
  925. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  926. PBF_REG_P0_TQ_LINES_FREED_CNT},
  927. {1, (CHIP_IS_E3B0(bp)) ?
  928. PBF_REG_TQ_OCCUPANCY_Q1 :
  929. PBF_REG_P1_TQ_OCCUPANCY,
  930. (CHIP_IS_E3B0(bp)) ?
  931. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  932. PBF_REG_P1_TQ_LINES_FREED_CNT},
  933. {4, (CHIP_IS_E3B0(bp)) ?
  934. PBF_REG_TQ_OCCUPANCY_LB_Q :
  935. PBF_REG_P4_TQ_OCCUPANCY,
  936. (CHIP_IS_E3B0(bp)) ?
  937. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  938. PBF_REG_P4_TQ_LINES_FREED_CNT}
  939. };
  940. struct pbf_pN_buf_regs buf_regs[] = {
  941. {0, (CHIP_IS_E3B0(bp)) ?
  942. PBF_REG_INIT_CRD_Q0 :
  943. PBF_REG_P0_INIT_CRD ,
  944. (CHIP_IS_E3B0(bp)) ?
  945. PBF_REG_CREDIT_Q0 :
  946. PBF_REG_P0_CREDIT,
  947. (CHIP_IS_E3B0(bp)) ?
  948. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  949. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  950. {1, (CHIP_IS_E3B0(bp)) ?
  951. PBF_REG_INIT_CRD_Q1 :
  952. PBF_REG_P1_INIT_CRD,
  953. (CHIP_IS_E3B0(bp)) ?
  954. PBF_REG_CREDIT_Q1 :
  955. PBF_REG_P1_CREDIT,
  956. (CHIP_IS_E3B0(bp)) ?
  957. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  958. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  959. {4, (CHIP_IS_E3B0(bp)) ?
  960. PBF_REG_INIT_CRD_LB_Q :
  961. PBF_REG_P4_INIT_CRD,
  962. (CHIP_IS_E3B0(bp)) ?
  963. PBF_REG_CREDIT_LB_Q :
  964. PBF_REG_P4_CREDIT,
  965. (CHIP_IS_E3B0(bp)) ?
  966. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  967. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  968. };
  969. int i;
  970. /* Verify the command queues are flushed P0, P1, P4 */
  971. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  972. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  973. /* Verify the transmission buffers are flushed P0, P1, P4 */
  974. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  975. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  976. }
  977. #define OP_GEN_PARAM(param) \
  978. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  979. #define OP_GEN_TYPE(type) \
  980. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  981. #define OP_GEN_AGG_VECT(index) \
  982. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  983. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  984. u32 poll_cnt)
  985. {
  986. struct sdm_op_gen op_gen = {0};
  987. u32 comp_addr = BAR_CSTRORM_INTMEM +
  988. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  989. int ret = 0;
  990. if (REG_RD(bp, comp_addr)) {
  991. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  992. return 1;
  993. }
  994. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  995. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  996. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  997. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  998. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  999. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1000. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1001. BNX2X_ERR("FW final cleanup did not succeed\n");
  1002. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1003. (REG_RD(bp, comp_addr)));
  1004. ret = 1;
  1005. }
  1006. /* Zero completion for nxt FLR */
  1007. REG_WR(bp, comp_addr, 0);
  1008. return ret;
  1009. }
  1010. static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1011. {
  1012. u16 status;
  1013. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1014. return status & PCI_EXP_DEVSTA_TRPND;
  1015. }
  1016. /* PF FLR specific routines
  1017. */
  1018. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1019. {
  1020. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1021. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1022. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1023. "CFC PF usage counter timed out",
  1024. poll_cnt))
  1025. return 1;
  1026. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1027. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1028. DORQ_REG_PF_USAGE_CNT,
  1029. "DQ PF usage counter timed out",
  1030. poll_cnt))
  1031. return 1;
  1032. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1033. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1034. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1035. "QM PF usage counter timed out",
  1036. poll_cnt))
  1037. return 1;
  1038. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1039. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1040. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1041. "Timers VNIC usage counter timed out",
  1042. poll_cnt))
  1043. return 1;
  1044. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1045. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1046. "Timers NUM_SCANS usage counter timed out",
  1047. poll_cnt))
  1048. return 1;
  1049. /* Wait DMAE PF usage counter to zero */
  1050. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1051. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1052. "DMAE dommand register timed out",
  1053. poll_cnt))
  1054. return 1;
  1055. return 0;
  1056. }
  1057. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1058. {
  1059. u32 val;
  1060. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1061. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1062. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1063. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1064. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1065. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1066. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1067. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1068. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1069. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1070. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1071. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1072. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1073. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1074. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1075. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1076. val);
  1077. }
  1078. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1079. {
  1080. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1081. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1082. /* Re-enable PF target read access */
  1083. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1084. /* Poll HW usage counters */
  1085. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1086. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1087. return -EBUSY;
  1088. /* Zero the igu 'trailing edge' and 'leading edge' */
  1089. /* Send the FW cleanup command */
  1090. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1091. return -EBUSY;
  1092. /* ATC cleanup */
  1093. /* Verify TX hw is flushed */
  1094. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1095. /* Wait 100ms (not adjusted according to platform) */
  1096. msleep(100);
  1097. /* Verify no pending pci transactions */
  1098. if (bnx2x_is_pcie_pending(bp->pdev))
  1099. BNX2X_ERR("PCIE Transactions still pending\n");
  1100. /* Debug */
  1101. bnx2x_hw_enable_status(bp);
  1102. /*
  1103. * Master enable - Due to WB DMAE writes performed before this
  1104. * register is re-initialized as part of the regular function init
  1105. */
  1106. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1107. return 0;
  1108. }
  1109. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1110. {
  1111. int port = BP_PORT(bp);
  1112. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1113. u32 val = REG_RD(bp, addr);
  1114. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1115. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1116. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1117. if (msix) {
  1118. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1119. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1120. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1121. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1122. if (single_msix)
  1123. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1124. } else if (msi) {
  1125. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1126. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1127. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1128. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1129. } else {
  1130. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1131. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1132. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1133. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1134. if (!CHIP_IS_E1(bp)) {
  1135. DP(NETIF_MSG_IFUP,
  1136. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1137. REG_WR(bp, addr, val);
  1138. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1139. }
  1140. }
  1141. if (CHIP_IS_E1(bp))
  1142. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1143. DP(NETIF_MSG_IFUP,
  1144. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1145. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1146. REG_WR(bp, addr, val);
  1147. /*
  1148. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1149. */
  1150. mmiowb();
  1151. barrier();
  1152. if (!CHIP_IS_E1(bp)) {
  1153. /* init leading/trailing edge */
  1154. if (IS_MF(bp)) {
  1155. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1156. if (bp->port.pmf)
  1157. /* enable nig and gpio3 attention */
  1158. val |= 0x1100;
  1159. } else
  1160. val = 0xffff;
  1161. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1162. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1163. }
  1164. /* Make sure that interrupts are indeed enabled from here on */
  1165. mmiowb();
  1166. }
  1167. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1168. {
  1169. u32 val;
  1170. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1171. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1172. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1173. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1174. if (msix) {
  1175. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1176. IGU_PF_CONF_SINGLE_ISR_EN);
  1177. val |= (IGU_PF_CONF_FUNC_EN |
  1178. IGU_PF_CONF_MSI_MSIX_EN |
  1179. IGU_PF_CONF_ATTN_BIT_EN);
  1180. if (single_msix)
  1181. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1182. } else if (msi) {
  1183. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1184. val |= (IGU_PF_CONF_FUNC_EN |
  1185. IGU_PF_CONF_MSI_MSIX_EN |
  1186. IGU_PF_CONF_ATTN_BIT_EN |
  1187. IGU_PF_CONF_SINGLE_ISR_EN);
  1188. } else {
  1189. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1190. val |= (IGU_PF_CONF_FUNC_EN |
  1191. IGU_PF_CONF_INT_LINE_EN |
  1192. IGU_PF_CONF_ATTN_BIT_EN |
  1193. IGU_PF_CONF_SINGLE_ISR_EN);
  1194. }
  1195. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1196. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1197. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1198. if (val & IGU_PF_CONF_INT_LINE_EN)
  1199. pci_intx(bp->pdev, true);
  1200. barrier();
  1201. /* init leading/trailing edge */
  1202. if (IS_MF(bp)) {
  1203. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1204. if (bp->port.pmf)
  1205. /* enable nig and gpio3 attention */
  1206. val |= 0x1100;
  1207. } else
  1208. val = 0xffff;
  1209. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1210. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1211. /* Make sure that interrupts are indeed enabled from here on */
  1212. mmiowb();
  1213. }
  1214. void bnx2x_int_enable(struct bnx2x *bp)
  1215. {
  1216. if (bp->common.int_block == INT_BLOCK_HC)
  1217. bnx2x_hc_int_enable(bp);
  1218. else
  1219. bnx2x_igu_int_enable(bp);
  1220. }
  1221. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1222. {
  1223. int port = BP_PORT(bp);
  1224. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1225. u32 val = REG_RD(bp, addr);
  1226. /*
  1227. * in E1 we must use only PCI configuration space to disable
  1228. * MSI/MSIX capablility
  1229. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1230. */
  1231. if (CHIP_IS_E1(bp)) {
  1232. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1233. * Use mask register to prevent from HC sending interrupts
  1234. * after we exit the function
  1235. */
  1236. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1237. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1238. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1239. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1240. } else
  1241. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1242. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1243. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1244. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1245. DP(NETIF_MSG_IFDOWN,
  1246. "write %x to HC %d (addr 0x%x)\n",
  1247. val, port, addr);
  1248. /* flush all outstanding writes */
  1249. mmiowb();
  1250. REG_WR(bp, addr, val);
  1251. if (REG_RD(bp, addr) != val)
  1252. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1253. }
  1254. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1255. {
  1256. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1257. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1258. IGU_PF_CONF_INT_LINE_EN |
  1259. IGU_PF_CONF_ATTN_BIT_EN);
  1260. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1261. /* flush all outstanding writes */
  1262. mmiowb();
  1263. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1264. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1265. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1266. }
  1267. static void bnx2x_int_disable(struct bnx2x *bp)
  1268. {
  1269. if (bp->common.int_block == INT_BLOCK_HC)
  1270. bnx2x_hc_int_disable(bp);
  1271. else
  1272. bnx2x_igu_int_disable(bp);
  1273. }
  1274. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1275. {
  1276. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1277. int i, offset;
  1278. if (disable_hw)
  1279. /* prevent the HW from sending interrupts */
  1280. bnx2x_int_disable(bp);
  1281. /* make sure all ISRs are done */
  1282. if (msix) {
  1283. synchronize_irq(bp->msix_table[0].vector);
  1284. offset = 1;
  1285. if (CNIC_SUPPORT(bp))
  1286. offset++;
  1287. for_each_eth_queue(bp, i)
  1288. synchronize_irq(bp->msix_table[offset++].vector);
  1289. } else
  1290. synchronize_irq(bp->pdev->irq);
  1291. /* make sure sp_task is not running */
  1292. cancel_delayed_work(&bp->sp_task);
  1293. cancel_delayed_work(&bp->period_task);
  1294. flush_workqueue(bnx2x_wq);
  1295. }
  1296. /* fast path */
  1297. /*
  1298. * General service functions
  1299. */
  1300. /* Return true if succeeded to acquire the lock */
  1301. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1302. {
  1303. u32 lock_status;
  1304. u32 resource_bit = (1 << resource);
  1305. int func = BP_FUNC(bp);
  1306. u32 hw_lock_control_reg;
  1307. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1308. "Trying to take a lock on resource %d\n", resource);
  1309. /* Validating that the resource is within range */
  1310. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1311. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1312. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1313. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1314. return false;
  1315. }
  1316. if (func <= 5)
  1317. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1318. else
  1319. hw_lock_control_reg =
  1320. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1321. /* Try to acquire the lock */
  1322. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1323. lock_status = REG_RD(bp, hw_lock_control_reg);
  1324. if (lock_status & resource_bit)
  1325. return true;
  1326. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1327. "Failed to get a lock on resource %d\n", resource);
  1328. return false;
  1329. }
  1330. /**
  1331. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1332. *
  1333. * @bp: driver handle
  1334. *
  1335. * Returns the recovery leader resource id according to the engine this function
  1336. * belongs to. Currently only only 2 engines is supported.
  1337. */
  1338. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1339. {
  1340. if (BP_PATH(bp))
  1341. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1342. else
  1343. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1344. }
  1345. /**
  1346. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1347. *
  1348. * @bp: driver handle
  1349. *
  1350. * Tries to aquire a leader lock for current engine.
  1351. */
  1352. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1353. {
  1354. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1355. }
  1356. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1357. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1358. {
  1359. struct bnx2x *bp = fp->bp;
  1360. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1361. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1362. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1363. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1364. DP(BNX2X_MSG_SP,
  1365. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1366. fp->index, cid, command, bp->state,
  1367. rr_cqe->ramrod_cqe.ramrod_type);
  1368. switch (command) {
  1369. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1370. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1371. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1372. break;
  1373. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1374. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1375. drv_cmd = BNX2X_Q_CMD_SETUP;
  1376. break;
  1377. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1378. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1379. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1380. break;
  1381. case (RAMROD_CMD_ID_ETH_HALT):
  1382. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1383. drv_cmd = BNX2X_Q_CMD_HALT;
  1384. break;
  1385. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1386. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1387. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1388. break;
  1389. case (RAMROD_CMD_ID_ETH_EMPTY):
  1390. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1391. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1392. break;
  1393. default:
  1394. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1395. command, fp->index);
  1396. return;
  1397. }
  1398. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1399. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1400. /* q_obj->complete_cmd() failure means that this was
  1401. * an unexpected completion.
  1402. *
  1403. * In this case we don't want to increase the bp->spq_left
  1404. * because apparently we haven't sent this command the first
  1405. * place.
  1406. */
  1407. #ifdef BNX2X_STOP_ON_ERROR
  1408. bnx2x_panic();
  1409. #else
  1410. return;
  1411. #endif
  1412. smp_mb__before_atomic_inc();
  1413. atomic_inc(&bp->cq_spq_left);
  1414. /* push the change in bp->spq_left and towards the memory */
  1415. smp_mb__after_atomic_inc();
  1416. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1417. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1418. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1419. /* if Q update ramrod is completed for last Q in AFEX vif set
  1420. * flow, then ACK MCP at the end
  1421. *
  1422. * mark pending ACK to MCP bit.
  1423. * prevent case that both bits are cleared.
  1424. * At the end of load/unload driver checks that
  1425. * sp_state is cleaerd, and this order prevents
  1426. * races
  1427. */
  1428. smp_mb__before_clear_bit();
  1429. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1430. wmb();
  1431. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1432. smp_mb__after_clear_bit();
  1433. /* schedule workqueue to send ack to MCP */
  1434. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1435. }
  1436. return;
  1437. }
  1438. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1439. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1440. {
  1441. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1442. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1443. start);
  1444. }
  1445. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1446. {
  1447. struct bnx2x *bp = netdev_priv(dev_instance);
  1448. u16 status = bnx2x_ack_int(bp);
  1449. u16 mask;
  1450. int i;
  1451. u8 cos;
  1452. /* Return here if interrupt is shared and it's not for us */
  1453. if (unlikely(status == 0)) {
  1454. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1455. return IRQ_NONE;
  1456. }
  1457. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1458. #ifdef BNX2X_STOP_ON_ERROR
  1459. if (unlikely(bp->panic))
  1460. return IRQ_HANDLED;
  1461. #endif
  1462. for_each_eth_queue(bp, i) {
  1463. struct bnx2x_fastpath *fp = &bp->fp[i];
  1464. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1465. if (status & mask) {
  1466. /* Handle Rx or Tx according to SB id */
  1467. prefetch(fp->rx_cons_sb);
  1468. for_each_cos_in_tx_queue(fp, cos)
  1469. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1470. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1471. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1472. status &= ~mask;
  1473. }
  1474. }
  1475. if (CNIC_SUPPORT(bp)) {
  1476. mask = 0x2;
  1477. if (status & (mask | 0x1)) {
  1478. struct cnic_ops *c_ops = NULL;
  1479. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1480. rcu_read_lock();
  1481. c_ops = rcu_dereference(bp->cnic_ops);
  1482. if (c_ops)
  1483. c_ops->cnic_handler(bp->cnic_data,
  1484. NULL);
  1485. rcu_read_unlock();
  1486. }
  1487. status &= ~mask;
  1488. }
  1489. }
  1490. if (unlikely(status & 0x1)) {
  1491. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1492. status &= ~0x1;
  1493. if (!status)
  1494. return IRQ_HANDLED;
  1495. }
  1496. if (unlikely(status))
  1497. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1498. status);
  1499. return IRQ_HANDLED;
  1500. }
  1501. /* Link */
  1502. /*
  1503. * General service functions
  1504. */
  1505. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1506. {
  1507. u32 lock_status;
  1508. u32 resource_bit = (1 << resource);
  1509. int func = BP_FUNC(bp);
  1510. u32 hw_lock_control_reg;
  1511. int cnt;
  1512. /* Validating that the resource is within range */
  1513. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1514. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1515. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1516. return -EINVAL;
  1517. }
  1518. if (func <= 5) {
  1519. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1520. } else {
  1521. hw_lock_control_reg =
  1522. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1523. }
  1524. /* Validating that the resource is not already taken */
  1525. lock_status = REG_RD(bp, hw_lock_control_reg);
  1526. if (lock_status & resource_bit) {
  1527. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1528. lock_status, resource_bit);
  1529. return -EEXIST;
  1530. }
  1531. /* Try for 5 second every 5ms */
  1532. for (cnt = 0; cnt < 1000; cnt++) {
  1533. /* Try to acquire the lock */
  1534. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1535. lock_status = REG_RD(bp, hw_lock_control_reg);
  1536. if (lock_status & resource_bit)
  1537. return 0;
  1538. msleep(5);
  1539. }
  1540. BNX2X_ERR("Timeout\n");
  1541. return -EAGAIN;
  1542. }
  1543. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1544. {
  1545. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1546. }
  1547. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1548. {
  1549. u32 lock_status;
  1550. u32 resource_bit = (1 << resource);
  1551. int func = BP_FUNC(bp);
  1552. u32 hw_lock_control_reg;
  1553. /* Validating that the resource is within range */
  1554. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1555. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1556. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1557. return -EINVAL;
  1558. }
  1559. if (func <= 5) {
  1560. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1561. } else {
  1562. hw_lock_control_reg =
  1563. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1564. }
  1565. /* Validating that the resource is currently taken */
  1566. lock_status = REG_RD(bp, hw_lock_control_reg);
  1567. if (!(lock_status & resource_bit)) {
  1568. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1569. lock_status, resource_bit);
  1570. return -EFAULT;
  1571. }
  1572. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1573. return 0;
  1574. }
  1575. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1576. {
  1577. /* The GPIO should be swapped if swap register is set and active */
  1578. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1579. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1580. int gpio_shift = gpio_num +
  1581. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1582. u32 gpio_mask = (1 << gpio_shift);
  1583. u32 gpio_reg;
  1584. int value;
  1585. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1586. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1587. return -EINVAL;
  1588. }
  1589. /* read GPIO value */
  1590. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1591. /* get the requested pin value */
  1592. if ((gpio_reg & gpio_mask) == gpio_mask)
  1593. value = 1;
  1594. else
  1595. value = 0;
  1596. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1597. return value;
  1598. }
  1599. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1600. {
  1601. /* The GPIO should be swapped if swap register is set and active */
  1602. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1603. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1604. int gpio_shift = gpio_num +
  1605. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1606. u32 gpio_mask = (1 << gpio_shift);
  1607. u32 gpio_reg;
  1608. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1609. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1610. return -EINVAL;
  1611. }
  1612. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1613. /* read GPIO and mask except the float bits */
  1614. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1615. switch (mode) {
  1616. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1617. DP(NETIF_MSG_LINK,
  1618. "Set GPIO %d (shift %d) -> output low\n",
  1619. gpio_num, gpio_shift);
  1620. /* clear FLOAT and set CLR */
  1621. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1622. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1623. break;
  1624. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1625. DP(NETIF_MSG_LINK,
  1626. "Set GPIO %d (shift %d) -> output high\n",
  1627. gpio_num, gpio_shift);
  1628. /* clear FLOAT and set SET */
  1629. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1630. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1631. break;
  1632. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1633. DP(NETIF_MSG_LINK,
  1634. "Set GPIO %d (shift %d) -> input\n",
  1635. gpio_num, gpio_shift);
  1636. /* set FLOAT */
  1637. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1638. break;
  1639. default:
  1640. break;
  1641. }
  1642. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1643. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1644. return 0;
  1645. }
  1646. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1647. {
  1648. u32 gpio_reg = 0;
  1649. int rc = 0;
  1650. /* Any port swapping should be handled by caller. */
  1651. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1652. /* read GPIO and mask except the float bits */
  1653. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1654. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1655. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1656. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1657. switch (mode) {
  1658. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1659. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1660. /* set CLR */
  1661. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1662. break;
  1663. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1664. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1665. /* set SET */
  1666. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1667. break;
  1668. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1669. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1670. /* set FLOAT */
  1671. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1672. break;
  1673. default:
  1674. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1675. rc = -EINVAL;
  1676. break;
  1677. }
  1678. if (rc == 0)
  1679. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1680. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1681. return rc;
  1682. }
  1683. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1684. {
  1685. /* The GPIO should be swapped if swap register is set and active */
  1686. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1687. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1688. int gpio_shift = gpio_num +
  1689. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1690. u32 gpio_mask = (1 << gpio_shift);
  1691. u32 gpio_reg;
  1692. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1693. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1694. return -EINVAL;
  1695. }
  1696. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1697. /* read GPIO int */
  1698. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1699. switch (mode) {
  1700. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1701. DP(NETIF_MSG_LINK,
  1702. "Clear GPIO INT %d (shift %d) -> output low\n",
  1703. gpio_num, gpio_shift);
  1704. /* clear SET and set CLR */
  1705. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1706. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1707. break;
  1708. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1709. DP(NETIF_MSG_LINK,
  1710. "Set GPIO INT %d (shift %d) -> output high\n",
  1711. gpio_num, gpio_shift);
  1712. /* clear CLR and set SET */
  1713. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1714. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1715. break;
  1716. default:
  1717. break;
  1718. }
  1719. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1720. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1721. return 0;
  1722. }
  1723. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1724. {
  1725. u32 spio_reg;
  1726. /* Only 2 SPIOs are configurable */
  1727. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1728. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1729. return -EINVAL;
  1730. }
  1731. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1732. /* read SPIO and mask except the float bits */
  1733. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1734. switch (mode) {
  1735. case MISC_SPIO_OUTPUT_LOW:
  1736. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1737. /* clear FLOAT and set CLR */
  1738. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1739. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1740. break;
  1741. case MISC_SPIO_OUTPUT_HIGH:
  1742. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1743. /* clear FLOAT and set SET */
  1744. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1745. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1746. break;
  1747. case MISC_SPIO_INPUT_HI_Z:
  1748. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1749. /* set FLOAT */
  1750. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1751. break;
  1752. default:
  1753. break;
  1754. }
  1755. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1756. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1757. return 0;
  1758. }
  1759. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1760. {
  1761. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1762. switch (bp->link_vars.ieee_fc &
  1763. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1764. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1765. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1766. ADVERTISED_Pause);
  1767. break;
  1768. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1769. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1770. ADVERTISED_Pause);
  1771. break;
  1772. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1773. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1774. break;
  1775. default:
  1776. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1777. ADVERTISED_Pause);
  1778. break;
  1779. }
  1780. }
  1781. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1782. {
  1783. /* Initialize link parameters structure variables
  1784. * It is recommended to turn off RX FC for jumbo frames
  1785. * for better performance
  1786. */
  1787. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1788. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1789. else
  1790. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1791. }
  1792. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1793. {
  1794. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1795. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1796. if (!BP_NOMCP(bp)) {
  1797. bnx2x_set_requested_fc(bp);
  1798. bnx2x_acquire_phy_lock(bp);
  1799. if (load_mode == LOAD_DIAG) {
  1800. struct link_params *lp = &bp->link_params;
  1801. lp->loopback_mode = LOOPBACK_XGXS;
  1802. /* do PHY loopback at 10G speed, if possible */
  1803. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1804. if (lp->speed_cap_mask[cfx_idx] &
  1805. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1806. lp->req_line_speed[cfx_idx] =
  1807. SPEED_10000;
  1808. else
  1809. lp->req_line_speed[cfx_idx] =
  1810. SPEED_1000;
  1811. }
  1812. }
  1813. if (load_mode == LOAD_LOOPBACK_EXT) {
  1814. struct link_params *lp = &bp->link_params;
  1815. lp->loopback_mode = LOOPBACK_EXT;
  1816. }
  1817. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1818. bnx2x_release_phy_lock(bp);
  1819. bnx2x_calc_fc_adv(bp);
  1820. if (bp->link_vars.link_up) {
  1821. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1822. bnx2x_link_report(bp);
  1823. }
  1824. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1825. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1826. return rc;
  1827. }
  1828. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1829. return -EINVAL;
  1830. }
  1831. void bnx2x_link_set(struct bnx2x *bp)
  1832. {
  1833. if (!BP_NOMCP(bp)) {
  1834. bnx2x_acquire_phy_lock(bp);
  1835. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1836. bnx2x_release_phy_lock(bp);
  1837. bnx2x_calc_fc_adv(bp);
  1838. } else
  1839. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1840. }
  1841. static void bnx2x__link_reset(struct bnx2x *bp)
  1842. {
  1843. if (!BP_NOMCP(bp)) {
  1844. bnx2x_acquire_phy_lock(bp);
  1845. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1846. bnx2x_release_phy_lock(bp);
  1847. } else
  1848. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1849. }
  1850. void bnx2x_force_link_reset(struct bnx2x *bp)
  1851. {
  1852. bnx2x_acquire_phy_lock(bp);
  1853. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1854. bnx2x_release_phy_lock(bp);
  1855. }
  1856. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1857. {
  1858. u8 rc = 0;
  1859. if (!BP_NOMCP(bp)) {
  1860. bnx2x_acquire_phy_lock(bp);
  1861. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1862. is_serdes);
  1863. bnx2x_release_phy_lock(bp);
  1864. } else
  1865. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1866. return rc;
  1867. }
  1868. /* Calculates the sum of vn_min_rates.
  1869. It's needed for further normalizing of the min_rates.
  1870. Returns:
  1871. sum of vn_min_rates.
  1872. or
  1873. 0 - if all the min_rates are 0.
  1874. In the later case fainess algorithm should be deactivated.
  1875. If not all min_rates are zero then those that are zeroes will be set to 1.
  1876. */
  1877. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1878. struct cmng_init_input *input)
  1879. {
  1880. int all_zero = 1;
  1881. int vn;
  1882. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1883. u32 vn_cfg = bp->mf_config[vn];
  1884. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1885. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1886. /* Skip hidden vns */
  1887. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1888. vn_min_rate = 0;
  1889. /* If min rate is zero - set it to 1 */
  1890. else if (!vn_min_rate)
  1891. vn_min_rate = DEF_MIN_RATE;
  1892. else
  1893. all_zero = 0;
  1894. input->vnic_min_rate[vn] = vn_min_rate;
  1895. }
  1896. /* if ETS or all min rates are zeros - disable fairness */
  1897. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1898. input->flags.cmng_enables &=
  1899. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1900. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1901. } else if (all_zero) {
  1902. input->flags.cmng_enables &=
  1903. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1904. DP(NETIF_MSG_IFUP,
  1905. "All MIN values are zeroes fairness will be disabled\n");
  1906. } else
  1907. input->flags.cmng_enables |=
  1908. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1909. }
  1910. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1911. struct cmng_init_input *input)
  1912. {
  1913. u16 vn_max_rate;
  1914. u32 vn_cfg = bp->mf_config[vn];
  1915. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1916. vn_max_rate = 0;
  1917. else {
  1918. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1919. if (IS_MF_SI(bp)) {
  1920. /* maxCfg in percents of linkspeed */
  1921. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1922. } else /* SD modes */
  1923. /* maxCfg is absolute in 100Mb units */
  1924. vn_max_rate = maxCfg * 100;
  1925. }
  1926. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1927. input->vnic_max_rate[vn] = vn_max_rate;
  1928. }
  1929. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1930. {
  1931. if (CHIP_REV_IS_SLOW(bp))
  1932. return CMNG_FNS_NONE;
  1933. if (IS_MF(bp))
  1934. return CMNG_FNS_MINMAX;
  1935. return CMNG_FNS_NONE;
  1936. }
  1937. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1938. {
  1939. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1940. if (BP_NOMCP(bp))
  1941. return; /* what should be the default bvalue in this case */
  1942. /* For 2 port configuration the absolute function number formula
  1943. * is:
  1944. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1945. *
  1946. * and there are 4 functions per port
  1947. *
  1948. * For 4 port configuration it is
  1949. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1950. *
  1951. * and there are 2 functions per port
  1952. */
  1953. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1954. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1955. if (func >= E1H_FUNC_MAX)
  1956. break;
  1957. bp->mf_config[vn] =
  1958. MF_CFG_RD(bp, func_mf_config[func].config);
  1959. }
  1960. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  1961. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1962. bp->flags |= MF_FUNC_DIS;
  1963. } else {
  1964. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  1965. bp->flags &= ~MF_FUNC_DIS;
  1966. }
  1967. }
  1968. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1969. {
  1970. struct cmng_init_input input;
  1971. memset(&input, 0, sizeof(struct cmng_init_input));
  1972. input.port_rate = bp->link_vars.line_speed;
  1973. if (cmng_type == CMNG_FNS_MINMAX) {
  1974. int vn;
  1975. /* read mf conf from shmem */
  1976. if (read_cfg)
  1977. bnx2x_read_mf_cfg(bp);
  1978. /* vn_weight_sum and enable fairness if not 0 */
  1979. bnx2x_calc_vn_min(bp, &input);
  1980. /* calculate and set min-max rate for each vn */
  1981. if (bp->port.pmf)
  1982. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  1983. bnx2x_calc_vn_max(bp, vn, &input);
  1984. /* always enable rate shaping and fairness */
  1985. input.flags.cmng_enables |=
  1986. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1987. bnx2x_init_cmng(&input, &bp->cmng);
  1988. return;
  1989. }
  1990. /* rate shaping and fairness are disabled */
  1991. DP(NETIF_MSG_IFUP,
  1992. "rate shaping and fairness are disabled\n");
  1993. }
  1994. static void storm_memset_cmng(struct bnx2x *bp,
  1995. struct cmng_init *cmng,
  1996. u8 port)
  1997. {
  1998. int vn;
  1999. size_t size = sizeof(struct cmng_struct_per_port);
  2000. u32 addr = BAR_XSTRORM_INTMEM +
  2001. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2002. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2003. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2004. int func = func_by_vn(bp, vn);
  2005. addr = BAR_XSTRORM_INTMEM +
  2006. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2007. size = sizeof(struct rate_shaping_vars_per_vn);
  2008. __storm_memset_struct(bp, addr, size,
  2009. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2010. addr = BAR_XSTRORM_INTMEM +
  2011. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2012. size = sizeof(struct fairness_vars_per_vn);
  2013. __storm_memset_struct(bp, addr, size,
  2014. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2015. }
  2016. }
  2017. /* This function is called upon link interrupt */
  2018. static void bnx2x_link_attn(struct bnx2x *bp)
  2019. {
  2020. /* Make sure that we are synced with the current statistics */
  2021. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2022. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2023. if (bp->link_vars.link_up) {
  2024. /* dropless flow control */
  2025. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2026. int port = BP_PORT(bp);
  2027. u32 pause_enabled = 0;
  2028. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2029. pause_enabled = 1;
  2030. REG_WR(bp, BAR_USTRORM_INTMEM +
  2031. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2032. pause_enabled);
  2033. }
  2034. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2035. struct host_port_stats *pstats;
  2036. pstats = bnx2x_sp(bp, port_stats);
  2037. /* reset old mac stats */
  2038. memset(&(pstats->mac_stx[0]), 0,
  2039. sizeof(struct mac_stx));
  2040. }
  2041. if (bp->state == BNX2X_STATE_OPEN)
  2042. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2043. }
  2044. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2045. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2046. if (cmng_fns != CMNG_FNS_NONE) {
  2047. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2048. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2049. } else
  2050. /* rate shaping and fairness are disabled */
  2051. DP(NETIF_MSG_IFUP,
  2052. "single function mode without fairness\n");
  2053. }
  2054. __bnx2x_link_report(bp);
  2055. if (IS_MF(bp))
  2056. bnx2x_link_sync_notify(bp);
  2057. }
  2058. void bnx2x__link_status_update(struct bnx2x *bp)
  2059. {
  2060. if (bp->state != BNX2X_STATE_OPEN)
  2061. return;
  2062. /* read updated dcb configuration */
  2063. if (IS_PF(bp)) {
  2064. bnx2x_dcbx_pmf_update(bp);
  2065. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2066. if (bp->link_vars.link_up)
  2067. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2068. else
  2069. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2070. /* indicate link status */
  2071. bnx2x_link_report(bp);
  2072. } else { /* VF */
  2073. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2074. SUPPORTED_10baseT_Full |
  2075. SUPPORTED_100baseT_Half |
  2076. SUPPORTED_100baseT_Full |
  2077. SUPPORTED_1000baseT_Full |
  2078. SUPPORTED_2500baseX_Full |
  2079. SUPPORTED_10000baseT_Full |
  2080. SUPPORTED_TP |
  2081. SUPPORTED_FIBRE |
  2082. SUPPORTED_Autoneg |
  2083. SUPPORTED_Pause |
  2084. SUPPORTED_Asym_Pause);
  2085. bp->port.advertising[0] = bp->port.supported[0];
  2086. bp->link_params.bp = bp;
  2087. bp->link_params.port = BP_PORT(bp);
  2088. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2089. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2090. bp->link_params.req_line_speed[0] = SPEED_10000;
  2091. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2092. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2093. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2094. bp->link_vars.line_speed = SPEED_10000;
  2095. bp->link_vars.link_status =
  2096. (LINK_STATUS_LINK_UP |
  2097. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2098. bp->link_vars.link_up = 1;
  2099. bp->link_vars.duplex = DUPLEX_FULL;
  2100. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2101. __bnx2x_link_report(bp);
  2102. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2103. }
  2104. }
  2105. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2106. u16 vlan_val, u8 allowed_prio)
  2107. {
  2108. struct bnx2x_func_state_params func_params = {0};
  2109. struct bnx2x_func_afex_update_params *f_update_params =
  2110. &func_params.params.afex_update;
  2111. func_params.f_obj = &bp->func_obj;
  2112. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2113. /* no need to wait for RAMROD completion, so don't
  2114. * set RAMROD_COMP_WAIT flag
  2115. */
  2116. f_update_params->vif_id = vifid;
  2117. f_update_params->afex_default_vlan = vlan_val;
  2118. f_update_params->allowed_priorities = allowed_prio;
  2119. /* if ramrod can not be sent, response to MCP immediately */
  2120. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2121. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2122. return 0;
  2123. }
  2124. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2125. u16 vif_index, u8 func_bit_map)
  2126. {
  2127. struct bnx2x_func_state_params func_params = {0};
  2128. struct bnx2x_func_afex_viflists_params *update_params =
  2129. &func_params.params.afex_viflists;
  2130. int rc;
  2131. u32 drv_msg_code;
  2132. /* validate only LIST_SET and LIST_GET are received from switch */
  2133. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2134. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2135. cmd_type);
  2136. func_params.f_obj = &bp->func_obj;
  2137. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2138. /* set parameters according to cmd_type */
  2139. update_params->afex_vif_list_command = cmd_type;
  2140. update_params->vif_list_index = cpu_to_le16(vif_index);
  2141. update_params->func_bit_map =
  2142. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2143. update_params->func_to_clear = 0;
  2144. drv_msg_code =
  2145. (cmd_type == VIF_LIST_RULE_GET) ?
  2146. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2147. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2148. /* if ramrod can not be sent, respond to MCP immediately for
  2149. * SET and GET requests (other are not triggered from MCP)
  2150. */
  2151. rc = bnx2x_func_state_change(bp, &func_params);
  2152. if (rc < 0)
  2153. bnx2x_fw_command(bp, drv_msg_code, 0);
  2154. return 0;
  2155. }
  2156. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2157. {
  2158. struct afex_stats afex_stats;
  2159. u32 func = BP_ABS_FUNC(bp);
  2160. u32 mf_config;
  2161. u16 vlan_val;
  2162. u32 vlan_prio;
  2163. u16 vif_id;
  2164. u8 allowed_prio;
  2165. u8 vlan_mode;
  2166. u32 addr_to_write, vifid, addrs, stats_type, i;
  2167. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2168. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2169. DP(BNX2X_MSG_MCP,
  2170. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2171. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2172. }
  2173. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2174. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2175. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2176. DP(BNX2X_MSG_MCP,
  2177. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2178. vifid, addrs);
  2179. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2180. addrs);
  2181. }
  2182. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2183. addr_to_write = SHMEM2_RD(bp,
  2184. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2185. stats_type = SHMEM2_RD(bp,
  2186. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2187. DP(BNX2X_MSG_MCP,
  2188. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2189. addr_to_write);
  2190. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2191. /* write response to scratchpad, for MCP */
  2192. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2193. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2194. *(((u32 *)(&afex_stats))+i));
  2195. /* send ack message to MCP */
  2196. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2197. }
  2198. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2199. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2200. bp->mf_config[BP_VN(bp)] = mf_config;
  2201. DP(BNX2X_MSG_MCP,
  2202. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2203. mf_config);
  2204. /* if VIF_SET is "enabled" */
  2205. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2206. /* set rate limit directly to internal RAM */
  2207. struct cmng_init_input cmng_input;
  2208. struct rate_shaping_vars_per_vn m_rs_vn;
  2209. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2210. u32 addr = BAR_XSTRORM_INTMEM +
  2211. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2212. bp->mf_config[BP_VN(bp)] = mf_config;
  2213. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2214. m_rs_vn.vn_counter.rate =
  2215. cmng_input.vnic_max_rate[BP_VN(bp)];
  2216. m_rs_vn.vn_counter.quota =
  2217. (m_rs_vn.vn_counter.rate *
  2218. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2219. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2220. /* read relevant values from mf_cfg struct in shmem */
  2221. vif_id =
  2222. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2223. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2224. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2225. vlan_val =
  2226. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2227. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2228. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2229. vlan_prio = (mf_config &
  2230. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2231. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2232. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2233. vlan_mode =
  2234. (MF_CFG_RD(bp,
  2235. func_mf_config[func].afex_config) &
  2236. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2237. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2238. allowed_prio =
  2239. (MF_CFG_RD(bp,
  2240. func_mf_config[func].afex_config) &
  2241. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2242. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2243. /* send ramrod to FW, return in case of failure */
  2244. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2245. allowed_prio))
  2246. return;
  2247. bp->afex_def_vlan_tag = vlan_val;
  2248. bp->afex_vlan_mode = vlan_mode;
  2249. } else {
  2250. /* notify link down because BP->flags is disabled */
  2251. bnx2x_link_report(bp);
  2252. /* send INVALID VIF ramrod to FW */
  2253. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2254. /* Reset the default afex VLAN */
  2255. bp->afex_def_vlan_tag = -1;
  2256. }
  2257. }
  2258. }
  2259. static void bnx2x_pmf_update(struct bnx2x *bp)
  2260. {
  2261. int port = BP_PORT(bp);
  2262. u32 val;
  2263. bp->port.pmf = 1;
  2264. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2265. /*
  2266. * We need the mb() to ensure the ordering between the writing to
  2267. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2268. */
  2269. smp_mb();
  2270. /* queue a periodic task */
  2271. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2272. bnx2x_dcbx_pmf_update(bp);
  2273. /* enable nig attention */
  2274. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2275. if (bp->common.int_block == INT_BLOCK_HC) {
  2276. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2277. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2278. } else if (!CHIP_IS_E1x(bp)) {
  2279. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2280. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2281. }
  2282. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2283. }
  2284. /* end of Link */
  2285. /* slow path */
  2286. /*
  2287. * General service functions
  2288. */
  2289. /* send the MCP a request, block until there is a reply */
  2290. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2291. {
  2292. int mb_idx = BP_FW_MB_IDX(bp);
  2293. u32 seq;
  2294. u32 rc = 0;
  2295. u32 cnt = 1;
  2296. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2297. mutex_lock(&bp->fw_mb_mutex);
  2298. seq = ++bp->fw_seq;
  2299. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2300. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2301. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2302. (command | seq), param);
  2303. do {
  2304. /* let the FW do it's magic ... */
  2305. msleep(delay);
  2306. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2307. /* Give the FW up to 5 second (500*10ms) */
  2308. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2309. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2310. cnt*delay, rc, seq);
  2311. /* is this a reply to our command? */
  2312. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2313. rc &= FW_MSG_CODE_MASK;
  2314. else {
  2315. /* FW BUG! */
  2316. BNX2X_ERR("FW failed to respond!\n");
  2317. bnx2x_fw_dump(bp);
  2318. rc = 0;
  2319. }
  2320. mutex_unlock(&bp->fw_mb_mutex);
  2321. return rc;
  2322. }
  2323. static void storm_memset_func_cfg(struct bnx2x *bp,
  2324. struct tstorm_eth_function_common_config *tcfg,
  2325. u16 abs_fid)
  2326. {
  2327. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2328. u32 addr = BAR_TSTRORM_INTMEM +
  2329. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2330. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2331. }
  2332. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2333. {
  2334. if (CHIP_IS_E1x(bp)) {
  2335. struct tstorm_eth_function_common_config tcfg = {0};
  2336. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2337. }
  2338. /* Enable the function in the FW */
  2339. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2340. storm_memset_func_en(bp, p->func_id, 1);
  2341. /* spq */
  2342. if (p->func_flgs & FUNC_FLG_SPQ) {
  2343. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2344. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2345. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2346. }
  2347. }
  2348. /**
  2349. * bnx2x_get_tx_only_flags - Return common flags
  2350. *
  2351. * @bp device handle
  2352. * @fp queue handle
  2353. * @zero_stats TRUE if statistics zeroing is needed
  2354. *
  2355. * Return the flags that are common for the Tx-only and not normal connections.
  2356. */
  2357. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2358. struct bnx2x_fastpath *fp,
  2359. bool zero_stats)
  2360. {
  2361. unsigned long flags = 0;
  2362. /* PF driver will always initialize the Queue to an ACTIVE state */
  2363. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2364. /* tx only connections collect statistics (on the same index as the
  2365. * parent connection). The statistics are zeroed when the parent
  2366. * connection is initialized.
  2367. */
  2368. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2369. if (zero_stats)
  2370. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2371. return flags;
  2372. }
  2373. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2374. struct bnx2x_fastpath *fp,
  2375. bool leading)
  2376. {
  2377. unsigned long flags = 0;
  2378. /* calculate other queue flags */
  2379. if (IS_MF_SD(bp))
  2380. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2381. if (IS_FCOE_FP(fp)) {
  2382. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2383. /* For FCoE - force usage of default priority (for afex) */
  2384. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2385. }
  2386. if (!fp->disable_tpa) {
  2387. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2388. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2389. if (fp->mode == TPA_MODE_GRO)
  2390. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2391. }
  2392. if (leading) {
  2393. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2394. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2395. }
  2396. /* Always set HW VLAN stripping */
  2397. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2398. /* configure silent vlan removal */
  2399. if (IS_MF_AFEX(bp))
  2400. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2401. return flags | bnx2x_get_common_flags(bp, fp, true);
  2402. }
  2403. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2404. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2405. u8 cos)
  2406. {
  2407. gen_init->stat_id = bnx2x_stats_id(fp);
  2408. gen_init->spcl_id = fp->cl_id;
  2409. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2410. if (IS_FCOE_FP(fp))
  2411. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2412. else
  2413. gen_init->mtu = bp->dev->mtu;
  2414. gen_init->cos = cos;
  2415. }
  2416. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2417. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2418. struct bnx2x_rxq_setup_params *rxq_init)
  2419. {
  2420. u8 max_sge = 0;
  2421. u16 sge_sz = 0;
  2422. u16 tpa_agg_size = 0;
  2423. if (!fp->disable_tpa) {
  2424. pause->sge_th_lo = SGE_TH_LO(bp);
  2425. pause->sge_th_hi = SGE_TH_HI(bp);
  2426. /* validate SGE ring has enough to cross high threshold */
  2427. WARN_ON(bp->dropless_fc &&
  2428. pause->sge_th_hi + FW_PREFETCH_CNT >
  2429. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2430. tpa_agg_size = min_t(u32,
  2431. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2432. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2433. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2434. SGE_PAGE_SHIFT;
  2435. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2436. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2437. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2438. 0xffff);
  2439. }
  2440. /* pause - not for e1 */
  2441. if (!CHIP_IS_E1(bp)) {
  2442. pause->bd_th_lo = BD_TH_LO(bp);
  2443. pause->bd_th_hi = BD_TH_HI(bp);
  2444. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2445. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2446. /*
  2447. * validate that rings have enough entries to cross
  2448. * high thresholds
  2449. */
  2450. WARN_ON(bp->dropless_fc &&
  2451. pause->bd_th_hi + FW_PREFETCH_CNT >
  2452. bp->rx_ring_size);
  2453. WARN_ON(bp->dropless_fc &&
  2454. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2455. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2456. pause->pri_map = 1;
  2457. }
  2458. /* rxq setup */
  2459. rxq_init->dscr_map = fp->rx_desc_mapping;
  2460. rxq_init->sge_map = fp->rx_sge_mapping;
  2461. rxq_init->rcq_map = fp->rx_comp_mapping;
  2462. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2463. /* This should be a maximum number of data bytes that may be
  2464. * placed on the BD (not including paddings).
  2465. */
  2466. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2467. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2468. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2469. rxq_init->tpa_agg_sz = tpa_agg_size;
  2470. rxq_init->sge_buf_sz = sge_sz;
  2471. rxq_init->max_sges_pkt = max_sge;
  2472. rxq_init->rss_engine_id = BP_FUNC(bp);
  2473. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2474. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2475. *
  2476. * For PF Clients it should be the maximum avaliable number.
  2477. * VF driver(s) may want to define it to a smaller value.
  2478. */
  2479. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2480. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2481. rxq_init->fw_sb_id = fp->fw_sb_id;
  2482. if (IS_FCOE_FP(fp))
  2483. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2484. else
  2485. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2486. /* configure silent vlan removal
  2487. * if multi function mode is afex, then mask default vlan
  2488. */
  2489. if (IS_MF_AFEX(bp)) {
  2490. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2491. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2492. }
  2493. }
  2494. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2495. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2496. u8 cos)
  2497. {
  2498. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2499. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2500. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2501. txq_init->fw_sb_id = fp->fw_sb_id;
  2502. /*
  2503. * set the tss leading client id for TX classfication ==
  2504. * leading RSS client id
  2505. */
  2506. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2507. if (IS_FCOE_FP(fp)) {
  2508. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2509. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2510. }
  2511. }
  2512. static void bnx2x_pf_init(struct bnx2x *bp)
  2513. {
  2514. struct bnx2x_func_init_params func_init = {0};
  2515. struct event_ring_data eq_data = { {0} };
  2516. u16 flags;
  2517. if (!CHIP_IS_E1x(bp)) {
  2518. /* reset IGU PF statistics: MSIX + ATTN */
  2519. /* PF */
  2520. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2521. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2522. (CHIP_MODE_IS_4_PORT(bp) ?
  2523. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2524. /* ATTN */
  2525. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2526. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2527. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2528. (CHIP_MODE_IS_4_PORT(bp) ?
  2529. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2530. }
  2531. /* function setup flags */
  2532. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2533. /* This flag is relevant for E1x only.
  2534. * E2 doesn't have a TPA configuration in a function level.
  2535. */
  2536. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2537. func_init.func_flgs = flags;
  2538. func_init.pf_id = BP_FUNC(bp);
  2539. func_init.func_id = BP_FUNC(bp);
  2540. func_init.spq_map = bp->spq_mapping;
  2541. func_init.spq_prod = bp->spq_prod_idx;
  2542. bnx2x_func_init(bp, &func_init);
  2543. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2544. /*
  2545. * Congestion management values depend on the link rate
  2546. * There is no active link so initial link rate is set to 10 Gbps.
  2547. * When the link comes up The congestion management values are
  2548. * re-calculated according to the actual link rate.
  2549. */
  2550. bp->link_vars.line_speed = SPEED_10000;
  2551. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2552. /* Only the PMF sets the HW */
  2553. if (bp->port.pmf)
  2554. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2555. /* init Event Queue */
  2556. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2557. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2558. eq_data.producer = bp->eq_prod;
  2559. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2560. eq_data.sb_id = DEF_SB_ID;
  2561. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2562. }
  2563. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2564. {
  2565. int port = BP_PORT(bp);
  2566. bnx2x_tx_disable(bp);
  2567. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2568. }
  2569. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2570. {
  2571. int port = BP_PORT(bp);
  2572. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2573. /* Tx queue should be only reenabled */
  2574. netif_tx_wake_all_queues(bp->dev);
  2575. /*
  2576. * Should not call netif_carrier_on since it will be called if the link
  2577. * is up when checking for link state
  2578. */
  2579. }
  2580. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2581. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2582. {
  2583. struct eth_stats_info *ether_stat =
  2584. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2585. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2586. ETH_STAT_INFO_VERSION_LEN);
  2587. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2588. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2589. ether_stat->mac_local);
  2590. ether_stat->mtu_size = bp->dev->mtu;
  2591. if (bp->dev->features & NETIF_F_RXCSUM)
  2592. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2593. if (bp->dev->features & NETIF_F_TSO)
  2594. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2595. ether_stat->feature_flags |= bp->common.boot_mode;
  2596. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2597. ether_stat->txq_size = bp->tx_ring_size;
  2598. ether_stat->rxq_size = bp->rx_ring_size;
  2599. }
  2600. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2601. {
  2602. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2603. struct fcoe_stats_info *fcoe_stat =
  2604. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2605. if (!CNIC_LOADED(bp))
  2606. return;
  2607. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2608. bp->fip_mac, ETH_ALEN);
  2609. fcoe_stat->qos_priority =
  2610. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2611. /* insert FCoE stats from ramrod response */
  2612. if (!NO_FCOE(bp)) {
  2613. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2614. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2615. tstorm_queue_statistics;
  2616. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2617. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2618. xstorm_queue_statistics;
  2619. struct fcoe_statistics_params *fw_fcoe_stat =
  2620. &bp->fw_stats_data->fcoe;
  2621. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2622. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2623. ADD_64(fcoe_stat->rx_bytes_hi,
  2624. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2625. fcoe_stat->rx_bytes_lo,
  2626. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2627. ADD_64(fcoe_stat->rx_bytes_hi,
  2628. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2629. fcoe_stat->rx_bytes_lo,
  2630. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2631. ADD_64(fcoe_stat->rx_bytes_hi,
  2632. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2633. fcoe_stat->rx_bytes_lo,
  2634. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2635. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2636. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2637. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2638. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2639. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2640. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2641. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2642. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2643. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2644. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2645. ADD_64(fcoe_stat->tx_bytes_hi,
  2646. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2647. fcoe_stat->tx_bytes_lo,
  2648. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2649. ADD_64(fcoe_stat->tx_bytes_hi,
  2650. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2651. fcoe_stat->tx_bytes_lo,
  2652. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2653. ADD_64(fcoe_stat->tx_bytes_hi,
  2654. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2655. fcoe_stat->tx_bytes_lo,
  2656. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2657. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2658. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2659. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2660. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2661. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2662. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2663. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2664. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2665. }
  2666. /* ask L5 driver to add data to the struct */
  2667. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2668. }
  2669. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2670. {
  2671. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2672. struct iscsi_stats_info *iscsi_stat =
  2673. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2674. if (!CNIC_LOADED(bp))
  2675. return;
  2676. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2677. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2678. iscsi_stat->qos_priority =
  2679. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2680. /* ask L5 driver to add data to the struct */
  2681. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2682. }
  2683. /* called due to MCP event (on pmf):
  2684. * reread new bandwidth configuration
  2685. * configure FW
  2686. * notify others function about the change
  2687. */
  2688. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2689. {
  2690. if (bp->link_vars.link_up) {
  2691. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2692. bnx2x_link_sync_notify(bp);
  2693. }
  2694. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2695. }
  2696. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2697. {
  2698. bnx2x_config_mf_bw(bp);
  2699. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2700. }
  2701. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2702. {
  2703. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2704. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2705. }
  2706. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2707. {
  2708. enum drv_info_opcode op_code;
  2709. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2710. /* if drv_info version supported by MFW doesn't match - send NACK */
  2711. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2712. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2713. return;
  2714. }
  2715. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2716. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2717. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2718. sizeof(union drv_info_to_mcp));
  2719. switch (op_code) {
  2720. case ETH_STATS_OPCODE:
  2721. bnx2x_drv_info_ether_stat(bp);
  2722. break;
  2723. case FCOE_STATS_OPCODE:
  2724. bnx2x_drv_info_fcoe_stat(bp);
  2725. break;
  2726. case ISCSI_STATS_OPCODE:
  2727. bnx2x_drv_info_iscsi_stat(bp);
  2728. break;
  2729. default:
  2730. /* if op code isn't supported - send NACK */
  2731. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2732. return;
  2733. }
  2734. /* if we got drv_info attn from MFW then these fields are defined in
  2735. * shmem2 for sure
  2736. */
  2737. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2738. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2739. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2740. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2741. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2742. }
  2743. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2744. {
  2745. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2746. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2747. /*
  2748. * This is the only place besides the function initialization
  2749. * where the bp->flags can change so it is done without any
  2750. * locks
  2751. */
  2752. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2753. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2754. bp->flags |= MF_FUNC_DIS;
  2755. bnx2x_e1h_disable(bp);
  2756. } else {
  2757. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2758. bp->flags &= ~MF_FUNC_DIS;
  2759. bnx2x_e1h_enable(bp);
  2760. }
  2761. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2762. }
  2763. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2764. bnx2x_config_mf_bw(bp);
  2765. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2766. }
  2767. /* Report results to MCP */
  2768. if (dcc_event)
  2769. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2770. else
  2771. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2772. }
  2773. /* must be called under the spq lock */
  2774. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2775. {
  2776. struct eth_spe *next_spe = bp->spq_prod_bd;
  2777. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2778. bp->spq_prod_bd = bp->spq;
  2779. bp->spq_prod_idx = 0;
  2780. DP(BNX2X_MSG_SP, "end of spq\n");
  2781. } else {
  2782. bp->spq_prod_bd++;
  2783. bp->spq_prod_idx++;
  2784. }
  2785. return next_spe;
  2786. }
  2787. /* must be called under the spq lock */
  2788. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2789. {
  2790. int func = BP_FUNC(bp);
  2791. /*
  2792. * Make sure that BD data is updated before writing the producer:
  2793. * BD data is written to the memory, the producer is read from the
  2794. * memory, thus we need a full memory barrier to ensure the ordering.
  2795. */
  2796. mb();
  2797. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2798. bp->spq_prod_idx);
  2799. mmiowb();
  2800. }
  2801. /**
  2802. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2803. *
  2804. * @cmd: command to check
  2805. * @cmd_type: command type
  2806. */
  2807. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2808. {
  2809. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2810. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2811. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2812. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2813. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2814. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2815. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2816. return true;
  2817. else
  2818. return false;
  2819. }
  2820. /**
  2821. * bnx2x_sp_post - place a single command on an SP ring
  2822. *
  2823. * @bp: driver handle
  2824. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2825. * @cid: SW CID the command is related to
  2826. * @data_hi: command private data address (high 32 bits)
  2827. * @data_lo: command private data address (low 32 bits)
  2828. * @cmd_type: command type (e.g. NONE, ETH)
  2829. *
  2830. * SP data is handled as if it's always an address pair, thus data fields are
  2831. * not swapped to little endian in upper functions. Instead this function swaps
  2832. * data as if it's two u32 fields.
  2833. */
  2834. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2835. u32 data_hi, u32 data_lo, int cmd_type)
  2836. {
  2837. struct eth_spe *spe;
  2838. u16 type;
  2839. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2840. #ifdef BNX2X_STOP_ON_ERROR
  2841. if (unlikely(bp->panic)) {
  2842. BNX2X_ERR("Can't post SP when there is panic\n");
  2843. return -EIO;
  2844. }
  2845. #endif
  2846. spin_lock_bh(&bp->spq_lock);
  2847. if (common) {
  2848. if (!atomic_read(&bp->eq_spq_left)) {
  2849. BNX2X_ERR("BUG! EQ ring full!\n");
  2850. spin_unlock_bh(&bp->spq_lock);
  2851. bnx2x_panic();
  2852. return -EBUSY;
  2853. }
  2854. } else if (!atomic_read(&bp->cq_spq_left)) {
  2855. BNX2X_ERR("BUG! SPQ ring full!\n");
  2856. spin_unlock_bh(&bp->spq_lock);
  2857. bnx2x_panic();
  2858. return -EBUSY;
  2859. }
  2860. spe = bnx2x_sp_get_next(bp);
  2861. /* CID needs port number to be encoded int it */
  2862. spe->hdr.conn_and_cmd_data =
  2863. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2864. HW_CID(bp, cid));
  2865. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2866. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2867. SPE_HDR_FUNCTION_ID);
  2868. spe->hdr.type = cpu_to_le16(type);
  2869. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2870. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2871. /*
  2872. * It's ok if the actual decrement is issued towards the memory
  2873. * somewhere between the spin_lock and spin_unlock. Thus no
  2874. * more explict memory barrier is needed.
  2875. */
  2876. if (common)
  2877. atomic_dec(&bp->eq_spq_left);
  2878. else
  2879. atomic_dec(&bp->cq_spq_left);
  2880. DP(BNX2X_MSG_SP,
  2881. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2882. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2883. (u32)(U64_LO(bp->spq_mapping) +
  2884. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2885. HW_CID(bp, cid), data_hi, data_lo, type,
  2886. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2887. bnx2x_sp_prod_update(bp);
  2888. spin_unlock_bh(&bp->spq_lock);
  2889. return 0;
  2890. }
  2891. /* acquire split MCP access lock register */
  2892. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2893. {
  2894. u32 j, val;
  2895. int rc = 0;
  2896. might_sleep();
  2897. for (j = 0; j < 1000; j++) {
  2898. val = (1UL << 31);
  2899. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2900. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2901. if (val & (1L << 31))
  2902. break;
  2903. msleep(5);
  2904. }
  2905. if (!(val & (1L << 31))) {
  2906. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2907. rc = -EBUSY;
  2908. }
  2909. return rc;
  2910. }
  2911. /* release split MCP access lock register */
  2912. static void bnx2x_release_alr(struct bnx2x *bp)
  2913. {
  2914. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2915. }
  2916. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2917. #define BNX2X_DEF_SB_IDX 0x0002
  2918. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2919. {
  2920. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2921. u16 rc = 0;
  2922. barrier(); /* status block is written to by the chip */
  2923. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2924. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2925. rc |= BNX2X_DEF_SB_ATT_IDX;
  2926. }
  2927. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2928. bp->def_idx = def_sb->sp_sb.running_index;
  2929. rc |= BNX2X_DEF_SB_IDX;
  2930. }
  2931. /* Do not reorder: indecies reading should complete before handling */
  2932. barrier();
  2933. return rc;
  2934. }
  2935. /*
  2936. * slow path service functions
  2937. */
  2938. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2939. {
  2940. int port = BP_PORT(bp);
  2941. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2942. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2943. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2944. NIG_REG_MASK_INTERRUPT_PORT0;
  2945. u32 aeu_mask;
  2946. u32 nig_mask = 0;
  2947. u32 reg_addr;
  2948. if (bp->attn_state & asserted)
  2949. BNX2X_ERR("IGU ERROR\n");
  2950. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2951. aeu_mask = REG_RD(bp, aeu_addr);
  2952. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2953. aeu_mask, asserted);
  2954. aeu_mask &= ~(asserted & 0x3ff);
  2955. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2956. REG_WR(bp, aeu_addr, aeu_mask);
  2957. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2958. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2959. bp->attn_state |= asserted;
  2960. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2961. if (asserted & ATTN_HARD_WIRED_MASK) {
  2962. if (asserted & ATTN_NIG_FOR_FUNC) {
  2963. bnx2x_acquire_phy_lock(bp);
  2964. /* save nig interrupt mask */
  2965. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2966. /* If nig_mask is not set, no need to call the update
  2967. * function.
  2968. */
  2969. if (nig_mask) {
  2970. REG_WR(bp, nig_int_mask_addr, 0);
  2971. bnx2x_link_attn(bp);
  2972. }
  2973. /* handle unicore attn? */
  2974. }
  2975. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2976. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2977. if (asserted & GPIO_2_FUNC)
  2978. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2979. if (asserted & GPIO_3_FUNC)
  2980. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2981. if (asserted & GPIO_4_FUNC)
  2982. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2983. if (port == 0) {
  2984. if (asserted & ATTN_GENERAL_ATTN_1) {
  2985. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2986. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2987. }
  2988. if (asserted & ATTN_GENERAL_ATTN_2) {
  2989. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2990. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2991. }
  2992. if (asserted & ATTN_GENERAL_ATTN_3) {
  2993. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2994. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2995. }
  2996. } else {
  2997. if (asserted & ATTN_GENERAL_ATTN_4) {
  2998. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2999. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3000. }
  3001. if (asserted & ATTN_GENERAL_ATTN_5) {
  3002. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3003. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3004. }
  3005. if (asserted & ATTN_GENERAL_ATTN_6) {
  3006. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3007. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3008. }
  3009. }
  3010. } /* if hardwired */
  3011. if (bp->common.int_block == INT_BLOCK_HC)
  3012. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3013. COMMAND_REG_ATTN_BITS_SET);
  3014. else
  3015. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3016. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3017. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3018. REG_WR(bp, reg_addr, asserted);
  3019. /* now set back the mask */
  3020. if (asserted & ATTN_NIG_FOR_FUNC) {
  3021. /* Verify that IGU ack through BAR was written before restoring
  3022. * NIG mask. This loop should exit after 2-3 iterations max.
  3023. */
  3024. if (bp->common.int_block != INT_BLOCK_HC) {
  3025. u32 cnt = 0, igu_acked;
  3026. do {
  3027. igu_acked = REG_RD(bp,
  3028. IGU_REG_ATTENTION_ACK_BITS);
  3029. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3030. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3031. if (!igu_acked)
  3032. DP(NETIF_MSG_HW,
  3033. "Failed to verify IGU ack on time\n");
  3034. barrier();
  3035. }
  3036. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3037. bnx2x_release_phy_lock(bp);
  3038. }
  3039. }
  3040. static void bnx2x_fan_failure(struct bnx2x *bp)
  3041. {
  3042. int port = BP_PORT(bp);
  3043. u32 ext_phy_config;
  3044. /* mark the failure */
  3045. ext_phy_config =
  3046. SHMEM_RD(bp,
  3047. dev_info.port_hw_config[port].external_phy_config);
  3048. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3049. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3050. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3051. ext_phy_config);
  3052. /* log the failure */
  3053. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3054. "Please contact OEM Support for assistance\n");
  3055. /*
  3056. * Scheudle device reset (unload)
  3057. * This is due to some boards consuming sufficient power when driver is
  3058. * up to overheat if fan fails.
  3059. */
  3060. smp_mb__before_clear_bit();
  3061. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3062. smp_mb__after_clear_bit();
  3063. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3064. }
  3065. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3066. {
  3067. int port = BP_PORT(bp);
  3068. int reg_offset;
  3069. u32 val;
  3070. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3071. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3072. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3073. val = REG_RD(bp, reg_offset);
  3074. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3075. REG_WR(bp, reg_offset, val);
  3076. BNX2X_ERR("SPIO5 hw attention\n");
  3077. /* Fan failure attention */
  3078. bnx2x_hw_reset_phy(&bp->link_params);
  3079. bnx2x_fan_failure(bp);
  3080. }
  3081. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3082. bnx2x_acquire_phy_lock(bp);
  3083. bnx2x_handle_module_detect_int(&bp->link_params);
  3084. bnx2x_release_phy_lock(bp);
  3085. }
  3086. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3087. val = REG_RD(bp, reg_offset);
  3088. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3089. REG_WR(bp, reg_offset, val);
  3090. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3091. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3092. bnx2x_panic();
  3093. }
  3094. }
  3095. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3096. {
  3097. u32 val;
  3098. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3099. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3100. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3101. /* DORQ discard attention */
  3102. if (val & 0x2)
  3103. BNX2X_ERR("FATAL error from DORQ\n");
  3104. }
  3105. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3106. int port = BP_PORT(bp);
  3107. int reg_offset;
  3108. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3109. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3110. val = REG_RD(bp, reg_offset);
  3111. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3112. REG_WR(bp, reg_offset, val);
  3113. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3114. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3115. bnx2x_panic();
  3116. }
  3117. }
  3118. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3119. {
  3120. u32 val;
  3121. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3122. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3123. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3124. /* CFC error attention */
  3125. if (val & 0x2)
  3126. BNX2X_ERR("FATAL error from CFC\n");
  3127. }
  3128. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3129. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3130. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3131. /* RQ_USDMDP_FIFO_OVERFLOW */
  3132. if (val & 0x18000)
  3133. BNX2X_ERR("FATAL error from PXP\n");
  3134. if (!CHIP_IS_E1x(bp)) {
  3135. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3136. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3137. }
  3138. }
  3139. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3140. int port = BP_PORT(bp);
  3141. int reg_offset;
  3142. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3143. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3144. val = REG_RD(bp, reg_offset);
  3145. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3146. REG_WR(bp, reg_offset, val);
  3147. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3148. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3149. bnx2x_panic();
  3150. }
  3151. }
  3152. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3153. {
  3154. u32 val;
  3155. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3156. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3157. int func = BP_FUNC(bp);
  3158. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3159. bnx2x_read_mf_cfg(bp);
  3160. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3161. func_mf_config[BP_ABS_FUNC(bp)].config);
  3162. val = SHMEM_RD(bp,
  3163. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3164. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3165. bnx2x_dcc_event(bp,
  3166. (val & DRV_STATUS_DCC_EVENT_MASK));
  3167. if (val & DRV_STATUS_SET_MF_BW)
  3168. bnx2x_set_mf_bw(bp);
  3169. if (val & DRV_STATUS_DRV_INFO_REQ)
  3170. bnx2x_handle_drv_info_req(bp);
  3171. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3172. bnx2x_pmf_update(bp);
  3173. if (bp->port.pmf &&
  3174. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3175. bp->dcbx_enabled > 0)
  3176. /* start dcbx state machine */
  3177. bnx2x_dcbx_set_params(bp,
  3178. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3179. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3180. bnx2x_handle_afex_cmd(bp,
  3181. val & DRV_STATUS_AFEX_EVENT_MASK);
  3182. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3183. bnx2x_handle_eee_event(bp);
  3184. if (bp->link_vars.periodic_flags &
  3185. PERIODIC_FLAGS_LINK_EVENT) {
  3186. /* sync with link */
  3187. bnx2x_acquire_phy_lock(bp);
  3188. bp->link_vars.periodic_flags &=
  3189. ~PERIODIC_FLAGS_LINK_EVENT;
  3190. bnx2x_release_phy_lock(bp);
  3191. if (IS_MF(bp))
  3192. bnx2x_link_sync_notify(bp);
  3193. bnx2x_link_report(bp);
  3194. }
  3195. /* Always call it here: bnx2x_link_report() will
  3196. * prevent the link indication duplication.
  3197. */
  3198. bnx2x__link_status_update(bp);
  3199. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3200. BNX2X_ERR("MC assert!\n");
  3201. bnx2x_mc_assert(bp);
  3202. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3203. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3204. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3205. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3206. bnx2x_panic();
  3207. } else if (attn & BNX2X_MCP_ASSERT) {
  3208. BNX2X_ERR("MCP assert!\n");
  3209. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3210. bnx2x_fw_dump(bp);
  3211. } else
  3212. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3213. }
  3214. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3215. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3216. if (attn & BNX2X_GRC_TIMEOUT) {
  3217. val = CHIP_IS_E1(bp) ? 0 :
  3218. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3219. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3220. }
  3221. if (attn & BNX2X_GRC_RSV) {
  3222. val = CHIP_IS_E1(bp) ? 0 :
  3223. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3224. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3225. }
  3226. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3227. }
  3228. }
  3229. /*
  3230. * Bits map:
  3231. * 0-7 - Engine0 load counter.
  3232. * 8-15 - Engine1 load counter.
  3233. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3234. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3235. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3236. * on the engine
  3237. * 19 - Engine1 ONE_IS_LOADED.
  3238. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3239. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3240. * just the one belonging to its engine).
  3241. *
  3242. */
  3243. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3244. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3245. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3246. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3247. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3248. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3249. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3250. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3251. /*
  3252. * Set the GLOBAL_RESET bit.
  3253. *
  3254. * Should be run under rtnl lock
  3255. */
  3256. void bnx2x_set_reset_global(struct bnx2x *bp)
  3257. {
  3258. u32 val;
  3259. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3260. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3261. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3262. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3263. }
  3264. /*
  3265. * Clear the GLOBAL_RESET bit.
  3266. *
  3267. * Should be run under rtnl lock
  3268. */
  3269. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3270. {
  3271. u32 val;
  3272. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3273. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3274. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3275. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3276. }
  3277. /*
  3278. * Checks the GLOBAL_RESET bit.
  3279. *
  3280. * should be run under rtnl lock
  3281. */
  3282. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3283. {
  3284. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3285. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3286. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3287. }
  3288. /*
  3289. * Clear RESET_IN_PROGRESS bit for the current engine.
  3290. *
  3291. * Should be run under rtnl lock
  3292. */
  3293. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3294. {
  3295. u32 val;
  3296. u32 bit = BP_PATH(bp) ?
  3297. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3298. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3299. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3300. /* Clear the bit */
  3301. val &= ~bit;
  3302. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3303. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3304. }
  3305. /*
  3306. * Set RESET_IN_PROGRESS for the current engine.
  3307. *
  3308. * should be run under rtnl lock
  3309. */
  3310. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3311. {
  3312. u32 val;
  3313. u32 bit = BP_PATH(bp) ?
  3314. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3315. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3316. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3317. /* Set the bit */
  3318. val |= bit;
  3319. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3320. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3321. }
  3322. /*
  3323. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3324. * should be run under rtnl lock
  3325. */
  3326. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3327. {
  3328. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3329. u32 bit = engine ?
  3330. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3331. /* return false if bit is set */
  3332. return (val & bit) ? false : true;
  3333. }
  3334. /*
  3335. * set pf load for the current pf.
  3336. *
  3337. * should be run under rtnl lock
  3338. */
  3339. void bnx2x_set_pf_load(struct bnx2x *bp)
  3340. {
  3341. u32 val1, val;
  3342. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3343. BNX2X_PATH0_LOAD_CNT_MASK;
  3344. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3345. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3346. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3347. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3348. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3349. /* get the current counter value */
  3350. val1 = (val & mask) >> shift;
  3351. /* set bit of that PF */
  3352. val1 |= (1 << bp->pf_num);
  3353. /* clear the old value */
  3354. val &= ~mask;
  3355. /* set the new one */
  3356. val |= ((val1 << shift) & mask);
  3357. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3358. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3359. }
  3360. /**
  3361. * bnx2x_clear_pf_load - clear pf load mark
  3362. *
  3363. * @bp: driver handle
  3364. *
  3365. * Should be run under rtnl lock.
  3366. * Decrements the load counter for the current engine. Returns
  3367. * whether other functions are still loaded
  3368. */
  3369. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3370. {
  3371. u32 val1, val;
  3372. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3373. BNX2X_PATH0_LOAD_CNT_MASK;
  3374. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3375. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3376. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3377. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3378. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3379. /* get the current counter value */
  3380. val1 = (val & mask) >> shift;
  3381. /* clear bit of that PF */
  3382. val1 &= ~(1 << bp->pf_num);
  3383. /* clear the old value */
  3384. val &= ~mask;
  3385. /* set the new one */
  3386. val |= ((val1 << shift) & mask);
  3387. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3388. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3389. return val1 != 0;
  3390. }
  3391. /*
  3392. * Read the load status for the current engine.
  3393. *
  3394. * should be run under rtnl lock
  3395. */
  3396. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3397. {
  3398. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3399. BNX2X_PATH0_LOAD_CNT_MASK);
  3400. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3401. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3402. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3403. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3404. val = (val & mask) >> shift;
  3405. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3406. engine, val);
  3407. return val != 0;
  3408. }
  3409. static void _print_next_block(int idx, const char *blk)
  3410. {
  3411. pr_cont("%s%s", idx ? ", " : "", blk);
  3412. }
  3413. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3414. bool print)
  3415. {
  3416. int i = 0;
  3417. u32 cur_bit = 0;
  3418. for (i = 0; sig; i++) {
  3419. cur_bit = ((u32)0x1 << i);
  3420. if (sig & cur_bit) {
  3421. switch (cur_bit) {
  3422. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3423. if (print)
  3424. _print_next_block(par_num++, "BRB");
  3425. break;
  3426. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3427. if (print)
  3428. _print_next_block(par_num++, "PARSER");
  3429. break;
  3430. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3431. if (print)
  3432. _print_next_block(par_num++, "TSDM");
  3433. break;
  3434. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3435. if (print)
  3436. _print_next_block(par_num++,
  3437. "SEARCHER");
  3438. break;
  3439. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3440. if (print)
  3441. _print_next_block(par_num++, "TCM");
  3442. break;
  3443. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3444. if (print)
  3445. _print_next_block(par_num++, "TSEMI");
  3446. break;
  3447. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3448. if (print)
  3449. _print_next_block(par_num++, "XPB");
  3450. break;
  3451. }
  3452. /* Clear the bit */
  3453. sig &= ~cur_bit;
  3454. }
  3455. }
  3456. return par_num;
  3457. }
  3458. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3459. bool *global, bool print)
  3460. {
  3461. int i = 0;
  3462. u32 cur_bit = 0;
  3463. for (i = 0; sig; i++) {
  3464. cur_bit = ((u32)0x1 << i);
  3465. if (sig & cur_bit) {
  3466. switch (cur_bit) {
  3467. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3468. if (print)
  3469. _print_next_block(par_num++, "PBF");
  3470. break;
  3471. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3472. if (print)
  3473. _print_next_block(par_num++, "QM");
  3474. break;
  3475. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3476. if (print)
  3477. _print_next_block(par_num++, "TM");
  3478. break;
  3479. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3480. if (print)
  3481. _print_next_block(par_num++, "XSDM");
  3482. break;
  3483. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3484. if (print)
  3485. _print_next_block(par_num++, "XCM");
  3486. break;
  3487. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3488. if (print)
  3489. _print_next_block(par_num++, "XSEMI");
  3490. break;
  3491. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3492. if (print)
  3493. _print_next_block(par_num++,
  3494. "DOORBELLQ");
  3495. break;
  3496. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3497. if (print)
  3498. _print_next_block(par_num++, "NIG");
  3499. break;
  3500. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3501. if (print)
  3502. _print_next_block(par_num++,
  3503. "VAUX PCI CORE");
  3504. *global = true;
  3505. break;
  3506. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3507. if (print)
  3508. _print_next_block(par_num++, "DEBUG");
  3509. break;
  3510. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3511. if (print)
  3512. _print_next_block(par_num++, "USDM");
  3513. break;
  3514. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3515. if (print)
  3516. _print_next_block(par_num++, "UCM");
  3517. break;
  3518. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3519. if (print)
  3520. _print_next_block(par_num++, "USEMI");
  3521. break;
  3522. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3523. if (print)
  3524. _print_next_block(par_num++, "UPB");
  3525. break;
  3526. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3527. if (print)
  3528. _print_next_block(par_num++, "CSDM");
  3529. break;
  3530. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3531. if (print)
  3532. _print_next_block(par_num++, "CCM");
  3533. break;
  3534. }
  3535. /* Clear the bit */
  3536. sig &= ~cur_bit;
  3537. }
  3538. }
  3539. return par_num;
  3540. }
  3541. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3542. bool print)
  3543. {
  3544. int i = 0;
  3545. u32 cur_bit = 0;
  3546. for (i = 0; sig; i++) {
  3547. cur_bit = ((u32)0x1 << i);
  3548. if (sig & cur_bit) {
  3549. switch (cur_bit) {
  3550. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3551. if (print)
  3552. _print_next_block(par_num++, "CSEMI");
  3553. break;
  3554. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3555. if (print)
  3556. _print_next_block(par_num++, "PXP");
  3557. break;
  3558. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3559. if (print)
  3560. _print_next_block(par_num++,
  3561. "PXPPCICLOCKCLIENT");
  3562. break;
  3563. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3564. if (print)
  3565. _print_next_block(par_num++, "CFC");
  3566. break;
  3567. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3568. if (print)
  3569. _print_next_block(par_num++, "CDU");
  3570. break;
  3571. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3572. if (print)
  3573. _print_next_block(par_num++, "DMAE");
  3574. break;
  3575. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3576. if (print)
  3577. _print_next_block(par_num++, "IGU");
  3578. break;
  3579. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3580. if (print)
  3581. _print_next_block(par_num++, "MISC");
  3582. break;
  3583. }
  3584. /* Clear the bit */
  3585. sig &= ~cur_bit;
  3586. }
  3587. }
  3588. return par_num;
  3589. }
  3590. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3591. bool *global, bool print)
  3592. {
  3593. int i = 0;
  3594. u32 cur_bit = 0;
  3595. for (i = 0; sig; i++) {
  3596. cur_bit = ((u32)0x1 << i);
  3597. if (sig & cur_bit) {
  3598. switch (cur_bit) {
  3599. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3600. if (print)
  3601. _print_next_block(par_num++, "MCP ROM");
  3602. *global = true;
  3603. break;
  3604. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3605. if (print)
  3606. _print_next_block(par_num++,
  3607. "MCP UMP RX");
  3608. *global = true;
  3609. break;
  3610. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3611. if (print)
  3612. _print_next_block(par_num++,
  3613. "MCP UMP TX");
  3614. *global = true;
  3615. break;
  3616. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3617. if (print)
  3618. _print_next_block(par_num++,
  3619. "MCP SCPAD");
  3620. *global = true;
  3621. break;
  3622. }
  3623. /* Clear the bit */
  3624. sig &= ~cur_bit;
  3625. }
  3626. }
  3627. return par_num;
  3628. }
  3629. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3630. bool print)
  3631. {
  3632. int i = 0;
  3633. u32 cur_bit = 0;
  3634. for (i = 0; sig; i++) {
  3635. cur_bit = ((u32)0x1 << i);
  3636. if (sig & cur_bit) {
  3637. switch (cur_bit) {
  3638. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3639. if (print)
  3640. _print_next_block(par_num++, "PGLUE_B");
  3641. break;
  3642. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3643. if (print)
  3644. _print_next_block(par_num++, "ATC");
  3645. break;
  3646. }
  3647. /* Clear the bit */
  3648. sig &= ~cur_bit;
  3649. }
  3650. }
  3651. return par_num;
  3652. }
  3653. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3654. u32 *sig)
  3655. {
  3656. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3657. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3658. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3659. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3660. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3661. int par_num = 0;
  3662. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3663. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3664. sig[0] & HW_PRTY_ASSERT_SET_0,
  3665. sig[1] & HW_PRTY_ASSERT_SET_1,
  3666. sig[2] & HW_PRTY_ASSERT_SET_2,
  3667. sig[3] & HW_PRTY_ASSERT_SET_3,
  3668. sig[4] & HW_PRTY_ASSERT_SET_4);
  3669. if (print)
  3670. netdev_err(bp->dev,
  3671. "Parity errors detected in blocks: ");
  3672. par_num = bnx2x_check_blocks_with_parity0(
  3673. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3674. par_num = bnx2x_check_blocks_with_parity1(
  3675. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3676. par_num = bnx2x_check_blocks_with_parity2(
  3677. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3678. par_num = bnx2x_check_blocks_with_parity3(
  3679. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3680. par_num = bnx2x_check_blocks_with_parity4(
  3681. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3682. if (print)
  3683. pr_cont("\n");
  3684. return true;
  3685. } else
  3686. return false;
  3687. }
  3688. /**
  3689. * bnx2x_chk_parity_attn - checks for parity attentions.
  3690. *
  3691. * @bp: driver handle
  3692. * @global: true if there was a global attention
  3693. * @print: show parity attention in syslog
  3694. */
  3695. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3696. {
  3697. struct attn_route attn = { {0} };
  3698. int port = BP_PORT(bp);
  3699. attn.sig[0] = REG_RD(bp,
  3700. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3701. port*4);
  3702. attn.sig[1] = REG_RD(bp,
  3703. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3704. port*4);
  3705. attn.sig[2] = REG_RD(bp,
  3706. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3707. port*4);
  3708. attn.sig[3] = REG_RD(bp,
  3709. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3710. port*4);
  3711. if (!CHIP_IS_E1x(bp))
  3712. attn.sig[4] = REG_RD(bp,
  3713. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3714. port*4);
  3715. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3716. }
  3717. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3718. {
  3719. u32 val;
  3720. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3721. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3722. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3723. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3724. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3725. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3726. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3727. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3728. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3729. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3730. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3731. if (val &
  3732. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3733. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3734. if (val &
  3735. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3736. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3737. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3738. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3739. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3740. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3741. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3742. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3743. }
  3744. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3745. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3746. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3747. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3748. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3749. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3750. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3751. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3752. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3753. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3754. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3755. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3756. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3757. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3758. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3759. }
  3760. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3761. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3762. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3763. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3764. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3765. }
  3766. }
  3767. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3768. {
  3769. struct attn_route attn, *group_mask;
  3770. int port = BP_PORT(bp);
  3771. int index;
  3772. u32 reg_addr;
  3773. u32 val;
  3774. u32 aeu_mask;
  3775. bool global = false;
  3776. /* need to take HW lock because MCP or other port might also
  3777. try to handle this event */
  3778. bnx2x_acquire_alr(bp);
  3779. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3780. #ifndef BNX2X_STOP_ON_ERROR
  3781. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3782. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3783. /* Disable HW interrupts */
  3784. bnx2x_int_disable(bp);
  3785. /* In case of parity errors don't handle attentions so that
  3786. * other function would "see" parity errors.
  3787. */
  3788. #else
  3789. bnx2x_panic();
  3790. #endif
  3791. bnx2x_release_alr(bp);
  3792. return;
  3793. }
  3794. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3795. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3796. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3797. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3798. if (!CHIP_IS_E1x(bp))
  3799. attn.sig[4] =
  3800. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3801. else
  3802. attn.sig[4] = 0;
  3803. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3804. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3805. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3806. if (deasserted & (1 << index)) {
  3807. group_mask = &bp->attn_group[index];
  3808. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3809. index,
  3810. group_mask->sig[0], group_mask->sig[1],
  3811. group_mask->sig[2], group_mask->sig[3],
  3812. group_mask->sig[4]);
  3813. bnx2x_attn_int_deasserted4(bp,
  3814. attn.sig[4] & group_mask->sig[4]);
  3815. bnx2x_attn_int_deasserted3(bp,
  3816. attn.sig[3] & group_mask->sig[3]);
  3817. bnx2x_attn_int_deasserted1(bp,
  3818. attn.sig[1] & group_mask->sig[1]);
  3819. bnx2x_attn_int_deasserted2(bp,
  3820. attn.sig[2] & group_mask->sig[2]);
  3821. bnx2x_attn_int_deasserted0(bp,
  3822. attn.sig[0] & group_mask->sig[0]);
  3823. }
  3824. }
  3825. bnx2x_release_alr(bp);
  3826. if (bp->common.int_block == INT_BLOCK_HC)
  3827. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3828. COMMAND_REG_ATTN_BITS_CLR);
  3829. else
  3830. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3831. val = ~deasserted;
  3832. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3833. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3834. REG_WR(bp, reg_addr, val);
  3835. if (~bp->attn_state & deasserted)
  3836. BNX2X_ERR("IGU ERROR\n");
  3837. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3838. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3839. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3840. aeu_mask = REG_RD(bp, reg_addr);
  3841. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3842. aeu_mask, deasserted);
  3843. aeu_mask |= (deasserted & 0x3ff);
  3844. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3845. REG_WR(bp, reg_addr, aeu_mask);
  3846. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3847. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3848. bp->attn_state &= ~deasserted;
  3849. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3850. }
  3851. static void bnx2x_attn_int(struct bnx2x *bp)
  3852. {
  3853. /* read local copy of bits */
  3854. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3855. attn_bits);
  3856. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3857. attn_bits_ack);
  3858. u32 attn_state = bp->attn_state;
  3859. /* look for changed bits */
  3860. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3861. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3862. DP(NETIF_MSG_HW,
  3863. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3864. attn_bits, attn_ack, asserted, deasserted);
  3865. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3866. BNX2X_ERR("BAD attention state\n");
  3867. /* handle bits that were raised */
  3868. if (asserted)
  3869. bnx2x_attn_int_asserted(bp, asserted);
  3870. if (deasserted)
  3871. bnx2x_attn_int_deasserted(bp, deasserted);
  3872. }
  3873. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3874. u16 index, u8 op, u8 update)
  3875. {
  3876. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3877. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3878. igu_addr);
  3879. }
  3880. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3881. {
  3882. /* No memory barriers */
  3883. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3884. mmiowb(); /* keep prod updates ordered */
  3885. }
  3886. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3887. union event_ring_elem *elem)
  3888. {
  3889. u8 err = elem->message.error;
  3890. if (!bp->cnic_eth_dev.starting_cid ||
  3891. (cid < bp->cnic_eth_dev.starting_cid &&
  3892. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3893. return 1;
  3894. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3895. if (unlikely(err)) {
  3896. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3897. cid);
  3898. bnx2x_panic_dump(bp);
  3899. }
  3900. bnx2x_cnic_cfc_comp(bp, cid, err);
  3901. return 0;
  3902. }
  3903. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3904. {
  3905. struct bnx2x_mcast_ramrod_params rparam;
  3906. int rc;
  3907. memset(&rparam, 0, sizeof(rparam));
  3908. rparam.mcast_obj = &bp->mcast_obj;
  3909. netif_addr_lock_bh(bp->dev);
  3910. /* Clear pending state for the last command */
  3911. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3912. /* If there are pending mcast commands - send them */
  3913. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3914. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3915. if (rc < 0)
  3916. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3917. rc);
  3918. }
  3919. netif_addr_unlock_bh(bp->dev);
  3920. }
  3921. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3922. union event_ring_elem *elem)
  3923. {
  3924. unsigned long ramrod_flags = 0;
  3925. int rc = 0;
  3926. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3927. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3928. /* Always push next commands out, don't wait here */
  3929. __set_bit(RAMROD_CONT, &ramrod_flags);
  3930. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3931. case BNX2X_FILTER_MAC_PENDING:
  3932. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3933. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  3934. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3935. else
  3936. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  3937. break;
  3938. case BNX2X_FILTER_MCAST_PENDING:
  3939. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3940. /* This is only relevant for 57710 where multicast MACs are
  3941. * configured as unicast MACs using the same ramrod.
  3942. */
  3943. bnx2x_handle_mcast_eqe(bp);
  3944. return;
  3945. default:
  3946. BNX2X_ERR("Unsupported classification command: %d\n",
  3947. elem->message.data.eth_event.echo);
  3948. return;
  3949. }
  3950. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3951. if (rc < 0)
  3952. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3953. else if (rc > 0)
  3954. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3955. }
  3956. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3957. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3958. {
  3959. netif_addr_lock_bh(bp->dev);
  3960. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3961. /* Send rx_mode command again if was requested */
  3962. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3963. bnx2x_set_storm_rx_mode(bp);
  3964. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3965. &bp->sp_state))
  3966. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3967. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3968. &bp->sp_state))
  3969. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3970. netif_addr_unlock_bh(bp->dev);
  3971. }
  3972. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3973. union event_ring_elem *elem)
  3974. {
  3975. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3976. DP(BNX2X_MSG_SP,
  3977. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3978. elem->message.data.vif_list_event.func_bit_map);
  3979. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3980. elem->message.data.vif_list_event.func_bit_map);
  3981. } else if (elem->message.data.vif_list_event.echo ==
  3982. VIF_LIST_RULE_SET) {
  3983. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3984. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3985. }
  3986. }
  3987. /* called with rtnl_lock */
  3988. static void bnx2x_after_function_update(struct bnx2x *bp)
  3989. {
  3990. int q, rc;
  3991. struct bnx2x_fastpath *fp;
  3992. struct bnx2x_queue_state_params queue_params = {NULL};
  3993. struct bnx2x_queue_update_params *q_update_params =
  3994. &queue_params.params.update;
  3995. /* Send Q update command with afex vlan removal values for all Qs */
  3996. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3997. /* set silent vlan removal values according to vlan mode */
  3998. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3999. &q_update_params->update_flags);
  4000. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4001. &q_update_params->update_flags);
  4002. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4003. /* in access mode mark mask and value are 0 to strip all vlans */
  4004. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4005. q_update_params->silent_removal_value = 0;
  4006. q_update_params->silent_removal_mask = 0;
  4007. } else {
  4008. q_update_params->silent_removal_value =
  4009. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4010. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4011. }
  4012. for_each_eth_queue(bp, q) {
  4013. /* Set the appropriate Queue object */
  4014. fp = &bp->fp[q];
  4015. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4016. /* send the ramrod */
  4017. rc = bnx2x_queue_state_change(bp, &queue_params);
  4018. if (rc < 0)
  4019. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4020. q);
  4021. }
  4022. if (!NO_FCOE(bp)) {
  4023. fp = &bp->fp[FCOE_IDX(bp)];
  4024. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4025. /* clear pending completion bit */
  4026. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4027. /* mark latest Q bit */
  4028. smp_mb__before_clear_bit();
  4029. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4030. smp_mb__after_clear_bit();
  4031. /* send Q update ramrod for FCoE Q */
  4032. rc = bnx2x_queue_state_change(bp, &queue_params);
  4033. if (rc < 0)
  4034. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4035. q);
  4036. } else {
  4037. /* If no FCoE ring - ACK MCP now */
  4038. bnx2x_link_report(bp);
  4039. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4040. }
  4041. }
  4042. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4043. struct bnx2x *bp, u32 cid)
  4044. {
  4045. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4046. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4047. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4048. else
  4049. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4050. }
  4051. static void bnx2x_eq_int(struct bnx2x *bp)
  4052. {
  4053. u16 hw_cons, sw_cons, sw_prod;
  4054. union event_ring_elem *elem;
  4055. u8 echo;
  4056. u32 cid;
  4057. u8 opcode;
  4058. int spqe_cnt = 0;
  4059. struct bnx2x_queue_sp_obj *q_obj;
  4060. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4061. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4062. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4063. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4064. * when we get the the next-page we nned to adjust so the loop
  4065. * condition below will be met. The next element is the size of a
  4066. * regular element and hence incrementing by 1
  4067. */
  4068. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4069. hw_cons++;
  4070. /* This function may never run in parallel with itself for a
  4071. * specific bp, thus there is no need in "paired" read memory
  4072. * barrier here.
  4073. */
  4074. sw_cons = bp->eq_cons;
  4075. sw_prod = bp->eq_prod;
  4076. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4077. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4078. for (; sw_cons != hw_cons;
  4079. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4080. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4081. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4082. opcode = elem->message.opcode;
  4083. /* handle eq element */
  4084. switch (opcode) {
  4085. case EVENT_RING_OPCODE_STAT_QUERY:
  4086. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4087. "got statistics comp event %d\n",
  4088. bp->stats_comp++);
  4089. /* nothing to do with stats comp */
  4090. goto next_spqe;
  4091. case EVENT_RING_OPCODE_CFC_DEL:
  4092. /* handle according to cid range */
  4093. /*
  4094. * we may want to verify here that the bp state is
  4095. * HALTING
  4096. */
  4097. DP(BNX2X_MSG_SP,
  4098. "got delete ramrod for MULTI[%d]\n", cid);
  4099. if (CNIC_LOADED(bp) &&
  4100. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4101. goto next_spqe;
  4102. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4103. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4104. break;
  4105. goto next_spqe;
  4106. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4107. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4108. if (f_obj->complete_cmd(bp, f_obj,
  4109. BNX2X_F_CMD_TX_STOP))
  4110. break;
  4111. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4112. goto next_spqe;
  4113. case EVENT_RING_OPCODE_START_TRAFFIC:
  4114. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4115. if (f_obj->complete_cmd(bp, f_obj,
  4116. BNX2X_F_CMD_TX_START))
  4117. break;
  4118. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4119. goto next_spqe;
  4120. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4121. echo = elem->message.data.function_update_event.echo;
  4122. if (echo == SWITCH_UPDATE) {
  4123. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4124. "got FUNC_SWITCH_UPDATE ramrod\n");
  4125. if (f_obj->complete_cmd(
  4126. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4127. break;
  4128. } else {
  4129. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4130. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4131. f_obj->complete_cmd(bp, f_obj,
  4132. BNX2X_F_CMD_AFEX_UPDATE);
  4133. /* We will perform the Queues update from
  4134. * sp_rtnl task as all Queue SP operations
  4135. * should run under rtnl_lock.
  4136. */
  4137. smp_mb__before_clear_bit();
  4138. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4139. &bp->sp_rtnl_state);
  4140. smp_mb__after_clear_bit();
  4141. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4142. }
  4143. goto next_spqe;
  4144. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4145. f_obj->complete_cmd(bp, f_obj,
  4146. BNX2X_F_CMD_AFEX_VIFLISTS);
  4147. bnx2x_after_afex_vif_lists(bp, elem);
  4148. goto next_spqe;
  4149. case EVENT_RING_OPCODE_FUNCTION_START:
  4150. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4151. "got FUNC_START ramrod\n");
  4152. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4153. break;
  4154. goto next_spqe;
  4155. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4156. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4157. "got FUNC_STOP ramrod\n");
  4158. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4159. break;
  4160. goto next_spqe;
  4161. }
  4162. switch (opcode | bp->state) {
  4163. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4164. BNX2X_STATE_OPEN):
  4165. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4166. BNX2X_STATE_OPENING_WAIT4_PORT):
  4167. cid = elem->message.data.eth_event.echo &
  4168. BNX2X_SWCID_MASK;
  4169. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4170. cid);
  4171. rss_raw->clear_pending(rss_raw);
  4172. break;
  4173. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4174. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4175. case (EVENT_RING_OPCODE_SET_MAC |
  4176. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4177. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4178. BNX2X_STATE_OPEN):
  4179. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4180. BNX2X_STATE_DIAG):
  4181. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4182. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4183. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4184. bnx2x_handle_classification_eqe(bp, elem);
  4185. break;
  4186. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4187. BNX2X_STATE_OPEN):
  4188. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4189. BNX2X_STATE_DIAG):
  4190. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4191. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4192. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4193. bnx2x_handle_mcast_eqe(bp);
  4194. break;
  4195. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4196. BNX2X_STATE_OPEN):
  4197. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4198. BNX2X_STATE_DIAG):
  4199. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4200. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4201. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4202. bnx2x_handle_rx_mode_eqe(bp);
  4203. break;
  4204. default:
  4205. /* unknown event log error and continue */
  4206. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4207. elem->message.opcode, bp->state);
  4208. }
  4209. next_spqe:
  4210. spqe_cnt++;
  4211. } /* for */
  4212. smp_mb__before_atomic_inc();
  4213. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4214. bp->eq_cons = sw_cons;
  4215. bp->eq_prod = sw_prod;
  4216. /* Make sure that above mem writes were issued towards the memory */
  4217. smp_wmb();
  4218. /* update producer */
  4219. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4220. }
  4221. static void bnx2x_sp_task(struct work_struct *work)
  4222. {
  4223. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4224. u16 status;
  4225. status = bnx2x_update_dsb_idx(bp);
  4226. /* if (status == 0) */
  4227. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4228. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4229. /* HW attentions */
  4230. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4231. bnx2x_attn_int(bp);
  4232. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4233. }
  4234. /* SP events: STAT_QUERY and others */
  4235. if (status & BNX2X_DEF_SB_IDX) {
  4236. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4237. if (FCOE_INIT(bp) &&
  4238. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4239. /*
  4240. * Prevent local bottom-halves from running as
  4241. * we are going to change the local NAPI list.
  4242. */
  4243. local_bh_disable();
  4244. napi_schedule(&bnx2x_fcoe(bp, napi));
  4245. local_bh_enable();
  4246. }
  4247. /* Handle EQ completions */
  4248. bnx2x_eq_int(bp);
  4249. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4250. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4251. status &= ~BNX2X_DEF_SB_IDX;
  4252. }
  4253. if (unlikely(status))
  4254. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4255. status);
  4256. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4257. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4258. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4259. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4260. &bp->sp_state)) {
  4261. bnx2x_link_report(bp);
  4262. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4263. }
  4264. }
  4265. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4266. {
  4267. struct net_device *dev = dev_instance;
  4268. struct bnx2x *bp = netdev_priv(dev);
  4269. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4270. IGU_INT_DISABLE, 0);
  4271. #ifdef BNX2X_STOP_ON_ERROR
  4272. if (unlikely(bp->panic))
  4273. return IRQ_HANDLED;
  4274. #endif
  4275. if (CNIC_LOADED(bp)) {
  4276. struct cnic_ops *c_ops;
  4277. rcu_read_lock();
  4278. c_ops = rcu_dereference(bp->cnic_ops);
  4279. if (c_ops)
  4280. c_ops->cnic_handler(bp->cnic_data, NULL);
  4281. rcu_read_unlock();
  4282. }
  4283. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4284. return IRQ_HANDLED;
  4285. }
  4286. /* end of slow path */
  4287. void bnx2x_drv_pulse(struct bnx2x *bp)
  4288. {
  4289. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4290. bp->fw_drv_pulse_wr_seq);
  4291. }
  4292. static void bnx2x_timer(unsigned long data)
  4293. {
  4294. struct bnx2x *bp = (struct bnx2x *) data;
  4295. if (!netif_running(bp->dev))
  4296. return;
  4297. if (!BP_NOMCP(bp)) {
  4298. int mb_idx = BP_FW_MB_IDX(bp);
  4299. u32 drv_pulse;
  4300. u32 mcp_pulse;
  4301. ++bp->fw_drv_pulse_wr_seq;
  4302. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4303. /* TBD - add SYSTEM_TIME */
  4304. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4305. bnx2x_drv_pulse(bp);
  4306. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4307. MCP_PULSE_SEQ_MASK);
  4308. /* The delta between driver pulse and mcp response
  4309. * should be 1 (before mcp response) or 0 (after mcp response)
  4310. */
  4311. if ((drv_pulse != mcp_pulse) &&
  4312. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4313. /* someone lost a heartbeat... */
  4314. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4315. drv_pulse, mcp_pulse);
  4316. }
  4317. }
  4318. if (bp->state == BNX2X_STATE_OPEN)
  4319. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4320. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4321. }
  4322. /* end of Statistics */
  4323. /* nic init */
  4324. /*
  4325. * nic init service functions
  4326. */
  4327. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4328. {
  4329. u32 i;
  4330. if (!(len%4) && !(addr%4))
  4331. for (i = 0; i < len; i += 4)
  4332. REG_WR(bp, addr + i, fill);
  4333. else
  4334. for (i = 0; i < len; i++)
  4335. REG_WR8(bp, addr + i, fill);
  4336. }
  4337. /* helper: writes FP SP data to FW - data_size in dwords */
  4338. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4339. int fw_sb_id,
  4340. u32 *sb_data_p,
  4341. u32 data_size)
  4342. {
  4343. int index;
  4344. for (index = 0; index < data_size; index++)
  4345. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4346. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4347. sizeof(u32)*index,
  4348. *(sb_data_p + index));
  4349. }
  4350. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4351. {
  4352. u32 *sb_data_p;
  4353. u32 data_size = 0;
  4354. struct hc_status_block_data_e2 sb_data_e2;
  4355. struct hc_status_block_data_e1x sb_data_e1x;
  4356. /* disable the function first */
  4357. if (!CHIP_IS_E1x(bp)) {
  4358. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4359. sb_data_e2.common.state = SB_DISABLED;
  4360. sb_data_e2.common.p_func.vf_valid = false;
  4361. sb_data_p = (u32 *)&sb_data_e2;
  4362. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4363. } else {
  4364. memset(&sb_data_e1x, 0,
  4365. sizeof(struct hc_status_block_data_e1x));
  4366. sb_data_e1x.common.state = SB_DISABLED;
  4367. sb_data_e1x.common.p_func.vf_valid = false;
  4368. sb_data_p = (u32 *)&sb_data_e1x;
  4369. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4370. }
  4371. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4372. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4373. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4374. CSTORM_STATUS_BLOCK_SIZE);
  4375. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4376. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4377. CSTORM_SYNC_BLOCK_SIZE);
  4378. }
  4379. /* helper: writes SP SB data to FW */
  4380. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4381. struct hc_sp_status_block_data *sp_sb_data)
  4382. {
  4383. int func = BP_FUNC(bp);
  4384. int i;
  4385. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4386. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4387. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4388. i*sizeof(u32),
  4389. *((u32 *)sp_sb_data + i));
  4390. }
  4391. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4392. {
  4393. int func = BP_FUNC(bp);
  4394. struct hc_sp_status_block_data sp_sb_data;
  4395. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4396. sp_sb_data.state = SB_DISABLED;
  4397. sp_sb_data.p_func.vf_valid = false;
  4398. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4399. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4400. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4401. CSTORM_SP_STATUS_BLOCK_SIZE);
  4402. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4403. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4404. CSTORM_SP_SYNC_BLOCK_SIZE);
  4405. }
  4406. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4407. int igu_sb_id, int igu_seg_id)
  4408. {
  4409. hc_sm->igu_sb_id = igu_sb_id;
  4410. hc_sm->igu_seg_id = igu_seg_id;
  4411. hc_sm->timer_value = 0xFF;
  4412. hc_sm->time_to_expire = 0xFFFFFFFF;
  4413. }
  4414. /* allocates state machine ids. */
  4415. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4416. {
  4417. /* zero out state machine indices */
  4418. /* rx indices */
  4419. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4420. /* tx indices */
  4421. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4422. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4423. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4424. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4425. /* map indices */
  4426. /* rx indices */
  4427. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4428. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4429. /* tx indices */
  4430. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4431. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4432. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4433. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4434. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4435. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4436. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4437. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4438. }
  4439. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4440. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4441. {
  4442. int igu_seg_id;
  4443. struct hc_status_block_data_e2 sb_data_e2;
  4444. struct hc_status_block_data_e1x sb_data_e1x;
  4445. struct hc_status_block_sm *hc_sm_p;
  4446. int data_size;
  4447. u32 *sb_data_p;
  4448. if (CHIP_INT_MODE_IS_BC(bp))
  4449. igu_seg_id = HC_SEG_ACCESS_NORM;
  4450. else
  4451. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4452. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4453. if (!CHIP_IS_E1x(bp)) {
  4454. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4455. sb_data_e2.common.state = SB_ENABLED;
  4456. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4457. sb_data_e2.common.p_func.vf_id = vfid;
  4458. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4459. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4460. sb_data_e2.common.same_igu_sb_1b = true;
  4461. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4462. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4463. hc_sm_p = sb_data_e2.common.state_machine;
  4464. sb_data_p = (u32 *)&sb_data_e2;
  4465. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4466. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4467. } else {
  4468. memset(&sb_data_e1x, 0,
  4469. sizeof(struct hc_status_block_data_e1x));
  4470. sb_data_e1x.common.state = SB_ENABLED;
  4471. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4472. sb_data_e1x.common.p_func.vf_id = 0xff;
  4473. sb_data_e1x.common.p_func.vf_valid = false;
  4474. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4475. sb_data_e1x.common.same_igu_sb_1b = true;
  4476. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4477. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4478. hc_sm_p = sb_data_e1x.common.state_machine;
  4479. sb_data_p = (u32 *)&sb_data_e1x;
  4480. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4481. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4482. }
  4483. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4484. igu_sb_id, igu_seg_id);
  4485. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4486. igu_sb_id, igu_seg_id);
  4487. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4488. /* write indecies to HW */
  4489. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4490. }
  4491. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4492. u16 tx_usec, u16 rx_usec)
  4493. {
  4494. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4495. false, rx_usec);
  4496. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4497. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4498. tx_usec);
  4499. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4500. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4501. tx_usec);
  4502. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4503. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4504. tx_usec);
  4505. }
  4506. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4507. {
  4508. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4509. dma_addr_t mapping = bp->def_status_blk_mapping;
  4510. int igu_sp_sb_index;
  4511. int igu_seg_id;
  4512. int port = BP_PORT(bp);
  4513. int func = BP_FUNC(bp);
  4514. int reg_offset, reg_offset_en5;
  4515. u64 section;
  4516. int index;
  4517. struct hc_sp_status_block_data sp_sb_data;
  4518. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4519. if (CHIP_INT_MODE_IS_BC(bp)) {
  4520. igu_sp_sb_index = DEF_SB_IGU_ID;
  4521. igu_seg_id = HC_SEG_ACCESS_DEF;
  4522. } else {
  4523. igu_sp_sb_index = bp->igu_dsb_id;
  4524. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4525. }
  4526. /* ATTN */
  4527. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4528. atten_status_block);
  4529. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4530. bp->attn_state = 0;
  4531. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4532. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4533. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4534. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4535. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4536. int sindex;
  4537. /* take care of sig[0]..sig[4] */
  4538. for (sindex = 0; sindex < 4; sindex++)
  4539. bp->attn_group[index].sig[sindex] =
  4540. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4541. if (!CHIP_IS_E1x(bp))
  4542. /*
  4543. * enable5 is separate from the rest of the registers,
  4544. * and therefore the address skip is 4
  4545. * and not 16 between the different groups
  4546. */
  4547. bp->attn_group[index].sig[4] = REG_RD(bp,
  4548. reg_offset_en5 + 0x4*index);
  4549. else
  4550. bp->attn_group[index].sig[4] = 0;
  4551. }
  4552. if (bp->common.int_block == INT_BLOCK_HC) {
  4553. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4554. HC_REG_ATTN_MSG0_ADDR_L);
  4555. REG_WR(bp, reg_offset, U64_LO(section));
  4556. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4557. } else if (!CHIP_IS_E1x(bp)) {
  4558. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4559. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4560. }
  4561. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4562. sp_sb);
  4563. bnx2x_zero_sp_sb(bp);
  4564. sp_sb_data.state = SB_ENABLED;
  4565. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4566. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4567. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4568. sp_sb_data.igu_seg_id = igu_seg_id;
  4569. sp_sb_data.p_func.pf_id = func;
  4570. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4571. sp_sb_data.p_func.vf_id = 0xff;
  4572. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4573. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4574. }
  4575. void bnx2x_update_coalesce(struct bnx2x *bp)
  4576. {
  4577. int i;
  4578. for_each_eth_queue(bp, i)
  4579. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4580. bp->tx_ticks, bp->rx_ticks);
  4581. }
  4582. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4583. {
  4584. spin_lock_init(&bp->spq_lock);
  4585. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4586. bp->spq_prod_idx = 0;
  4587. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4588. bp->spq_prod_bd = bp->spq;
  4589. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4590. }
  4591. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4592. {
  4593. int i;
  4594. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4595. union event_ring_elem *elem =
  4596. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4597. elem->next_page.addr.hi =
  4598. cpu_to_le32(U64_HI(bp->eq_mapping +
  4599. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4600. elem->next_page.addr.lo =
  4601. cpu_to_le32(U64_LO(bp->eq_mapping +
  4602. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4603. }
  4604. bp->eq_cons = 0;
  4605. bp->eq_prod = NUM_EQ_DESC;
  4606. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4607. /* we want a warning message before it gets rought... */
  4608. atomic_set(&bp->eq_spq_left,
  4609. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4610. }
  4611. /* called with netif_addr_lock_bh() */
  4612. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4613. unsigned long rx_mode_flags,
  4614. unsigned long rx_accept_flags,
  4615. unsigned long tx_accept_flags,
  4616. unsigned long ramrod_flags)
  4617. {
  4618. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4619. int rc;
  4620. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4621. /* Prepare ramrod parameters */
  4622. ramrod_param.cid = 0;
  4623. ramrod_param.cl_id = cl_id;
  4624. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4625. ramrod_param.func_id = BP_FUNC(bp);
  4626. ramrod_param.pstate = &bp->sp_state;
  4627. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4628. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4629. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4630. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4631. ramrod_param.ramrod_flags = ramrod_flags;
  4632. ramrod_param.rx_mode_flags = rx_mode_flags;
  4633. ramrod_param.rx_accept_flags = rx_accept_flags;
  4634. ramrod_param.tx_accept_flags = tx_accept_flags;
  4635. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4636. if (rc < 0) {
  4637. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4638. return;
  4639. }
  4640. }
  4641. /* called with netif_addr_lock_bh() */
  4642. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4643. {
  4644. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4645. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4646. if (!NO_FCOE(bp))
  4647. /* Configure rx_mode of FCoE Queue */
  4648. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4649. switch (bp->rx_mode) {
  4650. case BNX2X_RX_MODE_NONE:
  4651. /*
  4652. * 'drop all' supersedes any accept flags that may have been
  4653. * passed to the function.
  4654. */
  4655. break;
  4656. case BNX2X_RX_MODE_NORMAL:
  4657. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4658. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4659. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4660. /* internal switching mode */
  4661. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4662. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4663. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4664. break;
  4665. case BNX2X_RX_MODE_ALLMULTI:
  4666. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4667. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4668. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4669. /* internal switching mode */
  4670. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4671. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4672. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4673. break;
  4674. case BNX2X_RX_MODE_PROMISC:
  4675. /* According to deffinition of SI mode, iface in promisc mode
  4676. * should receive matched and unmatched (in resolution of port)
  4677. * unicast packets.
  4678. */
  4679. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4680. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4681. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4682. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4683. /* internal switching mode */
  4684. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4685. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4686. if (IS_MF_SI(bp))
  4687. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4688. else
  4689. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4690. break;
  4691. default:
  4692. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4693. return;
  4694. }
  4695. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4696. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4697. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4698. }
  4699. __set_bit(RAMROD_RX, &ramrod_flags);
  4700. __set_bit(RAMROD_TX, &ramrod_flags);
  4701. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4702. tx_accept_flags, ramrod_flags);
  4703. }
  4704. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4705. {
  4706. int i;
  4707. if (IS_MF_SI(bp))
  4708. /*
  4709. * In switch independent mode, the TSTORM needs to accept
  4710. * packets that failed classification, since approximate match
  4711. * mac addresses aren't written to NIG LLH
  4712. */
  4713. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4714. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4715. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4716. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4717. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4718. /* Zero this manually as its initialization is
  4719. currently missing in the initTool */
  4720. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4721. REG_WR(bp, BAR_USTRORM_INTMEM +
  4722. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4723. if (!CHIP_IS_E1x(bp)) {
  4724. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4725. CHIP_INT_MODE_IS_BC(bp) ?
  4726. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4727. }
  4728. }
  4729. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4730. {
  4731. switch (load_code) {
  4732. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4733. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4734. bnx2x_init_internal_common(bp);
  4735. /* no break */
  4736. case FW_MSG_CODE_DRV_LOAD_PORT:
  4737. /* nothing to do */
  4738. /* no break */
  4739. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4740. /* internal memory per function is
  4741. initialized inside bnx2x_pf_init */
  4742. break;
  4743. default:
  4744. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4745. break;
  4746. }
  4747. }
  4748. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4749. {
  4750. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4751. }
  4752. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4753. {
  4754. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4755. }
  4756. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4757. {
  4758. if (CHIP_IS_E1x(fp->bp))
  4759. return BP_L_ID(fp->bp) + fp->index;
  4760. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4761. return bnx2x_fp_igu_sb_id(fp);
  4762. }
  4763. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4764. {
  4765. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4766. u8 cos;
  4767. unsigned long q_type = 0;
  4768. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4769. fp->rx_queue = fp_idx;
  4770. fp->cid = fp_idx;
  4771. fp->cl_id = bnx2x_fp_cl_id(fp);
  4772. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4773. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4774. /* qZone id equals to FW (per path) client id */
  4775. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4776. /* init shortcut */
  4777. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4778. /* Setup SB indicies */
  4779. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4780. /* Configure Queue State object */
  4781. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4782. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4783. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4784. /* init tx data */
  4785. for_each_cos_in_tx_queue(fp, cos) {
  4786. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4787. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4788. FP_COS_TO_TXQ(fp, cos, bp),
  4789. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4790. cids[cos] = fp->txdata_ptr[cos]->cid;
  4791. }
  4792. /* nothing more for vf to do here */
  4793. if (IS_VF(bp))
  4794. return;
  4795. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4796. fp->fw_sb_id, fp->igu_sb_id);
  4797. bnx2x_update_fpsb_idx(fp);
  4798. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4799. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4800. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4801. /**
  4802. * Configure classification DBs: Always enable Tx switching
  4803. */
  4804. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4805. DP(NETIF_MSG_IFUP,
  4806. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4807. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4808. fp->igu_sb_id);
  4809. }
  4810. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4811. {
  4812. int i;
  4813. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4814. struct eth_tx_next_bd *tx_next_bd =
  4815. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4816. tx_next_bd->addr_hi =
  4817. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4818. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4819. tx_next_bd->addr_lo =
  4820. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4821. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4822. }
  4823. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4824. txdata->tx_db.data.zero_fill1 = 0;
  4825. txdata->tx_db.data.prod = 0;
  4826. txdata->tx_pkt_prod = 0;
  4827. txdata->tx_pkt_cons = 0;
  4828. txdata->tx_bd_prod = 0;
  4829. txdata->tx_bd_cons = 0;
  4830. txdata->tx_pkt = 0;
  4831. }
  4832. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4833. {
  4834. int i;
  4835. for_each_tx_queue_cnic(bp, i)
  4836. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4837. }
  4838. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4839. {
  4840. int i;
  4841. u8 cos;
  4842. for_each_eth_queue(bp, i)
  4843. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4844. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4845. }
  4846. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4847. {
  4848. if (!NO_FCOE(bp))
  4849. bnx2x_init_fcoe_fp(bp);
  4850. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4851. BNX2X_VF_ID_INVALID, false,
  4852. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4853. /* ensure status block indices were read */
  4854. rmb();
  4855. bnx2x_init_rx_rings_cnic(bp);
  4856. bnx2x_init_tx_rings_cnic(bp);
  4857. /* flush all */
  4858. mb();
  4859. mmiowb();
  4860. }
  4861. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4862. {
  4863. int i;
  4864. for_each_eth_queue(bp, i)
  4865. bnx2x_init_eth_fp(bp, i);
  4866. /* ensure status block indices were read */
  4867. rmb();
  4868. bnx2x_init_rx_rings(bp);
  4869. bnx2x_init_tx_rings(bp);
  4870. if (IS_VF(bp))
  4871. return;
  4872. /* Initialize MOD_ABS interrupts */
  4873. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4874. bp->common.shmem_base, bp->common.shmem2_base,
  4875. BP_PORT(bp));
  4876. bnx2x_init_def_sb(bp);
  4877. bnx2x_update_dsb_idx(bp);
  4878. bnx2x_init_sp_ring(bp);
  4879. bnx2x_init_eq_ring(bp);
  4880. bnx2x_init_internal(bp, load_code);
  4881. bnx2x_pf_init(bp);
  4882. bnx2x_stats_init(bp);
  4883. /* flush all before enabling interrupts */
  4884. mb();
  4885. mmiowb();
  4886. bnx2x_int_enable(bp);
  4887. /* Check for SPIO5 */
  4888. bnx2x_attn_int_deasserted0(bp,
  4889. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4890. AEU_INPUTS_ATTN_BITS_SPIO5);
  4891. }
  4892. /* end of nic init */
  4893. /*
  4894. * gzip service functions
  4895. */
  4896. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4897. {
  4898. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4899. &bp->gunzip_mapping, GFP_KERNEL);
  4900. if (bp->gunzip_buf == NULL)
  4901. goto gunzip_nomem1;
  4902. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4903. if (bp->strm == NULL)
  4904. goto gunzip_nomem2;
  4905. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4906. if (bp->strm->workspace == NULL)
  4907. goto gunzip_nomem3;
  4908. return 0;
  4909. gunzip_nomem3:
  4910. kfree(bp->strm);
  4911. bp->strm = NULL;
  4912. gunzip_nomem2:
  4913. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4914. bp->gunzip_mapping);
  4915. bp->gunzip_buf = NULL;
  4916. gunzip_nomem1:
  4917. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4918. return -ENOMEM;
  4919. }
  4920. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4921. {
  4922. if (bp->strm) {
  4923. vfree(bp->strm->workspace);
  4924. kfree(bp->strm);
  4925. bp->strm = NULL;
  4926. }
  4927. if (bp->gunzip_buf) {
  4928. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4929. bp->gunzip_mapping);
  4930. bp->gunzip_buf = NULL;
  4931. }
  4932. }
  4933. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4934. {
  4935. int n, rc;
  4936. /* check gzip header */
  4937. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4938. BNX2X_ERR("Bad gzip header\n");
  4939. return -EINVAL;
  4940. }
  4941. n = 10;
  4942. #define FNAME 0x8
  4943. if (zbuf[3] & FNAME)
  4944. while ((zbuf[n++] != 0) && (n < len));
  4945. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4946. bp->strm->avail_in = len - n;
  4947. bp->strm->next_out = bp->gunzip_buf;
  4948. bp->strm->avail_out = FW_BUF_SIZE;
  4949. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4950. if (rc != Z_OK)
  4951. return rc;
  4952. rc = zlib_inflate(bp->strm, Z_FINISH);
  4953. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4954. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4955. bp->strm->msg);
  4956. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4957. if (bp->gunzip_outlen & 0x3)
  4958. netdev_err(bp->dev,
  4959. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4960. bp->gunzip_outlen);
  4961. bp->gunzip_outlen >>= 2;
  4962. zlib_inflateEnd(bp->strm);
  4963. if (rc == Z_STREAM_END)
  4964. return 0;
  4965. return rc;
  4966. }
  4967. /* nic load/unload */
  4968. /*
  4969. * General service functions
  4970. */
  4971. /* send a NIG loopback debug packet */
  4972. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4973. {
  4974. u32 wb_write[3];
  4975. /* Ethernet source and destination addresses */
  4976. wb_write[0] = 0x55555555;
  4977. wb_write[1] = 0x55555555;
  4978. wb_write[2] = 0x20; /* SOP */
  4979. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4980. /* NON-IP protocol */
  4981. wb_write[0] = 0x09000000;
  4982. wb_write[1] = 0x55555555;
  4983. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4984. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4985. }
  4986. /* some of the internal memories
  4987. * are not directly readable from the driver
  4988. * to test them we send debug packets
  4989. */
  4990. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4991. {
  4992. int factor;
  4993. int count, i;
  4994. u32 val = 0;
  4995. if (CHIP_REV_IS_FPGA(bp))
  4996. factor = 120;
  4997. else if (CHIP_REV_IS_EMUL(bp))
  4998. factor = 200;
  4999. else
  5000. factor = 1;
  5001. /* Disable inputs of parser neighbor blocks */
  5002. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5003. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5004. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5005. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5006. /* Write 0 to parser credits for CFC search request */
  5007. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5008. /* send Ethernet packet */
  5009. bnx2x_lb_pckt(bp);
  5010. /* TODO do i reset NIG statistic? */
  5011. /* Wait until NIG register shows 1 packet of size 0x10 */
  5012. count = 1000 * factor;
  5013. while (count) {
  5014. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5015. val = *bnx2x_sp(bp, wb_data[0]);
  5016. if (val == 0x10)
  5017. break;
  5018. msleep(10);
  5019. count--;
  5020. }
  5021. if (val != 0x10) {
  5022. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5023. return -1;
  5024. }
  5025. /* Wait until PRS register shows 1 packet */
  5026. count = 1000 * factor;
  5027. while (count) {
  5028. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5029. if (val == 1)
  5030. break;
  5031. msleep(10);
  5032. count--;
  5033. }
  5034. if (val != 0x1) {
  5035. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5036. return -2;
  5037. }
  5038. /* Reset and init BRB, PRS */
  5039. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5040. msleep(50);
  5041. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5042. msleep(50);
  5043. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5044. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5045. DP(NETIF_MSG_HW, "part2\n");
  5046. /* Disable inputs of parser neighbor blocks */
  5047. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5048. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5049. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5050. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5051. /* Write 0 to parser credits for CFC search request */
  5052. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5053. /* send 10 Ethernet packets */
  5054. for (i = 0; i < 10; i++)
  5055. bnx2x_lb_pckt(bp);
  5056. /* Wait until NIG register shows 10 + 1
  5057. packets of size 11*0x10 = 0xb0 */
  5058. count = 1000 * factor;
  5059. while (count) {
  5060. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5061. val = *bnx2x_sp(bp, wb_data[0]);
  5062. if (val == 0xb0)
  5063. break;
  5064. msleep(10);
  5065. count--;
  5066. }
  5067. if (val != 0xb0) {
  5068. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5069. return -3;
  5070. }
  5071. /* Wait until PRS register shows 2 packets */
  5072. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5073. if (val != 2)
  5074. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5075. /* Write 1 to parser credits for CFC search request */
  5076. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5077. /* Wait until PRS register shows 3 packets */
  5078. msleep(10 * factor);
  5079. /* Wait until NIG register shows 1 packet of size 0x10 */
  5080. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5081. if (val != 3)
  5082. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5083. /* clear NIG EOP FIFO */
  5084. for (i = 0; i < 11; i++)
  5085. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5086. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5087. if (val != 1) {
  5088. BNX2X_ERR("clear of NIG failed\n");
  5089. return -4;
  5090. }
  5091. /* Reset and init BRB, PRS, NIG */
  5092. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5093. msleep(50);
  5094. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5095. msleep(50);
  5096. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5097. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5098. if (!CNIC_SUPPORT(bp))
  5099. /* set NIC mode */
  5100. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5101. /* Enable inputs of parser neighbor blocks */
  5102. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5103. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5104. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5105. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5106. DP(NETIF_MSG_HW, "done\n");
  5107. return 0; /* OK */
  5108. }
  5109. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5110. {
  5111. u32 val;
  5112. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5113. if (!CHIP_IS_E1x(bp))
  5114. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5115. else
  5116. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5117. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5118. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5119. /*
  5120. * mask read length error interrupts in brb for parser
  5121. * (parsing unit and 'checksum and crc' unit)
  5122. * these errors are legal (PU reads fixed length and CAC can cause
  5123. * read length error on truncated packets)
  5124. */
  5125. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5126. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5127. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5128. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5129. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5130. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5131. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5132. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5133. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5134. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5135. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5136. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5137. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5138. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5139. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5140. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5141. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5142. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5143. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5144. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5145. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5146. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5147. if (!CHIP_IS_E1x(bp))
  5148. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5149. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5150. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5151. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5152. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5153. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5154. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5155. if (!CHIP_IS_E1x(bp))
  5156. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5157. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5158. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5159. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5160. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5161. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5162. }
  5163. static void bnx2x_reset_common(struct bnx2x *bp)
  5164. {
  5165. u32 val = 0x1400;
  5166. /* reset_common */
  5167. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5168. 0xd3ffff7f);
  5169. if (CHIP_IS_E3(bp)) {
  5170. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5171. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5172. }
  5173. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5174. }
  5175. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5176. {
  5177. bp->dmae_ready = 0;
  5178. spin_lock_init(&bp->dmae_lock);
  5179. }
  5180. static void bnx2x_init_pxp(struct bnx2x *bp)
  5181. {
  5182. u16 devctl;
  5183. int r_order, w_order;
  5184. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5185. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5186. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5187. if (bp->mrrs == -1)
  5188. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5189. else {
  5190. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5191. r_order = bp->mrrs;
  5192. }
  5193. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5194. }
  5195. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5196. {
  5197. int is_required;
  5198. u32 val;
  5199. int port;
  5200. if (BP_NOMCP(bp))
  5201. return;
  5202. is_required = 0;
  5203. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5204. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5205. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5206. is_required = 1;
  5207. /*
  5208. * The fan failure mechanism is usually related to the PHY type since
  5209. * the power consumption of the board is affected by the PHY. Currently,
  5210. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5211. */
  5212. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5213. for (port = PORT_0; port < PORT_MAX; port++) {
  5214. is_required |=
  5215. bnx2x_fan_failure_det_req(
  5216. bp,
  5217. bp->common.shmem_base,
  5218. bp->common.shmem2_base,
  5219. port);
  5220. }
  5221. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5222. if (is_required == 0)
  5223. return;
  5224. /* Fan failure is indicated by SPIO 5 */
  5225. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5226. /* set to active low mode */
  5227. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5228. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5229. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5230. /* enable interrupt to signal the IGU */
  5231. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5232. val |= MISC_SPIO_SPIO5;
  5233. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5234. }
  5235. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5236. {
  5237. u32 offset = 0;
  5238. if (CHIP_IS_E1(bp))
  5239. return;
  5240. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5241. return;
  5242. switch (BP_ABS_FUNC(bp)) {
  5243. case 0:
  5244. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5245. break;
  5246. case 1:
  5247. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5248. break;
  5249. case 2:
  5250. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5251. break;
  5252. case 3:
  5253. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5254. break;
  5255. case 4:
  5256. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5257. break;
  5258. case 5:
  5259. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5260. break;
  5261. case 6:
  5262. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5263. break;
  5264. case 7:
  5265. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5266. break;
  5267. default:
  5268. return;
  5269. }
  5270. REG_WR(bp, offset, pretend_func_num);
  5271. REG_RD(bp, offset);
  5272. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5273. }
  5274. void bnx2x_pf_disable(struct bnx2x *bp)
  5275. {
  5276. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5277. val &= ~IGU_PF_CONF_FUNC_EN;
  5278. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5279. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5280. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5281. }
  5282. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5283. {
  5284. u32 shmem_base[2], shmem2_base[2];
  5285. /* Avoid common init in case MFW supports LFA */
  5286. if (SHMEM2_RD(bp, size) >
  5287. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5288. return;
  5289. shmem_base[0] = bp->common.shmem_base;
  5290. shmem2_base[0] = bp->common.shmem2_base;
  5291. if (!CHIP_IS_E1x(bp)) {
  5292. shmem_base[1] =
  5293. SHMEM2_RD(bp, other_shmem_base_addr);
  5294. shmem2_base[1] =
  5295. SHMEM2_RD(bp, other_shmem2_base_addr);
  5296. }
  5297. bnx2x_acquire_phy_lock(bp);
  5298. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5299. bp->common.chip_id);
  5300. bnx2x_release_phy_lock(bp);
  5301. }
  5302. /**
  5303. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5304. *
  5305. * @bp: driver handle
  5306. */
  5307. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5308. {
  5309. u32 val;
  5310. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5311. /*
  5312. * take the UNDI lock to protect undi_unload flow from accessing
  5313. * registers while we're resetting the chip
  5314. */
  5315. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5316. bnx2x_reset_common(bp);
  5317. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5318. val = 0xfffc;
  5319. if (CHIP_IS_E3(bp)) {
  5320. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5321. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5322. }
  5323. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5324. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5325. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5326. if (!CHIP_IS_E1x(bp)) {
  5327. u8 abs_func_id;
  5328. /**
  5329. * 4-port mode or 2-port mode we need to turn of master-enable
  5330. * for everyone, after that, turn it back on for self.
  5331. * so, we disregard multi-function or not, and always disable
  5332. * for all functions on the given path, this means 0,2,4,6 for
  5333. * path 0 and 1,3,5,7 for path 1
  5334. */
  5335. for (abs_func_id = BP_PATH(bp);
  5336. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5337. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5338. REG_WR(bp,
  5339. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5340. 1);
  5341. continue;
  5342. }
  5343. bnx2x_pretend_func(bp, abs_func_id);
  5344. /* clear pf enable */
  5345. bnx2x_pf_disable(bp);
  5346. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5347. }
  5348. }
  5349. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5350. if (CHIP_IS_E1(bp)) {
  5351. /* enable HW interrupt from PXP on USDM overflow
  5352. bit 16 on INT_MASK_0 */
  5353. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5354. }
  5355. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5356. bnx2x_init_pxp(bp);
  5357. #ifdef __BIG_ENDIAN
  5358. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5359. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5360. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5361. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5362. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5363. /* make sure this value is 0 */
  5364. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5365. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5366. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5367. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5368. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5369. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5370. #endif
  5371. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5372. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5373. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5374. /* let the HW do it's magic ... */
  5375. msleep(100);
  5376. /* finish PXP init */
  5377. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5378. if (val != 1) {
  5379. BNX2X_ERR("PXP2 CFG failed\n");
  5380. return -EBUSY;
  5381. }
  5382. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5383. if (val != 1) {
  5384. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5385. return -EBUSY;
  5386. }
  5387. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5388. * have entries with value "0" and valid bit on.
  5389. * This needs to be done by the first PF that is loaded in a path
  5390. * (i.e. common phase)
  5391. */
  5392. if (!CHIP_IS_E1x(bp)) {
  5393. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5394. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5395. * This occurs when a different function (func2,3) is being marked
  5396. * as "scan-off". Real-life scenario for example: if a driver is being
  5397. * load-unloaded while func6,7 are down. This will cause the timer to access
  5398. * the ilt, translate to a logical address and send a request to read/write.
  5399. * Since the ilt for the function that is down is not valid, this will cause
  5400. * a translation error which is unrecoverable.
  5401. * The Workaround is intended to make sure that when this happens nothing fatal
  5402. * will occur. The workaround:
  5403. * 1. First PF driver which loads on a path will:
  5404. * a. After taking the chip out of reset, by using pretend,
  5405. * it will write "0" to the following registers of
  5406. * the other vnics.
  5407. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5408. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5409. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5410. * And for itself it will write '1' to
  5411. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5412. * dmae-operations (writing to pram for example.)
  5413. * note: can be done for only function 6,7 but cleaner this
  5414. * way.
  5415. * b. Write zero+valid to the entire ILT.
  5416. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5417. * VNIC3 (of that port). The range allocated will be the
  5418. * entire ILT. This is needed to prevent ILT range error.
  5419. * 2. Any PF driver load flow:
  5420. * a. ILT update with the physical addresses of the allocated
  5421. * logical pages.
  5422. * b. Wait 20msec. - note that this timeout is needed to make
  5423. * sure there are no requests in one of the PXP internal
  5424. * queues with "old" ILT addresses.
  5425. * c. PF enable in the PGLC.
  5426. * d. Clear the was_error of the PF in the PGLC. (could have
  5427. * occured while driver was down)
  5428. * e. PF enable in the CFC (WEAK + STRONG)
  5429. * f. Timers scan enable
  5430. * 3. PF driver unload flow:
  5431. * a. Clear the Timers scan_en.
  5432. * b. Polling for scan_on=0 for that PF.
  5433. * c. Clear the PF enable bit in the PXP.
  5434. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5435. * e. Write zero+valid to all ILT entries (The valid bit must
  5436. * stay set)
  5437. * f. If this is VNIC 3 of a port then also init
  5438. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5439. * to the last enrty in the ILT.
  5440. *
  5441. * Notes:
  5442. * Currently the PF error in the PGLC is non recoverable.
  5443. * In the future the there will be a recovery routine for this error.
  5444. * Currently attention is masked.
  5445. * Having an MCP lock on the load/unload process does not guarantee that
  5446. * there is no Timer disable during Func6/7 enable. This is because the
  5447. * Timers scan is currently being cleared by the MCP on FLR.
  5448. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5449. * there is error before clearing it. But the flow above is simpler and
  5450. * more general.
  5451. * All ILT entries are written by zero+valid and not just PF6/7
  5452. * ILT entries since in the future the ILT entries allocation for
  5453. * PF-s might be dynamic.
  5454. */
  5455. struct ilt_client_info ilt_cli;
  5456. struct bnx2x_ilt ilt;
  5457. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5458. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5459. /* initialize dummy TM client */
  5460. ilt_cli.start = 0;
  5461. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5462. ilt_cli.client_num = ILT_CLIENT_TM;
  5463. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5464. * Step 2: set the timers first/last ilt entry to point
  5465. * to the entire range to prevent ILT range error for 3rd/4th
  5466. * vnic (this code assumes existance of the vnic)
  5467. *
  5468. * both steps performed by call to bnx2x_ilt_client_init_op()
  5469. * with dummy TM client
  5470. *
  5471. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5472. * and his brother are split registers
  5473. */
  5474. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5475. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5476. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5477. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5478. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5479. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5480. }
  5481. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5482. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5483. if (!CHIP_IS_E1x(bp)) {
  5484. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5485. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5486. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5487. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5488. /* let the HW do it's magic ... */
  5489. do {
  5490. msleep(200);
  5491. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5492. } while (factor-- && (val != 1));
  5493. if (val != 1) {
  5494. BNX2X_ERR("ATC_INIT failed\n");
  5495. return -EBUSY;
  5496. }
  5497. }
  5498. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5499. /* clean the DMAE memory */
  5500. bp->dmae_ready = 1;
  5501. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5502. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5503. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5504. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5505. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5506. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5507. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5508. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5509. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5510. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5511. /* QM queues pointers table */
  5512. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5513. /* soft reset pulse */
  5514. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5515. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5516. if (CNIC_SUPPORT(bp))
  5517. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5518. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5519. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5520. if (!CHIP_REV_IS_SLOW(bp))
  5521. /* enable hw interrupt from doorbell Q */
  5522. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5523. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5524. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5525. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5526. if (!CHIP_IS_E1(bp))
  5527. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5528. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5529. if (IS_MF_AFEX(bp)) {
  5530. /* configure that VNTag and VLAN headers must be
  5531. * received in afex mode
  5532. */
  5533. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5534. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5535. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5536. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5537. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5538. } else {
  5539. /* Bit-map indicating which L2 hdrs may appear
  5540. * after the basic Ethernet header
  5541. */
  5542. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5543. bp->path_has_ovlan ? 7 : 6);
  5544. }
  5545. }
  5546. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5547. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5548. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5549. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5550. if (!CHIP_IS_E1x(bp)) {
  5551. /* reset VFC memories */
  5552. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5553. VFC_MEMORIES_RST_REG_CAM_RST |
  5554. VFC_MEMORIES_RST_REG_RAM_RST);
  5555. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5556. VFC_MEMORIES_RST_REG_CAM_RST |
  5557. VFC_MEMORIES_RST_REG_RAM_RST);
  5558. msleep(20);
  5559. }
  5560. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5561. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5562. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5563. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5564. /* sync semi rtc */
  5565. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5566. 0x80000000);
  5567. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5568. 0x80000000);
  5569. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5570. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5571. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5572. if (!CHIP_IS_E1x(bp)) {
  5573. if (IS_MF_AFEX(bp)) {
  5574. /* configure that VNTag and VLAN headers must be
  5575. * sent in afex mode
  5576. */
  5577. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5578. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5579. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5580. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5581. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5582. } else {
  5583. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5584. bp->path_has_ovlan ? 7 : 6);
  5585. }
  5586. }
  5587. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5588. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5589. if (CNIC_SUPPORT(bp)) {
  5590. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5591. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5592. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5593. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5594. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5595. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5596. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5597. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5598. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5599. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5600. }
  5601. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5602. if (sizeof(union cdu_context) != 1024)
  5603. /* we currently assume that a context is 1024 bytes */
  5604. dev_alert(&bp->pdev->dev,
  5605. "please adjust the size of cdu_context(%ld)\n",
  5606. (long)sizeof(union cdu_context));
  5607. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5608. val = (4 << 24) + (0 << 12) + 1024;
  5609. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5610. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5611. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5612. /* enable context validation interrupt from CFC */
  5613. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5614. /* set the thresholds to prevent CFC/CDU race */
  5615. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5616. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5617. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5618. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5619. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5620. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5621. /* Reset PCIE errors for debug */
  5622. REG_WR(bp, 0x2814, 0xffffffff);
  5623. REG_WR(bp, 0x3820, 0xffffffff);
  5624. if (!CHIP_IS_E1x(bp)) {
  5625. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5626. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5627. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5628. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5629. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5630. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5631. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5632. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5633. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5634. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5635. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5636. }
  5637. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5638. if (!CHIP_IS_E1(bp)) {
  5639. /* in E3 this done in per-port section */
  5640. if (!CHIP_IS_E3(bp))
  5641. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5642. }
  5643. if (CHIP_IS_E1H(bp))
  5644. /* not applicable for E2 (and above ...) */
  5645. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5646. if (CHIP_REV_IS_SLOW(bp))
  5647. msleep(200);
  5648. /* finish CFC init */
  5649. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5650. if (val != 1) {
  5651. BNX2X_ERR("CFC LL_INIT failed\n");
  5652. return -EBUSY;
  5653. }
  5654. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5655. if (val != 1) {
  5656. BNX2X_ERR("CFC AC_INIT failed\n");
  5657. return -EBUSY;
  5658. }
  5659. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5660. if (val != 1) {
  5661. BNX2X_ERR("CFC CAM_INIT failed\n");
  5662. return -EBUSY;
  5663. }
  5664. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5665. if (CHIP_IS_E1(bp)) {
  5666. /* read NIG statistic
  5667. to see if this is our first up since powerup */
  5668. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5669. val = *bnx2x_sp(bp, wb_data[0]);
  5670. /* do internal memory self test */
  5671. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5672. BNX2X_ERR("internal mem self test failed\n");
  5673. return -EBUSY;
  5674. }
  5675. }
  5676. bnx2x_setup_fan_failure_detection(bp);
  5677. /* clear PXP2 attentions */
  5678. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5679. bnx2x_enable_blocks_attention(bp);
  5680. bnx2x_enable_blocks_parity(bp);
  5681. if (!BP_NOMCP(bp)) {
  5682. if (CHIP_IS_E1x(bp))
  5683. bnx2x__common_init_phy(bp);
  5684. } else
  5685. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5686. return 0;
  5687. }
  5688. /**
  5689. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5690. *
  5691. * @bp: driver handle
  5692. */
  5693. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5694. {
  5695. int rc = bnx2x_init_hw_common(bp);
  5696. if (rc)
  5697. return rc;
  5698. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5699. if (!BP_NOMCP(bp))
  5700. bnx2x__common_init_phy(bp);
  5701. return 0;
  5702. }
  5703. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5704. {
  5705. int port = BP_PORT(bp);
  5706. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5707. u32 low, high;
  5708. u32 val;
  5709. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5710. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5711. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5712. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5713. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5714. /* Timers bug workaround: disables the pf_master bit in pglue at
  5715. * common phase, we need to enable it here before any dmae access are
  5716. * attempted. Therefore we manually added the enable-master to the
  5717. * port phase (it also happens in the function phase)
  5718. */
  5719. if (!CHIP_IS_E1x(bp))
  5720. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5721. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5722. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5723. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5724. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5725. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5726. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5727. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5728. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5729. /* QM cid (connection) count */
  5730. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5731. if (CNIC_SUPPORT(bp)) {
  5732. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5733. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5734. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5735. }
  5736. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5737. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5738. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5739. if (IS_MF(bp))
  5740. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5741. else if (bp->dev->mtu > 4096) {
  5742. if (bp->flags & ONE_PORT_FLAG)
  5743. low = 160;
  5744. else {
  5745. val = bp->dev->mtu;
  5746. /* (24*1024 + val*4)/256 */
  5747. low = 96 + (val/64) +
  5748. ((val % 64) ? 1 : 0);
  5749. }
  5750. } else
  5751. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5752. high = low + 56; /* 14*1024/256 */
  5753. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5754. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5755. }
  5756. if (CHIP_MODE_IS_4_PORT(bp))
  5757. REG_WR(bp, (BP_PORT(bp) ?
  5758. BRB1_REG_MAC_GUARANTIED_1 :
  5759. BRB1_REG_MAC_GUARANTIED_0), 40);
  5760. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5761. if (CHIP_IS_E3B0(bp)) {
  5762. if (IS_MF_AFEX(bp)) {
  5763. /* configure headers for AFEX mode */
  5764. REG_WR(bp, BP_PORT(bp) ?
  5765. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5766. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5767. REG_WR(bp, BP_PORT(bp) ?
  5768. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5769. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5770. REG_WR(bp, BP_PORT(bp) ?
  5771. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5772. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5773. } else {
  5774. /* Ovlan exists only if we are in multi-function +
  5775. * switch-dependent mode, in switch-independent there
  5776. * is no ovlan headers
  5777. */
  5778. REG_WR(bp, BP_PORT(bp) ?
  5779. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5780. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5781. (bp->path_has_ovlan ? 7 : 6));
  5782. }
  5783. }
  5784. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5785. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5786. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5787. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5788. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5789. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5790. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5791. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5792. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5793. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5794. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5795. if (CHIP_IS_E1x(bp)) {
  5796. /* configure PBF to work without PAUSE mtu 9000 */
  5797. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5798. /* update threshold */
  5799. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5800. /* update init credit */
  5801. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5802. /* probe changes */
  5803. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5804. udelay(50);
  5805. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5806. }
  5807. if (CNIC_SUPPORT(bp))
  5808. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5809. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5810. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5811. if (CHIP_IS_E1(bp)) {
  5812. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5813. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5814. }
  5815. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5816. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5817. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5818. /* init aeu_mask_attn_func_0/1:
  5819. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5820. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5821. * bits 4-7 are used for "per vn group attention" */
  5822. val = IS_MF(bp) ? 0xF7 : 0x7;
  5823. /* Enable DCBX attention for all but E1 */
  5824. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5825. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5826. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5827. if (!CHIP_IS_E1x(bp)) {
  5828. /* Bit-map indicating which L2 hdrs may appear after the
  5829. * basic Ethernet header
  5830. */
  5831. if (IS_MF_AFEX(bp))
  5832. REG_WR(bp, BP_PORT(bp) ?
  5833. NIG_REG_P1_HDRS_AFTER_BASIC :
  5834. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5835. else
  5836. REG_WR(bp, BP_PORT(bp) ?
  5837. NIG_REG_P1_HDRS_AFTER_BASIC :
  5838. NIG_REG_P0_HDRS_AFTER_BASIC,
  5839. IS_MF_SD(bp) ? 7 : 6);
  5840. if (CHIP_IS_E3(bp))
  5841. REG_WR(bp, BP_PORT(bp) ?
  5842. NIG_REG_LLH1_MF_MODE :
  5843. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5844. }
  5845. if (!CHIP_IS_E3(bp))
  5846. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5847. if (!CHIP_IS_E1(bp)) {
  5848. /* 0x2 disable mf_ov, 0x1 enable */
  5849. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5850. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5851. if (!CHIP_IS_E1x(bp)) {
  5852. val = 0;
  5853. switch (bp->mf_mode) {
  5854. case MULTI_FUNCTION_SD:
  5855. val = 1;
  5856. break;
  5857. case MULTI_FUNCTION_SI:
  5858. case MULTI_FUNCTION_AFEX:
  5859. val = 2;
  5860. break;
  5861. }
  5862. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5863. NIG_REG_LLH0_CLS_TYPE), val);
  5864. }
  5865. {
  5866. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5867. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5868. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5869. }
  5870. }
  5871. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5872. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5873. if (val & MISC_SPIO_SPIO5) {
  5874. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5875. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5876. val = REG_RD(bp, reg_addr);
  5877. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5878. REG_WR(bp, reg_addr, val);
  5879. }
  5880. return 0;
  5881. }
  5882. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5883. {
  5884. int reg;
  5885. u32 wb_write[2];
  5886. if (CHIP_IS_E1(bp))
  5887. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5888. else
  5889. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5890. wb_write[0] = ONCHIP_ADDR1(addr);
  5891. wb_write[1] = ONCHIP_ADDR2(addr);
  5892. REG_WR_DMAE(bp, reg, wb_write, 2);
  5893. }
  5894. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5895. u8 idu_sb_id, bool is_Pf)
  5896. {
  5897. u32 data, ctl, cnt = 100;
  5898. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5899. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5900. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5901. u32 sb_bit = 1 << (idu_sb_id%32);
  5902. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5903. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5904. /* Not supported in BC mode */
  5905. if (CHIP_INT_MODE_IS_BC(bp))
  5906. return;
  5907. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5908. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5909. IGU_REGULAR_CLEANUP_SET |
  5910. IGU_REGULAR_BCLEANUP;
  5911. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5912. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5913. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5914. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5915. data, igu_addr_data);
  5916. REG_WR(bp, igu_addr_data, data);
  5917. mmiowb();
  5918. barrier();
  5919. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5920. ctl, igu_addr_ctl);
  5921. REG_WR(bp, igu_addr_ctl, ctl);
  5922. mmiowb();
  5923. barrier();
  5924. /* wait for clean up to finish */
  5925. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5926. msleep(20);
  5927. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5928. DP(NETIF_MSG_HW,
  5929. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5930. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5931. }
  5932. }
  5933. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5934. {
  5935. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5936. }
  5937. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5938. {
  5939. u32 i, base = FUNC_ILT_BASE(func);
  5940. for (i = base; i < base + ILT_PER_FUNC; i++)
  5941. bnx2x_ilt_wr(bp, i, 0);
  5942. }
  5943. static void bnx2x_init_searcher(struct bnx2x *bp)
  5944. {
  5945. int port = BP_PORT(bp);
  5946. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5947. /* T1 hash bits value determines the T1 number of entries */
  5948. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5949. }
  5950. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  5951. {
  5952. int rc;
  5953. struct bnx2x_func_state_params func_params = {NULL};
  5954. struct bnx2x_func_switch_update_params *switch_update_params =
  5955. &func_params.params.switch_update;
  5956. /* Prepare parameters for function state transitions */
  5957. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  5958. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  5959. func_params.f_obj = &bp->func_obj;
  5960. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  5961. /* Function parameters */
  5962. switch_update_params->suspend = suspend;
  5963. rc = bnx2x_func_state_change(bp, &func_params);
  5964. return rc;
  5965. }
  5966. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  5967. {
  5968. int rc, i, port = BP_PORT(bp);
  5969. int vlan_en = 0, mac_en[NUM_MACS];
  5970. /* Close input from network */
  5971. if (bp->mf_mode == SINGLE_FUNCTION) {
  5972. bnx2x_set_rx_filter(&bp->link_params, 0);
  5973. } else {
  5974. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5975. NIG_REG_LLH0_FUNC_EN);
  5976. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5977. NIG_REG_LLH0_FUNC_EN, 0);
  5978. for (i = 0; i < NUM_MACS; i++) {
  5979. mac_en[i] = REG_RD(bp, port ?
  5980. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5981. 4 * i) :
  5982. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  5983. 4 * i));
  5984. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5985. 4 * i) :
  5986. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  5987. }
  5988. }
  5989. /* Close BMC to host */
  5990. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  5991. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  5992. /* Suspend Tx switching to the PF. Completion of this ramrod
  5993. * further guarantees that all the packets of that PF / child
  5994. * VFs in BRB were processed by the Parser, so it is safe to
  5995. * change the NIC_MODE register.
  5996. */
  5997. rc = bnx2x_func_switch_update(bp, 1);
  5998. if (rc) {
  5999. BNX2X_ERR("Can't suspend tx-switching!\n");
  6000. return rc;
  6001. }
  6002. /* Change NIC_MODE register */
  6003. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6004. /* Open input from network */
  6005. if (bp->mf_mode == SINGLE_FUNCTION) {
  6006. bnx2x_set_rx_filter(&bp->link_params, 1);
  6007. } else {
  6008. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6009. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6010. for (i = 0; i < NUM_MACS; i++) {
  6011. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6012. 4 * i) :
  6013. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6014. mac_en[i]);
  6015. }
  6016. }
  6017. /* Enable BMC to host */
  6018. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6019. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6020. /* Resume Tx switching to the PF */
  6021. rc = bnx2x_func_switch_update(bp, 0);
  6022. if (rc) {
  6023. BNX2X_ERR("Can't resume tx-switching!\n");
  6024. return rc;
  6025. }
  6026. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6027. return 0;
  6028. }
  6029. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6030. {
  6031. int rc;
  6032. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6033. if (CONFIGURE_NIC_MODE(bp)) {
  6034. /* Configrue searcher as part of function hw init */
  6035. bnx2x_init_searcher(bp);
  6036. /* Reset NIC mode */
  6037. rc = bnx2x_reset_nic_mode(bp);
  6038. if (rc)
  6039. BNX2X_ERR("Can't change NIC mode!\n");
  6040. return rc;
  6041. }
  6042. return 0;
  6043. }
  6044. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6045. {
  6046. int port = BP_PORT(bp);
  6047. int func = BP_FUNC(bp);
  6048. int init_phase = PHASE_PF0 + func;
  6049. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6050. u16 cdu_ilt_start;
  6051. u32 addr, val;
  6052. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6053. int i, main_mem_width, rc;
  6054. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6055. /* FLR cleanup - hmmm */
  6056. if (!CHIP_IS_E1x(bp)) {
  6057. rc = bnx2x_pf_flr_clnup(bp);
  6058. if (rc)
  6059. return rc;
  6060. }
  6061. /* set MSI reconfigure capability */
  6062. if (bp->common.int_block == INT_BLOCK_HC) {
  6063. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6064. val = REG_RD(bp, addr);
  6065. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6066. REG_WR(bp, addr, val);
  6067. }
  6068. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6069. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6070. ilt = BP_ILT(bp);
  6071. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6072. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6073. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6074. ilt->lines[cdu_ilt_start + i].page_mapping =
  6075. bp->context[i].cxt_mapping;
  6076. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6077. }
  6078. bnx2x_ilt_init_op(bp, INITOP_SET);
  6079. if (!CONFIGURE_NIC_MODE(bp)) {
  6080. bnx2x_init_searcher(bp);
  6081. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6082. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6083. } else {
  6084. /* Set NIC mode */
  6085. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6086. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6087. }
  6088. if (!CHIP_IS_E1x(bp)) {
  6089. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6090. /* Turn on a single ISR mode in IGU if driver is going to use
  6091. * INT#x or MSI
  6092. */
  6093. if (!(bp->flags & USING_MSIX_FLAG))
  6094. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6095. /*
  6096. * Timers workaround bug: function init part.
  6097. * Need to wait 20msec after initializing ILT,
  6098. * needed to make sure there are no requests in
  6099. * one of the PXP internal queues with "old" ILT addresses
  6100. */
  6101. msleep(20);
  6102. /*
  6103. * Master enable - Due to WB DMAE writes performed before this
  6104. * register is re-initialized as part of the regular function
  6105. * init
  6106. */
  6107. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6108. /* Enable the function in IGU */
  6109. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6110. }
  6111. bp->dmae_ready = 1;
  6112. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6113. if (!CHIP_IS_E1x(bp))
  6114. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6115. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6116. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6117. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6118. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6119. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6120. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6121. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6122. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6123. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6124. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6125. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6126. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6127. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6128. if (!CHIP_IS_E1x(bp))
  6129. REG_WR(bp, QM_REG_PF_EN, 1);
  6130. if (!CHIP_IS_E1x(bp)) {
  6131. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6132. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6133. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6134. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6135. }
  6136. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6137. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6138. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6139. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6140. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6141. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6142. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6143. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6144. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6145. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6146. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6147. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6148. if (!CHIP_IS_E1x(bp))
  6149. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6150. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6151. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6152. if (!CHIP_IS_E1x(bp))
  6153. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6154. if (IS_MF(bp)) {
  6155. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6156. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6157. }
  6158. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6159. /* HC init per function */
  6160. if (bp->common.int_block == INT_BLOCK_HC) {
  6161. if (CHIP_IS_E1H(bp)) {
  6162. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6163. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6164. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6165. }
  6166. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6167. } else {
  6168. int num_segs, sb_idx, prod_offset;
  6169. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6170. if (!CHIP_IS_E1x(bp)) {
  6171. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6172. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6173. }
  6174. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6175. if (!CHIP_IS_E1x(bp)) {
  6176. int dsb_idx = 0;
  6177. /**
  6178. * Producer memory:
  6179. * E2 mode: address 0-135 match to the mapping memory;
  6180. * 136 - PF0 default prod; 137 - PF1 default prod;
  6181. * 138 - PF2 default prod; 139 - PF3 default prod;
  6182. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6183. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6184. * 144-147 reserved.
  6185. *
  6186. * E1.5 mode - In backward compatible mode;
  6187. * for non default SB; each even line in the memory
  6188. * holds the U producer and each odd line hold
  6189. * the C producer. The first 128 producers are for
  6190. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6191. * producers are for the DSB for each PF.
  6192. * Each PF has five segments: (the order inside each
  6193. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6194. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6195. * 144-147 attn prods;
  6196. */
  6197. /* non-default-status-blocks */
  6198. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6199. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6200. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6201. prod_offset = (bp->igu_base_sb + sb_idx) *
  6202. num_segs;
  6203. for (i = 0; i < num_segs; i++) {
  6204. addr = IGU_REG_PROD_CONS_MEMORY +
  6205. (prod_offset + i) * 4;
  6206. REG_WR(bp, addr, 0);
  6207. }
  6208. /* send consumer update with value 0 */
  6209. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6210. USTORM_ID, 0, IGU_INT_NOP, 1);
  6211. bnx2x_igu_clear_sb(bp,
  6212. bp->igu_base_sb + sb_idx);
  6213. }
  6214. /* default-status-blocks */
  6215. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6216. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6217. if (CHIP_MODE_IS_4_PORT(bp))
  6218. dsb_idx = BP_FUNC(bp);
  6219. else
  6220. dsb_idx = BP_VN(bp);
  6221. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6222. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6223. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6224. /*
  6225. * igu prods come in chunks of E1HVN_MAX (4) -
  6226. * does not matters what is the current chip mode
  6227. */
  6228. for (i = 0; i < (num_segs * E1HVN_MAX);
  6229. i += E1HVN_MAX) {
  6230. addr = IGU_REG_PROD_CONS_MEMORY +
  6231. (prod_offset + i)*4;
  6232. REG_WR(bp, addr, 0);
  6233. }
  6234. /* send consumer update with 0 */
  6235. if (CHIP_INT_MODE_IS_BC(bp)) {
  6236. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6237. USTORM_ID, 0, IGU_INT_NOP, 1);
  6238. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6239. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6240. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6241. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6242. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6243. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6244. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6245. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6246. } else {
  6247. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6248. USTORM_ID, 0, IGU_INT_NOP, 1);
  6249. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6250. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6251. }
  6252. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6253. /* !!! these should become driver const once
  6254. rf-tool supports split-68 const */
  6255. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6256. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6257. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6258. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6259. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6260. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6261. }
  6262. }
  6263. /* Reset PCIE errors for debug */
  6264. REG_WR(bp, 0x2114, 0xffffffff);
  6265. REG_WR(bp, 0x2120, 0xffffffff);
  6266. if (CHIP_IS_E1x(bp)) {
  6267. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6268. main_mem_base = HC_REG_MAIN_MEMORY +
  6269. BP_PORT(bp) * (main_mem_size * 4);
  6270. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6271. main_mem_width = 8;
  6272. val = REG_RD(bp, main_mem_prty_clr);
  6273. if (val)
  6274. DP(NETIF_MSG_HW,
  6275. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6276. val);
  6277. /* Clear "false" parity errors in MSI-X table */
  6278. for (i = main_mem_base;
  6279. i < main_mem_base + main_mem_size * 4;
  6280. i += main_mem_width) {
  6281. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6282. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6283. i, main_mem_width / 4);
  6284. }
  6285. /* Clear HC parity attention */
  6286. REG_RD(bp, main_mem_prty_clr);
  6287. }
  6288. #ifdef BNX2X_STOP_ON_ERROR
  6289. /* Enable STORMs SP logging */
  6290. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6291. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6292. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6293. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6294. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6295. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6296. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6297. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6298. #endif
  6299. bnx2x_phy_probe(&bp->link_params);
  6300. return 0;
  6301. }
  6302. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6303. {
  6304. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6305. if (!CHIP_IS_E1x(bp))
  6306. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6307. sizeof(struct host_hc_status_block_e2));
  6308. else
  6309. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6310. sizeof(struct host_hc_status_block_e1x));
  6311. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6312. }
  6313. void bnx2x_free_mem(struct bnx2x *bp)
  6314. {
  6315. int i;
  6316. /* fastpath */
  6317. bnx2x_free_fp_mem(bp);
  6318. /* end of fastpath */
  6319. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6320. sizeof(struct host_sp_status_block));
  6321. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6322. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6323. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6324. sizeof(struct bnx2x_slowpath));
  6325. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6326. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6327. bp->context[i].size);
  6328. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6329. BNX2X_FREE(bp->ilt->lines);
  6330. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6331. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6332. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6333. }
  6334. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6335. {
  6336. int num_groups;
  6337. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6338. /* number of queues for statistics is number of eth queues + FCoE */
  6339. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6340. /* Total number of FW statistics requests =
  6341. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6342. * num of queues
  6343. */
  6344. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6345. /* Request is built from stats_query_header and an array of
  6346. * stats_query_cmd_group each of which contains
  6347. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6348. * configured in the stats_query_header.
  6349. */
  6350. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6351. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6352. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6353. num_groups * sizeof(struct stats_query_cmd_group);
  6354. /* Data for statistics requests + stats_conter
  6355. *
  6356. * stats_counter holds per-STORM counters that are incremented
  6357. * when STORM has finished with the current request.
  6358. *
  6359. * memory for FCoE offloaded statistics are counted anyway,
  6360. * even if they will not be sent.
  6361. */
  6362. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6363. sizeof(struct per_pf_stats) +
  6364. sizeof(struct fcoe_statistics_params) +
  6365. sizeof(struct per_queue_stats) * num_queue_stats +
  6366. sizeof(struct stats_counter);
  6367. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6368. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6369. /* Set shortcuts */
  6370. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6371. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6372. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6373. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6374. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6375. bp->fw_stats_req_sz;
  6376. return 0;
  6377. alloc_mem_err:
  6378. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6379. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6380. BNX2X_ERR("Can't allocate memory\n");
  6381. return -ENOMEM;
  6382. }
  6383. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6384. {
  6385. if (!CHIP_IS_E1x(bp))
  6386. /* size = the status block + ramrod buffers */
  6387. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6388. sizeof(struct host_hc_status_block_e2));
  6389. else
  6390. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6391. &bp->cnic_sb_mapping,
  6392. sizeof(struct
  6393. host_hc_status_block_e1x));
  6394. if (CONFIGURE_NIC_MODE(bp))
  6395. /* allocate searcher T2 table, as it wan't allocated before */
  6396. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6397. /* write address to which L5 should insert its values */
  6398. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6399. &bp->slowpath->drv_info_to_mcp;
  6400. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6401. goto alloc_mem_err;
  6402. return 0;
  6403. alloc_mem_err:
  6404. bnx2x_free_mem_cnic(bp);
  6405. BNX2X_ERR("Can't allocate memory\n");
  6406. return -ENOMEM;
  6407. }
  6408. int bnx2x_alloc_mem(struct bnx2x *bp)
  6409. {
  6410. int i, allocated, context_size;
  6411. if (!CONFIGURE_NIC_MODE(bp))
  6412. /* allocate searcher T2 table */
  6413. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6414. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6415. sizeof(struct host_sp_status_block));
  6416. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6417. sizeof(struct bnx2x_slowpath));
  6418. /* Allocated memory for FW statistics */
  6419. if (bnx2x_alloc_fw_stats_mem(bp))
  6420. goto alloc_mem_err;
  6421. /* Allocate memory for CDU context:
  6422. * This memory is allocated separately and not in the generic ILT
  6423. * functions because CDU differs in few aspects:
  6424. * 1. There are multiple entities allocating memory for context -
  6425. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6426. * its own ILT lines.
  6427. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6428. * for the other ILT clients), to be efficient we want to support
  6429. * allocation of sub-page-size in the last entry.
  6430. * 3. Context pointers are used by the driver to pass to FW / update
  6431. * the context (for the other ILT clients the pointers are used just to
  6432. * free the memory during unload).
  6433. */
  6434. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6435. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6436. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6437. (context_size - allocated));
  6438. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6439. &bp->context[i].cxt_mapping,
  6440. bp->context[i].size);
  6441. allocated += bp->context[i].size;
  6442. }
  6443. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6444. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6445. goto alloc_mem_err;
  6446. /* Slow path ring */
  6447. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6448. /* EQ */
  6449. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6450. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6451. /* fastpath */
  6452. /* need to be done at the end, since it's self adjusting to amount
  6453. * of memory available for RSS queues
  6454. */
  6455. if (bnx2x_alloc_fp_mem(bp))
  6456. goto alloc_mem_err;
  6457. return 0;
  6458. alloc_mem_err:
  6459. bnx2x_free_mem(bp);
  6460. BNX2X_ERR("Can't allocate memory\n");
  6461. return -ENOMEM;
  6462. }
  6463. /*
  6464. * Init service functions
  6465. */
  6466. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6467. struct bnx2x_vlan_mac_obj *obj, bool set,
  6468. int mac_type, unsigned long *ramrod_flags)
  6469. {
  6470. int rc;
  6471. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6472. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6473. /* Fill general parameters */
  6474. ramrod_param.vlan_mac_obj = obj;
  6475. ramrod_param.ramrod_flags = *ramrod_flags;
  6476. /* Fill a user request section if needed */
  6477. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6478. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6479. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6480. /* Set the command: ADD or DEL */
  6481. if (set)
  6482. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6483. else
  6484. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6485. }
  6486. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6487. if (rc == -EEXIST) {
  6488. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6489. /* do not treat adding same MAC as error */
  6490. rc = 0;
  6491. } else if (rc < 0)
  6492. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6493. return rc;
  6494. }
  6495. int bnx2x_del_all_macs(struct bnx2x *bp,
  6496. struct bnx2x_vlan_mac_obj *mac_obj,
  6497. int mac_type, bool wait_for_comp)
  6498. {
  6499. int rc;
  6500. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6501. /* Wait for completion of requested */
  6502. if (wait_for_comp)
  6503. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6504. /* Set the mac type of addresses we want to clear */
  6505. __set_bit(mac_type, &vlan_mac_flags);
  6506. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6507. if (rc < 0)
  6508. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6509. return rc;
  6510. }
  6511. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6512. {
  6513. unsigned long ramrod_flags = 0;
  6514. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6515. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6516. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6517. "Ignoring Zero MAC for STORAGE SD mode\n");
  6518. return 0;
  6519. }
  6520. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6521. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6522. /* Eth MAC is set on RSS leading client (fp[0]) */
  6523. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6524. set, BNX2X_ETH_MAC, &ramrod_flags);
  6525. }
  6526. int bnx2x_setup_leading(struct bnx2x *bp)
  6527. {
  6528. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6529. }
  6530. /**
  6531. * bnx2x_set_int_mode - configure interrupt mode
  6532. *
  6533. * @bp: driver handle
  6534. *
  6535. * In case of MSI-X it will also try to enable MSI-X.
  6536. */
  6537. int bnx2x_set_int_mode(struct bnx2x *bp)
  6538. {
  6539. int rc = 0;
  6540. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6541. return -EINVAL;
  6542. switch (int_mode) {
  6543. case BNX2X_INT_MODE_MSIX:
  6544. /* attempt to enable msix */
  6545. rc = bnx2x_enable_msix(bp);
  6546. /* msix attained */
  6547. if (!rc)
  6548. return 0;
  6549. /* vfs use only msix */
  6550. if (rc && IS_VF(bp))
  6551. return rc;
  6552. /* failed to enable multiple MSI-X */
  6553. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6554. bp->num_queues,
  6555. 1 + bp->num_cnic_queues);
  6556. /* falling through... */
  6557. case BNX2X_INT_MODE_MSI:
  6558. bnx2x_enable_msi(bp);
  6559. /* falling through... */
  6560. case BNX2X_INT_MODE_INTX:
  6561. bp->num_ethernet_queues = 1;
  6562. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6563. BNX2X_DEV_INFO("set number of queues to 1\n");
  6564. break;
  6565. default:
  6566. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6567. return -EINVAL;
  6568. }
  6569. return 0;
  6570. }
  6571. /* must be called prior to any HW initializations */
  6572. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6573. {
  6574. return L2_ILT_LINES(bp);
  6575. }
  6576. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6577. {
  6578. struct ilt_client_info *ilt_client;
  6579. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6580. u16 line = 0;
  6581. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6582. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6583. /* CDU */
  6584. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6585. ilt_client->client_num = ILT_CLIENT_CDU;
  6586. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6587. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6588. ilt_client->start = line;
  6589. line += bnx2x_cid_ilt_lines(bp);
  6590. if (CNIC_SUPPORT(bp))
  6591. line += CNIC_ILT_LINES;
  6592. ilt_client->end = line - 1;
  6593. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6594. ilt_client->start,
  6595. ilt_client->end,
  6596. ilt_client->page_size,
  6597. ilt_client->flags,
  6598. ilog2(ilt_client->page_size >> 12));
  6599. /* QM */
  6600. if (QM_INIT(bp->qm_cid_count)) {
  6601. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6602. ilt_client->client_num = ILT_CLIENT_QM;
  6603. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6604. ilt_client->flags = 0;
  6605. ilt_client->start = line;
  6606. /* 4 bytes for each cid */
  6607. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6608. QM_ILT_PAGE_SZ);
  6609. ilt_client->end = line - 1;
  6610. DP(NETIF_MSG_IFUP,
  6611. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6612. ilt_client->start,
  6613. ilt_client->end,
  6614. ilt_client->page_size,
  6615. ilt_client->flags,
  6616. ilog2(ilt_client->page_size >> 12));
  6617. }
  6618. if (CNIC_SUPPORT(bp)) {
  6619. /* SRC */
  6620. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6621. ilt_client->client_num = ILT_CLIENT_SRC;
  6622. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6623. ilt_client->flags = 0;
  6624. ilt_client->start = line;
  6625. line += SRC_ILT_LINES;
  6626. ilt_client->end = line - 1;
  6627. DP(NETIF_MSG_IFUP,
  6628. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6629. ilt_client->start,
  6630. ilt_client->end,
  6631. ilt_client->page_size,
  6632. ilt_client->flags,
  6633. ilog2(ilt_client->page_size >> 12));
  6634. /* TM */
  6635. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6636. ilt_client->client_num = ILT_CLIENT_TM;
  6637. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6638. ilt_client->flags = 0;
  6639. ilt_client->start = line;
  6640. line += TM_ILT_LINES;
  6641. ilt_client->end = line - 1;
  6642. DP(NETIF_MSG_IFUP,
  6643. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6644. ilt_client->start,
  6645. ilt_client->end,
  6646. ilt_client->page_size,
  6647. ilt_client->flags,
  6648. ilog2(ilt_client->page_size >> 12));
  6649. }
  6650. BUG_ON(line > ILT_MAX_LINES);
  6651. }
  6652. /**
  6653. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6654. *
  6655. * @bp: driver handle
  6656. * @fp: pointer to fastpath
  6657. * @init_params: pointer to parameters structure
  6658. *
  6659. * parameters configured:
  6660. * - HC configuration
  6661. * - Queue's CDU context
  6662. */
  6663. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6664. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6665. {
  6666. u8 cos;
  6667. int cxt_index, cxt_offset;
  6668. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6669. if (!IS_FCOE_FP(fp)) {
  6670. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6671. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6672. /* If HC is supporterd, enable host coalescing in the transition
  6673. * to INIT state.
  6674. */
  6675. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6676. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6677. /* HC rate */
  6678. init_params->rx.hc_rate = bp->rx_ticks ?
  6679. (1000000 / bp->rx_ticks) : 0;
  6680. init_params->tx.hc_rate = bp->tx_ticks ?
  6681. (1000000 / bp->tx_ticks) : 0;
  6682. /* FW SB ID */
  6683. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6684. fp->fw_sb_id;
  6685. /*
  6686. * CQ index among the SB indices: FCoE clients uses the default
  6687. * SB, therefore it's different.
  6688. */
  6689. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6690. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6691. }
  6692. /* set maximum number of COSs supported by this queue */
  6693. init_params->max_cos = fp->max_cos;
  6694. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6695. fp->index, init_params->max_cos);
  6696. /* set the context pointers queue object */
  6697. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6698. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6699. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6700. ILT_PAGE_CIDS);
  6701. init_params->cxts[cos] =
  6702. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6703. }
  6704. }
  6705. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6706. struct bnx2x_queue_state_params *q_params,
  6707. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6708. int tx_index, bool leading)
  6709. {
  6710. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6711. /* Set the command */
  6712. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6713. /* Set tx-only QUEUE flags: don't zero statistics */
  6714. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6715. /* choose the index of the cid to send the slow path on */
  6716. tx_only_params->cid_index = tx_index;
  6717. /* Set general TX_ONLY_SETUP parameters */
  6718. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6719. /* Set Tx TX_ONLY_SETUP parameters */
  6720. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6721. DP(NETIF_MSG_IFUP,
  6722. "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",
  6723. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6724. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6725. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6726. /* send the ramrod */
  6727. return bnx2x_queue_state_change(bp, q_params);
  6728. }
  6729. /**
  6730. * bnx2x_setup_queue - setup queue
  6731. *
  6732. * @bp: driver handle
  6733. * @fp: pointer to fastpath
  6734. * @leading: is leading
  6735. *
  6736. * This function performs 2 steps in a Queue state machine
  6737. * actually: 1) RESET->INIT 2) INIT->SETUP
  6738. */
  6739. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6740. bool leading)
  6741. {
  6742. struct bnx2x_queue_state_params q_params = {NULL};
  6743. struct bnx2x_queue_setup_params *setup_params =
  6744. &q_params.params.setup;
  6745. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6746. &q_params.params.tx_only;
  6747. int rc;
  6748. u8 tx_index;
  6749. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6750. /* reset IGU state skip FCoE L2 queue */
  6751. if (!IS_FCOE_FP(fp))
  6752. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6753. IGU_INT_ENABLE, 0);
  6754. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6755. /* We want to wait for completion in this context */
  6756. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6757. /* Prepare the INIT parameters */
  6758. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6759. /* Set the command */
  6760. q_params.cmd = BNX2X_Q_CMD_INIT;
  6761. /* Change the state to INIT */
  6762. rc = bnx2x_queue_state_change(bp, &q_params);
  6763. if (rc) {
  6764. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6765. return rc;
  6766. }
  6767. DP(NETIF_MSG_IFUP, "init complete\n");
  6768. /* Now move the Queue to the SETUP state... */
  6769. memset(setup_params, 0, sizeof(*setup_params));
  6770. /* Set QUEUE flags */
  6771. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6772. /* Set general SETUP parameters */
  6773. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6774. FIRST_TX_COS_INDEX);
  6775. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6776. &setup_params->rxq_params);
  6777. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6778. FIRST_TX_COS_INDEX);
  6779. /* Set the command */
  6780. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6781. if (IS_FCOE_FP(fp))
  6782. bp->fcoe_init = true;
  6783. /* Change the state to SETUP */
  6784. rc = bnx2x_queue_state_change(bp, &q_params);
  6785. if (rc) {
  6786. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6787. return rc;
  6788. }
  6789. /* loop through the relevant tx-only indices */
  6790. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6791. tx_index < fp->max_cos;
  6792. tx_index++) {
  6793. /* prepare and send tx-only ramrod*/
  6794. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6795. tx_only_params, tx_index, leading);
  6796. if (rc) {
  6797. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6798. fp->index, tx_index);
  6799. return rc;
  6800. }
  6801. }
  6802. return rc;
  6803. }
  6804. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6805. {
  6806. struct bnx2x_fastpath *fp = &bp->fp[index];
  6807. struct bnx2x_fp_txdata *txdata;
  6808. struct bnx2x_queue_state_params q_params = {NULL};
  6809. int rc, tx_index;
  6810. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6811. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6812. /* We want to wait for completion in this context */
  6813. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6814. /* close tx-only connections */
  6815. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6816. tx_index < fp->max_cos;
  6817. tx_index++){
  6818. /* ascertain this is a normal queue*/
  6819. txdata = fp->txdata_ptr[tx_index];
  6820. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6821. txdata->txq_index);
  6822. /* send halt terminate on tx-only connection */
  6823. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6824. memset(&q_params.params.terminate, 0,
  6825. sizeof(q_params.params.terminate));
  6826. q_params.params.terminate.cid_index = tx_index;
  6827. rc = bnx2x_queue_state_change(bp, &q_params);
  6828. if (rc)
  6829. return rc;
  6830. /* send halt terminate on tx-only connection */
  6831. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6832. memset(&q_params.params.cfc_del, 0,
  6833. sizeof(q_params.params.cfc_del));
  6834. q_params.params.cfc_del.cid_index = tx_index;
  6835. rc = bnx2x_queue_state_change(bp, &q_params);
  6836. if (rc)
  6837. return rc;
  6838. }
  6839. /* Stop the primary connection: */
  6840. /* ...halt the connection */
  6841. q_params.cmd = BNX2X_Q_CMD_HALT;
  6842. rc = bnx2x_queue_state_change(bp, &q_params);
  6843. if (rc)
  6844. return rc;
  6845. /* ...terminate the connection */
  6846. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6847. memset(&q_params.params.terminate, 0,
  6848. sizeof(q_params.params.terminate));
  6849. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6850. rc = bnx2x_queue_state_change(bp, &q_params);
  6851. if (rc)
  6852. return rc;
  6853. /* ...delete cfc entry */
  6854. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6855. memset(&q_params.params.cfc_del, 0,
  6856. sizeof(q_params.params.cfc_del));
  6857. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6858. return bnx2x_queue_state_change(bp, &q_params);
  6859. }
  6860. static void bnx2x_reset_func(struct bnx2x *bp)
  6861. {
  6862. int port = BP_PORT(bp);
  6863. int func = BP_FUNC(bp);
  6864. int i;
  6865. /* Disable the function in the FW */
  6866. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6867. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6868. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6869. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6870. /* FP SBs */
  6871. for_each_eth_queue(bp, i) {
  6872. struct bnx2x_fastpath *fp = &bp->fp[i];
  6873. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6874. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6875. SB_DISABLED);
  6876. }
  6877. if (CNIC_LOADED(bp))
  6878. /* CNIC SB */
  6879. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6880. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6881. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6882. /* SP SB */
  6883. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6884. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6885. SB_DISABLED);
  6886. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6887. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6888. 0);
  6889. /* Configure IGU */
  6890. if (bp->common.int_block == INT_BLOCK_HC) {
  6891. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6892. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6893. } else {
  6894. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6895. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6896. }
  6897. if (CNIC_LOADED(bp)) {
  6898. /* Disable Timer scan */
  6899. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6900. /*
  6901. * Wait for at least 10ms and up to 2 second for the timers
  6902. * scan to complete
  6903. */
  6904. for (i = 0; i < 200; i++) {
  6905. msleep(10);
  6906. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6907. break;
  6908. }
  6909. }
  6910. /* Clear ILT */
  6911. bnx2x_clear_func_ilt(bp, func);
  6912. /* Timers workaround bug for E2: if this is vnic-3,
  6913. * we need to set the entire ilt range for this timers.
  6914. */
  6915. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6916. struct ilt_client_info ilt_cli;
  6917. /* use dummy TM client */
  6918. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6919. ilt_cli.start = 0;
  6920. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6921. ilt_cli.client_num = ILT_CLIENT_TM;
  6922. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6923. }
  6924. /* this assumes that reset_port() called before reset_func()*/
  6925. if (!CHIP_IS_E1x(bp))
  6926. bnx2x_pf_disable(bp);
  6927. bp->dmae_ready = 0;
  6928. }
  6929. static void bnx2x_reset_port(struct bnx2x *bp)
  6930. {
  6931. int port = BP_PORT(bp);
  6932. u32 val;
  6933. /* Reset physical Link */
  6934. bnx2x__link_reset(bp);
  6935. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6936. /* Do not rcv packets to BRB */
  6937. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6938. /* Do not direct rcv packets that are not for MCP to the BRB */
  6939. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6940. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6941. /* Configure AEU */
  6942. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6943. msleep(100);
  6944. /* Check for BRB port occupancy */
  6945. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6946. if (val)
  6947. DP(NETIF_MSG_IFDOWN,
  6948. "BRB1 is not empty %d blocks are occupied\n", val);
  6949. /* TODO: Close Doorbell port? */
  6950. }
  6951. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6952. {
  6953. struct bnx2x_func_state_params func_params = {NULL};
  6954. /* Prepare parameters for function state transitions */
  6955. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6956. func_params.f_obj = &bp->func_obj;
  6957. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6958. func_params.params.hw_init.load_phase = load_code;
  6959. return bnx2x_func_state_change(bp, &func_params);
  6960. }
  6961. static int bnx2x_func_stop(struct bnx2x *bp)
  6962. {
  6963. struct bnx2x_func_state_params func_params = {NULL};
  6964. int rc;
  6965. /* Prepare parameters for function state transitions */
  6966. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6967. func_params.f_obj = &bp->func_obj;
  6968. func_params.cmd = BNX2X_F_CMD_STOP;
  6969. /*
  6970. * Try to stop the function the 'good way'. If fails (in case
  6971. * of a parity error during bnx2x_chip_cleanup()) and we are
  6972. * not in a debug mode, perform a state transaction in order to
  6973. * enable further HW_RESET transaction.
  6974. */
  6975. rc = bnx2x_func_state_change(bp, &func_params);
  6976. if (rc) {
  6977. #ifdef BNX2X_STOP_ON_ERROR
  6978. return rc;
  6979. #else
  6980. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6981. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6982. return bnx2x_func_state_change(bp, &func_params);
  6983. #endif
  6984. }
  6985. return 0;
  6986. }
  6987. /**
  6988. * bnx2x_send_unload_req - request unload mode from the MCP.
  6989. *
  6990. * @bp: driver handle
  6991. * @unload_mode: requested function's unload mode
  6992. *
  6993. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6994. */
  6995. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6996. {
  6997. u32 reset_code = 0;
  6998. int port = BP_PORT(bp);
  6999. /* Select the UNLOAD request mode */
  7000. if (unload_mode == UNLOAD_NORMAL)
  7001. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7002. else if (bp->flags & NO_WOL_FLAG)
  7003. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7004. else if (bp->wol) {
  7005. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7006. u8 *mac_addr = bp->dev->dev_addr;
  7007. u32 val;
  7008. u16 pmc;
  7009. /* The mac address is written to entries 1-4 to
  7010. * preserve entry 0 which is used by the PMF
  7011. */
  7012. u8 entry = (BP_VN(bp) + 1)*8;
  7013. val = (mac_addr[0] << 8) | mac_addr[1];
  7014. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7015. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7016. (mac_addr[4] << 8) | mac_addr[5];
  7017. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7018. /* Enable the PME and clear the status */
  7019. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7020. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7021. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7022. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7023. } else
  7024. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7025. /* Send the request to the MCP */
  7026. if (!BP_NOMCP(bp))
  7027. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7028. else {
  7029. int path = BP_PATH(bp);
  7030. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7031. path, load_count[path][0], load_count[path][1],
  7032. load_count[path][2]);
  7033. load_count[path][0]--;
  7034. load_count[path][1 + port]--;
  7035. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7036. path, load_count[path][0], load_count[path][1],
  7037. load_count[path][2]);
  7038. if (load_count[path][0] == 0)
  7039. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7040. else if (load_count[path][1 + port] == 0)
  7041. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7042. else
  7043. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7044. }
  7045. return reset_code;
  7046. }
  7047. /**
  7048. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7049. *
  7050. * @bp: driver handle
  7051. * @keep_link: true iff link should be kept up
  7052. */
  7053. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7054. {
  7055. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7056. /* Report UNLOAD_DONE to MCP */
  7057. if (!BP_NOMCP(bp))
  7058. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7059. }
  7060. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7061. {
  7062. int tout = 50;
  7063. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7064. if (!bp->port.pmf)
  7065. return 0;
  7066. /*
  7067. * (assumption: No Attention from MCP at this stage)
  7068. * PMF probably in the middle of TXdisable/enable transaction
  7069. * 1. Sync IRS for default SB
  7070. * 2. Sync SP queue - this guarantes us that attention handling started
  7071. * 3. Wait, that TXdisable/enable transaction completes
  7072. *
  7073. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7074. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7075. * received complettion for the transaction the state is TX_STOPPED.
  7076. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7077. * transaction.
  7078. */
  7079. /* make sure default SB ISR is done */
  7080. if (msix)
  7081. synchronize_irq(bp->msix_table[0].vector);
  7082. else
  7083. synchronize_irq(bp->pdev->irq);
  7084. flush_workqueue(bnx2x_wq);
  7085. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7086. BNX2X_F_STATE_STARTED && tout--)
  7087. msleep(20);
  7088. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7089. BNX2X_F_STATE_STARTED) {
  7090. #ifdef BNX2X_STOP_ON_ERROR
  7091. BNX2X_ERR("Wrong function state\n");
  7092. return -EBUSY;
  7093. #else
  7094. /*
  7095. * Failed to complete the transaction in a "good way"
  7096. * Force both transactions with CLR bit
  7097. */
  7098. struct bnx2x_func_state_params func_params = {NULL};
  7099. DP(NETIF_MSG_IFDOWN,
  7100. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7101. func_params.f_obj = &bp->func_obj;
  7102. __set_bit(RAMROD_DRV_CLR_ONLY,
  7103. &func_params.ramrod_flags);
  7104. /* STARTED-->TX_ST0PPED */
  7105. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7106. bnx2x_func_state_change(bp, &func_params);
  7107. /* TX_ST0PPED-->STARTED */
  7108. func_params.cmd = BNX2X_F_CMD_TX_START;
  7109. return bnx2x_func_state_change(bp, &func_params);
  7110. #endif
  7111. }
  7112. return 0;
  7113. }
  7114. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7115. {
  7116. int port = BP_PORT(bp);
  7117. int i, rc = 0;
  7118. u8 cos;
  7119. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7120. u32 reset_code;
  7121. /* Wait until tx fastpath tasks complete */
  7122. for_each_tx_queue(bp, i) {
  7123. struct bnx2x_fastpath *fp = &bp->fp[i];
  7124. for_each_cos_in_tx_queue(fp, cos)
  7125. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7126. #ifdef BNX2X_STOP_ON_ERROR
  7127. if (rc)
  7128. return;
  7129. #endif
  7130. }
  7131. /* Give HW time to discard old tx messages */
  7132. usleep_range(1000, 1000);
  7133. /* Clean all ETH MACs */
  7134. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7135. false);
  7136. if (rc < 0)
  7137. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7138. /* Clean up UC list */
  7139. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7140. true);
  7141. if (rc < 0)
  7142. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7143. rc);
  7144. /* Disable LLH */
  7145. if (!CHIP_IS_E1(bp))
  7146. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7147. /* Set "drop all" (stop Rx).
  7148. * We need to take a netif_addr_lock() here in order to prevent
  7149. * a race between the completion code and this code.
  7150. */
  7151. netif_addr_lock_bh(bp->dev);
  7152. /* Schedule the rx_mode command */
  7153. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7154. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7155. else
  7156. bnx2x_set_storm_rx_mode(bp);
  7157. /* Cleanup multicast configuration */
  7158. rparam.mcast_obj = &bp->mcast_obj;
  7159. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7160. if (rc < 0)
  7161. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7162. netif_addr_unlock_bh(bp->dev);
  7163. /*
  7164. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7165. * this function should perform FUNC, PORT or COMMON HW
  7166. * reset.
  7167. */
  7168. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7169. /*
  7170. * (assumption: No Attention from MCP at this stage)
  7171. * PMF probably in the middle of TXdisable/enable transaction
  7172. */
  7173. rc = bnx2x_func_wait_started(bp);
  7174. if (rc) {
  7175. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7176. #ifdef BNX2X_STOP_ON_ERROR
  7177. return;
  7178. #endif
  7179. }
  7180. /* Close multi and leading connections
  7181. * Completions for ramrods are collected in a synchronous way
  7182. */
  7183. for_each_eth_queue(bp, i)
  7184. if (bnx2x_stop_queue(bp, i))
  7185. #ifdef BNX2X_STOP_ON_ERROR
  7186. return;
  7187. #else
  7188. goto unload_error;
  7189. #endif
  7190. if (CNIC_LOADED(bp)) {
  7191. for_each_cnic_queue(bp, i)
  7192. if (bnx2x_stop_queue(bp, i))
  7193. #ifdef BNX2X_STOP_ON_ERROR
  7194. return;
  7195. #else
  7196. goto unload_error;
  7197. #endif
  7198. }
  7199. /* If SP settings didn't get completed so far - something
  7200. * very wrong has happen.
  7201. */
  7202. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7203. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7204. #ifndef BNX2X_STOP_ON_ERROR
  7205. unload_error:
  7206. #endif
  7207. rc = bnx2x_func_stop(bp);
  7208. if (rc) {
  7209. BNX2X_ERR("Function stop failed!\n");
  7210. #ifdef BNX2X_STOP_ON_ERROR
  7211. return;
  7212. #endif
  7213. }
  7214. /* Disable HW interrupts, NAPI */
  7215. bnx2x_netif_stop(bp, 1);
  7216. /* Delete all NAPI objects */
  7217. bnx2x_del_all_napi(bp);
  7218. if (CNIC_LOADED(bp))
  7219. bnx2x_del_all_napi_cnic(bp);
  7220. /* Release IRQs */
  7221. bnx2x_free_irq(bp);
  7222. /* Reset the chip */
  7223. rc = bnx2x_reset_hw(bp, reset_code);
  7224. if (rc)
  7225. BNX2X_ERR("HW_RESET failed\n");
  7226. /* Report UNLOAD_DONE to MCP */
  7227. bnx2x_send_unload_done(bp, keep_link);
  7228. }
  7229. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7230. {
  7231. u32 val;
  7232. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7233. if (CHIP_IS_E1(bp)) {
  7234. int port = BP_PORT(bp);
  7235. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7236. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7237. val = REG_RD(bp, addr);
  7238. val &= ~(0x300);
  7239. REG_WR(bp, addr, val);
  7240. } else {
  7241. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7242. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7243. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7244. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7245. }
  7246. }
  7247. /* Close gates #2, #3 and #4: */
  7248. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7249. {
  7250. u32 val;
  7251. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7252. if (!CHIP_IS_E1(bp)) {
  7253. /* #4 */
  7254. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7255. /* #2 */
  7256. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7257. }
  7258. /* #3 */
  7259. if (CHIP_IS_E1x(bp)) {
  7260. /* Prevent interrupts from HC on both ports */
  7261. val = REG_RD(bp, HC_REG_CONFIG_1);
  7262. REG_WR(bp, HC_REG_CONFIG_1,
  7263. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7264. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7265. val = REG_RD(bp, HC_REG_CONFIG_0);
  7266. REG_WR(bp, HC_REG_CONFIG_0,
  7267. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7268. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7269. } else {
  7270. /* Prevent incomming interrupts in IGU */
  7271. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7272. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7273. (!close) ?
  7274. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7275. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7276. }
  7277. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7278. close ? "closing" : "opening");
  7279. mmiowb();
  7280. }
  7281. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7282. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7283. {
  7284. /* Do some magic... */
  7285. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7286. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7287. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7288. }
  7289. /**
  7290. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7291. *
  7292. * @bp: driver handle
  7293. * @magic_val: old value of the `magic' bit.
  7294. */
  7295. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7296. {
  7297. /* Restore the `magic' bit value... */
  7298. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7299. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7300. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7301. }
  7302. /**
  7303. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7304. *
  7305. * @bp: driver handle
  7306. * @magic_val: old value of 'magic' bit.
  7307. *
  7308. * Takes care of CLP configurations.
  7309. */
  7310. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7311. {
  7312. u32 shmem;
  7313. u32 validity_offset;
  7314. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7315. /* Set `magic' bit in order to save MF config */
  7316. if (!CHIP_IS_E1(bp))
  7317. bnx2x_clp_reset_prep(bp, magic_val);
  7318. /* Get shmem offset */
  7319. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7320. validity_offset =
  7321. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7322. /* Clear validity map flags */
  7323. if (shmem > 0)
  7324. REG_WR(bp, shmem + validity_offset, 0);
  7325. }
  7326. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7327. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7328. /**
  7329. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7330. *
  7331. * @bp: driver handle
  7332. */
  7333. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7334. {
  7335. /* special handling for emulation and FPGA,
  7336. wait 10 times longer */
  7337. if (CHIP_REV_IS_SLOW(bp))
  7338. msleep(MCP_ONE_TIMEOUT*10);
  7339. else
  7340. msleep(MCP_ONE_TIMEOUT);
  7341. }
  7342. /*
  7343. * initializes bp->common.shmem_base and waits for validity signature to appear
  7344. */
  7345. static int bnx2x_init_shmem(struct bnx2x *bp)
  7346. {
  7347. int cnt = 0;
  7348. u32 val = 0;
  7349. do {
  7350. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7351. if (bp->common.shmem_base) {
  7352. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7353. if (val & SHR_MEM_VALIDITY_MB)
  7354. return 0;
  7355. }
  7356. bnx2x_mcp_wait_one(bp);
  7357. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7358. BNX2X_ERR("BAD MCP validity signature\n");
  7359. return -ENODEV;
  7360. }
  7361. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7362. {
  7363. int rc = bnx2x_init_shmem(bp);
  7364. /* Restore the `magic' bit value */
  7365. if (!CHIP_IS_E1(bp))
  7366. bnx2x_clp_reset_done(bp, magic_val);
  7367. return rc;
  7368. }
  7369. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7370. {
  7371. if (!CHIP_IS_E1(bp)) {
  7372. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7373. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7374. mmiowb();
  7375. }
  7376. }
  7377. /*
  7378. * Reset the whole chip except for:
  7379. * - PCIE core
  7380. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7381. * one reset bit)
  7382. * - IGU
  7383. * - MISC (including AEU)
  7384. * - GRC
  7385. * - RBCN, RBCP
  7386. */
  7387. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7388. {
  7389. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7390. u32 global_bits2, stay_reset2;
  7391. /*
  7392. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7393. * (per chip) blocks.
  7394. */
  7395. global_bits2 =
  7396. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7397. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7398. /* Don't reset the following blocks.
  7399. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7400. * reset, as in 4 port device they might still be owned
  7401. * by the MCP (there is only one leader per path).
  7402. */
  7403. not_reset_mask1 =
  7404. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7405. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7406. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7407. not_reset_mask2 =
  7408. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7409. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7410. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7411. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7412. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7413. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7414. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7415. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7416. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7417. MISC_REGISTERS_RESET_REG_2_PGLC |
  7418. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7419. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7420. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7421. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7422. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7423. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7424. /*
  7425. * Keep the following blocks in reset:
  7426. * - all xxMACs are handled by the bnx2x_link code.
  7427. */
  7428. stay_reset2 =
  7429. MISC_REGISTERS_RESET_REG_2_XMAC |
  7430. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7431. /* Full reset masks according to the chip */
  7432. reset_mask1 = 0xffffffff;
  7433. if (CHIP_IS_E1(bp))
  7434. reset_mask2 = 0xffff;
  7435. else if (CHIP_IS_E1H(bp))
  7436. reset_mask2 = 0x1ffff;
  7437. else if (CHIP_IS_E2(bp))
  7438. reset_mask2 = 0xfffff;
  7439. else /* CHIP_IS_E3 */
  7440. reset_mask2 = 0x3ffffff;
  7441. /* Don't reset global blocks unless we need to */
  7442. if (!global)
  7443. reset_mask2 &= ~global_bits2;
  7444. /*
  7445. * In case of attention in the QM, we need to reset PXP
  7446. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7447. * because otherwise QM reset would release 'close the gates' shortly
  7448. * before resetting the PXP, then the PSWRQ would send a write
  7449. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7450. * read the payload data from PSWWR, but PSWWR would not
  7451. * respond. The write queue in PGLUE would stuck, dmae commands
  7452. * would not return. Therefore it's important to reset the second
  7453. * reset register (containing the
  7454. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7455. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7456. * bit).
  7457. */
  7458. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7459. reset_mask2 & (~not_reset_mask2));
  7460. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7461. reset_mask1 & (~not_reset_mask1));
  7462. barrier();
  7463. mmiowb();
  7464. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7465. reset_mask2 & (~stay_reset2));
  7466. barrier();
  7467. mmiowb();
  7468. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7469. mmiowb();
  7470. }
  7471. /**
  7472. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7473. * It should get cleared in no more than 1s.
  7474. *
  7475. * @bp: driver handle
  7476. *
  7477. * It should get cleared in no more than 1s. Returns 0 if
  7478. * pending writes bit gets cleared.
  7479. */
  7480. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7481. {
  7482. u32 cnt = 1000;
  7483. u32 pend_bits = 0;
  7484. do {
  7485. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7486. if (pend_bits == 0)
  7487. break;
  7488. usleep_range(1000, 1000);
  7489. } while (cnt-- > 0);
  7490. if (cnt <= 0) {
  7491. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7492. pend_bits);
  7493. return -EBUSY;
  7494. }
  7495. return 0;
  7496. }
  7497. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7498. {
  7499. int cnt = 1000;
  7500. u32 val = 0;
  7501. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7502. u32 tags_63_32 = 0;
  7503. /* Empty the Tetris buffer, wait for 1s */
  7504. do {
  7505. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7506. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7507. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7508. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7509. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7510. if (CHIP_IS_E3(bp))
  7511. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7512. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7513. ((port_is_idle_0 & 0x1) == 0x1) &&
  7514. ((port_is_idle_1 & 0x1) == 0x1) &&
  7515. (pgl_exp_rom2 == 0xffffffff) &&
  7516. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7517. break;
  7518. usleep_range(1000, 1000);
  7519. } while (cnt-- > 0);
  7520. if (cnt <= 0) {
  7521. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7522. 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",
  7523. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7524. pgl_exp_rom2);
  7525. return -EAGAIN;
  7526. }
  7527. barrier();
  7528. /* Close gates #2, #3 and #4 */
  7529. bnx2x_set_234_gates(bp, true);
  7530. /* Poll for IGU VQs for 57712 and newer chips */
  7531. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7532. return -EAGAIN;
  7533. /* TBD: Indicate that "process kill" is in progress to MCP */
  7534. /* Clear "unprepared" bit */
  7535. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7536. barrier();
  7537. /* Make sure all is written to the chip before the reset */
  7538. mmiowb();
  7539. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7540. * PSWHST, GRC and PSWRD Tetris buffer.
  7541. */
  7542. usleep_range(1000, 1000);
  7543. /* Prepare to chip reset: */
  7544. /* MCP */
  7545. if (global)
  7546. bnx2x_reset_mcp_prep(bp, &val);
  7547. /* PXP */
  7548. bnx2x_pxp_prep(bp);
  7549. barrier();
  7550. /* reset the chip */
  7551. bnx2x_process_kill_chip_reset(bp, global);
  7552. barrier();
  7553. /* Recover after reset: */
  7554. /* MCP */
  7555. if (global && bnx2x_reset_mcp_comp(bp, val))
  7556. return -EAGAIN;
  7557. /* TBD: Add resetting the NO_MCP mode DB here */
  7558. /* Open the gates #2, #3 and #4 */
  7559. bnx2x_set_234_gates(bp, false);
  7560. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7561. * reset state, re-enable attentions. */
  7562. return 0;
  7563. }
  7564. static int bnx2x_leader_reset(struct bnx2x *bp)
  7565. {
  7566. int rc = 0;
  7567. bool global = bnx2x_reset_is_global(bp);
  7568. u32 load_code;
  7569. /* if not going to reset MCP - load "fake" driver to reset HW while
  7570. * driver is owner of the HW
  7571. */
  7572. if (!global && !BP_NOMCP(bp)) {
  7573. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7574. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7575. if (!load_code) {
  7576. BNX2X_ERR("MCP response failure, aborting\n");
  7577. rc = -EAGAIN;
  7578. goto exit_leader_reset;
  7579. }
  7580. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7581. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7582. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7583. rc = -EAGAIN;
  7584. goto exit_leader_reset2;
  7585. }
  7586. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7587. if (!load_code) {
  7588. BNX2X_ERR("MCP response failure, aborting\n");
  7589. rc = -EAGAIN;
  7590. goto exit_leader_reset2;
  7591. }
  7592. }
  7593. /* Try to recover after the failure */
  7594. if (bnx2x_process_kill(bp, global)) {
  7595. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7596. BP_PATH(bp));
  7597. rc = -EAGAIN;
  7598. goto exit_leader_reset2;
  7599. }
  7600. /*
  7601. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7602. * state.
  7603. */
  7604. bnx2x_set_reset_done(bp);
  7605. if (global)
  7606. bnx2x_clear_reset_global(bp);
  7607. exit_leader_reset2:
  7608. /* unload "fake driver" if it was loaded */
  7609. if (!global && !BP_NOMCP(bp)) {
  7610. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7611. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7612. }
  7613. exit_leader_reset:
  7614. bp->is_leader = 0;
  7615. bnx2x_release_leader_lock(bp);
  7616. smp_mb();
  7617. return rc;
  7618. }
  7619. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7620. {
  7621. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7622. /* Disconnect this device */
  7623. netif_device_detach(bp->dev);
  7624. /*
  7625. * Block ifup for all function on this engine until "process kill"
  7626. * or power cycle.
  7627. */
  7628. bnx2x_set_reset_in_progress(bp);
  7629. /* Shut down the power */
  7630. bnx2x_set_power_state(bp, PCI_D3hot);
  7631. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7632. smp_mb();
  7633. }
  7634. /*
  7635. * Assumption: runs under rtnl lock. This together with the fact
  7636. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7637. * will never be called when netif_running(bp->dev) is false.
  7638. */
  7639. static void bnx2x_parity_recover(struct bnx2x *bp)
  7640. {
  7641. bool global = false;
  7642. u32 error_recovered, error_unrecovered;
  7643. bool is_parity;
  7644. DP(NETIF_MSG_HW, "Handling parity\n");
  7645. while (1) {
  7646. switch (bp->recovery_state) {
  7647. case BNX2X_RECOVERY_INIT:
  7648. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7649. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7650. WARN_ON(!is_parity);
  7651. /* Try to get a LEADER_LOCK HW lock */
  7652. if (bnx2x_trylock_leader_lock(bp)) {
  7653. bnx2x_set_reset_in_progress(bp);
  7654. /*
  7655. * Check if there is a global attention and if
  7656. * there was a global attention, set the global
  7657. * reset bit.
  7658. */
  7659. if (global)
  7660. bnx2x_set_reset_global(bp);
  7661. bp->is_leader = 1;
  7662. }
  7663. /* Stop the driver */
  7664. /* If interface has been removed - break */
  7665. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7666. return;
  7667. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7668. /* Ensure "is_leader", MCP command sequence and
  7669. * "recovery_state" update values are seen on other
  7670. * CPUs.
  7671. */
  7672. smp_mb();
  7673. break;
  7674. case BNX2X_RECOVERY_WAIT:
  7675. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7676. if (bp->is_leader) {
  7677. int other_engine = BP_PATH(bp) ? 0 : 1;
  7678. bool other_load_status =
  7679. bnx2x_get_load_status(bp, other_engine);
  7680. bool load_status =
  7681. bnx2x_get_load_status(bp, BP_PATH(bp));
  7682. global = bnx2x_reset_is_global(bp);
  7683. /*
  7684. * In case of a parity in a global block, let
  7685. * the first leader that performs a
  7686. * leader_reset() reset the global blocks in
  7687. * order to clear global attentions. Otherwise
  7688. * the the gates will remain closed for that
  7689. * engine.
  7690. */
  7691. if (load_status ||
  7692. (global && other_load_status)) {
  7693. /* Wait until all other functions get
  7694. * down.
  7695. */
  7696. schedule_delayed_work(&bp->sp_rtnl_task,
  7697. HZ/10);
  7698. return;
  7699. } else {
  7700. /* If all other functions got down -
  7701. * try to bring the chip back to
  7702. * normal. In any case it's an exit
  7703. * point for a leader.
  7704. */
  7705. if (bnx2x_leader_reset(bp)) {
  7706. bnx2x_recovery_failed(bp);
  7707. return;
  7708. }
  7709. /* If we are here, means that the
  7710. * leader has succeeded and doesn't
  7711. * want to be a leader any more. Try
  7712. * to continue as a none-leader.
  7713. */
  7714. break;
  7715. }
  7716. } else { /* non-leader */
  7717. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7718. /* Try to get a LEADER_LOCK HW lock as
  7719. * long as a former leader may have
  7720. * been unloaded by the user or
  7721. * released a leadership by another
  7722. * reason.
  7723. */
  7724. if (bnx2x_trylock_leader_lock(bp)) {
  7725. /* I'm a leader now! Restart a
  7726. * switch case.
  7727. */
  7728. bp->is_leader = 1;
  7729. break;
  7730. }
  7731. schedule_delayed_work(&bp->sp_rtnl_task,
  7732. HZ/10);
  7733. return;
  7734. } else {
  7735. /*
  7736. * If there was a global attention, wait
  7737. * for it to be cleared.
  7738. */
  7739. if (bnx2x_reset_is_global(bp)) {
  7740. schedule_delayed_work(
  7741. &bp->sp_rtnl_task,
  7742. HZ/10);
  7743. return;
  7744. }
  7745. error_recovered =
  7746. bp->eth_stats.recoverable_error;
  7747. error_unrecovered =
  7748. bp->eth_stats.unrecoverable_error;
  7749. bp->recovery_state =
  7750. BNX2X_RECOVERY_NIC_LOADING;
  7751. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7752. error_unrecovered++;
  7753. netdev_err(bp->dev,
  7754. "Recovery failed. Power cycle needed\n");
  7755. /* Disconnect this device */
  7756. netif_device_detach(bp->dev);
  7757. /* Shut down the power */
  7758. bnx2x_set_power_state(
  7759. bp, PCI_D3hot);
  7760. smp_mb();
  7761. } else {
  7762. bp->recovery_state =
  7763. BNX2X_RECOVERY_DONE;
  7764. error_recovered++;
  7765. smp_mb();
  7766. }
  7767. bp->eth_stats.recoverable_error =
  7768. error_recovered;
  7769. bp->eth_stats.unrecoverable_error =
  7770. error_unrecovered;
  7771. return;
  7772. }
  7773. }
  7774. default:
  7775. return;
  7776. }
  7777. }
  7778. }
  7779. static int bnx2x_close(struct net_device *dev);
  7780. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7781. * scheduled on a general queue in order to prevent a dead lock.
  7782. */
  7783. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7784. {
  7785. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7786. rtnl_lock();
  7787. if (!netif_running(bp->dev))
  7788. goto sp_rtnl_exit;
  7789. /* if stop on error is defined no recovery flows should be executed */
  7790. #ifdef BNX2X_STOP_ON_ERROR
  7791. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7792. "you will need to reboot when done\n");
  7793. goto sp_rtnl_not_reset;
  7794. #endif
  7795. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7796. /*
  7797. * Clear all pending SP commands as we are going to reset the
  7798. * function anyway.
  7799. */
  7800. bp->sp_rtnl_state = 0;
  7801. smp_mb();
  7802. bnx2x_parity_recover(bp);
  7803. goto sp_rtnl_exit;
  7804. }
  7805. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7806. /*
  7807. * Clear all pending SP commands as we are going to reset the
  7808. * function anyway.
  7809. */
  7810. bp->sp_rtnl_state = 0;
  7811. smp_mb();
  7812. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7813. bnx2x_nic_load(bp, LOAD_NORMAL);
  7814. goto sp_rtnl_exit;
  7815. }
  7816. #ifdef BNX2X_STOP_ON_ERROR
  7817. sp_rtnl_not_reset:
  7818. #endif
  7819. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7820. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7821. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7822. bnx2x_after_function_update(bp);
  7823. /*
  7824. * in case of fan failure we need to reset id if the "stop on error"
  7825. * debug flag is set, since we trying to prevent permanent overheating
  7826. * damage
  7827. */
  7828. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7829. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7830. netif_device_detach(bp->dev);
  7831. bnx2x_close(bp->dev);
  7832. }
  7833. sp_rtnl_exit:
  7834. rtnl_unlock();
  7835. }
  7836. /* end of nic load/unload */
  7837. static void bnx2x_period_task(struct work_struct *work)
  7838. {
  7839. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7840. if (!netif_running(bp->dev))
  7841. goto period_task_exit;
  7842. if (CHIP_REV_IS_SLOW(bp)) {
  7843. BNX2X_ERR("period task called on emulation, ignoring\n");
  7844. goto period_task_exit;
  7845. }
  7846. bnx2x_acquire_phy_lock(bp);
  7847. /*
  7848. * The barrier is needed to ensure the ordering between the writing to
  7849. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7850. * the reading here.
  7851. */
  7852. smp_mb();
  7853. if (bp->port.pmf) {
  7854. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7855. /* Re-queue task in 1 sec */
  7856. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7857. }
  7858. bnx2x_release_phy_lock(bp);
  7859. period_task_exit:
  7860. return;
  7861. }
  7862. /*
  7863. * Init service functions
  7864. */
  7865. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7866. {
  7867. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7868. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7869. return base + (BP_ABS_FUNC(bp)) * stride;
  7870. }
  7871. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7872. {
  7873. u32 reg = bnx2x_get_pretend_reg(bp);
  7874. /* Flush all outstanding writes */
  7875. mmiowb();
  7876. /* Pretend to be function 0 */
  7877. REG_WR(bp, reg, 0);
  7878. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7879. /* From now we are in the "like-E1" mode */
  7880. bnx2x_int_disable(bp);
  7881. /* Flush all outstanding writes */
  7882. mmiowb();
  7883. /* Restore the original function */
  7884. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7885. REG_RD(bp, reg);
  7886. }
  7887. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7888. {
  7889. if (CHIP_IS_E1(bp))
  7890. bnx2x_int_disable(bp);
  7891. else
  7892. bnx2x_undi_int_disable_e1h(bp);
  7893. }
  7894. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7895. {
  7896. u32 val, base_addr, offset, mask, reset_reg;
  7897. bool mac_stopped = false;
  7898. u8 port = BP_PORT(bp);
  7899. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7900. if (!CHIP_IS_E3(bp)) {
  7901. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7902. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7903. if ((mask & reset_reg) && val) {
  7904. u32 wb_data[2];
  7905. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7906. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7907. : NIG_REG_INGRESS_BMAC0_MEM;
  7908. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7909. : BIGMAC_REGISTER_BMAC_CONTROL;
  7910. /*
  7911. * use rd/wr since we cannot use dmae. This is safe
  7912. * since MCP won't access the bus due to the request
  7913. * to unload, and no function on the path can be
  7914. * loaded at this time.
  7915. */
  7916. wb_data[0] = REG_RD(bp, base_addr + offset);
  7917. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7918. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7919. REG_WR(bp, base_addr + offset, wb_data[0]);
  7920. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7921. }
  7922. BNX2X_DEV_INFO("Disable emac Rx\n");
  7923. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7924. mac_stopped = true;
  7925. } else {
  7926. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7927. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7928. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7929. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7930. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7931. val & ~(1 << 1));
  7932. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7933. val | (1 << 1));
  7934. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7935. mac_stopped = true;
  7936. }
  7937. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7938. if (mask & reset_reg) {
  7939. BNX2X_DEV_INFO("Disable umac Rx\n");
  7940. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7941. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7942. mac_stopped = true;
  7943. }
  7944. }
  7945. if (mac_stopped)
  7946. msleep(20);
  7947. }
  7948. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7949. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7950. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7951. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7952. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  7953. {
  7954. u16 rcq, bd;
  7955. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7956. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7957. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7958. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7959. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7960. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7961. port, bd, rcq);
  7962. }
  7963. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  7964. {
  7965. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  7966. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  7967. if (!rc) {
  7968. BNX2X_ERR("MCP response failure, aborting\n");
  7969. return -EBUSY;
  7970. }
  7971. return 0;
  7972. }
  7973. static struct bnx2x_prev_path_list *
  7974. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  7975. {
  7976. struct bnx2x_prev_path_list *tmp_list;
  7977. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  7978. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7979. bp->pdev->bus->number == tmp_list->bus &&
  7980. BP_PATH(bp) == tmp_list->path)
  7981. return tmp_list;
  7982. return NULL;
  7983. }
  7984. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7985. {
  7986. struct bnx2x_prev_path_list *tmp_list;
  7987. int rc = false;
  7988. if (down_trylock(&bnx2x_prev_sem))
  7989. return false;
  7990. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7991. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7992. bp->pdev->bus->number == tmp_list->bus &&
  7993. BP_PATH(bp) == tmp_list->path) {
  7994. rc = true;
  7995. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7996. BP_PATH(bp));
  7997. break;
  7998. }
  7999. }
  8000. up(&bnx2x_prev_sem);
  8001. return rc;
  8002. }
  8003. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8004. {
  8005. struct bnx2x_prev_path_list *tmp_list;
  8006. int rc;
  8007. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8008. if (!tmp_list) {
  8009. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8010. return -ENOMEM;
  8011. }
  8012. tmp_list->bus = bp->pdev->bus->number;
  8013. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8014. tmp_list->path = BP_PATH(bp);
  8015. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8016. rc = down_interruptible(&bnx2x_prev_sem);
  8017. if (rc) {
  8018. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8019. kfree(tmp_list);
  8020. } else {
  8021. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8022. BP_PATH(bp));
  8023. list_add(&tmp_list->list, &bnx2x_prev_list);
  8024. up(&bnx2x_prev_sem);
  8025. }
  8026. return rc;
  8027. }
  8028. static int bnx2x_do_flr(struct bnx2x *bp)
  8029. {
  8030. int i;
  8031. u16 status;
  8032. struct pci_dev *dev = bp->pdev;
  8033. if (CHIP_IS_E1x(bp)) {
  8034. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8035. return -EINVAL;
  8036. }
  8037. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8038. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8039. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8040. bp->common.bc_ver);
  8041. return -EINVAL;
  8042. }
  8043. /* Wait for Transaction Pending bit clean */
  8044. for (i = 0; i < 4; i++) {
  8045. if (i)
  8046. msleep((1 << (i - 1)) * 100);
  8047. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8048. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8049. goto clear;
  8050. }
  8051. dev_err(&dev->dev,
  8052. "transaction is not cleared; proceeding with reset anyway\n");
  8053. clear:
  8054. BNX2X_DEV_INFO("Initiating FLR\n");
  8055. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8056. return 0;
  8057. }
  8058. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8059. {
  8060. int rc;
  8061. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8062. /* Test if previous unload process was already finished for this path */
  8063. if (bnx2x_prev_is_path_marked(bp))
  8064. return bnx2x_prev_mcp_done(bp);
  8065. /* If function has FLR capabilities, and existing FW version matches
  8066. * the one required, then FLR will be sufficient to clean any residue
  8067. * left by previous driver
  8068. */
  8069. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8070. if (!rc) {
  8071. /* fw version is good */
  8072. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8073. rc = bnx2x_do_flr(bp);
  8074. }
  8075. if (!rc) {
  8076. /* FLR was performed */
  8077. BNX2X_DEV_INFO("FLR successful\n");
  8078. return 0;
  8079. }
  8080. BNX2X_DEV_INFO("Could not FLR\n");
  8081. /* Close the MCP request, return failure*/
  8082. rc = bnx2x_prev_mcp_done(bp);
  8083. if (!rc)
  8084. rc = BNX2X_PREV_WAIT_NEEDED;
  8085. return rc;
  8086. }
  8087. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8088. {
  8089. u32 reset_reg, tmp_reg = 0, rc;
  8090. bool prev_undi = false;
  8091. /* It is possible a previous function received 'common' answer,
  8092. * but hasn't loaded yet, therefore creating a scenario of
  8093. * multiple functions receiving 'common' on the same path.
  8094. */
  8095. BNX2X_DEV_INFO("Common unload Flow\n");
  8096. if (bnx2x_prev_is_path_marked(bp))
  8097. return bnx2x_prev_mcp_done(bp);
  8098. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8099. /* Reset should be performed after BRB is emptied */
  8100. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8101. u32 timer_count = 1000;
  8102. /* Close the MAC Rx to prevent BRB from filling up */
  8103. bnx2x_prev_unload_close_mac(bp);
  8104. /* Check if the UNDI driver was previously loaded
  8105. * UNDI driver initializes CID offset for normal bell to 0x7
  8106. */
  8107. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8108. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8109. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8110. if (tmp_reg == 0x7) {
  8111. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8112. prev_undi = true;
  8113. /* clear the UNDI indication */
  8114. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8115. }
  8116. }
  8117. /* wait until BRB is empty */
  8118. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8119. while (timer_count) {
  8120. u32 prev_brb = tmp_reg;
  8121. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8122. if (!tmp_reg)
  8123. break;
  8124. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8125. /* reset timer as long as BRB actually gets emptied */
  8126. if (prev_brb > tmp_reg)
  8127. timer_count = 1000;
  8128. else
  8129. timer_count--;
  8130. /* If UNDI resides in memory, manually increment it */
  8131. if (prev_undi)
  8132. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8133. udelay(10);
  8134. }
  8135. if (!timer_count)
  8136. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8137. }
  8138. /* No packets are in the pipeline, path is ready for reset */
  8139. bnx2x_reset_common(bp);
  8140. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8141. if (rc) {
  8142. bnx2x_prev_mcp_done(bp);
  8143. return rc;
  8144. }
  8145. return bnx2x_prev_mcp_done(bp);
  8146. }
  8147. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8148. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8149. * the addresses of the transaction, resulting in was-error bit set in the pci
  8150. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8151. * to clear the interrupt which detected this from the pglueb and the was done
  8152. * bit
  8153. */
  8154. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8155. {
  8156. if (!CHIP_IS_E1x(bp)) {
  8157. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8158. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8159. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8160. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8161. 1 << BP_FUNC(bp));
  8162. }
  8163. }
  8164. }
  8165. static int bnx2x_prev_unload(struct bnx2x *bp)
  8166. {
  8167. int time_counter = 10;
  8168. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8169. struct bnx2x_prev_path_list *prev_list;
  8170. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8171. /* clear hw from errors which may have resulted from an interrupted
  8172. * dmae transaction.
  8173. */
  8174. bnx2x_prev_interrupted_dmae(bp);
  8175. /* Release previously held locks */
  8176. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8177. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8178. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8179. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8180. if (hw_lock_val) {
  8181. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8182. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8183. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8184. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8185. }
  8186. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8187. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8188. } else
  8189. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8190. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8191. BNX2X_DEV_INFO("Release previously held alr\n");
  8192. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8193. }
  8194. do {
  8195. /* Lock MCP using an unload request */
  8196. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8197. if (!fw) {
  8198. BNX2X_ERR("MCP response failure, aborting\n");
  8199. rc = -EBUSY;
  8200. break;
  8201. }
  8202. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8203. rc = bnx2x_prev_unload_common(bp);
  8204. break;
  8205. }
  8206. /* non-common reply from MCP night require looping */
  8207. rc = bnx2x_prev_unload_uncommon(bp);
  8208. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8209. break;
  8210. msleep(20);
  8211. } while (--time_counter);
  8212. if (!time_counter || rc) {
  8213. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8214. rc = -EBUSY;
  8215. }
  8216. /* Mark function if its port was used to boot from SAN */
  8217. prev_list = bnx2x_prev_path_get_entry(bp);
  8218. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8219. bp->link_params.feature_config_flags |=
  8220. FEATURE_CONFIG_BOOT_FROM_SAN;
  8221. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8222. return rc;
  8223. }
  8224. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8225. {
  8226. u32 val, val2, val3, val4, id, boot_mode;
  8227. u16 pmc;
  8228. /* Get the chip revision id and number. */
  8229. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8230. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8231. id = ((val & 0xffff) << 16);
  8232. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8233. id |= ((val & 0xf) << 12);
  8234. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8235. id |= ((val & 0xff) << 4);
  8236. val = REG_RD(bp, MISC_REG_BOND_ID);
  8237. id |= (val & 0xf);
  8238. bp->common.chip_id = id;
  8239. /* force 57811 according to MISC register */
  8240. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8241. if (CHIP_IS_57810(bp))
  8242. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8243. (bp->common.chip_id & 0x0000FFFF);
  8244. else if (CHIP_IS_57810_MF(bp))
  8245. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8246. (bp->common.chip_id & 0x0000FFFF);
  8247. bp->common.chip_id |= 0x1;
  8248. }
  8249. /* Set doorbell size */
  8250. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8251. if (!CHIP_IS_E1x(bp)) {
  8252. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8253. if ((val & 1) == 0)
  8254. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8255. else
  8256. val = (val >> 1) & 1;
  8257. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8258. "2_PORT_MODE");
  8259. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8260. CHIP_2_PORT_MODE;
  8261. if (CHIP_MODE_IS_4_PORT(bp))
  8262. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8263. else
  8264. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8265. } else {
  8266. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8267. bp->pfid = bp->pf_num; /* 0..7 */
  8268. }
  8269. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8270. bp->link_params.chip_id = bp->common.chip_id;
  8271. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8272. val = (REG_RD(bp, 0x2874) & 0x55);
  8273. if ((bp->common.chip_id & 0x1) ||
  8274. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8275. bp->flags |= ONE_PORT_FLAG;
  8276. BNX2X_DEV_INFO("single port device\n");
  8277. }
  8278. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8279. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8280. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8281. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8282. bp->common.flash_size, bp->common.flash_size);
  8283. bnx2x_init_shmem(bp);
  8284. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8285. MISC_REG_GENERIC_CR_1 :
  8286. MISC_REG_GENERIC_CR_0));
  8287. bp->link_params.shmem_base = bp->common.shmem_base;
  8288. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8289. if (SHMEM2_RD(bp, size) >
  8290. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8291. bp->link_params.lfa_base =
  8292. REG_RD(bp, bp->common.shmem2_base +
  8293. (u32)offsetof(struct shmem2_region,
  8294. lfa_host_addr[BP_PORT(bp)]));
  8295. else
  8296. bp->link_params.lfa_base = 0;
  8297. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8298. bp->common.shmem_base, bp->common.shmem2_base);
  8299. if (!bp->common.shmem_base) {
  8300. BNX2X_DEV_INFO("MCP not active\n");
  8301. bp->flags |= NO_MCP_FLAG;
  8302. return;
  8303. }
  8304. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8305. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8306. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8307. SHARED_HW_CFG_LED_MODE_MASK) >>
  8308. SHARED_HW_CFG_LED_MODE_SHIFT);
  8309. bp->link_params.feature_config_flags = 0;
  8310. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8311. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8312. bp->link_params.feature_config_flags |=
  8313. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8314. else
  8315. bp->link_params.feature_config_flags &=
  8316. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8317. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8318. bp->common.bc_ver = val;
  8319. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8320. if (val < BNX2X_BC_VER) {
  8321. /* for now only warn
  8322. * later we might need to enforce this */
  8323. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8324. BNX2X_BC_VER, val);
  8325. }
  8326. bp->link_params.feature_config_flags |=
  8327. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8328. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8329. bp->link_params.feature_config_flags |=
  8330. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8331. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8332. bp->link_params.feature_config_flags |=
  8333. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8334. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8335. bp->link_params.feature_config_flags |=
  8336. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8337. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8338. bp->link_params.feature_config_flags |=
  8339. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8340. FEATURE_CONFIG_MT_SUPPORT : 0;
  8341. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8342. BC_SUPPORTS_PFC_STATS : 0;
  8343. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8344. BC_SUPPORTS_FCOE_FEATURES : 0;
  8345. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8346. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8347. boot_mode = SHMEM_RD(bp,
  8348. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8349. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8350. switch (boot_mode) {
  8351. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8352. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8353. break;
  8354. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8355. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8356. break;
  8357. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8358. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8359. break;
  8360. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8361. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8362. break;
  8363. }
  8364. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8365. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8366. BNX2X_DEV_INFO("%sWoL capable\n",
  8367. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8368. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8369. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8370. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8371. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8372. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8373. val, val2, val3, val4);
  8374. }
  8375. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8376. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8377. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8378. {
  8379. int pfid = BP_FUNC(bp);
  8380. int igu_sb_id;
  8381. u32 val;
  8382. u8 fid, igu_sb_cnt = 0;
  8383. bp->igu_base_sb = 0xff;
  8384. if (CHIP_INT_MODE_IS_BC(bp)) {
  8385. int vn = BP_VN(bp);
  8386. igu_sb_cnt = bp->igu_sb_cnt;
  8387. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8388. FP_SB_MAX_E1x;
  8389. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8390. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8391. return 0;
  8392. }
  8393. /* IGU in normal mode - read CAM */
  8394. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8395. igu_sb_id++) {
  8396. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8397. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8398. continue;
  8399. fid = IGU_FID(val);
  8400. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8401. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8402. continue;
  8403. if (IGU_VEC(val) == 0)
  8404. /* default status block */
  8405. bp->igu_dsb_id = igu_sb_id;
  8406. else {
  8407. if (bp->igu_base_sb == 0xff)
  8408. bp->igu_base_sb = igu_sb_id;
  8409. igu_sb_cnt++;
  8410. }
  8411. }
  8412. }
  8413. #ifdef CONFIG_PCI_MSI
  8414. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8415. * optional that number of CAM entries will not be equal to the value
  8416. * advertised in PCI.
  8417. * Driver should use the minimal value of both as the actual status
  8418. * block count
  8419. */
  8420. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8421. #endif
  8422. if (igu_sb_cnt == 0) {
  8423. BNX2X_ERR("CAM configuration error\n");
  8424. return -EINVAL;
  8425. }
  8426. return 0;
  8427. }
  8428. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8429. {
  8430. int cfg_size = 0, idx, port = BP_PORT(bp);
  8431. /* Aggregation of supported attributes of all external phys */
  8432. bp->port.supported[0] = 0;
  8433. bp->port.supported[1] = 0;
  8434. switch (bp->link_params.num_phys) {
  8435. case 1:
  8436. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8437. cfg_size = 1;
  8438. break;
  8439. case 2:
  8440. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8441. cfg_size = 1;
  8442. break;
  8443. case 3:
  8444. if (bp->link_params.multi_phy_config &
  8445. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8446. bp->port.supported[1] =
  8447. bp->link_params.phy[EXT_PHY1].supported;
  8448. bp->port.supported[0] =
  8449. bp->link_params.phy[EXT_PHY2].supported;
  8450. } else {
  8451. bp->port.supported[0] =
  8452. bp->link_params.phy[EXT_PHY1].supported;
  8453. bp->port.supported[1] =
  8454. bp->link_params.phy[EXT_PHY2].supported;
  8455. }
  8456. cfg_size = 2;
  8457. break;
  8458. }
  8459. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8460. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8461. SHMEM_RD(bp,
  8462. dev_info.port_hw_config[port].external_phy_config),
  8463. SHMEM_RD(bp,
  8464. dev_info.port_hw_config[port].external_phy_config2));
  8465. return;
  8466. }
  8467. if (CHIP_IS_E3(bp))
  8468. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8469. else {
  8470. switch (switch_cfg) {
  8471. case SWITCH_CFG_1G:
  8472. bp->port.phy_addr = REG_RD(
  8473. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8474. break;
  8475. case SWITCH_CFG_10G:
  8476. bp->port.phy_addr = REG_RD(
  8477. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8478. break;
  8479. default:
  8480. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8481. bp->port.link_config[0]);
  8482. return;
  8483. }
  8484. }
  8485. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8486. /* mask what we support according to speed_cap_mask per configuration */
  8487. for (idx = 0; idx < cfg_size; idx++) {
  8488. if (!(bp->link_params.speed_cap_mask[idx] &
  8489. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8490. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8491. if (!(bp->link_params.speed_cap_mask[idx] &
  8492. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8493. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8494. if (!(bp->link_params.speed_cap_mask[idx] &
  8495. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8496. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8497. if (!(bp->link_params.speed_cap_mask[idx] &
  8498. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8499. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8500. if (!(bp->link_params.speed_cap_mask[idx] &
  8501. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8502. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8503. SUPPORTED_1000baseT_Full);
  8504. if (!(bp->link_params.speed_cap_mask[idx] &
  8505. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8506. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8507. if (!(bp->link_params.speed_cap_mask[idx] &
  8508. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8509. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8510. }
  8511. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8512. bp->port.supported[1]);
  8513. }
  8514. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8515. {
  8516. u32 link_config, idx, cfg_size = 0;
  8517. bp->port.advertising[0] = 0;
  8518. bp->port.advertising[1] = 0;
  8519. switch (bp->link_params.num_phys) {
  8520. case 1:
  8521. case 2:
  8522. cfg_size = 1;
  8523. break;
  8524. case 3:
  8525. cfg_size = 2;
  8526. break;
  8527. }
  8528. for (idx = 0; idx < cfg_size; idx++) {
  8529. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8530. link_config = bp->port.link_config[idx];
  8531. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8532. case PORT_FEATURE_LINK_SPEED_AUTO:
  8533. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8534. bp->link_params.req_line_speed[idx] =
  8535. SPEED_AUTO_NEG;
  8536. bp->port.advertising[idx] |=
  8537. bp->port.supported[idx];
  8538. if (bp->link_params.phy[EXT_PHY1].type ==
  8539. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8540. bp->port.advertising[idx] |=
  8541. (SUPPORTED_100baseT_Half |
  8542. SUPPORTED_100baseT_Full);
  8543. } else {
  8544. /* force 10G, no AN */
  8545. bp->link_params.req_line_speed[idx] =
  8546. SPEED_10000;
  8547. bp->port.advertising[idx] |=
  8548. (ADVERTISED_10000baseT_Full |
  8549. ADVERTISED_FIBRE);
  8550. continue;
  8551. }
  8552. break;
  8553. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8554. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8555. bp->link_params.req_line_speed[idx] =
  8556. SPEED_10;
  8557. bp->port.advertising[idx] |=
  8558. (ADVERTISED_10baseT_Full |
  8559. ADVERTISED_TP);
  8560. } else {
  8561. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8562. link_config,
  8563. bp->link_params.speed_cap_mask[idx]);
  8564. return;
  8565. }
  8566. break;
  8567. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8568. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8569. bp->link_params.req_line_speed[idx] =
  8570. SPEED_10;
  8571. bp->link_params.req_duplex[idx] =
  8572. DUPLEX_HALF;
  8573. bp->port.advertising[idx] |=
  8574. (ADVERTISED_10baseT_Half |
  8575. ADVERTISED_TP);
  8576. } else {
  8577. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8578. link_config,
  8579. bp->link_params.speed_cap_mask[idx]);
  8580. return;
  8581. }
  8582. break;
  8583. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8584. if (bp->port.supported[idx] &
  8585. SUPPORTED_100baseT_Full) {
  8586. bp->link_params.req_line_speed[idx] =
  8587. SPEED_100;
  8588. bp->port.advertising[idx] |=
  8589. (ADVERTISED_100baseT_Full |
  8590. ADVERTISED_TP);
  8591. } else {
  8592. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8593. link_config,
  8594. bp->link_params.speed_cap_mask[idx]);
  8595. return;
  8596. }
  8597. break;
  8598. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8599. if (bp->port.supported[idx] &
  8600. SUPPORTED_100baseT_Half) {
  8601. bp->link_params.req_line_speed[idx] =
  8602. SPEED_100;
  8603. bp->link_params.req_duplex[idx] =
  8604. DUPLEX_HALF;
  8605. bp->port.advertising[idx] |=
  8606. (ADVERTISED_100baseT_Half |
  8607. ADVERTISED_TP);
  8608. } else {
  8609. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8610. link_config,
  8611. bp->link_params.speed_cap_mask[idx]);
  8612. return;
  8613. }
  8614. break;
  8615. case PORT_FEATURE_LINK_SPEED_1G:
  8616. if (bp->port.supported[idx] &
  8617. SUPPORTED_1000baseT_Full) {
  8618. bp->link_params.req_line_speed[idx] =
  8619. SPEED_1000;
  8620. bp->port.advertising[idx] |=
  8621. (ADVERTISED_1000baseT_Full |
  8622. ADVERTISED_TP);
  8623. } else {
  8624. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8625. link_config,
  8626. bp->link_params.speed_cap_mask[idx]);
  8627. return;
  8628. }
  8629. break;
  8630. case PORT_FEATURE_LINK_SPEED_2_5G:
  8631. if (bp->port.supported[idx] &
  8632. SUPPORTED_2500baseX_Full) {
  8633. bp->link_params.req_line_speed[idx] =
  8634. SPEED_2500;
  8635. bp->port.advertising[idx] |=
  8636. (ADVERTISED_2500baseX_Full |
  8637. ADVERTISED_TP);
  8638. } else {
  8639. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8640. link_config,
  8641. bp->link_params.speed_cap_mask[idx]);
  8642. return;
  8643. }
  8644. break;
  8645. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8646. if (bp->port.supported[idx] &
  8647. SUPPORTED_10000baseT_Full) {
  8648. bp->link_params.req_line_speed[idx] =
  8649. SPEED_10000;
  8650. bp->port.advertising[idx] |=
  8651. (ADVERTISED_10000baseT_Full |
  8652. ADVERTISED_FIBRE);
  8653. } else {
  8654. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8655. link_config,
  8656. bp->link_params.speed_cap_mask[idx]);
  8657. return;
  8658. }
  8659. break;
  8660. case PORT_FEATURE_LINK_SPEED_20G:
  8661. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8662. break;
  8663. default:
  8664. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8665. link_config);
  8666. bp->link_params.req_line_speed[idx] =
  8667. SPEED_AUTO_NEG;
  8668. bp->port.advertising[idx] =
  8669. bp->port.supported[idx];
  8670. break;
  8671. }
  8672. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8673. PORT_FEATURE_FLOW_CONTROL_MASK);
  8674. if (bp->link_params.req_flow_ctrl[idx] ==
  8675. BNX2X_FLOW_CTRL_AUTO) {
  8676. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8677. bp->link_params.req_flow_ctrl[idx] =
  8678. BNX2X_FLOW_CTRL_NONE;
  8679. else
  8680. bnx2x_set_requested_fc(bp);
  8681. }
  8682. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8683. bp->link_params.req_line_speed[idx],
  8684. bp->link_params.req_duplex[idx],
  8685. bp->link_params.req_flow_ctrl[idx],
  8686. bp->port.advertising[idx]);
  8687. }
  8688. }
  8689. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8690. {
  8691. mac_hi = cpu_to_be16(mac_hi);
  8692. mac_lo = cpu_to_be32(mac_lo);
  8693. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8694. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8695. }
  8696. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8697. {
  8698. int port = BP_PORT(bp);
  8699. u32 config;
  8700. u32 ext_phy_type, ext_phy_config, eee_mode;
  8701. bp->link_params.bp = bp;
  8702. bp->link_params.port = port;
  8703. bp->link_params.lane_config =
  8704. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8705. bp->link_params.speed_cap_mask[0] =
  8706. SHMEM_RD(bp,
  8707. dev_info.port_hw_config[port].speed_capability_mask);
  8708. bp->link_params.speed_cap_mask[1] =
  8709. SHMEM_RD(bp,
  8710. dev_info.port_hw_config[port].speed_capability_mask2);
  8711. bp->port.link_config[0] =
  8712. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8713. bp->port.link_config[1] =
  8714. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8715. bp->link_params.multi_phy_config =
  8716. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8717. /* If the device is capable of WoL, set the default state according
  8718. * to the HW
  8719. */
  8720. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8721. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8722. (config & PORT_FEATURE_WOL_ENABLED));
  8723. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8724. bp->link_params.lane_config,
  8725. bp->link_params.speed_cap_mask[0],
  8726. bp->port.link_config[0]);
  8727. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8728. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8729. bnx2x_phy_probe(&bp->link_params);
  8730. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8731. bnx2x_link_settings_requested(bp);
  8732. /*
  8733. * If connected directly, work with the internal PHY, otherwise, work
  8734. * with the external PHY
  8735. */
  8736. ext_phy_config =
  8737. SHMEM_RD(bp,
  8738. dev_info.port_hw_config[port].external_phy_config);
  8739. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8740. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8741. bp->mdio.prtad = bp->port.phy_addr;
  8742. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8743. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8744. bp->mdio.prtad =
  8745. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8746. /* Configure link feature according to nvram value */
  8747. eee_mode = (((SHMEM_RD(bp, dev_info.
  8748. port_feature_config[port].eee_power_mode)) &
  8749. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8750. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8751. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8752. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8753. EEE_MODE_ENABLE_LPI |
  8754. EEE_MODE_OUTPUT_TIME;
  8755. } else {
  8756. bp->link_params.eee_mode = 0;
  8757. }
  8758. }
  8759. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8760. {
  8761. u32 no_flags = NO_ISCSI_FLAG;
  8762. int port = BP_PORT(bp);
  8763. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8764. drv_lic_key[port].max_iscsi_conn);
  8765. if (!CNIC_SUPPORT(bp)) {
  8766. bp->flags |= no_flags;
  8767. return;
  8768. }
  8769. /* Get the number of maximum allowed iSCSI connections */
  8770. bp->cnic_eth_dev.max_iscsi_conn =
  8771. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8772. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8773. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8774. bp->cnic_eth_dev.max_iscsi_conn);
  8775. /*
  8776. * If maximum allowed number of connections is zero -
  8777. * disable the feature.
  8778. */
  8779. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8780. bp->flags |= no_flags;
  8781. }
  8782. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8783. {
  8784. /* Port info */
  8785. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8786. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8787. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8788. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8789. /* Node info */
  8790. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8791. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8792. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8793. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8794. }
  8795. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8796. {
  8797. int port = BP_PORT(bp);
  8798. int func = BP_ABS_FUNC(bp);
  8799. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8800. drv_lic_key[port].max_fcoe_conn);
  8801. if (!CNIC_SUPPORT(bp)) {
  8802. bp->flags |= NO_FCOE_FLAG;
  8803. return;
  8804. }
  8805. /* Get the number of maximum allowed FCoE connections */
  8806. bp->cnic_eth_dev.max_fcoe_conn =
  8807. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8808. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8809. /* Read the WWN: */
  8810. if (!IS_MF(bp)) {
  8811. /* Port info */
  8812. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8813. SHMEM_RD(bp,
  8814. dev_info.port_hw_config[port].
  8815. fcoe_wwn_port_name_upper);
  8816. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8817. SHMEM_RD(bp,
  8818. dev_info.port_hw_config[port].
  8819. fcoe_wwn_port_name_lower);
  8820. /* Node info */
  8821. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8822. SHMEM_RD(bp,
  8823. dev_info.port_hw_config[port].
  8824. fcoe_wwn_node_name_upper);
  8825. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8826. SHMEM_RD(bp,
  8827. dev_info.port_hw_config[port].
  8828. fcoe_wwn_node_name_lower);
  8829. } else if (!IS_MF_SD(bp)) {
  8830. /*
  8831. * Read the WWN info only if the FCoE feature is enabled for
  8832. * this function.
  8833. */
  8834. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8835. bnx2x_get_ext_wwn_info(bp, func);
  8836. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8837. bnx2x_get_ext_wwn_info(bp, func);
  8838. }
  8839. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8840. /*
  8841. * If maximum allowed number of connections is zero -
  8842. * disable the feature.
  8843. */
  8844. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8845. bp->flags |= NO_FCOE_FLAG;
  8846. }
  8847. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8848. {
  8849. /*
  8850. * iSCSI may be dynamically disabled but reading
  8851. * info here we will decrease memory usage by driver
  8852. * if the feature is disabled for good
  8853. */
  8854. bnx2x_get_iscsi_info(bp);
  8855. bnx2x_get_fcoe_info(bp);
  8856. }
  8857. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8858. {
  8859. u32 val, val2;
  8860. int func = BP_ABS_FUNC(bp);
  8861. int port = BP_PORT(bp);
  8862. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8863. u8 *fip_mac = bp->fip_mac;
  8864. if (IS_MF(bp)) {
  8865. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8866. * FCoE MAC then the appropriate feature should be disabled.
  8867. * In non SD mode features configuration comes from struct
  8868. * func_ext_config.
  8869. */
  8870. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8871. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8872. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8873. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8874. iscsi_mac_addr_upper);
  8875. val = MF_CFG_RD(bp, func_ext_config[func].
  8876. iscsi_mac_addr_lower);
  8877. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8878. BNX2X_DEV_INFO
  8879. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8880. } else {
  8881. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8882. }
  8883. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8884. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8885. fcoe_mac_addr_upper);
  8886. val = MF_CFG_RD(bp, func_ext_config[func].
  8887. fcoe_mac_addr_lower);
  8888. bnx2x_set_mac_buf(fip_mac, val, val2);
  8889. BNX2X_DEV_INFO
  8890. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  8891. } else {
  8892. bp->flags |= NO_FCOE_FLAG;
  8893. }
  8894. bp->mf_ext_config = cfg;
  8895. } else { /* SD MODE */
  8896. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8897. /* use primary mac as iscsi mac */
  8898. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  8899. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8900. BNX2X_DEV_INFO
  8901. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8902. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  8903. /* use primary mac as fip mac */
  8904. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  8905. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8906. BNX2X_DEV_INFO
  8907. ("Read FIP MAC: %pM\n", fip_mac);
  8908. }
  8909. }
  8910. if (IS_MF_STORAGE_SD(bp))
  8911. /* Zero primary MAC configuration */
  8912. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8913. if (IS_MF_FCOE_AFEX(bp))
  8914. /* use FIP MAC as primary MAC */
  8915. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8916. } else {
  8917. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8918. iscsi_mac_upper);
  8919. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8920. iscsi_mac_lower);
  8921. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8922. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8923. fcoe_fip_mac_upper);
  8924. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8925. fcoe_fip_mac_lower);
  8926. bnx2x_set_mac_buf(fip_mac, val, val2);
  8927. }
  8928. /* Disable iSCSI OOO if MAC configuration is invalid. */
  8929. if (!is_valid_ether_addr(iscsi_mac)) {
  8930. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8931. memset(iscsi_mac, 0, ETH_ALEN);
  8932. }
  8933. /* Disable FCoE if MAC configuration is invalid. */
  8934. if (!is_valid_ether_addr(fip_mac)) {
  8935. bp->flags |= NO_FCOE_FLAG;
  8936. memset(bp->fip_mac, 0, ETH_ALEN);
  8937. }
  8938. }
  8939. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8940. {
  8941. u32 val, val2;
  8942. int func = BP_ABS_FUNC(bp);
  8943. int port = BP_PORT(bp);
  8944. /* Zero primary MAC configuration */
  8945. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8946. if (BP_NOMCP(bp)) {
  8947. BNX2X_ERROR("warning: random MAC workaround active\n");
  8948. eth_hw_addr_random(bp->dev);
  8949. } else if (IS_MF(bp)) {
  8950. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8951. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8952. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8953. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8954. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8955. if (CNIC_SUPPORT(bp))
  8956. bnx2x_get_cnic_mac_hwinfo(bp);
  8957. } else {
  8958. /* in SF read MACs from port configuration */
  8959. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8960. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8961. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8962. if (CNIC_SUPPORT(bp))
  8963. bnx2x_get_cnic_mac_hwinfo(bp);
  8964. }
  8965. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8966. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8967. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8968. dev_err(&bp->pdev->dev,
  8969. "bad Ethernet MAC address configuration: %pM\n"
  8970. "change it manually before bringing up the appropriate network interface\n",
  8971. bp->dev->dev_addr);
  8972. }
  8973. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  8974. {
  8975. int tmp;
  8976. u32 cfg;
  8977. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  8978. /* Take function: tmp = func */
  8979. tmp = BP_ABS_FUNC(bp);
  8980. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  8981. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  8982. } else {
  8983. /* Take port: tmp = port */
  8984. tmp = BP_PORT(bp);
  8985. cfg = SHMEM_RD(bp,
  8986. dev_info.port_hw_config[tmp].generic_features);
  8987. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  8988. }
  8989. return cfg;
  8990. }
  8991. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  8992. {
  8993. int /*abs*/func = BP_ABS_FUNC(bp);
  8994. int vn;
  8995. u32 val = 0;
  8996. int rc = 0;
  8997. bnx2x_get_common_hwinfo(bp);
  8998. /*
  8999. * initialize IGU parameters
  9000. */
  9001. if (CHIP_IS_E1x(bp)) {
  9002. bp->common.int_block = INT_BLOCK_HC;
  9003. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9004. bp->igu_base_sb = 0;
  9005. } else {
  9006. bp->common.int_block = INT_BLOCK_IGU;
  9007. /* do not allow device reset during IGU info preocessing */
  9008. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9009. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9010. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9011. int tout = 5000;
  9012. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9013. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9014. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9015. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9016. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9017. tout--;
  9018. usleep_range(1000, 1000);
  9019. }
  9020. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9021. dev_err(&bp->pdev->dev,
  9022. "FORCING Normal Mode failed!!!\n");
  9023. bnx2x_release_hw_lock(bp,
  9024. HW_LOCK_RESOURCE_RESET);
  9025. return -EPERM;
  9026. }
  9027. }
  9028. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9029. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9030. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9031. } else
  9032. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9033. rc = bnx2x_get_igu_cam_info(bp);
  9034. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9035. if (rc)
  9036. return rc;
  9037. }
  9038. /*
  9039. * set base FW non-default (fast path) status block id, this value is
  9040. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9041. * determine the id used by the FW.
  9042. */
  9043. if (CHIP_IS_E1x(bp))
  9044. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9045. else /*
  9046. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9047. * the same queue are indicated on the same IGU SB). So we prefer
  9048. * FW and IGU SBs to be the same value.
  9049. */
  9050. bp->base_fw_ndsb = bp->igu_base_sb;
  9051. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9052. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9053. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9054. /*
  9055. * Initialize MF configuration
  9056. */
  9057. bp->mf_ov = 0;
  9058. bp->mf_mode = 0;
  9059. vn = BP_VN(bp);
  9060. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9061. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9062. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9063. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9064. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9065. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9066. else
  9067. bp->common.mf_cfg_base = bp->common.shmem_base +
  9068. offsetof(struct shmem_region, func_mb) +
  9069. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9070. /*
  9071. * get mf configuration:
  9072. * 1. existence of MF configuration
  9073. * 2. MAC address must be legal (check only upper bytes)
  9074. * for Switch-Independent mode;
  9075. * OVLAN must be legal for Switch-Dependent mode
  9076. * 3. SF_MODE configures specific MF mode
  9077. */
  9078. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9079. /* get mf configuration */
  9080. val = SHMEM_RD(bp,
  9081. dev_info.shared_feature_config.config);
  9082. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9083. switch (val) {
  9084. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9085. val = MF_CFG_RD(bp, func_mf_config[func].
  9086. mac_upper);
  9087. /* check for legal mac (upper bytes)*/
  9088. if (val != 0xffff) {
  9089. bp->mf_mode = MULTI_FUNCTION_SI;
  9090. bp->mf_config[vn] = MF_CFG_RD(bp,
  9091. func_mf_config[func].config);
  9092. } else
  9093. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9094. break;
  9095. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9096. if ((!CHIP_IS_E1x(bp)) &&
  9097. (MF_CFG_RD(bp, func_mf_config[func].
  9098. mac_upper) != 0xffff) &&
  9099. (SHMEM2_HAS(bp,
  9100. afex_driver_support))) {
  9101. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9102. bp->mf_config[vn] = MF_CFG_RD(bp,
  9103. func_mf_config[func].config);
  9104. } else {
  9105. BNX2X_DEV_INFO("can not configure afex mode\n");
  9106. }
  9107. break;
  9108. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9109. /* get OV configuration */
  9110. val = MF_CFG_RD(bp,
  9111. func_mf_config[FUNC_0].e1hov_tag);
  9112. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9113. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9114. bp->mf_mode = MULTI_FUNCTION_SD;
  9115. bp->mf_config[vn] = MF_CFG_RD(bp,
  9116. func_mf_config[func].config);
  9117. } else
  9118. BNX2X_DEV_INFO("illegal OV for SD\n");
  9119. break;
  9120. default:
  9121. /* Unknown configuration: reset mf_config */
  9122. bp->mf_config[vn] = 0;
  9123. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9124. }
  9125. }
  9126. BNX2X_DEV_INFO("%s function mode\n",
  9127. IS_MF(bp) ? "multi" : "single");
  9128. switch (bp->mf_mode) {
  9129. case MULTI_FUNCTION_SD:
  9130. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9131. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9132. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9133. bp->mf_ov = val;
  9134. bp->path_has_ovlan = true;
  9135. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9136. func, bp->mf_ov, bp->mf_ov);
  9137. } else {
  9138. dev_err(&bp->pdev->dev,
  9139. "No valid MF OV for func %d, aborting\n",
  9140. func);
  9141. return -EPERM;
  9142. }
  9143. break;
  9144. case MULTI_FUNCTION_AFEX:
  9145. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9146. break;
  9147. case MULTI_FUNCTION_SI:
  9148. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9149. func);
  9150. break;
  9151. default:
  9152. if (vn) {
  9153. dev_err(&bp->pdev->dev,
  9154. "VN %d is in a single function mode, aborting\n",
  9155. vn);
  9156. return -EPERM;
  9157. }
  9158. break;
  9159. }
  9160. /* check if other port on the path needs ovlan:
  9161. * Since MF configuration is shared between ports
  9162. * Possible mixed modes are only
  9163. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9164. */
  9165. if (CHIP_MODE_IS_4_PORT(bp) &&
  9166. !bp->path_has_ovlan &&
  9167. !IS_MF(bp) &&
  9168. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9169. u8 other_port = !BP_PORT(bp);
  9170. u8 other_func = BP_PATH(bp) + 2*other_port;
  9171. val = MF_CFG_RD(bp,
  9172. func_mf_config[other_func].e1hov_tag);
  9173. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9174. bp->path_has_ovlan = true;
  9175. }
  9176. }
  9177. /* adjust igu_sb_cnt to MF for E1x */
  9178. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9179. bp->igu_sb_cnt /= E1HVN_MAX;
  9180. /* port info */
  9181. bnx2x_get_port_hwinfo(bp);
  9182. /* Get MAC addresses */
  9183. bnx2x_get_mac_hwinfo(bp);
  9184. bnx2x_get_cnic_info(bp);
  9185. return rc;
  9186. }
  9187. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9188. {
  9189. int cnt, i, block_end, rodi;
  9190. char vpd_start[BNX2X_VPD_LEN+1];
  9191. char str_id_reg[VENDOR_ID_LEN+1];
  9192. char str_id_cap[VENDOR_ID_LEN+1];
  9193. char *vpd_data;
  9194. char *vpd_extended_data = NULL;
  9195. u8 len;
  9196. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9197. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9198. if (cnt < BNX2X_VPD_LEN)
  9199. goto out_not_found;
  9200. /* VPD RO tag should be first tag after identifier string, hence
  9201. * we should be able to find it in first BNX2X_VPD_LEN chars
  9202. */
  9203. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9204. PCI_VPD_LRDT_RO_DATA);
  9205. if (i < 0)
  9206. goto out_not_found;
  9207. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9208. pci_vpd_lrdt_size(&vpd_start[i]);
  9209. i += PCI_VPD_LRDT_TAG_SIZE;
  9210. if (block_end > BNX2X_VPD_LEN) {
  9211. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9212. if (vpd_extended_data == NULL)
  9213. goto out_not_found;
  9214. /* read rest of vpd image into vpd_extended_data */
  9215. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9216. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9217. block_end - BNX2X_VPD_LEN,
  9218. vpd_extended_data + BNX2X_VPD_LEN);
  9219. if (cnt < (block_end - BNX2X_VPD_LEN))
  9220. goto out_not_found;
  9221. vpd_data = vpd_extended_data;
  9222. } else
  9223. vpd_data = vpd_start;
  9224. /* now vpd_data holds full vpd content in both cases */
  9225. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9226. PCI_VPD_RO_KEYWORD_MFR_ID);
  9227. if (rodi < 0)
  9228. goto out_not_found;
  9229. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9230. if (len != VENDOR_ID_LEN)
  9231. goto out_not_found;
  9232. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9233. /* vendor specific info */
  9234. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9235. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9236. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9237. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9238. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9239. PCI_VPD_RO_KEYWORD_VENDOR0);
  9240. if (rodi >= 0) {
  9241. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9242. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9243. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9244. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9245. bp->fw_ver[len] = ' ';
  9246. }
  9247. }
  9248. kfree(vpd_extended_data);
  9249. return;
  9250. }
  9251. out_not_found:
  9252. kfree(vpd_extended_data);
  9253. return;
  9254. }
  9255. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9256. {
  9257. u32 flags = 0;
  9258. if (CHIP_REV_IS_FPGA(bp))
  9259. SET_FLAGS(flags, MODE_FPGA);
  9260. else if (CHIP_REV_IS_EMUL(bp))
  9261. SET_FLAGS(flags, MODE_EMUL);
  9262. else
  9263. SET_FLAGS(flags, MODE_ASIC);
  9264. if (CHIP_MODE_IS_4_PORT(bp))
  9265. SET_FLAGS(flags, MODE_PORT4);
  9266. else
  9267. SET_FLAGS(flags, MODE_PORT2);
  9268. if (CHIP_IS_E2(bp))
  9269. SET_FLAGS(flags, MODE_E2);
  9270. else if (CHIP_IS_E3(bp)) {
  9271. SET_FLAGS(flags, MODE_E3);
  9272. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9273. SET_FLAGS(flags, MODE_E3_A0);
  9274. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9275. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9276. }
  9277. if (IS_MF(bp)) {
  9278. SET_FLAGS(flags, MODE_MF);
  9279. switch (bp->mf_mode) {
  9280. case MULTI_FUNCTION_SD:
  9281. SET_FLAGS(flags, MODE_MF_SD);
  9282. break;
  9283. case MULTI_FUNCTION_SI:
  9284. SET_FLAGS(flags, MODE_MF_SI);
  9285. break;
  9286. case MULTI_FUNCTION_AFEX:
  9287. SET_FLAGS(flags, MODE_MF_AFEX);
  9288. break;
  9289. }
  9290. } else
  9291. SET_FLAGS(flags, MODE_SF);
  9292. #if defined(__LITTLE_ENDIAN)
  9293. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9294. #else /*(__BIG_ENDIAN)*/
  9295. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9296. #endif
  9297. INIT_MODE_FLAGS(bp) = flags;
  9298. }
  9299. static int bnx2x_init_bp(struct bnx2x *bp)
  9300. {
  9301. int func;
  9302. int rc;
  9303. mutex_init(&bp->port.phy_mutex);
  9304. mutex_init(&bp->fw_mb_mutex);
  9305. spin_lock_init(&bp->stats_lock);
  9306. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9307. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9308. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9309. if (IS_PF(bp)) {
  9310. rc = bnx2x_get_hwinfo(bp);
  9311. if (rc)
  9312. return rc;
  9313. } else {
  9314. random_ether_addr(bp->dev->dev_addr);
  9315. }
  9316. bnx2x_set_modes_bitmap(bp);
  9317. rc = bnx2x_alloc_mem_bp(bp);
  9318. if (rc)
  9319. return rc;
  9320. bnx2x_read_fwinfo(bp);
  9321. func = BP_FUNC(bp);
  9322. /* need to reset chip if undi was active */
  9323. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9324. /* init fw_seq */
  9325. bp->fw_seq =
  9326. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9327. DRV_MSG_SEQ_NUMBER_MASK;
  9328. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9329. bnx2x_prev_unload(bp);
  9330. }
  9331. if (CHIP_REV_IS_FPGA(bp))
  9332. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9333. if (BP_NOMCP(bp) && (func == 0))
  9334. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9335. bp->disable_tpa = disable_tpa;
  9336. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9337. /* Set TPA flags */
  9338. if (bp->disable_tpa) {
  9339. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9340. bp->dev->features &= ~NETIF_F_LRO;
  9341. } else {
  9342. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9343. bp->dev->features |= NETIF_F_LRO;
  9344. }
  9345. if (CHIP_IS_E1(bp))
  9346. bp->dropless_fc = 0;
  9347. else
  9348. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9349. bp->mrrs = mrrs;
  9350. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9351. if (IS_VF(bp))
  9352. bp->rx_ring_size = MAX_RX_AVAIL;
  9353. /* make sure that the numbers are in the right granularity */
  9354. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9355. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9356. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9357. init_timer(&bp->timer);
  9358. bp->timer.expires = jiffies + bp->current_interval;
  9359. bp->timer.data = (unsigned long) bp;
  9360. bp->timer.function = bnx2x_timer;
  9361. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9362. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9363. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9364. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9365. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9366. bnx2x_dcbx_init_params(bp);
  9367. } else {
  9368. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9369. }
  9370. if (CHIP_IS_E1x(bp))
  9371. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9372. else
  9373. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9374. /* multiple tx priority */
  9375. if (IS_VF(bp))
  9376. bp->max_cos = 1;
  9377. else if (CHIP_IS_E1x(bp))
  9378. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9379. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9380. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9381. else if (CHIP_IS_E3B0(bp))
  9382. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9383. else
  9384. BNX2X_ERR("unknown chip %x revision %x\n",
  9385. CHIP_NUM(bp), CHIP_REV(bp));
  9386. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9387. /* We need at least one default status block for slow-path events,
  9388. * second status block for the L2 queue, and a third status block for
  9389. * CNIC if supproted.
  9390. */
  9391. if (CNIC_SUPPORT(bp))
  9392. bp->min_msix_vec_cnt = 3;
  9393. else
  9394. bp->min_msix_vec_cnt = 2;
  9395. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9396. return rc;
  9397. }
  9398. /****************************************************************************
  9399. * General service functions
  9400. ****************************************************************************/
  9401. /*
  9402. * net_device service functions
  9403. */
  9404. /* called with rtnl_lock */
  9405. static int bnx2x_open(struct net_device *dev)
  9406. {
  9407. struct bnx2x *bp = netdev_priv(dev);
  9408. bool global = false;
  9409. int other_engine = BP_PATH(bp) ? 0 : 1;
  9410. bool other_load_status, load_status;
  9411. bp->stats_init = true;
  9412. netif_carrier_off(dev);
  9413. bnx2x_set_power_state(bp, PCI_D0);
  9414. /* If parity had happen during the unload, then attentions
  9415. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9416. * want the first function loaded on the current engine to
  9417. * complete the recovery.
  9418. * Parity recovery is only relevant for PF driver.
  9419. */
  9420. if (IS_PF(bp)) {
  9421. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9422. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9423. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9424. bnx2x_chk_parity_attn(bp, &global, true)) {
  9425. do {
  9426. /* If there are attentions and they are in a
  9427. * global blocks, set the GLOBAL_RESET bit
  9428. * regardless whether it will be this function
  9429. * that will complete the recovery or not.
  9430. */
  9431. if (global)
  9432. bnx2x_set_reset_global(bp);
  9433. /* Only the first function on the current
  9434. * engine should try to recover in open. In case
  9435. * of attentions in global blocks only the first
  9436. * in the chip should try to recover.
  9437. */
  9438. if ((!load_status &&
  9439. (!global || !other_load_status)) &&
  9440. bnx2x_trylock_leader_lock(bp) &&
  9441. !bnx2x_leader_reset(bp)) {
  9442. netdev_info(bp->dev,
  9443. "Recovered in open\n");
  9444. break;
  9445. }
  9446. /* recovery has failed... */
  9447. bnx2x_set_power_state(bp, PCI_D3hot);
  9448. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9449. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9450. "If you still see this message after a few retries then power cycle is required.\n");
  9451. return -EAGAIN;
  9452. } while (0);
  9453. }
  9454. }
  9455. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9456. return bnx2x_nic_load(bp, LOAD_OPEN);
  9457. }
  9458. /* called with rtnl_lock */
  9459. static int bnx2x_close(struct net_device *dev)
  9460. {
  9461. struct bnx2x *bp = netdev_priv(dev);
  9462. /* Unload the driver, release IRQs */
  9463. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9464. /* Power off */
  9465. bnx2x_set_power_state(bp, PCI_D3hot);
  9466. return 0;
  9467. }
  9468. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9469. struct bnx2x_mcast_ramrod_params *p)
  9470. {
  9471. int mc_count = netdev_mc_count(bp->dev);
  9472. struct bnx2x_mcast_list_elem *mc_mac =
  9473. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9474. struct netdev_hw_addr *ha;
  9475. if (!mc_mac)
  9476. return -ENOMEM;
  9477. INIT_LIST_HEAD(&p->mcast_list);
  9478. netdev_for_each_mc_addr(ha, bp->dev) {
  9479. mc_mac->mac = bnx2x_mc_addr(ha);
  9480. list_add_tail(&mc_mac->link, &p->mcast_list);
  9481. mc_mac++;
  9482. }
  9483. p->mcast_list_len = mc_count;
  9484. return 0;
  9485. }
  9486. static void bnx2x_free_mcast_macs_list(
  9487. struct bnx2x_mcast_ramrod_params *p)
  9488. {
  9489. struct bnx2x_mcast_list_elem *mc_mac =
  9490. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9491. link);
  9492. WARN_ON(!mc_mac);
  9493. kfree(mc_mac);
  9494. }
  9495. /**
  9496. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9497. *
  9498. * @bp: driver handle
  9499. *
  9500. * We will use zero (0) as a MAC type for these MACs.
  9501. */
  9502. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9503. {
  9504. int rc;
  9505. struct net_device *dev = bp->dev;
  9506. struct netdev_hw_addr *ha;
  9507. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9508. unsigned long ramrod_flags = 0;
  9509. /* First schedule a cleanup up of old configuration */
  9510. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9511. if (rc < 0) {
  9512. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9513. return rc;
  9514. }
  9515. netdev_for_each_uc_addr(ha, dev) {
  9516. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9517. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9518. if (rc == -EEXIST) {
  9519. DP(BNX2X_MSG_SP,
  9520. "Failed to schedule ADD operations: %d\n", rc);
  9521. /* do not treat adding same MAC as error */
  9522. rc = 0;
  9523. } else if (rc < 0) {
  9524. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9525. rc);
  9526. return rc;
  9527. }
  9528. }
  9529. /* Execute the pending commands */
  9530. __set_bit(RAMROD_CONT, &ramrod_flags);
  9531. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9532. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9533. }
  9534. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9535. {
  9536. struct net_device *dev = bp->dev;
  9537. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9538. int rc = 0;
  9539. rparam.mcast_obj = &bp->mcast_obj;
  9540. /* first, clear all configured multicast MACs */
  9541. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9542. if (rc < 0) {
  9543. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9544. return rc;
  9545. }
  9546. /* then, configure a new MACs list */
  9547. if (netdev_mc_count(dev)) {
  9548. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9549. if (rc) {
  9550. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9551. rc);
  9552. return rc;
  9553. }
  9554. /* Now add the new MACs */
  9555. rc = bnx2x_config_mcast(bp, &rparam,
  9556. BNX2X_MCAST_CMD_ADD);
  9557. if (rc < 0)
  9558. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9559. rc);
  9560. bnx2x_free_mcast_macs_list(&rparam);
  9561. }
  9562. return rc;
  9563. }
  9564. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9565. void bnx2x_set_rx_mode(struct net_device *dev)
  9566. {
  9567. struct bnx2x *bp = netdev_priv(dev);
  9568. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9569. if (bp->state != BNX2X_STATE_OPEN) {
  9570. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9571. return;
  9572. }
  9573. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9574. if (dev->flags & IFF_PROMISC)
  9575. rx_mode = BNX2X_RX_MODE_PROMISC;
  9576. else if ((dev->flags & IFF_ALLMULTI) ||
  9577. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9578. CHIP_IS_E1(bp)))
  9579. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9580. else {
  9581. /* some multicasts */
  9582. if (bnx2x_set_mc_list(bp) < 0)
  9583. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9584. if (bnx2x_set_uc_list(bp) < 0)
  9585. rx_mode = BNX2X_RX_MODE_PROMISC;
  9586. }
  9587. bp->rx_mode = rx_mode;
  9588. /* handle ISCSI SD mode */
  9589. if (IS_MF_ISCSI_SD(bp))
  9590. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9591. /* Schedule the rx_mode command */
  9592. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9593. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9594. return;
  9595. }
  9596. bnx2x_set_storm_rx_mode(bp);
  9597. }
  9598. /* called with rtnl_lock */
  9599. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9600. int devad, u16 addr)
  9601. {
  9602. struct bnx2x *bp = netdev_priv(netdev);
  9603. u16 value;
  9604. int rc;
  9605. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9606. prtad, devad, addr);
  9607. /* The HW expects different devad if CL22 is used */
  9608. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9609. bnx2x_acquire_phy_lock(bp);
  9610. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9611. bnx2x_release_phy_lock(bp);
  9612. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9613. if (!rc)
  9614. rc = value;
  9615. return rc;
  9616. }
  9617. /* called with rtnl_lock */
  9618. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9619. u16 addr, u16 value)
  9620. {
  9621. struct bnx2x *bp = netdev_priv(netdev);
  9622. int rc;
  9623. DP(NETIF_MSG_LINK,
  9624. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9625. prtad, devad, addr, value);
  9626. /* The HW expects different devad if CL22 is used */
  9627. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9628. bnx2x_acquire_phy_lock(bp);
  9629. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9630. bnx2x_release_phy_lock(bp);
  9631. return rc;
  9632. }
  9633. /* called with rtnl_lock */
  9634. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9635. {
  9636. struct bnx2x *bp = netdev_priv(dev);
  9637. struct mii_ioctl_data *mdio = if_mii(ifr);
  9638. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9639. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9640. if (!netif_running(dev))
  9641. return -EAGAIN;
  9642. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9643. }
  9644. #ifdef CONFIG_NET_POLL_CONTROLLER
  9645. static void poll_bnx2x(struct net_device *dev)
  9646. {
  9647. struct bnx2x *bp = netdev_priv(dev);
  9648. int i;
  9649. for_each_eth_queue(bp, i) {
  9650. struct bnx2x_fastpath *fp = &bp->fp[i];
  9651. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9652. }
  9653. }
  9654. #endif
  9655. static int bnx2x_validate_addr(struct net_device *dev)
  9656. {
  9657. struct bnx2x *bp = netdev_priv(dev);
  9658. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9659. BNX2X_ERR("Non-valid Ethernet address\n");
  9660. return -EADDRNOTAVAIL;
  9661. }
  9662. return 0;
  9663. }
  9664. static const struct net_device_ops bnx2x_netdev_ops = {
  9665. .ndo_open = bnx2x_open,
  9666. .ndo_stop = bnx2x_close,
  9667. .ndo_start_xmit = bnx2x_start_xmit,
  9668. .ndo_select_queue = bnx2x_select_queue,
  9669. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9670. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9671. .ndo_validate_addr = bnx2x_validate_addr,
  9672. .ndo_do_ioctl = bnx2x_ioctl,
  9673. .ndo_change_mtu = bnx2x_change_mtu,
  9674. .ndo_fix_features = bnx2x_fix_features,
  9675. .ndo_set_features = bnx2x_set_features,
  9676. .ndo_tx_timeout = bnx2x_tx_timeout,
  9677. #ifdef CONFIG_NET_POLL_CONTROLLER
  9678. .ndo_poll_controller = poll_bnx2x,
  9679. #endif
  9680. .ndo_setup_tc = bnx2x_setup_tc,
  9681. #ifdef NETDEV_FCOE_WWNN
  9682. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9683. #endif
  9684. };
  9685. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9686. {
  9687. struct device *dev = &bp->pdev->dev;
  9688. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9689. bp->flags |= USING_DAC_FLAG;
  9690. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9691. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9692. return -EIO;
  9693. }
  9694. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9695. dev_err(dev, "System does not support DMA, aborting\n");
  9696. return -EIO;
  9697. }
  9698. return 0;
  9699. }
  9700. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9701. struct net_device *dev, unsigned long board_type)
  9702. {
  9703. int rc;
  9704. u32 pci_cfg_dword;
  9705. bool chip_is_e1x = (board_type == BCM57710 ||
  9706. board_type == BCM57711 ||
  9707. board_type == BCM57711E);
  9708. SET_NETDEV_DEV(dev, &pdev->dev);
  9709. bp->dev = dev;
  9710. bp->pdev = pdev;
  9711. rc = pci_enable_device(pdev);
  9712. if (rc) {
  9713. dev_err(&bp->pdev->dev,
  9714. "Cannot enable PCI device, aborting\n");
  9715. goto err_out;
  9716. }
  9717. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9718. dev_err(&bp->pdev->dev,
  9719. "Cannot find PCI device base address, aborting\n");
  9720. rc = -ENODEV;
  9721. goto err_out_disable;
  9722. }
  9723. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9724. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9725. rc = -ENODEV;
  9726. goto err_out_disable;
  9727. }
  9728. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9729. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9730. PCICFG_REVESION_ID_ERROR_VAL) {
  9731. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9732. rc = -ENODEV;
  9733. goto err_out_disable;
  9734. }
  9735. if (atomic_read(&pdev->enable_cnt) == 1) {
  9736. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9737. if (rc) {
  9738. dev_err(&bp->pdev->dev,
  9739. "Cannot obtain PCI resources, aborting\n");
  9740. goto err_out_disable;
  9741. }
  9742. pci_set_master(pdev);
  9743. pci_save_state(pdev);
  9744. }
  9745. if (IS_PF(bp)) {
  9746. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9747. if (bp->pm_cap == 0) {
  9748. dev_err(&bp->pdev->dev,
  9749. "Cannot find power management capability, aborting\n");
  9750. rc = -EIO;
  9751. goto err_out_release;
  9752. }
  9753. }
  9754. if (!pci_is_pcie(pdev)) {
  9755. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9756. rc = -EIO;
  9757. goto err_out_release;
  9758. }
  9759. rc = bnx2x_set_coherency_mask(bp);
  9760. if (rc)
  9761. goto err_out_release;
  9762. dev->mem_start = pci_resource_start(pdev, 0);
  9763. dev->base_addr = dev->mem_start;
  9764. dev->mem_end = pci_resource_end(pdev, 0);
  9765. dev->irq = pdev->irq;
  9766. bp->regview = pci_ioremap_bar(pdev, 0);
  9767. if (!bp->regview) {
  9768. dev_err(&bp->pdev->dev,
  9769. "Cannot map register space, aborting\n");
  9770. rc = -ENOMEM;
  9771. goto err_out_release;
  9772. }
  9773. /* In E1/E1H use pci device function given by kernel.
  9774. * In E2/E3 read physical function from ME register since these chips
  9775. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9776. * (depending on hypervisor).
  9777. */
  9778. if (chip_is_e1x)
  9779. bp->pf_num = PCI_FUNC(pdev->devfn);
  9780. else {/* chip is E2/3*/
  9781. pci_read_config_dword(bp->pdev,
  9782. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9783. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9784. ME_REG_ABS_PF_NUM_SHIFT);
  9785. }
  9786. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9787. bnx2x_set_power_state(bp, PCI_D0);
  9788. /* clean indirect addresses */
  9789. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9790. PCICFG_VENDOR_ID_OFFSET);
  9791. /*
  9792. * Clean the following indirect addresses for all functions since it
  9793. * is not used by the driver.
  9794. */
  9795. if (IS_PF(bp)) {
  9796. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9797. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9798. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9799. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9800. if (chip_is_e1x) {
  9801. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9802. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9803. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9804. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9805. }
  9806. /* Enable internal target-read (in case we are probed after PF
  9807. * FLR). Must be done prior to any BAR read access. Only for
  9808. * 57712 and up
  9809. */
  9810. if (!chip_is_e1x)
  9811. REG_WR(bp,
  9812. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9813. }
  9814. dev->watchdog_timeo = TX_TIMEOUT;
  9815. dev->netdev_ops = &bnx2x_netdev_ops;
  9816. bnx2x_set_ethtool_ops(dev);
  9817. dev->priv_flags |= IFF_UNICAST_FLT;
  9818. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9819. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9820. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9821. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9822. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9823. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9824. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9825. if (bp->flags & USING_DAC_FLAG)
  9826. dev->features |= NETIF_F_HIGHDMA;
  9827. /* Add Loopback capability to the device */
  9828. dev->hw_features |= NETIF_F_LOOPBACK;
  9829. #ifdef BCM_DCBNL
  9830. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9831. #endif
  9832. /* get_port_hwinfo() will set prtad and mmds properly */
  9833. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9834. bp->mdio.mmds = 0;
  9835. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9836. bp->mdio.dev = dev;
  9837. bp->mdio.mdio_read = bnx2x_mdio_read;
  9838. bp->mdio.mdio_write = bnx2x_mdio_write;
  9839. return 0;
  9840. err_out_release:
  9841. if (atomic_read(&pdev->enable_cnt) == 1)
  9842. pci_release_regions(pdev);
  9843. err_out_disable:
  9844. pci_disable_device(pdev);
  9845. pci_set_drvdata(pdev, NULL);
  9846. err_out:
  9847. return rc;
  9848. }
  9849. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  9850. {
  9851. u32 val = 0;
  9852. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  9853. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9854. /* return value of 1=2.5GHz 2=5GHz */
  9855. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9856. }
  9857. static int bnx2x_check_firmware(struct bnx2x *bp)
  9858. {
  9859. const struct firmware *firmware = bp->firmware;
  9860. struct bnx2x_fw_file_hdr *fw_hdr;
  9861. struct bnx2x_fw_file_section *sections;
  9862. u32 offset, len, num_ops;
  9863. u16 *ops_offsets;
  9864. int i;
  9865. const u8 *fw_ver;
  9866. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9867. BNX2X_ERR("Wrong FW size\n");
  9868. return -EINVAL;
  9869. }
  9870. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9871. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9872. /* Make sure none of the offsets and sizes make us read beyond
  9873. * the end of the firmware data */
  9874. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9875. offset = be32_to_cpu(sections[i].offset);
  9876. len = be32_to_cpu(sections[i].len);
  9877. if (offset + len > firmware->size) {
  9878. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9879. return -EINVAL;
  9880. }
  9881. }
  9882. /* Likewise for the init_ops offsets */
  9883. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9884. ops_offsets = (u16 *)(firmware->data + offset);
  9885. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9886. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9887. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9888. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9889. return -EINVAL;
  9890. }
  9891. }
  9892. /* Check FW version */
  9893. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9894. fw_ver = firmware->data + offset;
  9895. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9896. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9897. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9898. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9899. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9900. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9901. BCM_5710_FW_MAJOR_VERSION,
  9902. BCM_5710_FW_MINOR_VERSION,
  9903. BCM_5710_FW_REVISION_VERSION,
  9904. BCM_5710_FW_ENGINEERING_VERSION);
  9905. return -EINVAL;
  9906. }
  9907. return 0;
  9908. }
  9909. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9910. {
  9911. const __be32 *source = (const __be32 *)_source;
  9912. u32 *target = (u32 *)_target;
  9913. u32 i;
  9914. for (i = 0; i < n/4; i++)
  9915. target[i] = be32_to_cpu(source[i]);
  9916. }
  9917. /*
  9918. Ops array is stored in the following format:
  9919. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9920. */
  9921. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9922. {
  9923. const __be32 *source = (const __be32 *)_source;
  9924. struct raw_op *target = (struct raw_op *)_target;
  9925. u32 i, j, tmp;
  9926. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9927. tmp = be32_to_cpu(source[j]);
  9928. target[i].op = (tmp >> 24) & 0xff;
  9929. target[i].offset = tmp & 0xffffff;
  9930. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9931. }
  9932. }
  9933. /* IRO array is stored in the following format:
  9934. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9935. */
  9936. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9937. {
  9938. const __be32 *source = (const __be32 *)_source;
  9939. struct iro *target = (struct iro *)_target;
  9940. u32 i, j, tmp;
  9941. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9942. target[i].base = be32_to_cpu(source[j]);
  9943. j++;
  9944. tmp = be32_to_cpu(source[j]);
  9945. target[i].m1 = (tmp >> 16) & 0xffff;
  9946. target[i].m2 = tmp & 0xffff;
  9947. j++;
  9948. tmp = be32_to_cpu(source[j]);
  9949. target[i].m3 = (tmp >> 16) & 0xffff;
  9950. target[i].size = tmp & 0xffff;
  9951. j++;
  9952. }
  9953. }
  9954. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9955. {
  9956. const __be16 *source = (const __be16 *)_source;
  9957. u16 *target = (u16 *)_target;
  9958. u32 i;
  9959. for (i = 0; i < n/2; i++)
  9960. target[i] = be16_to_cpu(source[i]);
  9961. }
  9962. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9963. do { \
  9964. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9965. bp->arr = kmalloc(len, GFP_KERNEL); \
  9966. if (!bp->arr) \
  9967. goto lbl; \
  9968. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9969. (u8 *)bp->arr, len); \
  9970. } while (0)
  9971. static int bnx2x_init_firmware(struct bnx2x *bp)
  9972. {
  9973. const char *fw_file_name;
  9974. struct bnx2x_fw_file_hdr *fw_hdr;
  9975. int rc;
  9976. if (bp->firmware)
  9977. return 0;
  9978. if (CHIP_IS_E1(bp))
  9979. fw_file_name = FW_FILE_NAME_E1;
  9980. else if (CHIP_IS_E1H(bp))
  9981. fw_file_name = FW_FILE_NAME_E1H;
  9982. else if (!CHIP_IS_E1x(bp))
  9983. fw_file_name = FW_FILE_NAME_E2;
  9984. else {
  9985. BNX2X_ERR("Unsupported chip revision\n");
  9986. return -EINVAL;
  9987. }
  9988. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9989. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9990. if (rc) {
  9991. BNX2X_ERR("Can't load firmware file %s\n",
  9992. fw_file_name);
  9993. goto request_firmware_exit;
  9994. }
  9995. rc = bnx2x_check_firmware(bp);
  9996. if (rc) {
  9997. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9998. goto request_firmware_exit;
  9999. }
  10000. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10001. /* Initialize the pointers to the init arrays */
  10002. /* Blob */
  10003. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10004. /* Opcodes */
  10005. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10006. /* Offsets */
  10007. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10008. be16_to_cpu_n);
  10009. /* STORMs firmware */
  10010. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10011. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10012. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10013. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10014. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10015. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10016. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10017. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10018. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10019. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10020. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10021. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10022. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10023. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10024. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10025. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10026. /* IRO */
  10027. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10028. return 0;
  10029. iro_alloc_err:
  10030. kfree(bp->init_ops_offsets);
  10031. init_offsets_alloc_err:
  10032. kfree(bp->init_ops);
  10033. init_ops_alloc_err:
  10034. kfree(bp->init_data);
  10035. request_firmware_exit:
  10036. release_firmware(bp->firmware);
  10037. bp->firmware = NULL;
  10038. return rc;
  10039. }
  10040. static void bnx2x_release_firmware(struct bnx2x *bp)
  10041. {
  10042. kfree(bp->init_ops_offsets);
  10043. kfree(bp->init_ops);
  10044. kfree(bp->init_data);
  10045. release_firmware(bp->firmware);
  10046. bp->firmware = NULL;
  10047. }
  10048. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10049. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10050. .init_hw_cmn = bnx2x_init_hw_common,
  10051. .init_hw_port = bnx2x_init_hw_port,
  10052. .init_hw_func = bnx2x_init_hw_func,
  10053. .reset_hw_cmn = bnx2x_reset_common,
  10054. .reset_hw_port = bnx2x_reset_port,
  10055. .reset_hw_func = bnx2x_reset_func,
  10056. .gunzip_init = bnx2x_gunzip_init,
  10057. .gunzip_end = bnx2x_gunzip_end,
  10058. .init_fw = bnx2x_init_firmware,
  10059. .release_fw = bnx2x_release_firmware,
  10060. };
  10061. void bnx2x__init_func_obj(struct bnx2x *bp)
  10062. {
  10063. /* Prepare DMAE related driver resources */
  10064. bnx2x_setup_dmae(bp);
  10065. bnx2x_init_func_obj(bp, &bp->func_obj,
  10066. bnx2x_sp(bp, func_rdata),
  10067. bnx2x_sp_mapping(bp, func_rdata),
  10068. bnx2x_sp(bp, func_afex_rdata),
  10069. bnx2x_sp_mapping(bp, func_afex_rdata),
  10070. &bnx2x_func_sp_drv);
  10071. }
  10072. /* must be called after sriov-enable */
  10073. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10074. {
  10075. int cid_count = BNX2X_L2_MAX_CID(bp);
  10076. if (CNIC_SUPPORT(bp))
  10077. cid_count += CNIC_CID_MAX;
  10078. return roundup(cid_count, QM_CID_ROUND);
  10079. }
  10080. /**
  10081. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10082. *
  10083. * @dev: pci device
  10084. *
  10085. */
  10086. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10087. int cnic_cnt, bool is_vf)
  10088. {
  10089. int pos, index;
  10090. u16 control = 0;
  10091. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10092. /*
  10093. * If MSI-X is not supported - return number of SBs needed to support
  10094. * one fast path queue: one FP queue + SB for CNIC
  10095. */
  10096. if (!pos) {
  10097. dev_info(&pdev->dev, "no msix capability found\n");
  10098. return 1 + cnic_cnt;
  10099. }
  10100. dev_info(&pdev->dev, "msix capability found\n");
  10101. /*
  10102. * The value in the PCI configuration space is the index of the last
  10103. * entry, namely one less than the actual size of the table, which is
  10104. * exactly what we want to return from this function: number of all SBs
  10105. * without the default SB.
  10106. * For VFs there is no default SB, then we return (index+1).
  10107. */
  10108. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10109. index = control & PCI_MSIX_FLAGS_QSIZE;
  10110. return is_vf ? index + 1 : index;
  10111. }
  10112. static int set_max_cos_est(int chip_id)
  10113. {
  10114. switch (chip_id) {
  10115. case BCM57710:
  10116. case BCM57711:
  10117. case BCM57711E:
  10118. return BNX2X_MULTI_TX_COS_E1X;
  10119. case BCM57712:
  10120. case BCM57712_MF:
  10121. case BCM57712_VF:
  10122. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10123. case BCM57800:
  10124. case BCM57800_MF:
  10125. case BCM57800_VF:
  10126. case BCM57810:
  10127. case BCM57810_MF:
  10128. case BCM57840_4_10:
  10129. case BCM57840_2_20:
  10130. case BCM57840_O:
  10131. case BCM57840_MFO:
  10132. case BCM57810_VF:
  10133. case BCM57840_MF:
  10134. case BCM57840_VF:
  10135. case BCM57811:
  10136. case BCM57811_MF:
  10137. case BCM57811_VF:
  10138. return BNX2X_MULTI_TX_COS_E3B0;
  10139. return 1;
  10140. default:
  10141. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10142. return -ENODEV;
  10143. }
  10144. }
  10145. static int set_is_vf(int chip_id)
  10146. {
  10147. switch (chip_id) {
  10148. case BCM57712_VF:
  10149. case BCM57800_VF:
  10150. case BCM57810_VF:
  10151. case BCM57840_VF:
  10152. case BCM57811_VF:
  10153. return true;
  10154. default:
  10155. return false;
  10156. }
  10157. }
  10158. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10159. static int bnx2x_init_one(struct pci_dev *pdev,
  10160. const struct pci_device_id *ent)
  10161. {
  10162. struct net_device *dev = NULL;
  10163. struct bnx2x *bp;
  10164. int pcie_width, pcie_speed;
  10165. int rc, max_non_def_sbs;
  10166. int rx_count, tx_count, rss_count, doorbell_size;
  10167. int max_cos_est;
  10168. bool is_vf;
  10169. int cnic_cnt;
  10170. /* An estimated maximum supported CoS number according to the chip
  10171. * version.
  10172. * We will try to roughly estimate the maximum number of CoSes this chip
  10173. * may support in order to minimize the memory allocated for Tx
  10174. * netdev_queue's. This number will be accurately calculated during the
  10175. * initialization of bp->max_cos based on the chip versions AND chip
  10176. * revision in the bnx2x_init_bp().
  10177. */
  10178. max_cos_est = set_max_cos_est(ent->driver_data);
  10179. if (max_cos_est < 0)
  10180. return max_cos_est;
  10181. is_vf = set_is_vf(ent->driver_data);
  10182. cnic_cnt = is_vf ? 0 : 1;
  10183. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10184. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10185. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10186. if (rss_count < 1)
  10187. return -EINVAL;
  10188. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10189. rx_count = rss_count + cnic_cnt;
  10190. /* Maximum number of netdev Tx queues:
  10191. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10192. */
  10193. tx_count = rss_count * max_cos_est + cnic_cnt;
  10194. /* dev zeroed in init_etherdev */
  10195. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10196. if (!dev)
  10197. return -ENOMEM;
  10198. bp = netdev_priv(dev);
  10199. bp->flags = 0;
  10200. if (is_vf)
  10201. bp->flags |= IS_VF_FLAG;
  10202. bp->igu_sb_cnt = max_non_def_sbs;
  10203. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10204. bp->msg_enable = debug;
  10205. bp->cnic_support = cnic_cnt;
  10206. bp->cnic_probe = bnx2x_cnic_probe;
  10207. pci_set_drvdata(pdev, dev);
  10208. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10209. if (rc < 0) {
  10210. free_netdev(dev);
  10211. return rc;
  10212. }
  10213. BNX2X_DEV_INFO("This is a %s function\n",
  10214. IS_PF(bp) ? "physical" : "virtual");
  10215. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10216. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10217. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10218. tx_count, rx_count);
  10219. rc = bnx2x_init_bp(bp);
  10220. if (rc)
  10221. goto init_one_exit;
  10222. /* Map doorbells here as we need the real value of bp->max_cos which
  10223. * is initialized in bnx2x_init_bp() to determine the number of
  10224. * l2 connections.
  10225. */
  10226. if (IS_VF(bp)) {
  10227. /* vf doorbells are embedded within the regview */
  10228. bp->doorbells = bp->regview + PXP_VF_ADDR_DB_START;
  10229. /* allocate vf2pf mailbox for vf to pf channel */
  10230. BNX2X_PCI_ALLOC(bp->vf2pf_mbox, &bp->vf2pf_mbox_mapping,
  10231. sizeof(struct bnx2x_vf_mbx_msg));
  10232. } else {
  10233. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10234. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10235. dev_err(&bp->pdev->dev,
  10236. "Cannot map doorbells, bar size too small, aborting\n");
  10237. rc = -ENOMEM;
  10238. goto init_one_exit;
  10239. }
  10240. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10241. doorbell_size);
  10242. }
  10243. if (!bp->doorbells) {
  10244. dev_err(&bp->pdev->dev,
  10245. "Cannot map doorbell space, aborting\n");
  10246. rc = -ENOMEM;
  10247. goto init_one_exit;
  10248. }
  10249. if (IS_VF(bp)) {
  10250. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10251. if (rc)
  10252. goto init_one_exit;
  10253. }
  10254. /* calc qm_cid_count */
  10255. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10256. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10257. /* disable FCOE L2 queue for E1x*/
  10258. if (CHIP_IS_E1x(bp))
  10259. bp->flags |= NO_FCOE_FLAG;
  10260. /* disable FCOE for 57840 device, until FW supports it */
  10261. switch (ent->driver_data) {
  10262. case BCM57840_O:
  10263. case BCM57840_4_10:
  10264. case BCM57840_2_20:
  10265. case BCM57840_MFO:
  10266. case BCM57840_MF:
  10267. bp->flags |= NO_FCOE_FLAG;
  10268. }
  10269. /* Set bp->num_queues for MSI-X mode*/
  10270. bnx2x_set_num_queues(bp);
  10271. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10272. * needed.
  10273. */
  10274. rc = bnx2x_set_int_mode(bp);
  10275. if (rc) {
  10276. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10277. goto init_one_exit;
  10278. }
  10279. /* register the net device */
  10280. rc = register_netdev(dev);
  10281. if (rc) {
  10282. dev_err(&pdev->dev, "Cannot register net device\n");
  10283. goto init_one_exit;
  10284. }
  10285. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10286. if (!NO_FCOE(bp)) {
  10287. /* Add storage MAC address */
  10288. rtnl_lock();
  10289. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10290. rtnl_unlock();
  10291. }
  10292. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10293. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10294. pcie_width, pcie_speed);
  10295. BNX2X_DEV_INFO(
  10296. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10297. board_info[ent->driver_data].name,
  10298. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10299. pcie_width,
  10300. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10301. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10302. "5GHz (Gen2)" : "2.5GHz",
  10303. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10304. return 0;
  10305. alloc_mem_err:
  10306. BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
  10307. sizeof(struct bnx2x_vf_mbx_msg));
  10308. rc = -ENOMEM;
  10309. init_one_exit:
  10310. if (bp->regview)
  10311. iounmap(bp->regview);
  10312. if (IS_PF(bp) && bp->doorbells)
  10313. iounmap(bp->doorbells);
  10314. free_netdev(dev);
  10315. if (atomic_read(&pdev->enable_cnt) == 1)
  10316. pci_release_regions(pdev);
  10317. pci_disable_device(pdev);
  10318. pci_set_drvdata(pdev, NULL);
  10319. return rc;
  10320. }
  10321. static void bnx2x_remove_one(struct pci_dev *pdev)
  10322. {
  10323. struct net_device *dev = pci_get_drvdata(pdev);
  10324. struct bnx2x *bp;
  10325. if (!dev) {
  10326. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10327. return;
  10328. }
  10329. bp = netdev_priv(dev);
  10330. /* Delete storage MAC address */
  10331. if (!NO_FCOE(bp)) {
  10332. rtnl_lock();
  10333. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10334. rtnl_unlock();
  10335. }
  10336. #ifdef BCM_DCBNL
  10337. /* Delete app tlvs from dcbnl */
  10338. bnx2x_dcbnl_update_applist(bp, true);
  10339. #endif
  10340. unregister_netdev(dev);
  10341. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10342. if (IS_PF(bp))
  10343. bnx2x_set_power_state(bp, PCI_D0);
  10344. /* Disable MSI/MSI-X */
  10345. bnx2x_disable_msi(bp);
  10346. /* Power off */
  10347. if (IS_PF(bp))
  10348. bnx2x_set_power_state(bp, PCI_D3hot);
  10349. /* Make sure RESET task is not scheduled before continuing */
  10350. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10351. /* send message via vfpf channel to release the resources of this vf */
  10352. if (IS_VF(bp))
  10353. bnx2x_vfpf_release(bp);
  10354. if (bp->regview)
  10355. iounmap(bp->regview);
  10356. /* for vf doorbells are part of the regview and were unmapped along with
  10357. * it. FW is only loaded by PF.
  10358. */
  10359. if (IS_PF(bp)) {
  10360. if (bp->doorbells)
  10361. iounmap(bp->doorbells);
  10362. bnx2x_release_firmware(bp);
  10363. }
  10364. bnx2x_free_mem_bp(bp);
  10365. free_netdev(dev);
  10366. if (atomic_read(&pdev->enable_cnt) == 1)
  10367. pci_release_regions(pdev);
  10368. pci_disable_device(pdev);
  10369. pci_set_drvdata(pdev, NULL);
  10370. }
  10371. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10372. {
  10373. int i;
  10374. bp->state = BNX2X_STATE_ERROR;
  10375. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10376. if (CNIC_LOADED(bp))
  10377. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10378. /* Stop Tx */
  10379. bnx2x_tx_disable(bp);
  10380. bnx2x_netif_stop(bp, 0);
  10381. /* Delete all NAPI objects */
  10382. bnx2x_del_all_napi(bp);
  10383. if (CNIC_LOADED(bp))
  10384. bnx2x_del_all_napi_cnic(bp);
  10385. del_timer_sync(&bp->timer);
  10386. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10387. /* Release IRQs */
  10388. bnx2x_free_irq(bp);
  10389. /* Free SKBs, SGEs, TPA pool and driver internals */
  10390. bnx2x_free_skbs(bp);
  10391. for_each_rx_queue(bp, i)
  10392. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10393. bnx2x_free_mem(bp);
  10394. bp->state = BNX2X_STATE_CLOSED;
  10395. netif_carrier_off(bp->dev);
  10396. return 0;
  10397. }
  10398. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10399. {
  10400. u32 val;
  10401. mutex_init(&bp->port.phy_mutex);
  10402. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10403. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10404. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10405. BNX2X_ERR("BAD MCP validity signature\n");
  10406. }
  10407. /**
  10408. * bnx2x_io_error_detected - called when PCI error is detected
  10409. * @pdev: Pointer to PCI device
  10410. * @state: The current pci connection state
  10411. *
  10412. * This function is called after a PCI bus error affecting
  10413. * this device has been detected.
  10414. */
  10415. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10416. pci_channel_state_t state)
  10417. {
  10418. struct net_device *dev = pci_get_drvdata(pdev);
  10419. struct bnx2x *bp = netdev_priv(dev);
  10420. rtnl_lock();
  10421. netif_device_detach(dev);
  10422. if (state == pci_channel_io_perm_failure) {
  10423. rtnl_unlock();
  10424. return PCI_ERS_RESULT_DISCONNECT;
  10425. }
  10426. if (netif_running(dev))
  10427. bnx2x_eeh_nic_unload(bp);
  10428. pci_disable_device(pdev);
  10429. rtnl_unlock();
  10430. /* Request a slot reset */
  10431. return PCI_ERS_RESULT_NEED_RESET;
  10432. }
  10433. /**
  10434. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10435. * @pdev: Pointer to PCI device
  10436. *
  10437. * Restart the card from scratch, as if from a cold-boot.
  10438. */
  10439. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10440. {
  10441. struct net_device *dev = pci_get_drvdata(pdev);
  10442. struct bnx2x *bp = netdev_priv(dev);
  10443. rtnl_lock();
  10444. if (pci_enable_device(pdev)) {
  10445. dev_err(&pdev->dev,
  10446. "Cannot re-enable PCI device after reset\n");
  10447. rtnl_unlock();
  10448. return PCI_ERS_RESULT_DISCONNECT;
  10449. }
  10450. pci_set_master(pdev);
  10451. pci_restore_state(pdev);
  10452. if (netif_running(dev))
  10453. bnx2x_set_power_state(bp, PCI_D0);
  10454. rtnl_unlock();
  10455. return PCI_ERS_RESULT_RECOVERED;
  10456. }
  10457. /**
  10458. * bnx2x_io_resume - called when traffic can start flowing again
  10459. * @pdev: Pointer to PCI device
  10460. *
  10461. * This callback is called when the error recovery driver tells us that
  10462. * its OK to resume normal operation.
  10463. */
  10464. static void bnx2x_io_resume(struct pci_dev *pdev)
  10465. {
  10466. struct net_device *dev = pci_get_drvdata(pdev);
  10467. struct bnx2x *bp = netdev_priv(dev);
  10468. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10469. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10470. return;
  10471. }
  10472. rtnl_lock();
  10473. bnx2x_eeh_recover(bp);
  10474. if (netif_running(dev))
  10475. bnx2x_nic_load(bp, LOAD_NORMAL);
  10476. netif_device_attach(dev);
  10477. rtnl_unlock();
  10478. }
  10479. static const struct pci_error_handlers bnx2x_err_handler = {
  10480. .error_detected = bnx2x_io_error_detected,
  10481. .slot_reset = bnx2x_io_slot_reset,
  10482. .resume = bnx2x_io_resume,
  10483. };
  10484. static struct pci_driver bnx2x_pci_driver = {
  10485. .name = DRV_MODULE_NAME,
  10486. .id_table = bnx2x_pci_tbl,
  10487. .probe = bnx2x_init_one,
  10488. .remove = bnx2x_remove_one,
  10489. .suspend = bnx2x_suspend,
  10490. .resume = bnx2x_resume,
  10491. .err_handler = &bnx2x_err_handler,
  10492. };
  10493. static int __init bnx2x_init(void)
  10494. {
  10495. int ret;
  10496. pr_info("%s", version);
  10497. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10498. if (bnx2x_wq == NULL) {
  10499. pr_err("Cannot create workqueue\n");
  10500. return -ENOMEM;
  10501. }
  10502. ret = pci_register_driver(&bnx2x_pci_driver);
  10503. if (ret) {
  10504. pr_err("Cannot register driver\n");
  10505. destroy_workqueue(bnx2x_wq);
  10506. }
  10507. return ret;
  10508. }
  10509. static void __exit bnx2x_cleanup(void)
  10510. {
  10511. struct list_head *pos, *q;
  10512. pci_unregister_driver(&bnx2x_pci_driver);
  10513. destroy_workqueue(bnx2x_wq);
  10514. /* Free globablly allocated resources */
  10515. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10516. struct bnx2x_prev_path_list *tmp =
  10517. list_entry(pos, struct bnx2x_prev_path_list, list);
  10518. list_del(pos);
  10519. kfree(tmp);
  10520. }
  10521. }
  10522. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10523. {
  10524. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10525. }
  10526. module_init(bnx2x_init);
  10527. module_exit(bnx2x_cleanup);
  10528. /**
  10529. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10530. *
  10531. * @bp: driver handle
  10532. * @set: set or clear the CAM entry
  10533. *
  10534. * This function will wait until the ramdord completion returns.
  10535. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10536. */
  10537. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10538. {
  10539. unsigned long ramrod_flags = 0;
  10540. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10541. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10542. &bp->iscsi_l2_mac_obj, true,
  10543. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10544. }
  10545. /* count denotes the number of new completions we have seen */
  10546. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10547. {
  10548. struct eth_spe *spe;
  10549. int cxt_index, cxt_offset;
  10550. #ifdef BNX2X_STOP_ON_ERROR
  10551. if (unlikely(bp->panic))
  10552. return;
  10553. #endif
  10554. spin_lock_bh(&bp->spq_lock);
  10555. BUG_ON(bp->cnic_spq_pending < count);
  10556. bp->cnic_spq_pending -= count;
  10557. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10558. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10559. & SPE_HDR_CONN_TYPE) >>
  10560. SPE_HDR_CONN_TYPE_SHIFT;
  10561. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10562. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10563. /* Set validation for iSCSI L2 client before sending SETUP
  10564. * ramrod
  10565. */
  10566. if (type == ETH_CONNECTION_TYPE) {
  10567. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10568. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10569. ILT_PAGE_CIDS;
  10570. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10571. (cxt_index * ILT_PAGE_CIDS);
  10572. bnx2x_set_ctx_validation(bp,
  10573. &bp->context[cxt_index].
  10574. vcxt[cxt_offset].eth,
  10575. BNX2X_ISCSI_ETH_CID(bp));
  10576. }
  10577. }
  10578. /*
  10579. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10580. * and in the air. We also check that number of outstanding
  10581. * COMMON ramrods is not more than the EQ and SPQ can
  10582. * accommodate.
  10583. */
  10584. if (type == ETH_CONNECTION_TYPE) {
  10585. if (!atomic_read(&bp->cq_spq_left))
  10586. break;
  10587. else
  10588. atomic_dec(&bp->cq_spq_left);
  10589. } else if (type == NONE_CONNECTION_TYPE) {
  10590. if (!atomic_read(&bp->eq_spq_left))
  10591. break;
  10592. else
  10593. atomic_dec(&bp->eq_spq_left);
  10594. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10595. (type == FCOE_CONNECTION_TYPE)) {
  10596. if (bp->cnic_spq_pending >=
  10597. bp->cnic_eth_dev.max_kwqe_pending)
  10598. break;
  10599. else
  10600. bp->cnic_spq_pending++;
  10601. } else {
  10602. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10603. bnx2x_panic();
  10604. break;
  10605. }
  10606. spe = bnx2x_sp_get_next(bp);
  10607. *spe = *bp->cnic_kwq_cons;
  10608. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10609. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10610. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10611. bp->cnic_kwq_cons = bp->cnic_kwq;
  10612. else
  10613. bp->cnic_kwq_cons++;
  10614. }
  10615. bnx2x_sp_prod_update(bp);
  10616. spin_unlock_bh(&bp->spq_lock);
  10617. }
  10618. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10619. struct kwqe_16 *kwqes[], u32 count)
  10620. {
  10621. struct bnx2x *bp = netdev_priv(dev);
  10622. int i;
  10623. #ifdef BNX2X_STOP_ON_ERROR
  10624. if (unlikely(bp->panic)) {
  10625. BNX2X_ERR("Can't post to SP queue while panic\n");
  10626. return -EIO;
  10627. }
  10628. #endif
  10629. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10630. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10631. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10632. return -EAGAIN;
  10633. }
  10634. spin_lock_bh(&bp->spq_lock);
  10635. for (i = 0; i < count; i++) {
  10636. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10637. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10638. break;
  10639. *bp->cnic_kwq_prod = *spe;
  10640. bp->cnic_kwq_pending++;
  10641. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10642. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10643. spe->data.update_data_addr.hi,
  10644. spe->data.update_data_addr.lo,
  10645. bp->cnic_kwq_pending);
  10646. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10647. bp->cnic_kwq_prod = bp->cnic_kwq;
  10648. else
  10649. bp->cnic_kwq_prod++;
  10650. }
  10651. spin_unlock_bh(&bp->spq_lock);
  10652. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10653. bnx2x_cnic_sp_post(bp, 0);
  10654. return i;
  10655. }
  10656. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10657. {
  10658. struct cnic_ops *c_ops;
  10659. int rc = 0;
  10660. mutex_lock(&bp->cnic_mutex);
  10661. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10662. lockdep_is_held(&bp->cnic_mutex));
  10663. if (c_ops)
  10664. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10665. mutex_unlock(&bp->cnic_mutex);
  10666. return rc;
  10667. }
  10668. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10669. {
  10670. struct cnic_ops *c_ops;
  10671. int rc = 0;
  10672. rcu_read_lock();
  10673. c_ops = rcu_dereference(bp->cnic_ops);
  10674. if (c_ops)
  10675. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10676. rcu_read_unlock();
  10677. return rc;
  10678. }
  10679. /*
  10680. * for commands that have no data
  10681. */
  10682. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10683. {
  10684. struct cnic_ctl_info ctl = {0};
  10685. ctl.cmd = cmd;
  10686. return bnx2x_cnic_ctl_send(bp, &ctl);
  10687. }
  10688. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10689. {
  10690. struct cnic_ctl_info ctl = {0};
  10691. /* first we tell CNIC and only then we count this as a completion */
  10692. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10693. ctl.data.comp.cid = cid;
  10694. ctl.data.comp.error = err;
  10695. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10696. bnx2x_cnic_sp_post(bp, 0);
  10697. }
  10698. /* Called with netif_addr_lock_bh() taken.
  10699. * Sets an rx_mode config for an iSCSI ETH client.
  10700. * Doesn't block.
  10701. * Completion should be checked outside.
  10702. */
  10703. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10704. {
  10705. unsigned long accept_flags = 0, ramrod_flags = 0;
  10706. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10707. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10708. if (start) {
  10709. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10710. * because it's the only way for UIO Queue to accept
  10711. * multicasts (in non-promiscuous mode only one Queue per
  10712. * function will receive multicast packets (leading in our
  10713. * case).
  10714. */
  10715. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10716. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10717. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10718. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10719. /* Clear STOP_PENDING bit if START is requested */
  10720. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10721. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10722. } else
  10723. /* Clear START_PENDING bit if STOP is requested */
  10724. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10725. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10726. set_bit(sched_state, &bp->sp_state);
  10727. else {
  10728. __set_bit(RAMROD_RX, &ramrod_flags);
  10729. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10730. ramrod_flags);
  10731. }
  10732. }
  10733. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10734. {
  10735. struct bnx2x *bp = netdev_priv(dev);
  10736. int rc = 0;
  10737. switch (ctl->cmd) {
  10738. case DRV_CTL_CTXTBL_WR_CMD: {
  10739. u32 index = ctl->data.io.offset;
  10740. dma_addr_t addr = ctl->data.io.dma_addr;
  10741. bnx2x_ilt_wr(bp, index, addr);
  10742. break;
  10743. }
  10744. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10745. int count = ctl->data.credit.credit_count;
  10746. bnx2x_cnic_sp_post(bp, count);
  10747. break;
  10748. }
  10749. /* rtnl_lock is held. */
  10750. case DRV_CTL_START_L2_CMD: {
  10751. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10752. unsigned long sp_bits = 0;
  10753. /* Configure the iSCSI classification object */
  10754. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10755. cp->iscsi_l2_client_id,
  10756. cp->iscsi_l2_cid, BP_FUNC(bp),
  10757. bnx2x_sp(bp, mac_rdata),
  10758. bnx2x_sp_mapping(bp, mac_rdata),
  10759. BNX2X_FILTER_MAC_PENDING,
  10760. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10761. &bp->macs_pool);
  10762. /* Set iSCSI MAC address */
  10763. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10764. if (rc)
  10765. break;
  10766. mmiowb();
  10767. barrier();
  10768. /* Start accepting on iSCSI L2 ring */
  10769. netif_addr_lock_bh(dev);
  10770. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10771. netif_addr_unlock_bh(dev);
  10772. /* bits to wait on */
  10773. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10774. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10775. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10776. BNX2X_ERR("rx_mode completion timed out!\n");
  10777. break;
  10778. }
  10779. /* rtnl_lock is held. */
  10780. case DRV_CTL_STOP_L2_CMD: {
  10781. unsigned long sp_bits = 0;
  10782. /* Stop accepting on iSCSI L2 ring */
  10783. netif_addr_lock_bh(dev);
  10784. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10785. netif_addr_unlock_bh(dev);
  10786. /* bits to wait on */
  10787. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10788. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10789. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10790. BNX2X_ERR("rx_mode completion timed out!\n");
  10791. mmiowb();
  10792. barrier();
  10793. /* Unset iSCSI L2 MAC */
  10794. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10795. BNX2X_ISCSI_ETH_MAC, true);
  10796. break;
  10797. }
  10798. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10799. int count = ctl->data.credit.credit_count;
  10800. smp_mb__before_atomic_inc();
  10801. atomic_add(count, &bp->cq_spq_left);
  10802. smp_mb__after_atomic_inc();
  10803. break;
  10804. }
  10805. case DRV_CTL_ULP_REGISTER_CMD: {
  10806. int ulp_type = ctl->data.register_data.ulp_type;
  10807. if (CHIP_IS_E3(bp)) {
  10808. int idx = BP_FW_MB_IDX(bp);
  10809. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10810. int path = BP_PATH(bp);
  10811. int port = BP_PORT(bp);
  10812. int i;
  10813. u32 scratch_offset;
  10814. u32 *host_addr;
  10815. /* first write capability to shmem2 */
  10816. if (ulp_type == CNIC_ULP_ISCSI)
  10817. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10818. else if (ulp_type == CNIC_ULP_FCOE)
  10819. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10820. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10821. if ((ulp_type != CNIC_ULP_FCOE) ||
  10822. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10823. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10824. break;
  10825. /* if reached here - should write fcoe capabilities */
  10826. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10827. if (!scratch_offset)
  10828. break;
  10829. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10830. fcoe_features[path][port]);
  10831. host_addr = (u32 *) &(ctl->data.register_data.
  10832. fcoe_features);
  10833. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10834. i += 4)
  10835. REG_WR(bp, scratch_offset + i,
  10836. *(host_addr + i/4));
  10837. }
  10838. break;
  10839. }
  10840. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10841. int ulp_type = ctl->data.ulp_type;
  10842. if (CHIP_IS_E3(bp)) {
  10843. int idx = BP_FW_MB_IDX(bp);
  10844. u32 cap;
  10845. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10846. if (ulp_type == CNIC_ULP_ISCSI)
  10847. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10848. else if (ulp_type == CNIC_ULP_FCOE)
  10849. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10850. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10851. }
  10852. break;
  10853. }
  10854. default:
  10855. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10856. rc = -EINVAL;
  10857. }
  10858. return rc;
  10859. }
  10860. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10861. {
  10862. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10863. if (bp->flags & USING_MSIX_FLAG) {
  10864. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10865. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10866. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10867. } else {
  10868. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10869. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10870. }
  10871. if (!CHIP_IS_E1x(bp))
  10872. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10873. else
  10874. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10875. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10876. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10877. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10878. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10879. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10880. cp->num_irq = 2;
  10881. }
  10882. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  10883. {
  10884. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10885. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10886. bnx2x_cid_ilt_lines(bp);
  10887. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10888. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10889. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10890. if (NO_ISCSI_OOO(bp))
  10891. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10892. }
  10893. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10894. void *data)
  10895. {
  10896. struct bnx2x *bp = netdev_priv(dev);
  10897. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10898. int rc;
  10899. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  10900. if (ops == NULL) {
  10901. BNX2X_ERR("NULL ops received\n");
  10902. return -EINVAL;
  10903. }
  10904. if (!CNIC_SUPPORT(bp)) {
  10905. BNX2X_ERR("Can't register CNIC when not supported\n");
  10906. return -EOPNOTSUPP;
  10907. }
  10908. if (!CNIC_LOADED(bp)) {
  10909. rc = bnx2x_load_cnic(bp);
  10910. if (rc) {
  10911. BNX2X_ERR("CNIC-related load failed\n");
  10912. return rc;
  10913. }
  10914. }
  10915. bp->cnic_enabled = true;
  10916. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10917. if (!bp->cnic_kwq)
  10918. return -ENOMEM;
  10919. bp->cnic_kwq_cons = bp->cnic_kwq;
  10920. bp->cnic_kwq_prod = bp->cnic_kwq;
  10921. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10922. bp->cnic_spq_pending = 0;
  10923. bp->cnic_kwq_pending = 0;
  10924. bp->cnic_data = data;
  10925. cp->num_irq = 0;
  10926. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10927. cp->iro_arr = bp->iro_arr;
  10928. bnx2x_setup_cnic_irq_info(bp);
  10929. rcu_assign_pointer(bp->cnic_ops, ops);
  10930. return 0;
  10931. }
  10932. static int bnx2x_unregister_cnic(struct net_device *dev)
  10933. {
  10934. struct bnx2x *bp = netdev_priv(dev);
  10935. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10936. mutex_lock(&bp->cnic_mutex);
  10937. cp->drv_state = 0;
  10938. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10939. mutex_unlock(&bp->cnic_mutex);
  10940. synchronize_rcu();
  10941. kfree(bp->cnic_kwq);
  10942. bp->cnic_kwq = NULL;
  10943. return 0;
  10944. }
  10945. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10946. {
  10947. struct bnx2x *bp = netdev_priv(dev);
  10948. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10949. /* If both iSCSI and FCoE are disabled - return NULL in
  10950. * order to indicate CNIC that it should not try to work
  10951. * with this device.
  10952. */
  10953. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10954. return NULL;
  10955. cp->drv_owner = THIS_MODULE;
  10956. cp->chip_id = CHIP_ID(bp);
  10957. cp->pdev = bp->pdev;
  10958. cp->io_base = bp->regview;
  10959. cp->io_base2 = bp->doorbells;
  10960. cp->max_kwqe_pending = 8;
  10961. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10962. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10963. bnx2x_cid_ilt_lines(bp);
  10964. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10965. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10966. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10967. cp->drv_ctl = bnx2x_drv_ctl;
  10968. cp->drv_register_cnic = bnx2x_register_cnic;
  10969. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10970. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10971. cp->iscsi_l2_client_id =
  10972. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10973. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10974. if (NO_ISCSI_OOO(bp))
  10975. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10976. if (NO_ISCSI(bp))
  10977. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10978. if (NO_FCOE(bp))
  10979. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10980. BNX2X_DEV_INFO(
  10981. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10982. cp->ctx_blk_size,
  10983. cp->ctx_tbl_offset,
  10984. cp->ctx_tbl_len,
  10985. cp->starting_cid);
  10986. return cp;
  10987. }
  10988. int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
  10989. {
  10990. struct cstorm_vf_zone_data __iomem *zone_data =
  10991. REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
  10992. int tout = 600, interval = 100; /* wait for 60 seconds */
  10993. if (*done) {
  10994. BNX2X_ERR("done was non zero before message to pf was sent\n");
  10995. WARN_ON(true);
  10996. return -EINVAL;
  10997. }
  10998. /* Write message address */
  10999. writel(U64_LO(msg_mapping),
  11000. &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
  11001. writel(U64_HI(msg_mapping),
  11002. &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
  11003. /* make sure the address is written before FW accesses it */
  11004. wmb();
  11005. /* Trigger the PF FW */
  11006. writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
  11007. /* Wait for PF to complete */
  11008. while ((tout >= 0) && (!*done)) {
  11009. msleep(interval);
  11010. tout -= 1;
  11011. /* progress indicator - HV can take its own sweet time in
  11012. * answering VFs...
  11013. */
  11014. DP_CONT(BNX2X_MSG_IOV, ".");
  11015. }
  11016. if (!*done) {
  11017. BNX2X_ERR("PF response has timed out\n");
  11018. return -EAGAIN;
  11019. }
  11020. DP(BNX2X_MSG_SP, "Got a response from PF\n");
  11021. return 0;
  11022. }
  11023. int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
  11024. {
  11025. u32 me_reg;
  11026. int tout = 10, interval = 100; /* Wait for 1 sec */
  11027. do {
  11028. /* pxp traps vf read of doorbells and returns me reg value */
  11029. me_reg = readl(bp->doorbells);
  11030. if (GOOD_ME_REG(me_reg))
  11031. break;
  11032. msleep(interval);
  11033. BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
  11034. me_reg);
  11035. } while (tout-- > 0);
  11036. if (!GOOD_ME_REG(me_reg)) {
  11037. BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
  11038. return -EINVAL;
  11039. }
  11040. BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
  11041. *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
  11042. return 0;
  11043. }
  11044. int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
  11045. {
  11046. int rc = 0, attempts = 0;
  11047. struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
  11048. struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
  11049. u32 vf_id;
  11050. bool resources_acquired = false;
  11051. /* clear mailbox and prep first tlv */
  11052. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
  11053. if (bnx2x_get_vf_id(bp, &vf_id))
  11054. return -EAGAIN;
  11055. req->vfdev_info.vf_id = vf_id;
  11056. req->vfdev_info.vf_os = 0;
  11057. req->resc_request.num_rxqs = rx_count;
  11058. req->resc_request.num_txqs = tx_count;
  11059. req->resc_request.num_sbs = bp->igu_sb_cnt;
  11060. req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
  11061. req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
  11062. /* add list termination tlv */
  11063. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11064. sizeof(struct channel_list_end_tlv));
  11065. /* output tlvs list */
  11066. bnx2x_dp_tlv_list(bp, req);
  11067. while (!resources_acquired) {
  11068. DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
  11069. /* send acquire request */
  11070. rc = bnx2x_send_msg2pf(bp,
  11071. &resp->hdr.status,
  11072. bp->vf2pf_mbox_mapping);
  11073. /* PF timeout */
  11074. if (rc)
  11075. return rc;
  11076. /* copy acquire response from buffer to bp */
  11077. memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
  11078. attempts++;
  11079. /* test whether the PF accepted our request. If not, humble the
  11080. * the request and try again.
  11081. */
  11082. if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
  11083. DP(BNX2X_MSG_SP, "resources acquired\n");
  11084. resources_acquired = true;
  11085. } else if (bp->acquire_resp.hdr.status ==
  11086. PFVF_STATUS_NO_RESOURCE &&
  11087. attempts < VF_ACQUIRE_THRESH) {
  11088. DP(BNX2X_MSG_SP,
  11089. "PF unwilling to fulfill resource request. Try PF recommended amount\n");
  11090. /* humble our request */
  11091. req->resc_request.num_txqs =
  11092. bp->acquire_resp.resc.num_txqs;
  11093. req->resc_request.num_rxqs =
  11094. bp->acquire_resp.resc.num_rxqs;
  11095. req->resc_request.num_sbs =
  11096. bp->acquire_resp.resc.num_sbs;
  11097. req->resc_request.num_mac_filters =
  11098. bp->acquire_resp.resc.num_mac_filters;
  11099. req->resc_request.num_vlan_filters =
  11100. bp->acquire_resp.resc.num_vlan_filters;
  11101. req->resc_request.num_mc_filters =
  11102. bp->acquire_resp.resc.num_mc_filters;
  11103. /* Clear response buffer */
  11104. memset(&bp->vf2pf_mbox->resp, 0,
  11105. sizeof(union pfvf_tlvs));
  11106. } else {
  11107. /* PF reports error */
  11108. BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
  11109. bp->acquire_resp.hdr.status);
  11110. return -EAGAIN;
  11111. }
  11112. }
  11113. /* get HW info */
  11114. bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
  11115. bp->link_params.chip_id = bp->common.chip_id;
  11116. bp->db_size = bp->acquire_resp.pfdev_info.db_size;
  11117. bp->common.int_block = INT_BLOCK_IGU;
  11118. bp->common.chip_port_mode = CHIP_2_PORT_MODE;
  11119. bp->igu_dsb_id = -1;
  11120. bp->mf_ov = 0;
  11121. bp->mf_mode = 0;
  11122. bp->common.flash_size = 0;
  11123. bp->flags |=
  11124. NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
  11125. bp->igu_sb_cnt = 1;
  11126. bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
  11127. strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
  11128. sizeof(bp->fw_ver));
  11129. if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
  11130. memcpy(bp->dev->dev_addr,
  11131. bp->acquire_resp.resc.current_mac_addr,
  11132. ETH_ALEN);
  11133. return 0;
  11134. }
  11135. int bnx2x_vfpf_release(struct bnx2x *bp)
  11136. {
  11137. struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
  11138. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11139. u32 rc = 0, vf_id;
  11140. /* clear mailbox and prep first tlv */
  11141. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
  11142. if (bnx2x_get_vf_id(bp, &vf_id))
  11143. return -EAGAIN;
  11144. req->vf_id = vf_id;
  11145. /* add list termination tlv */
  11146. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11147. sizeof(struct channel_list_end_tlv));
  11148. /* output tlvs list */
  11149. bnx2x_dp_tlv_list(bp, req);
  11150. /* send release request */
  11151. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11152. if (rc)
  11153. /* PF timeout */
  11154. return rc;
  11155. if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
  11156. /* PF released us */
  11157. DP(BNX2X_MSG_SP, "vf released\n");
  11158. } else {
  11159. /* PF reports error */
  11160. BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
  11161. resp->hdr.status);
  11162. return -EAGAIN;
  11163. }
  11164. return 0;
  11165. }